Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8690553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:55:33+00:00 2026-06-12T23:55:33+00:00

I have added custom fields in products table in magento. I want to sort

  • 0

I have added custom fields in products table in magento. I want to sort use that custom field but it won’t. I don’t know what is the issue?.

    $_cproduct = Mage::getmodel('catalog/product');
    $_productCollection = $_cproduct->getCollection();
    $_productCollection->addAttributeToSelect('name')->addAttributeToSelect('expired')->addAttributeToSelect('dealcategory')->addAttributeToSelect('dealcity')->addAttributeToSelect('deal_position')->addAttributeToSelect('special_to_date')->addAttributeToSelect('title')->setStore(Mage::app()->getStore()->getId())->addStoreFilter(Mage::app()->getStore()->getId())->addAttributeToSort('entity_id', 'DESC')->addAttributeToSort('dealcategory', 'DESC');
    $_productCollection->addAttributeToFilter('status', 1)->addAttributeToFilter('expired', 0);


$_productCollection->addAttributeToFilter('dealcategory', array('in' => array(129, 135, 136, 137, 141, 156, 205)));


    $now = Mage::getModel('core/date')->timestamp(time());
    $dateStart = date('Y-m-d' . ' 00:00:00', $now);    

    $_productCollection->addFieldToFilter('special_to_date', array('from' => $dateStart));
    $dealcity = Mage::app()->getRequest()->getParam('dealcity', false);
    $_productCollection->addAttributeToSort('deal_position', 'ASC');


    echo "<pre>";
    print_r($_productCollection->getData());
    echo "</pre>";

But every time I got unusual order like below, I want ot sort based on “deal_position“

Array
(
    [0] => Array
        (
            [entity_id] => 2568
            [entity_type_id] => 10
            [attribute_set_id] => 9
            [type_id] => virtual
            [sku] => comedybar7/2/12
            [created_at] => 2012-07-02 18:36:22
            [updated_at] => 2012-10-16 09:52:41
            [has_options] => 0
            [required_options] => 0
            [dealcategory_value] => Side travel deal
            [status] => 1
            [expired] => 0
            [dealcategory] => 135
            [special_to_date] => 2012-10-25 00:00:00
            [deal_position] => 4
        )

    [1] => Array
        (
            [entity_id] => 2566
            [entity_type_id] => 10
            [attribute_set_id] => 9
            [type_id] => virtual
            [sku] => livingwellfinal
            [created_at] => 2012-06-28 14:48:34
            [updated_at] => 2012-10-16 09:51:58
            [has_options] => 0
            [required_options] => 0
            [dealcategory_value] => Side Deal
            [status] => 1
            [expired] => 0
            [dealcategory] => 129
            [special_to_date] => 2012-11-30 00:00:00
            [deal_position] => 1
        )

    [2] => Array
        (
            [entity_id] => 2565
            [entity_type_id] => 10
            [attribute_set_id] => 9
            [type_id] => simple
            [sku] => laser-toenail-10-toes
            [created_at] => 2012-06-27 21:10:19
            [updated_at] => 2012-10-16 09:52:23
            [has_options] => 0
            [required_options] => 0
            [dealcategory_value] => Side Deal
            [status] => 1
            [expired] => 0
            [dealcategory] => 129
            [special_to_date] => 2012-11-30 00:00:00
            [deal_position] => 3
        )

    [3] => Array
        (
            [entity_id] => 2564
            [entity_type_id] => 10
            [attribute_set_id] => 9
            [type_id] => simple
            [sku] => laser-toenail-5-toes
            [created_at] => 2012-06-27 21:10:19
            [updated_at] => 2012-10-16 09:52:10
            [has_options] => 0
            [required_options] => 0
            [dealcategory_value] => Side Deal
            [status] => 1
            [expired] => 0
            [dealcategory] => 129
            [special_to_date] => 2012-12-31 00:00:00
            [deal_position] => 2
        )

)

I used addOrder() that also returns the same output. What is the issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:55:35+00:00Added an answer on June 12, 2026 at 11:55 pm

    It seems you’ve got lost in your own code. You’ve added 3! sorts in your code:

    line3: ...->addAttributeToSort('entity_id', 'DESC')->addAttributeToSort('dealcategory', 'DESC');
    line10: $_productCollection->addAttributeToSort('deal_position', 'ASC');
    

    Make sure you have only sort that you need. Also, do not use addAttributeToSelect multiple times, use it once, but pass an array as an argument:

    $_productCollection->addAttributeToSelect(array('name', 'expired', ...));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to magento. I have added two text fileds(custom options) for products
I have a custom comment app but also want to use the original Comment
I have a CMS app that allows custom fields to be added. One type
I have a custom list, and I've added a 'Page Image' field by clicking
I have a default ListView that i have added my custom views for the
can anybody help me with this ? I have added some custom fields to
I have added an index on a table just to ensure that a set
I want to add one new custom field to one page checkout in Magento.
I have modified the WIT for a bug and added 2 custom fields, i.e.
I have a form with multiple fields that I'm validating (some with methods added

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.