Custom loop not working

时间:2018-05-29 作者:Stef

因此,我创建了一个自定义循环,在该循环中,我的自定义帖子类型的帖子将出现,并且在其中,我向meta“layout\\u meta\\u box”声明了值“synosis”。自定义帖子类型正在工作,但元框值不工作。我做错了什么?

<?php
/*
Template Name: Archief Synopsis
Template Post Type: algemeen
*/
get_header();
$args = array(
    \'post_type\'=> \'televisie\',
    \'post_status\' => \'publish\',
    \'posts_per_page\' => 5,
    \'layout_meta_box\' => \'synopsis\',
);
$custom_query = new WP_Query( $args );

?> 
    <div class="container-fluid-limited">
        <div class="row">
            <div class="col-lg-9 col-article">
                <h1>Alle artikels over <?php post_type_archive_title(); ?></h1>
                <?php
                if ( $custom_query->have_posts() ) :
                    while ( $custom_query->have_posts() ) :
                        $custom_query->the_post();
                        get_template_part( \'template-parts/post/content\', \'excerpt\' );
                    endwhile;
                else :
                    get_template_part( \'template-parts/post/content\', \'none\');
                endif;
                wp_reset_postdata(); ?>
            </div>
            <div class="col-lg-3 sidebar">
                <?php get_sidebar(); ?>
            </div>
        </div>
    </div>
<?php get_footer(); ?>

1 个回复
最合适的回答,由SO网友:wharfdale 整理而成

尝试以下操作:

$args = array(
  \'post_type\'=> \'televisie\',
  \'post_status\' => \'publish\',
  \'posts_per_page\' => 5,
  \'meta_key\'     => \'layout_meta_box\',
  \'meta_value\'   => \'synopsis\',
);
这也是一篇有用的文章:https://css-tricks.com/snippets/wordpress/custom-loop-based-on-custom-fields/

结束