How to Get Current Archive Info in an Oxygen Repeater

In this tutorial, we’re covering how to get the current archive info in an Oxygen Repeater when using an Advanced Query. When creating an Archive template in Oxygen, you may often want to use an Advanced Query. However, when using an Advanced Query, the query is changed and, therefore, loses its natural filtering for getting the current archive information, such as the current taxonomy and term.

To fix this, we can add two functions to your site using your preferred code snippets plugin, like WP Code Box.

/**
 * Get the current term
 * 
 * @return string $current_terms - the current term
 */
if (!function_exists('bitt_current_archive_term')) {

    function bitt_current_archive_term()
    {
        $current_terms = get_queried_object()->term_id;
        return $current_terms;
    }
}

/**
 * Get the current taxonomy
 * 
 * @return string $current_taxonomy - the current taxonomy
 */
if (!function_exists('bitt_current_archive_taxonomy')) {

    function bitt_current_archive_taxonomy()
    {
        $current_taxonomy = get_queried_object()->taxonomy;
        return $current_taxonomy;
    }
}

These snippets can also be found here:

With these functions added, we can now update our Advanced Query to use the current archive information. Within the Advanced Query, add the “tax_query” parameter and a new array.

Then, add the following values to the array:

  • taxonomy = PHP Function Return value of “bitt_current_archive_taxonomy”.
  • field = “id”
  • terms = PHP Function Return value of “bitt_current_archive_term”.

With this setup, we can add additional parameters to the Advanced Query, such as what post types should be returned, how many posts per page, or anything else you’d like to include from WP_Query.

  1. Davor says:

    Thank you, this was a lifesaver!

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2020-2024 Luxibay
Name(Required)
Please let us know what's on your mind. Have a question for us? Ask away.
This field is for validation purposes and should be left unchanged.