Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have found many answers separately for Taxonomy, Custom fields and Tags, most of them outdated.

But how to combine a search in:

- designed custom fields of a custom post
- custom taxonomy terms
- Tags
- Title (already by default)
- Content (already by default)

One of my custom items could be for example:

item 1
tag: tag1, tag2, tag3
taxonomy: tax1, tax2
custom field 1: cf1
title: composed title 1
desc: a full paragraph with many words

Now I would like to be able to search for :

"paragraph tag2 cf1 composed"

The solution seems incredibly complicated... is it only possible with a new SQL query (JOIN LEFT etc) of can I find my way with simple $query->set() ?

add_filter( 'pre_get_posts', 'cjg_theme_filter' );

if (!function_exists('cjg_theme_filter')) {
    function cjg_theme_filter( $query ){

    if ( $query->is_main_query() ){
          //is_search is necessary for custom taxonomy urls
        if ( $query->get( 'tag' ) OR $query->get( 'artprim_categories' ) OR is_search() )
            $query->set( 'post_type', array( 'post', 'artprim_item' ) );

        if ( is_search() ){
            $queryString = $query->query_vars['s'];

            $queryTab = explode(' ', $queryString);

            $meta = array();
            foreach($queryTab as $queryString){
                $meta[] = array(
                    'key' => 'date',
                    'value' => $queryString,
                    'compare' => 'LIKE');
            }
            $query->set( 'meta_query',$meta );
        };        
    }

    return $query;

}}
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

it seems Relevanssi is a very good updated plugin

it solved my problems

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.