How to compare a date in custom field with today’s date in custom WP_Query?
Try with this. ‘meta_query’ => array( array( ‘key’ => ‘event_date’, ‘value’ => date(‘Y-m-d’), ‘type’ => ‘date’, ‘compare’ => ‘<=’ ) hope is useful for it.
Try with this. ‘meta_query’ => array( array( ‘key’ => ‘event_date’, ‘value’ => date(‘Y-m-d’), ‘type’ => ‘date’, ‘compare’ => ‘<=’ ) hope is useful for it.
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
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
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.
Using get_option() you can get the page that is assigned to the front page: $frontpage = get_post(get_option(‘page_on_front’)); Or as you have it: $my_query = new WP_Query( array( ‘page_id’ => get_option(‘page_on_front’) ) );
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
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
I think I’d setup a loop for all posts and the do something like this inside the loop: $post_cats = get_the_category(); $brand_cats = 0; $retail_cats = 0; foreach ( $post_cats as $post_cat ) { if ($post_cat->category_parent == 187) { $brand_cats++; if ($post_cat->category_parent == 186) { $retail_cats++; } } if ( $brand_cats > 1 ) echo … Read more
$args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => 10, ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘_price’, ‘order’ => ‘asc’ ); $loop = new WP_Query( $args ); echo ‘<form id=”checkme”>’; while ( $loop->have_posts() ) : $loop->the_post(); global $product; echo ‘<div>’; echo ‘ <input type=”radio” name=”products” value=”‘.get_the_title().'” >’; echo ‘<label>’ . woocommerce_get_product_thumbnail().’ ‘.get_the_title().'</label>’; echo ‘</div>’; /* echo ‘<br … Read more
You can create a taxonomy query. Assuming that “curso” is the term slug, it would look like this: $query = new WP_Query( array( ‘post_type’ => ‘obras_en_curso’, ‘posts_per_page’ => 4, ‘tax_query’ => array( array( ‘taxonomy’ => ‘casa_unifamiliar’, ‘field’ => ‘slug’, ‘terms’ => ‘curso’, ), ), ) ); For more information, see: https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters