Elle Em
asked 9 years ago

Hi everyone!

Thank you for this fantastic plugin – with it, I aspire to change the world 🙂
In order to do that, however, I require one last thing and that’s the ability to search by tags.

I am not a tech master in any sense of the word, but can figure little things out – this situation, however, has stumped me for a few days.

I have a list of tags that I would like to use and have questioners, not only be able to use the tags, but to search by them. The tags are specific geographic areas and, instead of categories because there are so many, I want to simplify it with tags.

Would someone be able to help me and, if possible, give me a CSS or simple step-by-steps to make this happen?

Also, is there a way to modify the wording, i.e. instead of "Question" change it to "Thought", etc.?

Thank you so much and I hope to hear back!

1 Answers
DominicStaff
answered 9 years ago

Hi,
To resolve this issue, you can make a tags box as categories dropdown list on a question listing page, please add the following code to the functions.php file.

/*-----------------------------------------------------------------------------------*/
/*  Question Actions
/*-----------------------------------------------------------------------------------*/
add_filter('dwqa_filter_bar','custom_dwqa_question_filter');
function custom_dwqa_question_filter( $tag_field ) { 
  ob_start();
  ?>
  <div class="filter-by-tags select">
    <?php 
        $selected = get_query_var( 'dwqa-question_tag');
        if( ! $selected ) {
          $question_tag_rewrite = get_option( 'dwqa-question-tag-rewrite', 'question-tag' );
          $question_tag_rewrite = $question_tag_rewrite ? $question_tag_rewrite : 'question-tag';
          $selected =  isset($_GET[$question_tag_rewrite]) ? $_GET[$question_tag_rewrite] : 'all'; 
        }
        $selected_label = __('Select a Tag','dwqa');
        if( $selected != 'all' ) {
            $field = is_numeric($selected) ? 'id' : 'slug' ;
            $selected_term = get_term_by( $field, $selected, 'dwqa-question_tag' );
            $selected_label = $selected_term->name;
        }
    ?>
    <span class="current-select"><?php echo $selected_label; ?></span>
    <ul id="dwqa-filter-by-tags" class="category-list" data-selected="<?php echo $selected_term->term_id; ?>">
    <?php  
        //$exclude_FAQ = get_term_by( 'name', 'FAQ', 'dwqa-question_tag' );
        $exclude_id = '';
        // if( $exclude_FAQ ) {
        //     $exclude_id = $exclude_FAQ->term_id;
        // }

        wp_list_categories( array(
            'show_option_all'   =>  __('All','dwqa'),
            'show_option_none'  => __('Empty','dwqa'),
            'orderby'           => 'count',
            'order'             => 'DESC',
            'taxonomy'          => 'dwqa-question_tag',
            'hide_empty'        => 0,
            'show_count'        => 0,
            'title_li'          => '',
            'hierarchical'      => 0,
            'exclude'           => $exclude_id,
            'walker'            => new Walker_Category_DWQA()
        ) );
    ?>  
    </ul>
  </div>
  <?php 
  $tag_field = ob_get_contents();
  ob_end_clean();
  return $tag_field;
}

Then add the following code to the style.css file:

.dwqa-container .dwqa-list-question .sort-by .filter-by-tags.select {
   left: 210px;
   right: auto;
}

Hope this helps !

marksunming
replied 8 years ago

Hi, when I use your code the search by tag dropdown list does come up. However, it is aligned to the right although I copy the code into the style.css file. Do you have any idea how I can change the dropdown list position? Thank you very much.

dominic Staff
replied 8 years ago

Please create a private answer then send me your username & password of your site. Also, you can tell me detail about the position that you want to display the Tag section, I will check and help you resolve it.

jayakumar
replied 8 years ago

Hi @Dominic,

I have implemented the tags on a question listing page in a dropdown list as per your suggestions, but the filtering is not working.
Please see – http://forum.cartin24.com/

Could you please help me to resolve the issue

nobita
replied 8 years ago

@Jayakumar VK : hi , to resolve this problem , need to change the code :

'walker'            => new Walker_Category_DWQA()

to

'walker'          => new DWQA_Walker_Category,
Powered by DW Question & Answer Pro