Forum Replies Created
-
AuthorPosts
-
June 13, 2025 at 9:51 AM in reply to: Populate a selewct list in a CPT from values set in a Settings Page #48437
Andrew
ParticipantFurther to this I have this code that shows the select list in my product CPT but the list is empty:
add_filter( 'rwmb_meta_boxes', 'register_custom_meta_boxes' ); // Hook into Meta Box to register custom meta boxes function register_custom_meta_boxes( $meta_boxes ) { // Retrieve stored values from the settings page field $options = get_option( 'prod_cats_test', [] ); // Replace with the actual field key inside your settings page // Ensure values are correctly formatted before populating the select field if ( is_array( $options ) && !empty( $options ) ) { $formatted_options = array_combine( $options, $options ); // Convert array into key-value pairs for the select field } else { $formatted_options = []; // Fallback to an empty array to prevent errors } // Define the custom meta box for the specific post type $meta_boxes[] = [ 'title' => 'Product Categories', // Title of the meta box 'id' => 'custom_select_meta_box', // Unique ID for the meta box 'post_types' => ['product'], // Specify the post type(s) where this meta box should appear 'fields' => [ [ 'id' => 'product_cats', // Field ID for storing the selection 'name' => 'Select an Option', // Label for the select field 'type' => 'select', // Define the field type as a dropdown select box 'options' => $formatted_options, // Populate dropdown dynamically ], ], ]; return $meta_boxes; // Return the modified array of meta boxes for registration }Andrew
ParticipantHi Peter,
Thank you for that, it worked perfectly.
Andrew
ParticipantSorry this is the code snippet:
<?php $files = rwmb_meta( 'fees_file_upload' ); ?> <h3>Uploaded files</h3> <ul> <?php foreach ( $files as $file ) : ?> <li><a href="<?= $file['url']; ?>"><?= $file['name']; ?></a></li> <?php endforeach ?> </ul>Andrew
ParticipantAndrew
ParticipantAndrew
ParticipantHi Anh, apologies for the delay getting back to you. Here is a screenshot of the relationship set up.
Andrew
ParticipantThink I've worked it out thanks
Andrew
ParticipantI managed to get the image via the ID.
If I'm using a loop like this
<?php foreach($teams as $p): ?>and while in the loop I useget_permalink()it gets the permalink of the parent post instead of the current post in the loop. How would I get the permalink of the current post in the loop?Andrew
ParticipantHi Peter, yes I managed to use the api in a code block and that worked as desired. Was hoping to be able to use the Oxygen repeater to do this but this seems like a limitation of either Oxygen or me.
Andrew
ParticipantLooks like they are ordering based on what team-members are set in the cpt rather than the order they are set in the relationship.
Andrew
ParticipantThanks for this. It worked perfectly 🙂
Andrew
ParticipantHi Long,
Got it working thanks to your advise. Thank you very much.
-
AuthorPosts