Here is a simple function that will return the Permalink of the last painting post:
function Get_most_recent_permalink(){
global $post;
$tmp_post = $post;
$args = array(
'numberposts' => 1,
'offset' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'Painting',
'post_status' => 'publish' );
$myposts = get_posts( $args );
$permalink = get_permalink($myposts[0]->ID);
$post = $tmp_post;
return $permalink;
}
so once you paste that function in your theme’s functions.php file you can just call it whenever you want:
<a href="https://wordpress.stackexchange.com/questions/12143/<?php echo Get_most_recent_permalink(); ?>">last painting</a>
Related Posts:
- Can I create permalinks like this: /%post_type%/%postname%/
- Is it possible to get a page link from its slug?
- Custom post types, taxonomies, and permalinks
- How to create a permalink structure with custom taxonomies and custom post types like base-name/parent-tax/child-tax/custom-post-type-name
- Need help with add_rewrite_rule
- Permalinks: custom post type -> custom taxonomy -> post
- After server migration only the homepage works
- Mixing custom post type and taxonomy rewrite structures?
- Resolve a custom post type name vs. page permalink conflict (same slug)
- remove “index.php” from permalinks
- where is permalink info stored in database?
- Custom Post Type pages are “not found”
- Changing permalinks gives me 404 errors on nginx
- How do I add /blog/ as a prefix to permalink structure for blog posts, tag pages, etc.?
- Remove taxonomy slug from a custom hierarchical taxonomy permalink
- Adding categories to custom post type in permalink
- Change media item permalink
- How do I get the permalink of a custom post type?
- Can a custom post type have a Parent Page?
- remove custom post type permalink
- How to rewrite URI of custom post type?
- Add extra parameters after permalink?
- Get Permalink without domain (i.e. get relative permalink) [duplicate]
- How does WordPress create URLs that Apache knows about?
- Strange permalink issue: can’t rename /company-2/ to /company/
- Passing and retrieving query vars in wordpress
- Rewriting a custom-post-type permalink with taxonomy term?
- Getting hierarchical custom post type permalinks to work just like pages
- Get the current page URL (including pagination)
- Stop WordPress appending `-2` to the end of my url after i change it
- Get default permalink structure from pretty URL’s
- How to get permalink and title from post ID?
- Why is “/page/2/” not working?
- WordPress Permalinks not working in Apache2 Ubuntu 14.04
- Where, When, & How to Properly Flush Rewrite Rules Within the Scope of a Plugin?
- Performance of my permalink structure?
- Permalink format: singular or plural
- Add .html (dot HTML) extension to custom post types
- What is the difference between get_post_permalink and get_permalink?
- How to change permalink structure for custom post type and it’s taxonomies?
- Shouldn’t this be easy?! Custom post type/custom taxonomy permalink
- WordPress matching URLs with trailing tildes
- Get current URL (permalink) without /page/{pagenum}/
- Nested custom post types with permalinks
- How to prefix post permalinks with /blog/ – without affecting custom post types?
- How does WordPress handle permalinks?
- Pretty permalinks for search results with extra query var
- Get page permalink without wpurl
- How can I get the privacy policy page?
- Can I use REST-API on plain permalink format?
- WordPress slug issue with non-latin characters
- Change permalinks for posts but not for custom post types
- Rewrite Rule for Multilingual Website, Like qTranslate?
- Custom Post Type Permalink / Rewrite not working immediately
- Best way to flush_rewrite_rules for custom post type, in a mu-plugins plugin?
- How to get pretty URLs with add_query_arg in permalinks
- How do I append multiple taxonomies to the URL?
- What is the best permalink structure for SEO?
- Change author permalink
- Custom rewrite rules for archive page and single post
- WordPress 3.3 custom post type with /%postname%/ permastruct?
- WordPress Rewrite Rules for Custom Post Type and Taxonomy
- Creating custom permalink structure for languages
- Hide permalink and preview button and link on custom post
- Custom post type permalink endpoint
- How can I make Capital letter ( upper-case ) permalinks?
- How can I reverse engineer a Permalink to Find the Page?
- Mapping Domains to Permalinks (not multisite)
- How to remove dates from existing permalinks?
- How do I set a custom base URL for standard posts?
- Removing Parent Page(s) from Permalink
- How to remove slug from hierarchical custom types in 3.5.2
- Permalink Structure for Multiple Post Type Archives by Taxonomy
- Why permalinks work with /index.php/%postname% but not with just %postname%?
- Setting up WordPress with Custom Permalinks and no .htaccess File?
- Getting the Site URL Including the Front Base
- Does WordPress Change the .htaccess File When Updating?
- Custom post types – Use post_id in permalink structure
- Using $_GET variables in the URL?
- Removing the redirect after changing a page’s slug
- How to display a public profile page for registered users with custom slug?
- Removing leading zeros from custom permalink structure
- Must slugs be unique?
- Custom Post type & Taxonomy URL structure
- Setting 404 page in Nginx
- Custom post type 404s with rewriting even after resetting permalinks
- Remove slug in taxonomy url
- Multiple post types – share same ReWrite slug?
- Taxonomy, Terms, and Template Files
- Removing unnecessary numbers appended to postname in permalinks
- How to remove /blog/ prefix for custom post types in permalinks?
- How to get the clean permalink in a draft?
- How to use relative links on my pages?
- Slug Formatting : Acceptable Characters?
- Disable permalink on custom post type
- How does wordpress keep track of post id when post id is not used in permalinks?
- How to filter to output of the get_permalink() function
- Combining Multiple Taxonomies in one URL
- Stop WordPress from reserving slugs for media items?
- Including category-base in a post permalink results in 404