0

Hi newbie question just create Rest endpoint for query-specific post type is work fine but did not get data from wp_postmeta how to query related data or using other WP_ ?

try meta_query but how to add post_id for query relation

$all_pms =  new WP_Query( [
 'post_type' => 
     'pms-subscription',
     'post_status'=>'active', 
     'meta_query'=>[
          'pms_subscription_plan_price' => 126 <-- assume it relation but not work
     ]
  ] 
  );

thank

0

1 Answer 1

0

Try:

 $all_pms =  new WP_Query( [
 'post_type' => 'pms-subscription',
 'post_status'=>'active', 
 'meta_query'=>[
      'meta_key'=>'pms_subscription_plan_price',
      'meta_value'=> '126', // string
      'meta_compare' => '=', // or  > or  < or !=
 ]
] 
);

https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters

Although ..re-reading your question I'm not sure what you're exactly looking for..

With this query you're searching posts of type pms-subscription having post_status =active and custom field with meta_key pms_subscription_plan_price and meta_value equals '126'

1
  • Yup can we make meta value dynamic like get post_id from main query Jan 14, 2020 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.