SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question WP Custom Post Type Conditional in loop

    I need multiple loops on a page and have created them as such

    `global $post;
    $args = array( 'numberposts' => 3, 'category' => 10 );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) : setup_postdata($post); ?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?> "><?php the_title();?></a></li>
    <?php endforeach; ?>`

    I have a custom post type (foo_post_type) which should be used as a conditional while the loop runs. For example, for each post in this loop:

    `if ('foo_post_type' == 'xyz' || 'foo_post_type' == '0' && 'category' => 10) {
    ...then display in the loop.....
    }`

    But I am able to grab the custom post type for each post in the loop before the loop runs. And if I grab the custom post type during the loop it returns the same (usually incorrect) value. Where can I stick this foo_post_type in the loop shown at the top so it displays and evaluates each post bringing back the latest 3 which adhere to each condition?

    (Unfortunately, I do not have a public link to the site.)

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Location
    Glasgow, Scotland
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $post->post_type should give you the post type of the current post if you use it inside your foreach.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •