So I've created a custom loop where posts of my custom post type will appear and posts where I've declared the value 'synopsis' to the meta 'layout_meta_box'. The custom post type is working, but the meta box value is not working. What did I do wrong?

Template Name: Archief Synopsis
Template Post Type: algemeen
$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>
                if ( $custom_query->have_posts() ) :
                    while ( $custom_query->have_posts() ) :
                        get_template_part( 'template-parts/post/content', 'excerpt' );
                else :
                    get_template_part( 'template-parts/post/content', 'none');
                wp_reset_postdata(); ?>
            <div class="col-lg-3 sidebar">
                <?php get_sidebar(); ?>
<?php get_footer(); ?>
  • layout_meta_box is not a part of WP_Query. – Wilco May 29 '18 at 15:07
  • That's my custom meta value, I thought I could do that... – Stef May 29 '18 at 15:08

Try this:

$args = array(
  'post_type'=> 'televisie',
  'post_status' => 'publish',
  'posts_per_page' => 5,
  'meta_key'     => 'layout_meta_box',
  'meta_value'   => 'synopsis',

A helpful article too: https://css-tricks.com/snippets/wordpress/custom-loop-based-on-custom-fields/

  • Just updated again. Try with 'meta_key' or just 'meta'. Can't remember right now which is needed. – wharfdale May 29 '18 at 15:11
  • 1
    Thank you so much! You're my hero! For the record: both meta and meta_key are working. – Stef May 29 '18 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.