Support

Account

Forum Replies Created

  • Looking at some of the code you might need to debug a little but here’s some parts I see that are missing some syntax.

    foreach( $repeater as $row ) needs foreach( $repeater as $row ) :

    You are also missing the end of the foreach loop endforeach; ?>, which leads me to suggest you not render any HTML until you know the logic is working.

    Strip it down and build piece by piece. Then post where you are getting stuck but pay close attn to getting the syntax buttoned up first before adding HTML.

  • @mrjpotter I’d have to see your codes to help. I am sort of a PHP hack so no guarantees but I am happy to take a look.

  • Si Amigo,

    I got everything working. I am still kinda if’y about the syntax and coding style.

    Thanks again for the help, made all the difference for me.

    Cheers,
    Josh

  • Oh wait this might be working…I am new to PHP….
    notice the instances of “$currMonth != $date->format(‘F’)”, I imagine this makes the function return a string, is that right?

    <?php
                 
                 $repeater = get_field('race_event');
                 foreach( $repeater as $key => $row )
                   { 
                     $column_id[ $key ] = $row['race_date'];
                   } 
                   array_multisort( $column_id, SORT_ASC, $repeater );
                   
                   $currMonth = "start";
                   foreach( $repeater as $row ) :
                   {
                     $date = DateTime::createFromFormat('Ymd', $row['race_date']); 
                     $website_url = $row['race_website'];
                     
                     if ($currMonth != $date->format('F')) :
                       {
                         echo '<h2>' . $date->format('F') . '</h2><br>';
                         $currMonth = $date->format('F');
                       }
                     endif;
                     
                     echo '<ul>';
    		               echo '<li><h2>' . $row['race_name'] . '</h2></li>';
    		               echo '<li>Date ' . $date->format('F d, Y') . '</li>';
    		               echo '<li>Distance ' . $row['race_distance'] . '</li>';
    		               echo '<li>Vertical ' . $row['race_vertical'] . '</li>';
    		               echo '<li>URL <a href=' . $website_url . '> ' . $website_url . ' </a></li>';
    		               echo '<li>' . $row['race_description'] . '</li>';
    		             echo '</ul>';
                   }
                   endforeach;
                   ?>
  • I think this is on the right track but I am getting this error.
    Did I miss something in your example?

    Fatal error: Function name must be a string

    this is my code

    <?php
                 
                 $repeater = get_field('race_event');
                 foreach( $repeater as $key => $row )
                   { 
                     $column_id[ $key ] = $row['race_date'];
                   } 
                   array_multisort( $column_id, SORT_ASC, $repeater );
                   
                   $currMonth = "start";
                   foreach( $repeater as $row ) :
                   {
                     $date = DateTime::createFromFormat('Ymd', $row['race_date']); 
                     $website_url = $row['race_website'];
                     
                     if ($currMonth != $date('F')) :
                       {
                         echo '<h2>' . $date('F') . '</h2><br>';
                         $currMonth = $date('F');
                       }
                     endif;
                     
                     echo '<ul>';
    		               echo '<li><h2>' . $row['race_name'] . '</h2></li>';
    		               echo '<li>Date ' . $date->format('F d, Y') . '</li>';
    		               echo '<li>Distance ' . $row['race_distance'] . '</li>';
    		               echo '<li>Vertical ' . $row['race_vertical'] . '</li>';
    		               echo '<li>URL <a href=' . $website_url . '> ' . $website_url . ' </a></li>';
    		               echo '<li>' . $row['race_description'] . '</li>';
    		             echo '</ul>';
                   }
                   endforeach;
                   ?>
  • My code is sorting.

    My question may not have been clear, sorry.

    Is there a way to do grouping within the sorting so all the entries for May are in a group with the “May” heading and all the June dated custom fields are in the “June” grouping?

    If so could you give me some tips on how to implement that with my code above?

  • Do you mind giving me any tips on formatting and code structure? I am kinda new to PHP and although this works I am not confident.

    One other question I have is, can you recommend a way to approach a UI that would let a user jump to points on the page that are grouped into the same month? Back story is each repeater will have a name and date and now, since I can sort the list by date I was hoping to make it easier for the user to jump to the content for August.

    <!-- repeater	-->
       <?php
         $repeater = get_field('race_event');
           foreach( $repeater as $key => $row )
             { 
               $column_id[ $key ] = $row['race_date'];
              } 
                array_multisort( $column_id, SORT_ASC, $repeater );
                foreach( $repeater as $row ) :
                  {
                    echo '<li>' . $row['race_name'] . '</li>';
    		$date = DateTime::createFromFormat('Ymd', $row['race_date']); 
    		echo '<li>' . $date->format('m-d-Y') . '</li>';
                   }
             endforeach;
         ?>          
    <!-- /repeater	-->
Viewing 8 posts - 1 through 8 (of 8 total)