Support

Account

Forum Replies Created

  • Alright, thanks. Sorry, it’s not yet clear yet. Let’s say I would put the next function in functions.php. Then it would send a mail every time a ACF form is saved, right?

    <?php function sendMail(){
    $to = '[email protected]';
    $subject = 'New mail';
    $headers = 'From: Themailer <[email protected]';
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $message = '<html><p>Thank you!</p></html>';
    mail($to, $subject, $message, $headers);
     }
     add_action('acf/pre_save_post', 'sendMail', 20); ?>

    How would I link this to a specific ACF form? Thanks!

  • Alright, thanks. But must I place this function in the same post template file? Or can I put it in the functions.php and set a specific form for this function?

    So the mail will only be send when form X is submitted.

  • Thanks, I already got it solved. It was a problem with a No Admin Acces plugin.. that set all capabilities for that role to none.

    I have solved the problem with the library access with some custom code.

    Thanks for your response.

  • Hi Wells,

    I tried several things, also the array but or I get 0, or I get the number of all posts in the post-type.

    This gives me 0:

    function get_post_count_by_meta( $meta_key, $meta_value, $post_type = 'post' ) {
    
    	$args = array(
    			'post_type' => $post_type,
    			'numberposts'	=> -1,			
    			'post_status'	=> 'publish',
    		);
    		
    		if ( $meta_key && $meta_value ) {
    				if ( is_array($meta_value) ) {
    	        $args['meta_query'][] = array('key' => $meta_key, 'value' => $meta_value, 'compare' => 'IN');
    	    }
    		
    		else {
    	        $args['meta_query'][] = array('key' => $meta_key, 'value' => $meta_value);
            }	
        }
    		
    		$posts = get_posts($args);
    		
    		$count = count($posts);
    
    	
    	return $count; 
    
    }
     $post_count = get_post_count_by_meta('niveau_jaren', 'Jaar 2', 'any');
    echo $post_count; 

    But I have an array that shows me all the posts that are checked with ‘Jaar 2’ which works:

     $args = array(
    	'numberposts' => -1,
    	'post_type' => 'any',
    	'meta_query' => array(
    		
    		array(
    			'key' => 'niveau_jaren',
    			'value' => 'Jaar 2',
    			'compare' => 'LIKE'			
    		),
    		
    	
    )
    );

    Now how would I ‘translate’ this array to the code above? Thanks!

  • Thank you, it was indeed the % % at the values.

  • Also tried this:

    <?php  if (is_page( 'testpagina' ) ) {
    // args
    
    $args = array(
    	'numberposts' => -1,
    	'post_type' => 'any',
    	'meta_query' => array(
    		'relation' => 'OR',
    		array(
    			'key' => 'niveau_jaren',
    			'value' => '%Jaar 1%',
    			'compare' => 'LIKE'
    		),
    		array(
    			'key' => 'niveau_jaren',
    			'value' => '%Jaar 3%',
    			'compare' => 'LIKE'
    		)
    	)
    );
     
    // get results
    $the_query = new WP_Query( $args );

    This should mean it gets the posts with value ‘Jaar 1’ or ‘Jaar 3’, right? I don’t get anything..

  • Well.. it does work with a radio button field group. But in my case I need to get it worked with checkboxes. Do I need to change anything?

  • @wells5609 If you could help me a bit further, that would be great.

    I’m trying to connect my field group to a ajax filter plugin. It should be able to just put the field key in the shortcode and it should work but it does not so I’m trying to edit the plugin a bit. I’ve been able to show the correct field list in the plugin, but it does not show the counts or use the filter function..

    This is one part of the code (uag-wall-functions.php):

    if (strstr($key,'metakey')) {
    $matches = array();
    if (preg_match_all('/{([^}]*)}/', $value, $matches)) {
    		$i = 0;
    		foreach($matches[1] as $array) {
    		$i++;
    						
    	        $all_arg = explode(',', $array);
    		foreach($all_arg as $arg) {
    		$str_arr = explode(':', $arg);
    		$metakey[$i][$str_arr[0]] = $str_arr[1];
    		}
    						
    /* ARGS */
    $key = (isset($metakey[$i]['key'])) ? $metakey[$i]['key'] : null; 
    $field_key = (isset($metakey[$i]['field_key'])) ? $metakey[$i]['field_key'] : null;
    $title = (isset($metakey[$i]['title'])) ? $metakey[$i]['title'] : __('Untitled','uag');
    $reset_text = (isset($metakey[$i]['reset_text'])) ? $metakey[$i]['reset_text'] : __('Reset','uag');
    
    $metavalues = get_field_object($field_key);
    	if( $metavalues )
    		{
    $display .= '<div class="uag-filter" data-key="'.$field_key.'">
    											<div class="uag-filter-head"><span class="uag-toggle"></span>'.$title.'<div class="uag-helpers"><span class="uag-loading uag-hide"></span><a href="#" class="uag-reset">'.$reset_text.'</a></div></div>
    											<div class="uag-mainbody">
    												<div class="uag-filter-body">';
    											
    foreach($metavalues['choices'] as $metavalue) {
    $display .= '<a href="#" class="uag-filter-option" data-metakey="'.$field_key.'" data-metavalue="'.$metavalue.'">'.$metavalue;
    
    if ($args['count'] == 'show') {
    									$display .= '<span class="uag-count">'.uag_meta_count($field_key, $metavalue, $args).'</span>';
    		}
    	$display .= '</a>';
    		}
    												
    	$display .= '</div>
    									</div>
    								</div>';
    	}

    and the functions.php file:

    /* Collect meta values */
    	function uag_meta_values($metakey) {
    		global $wpdb;
    		$prefix = $wpdb->prefix.'postmeta';
    		$posts = $wpdb->prefix.'posts';
    		$values = $wpdb->get_col("SELECT meta_value AS $metakey FROM $posts 
    	JOIN $prefix ON ($prefix.post_id =  $posts.ID) 
    	WHERE post_status = 'publish' 
    	AND meta_key = '$metakey'");
    		$values = array_unique($values);
    		return $values;
    	}
    
    	/* Count */
    	function uag_count_meta_values($metakey) {
    		global $wpdb;
    		$prefix = $wpdb->prefix.'postmeta';
    		$posts = $wpdb->prefix.'posts';
    		$values = $wpdb->get_col("SELECT meta_value AS $metakey FROM $posts 
    	        JOIN $prefix ON ($prefix.post_id =  $posts.ID) 
    	        WHERE post_status = 'publish' 
    		AND meta_key = '$metakey'");
    		$values = array_unique($values);
    		return count($values);
    	}
    	
    	/* meta count by value */
    	function uag_meta_count($metakey, $metavalue, $args = null) {
    	$loop = array(
    	'post_type'	   => 'any',
    	'posts_per_page' => -1,
            'meta_key'	   => $metakey,
            'meta_value'     => $metavalue,
    
    		);

    Sorry, it’s a lot of code. But actually I’m not sure where to start in here. If you would point me in the good direction that would be enough. Thanks

  • Hi @Elliot,

    url: "../wp-content/themes/twentytwelve/fields/test.php"

    I’ve done it this way indeed, I’m not using the native wp_ajax functions. So that would be the problem. I’ll find out how to do it correctly, thanks.

  • Hi Elliot,

    Well, my field shows up in the acf plugin. I thought it would not show up or even get an error if it was not registered, right? The error is only resolving when it posts the data.

    If not, how can I check if it is registered the right way?

  • Thanks for your response, actually this does not solve the issue. Let me explain better.

    This is a part of my php file for the field:

    <?php
    
    class acf_field_number_range extends acf_field
    {
    
    (..)
    
    <script type="text/javascript">
    
    $("#slider").bind("valuesChanged", function (e, data) {
       $.ajax({
       type: "POST",
       dataType: "text",
       url: "../wp-content/themes/twentytwelve/fields/test.php",
       data: { minValue: data.values.min, maxValue: data.values.max },
       async: false,
       success: function(data){
          alert(data);
          
        },
         error: function(xhr) {
                 alert('fail')
                }
     });
    });
    
    </script>

    But the alert popup gives this error:

    Fatal error: Class ‘acf_field’ not found in /home/…/…etc/../..etc/ test.php</b> on line 3

    How can I get these values of the range slider? Thanks

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