Discussion:
something like a post_get_posts?
Josh
2013-09-06 21:04:58 UTC
Permalink
We make heavy use of Scribu's excellent Posts 2 Posts plugin. There's a very handy P2P method that operates on the wp_query object where you can have it find connected posts and add them to the wp_query->posts array.

What I'm looking to do is have a function that runs this where appropriate based on post type, but since it operates on the wp_query object it doesn't seem I could use pre_get_posts. There's no post_get_posts, but is there another action I can hook into that might be workable?

loop_start seems like a good candidate but there's not much documentation about that one.

Thanks in advance,
Josh
Jeremy Clarke
2013-09-10 17:04:25 UTC
Permalink
Post by Josh
There's no post_get_posts, but is there another action I can hook into
that might be workable?
I think the 'wp' action should offer what you need. IIRC it runs after the
main query is complete but before the template is rendered.
Post by Josh
loop_start seems like a good candidate but there's not much documentation about that one.
In theory this would work but be very careful. 'loop_start' will fire on
every single loop, including secondary queries for widgets, related posts
etc.

In either case you should be sure to check is_main_query() against your
WP_Query object before modifying it, or at least be aware of the difference
between filtering the main query of a screen versus filtering all possible
WP_Query instances.

http://codex.wordpress.org/Function_Reference/is_main_query
--
Jeremy Clarke • jeremyclarke.org
Code and Design • globalvoicesonline.org
Josh
2013-09-10 17:36:46 UTC
Permalink
Great, thanks.
Post by Jeremy Clarke
Post by Josh
There's no post_get_posts, but is there another action I can hook into
that might be workable?
I think the 'wp' action should offer what you need. IIRC it runs after the
main query is complete but before the template is rendered.
Post by Josh
loop_start seems like a good candidate but there's not much documentation
about that one.
In theory this would work but be very careful. 'loop_start' will fire on
every single loop, including secondary queries for widgets, related posts
etc.
In either case you should be sure to check is_main_query() against your
WP_Query object before modifying it, or at least be aware of the difference
between filtering the main query of a screen versus filtering all possible
WP_Query instances.
http://codex.wordpress.org/Function_Reference/is_main_query
--
Jeremy Clarke • jeremyclarke.org (http://jeremyclarke.org)
Code and Design • globalvoicesonline.org (http://globalvoicesonline.org)
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Daniel Dvorkin
2013-09-11 13:47:53 UTC
Permalink
Filter the_posts?



---------------------
Daniel Dvorkin
Móvil: +54 (0261) 15-315-2244
Skype: mzaweb
http://mzaweb.com
Post by Josh
Great, thanks.
Post by Jeremy Clarke
Post by Josh
There's no post_get_posts, but is there another action I can hook into
that might be workable?
I think the 'wp' action should offer what you need. IIRC it runs after
the
Post by Jeremy Clarke
main query is complete but before the template is rendered.
Post by Josh
loop_start seems like a good candidate but there's not much
documentation
Post by Jeremy Clarke
Post by Josh
about that one.
In theory this would work but be very careful. 'loop_start' will fire on
every single loop, including secondary queries for widgets, related posts
etc.
In either case you should be sure to check is_main_query() against your
WP_Query object before modifying it, or at least be aware of the
difference
Post by Jeremy Clarke
between filtering the main query of a screen versus filtering all
possible
Post by Jeremy Clarke
WP_Query instances.
http://codex.wordpress.org/Function_Reference/is_main_query
--
Jeremy Clarke • jeremyclarke.org (http://jeremyclarke.org)
Code and Design • globalvoicesonline.org (http://globalvoicesonline.org)
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...