Support » Plugins » Query Category Parent

  • Resolved blackbookdesign

    (@blackbookdesign)


    Hi,

    I am trying to query the parent category of teh post displayed.
    I was able to print out that perticular category with the aid from: ERICULOUS.

    <?php
    $parentscategory ="";
    $returnto ="[:en]Return to [:fr]Retourner &agrave;";
    foreach((get_the_category()) as $category) {
    if ($category->category_parent == 0) {
    $parentscategory .= _e(' <a href="' . get_category_link($category->cat_ID) . '" title="' . $category->name . '">' . $returnto . ' ' . $category->name . '</a> ');
    }
    }
    echo substr($parentscategory,0,-2)
    ;
    ?>

    But I can’t seem to modify the code to adapt it to a query.

    I know it’s probably a simple change in the code to call:

    <?php
     $categoryvariable=$cat; // assign the variable as current category
     $query= 'cat=' . $categoryvariable. '&orderby=date&order=ASC'; // concatenate the query
     query_posts($query); // run the query
     ?>

    But when I try my page doesn’t get printed at all or I have errors. If somebody could help me out I would definitely appreciate.

Viewing 1 replies (of 1 total)
  • Thread Starter blackbookdesign

    (@blackbookdesign)

    Ok so I was hacking like a noob. I didn’t manage to call anothe query.

    <?php
    $parentscategory ="";
    foreach((get_the_category()) as $category) {
    if ($category->category_parent == 0) {
    $query=('cat= ' . $category->cat_ID. ''); // concatenate the query
    }
    }
    $my_query = new WP_Query($query);
    ;
    ?>

    and then call

    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

    So in the end my error was pushing 2 exact same queries at the same time and jamming the system. well thats what I think it is… 🙂

    Hopefully this can help some people in the long run.

    Cheers

Viewing 1 replies (of 1 total)
  • The topic ‘Query Category Parent’ is closed to new replies.