Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function exercise_shortcode( $atts ) {
- //shortcode atts
- $atts = shortcode_atts( array(
- 'muskelgruppe' => 'rücken',
- ), $atts, 'exercise' );
- //Get Muskelgruppe from shortcode atts
- $muskelgruppe = $atts['muskelgruppe'];
- //Get only Posts with a Repeater
- $exercises = get_posts(
- array(
- 'post_type' => 'post',
- 'posts_per_page' => 500,
- 'meta_query' => array(
- 'relation' => 'AND',
- array(
- 'key' => 'uebungen',
- 'compare' => 'EXISTS',
- ),
- ),
- )
- );
- $output = "";
- //Loop
- if ( $exercises ) {
- foreach ( $exercises as $exercise ) {
- setup_postdata( $exercise );
- if( have_rows('uebungen',$exercise->ID )) {
- while( have_rows('uebungen',$exercise->ID) ) : the_row();
- if( $muskelgruppe == get_sub_field('uebung_gruppe')) {
- //Hier kannst du deine gewünschten Felder abrufen
- $exercise_title = get_sub_field('uebung_name');
- //Dem Output anfügen
- $output .= '<div class="uebung">';
- $output .= '<p>';
- $output .= $exercise_title;
- $output .= '</p>';
- $output .= '</div>';
- }
- endwhile;
- }
- }
- wp_reset_postdata();
- }
- return $output;
- }
- add_shortcode( 'exercices', 'exercise_shortcode' );
- // Use [exercices muskelgruppe="xyz"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement