-
Notifications
You must be signed in to change notification settings - Fork 15
Proposal: Allow router to accept query_data array for what data to include in $post #129
Description
OK so 99% of the time whenever I need a custom filter, it is to one of these scenarios:
- Add pages to
related
- Include "featured" pages/posts on the homepage (or a shop landing page etc)
- Add some detail to the site data object (like News page name, URL etc).
- Manipulate a post meta data value in someway (like format a date, or add in gallery images or related posts out of a meta field)
Now it seems that some of that (3) would be best as a filter, but (1) and (2) are using the rez_gather_related
filter and thus the most dangerous and confusing things to do.
Using rez_gather_related
It's super easy to get an infinite loop, or make an insane query that slows down your server. The filters end up looking like a mess of if()
statements testing against the dev_ids
to see when to load all siblings etc...
So could we make an alternative to the rez_gather_related
filter? And it seems to me we could do this in a WordPress way by defining an array of settings on the route (trying to match the wp_query
syntax).
Now I'm not exactly sure how these settings get used behind the scenes, like do they go on the loop
posts? Perhaps anytime a post with the matching dev_id
is queried it factors in the provided settings?
This method would also be backwards compatible, which is nice. You could also opt out of data this way too, making things even faster!
I was thinking something like this in router.php:
$story_args = array(
'title' => true,
'post_content' => true,
'post_excerpt' => true,
'relative_path' => true,
'meta' => array('all', 'meta_key_1', 'meta_key_2'),
'attachments' => array('all', 'image/jpeg', 'image/gif'),
'related' => array('parent', 'siblings', 'children', 'next', 'previous'),
'taxonomies' => array('all', 'category', 'custom_taxonomy_name')
);
$programmed_routes = array(
path_from_dev_id('stories') => array(
'component' => 'StoriesGrid',
'name' => 'StoriesGridPage',
'query_data' => $story_args
)
);
I think there is also an opportunity to include more things in the $post object by default (all attachments, all ACF content, all meta etc). We have some of this all ready, but it's good to look at it again now that we are down the road a little with Vuepress. Also change the name! LOL!
Then most themes would only need to use the rez_serialize_post
or the rez_build_site_data
filters, which are way easier to understand and less dangerous.