lonekorean / wordpress-export-to-markdown

Converts a WordPress export XML file into Markdown files.
MIT License
1.07k stars 216 forks source link

Maybe useful | Ways to add custom additional info (Like post_id, author_id etc) #76

Closed uarefans closed 5 months ago

uarefans commented 2 years ago

Maybe we need some data from wordpress like user_id, or category_id and etc. The key is in xml files from wordpress. So yo have to

  1. edit from cpanel or direct from your server or localhost /wp-admin/includes/export.php
  2. search <item>
  3. add something like this below <item>...</item>
    
    // for author id
    <authorid><?php echo intval( $post->post_author ); ?></authorid>

// for author name

4. save & export again from wordpress (don't forget to refresh page)
5. Check your xml files and search `<authorid>` for confirmation step is successful
6. open your wordpress-export-to-markdown directory
7. Edit src/parser.js

// Add function getPostAuthor(post) { return post.author[0]; }

// Add function getPostAuthorId(post) { return post.authorid[0]; }


// Edit // Find frontmatter: // And Add like this frontmatter: { id: getPostId(post), date: getPostDate(post), authorid: getPostAuthorId(post), author: getPostAuthor(post), slug: getPostSlug(post), title: getPostTitle(post), categories: getCategories(post), tags: getTags(post), },


8. Save and run again and you will be see

id: "12345" date: "2022-02-22" authorid: "11" author: "AAAAAAAA" slug: "magic-nexea-partnership-elevates-the-growth-of-startups-to-a-total-of-rm41mil-combined-revenues" title: "MaGIC-NEXEA partnership elevates the growth of startups to a total of RM41mil combined revenues" categories:

KUALA LUMPUR, MALAYSIA - Media OutReach - 11 February 2022 - NEXEA's Entrepreneurs Programme and Malaysian Global Innovation and Creativity Centre (MaGIC) renewed their partnership to continue helping startups grow their businesses during this challenging time. Despite the pandemic, the Entrepreneurs Programme continues to provide a platform for tech entrepreneurs to connect with peers and like-minded individuals in an opportunity to grow, gain knowledge, and develop themselves for success.



9. Additional, coverImage: "xxxxx.jpg", you will need install this plugins [https://wordpress.org/plugins/export-media-with-selected-content/](https://wordpress.org/plugins/export-media-with-selected-content/)
10. Open wordpress tools->export 
11. Checklist in bottom section and export again
Kiran-Wicksteed commented 2 years ago

Hey! How exactly do you write the cover image functions? Keeps returning undefined for me...

lonekorean commented 5 months ago

Thank you for sharing! The way frontmatter is handled has been rearchitected to make things easier.

Contributors (or people just hacking for their own use) can more easily add frontmatter by following this example.

End users can add/remove/alias frontmatter fields by editing frontmatter_fields in settings.js.