• Resolved DesignsAndCode

    (@designsandcode)


    Hi there please help!

    I’ve searched the internet for so long now but can’t find this info.

    When on a category page ie

    www.yoursite.com/category/uncategorized it is fairly straightforward to get the category id of the current category – I can use something like

    get_query_var( 'cat' ) or some other alternative.

    BUT

    How do I get all the categories (ids, slugs anything!) when using multiple categories on the category page from a URL like:

    https://www.yoursite.com/?category_name=category1+category2+category3

    The category page only lists the first category name, which is not good, but the filtering is however correct!

    I do not want to use $_GET or $_REQUEST, these are both surely the wrong way to do it.

    Thanks for any help in advance, I am completely stuck!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter DesignsAndCode

    (@designsandcode)

    After searching some more I found the answer. To get the query var as it is in the URL use $wp_query, even if the url is rewritten like

    www.yoursite.com/category/category1+category2+category3/
    You can still retrieve the category names using:

    global $wp_query;
    $wp_query->query['category_name']

    For some reason this is different to get_query_var( 'category_name' ) which only shows the first category out of multiple categories.

    ??

    Thread Starter DesignsAndCode

    (@designsandcode)

    Closing topic

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to get all categories on a category page (when using multiple categories)??’ is closed to new replies.