Support

Account

Forum Replies Created

  • Thanks so much Luca – always have trouble with the relationship field 🙁

  • Have tried the following and it’s removed the error but does not display anything if the page has no selected addons. If the array doesn’t exist then I can’t get it to output anything.

    <?php 
        if(is_array($addons_included_ids)) :
        if( in_array($addon->ID, $addons_included_ids) ): ?>
  • Thank you Lucas – that worked for 95% of them. However, when the page has no addons selected I get the following error:

    Warning: in_array() expects parameter 2 to be array, string given in

    Not sure what’s going on there?

  • Hi Luca,

    add_ons_suites is a relationship field on the current post – multiple posts from the ctp addons are selected and return the post-ID.

    Hope that helps.

  • Hi Aregmk – can see what you are getting at but it’s returning negative (i.e. <i class="fas fa-times"></i> where there are five add-ons selected.

  • The post object – switched it to post ID but it makes no difference?

  • Thanks aregmk – have added set_postdata($addon) after the foreach but not getting the right result, i.e. getting same result if item is in the relationship or not.

    Adding the post_id onto the add_on_suites gives me the opposite result. Note: add_on_suites is not a field of the addons cpt – it is a field on the current post (i.e. the relationship exists on this post to the addons cpt).

    Wondering if it could be the $included query <?php if( $included ): ?> is just checking if ‘anything at all’ is included and if so, then giving me a tick?

  • Can you confirm that this has been fixed please. Server is about to upgrade to 7.2 and I am using both of these.

  • Think that I asked the wrong question, or didn’t put all info (!duh).

    I have two CPTs: Products & tools. In Products you can select related tools using the relationship field.

    The tools have a radio button (wheel_section). On the product page I want to get all relationships and display them in groups based on the value of wheel_section.

    Been searching, racking my brain, biting my nails, etc. but cannot work out how to do this. This is how far I have got – if anyone can point me in the right direction would be very grateful.

    1) Get related posts
    <?php $posts = get_field('product_tools'); if( $posts ): ?>

    2) Look through posts / setup data

    <?php $i=0; foreach( $posts as $post): ?>
     <?php setup_postdata($post); ?>

    3) Get choices from wheel_section radio button
    <?php echo implode(', ', get_field_object('wheel_section')[choices]); ?>

    4) Loop through choices
    This is where I get lost. Now I have an array and I need to loop through each choice and get corresponding label and calculators so I get:

    WHEEL SECTION LABEL 1
    – calculators in wheel section 1

    WHEEL SECTION LABEL 2
    – calculators in wheel section 2

  • Thanks so much for this – wasn’t aware of the options feature! Love it!

  • Thanks James – we forgot the opening and closing {}

    Working beautifully now – thanks so much for your help.

  • This reply has been marked as private.
  • Hi James,

    Understand where you’re coming from but this didn’t fix the issue. Used code:

    <?php if( have_rows('digital_sections') ): ?>
        
        <style>  
            .photo-box {
                  -webkit-background-size: cover;
                  -moz-background-size: cover;
                  -o-background-size:  cover;
                  background-size: cover;
    
            }
            .fore-image {
                   background-size: contain;
            }
        </style>
        
        <?php while ( have_rows('digital_sections') ) : the_row();?>
    
            <?php if( get_row_layout() == 'hero_images' ); ?>
            <header class="container-fluid photo-box" style="background: url(<?php the_sub_field('hero_image'); ?>) no-repeat center center fixed;">
                <div class="fore-image" style="background: url(<?php the_sub_field('fore_image'); ?>) no-repeat center;"></div>
            </header>        
    
    <?php endwhile; endif; ?>

    And now everything within the <?php while ( have_rows('digital_sections') ) : the_row();?> is repeated and the first set still empty?

    Resulting code:

    <header style="background: url() no-repeat center center fixed;" class="container-fluid photo-box">
                <div style="background: transparent url("") no-repeat scroll center center; transform: translate(0px, -4.5%);" class="fore-image"></div>
            </header>
    <header style="background: url("http://localhost/startup/wp-content/uploads/2016/06/sg-bg-2.jpg") no-repeat center center fixed;" class="container-fluid photo-box">
                <div style="background: transparent url("http://localhost/startup/wp-content/uploads/2016/06/fore-image.png";) no-repeat scroll center center;" class="fore-image"></div>
            </header>
    
  • Thanks Jonathon – that worked! Made my day 🙂

  • Am trying to do a similar thing – not sure if you figured it but I found the answer at bloke.com. Add to functions.php

    I’m trying to take it a step further and want to display a repeater field in the tab and can’t figure it out. Any Woocommerce gurus out there that can help?

    add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
    function woo_new_product_tab( $tabs ) {
    global $post, $product;
    $ingredients = get_post_meta($post->ID, 'ingredients', TRUE);
    // Adds the new tab
    if (!empty($ingredients)) {
    $tabs['test_tab'] = array(
    'title' => __( 'Ingredients', 'woocommerce' ),
    'priority' => 50,
    'callback' => 'woo_new_product_tab_content'
    );
    }return $tabs;
    }
    function woo_new_product_tab_content() {
    global $post, $product;
    $ingredients = get_post_meta($post->ID, 'ingredients', TRUE);
    echo($ingredients);
    }
  • Any idea why I’m having problems with this John?

    I’m getting all data in correctly but I want to change the order displayed. When I put the relationship lookup first, the awards data (award name/year/short description) disappears. I can make it appear this way using absolute positioning but it stuffs up when it comes to other devices.

    !! I will get this relationshi/reverse relationship stuff worked out one day 🙂

    Thx

    This is the order I want but cannot get

    
    <?php $awards_query = new WP_Query( array( 'post_type' => 'awards', 'showposts' => 50, 'meta_key'=>'award_year',  'orderby' => 'meta_value_num' ) ); ?>
    
    <?php while ($awards_query->have_posts()) : $awards_query->the_post(); ?>
    
    <div class="vc_col-med-4 vc_col-lg-4 vc_col-sm-6 vc_col-xs-12 awards"> 
    <?php foreach(get_field('project') as $post):
       setup_postdata($post); ?>
       <a href="<?php the_permalink(); ?>" >
       <?php the_post_thumbnail('awards', array( 'class' => 'award_img' ) ); ?></a>
       <h3 class="award_project"><?php the_title(); ?></h3>
       <?php endforeach; wp_reset_postdata(); ?>
    
      <h2 class="award_name"><?php the_field('award_name'); ?> | 
      <?php the_field('award_year'); ?></h2>
      <p><?php the_field('short_description'); ?></p> 
    
    </div><!--end cols -->
    
    

    This is the work around I’m using with absolute positioning

    
    <?php $awards_query = new WP_Query( array( 'post_type' => 'awards', 'showposts' => 50, 'meta_key'=>'award_year',  'orderby' => 'meta_value_num' ) ); ?>
    
    <?php while ($awards_query->have_posts()) : $awards_query->the_post(); ?>
    
    <div class="vc_col-med-4 vc_col-lg-4 vc_col-sm-6 vc_col-xs-12 awards"> 
      <h2 class="award_name"><?php the_field('award_name'); ?> | 
      <?php the_field('award_year'); ?></h2>
      <p><?php the_field('short_description'); ?></p> 
    
    <?php foreach(get_field('project') as $post):
       setup_postdata($post); ?>
       <a href="<?php the_permalink(); ?>" >
       <?php the_post_thumbnail('awards', array( 'class' => 'award_img' ) ); ?></a>
       <h3 class="award_project"><?php the_title(); ?></h3>
       <?php endforeach; wp_reset_postdata(); ?>
    
    </div><!--end cols -->
    
    
  • Hi RBmac,

    Been away from the desk. Thanks for responding. Of course, not in the loop – makes total sense and now have it working. Setup_postdata was the answer.

    Code for anyone looking for it:

    <?php
    $args = array(
    	'post_type' => 'post',
    	'posts_per_page' => 1,
    	'meta_query' => array(
    		array(
    			'key' => 'field', // name of custom field
    			'value' => '"' . get_the_ID() . '"',
    			'compare' => 'LIKE'
    		)
    	)
    );
    $lastposts = get_posts( $args );
    foreach ( $lastposts as $post ) :
      setup_postdata( $post ); ?>
    	<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    	<p><?php the_content(); ?>
    <?php endforeach; 
    wp_reset_postdata(); ?>
  • Hi Kylu, am yet to solve this problem.

  • Was having the same issue and this worked for me! Thx

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