Hi notavailable98
What is the meta key name and what is it’s value when it’s a sold property?
Hi keesiemeijer, and thanks for the quick reply!
the meta key is ‘_premprop_sold’ and the value is ‘yes’.
Do all properties have the _premprop_sold meta key (with ‘yes’ and ‘no’ values) or only the properties that are sold?
If all properties have the _premprop_sold meta key try it with this in your (child) theme’s functions.php file.
add_filter( 'related_posts_by_taxonomy_posts_join', 'rpbt_filter_tax_related_join' );
function rpbt_filter_tax_related_join( $args ){
global $wpdb;
$args .= " INNER JOIN $wpdb->postmeta AS mt1 ON ( $wpdb->posts.ID = mt1.post_id )";
return $args;
}
add_filter( 'related_posts_by_taxonomy_posts_where', 'rpbt_filter_tax_related_where' );
function rpbt_filter_tax_related_where( $args ){
// Query for premprop_sold meta key where value is not yes
$args .= " AND ( mt1.meta_key = '_premprop_sold' AND mt1.meta_value != 'yes' )";
return $args;
}
btw:
consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost. Or create a plugin with the code above.
Hi,
Thank you very much for the code!
I put it in my site specific plugin and it did not cause any errors but I’m having problems testing if it actually does the job. I created a property almost identical to another property, with the exact same taxonomies, and it is NOT marked as sold. On the new property page, I can see the original one at the top of the related posts list, however on the original property page I do not see the new one at all. I assume it may have something to do with caching, but that’s just my assumption…
Thanks so much for the help! I appreciate all your efforts.
I would test it like this.
Remove the code from your site site specific plugin. Go to a page were there are sold and unsold related properties. Add the code back. Refresh the page and see if only the unsold related properties remain.
Do unsold properties have the _premprop_sold meta key with a value of ‘no’?
Works perfectly, Thank you very much!
I appreciate your taking the time and effort to help and the extensive scope of your support.
P.S. Correct, unsold properties have the _premprop_sold meta key with the value of ‘no’.
You’re welcome 🙂
btw:
This will add the meta query to the widget also. Do you want it to only be used by the shortcode?
I know it applies to the widget as well and that’s great.
Thanks again 🙂