Skip Navigation

[Fermé] Filter for properties where not parent has been assigned

This support ticket is created Il y a 8 années et 9 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 5 réponses, has 3 voix.

Last updated by Luo Yang Il y a 8 années et 9 mois.

Assisted by: Luo Yang.

Auteur
Publications
#286203

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.

#286508

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.

#286559

Can you suggested a filter via a hook that would work?

#287368

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

#288013

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.

#288827

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

Le sujet ‘[Fermé] Filter for properties where not parent has been assigned’ est fermé à de nouvelles réponses.