I use the property "pages" for the number of pages of an article or book.

There are two problems.


If I use C-c ^ to sort the items by the value of pages org-sort seems to interpret the numbers lexicographically: 1<100<20<3. Of course I need the natural order of numbers: 1<3<20<100.


If I use C-c a m to search for items with pages<20 I get the correct items and the "wrong" items: where the pages property is not defined. How to ignore the "wrong" items?

1 Answer 1


For the first problem, you have to use a function like this:

#+BEGIN_SRC emacs-lisp
(defun sort-by-pages ()
 (string-to-number (org-entry-get nil "pages")))

then type C-c ^ f and select the function sort-by-pages. The problem is properties in org-mode are strings, and you need this to convert them to numbers.

For problem two try: pages<20+pages<>"" the second one should eliminate the nulls.

  • Thanks, this solves both problems. But for the first one. Can I make the function more general?: With one argument, the name of the numerical property, for example "pages". (I have more than one numerical property. It's not good to define a new function for every new numerical property.)
    – rl1
    Commented Apr 23, 2017 at 21:04
  • 1
    I don't think you can do that. I am pretty sure no arguments are allowed. Commented Apr 23, 2017 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.