WordPress.org

Ready to get started?Download WordPress

Forums

Query Custom Fields
hey scribu I still need to sort by Custom Fields can you help? (4 posts)

  1. NPSites
    Member
    Posted 3 years ago #

    I just started putting together an Events Site
    not all of my posts are events but posts are separated in subcategories

    I added a custom field DateStart

    When I am in a category with events I need to sort them by the custom field. I have seen some code to make a custom call similar to what you do in this plugin but it kills post navigation to older posts.

    here is a deeper explanation
    http://wordpress.org/support/topic/index-or-cat-posts-orderby-meta_key-with-page-navigation?replies=1#post-1668121

    Unfortunately with thousands of posts and many dates i can not use taxonomies they are growing too large now in my Database.

    I am just getting started and my taxonomy is reserved for
    Tags: State, City-State, State-EventType
    Categories with children: State/City/EventType
    Each post has at least 10 custom fields.

    10,208 Posts
    1 Page
    151 Categories
    9,075 Tags

    so its a little crazy heheh
    Thanks if you have any ideas >:o)

    http://wordpress.org/extend/plugins/query-custom-fields/

  2. MichaelH
    Member
    Posted 3 years ago #

    Could you use the orderby=meta_value clause with query_posts?

  3. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    After you've registered the DateStart custom field:

    function my_queryable_custom_fields() {
        register_queryable_custom_field( 'DateStart' );
    }
    add_action('init', 'define_queryable_custom_fields');

    You can just go to this URL:

    /category/some-category/?orderby=DateStart

    and it should display sorted posts, even if they don't have a DateStart custom field.

  4. Creatier
    Member
    Posted 3 years ago #

    Hi Scribu,

    First of all, thanks for all the work on WP.
    In the above example, shouldn't the add_action be like:
    add_action('init', 'my_queryable_custom_fields'); instead of define?

    I am looking forward to future versions of the plugin.

    @NPSites: if you only need to sort by ONE custom field than orderby=meta_value can be used without trouble as MichaelH already stated.

    Good luck!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic