Support » Fixing WordPress » How to create sorter

  • Resolved ievii

    (@ievii)


    Hi, i have problem, i don’t know how to change code:

    $blog_query = new WP_Query( array( ‘post_type’ => ‘post’, ‘paged’ => $paged ) );

    I need add sorter for posts to select the specific category of posts

    something like this:

    $blog_query = new WP_Query( array( ‘post_type’ => ‘post’, ‘cat_name’ => ‘kategorija-kategorija’, ‘paged’ => $paged ) );

Viewing 3 replies - 1 through 3 (of 3 total)
  • J M

    (@hiphopinenglish)

    I find it’s cleaner to start with an array of arguments. Like so:

    <?php
    $args = array(
    	'post_type' => 'post',
    	'category_name' => 'kategorija-kategorija', // This must be a SLUG, not a name
    	'paged' => $paged
    ); 
    
    $blog_query = new WP_Query( $args );
    ?>

    Your mistake was this: the key is category_name not cat_name. See the Codex for possible parameters.

    thanks 🙂

    works well

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to create sorter’ is closed to new replies.