Forum Replies Created
-
AuthorPosts
-
December 11, 2024 at 6:33 PM in reply to: Taxonomy and Related CPT are not being copied when duplicating CPT using Polylan #47164
AnLip
ParticipantI'll add to avoid unnecessary questions about that, that every bit of information has already been created and associated (other language taxonomies and related CPTs), so they are available in the database.
AnLip
ParticipantFor the moment the only workaround I have found is to change the field to a simple Select type, but then i lose the Taxonomy's possibility to have an archive for all posts that share the same "Country".
What would be a better workaround ?
September 17, 2024 at 2:50 PM in reply to: ✅Set Default Term for Specific Post Submission Form #46483AnLip
ParticipantI also tried with hook "rwmb_frontend_before_save_post' but the fatal error is still caused.
September 17, 2024 at 2:44 PM in reply to: ✅Set Default Term for Specific Post Submission Form #46482AnLip
ParticipantHi Peter, I'm trying your logic out but I get fatal errors crashing the site.
This is my code, would it work ?
add_action( 'rwmb_frontend_after_save_post', function( $config ) { // Make sure we're working on the correct form if ( 'actualites-gf' === $config['id'] ) { // Get the post ID $post_id = $config['post_id']; // Get the 'actualite' category ID $category_id = get_cat_ID('actualite'); // Add the category to the post wp_set_post_categories( $post_id, array( $category_id ), true ); } } );AnLip
ParticipantHi Peter, I'd also like to report that the documentation for the URL type of custom field does not exist, at least it redirects to another custom field's doc page : on this page https://docs.metabox.io/fields/ when you click on the "URL" type of field, it takes you to the doc for the Text field element. If you manually try https://docs.metabox.io/fields/url/ it doesn't work (404).
AnLip
ParticipantThe problem is that an empty field will cause the text to pick up the current post's url.
My setup is as follows :
- in Bricks, there is a LOOP (set to the Field Group named "designers-gf") that is set to loop through the results for the "MB Group: Références Bibliographiques" group.
- The "designers-gf" field group includes (amongst other fields) this "MB Group: Références Bibliographiques" that has two fields : a text field "designers_ref" for the text, and "designers_url" for the URL.
- In Bricks builder, I set the url value to apply to the link for the text. Therefore if there is a value for the URL it should be used for the link, but if there is no value for the URL it should just remain a text without a link.Now the problem is that when there is no value inserted to the URL field, the text element will by default pick up the current post's url and link to it. I need this to remain unlinked if there is no value added to the URL field. I feel that this is the way it used to work, but I can't figure out how to get there.
AnLip
ParticipantI think it would be so great if MetaBox added a feature that allows to select custom fields to create the Post title. I will copy this message to the FB group, that is where I have seen my feature request taken in account by Anh Tran (I believe he likes good ideas :-).
AnLip
ParticipantIO figured it out on my own (thanks ChatGPT) and ended up with this function that works perfectly, some might find it useful :
<?php function update_objet_post_title_with_designer_and_latest_values($post_id, $post, $update) { if ($post->post_type !== 'objet' || wp_is_post_revision($post_id) || !$update) { return; } $genre_terms = get_the_terms($post_id, 'genre'); $genre = !is_wp_error($genre_terms) && !empty($genre_terms) ? $genre_terms[0]->name : ''; $date_terms = get_the_terms($post_id, 'date'); $date = !is_wp_error($date_terms) && !empty($date_terms) ? $date_terms[0]->name : ''; $objet_designation = get_post_meta($post_id, 'objet_designation', true); $designer_title = ''; $connected_designers = MB_Relationships_API::get_connected([ 'id' => 'objet-designer', 'from' => $post_id, ]); foreach ($connected_designers as $designer) { // Assuming the designer's name is stored in "last, first" format. $name_parts = explode(', ', $designer->post_title); if (count($name_parts) == 2) { $designer_title = trim($name_parts[1]) . ' ' . trim($name_parts[0]); } else { $designer_title = $designer->post_title; // Use original if not in expected format. } // Sanitize for safety while preserving accents and capital letters. $designer_title = wp_kses_post($designer_title); break; } $designer_part = $designer_title ? " - $designer_title" : ''; $new_title = trim("$genre \"$objet_designation\"$designer_part - $date"); $new_title = rtrim($new_title, " -"); if (get_the_title($post_id) !== $new_title) { remove_action('wp_after_insert_post', 'update_objet_post_title_with_designer_and_latest_values', 10); // Sanitize slug for URL, ensuring accents are handled appropriately. $sanitized_slug = sanitize_title($new_title); wp_update_post([ 'ID' => $post_id, 'post_title' => $new_title, 'post_name' => $sanitized_slug, ]); add_action('wp_after_insert_post', 'update_objet_post_title_with_designer_and_latest_values', 10, 3); } } add_action('wp_after_insert_post', 'update_objet_post_title_with_designer_and_latest_values', 10, 3);AnLip
ParticipantSo basically, where the snippet above has this line :
$designer_post_id = rwmb_meta( 'related_designer_id', '', $post_id );it should be able to pull the value of the related post's title and insert it here.
AnLip
ParticipantHi Peter,
The code is generated by ChatGPT, it invented some name for a custom field that does not exist (for the relationship), since the data I want to pull is coming from the Meta Box created Relationship (between two CPTs : "objet" and "designers").
So the question again : how can you pull the data of a relationship while in the admin area and saving a post ?
AnLip
ParticipantThe post title is wrong, I do not need help anymore with pulling the taxonomy values (I have managed that in the provided above code).
My only issue is with pulling the current post's related post's title, and inserting it in the newly generated title (before the date).
AnLip
ParticipantThank you Peter, but I don't understand what you are suggesting.
Could you provide a code that will work inside a Bricks User query ?AnLip
ParticipantThanks Peter, have you also fixed the use of taxonomy fields being attributed to Media Attachments ?
I have tried outputting custom text fields but with no success. Whether I use the Bricks dynamic data way or a code block and the PHP provided in the MB custom fields editor, either way the values don't show in the frontend. Using the Bricks dynamic data way in a Basic text element leaves the value as such : {mb_attachment_text_line_1} in the frontend, and using the codeblock just outputs nothing...
AnLip
ParticipantHi Peter,
Any news for this matter ? It would be such a good addition to MetaBox...
AnLip
ParticipantOK, issue solved : someone helped me on the MB facebook group stating I had many custom fields and the PHP max_input_vars was too low at 1000 so changing it 8000 solved the problem. I can now resave my group field as I want and the values have come back frontend and backend ! As mentioned by the person who helped me, the devs should really get a warning shown after a certain number of fields has been reached !!!
-
AuthorPosts