Support

Account

Forum Replies Created

  • Hi John, thank you for your advice.
    For some reason filter is not working when it’s added to the page. Definitely works when add_action is being added to the functions.php, but it’s preventing me from seeing any drafts on the site.

    
    <?php
    if (get_field('alternative_method')):
    	// add filter to only get published posts
    	add_action('pre_get_posts', 'acf_field_only_published_posts', 10, 1);
    	// get field
      $alt_posts = get_field('alternative_method');
    	// remove the filter so it does not affect other queries
    	remove_filter('pre_get_posts', 'acf_field_only_published_posts');
    
    	if (!empty($alt_posts)): ?>
    
    	<section id="alt-method">
          <div class="text full">
            <h2>Alternative methods</h2>
          </div>
    
          <div class="recipes-list item-listing">
              <?php foreach( $alt_posts as $post ):
                  setup_postdata($post); ?>
                  <?php if ( get_post_status() == 'publish' ) :?>
                     <?php get_template_part( 'template-parts/content-recipe-card', get_post_format() ); ?>
                  <?php endif;?>
              <?php endforeach; ?>
              <?php
              wp_reset_postdata(); ?>
    
          </div>
        </section>
    
    	<?php endif; ?>
    <?php endif; ?>
    
  • Update this was sorted with 4. Sub custom field values

    I’ve changed the REPEATER name to ‘quote’

    
    // filter
        function my_posts_where( $where ) {
    
        	$where = str_replace("meta_key = 'quote_$", "meta_key LIKE 'quote_%", $where);
    
        	return $where;
        }
    
        add_filter('posts_where', 'my_posts_where');
    
        // vars
        $person = '"' . get_the_ID() . '"';
        $personID = get_the_ID();
    
        $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    
        // args
        $args = array(
        	'posts_per_page' => 10,
            'paged' => $paged,
            'order' => 'DESC',
        	'post_type'		=> 'recipes',
        	'meta_query' => array(
            	array(
            		'key' => 'quote_$_person',
            		'value' => '"' . get_the_ID() . '"',
            		'compare' => 'LIKE',
            	)
            )
        );
    
  • An update, I’m trying to use an example from here 4. Sub custom field values
    I’ve updated REPEATER name to ‘quote’

    <?php
    
        // filter
        function my_posts_where( $where ) {
    
        	$where = str_replace("meta_key = 'quote_$", "meta_key LIKE 'quote_%", $where);
    
        	return $where;
        }
    
        add_filter('posts_where', 'my_posts_where');
    
        // vars
        $person = '"' . get_the_ID() . '"';
    
        $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    
        // args
        $args = array(
        	'posts_per_page' => 10,
            'paged' => $paged,
            'order' => 'DESC',
        	'post_type' => 'recipes',
        	'meta_query' => array(
            	array(
            		'key' => 'quote_$_person',
            		'value' => '"' . get_the_ID() . '"',
            		'compare' => 'LIKE',
            	)
            )
        );
    
        $the_query = new WP_Query( $args );
        if($the_query->have_posts() ) :
            while ( $the_query->have_posts() ) :
               $the_query->the_post();
    
               get_template_part( 'template-parts/content-recipe-card', get_post_format() );
    
            endwhile;
    
        else: ;
        endif;
    
        ?>
    
  • The snippet above is the relationship that sits under repeater. My current structure looks like this ingredients=repeater/items=repeater/ingredient_name=relationship. Ingredient_name has a field “link” this is what I want to store and use outside the loop as it will need to turn into Amazon asin link.

  • Hi John, that makes sense! Unfortunately, for myself, ingredients relationship is a subfield and listed in both repeater and flexible content. I’ve attached design just to illustrate how it’s done on a recipe page. Thanks for pointing me the bidirectional way, have you seen anyone achieving similar having relationship as a subfield?

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