Support

Account

Forum Replies Created

  • So there is no way to get sub field values without doing the “have_rows()” loop which also have to be nested inside the wordpress loop?

    This didn’t work for me though. This is running from functions.php:

    
    if ( have_posts() ) :
      while ( have_posts() ) : the_post();
    
        if( have_rows($field_key) ):
          echo "<p style='margin-left:180px;'><br>rows finns</p>";
              while ( have_rows($field_key) ) : the_row();
    
                  $header = get_sub_field('pagetype1_sidebar_item_header');
                  echo "<p style='margin-left:180px;'><br>the sub field value is: " . $header . "</p>";
    
              endwhile;
        else :
                echo "<p style='margin-left:180px;'><br> no rows</p>";
        endif;
     endwhile;
    endif;
  • Great, thanks! But it didn’t register any rows when doing “have_rows”!
    I’m checking a repeater field that has 2 rows.

    
            $field_key = "pagetype1_sidebar_items";
    
            if( have_rows($field_key) ):
                echo "<p style='margin-left:180px;'><br>there are rows</p>";
                while ( have_rows($field_key) ) : the_row();
    
                $header = get_sub_field('pagetype1_sidebar_item_header');
                echo "<p style='margin-left:180px;'><br>subfield:. " . $header . "</p>";
    
                endwhile;
            else :
                echo "<p style='margin-left:180px;'><br> No rows</p>";
            endif;

    This gives me “No rows”.

    By the way, I didn’t find any documentation on the “the_row()” function, is it explained somewhere?

  • Could be interesting. But I still want to be able to check how many rows there are in a repetaer field and also check the values of the fields.

    In my first post I used the wrong function (get_sub_field), and I checked a sub field.

    if I use get_field_object on a repetaer field (which holds rows with sub fields):
    $subfield = get_field_object('pagetype1_sidebar_items');

    I get this repeater field object. But I thought it would contain the rows with the sub fields? If I var dump it I get:

    array(18) {
      ["key"]=>
      string(29) "field_pagetype1_sidebar_items"
      ["label"]=>
      string(0) ""
      ["name"]=>
      string(23) "pagetype1_sidebar_items"
      ["_name"]=>
      string(23) "pagetype1_sidebar_items"
      ["type"]=>
      string(4) "text"
      ["order_no"]=>
      int(1)
      ["instructions"]=>
      string(0) ""
      ["required"]=>
      int(0)
      ["id"]=>
      string(33) "acf-field-pagetype1_sidebar_items"
      ["class"]=>
      string(4) "text"
      ["conditional_logic"]=>
      array(3) {
        ["status"]=>
        int(0)
        ["allorany"]=>
        string(3) "all"
        ["rules"]=>
        int(0)
      }
      ["default_value"]=>
      string(0) ""
      ["formatting"]=>
      string(4) "html"
      ["maxlength"]=>
      string(0) ""
      ["placeholder"]=>
      string(0) ""
      ["prepend"]=>
      string(0) ""
      ["append"]=>
      string(0) ""
      ["value"]=>
      bool(false)
    }

    It doesn’t contain the two rows with sub fields. So this doesn’t get me the info I need – I need to check if there are rows, and if so, check the values of the rows.

  • So I add the image first with update_field(). And I want to specify the image size of this image in its custom field – do I put the extra code in a page template for each page? Or where do I put it?

    I look in the documentation, and on “Customized display (Object)” they first get the image object (I guess for the current page), then it seems they use that object to echo the image somewhere (anywhere). So they are not changing the custom field image, they get the data from it to display it again in some other part of the page (if I didn’t misunderstood it). I want to change the original custom field image that is already added with “update_field”.And it seems that this image is always the full size image.

  • What would the final code look like if I want to set image ID 181 and ‘medium’ size?

    $imagefield = 'pagetype1_image';
    update_field( $imagefield, 181, $page_id );

    This only specifies the ID, not the size?

    The field is set to return the image object.

  • I’m just testing things right now to learn how to create all the custom fields. So while I’m doing this, it is pretty convenient to have it run on each page load. I just need to prevent it from creating duplicate content when running it several times.

  • Okay, so if I want to add an alt text, I better update the actual image.

    But regarding image size, is this specified beforehand on the field? There is a section called “preview size”, I guess that’s where you specify what size is going to be selected? So there is only one set size for each field?

Viewing 7 posts - 1 through 7 (of 7 total)