If have_post not available then ng-bind

54 views Asked by At

Hope you all be safe in this time of crisis. I'm looking for a solution to program my theme.. I do sometimes have content in my wordpress however i also does via a json. I wrote something but its throwing basic WP errors.

I need something like this but code correctly:

<div class="col-md-12">
            <h3 class="h3">About {{ctrl.Coin.name}}</h3>

            <?php
              if ( have_posts()  && get_the_content() != '') {
                  while ( have_posts() ) :
                    the_post();

                    get_template_part( 'template-parts/coindetail-content', get_post_type() );

                  endwhile; // End of the loop.
                } else {
                  echo '<p ng-bind-html="ctrl.Coin.descriptionhtml"></p>';
                }
                ?>
          </div>

Who can help me with this?

Regards Dutch

1

There are 1 answers

7
Shivendra Singh On

Wrong function. You have to call have_posts() instead of have_post().

like:

$args = array(
'post_type' => 'coins', //post type name
'posts_per_page' => -1
);


$loop = new WP_Query($args);
if($loop->have_posts() && $loop->post_content != '') {
    while($loop->have_posts()) : $loop->the_post();
    get_template_part( 'template-parts/coindetail-content', 'coins');
    endwhile; // End of the loop.
} else {
    echo '<p ng-bind-html="ctrl.Coin.descriptionhtml"></p>';
}

?>