Support

Account

Forum Replies Created

  • Thanks for your hints.
    Did some digging and tweaking, and this code works

    
    $pasiPregatire = $_POST['acf']['field_58197932d0cff'];
    foreach ($pasiPregatire as $row) 
        {
            $image_id = $row['field_58197943d0d00'];
            $size = 'full'; // or the size you want to get
            $imageRet = wp_get_attachment_image($image_id, $size);
            $textRet = $row['field_58197952d0d01'];
            $retetaPas .= '<div>' . $imageRet . $textRet . '</div>';
        }
    $postContent = $_POST['acf']['field_54dfc94e35ec5'] . $retetaPas;
    

    I will work on something for nested repeaters.

  • This is my code

    
    add_filter('acf/pre_save_post' , 'rtm_pre_save_post' );
    function rtm__save_post( $post_id ) {
      $category = $_POST['acf']['field_54dfccb977a11']; 
      $pasiPregatire = $_POST['acf']['field_58197932d0cff']; // << i know this is an array and won't work
       $postContent = $_POST['acf']['field_54dfc94e35ec5'] /* << text area field */ .   $pasiPregatire	;
    // check if this is to be a new post
    if( $post_id != 'new' ) {
       return $post_id;
    }
    // Create a new post
    	$post = array(
    		'post_type'     => 'post', 
    		'post_status'   => 'pending',
    		'post_title'    => wp_strip_all_tags($_POST['acf']['field_54dfc93e35ec4']),
    		'post_content'  => $postContent,
    		'post_category'  => array($category),
    	);
    	// insert the post
    	$post_id = wp_insert_post( $post );
    	// Save the fields to the post
    	do_action( 'acf/save_post' , $post_id );
    	return $post_id;
    }

    But i don’t realize how to put $pasiPregatire (even with the foreach loop) in $postContent

  • Image field should return image url, not id or array.
    If you want more control you can set to return id and from that

    <?php
    	$imgID = get_sub_field('background_image');
    	$imgSize = "full"; // (thumbnail, medium, large, full or custom size)
    	$imgArr = wp_get_attachment_image_src( $attachid, $size );
    	// url = $image[0];
    	// width = $image[1];
    	// height = $image[2];
    ?>
    <?php 
    if( !empty($image) ): ?>
    	<div id="mainPhoto" style="background-image: url(<?php echo $imgArr[0]; ?> );">
    		<div id="pageTitle">
    			<?php the_field('page_title'); ?>
    		</div>
    	</div>
    <?php endif; ?>       
  • You need to extend you code and relate it to WordPress tags or categories. I think for what you need is tags
    1. Create a repeater field with two fields inside: ingredient_name and quantity. ingredient_name must be a taxonomy type field with post_tag.
    2 in your template use ingredient_name to create the link; and ingredient_name + quantity to make the structured data

  • Since i needed something like this, I found a very simple way to accomplish this:
    1. Create a time picker field with return and display format set to H:i
    2. If is a front end form hide “now” button with css.
    3. use this in your template to get time

    <?php 
    $preptime = get_field('prep_time');
    $preparr = explode(':', $preptime);
    $hour = $preparr[0];
    $min = $preparr[1];
    echo '<time content="PT'.$hour.'H'.$min.'M" itemprop="prepTime">'.$preptime.'</time>';
    ?>
  • Hello.
    This code works like a charm.
    I use this code for the featured image.
    How can i make this work for a repeater field in the same form?

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