Skip to content
This repository was archived by the owner on Mar 23, 2021. It is now read-only.
This repository was archived by the owner on Mar 23, 2021. It is now read-only.

Proposal: Allow router to accept query_data array for what data to include in $post #129

@drewbaker

Description

@drewbaker

OK so 99% of the time whenever I need a custom filter, it is to one of these scenarios:

  1. Add pages to related
  2. Include "featured" pages/posts on the homepage (or a shop landing page etc)
  3. Add some detail to the site data object (like News page name, URL etc).
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions