WordPress.org

Ready to get started?Download WordPress

Forums

Simple Fields
Pages select in extension API (2 posts)

  1. Rafael Garcia Lepper
    Member
    Posted 1 year ago #

    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

    http://wordpress.org/extend/plugins/simple-fields/

  2. Pär Thernström
    Member
    Plugin Author

    Posted 1 year ago #

    Hi! Cool to hear that you're writing you own field using the Extension API! Also, sorry for taking so long to answer. Did you solve this or do you still need help? If you still need help, could you explain your problem a bit more in detail? I didn't quite understand what the problem with the select-dropdown was..

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic