Show only posts related to the ACF post object in slider

Hello @wowflak,

Thanks for writing in! You cannot use the Query Builder in your Looper because what you are trying to display on your slider are the related release albums under the same artists. You should be using the Query String Looper provider instead. Perhaps these threads may help you:

or check out this video to know more about the Query String Looper Provider:

References:

Best Regards.

Thanks, I have tried adding the string:
category_name ={{dc:term:slug}}&post_type=releases&posts_per_page=3&offset=0&ignore_sticky_posts=1&post__not_in%5B0%5D={{dc:post:id}}

and this does not work, I am confused on how to modify since these are both CPT’s that are related to each other via post object and not category, I know I am missing it but just cannot see it. Thanks for your help.

Hi @wowflak,

You need to create the meta query using the meta_key to specify the field name instead of the category. You need to mention the meta key in your Query String and that might look like that.
Your main query should look like that.

$meta_query[] = array(
    'key'     => 'artist',
    'value'   => '{{dc:acf:post_field field="artist"}}',
    'compare' => '==',
);

$query = array(
    'post_type'  => 'releases',
    'meta_key'   => 'artist',
    'orderby'    => 'meta_value',
    'order'      => 'ASC',
    'meta_query' => $meta_query
);

The Query String will look like that which I have generated using the http_build_query() function.

`post_type=releases&meta_key=artist&orderby=meta_value&order=ASC&meta_query%5B0%5D%5Bkey%5D=artist&meta_query%5B0%5D%5Bvalue%5D=%7B%7Bdc%3Aacf%3Apost_field+field%3D%22artist%22%7D%7D&meta_query%5B0%5D%5Bcompare%5D=%3D%3D`

I would suggest you go through the following article on ACF and custom field query.


Hope it helps.
Thanks

Thank you but I am sorry this is still not working

Hello @wowflak,

When you get the custom post type “Releases”, we access it using the meta query and the meta query values only accepts ‘NUMERIC’, ‘BINARY’, ‘CHAR’, ‘DATE’, ‘DATETIME’, ‘DECIMAL’, ‘SIGNED’, ‘TIME’, ‘UNSIGNED’. Since the “Artists” is a Post Object, the query will return nothing. You need to edit your Releases Fields and change the return format to Post ID only.

Kindly let us know how it goes.

Ahh okay, I have made that change and still does not work. Here is what I have done:
In the “Post Scroll Slider” I have my Looper Provider set as Query String. The string I am using is:
post_type=releases&meta_key=artist&orderby=meta_value&order=ASC&meta_query%5B0%5D%5Bkey%5D=artist&meta_query%5B0%5D%5Bvalue%5D=%7B%7Bdc%3Aacf%3Apost_field+field%3D%22artist%22%7D%7D&meta_query%5B0%5D%5Bcompare%5D=%3D%3D

But all it shows is the current post in slider. Not sure what I am missing?

Also since changing the return format to post ID it has broken the relationship in Release Layout. I was doing that this way:
Looper provider is Dynamic Content:
{{dc:acf:post_field field=“artist”}}

Then for the related artist title I am doing this:
{{dc:post:title}}

I will include link in secure note.

Thanks

I have also tried different variations of using the condition to try and limit showing releases only to the current post name with no luck. Really need to get this working or will need to try a different solution.

Thanks

Still not working, I have tried several different ways. Can you please take a look and help?

Thanks so much

Following up here, I used http build query to generate a query string using this object :

$data=array(
			'post_type' 		=> 'releases',
			'meta_key'			=> 'artist',
			'orderby'			=> 'meta_value',
			'order'	 			=> 'DESC',
			'meta_query'		=> array(
				array(
					'key'		=> 'artist',
					'value'		=> '{{dc:acf:post_field field="artist"}}',
					'compare' => '==',
					'type'		=> 'NUMERIC'
				)
			),
		);

This generated the string:

post_type=releases&meta_key=artist&orderby=meta_value&order=DESC&meta_query%5B0%5D%5Bkey%5D=artist&meta_query%5B0%5D%5Bvalue%5D=%7B%7Bdc%3Aacf%3Apost_field+field%3D%22artist%22%7D%7D&meta_query%5B0%5D%5Bcompare%5D=%3D%3D&meta_query%5B0%5D%5Btype%5D=NUMERIC

This does not work, however if I hard code an artist ID in like so:

