I am trying to custom sort taxonomies on a custom query I have written for one of my website
I cannot use any custom plugin as I have tried and they do not work with my current setup.
add_action('init', 'ecommerce_create_post_type', 1);
function ecommerce_create_post_type() {
// Create new Latest-News custom post type
$labels = array(
'name' => _x('Products', 'post type general name'),
'singular_name' => _x('Products', 'post type singular name'),
'add_new' => _x('Add New', 'Product'),
'add_new_item' => __('Add New Product'),
'edit_item' => __('Edit Product'),
'new_item' => __('New Products'),
'view_item' => __('View Products'),
'search_items' => __('Search Products'),
'not_found' => __('No Products found'),
'not_found_in_trash' => __('No Products found in Trash'),
'_builtin' => false,
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_ui' => true,
'query_var' => true,
'sort' => true,
'register_meta_box_cb' => 'icom_meta_boxes',
'rewrite' => array(
'slug' => 'products',
'with_front' => false
),
'capability_type' => 'post',
'hierarchical' => true,
'menu_position' => 20,
'supports' => array('title','editor','thumbnail','custom-fields','excerpt'),
'menu_icon' => ICOMMERCE_DIR.'/images/cart.png'
);
register_post_type('products',$args);
// Product categories, is heirarchical and can use permalinks
$labels = array(
'name' => _x( 'Product Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Product Category', 'taxonomy singular name'),
'search_items' => __( 'Search Categories'),
'all_items' => __( 'All Product Categories'),
'parent_item' => __( 'Product Category'),
'parent_item_colon' => __( 'Parent Product Category:'),
'edit_item' => __( 'Edit Product Category'),
'update_item' => __( 'Update Product Category'),
'add_new_item' => __( 'Add New Product Category'),
'new_item_name' => __( 'New Product Category Name')
);
register_taxonomy( 'icomcat', 'products', array(
'rewrite' => array(
'slug' => 'product-category',
'with_front' => false,
'sort' => true,
),
'labels' => $labels,
) );
}
using the following code , I am fetching the latest products
<?php
global $wpdb;
$prefix=$wpdb->prefix;
$latest_products = $wpdb->get_results(
"SELECT a.term_id, a.name
FROM ".$prefix."terms a,".$prefix."term_taxonomy b
WHERE b.parent=".$prodcatid."
and a.term_id=b.term_id
and b.taxonomy='icomcat'
order by a.name desc");
if ( count( $latest_products ) > 0 ) {$count=0;
echo '<div class="clear3"> </div><div class="text12"> <h3> <a> <?php $current_category = single_cat_title("", false); ?></a></h3></div><div class="clear3"> </div><div id="cateogybox">';
foreach ( $latest_products as $latest_product ) { $count=$count+1;
?>
I am trying to sort these results using the date field. as you can see I am firing
$latest_products = $wpdb->get_results(
"SELECT a.term_id, a.name
FROM ".$prefix."terms a,".$prefix."term_taxonomy b
WHERE b.parent=".$prodcatid."
and a.term_id=b.term_id
and b.taxonomy='icomcat'
order by a.name desc");
but my results are not sorted by date.
termsand theterm_taxonomytables only and neither of those have a "date" field nor do you even attempt toORDER BYsuch a field. – s_ha_dum Mar 24 at 18:01