How to throw error to user when saving post

You can use admin_notices hook http://codex.wordpress.org/Plugin_API/Action_Reference/admin_notices For example: function ravs_admin_notice() { ?> <div class=”error”> <p><?php _e( ‘Article with this title is not found!’, ‘my-text-domain’ ); ?></p> </div> <?php } on publish_{your_custom_post_type} hook http://codex.wordpress.org/Post_Status_Transitions function on_post_publish( $ID, $post ) { // A function to perform actions when a {your_custom_post_type} is published. $post_exists = $wpdb->get_row(“SELECT post_name FROM … Read more

Custom Post Type Pagination Not Working On Archive Page

Modify main query on post type archive page Instead of direct modify main query, just use normal loop ( you can create post type template, in your case archive-portofolio.php ), and run your modifying query under filter pre_get_posts. Your normal loop on archive-portfolio.php <div class=”row text-center small-up-1 medium-up-2 large-up-3 small_section”> <?php if ( have_posts() ) … Read more

How to customize post edit notices

You can used the post_updated_messages filter. add_filter( ‘post_updated_messages’, ‘rw_post_updated_messages’ ); function rw_post_updated_messages( $messages ) { $post = get_post(); $post_type = get_post_type( $post ); $post_type_object = get_post_type_object( $post_type ); $messages[‘my-post-type’] = array( 0 => ”, // Unused. Messages start at index 1. 1 => __( ‘My Post Type updated.’ ), 2 => __( ‘Custom field updated.’ … Read more

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

Is it OK to move admin menu items?

this might work: add_filter(‘custom_menu_order’, ‘my_custom_menu_order’); add_filter(‘menu_order’, ‘my_custom_menu_order’); function my_custom_menu_order($menu_ord) { if (!$menu_ord) return true; return array( ‘index.php’, // the dashboard link ‘edit.php?post_type=custom_post_type’, ‘edit.php?post_type=page’, ‘edit.php’ // posts // add anything else you want, just get the url ); }

Creating a metabox to upload multiple images, Ignoring The Featured Image

Generally speaking, I would take the approach of querying for post attachments, but withhold the attachment that is the post thumbnail. WP provides a simple way of finding the post thumbnail ID with get_post_thumbnail_id (Codex Ref). To modify the code from the other post, I would add the following parameter to the $args array to … Read more