Simply change order parameter from DESC
to ASC
:
function Get_First_permalink(){
global $post;
$tmp_post = $post;
$args = array(
'numberposts' => 1,
'offset' => 0,
'orderby' => 'post_date',
'order' => 'ASC',
'post_type' => 'POST_TYPE_NAME',
'post_status' => 'publish' );
$myposts = get_posts( $args );
setup_postdata($myposts[0]);
$permalink = get_permalink($post->ID);
$post = $tmp_post;
return $permalink;
}
so once you paste that function in your theme’s functions.php and you have changed POST_TYPE_NAME
to your post type name ,you can just call it whenever you want:
<a href="https://wordpress.stackexchange.com/questions/18647/<?php echo Get_First_permalink(); ?>">First Post</a>
Related Posts:
- Allow member to have access to custom post type only. Permission to only edit their own posts
- add_rewrite_endpoint() not working for custom post type archives
- Pagination with custom post type not working
- WP_Query() show posts that end later than today
- Custom post type URL with post ID that allows archiving and paging
- How do i display the post type title?
- Sorting a query by custom field date
- custom post type archive page url to point to Page permalink
- WordPress Custom Post Type Category Page
- White screen error for a custom theme
- Custom post types – RSS lastBuildDate issue
- disable /feed/ for custom post type
- Archive page for taxonomy of custom post type
- CPT tax slug conflict with post type slug
- $wpdb returns no results with SELECT query on custom post type, works on default post type
- Display Post Author for Custom Post Type in Edit-Post Screen
- Upload Image from Front End and Resize
- Multisite with a single, shared custom post type, while retaining site URL
- How to query different post types in specific order?
- How can I display my custom metaboxes on a custom post template?
- “Allow Comments” box cannot be checked
- How to specify URLS for custom posts & taxonomies
- Allow Administrator role access to custom capabilities [duplicate]
- Second Custom Post Type Archive
- Delete link on single-custom.php with redirection
- Creating Multiple Loops in Genesis, One Post then 20, each with custom fields
- Hook to override title, image and content
- Populate dropdown from one custom post type inside another custom post type
- No posts found – Custom Post Type show_ui
- Customize my custom taxonomy table in Admin panel
- How do I do this with WordPress? Taxonomies?
- Custom-Posttype & Custom Taxonomy WP_Query
- Display Ad on Specific Categories
- Custom setting to show or hide field
- Redirect 404 page with ID in slug to associated page with same ID in slug
- Only keep the First and Last Revision of a post
- Content vs Template on custom post
- Show post in table front end
- Custom Post Type Permalink empty
- Add custom column to post list table
- Why is my category template ignoring post type?
- the_content filter on some post types only not working
- A form that can save/edit after first input
- Create 2 Post Types, one parent to another in Plugin
- Can slugs from posts and custom post types conflict?
- Integrate Custom Post Type Events into Calendar
- BBPress Search results in WordPress search
- Form action doesn’t work if slug isn’t same as custom post title
- Retrieve custom post types by custom taxonomies with WP_Query
- Pages Become “Archive” Instead of Using Page Template
- How do I add a Custom Post Type that looks and behaves exactly the same as Posts?
- Custom Post Type archive-{post-type}.php not working
- Custom post type single page (single-{CPT-name}) 404 when slug includes hyphens
- Custom URL redirect in WP
- Custom Post type & Taxonomy 404
- How can I include active content in a custom post type?
- Custom Category Walker with Image, Fallback to Most Recent Post in Category Image
- How can I output WPAlchemy repeating fields meta values in my page template?
- Displaying a list of Contacts
- Custom Sidebar in Editor (not Widget) for Custom Post Type in Genesis
- Questions regarding add_meta_box()
- Loop Post Types with Name and Links
- Custom post pagination trouble
- How to Control CSS Class Visiblity From WordPress Admin Panel based on Tax Terms
- Best Way to Query Custom Taxonomies Used on Custom Post Type
- Galleries of images attached to posts
- Retrieve posts by author
- Last post in loop – custom post types
- Question about link two types of data in wordpress
- Adding Category Name in Slug in Custom Post Type
- Add Tags to a Custom Post Type from a FrontEnd Form
- Archive page of CPT’s custom Taxonomy
- How to mass get post editor URLs
- Custom Post Type add_rewrite_rule
- Post type to appear on every page on site
- How to show related posts of category on post within custom posttype
- Saving custom JSON as custom post type
- Get custome post type name
- Custom search for a custom post type in WordPress
- Remove wp directory and slug for custom post type from the URLs
- WPML – Auto Duplicate Post Issue
- Loop carousel slider in wordpress
- How can I add a “fake” parent into the permalink?
- Best way to structure article and issue relationship for CPT
- How to display custom post types AND regular posts separately on a shared taxonomy archive?
- Custom Post Type used for FAQs Accordion
- Custom post types working in functions.php but not in plugin
- Change column of row action (Quick Edit) links in WP_List_Table
- Missing categories for Custom Taxonomy and Custom Posts
- Custom Post Type Slug / Page Slug Conflict – Prevent use of reserved slug on page save?
- How do I add a checkbox option to this custom post type code?
- Comment moderation with disqus comments
- 404 on Pages for Custom Post Type & Query_Posts
- Classic Custom Post Types and WP-PageNavi
- Can I set a CPT title field to a dropdown with preset options if user is of a given type?
- List of filtered Events is breaking paging?
- Show one of the taxonomies always as default
- How can i manually relate pages?
- Pagination for Custom Post Type with Multiple Types
- From form submission values – dynamically update CPT “has_archive” slug and custom taxonomy “rewrite” slug value