While creating Block Themes in WordPress, how can I query custom posts for an Archive view?

I found a solution for this. So for those of you who face a similar situation, here’s what I did (based on this solution : https://stackoverflow.com/questions/68871598/wordpress-query-loop-block-not-showing-custom-post-types) So basically the custom post type that I had created needed to have this argument while registering the post-type in functions.php ‘show_in_rest’ => true And then I just had … Read more

Can I create a loop with multiple post types and specify different $args for each post type?

Can I create a loop with multiple post types and specify different $args for each post type? Simply put no… you can’t have a single query instance with three differing sets of arguments. The reason why is pretty simple, the query class will only take one array of arguments per instance. If you want differing … Read more

How to echo data after a WP_Query

Within your Query loop, using your image URL as an example, put this: <?php $image_url = get_post_meta($post->ID, ‘image-url-field’, true); ?> Replace “image-url-field” with the name of your custom field. Then, also within that same loop, do this: <?php echo $image_url; ?> Reference: http://codex.wordpress.org/Function_Reference/get_post_meta

Order query by meta_value with multiple custom fields

You can use meta_query to get only posts with display_submenuexpositions = true and order them by order_submenuexpositions. $args = array( ‘orderby’ => ‘meta_value’, ‘meta_key’ => ‘order_submenuexpositions’, ‘meta_query’ => array( array( ‘key’ => ‘display_submenuexpositions’, ‘value’ => ‘true’, ‘compare’ => ‘LIKE’ ) ) ); $query_posts( $args );

Sub-loop / nested loops Best Practices

First see When should you use WP_Query vs query_posts() vs get_posts()? My understanding of “The Loop” is that there is, and should only ever be, ONE “The Loop” per page/post – and that The Loop is responsible for iterating through that page/post/archive’s content. Yes, it’s commonly referred to as “main loop”. But “loop” in general … Read more

3 Columns, 3 Categories, One Archive, and Pagination

OK this is what I ended up with, that works well: // get paged value. $paged = get_query_var( ‘paged’ ); $maxPages = array(); $max = 0; // Create the queries $soundPosts = new WP_Query(‘posts_per_page=1&cat=4&paged=’ . $paged); $viewsPosts = new WP_Query(‘posts_per_page=1&cat=5&paged=’ . $paged); $wordsPosts = new WP_Query(‘posts_per_page=1&cat=6&paged=’ . $paged); // get max number of pages for … Read more