• I am using WordPress to build a job website and a huge portion of my website is involved with storing and retrieving user information to and from the database.

    There are three types of custom posts on the website Jobs, Resumes and Companies. Here are my questions :

    1. Are the fields in the wp_postmeta table common to all of the post types. Meaning, if a Resume has ‘education level’ meta field, will Companies also have it?

    2. How do I add more fields in the wp_postmeta table if that is required. I am looking for a method that involves writing code in the theme files and not directly adding fields to the database tables from phpmyadmin.

    Any help on these topics is very much appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi There, post meta is generally specific to each post type though you could use the same function and register it multiple times to different post types. here are some decent articles if you want to hand code them (and deal with saving the data) yourself

    https://wptips.me/add-meta-box-custom-post-type/
    https://wptheming.com/2010/08/custom-metabox-for-post-type/

    While that will technically work I am guessing that ‘education level’ may be either a taxonomy or custom html select input. In either case I would recommend using a plugin to help register these for you.

    either of the following would be a good helper plugin which allow you to keep the code for you meta boxes in your theme (both are free)

    https://github.com/alleyinteractive/wordpress-fieldmanager
    — installing https://github.com/alleyinteractive/fieldmanager-demos as well will register a bunch of example post type will all the fields and functionality the plugin offers

    or

    https://github.com/WebDevStudios/CMB2

    Thread Starter lordram

    (@lordram)

    Hey Dan, thanks a lot for replying here as well as on twitter. Your post was really helpful. Just clarify one more thing for me if possible : Does using the add_meta_box() function create a field within the wp_postmeta table in the database? The description for this function in the codex does not really say that it does.

    If it doesn’t, what is the procedure to do that? I am really keen on understanding how creating fields in the wp_postmeta works when hand coded because I know the theme developer has done it but I cannot find any occurrences of the add_post_meta() function where this is happening.

    Once again, thanks a lot ?? Been stuck on this for a long time.

    the wp_postmeta table looks like this:

    meta_id | post_id | meta_key | meta_value

    so a custom meta field’s key would be found under the meta_key column (if that make sense). If you are not seeing any calls to add_meta_box check and see if your theme has the ACF (Advanced Custom Fields) plugin installed. If this is the case the custom meta is probably being register via ACF’s admin area and thus will not be found in the code of the theme.

    If ACF is not installed check for any other plugins that may be doing something similar like that pods plugin.

    Hope this helps.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Post Meta for Custom Post Types’ is closed to new replies.