• Hi to all,

    how are you? I’d like to create a plugin that export my wp comments on one csv file.
    I don’t find any plugni that do this job for me.
    I want to proceed ad:
    Create on functions.php a function that retrieve my data or a db view that join wp_comments e wp_metadata to have all comments and related data to one file, than create a new menu iteam on the dashboard with a export button that call this function and save file?

    Is it possibile?

    Thanks very much
    Gabriele

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    It is possible.

    If you have file privileges on your SQL server, you could send a query for the required tables using $wpdb. I’m unsure of the exact query, but it would include something like

    ...INTO OUTFILE '/tmp/comments.csv'
    FIELDS TERMINATED BY ','
    ENCLOSED BY '"'
    LINES TERMINATED BY '\n'

    Alternately, you could simply use get_comments() and step through each object returned to get the corresponding commentmeta and then write formatted csv lines to a file based on the data contained in the object and commentmeta.

    To launch this process from a dashboard button, you would either need to create a dashboard widget to contain the button, or inject it into an existing widget using some available hook provided by the widget. Examine wp-admin/includes/dashboard.php to get an idea of the possibilities.

Viewing 1 replies (of 1 total)
  • The topic ‘Create plugin to export comments on csv file’ is closed to new replies.