PHP code example of alleyinteractive / wp-find-one

1. Go to this page and download the library: Download alleyinteractive/wp-find-one library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alleyinteractive / wp-find-one example snippets




use function Alley\WP\find_one_post;

// Returns a \WP_Post or null.
$person = find_one_post(
    [
        'meta_key'   => 'twitter',
        'meta_value' => '@potatomaster',
        'post_type'  => 'person',
    ]
);



$person = \get_posts(
    [
        'meta_key'         => 'twitter',
        'meta_value'       => '@potatomaster',
        'post_type'        => 'person',
        'posts_per_page'   => 1,
        'suppress_filters' => false,
    ]
);

if ( ! empty( $person[0] ) ) {
	$person = $person[0];
}



use function Alley\WP\find_one_term;

// Returns a \WP_Term or null.
$category = find_one_term(
    [
        'slug'     => 'potatomaster',
        'taxonomy' => 'category',
    ]
);



$category = \get_terms(
    [
        'number'   => 1,
        'slug'     => 'potatomaster',
        'taxonomy' => 'category',
    ]
);

if ( ! empty( $category[0] ) ) {
	$category = $category[0];
}



use function Alley\WP\find_result;

// Returns a \WP_Network or null.
$network = find_result( \WP_Network::class, \get_networks() );