Divi WordPress Theme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix How to add search filter by tag values ?

Discussion in 'Misc WordPress Requests' started by juperlas, Feb 20, 2018.

  1. juperlas


    How to add search filter by tag values ?, by juperlas

    I’m trying to improving the wordpress search.
    I would like to find all the posts or pages that search string matchs with the next and in this order:
    1.- post tags,
    2.- custom field,
    3.- post or page title,
    4.- post or page content

    It’s more, I need to obtain them after a date.
    I’m doing the next but it doesn’t work, if someone could help me I would appreciate

    function search_filter( $query ) {
    if ($query->is_search) {
    //filter by custom field ‘sinonimo’
    $query->set( ‘meta_key’ , ‘sinonimo’ );
    $query->set( ‘meta_value’ , $query->get(‘s’) );

    //filter by tags
    $terms = explode(‘ ‘, $query->get(‘s’));
    $query->set(‘tax_query’, array(
    //filter by date
    $date_query = array(
    ‘after’ =>; array( ‘year’ => 2014,
    ‘month’ => 1,
    ‘day’ => 1),
    ‘inclusive’ =>; true,

    $query->set( ‘date_query’,$date_query);
    return $query;


    How to add search filter by tag values ?

Share This Page

Monarch Social Sharing Plugin