Viewing 4 replies - 1 through 4 (of 4 total)
  • You’d need to grab the categories, turn them in to an array, and then output the title for each using the get_terms(); function.

    $cats = explode(',', $_REQUEST['cat']);
    $args = array(
        'include' => $cats,
        'field' => 'name'
    );
    $term_names = get_terms('category', $args)
    
    if(!empty($term_names)) : foreach($term_names as $term_name) :
    
            echo $term_name;
    
        endforeach;
    endif;

    Code is untested, so may contain a typo or two.

    Thread Starter Kreittis

    (@kreittis)

    I’m very bad at PHP and hacking WordPress so please bear with me.

    I assume that the code you provided goes after The Loop and then I just replace single_cat_title(); with get_terms( $term_name );, am I correct?

    Thread Starter Kreittis

    (@kreittis)

    I hate to ask again but I really need help.

    Is the above code provided by duck__boy meant to be replacement for single_cat_title();? I tried to replace it with that but it didn’t do anything, multi category query still shows just one title.

    Thread Starter Kreittis

    (@kreittis)

    I still haven’t resolved this problem so let’s try this again.

    Here is my full category.php code: https://pastebin.com/LDwrDaxh

    Now then, if I replace single_cat_title() with

    $cats = explode(',', $_REQUEST['cat']);
    $args = array(
        'include' => $cats,
        'field' => 'name'
    );
    $term_names = get_terms('category', $args);
    
    if(!empty($term_names)) : foreach($term_names as $term_name) :
    
            echo $term_name;
    
       endforeach;
    endif;

    The content section goes blank. How would I resolve this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Displaying names of categories after multiple category query’ is closed to new replies.