Forum Replies Created
-
AuthorPosts
-
June 4, 2019 at 11:07 AM in reply to: How to make repeating post with custom fields using Meta Box #14827
Anh Tran
KeymasterHi Jonathan,
Please see this docs: https://docs.metabox.io/extensions/meta-box-group/#outputing-group-in-a-page-builder
Anh Tran
KeymasterHi @easy,
The working code here: https://pastebin.com/qKA2uYWL
There are 2 notes:
- I added the code to get the current post ID
- Query args are set for the current post type, so the param should be in the
frompart instead ofto
I also optimize the query a little bit.
I'm checking the bug with reordering. Thanks for your feedback.
Updated: I've checked the reorder bug and it seems to be the browser cache. Pressing Ctrl-F5 to reload the page without cache will fix this.
Anh Tran
KeymasterAnh Tran
KeymasterHi Neil,
This is an interesting case.
I think you probably don't need a CPT for Menu. Since each location has a specific menu, a CPT Menu probably serves nothing.
If I do this, I probably will set CPTs this way:
- Menu items: each menu item has a default price
- Locations: each location will has a cloneable group of menu items, like this:
- Menu item: a
postfield (for selecting menu items from the list) - Custom price: a
textfield (if that location has a different price for that menu item)
- Menu item: a
If some locations have unique menu items, they should be added as a new posts under Menu items first. Then users can select from the list when edit a Location.
Anh Tran
KeymasterHi Neil,
You can convert the format using PHP
date()function. Assuming your time has format "04:20 PM", and you want to convert to "16:20", here is the code:$time = rwmb_meta( 'field_id' ); // 04:20 PM echo date( 'H:i', strtotime( $time ) ); // 16:20Anh Tran
KeymasterYes, we have resolved this problem and the fix was added in the 4.18.2 version.
Anh Tran
KeymasterHi Dave, sorry for the delay. I couldn't find anything wrong with the code. Can you send me a temporary admin account to take a look into that closer?
Anh Tran
KeymasterPrefix is just an option and sometimes, it confuses people. So in the MB Builder, we don't include it. You can add the prefix manually in the ID fields if you want.
Anh Tran
KeymasterSorry for the delay, here you are.
Anh Tran
KeymasterHmm, looks like the disabled elements won't be submitted when submitting the form.
I think both issues (disable selection and limit the query) can be done like this:
- Make an extra query to get the current selected options (do it by making a SQL query directly to the database). With this, you get the IDs of the connected posts.
- Set the
post__inforquery_argsin the relationship meta box. So the query only get the selected items.
Anh Tran
KeymasterIf the field is updating, that means it still saves values in the post meta. Can you verify that?
And did you put all the fields in one meta box?
Anh Tran
KeymasterYou can set
query_argsparameter forfromandtoto limit the query. If you know the IDs of selected items, you can do this:MB_Relationships_API::register( [ 'id' => 'posts_to_pages', 'from' => [ 'post_types' => 'post', 'query_args' => [ 'post__in' => [1,2,3], 'posts_per_page' => 10 ], ], 'to' => 'page', ] );Anh Tran
KeymasterI don't see anything wrong here. Do you see other fields saved in the database?
Anh Tran
KeymasterHi Will,
For WP_Query, the plugin doesn't integrate with it. You need to perform an extra query to get the posts you want, then use the returned ID to create your own WP_Query.
global $wpdb; $ids = $wpdb->get_col( "SELECT ID FROM your_table WHERE field1='value1' OR field2='value2'" ); $query = new WP_Query( [ 'post_type' => 'post', 'post__in' => $id, ] ); -
AuthorPosts