I fixed this by adding:
global $post;
More specific: I can’t explain why this works, that’s beyond my WordPress skills, but I added it right after the start of the query, so the code looks like this:
<?php global $post;
$loop = new WP_Query( array(
'post_type' => 'kurs',
'posts_per_page' => '5',
'meta_key' => 'dato',
'meta_value' => date('Y-m-d'),
'meta_compare' => '>=',
'orderby' => 'meta_value',
'order' => 'ASC'
) ); ?>
Related Posts:
- Widget: Custom Post Type Post Listing Dropdown on Admin Side
- Where to put my code: plugin or functions.php?
- Query all posts where a meta key does not exist
- Can the Next/Prev Post links be ordered by menu order or by a meta key?
- what is the correct way to compare dates in a WP query_posts meta_query
- Advanced search form with filters for custom taxonomies and custom fields
- Meta query with boolean true/false value
- Get post with multiple meta keys and value
- Correctly delete posts with meta and attachments [duplicate]
- Custom Post Type Data in Sidebar widgets?
- Storing revisions of metadata for custom post type
- Custom field values deleted when trashing custom post type
- How to get all custom fields of any post type
- Update CPT meta data using REST API
- Admin Area Custom Type Search By Meta Fields Without Title & Content
- Echo all meta keys of a custom-post TYPE
- Custom Post type – how to get checkbox to update meta field to null
- How can I filter posts by post_parent in the admin?
- How do I Paginate Search Results for Custom Post Types?
- Including Custom Post Types in “Recent Posts” Widget
- Ordering posts having multiple post-meta date fields
- Custom Post Type with Input fields to seperate table on database.
- Limit widget to a specific registered sidebar
- How do I remove all the metaboxes for a custom post type?
- Custom Queries: Joining On Meta Values From Two Custom Post Types
- Gutenberg how to make attribute to save to meta
- How to programmatically create a connection with [Plugin: Posts 2 Posts] on cpt publish?
- Post metadata deletes itself
- How to create a mini directory in WordPress?
- How Can I save multiple records in same meta key?
- Get all posts from custom post type and insert in select input as metabox
- Detect meta value changes when post is updated (post_updated)
- Search everything (posts, pages, tags, cpt, meta)
- Include custom post types in categories widget
- Permalinks using event date (year & month) instead of publication date
- Custom Post Type: Set post_title equal to a custom post type field
- I can’t set meta_key in my custom post type query
- Grossly inefficient wordpress loops!
- Compare 3 custom fields and sort by oldest
- Including a custom post type in the Archives widget
- How Do I Use WP_Query to Run This Database Query as Search Result?
- WordPress Admin Panel search posts with custom post meta values along with title
- Creating a custom post type upon registration
- How to Update post status using meta data in Custom post TYpe
- Rest Api v2 orderby meta_key in custom post type
- bulk Update post_meta with default values
- Reason action hook won’t work with update_post_meta from frontend form? Alternative?
- Can’t sort order of wp_query with 2 meta keys
- Showing Meta Data for Custom Post Types?
- How to get source of custom meta image?
- Having trouble with custom post type / meta box
- Query for posts from any post type but only add instock products
- How can I include meta box content when searching?
- update a post meta from a single table cell TablePress
- update custom post type meta from a shortcode
- How to embed form data within the ‘Add new post’
- Custom Meta Boxes – Nonce Issue – Move to trash issue
- Displaying Meta Box Image
- Custom post type category not displaying in custom post type
- How to make custom post meta wp_editor translatable?
- Automatically adding meta data to posts or multiple query help
- How to keep a check box in custom meta box for custom post type checked by default for add new post?
- How to add multiple featured image in meta box in post editor?
- Show metabox in custom-post-template depending on taxonomy term?
- ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
- update_post_meta() whenever custom post type is updated
- Formatting custom meta box date from YYYY/MM/DD to a more readable alternative
- Trigger “unsaved changes” dialog for custom post meta changes
- Using date stored as custom field to filter posts displayed in admin
- Conditionally Query Custom Post Types by Post Meta for Blog Home Page?
- Displaying custom posts only if custom meta box’s date is not expired
- Displaying Metabox value (custom post type taxonomy)
- How do I sort a custom post type admin column using two meta keys?
- Add Post Url to Manage Edit Screen
- Add custom post types stats to a custom dashboard widget
- How to create another version of the Category widget?
- ‘Pages’ widget alternative for custom post types?
- Including Custom Post Type posts in a page template contextually (or should I widget?)
- How to best delete orphan wp_postmeta
- How can I display my custom metaboxes on a custom post template?
- Display all custom post type posts and order them by an optional meta_key
- Meta Box Only in CPT Edit Page, Not in Add New
- get_post_meta is returning image id
- Custom Post Type, Saving Multiple Checkboxes
- get_template_part() – post-meta not working?
- How can I get_post_meta() in the most efficient way?
- need advice on how to do a lists using custom post types – taxonomy vs postmeta
- Count posts with specific term_meta
- Custom search for custom post meta with pre_get_posts interferes with WP search
- Create a random unique 6 digit number as custom field for custom post type
- Export entries and multiple custom field meta to .csv?
- how to interconnect custom post types?
- WordPress Orderby Numeric Value Not Working
- Custom Post Status Transition Issues With Get Post Meta
- Replace title column in post list with post meta value
- right_now_content_table_end function not working?
- Metadata for a taxonomy – is there any WordPress way of doing this?
- My theme saves their custom post type’s metadata as a serialized array, how to access the keys?
- List all images from a single post meta value
- Does WordPress limit the length of slug names for Post Meta or Terms?