• Hi

    To start, the plugin is amazing πŸ™‚

    I have one question however, I want there to be the search options in the header, so used

    <?php do_action('show_beautiful_filters', 'my_cpt'); ?>

    Which shows the dropdowns – great

    I also want to show the post count next to each option, so ticked the checkbox in admin.

    Here is where my question lies. The counts show great on the actual job search and list page where the main search results are shown using

    <?php do_action('show_beautiful_filters'); ?>

    ad when on the job search page, the header post counts show up fine.

    However when on any other page (such as homepage or contact page where the <?php do_action('show_beautiful_filters'); ?> isn’t) the post counts are all 0.

    Am I missing something?

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Jonathandejong

    (@jonathandejong)

    Hi Candell,

    I took a quick look in the code. You seem to have found a bug indeed!
    I did a quick patch but haven’t got time to test it .. Could you try it out and see if that fixes the problem?

    Just replace your plugin with this:
    https://dl.dropboxusercontent.com/u/10298919/beautiful-taxonomy-filters.zip

    If it works I’ll ship a new version and you’ll be able to update it as usual through wp admin πŸ™‚

    Thread Starter candell

    (@candell)

    That’s great thanks Jonathan. It does work and will be great for most, could I please ask another question.

    I am modifying the query via pre_get_posts;

    add_filter( 'pre_get_posts', 'jobs_query_for_beautiful_filters' );
    function jobs_query_for_beautiful_filters( $query ) {
    	$timecutoff = date("Ymd");
    	
    	
    	 if ( (! is_post_type_archive('sc_jobs') ) && ( ! is_tax( 'job_categories' ) ) && ( ! is_tax( 'the_advertiser' ) ) || is_admin() ) {
    	
    		return;
    	};
        
    	
    	$query->set( 'post_type', 'sc_jobs' );
    	$query->set( 'orderby', 'meta_value' );
    	$query->set( 'meta_key', 'closing_date' );
    	$query->set( 'meta_compare', '>=' );
    	$query->set( 'meta_value', $timecutoff );
    	$query->set( 'order', 'ASC' );
    }

    to take in to account the closing date meta. The job page search options take this in to account and show the correct counts, however the fixed header search options show numbers disregarding the modified query so the post counts do not match.

    Plugin Author Jonathandejong

    (@jonathandejong)

    Awesome!

    As for your second question.
    The reason this happen is because BTF can’t know what wp_query to look at when it calculates the post count so it creates it’s own query.

    I just added a filter you can use to modify the arguments for the query:
    beautiful_filters_post_count_args

    it takes just an $args array in which you can add your meta_query so it also excludes posts with an older closing_date.
    Using that you can remove your current pre_get_post hook because it will be run on all places the count happens.

    Here’s the new beta with the filter:
    https://dl.dropboxusercontent.com/u/10298919/beautiful-taxonomy-filters.zip
    test it and tell me if it works!

    Thread Starter candell

    (@candell)

    Hi

    Thanks for the amazing support, how do I actually do that?

    Thanks again

    Plugin Author Jonathandejong

    (@jonathandejong)

    Hi,

    No problem! If you enjoy BTF I much appreciate a good review πŸ™‚

    To do this you’d simply add this to your functions.php or custom plugin file:

    
    function modify_btf_post_count_query( $args ) {
    	$args['meta_query'] => array(
    		array(
    			'key' => 'closing_date',
    			'value' => date( 'Ymd' ),
    			'compare' => '>=',
    		),
    	);
    
    	return $args;
    }
    add_filter( 'beautiful_filters_post_count_args', 'modify_btf_post_count_query', 10, 1 );
    

    Do note that you’re actually modifying all queries on your tax pages with your code so you probably want to keep the code for your own archive loop. But you should add a $query->is_main_query() to your if statement to avoid messing with other queries.

    
    if ( (! is_post_type_archive('sc_jobs') ) && ( ! is_tax( 'job_categories' ) ) && ( ! is_tax( 'the_advertiser' ) ) || is_admin() || ! $query->is_main_query() ) {
    
    Thread Starter candell

    (@candell)

    Got it thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Post count on do action in header’ is closed to new replies.