WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wp_query not working in 2.0? (13 posts)

  1. Tijmen
    Member
    Posted 8 years ago #

    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; ?>

  2. Kafkaesqui

    Posted 8 years ago #

    $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?

  3. Tijmen
    Member
    Posted 8 years ago #

    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.

  4. Tijmen
    Member
    Posted 8 years ago #

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

  5. Kafkaesqui

    Posted 8 years ago #

    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.

  6. Tijmen
    Member
    Posted 8 years ago #

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

  7. Kafkaesqui

    Posted 8 years ago #

    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...

  8. Kafkaesqui

    Posted 8 years ago #

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

  9. Ryan Boren
    WordPress Dev
    Posted 8 years ago #

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

  10. Kafkaesqui

    Posted 8 years ago #

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

  11. Why not just use $wpdb?

  12. Kafkaesqui

    Posted 8 years ago #

    ?

    How so, Viper?

  13. henkblanken
    Member
    Posted 8 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags