Skip Navigation

[Closed] How to Filter Query based on custom property

This support ticket is created 4 years, 1 month ago. 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.

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

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Shane 4 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#1839579

I had your help with filtering based on a taxonomy but want to change it to filter out so it only shows those that have a custom property (named visibility created using toolset) set to public.

Here's what I got before, how should the new look (This is in a function using custom code called from the wpv_filter_query;

if($views_ID == 1111) {
$query['tax_query'][] = array(
'taxonomy' => 'post_tag', // taxonomy name
'field' => 'slug',
'terms' => 'ourslughere', // term slug for exclude
'operator' => 'NOT IN'
);
$query['tax_query']['relation'] = 'AND';
}

I'd assume something like

if($views_ID == 1111) {
$query[] = array(
'meta_key' => 'visibility',
'meta_value' => 'public'
);
}

But must be missing something.

Thanks

#1840505

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Don,

Thank you for getting in touch.

Given that you are using a custom query for the meta and seeing that visibility is a types custom field then the meta key should be "wpcf-visibility".

Please try with this meta key and let me know if it helps.
Thanks,
Shane

#1840619

Thanks Changed out from using the custom code. But related to visibility, is there a way to make an entire content template not show based on a custom field value (basically if set to private then I want it only to show the content if it's the original author of the post). I know I can add a conditional block and move everything inside it but is there a better way?

Also, I added the visibility (changed to slab-visibility) on the edit and upload pages and it saves right but when you edit it always goes back to the default value. Any idea why?

#1841495

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Don,

I know I can add a conditional block and move everything inside it but is there a better way?

This is the way I am thinking of doing it, just add a conditional and add the information you don't want to appear inside it.

Also, I added the visibility (changed to slab-visibility) on the edit and upload pages and it saves right but when you edit it always goes back to the default value. Any idea why?

Not clear what you mean by this, is it that you changed the slug ? Let me know exactly the steps you did to make the change to slab-visibility.

Thanks,
Shane

The topic ‘[Closed] How to Filter Query based on custom property’ is closed to new replies.