Support

Account

Forum Replies Created

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

  • May I ask how you know it’s definitely ACF causing the issue?

    Are there any errors/error logs?

  • 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

  • Sorry, can you show what you enter into the field of ‘social_icon_static’

    Ideally, it would be useful to see the code when it’s hardcoded

    Then copy and paste the source when you’re outputting the code with the ACF field

    Just trying to work out the difference as to why one works and one doesn’t!

  • 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 @forbiddenchunk,
    Please can you post your code? I’d expect at least one value before seeing no results.
    Looking at the array, do any of the price ranges only have a total of 2?

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

  • Hi @iceman333

    Which but does not solve the problem? If you provide more details, maybe someone can help!

  • 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

  • What does get_field(‘social_icon_static’); output?

    May help to then se what’s happening.

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

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

  • Hi @beclickedagency

    I’m not familiar with Elementor but I wonder if it’s a paid add-on.

    If you look here unless I’m mistaken it seems to be you need to get the repeater add-on

  • Hi @toniup

    Within your loop, you could use the get_post_type() to see which post type is the post is.

    You could then add a conditional. Something like:

    
    <?php
    $posts = get_field( 'relazioni_strutture' );
    if ( $posts ) : ?>
    	<?php foreach( $posts as $post) : ?>
    	<?php setup_postdata( $post ); ?>
    
    	<?php $post_type = get_post_type();
    	if( $post_type == 'Struttura' ):
    	?>
    
    		<?php the_title(); ?>
    
    	<?php endif; #$post_type ?>
    
    	<?php endforeach; ?>
    	<?php wp_reset_postdata(); ?>
    <?php endif; ?>
    

    May need tweaking but should get you underway

  • Hi @atise

    If you’re creating an image field, when you add the code to your template (please see here), you can add the class to your img tag.

    Once you add the class, say ‘responsive-img’, you can then reference that in your CSS.

    So:

    
    <?php 
    $image = get_field('image');
    if( !empty( $image ) ): ?>
        <img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" class="responsive-img" />
    <?php endif; ?>

    Then in your CSS:

    .responsive-img {
    /*whatever you need to add*/
    }
  • Hi @liqid

    Ok, so hardcoding works, which means it must be when outputting the field that additional code(?) is being added.

    If you hard code it and it works, copy the line into something like notepad

    Then, add your code back in, inspect it and copy the line into notepad

    If you compare them, does the latter one have anything different? If so, what is the difference?

  • Hi @pmmg
    I think I’d be inclined to do something like:

    
    $current_url = get_permalink();
    $state_url = get_field('state_url');
    $product = get_title();
    echo '<a href="$current_url.$state_url.'-'.$product">Link</a>';
    

    Or

    
    $site_url = get_site_url();
    $state_url = get_field('state_url');
    $product = get_title();
    echo '<a href="$site_url.'/product/'.$state_url.'-'.$product">Link</a>';
    

    May need a little tweaking but should get you underway!

  • Hi @avahidesign

    I guess you can approach it in different ways.

    If you’re looping through your CPT, you can simply echo out the custom field if it exists:

    <?php
    global $wp_query;
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    $args = array(
    	'posts_per_page' => 10,
    	'post_type'		=> 'your-cpt',
    	'paged' 		=> $paged
    );
    $wp_query = new WP_Query($args); ?>
    <?php if ($wp_query->have_posts()) : ?>
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); 
    $position = get_field('position');
    ?>
    
    Your loop content
    <?php 
    if($position):
    	echo $position;
    endif;
    ?>
    
    <?php endwhile;  ?> 
    <?php endif; wp_reset_query(); ?>

    Or you can add ACF fields to a custom excerpt:

    // Custom Excerpt function for Advanced Custom Fields
    function custom_field_excerpt() {
    	global $post;
    	$text = get_field('position'); //Replace 'your_field_name'
    	if ( '' != $text ) {
    		$text = strip_shortcodes( $text );
    		$text = apply_filters('the_content', $text);
    		$text = str_replace(']]>', ']]>', $text);
    		$excerpt_length = 20; // 20 words
    		$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
    		$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
    	}
    	return apply_filters('the_excerpt', $text);
    }

    Then in your loop, display the custom excerpt:
    echo custom_field_excerpt();

  • Hi @unbekannter

    The below will output the selected checkboxes into an array:

    
    $values = array();
    $time = get_field('second-field');
    foreach ($time as $second) {
        $values[] = '"'.$second.'" => 0'; 
    }
    
    echo implode(',', $values);
    

    Do you need it as an associative array? I’m trying to work out it out.
    You asked for checkboxes to be an array but the example you give of how it needs to be is more like an associative array (I believe but could be wrong!).

  • Hi @cstrasz

    If you add this to the functions file:

    
    // Custom Excerpt function for Advanced Custom Fields
    function custom_field_excerpt() {
    	global $post;
    	$text = get_field('your_field_name'); //Replace 'your_field_name'
    	if ( '' != $text ) {
    		$text = strip_shortcodes( $text );
    		$text = apply_filters('the_content', $text);
    		$text = str_replace(']]>', ']]>', $text);
    		$excerpt_length = 20; // 20 words
    		$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
    		$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
    	}
    	return apply_filters('the_excerpt', $text);
    }
    

    Ensure you replace ‘your_field_name’ with the actual ACF field you need to use.

    In your template (possibly archive.php), where you need to find the loop and add:
    echo custom_field_excerpt();

    Depending on your theme/custom code, you may need to adjust where the code is displayed.

    For example, you may have the loop which has an include to another file to show the content, so the above line may need adding there instead.

Viewing 25 posts - 276 through 300 (of 366 total)