我分别找到了分类法、自定义字段和标记的许多答案,其中大多数都已过时。
但如何在中组合搜索:
- designed custom fields of a custom post
- custom taxonomy terms
- Tags
- Title (already by default)
- Content (already by default)
我的一个自定义项目可以是,例如:
item 1
tag: tag1, tag2, tag3
taxonomy: tax1, tax2
custom field 1: cf1
title: composed title 1
desc: a full paragraph with many words
现在,我希望能够搜索:
"paragraph tag2 cf1 composed"
解决方案似乎极其复杂。。。是否只能使用新的SQL查询(
JOIN LEFT
等)我能找到简单的方法吗
$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;
}}