I would like to filter for Properties, that are children of Agents, where no agent has been assigned to the property. I don't know if the system records those records as Agent Title being empty or perhaps the word None.
What would be the correct way to express that kind of filter?
Thank you.
Hi John,
There is nothing ready for that, I have to talk to our development team in order to find a workaround for you. I'll let you as soon as I find something.
Can you suggested a filter via a hook that would work?
Hi John,
Yes, I can. You should paste the code below in functions.php:
add_filter( 'wpv_filter_query', 'exclude_terms_func', 10, 3 );
function exclude_terms_func($query, $setting, $views_ID)
{
if($views_ID == 234)
{
$query['meta_query'][] = array(
'key' => '_wpcf_belongs_agent_id',
'operator' => 'NOT EXISTS'
);
}
return $query;
}
You gotta replace 234 with your View's ID. It should display only properties without agent assigned.
Please let me know if you are satisfied with my reply and any other questions you may have.
Regards,
Adriano Ferreira
It looks to me like the code should work.
However, the view returns ALL the properties.
Am I supposed to add a filter on the view or should the function be enough?
Function reads
<?php
//functions for Divi for berrylandco.com JEL 09/10/14
add_shortcode('images', 'images_shortcode');
function images_shortcode() {
global $post;
$out = '';
$attachments = get_posts( array('post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image') );
foreach ($attachments as $attachment) {
$out .= wp_get_attachment_image($attachment->ID, 'thumbnail');
}
return $out;
}
function my_scripts() {
wp_enqueue_style( 'style-flexslider', get_stylesheet_directory_uri(). '/css/flexslider.css' );
wp_enqueue_script( 'script-flexslider', get_stylesheet_directory_uri() . '/js/jquery.flexslider.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'my_scripts' );
add_filter( 'wpv_filter_query', 'exclude_terms_func', 10, 3 );
function exclude_terms_func($query, $setting, $views_ID)
{
if($views_ID == 1818)
{
$query['meta_query'][] = array(
'key' => '_wpcf_belongs_agent_id',
'operator' => 'NOT EXISTS'
);
}
return $query;
}
Thank you.
Dear John,
I just take over this thread. I assume the Agents post type is using slug "agent"
Please try modify the PHP codes as below:
add_filter( 'wpv_filter_query', 'exclude_terms_func', 10, 3 );
function exclude_terms_func($query, $setting, $views_ID)
{
if($views_ID == 1818)
{
$query['meta_query'][] = array(
'key' => '_wpcf_belongs_agent_id',
'operator' => 'NOT EXISTS',
'value' => 'some value'
);
}
return $query;
}
Please replace agent with the slug of Agents post type
More help:
(Note: Due to bug #23268, value is required for NOT EXISTS comparisons to work correctly prior to 3.9. You must supply some string for the value parameter. An empty string or NULL will NOT work. However, any other string will do the trick and will NOT show up in your SQL when using NOT EXISTS.
http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters