Seems you got it to work, could you post your final code? Thanks! 🙂
You can copy ACF into your plugin folder and include it (http://www.advancedcustomfields.com/resources/how-to/including-acf-in-a-plugin-theme/):
include_once('advanced-custom-fields/acf.php' );
Might be a better way…
Add to functions.php (http://www.advancedcustomfields.com/resources/functions/acf_set_options_page_title/):
if( function_exists('acf_set_options_page_title') )
{
acf_set_options_page_title( __('Theme Options') );
}
cheers
Didn’t realize had already been solved and one year old. Oops..
Try this… not my code, but should remove menu items for everyone except admin (goes in functions.php):
function remove_menus()
{
global $menu;
global $current_user;
get_currentuserinfo();
if($current_user->user_login != 'admin')
{
$restricted = array(__('Posts'),
__('Media'),
__('Links'),
__('Pages'),
__('Comments'),
__('Appearance'),
__('Plugins'),
__('Users'),
__('Tools'),
__('Settings'),
__('Options')
);
end ($menu);
while (prev($menu)){
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
}// end while
}// end if
}
add_action('admin_menu', 'remove_menus');
I just did the same thing, below is how I did it. Since Elliot added the have_rows function in 4.3 (http://www.advancedcustomfields.com/resources/functions/have_rows/) it’s much easier to get it to work. My code might not be optimal (been up too long…), but it works.
<?php
$rows = get_field('reaction_videos');
if($rows) {
echo '<h3 class="reaction">Reaction Videos</h3>';
echo '<ul>';
while(the_sub_field('reaction_videos')) {
$video = the_sub_field('reaction_video');
$desc = the_sub_field('reaction_video_desc');
echo '<li><a href="' . $video . '" title="' . $desc . '" class="lightbox" rel="foobox">' . $desc . '</a></li>' ;
}
}
?>
Hi, sorry for not being clear. I am using the field group to create a table of contents, and then the data entered is displayed via a custom template.
Anyway I can send you the login info?
I am using 1 field group for the custom post layout, and then several field groups as table of contents.
Each table of contents field group displays post in a custom post type added to a specific category.
So e.g. I have a custom post type called Athletes. Each athlete is categorized (Soccer player, Runner, etc.) and displayed to the user based on the 1st Field group is set up (it might have a age field, a repeater for wins, etc.).
Then theres a Field group for each type of sport thats set up to list the Athletes, show a photo, and a small bio.
Now let’s say you have someone adding all the athletes, and he/she needs to add more ToC Field Groups for other sports (Basketball, Baseball, etc.).
How can i let them do that without giving them full admin rights? I thought I could maybe use the Options Page add-on to add new field groups.
Hope that makes sense and thanks a lot for your help!
Thanks great to hear 🙂
Ended up just coding it using: http://www.tcbarrett.com/2013/05/wordpress-how-to-get-the-slug-of-your-post-or-page/
I figured it out 🙂
Just duplicated the field group. Then added taxonomies to the custom post type. Now have the large table split into smaller section. Each gets a field group that only displays if the custom post type post containing the table info is posted in a specific category.
Know this probably doesn’t make sense, but thanks anyway 🙂
Hi.
sorry for the late reply.
I am using a custom post type (just one post) to enter all the info for the table of contents. Then in my template I am pulling the entered info from that particular post using the post number like this:
<?php
if( get_field('repeater', 128) )
{
$i = 1;
while( has_sub_field('repeater', 128) )
{
$link = get_sub_field('sub_field_1');
$desc = get_sub_field('sub_field_2');
echo ...
$i++;
}
}
?>
Because the single post where I am entering the info is getting so big, I want to instead create a custom post type for each section of the table of contents. I can easily do this for new stuff that I need to add, but the stuff that I have already added I would like to move some of the entered info to a new post type.
I am using a post type just so it’s easier later to see where the info needs to be entered.
Sorry for my poor explaining, let me know if I’m still not making sense. Thanks!
Nice job! I ended up getting it to work, but using the shuffle function is so much easier lol. Think I was trying to shuffle the caption and color each at the same time, while you are just shuffling the row number with the row content.
Glad you got it to work! 🙂
Will refer back to this, need to do something similar with my project.
Give me one sec, goning to test something on my site.
Ah think it makes sense now… forgive my previous mistakes, was confused about your objective 😛
So I think I get it know:
You enter each caption and then choose a color corresponding to that caption right? So you enter caption 1 and choose the image for that caption to be grey.
In that case, this is what you want to do:
<?php
$template_directory = bloginfo('template_directory');
$rows = get_field('slider_image');
if($rows) {
echo '<ul>';
$i = 0;
while(has_sub_field('slider_image')) {
$field = get_sub_field_object('logo_colour');
$value = get_sub_field('logo_colour');
$label = $field['choices'][ $value ];
echo '<li>' . $rows[$i]['the_caption'] . '</li>';
echo '<li><img src="'. $template_directory . '/logo_'. $label . '.png" /></li>';
$i++;
}
echo '</ul>';
}
?>
Should have probably asked this before, but is:
the_caption – > text box?
colour_type -> Select with choices gray or white?
This is the updated code:
<?php
$rows = get_field('slider_image' );
$sub_field = has_sub_field('slider_image');
$rand_row = $rows[ array_rand( $rows ) ];
$logo_colour = get_sub_field('logo_colour');
$caption = get_sub_field('the_caption');
$template_directory = bloginfo('template_directory');
if($rows) // if slider_image exits
{
echo '<h3>Header</h3>';
echo '<ul>';
while($sub_field) // enables us to use get_sub_field
{
$rows = $rand_row['slider_image']; // random order of rows
foreach ($rows as $row) {
echo '<li>' . $caption . '</li>'; // displays caption
if(($logo_colour) == "white") { // displays white logo if selected, else grey
echo '<li><img src="'. $template_directory . '/logo_white.png" /></li>';
} else {
echo '<li><img src="'. $template_directory . '/logo_grey.png" /></li>';
}
}
echo '</ul>';
}
}
?>
And get rid of:
$row_count = count($rows);
So change:
$row_count = count($rows);
$rand_row = $rows[ array_rand( $rows, $row_count ) ];
Back to:
$rand_row = $rows[ array_rand( $rows ) ];
Sorry I meant:
$rows = $rand_row['slider_image'];
Ah k, well hopefully this works 🙂
Change:
$rows = $rand_row;
To:
$rows = $rand_row($rows);
If that doesn’t work, I can get it to work a different way.
Is it still not stopping loading or now not loading? If it’s not stopping loading, does it at least load it correctly (meaning in random order).
Hi, forgot to set a limit to the array… for my use I was using a for loop.
Change:
$rand_row = $rows[ array_rand( $rows ) ];
to:
$row_count = count($rows);
$rand_row = $rows[ array_rand( $rows, $row_count ) ];
Did you try uploading it? What error message does it display?
This should work. Put it in a list for now, will have to change that.
<?php
$rows = get_field('slider_image' );
$sub_field = has_sub_field('slider_image');
$rand_row = $rows[ array_rand( $rows ) ];
$logo_colour = get_sub_field('logo_colour');
$caption = get_sub_field('the_caption');
$template_directory = bloginfo('template_directory');
if($rows) // if slider_image exits
{
echo '<h3>Header</h3>';
echo '<ul>';
while($sub_field) // enables us to use get_sub_field
{
$rows = $rand_row; // random order of rows
foreach ($rows as $row) {
echo '<li>' . $caption . '</li>'; // displays caption
if(($logo_colour) == "white")) { // displays white logo if selected, else grey
echo '<li><img src="'. $template_directory . '/logo_white.png" /></li>';
} else {
echo '<li><img src="'. $template_directory . '/logo_grey.png" /></li>';
}
}
echo '</ul>';
}
?>
Sorry, missed the caption field. So if I understand correctly you want the order of the img and the caption to be random?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.