Mix post date with post meta value using WP_Query

Finally I’ve decided to use custom sql query with get_results method. $query = “SELECT SQL_CALC_FOUND_ROWS p.*, IFNULL(m2.meta_value, p.post_date_gmt) as zen_date FROM {$wpdb->posts} p LEFT JOIN {$wpdb->postmeta} m1 ON (p.ID = m1.post_id AND m1.meta_key = ‘is-exclude’) LEFT JOIN {$wpdb->postmeta} m2 ON (p.ID = m2.post_id AND m2.meta_key = ‘is-push’) WHERE p.post_type=”post” AND p.post_status=”publish” AND m1.post_id IS NULL … Read more

How to query search only for post titles?

Try this $posts = $wpdb->get_results(“SELECT * FROM “.$wpdb->prefix.”posts WHERE post_title LIKE ‘%” . $_REQUEST[‘s’] .”%’ AND post_status=”publish” AND post_type=”post””); $do_not_duplicate = $post->ID; foreach($tit as $post) { if( $post->ID == $do_not_duplicate ) continue; ?> Please let me know if any query. Hope it will help you!

How to compare between two dates in a nested loop?

That date format will be a problem for wp_query because it’s a string in the format d-m-y. Your meta_query is close but the key needs to be the field name, and the stored date format must be yyyy-mm-dd: ‘meta_query’ => array( array( ‘key’ => ‘usp-custom-51’, ‘value’ => array($start, $end), ‘compare’ => ‘BETWEEN’, ‘type’ => ‘DATE’ … Read more

Query child posts with tax query on parents

My solution to this ended up splitting this into 2 queries: Get the IDs of all the parent products I want to ignore Get all the variations that don’t a post_parent from that list of IDs $archived_products = wc_get_products( array( ‘type’ => array( ‘variable’, ‘variable-subscription’ ), ‘paginate’ => false, ‘limit’ => -1, ‘category’ => array( … Read more

WP_Query & Duplicate entries

There shouldn’t be a foreach loop inside the while. The while loops over posts, so you don’t need another foreach. The while loop in this context is what WordPress calls “The Loop”. See the section of documentation for The Loop on secondary queries here. So your loop should look like this: <?php while ( $posts->have_posts() … Read more

Post Filtered by Custom Field Value

Took the advice and decided not to reinvent the wheel. Created a taxonomy specific for products called Product categories. Added the following code to my functions.php. add_action(‘init’, ‘products_categories’, 0); function products_categories(){ $labels = array (‘name’ => _x(‘Product Categories’,’taxonomy general name’), ‘singular_name’ =>_x(‘Product Category’,’taxonomy singular name’), ‘serch_items’ => __(‘Search Product Categories’), ‘popular_items’ => (‘Popular Product Categories’), … Read more