How can I create a WP_Query that returns posts where one meta_value
How can I create a WP_Query that returns posts where one meta_value <= another meta_value
How can I create a WP_Query that returns posts where one meta_value <= another meta_value
The integral part is using a date_query in a custom WP_Query to fetch the adjacent posts according to the parameters passed to it. Here is an idea coming from a plugin I’m busy with To accomplish what you need, you’ll need the following The current post object to get the post_date and ID The categories … Read more
I’m afraid that there is no way to do such advanced queries using WP_Query. But, of course, you can still achieve that result, but you’ll need to write a little bit more code. There are two solutions: It’s hard to give you precise code, because there aren’t many details in your question, but maybe this … Read more
$post_count is a WP_Query variable. You need $the_query->post_count if( $the_query->have_posts() ): ?> <h1>Partners<h1><hr> <?php while( $the_query->have_posts() ) : $the_query->the_post(); if($the_query->post_count=1){ // … Otherwise it looks like it should work though I am not in a position to test this right now.
This is default behavior when the post__in parameter is used. If you read the docs, you will see that you should set ‘ignore_sticky_posts’ => 1 to eliminate sticky posts being queried EDIT Your query arguments should look like this $recommended_args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 3, ‘post__in’ => get_option(‘sticky_posts’), ‘orderby’ => ‘date’, ‘ignore_sticky_posts’ … Read more
Dear I have wasted my week on this problem, basically when you select static page as your home page in setting->reading of wordpress the complete behavior of listing things are changed, basically static pages are never meant for pagination the fact is when you call the $paged variable it will always return zero even if … Read more
I solved it with a bit of JS instead. Queried the two post types in a merged query and outputted each item with a ‘data-sort’ tag on each element. Then sorting the elements independently. $archive_items.sort(function(a,b) { var an = a.getAttribute(‘data-sort’), bn = b.getAttribute(‘data-sort’); if(an < bn) { return 1; } if(an > bn) { return … Read more
How-to simplify your life I’d go a fairly simpler route: Add a “main/parent” page Apply your template there Add “child” pages to this main page Alter the query to include them Code example as plugin for a quick test Here’s an (untested) plugin that modifies the query args to not only reduce it to a … Read more
You can do it like so: Use the meta_query parameter to query both posts that have the metadata _my_column (or whatever is the meta key) and posts that do not have it (i.e. does not exist in the database). Use a custom name (i.e. array key) with the above meta query clauses and then use … Read more
You should use wc_get_products and a custom filter for adding your specific query. Example I want to find products containing a specific attribute value “table-filter”. $args = array( ‘table-filter’ => array(1,2,3) ); $products = wc_get_products($args); Than I have a filter for this: add_filter(‘woocommerce_product_data_store_cpt_get_products_query’, ‘my_handle_custom_query_var’, 10, 2); function my_handle_custom_query_var($query, $query_vars) { if (!empty($query_vars[‘table-filter’])) { $query[‘tax_query’][] = … Read more