Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1130349
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionI am using the following code to modify the default WordPress search and The Events Calendar search to include custom fields.
The custom fields are added by the Advanced Custom Field (ACF) plugin (/). I am particularly interested in a field which is a ACF repeater field. (Although, it would be helpful if all post_meta associated with the event post can be searched.)
/**
* Extend WordPress search to include custom fields
* /
*
* /
*/
/**
* Join posts and postmeta tables
*
*/
function cf_search_join( $join ) {
global $wpdb;
if ( is_search() || !empty( $_REQUEST['tribe-bar-search'] ) ) {
$join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}
return $join;
}
add_filter('posts_join', 'cf_search_join' );
/**
* Modify the search query with posts_where
*
*/
function cf_search_where( $where ) {
global $wpdb;
if ( is_search() || !empty( $_REQUEST['tribe-bar-search'] ) ) {
$where = preg_replace(
"/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
"(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where );
}
return $where;
}
add_filter( 'posts_where', 'cf_search_where' );
/**
* Prevent duplicates
*
*/
function cf_search_distinct( $where ) {
global $wpdb;
if ( is_search() || !empty( $_REQUEST['tribe-bar-search'] ) ) {
return "DISTINCT";
}
return $where;
}
add_filter( 'posts_distinct', 'cf_search_distinct' );
The code works fine for the default WordPress search but not for The Events Calendar search.
I have tried the code with the default Twenty Seventeen theme and disabling plugins other than The Events Calendar ones, to rule out any theme/plugin conflicts, but that didn't work either.
Any pointers on where I might be going wrong will be extremely helpful.
Thanks.
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionI am using the following code to modify the default WordPress search and The Events Calendar search to include custom fields.
The custom fields are added by the Advanced Custom Field (ACF) plugin (/). I am particularly interested in a field which is a ACF repeater field. (Although, it would be helpful if all post_meta associated with the event post can be searched.)
/**
* Extend WordPress search to include custom fields
* /
*
* /
*/
/**
* Join posts and postmeta tables
*
*/
function cf_search_join( $join ) {
global $wpdb;
if ( is_search() || !empty( $_REQUEST['tribe-bar-search'] ) ) {
$join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}
return $join;
}
add_filter('posts_join', 'cf_search_join' );
/**
* Modify the search query with posts_where
*
*/
function cf_search_where( $where ) {
global $wpdb;
if ( is_search() || !empty( $_REQUEST['tribe-bar-search'] ) ) {
$where = preg_replace(
"/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
"(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where );
}
return $where;
}
add_filter( 'posts_where', 'cf_search_where' );
/**
* Prevent duplicates
*
*/
function cf_search_distinct( $where ) {
global $wpdb;
if ( is_search() || !empty( $_REQUEST['tribe-bar-search'] ) ) {
return "DISTINCT";
}
return $where;
}
add_filter( 'posts_distinct', 'cf_search_distinct' );
The code works fine for the default WordPress search but not for The Events Calendar search.
I have tried the code with the default Twenty Seventeen theme and disabling plugins other than The Events Calendar ones, to rule out any theme/plugin conflicts, but that didn't work either.
Any pointers on where I might be going wrong will be extremely helpful.
Thanks.
本文标签: Extend 39The Events Calendar39 search to include custom fields
版权声明:本文标题:Extend 'The Events Calendar' search to include custom fields 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749084264a2313525.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论