A signup form to request that WordPress Users signup using their email.
How To Export Posts To CSV In WordPress
Add Custom Button On The Post Listing
To generate the CSV, we first need to give a button on the listing page of a post screen. On the click of this button, we will write a code for generating a CSV.
Open your
functions.php
file and place the below code in it.
12345678910add_action(
'manage_posts_extra_tablenav'
,
'admin_post_list_top_export_button'
, 20, 1 );
function
admin_post_list_top_export_button(
$which
) {
global
$typenow
;
if
(
'post'
===
$typenow
&&
'top'
===
$which
) {
?>
<input type=
"submit"
name=
"export_all_posts"
id=
"export_all_posts"
class
=
"button button-primary"
value=
"Export All Posts"
/>
<?php
}
}
Above code add the button ‘Export All Posts’ on the posts listing as shown in the screenshot. Here, we have used the hook manage_posts_extra_tablenav to place our custom button on post screen page.
Actual Code Which Export Posts To CSV
At this stage, you are ready with your custom button which should generate our CSV. So, let’s add a code that generates the CSV on the click of a button and send it to the browser for download.
Add the below code in the
functions.php
file.
12345678910111213141516171819202122232425262728293031add_action(
'init'
,
'func_export_all_posts'
);
function
func_export_all_posts() {
if
(isset(
$_GET
[
'export_all_posts'
])) {
$arg
=
array
(
'post_type'
=>
'post'
,
'post_status'
=>
'publish'
,
'posts_per_page'
=> -1,
);
global
$post
;
$arr_post
= get_posts(
$arg
);
if
(
$arr_post
) {
header(
'Content-type: text/csv'
);
header(
'Content-Disposition: attachment; filename="wp.csv"'
);
header(
'Pragma: no-cache'
);
header(
'Expires: 0'
);
fputcsv
(
$file
,
array
(
'Post Title'
,
'URL'
));
foreach
(
$arr_post
as
$post
) {
setup_postdata(
$post
);
fputcsv
(
$file
,
array
(get_the_title(), get_the_permalink()));
}
exit
();
}
}
}
Make WordPress Load Fast in a Few Clicks
Recognized as the most powerful caching plugin by WordPress experts
Minimal Configuration, Immediate Results
Don’t waste your time struggling with complex plugin settings. WP Rocket launches upon activation.
Sitewide Message: WordPress Plugin
Simply. Display a message at the top of every page on your website. You can change the background colour, text colour and URL location.
NEW FEATURES
- Scheduled Message – Choose when to show or hide a message on your website.
- Link Location – Open link url in new window or same window.