admin管理员组文章数量:1336148
I want to get all post with the value X looking in the meta_key field. After tha I want to loop trough all post and get the title.
I got this so far.
function get_events( ) {
$recurrence_ids = get_post_custom_values( '_recurrence_id' );
$recurrence_id = $recurrence_ids[0];
$query_args =
array('meta_query' => array(
array(
'key' => '_recurrence_id',
'value' => $recurrence_id
)
)
);
$query = new WP_Query( $query_args );
print_r( $query );}
add_shortcode( 'get_events', 'get_events' );
I got [post_count] => 0 back
As you see here my DB i search here for the ke<
I want to get all post with the value X looking in the meta_key field. After tha I want to loop trough all post and get the title.
I got this so far.
function get_events( ) {
$recurrence_ids = get_post_custom_values( '_recurrence_id' );
$recurrence_id = $recurrence_ids[0];
$query_args =
array('meta_query' => array(
array(
'key' => '_recurrence_id',
'value' => $recurrence_id
)
)
);
$query = new WP_Query( $query_args );
print_r( $query );}
add_shortcode( 'get_events', 'get_events' );
I got [post_count] => 0 back
As you see here my DB i search here for the ke<
Share Improve this question asked Jul 21, 2020 at 9:44 user1551496user1551496 113 bronze badges 2- Are you querying posts? Or a different post type? Unless you’re querying blog posts you need to specify the post type. – Jacob Peattie Commented Jul 21, 2020 at 10:08
- i use event post, i got it now, i works – user1551496 Commented Jul 21, 2020 at 11:20
1 Answer
Reset to default 0Now i got this code and i works.
function get_events( ) {
$recurrence_ids = get_post_custom_values( '_recurrence_id' );
$recurrence_id = $recurrence_ids[0];
$the_query_args = array(
'posts_per_page' => -1,
'post_type' => 'event',
'meta_key' => '_recurrence_id',
'meta_value' => $recurrence_id
);
$the_query = new WP_Query( $the_query_args );
if ( $the_query->have_posts() ) {
$output = '<div class="weitere-termine">';
while ( $the_query->have_posts() ) {
$the_query->the_post();
setlocale (LC_TIME, "de_DE.utf8");
$date = get_post_custom_values( '_event_start_date' );
if($date){
$date = strftime("%a. %d.%m.%Y", strtotime($date[0])) ;
}
$output .= '<a href="' . get_the_permalink() . '">';
$output .= '<span>' . $date . '</span>';
$output .= '</a>';
}
$output .= '</div>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
return $output;
}
add_shortcode( 'get_events', 'get_events' );
本文标签: Query custom post type custom meta key
版权声明:本文标题:Query custom post type custom meta key 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742244905a2439067.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论