$data=array(
			'post_type' 		=> 'releases',
			'meta_key'			=> 'artist',
			'orderby'			=> 'meta_value',
			'order'	 			=> 'DESC',
			'meta_query'		=> array(
				array(
					'key'		=> 'artist',
					'value'		=> '2580',
					'compare' => '==',
					'type'		=> 'NUMERIC'
				)
			),
		);

and get this string:

post_type=releases&meta_key=artist&orderby=meta_value&order=DESC&meta_query%5B0%5D%5Bkey%5D=artist&meta_query%5B0%5D%5Bvalue%5D=2580&meta_query%5B0%5D%5Btype%5D=NUMERIC&meta_query%5B0%5D%5Bcompare%5D=%3D%3D

It works, so something is up with
{{dc:acf:post_field field="artist"}}

Return format for Artist meta is Post ID. However if hard coded the artist ID the Post Object return still works and I like the Post Object return because I am pulling the artist name on another part of the site and it only works with Post Object. So I would prefer if it could work that way.

Please take a look and let me know if you have another suggestion.

Thanks

Hi @wowflak,

I would suggest you set the Return Format to Post ID as suggested by my colleague.

Thanks

That is exactly what I have done if you read the post above. I have tried both ways with Return Format set to Post ID and also Post Object (my preference would be to have return as post object but will take anything that works at this point). Neither work when I use {{dc:acf:post_field field="artist"}} It returns nothing. If I hard code an artist ID in the string it will return that artists releases. So I know the string works it just does not work with the dynamic content.

