你可以这样试试
$query = "
SELECT *
FROM $wpdb->posts
WHERE $wpdb->posts.post_title LIKE '$param2%'
ORDER BY $wpdb->posts.post_title
";
$wpdb->get_results($query);
替代方式和标准方式
add_filter( 'posts_where', 'wpse18703_posts_where', 10, 2 );
function wpse18703_posts_where( $where, &$wp_query )
{
global $wpdb;
if ( $wpse18703_title = $wp_query->get( 'wpse18703_title' ) ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql( like_escape( $wpse18703_title ) ) . '%\'';
}
return $where;
}
以这种方式使用
$args = array(
'post_type' => 'product',
'wpse18703_title' => 'your string',
'posts_per_page' => $page_size,
'paged' => $page,
'post_status' => 'publish',
'orderby' => 'title',
'order' => 'ASC',
);
$result = new WP_Query($args);