Remove value from array within post meta ajax admin

You’re not printing anything from the AJAX callback. Trying using wp_send_json_success: function ajaxtestdel(){ global $post; $currentPdfs = get_post_meta( $post->ID, ‘pdf_upload_url’, true ); $postValue = isset($_POST[‘postid’]) ? $_POST[‘postid’] : ”; $array_without_strawberries = array_diff($currentPdfs, array($postValue)); update_post_meta( $post->ID, ‘pdf_upload_url’, $array_without_strawberries ); // Send something back to AJAX wp_send_json_success(); } I have a feeling that perhaps your jQuery selector … Read more

Is it possible to restrict access to specific pages in the admin area based on the page slug?

So following from the comment discussion, a sufficient answer on another StackEx question goes like this: add_filter( ‘parse_query’, ‘exclude_pages_from_admin’ ); function exclude_pages_from_admin($query) { global $pagenow,$post_type; if (is_admin() && $pagenow==’edit.php’ && $post_type ==’page’) { $query->query_vars[‘post__not_in’] = array(’21’,’22’,’23’); } } The only part that’s terribly important to us is the array of post IDS. The problem is … Read more

WordPress wraps span tags into p tags

I have investigated this problem and recognized that it is not the TinyMCE fault, but the issue is caused by the the hook function wpautop instead. And tags are wrapped just before post is being displayed. So in order to fix this issue just remove the hook function like that. remove_filter( ‘the_content’, ‘wpautop’ ); This … Read more

Add ‘page template’ column to dashboard for CPTs

<?php // add new column to the columns array function wpse267793_columns($columns) { // Column name $columns[‘template’] = ‘Template file’; return $columns; } function wpse267793_show_template_columns($name, $post_id) { // get template file name from post meta $template = get_post_meta($post_id, ‘_wp_page_template’, true); echo $template; } // change ‘CPT’ to the relevant custom post type add_filter(‘manage_CPT_posts_columns’, ‘wpse267793_columns’); add_action(‘manage_CPT_posts_custom_column’, ‘wpse267793_show_template_columns’, … Read more

WordPress Screen options does not show any fields

Ok, found it. Not really WordPress related but might be helpful to someone anyway. It was my browser ad blocker plugin. Apparently it adds CSS to pages upon loading. The CSS showed as “inline” in the dev tools inspector but didn’t show at all when viewing page source code. When checking the CSS of the … Read more

WordPress Admin Menu Order for ‘admin.php’ pages

Instead of this: return array( ‘index.php’, // Dashboard ‘separator1’, // –Space– ‘edit.php?post_type=page’, // Pages ‘edit.php’, // Posts ‘edit.php?post_type=portfolio’, // Portfolio ‘admin.php?page=wpcf7’, // Contact Form 7 ‘upload.php’, // Media ‘edit-comments.php’, // Comments ); try this: return array( ‘index.php’, // Dashboard ‘separator1’, // –Space– ‘edit.php?post_type=page’, // Pages ‘edit.php’, // Posts ‘portfolio’, // Portfolio ‘wpcf7’, // Contact Form … Read more