Further info on the need for Post Object - I use the Artist name in another Layout for the Release. So in that layout the album (release) pulls the related artist name in and I need that to be returned as a name and not a ID. If return is set to Post ID on artist field it returns just the name of current post and not Artist name (method described here https://theme.co/forum/t/dynamic-acf-relationship-fields-between-2-cpts/93522/6. )So if I need to return Post ID in order to get the relationship working on the Artist post type Layout than that screws up the Release post type Layout. I will share links again to pages in secure note.

Please take a look and advise on next steps, I feel I have tried all suggestions so far.

Thanks

Hi @wowflak,

I have checked and found that the {{dc:acf:post_field field="artist"}} is returning the Post ID while the Artist is set to the Post ID.

I have added a section with the same query you have provided and printed the {{dc:looper:debug_provider}}, please find the details of the query that was executed against your string by clicking on the spider icon in the Page Builder.
I have hidden the section in all the breakpoints as it shows the output in the frontend, you need to deselect the specific breakpoint from the Customize option and click into the spider icon.

Hope it helps you to construct your Query String.

Thanks

Not sure I understand this. First of all you ran this query inside the Release Layout and I need this query to work on the Artist Layout. The Release Layout is set to work with only Release Post Type. My issue is not with the Release Layout. The {{dc:acf:post_field field="artist"}} works on its own in Release Layout because that layout is set to work on CPT Release which contains that ACF field in it.

I want the Post Scroll Slider to work on my Artist Layout. The query string suggested by you does not work with the {{dc:acf:post_field field="artist"}} Please look at the Artist Layout which contains this query string post_type=releases&meta_key=artist&orderby=meta_value&order=DESC&meta_query%5B0%5D%5Bkey%5D=artist&meta_query%5B0%5D%5Bvalue%5D=%7B%7Bdc%3Aacf%3Apost_field+field%3D%22artist%22%7D%7D&meta_query%5B0%5D%5Bcompare%5D=%3D%3D&meta_query%5B0%5D%5Btype%5D=NUMERIC inside of the Post Scroll Slider looper provider.

To reiterate the Artist Layout is for the CPT Artist. The artist has multiple releases (CPT is Releases) that are connected to it via a ACF field called “artist”. I want the Post Scroll Slider to only pull those releases that are related to the artist while on the artist page. So if artist name is Joe Blow then we should only see Releases related to Joe Blow on the Joe Blow Artist page.

Example of Artist page here:


Slider is just below socials and tour dates.

Can anyone please help with this, going on many days now.

Thanks

Please can someone help me sort this out. This has been back and forth for days. Should I start a new thread?
Thanks

Hi @wowflak,

I am another stuff checking this thread. I am not quite sure If I understand correctly your issue but if you want to display a post related to the ACF post object inside a repeater then it will require 2 looper providers to do that.

Let say for example on your page https://frlstesting.wpengine.com/artists/starset/, I select 3 post objects from the release CPT.

If you want to display them on the artist single page, your structure should look like this one.

  • Looper Provider - ACF Key Repeater Field (Post Carousel Scroll Slider)
    – Consumer (Slide Container)
    — Looper Provider- Looper Consumer - ACF repeater subfield ( Slide)
    ---- Image
    ---- Text

This is the dynamic code for the image {{dc:post:featured_image}} and {{dc:post:title}} for the title.

You can check the example I have made at the bottom of this page: https://frlstesting.wpengine.com/artists/starset/

Please let us know if that’s what you wanted. If not, please give us more insights.

Hope that helps.

Thank you for responding but that is not quite it. In this example the Artist is Starset and I only want to show releases from the Artist Starset on the page. On the Artist page for Wage War I only want to show releases by Wage War. To access those releases I need to query the Releases CPT custom fields. Specifically the field Artist which is the relationship to the release.

So I have a CPT called Artist and I have a Layout called Artist Layout for the Artist CPT. Now in that layout I have a Post Scroll Slider and inside that slider I want it to show Releases only by the current post Artist. I need to access the Post Object called Artist inside of the Release Fields for the CPT called Releases. This Artist Field is the name of the artist whose release this belongs to. I do not need to access the Artist Fields for CPT Artists which is what you did in the latest example.

The CPT Releases are the records made by the artists.

This is why I was pointed down the path of Query String which you can read about above.

This is suggested string post_type=releases&meta_key=artist&orderby=meta_value&order=DESC&meta_query%5B0%5D%5Bkey%5D=artist&meta_query%5B0%5D%5Bvalue%5D=%7B%7Bdc%3Aacf%3Apost_field+field%3D%22artist%22%7D%7D&meta_query%5B0%5D%5Bcompare%5D=%3D%3D&meta_query%5B0%5D%5Btype%5D=NUMERIC
However this does not return anything.

I realize with the name Artist used in different places this can be confusing so let’s break down here:

CPT = Artist (I have layout for this but need to access custom field in the CPT Releases in order to show relationship between artist and associated releases inside of post scroll slider)

CPT= Releases (This has the custom field called "Artist" that I need to query in order to return associated releases on Artist CPT page)

I hope this is clear, please let me know.

Thanks again

Hi @wowflak,

Sorry for my previous response and thank you for explaining everything. I have fully understood your issues. The reason why your query is not valid because when we try to run this query.

$data=array(
			'post_type' 		=> 'releases',
			'meta_key'			=> 'artist',
			'orderby'			=> 'meta_value',
			'order'	 			=> 'DESC',
			'meta_query'		=> array(
				array(
					'key'		=> 'artist',
					'value'		=> '{{dc:post:id}}',
					'compare' => '==',
					'type'		=> 'NUMERIC'
				)
			),
		);

It will generate this string:

post_type=releases&meta_key=artist&orderby=meta_value&order=DESC&meta_query%5B0%5D%5Bkey%5D=artist&meta_query%5B0%5D%5Bvalue%5D=%7B%7Bdc%3Apost%3Aid%7D%7D&meta_query%5B0%5D%5Bcompare%5D=%3D%3D&meta_query%5B0%5D%5Btype%5D=NUMERIC

Then the value {{dc:post:id}} is no longer a valid Dynamic Content because it was replaced with this one %7B%7Bdc%3Apost%3Aid%7D%7D. That being said, we need to encode the query string first then once we are done creating our query string that’s the time we add the Dynamic Content in the right place.

The correct Query String should look like this one:

post_type=releases&meta_key=artist&orderby=meta_value&order=DESC&meta_query%5B0%5D%5Bkey%5D=artist&meta_query%5B0%5D%5Bvalue%5D={{dc:post:id}}&meta_query%5B0%5D%5Bcompare%5D=%3D%3D&meta_query%5B0%5D%5Btype%5D=NUMERIC

Please note I change the {{dc:acf:post_field field=“artist”}} to {{dc:post:id}} because that’s the right Dynamic Content to get the ID of the current Artists.

You can check again the test I have made at the bottom of this page: https://frlstesting.wpengine.com/artists/starset/

Hope that helps.

Thank you!! I also see it appears to work with Post Object as the return. That is great news! Really appreciate it and the explanation.

Hi @wowflak,

You’re welcome and it’s our pleasure to help you! If you have any other concerns or clarifications regarding our theme features, feel free to open up a new thread.

Thank you.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.