admin管理员组文章数量:1122846
I have a ACF select field which takes multiple value. Now I want to use get_posts()
to get those custom posts. My arguments look like this:
$party = 'test1';
$function = 'test1, test2';
$args = array(
'numberposts' => -1,
'post_type' => 'event',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'party',
'compare' => '=',
'value' => $party,
),
array(
'key' => 'function',
'compare' => 'IN',
'value' => array($function),
)
)
);
$items = get_posts($args);
But this does not work! Don't know what is wrong here!
I have a ACF select field which takes multiple value. Now I want to use get_posts()
to get those custom posts. My arguments look like this:
$party = 'test1';
$function = 'test1, test2';
$args = array(
'numberposts' => -1,
'post_type' => 'event',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'party',
'compare' => '=',
'value' => $party,
),
array(
'key' => 'function',
'compare' => 'IN',
'value' => array($function),
)
)
);
$items = get_posts($args);
But this does not work! Don't know what is wrong here!
Share Improve this question asked May 26, 2016 at 7:27 Imrul.HImrul.H 1752 silver badges14 bronze badges 2 |1 Answer
Reset to default 0This is not the way which you have clled for ACF.
Parameters
<?php $field = get_field($field_name, $post_id, $format_value); ?>
- $field_name: the name of the field to be retrieved. eg “page_content” (required)
- $post_id: Specific post ID where your value was entered. Defaults to current post ID (not required). This can also be options / taxonomies / users / etc
- $format_value: whether or not to format the value loaded from the db. Defaults to true (not required).
Usage
Get a value from the current post
$value = get_field( "text_field" );
Get a value from a specific post
$value = get_field( "text_field", 123 );
Check if value exists
$value = get_field( "text_field" );
if( $value ) {
echo $value;
} else {
echo 'empty';
}
Get a value from other places
$post_id = null; // current post
$post_id = 1;
$post_id = "option";
$post_id = "options"; // same as above
$post_id = "category_2"; // target a specific category
$post_id = "event_3"; // target a specific taxonomy (this tax is called "event")
$post_id = "user_1"; // target a specific user (user id = 1)
$value = get_field( "text_field", $post_id );
Get a value without formatting
In this example, the field image
is an image field which would normally return an Image object.
However, by passing false as a 3rd parameter to the get_field function, the value is never formatted and returned as is from the Database.
Please note the second parameter is set to false
to target the current post
$image = get_field('image', false, false);
本文标签: advanced custom fieldsGet posts with multiple meta values
版权声明:本文标题:advanced custom fields - Get posts with multiple meta values 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736289972a1928416.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$items = new WP_Query( $args );
WP_Query Reference. – emilushi Commented May 26, 2016 at 11:16