wp-lemon Docs

Query Functions

Query Functions

The following function documentation is automatically generated.

Functions

NameReturn TypeSummary/Returns
adjacent_post_info()array or falseGet next or previous post when available, otherwise get the first or last post.

Returns: Array with post id, title and url.
archive_query()\Timber\PostCollectionInterface or nullArchive query that queries an x amount of posts of a specific post type.

Returns: Returns collection of posts.
get_post_type_options()arrayGet options for a specific post type.

Returns: The post type options.
get_total_posts()arrayCount function to use in relation with the above archive_query() Counts total amount of posts that can be queried in our ajax load more archives.

Returns: Array with context data to be added to the archive.twig.
latest_items_query()\Timber\PostCollectionInterface or nullContext function that queries the latest x amount of posts.

Returns: Returns collection of posts.
next_post_info()array or falseGet next post when available, otherwise get the first post.

Returns: Array with post id, title and url.
other_items_query()\Timber\PostCollectionInterface or nullContext function that queries other ID's of a specific post type on a singular template.

Returns: Returns collection of posts.
previous_post_info()array or falseGet previous post when available, otherwise get the last post.

Returns: Array with post id, title and url.
specific_items_query()\Timber\PostCollectionInterface or nullContext function that queries specific ID's from a specific posttype

Returns: Returns collection of posts.
taxonomy_post_collection()arrayReturns a collection of posts based on a taxonomy and post type.

Returns: Returns an array with (bool) categories, (nested-array) collection, (int) amount and (string) debug.

get_post_type_options()

Get options for a specific post type.

This function queries all posts of the given post type and returns an array containing the post ids and titles.

This is useful for creating a dropdown or select field in a form where the user can choose from existing posts of that type.

since 5.39.0

get_post_type_options( string $post_type )

Returns: array The post type options.

NameTypeDescription
$post_typestringThe post type to get the options for.

latest_items_query()

Context function that queries the latest x amount of posts.

Does have a $predefined_posts param to filter which post to query.

latest_items_query( string $type, int $amount = 2, array $predefined_posts = null, string $taxonomy = null, int[] $term_ids = null, array<string,mixed>|bool|null $extra_args = null )

Returns: \Timber\PostCollectionInterface|null Returns collection of posts.

NameTypeDescription
$typestringwhich post type we want to query.
$amountintAmount of posts we want to query.
$predefined_postsarray<string,mixed>Array with predefined post ids.
$taxonomystringname of the taxonomy we want to query.
$term_idsint[]Array of term ids which we want to query.
$extra_argsarray<string,mixed> or bool or nullExtra arguments we want to mix in.

other_items_query()

Context function that queries other ID's of a specific post type on a singular template.

Excludes current post.

other_items_query( string $type, int $amount, int $current_id, string $taxonomy = null, array $terms = [] )

Returns: \Timber\PostCollectionInterface|null Returns collection of posts.

NameTypeDescription
$typestringwhich post type we want to query.
$amountintAmount of posts we want to query.
$current_idintwhich ID we want to exclude.
$taxonomystringName of the taxonomy to query.
$termsarrayID of the term to query inside $taxonomy.

specific_items_query()

Context function that queries specific ID's from a specific posttype

specific_items_query( string $type, int $amount = -1, array $post_ids = [] )

Returns: \Timber\PostCollectionInterface|null Returns collection of posts.

NameTypeDescription
$typestringWhich posttype we want to query.
$amountintAmount of posts we want to query.
$post_idsarrayThe posts id's to query.

archive_query()

Archive query that queries an x amount of posts of a specific post type.

Uses the page template php file and archive.twig file to display the items and setup context for the ajax call. Uses archive.js for the ajax call Uses archive-ajax.php to output the new items.

archive_query( string $type, int $amount = -1, string $taxonomy = null, array $terms = [], array $extra_args = null )

Returns: \Timber\PostCollectionInterface|null Returns collection of posts.

NameTypeDescription
$typestringwhich posttype we want to query.
$amountintAmount of posts we want to query.
$taxonomystringName of the taxonomy to query.
$termsarrayID of the term to query inside $taxonomy.
$extra_argsarrayExtra arguments we want to mix in.

get_total_posts()

Count function to use in relation with the above archive_query() Counts total amount of posts that can be queried in our ajax load more archives.

get_total_posts( string $post_type, int $loaded_posts = '', string $taxonomy = null, array $term = null, array $extra_args = null )

Returns: array Array with context data to be added to the archive.twig.

NameTypeDescription
$post_typestringwhich posttype we want to query.
$loaded_postsinthow many posts there are currently loaded.
$taxonomystringthe taxonomy we want to query if any.
$termarraythe terms we want to query if any.
$extra_argsarrayExtra arguments we want to mix in.

adjacent_post_info()

Get next or previous post when available, otherwise get the first or last post.

adjacent_post_info( string $direction, string|null $orderby = null )

Returns: array|false Array with post id, title and url.

NameTypeDescription
$directionstringDirection to query. Can be next or previous.
$orderbystring or nullOrderby parameter for the query.

next_post_info()

Get next post when available, otherwise get the first post.

since 3.31.3

next_post_info( string|null $orderby = null )

Returns: array|false Array with post id, title and url.

NameTypeDescription
$orderbystring or nullOrderby parameter for the query.

previous_post_info()

Get previous post when available, otherwise get the last post.

since 3.31.3

previous_post_info( string|null $orderby = null )

Returns: array|false Array with post id, title and url.

NameTypeDescription
$orderbystring or nullOrderby parameter for the query.

taxonomy_post_collection()

Returns a collection of posts based on a taxonomy and post type.

Use the 'collection' key to first loop through the main categories which holds name, slug, id, description and posts and then run a nested loop through the posts.

<nav class="post-overview__nav">
{% for category in post.collection %}
<a class="post-overview__navbtn" href="#{{ category.slug }}">{{ category.name }}</a>
{% endfor %}
</nav>
<div class="post-overview__content">
{% for category in post.collection %}
<div class="post-overview__category" id="{{ category.slug }}">
<h2 class="post-overview__categorytitle">{{ category.name }}</h2>
<div class="post-overview__categorycontent row archive-content">
{% set index = 1 %}
{% for post in category.posts %}
{% set index = index == 3 + 1 ? 1 : index %}
{% set delay = 100 * index %}
{% include [
'components/cards/crd-' ~ card_type ~ '.twig',
'components/cards/crd-default.twig'
] %}
{% endfor %}
</div>
</div>
{% endfor %}
</div>

since 4.9.0

taxonomy_post_collection( string $taxonomy, string $post_type )

Returns: array Returns an array with (bool) categories, (nested-array) collection, (int) amount and (string) debug.

NameTypeDescription
$taxonomystringThe taxonomy to query.
$post_typestringThe post type to query.

Edit this page on GitHub