Support

Account

Forum Replies Created

  • I’ll mark this request for the developer to take a look at when he has time.

  • Looking back at the code, I think it may have something to do with the call to update post, not sure why that’s in there, either that of the insert post. Looking at it, since we’re updating the post the the insert needs to be removed and an change is needed to the update.

    try this.

    
    <?php 
    
      function my_pre_save_post($post_id) {
      
        // check for numerical post_id and check post_type
        if (!is_numeric($post_id) || get_post_type($post_id) != 'post') {
          return $post_id;
        }
    
        // update status to draft
        $post = array(
          'ID' => $post_id,
          'post_status'  => 'draft' ,
        );  
    
        // update the post
        wp_update_post($post);
        
        return $post_id;
      }
      
      add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );
      
    ?>
    
  • You need to update the post parent of the image to attach it to the post, you could to that in the same function that you’re using to set the featured image.

    
    <?php
     
    function acf_set_featured_image($value, $post_id, $field ){
      if ($value != '') {
        //Add the value which is the image ID to the _thumbnail_id meta data for the current post
        add_post_meta($post_id, '_thumbnail_id', $value);
        // attach image to post
        wp_update_post(
          array(
            'ID' => $value, 
            'post_parent' => $post_id
          )
        );
      } else {
        delete_post_meta($post_id,'_thumbnail_id', $value);
      }
      return $value;
    }
    // acf/update_value/name={$field_name} - filter for a specific field based on it's name
    add_filter('acf/update_value/name=cursusfoto', 'acf_set_featured_image', 10, 3);
     
    ?>
    
  • I’ve tried setting up a simple test like this. I’ve created fields named bedrooms, city and state. It appears to be working.

    2 thinks, this code should look something like this:

    
    $GLOBALS['my_query_filters'] = array( 
      'field_565712fdeba5c'	=> 'city', 
      'field_565713a9eba5d' => 'state',
      'field_565713e2eba5e'	=> 'bedrooms'
    );
    

    These are field keys and field names for each field

    Make sure that you visit settings => permalinks and save it to make sure that you’re CPT archive is working.

  • I’m not 100% sure what it is you’re asking for.

    acf_form() lets you put forms on the front end of the site. http://www.advancedcustomfields.com/resources/acf_form/

  • That’s not a question I can answer. I will mark the question for the developer to look at if he has time, but as a general rule he doesn’t actually visit this forum on a regular bases. This is a forum for ACF users to get help from other ACF users.

    But like I said above. If I was having this problem I would do my own caching of the field group I was building using PHP so that I was not actually rebuilding the field group on every page load. ACF is built to take advantage of WP core functionality and core does not include persistent caching.

  • The way I would do this is, when adding the posts and/or pages to the new site I would record the page ID values that are added in an option value for the site. I would register the field groups in PHP and I’d get the option value and use this to set the post id in the acf field group’s location rules.

  • Sorry, back to your OP, yes, the Pro version includes a built in field group duplication. You’ll still need to edit all the field names to be unique.

  • I don’t think there is an easy way to do this. If you are using ACF4 this plugin will let you easily duplicate field groups https://wordpress.org/plugins/duplicate-post/ but you’ll need to edit each group to make the field names unique

  • I’m not the developer, so I don’t know completely what the logic of the caching is.

    I do know that there is no persistent object caching built into ACF. ACF is using the WP cache, the same cache WP uses for storing post, meta and other values so that it does not do multiple DB calls to get the same value over and over again on a single page load.

    If you have this set up to be persistent, then that’s another topic.

    So here is what’s happening from what I understand
    — Check to see if there is a cached value
    —- Yes – USE IT
    —- NO – Get the value and store in cache

    This is generally the way caching works

    Your code is adding values after the value has been added to the cache. Therefore the next time the value is needed the cached value will be use. Since your value is not in the cache, if the cache is not cleared then your added value will not exist because the already cached value will be used. So the cache needs to be regenerated to include your new value.

    I’m sure that the developer is not regenerating everything every time. There are many different cache keys for different parts of the data and only the things that need to be generated are.

    If you are using a persistent cache added to WP then I would suggest adding you own object cache in your own code so that instead of rebuilding your local fields every time that you can use your own cached value to add the entire local field group in one call.

  • If you are creating new custom post types then you can just add the same field group to the new post types. Fields can have the same names when used on different post types.

    If I understand what you doing though, I’d probably set up a custom taxonomy of location for the custom post type, then you can create separate lists for each location and only need to add one more template file to your theme “taxonomy-location.php” http://codex.wordpress.org/Function_Reference/register_taxonomy

  • thank’s for the clarification on the version. I actually should have realized that it wouldn’t work on 4. But it will help others that find this thread.

  • I can’t look at the code for the deluxe version of the plugin, so that’s probably why I’m not seeing the error. There is supposed to be compatibility with ACF. At this point I’m going to say that you’re best bet at getting help with the issue would be to contact the author of that plugin.

  • No, you are right, there is no editor in WP that allows you to edit this page. This is where I use ACF options pages. I create an options page that appears under the custom post type menu in the admin and then I add fields to this options page. Then I can edit, in your case, archive-events.php, to use the fields.

  • 
    <?php
     
    function acf_set_featured_image( $value, $post_id, $field  ){
        
        if($value != ''){
          //Add the value which is the image ID to the _thumbnail_id meta data for the current post
          add_post_meta($post_id, '_thumbnail_id', $value);
        } else {
          delete_post_meta($post_id,'_thumbnail_id', $value);
        }
     
        return $value;
    }
    
    // acf/update_value/name={$field_name} - filter for a specific field based on it's name
    add_filter('acf/update_value/name=cursusfoto', 'acf_set_featured_image', 10, 3);
     
    ?>
    
  • Glad you worked out your problem. Also, in case you haven’t run into it, all fields used on any options page must also be unique (unless you save the values to a post_id which was added in 5.2.7)

  • I’m sure this will be of value to anyone using that plugin.

    Does it work with both ACF4 and 5?

    Have you thought about making this into a plugin?

  • Because the added fields are not added to the cache and the next time acf gets the fields the new field will be missing, so the cache for the field group’s fields needs to be cleared. Or at least that’s my understanding of it.

    Something similar can happen when you add a field group after getting the field groups… under some conditions. I have a couple of plugins that get all of the ACF field groups, and then adds new field groups based on the existing fields. In these plugins I need to manually clear the acf field group cache to get my new field groups to appear where they are supposed to.

  • You’re going to hate me, but… I have a test site that I keep around for testing WooCommerce stuff. It has

    – WP 4.3.1
    – ACF 5.3.2.2
    – WooCommerce 2.4.10

    and I installed WooCommerce – Store Exporter 1.8.3

    I’m not saying that it’s not going away when deactivating this plugin, but with just these 3 plugins I’m not seeing an issue.

    What other plugins do you each have installed on the site, there must be something else in common.

    (Also, just a side note, the store exporter is not compatible with ACF5, only ACF4. Meaning it won’t export custom fields created with ACF5.)

  • Does this happen for all field groups for all post type location rules or just some post type location rules?

  • Glad you got the problem worked out, sorry no one replied sooner.

    I do recall that there were some issues with an earlier version of ACF4 with WP4.3.1 but I was under the impression that the latest version available for 4 had corrected them.

    So what you’re saying is the Gallery add on for ACF4 is still having issues?

  • Looking at acf_the_content I don’t see any reason why you couldn’t do the same thing by using acf_the_content everywhere you have the_content in your above code. acf_the_content basically calls most of the same filters that the_content runs as far as I know.

Viewing 25 posts - 12,626 through 12,650 (of 14,460 total)