Aleš Sýkora wrote

Oxygen Dynamic repeater examples

14. 1. 2021 in ,

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' );
?>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More from category
Aleš Sýkora wrote
Multistep form with Toolset Forms and Bootstrap Accordion
19. 9. 2018 in
Need to make long form simple to use? Use the accordion module from bootstrap and Toolset forms. Try it now! We provide you code snippets & easy tutorial.
Read More
Aleš Sýkora wrote
Conditional check if page is parent or child in WordPress
14. 1. 2021 in
If you need to display something only if post has childs (or not), you can use this conditional in your code.
Read More
Aleš Sýkora wrote
Auto login after creating new user with Toolset user form
11. 7. 2019 in
Snippet from our fan.
Read More
magnifiercross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram