Home Forums Plugin Support WP User Frontend Pro Order by custom date field

This topic is: not resolved

This topic contains 6 replies, has 2 voices, and was last updated by  towhid 3 years, 11 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #46203

    Chili it
    Member
    Post count: 9

    Hello,

    I have problem with order posts added by WP Frontend PRO.

    I created page tamplates with this code:
    ….

     $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
      $query_args = array(
       'meta_key' => 'dok_adna_data_wydarzenia_', // name of custom field
       'orderby' => 'meta_value_num',
       'order' => 'DESC',
       'paged' => $paged,
        'offset'     =>  $offset,
       'posts_per_page' => 20,
       'cat' => '435'
      
        );
      $the_query = new WP_Query( $query_args );

    ….

    But i have problem . This code sorts by day, does not include the month. For example: April 20, April 15, June 10, July 5.

    Any idea how to fix it?

    #46468

    Chili it
    Member
    Post count: 9

    I found “problem”.

    In form date format is: dd/mm/yy. So WordPress sort by “dd”. Now i change for mm/dd/yy, but now is other problem. In my country displaying: mm/dd/yy is “not normal”. Normal is: dd/mm/yy. How to change displaying date from: mm/dd/yy to: dd/mm/yy ?

    #46473

    towhid
    Participant
    Post count: 4505

    Hello Chili,

    Where you put the code? In your theme? or plugin?

    Can I get a screenshot of the output after put the code.

    Thanks

    #46484

    Chili it
    Member
    Post count: 9

    I put in page template(i created it).

    The code:

    <?php
    
    /*
    Template Name: Kalendarium
    */
    
    global $gk_tpl;
    
    /*$args = array(
       'meta_key' => 'dok_adna_data_wydarzenia_', // name of custom field
       'orderby' => 'meta_value_num',
       'order' => 'DESC',
       'paged' => $paged,
        'offset'     =>  $offset,
       'posts_per_page' => 5,
       'cat' => '435'
    
    );
    $event_query = new WP_Query( $args );*/
    
     $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
      $query_args = array(
       'meta_key' => 'dok_adna_data_wydarzenia_', // name of custom field
       'orderby' => 'meta_value',
       'order' => 'DESC',
       'paged' => $paged,
        'offset'     =>  $offset,
       'posts_per_page' => 20,
       'cat' => '435'
      
        );
      $the_query = new WP_Query( $query_args );
    (...)
    <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); // run the loop ?>
      <article style="width:100%;margin-bottom:20px;border-bottom:3px solid #eee;">
       <div style="float:left;width:30%;"><a href="<?php echo get_permalink(); ?>"><?php the_post_thumbnail( 'whatson-thumb' ); ?></a></div>
        <div style="float:right;width:65%;margin-left:2%;"><h2><a href="<?php echo get_permalink(); ?>"><?php echo the_title(); ?></a></h2>
        <div class="excerpt">
          <?php the_excerpt(); ?>
    	  <p style="font-weight:700;">Płatność za wydarzenie: <?php echo get_post_meta( $post->ID, 'p_atno___za_wydarzenie', true ); ?></p>
    	  <p style="font-weight:700;">Data wydarzenia: <?php echo get_post_meta( $post->ID, 'dok_adna_data_wydarzenia_', true ); ?></p>
    	  <a href="<?php echo get_permalink(); ?>" style="display:inline;"><button style="float:right;">Czytaj więcej</button></a>
        </div></div>
      </article>
    <?php endwhile; ?>
    (...)
    
    

    Website link: http://chiliit-vps.ogicom.pl/radio5-kalendarium/
    (Now some “posts” have diffrent data-format. I know it. I need to change it).
    I need solution. To sort by “dok_adna_data_wydarzenia_”(date).
    2 solutions for me:
    1. Set mm/dd/yy in back-end and change it for dd/mm/yy on front-end(only display).
    2. Or set dd/mm/yy in back-end and sort correctly by date.

    #46497

    towhid
    Participant
    Post count: 4505

    Did you put this code in theme's functions.php file?

    #46500

    Chili it
    Member
    Post count: 9

    No. I created MY PAGE-TEMPLATE(like CONTACT PAGE TEMPLATE, GALLERY PAGE TEMPLATE etc..). I add Page Template in (Back-End Menu)->Pages->Title of Page(edit)->Page atributtes->Templates->MY PAGE-TEMPLATE(here: Kalendarium).

    This code which i pasted is only FRAGMENT from MY PAGE-TEMPLATE. This “(…)” in code mean: “much irrelevant to the case code, which made it difficult only to read everything.”

    #52001

    towhid
    Participant
    Post count: 4505

    Hello Chill,

    The code you provide to me is not complete and meaningful. Can you please send me the template file. I will check it and let you know the result.

    Thanks

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Order by custom date field’ is closed to new replies.