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
- Query all posts where a meta key does not exist
- Correctly delete posts with meta and attachments [duplicate]
- Storing revisions of metadata for custom post type
- Admin Area Custom Type Search By Meta Fields Without Title & Content
- How can I filter posts by post_parent in the admin?
- Including Custom Post Types in “Recent Posts” Widget
- Custom Post Type with Input fields to seperate table on database.
- How to create a mini directory in WordPress?
- How Can I save multiple records in same meta key?
- Detect meta value changes when post is updated (post_updated)
- Search everything (posts, pages, tags, cpt, meta)
- Permalinks using event date (year & month) instead of publication date
- Compare 3 custom fields and sort by oldest
- Creating a custom post type upon registration
- 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
- update custom post type meta from a shortcode
- Custom Meta Boxes – Nonce Issue – Move to trash issue
- Displaying Meta Box Image
- How to keep a check box in custom meta box for custom post type checked by default for add new post?
- Show metabox in custom-post-template depending on taxonomy term?
- Using date stored as custom field to filter posts displayed in admin
- How to create another version of the Category widget?
- Meta Box Only in CPT Edit Page, Not in Add New
- get_post_meta is returning image id
- get_template_part() – post-meta not working?
- Metadata for a taxonomy – is there any WordPress way of doing this?
- Populate Custom Fields in a Custom Post Type?
- Update CPT post meta with update_post_meta and cron job
- Custom meta box data array: foreach not working correctly?
- How to create Blog Post Specific Widget
- How to check if user meta field is empty in conditional else statement
- Get posts between custom dates
- Custom page sidebar using Template dropdown box
- A better way to add a meta box to custom post types
- Should wp_postmeta meta_key always be unique for a given post_id?
- How do I set all of a particular post meta to a value within the custom post type I’m in?
- Storing a many to many post type relationship in post meta and keeping SQL ability for Joins
- Want to be able to sign up subscribers as authors
- Can’t publish custom post type – “You are not allowed to edit this post.”
- Filter date from post meta when date is in string format
- Get only used meta_values
- the_post_thumbnail call removing li in code
- Is there a way to exclude posts based on meta_values?
- Submitting Custom Post Types with custom fields from Front-end form
- Get $post->ID from a URL
- Displaying a div from an assigned meta_value when on a page
- Setting Post Title via Meta Data returns Auto-draft
- Publish and save specific postmeta to a filtered post_type
- Custom post type suddenly stoped working after WordPress 5 update
- Batch Extract Date from post title and put into ACF custom field
- How to show custom field on specific custom post type posts only when filled
- How to handle this specific case of custom post type?
- Save CTP post meta different values each day without overwriting previous values
- Methods for development wordpress themes [closed]
- is_main_query() never called on WP 4.4
- Related posts meta_query CPT
- Meta box with front-end styling
- Sanitaizing Select Optin For Custom Post Type Metabox in WP
- Cannot Save MetaBox Data in Custom Post Type
- Getting WordPress to store 0 values for custom post type meta
- Say I have a tech blog, how best would I store technical specs for a phone, if i use custom post types
- Hide title field of selected post-types on edit pages
- Replace Content of Sidebar on Custom Post Type
- Save data is post using php front end
- How to keep custom post type related information
- Can’t save meta box data in WordPress using custom post types
- Creating a custom post type upon registration for a specific user role
- How to sort by multiple values in a nested WP_Query
- Where is get_post_meta value located?
- How can I use a custom template to load custom post type posts based on a post_meta value
- How do I create a customised table list of a custom post type (in the admin area)?
- How to properly get the wp_postmeta.meta_value of a custom post type in specifics?
- Custom post meta box as a sub form
- Metaboxes in Loop
- Custom meta box data not saving
- Collect custom post in a calendar
- I want to link an author to everything from any post type that they publish on the website
- How can I get the $key / $value pairs of custom fields that were added via 3rd party plugins or themes?
- meta query always fails even if data is correct
- Values inside a custom field to determine which category posts to display
- Display a post count from a custom metabox selection
- how to override menu widget?
- Displaying database table in backend of wordpress
- How to rewrite CPT-Permalinks the correct way (incorporating meta-box-data)?
- Custom post type submenu sorted by specific meta_key & meta_value
- Filter CPT based on meta box value using Flexible Posts widget?
- Creating Multiple Admin Widget Page with Calling One Sidebar
- Advanced search form with filters for custom taxonomies and custom fields
- Querying meta values within an array
- why get_post_meta is returning 0?
- Post_type doesn’t work for widgets?
- Save post_parent in a custom post type
- How to display custom message for (Genesis) featured posts if no posts
- Update an existing post in a custom post type
- Post Meta for Custom Post Types