Aleš Sýkora / January 14, 2021 / 0 comments

Oxygen Dynamic repeater examples

Post summary: Query parent pagedata in Oxygen repeater Query parent page on child page. If current page is parent then query this page itself. Display all posts with same ACF post object field value Gets current post ID and look for posts connected to it by post object field from ACF.

Query parent pagedata in Oxygen repeater

Query parent page on child page. If current page is parent then query this page itself.

// Code block before repeater

<?php
$args = array(
    'post_parent' => get_the_ID(), // Current post's ID
);
$children = get_children( $args );
// Check if the post has any child
if ( ! empty($children) ) {
    // The post has at least one child
  function dynamic_ids_query( $query ) {
    if ( $query->query['post_type'][0] == 'nabidka' ) {
	$post_id = get_the_ID();
    $query->set( 'p', $post_id );
    $query->set( 'no_found_rows', true ); /* Delete this if you need pagination */
  }
}
add_action( 'pre_get_posts', 'dynamic_ids_query' );
  echo "has childs";
} else {
    // There is no child for this post
    echo "do not have childs";
	function dynamic_ids_query( $query ) {
	global $post;
    if ( $query->query['post_type'][0] == 'nabidka' ) {
	$parentpost_id = wp_get_post_parent_id( $post_ID );
    $query->set( 'p', $parentpost_id );
    $query->set( 'no_found_rows', true ); /* Delete this if you need pagination */
  }
}
add_action( 'pre_get_posts', 'dynamic_ids_query' );
}
?>
//repeater block

//code block after repeater
<?php
remove_action( 'pre_get_posts', 'dynamic_ids_query' );
?>

Display all posts with same ACF post object field value

Gets current post ID and look for posts connected to it by post object field from ACF.

//before repeater code block
<?php
function dynamic_query_hraci( $query ) {​​​​​​
  global $post;
  if ( $query->query['post_type'][0] == 'post' ) {​​​​​​
    $hrac = get_the_ID();
    
    $query->set( 'meta_query', array(
          array(
                'key' => 'hrac',
                'value' => $hrac,
                'compare' => '=',
        )));     
    
    $query->set( 'no_found_rows', true );
  }​​​​​​​​​​​​​
}​​​​​​​​​​​​​
 
add_action( 'pre_get_posts', 'dynamic_query_hraci' );
?>
//repeater
//after repeater code block
<?php
remove_action( 'pre_get_posts', 'dynamic_query_hraci' );
?>

Fuel my passion for writing with a beer🍺

Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻

0 comments

Share Your Thoughts