Support » Fixing WordPress » Show first in loop the posts from a specific taxonomy

  • Hi!!
    I would like to display in my loop all posts, but the first only posts from a taxonomy ‘featured’ term ‘top’, the others dont have any taxonomy ‘featured’ checked.

    And the important to make pagination works.

    I try multiple loops, but dont work with pagination…I try to merge the 2 queries but i failed..

    Can anyone help me 😀 ?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Why not just use sticky posts?

    I need to have control with what is showing! If i have 2 taxonomy terms, and all posts from one must show first than other , and the 2 taxonomy must be showing first than others posts.

    And all must be working with the pagination…

    If you are using wp_query, you should be able to use the orderby parameter to order your posts by a meta value. Meaning that you would set up a custom field, and use it to order your posts. If you passed the field a number, you could mark featured posts with a “1”, and just leave everything else as “0” (or have multiple numbers to set up a hierarchy for your posts). Either way, this will do what you are trying to accomplish.

    An example of this used in the knowledge base is as follows:
    $query = new WP_Query( array ( 'post_type' => 'product', 'orderby' => 'meta_value', 'meta_key' => 'price' ) );

    http://codex.wordpress.org/Class_Reference/WP_Query
    (search for “Meta_value” to find the parameter i’m talking about)

    This is the same thing to change the order of a post type, i put the firsts with 0 and others 1.

    But i need to have all the posts in a rand mode.
    The premiums will display first and random , and after the others posts in random.

    :/

    Oh, you can specify more than one value for every parameter you pass to the query. For instance, you can tell the ‘orderby’ property to be both linked to a meta_value AND random. You’d accomplish this by adding ‘meta_value rand’ in place of the ‘meta_value’ code in the example above. Check out the following code, it should get what you want (according to the codex, I haven’t tested it).

    $query = new WP_Query( array ( 'post_type' => 'product', 'orderby' => 'meta_value rand', 'meta_key' => 'price' ) );

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Show first in loop the posts from a specific taxonomy’ is closed to new replies.