Support

Account

Home Forums Front-end Issues Assistance with ACF query

Helping

Assistance with ACF query

  • Hey,

    I’m currently building an nightclub website with WordPress and a lot of ACF’s features. There’s one query I cant wrap my head around.

    At a custom post type called event you can select artists from a custom post type called.. artists. I use a Relation ACF field for this.

    I managed to build a query to view all events the artist is related to at a single artist page.

    <?php
    	 
    	$posts = get_posts(array(
    		'post_type' => 'agenda',
    		'posts_per_page' => -1,
    		'meta_key' => 'datum', // Dutch for Date
    		'orderby' => 'datum',
    		'orderby' => 'meta_value_num',
    		'order' => 'DESC',
    		'meta_query' => array(
    			array(
    				'key' => 'artiesten',
    				'value' => '"' . get_the_ID() . '"',
    				'compare' => 'LIKE',
    			)
    		)
    	));
    	
    	?>

    Now I would like to create a page with the most billed artist per year. Is this possible in a single query? I could loop all artists and include a second loop to count the events the artist is billed on, but I don’t think my server agrees with a big artist database.

    Help is greatly appreciated!

    Sample event page: http://www.perron.nl/agenda/2manydjs-2/
    Sample artist page: http://www.perron.nl/artists/samnesia/

  • Hi @Martijnnn

    I think the only way to do this is to first query all events for the year. Then loop though all the events and load in the selected artists that played.

    You can then use this data to increase a counter for each artist.

    Then at the end of the loop, you will be left with counters for each artist which you can then find which one is the biggest and display that artists information.

    If performance is a concern, I would swap the relationship field type, for a plugin called ‘posts 2 posts’

    Thanks
    E

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Assistance with ACF query’ is closed to new replies.