acf/fields/post_object/result

Overview

This filter allows you to modify the result (text) displayed for each option in the post object field.

Changelog

  • 5.0.0 – Changed 4th parameter from $post_object to $post_id
  • 4.1.2 – Added filter

Parameters

filter( $title, $post, $field, $post_id )
  • $title (string) the text displayed for this post object
  • $post (object) the post object
  • $field (array) the field array containing all attributes & settings
  • $post_id (int) the current post ID being edited

Usage

There are 3 ways to hook into this filter

  1. acf/fields/post_object/result– filter for every field
  2. acf/fields/post_object/result/name={$field_name} – filter for a specific field based on it’s name
  3. acf/fields/post_object/result/key={$field_key} – filter for a specific field based on it’s name

functions.php

<?php

function my_post_object_result( $title, $post, $field, $post_id ) {

    // add post type to each result
    $title .= '(' . $post->post_type .  ')';

    return $title;

}

add_filter('acf/fields/post_object/result', 'my_post_object_result', 10, 4);

?>