How best to store data (URLs and IDs) extracted from posts and pages using custom taxonomies

by Sean   Last Updated March 11, 2018 13:08 PM

I want to store metadata extracted from post/page content:

  • IDs of other posts/pages on the same blog linked within the content of each post/page
  • certain external URLs contained within the content of each post/page

I've created two custom taxonomies to store this information: internal_reference and external_reference. Both are non-hierarchical and non-public. Edit page meta-boxes are also switched off as the metadata is extracted programmatically, and I don't want users overriding this with the checkboxes provided for other taxonomies like categories.

I've written a function that can extract the IDs and URLs from the post/page content, which runs on the save_post hook.

The problem I'm having is how best to store this information. Clearly I must use wp_set_post_terms to associated the terms with the post in question, but I can't work out whether I need to use add_term_meta to set the IDs and URLs or if I can just use the term's name or slug field. If it's best to store this using term meta data, then how do I find out each newly created term's ID after I call wp_set_post_terms with a bunch of URLs or post IDs?

How is this sort of thing intended to be done in WordPress? Forgive me if this is a rather basic question, but this feature of WordPress is new to me.

Related Questions

Merging custom taxonomies and removing duplicates

Updated November 09, 2017 15:08 PM

Why does wp_remove_object_terms not work?

Updated April 01, 2018 06:08 AM