Skip Navigation

[Resolved] Quering 2 post relationships with wpv-attribute

This support ticket is created 3 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by bernhardK 3 years, 4 months ago.

Author
Posts
#2147583

Hi all,

I'm querying 2 relationships within 1 view with the help of some code.

add_filter( 'wpv_filter_query', 'filter_by_parent_schuelerlogin_func', 99, 3 );
function filter_by_parent_schuelerlogin_func( $query_args, $view_settings, $view_id ) {
    if ( $view_id == 19015 && isset($_GET['schuelerid'])) {
        if(!isset($query_args['toolset_relationships'])){
            $query_args['toolset_relationships'] = array();
        }
        $query_args['toolset_relationships'][] = array(
                'role' => 'child',
                 'related_to' => $_GET['schuelerid'],
                'relationship' => 'schuler-protokoll'
        );
    }
    return $query_args;
}

With aboves code I am looking for URL param schuelerid within "related_to", however I want it to be some value that is available via [wpv-attribute] to that view. How can I get the wpv-attributes value? The wpv-attributes name is "schuelerid" as well.

Thanks
Bernhard

#2147763

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Bernhard

Looking into this a value passed to a View as a shortcode attribute isn't ordinarily available in the context of the wpv_filter_query filter, unless you actually use the passed value in a View filter.

You could add a Query Filter for a related post (it looks like that is what you are trying to do), but that won't make the passed value available to your callback added to wpv_filter_query, because Views pre-processes queries involved related posts to first apply the relationship filter and create a post__in argument in the main query that limits the possible results to only those matching the relationship filter.

But perhaps that is all you need—to add a Query Filter for your relationship where the post to filter by comes from a shortcode attribute—which means that the query you modify with the wpv_filter_query filter will have already eliminated posts that do not match the relationship requirement.

#2147893

Thanks Nigel, I am now using wpv-conditionals in this case.

One question and with the answer you may directly close this ticket. 🙂

Is it planned / on the roadmap to support querying multiple relationships in one view?
BR Bernhard