Support

Account

Forum Replies Created

  • This reply has been marked as private.
  • Hi John, Thanks for the note about the typo. However, it still doesn’t really help me because I don’t think I’ve formatted the entire code correctly. Your code makes no reference to the fan_artist relationship field, which is why it’s only going to output the Collection itself. So, looking at my code, where am I meant to put your code exactly, while also referencing the fan_artist relationship – which is connected to the fan_art relationship that is in the add_to_collection relationship? I really need to whole code to learn from this.
    I appreciate it might be a fair bit of code but I’m sure all the ingredients are there, it’s the formatting I’m struggling with.

    Thanks.

  • This is the code I ended up with based on what I assumed the structure should be:

    <?php
    
    $items = get_field('add_to_collection');
    
    	if($items) {
    
    		foreach ($items as $i) {
    
    		$artists = get_field('fan_artist', $i->ID);
    		$size = 'lisf_thumbnail';
      		
    			if($items) {
    
    			$collected_artists= array();
    
    				foreach ($items as $item) {
    
    					if (!is_array($item->ID, $collected_artists)) {
    					
    					$collected_artists[] = $item->ID;
    					
    					}
    				}
    			}
    		}
    	}
    
    	if ($collected_artists) {
    
    		foreach ($collected_artists as $artist_id) {
    
    		echo get_permalink($artist_id->ID); echo get_the_post_thumbnail($artist_id->ID, $size);
    
    		echo get_permalink($artist_id->ID); echo get_the_title($artist_id->ID); 
    		}
    	}
    
    ?>

    I’m sure it’s wrong but I can’t necessarily figure out why. It’s outputting the data for the Collection itself instead of the Fan Artist for one, no matter which return format I use.

    Also, I refer directly to the Fan Artist relationship in the $artists variable but don’t repeat it further down, as in your code you have $items/$artist_id

    When using the brackets system for if statements etc, it also won’t let me use html within the code. How can I use html with this formatting?

    Lastly, I’m getting this PHP warning too:

    “Warning: is_array() expects exactly 1 parameter, 2 given in… etc”

    I’m sure it’s getting close but, as I say, I just need help with the formatting/structure because I can’t figure it out so I’d really appreciate it if you could post full code for how you think it should be.

    Thanks a lot.

  • Hi John. Thanks for the response. I’m still struggling to get this working but I think it’s more to do with my inexperience in how to correctly format the whole code. I wasn’t using brackets for the if and foreach statements in my code, but you have in yours and you did use some different variable names to mine, and I’m also unsure what $artist_id is referring to in your code. Is that replacing $artist in my code?

    I’d really appreciate it if you could post the whole code as you think it should be based on combining my code with your suggested code.

    Which return value should I be using for the relationships too? Post Object or Post ID?

    Thanks.

  • Anyone have any thoughts on this please? Thanks.

  • Thank you so much John, that was it. Mystery solved!

  • I did actually manage to get this working, for displaying the display_name at least. The final code I used was:

    <span class="staff-note-label">Note Added By:</span>
    <?php
    $user = get_sub_field("staff_member");
    
    if( $user ): ?>
    
    <span class="staff-note-name"><a href="<?php echo $user['user_url']; ?>"><?php echo $user['display_name']; ?></a></span>
    
    <?php endif; ?>

    I’m unable to get the url to the User’s profile though. The url is showing as the current post url. I’m sure that user_url is the right meta and I noticed there’s code for the user_url in the multiple selected users example at:

    https://www.advancedcustomfields.com/resources/user/

    But I tried it with a multi select user field as well and used the second example code and the link is still for the current post and not the user profile url. How can I get the link for the user’s profile in this context?

    Thanks.

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