Make WordPress Core

Opened 16 years ago

Closed 15 years ago

#2712 closed enhancement (fixed)

Need to filter posts before post_type and user checks

Reported by: ev3rywh3re's profile ev3rywh3re Owned by:
Milestone: 2.1 Priority: normal
Severity: normal Version: 2.1
Component: General Keywords: filter the_posts has-patch
Focuses: Cc:


I'm working on making EventCalendar3 work with 2.1Alpha. It actually works well using standard filters while preserving the status = future with one exception.

Once you actually send the sql request with WP_Query, it goes through another check for status = future. This is around line 886 in query.php. I thought this may be a good place to add a filter like "posts_result". A filter can then be run on the results before the posts get the status check then filter "the_posts". I'm just going to paste a sample for query.php:

$this->request = apply_filters('posts_request', $request);

$this->posts = $wpdb->get_results($this->request);

$this->posts = apply_filters('posts_results', $this->posts);

// Check post status to determine if post should be displayed.

The only alternative is to publish those posts which is probably not really the correct since they should probably still be "future" posts until the proper date.

Attachments (1)

query_post_filter_moved.diff (739 bytes) - added by ev3rywh3re 16 years ago.
Patch to move the_post filter to act before post_type and user checks

Download all attachments as: .zip

Change History (6)

#1 @skeltoac
16 years ago

Have you considered using a custom post type?

#2 @ev3rywh3re
16 years ago

I was thinking about that, or walking through members of the category used by the plugin and marking them as published.

I just happened to notice that that location in query.php is ripe for a filter. Some plug in authors may want to manipulate posts before the post array is sanitized by user and post type. Another option could be to move the_posts filter to act before the post type checks. Then you can do a temporary change to post type in the array instead.

I think my only concern was manipulation of post type in the database. I thought the "future" post type is fitting (for this plugin)and I didn't want to destroy that methodology if the plugin is disabled. I was happy to see the post type changes and the updates to the category code.. It's so much more elegant now.

I am not the orginal author of the plugin, but I am hoping to send the revisions back to someone to clean up.

16 years ago

Patch to move the_post filter to act before post_type and user checks

#3 @ev3rywh3re
16 years ago

  • Keywords the_posts added

Just added a patch to move the_post filter to act before the user and post_type checks. I don't think an extra filter would be needed.

#4 @ev3rywh3re
16 years ago

  • Keywords has-patch added; posts hook removed
  • Summary changed from Need filter for posts after get results and before post status check to Need to filter posts before post_type and user checks

#5 @matt
15 years ago

  • Resolution set to fixed
  • Status changed from new to closed

This hook is already there.

Note: See TracTickets for help on using tickets.