Documentation

apply_filters("whereused_scan_meta", array $custom_meta_refs, string $meta_value, array $ref)

Details

  • whereused_scan_meta
  • filter
  • Active
  • 1.1.0

Parameters

$custom_meta_refs array
Array of WhereUsed/Reference objects
$meta_value string
Value of the post meta
$ref array
Array of values that must be passed to a new Reference object when adding a new Reference to the $custom_meta_refs array

Example Code To Handle Custom Field

/**
 * Modify post meta scanning: Associate the attachment ID of a PDF
 *
 * @since 1.1.0
 *
 * @param array  $custom_meta_refs
 * @param array  $ref
 * @param string $meta_value
 *
 * @return array Must return an array of WhereUsed/Reference objects
 */
function custom_whereused_scan_meta( array $custom_meta_refs, string $meta_value, array $ref ): array {

	$where = $ref['from_where'] ?? '';

	if ( 'post meta' == $where ) {

		$meta_key = $ref['from_where_key'] ?? '';
		$post_type = $ref['from_post_type'] ?? '';

		if ( 'product' == $post_type && 'product_online_file_id' == $meta_key ) {

			// Let's make sure it's an integer
			$id = (int) $meta_value;

			if ( $id ) {
				// This is an attachment id of a PDF file

				$ref['to_post_id'] = $id; // post ID of the attachment
				$ref['to_post_type'] = 'attachment'; // Post type
				$ref['to_type'] = 'id'; // This attachment was referenced by an ID (link, image, iframe, block, id)

				/**
				 * Add this reference to the meta references array
				 * by creating a Reference object from the $args we have modified
				 * @link https://whereused.com/docs/classes/reference/
				 * @notice If a valid Reference object is not returned, then the entry added below will be skipped.
				 */
				$custom_meta_refs[] = new WhereUsed\Reference( $ref );
			}
		}
	}

	return $custom_meta_refs;
}
add_filter( 'whereused_scan_meta', 'custom_whereused_scan_meta', 10, 3 );

Source

This filter can be found in /where-used/inc/Scan.php

/**
 * Hook that allows you to handle the scan of a specific post meta
 *
 * @link  https://whereused.com/docs/hooks/whereused_scan_meta/
 * @since 1.1.0
 *
 * @param array  $custom_meta_refs
 * @param string $meta_value
 * @param array  $ref
 *
 * @return array Must return an array of WhereUsed/Reference objects
 */
$custom_meta_refs = apply_filters( 'whereused_scan_meta', $custom_meta_refs, $meta_value, $ref );

If you notice any incorrect or missing information on this page, please let us know.