upload file with front-end submission and forward the data in an email

In case anyone needs this, here is my solution: if ($_FILES) { function insert_attachment($file_handler, $post_id, $setthumb = ‘false’) { if ($_FILES[$file_handler][‘error’] !== UPLOAD_ERR_OK) __return_false(); require_once(ABSPATH . “wp-admin” . ‘/includes/image.php’); require_once(ABSPATH . “wp-admin” . ‘/includes/file.php’); require_once(ABSPATH . “wp-admin” . ‘/includes/media.php’); $attach_id = media_handle_upload( $file_handler, $post_id ); //get url $attachment_url = wp_get_attachment_url($attach_id); add_post_meta($post_id, ‘_file_paths’, $attachment_url); $attachment_data = … Read more

Delete post meta front end

For anyone else looking for guidance on how to do this, I created another custom field called event_status and by using the save_post action in wordpress set a condition that once this changes to then the run delete_post_meta action as follows: function event_status_is_updated($post_id){ if(get_post_meta($post_id,’event_status’,true)==’not_complete’){ delete_post_meta($post_id,’date_dun’); } } add_action(‘save_post_event’,’event_status_is_updated’);

How to change custom post order ASC/DESC menu_order wise dynamically?

You can hook pre_get_posts and use the order_by argument of WP_Query. From a plugin or functions.php of active theme, something like the following (untested example): add_action( ‘pre_get_posts’, ‘my_post_type_sort’, 10, 1); function my_post_type_sort( $query ) { if ( is_admin || ! $query->is_main_query() ) { return; } if ( $query->get(‘post_type’) !== ‘name_of_post_type’ ) { return; } $query->set(‘orderby’, … Read more

How to add a new button on post

in the free theme Customizr, you can add content after the edit link with this code in the file functions.php of the child theme add_action(“__after_regular_heading_title”, function () { $post = $GLOBALS[“post”]; ?> <span> an addition after the link to edit “<?php echo htmlspecialchars($post->post_title);?>” </span> <?php });

Admin Bar – Customizer Label Change

You can use the get_node function and admin_bar_menu action. Like so, function edit_customizer_node( $wp_admin_bar ) { $customize = $wp_admin_bar->get_node( ‘customize’ ); if ( $customize ) { $customize->title = __( ‘Customize Theme’, ‘text-domain’ ); $wp_admin_bar->remove_node( ‘customize’ ); $wp_admin_bar->add_node( $customize ); } } add_action( ‘admin_bar_menu’, ‘edit_customizer_node’, 999 ); This can be placed in your theme’s functions.php file. … Read more