I want to get the permalinks of all published pages and export it to an excel file.
What is the best solution?
- Should I go to wp-admin panel and copy-paste the permalinks from the on Page editor?
- Can I get the export data using a mysql query?
I want to get the permalinks of all published pages and export it to an excel file.
What is the best solution?
Comments are closed.
It is possible but very difficult to do via a SQL query, because WordPress allows you to change your Permalink structure – so the SQL query would need to regard all permalink options to build the correct permalink when the query is executed.
And I guess you are looking for a way that does not require you to copy paste links from the admin page 😉
By far the best and easiest thing to do is write a small script that runs the export for you within WordPress and uses the functions
get_pages
andget_permalink
:Note: This code will only run inside WordPress, i.e. as as Plugin or inside a Theme. Also how to do the excel export is beyond the scope of my answer…
Personally I’d create a WordPress plugin (there are many guides out there on how this works, like this one).
In the plugin you could simply check for a URL param, and if this param is present then export the data. Additionally I would check if the user that requests the export has admin permissions before exporting the data.
A bit like this:
Please note that this code should only explain my suggested workflow. It does not use best practices and I don’t recommend to use it like this on a live site