WP_Query about meta_key and its array value

Try this $args = array( ‘post_type’ => ‘book’, ‘posts_per_page’ => -1, ); $query = new WP_Query($args); while($query->have_posts() ) : $query->the_post(); $date = get_post_meta( get_the_ID(), ‘date_all’, true ); if($date[‘year’] >= 2018 && $date[‘month’] == 3){ the_title(); } endwhile; wp_reset_query();

Insert wp_query after the_content with plugin (filter the_content won’t work)

You should remove your hook before query. function wpse_288691_add_query_after_content( $content ) { $ouptut=””; remove_filter( ‘the_content’, ‘wpse_288691_add_query_after_content’ ); // Do your *** WP_Query *** and assign result to $ouptut. // Reset query by executing `wp_reset_query`. add_filter( ‘the_content’, ‘wpse_288691_add_query_after_content’ ); return $content . $ouptut; } add_filter( ‘the_content’, ‘wpse_288691_add_query_after_content’ ); Do not echo anything inside the filter, only … Read more

Is meta_key used for ordering, filtering, or both?

Column meta_key is used for filtering and partially for ordering. Why partially? It is used for ordering only in combination with meta_value. Columns meta_key and meta_value are connected together like column name and column value in traditional table. For raw SQL select it would be possible to order posts by meta_key but from a practical … Read more

Multiple values in WP_Query : category__and

I’m little unclear from your question if the criteria has to match the Product AND the Service .. or the Product OR the Service. You can change the ‘relation’ parameter to achieve this (AND or OR) $args = array( ‘posts_per_page’ => -1, ‘cat’ => 7, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘product_customfield’, … Read more

How to pass a php variable to js within a template?

If you would want to pass the whole wp query you could pack it up in arrays, then json encode it and just write it out in a tag. <?php my_posts = array(); while ( have_posts() ) : the_post(); ?> <?php $properties = array( ‘title’ => get_the_title(), ‘link’ => get_the_permalink() ); $my_posts[] = $properties; ?> … Read more