/grid/the_object

DescriptionDescription

This filter is called when an object (post, term or user) has been setup in the loop after the WP_Query, WP_Term_Query or WP_User_Query.

It allows to modifies object properties like the title, excerpt, etc…

ArgumentsArguments

ArgumentTypeDescription
$objectobjectHolds current object data in the loop (title, excerpt, etc…)

ExampleExample

PHP
functions.php
function prefix_object_data( $object ) {

	// We get attachment object properties from a custom field.
	$attachment = get_post_meta( $object->ID, 'my_custom_attachment', true );

	// We override post thumbnail (custom property of the plugin).
	$object->post_thumbnail = [
		'alt'         => $attachment->alt,
		'title'       => $attachment->title,
		'caption'     => $attachment->caption,
		'description' => $attachment->description,
		'mime_type'   => 'image',
		'sizes'       => [
			'thumbnail' => [
				'url'    => $attachment->thumbnail_url,
				'width'  => $attachment->thumbnail_width,
				'height' => $attachment->thumbnail_height,
			],
			'lightbox'  => [
				'url' => $attachment->lightbox_url,
			],
		],
	];

	return $object;

}

add_filter( 'wp_grid_builder/grid/the_object', 'prefix_object_data', 10, 1 );