{"id":4335533,"date":"2013-11-20T11:11:31","date_gmt":"2013-11-20T11:11:31","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/sort-custom-type-posts-by-date-php\/"},"modified":"2016-08-21T12:45:02","modified_gmt":"2016-08-21T12:45:02","slug":"sort-custom-type-posts-by-date-php","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/sort-custom-type-posts-by-date-php\/","title":{"rendered":"sort custom type posts by date, php"},"content":{"rendered":"<p>Hi there<\/p>\n<p>I need to display custom type posts creatd via plugin sorted by date, asc<br \/>\nI&#8217;ve tried to use <code>sort ($fecha)<\/code> but It didn&#8217;t work, can anyone help me with this<\/p>\n<p>here the php code for the page template<\/p>\n<pre><code>&lt;?php\n\n\t  \/\/ The Loop\n\t  while ( $query-&gt;have_posts() ) : $query-&gt;the_post();\n\t  $fecha = get_post_meta($post-&gt;ID, &quot;fecha&quot;, true);\n\t  $fecha_tmp = explode(&quot;\/&quot;,$fecha);\n\t  $fecha_format = (int)($fecha_tmp[2] . $fecha_tmp[0] . $fecha_tmp[1]);\n\t  if ($fecha_format &gt;= $fecha_actual) {\n\t  ?&gt;\n\t  &lt;p class=&quot;main-blog8leftcontent&quot;&gt;&lt;span&gt;&lt;strong&gt;&lt;?php echo  date(&quot;d\/m\/Y&quot;, strtotime(get_post_meta($post-&gt;ID, &quot;fecha&quot;, true))) ?&gt; &lt;?php echo  get_post_meta($post-&gt;ID, &quot;lugar&quot;, true) ?&gt;&lt;\/strong&gt;&lt;\/span&gt; &lt;span&gt;&lt;?php the_title() ?&gt;&lt;\/span&gt; &lt;span&gt;&lt;a href=&quot;&lt;?php echo anyade_http(get_post_meta($post-&gt;ID, &quot;link&quot;, true)) ?&gt;&quot;&gt;&lt;?php _e(&quot;m\u00e9s informaci\u00f3&quot;) ?&gt;&lt;\/a&gt;&lt;\/span&gt;&lt;\/p&gt;\n\t  &lt;?php\n\t    };\n\t  endwhile;\n\t  \/\/ Reset Post Data\n          wp_reset_postdata();\n\t?&gt;<\/code><\/pre>\n<p>thanks in advance<\/p>\n","protected":false},"template":"","class_list":["post-4335533","topic","type-topic","status-closed","hentry","topic-tag-custom-type","topic-tag-php","topic-tag-sort"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/4335533","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/4335533\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=4335533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}