Есть сайт на WordPress. Как при выводе записей отфильтровать их по произвольному полю status
(и его значению publish
)?
// Query the posts
$all_blog_posts = $wpdb->get_results($wpdb->prepare("
SELECT * FROM " . $table_name . " WHERE post_type = 'community' AND post_status = 'publish' ORDER BY post_date DESC LIMIT %d, %d", $start, $per_page ) );
// At the same time, count the number of queried posts
$count = $wpdb->get_var($wpdb->prepare("
SELECT COUNT(ID) FROM " . $table_name . " WHERE post_type = 'community' AND post_status = 'publish'", array() ) );
// Loop into all the posts
...
Пробовала так, но в таком случае ничего не отображается:
// Query the posts
$all_blog_posts = $wpdb->get_results($wpdb->prepare("
SELECT * FROM " . $table_name . " WHERE post_type = 'community' AND post_status = 'publish' AND meta_key = 'status' AND meta_value = 'publish' ORDER BY post_date DESC LIMIT %d, %d", $start, $per_page ) );
// At the same time, count the number of queried posts
$count = $wpdb->get_var($wpdb->prepare("
SELECT COUNT(ID) FROM " . $table_name . " WHERE post_type = 'community' AND post_status = 'publish' AND meta_key = 'status' AND meta_value = 'publish'", array() ) );
// Loop into all the posts
...