I have a question that I would like to ask on WPSE, but fear that it leans towards the "Bad Subjective" end of Good Subjective, Bad Subjective spectrum.
So, I thought I'd ask here whether it would be appropriate to ask it on WPSE. If not appropriate, is there a way I could alter the question so that it would be appropriate?
Question I'd like to ask on WPSE
WP provides a large number of filters/actions to alter the query performed by WP_Query
.
There is ample (if not always adequate) documentation on individual filters in the Developer Resources (e.g., pre_get_posts, parse_request, request, etc).
And the Filter Reference and Action Reference in the codex goes a little way to documenting which filters/actions affect which phase of processing.
To futher complicate matters, in many cases, the same result can be achieved by using different filters/actions.
For example, suppose I want to change the default sorting of posts (including CPTs) on the edit.php screen. I can accomplish that goal in (at least) 2 different ways:
using the request filter
add_filter ('request', 'set_default_edit_orderby_using_request') ;
function
set_default_edit_orderby_using_request ($query_vars)
{
global $pagenow, $typenow ;
if ('edit.php' != $pagenow || 'my_cpt' != $typenow || isset ($query_vars['orderby'])) {
return ($query_vars) ;
}
$query_vars['meta_key'] = 'some_meta_key' ;
$query_vars['orderby'] = 'meta_value menu_order title' ;
$query_vars['order'] = 'ASC' ;
return ($query_vars) ;
}
using the pre_get_posts action
add_action ('pre_get_posts', 'set_default_edit_orderby_using_pre_get_posts') ;
function
set_default_edit_orderby_using_pre_get_posts ($query)
{
global $pagenow, $typenow ;
$orderby = $query->get ('orderby') ;
if ('edit.php' != $pagenow || 'my_cpt' != $typenow || !empty ($orderby)) {
return ;
}
$query->set ('meta_key', 'some_meta_key') ;
$query->set ('orderby', 'meta_value menu_order title') ;
$query->set ('order', 'ASC') ;
return ;
}
After much searching (here on WPSE, on the wordpress.org forums and on google), I have yet to find a good reference for best practices on which WP_Query
-related filter(s)/action(s) to use to accomplish a given task when more than 1 will do the job.
I'm looking for resources that would say things like:
when X and Y would both accomplish Z, prefer X because it is less expensive (in time/memory/etc)
Clarification of the question I'd like to ask
Based on the answers I've gotten so far, I think I need to clarify the question I'd like to ask on WPSE.
I'm not really asking whether request
or pre_get_posts
is "best" for the example use case in my question (to set the default orderby for the edit.php screen). That was just an example to set the stage.
What I'm asking for is suggestions for "good" reference material (e.g., books, blog posts, conference presentations, etc) that would help to answer (or at least offer lists things to one should consider when trying to answer) a whole range of questions about which WP_Query
-related hook to use for a whole range of use cases (when multiple hooks would produce the results.
Why I think the question might be "Bad Subjective" is that what 1 person things is a "good" discussion on top might be considered "bad" by another.