First off, you should use get_posts
instead of a raw SQL query. Or at least use $wpdb
.
<?php
$posts = get_posts(
array(
'post_status' => 'publish'
'numberposts' => -1
)
);
Then, try passing the entire post object to get_permalink
, which saves some database queries.
<?php
foreach( $posts as $p )
{
$link = get_permalink( $p );
// do stuff here...
}
The only thing I saw in get_permalink
that might cause an empty string it it checking for an empty post ID. Try the above, and see if it works for what you need.
Related Posts:
- How does WordPress handle permalinks?
- Get page permalink without wpurl
- Can I use REST-API on plain permalink format?
- How to change ‘with_front” key from an existing custom post type?
- Post titles not letting me use 2 consecutive dashes in permalink
- Make post slug have priority over category slug
- Adding anchor to paginate_links + Safari anchor bug
- How to stop permalink redirects for a particular slug
- Why does WP not use relative links when linking pages?
- 404 on category.php pagination
- flexible rewrite ‘ramble’ URLs with WordPress
- What is the action or filter for changing permalink in Edit Post/Page?
- Posts not working on windows after changing permalinks
- Custom permalink structure
- How to get rid of index.php?
- Relative or Absolute Paths for Flash Video Player Files
- Remove Custom Taxonomy Slug from Permalink
- WordPress Links Not Working After Migration
- Migrating WordPress blog to New Webhosts, something is adding a # and gibberish
- Adding File Extensions to Attachment Page Permalinks
- Permalink /%category%/%postname%/ returns 404 on OSX
- How to tranform Headlines into linkable permalinks?
- Best way to add internal link in widget
- Changing search URL to something other than “search”
- article pages not displaying on local instance of wordpress site
- breadcrumbs & rel=”nofollow”
- Use Regular Expression to get tag from permalink url during wp_rewrite in generate_rewrite_rules
- Permalinks for pages
- Create unique alphanumeric ID on wp_insert_post
- Programatically changing post’s permalink when identical post type is published
- Permalinks not working with Vagrant
- Possible to remove taxonomy from permalink if uncategorized?
- Is there a link parameter that will show me all my published pages?
- Add prefix to page URL based on the page template
- Files rendering adding “.x95527” before file extension [closed]
- Permalink /%postname%/ doesn’t work
- How to change hierarchical page permalinks to be flat
- Permalink structure with $_SESSION variables
- Relative v.s. absolute URLs: which ones should I use for cross-domain portability?
- Strange Anchor Tag Behavior (in-page links work, external pages do not) [closed]
- Custom permalinks in WordPress
- Permalink opens attachment instead of page
- How can I say if a URL is a post, page, or taxonomy archive?
- Changing WordPress routing to load the same page for different URLs
- Custom post type clean shortlink
- cannot link a external url, present page url acting as parent url
- add_rewrite_rule on default post type
- how to find duplicated permalinks?
- the_content(); erroneously closing off previous opening before it
- Bulk append URL (add word to slug)
- Conditional Permalink based on category?
- Permalink Custom Page Template
- How do i get post thumbnail using attachment code
- permalink error when modifying sanitize_title_with_dashes function
- The requested URL was not found on this server [closed]
- Shortcodes not working
- How to create posts or pages with the names in wordpress?
- WordPress permalink not working on subdomain
- Xampp 7.3.3 fresh install of WordPress 404 pages unless permalink is set to plain
- Make the blog page a child of another page and rewrite the blog url
- How to construct a dynamic rewrite rule for child pages that passes more than one query var
- Extending page urls without getting a 404
- Permalink conflict with React Router in subfolder
- 404 on pretty permalinks when serving via HTTPS
- Add /blog prefix for all WordPress front end url
- Permalink structure has suddenly changed
- How to experiment with permalink structure on a select number of posts
- In a multisite, how can I get posts from one site and display their permalinks in another site?
- Why does page for hierarchical taxonomy parent term go 404?
- Custom permalink gives 404 error only in some pages
- Can I link to content dynamically from a page to a new page?
- Custom permalink for one category
- Create new URL structure for custom post types
- No Ones Been Able to Override my WordPress Rewrite Rule Issue!
- Remove index.php from URL (WP installed in subdirectory)
- Page returns 404 for specific permalink
- Choose permalink on a per-post basis?
- Single.php not loading when permalink only contains date information
- WooCommerce product permalink changed
- Different Permastruck Between Ajax Request & Normal Request
- Imported posts using wrong domain name
- Is there a way to add slug to home_url on this function?
- Problem with multiple tags in URL
- Custom Permalinks and filters?
- Customized author slugs not working with get_author_posts_url method
- Custom WP permalink structure
- 404 error on second page load for child-pages
- Permalink structure as code in back-end?
- Internal Server Error every time I push up my WordPress Project to Heroku
- region selection
- Redirecting From An Old Permalink Structure
- WordPress custom permalinks, pages are now 404
- WordPress home page showing 404 error
- Include language variable in url
- Is it posible to translate a url prefix?
- AllowOveride All causes assetts and Admin Urls to 404
- Page permalinks are http but show up as https?
- Custom Permalink Structure For a Specific Category
- Error: “Sorry, this content could not be embedded” when using the Embed block
- WordPress not remembering old slugs for pages