We use the plugin “diviengine” to output our custom post types. However, as soon as we install relevanssi, the output of the post types no longer works correctly. The support of diviengine wrote me the following:
So, specifically we are using post__in argument to get assigned post object.
But Relevanssi ignore this parameter and returning all posts by “
relevanssi_populate_array
” function.Generated sql query by original query_posts function is following.
SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.ID IN (3547) AND wp_posts.post_type = 'autoren' AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-draft')) ORDER BY wp_posts.post_date DESC
Unfortunately, he could only help us so far. Perhaps someone here in the forum can help us?
]]>In my case I want to output default “post” articles and my custom post type “blog”.
In test environment I have 100+ post articles and 8 blog articles.
I tried query_posts() and pagination gets messed up.
Also pagination gets messed up with wp_query.
Well, maybe I am doing something wrong.
If I output only single post type, all works fine.
My args look like this:
'post_type' => array('post', 'blog'),
'post_status' => 'publish',
'posts_per_page' => 6,
I am doing it with AJAX, so my query is in functions.php.
I copied results to gsheets and marked titles which were repeating. I can tell that this is not related to offset. This is related to merged post types. So if I have 2 blog articles only, two “posts” articles are repeated.
If I have 8 blog articles, table looks a little horrible
What am I doing wrong?
If there any hack for multi post type?
I have the most recent wordpress version.
Regards
]]>1. If I display the search results through Query_posts, then instead of the specified parameters in the filter (by custom fields) I get the output of absolutely all records on the site.
2. If I display the search results via get_posts, sorting by an arbitrary CENA field does not work.
I do not use ACF. Changed the php version, did not help. What could be the problem. Thank!
<div style="float:left;margin:20px 0 0 0%;width:100%;text-align:center;">Найдено товаров по Вашему запросу - <span style="color:#3ac128"><?php global $wp_query; echo $wp_query->found_posts;?></span></div>
<div itemprop="articleBody" class="shina-textstr mycart_shelfItem">
<?php the_posts_pagination( array(
'screen_reader_text' => ' ',
'show_all' => False, // показаны все страницы участвующие в пагинации
'end_size' => 1, // количество страниц на концах
'mid_size' => 1, // количество страниц вокруг текущей
'prev_next' => True, // выводить ли боковые ссылки "предыдущая/следующая страница".
'prev_text' => __('?'),
'next_text' => __('?'),
) ); ?>
</div>
<div itemprop="articleBody" class="shina-textstr mycart_shelfItem">
<?php query_posts ( array ($query_string.'cat'=>get_query_var('cat'),'orderby'=>'meta_value_num','meta_key'=>'cena','posts_per_page'=>'24','order'=>'ASC'));
if (have_posts()) {
{echo '';}
while (have_posts()) {
the_post();?>
<div class="kazhdblok mycart_shelfItem">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<div class="miniatyri"><?php if ( in_category( array( 2, ) )) { ?><div class="shmnt">Шиномонтаж в подарок!</div><?php } ?><img src="<?php if (has_post_thumbnail()) { $thumb_id = get_post_thumbnail_id();$thumb_url = wp_get_attachment_image_src($thumb_id,'full', true);echo $thumb_url[0];}else {echo 'https://megashina-taganrog.ru/upload/ftk/'.get_post_meta($post->ID, 'foto', true).'';}?>">
</div></a>
<div class="nazvtovar"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><h3><?php if ( in_category( array( 3, ) )) { ?>
<?php echo 'Колесный диск '; echo get_post_meta($post->ID, 'opis', true); ?>
<?php } ?>
<?php if ( in_category( array( 2, ) )) { ?>
<?php echo 'Автомобильная шина '; echo get_post_meta($post->ID, 'opis', true); echo' '; echo get_post_meta($post->ID, 'sezon', true); ?>
<?php } ?></h3></a><div style="display:none" class="item_name"><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a> <a id="n-link" href="" download></a></div></div>
<?php echo '<div class="tsennik-k item_price">';
echo get_post_meta($post->ID, 'cena', true);
echo '<span class="rub-k"> руб.</span><br></div><div class="k"><input type="number" class="item_quantity" min="1" value="1"/></div>';?>
<div class="starcena">на <?php echo get_post_meta($post->ID, 'nomersklada', true); ?> складе <?php echo get_post_meta($post->ID, 'kolvonasklade', true); ?> шт</div>
<?php echo '<div class="vkorz">
<span class="dob item_add" tabindex="1" data-title=""><i title="в корзину" id="vko" class="sline-wallet"></i></span>
</div></div>';?>
<script>
$('.item_price').each(function(){
var str = $(this).text();
$(this).html(str.replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 '));
});
</script>
<?php }
}
?>
<noindex><div style="margin-top:50px;margin-bottom:210px;float:left;width:100%;"><?php the_posts_pagination( array(
'screen_reader_text' => ' ',
'show_all' => False, // показаны все страницы участвующие в пагинации
'end_size' => 1, // количество страниц на концах
'mid_size' => 1, // количество страниц вокруг текущей
'prev_next' => True, // выводить ли боковые ссылки "предыдущая/следующая страница".
'prev_text' => __('?'),
'next_text' => __('?'),
) ); ?></div>
</noindex>
</div>
]]>in this loop the only problem is the presentation, it showing many time in the top, so pls how can i let it to be showing one time?
Thanks
<?php query_posts('post_type=wear&meta_key=sold&meta_value=yes'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<p>I'd like this presentation to be showing one time if there is the sold</p>
<?php endwhile; ?>
<?php rewind_posts(); ?>
<?php while (have_posts()) : the_post(); ?>
<h1>Yes, there is some sold</h1>
<?php endwhile; ?>
<?php else : ?>
<h1>No sold available</h1>
<?php endif; ?>
]]>How can i have a query_posts that displays only recent tribe_events excluding all future events?
thanks in advance,
Tony
]]> $args = array
(
'post_type' => 'item',
'nopaging' => true,
'tax_query' => array
( array
(
'taxonomy' => $taxonomy,
'field' => 'term_taxonomy_id',
'terms' => $term_id
)
),
'meta_query' => array(
array(
'key' => 'from_import',
'value' => '1',
)
)
);
$posts = query_posts( $args );
When I remove meta_query or tax_query it works fine. How I can combine it?
]]>Can anyone out there have a look at the code I’m using and let me know if I should just leave it, or if I need to change it, and if I do, change it to what? Thanks.
I have 4 sections on my home page, each shows posts from a different category. One section shows 10 news stories, another 1 story with a video, etc.
I just use this same code 4 times, changing the obvious parameters:
<?php query_posts('category_name=video&showposts=1;'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
<?php the_content(); ?>
<?php echo do_shortcode( '[hupso]' ); ?>
<div class="rightdate"><?php the_time('F jS, Y') ?></div>
<div class="commentlink"><?php comments_popup_link('Comment »', '1 Comment »', '% Comments »'); ?></div>
<?php the_tags('<p class="post-tags"><strong>Tags:</strong> ', ', ', '</p>'); ?>
<div class="clear"></div>
<?php if ( $user_ID ) : ?> <?php edit_post_link(); ?> <?php endif; ?>
<div class="clear"></div>
</div>
<?php endwhile; ?>
<?php endif; ?>
Site is at https://rebellionnews.com/
]]>This is not a really question, more a solution (don’t know a better place than the support forum to post it):
I want to use a WP_Query to get the objects for contextual maps (instead of using query_posts and affecting the main query).
I use this simple solution, works great:
I changed line 1101 in geo-mashup.php
from:
$context_objects = $wp_query->posts;
to:
$context_objects = apply_filters(‘geo_mash_contextual_posts’, $wp_query->posts);
The code in functions.php is then something like this:
function map_query_filter(){
$args = array(
//
);
$map_query = new WP_Query( $args );
return $map_query->posts;
}
add_filter(‘geo_mash_contextual_posts’,’map_query_filter’);
Some real world example for people using post2post plugin:
On my site allcyclistsarebeautiful.com, when any Author page is being displayed, I want to show a map with all posts by the author and the all connected journeys.
In the post wrapper, after the content, I put a hook ‘para_postcontent_after’.
And in functions.php this (it’s little weird with my globals $post and $post_global, makes only sense in the context of my theme):
function acab_content_add_map_author(){
$query_args = array(
‘author’ => $GLOBALS[‘author’],
‘nopaging’ => true,
);
$author_posts = new WP_Query( $query_args );
$query_args = array(
‘connected_type’ => ‘user_to_journeys’,
‘connected_items’ => get_queried_object(),
‘nopaging’ => true,
);
$connected_journeys = new WP_Query( $query_args );
$map_query = new WP_Query();
$map_query->posts = array_merge( $connected_journeys->posts, $author_posts->posts);
$map_query->post_count = $connected_journeys->post_count + $author_posts->post_count;
return $map_query->posts;
}
function acab_content_add_map(){
if ( get_the_id() != 278 ) return;
global $post;
$post_global_id = $GLOBALS[‘post_global’]->ID;
$args_for_all = array(
‘height’ => ‘500’,
‘width’ => ‘100%’,
‘map_content’ => ‘global’,
‘zoom’ => ‘7’,
‘marker_select_attachments’ => ‘false’,
‘add_overview_control’ => ‘true’,
‘add_map_type_control’ => ‘false’,
‘load_empty_map’ => ‘true’,
‘click_to_load’ => ‘true’,
‘click_to_load_text’ => ‘click to load map’,
‘enable_scroll_wheel_zoom’ => ‘false’,
‘limit’ => ’50’
);
if (is_author()){
add_filter(‘geo_mash_contextual_posts’, ‘acab_content_add_map_author’);
$args = $args_for_all;
$args[‘map_content’] = ‘contextual’;
echo GeoMashup::map( $args );
}
}
add_action( ‘para_postcontent_after’, ‘acab_content_add_map’ );
And this a question:
I don’t want to make changes in the plugin. Is it possible to get a filter in line 1101 in future releases?
alright, be happy, happyHomelessHippie
]]>$args = 'cat='.$idCategory.'&tag=comparativas';
query_posts( $args );
The problem that I’m facing is that the list of post presented on the page doesn’t show up the corresponding thumbnail on each post.
Even when :$current_id = get_the_ID();
shows the correct Id if It’s echoed on the loop, I couldn’t make the template work properly.
Thumbnails are generated dynamically basically with these lines:
$post_id = $post->ID;
$thumbnail_id = get_post_thumbnail_id( $post_id );
$thumbnail_image = wp_get_attachment_image_src( $thumbnail_id,$thumbnail_size );
The problem is that I could’n find the way to send to the specific post ids to the function above, since the main$wp_query->posts;
retrieves the page id instead of the post requested by the query_posts method.
Do you know how to retrieve the nested id’s or rewrite the values on the main $wp_query?
If you have any clue that could help me to resolve this I will really appreciate it.
Thanks in advance
]]>Hope someone can help with this. What I want is to display Post Thumbnails from a specific category in the flexslider.
I’m using the following code so far which gets all irfomation from a specific category posts, but the thumbnails does not appear as a slide.
<?php
function add_flexslider() { // display attachment images as a flexslider gallery
$attachments = get_children(array(
'numberposts' => 2,
'post_status'=>"publish",
'post_type'=>"post",
'category_name' => 'Destaque', // category slug
)
);
if ($attachments) { // see if there are images attached to posting
echo '<div class="flexslider">';
echo '<ul class="slides">';
foreach ( $attachments as $attachment_id => $attachment ) { // create the list items for images with captions
echo '<li>';
echo wp_get_attachment_image_src( get_post_thumbnail_id($attachment->ID), 'full' );
echo '<p>';
echo get_post_field('post_excerpt', $attachment->ID);
echo '</p>';
echo '</li>';
}
echo '</ul>';
echo '</div>';
} // end see if images
}
//
?>
]]>