Support

Account

Home Forums General Issues Add a condition for post objects

Helping

Add a condition for post objects

  • Is there a way I can make a condition for post objects. I’m selecting two different types of custom post to be displayed. Let say if $post == custom_post_type_one display this code/markup else display this code/markup.

    Not sure how I can make that work.

    <?php

    $projects = get_field( ‘display_featured_projects’ );

    if ( $projects ) :

    foreach ( $projects as $post ) :
    setup_postdata( $post );
    ?>

    <?php endforeach ?>

    <?php wp_reset_postdata(); ?>

    <?php endif; ?>

  • 
      $projects = get_field( 'display_featured_projects');
      if ($projects) {
        foreach ($projects as $post) {
          setup_postdata($post);
          $post_type = get_post_type($post);
            if ($post_type == 'custom_post_type_one') {
              // do this
            } else {
              // do that
            }
        } // end foreach
        wp_reset_postdata();
      } end if projects
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.