Support » Themes and Templates » use of query_post in template, please help

  • Hi there, i’m not a developer and just stumbled into a php issue i cannot resolve.

    I have a template using the following php code to query posts on a specific category and show them in a table.

    <?php query_posts(array( "cat" => 80, "orderby" => "date", "order" => "DESC", "posts_per_page" => -1 )); ?>

    <?php $count_posts = $wp_query->post_count; ?>

    <?php while (have_posts()) : the_post(); ?>

    <!-- Getting Attachments -->
    $args = array(
    'post_type' => 'attachment',
    'numberposts' => null,
    'post_status' => null,
    'post_mime_type' => 'application/pdf',
    'post_parent' => get_the_ID()
    $attachments = get_posts($args);
    if ($attachments) {
    foreach ($attachments as $attachment) {
    $attachment_url = wp_get_attachment_url($attachment->ID);

    So far it shows the posts under a category number that appears on the array.

    I would like to modify this code in order to show the posts under any category that it’s being browsed, not a specific one.

    This way i will be able to use it in category.php so all posts under any categories will be showed that way.

    Is ther any body that can help me with this code? thanks in advance!


Viewing 3 replies - 1 through 3 (of 3 total)
  • From looking at the documentation try taking “cat” => 80 out altogether. Bear in mind that using query_posts is not recommended as it has some side effects. You might want to consider using WP_Query instead which looks like it will have less side effects and wil be more maintainable in the future. (see the section title Caveats)

    Thanks HOC, i solved it,

    I used:

    $cat_id = get_query_var(‘cat’);

    and then

    query_posts(array( “cat” => $cat_id,

    About query_post vs Wp_Query, I get an error, I also tried get_post, but i haven’t solved a post_per_page issue i have. -1 shows all posts without pagination, this result is desired, but if i use get_post i get default pagination despite the value i enter, i’m no a coder obviously, so it’s a challenge for me, but it seems easy, i’m trying to brake it, thanks for your help

    pleasure, glad you fixed it and thanks for posting how. It will help others with the same problem.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘use of query_post in template, please help’ is closed to new replies.