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

  • SEARCH
  • Home
  • 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 8792679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:00:49+00:00 2026-06-13T23:00:49+00:00

I have made a post type, events, that use a custom field, Datum (Swedish

  • 0

I have made a post type, “events”, that use a custom field, “Datum” (Swedish for date). I want the default view for this post type to be sorted by this field.

So far I got:

 register_post_type(
                'events',
                array(
                        'labels' => array(
                                'name' => __( 'Arrangemang' ),
                                'singular_name' => __( 'Arrangemang' )
                        ),
                        'supports' => array(
                                'title',
                                'editor',
                                'custom-fields'
                        ),
                        'public' => true,
                        'has_archive' => true,
                        'query_var' => array(
                                'post_type' => 'events',
                                'meta_key' => 'Datum',
                                'orderby' => 'meta_value',
                                'order' => 'ASC',
                        ),
                )
        );

But the ordering doesn’t work. If I on the archive page for events run print_r($wp_query->query_vars); I get:

Array
(
    [post_type] => events
    [error] =>
    [m] => 0
    [p] => 0
    [post_parent] =>
    [subpost] =>
    [subpost_id] =>
    [attachment] =>
    [attachment_id] => 0
    [name] =>
    [static] =>
    [pagename] =>
    [page_id] => 0
    [second] =>
    [minute] =>
    [hour] =>
    [day] => 0
    [monthnum] => 0
    [year] => 0
    [w] => 0
    [category_name] =>
    [tag] =>
    [cat] =>
    [tag_id] =>
    [author_name] =>
    [feed] =>
    [tb] =>
    [paged] => 0
    [comments_popup] =>
    [meta_key] =>
    [meta_value] =>
    [preview] =>
    [s] =>
    [sentence] =>
    [fields] =>
    [category__in] => Array
        (
        )

    [category__not_in] => Array
        (
        )

    [category__and] => Array
        (
        )

    [post__in] => Array
        (
        )

    [post__not_in] => Array
        (
        )

    [tag__in] => Array
        (
        )

    [tag__not_in] => Array
        (
        )

    [tag__and] => Array
        (
        )

    [tag_slug__in] => Array
        (
        )

    [tag_slug__and] => Array
        (
        )

    [meta_query] => Array
        (
        )

    [ignore_sticky_posts] =>
    [suppress_filters] =>
    [cache_results] => 1
    [update_post_term_cache] => 1
    [update_post_meta_cache] => 1
    [posts_per_page] => 100
    [nopaging] =>
    [comments_per_page] => 50
    [no_found_rows] =>
    [order] => DESC
    [orderby] => wp_posts.post_date DESC
)

Have I misunderstood the argument query_var for register_post_type, or why isn’t is sorting the list as I asked for?

  • 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-13T23:00:50+00:00Added an answer on June 13, 2026 at 11:00 pm

    I tried modifying the archive page, but that just ended up quering the posts twice, so I hooked up the “parse_query” to add the order by info if the query was the right one.

    I may need to define the right one better later, but right now it works fine, and the query is running just once.

    add_action('parse_request', 'event_sort');
    
    function event_sort($a)
    {
       if($a->query_vars AND count($a->query_vars) == 1 AND $a->query_vars['post_type'] == 'events')
       {
          $a->query_vars['meta_key'] = 'Datum';
          $a->query_vars['orderby'] = 'meta_value';
          $a->query_vars['order'] = 'ASC';
       }
    }
    

    Before I found parse_request I used parse_query:

    add_action('parse_query', 'event_sort');
    
    function event_sort($a)
    {
       if($a->query AND count($a->query) == 1 AND $a->query['post_type'] == 'events')
       {
          global $wp_query;
          $wp_query->set('meta_key', 'Datum');
          $wp_query->set('orderby', 'meta_value');
          $wp_query->set('order', 'ASC');
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok I have made my custom post type and they work fine(code shown below).
i have a form (made through codeigniter) that i want to submit with ajax
I have made a form validation using ajax post method. But i got the
Post-release, I have made one small change to one form in our development site
As another post I've made noted, I don't have much experience with jQuery, and
I have made a jQuery toggle for a menu that I had in mind.
I have made a code that read data from flash Nand (without filesystem). fd
I have made this function, that seems to work fine, but it return #
I have a CListView that uses ajaxLink() in the _view file. View (index.php) <?php
Let's say I have the following jQuery AJAX call: $.ajax({ type: POST, url: MyUrl,

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.