Documentation

On this page

  • Category: Tutorials
  • Written: April 29, 2012
  • Updated: November 27, 2012

Retrieving values from “other” pages (Taxonomy, user, media)

Other pages are a new location rule as of v3.1.8 and in short, allow you to add fields to “other” things beside posts. They are:

  • Taxonomy
  • User
  • Media

All the API functions can be used with the “Other” items. However, a second parameter is required to target the item in question. This is similar to passing through a post_id to target a specific post object.

The second parameter needed is a string in the format “$type_$id”.

Usage:

// get value from a taxonomy (taxonomy = "category", id = 3)
$value = get_field('field_name', 'category_3');
 
// get value from a taxonomy (taxonomy = "events", id = 76)
$value = get_field('field_name', 'events_76');
 
// get value from a user (user_id = 1)
$value = get_field('field_name', 'user_1');
 
// get value from a media attachment (id = 375). This works the same as a normal post (attachments are saved the same as posts!)
$value = get_field('field_name', 375);

Example

Repeater + Category

// get value from a taxonomy (taxonomy = "events", id = 76) - note that the_sub_field and get_sub_field don't need a second parameter
if(get_field('repeater_field_name', 'events_76'))
{
	echo '<ul>';
 
	while(the_repeater_field('repeater_field_name', 'events_76'))
	{
		echo '<li>sub_field_1 = ' . get_sub_field('sub_field_1') . ', sub_field_2 = ' . get_sub_field('sub_field_2') .', etc</li>';
	}
 
	echo '</ul>';
}

author.php

<?php
 
$author_id = get_the_author_meta( 'ID' );
$author_logo = get_field('author_logo', 'user_'. $author_id ); // image field, return type = "Image Object"
 
?>
<img src="<?php echo $author_logo['url']; ?>" alt="<?php echo $author_logo['alt']; ?>" />

Related Docs

Functions

ACF boasts a simple to use and powerful API

Learn More »