custom taxonomy sort order not working

Waqas_aamer

I have created a custom taxonomy named product_categories.

It has three fields :

  1. for banner image

  2. for category image and

  3. for sort order.

I have added 10 categories in it giving its sort order input also.

Now i want to show this in sorting order but it is not working.

In pt-categories input for sort order is this

<tr class="form-field">
<th scope="row" valign="top"><label for="cat_sort_order"><?php _e('Product Sort Order'); ?></label></th>
<td>
    <input id="banner-url" name="term_meta[sort_order]" type="text" style="width: 100%;" value="<?php echo $term_meta['sort_order'] ? $term_meta['sort_order'] : ''; ?>" />
    <span class="description"><?php _e('&nbsp;'); ?></span>
</td>

Saving funtion is this

    function save_product_categories_custom_fields($term_id)
    {
    if (isset($_POST['term_meta'])) {
        $t_id = $term_id;
        $term_meta = get_option("taxonomy_term_$t_id");
        $cat_keys = array_keys($_POST['term_meta']);
        foreach ($cat_keys as $key) {
            if (isset($_POST['term_meta'][$key])) {
                $term_meta[$key] = $_POST['term_meta'][$key];
            }
        }
     //save the option array
        update_option("taxonomy_term_$t_id", $term_meta);
    }
}

Here is the categories called

function getLatestProducts() { 
$args = array(
  'post_status' => 'publish',
  'post_type' => 'products', 
  'posts_per_page' => 12,
  'meta_key'        => '_cus_sort_order',
  'orderby'         => 'meta_value_num', 
  'order' => 'ASC'
);
?>
<?php
                $args = array(
                'orderby' => 'name',
                );
                $terms = get_terms('product_categories', $args);
                foreach($terms as $term) {      
               $prod_meta = get_option("taxonomy_term_".$term->term_id);
                    ?>
                <a href="<?php echo get_term_link($term->slug, 'product_categories') ?>">
                <?php
                    echo '<img src="'.$prod_meta['img'].'" title="" alt=""></a>';    ?>
                </div>
                <div class="product-name">
                <h5>
                <a href="<?php echo get_term_link($term->slug, 'product_categories') ?>">
                <?php echo $term->name;?>
                </a>
                </h5>

It is showing the categories names and images but not in sorted order.

Mehul Gohil

You have a mistake in your code of Categories Called

Corrected Code

function getLatestProducts() { 
    $args = array(
    'post_status' => 'publish',
    'post_type' => 'products', 
    'posts_per_page' => 12,
    'meta_key'        => '_cus_sort_order',
    'orderby'         => 'meta_value_num, name', 
    'order' => 'ASC'
);
            $terms = get_terms('product_categories', $args);
            foreach($terms as $term) {      
           $prod_meta = get_option("taxonomy_term_".$term->term_id);
                ?>
            <a href="<?php echo get_term_link($term->slug, 'product_categories') ?>">
            <?php
                echo '<img src="'.$prod_meta['img'].'" title="" alt=""></a>';    ?>
            </div>
            <div class="product-name">
            <h5>
            <a href="<?php echo get_term_link($term->slug, 'product_categories') ?>">
            <?php echo $term->name;?>
            </a>
            </h5>

I have removed an array of argument which is called after main arguments array. As the below mentioned argument array is overriding the above mentioned arguments array.

Removed Arguments Array

$args = array(
    'orderby' => 'name',
);

Hope this helps!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Woocommerce: order by custom taxonomy

From Dev

How to alphabetically sort custom posts if taxonomy is equals to 'custom_taxonomy'?

From Dev

Sort posts by custom taxonomy and custom field ASC

From Dev

Wordpress - Taxonomy single navigation order by custom field

From Dev

Wordpress - Taxonomy single navigation order by custom field

From Dev

Taxonomy template not working for custom post type

From Dev

Query custom post type with custom field and order ascending by custom taxonomy

From Dev

Prestashop custom admin module draggable sort/order not working

From Dev

Sort taxonomy terms table in the admin by custom sort field

From Dev

Database Custom Sort Order

From Dev

Database Custom Sort Order

From Dev

Taxonomy is not working

From Dev

Custom post type, sort taxonomy terms by a meta box value

From Dev

Wordpress Loop - Show posts from custom taxonomy terms in heirarchical order

From Dev

custom meta field in taxonomy media up loader button no working

From Dev

custom meta field in taxonomy media up loader button no working

From Dev

WP_Query for getting posts under custom taxonomy not working

From Dev

Sort list by a given custom order

From Dev

SSRS Report Custom Sort Order

From Dev

custom sort order on array of objects

From Dev

SQLALchemy custom integer sort order

From Dev

Custom sort order for an enum field

From Dev

Sort array by keys in custom order

From Dev

Sort an array in custom alphabetical order

From Dev

Sort Custom Objects in Specific Order

From Dev

Sort a php array in a custom order

From Dev

custom sort order on array of objects

From Dev

SSRS Report Custom Sort Order

From Dev

Sort JSON based on custom sort order array

Related Related

HotTag

Archive