How do I have multiple metaqueries inside one wordpress query

Question

I have a parent->child relationship between artists and releases. There is another parent->child relationship between releases and versions aka albums, singles, videos, misc.

So artist is the grandparent of version.

I’m using a wp query to find all version posts that belong to an artist. This works great, yay for me!

I’ve added some custom fields to the release level, including featuring and related to. I’d like this same query to pull all versions that belong to a release that has the artist listed in one of these fields.

My problem is, I can’t wrap my head around how to include release post type in as well. here’s my current code.

$args = array(
    'post_type' => array('single','album','videos','misc'),
    'posts_per_page' => -1,
    'meta_query' => array(
        array(
            array(
                'relation' => 'AND',
                'format' => array(
                    'key' => 'wpcf-format',
                ),
                'country' => array(
                    'key' => 'wpcf-country-of-release',
                ),
                'year' => array(
                    'key' => 'wpcf-release-year',
                    
                ),
                'label' => array(
                    'key' => 'wpcf-label',
                ),
                'artist' => array(
                    array(
                        'relation' => 'OR',
                        'mainartist'=> array(
                            'key' => $queriedartistid,
                        'value' => $thispostartistid,
                        ),
                        'splitartist'=> array(
                            'key' => $splitartist,
                        'value' => $thispostartistid,
                        ),
                        'relatedto'=> array(
                            'key' => $relatedto,
                        'value' => $thispostartistid,
                        ),
                        'featuring'=> array(
                            'key' => $featuring,
                        'value' => $thispostartistid,
                        ),
                        'performedby'=> array(
                            'key' => $performedby,
                        'value' => $thispostartistid,
                        ),
                        'variousartist'=> array(
                            'key' => $variousartist,
                        'value' => $thispostartistid,
                        ),
                    ),
                        
                ),
                'release' => array(
                    'key' => '_wpcf_belongs_release_id',
                    
                ),
                'bootleg' => array(
                    'key' => 'wpcf-bootleg',
                ),
                
                'catalogue' => array(
                    'key' => 'wpcf-catalogue-number',
                ),
                ),
                
            ),
        ),
    
'orderby' => array(
    'year' => 'ASC',
    'format' => 'ASC',
    'country' => 'ASC',
    'label' => 'ASC',
    'catalogue' => 'ASC',
    'other_info_empty' => 'ASC',
    'other_info_there' => 'ASC',
    )
); 

The problem is in my artist array. The search is only looking for versions, which don’t have the meta fields ‘featuringorrelated to` etc. Those are in the version level.

How can I structure this query to include also versions of releases with the artist listed in these meta fields?

In English:
show all versions, where the meta-key '_wpcf_belongs_release_id' matches a release which has the custom meta-key related_to with a value of $thispostartistid. How can I include that in this query?

Thanks, I think this is a complicated way to write this question, looking forward to comments that help me clean up and make my question clearer.

0
RCOTWUnite 2 months 2022-09-26T15:04:46-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse