我已尝试过以下场景,但如果帖子标题有& ()符号,
第一种方式,
$event_details = get_page_by_title($event_name, OBJECT, 'tribe_events');
第二种方式,
$event_name = html_entity_decode( $event_name );
$event_details = get_page_by_title($event_name, OBJECT, 'tribe_events');
第三种方式,
global $wpdb;
$search = $wpdb->query( "SELECT * FROM `wp_posts` WHERE `enter code here`post_title=".$title );
第四种方式,
$event_name = addslashes ( $event_name );
$event_details = get_page_by_title($event_name, OBJECT, 'tribe_events');
答案 0 :(得分:0)
只需使用esc_attr()
作为标题,并尝试使用esc_html()
$search = $wpdb->query( "SELECT * FROM `wp_posts` WHERE `enter code here`post_title='".esc_attr($title)."'" );