WordPress.org

Ready to get started?Download WordPress

Forums

posts_where problem (6 posts)

  1. Cristiano
    Member
    Posted 1 year ago #

    Hi WP friends,

    I have a taxonomy called "genero". I´m trying to limit my "genero" archive page to just show future posts, like an event page.

    So, I used this code:

    function filter_where( $where ) {
    	if(is_tax(genero)){
    		$where .= " AND post_date > '" . date('Y-m-d', strtotime('0 days')) . "'";
    	}
    	return $where;
    }
    add_filter( 'posts_where', 'filter_where' );
    
    function reset_filter_where() {
    	if(is_tax(genero)){
    		remove_filter( 'posts_where', 'filter_where' );
    	}
    }
    add_action('thematic_below_archiveloop','reset_filter_where');

    It works great on the genero´s archive page, but it breaks all the other looping on other pages. I don´t know what is happening.

    Any help?
    Thanks!

  2. Cristiano
    Member
    Posted 1 year ago #

    Ah, I´m using the thematic framework and the second action is just to put that code after the archive loop, to reset the filter...

  3. Rebecca Schaefer
    Member
    Posted 1 year ago #

    How does it "break" the other looping? Only displaying future posts?

    You need to place double (or single, whichever floats your boat) about genero. Not sure if that will fix the problem, but it's syntactically incorrect as is and can cause general wonkiness.
    if(is_tax('genero')){

  4. Cristiano
    Member
    Posted 1 year ago #

    Hey Rebecca, thanks for your answer!

    When I say it breaks I mean I get a blank page in another archive page, for exemple! On home, where I have another 2 loops, it shows the page, the header, but the loops are empty.

    I tryed your solution, with the same result...

  5. Rebecca Schaefer
    Member
    Posted 1 year ago #

    Can you provide a link?

    If you want to this happen *all* the time in that tax, try

    function filter_where( $where ) {
        $where .= " AND post_date > '" . date('Y-m-d', strtotime('0 days')) . "'";
       return $where;
    }
    function reset_filter_where() {
       remove_filter( 'posts_where', 'filter_where' );
    }
    if(is_tax('genero')) {
      add_filter( 'posts_where', 'filter_where' );
      add_action('thematic_below_archiveloop','reset_filter_where');
    }

    Basically check to see if we're even dealing with the taxonomy then registering the filters and actions.

  6. Cristiano
    Member
    Posted 1 year ago #

    Rebbeca, I can´t let the loopings broken, because the web is working right now and it has lot of visitors... let me know if you are still there, and I change it to you for some minutes! :)

Topic Closed

This topic has been closed to new replies.

About this Topic