• Resolved 10rous

    (@10rous)


    Hi there

    I need to display custom type posts creatd via plugin sorted by date, asc
    I’ve tried to use sort ($fecha) but It didn’t work, can anyone help me with this

    here the php code for the page template

    <?php
    
    	  // The Loop
    	  while ( $query->have_posts() ) : $query->the_post();
    	  $fecha = get_post_meta($post->ID, "fecha", true);
    	  $fecha_tmp = explode("/",$fecha);
    	  $fecha_format = (int)($fecha_tmp[2] . $fecha_tmp[0] . $fecha_tmp[1]);
    	  if ($fecha_format >= $fecha_actual) {
    	  ?>
    	  <p class="main-blog8leftcontent"><span><strong><?php echo  date("d/m/Y", strtotime(get_post_meta($post->ID, "fecha", true))) ?> <?php echo  get_post_meta($post->ID, "lugar", true) ?></strong></span> <span><?php the_title() ?></span> <span><a href="<?php echo anyade_http(get_post_meta($post->ID, "link", true)) ?>"><?php _e("més informació") ?></a></span></p>
    	  <?php
    	    };
    	  endwhile;
    	  // Reset Post Data
              wp_reset_postdata();
    	?>

    thanks in advance

Viewing 1 replies (of 1 total)
  • Thread Starter 10rous

    (@10rous)

    REsolved

    <?php
    /*
    Template Name: ferias
    */
    ?>
    <?php get_header(); ?>
    <?php
      $query = new WP_Query(array(
    			      'post_type' =>'fre_firas',
    			      'post_status'=> 'publish',
        				'meta_key' => 'fecha',
        				'orderby' => 'meta_value_num',
        				'order' => 'ASC',
    			      ));
    
      $query2 = new WP_Query(array(
    			      'post_type' =>'fre_firas',
    			      'post_status'=> 'publish',
        				'meta_key' => 'fecha',
        				'orderby' => 'meta_value_num',
        				'order' => 'ASC',
    			      ));
      $fecha_actual = (int)(date('Y') . date('m') . date('d'));
    ?>
    
    <?php
    
    	  // The Loop
    	  while ( $query->have_posts() ) : $query->the_post();
    	  $fecha = get_post_meta($post->ID, "fecha", true);
    	  $fecha_tmp = explode("/",$fecha);
    	  $fecha_format = (int)($fecha_tmp[2] . $fecha_tmp[0] . $fecha_tmp[1]);
    	  if ($fecha_format >= $fecha_actual) {
    	  ?>
    	  <p class="main-blog8leftcontent"><span><strong><?php echo  date("d/m/Y", strtotime(get_post_meta($post->ID, "fecha", true))) ?> <?php echo  get_post_meta($post->ID, "lugar", true) ?></strong></span> <span><?php the_title() ?></span> <span><a href="<?php echo anyade_http(get_post_meta($post->ID, "link", true)) ?>"><?php _e("més informació") ?></a></span></p>
    	  <?php
    	    };
    	  endwhile;
    	  // Reset Post Data
              wp_reset_postdata();
    	?>
Viewing 1 replies (of 1 total)

The topic ‘sort custom type posts by date, php’ is closed to new replies.