Skip to content

PostRelationshipControl

Junaid Bhura edited this page Oct 29, 2019 · 2 revisions

post-relationship-control

This component is used to select related posts in a block. It inherits BaseControl.

Usage

import { PostRelationshipControl } = gumponents.components;

<PostRelationshipControl
	label="Select people"
	help="Select people"
	postTypes="people"
	taxonomies={ [ { people_roles: [ 'ceo', 'management' ] } ] }
	value={ people.map( person => person.ID ) }
	onSelect={ people => setAttributes( { people } ) }
	buttonLabel="Select People"
	filter="people_meta"
	max="1"
/>

Props

label

The label for the control.

  • Type: String
  • Required: No

help

The help text for the control.

  • Type: String
  • Required: No

postTypes

Post type(s) to query for.

  • Type: String | Array
  • Required: No
  • Default: "post"

taxonomies

Taxonomies to filter, used in addition to post types above.

  • Type: String | Array
  • Required: No

buttonLabel

The label for the select button.

  • Type: String
  • Required: No

value

The selected post IDs for this control.

  • Type: Array
  • Required: Yes

onSelect

A function that receives the values of the control.

  • Type: Function
  • Required: Yes

filter

Creates a custom filter name which can be used to further customize results. More below.

  • Type: String
  • Required: No

max

The maximum number of selections that can be made with this control.

  • Type: Number
  • Required: No

Filters

gumponents_posts_relationship_query

This filter is used to query the WP_Query args before they are executed for this control.

If the filter property is used, then that gets appended to this, to create a custom filter name. For example if the value of the filter property was people_meta, the available filter would be gumponents_posts_relationship_query_people_meta

gumponents_posts_relationship_query_search_title

This filter is used to turn searching the title on or off.

gumponents_posts_relationship_results

This filter is used to customize results before they are passed on to this control.

If the filter property is used, then that gets appended to this, to create a custom filter name. For example if the value of the filter property was people_meta, the available filter would be gumponents_posts_relationship_results_people_meta