0

我只想在属于已登录用户的 wordpress 页面上显示帖子并包含自定义元键“颜色”。我有每个选项的代码,即我可以显示属于已登录用户的帖子或带有元键 = 颜色的帖子,但我无法弄清楚如何将两者结合起来,因此这两个条件都必须为真。以下是我正在使用的两段代码:

<!-- If Logged In -->
<?php       
if ( is_user_logged_in() ):
global $current_user;
get_currentuserinfo();
$author_query = array('posts_per_page' => '-1','author' => $current_user->ID);
$author_posts = new WP_Query($author_query);
while($author_posts->have_posts() : $author_posts->the_post(); 
get_template_part( 'content', 'page', 'the_meta()' );
?>

<!-- If Posts Contains Color Meta -->
<?php
$the_query = new WP_Query('meta_key=color');
while ($the_query->have_posts() ) : $the_query->the_post();
endwhile;
?>

有谁知道如何组合它们以便显示符合这两个条件的帖子?

4

1 回答 1

0

像这样的东西应该工作:

<?php
    if ( is_user_logged_in() ) :   
        global $current_user;
        get_currentuserinfo();

       $query = array('posts_per_page' => '-1','author' => $current_user->ID, 'meta_key' => 'color');
       $result = new WP_Query($query);

       while ($result->have_posts()) : $result->the_post(); 
           get_template_part( 'content', 'page', 'the_meta()' );
       endwhile;
    endif;
?>
于 2012-06-21T04:04:23.990 回答