get $post (object,parts/values) in meta-box

Do not rely on globals like get_the_ID() or get_post() do. Use the parameters for your callbacks. You get the current post object twice: When you register the metabox, you get the post object as a second parameter. When your output callback is called, you get it as the first parameter. Here is an example showing … Read more

Alternative to esc_textarea

esc_textarea shouldn’t strip out newlines — It’s just a thin wrapper around htmlspecialchars: http://core.trac.wordpress.org/browser/tags/3.3.2/wp-includes/formatting.php#L2536 <?php function esc_textarea( $text ) { $safe_text = htmlspecialchars( $text, ENT_QUOTES ); return apply_filters( ‘esc_textarea’, $safe_text, $text ); } That said, there are lots of options. What do you want your users to do have the ability to post? esc_html will … Read more

save_post not working with attachments

Not really, attachments are still not “full post types”. Manny Flerumond hints this quite well in this thread: Was thinking about this the past few days: currently any media files uploaded to a WordPress site defaults to the post status of inherit, which is a holdover to when media attachments were just that. Media was … Read more

Add_meta_box not appearing, but does appear in screen options

You missed one argument in the $args for add_meta_box. The correct use would be (Codex): add_meta_box( $id, $title, $callback, $post_type, $context, $priority, $callback_args ); You forgot to set the context, add it and you should be fine. add_meta_box( ‘content-on-page’, ‘Content On Page’, ‘ila_render_meta_box’, ‘page’, ‘normal’, // add this line ‘high’ );

Select box saves but doesn’t update value in admin

The second parameter of selected() has to agree with the value attribute of the current <option>. So assuming you have stuffed $selected with the value given by the relevant get_post_meta(), the following should work for you: <label for=”myplugin_meta_box_select”>Status:</label> <select name=”myplugin_meta_box_select” id=”myplugin_meta_box_select”> <option value=”Approved” <?php selected( $selected, ‘Approved’ ); ?>>Approved</option> <option value=”In Progress” <?php selected( $selected, … Read more

How to search by metadata using REST API

How can I search it by metadata? As far as I know, there’s no standard/built-in way of doing that (for the time being). But with custom coding, you can make it possible: You can append a city to the query string: /wp-json/wp/v2/horario_busao?city=London And then use the rest_{$this->post_type}_query filter to set the meta key/value pair which … Read more

How to add a SAVE button to replace PUBLISH on a custom post type?

Not mine but modified from here. But if you pop this into functions.php or a plugin it will work. add_filter( ‘gettext’, ‘change_publish_button’, 10, 2 ); function change_publish_button( $translation, $text ) { if ( ‘yourcustomposttype’ == get_post_type()) if ( $text == ‘Publish’ ) return ‘Save’; return $translation; }