Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • 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]

  • Hello
    thanks for the code, but I still do not receive an email, here is my new code

    // Sending email after Front-end post submission
    add_action('acf/save_post', 'yourdomain_save_post', 15);
    
    function yourdomain_save_post($post_id) {
    	// Return if not a post
    	if( get_post_type($post_id) !== 'recette' ) { // here 'post' will be your post type
    
    	    return;	
    
    	}
    	
    	// Return if editing in admin
    	if( is_admin() ) {
    	     return;
    	}
    
    	// Vars
    $post = get_post( $post_id );
    
    $title = wp_strip_all_tags(get_the_title($post->ID));
    
    $to			= "{$admin_email}";
    $subject	= "{$blog_title} :: {$title}";
    $message	= "Your message here";
    
    $headers = array(
    	'Content-Type: text/html; charset=UTF-8',
    	#'Bcc:' . '[email protected]',
    	'From: '.get_option( 'blogname' ).' <[email protected]>'
    );
    
    // send email
    wp_mail($to, $subject, $body, $headers );
    }
    
  • I think I misunderstood what you were asking before, hope this is what your looking for.

    ACF output:
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 150 150"><path style="fill:#fff" d="M3.305 49.574v79.388h143.916V49.708L75.382 80.745 3.305 49.574z"></path><path style="fill:#fff" d="M3.305 21.777v13.846l72.077 31.172 71.839-31.068v-13.95H3.305z"></path></svg>

    Hardcoded output:
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 150 150"><path style="fill:#fff" d="M3.305 49.574v79.388h143.916V49.708L75.382 80.745 3.305 49.574z"></path><path style="fill:#fff" d="M3.305 21.777v13.846l72.077 31.172 71.839-31.068v-13.95H3.305z"></path></svg>

    Look identical to me.

    Below is a screenshot of the actual output. The top <svg> tag is the acf field and the bottom is the hardcode between the <a> tag. Disregard the <img> tag as I’m using the SVG plugin till this is resolved.

    ACF and hardcode output

    Here’s the code:

            $social_icon_static = get_field('social_icon_static', $item);
            //$social_icon_hover = get_field('social_icon_hover', $item);
    
          if ( $depth == 0 ) {
    
              $item_output .= '</span><div class="uk-inline-clip uk-transition-toggle uk-animation-toggle social-icon-container" tabindex="0">
    
                <img class="uk-animation-slide-top uk-animation-reverse social-top" width="16px" height="16px" src="">
                '. get_template_part( 'assets/images/svg/inline', $social_icon_static) .'
                <img class="uk-transition-slide-bottom social-bottom" width="16px" height="16px" src="">
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 150 150"><path style="fill:#fff" d="M3.305 49.574v79.388h143.916V49.708L75.382 80.745 3.305 49.574z"/><path style="fill:#fff" d="M3.305 21.777v13.846l72.077 31.172 71.839-31.068v-13.95H3.305z"/></svg>
      
              </div>';
          }
  • Sorry, I think misunderstood what you were asking before.

    Here’s what the ACF field outputs:
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 150 150"><path style="fill:#fff" d="M3.305 49.574v79.388h143.916V49.708L75.382 80.745 3.305 49.574z"></path><path style="fill:#fff" d="M3.305 21.777v13.846l72.077 31.172 71.839-31.068v-13.95H3.305z"></path></svg>

    Here’s the hardcode:
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 150 150"><path style="fill:#fff" d="M3.305 49.574v79.388h143.916V49.708L75.382 80.745 3.305 49.574z"></path><path style="fill:#fff" d="M3.305 21.777v13.846l72.077 31.172 71.839-31.068v-13.95H3.305z"></path></svg>

    Look identical to me.

    Here’s a screenshot of the output. The top <svg> tag is the acf field rendering outside the <a> tag and the bottom is the hardcoded version. Disregard the <img> tag, I decided to use the SVG plugin till we resolve this.

    acf and hardcode output

    Hope this is what you were asking for.

  • What about something like:

    <?php
    
    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):
    echo '<p>Price: '.$price.'</p>';
    
    	$args = array(
    		'post_type'         => 'cars',
    		'posts_per_page'	=> -1,
    		'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>';
    	$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

    Again, untested code so may error or need some tweaking!

  • 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,

    i’ve just spun up a fresh install, in Italian as Site Language before i did anything else, then imported pages, repeaters, CPT, and ACF fields and groups.

    I think i’m a bt closer to understanding what’s causing the issue, but not why or how to fix it. i use Oxygen, and it’s Repeater function to show my CPT (events) and it’s ACF fields (artist name, event venue, event date, address etc) on the page.

    i build the repeater array like this:
    post type: event
    meta_query > array: key: ‘single_event_date’ (ACF field), value: PHP Function return Value – ‘event_order’, compare: < (past dates)

    ‘event_order’ is a custom function written like this:
    function event_order() {
    $today = date(‘Ymd’);
    return $today;
    }

    the objective is this: there’s a bunch of events set in the past and future. in some arrays i want to show only Future events, in others i want to show only past events. the array key is an ACF field called ‘single_event_date.’ the PHP value is today’s date (expressed as the new function ‘event_order’), and the array compares today’s date to the single_event_date to separate those events that are in the past, and those that are in the future.

    the problem is this: when the Site Language is English, the code snippet and the meta_query arrays work perfectly. in the old site, switching Site Language to Italian broke everything. and in thhis new test intall the same thing happens. WHY, and why when the site language isn’t English, i have no idea, but it’s the snippet, and ACF. any ideas?

  • Photo Gallery looks like a plugin add-on as seen here.

    So try adding the code from the plugin example to your template:

    <?php
        //Get the images ids from the post_metadata
        $images = acf_photo_gallery('gallery', $post->ID);
        //Check if return array has anything in it
        if( count($images) ):
            //Cool, we got some data so now let's loop over it
            foreach($images as $image):
                $id = $image['id']; // The attachment id of the media
                $title = $image['title']; //The title
                $caption= $image['caption']; //The caption
                $full_image_url= $image['full_image_url']; //Full size image url
                $full_image_url = acf_photo_gallery_resize_image($full_image_url, 262, 160); //Resized size to 262px width by 160px height image url
                $thumbnail_image_url= $image['thumbnail_image_url']; //Get the thumbnail size image url 150px by 150px
                $url= $image['url']; //Goto any link when clicked
                $target= $image['target']; //Open normal or new tab
                $alt = get_field('photo_gallery_alt', $id); //Get the alt which is a extra field (See below how to add extra fields)
                $class = get_field('photo_gallery_class', $id); //Get the class which is a extra field (See below how to add extra fields)
    ?>
    <div class="col-xs-6 col-md-3">
        <div class="thumbnail">
            <?php if( !empty($url) ){ ?><a href="<?php echo $url; ?>" <?php echo ($target == 'true' )? 'target="_blank"': ''; ?>><?php } ?>
                <img src="<?php echo $full_image_url; ?>" alt="<?php echo $title; ?>" title="<?php echo $title; ?>">
            <?php if( !empty($url) ){ ?></a><?php } ?>
        </div>
    </div>
    <?php endforeach; endif; ?>
  • Hi jarvis
    thank you very much for your help
    It’s super nice
    But I just realized that I already have a problem when I use my form
    When I click on add images nothing happens
    The add button turns black

    Here are screenshots
    These are of course tests that I carry out

    <?php /*Template Name: User Submit*/;?>
    <?php acf_form_head(); ?>
    <?php get_header(); ?>
    
    	<div id="container" >
    
        <div class="row">
        	<div class="col-sm-12">
        	    
    			<?php /* The loop */ ?>
    			<?php while ( have_posts() ) : the_post(); ?>
    		
    			
    				<!-- a supprimer si on enlève l'éditeur par défaut -->
    		
    				<!------------>
    
    	
    					<p> <?php the_field('Ingredients'); ?></p>
    					<p> <?php the_field('Cuisson'); ?></p>
    					<p> <?php the_field('Temps'); ?></p>
    				<p> <?php the_field('Preparation'); ?></p>
    				<p> <?php the_field('Difficulté'); ?></p>
    			<p> <?php the_field('gallery'); ?></p>
    			
    				<?php  $options = array('post_id'		=> 'new',
    		'field_groups' => array(4),
    		'post_title'	=> true,
    		
    	
    			'post_type'		=> 'recette',
    			'post_status'	=> 'draft',
    		
    		//'updated_message'    => 'Merci pour votre participation!Votre recette sera publiée prochainement',
    		'updated_message' => __("Recette publiée", 'acf'),
    		//'return'		=> home_url('merci'),
    	'%post_url%', // Redirect to new post url
    		'submit_value'	=> 'Postez votre recette'
    		//'submit_value'	=> 'Send'
    		);
    				 acf_form($options);?>
    
    			<?php endwhile; ?>
    </div>
    		</div><!-- #content -->
    	</div><!-- #primary -->
    
    <?php //get_footer(); ?>

    screnn
    scren1

  • Hi @flexi2202

    This is what I use and it works ok:

    $post = get_post( $post_id );
    
    $title = wp_strip_all_tags(get_the_title($post->ID));
    
    $to			= "{$admin_email}";
    $subject	= "{$blog_title} :: {$title}";
    $message	= "Your message here";
    
    $headers = array(
    	'Content-Type: text/html; charset=UTF-8',
    	#'Bcc:' . '[email protected]',
    	'From: '.get_option( 'blogname' ).' <[email protected]>'
    );
    
    // send email
    wp_mail($to, $subject, $body, $headers );

    Perhaps alter for your own needs and see if it works.

  • I think you’re missing a parameter.

    The example in the docs shows:
    [acf field="field_name" post_id="123"]

    As you’re using a tax/cat, you would need to pass in the ID I think.

    So something more like:
    [acf field="field_name" post_id="term_X"] # X is the term ID you're getting the value from

  • There were 2 errors in the code:
    1) The second loop had post_type twice
    2) The wp_reset_query was in the wrong place

    $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,
    		'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>';
    	wp_reset_query();
    
    endforeach;
    endif; #endif $filter_price

    I’ve tried the above code and it worked for me!

  • 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!

  • John, thanks for the add_attachment tip.

    I also found similar code at https://wordpress.stackexchange.com/a/310689/39300

    Whilst it assumes Post is the connected object, it also works for User.

    The following code now takes the connected User’s name and uses that also for Title and Alt fields.

    All told, now I have:

    • Filter avatars uploads to a specific folder
    • Rename uploaded avatar to match username
    • Use User’s name as attached image’s Title and Alt fields

    Thanks!

    /**
     * ==============================================================================
     *             ALSO SET IMAGE TITLE & ALT TO USER/POST NAME
     *    When an image is uploaded, use the attached Post (User) edtails
     *    to set Title, Alt fields etc.
     *    cf. https://wordpress.stackexchange.com/a/310689/39300
     *    cf. https://support.advancedcustomfields.com/forums/topic/force-an-image-file-upload-to-a-particular-directory/page/2/
     * ==============================================================================
     */
    
    // https://wordpress.stackexchange.com/a/310689/39300
    function my_set_image_meta_upon_image_upload( $post_ID ) {
    
        // "the first thing that your action should do is to remove
        // itself so that it does not run again."
        remove_filter('add_attachment', 'your_function_name_here');
    
        // Check if uploaded file is an image, else do nothing
    
        if ( wp_attachment_is_image( $post_ID ) ) {
    
            $my_image_title = get_post( $post_ID )->post_title;
    
            // Added by Robert Andrews
            // Get user name to use in image details
            $user = get_user_by( 'slug', $my_image_title );
            $user_name = $user->display_name;
            $my_image_title = $user_name;
    
            // Sanitize the title:  remove hyphens, underscores & extra spaces:
            // $my_image_title = preg_replace( '%[-_]+%', ' ',  $my_image_title );
    
            // Sanitize the title:  capitalize first letter of every word (other letters lower case):
            // $my_image_title = ucwords( strtolower( $my_image_title ) );
    
            // Create an array with the image meta (Title, Caption, Description) to be updated
            // Note:  comment out the Excerpt/Caption or Content/Description lines if not needed
            $my_image_meta = array(
                'ID'        => $post_ID,            // Specify the image (ID) to be updated
                'post_title'    => $my_image_title,     // Set image Title to sanitized title
                // 'post_excerpt'  => $my_image_title,     // Set image Caption (Excerpt) to sanitized title
                // 'post_content'  => $my_image_title,     // Set image Description (Content) to sanitized title
            );
    
            // Set the image Alt-Text
            update_post_meta( $post_ID, '_wp_attachment_image_alt', 'Photo of '.$my_image_title );
    
            // Set the image meta (e.g. Title, Excerpt, Content)
            wp_update_post( $my_image_meta );
    
        } 
    }
  • Hi @pbalazs89

    You could run 2 queries.

    The first loop you would query by the custom field ‘featured’ and set the posts per page to 2

    You then add another loop but this time query by the next custom field.

    Would that work for you?

  • This is what worked for me. Based on @hube2 but cleaned up a bit. Thanks!

    <a href="<?php the_sub_field('link', 'option'); ?>" target="_blank">
          <img class="test" src="<?php the_sub_field('image'); ?>" alt="<?php 
          echo get_post_meta(get_sub_field('image', false), '_wp_attachment_image_alt', true); ?>">
    </a>
  • It is actually relatively simple.I would like to create and evaluate a yearly catch list of all members for the fishing club.
    There are different waters, different fish species from the amount of fish weight is calculated.
    So this all works with repaeter.
    look here https://isen-fischer.de/form/fangmeldung-gaeste/
    I can also create post of it and see them in a list view.

    Now would like to process the data further.
    in Goggle sheet, I can not read the repeater. Only completely as text. But no single repeater.

    With DB query I don’t know my way around.

    this is my problem.

    gr Wolfgang

  • Hi @flexi2202,

    Is your form only visible to logged in users? I assume you’re logged in as non-admin?

    I think you need to use the acf_form() parameters

    On of the parameters is: html_after_fields.

    As you’re logged in, you can access the user ID:
    $user_id = get_current_user_id();

    So you could then use a hidden value:
    'html_after_fields' => '<input type="hidden" name="acf[author_id]" value="'.$user_id.'"/>',

    Using acf/save_post

    You can then grab the hidden value and updated the post author:

    add_action('acf/save_post', 'my_acf_save_post');
    function my_acf_save_post( $post_id ) {
    	
    	$arg = array(
    		'ID' => $post_id,
    		'post_author' => $_POST['acf']['author_id']
    	);
    	wp_update_post( $arg );	
    	
    }

    Code is untested but should point you in the right direction

  • Do any of your price ranges only have 2?
    If you add a wp_reset_query(); after before the closing for each, does that make a difference?

  • No, I was talking about your options for calling acf_form(). Yours are wrong.

    
    $options = array(
      'post_id' => 'new',
      'field_groups' => array(
        4
      ),
      'post_title' => true,
      'new_post' => array(
        'post_type' => 'recette',
        'post_status' => 'draft',
      ),
      'updated_message' => __("Recette publiée", 'acf'),
      'submit_value' => 'Postez votre recette'
    );
    acf_form($options);
    
  • I think it’s the query in the foreach.

    What if you change it to:

    			$args = array(
    				'posts_per_page'	=> -1,
    				'post_type'		=> 'your post type',
    				'meta_query'	=> array(
    					'relation'		=> 'AND',
    					array(
    						'key'		=> 'price',
    						'value'		=> $price,
    						'compare'	=> '<='
    					),
    				)
    			);

    Specify the post type and see if that works?

    We know the data up to that point is right, so the issue is that query. Just need to tweak it

  • Ah, think we need one minor amend, please try:

    <?php
    $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(
    				'key'     => 'price',
    				'value'   => $price,
    				'type' => 'numeric',
    				'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

    I think we need count not found

  • Hi @forbiddenchunk

    Try adding some debugging to the code, see what outputs you get at the various stages:

    <?php
    $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(
    				'key'     => 'price',
    				'value'   => $price,
    				'type' => 'numeric',
    				'compare' => '<=',
    			);
    			$wp_query = new WP_Query($args);
    
    		$figure_total = $wp_query->found_posts;
    
    		echo $figure_total;
    		
    	endforeach;
    endif; #endif $filter_price

    So first thing is see what the main array gets
    Then see what the filtered results returns

    When you then loop the filtered array, output the values as a heading

    I did just adjust the query in the foreach, as mentioned, I’ve not tested the code, just trying to cobble it together as a starting point.

  • Hi @forbiddenchunk

    Absolutely no idea if this would work or not:

    
    <?php
    $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):
    	foreach($filter_price as $price):
    
    		$figure = new WP_Query( 
    			$args,
    			array( 
    				'key'     => 'price',
    				'value'   => $price,
    				'type' => 'numeric',
    				'compare' => '<=',
    			) 
    		);
    					
    		$query = new WP_Query( $figure );
    
    		$figure_total = $query->found_posts;
    
    		echo $figure_total;
    		
    	endforeach;
    endif; #endif $filter_price

    Basically, you loop all the individual prices and put them into an array
    Filter the prices to remove duplicates
    Then loop the filtered results and pass the value into your query
    Your query then returns the count

    Not tried the code!

  • There are plugins that allow saving data to a different DB table, but there is nothing available that will work with repeaters.

    How to use a repeater https://www.advancedcustomfields.com/resources/repeater/

    Importing data requires a plugin that will work with ACF fields. One example is WP All Import Pro.

Viewing 25 results - 5,276 through 5,300 (of 21,397 total)