Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • I am still struggling with this. After more reading, experimenting, testing etc I have come up with this set of args for the query I am trying to create, but still with no output.

    <?php 
     //Set server timezone to GMT
     date_default_timezone_set('Europe/London'); 
     //Today's date
     $date_1 = date('Ymd', strtotime("now")); 
     //Future date - the arg will look between today's date and this future date to see if the post fall within the 2 dates
     $date_2 = date('Ymd', strtotime("+48 months"));
    ?>
    
    <?php
     $byartist_args = (array(
      'numberposts' => -1,
      'post_type' => 'Event',
      'meta_query' => array(
      'relation' => 'AND',
      array(
       'key' => 'artist',
       'value' => '"' . get_the_ID() . '"',
       'compare' => 'LIKE',
      ),
      array(
       'key' => 'event_date',
       'compare' => 'BETWEEN',
       'type' => 'DATE',
       'value' => array($date_1, $date_2),
       ),
      ),
     ));
    ?>	
    <?php $byartist_query = new WP_Query( $byartist_args ); ?>

    I can only assume that the issue is with this part, as everything else seems to be working okay:

    'value' => '"' . get_the_ID() . '"',

    There must be a way to compare the current post ID with the ID in a post object field and output based on this. Anyone?

  • This works

    
    
     
    add_filter('acf/get_field_group', 'hide_field_group_from_clone', 20);
    function hide_field_group_from_clone($group) {
    	//ob_start(); echo 'POST'."\r\n";print_r($_POST);error_log(ob_get_clean());
    	if (isset($_POST['action']) && $_POST['action'] == 'acf/fields/clone/query' && $group['key'] == 'group_5b586829bb34c') {
    		return false;
    	}
    	return $group;
    }
    
  • It appears that I was incorrect. It doesn’t work. I did a quick test and thought it was working but it appears I was not totally awake yet when I did the test.

  • Thank you John.

    I created the group in question via Add New Field Group in WP Admin, and then generated PHP code to instead create it programatically. I then deleted the field group I had created in WP admin. I have tried adding ‘private’ => 1 to the generated code e.g.

    ‘menu_order’ => 0,
    ‘position’ => ‘normal’,
    ‘style’ => ‘seamless’,
    ‘label_placement’ => ‘top’,
    ‘instruction_placement’ => ‘label’,
    ‘hide_on_screen’ => ”,
    ‘active’ => 1,
    ‘description’ => ”,
    ‘private’ => 1

    But this does not have the desired effect. Could you please advise?

    Many thanks,

    chris

  • I got an array being returned from an ACF field after moving onto my production web server. The cause is, I suspect, the bad migration procedure. I re-imported several times the WP database via XML export files one on top of another and again.

    As I use Timber/Twig, my code causing errors is {{post.front_page_quick_order|apply_filters('the_content')}} where the ACF field is front_page_quick_order.

    Making var_dump I saw clearly that front_page_quick_order was an array of strings.

    Searching in the WP database via PHPMyAdmin for front_page_quick_order gave me 25 entries in the wp_postmeta table.

    The quick fix 1 was: {{post.get_field('front_page_quick_order')|apply_filters('the_content')}} – just use the standard ACF function to get the field instead of Timber/Twig shorthand syntax.

    The fix 2 (the one I prefer): install WordPress WP-Sweep plugin and clean up the entire DB. Then return the code to the initial state {{post.front_page_quick_order|apply_filters('the_content')}}.
    NB: I tried WPOptimizer with no effect. After WP-Sweep 25 entries become 3.

  • …and on brief addition. It also happens that if you go on the previous post button that also events/post from the past are shown as well. more or less the entire query i sorted with the code above gets paginated. So more specifically the question would be is it possible to paginate ONLY the shown and sorted posts based in the event_start custom field.

    p.s. tried to update my initial post but somehow it seems impossible meanwhile at least i was unable to find an edit button. :/ there for sorry for the necessary follow up post.

  • Hi John,

    Thank you for your reply. I’m using ACF PRO, so ACF5. I switched out $_POST['fields'] with $_POST['acf'] but unfortunately my code is still not working. Saving an post as featured, doesn’t unset the featured option on a different post.

    So my code now looks like:

    function my_acf_save_post( $post_id ){
    	
    	$fields = false;
    	
    	if ( isset( $_POST['acf'] ) ) {
    		$fieldId = 'field_5b51ec43f331a';
    		$fields = $_POST['acf'];
    
    		$featuredArticle = $fields[$fieldId];
    		
    		if ( $featuredArticle ) {
    			$args = array(
    				'post_type' => array('post'),
    				'meta_query' => array(
    					array(
    						'key' => 'featured',
    						'value' => '1',
    						'compare' => '=='
    					)
    				)
    			);
    			
    			$post_query = new WP_Query( $args );
    			
    			if ( $post_query->have_posts() ) {
    				while ( $post_query->have_posts() ) {
    					$post_query->the_post();
    					
    					acf_update_field( $fieldId, false, get_the_ID() );
    					
    				}
    			}
    		}
    	}
    
    } // end my_acf_save_post
    add_action('acf/save_post', 'my_acf_save_post', 1);
  • I have the same problem. ACF pro 5.7.0 and previous version too. Website with WPML :

    I can pick the date and publish and it is saved correctly in the database…
    but when the edit (admin) page is reloaded while publishing, I get today’s date in the datepickers.
    So if I don’t pay attention and edit something else, the today’s date wipes out the date I had chosen the first time and my custom post start and end dates become today.

    Both start_date and end_date date fields currently have custom Ymd display format and 20180723 returnformat… because I was trying to debug a order by date query, and I thought there was a problem with american or french format : 31/12/2018 or 2018/12/31 or something like that. Values in database are 20181231. A forum post suggests increasing php.ini but not sure it’s relevant

  • To answer my question and assuming you are changing the first row, you need to simply use update_field:

    update_field(r1_0_g1_t1, ‘cow’, get_the_ID());

  • Hi John, I have a lot of different field types in my form. Tested it with simple text fields only after your comment, but the error persists.

    But good news – I solved it 5 minutes ago by adding wp-util as a dependency to my main script:

    
    wp_enqueue_script( 'app', asset_uri('assets/js/app.js'), array('jquery', 'wp-util'), null, true );
    

    So maybe you guys just forgot to add it as a dependency in acf_form_head?

  • Yes. Due to the way that ACF creates the meta_key values for repeaters (including flex fields) sub field names in each layout do not need to be unique.

  • Looks like I had part of my code wrong. Here’s what I’m currently using:

    <?php if( have_rows('google_drive_links') ): ?>
    <hr />
         <h3>Attachments</h3>
         <ul class="google-drive-links">
    <?php while( have_rows('google_drive_links') ): the_row(); 
         // vars
         $content = get_sub_field('google_link_name');
         $link = get_sub_field('google_link'); ?>
         <li class="google-drive-link-item">
         <a target="_blank" href="<?php echo $link; ?>"><?php echo $content; ?></a>
        </li>
    <?php endwhile; ?>
    </ul>
    <?php endif; ?>
  • Hey ninobysa,

    I am still working on my multistep form, i realized that i would need to create my own validation.

    $(".nextone").click(function(e){
            e.preventDefault();
    
                $.ajax({
                    dataType: 'json',
                    type: 'POST',
                    url: ajaxurl,
                    data: {
                        action: 'epm_registration_process',
                        epformdata: $('#field-group-1 input, #field-group-1 select').serialize()
                    },
                    success: function(resp) {
                        if (resp === true) {
                            //successful validation
                            if(animating) return false;
                            animating = true;
                            
                            current_fs = $(this).parent();
                            next_fs = $(this).parent().next();
                            
                            //activate next step on progressbar using the index of next_fs
                            $("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
                            
                            //show the next fieldset
                            next_fs.show(); 
                            //hide the current fieldset with style
                            current_fs.animate({opacity: 0}, {
                                step: function(now, mx) {
                                    //as the opacity of current_fs reduces to 0 - stored in "now"
                                    //1. scale current_fs down to 80%
                                    scale = 0.8 + (1 - now) * 0.2;
                                    //2. bring next_fs from the right(50%)
                                    left = (now * 50)+"%";
                                    //3. increase opacity of next_fs to 1 as it moves in
                                    opacity = 1 - now;
                                    /*current_fs.css({
                                        'transform': 'scale('+scale+')',
                                        'position': 'absolute'
                                    });*/
                                    next_fs.css({'opacity': opacity});
                                }, 
                                duration: 0, 
                                complete: function(){
                                    current_fs.hide();
                                    animating = false;
                                }, 
                                //this comes from the custom easing plugin
                                easing: 'easeInOutBack'
                            });
                            return false;
                        } else {
                            $.each(resp, function(i, v) {
                                console.log(i + " => " + v); // view in console for error messages
                                if( $('input[name="' + i + '"], select[name="' + i + '"]').hasClass('inputTxtError') ){}else{
                                    var msg = '<div class="acf-notice -error acf-error-message"><p>'+v+'</p></div>'
                                    $('input[name="' + i + '"], select[name="' + i + '"]').addClass('inputTxtError').before(msg);
                                }
                            });
                            var keys = Object.keys(resp);
                            $('input[name="'+keys[0]+'"]').focus();
                        }
                        return false;
                    },
                    error: function(errorThrown) {
                        console.log(errorThrown);
                    }
                });
                return false;
    
        });

    PHP CODE:

    function epm_registration_process($post_id){
        //Prepare basic user info
        $username = strtolower($_POST['acf']['field_5b4be98fd288c']);
        $firstname = $_POST['acf']['field_5b4be9d8d288d'];
        $lastname = $_POST['acf']['field_5b4be9e8d288e'];
        $email = $_POST['acf']['field_5b4be9f7d288f'];
        $password = $_POST['acf']['field_5b4bea0bd2890'];
        $cpassword = $_POST['acf']['field_5b4bea8bd2891'];
    
        $error = array();
        //IMPORTANT: You should make server side validation here!
        if( empty($username) ){
            $_SESSION['errors']['acf[field_5b4be98fd288c]'] = "Please enter a username";
        }elseif(username_exists( $username )){
            $_SESSION['errors']['acf[field_5b4be98fd288c]'] = "Username already exist";
        }
    
        if( empty($firstname) ){
            $_SESSION['errors']['acf[field_5b4be9d8d288d]'] = "Please enter your firstname";
        }
    
        if(count($_SESSION['errors']) > 0){
    	    //This is for ajax requests:
            if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&  strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
                echo json_encode($_SESSION['errors']);
                exit();
            }
    	    //This is when Javascript is turned off:
            echo '<ul>';
            foreach($_SESSION['errors'] as $key => $value){
                echo '<li>' . $value . '</li>';
            }
                echo '</ul>';
            exit();
        }else{
    	//form validation successful - process data here!!!!
       
           
        }   
    }
    add_action('wp_ajax_epm_registration_process', 'epm_registration_process');
    add_action('wp_ajax_nopriv_epm_registration_process', 'epm_registration_process');
    add_filter('acf/pre_save_post' , 'epm_registration_process', 10, 1 );

    I am stuck at how can i get $_POST data if form does not submit the normal way hence i cannot validate against a user already existing in the database etc… i am only able to check if the field is empty

  • After much scrutiny and a much needed lunch break, I found that the reason it returned false was $thing needed to be the following:

    $thing = $object['taxonomy'] . "_" . $object['id'];

    My mistake! I was returning the slug of a specific ‘region’ instead of literally the taxonomy/term slug.

    I accepted your answer, although there is a typo with a missing ‘}’

  • We had a client report that the datepicker field was not working correctly.

    Looking at the console, this.inputText() is not a function was throwing an error in ACF Pro 5.7.0.

    The call should be this.$inputText() and the error was found in the radio field: line 6852 of assets/js/acf-input.js.

    The GitHub repo doesn’t have version 5.7.0, otherwise we would have created a pull request. I’m attaching the files to this comment instead.

  • Try using the update_field ACF API function. In my experience, the backend ACF UI wasn’t selecting the attached terms because they weren’t associated correctly in the database.

    update_field documentation:
    https://www.advancedcustomfields.com/resources/update_field/#usage

    Here is an example that uses a Gravity Forms hook. After a user submits the form, a new post is created. Once it’s created and the terms are attached to the post, I take those terms (array) and use the update_field ACF function to attach them. Now, my taxonomy checkboxes on the backend are correctly selected.

    
    add_action( 'gform_after_submission_1', 'update_acf_terms_for_rentals', 10, 2 );
    function update_acf_terms_for_rentals( $entry, $form ) {
    
        //get the post
        $post = get_post( $entry['post_id'] );
    
        // get the term IDs array (IDs only)
        $term_list = wp_get_post_terms($post->ID, 'space', array("fields" => "ids"));
    
        // Insert the $term_list into the database via ACF
        $field_key = 'field_5b50eb94713f1';
        update_field($field_key, $term_list, $post->ID);
    }
    
    
  • Thank you John! πŸ™‚

    I tried many different similar plugins but this one really works πŸ™‚

    I’ve added this in my Form tab:
    [dynamichidden referencenumber "acf field='reference_number'"]

    And this in my Mail tab:
    Ref: [referencenumber]

    Thanks a lot.

  • The repeater field name is constructed by combining the parent field name (the repeater) the row index (yes it starts at 0) and the sub field name.

    "{$repeater_name}_{$index}_{$sub_field_name}"

    But even with this you can’t use the built in ACF shortcode. The reason is that the ACF shortcode will only work with basic fields that store simple text values and will not work for fields like image, nav menu, and many other fields that store values that need to be interpreted by ACF. For this type of thing you’re going to have to create your own shortcodes https://codex.wordpress.org/Shortcode_API

  • Im getting nowhere on this. So frustrating

    Is caption even part of the array from wp_get_attachment_metadata?

    Because I cant get it to return it, and a var dump doesnt seem to show it:

     array(5) {
      ["width"]=>
      int(400)
      ["height"]=>
      int(300)
      ["file"]=>
      string(19) "2018/07/400x300.png"
      ["sizes"]=>
      array(3) {
        ["thumbnail"]=>
        array(4) {
          ["file"]=>
          string(19) "400x300-150x150.png"
          ["width"]=>
          int(150)
          ["height"]=>
          int(150)
          ["mime-type"]=>
          string(9) "image/png"
        }
        ["medium"]=>
        array(4) {
          ["file"]=>
          string(19) "400x300-300x225.png"
          ["width"]=>
          int(300)
          ["height"]=>
          int(225)
          ["mime-type"]=>
          string(9) "image/png"
        }
        ["square"]=>
        array(4) {
          ["file"]=>
          string(19) "400x300-300x300.png"
          ["width"]=>
          int(300)
          ["height"]=>
          int(300)
          ["mime-type"]=>
          string(9) "image/png"
        }
      }
      ["image_meta"]=>
      array(12) {
        ["aperture"]=>
        string(1) "0"
        ["credit"]=>
        string(0) ""
        ["camera"]=>
        string(0) ""
        ["caption"]=>
        string(0) ""
        ["created_timestamp"]=>
        string(1) "0"
        ["copyright"]=>
        string(0) ""
        ["focal_length"]=>
        string(1) "0"
        ["iso"]=>
        string(1) "0"
        ["shutter_speed"]=>
        string(1) "0"
        ["title"]=>
        string(0) ""
        ["orientation"]=>
        string(1) "0"
        ["keywords"]=>
        array(0) {
        }
      }
    }

    Here is the code I tried:

    <?php
    $id = get_field('primary_image');
    $img_meta = wp_get_attachment_metadata( $id );
    echo $img_meta[image_meta][caption];
    ?>
  • Hi HQ80,

    thank you, this brought me a big step forward.

    I got all pages displayed that share a dropdown-field-value.
    Unfortunately now I’m struggling with the ordering.

    To be more concrete:
    – I got 6 pages that are part of a series
    – In the ACF-Template of these pages I have:
    — a dropdown for the series they belong to (dropdown field)
    — a dropdown for the prev page in the series (page field)
    — a dropdown for the next page in the series (page field)
    Image:
    Add Articles in Series

    As stated above I got all pages displayed that share a series.
    But for the ordering: How can I display in the correct order?

    My current code looks like this:

    <?php 
    			$posts = get_posts(array(
    				'posts_per_page'	=> -1,
    				'post_type'			=> 'page',
    				'meta_value'		=> 'series1',
    			));
    
    			if( $posts ): ?>
    				<ul class="list list--styled">
    				<?php foreach( $posts as $post ): 
    					setup_postdata( $post );
    					?>
    					<li>
    						<a href="<?php the_permalink(); ?>">
    						    <div><?php the_field('title_short'); ?></div>
    				    	</a>
    					</li>
    				<?php endforeach; ?>
    				</ul>
    				<?php wp_reset_postdata(); ?>
    			<?php endif; ?>
  • Unfortunately, that’s not my result. I’m getting false. Here’s my code that isn’t working. I’m trying to use the WP REST API to return custom fields on a custom Taxonomy called ‘region’ on a custom Post Type.

    function regions_get_custom_fields_cb($object, $field_name, $request){
        $thing = $object['slug'] . "_" . $object['id'];
        return get_fields($thing);
    }
    
    add_action('rest_api_init', function(){
        register_rest_field('region', 'custom_data', 
            array(
                'get_callback' => 'regions_get_custom_fields_cb', 
                'update_callback' => null, 
                'schema' => null
            )
        );
    });
  • It will work for a taxonomy, just use the right ID

    
    $fields = get_fields("term_{$term_id");
    
  • Thanks Joshua for sharing that! Had a similar issue and was now able to fix it quickly…

  • I don’t get how currently what I do works and copied changes from site to site are isolated between database tables but when you apply json sync it overwrites due to the field groups being the same.

    The files saved in the json folder reflect whatever you saved last. If two sites are using the same folder then they both pull from those last saved changes. This is based on the field group key. Two sites with the same field groups but that have different fields in them cannot share a folder.

    It appears you have more control over manually copying and then modifying/removing field groups between sites from the out of the box database way than using json sync. I guess this is because ACF is not built in mind for multisite and any solutions for multisite are work arounds.

    Yes. Basically, when using ACF on multisite you have completely different db entries. If the sites share a theme and you attempt to use local json then basically, you can only have to sites with identical field groups and fields. As you say, having two sites with the same theme requires work-a-rounds.

    My guess is that when the site was built was assumed that all sites would use the same fields and at some point along the way this assumption was proven false and the developer did what he needed to to make it work. Changing requirements usually result it this happening. I’m having a similar situation myself.

    I actually didn’t think about this site until I read your reply.

    I have a site that was originally built as a single site installation. It was then converted to mutlisite because the client wanted to add additional sites using the same theme. Unfortunately, this means that all the field groups need to be copied to every new site. I was already using local json so that wasn’t really an issue. Since the fields were not in the DB for the new site it just used the json files from the theme. Then, what has you are seeing I had to start making “adjustments” to the fields for each site. This has resulted in needing to add many filters to adjust fields for the different sites. In this case I have created an options page for each site. This options page contains a list of fields that need to be changed. Each field on the options page includes setting for “should the field be shown”, and the field “label” to use for each site and in some cases what the values of the field can be. The I use the acf/load_field to modify the field. I also use the acf/prepare_field filter to remove fields from specific sites where that is needed. On top of this all of the templates on the front end need to have additional checks added to see if a particular field should be shown or not. This results in giving me the ability to work on all of the field groups in the main site and be able to adjust those fields as needed for every other site. Every time I have to make an adjustment I have to also make adjustments to the options page and the filters. It’s all very complicated and the complication has grown over an extended period of time. I can’t imagine what the next developer will do when they inherit this site.

Viewing 25 results - 9,426 through 9,450 (of 21,340 total)