Support

Account

Forum Replies Created

  • Bump – Anyone have any ideas on how to make this work?

  • Hi Wibi,

    Did you ever figure out a solution to this? Wanting to do something similar – limit what options are available on the WYSIWYG in the acf_form for user-generated content.

    Thanks!

  • That’s great! (It’s been a few months since I last worked on this so I’m a bit fuzzy on the details).

    Yeah I didn’t have an exact need to show multiple records. I just wanted to be able to pull content from one area and then content from another. That’s what mainly started this whole thing – the price was based on the container, not the scent.

    Essentially I needed to bounce back and forth between two different taxonomies.

    It was tricky, but it works well (here’s the result of the exact code above) https://candleflare.com/scents/monkey-farts/

    The page is to pull all of the posts that have the scent taxonomy term “monkey farts” then display them, but while doing that, pull the base price from the container taxonomy associated with it (price is based on the container, not the product).

    What started this was being able to change the pricing at the container level, not product level, since this particular use case the prices are dependent on container, then added amount for the wick.

    Glad that I helped save you time! This bugged me for a week so I’m glad you were able to get it done in less time!

  • Hi Brad, Glad I could help you out! It took me a week and two other people to help me figure it out! It’s great to hear you were able to figure it out too!

  • Circling back to this to provide a solution for someone who may be looking for it.

    I had three custom post types before:
    product
    container
    scent

    I changed the container and scent from custom post type to taxonomy.

    Again, the goal was to put content in a format that I could pull, based on the product custom field values (using ACF custom fields).

    Thus: Lavender Mason Candle $20

    Where “Lavender Mason Candle” is the product, “lavender” is the scent, and “mason candle” is the container. The $20 comes from a custom field on the container taxonomy.

    Solution (this is for a taxonomy.php page, but the main part at the bottom could very well work on others.)

       <ul>
    	<?php
    		// Get the current page taxonomy term info
    		$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); 	
    										
    		// args
    		$args = array(
    			'post_type'   => 'products', //
    			'tax_query'   => array(
    				array(
    					'taxonomy' => 'scents',
    					'field'    => 'slug',
    					'terms'    => $term,
    				),
    			)
    		);
    
    		// New Query
    		$custom_query = new WP_Query( $args );?>
    					
    		<?php if( $custom_query->have_posts() ) : while( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
    				  	
    			<li>
    				<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a>
    				<!-- For part of the title, I want to temporarily pull info from the $container -->
    				<a href="<?php the_permalink(); ?>" title="<?php the_title();?>: $<?php $container = get_field('container'); if( $container ): the_field('base_price', $container); ?>+<?php endif; ?>">
    				<!-- After the title, I want to revert back to the original post data-->					
    					<p><?php the_title();?></p>
    					<!--Now back again to the container-->	
    					<?php $container = get_field('container'); if( $container ): ?>
    					<p class="price">$<?php the_field('base_price', $container); ?>+</p>
    					<?php endif; ?>
    					<!--And back again to the original post data-->
    				</a>
    								
    			</li>
    		<?php endwhile; wp_reset_postdata();?>
    </ul>

    This is the main worker to help selectively pick what goes from where:

        <?php $container = get_field('container'); if( $container ): ?>
    					<p class="price">$<?php the_field('base_price', $container); ?>+</p>
    					<?php endif; ?>

    Hope this helps someone else and saves them three days of searching for answers for something similar.

  • Hi John,

    The query is just to filter out the “product” custom post type, as the category could also be the scent too.

    `<?php get_header(); ?>

    <!– category.php–>

    <div id=”pagecontent” class=”contentwidth”>

    <h1><?php single_cat_title(); ?></h1>

    <section class=”productslist”>

    <ul class=”list-items categories”>
    <?php
    $cat = get_queried_object();
    $cat_id = $cat->cat_ID;
    $custom_query = new WP_Query(
    array(
    ‘post_type’ => array(‘post’, ‘products’),
    ‘cat’ => $cat_id
    )
    );

    if ( $custom_query->have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>

    <li>
    <?php // check if the post has a Post Thumbnail assigned to it.
    if ( has_post_thumbnail() ) {
    echo “<a href=”;
    the_permalink();
    echo “>”;
    the_post_thumbnail(‘thumbnail’);
    echo “</a>”;
    }
    ;?>
    <a href=”<?php the_permalink(); ?>” title=”<?php the_title();?>: $<?php the_field(‘base_price’); ?>+”>
    <p><?php the_title();?></p>
    <?php
    $post = get_field(‘container’);
    setup_postdata( $post );
    ?>
    <p class=”price”>$<?php the_field(‘base_price’); ?>+</p>
    <?php wp_reset_postdata(); // IMPORTANT – reset the $post object so the rest of the page works correctly ?>
    </a>
    </li>
    <?php endwhile; wp_reset_query();?>
    </ul>

    <?php else : ?>
    <p>Sorry, no posts matched your criteria.</p>
    <?php endif; ?>

    </section><!–end .categorylist–>

    </div><!–end #pagecontent.contentwidth–>
    <?php get_footer(); ?>
    `
    The whole point was to make it easier to update repeating pieces of content.

    Each product has a scent and container that is a repeating piece of content.

    There could be 50 products with one scent – having the scent as a CPT allows me to edit the scent info without editing 50 products at once. Same with container.

    Products are priced by container. So over the long term. it’s easier to change the container price over a few containers than it would be to change 200+ products pricing.

    The setup_postdata I got from somewhere in these forms and stuck with it because it worked on part of the code.

  • Hi John,

    Thank you for your answer! I’m actually wanting to output the “base_price” that is from a CPT.

    This works:

    <?php
    								$post_object = get_field('container');
    								if( $post_object ): 
    									// override $post
    									$post = $post_object;
    									setup_postdata( $post ); 
    							?>
    							<p class="price">$<?php the_field('base_price'); ?>+</p>
    							<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    							<?php endif; ?>'

    But I can’t get it to work when I move it above the first place where I have base_price without it calling the wrong title.

    I want it to pull:
    Current post link
    Current post title
    Price of the CPT of “containers” attached to post.
    Current post title
    Price of the CPT of “containers” attached to post.

    In that order. Which means I have to bounce between the current loop pulling the category info, to then the CPT of containers, to back to the category info, then back to the CPT again.

    I hope that makes sense.

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