Tagged: x
-
AuthorPosts
-
August 27, 2016 at 9:34 am #1149656
anncivolParticipantHello,
I would like to pass arguments in the query that generates categories or archives pages, but I don´t know where this query is created.
I need something like
<?php $args = array( 'post_status' => array( 'publish', 'inherit'), 'post_type' => array( 'post', 'attachment') ); $query = new WP_Query( $args ); ?>in order to retrieve attachments, besides regular posts, in a category page.
However, when I look at global>_index.php, I don´t see the query there. I expected to have
<?php if ( $query->have_posts() ) : ?>
but there is only
<?php if ( have_posts() ) : ?>It looks like the query has been imported from somewhere else, not created inside _index.php .
Please tell me in which file/function the query for categories is formed, so that I can include my arguments there.
P.S: I already know about child themes, have set one and will apply the changes to it.
Thank you in advance!
August 27, 2016 at 10:30 am #1149703
ThaiModeratorHi There,
You don’t have to edit the template files, just add the following code under functions.php file in your child theme:
function x_custom_filter($query) { if( !is_admin() && $query->is_main_query() ) { if( $query->is_archive() ) { $query->set('post_type', array( 'post', 'attachment' ) ); $query->set('post_status', array( 'publish', 'inherit' ) ); } } } add_action('pre_get_posts','x_custom_filter');Hope it helps 🙂
August 27, 2016 at 11:15 am #1149742
anncivolParticipantWorked perfectly! Thank you very very much!!! 🙂
August 27, 2016 at 11:56 am #1149782
ThaiModeratorGlad it worked 🙂
If you need anything else please let us know.
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1149656 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
