Front end post form won't post categories to custom post type

Trying to get a front end post form to work with my custom post type. It posting to the post type but the 2 custom taxonomies and the tag field aren't posting/saving. Here is my CPT.               add_action('init', 'portfolio_register');       function portfolio_register() {          $labels = array(         'name' => _x('User Lists', 'post type general name'),         'singular_name' => _x('User List', 'post type singular name'),         'add_new' => _x('Add New', 'list item'),         'add_new_item' => __('Add New List'),         'edit_item' => __('Edit List Item'),         'new_item' => __('New List Item'),         'view_item' => __('View List Item'),         'search_items' => __('Search Lists'),         'not_found' =>  __('Nothing found'),         'not_found_in_trash' => __('Nothing found in Trash'),         'parent_item_colon' => ''     );          $args = array(     'labels' => $labels,     'public' => true,      'publicly_queryable' => true,     'show_ui' => true,     'query_var' => true,     'menu_icon' => get_stylesheet_directory_uri() . '/img/cutleries.png',     'rewrite' => true,     'capability_type' => 'post',     'hierarchical' => false,     'show_admin_column' => true,     'menu_position' => null,     'taxonomies' => array('post_tag', 'list_type', 'list_state'),     'supports' => array('title',         'editor',         'author',         'custom-fields',         'comments')           );          register_post_type( 'user_lists' , $args ); }          register_taxonomy("list_type", array("user_lists"), array("hierarchical" => true, "label" => "List Types", "singular_label" => "List Type", "rewrite" => true, 'show_admin_column' => true,));           register_taxonomy("list_state", array("user_lists"), array("hierarchical" => true, "label" => "List State", "singular_label" => "List State", "rewrite" => true, 'show_admin_column' => true,));      And here is my form               <?php          //EricHamby.Com          add_shortcode('feEditor', 'feEDoShortcode');         add_action('init', 'catch_save_form');          function catch_save_form()     {      $errors = array();             if('POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "new_post")     {       // Do some minor form validation to make sure there is content     if(isset ($_POST['title']))       $title =  $_POST['title'];     else       $errors[] = 'Please enter the wine name';          if(isset ($_POST['description']))       $description = $_POST['description'];     else       $errors[] = 'Please enter some notes';          $tags = $_POST['post_tags'];              // ADD THE FORM INPUT TO $new_post ARRAY            $new_post = array('post_title'      => stripslashes($title),                       'post_content'    => stripslashes($description),                       'tags_input'      => stripslashes($tags),                       'post_status'     => 'publish', // Choose: publish, preview, future, draft, etc.                         'post_type'       => 'user_lists', //'post',page' or use a custom post type if you want to                       'tax_input'    => array(                         'list_type'  => $_POST['list_type'],                         'list_state' => $_POST['list_state'],            )        );            //SAVE THE POST         $pid = wp_insert_post($new_post);            //REDIRECT TO THE NEW POST ON SAVE       $link = get_permalink( $pid );      $_POST['form_errors'] = $errors;      wp_redirect( $link );      die();          } // END THE IF STATEMENT           }             //WHERE ALL THE MAGIC HAPPENS          function feEDoShortcode()        {         if(isset($_POST['form_errors']) && !empty($_POST['form_errors']))          foreach($_POST['form_errors'] as $e)           echo '
ERROR: '.$e.'
';          ?>             <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
Submit Your List!

              <form id="new_post" name="new_post" method="post" action="" class="wpcf7-form" enctype="multipart/form-data">                       <fieldset name="name">            <input type="hidden" id="title" value="<?php echo date('F jS Y h:i:s A'); ?>" tabindex="5" name="title" />           </fieldset>

              <fieldset class="category">         <?php erichamby_custom_taxonomy_dropdown( 'list_type', 'date', 'DESC', '10', 'list_type', '', '', 'Select List Type' ); ?>       </fieldset>

              <fieldset class="category">         <?php erichamby_custom_taxonomy_dropdown( 'list_state', 'date', 'DESC', '10', 'list_state', '', '', 'Select List State' ); ?>       </fieldset>

                   <fieldset class="content space">         Description and Notes:         <?php wp_editor("", 'description', array('media_buttons' => false, )); //change media_buttons to true to allow images/videos/music ?>       </fieldset>                   <fieldset class="tags space">         Additional Keywords (comma separated):         <input type="text" value="" tabindex="35" name="post_tags" id="post_tags" />       </fieldset>                   <fieldset class="submit space">         <input type="submit" value="Post Review" tabindex="40" id="submit" name="submit" />       </fieldset>            <input type="hidden" name="action" value="new_post" />       <?php wp_nonce_field( 'new-post' ); ?>     </form>

     <?php            }             function erichamby_custom_taxonomy_dropdown( $taxonomy, $orderby = 'date', $order = 'DESC', $limit = '-1', $name, $show_option_all = null, $show_option_none = null,    $show_option_select = null ) {        $args = array(         'orderby' => $orderby,         'order' => $order,         'number' => $limit,         'hide_empty' => 0,           );        $terms = get_terms( $taxonomy, $args );       $name = ( $name ) ? $name : $taxonomy;        if ( $terms ) {         printf( '<select name="%s" class="postform">', $name );         if ( $show_option_select ) {             printf( '<option>%s</option>', $show_option_select );         }         if ( $show_option_all ) {             printf( '<option value="0">%s</option>', $show_option_all );         }         if ( $show_option_none ) {             printf( '<option value="-1">%s</option>', $show_option_none );         }         foreach ( $terms as $term ) {             printf( '<option value="%s">%s</option>', $term->slug, $term->name       );                            }                                     print( '</select>' );                                       }                     }                    //EricHamby.Com                        ?>


How to implement pagination eg. newer - 3 - 4 - 5 - 6 - 7 - older

