我正在尝试对我为我的一个网站编写的自定义查询进行自定义分类
我无法使用任何自定义插件,因为我已经尝试过了,它们不适用于我当前的设置。
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,
) );
}
使用以下代码,我获取最新的产品
<?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;
?>
我正在尝试使用日期字段对这些结果进行排序。正如你所见,我正在开火
$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");
但我的结果不是按日期排序的。