Support

Account

Home Forums Add-ons Repeater Field Browse in repeater for post object

Solving

Browse in repeater for post object

  • I’m using a custom post type to make up a newsletter composed of a collection of posts. I’m using a repeater field with a repeating post object to assign the items I want included. I realise that I could also use a multi-select relationship field (and I’d be interested to know if there’s any real difference in the two approaches).

    My problem is that when the editor goes to select the posts the list only displays the name of the post. I have over 100 newsletters to convert to this system and each will have around 5 posts… around 500 posts all up, and with a lot with similar if not identical names.

    Is there any way to get the post object browse to display more information about the posts, the publication date (which they seem to be ordered by) perhaps?

    A better solution would be to allow a date range limiter on the browsing, but I’m not sure how complicated that would be to implement.

  • I’ve found this

    http://www.advancedcustomfields.com/resources/tutorials/customize-the-relationship-field-list-htm/

    Would it be possible to hack that to display a date instead of an image?

    (Using relationships instead of post objects, of course)

    -answer: yes.

    function my_acf_relationship_result( $html, $post )
    {
    	// add an image to each result
    	$image = get_field('thumbnail', $post->ID);
    	$date = get_the_date();
     
    	if( $image )
    	{
    		$html = '<img src="' . $image['url'] . '" />' . $html;
    	}
     
        return $html . ' ' . $date;
    }
     
    // acf/fields/relationship/result - filter for every field
    add_filter('acf/fields/relationship/result', 'my_acf_relationship_result', 10, 2);
  • Next question: Can you change the order that the browse list is sorted by? Looks like it’s alphabetical, which is going to get really annoying for anyone trying to find ten posts in a list of 500.

  • This plugin:

    http://www.cssigniter.com/ignite/custom-post-types-relationships/

    Has a much better browse interface (too bad it doesn’t seem to work with WP3.6).

    What are the chances of getting the ACF browse interface upgraded to something like this?

  • Hi @pbolger

    You can expect more filters in the future. Did you solve your previous issues using the filter to customize the HTML?

  • Hi Elliot,

    Displaying the date is a good first step, but having the items spread alphabetically over a 500 entry list is going to make getting stories for this weeks newsletter a complete pain. If you could add sort by publish date it’d make things a hell of a lot easier.

    Paul

  • Hi @pbolger

    You can customize all of the relationship query filters INCLUDING sort and order.

    Hope that helps

    Thanks
    E

  • Thanks. Could you add an example to show how to do this?

    Pbolger

  • Hi @pbolger

    If you can post your current filter code, then I can show you how to add the orderby and sort params, but these are already documented on the WP website under WP_Query and get_posts

    Thanks
    E

  • I hate to admit it, but my filter at present is just this:

    <?php
     
    function my_acf_relationship_result( $html, $post )
    {
    	// add an image to each result
    	$image = get_field('thumbnail', $post->ID);
    	$date = get_the_date();
     
    	if( $image )
    	{
    		$html = '<img src="' . $image['url'] . '" />' . $html;
    	}
     
        return $html . ' ' . $date;
    }
     
    // acf/fields/relationship/result - filter for every field
    add_filter('acf/fields/relationship/result', 'my_acf_relationship_result', 10, 2);
     
    
    ?>

    and I’ve edited core/fields/relationship.php to change the sort order.

    Not ideal, I know, but I needed it to work quickly.

  • Hi @pbolger

    The code you have posted is to modify the HTML produced for each result. This will not modify the query at all.

    Please read the docs for modifying the query of a relationship field.

    Thanks
    E

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

The topic ‘Browse in repeater for post object’ is closed to new replies.