How can I implement pagination like shown in the title perhaps something similar to most sites ![](http://imgur.com/Y2D08.jpg)


Create Table Failed Column Date DateType

I have a plugin that creates tables and one of them is failing and I feel like it's due to either my syntax or the fact that I'm trying to create a column with datatype DATE and not TIMESTAMP (only one that I can make work). Can someone look at my syntax below and tell me what is wrong?               $table = $wpdb->prefix.SSM_ACADEMIC_YEAR_TABLE;                  $sql =  "CREATE TABLE IF NOT EXISTS " . $table . " (                       id mediumint(12) NOT NULL AUTO_INCREMENT,                       description VARCHAR(200) NOT NULL,                       begin_date DATE NOT NULL,                        end_date DATE NOT NULL                     PRIMARY KEY (id));";              $wpdb->query($sql);      and now just looking at the other field in question, is it possible that it doesn't like VARCHAR(200)? Having issues here and running out of steam and time. Any help would be greatly appreciated!


Create an auto-populated menu that is automatically assigned to the primary menu in twentythirteen?

A similar question was asked about buddypress here , but I tried applying it to a twentythirteen, and I am getting this error. > Cannot use object of type stdClass as array in > /hsphere/local/home/c349026/expressbraiding.com/blog/wp-admin/menu.php on > line 25 How I can I properly apply the code bellow to a twenty thirteen child theme?                //give your menu a name      $name = 'theme default menu';      //create the menu      $menu_id = wp_create_nav_menu($name);      //then get the menu object by its name      $menu = get_term_by( 'name', $name, 'nav_menu' );      //then add the actuall link/ menu item and you do this for each item you want to add     wp_update_nav_menu_item($menu->term_id, 0, array(     'menu-item-title' =>  __('Home'),     'menu-item-classes' => 'home',     'menu-item-url' => home_url( '/' ),      'menu-item-status' => 'publish'));      // you add as many items ass you need with wp_update_nav_menu_item()          //then you set the wanted theme  location     $locations = get_theme_mod('nav_menu_locations');     $locations['LOCATION_NAME'] = $menu->term_id;     set_theme_mod( 'nav_menu_locations', $locations );      Thanks to @bainternet


Does is_child() exist in wp 3.5.1?

I'm trying to figure out how to get to a is_child() equivalent; I'd like to be able to target the parent page and it's children. How can this be achieved? My pseudo-code is...               if (is_page('pagename') || is_child('pagename')) {...}      ...however, the is_child() doesn't seem to work. I would like it to return true.


Make only the image an anchor link using the advanced excerpt plugin?

I am using the advanced excerpt plugin for Wordpress http://wordpress.org/plugins/advanced-excerpt/ so I can display images and video's in my excerpts, as opposed to just text. So my code is simply...               <?php the_excerpt(); ?>      Now if the excerpt is an image and text, I would like to make only the image tag an anchor link, not the text. If I do this...               <a href="<?php the_permalink(); ?>">         <?php the_excerpt(); ?>     </a>      ...it makes the whole excerpt an anchor link as you would expect. The trouble with this is the paragraph text then inherits the link colour which I do not want, and if I disable this colour just for this excerpt, it also disables intended anchor links. Is there any way I can do this in jQuery or PHP to select only the image in the excerpt and make it link to the corresponding blog post? Thanks in advance


How can I attach hotlinked images in posts/pages within the same server?

Not sure if this makes sense but I'm trying to attach hotlinked images to their posts/pages with no lucky, most plugins such Cache images works ok but only to external domains, I need to auto-attach hotlinked images in the same domain/server. _Addendum_ : This happened duo copying-pasting content from static html files into WP pages and posts. Thanks for any clue!


Override pluggable functions in a plugin?

WordPress has a file called `pluggable.php` which contains a list of functions you can override in your plugin. The problem I am facing (I am overriding `wp_authenticate`) is for each blog in my network I try to activate this plugin, I get: > failure, can't re-declare wp_authenticate which was previously declared in > pluggable.php This somewhat defeats the ease of use, I have to comment the function in the plugin file, activate the plugin, un-comment the function for it to work properly. What is the correct way to do it?   Can't expect users who download plugin to do all that. I am using 3.5 + multi-site configuration


How to echo the_title from an array of posts?

I'm trying to query wordpress post by using `query_posts` and trying to save them in an array so that I get retrieve the post from array. This is what I'm doing,                   $posts =array();         $args = array('posts_per_page' =>3,'cat' => 3 );         $posts[] = query_posts( $args );              global $post;         if ( ! empty($posts) ) :         foreach ($posts as $post) {         setup_postdata($post);               echo get_the_title();         }         wp_reset_postdata();         endif;         wp_reset_query();      When I run this script it shows a post which is not in `cat` 3\. but if I do `print_r($post)` it shows the correct three posts. Any idea of where I'm getting wrong?


facebook Page Publish 2

I am using acebook Page Publish 2 plugin . which is working fine. but i want to POST feature image on fb page. but it doesnot showing anything on facebook page. Does anybody tel me how to POST feature image on fb page Thanks


Extend page routing with custom parameters

In WordPress there is defined a simple routing               /%postname%/      So when I access `/projects/` it loads me `Projects` page which has specified custom `template_projects.php` template. Is it possible to extend routing but only for this template ? Let's say I want to extend routing to handle project id, so it should be:               /%postname%/%project-id%/      But other pages will work with base route.


How to prevent meta data from being edited in a post?

I need to add a 'poll' to every single post automatically, and wish to do this without having to manually create a poll each time using a plugin, so I had an idea to store the poll results as meta data in the post. So each time someone votes, it saves their vote as a custom field meta value in the post. This should work in theory, however one problem I've discovered early on is that when editing the post which contains a poll, if someone votes while I am editing and then I press Update, the results are reset back to whatever they were before I started editing, because the custom field is being saved along with the post. Is there any way to stop a certain custom field from being saved when I update a post? Or to make it retrieve the latest value before saving it?


Tags and Taxonomy links not working for Custom Post Types

In my theme, I registered a taxonomy by the name of `tax_groups` for a custom post type named `custom_items`. So the following URL was returning the lastest `custom_items` http://website.com/custom_items/ The Search widget was also working perfectly fine but not Tag and Taxonomy links like these:               http://website.com/tag/a_random_tag/     http://website.com/tax_groups/a_random_group/


Contents of HTML editor mangled after multiple UPDATES

In a perfect world, WordPress would take what I enter into the HTML editor and write it verbatim into the post/page document received by the browser. Disabling `wpautop` has already helped me slightly to this end. Alas.. **Setup:** I write some HTML into the editor and click UPDATE. My post/page is formatted correctly, but the contents of my editor have changed: `p` and `br` tags are gone, replaced respectively with actual empty lines and line breaks. When I view source, the contents of the editor `textarea` are what I originally typed, but its as if `p` and `br` tags are actually being rendered in the `textarea`. **The problem is that when I click UPDATE again (without changing anything), the post/page is formatted incorrectly, because said tags are lost.** How can I get my HTML editor contents not to be automatically mangled? I do not ever switch over to the visual editor. Just scanning through `wp- includes/formatting.php`, the function `format_to_edit` seems promising, but unsure how to proceed. **Example**   1. Enter `<p>Hello</p>` in HTML editor for new post   2. Click PUBLISH, published post is formatted correctly   3. Contents of editor changed after the PUBLISH refresh to `Hello` (p tags gone)   4. Click UPDATE, post is formatted incorrectly due to lack of p tags * * * **UDPATE** _After looking at some of the comments/answers and doing some testing, this does look like a hackery side-effect. I can't repro in a fresh install of Roots. Here are the details of my install:_   1. Customized Roots theme, no hackery.   2. Plugins: Akismet, Advanced Custom Fields, Custom Post Type UI, Google Analytics for WP


Find out if a page has no parent

Hay, have a basic menu looking like this               Item 1         Item 1.1             Item 1.1.1             Item 1.1.2         Item 1.2     Item 2         Item 2.1      I'm outputting this as a list using WordPresses "wp_list_pages()" function. This is working fine. However on the pages, i am list the subpages. So, when I'm on page "Item 1.1" it says "Other pages" and lists "Item 1.1.1" and "Item 1.1.2". I'm using               <?php wp_list_pages( array('child_of'=>get_the_ID(),'title_li'=>'') ); ?>       to do this. However, i only want this to output "other pages" on the subpage. I don't want to display the "other pages" on the top level pages (like "Item 1, Item 2"). Is there a way to see if the current page is a top level page?


post_class() breaks out of formatting. . . extra markup also generated

Hoping Im just running into something easy Here's the scenario, I've created a function called `tr_get_post_image_tplt` that spits out the post thumbnail (or custom size) for the post being called. Im calling it as follows from my front-page loop:               <a href="<?php the_permalink(); ?>"<?php post_class('thumbnail span1'); ?> ><?php tr_get_post_image_tplt('thumbnail', 'thumbnail');?>         I would expect the function to output something like:                     But instead Im getting:               class="post-864 post type-post status-publish format-quote hentry category-general thumbnail"

               Note that that the class has slipped out of the `<a>` tag and extra markup has been added. I've poured over this for hours now - so Im praying its not some silly typo. But assuming it isn't a typo can someone explain what's going on and how to avoid it in future? Here's the function, stored in a functionality plugin(though I've tried it in functions.php with the same results):               function tr_get_post_image_tplt($size='thumbnail', $class='thumbnail', $default='post-thumb-default.gif') {     global $post;          if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.         $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(), $size );              $alt_text =  get_the_title(get_post_thumbnail_id());         $tr_post_thumb = '';         //$tr_post_thumb = the_post_thumbnail($size); isn't flexable enough     }     else{         $photos = get_children( array(         'post_parent' => $post->ID,          'post_status' => 'inherit',          'post_type' => 'attachment',          'post_mime_type' => 'image',          'order' => 'ASC',          'orderby' => 'menu_order ID'         ) );         if (!empty($photos)) {             $photo = array_shift($photos);             $image_src = wp_get_attachment_image_src($photo->ID, $size);             $alt_text =  get_the_title($photo->ID);             $tr_post_thumb = '';         }         else {             // if above fails, spit out a default image             $alt_text =  get_the_title($post->ID);             $tr_post_thumb = '';               }     }     echo apply_filters('the_content', $tr_post_thumb );     }      Many thanks for sharing your experience!


Generate multiple goo.gl shortlinks for qtranslate bilingual blog

I'm working on revamping my personal blog with a custom built theme and making it bilingual with the help of qtranslate. I've gotten to a grinding halt when it comes to automatically generating the shortlinks (offered for analytics reasons). Up till now, I got the following code, based on Kovshenin's goo.gl plugin, that queries the google shorten API:               function googl_shortlink($url, $post_id) {         global $post;         if (is_404())             return;         if (!$post_id && $post) $post_id = $post->ID;              if ($post->post_status != 'publish')             return "";              $shortlink = get_post_meta($post_id, '_googl_shortlink', true);         if ($shortlink)             return $shortlink;              $permalink = get_permalink($post_id);              $http = new WP_Http();         $headers = array('Content-Type' => 'application/json');         $result = $http->request('https://www.googleapis.com/urlshortener/v1/url', array( 'method' => 'POST', 'body' => '{"longUrl": "' . $permalink . '"}', 'headers' => $headers));         $result = json_decode($result['body']);         $shortlink = $result->id;              if ($shortlink) {             add_post_meta($post_id, '_googl_shortlink', $shortlink, true);             return $shortlink;         } else {             return $url;         }     }     add_filter('get_shortlink', 'googl_shortlink', 9, 2);      and adds a nice column to my posts dashboard with a link to the analytics page:               function googl_post_columns($columns) {         $columns['shortlink'] = 'Shortlink';         return $columns;     }          function googl_custom_columns($column) {         global $post;         if ('shortlink' == $column) {             $shorturl = wp_get_shortlink();             $shorturl_caption = str_replace('http://', '', $shorturl);             $shorturl_info = str_replace('goo.gl/', 'goo.gl/info/', $shorturl);             echo "{$shorturl_caption} (info)";         }     }     add_action('manage_posts_custom_column', 'googl_custom_columns');     add_filter('manage_edit-post_columns', 'googl_post_columns');      Here's the problem: The snippet above works perfectly for a single language environment, but when it comes to going bilingual, it only generates the shortlinks for the default language. The question is: How can I make it generate the links for the second language as well? I think it's obvious that I'll need to save them in separate meta keys, but I can't find a way to make it look further than the default language.


Where is it better to start learning how to develop for Wordpress?

I have already read this question and answer to it ( Where do I start from ). So I have slightly different question. If I basicaly have no knowledge of how the WordPress code is structured and I have some ideas for plugin I would like to write should I start at the same place where author of the answer sugested in the post linked above or there is some other path? Thanks to all who will contribute to this question. P.S. I have more than 3.5 years of experience with PHP and other web technologies.


Editing custom fields for comments

I need help with why the save function is not working in the edit_comment hook. Here is the code for the 'comment_post' hook:               add_action( 'comment_post', 'save_comment_meta_data' );     function save_comment_meta_data( $comment_id ) {         if ( ( isset( $_POST['private'] ) ) && ( $_POST['private'] != '') )         $private = wp_filter_nohtml_kses($_POST['private']);         add_comment_meta( $comment_id, 'private', $private );     }      And here is the 'edit_comment' hook:               add_action( 'edit_comment', 'extend_comment_edit_metafields' );     function extend_comment_edit_metafields( $comment_id ) {         if( ! isset( $_POST['extend_comment_update'] ) || ! wp_verify_nonce( $_POST['extend_comment_update'], 'extend_comment_update' ) ) return;             if ( ( isset( $_POST['private'] ) ) && ( $_POST['private'] != '') ) :             $private = wp_filter_nohtml_kses($_POST['private']);             update_comment_meta( $comment_id, 'private', $private );             else :             delete_comment_meta( $comment_id, 'private', $private );             endif;     }      This adds a checkmark box in the edit window to make the comment private. The checkmark box appears but it does not save when I update the comment in the edit window. Any idea why?


Post edit screen: How to check if meta_box is registered?

I got some custom post types where i deregistered the "title" meta box. Now i always get "Auto Draft" as title. To avoid this i'd like to add the name of a taxonomy as the title. But how would i check if the meta box "title" exists or not?


Auto save title as custom meta field value

I create a custom post type where I removed the "Title", instead I want to use one of my custom meta value to become the title. This is just to make sure the title look good. Know that the post name post_title still exist even I remove the "Title" section, so in my function I added the code to save the title base on the custom meta value. The code working fine for the first time I save the post only. However, when I update the post, the title disappeared. What did I missed or done wrong? Thanks Update 2 This is the entire codes for meta box and save_post filter function:                   // Add meta box to editor     function add_listing_box() {         global $meta_box; // get all of the options from the $meta_box array              add_meta_box($meta_box['id'], $meta_box['title'], 'box_output', $meta_box['page'], $meta_box['context'], $meta_box['priority']);          }     add_action('admin_menu', 'add_listing_box');               function box_output () {         global $meta_box, $post;         echo '<input type="hidden" name="listing_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';         echo '
';              foreach ($meta_box['fields'] as $field) { // do this for each array inside of the fields array             // get current post meta data             $meta = get_post_meta($post->ID, $field['id'], true);                  echo '
', // create a table row for each option                     '', $field['name'], '	',                     ':	';             switch ($field['type']) {                      case 'text': // the HTML to display for type=text options                     echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:30%" />', '', $field['desc'];                     break;                           case 'textarea': // the HTML to display for type=textarea options                     echo '<textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="8" style="width:97%">', $meta ? $meta : $field['std'], '</textarea>', '', $field['desc'];                     break;                      case 'select': // the HTML to display for type=select options                     echo '<select name="', $field['id'], '" id="', $field['id'], '">';                     foreach ($field['options'] as $option) {                         echo '<option', $meta == $option ? ' selected="selected"' : '', '>', $option, '</option>';                     }                     echo '</select>',$field['desc'];                     break;                      case 'radio': // the HTML to display for type=radio options                     foreach ($field['options'] as $option) {                         echo '<input type="radio" name="', $field['id'], '" value="', $option['value'], '"', $meta == $option['value'] ? ' checked="checked"' : '', ' />', $option['name'];                     }                     break;                      case 'checkbox': // the HTML to display for type=checkbox options                     echo '<input type="checkbox" name="', $field['id'], '" id="', $field['id'], '"', $meta ? ' checked="checked"' : '', ' />';                     break;                      case 'image':                      $image = get_template_directory_uri().'/images/image.png';                      echo ''.$image.'';                     if ($meta) { $image = wp_get_attachment_image_src($meta, 'medium'); $image = $image[0]; }                     echo    '<input name="'.$field['id'].'" type="hidden" class="custom_upload_image" value="'.$meta.'" />
                          <input class="custom_upload_image_button button" type="button" value="Choose Image" />                           Remove Image
'.$field['desc'].'';                        break;                   }             echo     '',                 '
';         }              echo '
';          $title1 = get_post_meta($post->ID, 'cmf', true);           echo '<input type="hidden" name="post_title" id="post_title" value="',$title1,'" size="30" style="width:30%" />';              //here where I try to get the custom title.          }          // Save data from meta box     function for_meta_save_data($post_id,$post) {         global $meta_box;              // verify nonce -- checks that the user has access         if (!wp_verify_nonce($_POST['listing_meta_box_nonce'], basename(__FILE__))) {             return $post_id;         }              // check autosave         if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {             return $post_id;         }              // check permissions         if ('page' == $_POST['post_type']) {             if (!current_user_can('edit_page', $post_id)) {                 return $post_id;             }         } elseif (!current_user_can('edit_post', $post_id)) {             return $post_id;         }                   foreach ($meta_box['fields'] as $field) { // save each option             $old = get_post_meta($post_id, $field['id'], true);             $new = $_POST[$field['id']];             $title1 = $_POST["post_title"];             if ($new && $new != $old) { // compare changes to existing values                 update_post_meta($post_id, $field['id'], $new);                  } elseif ('' == $new && $old) {                 delete_post_meta($post_id, $field['id'], $old);                  }         }         $post->post_title = $_POST["post_title"];//here is where i try to  save post title.          }     add_action('save_post', 'for_meta_save_data'); // save the data      Well?


where to modify get_comment_author_link()?

Whenever a user presses on a comments author it redirects the user to the site which was enetered by user. I just want to add the target="_blank" element. where I can modify this? In file i see only this: get_comment_author_link()


How do increase the amount of links shown down the left in the admin menu?

I've inherited a Wordpress site that uses http://podsframework.org/ CMSframework plugin. unfortunately the previous admin created so many pods, which in turn created a lot of custom post types that have now hidden all the adminmenu link like options, themes, users etc aren't displayed anymore. So how do I get them to display?


How can I show different content for different user-levels?

Can I use is_user_logged_in to manage content for different roles? Example: If subscribevr user is logged in.... show content.... else show "you are not logged in" and on anonther page if contributor user is logged in.... show content.... else show "must be logged in or be a contributor so view this content" Does anybody know a good code I can solve this with?


How to Remove a Title from All Category and Tags Page?

I am trying to remove the title from all my category and tags page. So far, I have been using this code http://pastebin.com/xxmyw7BP. It works but not perfectly. The title of my category and tag page is removed. However, on my sidebar, the content in my recent posts widget also lose their titles. What other qualifier should I add other than is_archive() so that it strictly targets only the title on the category and tag pages? Thanks.


is this a bug or not?

When we make a custom post type (in my case 'news'(slug is news also)) and a page is with name 'News' (with slug 'news'). Then when I add some pages with parent 'news', it's displaying 404 in '%postname%' permalink setting. But it's fine with default permalink structure. I have some post types under 'news' post type also. Slug is conflicting that's why this is happening, but I wanna know is it a bug or something else ?


multiple external urls in wordpress website

I am working over a wordpress website which is basically a union of wordpress + their official website which is in php. In wordpress I am simply showing wordpress data. but when user need to create something , then user is directed to that official website. Example 1. Create new flower from the flower page (I have content page for flower) 2. Create new fruit from Fruit page I just want to know the standard way to manage all these number of external urls rather than giving a static links for all of them. Thanks


Mass crop images: Landscape images -> Portrait images

I have several images that are wider than they are tall (landscape). The problem is that the theme I'm using crops images to 150x214px (taller than they are wide). This set up works for the majority of the images but there are still several left with the sides cut off. Is there anyway I can mass-crop the images that are wider than they are tall? Here's what I mean: http://i.imgur.com/GQWMQ.jpg The image on the left is wider so the sides get cut off. I want to add height to these images so the whole product fits like the image on the right.


How does a minimal menu walker look like?

According to the docs of `wp_nav_menu` we can specify our own walker function. They suggest to copy the default one and modify it as needed. But to be honest, it is a bit too complicated for the to understand. Could you please provide a minimal example of a custom menu walker? Say, without sub menu items, without wrapping container, without all the classes applied by the default walker. Only one class, the `.current-menu- item` is important, of course. Also a way to specify the HTML element of menu items may be included.


Custom posts in different columns style

I'm trying to output a custom type posts with a sticky/featured work in a col-8 (thumbnail) and col-4 (content) then the rests of the posts should be in col-4. So far I have tried the code below but that only output all the posts, sure if I repeat the code and contain the output in col-4 its achievable but I don't think that's the best practice of doing it.               <?php             $loop = new WP_Query( array( 'post_type' => 'recentproject', 'orderby' => 'rand', 'posts_per_page' => '1') );                  ?>             <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
                 <?php edit_post_link(); // Always handy to have Edit Post Links available ?>                 <?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>                     <?php echo get_the_post_thumbnail(); ?>                 <?php endif; ?>

<?php the_title(); ?>
                 <?php echo the_content(); ?>
         <?php endwhile; ?>

             <?php             $loop = new WP_Query( array( 'post_type' => 'recentproject', 'orderby' => 'rand', 'posts_per_page' => '3') );             ?>             <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

<?php the_title(); ?>
                     <?php edit_post_link(); // Always handy to have Edit Post Links available ?>                     <?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>                         <?php echo get_the_post_thumbnail(); ?>                     <?php endif; ?>                     <?php echo the_content(); ?>
             <?php endwhile; ?>
      To explain what I intend to do see the image below. ![enter image description here](http://i.stack.imgur.com/v5OqL.png)


Wordpress Settings Lost After Site Migration

I've done my fair share of migrating Wordpress sites, but today I am completely and utterly stumped. I've worked for many hours on this, and I cannot find a solution. I hope someone here can help. I have a site that I'm trying to migrate from my local testing server to www.mysite.com (not the actual URL). On the testing server, I have my hosts file set up so my site is located at www.mysite.cam. Therefore, I can do a find-and-replace on the database without messing up serialized data (because the string lengths are the same for both URLs). I performed the usual migration routine:               1) Back everything up          2) Export testing server database to sql file.          3) Find and replace mysite.cam with mysite.com in the sql file.          4) Sync the remote directory in WinSCP          5) Import the sql file to the new database      Note: My wp-config.php file is host-independent, so it doesn't need to be changed. I use $_SERVER["HTTP_HOST"] to detect the host and use the right MySQL credentials. When I try to access my site, I've lost the main navigation menu, as well as many of my plugin settings. It looks like serialized data got messed up in the wp-options table, but (as you can see from above), nothing did. I even tried using the WP Migrate DB plugin (which can handle serialized URLs) with the exact same results. I tried doing the migration multiple times, on different URLs, with no avail. I also get some kind of database error from WP Super Cache the first time the site loads after being migrated. I tried disabling WP Super Cache, but it didn't help any of the problems. I could change the plugin settings that got messed up, but there are many plugins and many settings to change. Furthermore, I'm worried something else is broken that is not yet apparent. Here's some more info: The local (testing) site works perfectly The following plugins are installed: Comprehensive Google Map Plugin, jQuery Colorbox, Open external links in a new window, Post Types Order, Redirection, Use Google Libraries, WordPress Mobile Pack, WordPress SEO, WP-Migrate-DB, WP Super Cache (caching is currently turned off). The testing sever uses WAMP on Windows 7 The testing server version is version-controlled using Git The production server runs on GoDaddy Linux hosting Files are being transferred via SFTP on WinSCP I also tried regular FTP using FileZilla


How to set WYSIWYG editor width within wp_editor() function?

This is my current code:               $initial_data = $this->options['my_plugin_editor'];     $settings = array(         'quicktags' => array('buttons' => 'em,strong,link',),         'quicktags' => true,         'tinymce' => true,         'textarea_rows' => 20,     );     $id = 'my_plugin_editor_options[my_plugin_editor]';     wp_editor($initial_data,$id,$settings);      The problem is I am unable to set the width of the editor. I can set the height `'textarea_rows' => 20`, but I am not aware of a way how to set the width(cols). If I am using a standard textarea without an editor, this is working well `cols="120"` How to set cols in wp_editor function?


Should I use include or load_template for including shortcodes, plugins and so on?

I am wondering what is the right way to include additional php files for theme options, shortcodes, plugins and so on. Both load_template and include will work, but what has better semantic value? Thanks


Taxonomy slug by term ID

I'm trying to modify wp_nav_menu to display term thumbnails. To get those thumbnails I need term ID and taxonomy slug: `$thumbnailimg = get_the_term_thumbnail($term_id, '$taxonomy', 'medium');` I managed to get term ID for it with: `$term_id = (int)$item->object_id;` But now I need to check if that object is a term AND what custom taxonomy that term belongs to (I have 2 of them). Can anyone help me to solve this problem? :)


How to keep several local copies of a theme in sync?

I am working on several sites on a local installation of apache/mysql, using virtual hosts. I have created a child theme for twentyeleven and I want to use that child theme like a framework for all my sites locally. My question are :   1. How can I keep all the copies of my "framework" automatically up to date, in sync?   2. What would be better suited than twentyeleven to create a child theme from, and use it as a framework? Thank you


I am looking for a specialist WordPress host

I am looking for a host to start my new WordPress site. The criteria for this is that they must totally/truly specialise in WordPress hosting. Many companies claim to have a certain expertise in hosting WordPress, but the fact is they just have it installed. I would like recommendations for hosts in the UK but am open to worldwide offers.


Communicate between plugins

I have created two WordPress plugins. If both plugins are installed, some beneficial cooperation could take place between the two. So my question: what is the best way to get them to work together? How do I detect a certain plugin is enabled? How do I transmit information? I suppose I could use globals, but is there a better way?


Custom page template query_vars

I created a custom page template `movie-page.php` and a page `movie` in WP. The template shows fine when I visit **site.com/movie/** I want to add `movie_id` as a query var. Here's my code:               add_filter('query_vars', 'poe_query_vars');     function poe_query_vars( $vars ) {         $vars[] = 'movie_id';         return $vars;     }      I want to add rewrite rules so that **site.com/movie/123/** will give me movie_id=123. I'm not concerned with page numbers, although I could just use the `page` query var, I need to learn how to do this right.               add_filter('rewrite_rules_array', 'poe_rewrite_rules');     function poe_rewrite_rules($rules) {         $custom = array('movie/([0-9]+)/?$' => 'index.php?pagename=movie&movie_id=$matches[1]');         return $custom + $rules;     }      I have clicked on Save Permalinks, and can verify that the rule exists. The rule is at the top of the rules, and lower down I see the others created by the custom page template. In my movie-page.php template, I am echoing the rewrite rules, and the query vars and I can't get **/movie/123/** to give me a movie_id => 123. **Edit** \- adding the rewrite rules related to movie for reference               '/movie/([0-9]+)/([0-9]+)/?$' => 'index.php?pagename=movie&movie_id=$1&page=$2',     '/movie/([0-9]+)/?$' => 'index.php?pagename=movie&movie_id=$1',     ...     'movie/attachment/([^/]+)/?$' => 'index.php?attachment=$1',     'movie/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$1&tb=1',     'movie/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$1&feed=$2',     'movie/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$1&feed=$2',     'movie/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$1&cpage=$2',     '(movie)/trackback/?$' => 'index.php?pagename=$1&tb=1',     '(movie)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?pagename=$1&feed=$2',     '(movie)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?pagename=$1&feed=$2',     '(movie)/page/?([0-9]{1,})/?$' => 'index.php?pagename=$1&paged=$2',     '(movie)/comment-page-([0-9]{1,})/?$' => 'index.php?pagename=$1&cpage=$2',     '(movie)(/[0-9]+)?/?$' => 'index.php?pagename=$1&page=$2',     ...


Checking if some condition is matched before inserting post into database

Is there a way to check if some requirements are matched before adding new instance of custom post type to database? Like custom policies for adding new posts etc? What I want to do is to build two custom types: "Event" and "Suggestion" connected by one-to-many relationship (by Pods Framework). I want to allow admins create Events and users create Suggestions. Suggestion for specific Event can be add if admin set Post Status of this Event as "Open for suggestions". When status is changed to "Closed for suggestions", there is no way to add new Suggestion related to this Event. Is there any way too hook to some event before inserting post, that will check matching conditions and depending on result add or not post to database?


Category link redirect to custom template page instead of index.php?

I want to make template page for my custom taxonomy. I have custom taxonomy categories listed as navigation links. It's the country list (China, Slovenia, Serbia...). Every of this categories has cities as their subcategories (Belgrade, Honk Kong...). When i click on the e.g. **China** i get redirected to index.php Wordpress template file where there is some loop and scripts that show content. That is working great, but i don't want that :) I want, when i click on the category, to be **redirected on my custom template page** in which i would make some scripts that would display cities list for that country and when i click on the city i would go to index.php template and show the posts for that city! I hope you understand whatr i'm looking for! Please help!


custom post type not getting archived?

I'm used the plugin More Types to create a custom post type (News). I'm also using the plugin Smart Archives Reloaded to have an archive of my custom post type. The problem is when i click on a month which takes me to .com/2011/10 i just get a page not found. I've also added the wordpress archive widget to the sidebar just to see if it shows any of my posts, which it doesn't. If i post a normal post (one that comes built in with wordpress) that show's in the archive widget and also clicking on the month shows a page with that post on it instead of a page not found. In the More Types plugin i've set the post to archives yes. Is it possible the posts aren't getting archived and that's why i'm getting a page not found, or is this two separate issues? Thanks


How can I base a query off of the current page post type AND a meta value from another custom post type

I have 2 custom post types: Communities and Testimonials. I have a drop down menu in the Testimonials CPT that calls all of the communities. The drop down is using the ID of the community. I have a a widget that shows all the testimonials. But if I'm on a Location A page, I want to show only testimonials from Location A. I'm just not certain how to write that query. Thank you everyone in advance!


Control Custom Post Type template from a plugin

I can control the custom template to be used on custom post type pages but the template file would still need to have the markup of the theme. I was wondering if I could make it theme independent? Example: I have a plugin that registers my custom post type. I have the post meta info that I want to show in a custom template. I have that template working on my custom post type pages but the max I could do is to use get_header() & get_footer() calls but I can't deal out the need of having the theme markup between header & footer. Did that make any sense? Any ideas?


Image menu on responsive WordPress

1) Why WordPress only use based on "text" menus (navigation) only?   Maybe the answer is "it is for SEO and mobile responsive WordPress".   Am I correct? any other opinions? 2) What if I create "image navigation menu" for only PC version and create "mobile navigation and responsive" maybe select box.   Is it possible? I have found `is_mobil()` and I think it can be done. Please see this link `http:www.tourtips.com/` and see the beautiful image navigation menu. I really want to use it but I worry about mobile version.   Is there any way to keep this image menu for PC version and create another mobile or small size menu for smaller devices? if it's possible, what codes I should use? I think some of codes should be loaded depends on devices such as: `if...is_mobile()...` and CSS parts... and loading scripts... Any more things I should worry? any tips? any tutorial links?


Setting variables as custom field values

I have a function that performs some custom queries to get specific information regarding a post (children count, dates, etc). I am wondering if it is possible to send this custom query info (set as a variable) to a custom field automatically when I update the page.


Disable redirect canonical

I am trying to prevent index.php from redirecting to a file index.html which I also have in the home directry. I want the index.html file to remain there for a few days until the wordpress site is finished, being the page that visitors will see, and I'd access the new installation by adding index.php to the url; but wordpress redirects index.php to index.html meaning that I can only view the pages and posts and not the home page. I have tried putting remove_filter('template_redirect', 'redirect_canonical'); into the functions.php file but it doesnt work. Can anyone help ?


Picture inserted in the post not showing in "Gallery"

I have some posts in which I inserted the picture manually (before migrating to Worpdress)               <img src="http://www.example.com/images/2010/quand-l-inde-compte-ses-habitants,M35788.jpg" border="0" alt="" />      I want to use those pictures as "featured image", but they don't appear in the post Gallery. What is the best way to "import" them, knowing that they already are on my server ? Thanks


best practices for updating wordpress theme

Need to use a new theme for one of my Wordpress websites, but at the same time I need to also keep the current theme live whilst I make changes. What is the best practice? Should I develop the theme locally first? But that still doesn't help 100% because I need to make changes specific to the categories and posts that exist on the live site. Should I: So should I develop the theme locally then make those changes specific to my website on the live server (with a "under construction" page on while I make the changes)??


How to make modifications only to certain elements of an HTML string on the server-side?

Is there a similar way to select / perform DOM manipulation on the server-side (PHP) like the way jQuery works? For example, if I wanted to modify content of each `<pre class="raw">...</pre>` elements inside of a post content, in jQuery you can easily capture them all with:               //In jQuery, this will obtain a collection of <PRE> elements with class "raw":     $("pre.raw").each( function(index,tag) {         //Modify content of each PRE tags here...         tag.innerHTML = tag.innerHTML.replace( ..., ... );     });      In PHP however, I'm trying to do this by adding a filter to "the_content", which will then do some string replacements only inside each of those `<pre class="raw">` elements. Does WordPress already have some built-in utility method to grab elements this way? Or does some 3rd party PHP script exists that will do this?


Facebook comments box on front page

I have a WordPress 3.5.1 installation on my WordPress Shack, with the Facebook plugin 1.3.1 installed and the TwentyTwelve 1.1 theme. I have the settings on Facebook - Comments box so that I display the comments box on posts and pages. In Settings - Reading, I checked a static page as front page, "Welcome". I've checked the "Allow comments" checkbox for every page on my site. However, the Facebook comments box is displayed on every page, except the front page, "Welcome". This definitely is an issue with the front page, because if I select "latest posts" to display on the front page, the comments box is displayed on the Welcome page. How can I make that the comments box is displayed on the front page as well? I of course posted this at the WordPress support forums for Facebook, but I don't get any response.


Execute php file and display results in wordpress page

I´m not programer but I have a personal blog using wordpress and now I need to solve a proble that i describe below. I have a form build with contactform7, what i need is a way of run a php scrip that I have in a file for example called testfile.php, that gone take the file uploaded with contactform7 form testing that file and display the results in a new page with my blog theme. For now I´m in this point. I have the form and I receive an email with the file uploaded by user. In additional configuration of that for I have               on_sent_ok: "location = 'http://www.example.com/testfile.php';"      But the file isn't tested and the result from testfile.php isn´t showed with my theme, but in a new withe page.


Show Custom Fields in Quick Edit

I have several custom fields that I need my client to be able to edit at anytime. For the sake of convenience, I'd like them to be able to edit these custom fields from the Quick Edit. This way they don't have to open a bunch of new pages to go into each post. Is it possible to add editable custom fields to Quick Edit? Or am I out of luck?


Why allow overriding crucial pluggable functions wp_verify_nonce and wp_create_nonce?

Among the functions in `/wp-includes/pluggable.php` are the functions `wp_verify_nonce` and `wp_create_nonce`. Both functions are very important in the protection against CSRF-attacks. However, it is easy to override these functions in a plugin so that all nonces are accepted as valid.               if( ! function_exists('wp_verify_nonce') ) {       function wp_verify_nonce($nonce, $action = -1) {         return 1;       }     }      I have tested this, and indeed, CSRF protection is now disabled site-wide. What's the reason that these functions are put in the `pluggable.php` file if the security risks are so obvious?


WordPress appends the_content filtered text inside last paragraph tag of content (rather than after it)

Using WordPress version 3.2.1 I've noticed that when I use this filter:               add_action('the_content', 'myFunction', 0);      The content editor places the content written from "myFunction" **within** the last paragraph tag of the content. How can I force the WP to append the code **after** the last tag? For example, if my content is...
This is a paragraph
      And the "myFunction" routine appends "And this is some extra text" to the_content, the end result in the browser becomes:
This is a paragraphAnd this is some extra text
      Although I want it to be:
This is a paragraph
And this is some extra text


Is there an action for save_menu and/or update_menu?

I want to "save" my menus into transients. I want to update those when there's been any changes to the menus via the admin custom menus. I've looked for an action but can't see to find anything. Perhaps I missed the obvious?


Bloginfo hook - can it be more precise?

From the codex, regarding filter hooks:               bloginfo_url       applied to the the output of bloginfo("url"), bloginfo("directory") and bloginfo("home") before returning the information.      Is there a way I can specify that a bit more precise? So that I can hook something only to `bloginfo("url")` for example?


Apply nextgen-gallery lightbox effect

I wrote a Template which uses custom-fields via WP-MoreFields plugin. And there I add an image. In my template I display that Image like this:               <? echo wp_get_attachment_image( get_post_meta( get_the_ID(), 'afp_analysis_chart' , true), 'large' ); ?>      I also use the nextgen-gallery Plugin and configured it, so all images shell be applied the lightbox-effect. The problem is, the images displayed on this teplate are not applied. How can I force this behavior?


wp_insert_post not returning post ID?

I've had a read of the existing posts on here and still can't see why my instance is doing this, but I'm using wp_insert_post to add a post with some data it's given, and it's inserting the post just fine but the function is returning 0 in place of the post ID - does it have to be triggered to use this?                   $ember_prepare_post = array(         'post_author' => $ember_current_user_id,         'post_category' => $ember_post_category,         'post_content' => $ember_post_content,         'post_title' => $ember_post_title,         'post_status' => 'publish',         'post_excerpt' => $ember_post_excerpt,         'tags_input' => $ember_post_tags         );          // now we've prepared an array with the data, we're going to save it into the WP database and obtain the resulting post ID.          $ember_newpost_id = wp_insert_post($ember_prepare_post, true);      I'm not seeing any errors, and have had a read of the wp_insert_post function itself and cannot see why it wouldn't work. The ID's of the posts it creates definitely aren't zero, either. Thanks!


add_action(), add_filter() before or after function.

When looking through Wordpress snippets/tutorials/plugins I often see `add_action()` and `add_filter()` being placed before the function is declared:               add_action('publish_post', 'email_friends');          function email_friends($post_ID)  {        $friends = 'bob@example.org, susie@example.org';        mail($friends, "sally's blog updated" , 'I just put something on my blog: http://blog.example.com');        return $post_ID;     }      From a logic standpoint this just doesn't make sense to me. Why would you place the function after it is called in your code? This is usually how I would handle the same situation:               function email_friends($post_ID)  {        $friends = 'bob@example.org, susie@example.org';        mail($friends, "sally's blog updated" , 'I just put something on my blog: http://blog.example.com');        return $post_ID;     }          add_action('publish_post', 'email_friends');      I know both scenarios work, but is there a specific advantage to one or the other? About 90% of the time I see the first scenario being used, so that leads me to believe there is a benefit to this in some way.


My blog suddenly can't find my stylesheet?

I created a custom theme awhile back, and everything has worked fine up until now. All of a sudden, my theme was reverted back to the default twenty eleven theme because apparently my custom theme is missing it's stylesheet, but the stylesheet is clearly there. I link to it correctly and everything. I don't understand why all of a sudden it would stop working? Any suggestions?


How to give members access to their own protected page?

I'd like to give each member access to their own personal page that only I'll be able to edit. Each member will have their own personal page with private info. Do you have any suggestions on how to do this? Thank you!


Wordpress with Lan and Wan Access?

Can someone suggest tutorials on how to properly set up a wordpress multisite installation that I can access from both the LAN and WAN side? I've been looking for a bit and am unable to find what i'm looking for.   I'm using an Ubuntu server (on VirtualBox) behind my router. I have my domain name setup to forward to my router and it is port forwarding properly. But, what I really want to do is have my site (locally hosted) be accessible from the LAN as well as the WAN. Right now it's one or the other based on how I play with the dashboard>options panel... I don't mind reinstalling if it means having a proper setup.


add_action with a class method is causing fatal errors

I wasn't sure if this was a PHP issue (suited for StackOverflow) or a WordPress issue (suited for StackExchange), however since my issue **appears** to be with the `add_action()` function, I have placed the question here. Here's some simplified code which causes the same issue (to avoid re-posting my couple-hundred line plugin):               <?php     $class = new MyClass();     add_action('init', array($class, 'init'));          class MyClass {         public static function init() {             $this->core();         }         public static function core() {             echo "I never get this far...";         }     }     ?>      I get the following error: > **Fatal error** : Using $this when not in object context in > **/home/coupon/public_html/wp-content/plugins/test.php** on line **7** If my `add_action()` call were instead:               add_action('init', 'MyClass::init');      Then I would understand this error (since the function was called statically and there is no instance of DEMenu for `$this` to point to), however I don't understand why this is happening since I used an array and passed an instance of the class. My specific issue is actually related to this problem. I created a custom Walker class then used the `wp_nav_menu_args` filter to pass my custom Walker. I get this error in `class-wp-walker.php` on line **185**. The line in particular is:               $id_field = $this->db_fields['id'];      Any ideas? EDIT - `test.php` is now functioning properly, but the original issue is not solved... As such here's my plugin's index.php file (simplified):               $DEMenu = new DEMenu();          class DEMenu {              function DEMenu() {             if (is_admin()) {                 add_action('admin_menu', array(&$this, 'admin'));             } else {                 add_action('init', array(&$this, 'core'));             }         }              public function admin() {             /* Not important */         }              public function core() {             add_filter('wp_nav_menu_args', array(&$this, 'add_walker'));         }              public function add_walker( $args ) {             $args['walker'] = 'DEMenu_Walker';             return $args;         }          }          class DEMenu_Walker extends Walker_Nav_Menu {              function __construct() {             die("We made it to the constructor!");         }          }      As mentioned above, I am getting the following error: > **Fatal error** : Using $this when not in object context in > **/home/coupon/public_html/wp-includes/class-wp-walker.php** on line **185** Since the above `test.php` was failing and since the `Walker_Nav_Menu` class never has this error normally (not until I added my plugin) I figured the issue was with the one of my `add_action()` or `add_filter()` calls. However since it is still failing I'm not entirely sure where the issue is... FINAL EDIT - Carefully re-reading the `walk_nav_menu_tree()` function, I have found the issue with my walker class...               function walk_nav_menu_tree( $items, $depth, $r ) {             $walker = ( empty($r->walker) ) ? new Walker_Nav_Menu : $r->walker;             $args = array( $items, $depth, $r );                  return call_user_func_array( array(&$walker, 'walk'), $args );     }      Since `$walker` is being set to `$r->walker` it is a string, not an instance of a class. Therefore the class method is called statically instead of via an instance of the class. Instead of:               $args['walker'] = 'DEMenu_Walker';      I should have:               $args['walker'] = new DEMenu_Walker();      * * * **Task** : Call a class method as a hook for a WordPress plugin so that the `$this` variable is not broken


Can I force a password change?

When I create a new user, I would like to force that user to change their password on first log in, can this be done?


WordPress custom post type Single.php?

I have a WordPress custom post-type setup. I've created               single-[customposttype].php       However instead of displaying only the requested custom-post-type it goes to the URL, then displays all of the posts in the custom-type. Here's a copy of the code i'm currently using:               <?php query_posts("post_type=shorts"); while (have_posts()) : the_post(); ?>
         <?php echo get_post_meta($post->ID, "mo_short_embed", true); ?>

<?php the_title(); ?>
         <?php the_content(); ?>
      Thanks in advance :)


get_children() Not Working with orderby Parameter

I am trying to use the `orderby` parameter in the `get_children` function as below:               $navigation = get_children(array(       'post_parent' => $parent->ID,       'orderby' => 'menu_order'     ));      But it is having no effect on the result; it is still ordering by the default creation date. Any ideas?


wp_nav_menu li item empty

I created an menu by admin panel > Appearence > Menu. I have just one menu page in **menu_lateral_1** . Or the result is

my page
      With following code :                   $args = array(             'menu' => 'menu_lateral_1',             'container' => '',             'items_wrap' => '
%3$s
'     );     wp_nav_menu($args);      I don't understand where the first item comes ?!


How to use "TRUNCATE TABLE" MySQL statement?

I have tried dbDelta and $wpdb->query, they does not work. Does anyone has any ideas?


Ajax functions - no access to wp-admin.php only online

I'm having some trouble with my custom ajax function. I have this on my console log : "POST MYSITEURL/wp-admin/admin-ajax.php 302 Found". So my functions won't work... And I really don't understand why. I've developed a login form for the front end, it works well on my local but not online. Here is what I do :               function ajax_login_init(){     //First I register my scripts         wp_register_script('ajax-login-script', get_template_directory_uri() . '/js/ajax-login-script.js', array('jquery'),'',true );          wp_enqueue_script('ajax-login-script');     //I give them variables         wp_localize_script( 'ajax-login-script', 'ajax_login_object', array(              'ajaxurl' => admin_url( 'admin-ajax.php' ),             'redirecturl' => '/account'         ));          }          function allowAjaxLogin(){     //I allow the function             add_action( 'wp_ajax_nopriv_ajaxlogin', 'ajax_login' );             add_action( 'wp_ajax_priv_ajaxlogin', 'ajax_login' );          }     add_action( 'init','allowAjaxLogin' );               if (!is_user_logged_in()) {         add_action('init', 'ajax_login_init');     }          function ajax_login(){     // First check the nonce, if it fails the function will break         check_ajax_referer( 'ajax-login-nonce', 'security' );         // Nonce is checked, get the POST data and sign user on         $info = array();         $info['user_login'] = $_POST['username'];         $info['user_password'] = $_POST['password'];         $info['remember'] = $_POST['remember'];              $user_signon = wp_signon( $info, false );         if ( is_wp_error($user_signon) ){             echo json_encode(array('loggedin'=>false, 'message'=>__('Wrong username/password')));         } else {             echo json_encode(array('loggedin'=>true, 'message'=>__('Success)));         }              die();     }      As I said, it works well on my local version, but not online, someone can help me?


Inline Editing with wp_editor and tinymce (problem with textarea)

I want to use the new inline editing from tinymce with the wp_editor function in wordpress. Here is some info on how to set up tinymce inline editing http://www.tinymce.com/tryit/inline.php The code I am using to call wp_editor is as follows:               $editor_settings = array('dfw' => true,'quicktags' => false);     wp_editor( $postcontent, 'postcontent', $editor_settings );      And in functions.php I have the following to enable inline editing:               function mce_inline( $init ) {              $init['inline'] = true;              return $init;     }     add_filter('tiny_mce_before_init', 'mce_inline');      The problem here is that wp_editor is calling the editor and setting up a textarea. In order for tinymce inline editing to work correctly, we need to remove the textarea and replace it with a `editable` div element as tinymce.com says so.               <div class="editable" style="width:100%; height:550px">     This is an editable div element element.     </div>      Thus, my question is, how can I configure wp_editor so it replaces the textarea with a div element?


If or/and statement advanced custom fields

I'm really unexperienced when it comes to conditonal statements with php and unfortunately the documentation of Advanced Custom Fields isn't covering this topic as fair as I know. But anyway, what I'm trying to do is to display some markup and custom fields but only if one of the fields or both fields have data. For example I have a footer that could display an email address and/or website link. If both custom fields are not filled with data the footer markup shouldn't be displayed. If there's an email address and/or website link available it should display the footer markup and of course the data of the fields. This is what I currently have:                         <?php if( get_field('website') ): ?>          <a href="<?php the_field('website'); ?>"><?php the_field('website'); ?>          <?php endif; ?>               <?php if( get_field('emailaddress') ): ?>          <a href="mailto:<?php the_field('emailaddress'); ?>"><?php the_field('emailaddress'); ?          <?php endif; ?>                                                 But this code displays the footer markup even if both custom fields are not available. How can I make it that the footer markup is only shown if one of both of the custom fields have a value? If been trying to do it with an || statement but that returns an unexpected T_BOOLEAN_OR error               <?php if( get_field('website') ) || ( get_field('emailaddress') ): ?>          // do this          <?php endif; >      If anyone knows if this is possible, how to do this or could point me in the right direction that would be much appreciated.


Display site administrator's id by current blog id inside link

I need to add current subsite admin id on the end of the ref link. For example 1.example.com site admin id is 4 - the link displayed on 1.example.com should look like http://example.com/?ref=4 The working code (thx to @birgire):               <?php     function reflink_func( $atts ){     $uids = get_users(         array(             'blog_id'  => get_current_blog_id(),             'role'     => 'administrator',             'fields'   => 'ID',         )     );          $url = add_query_arg(          array( 'ref' => join( ',', $uids ) ),          'http://biznesvozmozhnost.ru/registration/?ref='      );          $link = 'Link text';          return $link;     }          add_shortcode( 'reflink', 'reflink_func' );     ?>


Wildcard search in WP Query

I am trying to do something like this:               $args = array(     'post_type' => 'product',     'meta_query' => array(         array(             'key' => 'custom-text-field',             'value' => '%rocket%',             'compare' => 'LIKE'         )     )     );     $query = new WP_Query( $args );      My goal being that the query will search through all the text of the `custom- text-field` and return any post where `rocket` is found. However it isn't working (I either get all the posts or no results). Is this possible directly in the `WP_Query` or do I need to use `$wpdb` to construct something first?


Custom post type rewrite with_front

What I'm setting up, I thought would be quite simple. In fact, I'm sort of amazed that the answer didn't just pop up after a half hour of searching here. Here is the code to create my CPT:               register_post_type('headline', array(     'labels'                => array(         'name'                  => 'Headlines',         'singular_name'         => 'Headline',         'add_new'               => 'Add Headline',         'add_new_item'          => 'Add Headline',         'edit_item'             => 'Edit Headline',         'new_item'              => 'New Headline',         'all_items'             => 'All Headlines',         'view_item'             => 'View Headline',         'search_items'          => 'Search Headlines',         'not_found'             =>  'No matching headlines found',         'not_found_in_trash'    => 'No matching headlines found in Trash',          'parent_item_colon'     => '',         'menu_name'             => 'Headlines'         ),     'description'           => 'Headlines from around the world.',     'public'                => true,     'supports'              => array('title', 'editor', 'author', 'excerpt', 'thumbnail', 'trackbacks', 'comments', 'revisions'),     'taxonomies'            => array('category', 'post_tag'),     'register_meta_box_cb'  => 'DfePostTypesHeadline::add_meta_boxes',     'has_archive'           => true,     'rewrite'               => array(         'with_front'    => false     ),     'can_export'            => true     ));      The problem is the "with_front" call. Or rather, with the rewrite rules themselves. I've got my `flush_rewrite_rules()` call happening on plugin activation/deactivation. And I can see that the .htaccess file _is_ getting rewritten, so it's working. But WordPress still cannot recognize my new permalink structure. I'm not sure if this is relevant or not, but my register_post_type call is happening on the "init" hook. I'm wondering if a different hook is necessary?               /* Giddyup */     public function DFEPostTypes() {         add_action( 'init', 'DFEPostTypes::register_content_types' );         add_action( 'admin_menu', 'DFEPostTypes::admin_pages' );         add_action( 'admin_enqueue_scripts', 'DFEPostTypes::admin_scripts' );         add_filter( 'template_include', 'DFEPostTypes::template' );         // Flush rewrite rules:         register_activation_hook( __FILE__, 'DFEPostTypes::flush_rewrite' );         register_deactivation_hook( __FILE__, 'DFEPostTypes::flush_rewrite' );     }      `register_content_types()` is the function that handles dynamically calling and registering the content types I work with.


Pagination on category page with custom post types

Wordpress is not new for me but I am really stuck on this piece of code that I can not get to work properly. I register a custom post type **News** and let the custom post type use the Wordpress categories               'taxonomies' => array('category')      So far so good. I can assign different categories to the custom post type News. But I want that people can see news from a specific category. So I want that to do that with the category.php page. The problem is that the pagination is not working. I get a page not found when I go to /page/2 I use this code on a category.php page.               // Get post ID     $post_type = get_post_type( $post->ID );          // Get category ID     $category_id = get_cat_ID(single_cat_title('', false));          // Wordpress pagination     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;          // WP_Query arguments     $args_news = array (         'post_type'             => array( 'news' ),         'pagination'            => true,         'posts_per_page'        => '9',         'orderby'               => 'date',         'paged'                 => $paged,         'cat'                   => $category_id,     );          // The Query     $query = new WP_Query( $args_news );          // The Loop     if ( $query->have_posts() ) {         while ( $query->have_posts() ) {             $query->the_post(); ?>

<?php the_title(); ?>

<?php the_content(); ?>

     <?php }          } else {          // no news found     }     ?>

<?php previous_posts_link( 'Newer Posts' );?>

<?php next_posts_link( 'Older Posts', $query->max_num_pages ); ?>

          <?php     // Reset postdata     wp_reset_postdata();


How to tranform Headlines into linkable permalinks?

My Wordpress site has fairly long entries and includes many data visualisations. I want to make it easier for visitors to refer to a specific part of a page and therefore would like to make it easy to link to a specific headline. I would like to make it possible for the visitors to link to the 'id' of a headline. I think the perfect solution is the one at GitHub. For example a link like this: `https://example.com/foo/bar#anchor-name`. When you hover over any headline a small symbol signals that you can link to this position in the document. The closest thing I've found is this plugin, which only works for Posts. **Edit:** Thanks for the very helpful comments! In the end I managed to do it with the help of the mentioned add-ids-to-header-tags-plugin. I changed it so that it also works for pages by using               if ( ! is_singular() ) {      instead of               if ( ! is_single() ) {      . If someone is interested in what the result looks like, here is the page I'm using it for: http://www.explainingprogress.com/data/population-growth-vital- statistics/child-mortality/


How to Capture Postback Data in Wordpress

Scenario: A registered user clicks a link in a Custom Page inside the Wordpress Dashboard, redirects to a third party website, he completes the action, the third party websites returns to another page inside the Dashboard and a POSTBACK data with UserID and other details are posted to a Postback.php file. Now, how do i integrate the postback.php inside the Wordpress so that i can update those data in the database for the corresponding logged in user. Edit: I searched in Google. Link: http://davidwalsh.name/wordpress-recent-posts Is it okay if i add include('wp-load.php'); in the generic postback.php file where i can load wordpress functions and mysql queries which updates the database outside wordpress?


Undefined variable: row?

I'm trying to select the `post_title` from `wp_posts` with a query which I did using this method:                    global $wpdb;          $test = $wpdb->get_var(              $wpdb->prepare(" SELECT post_title FROM {$wpdb->wp_posts}" )          );          echo "$test";      EDIT: It now gives me:               Notice: Undefined property: wpdb::$wp_posts in /../../../../wp-includes/wp-db.php on line 566          Warning: Missing argument 2 for wpdb::prepare(), called in /../../../../wp-content/themes/pms72/page-home.php on line 73 and defined in /../../../../wp-includes/wp-db.php on line 992


Help with my first Metabox helper class

I'm working on a metabox helper class and everything works well, but the radio image field. The images show up, but they aren't clickable.                       // Print radio_image input.         private function radio_image_input( $field ) {                  $selected_value = $field['value'];                  $radio_image_field = '';             $radio_image_field .='                                                           ';             if ( ! empty( $field['choices'] ) ) {                 foreach ( (array) $field['choices'] as $value => $label )                     $radio_image_field .= sprintf(                         '<input type="radio" name="%s" id="%s" value="%s" style="display:none;"/>',                         esc_attr( $field['id'] ),                         esc_attr( $value ),                         esc_attr( $value ),                         esc_html( $label )                     );             }                  return $radio_image_field;         }      I think the problem is the JS, but I couldn't figure out why/where. The full class is here:               if ( ! class_exists( 'TheUx_Metabox_API' ) ) {              class TheUx_Metabox_API {                  // Holds options for menu page.             var $options = array();                  // Holds settings fields data.             var $fields = array();                  // Supported input field types to white label while saving.             var $supported_fields = array();                  // Holds current folder path.             var $dir_path;                  // Holds current folder URI.             var $dir_uri;                       function __construct( $options = array(), $fields = array() ) {                      // Set directory path.                 $this->dir_path = str_replace( '\\', '/', dirname( __FILE__ ) );                      // Set directory uri.                 $this->dir_uri  = trailingslashit( home_url() ) . str_replace( str_replace( '\\', '/', ABSPATH ), '', $this->dir_path );                      // Default page options.                 $options_default = array(                     'metabox_id'    => '',                     'metabox_title' => '',                     'post_type'     => '',                     'context'       => 'normal',                     'priority'      => 'high',                 );                      $this->options = wp_parse_args( $options, $options_default );                 extract( $this->options );                      // Titles and slugs should not be empty.                 if ( empty( $metabox_id ) || empty( $metabox_title ) || empty( $post_type ) )                     return false;                      // Set input fields.                 $this->fields = (array) $fields;                      // Default field options.                 $field_default = array(                     'title'    => '',                     'type'     => '',                     'desc'     => '',                     'choices'  => array(),                     'multiple' => false,                     'sanit'    => '',                 );                      // To eliminate PHP warning we need to set default empty values.                 foreach ( $this->fields as $key => $field )                     $this->fields[ $key ] = wp_parse_args( $field, $field_default );                      // Set list of input field types. We are white labeling these field types while saving meta.                 $this->supported_fields = (array) apply_filters( 'theux_metabox_api_supported_fields', array(                      'text',                      'textarea',                      'radio',                      'radio_image',                      'checkbox',                      'select',                      'multicheck',                      'upload',                      'color',                      'editor'                  ));                      add_action( 'add_meta_boxes', array( $this, 'register_metabox' ) );                 add_action( 'save_post', array( $this, 'save_metabox' ), 10, 2 );                      add_action( 'admin_head', array( $this, 'color_picker_js' ) );                 add_action( 'admin_head', array( $this, 'upload_js' ) );             } // end of __construct                       /**              * HTML helper functions.               * A simple HTML helper functions to generate the form fields.              */                  // Print Help/descripting for field.             private function help_text( $field ) {                 if ( empty( $field['desc'] ) )                     return '';                      return '
' . wp_kses_data( $field['desc'] ) . '
';             }                  // Returns the form table html.             public function get_form_table( $fields, $show_help = true ) {                      $form_table = '';                 $form_table .= '
';                      foreach ( (array) $fields as $field )                     $form_table .= $this->get_table_row( $field, $show_help );                      $form_table .= '
';                      return apply_filters( 'theux_metabox_api_form_table', $form_table, $fields, $show_help );             }                  // Echo/display the HTML form table.             public function display_form_table( $fields, $show_help = true ) {                      echo $this->get_form_table( $fields, $show_help );             }                       // Returns the table row html.             public function get_table_row( $field, $show_help ) {                      $table_row = '
';                     $table_row .= sprintf( '%s	', esc_attr( $field['id'] ), $field['title'] );                     $table_row .= sprintf( '%s	', $this->get_field( $field, $show_help ) );                 $table_row .= '
';                      return apply_filters( 'theux_metabox_api_table_row', $table_row, $field, $show_help );             }                       // Returns a input field based on field options.             public function get_field( $field, $show_help = true ) {                      $field_default = array(                     'title'    => '',                     'id'       => '',                     'type'     => '',                     'default'  => '',                     'choices'  => array(),                     'value'    => '',                     'desc'     => '',                     'sanit'    => '',                     'multiple' => false, // for multiselect fiield                 );                      $field = wp_parse_args( $field, $field_default );                 $input_html = '';                      switch ( $field['type'] ) {                     case 'text'       : $input_html .= $this->text_input( $field ); break;                     case 'textarea'   : $input_html .= $this->textarea_input( $field ); break;                     case 'select'     : $input_html .= $this->select_input( $field ); break;                     case 'radio'      : $input_html .= $this->radio_input( $field ); break;                     case 'radio_image': $input_html .= $this->radio_image_input( $field ); break;                     case 'checkbox'   : $input_html .= $this->checkbox_input( $field ); break;                     case 'multicheck' : $input_html .= $this->multicheck_input( $field ); break;                     case 'upload'     : $input_html .= $this->upload_input( $field ); break;                     case 'color'      : $input_html .= $this->color_input( $field ); break;                     case 'editor'     : $input_html .= $this->editor_input( $field ); break;                 }                      if ( $show_help && 'checkbox' !== $field['type'] )                     $input_html .= $this->help_text( $field );                      return apply_filters( 'theux_metabox_api_input_field', $input_html, $field, $show_help );             }                  // Displays a input field based field options             public function display_field( $field, $show_help = true ) {                 echo $this->get_field( $field, $show_help );             }                       // Print text input.             private function text_input( $field ) {                 return sprintf(                     '<input type="text" name="%s" id="%s" value="%s" class="regular-text"/>',                     esc_attr( $field['id'] ),                     esc_attr( $field['id'] ),                     esc_attr( $field['value'] )                 );             }                  // Print textarea input.             private function textarea_input( $field ) {                 return sprintf(                     '<textarea name="%s" id="%s" rows="5" cols="40">%s</textarea>',                     esc_attr( $field['id'] ),                     esc_attr( $field['id'] ),                     esc_textarea( $field['value'] )                 );             }                  // Print select input.             private function select_input( $field ) {                 $selected_value = $field['value'];                 $multiple = ( true == $field['multiple'] || 'true' == $field['multiple'] ) ? true : false ;                      if ( $multiple )                     $field['id'] = $field['id'] . '[]';                      $select_field = sprintf(                     '<select name="%s" id="%s"%s>',                     esc_attr( $field['id'] ),                     esc_attr( $field['id'] ),                     ( $multiple ? ' multiple' : '' )                 );                      if ( ! empty( $field['choices'] ) ) {                     foreach ( (array) $field['choices'] as $value => $label ) {                         $selected = $multiple ? selected( in_array( $value, (array) $selected_value ), true, false ) : selected( $selected_value, $value, false );                         $select_field .= sprintf(                             '<option value="%s"%s>%s</option>',                             esc_attr( $value ),                             $selected,                             esc_html( $label )                         );                     }                 }                      $select_field .= '</select>';                 return $select_field;             }                  // Print checkbox input.             private function checkbox_input( $field ) {                 return sprintf(                     '<input type="checkbox" name="%s" id="%s"%s> %s',                     esc_attr( $field['id'] ),                     esc_attr( $field['id'] ),                     checked( $field['value'], 'on', false ),                     __( $field['desc'] )                 );             }                  // Print radio input.             private function radio_input( $field ) {                 $selected_value = $field['value'];                 $radio_field = '';                      if ( ! empty( $field['choices'] ) ) {                     foreach ( (array) $field['choices'] as $value => $label )                         $radio_field .= sprintf(                             '<input type="radio" name="%s" id="" value="%s"%s> %s
',                             esc_attr( $field['id'] ),                             esc_attr( $value ),                             checked( $selected_value, $value, false ),                             esc_html( $label )                         );                 }                      return $radio_field;             }                  // Print radio_image input.             private function radio_image_input( $field ) {                      $selected_value = $field['value'];                      $radio_image_field = '';                 $radio_image_field .='                                                                       ';                 if ( ! empty( $field['choices'] ) ) {                     foreach ( (array) $field['choices'] as $value => $label )                         $radio_image_field .= sprintf(                             '<input type="radio" name="%s" id="%s" value="%s" style="display:none;"/>',                             esc_attr( $field['id'] ),                             esc_attr( $value ),                             esc_attr( $value ),                             esc_html( $label )                         );                 }                      return $radio_image_field;             }                       // Print multi-checkbox input.             private function multicheck_input( $field ) {                 $selected_value = (array) $field['value'];                 $multicheck_field = '';                      if ( ! empty( $field['choices'] ) ) {                     foreach ( (array) $field['choices'] as $value => $label )                         $multicheck_field .= sprintf(                             '<input type="checkbox" name="%s[]" id="" value="%s"%s> %s
',                             esc_attr( $field['id'] ),                             esc_attr( $value ),                             checked( in_array( $value, $selected_value ), true, false ),                             esc_html( $label )                         );                 }                      return $multicheck_field;             }                  // Print upload input.             private function upload_input( $field ) {                      // We require to enqueue media uploader scripts and styles.                 wp_enqueue_media();                      return sprintf(                     '<input type="text" name="%s" id="%s" value="%s" class="regular-text hd-upload-input"/>' .                     '<input type="button" value="%s" class="hd-upload-button button button-secondary" id="hd_upload_%s"/>',                     esc_attr( $field['id'] ),                     esc_attr( $field['id'] ),                     esc_attr( $field['value'] ),                     __( 'Upload', 'theux' ),                     esc_attr( $field['id'] )                 );             }                  // Print color picker input.             private function color_input( $field ) {                      // We require to enqueue color picker scripts and styles.                 wp_enqueue_style( 'wp-color-picker' );                 wp_enqueue_script( 'wp-color-picker' );                      $default_color = empty( $field['default'] ) ? '' : ' data-default-color="' . esc_attr( $field['default'] ) . '"';                      return sprintf(                     '<input type="text" name="%s" id="%s" value="%s" class="hd-color-picker"%s/>',                     esc_attr( $field['id'] ),                     esc_attr( $field['id'] ),                     esc_attr( $field['value'] ),                     $default_color                 );             }                  // Print tinymce editor input.             private function editor_input( $field ) {                 $settings = array(                     'media_buttons' => false,                     'textarea_rows' => 5,                     'textarea_cols' => 45,                 );                      $content = $field['value'];                 $content = empty( $content ) ? '' : $content;                      ob_start();                 wp_editor( $content, $field['id'], $settings );                 return ob_get_clean();             }                            /**              * Main functions.               * The follow functions will register, print, save and sanitise the metabox.              */                  // Register metabox.             function register_metabox() {                      extract( $this->options );                 foreach ( (array) $post_type as $type )                     if ( post_type_exists( $type ) )                         add_meta_box( $metabox_id, esc_html( $metabox_title ), array( $this, 'display_metabox' ), $type, $context, $priority );             }                  // Print metabox content.             function display_metabox( $post ) {                      foreach ( (array) $this->fields as $meta_key => $meta_field ) {                     $this->fields[ $meta_key ]['id'] = $meta_key;                     $this->fields[ $meta_key ]['value'] = get_post_meta( $post->ID, $meta_key, true );                 }                      wp_nonce_field( $this->options['metabox_id'] . '_' . $post->ID, $this->options['metabox_id'] . '_' . $post->ID . '_nonce' );                 do_action( 'theux_metabox_api_metabox_before', $this->options, $this->fields );                      echo '
options['metabox_id'] ) . '">';                     $this->display_form_table( $this->fields, true );                 echo '
';                      do_action( 'theux_metabox_api_metabox_after', $this->options, $this->fields );             }                  // Save metabox.             function save_metabox( $post_id, $post ) {                      extract( $this->options );                      if ( ! isset( $_POST[ $metabox_id . '_' . $post_id . '_nonce' ] ) || ! wp_verify_nonce( $_POST[ $metabox_id . '_' . $post_id . '_nonce' ], $metabox_id . '_' . $post_id ) )                     return $post_id;                      if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )                     return $post_id;                      $post_type = get_post_type_object( $post->post_type );                      if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) )                     return $post_id;                      foreach ( (array) $this->fields as $meta_key => $meta_field ) {                          $meta_field['id'] = $meta_key;                          // White label field types                     if ( ! in_array( $meta_field['type'], $this->supported_fields ) )                         continue;                          $post_value = isset( $_POST[ $meta_key ] ) ? $_POST[ $meta_key ] : '';                     $new_value = $this->sanitize_value( $post_value, $meta_field );                     $old_value = get_post_meta( $post_id, $meta_key, true );                          if ( ( $new_value || 0 == $new_value ) && $new_value != $old_value )                         update_post_meta( $post_id, $meta_key, $new_value, $old_value );                     elseif ( '' == $new_value && $old_value )                         delete_post_meta( $post_id, $meta_key, $new_value );                 }                      do_action( 'theux_metabox_api_save_metabox', $post_id, $post );             }                  // Sanitize metabox value.             function sanitize_value( $new_value, $field ) {                      if ( ! isset( $field['sanit'] ) )                     $field['sanit'] = '';                      switch ( $field['sanit'] ) {                          case 'int' :                         return is_array( $new_value ) ? array_map( 'intval', $new_value ) : intval( $new_value );                         break;                          case 'absint' :                         return is_array( $new_value ) ? array_map( 'absint', $new_value ) : absint( $new_value );                         break;                          case 'email' :                         return is_array( $new_value ) ? array_map( 'sanitize_email', $new_value ) : sanitize_email( $new_value );                         break;                          case 'url' :                         return is_array( $new_value ) ? array_map( 'esc_url_raw', $new_value ) : esc_url_raw( $new_value );                         break;                          case 'bool' :                         return (bool) $new_value;                         break;                          case 'color' :                         return $this->sanitize_hex_color( $new_value );                         break;                          case 'html' :                         if ( current_user_can( 'unfiltered_html' ) )                             return is_array( $new_value ) ? array_map( 'wp_kses_post', $new_value ) : wp_kses_post( $new_value );                         else                             return is_array( $new_value ) ? array_map( 'wp_strip_all_tags', $new_value ) : wp_strip_all_tags( $new_value );                         break;                          case 'nohtml' :                         return is_array( $new_value ) ? array_map( 'wp_strip_all_tags', $new_value ) : wp_strip_all_tags( $new_value );                         break;                          default :                         return apply_filters( 'theux_metabox_api_sanitize_option', $new_value, $field, $setting );                         break;                 }             }                  // Sanitize hex color (taken from WP core).             function sanitize_hex_color( $color ) {                      if ( '' === $color )                     return '';                      if ( preg_match('|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) )                     return $color;                      return null;             }                       /**              * Enqueue helper functions.               * These functions will load the necessary javascript code.              */                  // Color picker.             public function color_picker_js() {                      echo '';                  } // End of function color_picker_js()                  // Upload image.             public function upload_js() {                 echo '';             } // End of function upload_js()                   } // TheUx_Metabox_API end     }; // class_exists check      A example how to use:               $layoutimg = array(         'default'       => get_template_directory_uri() . '/assets/images/'.'mb-default.png',         'one-col'       => get_template_directory_uri() . '/assets/images/'.'mb-1c.png',         'two-col-left'  => get_template_directory_uri() . '/assets/images/'.'mb-2cl.png',         'two-col-right' => get_template_directory_uri() . '/assets/images/'.'mb-2cr.png'     );          // ========     // = Post =     // ========          $example_options_post = array(         'metabox_title' =>  __('Layout Options','domain'),// Metabox Title         'metabox_id'    => 'post_metabox',   // Unique metabox id. it is alphanumeric and does not contains spaces.         'post_type'     => 'post',       // Post Type : you can also define as array. array( 'post', 'page' )         'context'       => 'normal',                    // Metabox Context. Should be any of these 'normal', 'advanced' or 'side'         'priority'      => 'high',                      // Metabox Priority. Should be any of these 'high', 'core', 'default' or 'low',     );          $example_fields_post = array(         'hd_radio_meta' => array(             'title'   => __('Layout','domain'),             'type'    => 'radio_image',             'choices' => $layoutimg,             'desc'    => ''.__('Select the layout you want on this specific page.','domain').'',             'sanit'   => 'nohtml',         )        );          $example_metabox_post = new TheUx_Metabox_API( $example_options_post, $example_fields_post );