Hi everyone,
I have create a plugin to show my events and I need to show posts that are schedule or in a future date into the archive-eventos.php and taxonomy.php
I need something to add into functions.php or into the plugin itself so can work with normal pagination and not special with special querys in the loop.
Also this should only target the custom post type called "eventos".
Many thanks to everyone for the help.
Arnav Joy answers:
please try this in functions.php
function aj_change_loop_output( $query ) {
if ( $query->is_main_query() && ( is_post_type_archive('evento') || is_tax( 'channel' ) ) ) {
$query->set( 'post_type', 'future' );
}
}
add_action( 'pre_get_posts', 'aj_change_loop_output' );
Arnav Joy comments:
please change this line
$query->set( 'post_type', 'future' );
to
$query->set( 'post_status', 'future' );
Rai comments:
Many Thanks Arnav,
Not working, I add it into the child theme functions.php it does not break the site but is not working. ;(
You can see it here, It should be 2 post that are with future dates: http://www.comunidadkundalini.com/eventos/
Arnav Joy comments:
please try this
function aj_change_loop_output( $query ) {
if ( $query->is_main_query() && ( is_post_type_archive('evento') || is_tax( 'channel' ) ) ) {
$query->set( 'post_type', 'eventos' );
$query->set( 'post_status', 'future' );
}
}
add_action( 'pre_get_posts', 'aj_change_loop_output' );
please check this line , here you have to write your own custom taxonomy
is_tax( 'channel' )
and in these lines replace it with your custom post type
is_post_type_archive('evento')
$query->set( 'post_type', 'eventos' );
please check post type
Rai comments:
Ok, I change the code to this:
function aj_change_loop_output( $query ) {
if ( $query->is_main_query() && ( is_post_type_archive('eventos') || is_tax( 'channel' ) ) ) {
$query->set( 'post_type', 'eventos' );
$query->set( 'post_status', 'future' );
}
}
add_action( 'pre_get_posts', 'aj_change_loop_output' );
I just change evento for eventos and it works, no the problem is that only shows future posts, I need that shows future and published also.
Many thanks.
Try it now: http://www.comunidadkundalini.com/eventos/
Arnav Joy comments:
change this
$query->set( 'post_status', 'future' );
to
$query->set( 'post_status', array( 'publish', 'future' );
Rai comments:
Another thing is that I have a lot of taxonomys, how to target all them without need to listed all.
Arnav Joy comments:
you mean you have lots of taxonomies or lots of terms of a taxonomy ?
Rai comments:
The last one works for publish and future posts, I just need to add the last ) a the end before the ;
What about if for the case of the taxonomys we target all them inside the custom post type?, could be possible?.
Many thanks.
Rai comments:
Let me check.
Rai comments:
I have 5 taxonomies and a lot of terms inside each one.
I try to add it like this but not working:
function aj_change_loop_output( $query ) {
if ( $query->is_main_query() && ( is_post_type_archive('eventos') || is_tax( 'pais' , 'escuela' , 'precio' , 'tematica' , 'duracion') ) ) {
$query->set( 'post_type', 'eventos' );
$query->set( 'post_status', array( 'publish', 'future' ));
}
}
add_action( 'pre_get_posts', 'aj_change_loop_output' );
Arnav Joy comments:
not sure but I hope this will work
function aj_change_loop_output( $query ) {
$taxonomy_names = get_object_taxonomies( 'eventos' );
if ( $query->is_main_query() && ( is_post_type_archive('eventos') || ( is_tax() && @in_array( get_query_var( 'taxonomy' ) , $taxonomy_names ) ) ) ) {
$query->set( 'post_type', 'eventos' );
$query->set( 'post_status', array( 'publish', 'future' ) );
}
}
add_action( 'pre_get_posts', 'aj_change_loop_output' );
Rai comments:
I try adding just one taxonomie to the list and now is working,
So to finish I will need to know how to add more then one tax.
if ( $query->is_main_query() && ( is_post_type_archive('eventos') || is_tax('pais') ) ) {
Arnav Joy comments:
or try this.
if ( $query->is_main_query() && ( is_post_type_archive('eventos') || is_tax('pais') || is_tax('escuela') || is_tax('precio') || is_tax('tematica') || is_tax('duracion') ) ) {
Rai comments:
Working!,
Excellent.
Many Thanks for this.
Rai comments:
So How can I select you so you can receive the payment?.
Arnav Joy comments:
ok Good to hear .
Please vote and close this question .
Arnav Joy comments:
please go to this link
http://www.wpquestions.com/question/pickAWinner/id/10188
Rai comments:
Ok, I think I vote all ready but not sure how to close this question.