Running multiple WP_Query

Your problem is here: foreach ($wqPort as $projeto) $wqPort is an object of type WP_Query, not an array. If you look at your PHP error log, you should be seeing warnings and notices for those lines Instead, use a standard post loop: $q = new WP_Query( [ .. args here … ] ); if ( … Read more

Should I reset $wp_query?

The query is right and its working. But should I reset something? Yes! Should I reset them both or just one of them, or is it fine like above? Neither! Your WP_Query object is self contained in $query, so there’s no reason to touch the $wp_query global variable, why would you? $wp_query represents the main … Read more

2 column recent post query not respecting float right [closed]

Try this <div class=”row”> <?php $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 3 ); $counter = 0; $_posts = new WP_Query($args); ?> <?php if( $_posts->have_posts() ) : ?> <?php while ( $_posts->have_posts() ) : $_posts->the_post(); $counter++ ?> <?php if ( $counter === 0 || $counter === 1) : ?> <div class=”col-md-6 float-left”> <div> <a … Read more

Target post_date_gmt if it’s empty or not set

I’ve figured it out: ‘meta_query’ => array( array( ‘relation’ => ‘OR’, array( ‘key’ => ‘_setting_update’, ‘value’ => ‘1’, ‘compare’ => ‘==’ ), array( ‘relation’ => ‘AND’, array( ‘key’ => ‘_created_date’, ‘value’ => ”, ‘compare’ => ‘NOT EXISTS’, ), array( ‘key’ => ‘_modified_date’, ‘value’ => ”, ‘compare’ => ‘NOT EXISTS’, ), ) ), ),

Increment paged on WP_Query

You need to create a new WP_Query instance with the updated arguments. I will usually write it like this $args = [ ‘post_type’ => ’employee’, ‘post_status’ => ‘any’, ‘posts_per_page’ => 10, ‘paged’ => 1, ]; $query = new WP_Query($args); while ($query->have_posts()) { // your logic goes here // foreach ($query->posts as $custom_stuff) {} // prepare … Read more

Using Transients

I have set set_transient( ‘pgggo_acf_list_transient’, $pgggo_qry, 12 * 7000 ); is that too high? 12 * 7000 is just over 23 hours. Whether or not that’s too high (or low) depends entirely on your specific needs. The expiry time should be based on how often the data needs to be refreshed. What if there is … Read more

Store metakey value as an array

I don’t think WP_Query returns the meta fields for you as well. So you need to loop over the posts and run get_post_meta() manually. Assuming one office has at max one _octopus_id, you could write it like this: // here we will store the ids $octopiIds = []; $query = new WP_Query([ ‘post_type’ => ‘office’, … Read more

Array to string conversion on array_map

Look closely at $offices: array (size=500) 0 => array (size=1) ‘id’ => string ‘1382’ (length=4) 1 => array (size=1) ‘id’ => string ‘1330’ (length=4) That is not an array of IDs. It’s an array of arrays. $offices[0] is not ‘1382’. It’s an array. So implode() on $offices is trying to concatenate arrays, which is what’s … Read more

WP_Query order by not working properly due to category I believe

I manage to fixed this the problem was type => ‘numeric’ $query = new WP_Query( array( ‘post_type’ => post, ‘posts_per_page’ => -1, ‘category_name’ => $category, ‘meta_query’ => array( ‘relation’ => ‘AND’, ‘price_clause’ => array( ‘key’ => ‘price’, ‘type’ => ‘numeric’, ‘compare’ => ‘EXISTS’ ), ‘external_clause’ => array( ‘key’ => ‘external_link’, ‘compare’ => ‘EXISTS’ ) ), … Read more

How to show all taxonomies within custom post type loop

I’m answering the <?php //echo tax names here ?>: In the loop, you can get the post terms using wp_get_post_terms(): while ($articles->have_posts() ): $articles->the_post(); $terms = wp_get_post_terms( get_the_ID(), ‘topic’, [ ‘fields’ => ‘names’ ] ); Then you can do something like echo implode( ‘ ‘, $terms ); inside the <div> tag: <div class=”masonry__item col-lg-3 col-md-6″ … Read more