WP Objects
Radoslav Georgiev edited this page Oct 21, 2018
·
3 revisions
The WP Objects field extends the WP Object field by allowing editors to select more than one object.
The WP Objects field builds on top of the WP Object field, inheriting all of its options:
You can adjust the maximum amount of items, which can be added to the field.
In PHP, use the set_max( $max )
method of the field:
Field::create( 'wp_objects', 'related_posts' )->set_max( 5 )
In addition to the Output Type setting, which defines how to handle every individual item, the Objects field also has the "Output Format" setting:
- Separate the values with commas (
comma
) - Ordered list (
ordered
) - Unordered list (
unordered
) - Paragraphs (
paragraphs
)
In PHP, use the set_output_format( $format )
method:
Field::create( 'wp_objects', 'related_articles' )->set_output_format( 'commas' );
<!-- Output a list of related articles -->
<?php the_value( 'related_articles' ) ?>
<!-- Use the list of articles manually -->
<?php
$links = array();
foreach( get_value( 'related_pages' ) as $item ) {
if( is_a( $item, 'WP_Post' ) ) {
$links[] = get_permalink( $item->ID );
} elseif( is_a( $item, 'WP_Term' ) ) {
$links[] = get_term_link( $item->term_id, $item->taxonomy );
} elseif( is_a( $item, 'WP_User' ) ) {
$links[] = get_author_link( false, $item->ID );
}
}
Quick start
- Creating fields and using their values
- Installation
- Administration interface
- Using the PHP API
- Container Settings
Locations
- Overview & Usage
- Post Type
- Options Page
- Taxonomy
- Comment
- User
- Widget
- Shortcode
- Menu Item
- Attachment
- Customizer
Fields
- Fields
- Text
- Textarea
- WYSIWYG
- Password
- Checkbox
- Select
- Multiselect
- Image Select
- File
- Image
- Audio
- Video
- Gallery
- WP Object
- WP Objects
- Link
- Date
- DateTime
- Time
- Color
- Font
- Icon
- Map
- Embed
- Number
- Sidebar
- Complex
- Repeater
- Layout
- Section
- Tab
- Message
Features
- Adding fields to the Customizer
- Conditional Logic
- Front-End Forms
- Administration columns
- Import and Export
- REST API
- JSON Synchronization
- Yoast SEO
Ultimate Post Types
Functions and API
Tutorials