Forum Replies Created

  • Thanks for helping pinpoint this, we were facing this exact issue but are developing within a plugin rather than a template which prevents us from putting the function at the top of the template file we wanted.

    What we found, rather than adding to init is to inject into wp_head with a priority of 1 to force it to appear first. Figured I’d add here as well just to give some alternative options.

    add_action( 'wp_head', 'inject_acf_form_head', 1 );
    function inject_acf_form_head( ) {
  • Hi @svsdnb,

    No – I hadn’t done, but you could effectively just add that to the code to replace the meta query that checks that time EXISTS with something more akin to the date check.

    $todays_date = current_time('Ymd');
    $right_now = current_time('Hi');
    $args = array(
        'post_type' => 'events',
        'posts_per_page' => '-1',
        'meta_query' => array(
            'relation' => 'AND',
            'date_clause' => array(
                'key' => 'event_date',
                'compare' => '>=',
                'value' => $todays_date,
            'time_clause' => array(
                'key' => 'event_time',
                'compare' => '>=',
                'value' => $right_now,
        'orderby' => array(
            'date_clause' => 'ASC',
            'time_clause' => 'ASC',

    I have yet to look at the Time picker field as part of the latest version, but something akin to that should work fine.

  • Thanks for voting that as the solution!

    With regards to your date/time issue, I personally used the 24 hour clock as it was easier, especially for sorting. To output it differently though, you can grab the time and then reformat it using the DateTime::createFromFormat function (

    // format Hi is 24 hour format hours and minutes, both with leading zero
    // i.e. 1630, 0625, 1942 etc.
    $event_time = DateTime::createFromFormat('Hi', get_field('event_time') );
    //Output in 12 hour format without leading zeros and with am/pm.
    // i.e. 12.30pm,  9.12am,  6.05pm
    echo $event_time->format('g.ia');
  • In an interesting twist of fate, I’m doing this exact thing for my client as well – so I’ll update this and confirm if the above works, or if not, what I did instead.


    Ignore my previous post, I found a more practical way of doing this here:

    WP core have revamped the orderby function to accept array inputs, so after a bit of poking around, this is the method that I’ve used and confirmed:

    $todays_date = current_time('Ymd');
    $args = array(
        'post_type' => 'events',
        'posts_per_page' => '-1',
        'meta_query' => array(
            'relation' => 'AND',
            'date_clause' => array(
                'key' => 'event_date',
                'compare' => '>=',
                'value' => $todays_date,
            'time_clause' => array(
                'key' => 'event_time',
                'compare' => 'EXISTS',
        'orderby' => array(
            'date_clause' => 'ASC',
            'time_clause' => 'ASC',
  • My immediate thought is that this is probably being called outside of the loop, which means that you’ll need to add an extra parameter to the have_rows() to also reference the Post ID, so it knows which post to look for the information in.

    In practice this would look like the following:

    global $post;
    if( have_rows('testmon', $post->ID ) ):
     	// loop through the rows of data
        while ( have_rows('testmon', $post->ID ) ) : the_row();
            // display a sub field value
    else :
        // no rows found
  • In this instance the problem is in different code for using ways of starting and finishing a loop.

    The standard way of doing this is to use curly brackets, which ends up with something that looks like the following

    if( have_rows('repeater_field') ){

    The alternate way of doing this is a shorthand way of opening/closing loops. This can make the code easier to read, and helps to differentiate which brackets are doing what. Some people like it, some don’t – it’s all down to personal style really. The same example in alternate style looks like this:

    if( have_rows('repeater_field') ) :
    	while('repeater_field') :

    The important thing is that you pick whichever one you prefer and stick with it. In your example – the while() loop has already opened with the alternate format, but it then opens/closes in standard format. To fix your whitescreen, removing those brackets and replacing the final one with “endwhile;” will stop the loop from hanging.


    Actually I also just noticed that you have a curly bracket opening underneath global $post; There’s no need for this, if you remove it and then remove one of the curly brackets at the end.

    Often what I will do is go through a function if I’m ever lost and just count the brackets on my fingers. Add one for every curly open bracket, remove one for every closing bracket. You should end up on 0.

    function sal_display_code_grid_item() {
        global $post;
            echo( '<div class="outside">');    
            echo ( '<div class ="my-header">' );
            $thispicture = get_field( "cg_pretty_picture" , $post->ID );
            echo( '<img src="' . $thispicture . '"/>'); 
            echo ( '</div><!-- end header -->' ); //end header
            echo( '<div class="inside">' );
            echo( '<ul>' );
            if( have_rows('cg_the_links', $post->ID ) ) :
                //tried with and without $post->ID, but I think that I need it
                while( have_rows('cg_the_links', $post->ID ) ): the_row();  
                    $thislink = get_sub_field('cg_link_url', $post->ID );
                    $thislinktext = get_sub_field('cg_link_text', $post->ID );
                    echo( '<li>' );
                    echo( '<a href="' . $thislink . '">' . $thislinktext . '</a>' );
                    echo( '</li>' );
            echo( '</ul>' );
            echo ( '</div>'); //end of inside div
            echo( '</div>' ); //end of outside
  • I just tested this and it works fine. Could this be because you’re working on a dev site that you can only access locally / via hosts, so Google is unable to verify itself?

  • –Edit–

    Most of this didn’t quite do what we needed – rather than adding to the confusion, I’m just removing this. The solution is in my post below.

  • Can you post the function that your while loop is a part of within your functions file, or potentially even just your functions file (although that could be exceptionally long, so if you do that maybe use

    It could be something to do with how you’re calling in the function itself within functions instead of using that code within a template file.

    Anything you can provide will give us some clues to help 🙂

  • I did actually just think – when you bring in the fields to use as part of the ACF Form, are you calling them as get_field() or the_field()?

    If you’re calling them with the_field, irrespective of conditional settings, I think they’ll probably show.

    Maybe if you could post the code for the template as well?

  • Can you show some screenshots of how you’ve set up the ACF fields in the back end so we can see how the conditional fields work?

  • There is a filter that you can hook into and pre-populate a field. The documentation only shows this for Select fields, but you should be able to use “date-picker” to prepopulate all Date Fields, or you could lock it down to that specific date field if you reference the field key.

    The format of the datepicker is YYYYMMDD

  • Hi @mariol,

    You can use wp_query to call in specific posts using the meta_query parameter. There are some pretty shiny examples of this here. Check out number 4 for sub-fields.

    What this would do is to give you all the posts that have band dates in on the set date. This will only do half of the job you need though, as it’s likely that a band will play twice on one day at different times.

    Run the first query and within the loop I’d probably set an array to save the time as the key and the post ID as the value. This then allows you to use krsort(), which will arrange the array in descending order by the key. You can then do a loop through the array, and use the array value of that post’s ID to grab the band name / images / etc. from that particular post, and then output the key afterwards as the time they go on-stage.

    Hopefully that gives you some things to go on, but if not let me know and post some code and we can see what’s going wrong and where.

  • This isn’t strictly speaking an ACF question, and more of a WP core question. Depending on how you’ve set up your site will depend on the particular code that you’ll need.

    Getting WP categories is relatively easy, and if you have set each of these up as a normal Post within WordPress, then you can use a combination of the function in_category() to check if the current post is in the specified category, and cat_is_ancestor_of() to check if that category is a sub-category of the parent.

    In practice this would look something like:

    global $post;
    // Get categories applied to post
    $categories = get_the_category($post->ID)
    // Retrieve the first category ID (just in case multiple selected)
    $current_category = $categories[0]->term_id;
    // If this post is in the category Books, or a child-category of Books
    if( in_category('books') || cat_is_ancestor_of('books', $current_category) ) {
    	// Get the template part from acffields/acf-books.php
    elseif( in_category('films') || cat_is_ancestor_of('films', $current_category) ){
    	// Get the template part from acffields/acf-films.php
    	// If you want to put something else in if no category selected, add it in here.

    If you have set your posts up as a Custom Post Type with a custom taxonomy – then this won’t work, and you’ll need to use get_post_terms() instead, and then do an alternate check to confirm if that post is within that post category.

    You can alter this to the actual names of the categories, and add / remove any as necessary. Hopefully this will help give you a good starting point.

  • Hello,

    The problem you have here is that get_field needs to have an additional parameter in it to specifically say which taxonomy term it is supposed to look at for the content.

    In this instance, you’ll be looking to output the field on the taxonomy page, which would be the following code:

    // vars
    $queried_object = get_queried_object(); 
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;
    // load thumbnail for this taxonomy term (term string)
    $service_editor = get_field('service_editor', $taxonomy . '_' . $term_id);
    echo $service_editor;

    Edit: Sorry Jonathan, I didn’t refresh the page before I posted and didn’t see your reply. Hope either of our responses help.

  • Sorry – those don’t work as they require authentication to see. Can you just upload them to your post through the little attachment icon in the bottom left?

  • If the field is within a repeater or flexible content field, you’ll need to use get_sub_field() instead of get_field().

    If the field is within an options page or if you’re loop has a different post ID, you’ll want to use the second parameter of get_field as either:



    get_field('enable_box', $post_id );

    If it’s not either of those, add an image of your acf field setup and we should be able to see what’s happening.

  • I feel that what you’re attempting is probably better with a different setup of ACF fields.

    Flexible content fields are typically used when you have completely separate areas of content that are just as likely to be used (i.e. some text could be one column, two columns or three)

    In this instance it seems that you’re looking for something like:

        - text or icon
        - text or icon
        - text or icon
        - text or icon
    .... etc.

    In this case it would be best to use a second flexible content field within your first one, so that your Headshot is always ready and available, and then you can have a second loop for your text or icon layouts.

    This also makes it very easy for you to wrap anything in any divs you need.

  • If you can post your entire code here as code rather than an image, we should be able to work out the best placement 🙂

  • Just move the <div id=”wrapper”> up above your WHILE loop, but below the IF check, where the commented out ul is.

    If you have any rows, it will then output the div wrapper, and then for each of those rows it’ll output the row data surrounded by a <div class=”container”>

  • The simple answer to this is yes. It would just involve you setting them up carefully and making sure to give them logical names. You can see an example and some template code here:

    Based on the fact that you’ll want non-repeating fields as well as repeating fields to sit side by side (the title of each section will only appear once per section) it may well be worth setting this up as a flexible content field with a repeater inside of it.

    product_group (Flexible Content)
        - product_group_title (Text)
        - product_group_description (Textarea)
        - product_group_repeater (Repeater)
            - product_group_repeater_title (Text)
            - product_group_repeater_size (Text / Number)
            - product_group_repeater_price (Number)
            - product_group_repeater_image (Image)
  • My first thought is that this would probably work if it weren’t a multiselect. It being a multiselect means that $value will be outputting an array of users. You’ll need to stick a foreach loop in there to confirm, something like:

    <div class="module_col">
    		<h3><?php the_sub_field('module_title'); ?></h3>
    		// Get List of students to check for eligibility
    		$students_list = get_sub_field('student_availability' );
    		// Set the default state to false, to be changed later
    		$student_authorised = false;
    		// Loop through students_list to check if user is allowed access
    		foreach( $students_list as $student ) :
    			// If user is in the list, set student_authorised to true and break out of loop
    			//(no need to loop through everybody if they're the first user)
    			if( in_array( $student_username, $student['nickname'] ) )
    				$student_authorised = true;
    		// If student is in the list, show download link
    		if ( $student_authorised ) : ?>
    			<a href="<?php the_sub_field('module_download'); ?>">
    				<button class="download_btn">
    					<span><i class="fa fa-cloud-download"></i>Download Module</span>
    		// if student not in list, show authentication error
    		else : echo 'Not logged in'; endif; ?>
  • Could you post a rundown of your fields and the template code to output so we can confirm that it’s not something untoward in there?

  • There are a few things that are going on in the code above, which may be the way you’ve copy/pasted it, but are worth noting.

    Firstly – some programs style apostrophes as a slightly different type of character that looks a lot like an apostrophe but is more akin to a grave, or an acute accent. MS Word is killer for this, but a lot of other programs do it too and it looks like something similar is happening in your code.

    – If we fix this, we can then see a couple of other issues – on line 6, you don’t close your php tag before the <h1>.

    – Your HTML comment is also missing a hyphen, as comments should be <!– –>, however this won’t cause anything other than styling issues for you.

    – The parameter “field_groups” has been misspelled as “field_gruops” which may be the underlying cause of your error.

    – The updated message has some curly quotes in it as well.

    Fixing all of the above gives you some code that looks more like the following:

    <?php $my_fields = array(
    <h1><?php the_title(); ?></h1>
    <?php the_content(); ?>
    <!-- <p>My custom field: <?php //the_field($provider_name); ?></p> -->
    <?php $new_provider = array (
    'post_id'	=> 'new_post',
    'new_post' => array(
    'post_type' => 'provider',
    'post-status' => 'draft'
    'field_groups'	=> $my_fields,
    'form' => true,
    'return' => '/',
    'html_before_fields' => ”,
    'html_after_fields' => ”,
    'submit_value'	=> __('Create a new provider'),
    'updated_message' => __("The provider has been saved", 'acf')

    If you run that through, it may work a little better?

  • The slug of the options page itself doesn’t affect any of the content within, it just determines what the URL of the options page is in the backend.

    All of the actual fields are just saved into the wp_options table in the database using the field name from ACF. This means if you use the same field with the same field name on multiple options pages (irrespective of the actual page slug) this will be overwritten.

    <?php the_field('title', 'options'); ?>

    This is why I said, make two separate forms in ACF with the same fields in, but with different slugs. This would be something like:

    Options page (Posts)
        - title_post
        - description_post
    Options page (Pages)
        - title_page
        - description_page

    This effectively allows you to keep the slug the same per options page, whilst incorporating the post-type of the page that this options page will appear in, to keep them unique.

    Then when you call in this information, you can use the block I added earlier to specify which fields to look at:

    get_field( 'description_' . get_post_type($post), 'options' );

    On a posts page this will give you

    get_field('description_post', 'options);

    and on a page:

    get_field('description_page', 'options);

Viewing 25 posts - 1 through 25 (of 44 total)