Custom query for sidebar isn’t returning results

Based on our chat in the comments here’s what I came with. Please advise if it works. <?php function primary_category_query_shortcode( $post, $atts ) { //global $post; //Uncomment this global if it still doesn’t work. $atts = shortcode_atts( $defaults, $atts, ‘primary_category_query’ ); $my_meta = get_post_meta ( $post->ID, ‘_yoast_wpseo_primary_category’, true ); // WP_Query arguments $args = array … Read more

How to loop for every result found in the_content() when using the search query?

got a solution with https://stackoverflow.com/questions/15737408/php-find-all-occurrences-of-a-substring-in-a-string $lastPos = 0; $positions = array(); if($pos==”){} else{ while (($lastPos = strpos($content, $findme, $lastPos))!== false){ $positions[] = $lastPos; $lastPos = $lastPos + strlen($findme); } // Displays foreach ($positions as $eachPos){ $pos = $eachPos; $exctractAfterQuery = substr($content,($pos+strlen($findme) ),40); $exctractBeforeQuery = substr($content,$pos-40,40); $newContent .= “[…”.$exctractBeforeQuery.'<strong class=”search-highlight”>’.$findme.”</strong>”.$exctractAfterQuery.”…]<br>”; } } It works well and … Read more

ACF Date Based wp_query

I’ve modified your existing code.Can you please try the code bellow: $args = array ( ‘post_type’ => ‘exhibitions’, ‘meta_query’=> array( ‘relation’ => ‘AND’, array( ‘key’ => ‘exhibition_status’, ‘value’ => ‘past’, ), array( ‘key’ => ‘end_date’, ‘compare’ => ‘EXISTS’, ‘type’ => ‘DATE’ ), ), ‘meta_key’ => ‘end_date’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’, ‘post_status’ => ‘publish’, … Read more

Woocommerce returns Product post_status as published even tho it is in status draft

The solution is simple, delete the if check you’re having problems and add the post_status parameter to get_posts. For example: $args = [ ‘post_status’ => ‘publish’, ]; $only_published_posts = get_posts( $args ); Likewise we can pass an array of the statuses we do want, e.g. $args = [ ‘post_status’ => [ ‘publish’, ‘pending’ ], ]; … Read more

get_users is missing or skipping over users in loop

Your problem is a basic PHP problem. You’re only looping over the even numbers, 0, 2, 4, 6 This is because at the end of every loop $offset increases by 1: for($offset = 0; $offset < 100; $offset++) But then for some reason it also gets incremented before the loop ends: $offset++; So offset is … Read more