[wp-trac] [WordPress Trac] #16641: custom post has_archive in multisite
WordPress Trac
wp-trac at lists.automattic.com
Sun Feb 27 19:41:24 UTC 2011
#16641: custom post has_archive in multisite
-------------------------------+------------------------------
Reporter: andreamk | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Post Types | Version: 3.1
Severity: minor | Resolution:
Keywords: reporter-feedback |
-------------------------------+------------------------------
Comment (by andreamk):
Suppose you create a custom post events and register it with has_archive.
if I put in my plugin a a new action
{{{
add_action('pre_get_posts', 'addCustomPost' );
public function addCustomPost( $query ) {
if (!is_admin() && !is_single() && !is_feed()) {
$exclude = array('attachment','revision','nav_menu_item');
$pType = $query->get('post_type');
if (is_array($pType)) {
foreach ($pType as $p) {
if (in_array($p, $exclude)) {
return $query;
}
}
} else {
if (in_array($pType , $exclude)) {
return $query;
}
}
if (is_array($query->query_vars['post_type']) {
$query->query_vars['post_type'][] = 'events';
} else {
if (!empty($query->query_vars['post_type'])) {
$query->query_vars['post_type'] =
array($query->query_vars['post_type'],'events);
} else {
$query->query_vars['post_type'] = 'events';
}
}
}
}
}}}
now if you go in events archive the var query_var become
{{{
object(WP_Query)#4322 (44) {
["query_vars"]=>
array(57) {
["post_type"]=>
array(2) {
[0]=>
string(7) "events"
[1]=>
string(7) "events"
}
.
.
.
}}}
to prevent this error I must check if my custom post type isn't already in
query var.
is the right thing to do but with all the plugins that there are
possibilities of conflict are high.
I think that preventing this type of error strengthens wordpress
--
Ticket URL: <http://core.trac.wordpress.org/ticket/16641#comment:4>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list