Dear Sir/Madam,
I have a custom post type ' coupon' containing repeatable field, there are 4 posts to the repeatable field group, I want to have a shortcode to query only the status is either used or noshow . Below is my script but it can't filter the post, I show all.
<?php
define( 'WP_USE_THEMES', false );
require_once '../wp-load.php' ;
$post_id = 4758;
$args = array(
'key' => 'wpcf-book-status',
'value' => array('used', 'noshow'),
'compare' => 'IN',
);
$rfg_ids = toolset_get_related_posts( $post_id, 'booking-group', 'parent', 100, 0, $args, 'post_id', 'child');
print_r($rfg_ids);
printf("Total found: %s<br/>", count($rfg_ids));
if ( $rfg_ids ){
foreach ( $rfg_ids as $rfg_id) {
$book_time = get_post_meta( $rfg_id, 'wpcf-book-timestamp', true);
$status = get_post_meta( $rfg_id, 'wpcf-book-status', true);
printf("%s - %s<br/>",date('Y-m-d H:i:s', $book_time), $status);
}
}
I tried below code but not work
$args = array(
'meta_query' => array(
array(
'key' => 'wpcf-book-status',
'value' => array('used', 'noshow'),
'compare' => 'IN'
),
)
);
Below code not work if compare is IN, it return 0 result
$args = array(
'meta_key' => 'wpcf-book-status',
'meta_value' => array('used', 'noshow'),
'meta_compare' => 'IN'
);
Only compare is = can work
$args = array(
'meta_key' => 'wpcf-book-status',
'meta_value' => 'used',
'meta_compare' => '='
);
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
As you can see with our official Doc for "toolset_get_related_posts":
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
4. array args: Additional query arguments to narrow down the search. Accepted arguments:
meta_key, meta_value and meta_compare: Works exactly like in WP_Query. Only limited values are supported for meta_compare ('=' | 'LIKE').
The only possible comparisons are ('=' | 'LIKE').
So what if you try to build the argument like:
$args = array(
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'wpcf-book-status',
'value' => 'used',
'compare' => '='
),array(
'key' => 'wpcf-book-status',
'value' => 'noshow',
'compare' => '='
),
)
);
Does that helps?