Community Forums › Forums › Archived Forums › General Discussion › Problem With Custom Fields Arrays
Tagged: cfs, custom field suite, genesis custom fields, nickthegeek
- This topic has 12 replies, 2 voices, and was last updated 10 years, 6 months ago by Brad Dalton.
-
AuthorPosts
-
March 23, 2014 at 10:37 am #96193TreefungusMember
Hi
I am using a plugin called Custom Field Suite by Matt Gibbs at http://uproot.us/. CFS is a lightweight version of ACF and super easy to use.
When wanting to for example display a text field front end then the plugin author provides this code:
<?php echo $cfs->get('field_name'); ?>
This won't work unless I use the genesis_get_custom_field instead of $cfs->get .
I of course rewrite the code into a function for Genesis.I saw that I had to use genesis_get_custom_fields on Nick The Geek's post which you can find here: http://designsbynickthegeek.com/tutorials/how-i-make-custom-fields-easier
However Nick mentioned that genesis_custom_fields does not work well with arrays so I am having trouble displaying this code taken from the plugin author's website:
<?php
$fields = $cfs->get('test');
foreach ($fields as $field) {
echo $field['test1'];
echo $field['test2'];
}
?>I have tried swapping out the $cfs->get with genesis_get_custom_field but nothing is showing.
So here is the exact code I am using on Genesis site:
add_action('genesis_after_header', 'test_content');
function test_content() {
$fields = genesis_get_custom_field('test');
if (!empty($fields)) {
foreach ($fields as $field) {
echo $field['test1'];
echo $field['test2'];
}
}
}I had to add if (!empty($fields)) as I was getting an error.
Does anyone know what to do? I am wondering why I cannot use the plugin's code example. Why do I need to use genesis_get_custom_field? I have tried his code on TwentyFourteen theme and it works fine. So it is not my settings with the plugin nor his code that is wrong or least I don't thing so.
Appreciate any help I can get.
March 23, 2014 at 12:38 pm #96205Brad DaltonParticipantGood question and i would like to see some sample code snippets added to the SP Code Snippets page.
Firstly, please use Github Gists to embed your code here as it cannot be copied from this page and pasted into a test installation without causing errors.
What do you actually want to do with custom fields?
March 23, 2014 at 12:50 pm #96206TreefungusMemberHi Brad
Sorry for not using Github Gists. Here is the code
https://gist.github.com/anonymous/9727841
I actually want to do several things with custom fields. One being a staff page. It is too difficult for the client to work in the text-editor with div class after div class which is needed to make the staff page look nice. So by using custom fields I can "pre style" everything and the client just need to add the info into the custom fields.
If you want I can provide login details for the test-site if that makes it easier for you.
Thanks
March 23, 2014 at 12:58 pm #96209Brad DaltonParticipantHere's a very basic example of what i use.
Here's my staff page http://wpsites.net/web-design/team-members-staff-authors-or-user-profile-page-template-for-genesis/
Like the idea of custom fields for a staff page.
You can change loop_start to any WordPress or genesis_hook
March 23, 2014 at 1:07 pm #96211TreefungusMemberI couldn't get the code to embed so just linked to the file. I hope that was okay. I accidentally added too much code but it won't ruin anything.
Looks good your staff page.
Yes thanks for the code example above. I can display my single custom field using this
but when using the loop field from this
then I cannot show anything. The loop is great as I can set up the loop-group with Name, Title, image, job description and so on. Where I have added div classes to these in the function.php. When client then hire another staff he just clicks "add new staff" on the staff page and a new loop group appears where he can fill out the staff name, title and so on. Makes sense?
March 23, 2014 at 1:16 pm #96218TreefungusMemberSorry I still can't embed the code but I can link to it. Hope that is ok.
That staff page is nice. Well done.
I have used similar code to the one u have provided. See code here:
However I really want this loop-field to work. Not genesis loop as we know but a loop because its called loop by the plugin author. You can see the loop code here:
How it works is really smart. I want to create a loop-group if can I call it that. That contains custom fields like name, title, job description and so on. Then pre style them in function.php when I echo the custom fields out. Creating the loop-group is easy but I cannot display them. Thats my problem I have. But this loop-group is really smart because the website owner then just click new staff and a new loop-group appears on the staff page. He then fills out the name, title and so on. Click publish and the new staff is added to the page and already styled. No need to work with html.
March 23, 2014 at 1:26 pm #96223TreefungusMemberWhy does my post no show up. Fourth time I write this. Now I will write in text edit on mac and then save it.
That is a nice staff page. Well done.
I have used similar code like you to display one custom field.. You can see that here.
But I really want the loop to work. This is not loop like we know from genesis loop. But a function in the plugin CFS. I create a loop-group that contains several custom fields like name, title and job description. I then style and echo them out in function.php. When client then wants to add a staff on the staff page he just click new and a new loop group appears with the custom fields. He fills name, title and job description out and click publish on the staff page. The details will then appear styled. No need to work with html markup.
Link to the plugin with the loop details can be found in link belowMarch 23, 2014 at 1:27 pm #96224TreefungusMemberMarch 23, 2014 at 2:11 pm #96240Brad DaltonParticipantMarch 23, 2014 at 2:18 pm #96242TreefungusMemberThey were a link to github showing the code I used to display a single custom field. So that is ok.
The other link was to uproot.us site explaining the loop field.
I inserted them using the link button in the wysiwyg.
Thanks for looking into this Brad.
March 25, 2014 at 6:55 am #96215TreefungusMemberThis thread is not my friend today. I think I lost my reply.
I cannot embed my code so have to link to it. Sorry about that.
That staff page looks nice.
I have used similar code like you to display a single field.
However when I use the loop field found here:
Then I cannot get it to work. Nothing shows up.It is a shame because I want to setup a loop-group if I can call it like that that contain custom fields like name, title, job description and so on. When the client then hires a new staff he just clicks "add staff" on the staff page and a new loop-group comes up and he fills out the fields. All fields are then pre-styled in the function.php making it super easy to maintain the staff page.
March 26, 2014 at 3:24 am #96694TreefungusMemberPlugin author came back with solution. So if anyone has a similar problem then here is the correct code.
https://gist.github.com/anonymous/9779510Plugin author did actually have a trouble shooting guide regarding my problem which I only found after. Doh.
Link to that: https://uproot.us/docs/troubleshooting/But nonetheless thanks for helping out Brad.
March 26, 2014 at 9:44 am #96740Brad DaltonParticipantI have asked them to publish some code snippets which work with Genesis which once done, i will also publish on my site.
Thanks for sharing a link to the code.
-
AuthorPosts
- The topic ‘Problem With Custom Fields Arrays’ is closed to new replies.