- 7 Tem 2013
- 8,265
- 4
- 749
Postorder by custom field /WordPress
If you want to make posts order by custom field use the below code.
priority = Custom Field name
and
If you want to make posts order by custom field use the below code.
priority = Custom Field name
Kod:
global $wp_query;
function priority_select($sql){
global $wpdb;
if (strpos($sql, proirity) !== false){
$sql = str_replace(ORDER BY {$wpdb->post****}.****_key, ORDER BY CAST({$wpdb->post****}.****_key AS UNSIGNED), $sql);
}
return $sql;
}
and
Kod:
add_filter(query, priority_select);
query_posts( array_merge(array(****_key => proirity, orderby=> ****_value, order => asc), $wp_query->query));
// loop code
wp_reset_query();