wp-lemon Docs
Query Functions
Query Functions
The following function documentation is automatically generated.
Functions
Name | Return Type | Summary/Returns |
---|---|---|
adjacent_post_info() | array or false | Get 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 null | Archive query that queries an x amount of posts of a specific post type. Returns: Returns collection of posts. |
get_post_type_options() | array | Get options for a specific post type. Returns: The post type options. |
get_total_posts() | array | 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. Returns: Array with context data to be added to the archive.twig. |
latest_items_query() | \Timber\PostCollectionInterface or null | Context function that queries the latest x amount of posts. Returns: Returns collection of posts. |
next_post_info() | array or false | Get next post when available, otherwise get the first post. Returns: Array with post id, title and url. |
other_items_query() | \Timber\PostCollectionInterface or null | Context 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 false | Get previous post when available, otherwise get the last post. Returns: Array with post id, title and url. |
specific_items_query() | \Timber\PostCollectionInterface or null | Context function that queries specific ID's from a specific posttype Returns: Returns collection of posts. |
taxonomy_post_collection() | array | Returns 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.
Name | Type | Description |
---|---|---|
$post_type | string | The 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.
Name | Type | Description |
---|---|---|
$type | string | which post type we want to query. |
$amount | int | Amount of posts we want to query. |
$predefined_posts | array<string,mixed> | Array with predefined post ids. |
$taxonomy | string | name of the taxonomy we want to query. |
$term_ids | int[] | Array of term ids which we want to query. |
$extra_args | array<string,mixed> or bool or null | Extra 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.
Name | Type | Description |
---|---|---|
$type | string | which post type we want to query. |
$amount | int | Amount of posts we want to query. |
$current_id | int | which ID we want to exclude. |
$taxonomy | string | Name of the taxonomy to query. |
$terms | array | ID 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.
Name | Type | Description |
---|---|---|
$type | string | Which posttype we want to query. |
$amount | int | Amount of posts we want to query. |
$post_ids | array | The 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.
Name | Type | Description |
---|---|---|
$type | string | which posttype we want to query. |
$amount | int | Amount of posts we want to query. |
$taxonomy | string | Name of the taxonomy to query. |
$terms | array | ID of the term to query inside $taxonomy. |
$extra_args | array | Extra 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.
Name | Type | Description |
---|---|---|
$post_type | string | which posttype we want to query. |
$loaded_posts | int | how many posts there are currently loaded. |
$taxonomy | string | the taxonomy we want to query if any. |
$term | array | the terms we want to query if any. |
$extra_args | array | Extra 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.
Name | Type | Description |
---|---|---|
$direction | string | Direction to query. Can be next or previous. |
$orderby | string or null | Orderby 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.
Name | Type | Description |
---|---|---|
$orderby | string or null | Orderby 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.
Name | Type | Description |
---|---|---|
$orderby | string or null | Orderby 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.
Name | Type | Description |
---|---|---|
$taxonomy | string | The taxonomy to query. |
$post_type | string | The post type to query. |
Edit this page on GitHub