Support

Account

Forum Replies Created

  • Thanks for commenting @jarvis.

    The number field is a select field which is working fine in the query.

    The time field uses the ‘Time Picker’ field.

  • Hi @jarvis,

    It worked, but not 100% but looking better thanks 🙂

    This is the code which I updated slightly;

    $args = array( 
    		'post_type'         => 'cars',
    		'posts_per_page'    => -1,
    		'post_status' => 'publish',
    		'meta_query'    => array(
    			'post_type' => 'cars',
    			'post_per_page' => -1,
    			'post_status' => 'publish', 
    			'meta_query' => array(
    				array(
    					'key'       => 'sold',
    					'value'     => array('no'),
    					'compare'   => 'IN',
    				),
    			)
    		)
    	);
    	$wp_query = new WP_Query($args);
    	if ($wp_query->have_posts()) :
    		$get_price = array();
    		while ($wp_query->have_posts()) : $wp_query->the_post();
    			$get_price[] = get_field('price');
    		endwhile;
    	endif; #endif $wp_query
    	
    	$filter_price = array_unique($get_price);
    	
    	if($filter_price):
    
    		echo '<select name="sort_price" id="sort_price">';
    		echo '<option value="" selected disabled>Select...</option>';
    		echo '<option value="">All</option>';
    		
    		foreach($filter_price as $price):
    		
    			$args = array(
    				'post_type'         => 'cars',
    				'post_status' => 'publish',
    				'posts_per_page'	=> -1,
    				'orderby' => 'meta_value_num',
    				'order' => 'DESC',
    				'meta_query'	=> array(
    					'relation'		=> 'AND',
    					array(
    						'key'		=> 'price',
    						'value'		=> $price,
    						'compare'	=> '<='
    					),
    					array(
    						'key'       => 'sold',
    						'value'     => array('no'),
    						'compare'   => 'IN',
    					)
    				)
    			);
    			$wp_query = new WP_Query($args);
    		
    			$figure_total = $wp_query->found_posts;
    			$count = count( $wp_query->get_posts() );	
    		
    			$round_price = round($price, -3);;
    			echo '<option value="'.$round_price.'">Up to £'.$round_price.' ('.$count.')</option>';
    		
    			
    			wp_reset_query();
    		endforeach;
    		
    		echo '</select>';
    		
    		endif; #endif $filter_price

    It outputs the fields but seems to have duplicated them – so the options are;

    <option value="5000">Up to £5000 (4)</option>
    <option value="7000">Up to £7000 (6)</option>
    <option value="7000">Up to £7000 (8)</option>
    <option value="8000">Up to £8000 (9)</option>
    <option value="10000">Up to £10000 (12)</option>
    <option value="10000">Up to £10000 (1)</option>
    <option value="9000">Up to £9000 (11)</option>
    <option value="6000">Up to £6000 (5)</option>
    <option value="8000">Up to £8000 (10)</option>
    <option value="7000">Up to £7000 (7)</option>
    <option value="4000">Up to £4000 (2)</option>
    <option value="5000">Up to £5000 (3)</option>

    As you can see it duplicates them and some of the counts aren’t right as

    Upto £40000 (0) [cars in that price range]
    Upto £50000 (2) [cars in that price range]
    Upto £50000 (3) [cars in that price range]

  • Hi @jarvis,

    Thanks, that’s amazing!

    Just wondering now in the foreach loop how I add my select fields – for example;

    <select name="sort_price" id="sort_price">
    	<option value="" selected disabled>Select...</option>
    	<option value="">All</option>
    	<option value="5000">Up to £5000 (<?php echo $count; ?>)</option>
    	<option value="6000">Up to £6000 (<?php echo $count; ?>)</option>
    	<option value="7000">Up to £7000 (<?php echo $count; ?>)</option>
    	<option value="8000">Up to £8000 (<?php echo $count; ?>)</option>
    	<option value="9000">Up to £9000 (<?php echo $count; ?>)</option>
    	<option value="10000">Up to £10,000 (<?php echo $count; ?>)</option>
    </select>
  • Hi @jarvis,

    No problem, here is the full code;

    $args = array( 
    	'post_type'         => 'cars',
    	'posts_per_page'    => -1,
    	'post_status' => 'publish',
    	'meta_query'    => array(
    		'post_type' => 'cars',
    		'post_per_page' => -1,
    		'post_status' => 'publish', 
    		'meta_query' => array(
    			array(
    				'key'       => 'sold',
    				'value'     => array('no'),
    				'compare'   => 'IN',
    			),
    		)
    	)
    );
    $wp_query = new WP_Query($args);
    if ($wp_query->have_posts()) :
    $get_price = array();
    while ($wp_query->have_posts()) : $wp_query->the_post();
    $get_price[] = get_field('price');
    endwhile;
    endif; #endif $wp_query
    
    echo '<pre>';
    print_r($get_price);
    echo '</pre>';
    
    $filter_price = array_unique($get_price);
    
    echo '<pre>';
    print_r($filter_price);
    echo '</pre>';
    
    if($filter_price):
    foreach($filter_price as $price):
    echo '<p>Price: '.$price.'</p>';
    
    	$args = array(
    		'post_type'         => 'cars',
    		'posts_per_page'	=> -1,
    		'post_type'		=> 'your post type',
    		'meta_query'	=> array(
    			'relation'		=> 'AND',
    			array(
    				'key'		=> 'price',
    				'value'		=> $price,
    				'compare'	=> '<='
    			),
    		)
    	);
    	$wp_query = new WP_Query($args);
    
    $figure_total = $wp_query->found_posts;
    $count = count( $wp_query->get_posts() );	
    
    echo '<p>$figure_total: '.$figure_total.' count: '.$count.'</p>';
    
    endforeach;
    endif; #endif $filter_price
    
    wp_reset_query();

    Thanks again for the help in cracking this!

  • Hi @jarvis,

    Apologies for the delay in getting back to you.

    I’ve added the code and this is what was now outputted;

    $figure_total: 0 count: 0

  • This is what it outputs now @jarvis;

    Array
    (
        [0] => 5199
        [1] => 6999
        [2] => 7499
        [3] => 7799
        [4] => 9799
        [5] => 10399
        [6] => 8699
        [7] => 6399
        [8] => 7999
        [9] => 7399
        [10] => 4399
        [11] => 4699
    )
    Array
    (
        [0] => 5199
        [1] => 6999
        [2] => 7499
        [3] => 7799
        [4] => 9799
        [5] => 10399
        [6] => 8699
        [7] => 6399
        [8] => 7999
        [9] => 7399
        [10] => 4399
        [11] => 4699
    )
    Price: 5199
    
    $figure_total: 2 count: 2
    
    Price: 6999
    
    $figure_total: 2 count: 2
    
    Price: 7499
    
    $figure_total: 2 count: 2
    
    Price: 7799
    
    $figure_total: 2 count: 2
    
    Price: 9799
    
    $figure_total: 2 count: 2
    
    Price: 10399
    
    $figure_total: 2 count: 2
    
    Price: 8699
    
    $figure_total: 2 count: 2
    
    Price: 6399
    
    $figure_total: 2 count: 2
    
    Price: 7999
    
    $figure_total: 2 count: 2
    
    Price: 7399
    
    $figure_total: 2 count: 2
    
    Price: 4399
    
    $figure_total: 2 count: 2
    
    Price: 4699
    
    $figure_total: 2 count: 2

    Is it because it’s not checking against the figure total? e.g. Cars within £5000 = 5, cars within £7000 = 8

  • Hi @jarvis,

    No problem, I appreciate the assistance.

    This is what it came back with;

    Array
    (
    [0] => 5199
    [1] => 6999
    [2] => 7499
    [3] => 7799
    [4] => 9799
    [5] => 10399
    [6] => 8699
    [7] => 6399
    [8] => 7999
    [9] => 7399
    [10] => 4399
    [11] => 4699
    )
    Array
    (
    [0] => 5199
    [1] => 6999
    [2] => 7499
    [3] => 7799
    [4] => 9799
    [5] => 10399
    [6] => 8699
    [7] => 6399
    [8] => 7999
    [9] => 7399
    [10] => 4399
    [11] => 4699
    )
    Price: 5199

    2
    Price: 6999

    2
    Price: 7499

    2
    Price: 7799

    2
    Price: 9799

    2
    Price: 10399

    2
    Price: 8699

    2
    Price: 6399

    2
    Price: 7999

    2
    Price: 7399

    2
    Price: 4399

    2
    Price: 4699

    2

    It’s looping the prices just not the count correctly which is odd.

  • Hi @jarvis,

    Thanks for replying, I’ve tried it and it only outputs one in a loop;

    2222222222

    I know £10,000 has 1 and £5000 should be around 12

  • Hi @jarvis,

    Thanks for replying, I managed to solve it using

    get_field('tax_amount', $post_id)

    and making sure the following was at the top;

    `global $post;

    $post_id = false;
    if (defined(‘DOING_AJAX’) && DOING_AJAX) {
    if (isset($_GET[‘post_id’])) {
    $post_id = $_GET[‘post_id’];
    }
    } else {
    $post_id = $post->ID;
    }`

  • Ok, I’ve been able to a bit further and can edit the widgets now.

    I’ve created an IF statement so that if the colour hasn’t been selected it will not show.

    However, they’re all coming back “no” despite 2 colours having selected.

    function woo_colour_swatches( $term_html, $term, $link, $count ) {
        
        $color = get_field('colour', $term);
    
        if( $colour ){
            echo 'Yes';
        }else{
            echo 'No';
        }
    
        echo '<a href=" '. $link .' ">'. $term->name .'</a>';
    
        return $some_modified_value;
    }
    add_filter( 'woocommerce_layered_nav_term_html', 'woo_colour_swatches', 10, 4 );

    **UPDATE**

    Mis-spelt color with colour

  • Hi @hube2,

    I worked out it was the output format that was causing the confusion. Once I had adjusted that in the back-end it worked.

    Thanks for the help though 🙂

  • I think that might that be it because I’ve downloaded the latest update plugin from the website and installed it manually that way.

    However, when I check updates in the admin area, it says “Current Version 5.3.7” despite it having 5.9.0 installed.

  • Thanks @hube2 , I did think that was the case but wanted to check.

    The other weird thing is (not sure if it’s related) is that the plugin keeps asking to be updated, which I do and then refresh the page and it asks again – it also says it’s 5.9.0 but looks like an old version.

  • Changed ACF in admin area to “Post Object” and then use;

    <?php 
    	$terms = get_sub_field('category');
    	if( $terms ): 
    ?>
        <ul>
        <?php foreach( $terms as $term ): ?>
            <h2>Term: <?php echo esc_html( $term->term_id ); ?></h2>
        <?php endforeach; ?>
        </ul>
    <?php endif; ?>
  • Hi John,

    Thanks, I cracked it with this (for other people’s reference)

    <?php
    	$career_one_group = get_sub_field('career_one_group');
    	if( $career_one_group ): 
    ?>
    
    	<?php if( have_rows('career_one_group') ): ?> 
        <?php while( have_rows('career_one_group') ): the_row(); 
        	$show_careers_information = get_sub_field('show_careers_information');
        	$show_local_vacancy = get_sub_field('show_local_vacancy');
        	$show_day_in_the_life_of_a = get_sub_field('show_day_in_the_life_of_a');
        	$show_what_employers_want_transferable_skills = get_sub_field('show_what_employers_want_transferable_skills');
        	$show_timeline = get_sub_field('show_timeline');
        ?>
        <!-- Start Loop -->
    
    			<?php if( $show_careers_information ): ?>
    
    			<?php endif; ?>
    
    	<!-- End Loop -->
    	<?php endwhile; ?>        
    	<?php endif; ?> 
    	<?php wp_reset_query(); ?>
    
    <?php endif; ?>	
  • It’s inside the group if that’s what you mean?

    I’ve attached URL (image) of back-end – https://ibb.co/7NqH5KP

  • Hi John,

    It seems you were right near the start and my brain wasn’t connecting the dots.

    This code cracked it;

    <?php
        if( have_rows('content') ):
        while ( have_rows('content') ) : the_row();
    ?>

    Thanks for the continued help 🙂

  • Sorry didn’t mean to confuse.

    I’m trying to show this flex layout on home.php which is blogs page, showing all my blogs.

    Each page has a banner (which works fine on other pages) but doesn’t on the blogs page.

  • These are the fields in ACF (flex);
    https://ibb.co/QKTMHp9

    and these are how they look in the blogs page;
    https://ibb.co/rvb7bPT

  • Hi John,

    That didn’t work sadly…

    I have the home.php page and want a banner, in the back-end I have fields created for banner_heading etc. and just want them to appear.

    However, it doesn’t despite trying different techniques including the above.

  • @lsterling03 codes work fine, but do I need to still set up the CRON job?

  • Perfect thanks John, I can see now where I was going wrong 🙂

Viewing 25 posts - 1 through 25 (of 54 total)