Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Thanks for the answer. I checked if the options are available:

    add_filter('acf/location/rule_match/page_template', 'get_themosis_templates_from_acf_rules', 11, 3);
    function get_themosis_templates_from_acf_rules($match, $rule, $options)
    {
        // vars
        if (isset($options['page_template'])) {
            $page_template = $options['page_template'];
        }
    
        // get page template
        if (!isset($options['page_template']) && isset($options['post_id'])) {
            $page_template = get_post_meta($options['post_id'], '_themosisPageTemplate', true);
        }
        if (isset($page_template)) {
            // compare
            if ($rule['operator'] == "==") {
                $match = ($page_template === $rule['value']);
            } elseif ($rule['operator'] == "!=") {
                $match = ($page_template !== $rule['value']);
            }
        }
        
        // return
        return $match;
    }
  • The only real solution is to use a child theme on the site where the local JSON is defined in the parent theme and there is no local JSON folder in the child theme. Then you can set a second load path to load the JSON files in the parent theme https://www.advancedcustomfields.com/resources/local-json/

    A solution for saving local JSON for and fields created in the child theme sub site would be to create a place outside of the theme to save and load field groups in the child theme. For example, when the theme is activated you can create an acf-json folder in wp-content/uploads/sites/{$site_id}/ and set the save and load points for the child theme to this location and this would create a unique location for json files for each site.

  • Alright, so I have run into this thread numerous times and it never helped solve the issue.

    I usually am writing my own plugin and using get_field seems to stop working with the identical behavior that @corydavidwilliam described. It’s not because of the theme or other plugins. It’s because of my own code. So I’ve isolated the problem and wanted to share, in case others run into the same.

    The following code was the culprit, the cause of my repeater returning string “1” instead of array( ‘date’ => ‘9/20/2017’, ‘time’ => ’12:30pm’ ).

    /**
     * Sort open house in RSS FEEDS by open house date, and hide expired entries.
     *
     * @param $query
     */
    function bn_open_house_sort_rss_by_open_house_date( $query ) {
    	if ( !is_feed() ) return;
    	if ( get_query_var('post_type') != 'open_house' ) return;
    	
    	if ( !($query instanceof WP_Query) ) return;
    	
    	$query->set('order', 'ASC');
    	$query->set('orderby', 'meta_value_num');
    	$query->set('meta_key', 'open_house_date_timestamp');
    
    	$query->set('meta_query', array(
    		array(
    			'key' => 'open_house_date_timestamp',
    			'value' => strtotime('-6 Hours'), // Do not show posts from several hours earlier
    			'compare' => '>=',
    			'type' => 'NUMERIC',
    		)
    	));
    }
    add_action( 'pre_get_posts', 'bn_open_house_sort_rss_by_open_house_date' );

    The problem with the above code is that get_query_var(‘post_type’) returns “open_house” during the loop of an RSS feed, as expected. However, get_field() performs it’s own query which tries to get the post type “acf-field” (the field group or specific field, I assume).

    Because my code is adding a meta_query, the acf field query never returns a result. My meta query should only apply to open houses – not ACF fields!

    The solution is to instead check the post type of the current query, and NOT use get_query_var.

    Replace: if ( get_query_var(‘post_type’) != ‘open_house’ ) return;

    With: if ( $query->get(‘post_type’) != ‘open_house’ ) return;

    This makes it so I still have the same behavior as before, except it doesn’t interfere with the get_field() function.

    Note that this won’t be an exact solution for everyone, but since this pops up so often I’m guessing people need to check into the pre_get_posts hook and see if that’s where the problem is coming from. I didn’t expect get_field() to perform a WP_Query.

  • @mkeys Thank you! This working fine on Advanced Custom Fields PRO v. 5.5.11

    Wonderful!

    Can we leave you donation somewhere? I’d like to think everyone on this post would be happy to throw a little at your skill and generosity.

    That would be very kind. I looked into making a donate button with paypal ( Donate via PayPal form ). It asks for stuff like shipping information which is silly, so if you’d rather just paypal me directly, my paypal email is: [email protected]

  • At this time after editing a CPT post (which is not working) is giving me this values after printing $options:

    array(4) {
      'lang' =>
      string(0) ""
      'ajax' =>
      bool(false)
      'post_id' =>
      string(2) "62"
      'post_type' =>
      string(8) "training"
    }

    Going to try to debug some things

  • Thanks John,

    This helped out. Although my options still aren’t working.. I get this error message:

    Undefined index: page_template
    Location:
    ...actions.php on line 81

    Underneath the two functions (the first one is also from my first post):

    add_filter('acf/location/rule_values/page_template', 'add_themosis_templates_to_acf_rules', 20);
    function add_themosis_templates_to_acf_rules($choices)
    {
        $key = 'theme';
        $configFile = 'templates.config.php';
        $configTemplates = include(themosis_path($key) . 'config' . DS . $configFile );
        $templates = array();
        foreach ($configTemplates as $configTemplate) {
            $prettyTemplateName = str_replace(array('-', '_'), ' ', ucfirst(trim($configTemplate)));
            $templates[$configTemplate] = $prettyTemplateName;
        }
        return array_merge(array('none' => __('None')), $templates);
    }
    
    // get themosis templates
    add_filter('acf/location/rule_match/page_template', 'get_themosis_templates_from_acf_rules', 11, 3);
    function get_themosis_templates_from_acf_rules($match, $rule, $options)
    {
        // vars
        $page_template = $options['page_template']; // This is line #81
        // get page template
        if (!$page_template && $options['post_id']) {
            $page_template = get_post_meta($options['post_id'], '_themosisPageTemplate', true);
        }
        // compare
        if ($rule['operator'] == "==") {
            $match = ($page_template === $rule['value']);
        } elseif ($rule['operator'] == "!=") {
            $match = ($page_template !== $rule['value']);
        }
        // return
        return $match;
    }
  • I’ve submitted a ticket and will update this post with their response.

    Seems like it shouldvalidate, at least according to the <input type=range> spec. Per https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range:

    By default, the granularity, is 1, meaning that the value is always an integer. You can change the step attribute to control the granularity. For example, If you need a value between 5 and 10, accurate to two decimal places, you should set the value of step to 0.01

  • then I guess i am not understanding the acf.add_action. I understood add_actions are a WordPress php hook. How does this integrate with jquery?

  • This is javascript (or jQuery) and it goes in a custom javascript file or as inline script as described at the top of the page.

  • To do what you originally asked you need to use clauses for your meta_query. see ‘orderby’ with multiple ‘meta_key’s on this page https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters, it’s the 10th code snippet in the Order & Orderby Parameters section.

  • You can’t just implode the array, it consists of an array of term objects and not just the name of the terms. You must loop through it and pluck out the term names, or you can use a WP function that does this

    
    $field_name = "job_field_area";
    $field = get_field_object($field_name);
    if ($field) {
      ?>
        <li class="list-item">
          <div lass="list-content">
            <h3><?php echo $field['label']; ?></h3>
            echo implode(', ', wp_list_pluck($field['value'], 'name'));
          </div>
        </li>
      <?php 
    }
    
  • i cant make it work šŸ™

    here is what I’m using:

    <?php								if(get_field('job_field_area') ):
    $field_name = "job_field_area";
    	$field = get_field_object($field_name);
    	echo '<li class="list-item">';
    	echo '<div class="list-content">';
    	echo '<h3>'. $field['label'] . '</h3>';
    	echo '<div class="field-text">';
    	echo implode(', ', $field['value']);
    	foreach ($field['value'] as $value);
    	echo '</div>';
    	echo '</div>';
    	echo '</li>';
    	endif; 
    ?>

    and I’m getting just the label… eg.Job “Field Area” but no values for it.

  • Same here. I have multiple WYSIWYG and the bug started after update to Version 5.6.2. It’s a JavaScript bug.

    Uncaught TypeError: Cannot read property ‘split’ of undefined
    at post.php?post=1778&action=edit&lang=pt-br:2658
    at d (acf-input.min.js:1)
    at Object.s (acf-input.min.js:1)
    at Object.apply_filters (acf-input.min.js:1)
    at Object.initialize_tinymce (acf-input.min.js:3)
    at Object.initialize (acf-input.min.js:3)
    at Object.initialize (acf-input.min.js:3)
    at acf-input.min.js:1
    at d (acf-input.min.js:1)
    at Object.i (acf-input.min.js:1)

    post.php?post=1778&action=edit&lang=pt-br:2658

    null

  • Hi John,

    This is a bit hard to explain. However, I wanted to display all the course providers who has a true value(1) within the relationship. Instead I got all the course providers who has a true value(1) within and apart from the relationship. Sorted this out with a radio field by following code. (should be possible with TRUE/FALSE as well)

    <?php while ( have_posts() ) : the_post();
    
                $rto_providers = get_posts(array(
                  'post_type' => 'rto_providers',
                  'meta_query' => array(
                    array(
                      'key' => 'courses_offered',
                      'value' => '"' . get_the_ID() . '"',
                      'compare' => 'LIKE'
                    )
                  )
                ));
                ?>
    
                <?php if( $rto_providers ): ?>
                  <?php foreach( $rto_providers as $rto_provider ): ?>
                    <?php if( get_field('account_activation', $rto_provider->ID) == 'Active' ): ?>
                      <div class="row bordered-row random">
                        <div class="col-md-2 providers-list">
                          <?php echo get_the_post_thumbnail( $rto_provider->ID ); ?>
                        </div>
                        <div class="col-md-8">
                          <a href="<?php echo get_permalink( $rto_provider->ID ); ?>">
                            <?php echo get_the_title( $rto_provider->ID ); ?>
                          </a>
                        </div>
                        <div class="col-md-2">
                          <a href="<?php echo get_permalink( $rto_provider->ID ); ?>" class="btn btn-base">
                            Visit Page
                          </a>
                        </div>
                      </div>
                    <?php endif; ?>
                  <?php endforeach; ?>
                <?php endif; ?>
                
          <?php endwhile; ?>
  • *SOLVED* (my bad!)

    DOH – it seems that it does not like this function:

    /*Function to defer or asynchronously load scripts*/
    function js_async_attr($tag){
    
    # Do not add defer or async attribute to these scripts
    $scripts_to_exclude = array();
    
    foreach($scripts_to_exclude as $exclude_script){
     if(true == strpos($tag, $exclude_script ) )
     return $tag;
    }
    
    # Defer or async all remaining scripts not excluded above
    return str_replace( ' src', ' defer="defer" src', $tag );
    }
    add_filter( 'script_loader_tag', 'js_async_attr', 10 );
  • If the values do not load there is either an error in JavaScript or an error in PHP during hte AJAX request.

    This can also be cause by not calling acf_form_head().

    JavaScript errors are usually caused by plugin conflicts. To begin debugging this start disabling other plugins to see if you can clear it up.

    PHP errors during AJAX can be found by enabling error logging https://codex.wordpress.org/WP_DEBUG

  • Hello,

    FYI, I had same issue and did this hook to make it:

    function acf_change_icon_on_files ( $icon, $mime, $attachment_id ){ // Display thumbnail instead of document.png
    		
    		if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) === false && $mime === 'application/pdf' ){
    			$get_image = wp_get_attachment_image_src ( $attachment_id, 'thumbnail' );
    			if ( $get_image ) {
    				$icon = $get_image[0];
    			} 
    		}
    		return $icon;
    	}
    	
    	add_filter( 'wp_mime_type_icon', 'acf_change_icon_on_files', 10, 3 );
  • Hello,

    I had same issue and make this hook for it:

    	function acf_change_icon_on_files ( $icon, $mime, $attachment_id ){ // Display thumbnail instead of document.png
    		
    		if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) === false && $mime === 'application/pdf' ){
    			$get_image = wp_get_attachment_image_src ( $attachment_id, 'thumbnail' );
    			if ( $get_image ) {
    				$icon = $get_image[0];
    			} 
    		}
    		return $icon;
    	}
    	
    	add_filter( 'wp_mime_type_icon', 'acf_change_icon_on_files', 10, 3 );
  • What a browser prints has little to do with ACF. This is usually controlled in a print style sheet for the page. It can also be effected by the browser in question and your print settings. If something is not being shown in the printed version then the first place to look is at the CSS ro figure out why.

  • 
    ......
                  'meta_query' => array(
                    array(
                      'key' => 'courses_offered',
                      'value' => '"' . get_the_ID() . '"',
                      'compare' => 'LIKE',
                    // added the next 2 lines
                    ),
                    array(
                      // what does this represent
                      // those that are active or inactive
                      // if you toggle the field on to make it inactive
                      // then the value here should be 0
                      'key' => 'status',
                      'compare' => '==',
                      'value' => '1'
                    )
                  )
    
  • yazminmedia,
    Fortunately, I got an email before you deleted your comment. The additional plugin use was fairly inconsequential to the question. (Or I assumed so in my answer given)

    In short, you can use a repeater to attach multiple files. If you need additional data on those files you can put those additional fields in the repeater.

    In the example from jaro, they only needed 1 video, but multiple subtitle files which each needed their own additional data (what language they were)

    If you happened to need multiple videos, and each of those needed multiple subtitle files with additional data, you could just nest the repeaters.

  • Here is an example for getting the E-mail (First name Last name) in the select user field.

    
    function alter_specific_user_field($result, $user, $field, $post_id) {
    
        $result = $user->user_email;
    
        if( $user->first_name ) {
            
            $result .= ' (' .  $user->first_name;
            
            if( $user->last_name ) {
                
                $result .= ' ' . $user->last_name;
                
            }
            
            $result .= ')';
        }
    
        return $result;
    }
    add_filter("acf/fields/user/result/key={field key here}", 'alter_specific_user_field', 10, 4);
    
  • @redeclipse

    It seems to look good in terms of no missing/extra brackets/commas, but I do see one potential issue.

    First, I can only assume $current has the appropriate data. During testing, you can leave one element out at a time… or hard code otherwise dynamic values.

    But.. the issue I see…

    When I was building my query… I looked at the existing ACF examples and docs and when using (as suggested):

    array(
      'key' => 'show_main',
      'compare' => '==',
      'value' => '1'
    )

    .. it didn’t work for me.

    But when I changed it to what made more sense to my brain anyway… which was:

    array(
      'key' => 'show_main',
      'compare' => '=',
      'value' => TRUE
    )

    … then it worked!

    That quick change might do it for you. I am not sure if double equals matters… I didn’t see double equals in the WP docs so I used single (which is the default). Note: I do not wrap TRUE in quotes in my example.

    Also, my bad on steering you towards get_posts() – it seems to be just a matter of preference in most cases.

    I noticed that in your original post you were using get_page() (singular) and I hadn’t heard of it, so I looked it up and saw that it had been deprecated in favour of, as it turns out: get_post() (singular)

    Now… I know you can achieve near same results with get_pages() and get_posts() (both plural)… maybe, just maybe, get_pages() is more appropriate for you. I only say that because Pages are hierarchical by nature, and maybe that fact is important to you and your query. I don’t know… but… with that said… with get_page() falling away, perhaps get_pages() will as well. Time will tell.

    At any rate, if you decide to jump over to get_pages() you just have to modify your args slightly.

    Best of luck with your project!

  • You need to set the location rules for the field group to include what user types it is shown form.

    
    User Form is equal to Add/Edit 'and'
    Current User Role is equal to Administrator 'and'
    

    If you want this available to multiple user types you would need to add and OR location rule

    
    OR
    
    User Form is equal to Add/Edit 'and'
    Current User Role is equal to Editor'and'
    
  • Thanks for the reply! I’ve come up with this code but unfortunately it still doesn’t work, can you tell me what’s wrong here?

    <?php 
    
    $posts = get_posts(array(
        'cat' => $current,
        'post_type' => array( 'page' ),
    	'meta_query' => array(
    		array(
    			'key' => 'show_main',
    			'compare' => '==',
    			'value' => '1'
    		)
    		)
    		)
    );
    
    if( $posts ): ?>
    	
    		
    	<?php foreach( $posts as $post ): 
    		
    		setup_postdata( $post )
    		
    		?>
    loop
    	<?php endforeach; ?>
    	
    	
    	<?php wp_reset_postdata(); ?>
    
    <?php endif; ?>
Viewing 25 results - 10,701 through 10,725 (of 21,318 total)