I intend to do the following:
/*
* Query all posts versions on taxonomy archive page.
*/
function sam_modify_taxonomy_query( $query ) {
if ( function_exists( 'pll__' ) && ! is_admin() && $query->is_tax() ) {
$query->set('tax_query', '');
$query->set('lang', '');
}
}
add_action( 'pre_get_posts', 'sam_modify_taxonomy_query' );
Below is the code I’m using in the file taxonomy-subtopic.php to achieve both, but I end up getting all posts that are assigned any “subtopic” instead of getting only the posts with the current term (e.g., “copyright” or “trademark“) on the archive page.
When readers visit the “copyright” archive page, for example, they should see only posts that have the term; in the main language or the secondary language if a main language version is not available.
<?php if (have_posts()) : ?>
<header class="header-title-wrapper">
xxx
</header><!-- .header-title-wrapper -->
<h2 class="widget-title"><span>All articles</span></h2>
<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
query_posts(array(
'post_type' => 'post',
'lang' => 'en-PH', // force querying the PH posts
'showposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'subtopic',
'field' => 'slug',
'terms' => $term->term_id,
'operator' => 'IN'
)
)
)
); ?>
<?php
/* Start the Loop */
while (have_posts()) : the_post(); ?>
<?php global $post;
if($post_id = pll_get_post($post->ID, pll_current_language())) { // get translated post (in current language) if exists
$post = get_post($post_id);
setup_postdata($post);
}?>
<?php
get_template_part('template-parts/content', get_post_format());
?>
<?php endwhile; ?>
I would appreciate any advice or explanation that may help fix this. Thank you!
]]>I found?this old question, but the code suggested uses?query_posts
. I’d like to use?WP_Query
. I tried to scramble something, but it didn’t work:
$current_year = date('Y');
$current_month = date('m');
$current_day=date('d');
$today = getdate();
$last_date = $wpdb->get_var("SELECT DATE(MAX(post_date)) FROM {$wpdb->posts} LIMIT 1");
if (!empty($last_date)) {
list($current_year,$current_month,$current_day) = explode('-',$last_date);
}
$args = array(
'date_query' => array(
array(
'after' => array(
'year' => $today["year"],
'month' => $today["month"],
'day' => $last_date,
),
'inclusive' => true,
),
),
'posts_per_page' => -1,
);
Any idea what’s wrong?
]]>I’m trying to skip certain posts in the loop, but doing so completely breaks it (less posts show up and the pagination is broken). Any idea what am I doing wrong?
$i = 0;
while ( have_posts() ) :
the_post();
if($i<5){
$i++;
continue;
}
generate_do_template_part( 'index' );
endwhile;
]]>I’m not an expert doing these mods but learning.
The way I’m trying to achieve it, is by modifying the WP query when the single store php file is called.
The problem is that I can’t find where this query is triggered.
Any help with this? Am I going in the right direction or is there a better way to do it?
Thanks!
]]>post_type=event&orderby=meta_value&meta_key=_event_start_date&order=asc&no_found_rows=true
Where I’m stuck now is with how to query only Future Events with the Repeater as opposed to displaying everything at once including past events.
Any suggestions? Thanks!
]]>$query->meta_query_clauses[ 'where' ]
is protected.
]]>Notice: amp_is_available was called incorrectly.
amp_is_available ()(or
amp_is_request (), formerly
is_amp_endpoint ()) was called too early and so it will not work properly. WordPress is currently doing the
load_script_textdomain_relative_pathhook. Calling this function before the
wpaction means it will not have access to
WP_Queryand the queried object to determine if it is an AMP response, thus neither the
amp_skip_post ()filter nor the AMP enabled toggle will be considered. It appears the plugin with slug
jetpackis responsible; please contact the author. Read Debugging in WordPress for more information. (This message was added in version 2.0.0.) In /web/htdocs/www.nerdream.it/home/wp-includes/functions.php on line 5663
Please can you help me? I have tried to wait for other plugin updates (AMP or Jetpack) but after a few days the situation is the same.
Thanks in advance,
Valerio.
I have a custom post type and in the CPT’s cpt-single.php
file I would like to pull in two posts instead of one.
The two posts will be the post the user clicked in the relevant archive, and the next post in date order (i.e. the default post sorting method of WordPress). The reason for this is the posts are essentially small, useful pieces of information and having two posts pulled in will create a better SEO and user experience.
Normally when I want to pull in a set number of posts on an archive page I would use WP_Query()
and set 'posts_per_page' => 2
but out of the box this won’t work on a cpt-single.php file because such code pulls in posts that are the most recent, not the post that was clicked on the archive page (and then the next most recent).
What I’m looking for is something that works with the WP loop so each post looks the same, but pulls in two posts (the selected one from the archive and then the next one in date order).
<?php
$newsArticles = new WP_Query(array(
'posts_per_page' => 2,
'post_type'=> 'news'
));
while( $newsArticles->have_posts()){
$newsArticles->the_post(); ?>
// HTML content goes here
<?php } ?>
<?php wp_reset_postdata(); ?>
Any help would be amazing.
Emily
]]>