Support

Account

Home Forums Add-ons Repeater Field Output of 2 repeater field blocks to a date list

Solving

Output of 2 repeater field blocks to a date list

  • Hello,

    due to some reasons I would like to add a 2nd repeater field block to the following jquery, which works fine so far.
    the 2nd repeater field block is called ” termineneu” with fields like termineneu_beginn , termineneu_ende ect.

    Is it possible ???

    
    <?php
    // get all rows from the postmeta table where the sub_field (type) equals 'june, or "06"'
    // - http://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results
    // $date = date('Ymd');    
      
    	$rows = $wpdb->get_results($wpdb->prepare( 
                "
                SELECT * 
                FROM $wpdb->postmeta  pm
                Join wp_posts p ON pm.post_id=p.ID
                WHERE p.post_status = 'publish' AND pm.meta_key LIKE %s
                AND pm.meta_value LIKE %s
                AND pm.meta_value > CURDATE()
               ORDER BY pm.meta_value ASC;
    			",     
                  't_block_%_beginn', // meta_name: $ParentName_$RowNumber_$ChildName
               "201705__"  // meta_value:
              
    		 ));
    	
    	// loop through the results
    	if( $rows )
    	{
    		foreach( $rows as $row )
    		{
    // for each result, find the 'repeater row number' and use it to load the info!                            
    	preg_match('_([0-9]+)_', $row->meta_key, $matches);
    			
     $meta_key_beginn = 't_block_' . $matches[0] . '_beginn'; // $matches[0] contains the row number!
             $beginn_id = get_post_meta( $row->post_id, $meta_key_beginn, true );
             $timestamp_beginn = DateTime::createFromFormat('Ymd', $beginn_id);
    
             $meta_key_ende = 't_block_' . $matches[0] . '_ende';
             $ende_id = get_post_meta( $row->post_id, $meta_key_ende, true );
             $timestamp_ende = DateTime::createFromFormat('Ymd', $ende_id);
             
             $meta_key_preis = 't_block_' . $matches[0] . '_preis'; // $matches[0] contains the row number!
             $preis = get_post_meta( $row->post_id, $meta_key_preis, true );
             
              $meta_key_buchbar = 't_block_' . $matches[0] . '_buchbar';
              $buchbar = get_post_meta( $row->post_id, $meta_key_buchbar, true );
              
              $meta_key_sprache = 't_block_' . $matches[0] . '_sprache';
              $sprache = get_post_meta( $row->post_id, $meta_key_sprache, true );
         
          echo '<li>' ;
         	echo '<h5>' . $timestamp_beginn->format('d.m.Y') . '  -  ';   
          echo '' .   $timestamp_ende->format('d.m.Y') . ' :';  
          echo '  ' ."<a href='" . get_permalink($row->post_id) . "'>";
          echo get_the_title( $row->post_id ).'   '; 
          echo "</a>"; 
          echo '  ' . $preis . ' € ';
          echo ' ' . $sprache . ' ';
          echo '  ' . $buchbar . '</li></h5>' ;
       
               
                 ?>    
    
                              
    			
    <?php
     
    	}
    }
     
    ?>
    
  • Hi @taro09

    I’m afraid I don’t understand your request. Could you please explain it in more details? Also, could you please share some screenshots of it?

    If you need to query a repeater, please check this article (under the Sub custom field values section): https://www.advancedcustomfields.com/resources/query-posts-custom-fields/.

    Thanks 🙂

  • Hello James,

    sorry for this confusion.
    I try to explain with my bad english .

    I have website with lots of travels. Each post is one travel with several traveldates. The above code gives me a list of all dates sorted by the beginning of a travel like:

    3.2.16 – 24.2.16 Brasil Price bookable ect.
    4.2.16 – 16.2.16 Thailand price
    ect.

    All dates / informations are repeater fields:
    named
    t_block_beginn ; t_block_ende ; t_block_price ect.

    Now I have to create a 2nd “block” of repeater fields with the same informations and named like
    newdates_beginn ; newdates_ende ; newdates_price ect.

    This 2nd “newdates – block” of repeater field shloud also be integrated in my query / sorted list …

    Hope now its quite understandable 🙂

  • Hi @taro09

    Could you please share the JSON export of the field group? Also, could you please tell me how do you want the data to show up? Do you need to join it or just show it separated? Could you please share some screenshots of the current result and add a note to let me know how you want it to be?

    Thanks 🙂

  • This reply has been marked as private.
  • Hi @taro09

    I’m afraid the XML export is not working. Did you modify it? For further investigation, could you please open a new ticket and provide temporary admin credentials to your site? You can open a new ticket here: https://support.advancedcustomfields.com/new-ticket. Also, please don’t forget to explain the issue again and provide the link to this thread.

    Thanks 🙂

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

The topic ‘Output of 2 repeater field blocks to a date list’ is closed to new replies.