如果您想直接在$wpdb中查询,可以在搜索中这样做。php:
global $wp_query;
global $wpdb;
global $post;
$search = sanitize_text_field( $_GET[\'s\']);
$querystr = "
SELECT wposts.ID, wpostmeta. *
FROM $wpdb->posts AS wposts
LEFT JOIN $wpdb->postmeta wpostmeta ON (wposts.ID = wpostmeta.post_id)yy
WHERE wposts.post_status = \'publish\' // all published
AND wposts.ID NOT IN (\'186\',\'184\' ,\'108\', \'124\', \'78\', \'80\', \'289\') // exclude all these IDs
AND wpostmeta.meta_key= \'_txt_en\' // Here the customField
AND wpostmeta.meta_value LIKE \'%".$search."%\'
GROUP BY wposts.ID
";
$postids = $wpdb->get_results($querystr,OBJECT);
if ($postids){
foreach ($postids as $post){
setup_postdata($post);
echo apply_filters(\'the_content\', get_post_meta($post->ID, \'_txt_en\', true));
}
}else{
echo "<p>Sorry, no matches.";
}
}