'pfbc-select pfbc-post-select'); /** * Constructor * * @param string $label The field label. * @param string $name The field name attribute. * @param string $post_type Post type to query (default: 'page'). * @param string $extra_args Extra query arguments in query string format. * @param array|null $properties Optional element properties. */ public function __construct($label, $name, $post_type = 'page', $extra_args = '', ?array $properties = null) { // Initialize with empty options - will be loaded via AJAX parent::__construct($label, $name, array(), $properties); $this->post_type = $post_type; $this->extra_args = $extra_args; $this->ajax_url = admin_url('admin-ajax.php'); $this->nonce = wp_create_nonce('accua_forms_get_posts'); // Add data attributes for JavaScript $this->attributes['data-post-type'] = $this->post_type; $this->attributes['data-ajax-url'] = $this->ajax_url; $this->attributes['data-nonce'] = $this->nonce; if (!empty($this->extra_args)) { $this->attributes['data-extra-args'] = $this->extra_args; } } /** * Render the post select element * * Outputs a native select that will be enhanced by JavaScript for search/AJAX. * Falls back to a working select if JavaScript is disabled (with initial options). */ public function render() { $this->applyAriaAttributes(); // Get current value $value = ''; if (isset($this->attributes['value'])) { $value = is_array($this->attributes['value']) ? reset($this->attributes['value']) : $this->attributes['value']; } // Store selected value for AJAX to include in first page if (!empty($value)) { $this->attributes['data-selected'] = $value; } // Generate unique ID for this element (access attributes array directly) $id = isset($this->attributes['id']) ? $this->attributes['id'] : ''; if (empty($id)) { $id = 'pfbc-post-select-' . uniqid(); $this->attributes['id'] = $id; } // Start rendering echo '