Echoing a variable inside a function

Use the Settings API. A look at my latest plugin may help you to understand how to register a save function for your fields. Most relevant excerpt: /** * Register custom settings for the fields. * * @see save_settings() * @see print_input_field() * @return void */ public function add_contact_fields() { register_setting( ‘general’, $this->option_name, array ( … Read more

Create an Array of Specific Custom Post Meta

If I’m understanding your issue correctly, and if by ‘project title’ you mean the content of the post_title field, then it’ll look something like this: $post_data = array(); $my_query = new WP_Query( $whatever_your_args_are ); if ( $my_query->have_posts() ) { while ( $my_query->have_posts() ) { $my_query->the_post(); $post_data[] = array( ‘project_title’ => get_the_title(), ‘latitude’ => get_post_meta( get_the_ID(), … Read more

Retrieve post thumbnail as array

The solution is to use wp_get_attachment_image_src. As per the Codex: $attachment_id = 8; $size=”full”; // returns an array $image_attributes = wp_get_attachment_image_src( $attachment_id, $size ); Although the return is said to be: [0] => url [1] => width [2] => height There is a fourth element that indicates if it is the full image (false) or … Read more

Resort get_categories

There is already a function in WordPress doing that: wp_terms_checklist(). It is used in the metabox for hierarchical taxonomies in the post editor. Maybe you can reuse that? The following is untested, see it just as a guide please, not as a complete solution: // File where “wp_terms_checklist()” is declared require_once ABSPATH . ‘wp-admin/includes/template.php’; // … Read more

How to save data of an input field to an array

Don’t use update_usermeta, it is deprecated, update_user_meta is the one to use. You get the previously saved value out with get_user_meta. <input type=”text” name=”group[]” id=’group[]’ class=”regular-text” value=”<?php echo esc_attr( get_user_meta( $user->ID, ‘group’, true ) ); ?>” />