• Hi guys,

    I’m using this function in a custom page to make the loop of the posts in a wordpress page with a little navigation menu.

    <?php
    	$temp = $wp_query; $wp_query= null;
    	$wp_query = new WP_Query(array('cat' => mangas)); $wp_query->query('showposts=2' . '&paged='.$paged);
    	while ($wp_query->have_posts()) : $wp_query->the_post();
    ?>

    In the theory, the posts must be filtered by the Slug of the category, in this case “mangas”.

    But not, the loop it is showing all the posts from my database.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Doesn’t mangas need to be in quotes as well?
    $wp_query = new WP_Query(array(‘cat’ => “mangas”));

    Thread Starter Tallyson

    (@tallyson)

    Doesn’t mangas need to be in quotes as well?
    $wp_query = new WP_Query(array(‘cat’ => “mangas”));

    Doesn’t worked

    If the code below doesn’t work, you’re doing something else wrong in that file:

    <?php
    
    /**
     * @link https://codex.www.ads-software.com/Class_Reference/WP_Query
     */
    $prefix_query = new WP_Query(array(
        // Use category slug, NOT name.
        'category_name' => 'mangas',
        'posts_per_page' => 2,
        // If get_query_var('paged') doesn’t work, try get_query_var('page').
        'paged' => max(1, get_query_var('paged')),
    ));
    
    if ($prefix_query->have_posts())
    {
        while ($prefix_query->have_posts())
        {
            $prefix_query->the_post();
    
            echo get_the_title().'<br />';
        }
    }
    else
    {
        echo 'No posts found.';
    }
    
    wp_reset_postdata();
    
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problens with wp_Query category Filter’ is closed to new replies.