I am not sure why you are using a custom query and not get_posts()
or WP_Query
as you should.
Anyway, you need to get the post ID …
$query ="SELECT wp_posts.post_title AS title ,
wp_posts.post_content AS content,
wp_posts.post_date AS blogdate ,
wp_posts.ID AS ID
And then just pass this ID to get_permalink()
:
get_permalink( $post->ID );
Similar for the title attribute:
the_title_attribute( [ 'post' => $post->ID ] );
Related Posts:
- Bulk update post slugs through database
- Change permalinks in posts via SQL
- Where is the old post permalink slug stored?
- How to Check if a Page Exists by URL?
- Use category base slug in posts’ permalink
- How to automatically generate a unique random slug
- Custom permalink structure only for default posts
- Post slugs and images cannot have same name?
- Change permalinks for post type ‘post’ only
- Export WordPress Posts and Meta Information in CSV format
- Change the Slug of Post Type post to baseurl/post/%postname%
- Different permalink for posts and authors
- Pretty URL with add_query_var
- get_permalink returns default link
- Group Posts by First Letter of Title
- Keep getting same permalink with WP_Query?
- How to control which category will be picked for the slug of a post?
- Change slug with custom field
- Why can posts never have a number as the link?
- Must permalinks always point to single post pages?
- How to allow slashes in single posts when i click in the edit permalink button
- Post custom permalink results in 404 for archive page
- Some posts returning 404 instead of displaying post
- Custom post type single (permalink) throws a 404 error
- Link for the page archive for posts, like using custom post types with get_post_type_archive_link
- Post in Multiple Categories to stay in current category (permalink, next previous post link)
- Use Cron to modify posts via sql
- Sql syntax error
- Random post permalink
- What Defines What Category A Post Picks (if in multiple)
- get_permalink executes link without https
- Permalink Settings: optional settings doesn’t apply to editor
- get posts and postmetas in assoc array
- Custom post type permalinks breaking due to 3.1 bug fix
- How can a guest view the “Pending Review” Post?
- Create pretty permalink for a post knowing the permalink structure
- Changing my permalink structure – will new layout conflict with existing page?
- How to change the page break URL from ../post/2 to …/post/page2/
- Link post permalinks to subdirectory /post
- change default post archive page link
- Remove permalink from images when inserting into post
- Remove the Edit button in posts for permalinks on certain user roles? WP 3.3
- How do I find which articles are missing a featured image in The WordPress database?
- Dynamically generate child-URLs for posts or custom posts
- Get the most repeated post contents from a search?
- Adding parent pages to posts
- Multiples Empty Posts were created and cannot delete them
- Plain permalinks not working!
- Delete WordPress posts from URL list sql query
- SQL query to retrieve all the records that have not indicated category
- Removing rel=”nofollow” from links posted in Post Content
- How to change permalink on post click on post listing page
- Changing Permalinks for Default Post type to reflect navigation
- How should I add links to other pages/posts from my post?
- WordPress not opening posts with only numbers if permalink is post_name
- Using permalinks, category slugs, and tag slugs
- Problem with permalink routing?
- Move first half of posts to one parent page, second half to the other page
- How to verify wp user password by sql query in wp? [closed]
- Get ALL post ID’s export list (Only id’s. Php or sql not important )
- How to check a post exist when the permalink has post id in it?
- After database migration, posts not showing up in dashboard
- How to do set post permalinks using 6 digit random unique function?
- Switch to page template when using post permalink
- Trying to use AngularJS with WordPress without any API
- How to handle broken links created by permalink/slug changes?
- How could I change my Permalink from blog to custom structure? [closed]
- Visting slug for ‘post’ post type shows 404 not archive?
- Any way for get_next_post() to use the actual post order instead of publish order?
- how do i add posts-page slug before posts slug in permalinks
- Permalink doesn’t get displayed in Twitter button (Local WordPress problem?)
- Retrieve post ID from “querying” URL
- hiding permalink in admin if the user is subscriber
- Why does WP_Post not contain its permalink?
- the_permalink() not working in a root installation
- When changing pages to posts, how do you set up 301 redirects for the page URLs?
- WordPress website loads more posts than expected
- SQL Command for restoring trashed comments
- Second get_permalink inside loop points to wrong URL
- Custom Permalink Structure for Pages & Posts
- How to Assign / Move all Deleted post to a category
- custom word in custom permalink structure
- Migrate posts from category and sub-category via SQL
- register_post_type permalink
- Updating permalink structure using ‘post_link’ filter results in 404 error for posts
- Post is blank when I click on the link
- Custom permalink for each post
- Unabled to Change Permalinks – Even Using the “Edit” (Resets to Original Permalink on “Update”)
- Post/page title to permalink transformation – what is behind the scenes?
- When WP_Query only returns 1 post, how do I automatically redirect to that post?
- Post titles and thumbnails as links to custom post types?
- Internal linking to posts permalink fail because of spaces and stripe at postname
- SQL Bulk Move old posts by one author to another category
- Link post images to post
- Making posts permalinks consistent numbers
- Export all posts to import as product items
- Can Permalink structure of %postname%/%post_id% improve performance
- How to link post titles on page A to its posts on page B?
- Problems with WordPress in subfolder, posts show a blank page
- How can I get posts from 9/13/11 to today with SQL? [closed]