|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Meta helper functions definition file. |
| 4 | + * |
| 5 | + * @package eXtended WordPress |
| 6 | + * @subpackage Helper\Functions |
| 7 | + */ |
| 8 | + |
| 9 | +use XWP\Helper\Functions as f; |
| 10 | + |
| 11 | +if ( ! function_exists( 'xwp_get_post_by_meta' ) ) : |
| 12 | + /** |
| 13 | + * Gets a post by its meta key and value. |
| 14 | + * |
| 15 | + * @param string $meta_key Meta key to search for. |
| 16 | + * @param mixed $value Meta value to search for. |
| 17 | + * @param 'ID'|'object' $retval Return value type, either 'ID' for post ID or 'object' for WP_Post object. |
| 18 | + * @return ($retval is 'ID ? int<0,max> : null|WP_Post) |
| 19 | + */ |
| 20 | + function xwp_get_post_by_meta( string $meta_key, mixed $value, string $retval = 'ID' ): int|WP_Post|null { |
| 21 | + return f\Post::get_by_meta( $meta_key, $value, $retval ); |
| 22 | + } |
| 23 | +endif; |
| 24 | + |
| 25 | +if ( ! function_exists( 'xwp_get_post_by_type_and_meta' ) ) : |
| 26 | + /** |
| 27 | + * Gets a post by its type and meta key and value. |
| 28 | + * |
| 29 | + * @param string $meta_key Meta key to search for. |
| 30 | + * @param mixed $value Meta value to search for. |
| 31 | + * @param string $post_type Post type to search for. |
| 32 | + * @param 'ID'|'object' $retval Return value type, either 'ID' for post ID or 'object' for WP_Post object. |
| 33 | + * @return ($retval is 'ID ? int<0,max> : null|WP_Post) |
| 34 | + */ |
| 35 | + function xwp_get_post_by_type_and_meta( string $meta_key, mixed $value, string $post_type, string $retval = 'ID' ): int|WP_Post|null { |
| 36 | + return f\Post::get_by_type_and_meta( $meta_key, $value, $post_type, $retval ); |
| 37 | + } |
| 38 | +endif; |
| 39 | + |
| 40 | + |
| 41 | +if ( ! function_exists( 'xwp_get_term_by_meta' ) ) : |
| 42 | + /** |
| 43 | + * Gets a term by its meta key and value. |
| 44 | + * |
| 45 | + * @param string $meta_key Meta key to search for. |
| 46 | + * @param mixed $value Meta value to search for. |
| 47 | + * @param 'ID'|'object' $retval Return value type, either 'ID' for term ID or 'object' for WP_Term object. |
| 48 | + * @return ($retval is 'ID ? int<0,max> : null|WP_Term) |
| 49 | + */ |
| 50 | + function xwp_get_term_by_meta( string $meta_key, mixed $value, string $retval = 'ID' ): int|WP_Term|null { |
| 51 | + return f\Term::get_by_meta( $meta_key, $value, $retval ); |
| 52 | + } |
| 53 | +endif; |
| 54 | + |
| 55 | +if ( ! function_exists( 'xwp_get_term_by_tax_and_meta' ) ) : |
| 56 | + /** |
| 57 | + * Gets a term by its taxonomy, meta key and value. |
| 58 | + * |
| 59 | + * @param string $meta_key Meta key to search for. |
| 60 | + * @param mixed $value Meta value to search for. |
| 61 | + * @param string $taxonomy Taxonomy to search for. |
| 62 | + * @param 'ID'|'object' $retval Return value type, either 'ID' for term ID or 'object' for WP_Term object. |
| 63 | + * @return ($retval is 'ID ? int<0,max> : null|WP_Term) |
| 64 | + */ |
| 65 | + function xwp_get_term_by_tax_and_meta( string $meta_key, mixed $value, string $taxonomy, string $retval = 'ID' ): int|WP_Term|null { |
| 66 | + return f\Term::get_by_tax_and_meta( $meta_key, $value, $taxonomy, $retval ); |
| 67 | + } |
| 68 | +endif; |
0 commit comments