I'm working with taxonomy page order by terms whit different WP_Query. AT the last of every loop something add a "post" that have page title and info from the before post. Very strange thing.
I don't find nothing about this (neither I know how to search this). Thanks por your time. My doce is this:
<?php
$the_query = new WP_Query( array(
'post_type' => 'intervencion',
'tax_query' => array(
array (
'taxonomy' => 'especialidad',
'field' => 'slug',
'terms' => 'bariatrica_ok',
)
),
) );
while ( $the_query->have_posts() ) : $the_query->the_post();?>
<?php $meta = get_post_meta(get_the_ID()); ?>
<div class="col-lg-3 col-md-4 col-sm-6">
<div class="ficha">
<?php if ( has_post_thumbnail() ) { ?>
<?php the_post_thumbnail('thumb_intervenciones', array('class' => 'img-responsive')); ?>
<?php } ?>
<h2><?php echo get_the_title(); ?></h2>
<p class="condiciones">Todo</br>incluido por:</p>
<p class="precio"><?php echo $meta['intervenciones_precio_intervencion'][0]; ?> €</p>
<a class="ficha-btn" href="<?php the_permalink()?>">Solicitar cita</a>
</div>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
The result at the bottom of the list is:
enter image description here
Related
I'm working on a Book Publisher's website. I've created a CTP called BOOKS and a Custom Taxonomy called WRITERS. I'm working on the taxonomy-writers.php and also added a couple Custom Meta Fields for WRITERS as birth date and a short bio. I also want to display the linked BOOK titles that each WRITER has. I currently have:
<?php
get_header();
global $be_themes_data;
while ( have_posts() ): the_post();
?>
<div class="tatsu-module tatsu-text-block-wrap tatsu-34Z1O7zkR ">
<div class="tatsu-text-inner tatsu-align-center clearfix">
<style>
.tatsu-34Z1O7zkR.tatsu-text-block-wrap .tatsu-text-inner{width: 80%;text-align: left;}
</style>
<?php
$term = get_queried_object();
$taxonomymetafield1 = get_field( 'small-bio', $term );
$taxonomymetafield2 = get_field( 'birth-date', $term );
?>
<h1 class="category-title"><?php echo $term->name; ?></h1>
<h5 class="category-title"><?php echo $taxonomymetafield2; ?></h5>
<p class="category-description"><?php echo $taxonomymetafield1; ?></p>
</div>
</div>
<?php $term = get_queried_object(); ?>
<?php echo $term->taxonomy; ?> Books written:<?php echo $term->count; ?></span>
</h1>
<?php
endwhile;
get_footer();
?>
For displaying custom post titles on the taxonomy page. you have to query your custom post type.
<?php
$args = array(
'post_type' => 'your_post_type',
'tax_query' => array(
array(
'taxonomy' => 'your_taxonomy'
'field' => 'slug', // You can name,slug,term_taxonomy_id as well
'terms' => 'your_term_slug', //pass data according to filed
),
),
);
$query = new WP_Query( $args );
after that, loop the query and take title from loop.
I am trying to display same custom post query multiple time in same page. The between the post is it will call different custom taxonomy based on one custom post type. When I am trying to call same custom post second time its not working. But showposts =2 is working but I need to display one post for a single post query. Here is the codes:
<div class="col-sm-6">
<?php
$querevent = new WP_Query( array(
'post_type' => 'tatstory', // name of post type.
'showposts' => 1,
) );
if ( $querevent->have_posts() ):
// Yep, we have posts, so let's loop through them.
while ( $querevent->have_posts() ) : $querevent->the_post(); ?>
<?php if ( has_term('event','eventname' ) && has_term('featured-in-story-page','fetstory' )) { ?>
<div class="listing_inner">
<div class="listing_img">
<?php the_post_thumbnail( 'shop-story', array( 'class' => 'img-fluid' ) ); ?>
</div>
<div class="listing_texts">
<p class="event yellow">Event</p>
<h2><?php the_title(); ?></h2>
</div>
</div>
<?php
} ?>
<?php endwhile;
else :
// No, we don't have any posts, so maybe we display a nice message
echo "<p class='no-posts'>" . __( "Sorry, there are no posts at this time." ) . "</p>";
endif;
?>
</div>
<div class="col-sm-6">
<?php
$quernews = new WP_Query( array(
'post_type' => 'tatstory', // name of post type.
'showposts' => 1,
) );
if ( $quernews->have_posts() ):
// Yep, we have posts, so let's loop through them.
while ( $quernews->have_posts() ) : $quernews->the_post(); ?>
<?php if ( has_term('news','eventname' ) && has_term('featured-in-story-page','fetstory' )) { ?>
<div class="listing_inner">
<div class="listing_img">
<?php the_post_thumbnail( 'shop-newscat', array( 'class' => 'img-fluid' ) ); ?>
</div>
<div class="listing_texts_right">
<p class="event blue">News</p>
<h2><?php the_title(); ?></h2>
</div>
</div>
<?php } ?>
<?php endwhile;
wp_reset_postdata();
else :
// No, we don't have any posts, so maybe we display a nice message
echo "<p class='no-posts'>" . __( "Sorry, there are no posts at this time." ) . "</p>";
endif;
?>
First i would change your WP_Query, example:
$query = new WP_Query( array(
'post_type' => 'tatstory',
'posts_per_page' => '1',
'tax_query' => array(
array (
'taxonomy' => 'eventname',
'field' => 'slug',
'terms' => 'news',
),
array (
'taxonomy' => 'fetstory',
'field' => 'slug',
'terms' => 'featured-in-story-page',
)
),
) );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
// display content
}
} else {
// display when no posts found
}
wp_reset_postdata(); // Restore original Post Data
The query will only collect posts that have the correct terms set.
Restoring original Post Data on the end (wp_reset_postdata()) may help you with calling a new WP_Query again. But I don't know of any reason why you cannot call it twice in a single page template.
I'm creating a dynamic section in my homepage with only posts format video. Now i need to get the URL from this videos...
I already got the Title, link and the date:
<div class="container">
<div class="row">
<div id="layer-videos-section">
<?php
$myposts = new WP_Query( array(
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => 'post-format-video'
)
)
) );
// Open the loop
if ( $myposts->have_posts() ) : while ( $myposts->have_posts() ) : $myposts->the_post();
$year = mysql2date('Y', $post->post_date);
$month = mysql2date('n', $post->post_date);
$day = mysql2date('j', $post->post_date);
?>
<p>
<span class="the_article">
<?php the_title(); ?>
</span>
<span class="the_day">
<?php the_time('j F Y'); ?>
</span>
</p>
<?php
// Close the loop
endwhile; endif;
// Reset $post data to default query
wp_reset_postdata();
?>
</div>
</div>
I got it!
I installed the plugin Featured Video Plus and got the vídeo url using a native function from this plugin:
get_the_post_video_url( $post_id )
I'm hoping someone can help me with this. I'm new to php so it is very much learning on the job.
I am customising an existing Wordpress theme but I am facing a problem with the themes advanced search/results.
The theme has no way to order search results and I know that the default order for Wordpress is by date. Currently if I perform a search, the results are displayed in date order but I need the results to be price high to low.
The current code is as follows
<?php /* If there are no posts to display, such as an empty archive page */ ?>
<?php if ( ! have_posts() ) : ?>
<article id="post-0" class="post error404 not-found">
<h1 class="posttitle"><?php _e( 'Not Found', THE_LANG ); ?></h1>
<div class="entry">
<p><?php _e( 'Apologies, but no results were found for the requested property archive. Perhaps searching will help find a related post.', THE_LANG ); ?></p>
</div>
</article>
<?php endif; ?>
<div class="nvr-prop-container row">
<?php if( have_posts() ){ ?>
<div class="search-title twelve columns">
<h4><?php _e('Search Result', THE_LANG); ?> (<?php echo $wp_query->post_count; ?>)</h4>
</div>
<?php
$nvr_idnum = 0;
$nvr_typecol = "nvr-prop-col";
$nvr_imgsize = "property-image";
?>
<ul id="nvr-prop-search" class="<?php echo esc_attr( $nvr_typecol ); ?>">
<?php
while ( have_posts() ) : the_post();
$nvr_idnum++;
echo nvr_prop_get_box( $nvr_imgsize, get_the_ID(), 'element columns', $nvr_unit, $nvr_cursymbol, $nvr_curplace );
$nvr_classpf="";
endwhile; // End the loop. Whew.
?>
I then decided to try and sort the results so I created
$sort_properties = new WP_Query(array(
'post_type' => 'properties',
'meta_key' => $nvr_initial.'_price',
'meta_value' => $nvr_price,
'orderby' => 'meta_value_num date',
'order' => 'DESC',
));
<?php /* If there are no posts to display, such as an empty archive page */ ?>
<?php if ( ! have_posts() ) : ?>
<article id="post-0" class="post error404 not-found">
<h1 class="posttitle"><?php _e( 'Not Found', THE_LANG ); ?></h1>
<div class="entry">
<p><?php _e( 'Apologies, but no results were found for the requested property archive. Perhaps searching will help find a related post.', THE_LANG ); ?></p>
</div>
</article>
<?php endif; ?>
<div class="nvr-prop-container row">
<?php if( $sort_properties->have_posts() ){ ?>
<div class="search-title twelve columns">
<h4><?php _e('Search Result', THE_LANG); ?> (<?php echo $wp_query->post_count; ?>)</h4>
</div>
<?php
$nvr_idnum = 0;
$nvr_typecol = "nvr-prop-col";
$nvr_imgsize = "property-image";
?>
<ul id="nvr-prop-search" class="<?php echo esc_attr( $nvr_typecol ); ?>">
<?php
while ( $sort_properties->have_posts() ) : $sort_properties->the_post();
$nvr_idnum++;
echo nvr_prop_get_box( $nvr_imgsize, get_the_ID(), 'element columns', $nvr_unit, $nvr_cursymbol, $nvr_curplace );
$nvr_classpf="";
endwhile; // End the loop. Whew.
?>
Now when I perform a search, the posts are sorted based on price which is fantastic but... now regardless of how I search all of the site posts are now being displayed.
I felt I was so close to finding a solution but I would very much grateful if someone cold advise me with this.
Kind regards
S
Have you tried to order only by the 'meta_val_num' without the 'date' like:
$args = array(
'post_type' => 'product',
'orderby' => 'meta_value_num',
'meta_key' => 'price',
);
$query = new WP_Query( $args );
Code from: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
I think you have to add the Search Parameter and probably use the new meta_query structure:
$search_query = get_search_query();
$sort_properties = new WP_Query(array(
'post_type' => 'properties',
's' => $search_query,
'orderby' => 'meta_value_num',
'meta_query' => array(
'key' => $nvr_initial.'_price',
'value' => $nvr_price,
)
));
I remember having some trouble, not using "meta_query" => array() for multiple conditions.
I am using WordPress in combination with WP Events Organiser. On my index.php, I want to display events and posts in the same loop, but only categories of "startseite" should be displayed either for the events as well as for the posts. At the moment it is working like this:
<?php global $wp_query;
$args = array(
'post_type' => array('post','event'),
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'category',
'terms' => 'startseite',
'field' => 'slug'
),
array(
'taxonomy' => 'event-category',
'terms' => 'startseite',
'field' => 'slug'),
));
query_posts( $args ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
... further on the loop:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="d-1of3" id="post-<?php the_ID(); ?>" <?php post_class( 'cf' ); ?> role="article">
<div class="entry-content">
<h2 class="h2 entry-title"><?php the_title(); ?></h2>
<p class="byline entry-meta vcard">
<?php printf( __( '', 'bonestheme' ).' %1$s',
'<time class="updated entry-time" datetime="' . get_the_time('Y-m-d') . '" itemprop="datePublished">' . get_the_time(get_option('date_format')) . '</time>'
); ?>
</p>
<section class="cf">
<?php the_content(); ?>
<?php echo eo_get_the_start('jS M YY'); ?>
</section>
</div>
<?php the_post_thumbnail( 'large' ); ?>
</article>
<?php endwhile; endif; ?>
Now I would like to display the date of the Event. I have found the following link with an example: http://codex.wp-event-organiser.com/function-eo_get_events.html
But I can't figure out how to change my code just to display the date. AND also it would be great to order the events by the date. Thanks for your help!!
just check the documentation in here.
Basically you add this:
echo eo_get_the_start('jS M YY');
Where you need to show the date.