Display ACF Repeater Fields on Child Pages - wordpress

I'd like to display the results of an ACF repeater field on child pages. An example of the current code:
<?php if( have_rows('recommended-properties') ): ?>
<?php while ( have_rows('recommended-properties') ) : the_row(); ?>
<?php the_sub_field('recommended-properties-title'); ?>
<?php the_sub_field('recommended-properties-description'); ?>
<?php endwhile; ?>
<?php endif; ?>
Now, I thought I may be able to store the parent page ID in a variable and use that the same way you can get values from another post (see: http://www.advancedcustomfields.com/resources/how-to-get-values-from-another-post/)
I tried the following:
<?php $parentPageId = wp_get_post_parent_id( $post_ID ); ?>
<?php if( have_rows('recommended-properties', echo $parentPageId;) ): ?>
<?php while ( have_rows('recommended-properties', echo $parentPageId;) ) : the_row(); ?>
<?php the_sub_field('recommended-properties-title'); ?>
<?php the_sub_field('recommended-properties-description'); ?>
<?php endwhile; ?>
<?php endif; ?>
But no luck unfortunately. Any suggestions for where I can go from here?
Many thanks!

You don't need add echo when you add parameter in function
try below code
<?php $parentPageId = wp_get_post_parent_id( $post_ID ); ?>
<?php if( have_rows('recommended-properties', $parentPageId) ): ?>
<?php while ( have_rows('recommended-properties', $parentPageId) ) : the_row(); ?>
<?php the_sub_field('recommended-properties-title'); ?>
<?php the_sub_field('recommended-properties-description'); ?>
<?php endwhile; ?>
<?php endif; ?>

Related

Strip tags + shortcodes from WordPress query

I have a custom query where I show posts from an author that have at least 400 characters. To have a good result I strip the tags out of the text:
<?php while ($query->have_posts()) : ?>
<?php $query->the_post(); ?>
<?php if( strlen( wp_strip_all_tags($post->post_content) ) > '400') : ?>
<?php $length = strlen( wp_strip_all_tags($post->post_content)); ?>
<?php echo $length; ?>
<?php endif; ?>
<?php endwhile; ?>
How can I combine "wp_strip_all_tags" with the WordPress "strip_shortcodes" function to get an even better result?

ACF repeater inside group

I tried to get ACF repeater from the group field.
I must be blind, but I cannot find a mistake inside my code.
<?php if( have_rows( 'acf_group' ) ): ?>
<?php while( have_rows( 'acf_group' ) ): the_row(); ?>
<?php if( have_rows( 'acf_repeater' ) ): ?>
<ul>
<?php while( have_rows( 'acf_repeater' ) ): the_row();
$link_text = get_sub_field( 'acf_repeater_field_text' );
$link_url = get_sub_field( 'acf_repeater_field_url' );
?>
<li>
<?php echo $link_text; ?>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>

Wordpress: check if current post is first in the loop

I need to style the first post in the loop differently from the rest in a wordpress theme template. Is there a specific wordpress function to check for this or do I just need to set a "first" flag like the below?
<?php while ( have_posts() ) : ?>
<?php the_post(); ?>
<?php if ( $first = !isset( $first ) ) : ?>
<!-- First Post HTML -->
<?php else : ?>
<!-- Every other posts HTML -->
<?php endif; ?>
<?php endwhile; ?>
The function I'm looking for would replace the $first = ! isset( $first) check. Does this function exist in WordPress?
Try this
<?php $Inc=0; ?>
<?php while ( have_posts() ) : ?>
<?php the_post(); ?>
<?php if ( $Inc==0 ) : ?>
<!-- First Post HTML -->
<?php else : ?>
<!-- Every other posts HTML -->
<?php endif; ?>
<?php $Inc++; ?>
<?php endwhile; ?>

WordPress Global Post Query and Custom Meta not workinging

I have a global post query running, but for some reason my custom meta is not being output. When I try to call it inside a typical WordPress loop it works, but not in my code below. Is there any reason why this would be the case? Been trying to figure it out for an hour now....
<?php global $post; $cntr = 0; $myposts = get_posts('&post_type=go-deeper&posts_per_page=12');
foreach($myposts as $post) : setup_postdata($post);?>
<li class="<?php echo "slide_" . $cntr; ?>"><?php the_post_thumbnail('full'); ?></li>
<?php $cntr++; ?>
<?php endforeach; ?>
I just re-wrote the query and it works now:
<?php if(have_posts()): $cntr = 0;?>
<?php query_posts('&post_type=go-deeper&posts_per_page=12');?>
<?php while(have_posts()):the_post();?>
<?php $deeper_link = get_post_meta( get_the_ID(), 'll_deeper_link', true ); ?>
<li class="<?php echo "slide_" . $cntr; ?>">
<?php the_post_thumbnail('full'); ?>
</li>
<?php $cntr++; ?>
<?php endwhile;?>
<?php wp_reset_query(); ?>
<?php endif;?>

wp_query help with retrieveing posts via tag

s it possible to retrieve post entry for a custom post type by tag, I have been trying with the following code, however it just locks me into a infinte loop.
<aside class="supporting_images">
<?php /*<?php if($post->ID == 241) : echo apply_filters('the_content', '[slideshow=3]'); endif; ?>
<?php the_post_thumbnail(); ?>*/?>
<?php if($post->ID == 241) : ?>
<?php
$query = new WP_Query();
$query->query('tag=branding');
?>
<?php while ($query->have_posts()) : ?>
hello
<?php endwhile; ?>
<?php endif;?>
First try changing your loop to:
<?php while ($query->have_posts()) : the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
The have_posts() function just returns true if there is another post but does not increment the loop counter, so the loop will never end.

Resources