[wp-hackers] Plugin Port to 2.0: Showing private posts in single-view

Filipe Fortes fortes at gmail.com
Thu Dec 22 01:32:28 GMT 2005


> > > If there are any extra hooks you need added, let us know now and we can
> > > try to get them into 2.0.
> >
> > The biggest thing that's been missing is that the posts_where and
> > posts_join filters aren't called when constructing archives (date or
> > category), meaning the archives can't take into account the private
> > posts (since post_status = 'publish' is hard coded).
>
> I thought we always called those filters.  Maybe I'm not following.  Can
> you elaborate a bit more?

I switched topics without introducing the issue, my fault. My plugin
depends on post_status being set to private for the protected posts.
Those posts are then shown through the posts_where and posts_join
filters. However, this technique doesn't work for list_cats, etc
because those filters aren't applied to the SQL queries which generate
them.

For example: Looking at template-functions.php, line 305, you can see:

		$cat_dates = $wpdb->get_results("SELECT category_id,
		UNIX_TIMESTAMP( MAX(post_date) ) AS ts
		FROM $wpdb->posts, $wpdb->post2cat, $wpdb->categories
		WHERE post_status = 'publish' AND post_id = ID $exclusions
		GROUP BY category_id");

As you can see, the SQL query is run without any filters, so my plugin
can't change the query to account for private posts. For another
example, see template-functions-general.php, line 333. You'll see:

$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS
`year`, MONTH(post_date) AS `month`, count(ID) as posts FROM
$wpdb->posts WHERE post_date < '$now' AND post_date != '0000-00-00
00:00:00' AND post_status = 'publish' GROUP BY YEAR(post_date),
MONTH(post_date) ORDER BY post_date DESC" . $limit);

Thanks.


More information about the wp-hackers mailing list