Title: Sort by meta_value_num
Last modified: October 19, 2016

---

# Sort by meta_value_num

 *  [ubertam](https://wordpress.org/support/users/ubertam/)
 * (@ubertam)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/sort-by-meta_value_num-2/)
 * I love this plugin. Thank you for making it. It has made my website very data-
   driven and much, much more automatic than what I usually deal with. I enter one
   post and now I can have data from that post in multiple places. Our use case 
   is this: we’re a law firm, and we post our case results on the Case Results page,
   the Attorney’s info page (for the attorneys on that case), and the Practice Area
   page (for the related practice area). I enter create the case result using a 
   custom post type that integrates Advanced Custom Fields. One of the custom fields
   is “hidden_value” where I type a numeric value of the case.
 * When I try and order by this hidden_value, it sorts alphabetically. 90,000 is
   above 40,000,000 because 9 comes first (in descending order).
 * I’ve made it work by modifying a few things in the plugin manually:
 * Changed references to “meta_value” to “meta_value_num” in the main plugin file.
   
   Changed same reference in wp_options here: s:14:”meta_value_num”
 * This works for what I want it to do. But when the plugin gets updated, I have
   to manually tweak it again.
 * Is there any way this can be updated to add another Order By that is “Custom 
   Field (Num)”?
 * I would be eternally grateful.
 * Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [ubertam](https://wordpress.org/support/users/ubertam/)
 * (@ubertam)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/sort-by-meta_value_num-2/#post-8330719)
 * Supporting custom taxonomies would be extremely awesome, as well. I have taxonomies
   for Case Results called “CR Attorneys” and “CR Practice Areas” so I don’t clutter
   up my “Categories” default taxonomy.
 * I’d be willing to donate $100 to make this happen.
 *  [roelernl](https://wordpress.org/support/users/roelernl/)
 * (@roelernl)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/sort-by-meta_value_num-2/#post-8781828)
 * Did you get it to work yet? Same problem here!
    I don’t have the reference in
   wp_options table?
 *  Thread Starter [ubertam](https://wordpress.org/support/users/ubertam/)
 * (@ubertam)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/sort-by-meta_value_num-2/#post-8782931)
 * I ended up using Flexible Posts Widget instead, and making a custom plugin to
   let me change the sort.
 * FPW lets you create a custom template (I called mine PCVA FPW Case Result, then
   added the file pcva_fpw_case_result.php to my child theme at \Jupiter-child\flexible-
   posts-widget\pcva_fpw_case_result.php). That PHP file declares the layout of 
   the result so I can have minimal information, make it link where I want it to,
   etc. Here is that code:
 *     ```
       <?php
       /**
        * Flexible Posts Widget: Default widget template
        * 
        * @since 3.4.0
        *
        * This template was added to overcome some often-requested changes
        * to the old default template (widget.php).
        */
   
       // Block direct requests
       if ( !defined('ABSPATH') )
       	die('-1');
   
       echo $before_widget;
   
       if ( ! empty( $title ) )
       	echo $before_title . $title . $after_title;
   
       if ( $flexible_posts->have_posts() ):
       ?>
       	<ul class="dpe-flexible-posts custom-field-case_result_list_entry pcva_fpw_attyresult">
       	<?php while ( $flexible_posts->have_posts() ) : $flexible_posts->the_post(); global $post; ?>
       		<li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
       			<a href="<?php echo the_permalink(); ?>">
       				<?php the_field('case_result_list_entry'); ?>
       			</a>
       		</li>
       	<?php endwhile; ?>
       	</ul><!-- .dpe-flexible-posts -->
       <?php	
       endif; // End have_posts()
   
       echo $after_widget;
       ```
   
 * Then, I made the following custom plugin so they would be sorted my way. Note:
   this didn’t make the FPW widget interface give me those options; it just overrode
   whatever setting was there. Here’s that plugin code:
 *     ```
       <?php
       /* Adjust Flexible Posts Widget to order by meta_key */
   
       add_filter( 'dpe_fpw_args', 'pcva_fpw_sortmeta' );
   
       function pcva_fpw_sortmeta($query) {
       	$query['meta_key'] = 'hidden_sort_value';
       	$query['orderby'] = 'meta_value_num';
       	return $query;
   
       }
       ```
   
 * FPW already does custom taxonomies, so it had less to tweak to get this to work.
 * Good luck!
 *  [roelernl](https://wordpress.org/support/users/roelernl/)
 * (@roelernl)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/sort-by-meta_value_num-2/#post-8784732)
 * Wow, really thank you a lot for taking the time on this reply! This will defenitely
   work for me!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Sort by meta_value_num’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/ultimate-posts-widget_5b9f2b.svg)
 * [Ultimate Posts Widget](https://wordpress.org/plugins/ultimate-posts-widget/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ultimate-posts-widget/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ultimate-posts-widget/)
 * [Active Topics](https://wordpress.org/support/plugin/ultimate-posts-widget/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ultimate-posts-widget/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ultimate-posts-widget/reviews/)

## Tags

 * [meta_value)](https://wordpress.org/support/topic-tag/meta_value/)
 * [meta_value_num](https://wordpress.org/support/topic-tag/meta_value_num/)
 * [order](https://wordpress.org/support/topic-tag/order/)

 * 4 replies
 * 2 participants
 * Last reply from: [roelernl](https://wordpress.org/support/users/roelernl/)
 * Last activity: [9 years, 6 months ago](https://wordpress.org/support/topic/sort-by-meta_value_num-2/#post-8784732)
 * Status: not resolved