Home Forums Add-ons Repeater Field Sub Custom Field Value Query and Post per Page


Sub Custom Field Value Query and Post per Page

  • Hey,

    I use a code similar to this from
    to query the repeater-fields of a post-type. That works great, but i have one problem: I need to have pagination with a post per page argument but this affects only the numbers of the parent post not how many values from the repeater are loaded. The Problem is, that each post do have an individual amount of repeater fields and i need to show a fix amount of repeater values.

    How can I fix this directly in the database-query without loading all the posts first?
    Thanks alot!

    here is the example code from

    // filter
    function my_posts_where( $where ) {
    	$where = str_replace("meta_key = 'dates_%", "meta_key LIKE 'dates_%", $where);
    	return $where;
    add_filter('posts_where', 'my_posts_where');
    // find todays date
    $date = date('Ymd');
    // args
    $args = array(
    	'numberposts'	=> -1,
    	'post_type'		=> 'event',
    	'meta_query'	=> array(
    		'relation'		=> 'AND',
    			'key'		=> 'dates_%_start_date',
    			'compare'	=> '<=',
    			'value'		=> $date,
    			'key'		=> 'dates_%_end_date',
    			'compare'	=> '>=',
    			'value'		=> $date,
    // query
    $the_query = new WP_Query( $args );
    <?php if( $the_query->have_posts() ): ?>
    	<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    			<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    	<?php endwhile; ?>
    <?php endif; ?>
    <?php wp_reset_query();	 // Restore global post data stomped by the_post(). ?>
  • You can’t do this with a query because you’re talking about the number of rows in a repeater and not the number of posts. One solution can be found here

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

The topic ‘Sub Custom Field Value Query and Post per Page’ is closed to new replies.