• Resolved tijmen

    (@tijmen)


    I’ve built my index page with four seperate loops, with posts from each category showing up somewhere else. I’ve used the wp_query thing. I just upgraded to 2.0, and this doesn’t seem to work anymore. Everything else works fine. What have I done wrong?


    <?php
    $query_background = $category_name=.$background_title.&showposts=5";
    $my_query = new WP_Query($query_background);
    while ($my_query->have_posts()) : $my_query->the_post();
    if( $post->ID == $voorpaginapost) continue;
    ?>

    <h2><a href="<?php the_permalink() ?>" title="<?php echo($permalink_title)?><?php the_title(); ?>">
    <?php the_title(); ?>
    </a></h2>

    <?php the_content($readmore); ?>

    <div class="aboutline"><?php the_time('l j F Y') ?> | <?php the_time('G:i')?>

    </div>
    <?php endwhile; ?>

Viewing 12 replies - 1 through 12 (of 12 total)
  • $query_background = $category_name=.$background_title.&showposts=5";

    This line is not valid PHP. Is this the code exactly as it is in your template?

    Thread Starter tijmen

    (@tijmen)

    Err, it isn’t.

    Hope this shows the good one:

    <?php
    $query_background = 'category_name=Background&showposts=5';
    $my_query = new WP_Query($query_background);
    while ($my_query->have_posts()) : $my_query->the_post();
    ?>

    <h2><a href="<?php the_permalink() ?>" title="<?php echo($permalink_title)?><?php the_title(); ?>">
    <?php the_title(); ?>
    </a></h2>

    <?php the_content($readmore); ?>

    <?php the_time('l j F Y') ?> | <?php the_time('G:i')?>

    <?php endwhile; ?>

    Where ‘Background’ is the name of the category that I want to show.

    Thread Starter tijmen

    (@tijmen)

    Maybe something has changed in the loop structure in 2.0? I still can’t figure it out.

    I suspect it relates to category_name. Try using the category ‘slug’ or nicename:

    $query_background = 'category_name=background&showposts=5';

    If *that* fails (let me know if it does, as I’m trying to track down a similar problem), pass the category ID # for “Background” instead:

    $query_background = 'cat=1&showposts=5';

    Just change 1 to the correct category ID.

    Thread Starter tijmen

    (@tijmen)

    The cat=1 thing worked. Thanks a lot! I’m still curious why this has changed in 2.0, anyone a guess?

    It’s apparently a bug.

    category_name *should* work. However, I’m finding in my testing that in the case of one category on my site, and only the one, it doesn’t. Guess I’ll file a bug report…

    Hmm, I think I figured it out (the bug that is). Any chance Background is assigned to a parent category?

    If a category has a parent, try specifying the full hierarchy for the category. “parent-cat/sub-cat”

    That worked, ryan. Interesting, and thanks. I’ll also note this in the bug ticket.

    Why not just use $wpdb?

    ?

    How so, Viper?

    I had the same problem. I tried just the full path and that works, even without the slug.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘wp_query not working in 2.0?’ is closed to new replies.