How to set posts per page using WP_Query()

query_posts will do the query again (destroy current wp_query and create a new one and then doing the query with the parameters you pass to it) To get the same behaviour after setting the new parameter with set_var you need to query the database again using something like this $wp_query->set(‘posts_per_page’, 1); $wp_query->query($wp_query->query_vars);

query multiple taxonomies

First of all, get all term slugs from the custom taxonomy space by current post ID. $space_terms = wp_get_post_terms( $post->ID, ‘space’ ); if( $space_terms ) { $space_terms = array(); foreach( $space_terms as $term ) { $space_terms[] = $term->slug; } } You should specify the logical relationship between each inner taxonomy array when there is more … Read more

get_template_part in for loop

Your problem is that the variable passed to setup_postdata() must be the global $post variable, like this: // Reference global $post variable. global $post; // Get posts. $posts = get_posts(array( ‘post_type’ => ‘post’, ‘post_count’ => 4 )); // Set global post variable to first post. $post = $posts[0]; // Setup post data. setup_postdata( $post ); … Read more

Query WooCommerce orders where meta data does not exist

The meta_query argument (that you can use in a WP_Query) is not enabled by default when using a WC_Order_Query through wc_get_orders() WooCommerce function. But for you can use the undocumented Custom Field Parameters (just like in a WP_Query): meta_key meta_value meta_value_num meta_compare So in your case you can use the following instead: $orders = wc_get_orders( … Read more

how to filter by last name for custom post

Order by the last word in the post title To order by the speaker’s last name, you can use the following setup (PHP 5.4+): // args $args = [ ‘posts_per_page’ => 10, ‘post_type’ => ‘speaker’, ‘meta_key’ => ‘speaker-front-page’, ‘meta_value’ => ‘1’, ‘orderby’ => ‘wpse_last_word’, //<– Our custom ordering! ‘order’ => ‘ASC’ ]; // query $the_query … Read more

tech