Recipe for displaying site field sets?

This topic is: resolved
Viewing 8 posts - 1 through 8 (of 8 total)
Author Posts
June 29, 2013 at 2:03 am #3253
Michelle
Post count: 11

Hi, not sure if this is a question or suggestion but is there a ‘code recipe’ for accessing field sets not associated with a post/page/type – ie Site Field Sets? That would be very helpful.

In particular, I’m trying to loop through a multi-item field set in the Site Field Sets. I think the loop is working correctly, but it’s returning two blank records instead of the images:

This code is in my footer.php file: http://pastebin.com/yjX6z4Vk

My Site Field Set is set up like htis:
footer_icons
-> logo_image
-> logo_link
-> hover_text

Thanks for your help!

June 29, 2013 at 4:14 am #3255
Michelle
Post count: 11

Okay, I’ve made a bit of progress. Using this code within the foreach loop, I can get an img tag to spit out:

echo $wf->site->field(“footer_icons.logo_image”);

BUT, the path to the image is incorrect – it doesn’t account for me working on a Windows localhost/WAMP installation and uses backslashes instead of forward slashes for the latter half of the URL:

http://localhost/webber/wp/wp-content/mp/uploads%5Csite%5Cimages%5Clogo-ut-austin.v1.gif

Any ideas? Thank you!

(PS I have updated to the latest beta to see if that fixed it but nothing changed.)

  • This reply was modified 11 years, 1 month ago by Michelle.
June 29, 2013 at 4:50 pm #3259
traversal
Post count: 207

You’re quite right about the site code, that’s exactly how you do it 🙂

Sorry about the image path thing – will check this in Windows again, and let you know when a fix is available.

June 29, 2013 at 4:51 pm #3260
traversal
Post count: 207

Actually, you don’t have to call “field” strictly in your code. Can also do:

$wf->site->footer_icons->logo_image

July 3, 2013 at 2:18 am #3263
Michelle
Post count: 11

Cool, thanks! I’ll look for the update – it’s making developing the site pretty tough not to have that working. 🙂

July 3, 2013 at 2:33 am #3264
Michelle
Post count: 11

Oh – and sorry – I’m still not getting how this should work, even if the paths were correct. See this pastebin for my updated code:

http://pastebin.com/BdFPPGNi

When I use this, it doesn’t loop correctly; it just outputs the first submitted entry multiple times. I tried using the code from example #4 on this page: https://www.masterpressplugin.com/docs/developer/recipes/field-sets-and-fields (see my original Pastebin above) but that didn’t work either. What am I missing?

Thanks!

Michelle

July 3, 2013 at 5:26 pm #3268
traversal
Post count: 207

Hey Michelle,

The code for the loop is slightly wrong. By reaccessing $wf->site->footer_logos, you’re actually accessing only the first item in that set each time. This is by design – we decided that if you access a field in a multi-item set like that, it would access the field from the first record in the set, which can be handy at times.

You need to use the $footer_logo loop variable each time, so your code should look something like this:

http://pastebin.com/Hk1UNgHc

Hope that helps.

I still haven’t had a chance to check the Windows issue, but will look at it soon. Sorry!

July 4, 2013 at 4:16 am #3269
Michelle
Post count: 11

Thanks so much Travis! That (+ the WAMP path fix) works great. Whew! 🙂

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

You must be logged in to reply to this topic.

Latest From the Blog

MasterPress 1.4.1 is now available

27th May 2024

This update addresses backwards compatibility issues that were introduced in the previous update. There were some edge cases where PHP 7 had issues and it didn’t work at all on PHP 5.6. We have now changed it so that the PHP 8 compatibility changes will now only affect PHP 8 and will be more thorough… 

Plugin Requirements

MasterPress requires a minimum of WordPress version 4.9, MySQL 5.6, and PHP version 5.6.20.

We also recommend that PHP is configured to use a memory limit of 64MB per request (128MB may be required for sites with higher complexity).

This plug-in is not compatible with the WordPress.com hosted service.

Three AM