WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WP_Query + 'cat' = no results (2 posts)

  1. barat
    Member
    Posted 4 years ago #

    Hi!

    It's my 1st post because I prefeer to solve my problems alone, but this whole WP is realy p***ng me off :/
    For me WP is so limited (sorry), everything have to be made in wicked, long, "go arround" way ... but it's no time to complain.
    I have to use WP for something (custom theme) so I want to use WP_Query to get some posts before the main loop fire.

    Made something like this:

    <?php
    $sticky = get_option( 'sticky_posts' );
    $args=array(
       'post__in' => $sticky,
       'caller_get_posts'=>1,
       'orderby' => 'ID',
       'posts_per_page' => 3
    );
    $my_query = new WP_Query($args);
    while ($my_query->have_posts()) : $my_query->the_post();
    ?>
    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a><?php the_category_id(); ?></h2>
    <?php
    endwhile;
    ?>

    As You can see I take 3 newest sticky posts (caller_get_posts to prevent showing all sticky posts or other wierd things).
    I made the_category_id() to be sure in which category returned posts are (this whole header in loop is for testing now).
    Everything goes OK, loop is working, main loop is not affected and is going its own way.

    I have a problem when I try to add one more var to query:

    $args=array(
       'post__in' => $sticky,
       'cat' => 15,
       'caller_get_posts'=>1,
       'orderby' => 'ID',
       'posts_per_page' => 3
    );

    When I add 'cat' I get NO RESULTS. ZERO, none, nada ...
    "Funniest" (not for me - I hate if something is working against the logic) thing is that I used cat IDs of returned posts (the_category_id()) from this 1st loop (those are IDs of subcategories). I've tried top level cat id too - nothing.
    Even if I make:

    $args=array(
       'cat' => 6
    );
    //i'm sure that this cat (6) exists and there are 60 posts in it!

    No results!
    Is WP realy so ... ehh ... not worth those words ...

    I just want to have 3 custom queries - each to take 3 sticky posts from specified categories + normal main loop with posts__not_in $sticky to prevent duplicates (which works too without 'cat'). Each post is only in ONE subcategory (and not added to main cat because I want to have links like /cat/subcat/postname/ - if I add it to cat and subcat then the link will be made from lowest ID and that means - /cat/postname/)

    Wordpres is realy pain in the a*s if You prefeer frameworks, pure php etc. but it have to be WP this time :(

    PS. Using WP 2.9.2 - wasn't able to pick this version from the list when I was creating this post.

  2. barat
    Member
    Posted 4 years ago #

    OK - solved it ...
    The problem was because of Category Visibility-iPeat Rev plugin ...

    I think that I have to check all installed plugins (I've to redesign blog which have been about 5 months online, and plugins wasn't instaled by me)

    BTW - replaced this plugin by:
    http://ryowebsite.com/wp-plugins/category-visibility/

    seems to work OK

    PS. I'm still thinking that WP is limited, and lot of things have to be made in "go around" way ;)

Topic Closed

This topic has been closed to new replies.

About this Topic