-
jjc710
Hello All,
I am working on a project where I am attempting to display content based on ACF relationships.
I have a CPT: Superstar
And another: Company.I am trying to show the company on the superstars post, and the superstars on the company post. I have followed previous tutorials such as:
https://generate.support/topic/can-i-query-posts-from-an-acf-relationship-field/#post-111633
But I get the following php errors:
Any clue how to resolve this?
Thanks!
-
David
Hi there,
in your ACF Field make sure the Return Format is a Post ID.
-
jjc710
Hi there,
thanks for the reply. That solved the error, however, nothing is being displayed.
Please see the screenshots:
and the code:
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) { if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'display-company-name' ) !== false && ! is_admin() ) { // get the relate post ID $current_post = get_the_ID() ; $relationship = get_field( "display_company", $current_post ); // Merge the current $query_args with the new args return array_merge( $query_args, array( 'post__in' => $relationship, ) ); } return $query_args; }, 10, 2 );
Any clue why this still is not displaying the related company?
-
David
The
display-company-name
class has to be attached to the Grid Block that is inside of the Query Loop and not the Posts Template. Can you confirm thats the case ? -
jjc710
I believe this is correct:
-
David
Ok, so it would suggest that the code isn’t returning any values.
To debug that change the code to:add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) { if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'display-company-name' ) !== false && ! is_admin() ) { // get the relate post ID $current_post = get_the_ID() ; $relationship = get_field( "display_company", $current_post ); var_dump($relationship); // Merge the current $query_args with the new args return array_merge( $query_args, array( 'post__in' => $relationship, ) ); } return $query_args; }, 10, 2 );
The only change is the addition of:
var_dump($relationship);
If it contains anything it will dump the value on the front end -
jjc710
C:\wamp64\www\spoilerfanatic\wp-content\plugins\code-snippets\php\snippet-ops.php(582) : eval()'d code:10:null
It’s returning null, I would assume. But the values are set, so Im confused as to why it isn’t returning anything.
-
jjc710
C:\wamp64\www\spoilerfanatic\wp-content\plugins\code-snippets\php\snippet-ops.php(582) : eval()'d code:10: array (size=1) 0 => int 33
And this is on a different post with the same settings.
-
It seems the 1st post does not have any related company set, and the 2nd post has one and its post ID is 33.
Can you provide an admin login for us to check the backend settings?
-
jjc710
Unfortunately its on my PC so I can not provide a url to login.
Even with the companies set (see below screenshot), nothing is being displayed on the post. It’s just blank:
As you will see: The company name is set (that company ID is 33, so the vardump showed it correctly.) But, it was not and still is not displaying the company name attached to the related company as evident in the 2nd screenshot above.
What would cause that? And how do I fix?
Thank you!!
-
Even with the companies set (see below screenshot), nothing is being displayed on the post. It’s just blank:
Where is the query loop block located?
But, it was not and still is not displaying the company name attached to the related company as evident in the 2nd screenshot above.
The editor does not know about the code you added, so no, it won’t show anything.
Does it show on the frontend? -
jjc710
The query loop block is located in an element for the single post. I have set it to “content template”, loop template, neither have displayed results on the front end.
No, that’s the issue I am having. It’s not displaying anything on the front end.
-
I would have to check the backend to know what the issue is, unfortunately.
Any chance you can put the site online?
And as you are using GP elements, it’s a GP Premium feature, can you also add the GP support key to your profile? Thanks!
-
jjc710
Hmm not sure of a way to get it online immediately. Is there anything specific I can screenshot and show that hasn’t already been posted in this thread that would indicate why it isn’t showing on the frontend?
-
Can you show me the settings for the query loop block in the element?
Let me know 🙂
-
jjc710
- You must be logged in to reply to this topic.