Lumberjack\PostTypes\Post::query PHP Method

query() public static method

Convenience function that takes a standard set of WP_Query arguments but mixes it with arguments that mean we're selecting the right post type
public static query ( array $args = null ) : array
$args array standard WP_Query array
return array An array of Post objects
    public static function query($args = null)
    {
        $args = is_array($args) ? $args : [];
        // Set the correct post type
        $args = array_merge($args, ['post_type' => static::$postType]);
        if (!isset($args['post_status'])) {
            $args['post_status'] = 'publish';
        }
        return static::posts($args);
    }

Usage Example

Beispiel #1
0
<?php

/**
 * Search results page
 *
 * Methods for TimberHelper can be found in the /lib sub-directory
 *
 * @package  WordPress
 * @subpackage  Timber
 * @since   Timber 0.1
 */
use Lumberjack\PostTypes\Post;
$templates = ['search.twig', 'posts.twig', 'generic-page.twig'];
$context = Timber::get_context();
$searchQuery = get_search_query();
$context['title'] = 'Search results for ' . $searchQuery;
$context['posts'] = Post::query(['s' => $searchQuery]);
Timber::render($templates, $context);
All Usage Examples Of Lumberjack\PostTypes\Post::query