Support

Account

Forum Replies Created

  • Solution: My posts weren’t be saved as “drafts” as I had thought. They were being saved as “Pending”

  • I’m using a POST OBJECT acf field called “special_id” for a custom post type called ‘pencils’. If I remove the meta query from the args, I get the list of all Pencil posts it can find (drafts, specifically). When I add this meta_query, I get nothing back. Even though there are many draft posts with special_id “470”. I can use get_field(“special_id”, $pencil_type_id); and get the number 470 back.

    But why can’t I query for those with this (or any) matching id? Do I have a typo or something?

    $args = array(
    ‘post_type’ => ‘pencils’,
    ‘post_status’ => array(‘draft’),
    ‘numberposts’ => -1,
    ‘meta_query’ => array(
    ‘relation’ => ‘OR’,
    array(
    ‘key’ => ‘special_id’,
    ‘value’ => 470,
    ‘compare’ => ‘=’,
    ),
    array(
    ‘key’ => ‘special_id’,
    ‘value’ => array(470),
    ‘compare’ => ‘=’,
    ),
    ),

    );
    $posts = get_posts($args);`

    get_post_meta( $some_pencil_id ) returns successfully:

    meta: Array
    (
     ...
        [special_id] => Array
            (
                [0] => 470
            )
    
      ...
    }
  • I received this reply from support@acf:

    It is against standard practise to import a field group bearing the same name to a site holding a similar field group without deleting the original. This will normally cause duplication issues or possibly break configured fields. The best practise is to make use of the local JSON feature that identifies changes to a field group and synchronize the changes. Please take a look at the following resource page for more info on this: https://www.advancedcustomfields.com/resources/local-json/

    I hope this info helps.

    Thanks,
    James

    I hope it’s fine to simply remove the errant fieldgroup, make a new home page (or recover it from backup) and try again. I hope the entire db isn’t corrupt as a result of this.

    Hopefully?

  • Ah, the late timing of the prepare_field filter seems to make this possible via the $field[‘value’] key

    function preselect_an_option( $field ) {
       
        if (isset($_GET['book_author'])){ // or however you get the value dynamically
            $field['value'] = $_GET['book_author']; // this is where it gets selected!
        }
        return $field;
             
    }
    add_filter('acf/prepare_field/name=book_author', 'preselect_an_option');
  • Oops, didn’t see your reply til now. Thanks! This still isn’t resolved yet.
    Okay, this is what I get:

    Array
    (
    [numberposts] => -1
    [post_type] => custom_type
    [orderby] => title
    [order] => ASC
    [post_status] => Array
    (
    [0] => publish
    [1] => private
    [2] => draft
    [3] => inherit
    [4] => future
    )

    [suppress_filters] =>
    [sort_column] => menu_order, post_title
    [sort_order] => ASC
    [post_parent ] => 695
    )

  • 3) Ideally, I would like a Reset Fields button (which clears all acf forms on the post) a Merge with Template button (which adds in any fields that aren’t already created) and a Copy from Template button (which resets all fields first then merges)

  • Alright, so I’ve created a custom post type where defaults can be set and given a unique name. (eg. the post title = template name)

    I have 2 things to figure out now:

    1) How to copy all ACF data from a given post to another post. (I know how to do it by individual field, I’m just hoping there’s a way to grab all fields at once and copy them over)

    2) How to use ACF on a given Post to select from the available templates.

  • I won’t be forking anyone’s repo anytime soon I’m afraid. But we’re pretty close to a “force update” feature I suppose. Needs some parameters to it somehow but I could see it being a very useful feature.

  • And yea, I just retested it with your explode code to make sure and it no worky. I can’t imagine how this could be useful to anyone as is. And I don’t have time to poke around. I suppose this could be a bug report but Elliot says It’s out of scope so I guess it wouldn’t get looked at?

    Or maybe I’m just not understanding something about how the default values are properly accessed.

  • I tried explode, there wasn’t a comma or anything separating it. No line feed, new line or anything. Just a flat string.

  • So, it feels redundant to have to create a DEFAULT POST when there are already default values lying around. But That’s what I’ve done. I’ve created a Default Post (like a default template for this category, and I’ll have to make one for each unique ACF category that I create) which is updated with the default options so that I can copy them whenever the default fields aren’t automatically set. The logic works like this:

    If my post is set to Category1 &&
    If my post’s ACF checkboxes are not already set
    THEN update_field( $my_field_key, $copy_values_from_default_post, $default_post_id )

    That’s my solution for today. Seems like it should have been more straightforward. Please let me know if there is a better way.

  • I’m close to a solution but unfortunately:

    $default_values = $my_get_field_object[‘default_value’]

    $default_values produces a string with no line breaks! I need the default values as an array so that I can use update_field($my_field_key, $default_values, $post->ID) to update the post.

    Suggestions?

  • aha! get_field_object

    I think you’ve nailed it but I’m gonna try it out first and see how it goes. Thank you both so far!

  • Oh Jonathan, there’s never only one. 🙁
    I’m just simplifying so that I can get this going dynamically for a larger scale intended use.

  • Thanks, Elliot. Yes, I would like to do that but how do I access the default values of the ACF checkbox? If I can capture that array, I can assign it to the postmeta on demand… right?

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