Forum Replies Created

  • Hi Tracy,

    First of, get_the_title does not take any other parameter than the ID of the post in question..

    What you’re asking for in your first post is the alt text that you’ve put into the image editor in the media library. This is not really part of ACF but is a standard WP thing.

    So assuming that the field you’ve wrote in for each image is indeed the alt field your code should look something like this:

    This assumes that what you have created in ACF is an image field where you have set the return value to be the images id.

    <?php $imageID = get_field('THIS IS YOUR FIELD NAME FOR THE IMAGE'); ?>
    <?php $image = wp_get_attachment_image_src( $imageID, 'full' ); ?>
    <?php $alt_text = get_post_meta($imageID , '_wp_attachment_image_alt', true); ?>
    <img src="<?php echo $image[0]; ?>" alt="<?php echo $alt_text; ?>" />
  • I agree of course.. from Elliots point of view that would probably mean that he’d have to make some sort of ajax validation check when the user saves a fieldgroup.. not impossible but tbh, I’d rather he focus on other areas of improvement since the use of the API and PHP is far less used than the admin interface and it still works as is.

    Perhaps something to develop on an github fork?

  • I cant be sure but isn’t the reason why elliot uses a random field key string to avoid issues where the user has entered the same field name for multiple fields.. I don’t think there’s a check for duplicate field names when the user creates his fields and by using a random string instead ACF wont make the two clash.

    This is just my speculations tho 🙂

  • Hi!

    You should use the post types slug for the post_type argument.. which I’m guessing would be portfolio-item?

    The reason why your ACF field is not being displayed is because you’re using the_field which tries to echo the result itself. In this case you’re already doing that so replace the_field with get_field and you should be golden!

  • Hi!

    You can do like this, where the $imageID is the ID of the image retrieved from ACF:

    $alt_text = get_post_meta($imageID , '_wp_attachment_image_alt', true);
  • Hi!

    Since you’re probably outputting the repeaterfield in a while loop you can use a counter for the steps:

    $i = 1;
    <p>Step <?php echo $i; ?></p>
  • I’ll agree in saying that relevanssi is a good plugin for extended search in WP.. I do think however that this is very much a question for the relevanssi support forums rather than ACF 🙂

  • Well that’s not entirely true.. It is out of the scope of ACF to automatically add default values to posts depending on category.. However if there’s no apparent reason to why the field_objects checkbox values are in one long string you could create a fork on the ACF repo on github and fix it yourself and hope for it to be included in the next version 🙂

  • sounds wierd..

    My recollection of the field object with a checkbox was an array with each value. But I haven’t had a look at it in some time..

    I suppose you could copy the field from the ACF core and make your own addon where you put the values in an array instead so that you can use them as you please

  • You say the default values are produced as a string.. I believe they’re like this: default1, default2, default3 etc.
    If you need this as an array why not simply use php explode?

    $myarray = explode(', ', $default_values);

    If the string does not contain a space just remove that from the first parameter of the explode 🙂

  • Good morning,

    So I’ve taken a look at your file and I can’t even find any reference to that which you are doing? Where in the code is this supposed to happen since there’s not anything there?

    In any case. The markup was chaos so I took the liberty of cleaning it up a bit for you with proper indents and a missing end div-tag.

  • As roberto says.. you need to put this inside php tags for the code to run.. or it will just be treated as a regular string!

    This applies to everything that’s not HTML or a string.

  • the do this inside the loop but outside any if statements:


    And post the result here

    if(in_array('In Stock', get_field('stock'))){
    }else if(in_array('Forthcoming', get_field('stock'))){
    }else if{in_array('Out of Stock', get_field('stock')){
    No selected

    This should work then according to
    which I assume works the same as radiobuttons..

  • Okay, It’d be much easier to help you if we could actually see the whole code in context 🙂

  • Nc, Ic (I see) .. hoho..

    Then I suppose it’s a bit more complicated.. so dynamic that you can’t even retrieve a specific field from the ACF interface?

    With get_field_object you should be able to retrieve the specific checkbox with it’s values if that’s what you need.

  • Ah! We’ll it seems your wp_query that comes after the regular loop overwrites the post object with this: $wp_query->the_post();

    You can try putting wp_reset_postdata(); right after the endwhile for that loop.. If that does not work try putting the value in a variable inside the regular loop that comes before the new wp_query and then access the variable where you need it 🙂

  • Isn’t it so that when jut one checkbox has been checked the return is not an array but rather just a string.. So if you know that your user will always just check one (if so Id use radiobuttons instead) you should just check it like a regular string..

    <?php if ('in_stock' == get_field('stock')) { ?>   
    <?php } ?>
  • hi!

    Is it uni-title or uni_title? Make sure those match since you’ve written both in your description..

    It should not matter what template you’re using it on, but I guess that depending on where in the template you use it you might need to provide the post id as well.. try this:

    <?php global $post; ?>
    <h3><?php the_field('uni_title', $post->ID); ?></h3>
  • Hi NC,

    Since you’ve set the checkbox default value yourself when creating the ACF field you don’t really need access to the array..

    If the value is just from one checkbox it will be saved as a string (if I remember correctly) and you can just manually write that out as the info to be saved without accessing the checkbox actual values.. Since it’s the same value as for the default value when ACF loads it it will recognize it as the default being checked while in reality you put it in there manually 🙂

Viewing 21 posts - 1,001 through 1,021 (of 1,021 total)