Pages select in extension API
-
Hi,
I’m using the Extensión API to create a link field type that should have a text field and either a textfield or a select with all the pages (selectable from checkboxes on the editor) to choose from where the option value should be the permalink. This post type is meant to make my client’s life easier not having to copy and paste the permalink when it’s an internal link.
I’m having trouble integrating the dinamically generated selectbox with the sprintf php function that the API uses specially generating this bit.
isset($saved_values["funkyDropdown"]) && ($saved_values["funkyDropdown"] == "[each permalink should be here]" ) ? "selected" : ""
Would really appreciate it if you could give me some guidance. How would you suggest I create it?
this is my edit_output function now which is giving me the warning sprintf(): Too few arguments
function edit_output($saved_values, $options) { // Get the WP pages array $pages = get_pages(); // Create the input and open the select $format = '<input type="text" name="%1$s" value="%2$s"> <select name="%3$s" id="%3$s"> <option value="" %4$s>Choose ...</option> '; // n is where the % number starts counting $n = 5; // Loop through the results, and output an HTML list foreach ( $pages as $page ) { // filter a few pages if(!($page->ID =! '28' || $page->ID == '10' || $page->ID == '8' || $page->ID == '2' || $page->ID == '16' || $page->ID == '18')){ // Option value $format .= '<option value="' . get_permalink( $page->ID ).'"%'.$n++.'$s>'; // Option text (post slug) $format .= $page->post_title; // Close option $format .= '</option>'; // Fill the values array to retrieve the saved values $the_values_array[] = isset($saved_values["funkyDropdown"]) && ($saved_values["funkyDropdown"] == get_permalink( $page->ID ) ) ? "selected" : ""; } } // Close the select $format .= '</select>'; return sprintf( $format, $this->get_options_name("name"), $this->get_options_id("name"), empty($saved_values["name"]) ? esc_attr($options["textDefaultName"]) : esc_attr($saved_values["name"]), $this->get_options_name("funkyDropdown"), $this->get_options_id("funkyDropdown"), $the_values_array ); } }
Thank you very much
- The topic ‘Pages select in extension API’ is closed to new replies.