I just read that, it seems a bit cryptic, so here is a bit more of what I’m trying to do.
I want to set up one blog that displays on many sites. Certain posts will display on one or a few sites, and some will be on all sites.
So what I’ve done is create a table with the list of sites (by domain) and a table that associates posts with sites.
What I want to do is have only posts that have been assigned to that site display on that site.
An example of how this might be used is these 4 domains:
dogs.tld
cats.tld
hamsters.tld
pets.tld
There may be categories like
Food
Care & Grooming
Cute Anecdotes
Vet Tips
These four different blogs have the same categories accross them all, but the blog posts wouldn’t be appropriate for all of them all the time.
A post about how to deal with pet stains in the carpet may be appropriate on all of the blogs, but a post on hairballs may only be appropriate on pets.tld and cats.tld.
It seems like the_posts hook is where I need to start, I think.
Well, I’ve figured this out, but it filters posts even in the admin panel. I’ll have to figure that one out.
add_filter('the_posts', 'my_function' , 1 );
function my_function( $posts ) {
// create an array to hold the posts we want to show
$new_posts = array();
//
// loop through all the post objects
//
foreach( $posts as $post ) {
$include = true;
//
// Perform Filter comparison
//
if ($filterPost>=1) {
$include = false;
}
//
// if we want to include it then
// add the post object to the new posts array
//
if ( $include === true ) {
$new_posts[] = $post;
}
}
//
// send the new post array back to be used by WordPress
//
return $new_posts;
}
Have you figured this out? I have a similar issue.
Not quite sure if anyone figured this out, as it was posted 6 months ago but I would suggest the following (even though perhaps a little hacky):
if(!strpos($_SERVER["REQUEST_URI"],"wp-admin")){
add_filter('the_posts','my_function');
}
What this is saying is, if the URL doesn’t contain the standard “wp-admin” part, apply the filter. Otherwise, it won’t filter them. I assume this is what you need? Obviously if you want it filtered on admin but not front end, remove the “!” just before the “strpos”.