Having an issue where when using the following payload with a post request on https://localhost:2368/ghost/api/v0.1/posts the body of the post is not loaded into ghost blog.
{
title: 'some title',
html: '<p>some html</p>',
plaintext: 'some plaintext'
}
After the request, only the title is loaded into ghost blog.
Using Ghost v2.13.1
Would be helpful discover field(s) that should be used for the body of a post.
#mattcameron Ghost uses mobiledoc (spec) - the html and plaintext fields are generated from that and can't be set separately.
The v0.1 API is private and not documented as it wasn't designed for use outside of the admin area, if you can I suggest you wait a little while for the v2 Admin API which will be released soon along with SDKs to make it easier to work with.
Related
I want to create a function that connect my Wordpress site to an external API when a post is updated. I aready did the method by using the post_updated Hook, but I would like to send a notification to the WP editor. Since on Gutemberg the post requests are made using AJAX, I'm not sure how to display notification without refreshing the page. Do you know if there is a Hook to send these notifications? Thanks in advance
I spect to send a notification to Wordpress Editor
In the block Editor, the Notices Data API is used to create custom Notifications with JS/AJAX for events like when a post is published, display errors or warnings. Below is the example usage given in the WordPress Gutenberg Notifications guide:
( function ( wp ) {
wp.data.dispatch( 'core/notices' ).createNotice(
'success', // Can be one of: success, info, warning, error.
'Post published.', // Text string to display.
{
isDismissible: true, // Whether the user can dismiss the notice.
// Any actions the user can perform.
actions: [
{
url: '#',
label: 'View post',
},
],
}
);
Depending on what you need notices for, withNotices (a Higher Order Component) could be of interest to you. There is also the ability to lock/prevent post saving which can be used in conjunction with your notice/s.
I encountered a problem while sending a link to my new Wordpress site to a friend. While the link on every other platform shows exactly the same description, as it should. Discord, on the other hand, puts author above description so that when the link is sent it sais:
[mydomain.com]
admin
[description]
It is not that much of a problem but I think that it should not take a place, especially when I often link lot of things on discord.
Adding this block of code to your wordpress functions.php (use child theme if necessary)
This is the shortest method of removing the data that discord pulls in though it will remove the data from being view from every site that wants to embed a link.
/* Disable oEmbeds author name & author url ~ Stops Showing in embeds */
add_filter( 'oembed_response_data', 'disable_embeds_filter_oembed_response_data_' );
function disable_embeds_filter_oembed_response_data_( $data ) {
unset($data['author_url']);
unset($data['author_name']);
return $data;
}
Note this was taken from another post on stackOverflow and isnt my own code : there is also a more compliacted solution on this thread as well. original post
This can also have so negative effects on SEO due to not sharing the data, and we all know google loves data.
An alternative solution is to set the author of the post to the site name rather than the admin user.
Side note you really should change your username from admin to something less generic so a potentual hacker has to work out the username as well as the password.
I have an entire post notification system built using firebase. Using a program like postman, I can send the title & body and the notifications show up on the iOS/android devices. So the entire linkage works. Specifically in postman using the Post function, the URL posted too is https://example.com/backend/sendNotification.php. The body code is:
{
"title" : "post title",
"body" : "post body"
}
But now I have to tie it into wordpress. The goal is that when a post is published, the title and body, most likely truncated to a limited amounts of characters, get passed to the URL.
I know the code will go in the function.php file, but beyond that I'm stumped. How can I pass the title & body to the URL?
First, you want to hook into the post creation. There are several hooks that would probably fit your needs. Then use wp_remote_post or curl to post your data to the webhook.
add_filter( 'wp_insert_post_data', 'push_post_data' );
function push_post_data( $data ) {
if ('publish' == $data['post_status']) {
wp_remote_post($url, $array_with_title_and body);
}
}
If you're using a child theme or a custom theme functions.php is fine.
I'm currently on a project where I want to have :
Wordpress for easy content managment.
AngularJS for some UX (the goal is to have no page reload + nice animation between pages loading) + further functionalities.
And care about the SEO.
In that purpose, I'm using Angular's Route module to get the user a smoother experience, and using the Angular HTML5 "pretty urls" mode to "hook" the page switching (No hashbang -> natural links).
I don't want to generate hashbangs because it's more difficult to maintain (HTML snapshots with phantom.js server etc...) than just leaving Wordpress generate the content as he does it well.
So my intention was to let angularJS controls the user's navigation, and wordpress to generate the content when user will F5 & for the SEO bots(No JS).
But I can't find a clean & clear solution to this problem because either the Angular way will work, either the "PHP" way will work.
Any ideas will be welcome ! :)
Wordpress already provides you with wp_ajax_ hook for AJAX requests. ( link)
Example:
mysite.com/my-test-page
Wordpress
In this simple case we need our wp_ajax_ hook to retrieve a page by it's slug.
One easy way is to use get_page_by_path($page_path, $output, $post_type), to get the page we want where $page_path is the slug.
Then return the page data as JSON, return json_encode($pageArray);
AngularJS
Route: Do a simple GET:
.when('/:page_slug', {
templateUrl: 'views/page.html',
controller: 'PageController',
resolve: {
page : function($route) {
return $http.get(wp_ajax_url,
{
'action': 'the_ajax_hook',
'data': $route.current.params.page_slug
}
);
}
}
})
SEO
Google recently announced they are updating the Webmaster Tools to show you how a Javascript generated site renders and provide you with tips on how to make your site crawl-able.
http://googlewebmastercentral.blogspot.com/2014/05/understanding-web-pages-better.html
Apart from that you can use other services to make your site SEO-friendly today:
getseojs.com
brombone.com
prerender.io
I want to show my wordpress post into jquery mobile application... But so far i didnt got the success. I am using jquery.post() function but my response comes empty....
Request to the desired url goes well , status comes 200 ok but response coming is always blank :( Although the same post function & url is working fine in other php pages....
below is my code
function get_Time(cityCode,date){
jQuery.post(
"http://test.local/time/",
{ city: cityCode, date:date},
function (data){jQuery('#print_time').html(data);}
);
}
function _get_Time(response)
{
alert("response:"+response);
var time = new Array();
time = response.split('|')
jQuery("#print_time").html(time[0]);
}
Please give me some solution for showing my wordpress post (only text + links) content into my jquery mobile applicaton....
I am not sure about what you are going to do. It seems to me, like you want to retrieve a certain WordPress post content + additional information via Ajax, I think the easiest way to do it is the following:
Write a custom server-side PHP-Script (which possibly takes a WordPress Slug or ID)
Create a connection to the database in this script, get the post contents you want to have and return these as text or JSON to your JQuery mobile and use it
It might work in a way like this (not tested):
include ‘path-to-wp-directory/wp-blog-header.php’;
$post_id=0;
if(isset($_REQUEST['post_id'])) {
$post_id=intval($_REQUEST['post_id']);
}
global $wpdb;
$post_content = $wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE post_id=".$post_id." AND post_status='publish'";
echo $post_content;
This is only possible if you have access to the server, of course. If you want to get Post Content from an external WordPress Blog, then you should consider using the RSS Feed.
The following article shows how to load WordPress functions in an external PHP Script, which also might be useful: http://www.bloggingtips.com/2009/01/25/use-wordpress-functions-externally/