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

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

How to get a category in a list item class

The first issue I’m seeing is that you’re trying to use the_category as a class. This won’t work as this function is intended to output the links to the categories assigned to that post. So it’s putting the href inside your class. You can debug and see how it works by removing your li and … Read more

Compile two queries to one set of results?

That would be nice if you query all three post_types at the same time, using one query, and then manipulating it using php. Consider this query: $args = array( ‘post_type’ => array( ‘pt1’, ‘pt2’, ‘pt3’ ), ‘meta_key’ => BUMP!!!! ); You can not use an array of meta_keys. So, I think the only way is … Read more

Generate a tabbed submenu — from taxonomy term or submenu item — with sample content

I ended up solving this problem with Ubermenu. What I wanted to write was complex enough that it made more sense to get a tested, commercial plugin that had the features I need. MaxMegaMenu didn’t do tabbed content but Ubermenu does. I’m able to construct menus like this: Taxonomy1 [Tabs] [DynamicTerms] [Dynamic Posts] Taxonomy2 [Tabs] … Read more