Customy WP Query Args are convertet in SQL result

As the dev note for 4.8.3 implies, you need to unescape the escaped % by using the $wpdb->remove_placeholder_escape method. Something like global $wpdb; add_filter(‘posts_request’,array($wpdb, ‘remove_placeholder_escape’)); Very untested.

Get Child Page IDs by Parent ID

This should work. I’m not entirely sure what is wrong with your code (it’s getting late) but the below code works on my end. Obviously I replaced $order->get_id() with a known ID and post_type was set to page. <?php $parentid = $order->get_id(); $child = new WP_Query( array(‘post_parent’ => $parentid, ‘post_type’ => ‘shop_subscription’) ); if ($child->have_posts()) … Read more

Append URL query to next post link in custom query

Deep down that function uses get_pagenum_link(). This is filterable with the get_pagenum_link filter. So you could add and remove that filter that uses a global variable that gets set in your function before the link is retrieved: function wpse_287817_add_query_args( $url ) { global $wpse_287817_query_args; return add_query_arg( $wpse_287817_query_args, $url ); } add_filter( ‘get_pagenum_link’, ‘wpse_287817_add_query_args’, 10 ); … Read more

Why are my paginated posts always returning the same results?

Found the culprit. I’d foolishly hard-coded the offset to be 0, which must have been overriding WordPress’ query. I changed: $posts_list = new WP_Query([ ‘posts_per_page’ => 1, ‘offset’ => 0, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘post_type’ => ‘post’, ‘suppress_filters’ => true, ‘paged’ => $paged ]); to: $posts_list = new WP_Query([ ‘posts_per_page’ => 1, ‘orderby’ … Read more

The most effective way to split by post type in custom query?

There is no need to split the query or do multiple queries. Just use the parameter orderby with value post_type to sort separated by post types. You can use a second value for additional sorting, e.g. by date. See Codex: Class Reference | WP_Query | Order & Orderby Parameters for more information.

ACF Query Structure

So you want to check if a field from acf has a value and if thats true you want to display it. You can do it with this: if( get_field( ‘video’ ) ) { ?> <video width=”320″ height=”240″ controls> <source src=”https://wordpress.stackexchange.com/questions/292287/<?php echo get_field(“video’ ); ?>” type=”video/mp4″> </video> <?php }else{ the_post_thumbnail(”, array(‘class’ => ‘img-responsive’)); } This … Read more

WP Query – order posts by meta field first and then order the rest

You should be able to name and sort your meta query clauses like this: $meta_query = array( ‘relation’ => ‘OR’, ‘foo’ => array( ‘key’ => ‘expiring_date’, ‘value’ => date(‘Ymd’), ‘compare’ => ‘>’, ‘type’ => ‘DATE’ ), ‘bar’ => array( ‘key’ => ‘expiring_date’, ‘compare’ => ‘NOT EXISTS’ ), ‘baz’ => array( ‘key’ => ‘expiring_date’, ‘value’ => … Read more