L
L
LastGeneral2021-07-27 15:37:18
WordPress
LastGeneral, 2021-07-27 15:37:18

How to display posts of a custom post type?

Created a costume type for Recipes ( recipes ), but it gives an error when outputting

<?php
    $args = array( 'post_type' => 'movies', 'posts_per_page' => 10 );
    $the_query = new WP_Query( $args );
?>

<?php if ( $the_query->have_posts() ) : ?>
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <h2><?php the_title(); ?></h2>
            <div class="entry-content">
                <?php the_content(); ?>
            </div>
        <?php wp_reset_postdata(); ?>
        
    <?php else: ?>

    <p><?php _e( 'Записи не найдены.' ); ?></p>

<?php endif; ?>

Parse error: syntax error, unexpected 'else' (T_ELSE) in /home/zhevzhik/carpathians.rest/super-grill/wp-content/themes/online-store-grills/archive-recipes.php on line 24

What is the reason for the error?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bingumd, 2021-07-27
@LastGeneral

...

<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
 
....

I
IvanMogilev, 2021-07-27
@IvanMogilev

I won't ask why you have the type recipes , and at the same time 'post_type' => 'movies', but you missed endwhile;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question