WordPress REST Create Post of Custom Type

Make sure your post type is shown in the REST API. $args = array( //* Use whatever other args you want ‘show_in_rest’ => true, ‘rest_base’ => ‘myslug’, ‘rest_controller_class’ => ‘WP_REST_Posts_Controller’, ); register_post_type( ‘myslug’, $args ); The endpoint to create a post would then be http://example.com/wp-json/wp/v2/myslug. Edit: The above is all that’s needed for a custom … Read more

$post>ID displays wrong post ID

If i understand correctly you are trying to display a list of child pages of a page in a widget, if so then first check if you are on a page using the conditional tag is_page() then you can use $wp_query->get_queried_object_id() like t31os has pointed out so your widget display function should look like this: … Read more

How to publish a post with empty title and empty content?

If the post content, title and excerpt are empty WordPress will prevent the insertion of the post. You can trick WordPress by first filtering the input array so empty values are set to something else, and then later resetting these values back to empty strings. This will bypass the standard check. add_filter(‘pre_post_title’, ‘wpse28021_mask_empty’); add_filter(‘pre_post_content’, ‘wpse28021_mask_empty’); … Read more

How to remove Nextpage tag inside posts text depending of utm_campaign

You can use the_post hook to remove <!–nextpage–>. In this case: add_action( ‘the_post’, ‘campaign_remove_nextpage’, 99); function campaign_remove_nextpage ( $post ) { if ( ($_GET[‘utm_campaign’]== ‘nonextpagecampaign’) && (false !== strpos( $post->post_content, ‘<!–nextpage–>’ )) ) { // Reset the global $pages: $GLOBALS[‘pages’] = [ $post->post_content ]; // Reset the global $numpages: $GLOBALS[‘numpages’] = 0; // Reset the … Read more