• Skip to main content

Victor Font Consulting Group, LLC

The DEX Intranet Specialists

Call Us:

+1 919-604-5828

  • Home
  • Care Plans
    • Care Articles
    • Optional Subscriptions
  • Consultations
  • Products
    • Code Snippets
    • Public GitHub Repositories
    • Gist Snippets
    • Pastebin Snippets (Free)
    • Free Plugins
  • FAQs
  • Support
    • Graphic Design
  • Contact
    • Speakers
    • Portfolio
  • Resources
    • Free WordPress Video Training
    • Tutorials
    • Articles
    • Cybersecurity
    • EU Referral Network
You are here: Home / Code Snippet / Sorting Custom Post Types

Sorting Custom Post Types

By Victor M. Font Jr.
July 3, 20155 Comments

VictorFont.com Portfolio pageThis site's Website Portfolio page displays portfolio custom post types. Actually, I borrowed the portfolio code from the Genesis Executive Pro theme and customized it to work with the Parallax Pro theme that we use on this site. While copying the php code, CSS, and templates from the Executive Pro theme is a pretty straight forward affair, I wanted the portfolio custom post types to be ordered alphabetically instead of the WordPress default reverse chronological order. To achieve this effect, I added the following code to the theme's functions.php file:

//* Sort the portfolio thumbnails alphabetically
add_filter("posts_orderby", "vmf_orderby_filter", 10, 2);

function vmf_orderby_filter($orderby, &$query){
    global $wpdb;
    //figure out whether you want to change the order
    if (get_query_var("post_type") == "portfolio") {
         return "$wpdb->posts.post_title ASC";
    }
    return $orderby;
 }
  • 0share
  • Facebook0
  • Twitter0
  • Pinterest0
  • LinkedIn0
  • Print
  • SMS0

About Victor M. Font Jr.

Victor M. Font Jr. is an award winning author, entrepreneur, and Senior IT Executive. A Founding Board Member of the North Carolina Executive Roundtable, he has served on the Board of Advisors, of the North Carolina Technology Association, the International Institute of Business Analysis, Association of Information Technology Professionals, Toastmasters International, and the North Carolina Commission for Mental Health, Developmental Disabilities, and Substance Abuse Services. He is author of several books including The Ultimate Guide to the SDLC and Winning With WordPress Basics, and Cybersecurity.

Reader Interactions

VictorFont.com runs on the Genesis Framework

Genesis FrameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Genesis provides the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Check out the incredible features and the selection of designs. It's that simple—start using Genesis now!

Click here to download The Genesis Guide for Absolute Beginners (PDF - 1.4 MB)

Leave a Reply Cancel reply

Your email address and website will not be published. Required fields are marked *
Posting a comment means that you agree with and accept our Comment & Product Review Policy

Comments

  1. Thomas Chang

    September 7, 2016 at 3:57 am

    Hi Victor,
    Very nice tutorial.
    Could you also share your code for this portfolio template, so that I can have a better idea of how it is generated ?

    Thanks,
    Thomas

    Reply
    • Victor M. Font Jr.

      September 7, 2016 at 7:57 am

      Thomas, the portfolio template code is from a child theme built for the Genesis Framework. The portfolio is available in many of the Studio Press themes. If you are not using the Genesis Framework, sharing code won’t be of any use to you.

      Reply
      • tianlong8bu

        September 7, 2016 at 10:54 am

        Yes, I’m using the Framework. Being new to Genesis, it is a headache for me to create the template file.

        Reply
        • Victor M. Font Jr.

          September 7, 2016 at 11:21 am

          Thomas,

          Did you purchase just one child template or the full suite of templates. Executive Pro has a template you can copy. Actually, there are three template files for the portfolio and code in functions.php and styles.css. It’s a lot more than a single template.

          Reply
          • tianlong8bu

            September 7, 2016 at 8:48 pm

            Hello Victor,

            Thank you so much for your guidance.

Call: +1 919-604-5828

Send us an E-mail

Accessibility Statement | Affiliate Marketing Disclosure | Capability Statement

Cookie Policy | Comment & Product Review Policy | Privacy Policy | Site Map | Terms & Conditions

Copyright © 2003–2023 Victor M. Font Jr.

Return to top of page