Skip Navigation

[Resolved] Unable to Query Posts Using Custom Fields

This support ticket is created 3 years, 10 months 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.

This topic contains 1 reply, has 1 voice.

Last updated by himanshuS 3 years, 10 months ago.

Author
Posts
#1901415

I have a custom filed named endorsee-email that I want to use to filter post that have current_user's email. The value in custom field is populated on post submit so I know there is data.

I am using the following code but it does not work. What am I missing regarding meta_query with toolset fields.

<?php global $wpdb;
global $post;
$current_user = wp_get_current_user();
$c_u_email = $current_user->user_email;
$args = array(
'post_type' => 'endorsement',
'post_status' => 'publish',
'meta_query' = array(
'relation' => 'AND',
array(
'key' => 'wpcf-endorsee-email',
'value' => $c_u_email,
'type' => 'EMAIL',
'compare' => '='
)
)
);
$endorsements = get_posts($args);
print_r($endorsements);
?>

Reference post: https://toolset.com/glossary/wp_query/

#1901447

My issue is resolved now. Thank you!