Support

Account

Forum Replies Created

  • @ekazda Thanks for sharing this solution. I just used it today. I greatly appreciate you coming back to the forum to share a solution with the community.

  • I’m not sure if I fully grasp what you’re trying to accomplish, so I could be way off here… but, if it’s a matter of drilling down deeper and deeper, I could envision using a custom hierarchical taxonomy to do something like this. You select the parent term and it displays the possible child options, over and over.

    Something like this:
    Car Trouble
    – Engine
    — Possible Engine Issue 1
    — Possible Engine Issue 2
    – Gear Box

    …and so on.

    Again, maybe that’s a stupid idea for your use case. Regardless, by using ACF fields on the actual terms themselves, you could specify a “question” field that is associated with each term and displayed to the user.

    So for example, if the user chose “the engine”, on the next screen they would see the question associated with that term. Like “Which of the following symptoms is your engine experiencing?”, then the child terms of “Engine” are displayed.

    In any case, good luck with your project!

  • Interesting! Sounds like a good solution. Thanks!

  • For anyone who may find this in the future, I was able to achieve this by use the ACF Post-2-Post plugin, as well as the acf/fields/relationship/query filter.

    Inside the filter, I only populate the results with ‘Lessons’ that have either no value (”) or have had a value set, but no longer do (‘a:0:{}’). (That’s ACF’s markup.)

    
    $args['meta_query'] = array (
      'relation' => 'OR',
      array (
        'key' => 'lessons',  
        'value' => '',
        'compare' => '=', 
      ),
      array (
        'key' => 'lessons',  
        'value' => 'a:0:{}',
      ),  
    );
    
  • Try this, using DateTime() rather than date():

    
    <?php 
    $today = new DateTime();
    $date_fr = DateTime::createFromFormat('Ymd', get_field('date_de_sortie_fr'));
    ?>
    
    <span>
      <?php 
      if($date_fr > $today) echo "Soon: ";
      
      echo $date_fr->format('Y-m-d'); 
      ?>
    </span>
    

    NOTE This requires that you store the date field in Ymd format.

  • Thanks @jimkrill. I thought maybe it was just me because I hadn’t heard much from anyone else about this. Your solution works great.

    Because I didn’t want to go back and edit my code after this issue is fixed, I had switched to just using a Post Object field rather than a Page Link, using get_permalink() with the ID, but I think your idea of using is_numeric() is a better solution.

  • Just a “thank you” for this โ€” I had the same question and didn’t realize those would apply to hierarchical CPTs as well.

  • Hey @acf-support James,

    Just wanted to check in on the status of this. I’ve found another instance where this is happening now โ€” when trying to retrieve an ACF taxonomy image from on the taxonomy page (taxonomy.php).

    I can pull them in fine from other pages, but when on taxonomy.php get_field() returns the image ID rather than the array.

  • Sure, no problem! Ok, since we’re outside the loop, first you just want to grab the global query that is being passed to your template files and assign the post data to a variable.

    Then you just add the post ID as a second parameter to get_field(). Here’s what it should look like:

    
    global $wp_query;  
    $post = $wp_query->post;
    
    <?php if (get_field('options_posts', $post->ID) == "para_1") {
        echo '<link rel="stylesheet" id="parallax-css"  href="#" type="text/css" media="all" />' ;
    } else if (get_field('options_posts', $post->ID) == "para_2") {
        echo '<link rel="stylesheet" id="parallax2-css"  href="#" type="text/css" media="all" />' ;
          } ?>
    

    That should take care of it for you, but if you have any trouble, let me know.

  • Hi @justawebbie,

    If this code is in your header, I’m guessing you’re trying to pull this field in from an options page?

    If that’s the case, you just need to add in another parameter to get_field().

    So it would become get_field('options_posts','option').

    If you’re just trying to pull in the field from the page you’re on, I’m assuming your header is being called before the WP loop starts. In that case, you’ll need to pass the page/post ID to get_field() instead. Let me know if you need more clarification.

  • @acf-support

    Hi James,

    Basically, you’ll just need to add an image field to any given page, and choose “Image Array” as the output.

    Then, in index.php, try to pull in the image object into a variable, passing the ID of the page you’ve chosen as the second parameter.

    You should find that it works inconsistently โ€” sometimes returning just the image ID rather than the object.

    Here’s a link to a video that shows my particular situation… probably about as clear as mud. ๐Ÿ™‚

    https://dl.dropboxusercontent.com/u/51884620/ACF%20Issue.mp4

    If you need further detail or code, just let me know.

    Thanks!

  • UPDATE:

    I discovered that in the case of a Category or Tag archive, the ACF returns the image ID, even if “Image Object” is the desired output.

    I’m guessing this is a bug?

  • Hi @elliot,

    I tried this out by rolling back to ACF 5.2 as well as ACF 5.1.9.1 (with WPML 3.1.9.1) and got the same result.

  • No problem @jodriscoll. ๐Ÿ™‚

    You can use strip_tags() to remove all tags. You can also choose to allow specific tags. Here’s a link about that…

    The updated code would then be:

    
    function project_excerpt() {
        global $post;
        $text = get_field('project_description');
        if ( '' != $text ) {
          $text = strip_shortcodes( $text );
          $text = apply_filters('the_content', $text);
          $text = strip_tags($text);
          $text = str_replace(']]>', ']]>>', $text);
          $text_length = strlen($text); // Get text length (characters)
          $excerpt_length = 350;  // 50 desired characters
          $excerpt_more = '...';
          
          // Shorten the text
          $text = substr($text, 0, $excerpt_length);
          
          // If the text is more than 50 characters, append $excerpt_more
          if ($text_length > $excerpt_length) {
            $text .= $excerpt_more;
          } 
    
        }
        return apply_filters('the_excerpt', $text);
      }
    

    One other note: I left them in, but I’m not sure that you need the calls to apply_filters() in there if you’re stripping everything out. You could just eliminate the first line:

    $text = apply_filters('the_content', $text);

    …and change the last one to return $text.

  • @gravycreative: Rather than using $image['url'] you just need to use $image['sizes']['blog-featured']

    That should fix it.

  • Rather than use wp_trim_words(), you could use PHP’s substr() like this:

    
    function project_excerpt() {
      global $post;
      $text = get_field('project_description');
      if ( '' != $text ) {
        $text = strip_shortcodes( $text );
        $text = apply_filters('the_content', $text);
        $text = str_replace(']]>', ']]>>', $text);
        $text_length = strlen($text); // Get text length (characters)
        $excerpt_length = 50;  // 50 desired characters
        $excerpt_more = '...';
        
        // Shorten the text
        $text = substr($text, 0, $excerpt_length);
        
        // If the text is more than 50 characters, append $excerpt_more
        if ($text_length > $excerpt_length) {
          $text .= $excerpt_more;
        } 
    
      }
      return apply_filters('the_excerpt', $text);
    }
    
  • @mattaton, yeah, I agree with you in that scenario. ๐Ÿ™‚

    Sorry, I don’t really know the ins and outs of adding that to the WP core either. Sometimes I just add an ACF Featured Image and remove WP Featured Image support from the post types I don’t want them on. At least that way the image fields are together in the same place.

  • There’s a somewhat unintuitive way you could do this, but I’m not sure if it’s what you’re looking for:

    You could basically use the photo description or caption to choose a featured image. For example, in your gallery, you could edit one photo that you “tag” by entering a key word in the description field… maybe “featured”.

    Then in your code, you could loop through the gallery images and when you find the image with the description “featured” you could display that and skip over all the others.

    I could supply a code snippet, but I wasn’t sure if this would be a good enough solution. I don’t know of any other way to tack on an extra checkbox on the edit window.

  • Same here. WPML 3.1.9.1 and ACF 5.2.1

    I rolled back to ACF 5.2.0 and an earlier WPML and everything worked fine. However, I had installed ACF 5.2.1 to fix the disappearing fields/metaboxes bugs… so I’m out of luck on that front until this issue is resolved.

    Just want to give props to Elliot though โ€” your responsiveness on bug fixes is superb. I appreciate the active development that you do on ACF.

  • Since most everyone else is having issues only with page attributes, I wanted to demo the related issue of certain other metaboxes disappearing. In this case, it’s the Categories box.

    Here’s a screenshot of that…

  • I have a very similar issue โ€” just slightly different. I have a custom taxonomy metabox and the normal Categories metabox showing. As soon as I click on any given taxonomy term or category, the Categories metabox is instantly hidden.

    I can get it back under Screen Options, but it goes away again if I click any term again.

    WP 4.1.1 & ACF 5.2.0, and as above, when disabled, the problem goes away.

  • I don’t think it’s possible to do all that in one step…

    A couple things:
    You’d need to use get_field() instead of the_field(), and echo the do_shortcode() function. Then you’ll have to combine them both with the HTML:

    <?php 
    $first_name = get_field(โ€˜first_nameโ€™);
    $last_name = get_field(โ€˜last_nameโ€™);
    $shortcode = '<p>' . do_shortcode($first_name) . do_shortcode($last_name) . '</p>';
    echo $shortcode;
    ?>
    
Viewing 25 posts - 1 through 25 (of 25 total)