Support

Account

Forum Replies Created

  • This reply has been marked as private.
  • Hi Elliot,

    I did purchase the repeater, but it is not used in this specific project. In this project I am using ACF in 2 ways:
    1- A custom post type called post_image that is using your “image” field to store a single image per post.
    2- In the standard post type a “Relationship” field is setup that pulls in posts where post_type = post_image…ideally dynamically filtered by category as the user selects/deselects categories.

    The idea is to populate the post_image area with a bunch of images in a various categories. And then when the user goes to create a new post they have the option of selecting a single image based based on the category(s) that post is being created in.

    Hopefully this give you enough background, but please let me know if you need more details.

  • This reply has been marked as private.
  • Got it! I didn’t realize the the Maximum Post setting was limiting the number of items that can be select or added (+). I thought that was limiting the number of items returned to the UI. Setting this this to 1 does exactly what I needed! – Thank you.

    In terms of jQuery load() I have some code the uses this function to re-load the relationship field, as the categories are checked/unchecked/, this refreshed the UI, but in the case of the relationship field the contents never get reloaded, just the spinning loading icon.
    jQuery( "#acf_957 " ).load("<?php echo $_SERVER['REQUEST_URI'] ?> #acf_957 > *" );

    If I test this against the Post Object select field the re-load works as expected.

    If I could solve the above I would be 75% there! The last 25% is how do I use ajax to force a ACF to re-query the posts based on a new category id list.

  • My Bad! … I had my custom post type set as “Hierarchical” change that to false and its good to go.

  • I have a similar is issue when trying to do this:

    function my_post_object_query( $args, $field, $post )
    {
        // filter by the posts current categories
        $args['cat'] = implode(",", wp_get_post_categories($post->ID));
    	echo "<pre>";
    	print_r($args);	
    	echo "<pre>";
    	return $args;
    	
    }
    
    add_filter('acf/fields/post_object/query/key=field_524f02159316d', 'my_post_object_query', 10, 3);

    The category filter is not picked up… same as above, the post_object.php is using get_pages() against a custom post type.

    Suggestions other then changing the core file?

  • Thanks! got part if it working now.
    $args['cat'] = implode(",", wp_get_post_categories($post->ID));
    I was sending an array and your code is looking for a string.

    I still need to figure out a couple of things:

    For the Relationship field I would like to limit the number of items that the user can add to the right to only one item instead of multiple items. I know through the UI you can set a max number of records to return, but this is not what I am trying to figure out.

    I have some jQuery that listens for category changes and captures the string of categories. You mentioned this “What you want to do is load the same wp-admin page, but target the correct select field (either via classes or id attribute). Then just replace the original one with what the AJAX returns.” in the your original response. This is the part I am struggling. with now. I have have the bits of code and now I just need to do the final hook up.

    Any points or threads you can point me at?

  • Hi There

    I am switching back to the Relationship field as it seems to sort of handle the cat filter.

    Here is my code

    function my_relationship_query( $args, $field, $post )
    {
        // increase the posts per page
        //$args['cat'] = wp_get_post_categories($post->ID);
    	$args['cat'] = '3,5';
    	
        return $args;
    }
     
    // filter for a specific field based on it's key
    add_filter('acf/fields/relationship/query/key=field_524f02159316d', 'my_relationship_query', 10, 4);

    using 3,5 works, but wp_get_post_categories($post->ID) does not work, just displays the loading icon.

    Also – Is it possible to limit the number of items that can be added from left to right to only 1?

  • Thanks!

    Making some headway, here is my new test code:

    function my_post_object_query( $args, $field, $post )
    {
    	
    	$args['cat'] = wp_get_post_categories($post->ID);
    	echo '<pre>';
    	print_r($args);
    	echo '</pre>';
    	//die;
        return $args;
    }
    
    // filter for a specific field based on it's key
    add_filter('acf/fields/post_object/query/key=field_524f02159316d', 'my_post_object_query', 10, 3);

    This returns the following array:

    Array
    (
        [numberposts] => -1
        [post_type] => post_images
        [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
        [cat] => Array
            (
                [0] => 5
            )
    
    )

    you can see the cat id is getting added, but the results that come back in the dropdown are not filter to only include posts form catid 5

  • Another related question, I think I might be better off using the post object, but this does not appear to do anything when I would expect the list of posts to filtered by category?

    function my_post_object_query( $args, $field, $post )
    {
    	
        
    	$args['cat'] = get_all_category_ids();
    
        return $args;
    }
    
    // filter for a specific field based on it's name
    add_filter('acf/fields/post_object/query/name=post_image', 'my_post_object_query', 10, 3);
    

    even hard coding a number rather then using get_all_category_ids() does nothing – am I missing something?

  • Thanks for the prompt reply!

    Should I be creating a new field type using your instruction?
    http://www.advancedcustomfields.com/resources/tutorials/creating-a-new-field-type/

    Currently I have the filter setup in the themes functions.php file.

    Any pointers or code snips you can forward or point me at to help me understand where and how to include the AJAX/jQuery piece?

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