WP Query and order by particular specified IDs

To keep the same post order as it was passed to the post__in parameter, you need to pass post__in as value to orderby argument and ASC to the order argument $query_args = [ ‘posts_per_page’ => $products, ‘no_found_rows’ => true, ‘post_type’ => ‘product’, ‘post__in’ => [161,165,131,202], ‘orderby’ => ‘post__in’, ‘order’ => ‘ASC’ ]; EDIT Looking at … Read more

Displaying a specific post in a wp query by post id

post_id is not a valid argument for query_post Change post_id to p, so you get: query_posts(‘p=40&post_type=homepage_video’); while (have_posts()): the_post(); ?> <div id=”video-panel-blue”> <?php get_custom_field(‘home-video-iframe’, TRUE); ?> </div> <?php endwhile; ?> to see the list of arguments you can use with query_posts take a look at this codex entry

Get count of custom post type created by current user

I’m posting a new answer because I found this thread while searching for the same thing and the solutions here weren’t optimal. The post_type argument can be a string or an array of post types. function custom_count_posts_by_author($user_id, $post_type = array(‘post’, ‘page’, ‘custom_post_type’)) { $args = array( ‘post_type’ => $post_type, ‘author’ => $user_id, ‘post_status’ => ‘publish’, … Read more

How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?

pre_get_posts is executed before each and every query. Your $query->is_main_query() is making this code change the query only for the Main query. So, if you’re in an archive page, you’re modifying only the archive posts, and not any of the others queries (widgets, menus, etc). But be aware, that code you added there will change … Read more