How can I display a specific user’s first published post?

The following query retrieves the oldest post of a specified user/author: $user_id = 42; // or whatever it is $args = array( ‘posts_per_page’ => 1, ‘post_status’ => ‘publish’, ‘author’ => $user_id, ‘orderby’ => ‘date’, ‘order’ => ‘ASC’, ); $first_post = new WP_Query($args); if ($first_post->have_posts()) { $first_post->the_post(); // Now you can use `the_title();` etc. wp_reset_postdata(); } … Read more

Show recent published posts

The arguments you are using are wrong. They should be: $args = array( ‘numberposts’ => ’10’, ‘post_type’ => ‘post’, ‘post_status’ =>’publish’, ‘tax_query’ => array( ‘taxonomy’ => ‘category’, ‘field’ => ‘id’, ‘terms’ => array( 10, 11, 57 ), ‘operator’ => ‘NOT IN’, ) ); Or shorter: $args = array( ‘numberposts’ => ’10’, ‘post_type’ => ‘post’, ‘post_status’ … 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);

How to add a checkbox inside the “Publish post” widget?

Hook into post_submitbox_misc_actions and print the checkbox: add_action( ‘post_submitbox_misc_actions’, function() { ?> <div class=”misc-pub-section”> <label><input type=”checkbox”> click me</label> </div> <?php }); Wrap the code in a <div class=”misc-pub-section”>, otherwise the spacing looks a little bit weird. Examples: language selector, noindex checkbox, public preview checkbox.

How to make scheduled post preview visible to anyone?

Draft previews Take a quick look at this chunk of core code in query.php which [Checks] post status to determine if post should be displayed. http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php#L2658 if ( ! is_user_logged_in() ) { // User must be logged in to view unpublished posts. $this->posts = array(); } …is what makes it somewhat non-straightforward to bypass for … Read more