0

Hello my fellow WP Developers,

I am running into a wall with a custom theme I am creating for a personal project.

Background

It's a website that will be used by users that collect a specific type of figures. This site will basically be a big data dump of all the figures ever released in this line. And because these figures are so rare to find I wanted to make a site where collectors can compile their own "I own this" list and what the current second hand value of the figure is and if there currently is a store that sells the figure.

Current Challenge

What I am trying to accomplish right now is the following:

I have added a custom post type for the figures (Called 'wdcc'). This post type has 3 taxonomies

  • Series
  • Edition
  • Store

What I currently want is that I can add "Stores" through normal means (add new etc.). Now I've created a custom meta box which I want to use to add stores that currently sell the figure. So I can choose the store from a dropdown (The select is populated with a foreach loop) and input the selling price in a input field. My idea was to use Datatable scripts and currently implemented this one Datatables.

Problem

I got the meta box semi working. There are still some parts that not entirely work as I want them too but I can interact with the meta box. It's more that I can't seem to figure out how to save the meta data I added through jQuery/Javascript.

I've been browsing through the codex like crazy at functions like save_post and update_post_meta. Searched google for hints and tips but so far I can't seem to figure this out.

Code

I use X Theme as my parent theme and have x-child as the active theme. I basically use their code style and some functions as they do and edit, add, update where needed.

I think it's best if I gist these files so here is a link to (what I believe) are the 3 most relevant files

Extra

If more info is needed. Please feel free to ask.

Many thanks

1 Answer 1

0

Refer to Creating a new PostBox in WordPress. As long as you name the fields the same in render as you do in save then you're good.

RENDER

echo '<input type="text" id="boxpost_meta_field" name="boxpost_meta_field"';

SAVE

$mydata = sanitize_text_field( $_POST['boxpost_meta_field'] );

// Update the meta field.
update_post_meta( $post_id, '_boxpost_meta_field_value_key', $mydata );

GET

$value = get_post_meta( $post->ID, '_boxpost_meta_field_value_key', true );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.