Viewing 9 replies - 1 through 9 (of 9 total)
  • When you use these parameters, you need to pass the category or tag slug, not the actual category or tag name. You can verify the slugs by going to Dashboard > Posts > Categories or Dashboard > Posts > Tags.

    Thread Starter Ravikumar Patel

    (@ravipatel)

    @stephencottontail : We have check category slug and have use “,”
    post is getting but when use “+” not working this one supported in wordpress latest version.

    $query = new WP_Query( 'category_name=facebook,uncategorized' ); (work)

    $query = new WP_Query( 'category_name=facebook+uncategorized' );(Not work)

    Hmm, the + sign works for tags but not categories. Instead, you should use this syntax if you want to test for multiple categories:

    $query = new WP_Query( array( 'category_in' => array( 1, 2 ) ) );

    You’ll need to know the IDs of the desired categories.

    Thread Starter Ravikumar Patel

    (@ravipatel)

    @stephencottontail : Thanks, I know all of techniques for code.

    Today Just i learn to junior developer with this code using “+” sign so not getting posts.

    So i post question because Review & test code by moderator and also change on site.

    New Defect ticket url

    Show Posts From Several Categories (Display posts that have these categories, using category id) would be

    $query = new WP_Query( ‘cat=10,11’ );
    but i never try with + sign if you get the solution then post here!!

    Moderator Marius L. J.

    (@clorith)

    Hi,

    The Trac ticket has been updated, but for convenience:

    This is because you are submitting a string which is parsed like an URL, you’ll need to either URLEncode the + sign (use %2B instead) or submit the query arguments as an array, WP_Query( array( 'category_name' => 'facebok+uncategorized' ) );, to stop this.

    This is sort of expected behavior, as it is a native PHP function called parse_str being ran if you submit the arguments as a string.

    Thread Starter Ravikumar Patel

    (@ravipatel)

    @marius I have tested code with this as per u have define code not working.

    $query = new WP_Query( 'category_name=facebook%2Buncategorized' );
    (working)

    $query = new WP_Query( array( 'category_name' => 'facebok+uncategorized' ) );

    (Not working)

    Moderator Marius L. J.

    (@clorith)

    @ravipatel That’s because you copied and pasted it with my facebook typo ??

    Thread Starter Ravikumar Patel

    (@ravipatel)

    @marius Thanks, Now working.

    $query = new WP_Query( array( 'category_name' => 'facebook+uncategorized' ) );

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Wp_Query on tag based not getting post when use sign’ is closed to new replies.