Support

Account

Forum Replies Created

  • Thanks Johnathan, yes tested that and it outputs the list – now i’ll see if I can hook that in. Appreciated.

  • Hi @jonathan yes the actual text from the selections, so only if selected in the backend.

  • Wow you do know your stuff! – Many thanks that works perfectly, the only thing that i don’t grasp 100% is
    $row_count--;

    I do understand by its use we are moving from zero based index to get the last proper row.

    You said earlier that:
    $rows--; is short form of $rows = $rows-1;

    So in the code that works, instead of using $row_count--; i tried $row_count-1;
    but that outputs nothing, I was wondering for my own curiousity how to use arithmetic operator on the row count so for instance I could output the 2nd last one.

  • tried to this using

    $rows = get_post_meta( 348, 'testimonials', false ); // get number of rows (8 but in a array)
    $row_count = $rows[0]; //get row number out of array (8)
    echo $row_count--; // because first row start with 0 not 1 subtract one from row number (8-1 =7)
    //now you could use $row_count to get last row (7)
    $lastrow =  'testimonials_'.$row_count.'_testimonial'; //you need to replace echo by a variable and use that
    
    echo $lastrow;

    What i get front end is
    8testimonials_7_testimonial

  • okay result i get from

    echo '<pre>';
    print_r( $rows);
    echo '</pre>';

    is

    Array
    (
        [0] => 8
    )

    Which is the 8 repeater rows current in the array.

    how do i use $rows--; ?
    and/or how would i always echo the last row after more rows where added?

  • ok thanks – so I can get a specific row output like so…

    <?php 	
    	$rows =  get_post_meta( 348, 'testimonials', false ); // get all the rows
    	$end_testimonial_content = get_post_meta( 348, 'testimonials_4_testimonial', true );// get the sub field value 
    	$end_testimonial_header = get_post_meta( 348, 'testimonials_4_testimonial_header', true ); // get the sub field value 
    	$last =  '<blockquote>' . $end_testimonial_content . '</blockquote><p>' . $end_testimonial_header . '</p>';
    	echo $last; 
    
    	?>

    I also tried with end function but couldn’t get it to work, but as a fallback at least I have something on the page.

  • Hi again,
    Thanks for your help – actually I didn’t have a date field – but added one and used this

    foreach( $repeater as $key => $row ) {
        
        $column_id[ $key ] = $row['date_added'];
    }
    
    /*
    *  Use the $column_id array to sort the $repeater array
    */
    
    array_multisort( $column_id, SORT_DESC, $repeater );
  • thank you very much that now outputs and sorts – I do have a follow up question about sorting by date entered – I’ll post a new thread.

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