Skip to content

Commit

Permalink
Exclude attachments from OowpQuery
Browse files Browse the repository at this point in the history
Should fix preview crash when titles clash; closes #19
  • Loading branch information
NoelLH committed Jul 14, 2021
1 parent fd04991 commit 69465a2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/OowpQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ function __construct($query = '')
);
$query = wp_parse_args($query, $defaults);

// if there is no post type, or the post type is singular and isn't valid, replace it with 'any'
// If there is no post type, or the post type is singular and isn't valid, replace it with any *except*
// 'attachment' which can cause crashes on ?preview=true if a file title matches a render-able post's.
if (!isset($query['post_type']) || (!is_array($query['post_type']) && !array_key_exists($query['post_type'],
$wp_post_types))) {
$query['post_type'] = 'any';
$query['post_type'] = $wp_post_types;
$attachmentTypeIndex = array_search('attachment', $query['post_type'], true);
if ($attachmentTypeIndex !== false) {
array_splice($query['post_type'], $attachmentTypeIndex, 1);
}
}

parent::__construct($query);
Expand Down

0 comments on commit 69465a2

Please sign in to comment.