Forums Forums Search & Filter Pro Category Description

Viewing 10 posts - 1 through 10 (of 18 total)
  • Anonymous
    #121844

    I was wondering whether a category’s description can be shown in the search results above the results when you select the category?

    I’m using the shortcode option with ajax.

    Trevor
    #121871

    You would need to use some custom PHP code, which would have to be inside the results.php file you are using (see the customisation guide here). You should be able to find the appropriate code from either the WordPress Codex OR StackExchange.

    To find the Category ID, you would also need some custom PHP, but this post/thread might help (with a few changes):

    https://support.searchandfilter.com/forums/topic/how-to-show-the-currently-selected-title-only/page/2/#post-108703

    Anonymous
    #122324

    Okay I’ve worked out how to obtain the ID and get the description but the ID has an extra 1 at the end of the string which I’ve had to strip off.

    Can you see why it would have the extra one and how to avoid it?

    Thanks

    		<?php global $searchandfilter;
    			$sf_current_query = $searchandfilter->get(119)->current_query()->get_array();
    			$currentCat = $sf_current_query['_sft_project_category']['active_terms'][0]['id'];
    			$currentCatID = rtrim($currentCat,'1');
    			echo category_description( $currentCatID );
    		 ?>
    Trevor
    #122348

    Can you use this code to print out the query:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(119)->current_query()->get_array();
    echo '<pre>',print_r($sf_current_query),'</pre>';
    ?>
    Anonymous
    #122357

    I get the following (you can see a 1 at the end of the array):

    Array
    (
        [_sft_project_category] => Array
            (
                [name] => Product Categories
                [singular_name] => Product Category
                [all_items_label] => All Categories
                [type] => taxonomy
                [active_terms] => Array
                    (
                        [0] => Array
                            (
                                [id] => 6
                                [name] => Fruit
                                [value] => fruit
                                [count] => 7
                            )
    
                    )
    
            )
    
        [_sft_project_tag] => Array
            (
                [name] => Product Tags
                [singular_name] => Product Tag
                [all_items_label] => All Tags
                [type] => taxonomy
                [active_terms] => Array
                    (
                        [0] => Array
                            (
                                [id] => 8
                                [name] => 6+ Months
                                [value] => 6-months
                                [count] => 11
                            )
    
                    )
    
            )
    
    )
    1
    Trevor
    #122362

    Can you inspect the page html in the browser inspector and see if that 1 at the end is inside or outside of the </pre> tag?

    Anonymous
    #122367

    Yes, it’s inside the tag.

    Trevor
    #122373

    How very odd. I may have to talk separately to our developer about the errant 1.

    What does the array look like if no category is selected?

    Anonymous
    #122375
    Array
    (
    )
    1
    Trevor
    #122377

    OK, so you would have to check if the sub array exists, and then unset it if it does.

    I am not sure what logic you would have to run through to decide which one gets unset. How do you determine if tags or categories was just set?

Viewing 10 posts - 1 through 10 (of 18 total)