Polylang not translating Metabox fields [closed]

Turn off custom fields syncronisation on polylang. I would also then add specific code to tell polylang to copy (not sync) the metas upon translation creation (so when you click ‘+’ it will also copy the metas, but changing the metas after this, won’t sync with other translations): add_filter(‘pll_copy_post_metas’, ‘copy_post_metas’, 10, 2); function copy_post_metas($metas, $sync){ … Read more

Sanitizing text fields in array

The best way to sanitize text fields within WordPress is to use sanitize_text_field() function: $data = sanitize_text_field( $_POST[‘key’] ); Additionally, if you register the meta field properly width register_meta() function, you can define the sanitize callback and the expected data type as well. For example: add_action( ‘init’, ‘cyb_register_meta_fields’ ); function cyb_register_meta_fields() { $args = array( … Read more

How to convert select to HTML with PHP tags inside of it [closed]

An example: your code <option value=”0″ ‘ .selected($horizon_featured,’normal’,false) .’>Descending</option> HTML code with some PHP mixed in: <option value=”0″ <?php echo .selected($horizon_featured,’normal’,false); ?>>Descending</option> Basically, you just put a <?php echo $something;?> where you want the PHP stuff to be.

Edit Parent page drop menu when creating a page

You can use the page_attributes_dropdown_pages_args filter to remove whatever you want. It’s based off of the wp_dropdown_pages() arguments so you can use the exclude parameter to remove certain pages or a fake parent to remove all the pages: /** * Filter the arguments of Page Attributes Parent Dropdown * * @param Array $args – List … Read more

Save meta value as an array of arrays

If you don’t need to query on the data, you can pass arrays directly to the post meta functions, WordPress will automatically serialize/unserialize the data for you. $your_array = array( array( ‘title’ => ‘something’, ‘price’ => ‘something’, ), array( ‘title’ => ‘something’, ‘price’ => ‘something’, ), ); update_post_meta( $post_id, ‘your_key’, $your_array );

Add custom metabox to media library images

Sure! Just follow this guide and make these changes: Hook into the add_meta_boxes_attachment action instead of the add_meta_boxes action In the add_meta_box() call, pass ‘attachment’ as the $screen parameter Hook into the save_post_attachment action instead of the save_post action And of course, make sure to customize the example code to your specific needs.