library/Content/PostFilters.php
public function initFilters()
    {

        //Only run on frontend
        if (is_admin()) {
            return;
        }

        global $wp_query;

        if ((is_category() || is_tax() || is_tag()) && !get_post_type()) {
            $postType = 'post';
        }

        $postType = get_post_type();

        if (!$postType && isset($wp_query->query['post_type'])) {
            $postType = $wp_query->query['post_type'];
        }

        if (!$postType) {
            return;
        }

        $queriedObject = get_queried_object();
        $objectId = null;
        if (isset($queriedObject->ID)) {
            $objectId = $queriedObject->ID;
        }

        $pageForPosts = get_option('page_for_' . get_post_type());

        if (($pageForPosts !== $objectId && !is_archive() && !is_post_type_archive() && !is_home() && !is_category() && !is_tax() && !is_tag()) || is_admin()) {
            return;
        }

        add_action('Municipio/viewData', function ($data) use ($wp_query, $postType) {

            //Get current post type enabledTaxonomyFilters
            if (!isset($data['postType']) || !$data['postType']) {
                $data['postType'] = $postType;
            }

            //Get header filters
            if ($enabledHeaderFilters = get_field('archive_' . $data['postType'] . '_post_filters_header', 'option')) {
                $data['enabledHeaderFilters'] = $enabledHeaderFilters;
            } else {
                $data['enabledHeaderFilters'] = array();
            }

            //Get taxonomy filters
            if ($enabledTaxonomyFilters = $this->getEnabledTaxonomies($data['postType'])) {
                $data['enabledTaxonomyFilters'] = $enabledTaxonomyFilters;
            } else {
                $data['enabledTaxonomyFilters'] = array();
            }

            //Is query string present?
            $data['queryString'] = (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) ? true : false;

            //The archive url
            $data['archiveUrl'] = $this->getArchiveSlug($postType);

            $data['searchQuery'] = $this->getSearchQuery();

            return $data;
        });
    }
public function initFilters()
    {

        //Only run on frontend
        if (is_admin()) {
            return;
        }

        global $wp_query;

        if ((is_category() || is_tax() || is_tag()) && !get_post_type()) {
            $postType = 'post';
        }

        $postType = get_post_type();

        if (!$postType && isset($wp_query->query['post_type'])) {
            $postType = $wp_query->query['post_type'];
        }

        if (!$postType) {
            return;
        }

        $queriedObject = get_queried_object();
        $objectId = null;
        if (isset($queriedObject->ID)) {
            $objectId = $queriedObject->ID;
        }

        $pageForPosts = get_option('page_for_' . get_post_type());

        if (($pageForPosts !== $objectId && !is_archive() && !is_post_type_archive() && !is_home() && !is_category() && !is_tax() && !is_tag()) || is_admin()) {
            return;
        }

        add_action('Municipio/viewData', function ($data) use ($wp_query, $postType) {

            //Get current post type enabledTaxonomyFilters
            if (!isset($data['postType']) || !$data['postType']) {
                $data['postType'] = $postType;
            }

            //Get header filters
            if ($enabledHeaderFilters = get_field('archive_' . $data['postType'] . '_post_filters_header', 'option')) {
                $data['enabledHeaderFilters'] = $enabledHeaderFilters;
            } else {
                $data['enabledHeaderFilters'] = array();
            }

            //Get taxonomy filters
            if ($enabledTaxonomyFilters = $this->getEnabledTaxonomies($data['postType'])) {
                $data['enabledTaxonomyFilters'] = $enabledTaxonomyFilters;
            } else {
                $data['enabledTaxonomyFilters'] = array();
            }

            //Is query string present?
            $data['queryString'] = (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) ? true : false;

            //The archive url
            $data['archiveUrl'] = $this->getArchiveSlug($postType);

            $data['searchQuery'] = $this->getSearchQuery();

            return $data;
        });
    }
public function initFilters ( ) { //Only run on frontend if ( is_admin ( ) ) { return ; } global $ wp_query ; if ( ( is_category ( ) || is_tax ( ) || is_tag ( ) ) && ! get_post_type ( ) ) { $ postType = 'post' ; } $ postType = get_post_type ( ) ; if ( ! $ postType && isset ( $ wp_query -> query [ 'post_type' ] ) ) { $ postType = $ wp_query -> query [ 'post_type' ] ; } if ( ! $ postType ) { return ; } $ queriedObject = get_queried_object ( ) ; $ objectId = null ; if ( isset ( $ queriedObject -> ID ) ) { $ objectId = $ queriedObject -> ID ; } $ pageForPosts = get_option ( 'page_for_' . get_post_type ( ) ) ; if ( ( $ pageForPosts !== $ objectId && ! is_archive ( ) && ! is_post_type_archive ( ) && ! is_home ( ) && ! is_category ( ) && ! is_tax ( ) && ! is_tag ( ) ) || is_admin ( ) ) { return ; } add_action ( 'Municipio/viewData' , function ( $ data ) use ( $ wp_query , $ postType ) { //Get current post type enabledTaxonomyFilters if ( ! isset ( $ data [ 'postType' ] ) || ! $ data [ 'postType' ] ) { $ data [ 'postType' ] = $ postType ; } //Get header filters if ( $ enabledHeaderFilters = get_field ( 'archive_' . $ data [ 'postType' ] . '_post_filters_header' , 'option' ) ) { $ data [ 'enabledHeaderFilters' ] = $ enabledHeaderFilters ; } else { $ data [ 'enabledHeaderFilters' ] = array ( ) ; } //Get taxonomy filters if ( $ enabledTaxonomyFilters = $ this -> getEnabledTaxonomies ( $ data [ 'postType' ] ) ) { $ data [ 'enabledTaxonomyFilters' ] = $ enabledTaxonomyFilters ; } else { $ data [ 'enabledTaxonomyFilters' ] = array ( ) ; } //Is query string present? $ data [ 'queryString' ] = ( isset ( $ _SERVER [ 'QUERY_STRING' ] ) && ! empty ( $ _SERVER [ 'QUERY_STRING' ] ) ) ? true : false ; //The archive url $ data [ 'archiveUrl' ] = $ this -> getArchiveSlug ( $ postType ) ; $ data [ 'searchQuery' ] = $ this -> getSearchQuery ( ) ; return $ data ; } ) ; }
Initialize the post filter UI
@return void
Initialize the post filter UI