get_permalink()
(which is used by get_the_permalink()
and the_permalink()
) returns the “ugly” URL if the post is not published, e.g. draft or scheduled, but you can use the following function instead which temporarily sets the post status to publish
so that we’d get the pretty URL.
function get_future_permalink( $id ) {
if ( $post = get_post( $id ) ) {
$post->post_status="publish";
return get_permalink( $post );
}
return '';
}
So instead of get_permalink( 258 )
, you’d use get_future_permalink( 258 )
, where 258
is the post ID.
Related Posts:
- Get Post Primary Category
- How to Create Columns with WordPress and CPTUI display page ?
- Cant get paginations on single.php to work with my custom post types
- Shortcode is displaying the content on top of the page [duplicate]
- Getting a Post ID to show its content in a Popup
- Add number in increment of one to DIV ID
- Query menu_order custom post types
- Custom post status not working
- How do I programmatically add items of content to a custom post type?
- using the_permalink to echo an href into a
- Filter posts with ajax form and checkboxes
- Get custom post type REST API not working
- How can I programmatically save data into custom fields that contain serialized data?
- Get all taxonomies for all post types
- Row actions not showing? Why?
- Displaying custom post type on front page
- How to allow “Add New” capability of CPT when links to its UI are placed as a submenu?
- wordpress custom post type remove duplicate menu item
- List terms from Custom Taxonomy
- WP_Query search posts by custom post type and custom taxonomy
- How to filter out post type meta?
- Loop through posts of a custom-post-type (event) and create .ics (iCal) file?
- How can I change the title of an Add New page in Admin for custom post type
- How to count custom post types with conditional operators
- Using wordpress template tags within an array
- How to display Custom Post Type Post based on Tag with Shortcode Parameter?
- Getting the URL of the parent page
- How to display selected taxonomies by their parent
- Get posts from a custom post type by child categories of a parent category
- get the custom post type title/name
- Push metadata in array
- CPT + CMB2: data not displaying for only first post in loop
- Get custom post type list for every category shortcode
- How do i calculate the total of values of custom fields in custom post types?
- Query & Order posts by custom fields
- Custom post type – get_day_link()
- Use custom metabox to update automatically a post after a given date
- get_post_meta not working on publishing
- ACF field key/value to show on taxonomy list
- Using custom field content as expression in IF statement [closed]
- How to Upload CSV Data into Custom Post Type Data with Metabox programmatically
- WordPress custom post type split into pages
- search suggest – filter post type
- Make a custom_post translatable
- How to update post meta on uploaded image from a custom form?
- Configuring a meta query with multiple post types that have the same relationship on a single page
- Different Category system needed for the Custom Post Type
- Specifying Mouseover Icon for Custom Post
- Trying to get custom post of a custom taxonomy
- Loop increase number
- Is This Code Efficient – Or is there a better way?
- Removing full title and breadcrumb header container for a specific post type
- Filter content in shortcode
- Custom post type and custom taxonomy 404 on page 2
- Show current user posts in custom post type query
- Using Pagination for Custom Post Type and keeps returning 404
- Validate Custom Post Type fields
- meta query not retrieving posts
- How do I get the index for a custom post?
- CPT Repeatable Fields + Undefined Index
- foreach loop inside the loop creating duplicates in output
- Sets post_parent in custom post type posts automatically based on cpt->page name
- Show the categories the current post has
- Custom Post Type Causes Error: Warning: call_user_func_array()
- Front end create custom post types
- redirect after submiting post for review
- How to display “Trash” in my custom post type?
- set object terms after some some time of published post – functions.php
- Why is my custom post content only viewable when signed into WordPress?
- Get only parent post in archive post
- update custom taxonomy custom fields
- Filter taxonomy by CPT
- Query custom post type that has a serialized relational advanced custom field value
- Pagination not working in custom post type. Help
- Sending current featured image to email
- Plugin Development using classes – Public & Private Callbacks
- Sort custom post column by generated value?
- Dynamic page for nav items used as filters
- How to use posts as tabs in a custom page?
- Custom post type order by post_title
- ACF field check value of field on all other articles
- How to use POST method using custom wordpress button?
- Tell wordpress to show a single page instead of an archive page
- News post with multiple permalinks? When opened from different page
- WordPress trying to query two custom types to get child from the parent
- PHP Notice: Unidentified index
- Wrap each child and it’s grandchildren separately
- Include images from pages in wp search.php results in default wp search
- WordPress loop add heading before first of type
- Featured image in custom post is being disabled
- Why isn’t my custom post type using the corresponding custom post template?
- Custom Search not working
- Order by custom field attribute
- Custom Post-type not returning the right child_of
- Cant we use a PHP file directly like myhome.com/some.php?
- Code in custom widget queries all posts, when it should only query the current post
- How to hide home title on pages and posts?
- Add Category names to post lists of custom post type
- Custom post type is_singular condtional not working when managing sidebar display
- Issue displaying multiple TinyMCE editors with WPAlchemy