Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi Adria,
    Any chance you could show how exactly you made these two queries?
    I have exactly the same problem as yourself.
    Thanks
    James

    Thread Starter jamesmoriarty

    (@jamesmoriarty)

    Tried that, but still not working!

    I also changed ‘loop’ to ‘my_query’ as follows:

    <?php $c=0; $my_query = new WP_Query
    ( array( 'post_type' => 'sport','posts_per_page' => 10 ) );
    while ( $my_query->have_posts() ) : $my_query->the_post();
    if( in_category('15', $post->ID) ) $c++;
    if( in_category('15', $post->ID) && $c < 5 ) skip;?>
    <?php endwhile; ?>
    Thread Starter jamesmoriarty

    (@jamesmoriarty)

    This is in addition to the standard loop, which is further down the page.

    This is what I have in full:

    <?php $c=0;
    $loop = new WP_Query
    ( array( 'post_type' => 'sport','posts_per_page' => 10 ) );
    while ( $loop->have_posts() ) : $loop->the_post();?>
    if( in_category('15') ) $c++;
    if(  in_category('15') && $c < 5 ) skip;?>
    <li<?php if ( $post->ID == $wp_query->post->ID ) { echo ' class="on"'; } else {} ?>>
    <a href="<?php the_permalink()?>">
    <div class="green">
    <?php echo get_post_meta($post->ID, 'sport_other', true);?>:</div>
    </a></li>
    <?php endwhile; ?>

    This is the main loop further down the page:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php endwhile; endif; ?>

    I also have another wp_query before the wp_query above which is as follows:

    <?php $loop = new WP_Query
    ( array( 'post_type' => 'sport', 'cat' => '15', 'posts_per_page' => 4 ) );
    while ( $loop->have_posts() ) : $loop->the_post();?>

    The above are the 4 posts I am trying to exclude from the second loop!

    Thanks Esmi for your help.

    Thread Starter jamesmoriarty

    (@jamesmoriarty)

    Thanks, but it doesn’t work for some reason. It is including all posts from category 15, and isn’t excluding any.

    This is what I have:

    <?php $c=0;
    $loop = new WP_Query
    ( array( 'post_type' => 'sport','posts_per_page' => 10 ) );
    while ( $loop->have_posts() ) : $loop->the_post();
    if( in_category('15') ) $c++;
    if(  in_category('15') && $c < 5 ) skip;?>
    <?php endwhile; ?>

    Any ideas what may be missing?
    Thanks.

    Thread Starter jamesmoriarty

    (@jamesmoriarty)

    Hi esmi,
    Thanks very much for your reply, but I should have included all the code that I am using. This query is outside the loop, as the main loop is in action elsewhere on the page.

    If I use the code you suggest, it upsets the conditional statement below, which basically applies the style ‘on’ to the post if it appears elsewhere on the page.

    <?php
    $loop = new WP_Query
    ( array( 'post_type' => 'sport', 'cat' => '-15', 'posts_per_page' => 10 ) );
    while ( $loop->have_posts() ) : $loop->the_post();?>
    <li<?php if
    ( $post->ID == $wp_query->post->ID )
    { echo ' class="on"'; } else {} ?>></li>
    <?php endwhile; ?>

    Any ideas as to how to make your suggested code work with this?

    Thanks a million,
    James

Viewing 5 replies - 1 through 5 (of 5 total)