I’m putting away posts, a client continues in a custom table that has the sections id
, post_id
and user_id
. To bring posts that a client follows I have broadened the WP_Query as follows:
class WP_Query_Posts_User_Follows expands WP_Query {
work __construct($args=array()) {
on the off chance that ( !empty($args['followed_by']) ) {
$this->followed_by = $args['followed_by'];
add_filter('posts_where', array($this, 'posts_where'));
}
parent::query($args);
}
work posts_where($where) {
worldwide $wpdb;
$table = $wpdb->prefix . 'post_followed_by';
$where .= $wpdb->prepare(" AND ID IN (SELECT post_id FROM $table WHERE user_id = %d)", $this->followed_by);
return $where;
}
}
If you notice there is sub-question in the WHERE
statement. My arrangement is that sub-inquiries are terrible as they obstruct execution and especially for this situation where the sub-inquiry might actually return hundred or thousands of post_ids
that a client follows. What are the choices that I have, taking into account that I need to work with WP_Query and can’t run a custom SQL straightforwardly utilizing wpdb
?