(check the edit below) Is it possible to sort the post based on a custom field?
I have a custom field called "value_date" where I enteradd a date e e.g yyyy/mm/dd
I used a template for custom post taxonomy-event-date.php and this is code in the function, It doesn't work.
<!-- // The Query // -->
<?php
if( have_posts() ) {
$alt_post = 'alt-post';
while( have_posts() ) {
the_post();
$alt_post = $alt_post == 'alt-post' ? '' : 'alt-post';
?>
<div class="box-page-shows-block">
<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'value_date', true);
wp_reset_query();
?>
</div>
<h2><?php the_title(); ?></h2>
<?php
}
}
?>
EDITFunctions.php Not working only displayed one post Loop in template for custom post taxonomy-event-date.php
<?php
$args = arrayadd_action(
'post_status' => 'publish',
'posts_per_page' => 6,
'paged' => $paged,
'meta_key' => 'value_date',
'orderby' => 'meta_value_num''pre_get_posts',
'order' => 'ASC'
);
$query = new WP_Query( $args 'search_filter');
iffunction search_filter( $query->have_posts() ) {
whileif ( $query->have_posts!is_admin() ) {
&& $query->the_post();?>
<h2><?php the_titleis_tax(); ?></h2>
<?php
}
'event', 'date' ) ) }{
wp_reset_query(); // Restore global post data$today stomped= the_postdate().
'Y-m-d' ?>
Functions.php
add_action('pre_get_posts','search_filter');
function search_filter($query){
if ( !is_admin() && $query->is_tax>set( 'event''post_status', 'date' ) 'publish') {;
$query->set('post_status''meta_value', 'publish'$today);
$query->set('meta_key', 'value_date');
$query->set('orderby', 'meta_value_num');
$query->set('order', 'ASC');
}
}