Add few specific post ids to wp_query

Here is another way of doing it, specially if you need to work with the query object. The issue with merging queries is that you loose the correctness of the query object. My idea here is to run two separate queries, one very lean one to get post ID’s from the date_query query and then … Read more

How to change bulk post status

Yes, it’s possible to loop all publish posts and change their post status to draft. add_action(‘admin_init’,’wpse_244394′); function wpse_244394(){ $args = array(‘post_type’=> ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’=>-1 ); $published_posts = get_posts($args); foreach($published_posts as $post_to_draft){ $query = array( ‘ID’ => $post_to_draft->ID, ‘post_status’ => ‘draft’, ); wp_update_post( $query, true ); } }

Creating new page with pre-defined parent page

You are right on the mark with GET, that would probably be easiest to make use of. Try this: Add_Child_Page::on_load(); class Add_Child_Page { static function on_load() { add_action( ‘init’, array( __CLASS__, ‘init’ ) ); add_action( ‘admin_init’, array( __CLASS__, ‘admin_init’ ) ); } static function init() { add_action( ‘admin_bar_menu’, array( __CLASS__, ‘admin_bar_menu’ ), 90 ); } … Read more

Get the post_id of a new post

Try this… add_action(‘post_updated’, ‘myfunction’); function myfunction( $post_id ) { global $post; if (!file_exists(“/www/foo/blog/wp-content/uploads/” . $post_id)) { mkdir(“/www/foo/blog/wp-content/uploads/” . $post_id, 0777); } } NOTE: Change from save_posts to post_updated which will stop the duplicate issue as it fires on “publish” only and not every time you hit add new or update etc. NOTE: I verified this … Read more

Detect Post Type when publish_post is ran

publish_post will give you a second parameter if you ask for it. Notice the fourth parameter of the add_action call. That is your post object. function run_on_publish_wpse_100421( $postid, $post ) { if (‘news’ == $post->post_type) // your code } } add_action(‘publish_post’,’run_on_publish_wpse_100421′,1,2);

set role specific screen options in post summary page

I assume, you need something like editors can’t see the category column or something like this. This snippet might help you: /** Remove “Options”-Panel, when User is not admin **/ add_filter( ‘manage_posts_columns’, ‘change_columns_for_user’, 10, 2 ); function change_columns_for_user( $columns, $post_type ){ if( ‘post’ != $post_type ) return $columns; if( current_user_can( ‘manage_options’ ) ) return $columns; … Read more