So I am attempting to filter out certain posts in the get_posts call. Essentially, I want to be able to specify a certain block of posts, and only get the posts that correspond with the block. Right now I have a table that contains both block IDs and post IDs, so I have been looking into using the posts_join and the posts_where hooks. However, I need to be able to dynamically modify the block retrieved depending on what the client currently has chosen. To this end, I am tracking what the client has selected using a cookie. I feel that I should be able to pass the block ID as a another value in the array given to get_posts, but I have no idea how to retrieve that value. So my question is: how should I go about doing this?
It seems that the simplest, most elegant solution would be to just add something like:
$postargs = array(
'blockID' => $id
);
$posts = get_posts($postargs);
I just don't know how in my hooked function:
function set_block_filter($id){
/* This should probably use the posts_join hook */
/* $join = 'LEFT JOIN wdpress.$table_name ON wdpress.$table_name.post_id = wdpress.wp_posts.ID'*/
/* something like that ^ http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join*/
/* $where = ' AND block_id=$id '*/
}
can retrieve the blockID from the $postargs array.
EDIT: So the solution was actually very simple, and I think most of my confusion was born from my misunderstanding about how cookies work. Since they are apparently accessible server-side, my answer was this:
function set_block_filter($query){
if($query->is_category){
$query->set('meta_key', 'block');
$query->set('meta_value', $_COOKIE['block']);
return;
}
}
add_action('pre_get_posts','set_issue_filter');