Support

Account

Forum Replies Created

  • Not to mention that the translation of “fields” is incorrect. The word fields has more than one meaning.

    The word:
    مجالات
    means fields as in areas of interest or specialty.

    In this context fields should be translated as:
    حقول

  • If I understand you correctly, you want to have a field “Add Event”, which will contain repeater fields: first the date on the top row, followed by other fields for details underneath it, so that in one post you could add multiple events on different dates.

    This seems quite straightforward so perhaps I’m missing something. See the attached screenshots for fields setup and appearance. The only thing I changed from default was to change layout from table to row.

    If I’ve misunderstood, could you clarify?

  • Although this is marked as solved, I’d like to suggest an alternative approach. I always like to create a workflow that could be maintained by a novice user even if it means a bit of extra programming.

    So why not create a CPT called Brands which contains just the title and image? I’d position its admin menu low down to avoid visual clutter or even make it a sub-menu, then create an ACF field as a relational post-object that would be selectable by title but displayable as an image without having to mess around with FTP uploads and careful file naming.

  • That being said, when I tested this just now it always returned an array of objects (as taxonomies are inherently multi-selectable even if you only actually give the option to select them using radio buttons) necessitating a foreach loop, but if your example code worked for you then clearly I’m setting my test up differently from you.

  • If you make the field Required, then you can do away with the if statement completely <?php $manufacturer = get_field('manufacturer'); echo $manufacturer->name; ?>. Otherwise you can shorten the notation a bit like this: <?php $manufacturer = get_field('manufacturer'); if( $manufacturer ) echo $manufacturer->name; ?>. If you’re doing more than just echoing the name within the statement then stick in curly braces.

  • You need to edit your field and change the return value from Term ID to Term Object, and then you can get the name from the object like this.

  • Are you still having trouble with this? If so, could you post a screenshot of your ACF settings for those fields, or alternatively the output of var_dump() for each $x1, $x2, and $x3 ?

  • The simplest way to approach this would be to associate the select field with a custom taxonomy, which users with appropriate privileges could add to.

  • Hi Pete,

    Check out the ACF Resources page on creating and using Select inputs – its examples are very close to your question.

  • Hi Bauralex,

    You need to use get_field() instead of the_field() as you are building a string, not printing to screen.

  • Is it possible that these apparent duplicates are simply WordPress version history?

  • How do you have two images in a single field? Are you using a repeater field?

  • One step simpler would be to put each of the field names into an array and then loop through using your code above:

    $my_fields = array('position','dimension','color','weight','etc');
    
    foreach ( $my_fields as $my_field ) {
    	if ( the_field( $my_field ) ) echo the_field( $my_field );
    }

    If you want to go one step more complicated, you could try automatically building the array of field names by querying all the fields within a particular field group.

  • You will have to do it using CSS. First create the radio box field – I’ll use three options, Red, Green, and Blue – then inspect the post creation page and you will find something like this:

    <div id="acf-radio" class="field field_type-radio field_key-field_53afc2e795462" data-field_name="radio" data-field_key="field_53afc2e795462" data-field_type="radio">
            <p class="label"><label for="acf-field-radio">Radio</label></p>
    
            <ul class="acf-radio-list radio horizontal">
                <li><label><input id="acf-field-radio-Red" type="radio" name="fields[field_53afc2e795462]" value="Red" checked="&quot;checked&quot;" data-checked="&quot;checked&quot;">Red</label></li>
    
                <li><label><input id="acf-field-radio-Blue" type="radio" name="fields[field_53afc2e795462]" value="Blue">Blue</label></li>
    
                <li><label><input id="acf-field-radio-Green" type="radio" name="fields[field_53afc2e795462]" value="Green">Green</label></li>
            </ul>
        </div>

    As you can see, each input has a unique ID which can be targeted with CSS styling. You might try a technique such as this one on TutsPlus.

  • If you have a field group with two image fields – let’s label them First Image and Second Image, with field names first_image and second_image. Make sure that the Return Value is Image Object.

    $image1 = get_field('first_image');
    echo $image1['title'];
    echo $image1['url'];
    
    $image2 = get_field('second_image');
    echo $image2['title'];
    echo $image2['url'];

    You can see all the information in the image object using var_dump($image1);.

  • It sounds to me you want to use something like Formidable Forms, which allows drag-drop form creation and limiting one form submission per logged-in user. These are front-end forms, however, not part of user profiles.

    If it must be on their profile pages, you might having a look at this plugin that extends ACF.

  • Your date formats are fine, but your meta_query logic is not.

    Currently your code will only display posts for events that are currently ongoing, i.e. for events that started in the past and will finish in the future (or start/end today). But it will not include events that are in the future that have not yet started.

    I think you can simplify your query by only filtering by the ending date, because in order to satisfy your requirements (only posts that are in the future, or today), it doesn’t matter when they started as long as they haven’t finished. And then to make sure you don’t get any events entered that end before they begin, I would use acf/validate_value to compare the two dates when the post is created.

    So your query arguments should be:

    $args = array (
         'category' => 1,
                'posts_per_page' => -1,
                'meta_key'       => 'date_debut',
                'orderby'       => 'meta_value_num',
                'order'          => 'ASC',
       'meta_query' => array(
             array(
                'key'       => 'date_fin',
                'compare'   => '>=',
                'value'     => $today,
            )
        ),
    );

    The only other issue you may have is with posts you created while experimenting with other date formats which may still exist in the database as saved.

  • As the ACF GUI only gives the option for a maximum character limit, you can use the acf/validate_value filter along with the PHP: strlen function to count the number of characters. I would also add a note under Field Instructions so the user knows the limit before submitting.

    Assuming you want a minimum of ten characters:

    add_filter('acf/validate_value/name=validate_this_image', 'my_acf_validate_value', 10, 4);
     
    function my_acf_validate_value( $valid, $value, $field, $input ){
     
    	// bail early if value is already invalid
    	if( !$valid ) {
     
    		return $valid;
     
    	}
     
     
    	// load data
    	
    	$my_text_field = get_field('text_field');
    	
    	if ( strlen($my_text_field) < 10 ) {
    		
    		$valid = 'Must be a minimum of 10 characters.';
    	} 
    	
     
    	// return
    	return $valid;
     
    }
    
  • The array it returns is the same as the array returned by the_author_meta. Thus, you can get any of the info stored therein (see Parameters on the linked page).

    First store the array as a variable, then select the ID.

    $select_staff = the_sub_field('select_staff');
    $select_staff_id = $select_staff('ID');
Viewing 19 posts - 1 through 19 (of 19 total)