I have a custom taxonomy called “co_writer” which I use to simply tag a post as having been co-written by another author. The “co_writer” terms basically share the same names and slugs with actual authors. For example, John Doe (author) has a “co_writer” term counterpart John Doe.
I need a code that will allow me to also display on an author’s archive posts that have that author’s name used as the term for the “co_writer” taxonomy. So if John Doe has been tagged as co-writer in a post mainly credited to Jane Doe, that post will also show up on John Doe’s author archive. Right now, the posts only appear on the main author’s archive since I lack the code that will grab those into the intended co-author’s page as well.
Is this possible? I was told pre_get_posts might be of use in this case, but I don’t know how exactly I can make it work. Thanks to anyone who can help.
]]>File Location: PLUGIN_ROOT/lib/includes/template-function.php
Lines: 1709 – 1715
If possible could you please update this function to only affect the post types that are created with your plugin. This will resolve the error your plugin is causing with other plugins like Advanced Custom Fields on paginated pages. Thanks for your help!
function fix_easy_property_listings_error( $query ){
remove_action('pre_get_posts','epl_home_pagination_fix');
$post_types_sold = array('property','land', 'commercial', 'business', 'commercial_land' , 'location_profile','rural');
$post_types_rental = array('rental');
global $wp_query;
if( isset($wp_query->query['paged']) && (in_array($query->query_vars['post_type'], $post_types_sold) || in_array($query->query_vars['post_type'], $post_types_rental)) )
$query->set('paged', $wp_query->query['paged']);
}
add_action('pre_get_posts', 'fix_easy_property_listings_error', 0);
]]>Then, I was able to display in category.php.
But, pagination doesn’t work well.
I click link to next, then page move to next page, but display still first page’s posts list.
Please tell me how to fix this code.
And I’m japanese, my english so poor..sorry!
category.php
<?php
foreach((get_the_category()) as $cat) {
$cat_id = $cat->cat_ID ;//get cat id
break ;//end of loop
}
//display list cat&meta key=value
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
query_posts( 'cat=' . $cat_id. '&posts_per_page=10&paged=$paged&meta_key=' . $_GET['key'] . '&meta_value=' . $_GET['value']);
?>
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<!--post list-->
<?php endwhile; endif; ?>
<nav id="pager">
<ul id="pager_ul">
<?php $maxpage = $wp_query->max_num_pages;
$current = $paged;
if(!$current){$current = 1;}
?>
<?php if(!($maxpage==1)): ?>
<li id="prev"><?php previous_posts_link('前へ'); ?></li>
<?php for($i=1; $i <= $maxpage; $i++): ?>
<?php if($i == $current): ?>
<li class="current"><?php echo $i; ?></li>
<?php else: ?>
<li><a href="<?php echo get_pagenum_link($i); ?>"><?php echo $i; ?></a></li>
<?php endif; ?>
<?php endfor; ?>
<li id="next"><?php next_posts_link('次へ'); ?></li>
<?php endif; ?>
</ul>
</nav><!-- / #pager -->
<?php wp_reset_query(); ?>
]]>I try to customize my archive with the category “9”.
I use this code in my functions.php
function archive_ausblick_order( $query ) {
if ( !is_admin() && is_category( '9' ) && $query->is_main_query() ) {
$query->set( 'meta_key', 'my_meta_box_dateBegin' );
$query->set( 'orderby', 'meta_value_date' );
$query->set( 'order', 'DESC' );
}
}
add_action( 'pre_get_posts', 'archive_ausblick_order' );
I only want the FRONTEND, ONLY IF CATEGORY 9 and ONLY THE MAIN QUERY.
But now all my archives are ordered like this. How can I make this function only take action if the user calls category(archive) 9?
Thanks,
Denis
Im having really hard time with one custom query and any help will be appreciated.So the story – my query is limiting front page posts to only those which have featured images. So far so good. My last goal is to sort those posts by custom field, order them in ASC order and show only posts which metakey/custom field date is in 30 days from now.
Current sorting is chaotic. For the second part showing only posts in the next 30 days what I have in mind is to set one var holding current date + 30 days, one var with custom field date and to check is the first one bigger than the second one but how I can get the custom field in this function and where to put this if check ? Probably these question are simple but Im struggling. Thank you for your time and for sharing knowledge.
So far this is my code along with my attempts but as it seems Im not even close…
add_action( 'pre_get_posts', function ( $q )
{
if ( $q->is_home() // Target the home page only
&& $q->is_main_query() // Target only the main query
|| $q->is_category()
) {
$meta_query = array(
array(
'key' => '_thumbnail_id',
)
);
$q->set( 'meta_query', $meta_query );
$q->set('orderby','meta_value_num');
$q->set('meta_key', 'event_date');
$q->set('order', 'ASC');
}
});
]]>The exact code is:
function search_filter($query) {
if ( !is_admin() && $query->is_main_query() ) {
$query->set('post_type', array( 'post' ) );
}
}
add_action('pre_get_posts','search_filter');
This appears to break all of my page links except for one which re-directs to a post for some reason. It happened after updating to 3.8 although i guess the code could be wrong too. Any help would be much appreciated!
Thanks
]]>I was using:
add_Action('pre_get_posts' , 'include_future_posts');
function include_future_posts($query)
{
$query-> set('post_status', array('publish', 'future'));
}
and it works for category.php
but not for single.php.
Anyone has an idea?
Thanks :))