mystile fatal error call to a member function is_visible() on a non-object

Wordpress version: 3.5.2 Woocommerce version: 2.0.13 Following is the code that is giving the error. The code is of product search. Although the function reads search by tag it doesn't. It searches based on other criterias taken from the checkboxes and drop down menus. In the code below, I've mentioned the line because of which the error started, by commenting besides it.               add_filter('the_posts', 'search_by_product_tag');          function search_by_product_tag($posts, $query = false)     {     //var_dump($_GET);     //$new_posts = array();     if($_GET['sh']=='search')     {     $search_tags = array(         'destination' => $_GET['destination'],          'days' => $_GET['days'],         'budget' => $_GET['budget']     );     //var_dump($search_tags);die();     $ignoreIds = array(0);     foreach($posts as $post)     {         $ignoreIds[] = $post->ID;     }     $matchedTags = get_post_by_tag($search_tags, $ignoreIds);     //var_dump($matchedTags);     if ($matchedTags)      {         foreach($matchedTags as $product_id)         {                $posts[] = get_posts($product_id->object_id);         }     }     return $posts;       }     if($_GET['f']=='filter')     {     //$filter_tags = array(         if(isset($_GET['price'])){             $price_range = $_GET['price'];               $price = $price_range;         }         else{             $price = "";         }              if(isset($_GET['holiday'])){             $holiday_type = $_GET['holiday'];                $holiday = implode("','", $holiday_type);         }         else{             $holiday = "";         }              if(isset($_GET['tour'])){             $tour_category = $_GET['tour'];              $tour = implode("','", $tour_category);         }         else{             $tour = "";         }       /*$ignoreIds = array(0);       foreach($posts as $post)       {          $ignoreIds[] = $post->ID;       }*/       $new_post = array();       //$matchedTags = get_post_by_filter_tag($price_range,$holiday_type,$tour_category, $ignoreIds);      $matchedTags = get_post_by_filter_tag($price,$holiday,$tour, $ignoreIds);      //var_dump($matchedTags);die();      if ($matchedTags)       {         foreach($matchedTags as $product_id)         {                $new_post[] = get_posts($product_id->ID); //Error was given after I added this line instead of the default given below             //$posts[] = get_post($product_id->id);         }     }     return $new_post;     die();     }          return $posts;     }     function get_post_by_tag($tags, $ignoreIds)      {     //Check for      global $wpdb, $wp_query;      $ignoreIdsForMySql = implode(",", $ignoreIds);     //var_dump($ignoreIdsForMySql);          //dynamic query     $query = "select distinct tr.object_id from $wpdb->terms t         inner join $wpdb->term_taxonomy tt on t.term_id = tt.term_id         inner join $wpdb->term_relationships tr on tt.term_taxonomy_id = tr.term_taxonomy_id         inner join $wpdb->posts p on p.ID = tr.object_id         inner join $wpdb->postmeta pm on p.ID = pm.post_id         and t.name IN ('".$tags['destination']."','".$tags['days']."')         where pm.meta_key = '_price' and pm.meta_value = '".$tags['budget']."'         and p.post_status = 'publish'         and p.post_type = 'product'         and (p.post_parent = 0 or p.post_parent is null);";          //var_dump($query);     //Search for the sku of a variation and return the parent.      $matchedProducts = $wpdb->get_results($query) ;          //var_dump($matchedProducts);     if(is_array($matchedProducts) && !empty($matchedProducts))     {     //var_dump($matchedProducts);     $wp_query->found_posts += sizeof($matchedProducts);     //var_dump($wp_query->found_posts, sizeof($matchedProducts));     return $matchedProducts;          }           //return get_post($product_id);          return null;     }          //function get_post_by_filter_tag($price_range,$holiday_type,$tour_category,$ignoreIds)       {     function get_post_by_filter_tag($price,$holiday,$tour,$ignoreIds)     {     //Check for      global $wpdb, $wp_query;     //$ignoreIdsForMySql = implode(",", $ignoreIds);     /*$price = $price_range;     $holiday = implode("','", $holiday_type);     $tour = implode("','", $tour_category);*/     //var_dump($ignoreIdsForMySql);          //dynamic query     $query = "select distinct p.ID from $wpdb->terms t          inner join $wpdb->term_taxonomy tt on t.term_id = tt.term_id         inner join $wpdb->term_relationships tr on tt.term_taxonomy_id = tr.term_taxonomy_id         inner join $wpdb->posts p on p.ID = tr.object_id         inner join $wpdb->postmeta visibility on p.ID = visibility.post_id             and visibility.meta_key = '_visibility'         and (visibility.meta_value = 'visible' or visibility.meta_value ='search')         inner join $wpdb->postmeta pm on p.ID = pm.post_id         and t.name IN ('".$holiday."','".$tour."')         where pm.meta_key = '_price' and pm.meta_value <= $price         and p.post_status = 'publish'         and p.post_type = 'product'         and (p.post_parent = 0 or p.post_parent is null);";             //Search for the sku of a variation and return the parent.      $matchedProducts = $wpdb->get_results($query) ;           var_dump($matchedProducts);//die();     if(is_array($matchedProducts) && !empty($matchedProducts))     {       //var_dump($matchedProducts);     $wp_query->found_posts += sizeof($matchedProducts);     //var_dump($wp_query->found_posts, sizeof($matchedProducts));     //var_dump($wp_query);     return $matchedProducts;          }          //return get_post($product_id);          return null;     }


Custom image size not regenerating when image editted

I have a custom image size at 200x150 that works fine in a plugin I'm working on. Uploading new files is no problem but when I edit an image, the default image sizes get regenerated but my custom size does not. Is there a way to force the regeneration programatically in a filter or something?


Order posts with a custom field but also without

I am querying and ordering posts with this code but my theme adds the custom field (cb_vote_nb_vote) only if someone clicks the "vote" button, since I am doing a listing, posts created without that custom field under a specific category must also be displayed. How do I achieve that?               global $wp_query;     $paged = $wp_query->get('paged') ? : 1;     $posts_per_page = 10; // feel free to change this     $args = array(     'cat'            => 47,     'meta_key'       => 'cb_vote_nb_vote',     'orderby'        => 'meta_value',     'order'          => 'DESC',     'paged'          => $paged,     'posts_per_page' => $posts_per_page     );     $query = new WP_Query( $args );     if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();          $current_order = ( $query->current_post + 1 ) + ( $posts_per_page * ( $paged - 1) );     echo 'Current post order is :' . $current_order;          endwhile; endif;     wp_reset_postdata();


How Do I Use The Wordpress Plugin Posts 2 Posts by Scribu?

I have a Wordpress site that relies on relationships quite heavily. It's a record label website where artists can be related to tours, reviews, album releases and store items throughout the site. I found the plugin Posts to Posts by Scribu which seems to do what I want, but I don't understand how to use it properly. Scribu has posted example code, but for some reason I just cannot understand it. Here is an example of what I want to do with the site I am working on. **Tours Page.** A tour item has a title and a custom meta field called 'tickets_link' Upon loading the tours page, all tours will be shown with their assigned artist and if it has a tickets link, then show that as well. If someone here can understand the code posted on Scribu's site for the plugin and then explain it to me, I would gratefully appreciate it. * * * **Here is my code from the functions.php file registering the connections:**                   function my_connection_types() {         if ( !function_exists('p2p_register_connection_type') )             return;              p2p_register_connection_type( 'tours', 'artists' );         p2p_register_connection_type( 'homepage_carousel', 'artists' );         p2p_register_connection_type( 'duka', 'artists' );         p2p_register_connection_type( 'products_carousel', 'artists' );     }       add_action('init', 'my_connection_types', 100);      * * * **Pseudo code to show what I want to do in my code:**   * Fetch all tours in my tours custom post archive using a loop that gets all tours added to the site.   * Each tour is related to an artist, so display all tours for a particular artist.   * Items are in the form of a heading (artist name) and each item is a tour that has been related to a particular artist in the backend using the metabox that shows as a result from registering a connection. * * * **Further update along with code I am using and print_r values.** I have the related artists showing up in my print_r contents of my query where before I didn't. When I do a print_r I get the following that shows up, but no way of accessing the data.               [connected_connected] => Array ( [0] => stdClass Object ( [ID] => 245 [post_author] => 1 [post_date] => 2011-03-10 13:55:23 [post_date_gmt] => 2011-03-10 13:55:23 [post_content] => [post_title] => 1200 Techniques [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => 1200-techniques [to_ping] => [pinged] => [post_modified] => 2011-03-10 13:55:23 [post_modified_gmt] => 2011-03-10 13:55:23 [post_content_filtered] => [post_parent] => 0 [guid] => http://localhost/testdev/?post_type=artists&p=245 [menu_order] => 0 [post_type] => artists [post_mime_type] => [comment_count] => 0 [p2p_id] => 2 [p2p_from] => 215 [p2p_to] => 245      **The code I am using to relate artists with tours is the following:**               $connected = new WP_Query(array(         'post_type' => 'tours',         'nopaging' => true,         'each_connected' => array(             'post_type' => 'artists',             'nopaging'  => true,         ),         'suppress_filters' => false     ));          while( $connected->have_posts() ): $connected->the_post();         the_title();         echo "
";     endwhile;             print_r($connected); // Print_r for showing contents of post object.      * * * **Update for Scribu:**               $args = array     (         'post_type'        => 'tours',         'nopaging'         => true,         'suppress_filters' => false     );          $connected = new WP_Query($args);          while($connected->have_posts()): $connected->the_post();              the_title();         echo "
";              foreach ($connected->connected AS $tour_item)         {             echo get_the_title($tour_item->ID);             echo "
";         }          endwhile;


How To Get Search Term and Use in Function

I'm trying to write a function that will 'grab' the search term entered into the blog search form, and then hook the function to the `get_search_query` filter like this `add_filter('get_search_query','myFunction');` so that everytime a search is made, 'myFunction' runs and grabs the search term (or so I think), I have this line in myFunction to grab the search term `$search_term = get_search_query();` but it seems to be causing problem, the blog doesn't display, except I comment that particular line out. What is the right way to achieve the subject. Thanks. Here is the code:               function myFunction(){     global $wpdb;     $search_term = get_search_query();     $table = $wpdb->prefix . "tableName";      $insert = "INSERT into $table(`serach_term`) VALUES ('$search_term')";     $wpdb->query($insert);        }          add_filter('get_search_query','myFunction');


Customizing Walker_Nav_Menu - Trunicating spaces

I've just started learning to code WP themes pretty much from scratch and I'm trying to figure out how to pass a variable thru a customized Walker_Nav_Menu but without any ascii spaces. The goal is to create an ouput like this:

              Menu 1         Menu 2           This pulls the 'Menu 1', 'Menu 2' text from the name of the menu, the title from the Menu description which displays on a second line below using a nifty little bit of CSS I wrote               a,a:after{content: ' ' attr(title);text-decoration:none;color:rgb(115,115,115);}      And the id also comes from the title and I just slap 'Btn' on the end.. this is for some javascript I'm doing. So far I've gotten it almost there, except, as expected, the id is outputting as               id="Contact MeBtn"      Here's my walker:               class Menu_With_Description extends Walker_Nav_Menu {     function __construct() {         add_filter( 'wp_nav_menu_args', array( __CLASS__, 'items_wrap' ) );     }          static function items_wrap( $args ) {         $args['container'] = '';         $args['items_wrap'] = '

                                 %3$s';         $args['fallback_cb'] = '__return_false';         return $args;     }          function start_lvl( &$output, $depth = 0, $args = array() ) {         $indent = str_repeat("\t", $depth);         $output .= "\n$indent
\n";     }          function end_lvl( &$output, $depth = 0, $args = array() ) {         $indent = str_repeat("\t", $depth);         $output .= "$indent
\n";     }          function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {         $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';         $class_names = $value = '';         $classes = empty( $item->classes ) ? array() : (array) $item->classes;         $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );         $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';         $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';         $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';         $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';         $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';         //$attributes .= $id . $value . $class_names;         $attributes .= $value;         $item_output = ! empty( $args->before ) ? $args->before : '';         $item_output .= 'description . 'Btn"'. $attributes . 'title="' . $item->description . '">';         $item_output .= ! empty( $args->links_before ) ? $args->links_before : '';         $item_output .= apply_filters( 'the_title', $item->title );         $item_output .= ! empty( $args->links_after ) ? $args->links_after : '';         $item_output .= '';         $item_output .= ! empty( $args->after ) ? $args->after : '';         $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );     }          function end_el( &$output, $item, $depth = 0, $args = array() ) {         $output .= "\n";     }     }      I'm sure this is probably written far from perfect, as I mentioned I just started.. I'm just happy that it's producing the output I'm looking for. But off topic constructive critique is also appreciated. Thanks.


'post' only for editor and administrator

How can I make it so that only Administrator and Editor could access 'post' post-type? (just like 'page' post-type) I'm planning to only let Author and Contributor use the Custom-Post-Type which I've prepared beforehand...


Parent cpt/child custom post type URL permalink relationship

I am attempting to set up a relationship in Wordpress between two custom post types I’ve created and display that relationship within each post type’s permalink URL structure. I have created two custom post types of **_solution_cpt_** and **_solution_offering_cpt_**. There is a one to many relationship from _’solution_cpt’_ to _’solution_offering_cpt’_. In other words, every _’solution_offering_cpt’_ will never have more than one parent _’solution_cpt’_. This is a one–to–one relationship. _The way I am relating each ‘solution_offering_cpt’ post to it’s pseudo ‘solution_cpt’ parent post is with a custom taxonomy. Every time a ‘solution_cpt’ post is created, I have a function that will create a new term and add it to my custom taxonomy. Of course, if the ‘solution_cpt’ post is deleted at a later date, then I also have a function to remove that term from the taxonomy._ The URL structure I am attempting to create is:               /solution/solution_cpt/solution_offering_cpt      The first level of `/solution/solution_cpt` is working and points to the correct post on the site. (The page it uses in my theme is 'single- solution_cpt.php'.) It's the URL to the second post type (ie. `/solution/solution_cpt/solution_offering_cpt`) that isn't working correctly and giving me a 404 error. (PS. I've flushed my permalinks several times.) Here is how I’ve registered my two custom post types and set up my custom taxonomy:               // Register post types     function ta_create_post_types() {         register_post_type(‘solution_cpt’, $labels,             ‘hierarchical’ => false,             'public' => true,             'has_archive' => false,             'rewrite' => array('slug' => 'solution'),             'capability_type' => 'post'         );         register_post_type('solution_offering_cpt', $labels,             'hierarchical' => false,             'public' => true,             'has_archive' => false,             'rewrite' => array('slug' => 'solution/%solution_cat%'),             'capability_type' => 'post'         );     }     add_action('init', 'ta_create_post_types', 0);          // Create custom taxonomy     function ta_create_custom_taxonomies() {         register_taxonomy('solution_cats', array('solution_cpt', 'solution_offering_cpt'), $labels,             'hierarchical' => true,             'query_var' => true,             'rewrite' => array('slug' => 'solution')         );     }     add_action('init', 'ta_create_custom_taxonomies', 0);      I also have two functions that control adding & removing terms from the _'solution_cats'_ custom taxonomy when a new _'solution_cpt'_ post is created or removed respectfully. I can post that code if it would benefit someone. ...just wanted to keep this initial inquiry as short as possible. _Note: that the terms that are created have mirrored titles and slugs of the created 'solution_cpt'. So, for example, if I were to create a 'solution_cpt' post of title "Creative Services", then a term would automatically be created and added to the taxonomy with a title of "Creative Services" and its slug set to "creative-services"._ I'm assuming I need to use the Wordpress Rewrite API to pull of the URL structure I'm needing. Again, that structure is:               /solution/solution_cpt/solution_offering_cpt      Here's the current rewrite code I have:               // Build the 'solution_offering_cpt' URL     function ta_add_rewrite_rules() {         global $wp_rewrite;              $wp_rewrite->add_rewrite_tag('%solution_cat%', '([^/]+)', 'solution_cat=');         $wp_rewrite->add_permastruct('offering', 'solution/%solution_cat%', false);     }     add_action('init', 'ta_add_rewrite_rules');          function filter_solution_offering_cpt_link($link, $post) {         if ($post->post_type != 'solution_offering_cpt')             return $link;              if ($cats = get_the_terms($post->ID, 'solution_cats'))             $link = str_replace('%solution_cat%', array_pop($cats)->slug, $link);             return $link;     }     add_filter('post_type_link', 'filter_solution_offering_cpt_link', 10, 2);      All I get is a 404 error when trying to navigate to a _'solution_offering_cpt'_ post. An example is I have created a _'solution_cpt'_ post of title "Creative Services" and slug "creative- services", and a _'solution_offering_cpt'_ post of title "UI/UX" and slug "ui- ux". When I navigate to `/solution/creative-services/ui-ux` I get a 404 error. I've flushed my permalinks. Not sure where I'm going wrong, but I'm sure my rewrites are off. The Wordpress Rewrite API is a bear and the documentation is terrible!! Would greatly appreciate help on this one guys & gals. Thanks!


Preview own posts if logged in

I want to make it so anyone logged in can view their own posts if draft or pending via the URL `?p=post_ID&preview=true`. What is the best way to do this?


Uncaught ReferenceError: the_ajax_script is not defined . How is this not defined?

I'm using this example as a guide link to ajax example i'm using to my plugin example. I get `Uncaught ReferenceError: the_ajax_script is not defined` in the JS console . I've put my JS in the main php file. The PHP that processes a response in a separate php file, as eventually I'm going to replace this simple example with calculations. I don't understand what I've done wrong. As far as i'm aware I've defined ajax **My code:** _**activate2.php (main file)_**                 function add_my_css_and_my_js_files(){         wp_enqueue_script('jquery-validate-min', plugins_url('jquery_validate_min.js', __FILE__ ) );          wp_enqueue_script( "the-calcs", plugins_url('the_calcs.php', __FILE__ )) ;      }     add_action('wp_enqueue_scripts', "add_my_css_and_my_js_files");           function include_jQuery() {         if (!is_admin()) {             wp_enqueue_script('jquery');         }     }     add_action('init', 'include_jQuery');          add_action( 'init', 'register_shortcodes' );     function register_shortcodes() {         add_shortcode( 'displaycalcs', 'mp_calcs_display' );     }          function mp_calcs_display() {         echo 'click me';              $output = <<<HTML     <form action="" method="post" name="formsubmit" id="formsubmit"   >
 Process

 operation type always robot
       Number of welds: <input type="number" name="numberofwelds" id="numberofwelds"  >       Number of construction welds: <input type="number" name="numberofconwelds" id="numberofconwelds"  >       Total one: <input type="text" name="totalone" id="totalone" disabled>

        Total two: <input type="text" name="totaltwo" id="totaltwo" disabled>

        Total three: <input type="text" name="totalthree" id="totalthree" disabled>

        <input type="submit"  value="Calculate" id="submit" name="submit">

     </form>           HTML;         return $output; }        **the_calcs.php (processes the ajax response)**               function test_ajax_load_scripts() {     wp_localize_script( 'activate2', 'the_ajax_script', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );       }     add_action('wp_enqueue_scripts', 'test_ajax_load_scripts');              function text_ajax_process_request() {             if ( isset( $_POST["post_var"] ) ) {             $response = $_POST["post_var"];             echo $response;             die();         }     }     add_action('wp_ajax_test_response', 'text_ajax_process_request');


Specific theme for non logged in users

I want to make an specific theme for non logged in users, but I don´t know how to make the function or plugin to shift the theme for them, and left another specific theme for logged in users. Anyone knows how to do this? The only clues I had are the functions `switch_theme` and `is_user_logged_in`, but don´t know how to make them work to do this. Thanks for your time.


Connect to a remote database for wordpress in my own hosting server

Yesterday I had asked this question but it was down voted due to the rules of this forum. Anyway, this is my learning and I really thank to the moderators who down voted this as they helped me to gain the tips. My problem is that, I have two domains in my host server **Hostgator** in the name of **damiracle.net** ( _as I am not authorized to give more than one hyperlink I have to write like this way_ ) and **damiracle.biz**. **The databases of damiracle.biz are frequently accessible to my employees**. I have to host a **wordpress website** in one of my directories in **damiracle.biz** ( _since there are no possibilities to host that particular website in damiracle.net_ ). But **I need to secure the database** of that particular website in one of the directories in damiracle.biz. In that case what I thought is that, I would host the database in damiracle.net and all the wordpress files in the damiracle.biz so that **my database remains secured** from my employees access. In the wp-config file of the wordpress website in damiracle.biz I have mentioned in the following way:               define('DB_NAME', 'the_db_name_of_the DB_inside_damiracle.net');          define('DB_USER', 'the_db_user_name_of_the DB_inside_damiracle.net');          define('DB_PASSWORD', 'the_password_of_the DB_inside_damiracle.net');          define('DB_HOST', 'ip_address_of_damiracle.net');      Since I have to set the Remote MySQL so I had set the ip-address of damiracle.net I had also tried setting the DB_HOST by writing damiracle.net:port No. instead of IP address But still I face the Database connection error. Can anyone please help? Thanks in advance.


my self hosted blog

After I transferred to wordpress.org and became independent and I now run my own self - hosted blog, my old blog posts just don't show up when I click on their title. Nothing is missing of them, they're all there, but when I click on their title I get a white page !! Is there something I should have done ? Like with the settings ? Or did I click on something wrong? Please help it's very terrifying :( Please and thank you.


wp_update_post based function works on existing posts, but not new posts

I have a function that will update the title of the post based on an 'advanced custom field'. It works on existing posts, but not when I create a new post. When I try and save the post and check the post listings, it isn't there. Any help would be greatly appreciated.               function my_post_title_updater( $post_id ) {              if ( get_post_type() == 'equipment' ) {                  $my_post = array();             $my_post['post_title'] = get_field( 'item_name', $post_id );                  wp_update_post( $my_post );              }          }          // run after ACF saves the $_POST['fields'] data     add_action('acf/save_post', 'my_post_title_updater', 20);


Display avatar with comment form?

I can display the current user's avatar alongside the comment form when posting a new comment with               $current_user = wp_get_current_user();     if ( ($current_user instanceof WP_User) ) {       echo get_avatar( $current_user->user_email, 32 );       }      ,but how could I bind the avatar to the comment form if I want to reply to another comment when the onclick `addComment.moveForm` is fired? The avatar should move along with the form as it moves. I would be very grateful if someone can point me in the right direction how to dynamically alter the comment form. Documentation on customizing the comment form at Wordpress.org is really poor and I have had a hard time finding any useful info around the internet as well.


a better menu, menu options assistance for WP

So long story short, im a noob WP dev and im like on my 2nd custom WP site so sorry if i sound a bit lost. As i was doing my first WP custom site, i noticed that for example, on the default theme and any other themes i tried out, when you add a menu item that has child options, they wrap under the parent option, think drop down menu. or like this               PARENT OPTION-1  PARENT OPTION-2  PARENT OPTION-3      CHILD OPT 1      CHILD OPT 2      etc, Now when making my own theme, when i manually put in the `<?php wp_nav_menu(); ?>` hook and add in the menu items dynamically via WP cpanel, my menu child items come out like this               PARENT OPTION-1                    PARENT OPTION-2  PARENT OPTION-3            CHILD OPTION1    CHILD OPTION2      As you can see, parent option 1s child menu options are horizontal, and the other menu parent items get pushed way to the side. Now when i leave menu items without child menu items, then the menu looks fine, its when child options are added that it becomes wonky. What im wanting to know is, what can i do to make it like it appears in the default themes? you know, to make it work like normal? Any tips/tricks/links and good explanations/help etc i gladly appreciate. EDIT*** looking at this deeper, the child menu items always show as opposed to only displaying on parent items mouseover. Thanks in advanced. http://somdowprod.net/


I want to add a class to main div on a template. how can I do that?

I'm building a template for twentyten child theme. I need to add a class in in the template page, but not in other pages.My template inherits the header and footer, so, I can't change any markup there. How can I add a class in there without adding that class to other pages? Thanks a lot for the help.


Resizing only featured images while uploading

I was taking a backup of my wp-content folder. But when I noticed size of uploads folder. I was astonished and each image used in my blog had 5 copies with different sizes in that folder. All these totaled to 7GB in 2 months. This way it won't take long to fill a server storage. I have a lot of image gallery posts. I didn't knew this that each image in wordpress is resized and kept in different sizes and thought only featured images went through resizing. So, is there a way that wordpress only resizes featured images?


Multiple Comment Threads + Form on one page

i was wondering if somebody has any reference on how to have a wp page with two totally separate wp comment threads + form side by side without using iframes. its a concept page that is basically a pro/con endless comment mashup. before i go into coding i was just wondering if anybody has some ideas/suggestions on how to go about this? thank you


XML Imported Custom Posts

I have an xml feed populating a custom post type. I need the custom post type to add the first imported image as the featured image. I have come across the following function and adapted it:               add_action('add_attachment', 'autoset_featured');     add_action('transition_post_status', 'autoset_featured');               function autoset_featured() {         global $post;             if ($post->post_type == 'property') {                 $already_has_thumb = has_post_thumbnail($post->ID);                     if (!$already_has_thumb)  {                         $orderby = 'post_date';                         $order = 'ASC';                         $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&orderby=$orderby&order=$order&numberposts=1" );                                 if ($attached_image) {                                     foreach ($attached_image as $attachment_id => $attachment) {                                     set_post_thumbnail($post->ID, $attachment_id);                                     }                                 }                     }             }       }      I need it to work so that the featured image is set at the time of the xml import/custom post creation. I have also tried all the following action hooks and various filters but none have worked:               add_action('add_attachment', 'autoset_featured');          add_action('the_post', 'autoset_featured');     add_action('save_post', 'autoset_featured');          add_action('draft_to_publish', 'autoset_featured');     add_action('new_to_publish', 'autoset_featured');     add_action('pending_to_publish', 'autoset_featured');     add_action('future_to_publish', 'autoset_featured');     add_action('attachment_fields_to_save', 'autoset_featured');      Currently the featured image is not being set at the time of post creation. If I open a custom post and click update - it works a dream. But it is unrealistic to have to open and update every post each day. Any suggestions? The import is set by a cron job. Does anyone know of a cron job to update all posts - I could set this 15 minutes after the original import.


Restrict my pages from public

In my site I want to restrict some pages from public. How can I do this?                   example : www.xyz.com/members      This pages only access when the user is log in but now its access public also using coping that url. If any plugins available in this?


Is there a way to lock certain pages from being edited by anyone other then the admin?

I have built a wordpress site and theme and have several pages that I do not want editors to edit. However, there are other pages that I want them to have access to edit. Is there a plugin or code that will lock certain pages from being edited by anyone other than the admin?


filter search result with custom post type meta key

The default search returns all post types, which is what I want. But for one specific custom post type I want to limit the result to a specific meta key value (a custom date that must be greater than today). Using the pre_get_posts hook and setting the meta_query does get me the correct result for that post type, but it also filters out all post types that do not have that key set. Is it possible to use the meta_query only for one specific cpt? That should be clear enough but here's some code nonetheless:               function searchExcludeOldMatches($query) {         if (!is_admin()&&$query->is_search) {             $query->set('meta_query', array(                 array(                     'key' => 'cpt-match-date'                     ,'value' => date('Y/m/d',time())                     ,'type' => 'DATE'                     ,'compare' => '>'                 )             ));         };         return $query;     };     add_filter('pre_get_posts','searchExcludeOldMatches');


post formats - how to get the relevant content part?

The following post formats got a specific type of content part that should get displayed:   * Audio   * Video   * Link ## Questions: **A)** What is the exact content (element) that is meant to get displayed for video & audio? **B)** How would you get the relevant part of the post content that represents the post format? **C)** What would you do with the rest of the content? **D)** How would you know which format a audio/video player needs as there's nothin built in? * * * _Note (ad C): How would a user know that she/he should only post eg. a "link" (post format) and not a link inside a text?_ _Note (ad D):As already asked by @bueltge there's no player._


How to get dynamic data in page hierarchy?

I'm trying to mimic the page hierarchy rules of WP. I'm checking for the existence of certain files, then requiring them if they exist -- in the same order as I understand the hierarchy rules. Here's a snippet:               if (is_author() === TRUE)     {         if (file_exists('_author-NICENAME.php') === TRUE)         {             require '_author-NICENAME.php';         }         elseif (file_exists('_author-ID.php') === TRUE)         {             require '_author-ID.php';         }         elseif (file_exists('_author.php') === TRUE)         {             require '_author.php';         }         elseif (file_exists('_archive.php') === TRUE)         {             require '_archive.php';         }         else         {             // missing _author-NICENAME.php, _author-ID.php, _author.php, or _archive.php             require '_index.php';         }     }      The parts of the file name that are in ALL CAPS are dynamic data, right? How do I get an author's "NICENAME" or "ID", etc.? I need this also for POSTTYPE, MIMETYPE, SUBTYPE, category SLUG, category ID, CUSTOM page, page SLUG, page ID, single POSTTYPE, tag SLUG, tag ID, TAXONOMY, taxonomy TERM, etc. **UPDATE 1:** Since I am trying to determine which files to load (in an attempt to mimic the hierarchy rules), I don't think I can be inside `The Loop`. I think this limits the functions available to me in order to get the dynamic data.


I would like to feature a tip on the homepage

I'm sorry if this question is explained somewhere, I couldn't find it. But it's also difficult to express this special thing in a second language.. I have a very simple homepage, and on that homepage I would like to display a "Tip". I've tried the Daily Tip plugin, as that does seem to do what I would like, but it's very buggy. So I thought, maybe I can single out a category and use posts to show that tip. The homepage is already with just 2 last posts: One from category Blog and one from category Column. On the right side I would like Tip, but with a special styling, so I have to separate it from the normal while loop. So this would be the result: article: BLOGPOST - article: COLUMN - custom: DAILY TIP (highlighted) (I'm not allowed to post an image) Does anyone have an idea how to achieve this? Maybe good to know that the code I've entered for the first two posts is:                        $post_ids = array(0);             foreach( array( 3, 4) as $cat_id ) {               if ( $posts = get_posts(array('cat' => $cat_id, 'showposts' => 1)) ) {                     $first = array_shift($posts);                 $post_ids[] = $first->ID;              }         }       query_posts(array('post__in' => $post_ids));      if (have_posts()) : while (have_posts()) : the_post(); >           (and so on) Thank you so much in advance!


How to make a website like the ones in theme demos?

I don't understand, in Joomla there was a quickstart package that came with templates to show the template's power with data. So our site would be like the one we see in the demos. I have found some nice themes in WordPress, how can I make my site like the one I see in these demos?   * http://www.themeskingdom.com/theme/widely/   * http://demo.s5themes.com/simplecorp/   * http://demo.s5themes.com/simplenbright/


How to redirect logged out users to specific page?

I have a question and a technical issue in wordpress. That is, i have a login form on my website to allow visitors to login to see special content. The question goes here, when the time they log in, i am managed to redirect them to a targeted page. When the time they logging out from the member zone, i am out of idea how to send them to a different targeted page. In my function.php file, I have this code:               add_action('wp_logout',create_function('','wp_redirect(home_url());exit();'));      How to add the page url that i want to redirect them to this code above? I am just beginner in php. Hope to get some guidance.


Using a Taxonomy in Two Spots in a WordPress Post

I have a taxonomy called stocks. it has various items such as 'NFLX', 'AAPL', 'GOOG' I want to be able to assign two things to a WordPress Post:   1. Main stock (only one item selected from the Stocks taxonomy.   2. Mentioned stocks (select one or more items from the Stocks taxonomy). Here's the other thing, I want the slug for the MAIN STOCK to be in the URL of my post. Example: I write an article on Apple Inc and mention other competing companies. The main stock would be AAPL. Mentioned stocks would be AAPL, GOOG, AMZN, etc. And I'd want the URL to be `www.example.com/AAPL/the-name-of-the-article` So, I'm trying to avoid creating two taxonomies (i.e. Main Stock and Mentioned Stocks) and filling both up with the same set of stocks. Ideally, I want to create one taxonomy and use it in two places. Then pull the slug for that taxonomy item selected for the "main stock" to be used in the URL of the post itself. Is this possible?


Implementing backbone.js to retrieve category posts using JSON API

_**Note:** I reformulated this post after solving my original problem because I immediately ran into another problem that can fit under the same title. First I'll summarize the first problem and my solution, then continue with the second problem._ My Wordpress 3.8 installation was set to work with Jetpack's JSON API. But my backbone.js GET requests were canceled (indicated by Google Chrome's Network Panel). Furthermore, I got this report in the console:               XMLHttpRequest cannot load http://public-api.wordpress.com/rest/v1/sites/americawasnotfree.org/posts/?category=life-after-the-treaties. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://americawasnotfree.org' is therefore not allowed access.      **Solution:** Use the JSON API plugin from dphiffer instead of Jetpack's solution. **NEW ISSUE:** Now even though I get the data, I have not figured out how to work with it using Underscore's templating framework. I'm following this tutorial. Below is my broken code (which includes code suggested by Dato'), and below that is what I've tried.

                              I have modified the #posts-list-template in several ways:   1. Passed `posts` as the data argument in `_.template()`, then tried traversing the object using bracket notation: `posts["responseJSON"]["posts"][0]["content"]`. (If I assign the returned object to a variable from Google Chrome's console, I can get the the "content" of post number 0 using this notation.   2. Passed the fetched data through `jQuery.parseJSON( data )` (thinking the data might not be correctly parsed).   3. I know `_.template()` is correctly passing templates. The function succeeds in displaying a div and sample text when placed in `#posts-list-template`.


wp-comments-post.php file returns a blank page

When i post a reply to my blog, it's return a blank page to me. It seems that happens because of this code in wp-comments-post.php               if ( 'POST' != $_SERVER['REQUEST_METHOD'] ) {         header('Allow: POST');         header('HTTP/1.1 405 Method Not Allowed');         header('Content-Type: text/plain');         exit;     }      I hosted the same blog with the same content in other hosting and it works fine, so i guess there should be a misconfiguration in the hosting server. Does anyone has the same issue so can help me out with?


Logout and redirect using the WP Menu

I have a navigation hyperlink in my secondary menu, that will allow the user to logout: ![enter image description here](http://i.stack.imgur.com/fzndm.png) However, the user is prompted with the following screen for confirmation, when clicking on the hyperlink in the secondary navigation menu: ![enter image description here](http://i.stack.imgur.com/5Z0oQ.png) I am currently using the following URL in the navigation menu to redirect the user back to the _Accounts_ page, as a temporary measure:               http://mywebsitenamehere.com/wp-login.php?action=logout&redirect_to=http://mywebsitenamehere.com/my-account/      Is there a way that I can use the WordPress menu above, and place in an appropriate URL to log the user out without the confirmation screen, and then send them back to the page that they were previously on?


Echo HTML in custom shortcode

I wrote a shortcode that I am trying to refine. It basically just gets a list of bookmarks and prints them. But I need to to add HTML around it depending on the type that is defined.               extract(shortcode_atts(array('cat' => '', 'type' => ''), $atts));          $bookmarks = get_bookmarks( array(       'orderby'  => 'name',       'order'    => 'ASC',       'category' => $cat     ));          if (is_single()){       if($type == 'audio'){echo '

Audio
';}       if($type == 'video'){echo '

Video
';}       foreach ( $bookmarks as $bookmark ) {          printf( ' %s', $bookmark->link_url, $bookmark->link_name, $bookmark->link_name, $bookmark->link_name );       }       echo '
';     }      So depending on whether I define the type as either audio or video it should output HTML according to the type. But I am not sure why this isn't working. Any help would be appreciated. Thanks.


Restoring this Revision button disabled

I'm fixing the wordy plugin to send posts to editors and when the edits are finished the modified posts are sent back as a revision. But when I go to the revision differences page the button 'Restore This Revision' is disabled. The revision also says current revision by _author name_ meaning it's not done editing? Also checking wp-admin/revision.php I see that there are two conditionals that add the disabled="disabled" attribute to the button. They are data.attributes.current and wp_check_post_lock I checked wp_check_post_lock and it is false so it's not that conditional that is disabling the button. My question is what is data.attributes.current? Is that a variable? constant? How do I code it so that instead of 'current revision by author name' it is 'revision by author name'. Not sure what is happening but what I think is that the revision isn't completed by the plugin when it should be. What do I need to change in the plugin?


How to create a custom style for a particular page type

I have a page that requires a different underline color for each first letter on all H2's in every "neighborhood" and there are 27 of them. I'm using a SASS variable for the hex color `$a`. The current CSS I have is:               h2:first-letter {       border-bottom: 4px solid $a;       padding-bottom: 10px;     }      But since in every neighborhood page I need it to have a new color how would I be able to change it in the field type on that particular page? In other words say the client wants to change the color in the future to something else how essentially can I allow them to change the CSS value from the WP admin edit Page area? Hope this makes sense as it will unlock some other more challenging questions I'm yet to post in hopes that the answer provided for this question will help me better understand how i would approach another similar problem like how to allow the client to change the background color of a specific container within each page as well.


Add post dates from child theme and change font size on homepage post

I know this is not difficult. I know it is supposed to be in the `style.css` in the child theme, but no font size I change seems to make any difference. The titles of the posts on my homepage never. get. any. smaller. Can anyone tell why? I don't need the lettering to be seen from across the room, so it would be great to resolve this. Also, I'd like to add the date underneath the titles. (?) internalcompass.us/castle               <?php     /**      * The main template file.      *      * This is the most generic template file in a WordPress theme      * and one of the two required files for a theme (the other being style.css).      * It is used to display a page when nothing more specific matches a query.      * For example, it puts together the home page when no home.php file exists.      *      * Learn more: http://codex.wordpress.org/Template_Hierarchy      *      * @package WordPress      * @subpackage Twenty_Twelve      * @since Twenty Twelve 1.0      */          get_header(); ?>          <?php ?>

             <?php easyrotator_display_rotator('erc_92_1372974446'); ?>
                   <?php if ( have_posts() ) : ?>                  <?php /* Start the Loop */ ?>             <?php while ( have_posts() ) : the_post(); ?>                 <?php get_template_part( 'content', get_post_format() ); ?>             <?php endwhile; ?>                  <?php twentytwelve_content_nav( 'nav-below' ); ?>              <?php else : ?>
                  <?php if ( current_user_can( 'edit_posts' ) ) :                 // Show a different message to a logged-in user who can add posts.             ?>
<?php _e( 'No posts to display', 'twentytwelve' ); ?>

<?php printf( __( 'Ready to publish your first post? Get started here.', 'twentytwelve' ), admin_url( 'post-new.php' ) ); ?>

                  <?php else :                 // Show the default message to everyone else.             ?>
<?php _e( 'Nothing Found', 'twentytwelve' ); ?>

<?php _e( 'Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve' ); ?>
                     <?php get_search_form(); ?>
             <?php endif; // end current_user_can() check ?>
              <?php endif; // end have_posts() check ?>


Get multiple term objects by ids

I have an array of ids that correspond to terms. How do I get the full term objects for each id?               $ids = array(1,2,3);      Ideally, I would love to be able to do something similar to the way taxonomy queries with `WP_Query` work, but obviously with terms instead of posts.


Backup the Database and Restore from the Backup?

I am using WordPress 3 and would like to backup the database to my computer (a Mac). My webhost is using PHP safe mode, so that sometimes limits what plugins I can use. What is a good way to do a database backup? Is it possible to be automated? Are incremental backups recommended/easy? Obviously I then need to test restoring form a backup.


Get custom post type by category in a page template

I've created a custom post type with categories and sub categories, what I need to do is list out the post titles and images for a given sub-category or category in a page template. I've got as far as getting the all the listed items in the custom post type, but I'm unsure how to go further... any help appreciated.               <?php      $args = array( 'post_type' => 'portfolio', 'posts_per_page' => 10 );     $loop = new WP_Query( $args );     while ( $loop->have_posts() ) : $loop->the_post();     the_title();     echo '
';     the_content();     echo '
';     endwhile;     ?>      The function that creates the custom post type and taxonomy looks like this:-               <?php          //      CUSTOM POST TYPE 1     add_action('init', 'portfolio_register');          function portfolio_register() {         $args = array(             'label' => __('Portfolio'),             'singular_label' => __('Portfolio'),             'public' => true,             'show_ui' => true,             'capability_type' => 'post',             'hierarchical' => false,             'rewrite' => true,             'supports' => array('title', 'editor', 'thumbnail')         );              register_taxonomy("galleries", array("portfolio"), array(             "hierarchical" => true,              "label" => "Galleries",              "singular_label" => "Galleries",              "rewrite" => true)         );              register_post_type( 'portfolio' , $args );     }               add_action("admin_init", "admin_init");     add_action('save_post', 'save_portfolio_options');     add_action('save_post', 'save_portfolio_single_options');          function admin_init(){         add_meta_box("gallerymeta", "Gallery Options", "portfolio_meta_options", "portfolio", "normal", "low");         add_meta_box("portfoliometa", "Portfolio Item Options", "portfolio_single_meta_options", "portfolio", "side", "low");     }          function portfolio_meta_options(){         global $post;         $custom = get_post_custom($post->ID);         $excerpt = $custom["excerpt"][0];         $info = $custom["info"][0];         $linkto = $custom["linkto"][0];     ?>


Creating an Image-Centric Custom Post Type?

Does anyone have any tips for creating an image-centric custom post type? To elaborate, my blog has rotating header images, shown below: ![Blog header showing random images](http://dl.dropbox.com/u/146967/20100820.sixohthree-header.jpg) The two images in the top left are randomized, and exist as attachments to a specific page that only exists to contain these images. I'm wondering if it's feasible to store these in a different way using custom post types. I've created a new post type, "header-image", and I'm trying to figure out where to go from here. I would like each header-image "post" to have one image attachment. Instead of pulling random images from a page, I would pull random posts from the header-image post type. Given this,   1. How might I incorporate a simple interface to the attachment process that is available from the "New Header Image" admin page?   2. Can I remove the post title and content input boxes to unclutter that page? Goals are to **create a better interface** to the current upload process, and eventually be able to **create a taxonomy** to flag images as left picture/right picture. (Looking at the above image, you can see the photo on the right covers up the face in the other photo. I could avoid this by marking photos for left and/or right side display.) The latter won't be a problem if I can implement the former. **Update:** based on an answer here, I was able to implement this setup. Full code is posted below.


Rename Smart YouTube's httpv back to http for all posts

I've used the Smart YouTube plugin to embed YouTube videos into my blogs. The way I did it is to replace the `http://` of the YouTube url with `httpv://` as the plugin describes. But now I noticed that it's much easier to just auto-embed the YouTube videos by posting the normal `http://` url. I would like to disable the Smart YouTube plugin and convert all those `httpv://` back to `http://`. Is there a good automated way to do that? Here's an example blog post of mine that now has Smart YouTube disabled so there's just a `httpv://` url lingering there.


How can I query posts from multiple roles?

I'm using the code below from another answer to query posts from 1 custom role, eg "friends". I thought I could just comma separate the roles to list posts from more than one role, but this didn't work. Is there another way I can write it? I've tried `'role' => 'friends', 'enemies'` and `'role' => 'friends, enemies'` but I guess `get_users` only supports one role.               <?php     $friends = get_users( array( 'role' => 'friends' ) );     $friend_ids = array();          foreach( $friends as $friend )      $friend_ids[] = $friend->ID;          $news = new WP_Query( array( 'author' => implode( ',', $friend_ids ), 'post_type' => 'news', 'paged' => get_query_var('paged') ) ); ?>


WordPress & MySQL , problem with use many array in meta_query

I use this code for display custom posts :               $args = array(         'category__in' => $bookcat,         'meta_query' => array(             'relation' => 'OR',             array('key' => 'bookname','compare' => 'LIKE','value' => $bookname),             array('key' => 'authr','compare' => 'LIKE','value' => $authr),             array('key' => 'translator','compare' => 'LIKE','value' => $translator),             array('key' => 'publisher','compare' => 'LIKE','value' => $publisher),             array('key' => 'pyear','compare' => '=','value' => $pyear,'type' => 'NUMERIC'),             array('key' => 'ptime','compare' => '=','value' => $ptime,'type' => 'NUMERIC')             )         );      There is 6 array in meta_query , when I use that code , mysql server use upper than 80% of cpu! But when I use 4 array or less thats work well.for example :                   'meta_query' => array(             'relation' => 'OR',             array('key' => 'bookname','compare' => 'LIKE','value' => $bookname),             array('key' => 'authr','compare' => 'LIKE','value' => $authr),             array('key' => 'translator','compare' => 'LIKE','value' => $translator),             array('key' => 'publisher','compare' => 'LIKE','value' => $publisher)             )      Is there limit to use number of array in wordpress meta_query?or I have mistake in my code? Thanks for any help.


Get all active posts that are tied to a custom taxonomy for a custom post type

I need to display all the categories I created for a custom post type then inside of each category I need to loop all the posts that are tied to that category. I tried constructing my WP_Query a number of different ways and I can't get it to work at all. Here's the code I have now:               $categories = get_categories('taxonomy=faqcat&order=DESC');     foreach ($categories as $cat) {              // loop through all  posts tied to category here     }      Updated Code.. still doesn't work.. keeps displaying the same posts in each category.               <?php     $categories = get_categories('taxonomy=faqcat&order=DESC');     foreach ($categories as $cat) :              echo '
' . $cat->name . ' (' . $cat->cat_ID . ' )
';         $q = new WP_Query(array('cat_ID' => $cat->cat_ID, 'post_type' => 'faq', 'tax_query' => array('taxonomy' => 'faqcat')));         if ($q->have_posts()) : while ($q->have_posts()) : $q->the_post();           echo $post->ID;                    ?>
 <?php the_title(); ?>

<?php the_content(); ?>

             <?php endwhile;         else:             ?>
<?php _e('Sorry, no posts matched your criteria.'); ?>
         <?php         endif;     endforeach;     ?>


Sending out scheduled emails

Will wordpress run cron if I have scheduled emails to send? Seems like if no visit (request) is made to the site, scheduled tasks won't run and therefore emails won't be sent eg. hourly. According to current situation, if there is no visit to the site for few hours ( and than visit is made) than all scheduled emails will be sent at the same time How can I prevent this, is there a plugin to add cron task?


Wordpress/Buddypress theme has suddenly stopped working

I am mystified because I haven't made any changes to any files on my site, haven't activated or deactivated any plugins, haven't done anything except navigate around the site, and my theme has suddenly stopped working. When I switch to the default Buddypress theme everything seems to work, but when I activate my theme it looks as though the main style.css, which is in the same place it always is, isn't getting loaded, as the site has no styling and is completely disfigured. You can see what I mean here. I have tried to reverting to an old version of my theme and still see the issue, which suggests that it is not related to the content of my child theme folder. I am completely stumped as to what is going on and would be glad of any help to get my site back up and running again. I have tried deactivating and reactivating my child theme, with no success.


Catchable fatal error on 3.6 update

Trying to debug the situation. Getting close, but will need a little help!! Here is the error:               Catchable fatal error: Object of class WP_Error could not be converted to string in /home/website/public_html/wp-content/themes/Alexia/lib/functions/common.php on line 97      And my code from the error:               // no cache files - let's finally resize it             $new_img_path = image_resize( $file_path, $width, $height, $crop );     line 97-->      $new_img_size = getimagesize( $new_img_path );             $new_img = str_replace( basename( $image_src[0] ), basename( $new_img_path ), $image_src[0] );             // resized output             $vt_image = array (                 'url' => $new_img,                 'width' => $new_img_size[0],                 'height' => $new_img_size[1]             );                  return $vt_image;         }              // default output - without resizing      Thanks in advance NINJAS!!


Can a Plugin Override New User Default Role Type

I'm making a plugin that creates user accounts. Is there a way I can create new users that get the role that I (the plugin developer) tell them to, as opposed to making them all the default new user role. I want to make new users a role type that is defined by my plugins parent plugin.


Lead Generation with Cookies in Wordpress

## New Edit I would like to show the_content BEFORE the more tag when the cookie is not set and the_content AFTER the more tag when the cookie is set. * * * I could not answer to my own question because my reputation is less than 10 so I will edit instead. This is the final answer. This will show the_content before the more tag if the cookie is NOT set, and the_content AFTER the more tag once the cookie IS set. Very useful when creating Lead Gen landing pages or when you want to display some content before or after a certain action is taken. Thanks.               <?php global $more;     while (have_posts()) : the_post();     if(isset($_COOKIE['CookieName'])) {     $more = 1;     the_content('',TRUE,''); }      else {     $more = 0;     the_content(); } ?>


Merging versions of wp_posts based on post_title

I have a live site and a backup/dev version of the site. For some reason (probably because I did an export from Moveable Type then moved everything from localhost to a live environment I had little control over), the live site has several posts which have been cut short at special characters. The backup version has the full versions of these posts, but the ID values are different. I'd like to merge my backup wp_posts table with the live wp_X_posts (it's on multisite - again, no control over this), updating post_content on live with post_content on backup where post_name matches. My MySQL is failing me right now. Can anyone help?


Getting WordPress to store 0 values for custom post type meta

I've created a very complex custom post type system for a football website and am using custom meta boxes to store various match stats. To decide whether or not I should display a stat I check whether the data has been entered in the back end like this:               if (get_post_meta($post->ID, 'stat_red_h', true) || get_post_meta($post->ID, 'stat_red_a', true)){         echo 'somestuff';     }      Where I echo the information within the if statement. However, in many cases the value for a stat is "0" and if "0" is entered for both the home and away stat then the row doesn't show, presumably because it counts it as empty. How can I tell WordPress that entering "0" as a value does not count it as empty, but is a valid value? Perhaps some sort of:               if ($stat_red_h=='0') {         $stat_red_h='REAL!!!';     }      In the functions file when saving the data? Perhaps you guys can help, this is the first time I've gone this deep into WordPress so I'm learning all the time. Thanks, Mike


Get data of all posts of a query before pagination

I am trying to build a classic archive page with 10 posts per page. But with a list of all the posts of this archive to be displayed on top of the classic loop. (The paginated posts would display feature image, excerpt... while the list of all post would retain only the permalink) I keep on thinking I could use the global loop already processed and hook just before pagination to get data and then let it paginate. But I can't find how so far. Another solution would be to run 2 loops on the page, one with pagination and one without, but the first method is probably better and possible, I think.... Did you guys ever came across similar issue? Any suggestion to this problem?


Show 1 post and after a specific date show the next one

I used the following query to have only 1 post published on the homepage from a particular category:               <?php if ( have_posts() ) : ?>     <?php query_posts('posts_per_page=1&orderby=date&order=DESC&cat=6'); ?>           <?php while ( have_posts() ) : the_post(); ?>        <?php wpe_excerpt('wpe_excerptlength_index', 'wpe_excerptmore'); ?>     <?php endwhile; endif; ?>      Each post has two custom fields containing a begin and an end date. What I need is that after the end date the next post (the one with following begin date) will be shown. But I don't know how to do it. Any hint?


How to show an image popup when one clicks on an image thumbnail?

I have created a Gallery View shortcode plugin. I wanna add an feature to that which is - Whenever someone clicks on any image in that gallery, that image should get open in a stylish popup window. Since I am seeking to add this feature to my own plugin, I can't even think to use another plugin. I tried to understand the coding of some such plugins but couldn't figure out any proper way to do so. Please suggest! Thanks!


dynamic external javascript generated using php

How to write an external javascript file with dynamic variable values generated using php from wp db values? So instead of using wp_localize_script for inline js variables, I'd like to use wp_enqueue_script with $src pointing to this php file acting like external js. So far, on the external js using php, the content as follow:               Header("content-type: application/x-javascript");     $params = array(       'timezone_string'           => get_option( 'timezone_string' ),       'jump_to_top'           => __( 'Jump to top' ),       .....     );     echo "$timezone_string $jump_to_top;     .....      When viewing page source, the external script file is listed correctly, but clicking on the external file link, it takes me to home page. I added wp- load.php, still the same. How to do this correctly?


How to pass URL parameters for advanced taxonomy queries with multiple terms for one custom taxonomy

This answer provides the code for a query that returns an OR match on a taxonomy term:               global $query_string;     $args['tax_query'] = array(         array(              'taxonomy' => 'status'             ,'terms'    => array( 'available', 'pending' ) // change to "sold" for 2nd query             ,'field'    => 'slug'         ),     );      I'd like to have my taxonomy template retrieve the term values for the array ( ,'terms' => array( 'available', 'pending' ) ) from the URL, the same as for the single term. The point is to allow taxonomy terms to change over time, without having to hard-code page templates for particular combinations of interest, so that, if there's a better way, please suggest it. Thanks to this post I have permalinks mapping to template files as follows:               example.com/cptslugs                maps to my archive-cptname.php template.      example.com/cptslug/cpt-post        maps to my single-cptname.php template.      example.com/cptslugs/ctxslug/term   maps to my taxonomy-ctxname.php template.       I'd like to have something like: example.com/cptslugs/ctxslug/term1/term2/ map to my taxonomy-ctxname.php template such that get_query_var( 'term' ) returns an array of terms (term1,term2) from the url. but if I could get example.com/cptslugs/ctxslug/?terms=term1,term2 to map to my taxonomy-ctxname.php template such that get_query_var( 'term' ) returns an array of terms (term1,term2) from the url, perhaps via a rewrite rule and a filter, that would be ok, too. But either way, the idea is that the template file should work, whether it's passed one term or an array of terms. **UPDATE** Ok - @scribu to the rescue! \-- maybe. Kept searching, and this is what I found. Thought I had it all figured, but I can't get it to work.               ?tax1=term1,term2&tax2;=term2+term3      maps to:               query_posts( array(       'tax1' => 'term1,term2',       'tax2' => 'term3+term4'     ) );      which further maps to:               query_posts( array(       'tax_query' => array(         array(           'taxonomy' => 'tax1',           'field' => 'slug',           'terms' => array('term1', 'term2'),           'operator' => 'OR'         ),         array(           'taxonomy' => 'tax2',           'field' => 'slug',           'terms' => array('term3', 'term4'),           'operator' => 'AND'         ),     ) );      example.com/?ctxname=term1,term2 renders the front page template. **Revision: it renders taxonomy-ctxname.php when you spell ctxname correctly. Imaging that!** example.com/?cptslug/ctxslug=term1,term2 (taxonomy is registered with a slug of cptslug/ctxslug) also renders the front page template. example.com/cptslug/?ctxslug=term1+term2 renders the archive-ctpname.php template. How do I get a URL that renders the taxonomy-ctxname.php or the taxonomy.php template? Then, once I get that down - suggestions for pretty urls are welcome but not absolutely necessary. **UPDATE TWO**               example.com/?ctxname=term1,term2 and               example.com/ctpslugs/ctxslug/term1,term2/ Both render taxonomy-ctxname.php as desired. See details in my answer, posted below.


WP API Returns "null" for /pages

When issuing a simple GET to /pages the API just returns the string null. When I run a GET on /wp-json the routes object returns the following for pages:               [/pages] => stdClass Object     (         [supports] => Array             (                 [0] => HEAD                 [1] => GET                 [2] => POST              )               [meta] => stdClass Object              (                  [self] => http://boutote.com/wp-json/pages              )               [accepts_json] => 1      )


How to handle sql with Custom List Table Example

I am using the Custom List Table Example plugin as a base to display entries from a table I created in the wordpress database... However I am having issues with this function               function column_default($item, $column_name){          }      I get the error message:               Fatal error: Cannot use object of type stdClass as array in      In the example in the plugin, it uses a simple array. But the $data returned from the query returns several rows of data (i.e. an array with object, object, object). Inside of my prepare_items() function:                global $wpdb;               $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'name'; //If no sort, default to title               $sql = "SELECT * FROM wp_nc_location ORDER BY " . $orderby;               $data = $wpdb->get_results($sql);


Not able to get current menu ID

I'm trying to get the current menu item ID. I hve found one thread that has put me on the right track: How to get current-menu-item title as variable? This is the code I use in my function.php file:               add_filter( 'wp_nav_menu_objects', 'current_wp_nav_menu_object' );          function current_wp_nav_menu_object( $sorted_menu_items )     {        foreach ( $sorted_menu_items as $menu_item ) {             if ( $menu_item->current ) {                 $GLOBALS['current_menu_title'] = $menu_item->title;                 $_SESSION['current_menu_title'] = $menu_item->title;                 break;             }         }         return $sorted_menu_items;     }      But there is one annoying problem. The data stores is always the last clicked menu item, not the current clicked menu item. Let'ssay I have the following menu items:   * Item 1    * Item 2    * Item 3    * Item 4 _(I use`echo $_SESSION['current_menu_title']` to see the result)_ Clicking the menu items in the following order, gives me the following results:               Item 1 -> no output     Item 2 -> outputs Item 1       Item 4 -> outputs Item 2       Item 1 -> outputs Item 4        Why isn't the current clicked menu item outputted?


WordpressMu network with private sites

Anyone know a way to have WordpressMU to work like this: New user registers an account and thus is registered for the whole network (default functionality in WP Multisite), but then he/she would be required to "ask" for an access for the sites within the network one by one. The network home page would be accessible for everyone, but the subsites should be private. So in essence, the user has one username and password for the whole network, but in order to view the site, the user has to be given rights to do so site by site basis by the admin of the site. Any ideas? Plugins? Anything?


Server Variables not recognized in certain posts

I've got a very strange issue that I've never seen in WordPress. I've just converted a big site over to a new responsive theme. The site has about 1,400 articles and there are ads on it. The way we are displaying the ads is through conditional logic which looks at the $_SERVER["HTTP_USER_AGENT"] variable and checks to see if it's desktop or mobile. The ads are only supposed to show on desktop so if it's mobile, it just doesn't echo is out. I've used the code from the answer here: http://stackoverflow.com/questions/4117555/simplest-way- to-detect-a-mobile-device, though I know there is a native WordPress function wp_is_mobile(), but it's based on the same idea. It works fine on most posts but there are a bunch of posts that it doesn't work on (i.e. the ad shows on mobile). I could not figure it out and ended up thinking that maybe the $_SERVER["HTTP_USER_AGENT"] variable wasn't being set on those pages for some reason. I used 'print_r($_SERVER)' to inspect and as soon as I loaded the page with those variables printed, the ad disappeared. Every subsequent page visit after that on that specific post does not show the ad. It's as if the SERVER variables weren't recognized until I printed them. Another thing is that when it was showing the ad on mobile and then I'd log into WordPress on mobile and go to that post, it wouldn't show (which is what I want). So the only time it was showing was on some of the posts only when logged out of WordPress. I am using W3 Total Cache and I don't know if that would affect server variables but it should be noted since I know that plugin can cause little things here and there. Any ideas on why this would be happening?


Upload image and assign it's id to post

At the moment i am working on database conversation script from other cms to Wordpress and faced one problem: I have a list of images, so i need to upload it to Wordpress, after it receive new link, change it with the old one in the post and insert this post. So i wondering if is possiple after `wp_insert_post` somehow assign image id's to the post which just been inserted. P.S. And also is there a method that after upload return url of file?


retrieve wordpress post-meta using php not wordpress functions

I am trying retrieve wordpress postmeta USING PHP not WORDPRESS functions, it needs to be in php no wordpress functions please. this is what I have:               $resultat = mysqli_query($con,"SELECT * FROM wp_posts                                       LEFT JOIN wp_postmeta                                       ON wp_posts.ID= wp_postmeta.post_id                                       where post_type='shop_order'");      the issue here is each meta key is in its own row so this doesn't work :/ any suggestions please? what I figured could be done is to get all the post ids first , store then in array then retrieve the values of each? let me know what you think


Pagination breaks on child-categories, works fine on parent-category

I have two parent categories, and pagination is working fine on them - the paged url's show as: `/parent-category-1/page/2/` ... etc   `/parent-page/parent-category-2/page/2/` ... etc   However, when I go to a child-category, pagination returns a 404 - for e.g.: `/category/parent-category-1/child-category/page/2/` ... etc = 404   `/category/parent-category-2/child-category/page/2/` ... etc = 404     * I'm using the WP-PageNavi plugin for my pagination.   * I don't have any custom permalinks set in my permalinks options. `parent-category-1` parents the categories for my standard blog posts.   `parent-category-2` parents the categories for a custom post type.   Here is the template for the blog posts under `parent-category-1` (standard template - `category.php`):
         <?php                  $paged = (get_query_var('page')) ? get_query_var('page') : 1; //  FOR PAGINATION                  $args = array(                'post_type' => 'post',                'category__in' => ($cat),                'posts_per_page' => 5,                 'page' => $paged, //  FOR PAGINATION             );                  // FOR PAGINATION - hijack the $wp_query variable temporarily             $temp = $wp_query;             $wp_query= null;             $wp_query = new WP_Query($args);                  $second_query = new WP_Query( $args );             if ( $second_query->have_posts() ):                while( $second_query->have_posts() ) : $second_query->the_post();                     $titlechars = 45000; // Character Limit - rediculously large number to eliminate limit                $posttitle = get_the_title();                $modtitle = substr($posttitle, 0, $titlechars);                     $contentchars = 120; // Character Limit                $postcontent = get_the_excerpt();                $modcontent = substr($postcontent, 0, $contentchars);                  echo '
';         ?>              <?php             if( get_field('image') ):                      $attachment_id = get_field('image');                 $size = 'customfeatins'; // (thumbnail, medium, large, full or custom size)                 $image = wp_get_attachment_image_src( $attachment_id, $size );                  echo '';         ?>              <?php else : ?>                  <?php echo '' ?>              <?php endif; ?>              <?php             echo '

' . $modtitle .'

' . get_the_date() .'

' . $modcontent . '… More ›

';         ?>              <?php                     /* PageNavi at Bottom */             if (function_exists('wp_pagenavi')){wp_pagenavi();}                   // FOR PAGINATION -  reassign the $wp_query variable to what is was originally and then reset the query back to start.             $wp_query = null;             $wp_query = $temp;                    endwhile;         ?>                   <?php             endif;             wp_reset_postdata(); // to reset the loop         ?>
      And the template for the custom-posts under `parent-category-2` (a custom template - `category-parent-category-2.php`):
              <?php                  $paged = (get_query_var('page')) ? get_query_var('page') : 1; //  FOR PAGINATION                  $category = get_the_category();                              $args = array(                    'post_type' => 'custom-post-type',                    'posts_per_page' => 5,                     'page' => $paged, //  FOR PAGINATION                    'category__in' => ($cat),                 );                  // FOR PAGINATION - hijack the $wp_query variable temporarily             $temp = $wp_query;             $wp_query= null;             $wp_query = new WP_Query($args);                          $second_query = new WP_Query( $args );             if ( $second_query->have_posts() ):                while( $second_query->have_posts() ) : $second_query->the_post();                     $titlechars = 45; // Character Limit                $posttitle = get_the_title();                $modtitle = substr($posttitle, 0, $titlechars);                     $contentchars = 120; // Character Limit                $postcontent = get_the_excerpt();                $modcontent = substr($postcontent, 0, $contentchars);                  echo '
';         ?>              <?php                  if( get_field('image') ):                      $attachment_id = get_field('image');                 $size = 'customfeatins'; // (thumbnail, medium, large, full or custom size)                 $image = wp_get_attachment_image_src( $attachment_id, $size );                  echo '';         ?>              <?php else : ?>                  <?php echo '' ?>              <?php endif; ?>              <?php             echo '

' . $modtitle .'

' . get_the_date() .'

' . $modcontent . '… More ›

';         ?>              <?php                     /* PageNavi at Bottom */             if (function_exists('wp_pagenavi')){wp_pagenavi();}                   // FOR PAGINATION -  reassign the $wp_query variable to what is was originally and then reset the query back to start.             $wp_query = null;             $wp_query = $temp;           ?>              <?php                                           endwhile;             endif;             wp_reset_postdata(); // to reset the loop         ?>
      I've searched through questions posted here and through the wp forums - I haven't found anything that deals with child-categories specifically. Any help here would be much appreciated!!! Thank you in advance.


Display content between two dates?

I want to display a meta field between two dates, the admin can set the two dates via the custom fields. How can i make such content show between the dates set? Thanks Matt


Redirect in an Admin page

I have a menu item I created called 'View Certificates' and a sub menu item called 'Add Certificates'. The Add Certificates page is just a file upload page. After the file uploads successfully, I want it to redirect back to the 'View Certificates' page. All my code is in the functions.php file. How do I go about doing this redirect?


Targeting specific instane of wp_list_pages

I have several menus generated on a page using wp_list_pages. I want to add a class to the last menu item on only one instance of these. For example, I have a menu here:
     <?php wp_list_pages('title_li=&include=24,26,28,30'); ?>
      And another like so:
     <?php wp_list_pages('title_li=&include=4,6,8,10,12,14,20,22'); ?>
      In my functions.php file I am using the following to add classes to the first and last menu items of wp_list_pages:               // Adds classes to first and last item in list of wp_list_pages     function add_markup_pages($output) {     $output= preg_replace('/page_item/', ' first-page-item page-item', $output, 1);     $output=substr_replace($output, " last-page-item page_item", strripos($output, "page_item"), strlen("page_item"));     return $output;     }     add_filter('wp_list_pages', 'add_markup_pages');      However, I only want to have this applied to the #headerlinks menu. How can I target it using the function above?


How do you control sidebars when there's no get_sidebar in templates?

I'm working with a WordPress 4.0 install, using Omega (the ThemeHall version; there are multiple Omega themes out there). Most of the instructions I've seen to control whether the sidebar appears or not tell me to work with the `get_sidebar` tag. This theme lets me turn the sidebar on everywhere or nowhere, so I've opted to turn it on universally so I can find, and remove, get_sidebar from page templates. But when I look at _all_ the .php files in the main theme folder, get_sidebar doesn't appear. Anywhere. Not in page.php, index.php, footer.php, etc. etc. etc. This is where my WordPress-understanding-powers come to a screeching halt. If get_sidebar isn't in the page templates, where is it? This is a typical page structure in the theme; this is page.php:               <?php     /**      * The template for displaying all pages.      *      * This is the template that displays all pages by default.      * Please note that this is the WordPress construct of pages      * and that other 'pages' on your WordPress site will use a      * different template.      *      * @package Omega      */          get_header(); ?>              <main  class="<?php echo omega_apply_atomic( 'main_class', 'content' );?>" <?php omega_attr( 'content' ); ?>>                  <?php              do_action( 'omega_before_content' );                   do_action( 'omega_content' );                   do_action( 'omega_after_content' );              ?>              </main><!-- .content -->          <?php get_footer(); ?>      In the absence of get_sidebar (and with sidebars turned on everywhere, I thought get_sidebar would appear _somewhere_ in these templates), what's the best way of controlling which templates get sidebars and which don't?


Why wordpress showe "admin is editing..." whoever edits?

Wordpress warns users when two of them are editing the same article, but the warning always says "admin is editing this page". Admin is currently logged off and the message is caused by another author. Language files have the %s in place.


Programatically Creating Initial Wordpress Site

(I have found some links to customising an initial install like this one and this one, but unless I'm missing something - which is quite possible, they don't answer my question) I'm wanting to set up a minimal Wordpress install that users can then run with. I have written a script which downloads the latest wordpress and creates a wp-config.php page with the database settings etc. The first time a user goes to their site, it asks them for a site title, username, password and email address. As someone created one of these sites and did not proceed to enter their details the site was eventually found and exploited by a hacker. It occurs to me that to fix this problem all I need to do is assign initial details for these fields and communicate them automatically to the site owner - but that seems easier said then done. On attempting to set up a new blog, I see that the database schema is not created until this install page has run. I'm loathe to create an initial SQL schema and dump it in for fear that newer versions of Wordpress will use a different schema, breaking the install process (Is this fear justified?) Is there a way I can go about programatically handling the "install.php" stuff - or at least have wordpress automatically create the schema and defaults so I can prepopulate a username and password ? (It strikes me that as an alternative I can probably play around with password protecting install.php in Apache with a .htaccess file, but that does not seem like an elegant solution to me)


Wordpress page title repeated in SOME pages

I have created a Wordpress site and titles were working just fine. Then, some time and plugins installed later, I noticed that in SOME pages I get the title repeated 2 times. Example of wrong page title: Contact - NAME | NAME Example of normal title: Our Services | NAME Now, if I go to General Settings and change title it will change both, no improvement. SEO by Yoast has the option to reset page titles, but that just removes all titles leaving the current URL as page title, so no good either. Here is the code I originally had: `<title><?php wp_title(''); ?><?php if(wp_title('', false)) { echo ' | '; } ?><?php bloginfo('name'); ?></title>` Here is the code I am using now: `<title><?php wp_title('|'); ?></title>` To sum up, I think somewhere in the database there's a wp_title repeated: once using '-' as separator, another one (the current one) using '|'. Any help will be most appreciated, thanks!


Plugin admin page meta_box toggle and order state not saving

I can't get the toggle state and open/close status of meta_boxes on my plugin admin page to be stored. The ajax response is always 0 I'm using meta boxes to hold sections of menu for a plugin.               wp_enqueue_script( 'common' );     wp_enqueue_script( 'wp-lists' );     wp_enqueue_script( 'postbox' );      are called on an init add_action hook add_meta_boxes are called with admin_menu add_action hook Then the admin page for my plugin is rendered thus...

Church Admin Plugin

                          <form style="display:none" method="get" action="">                 <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?>                 <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); ?>             </form>             <?php do_meta_boxes('church-admin','advanced',null);?>

           Why are opn/close toggles and order changes not saved?


WordPress JSON output

Update: I've changed the code as following               $cats = get_categories();     $output = array('categories' => array());          function collect_posts(){         $args = array( 'numberposts=' => 9999, 'category' => $cat );         $myposts = get_posts( $args );         foreach( $myposts as $post ) {             setup_postdata($post);              if (get_post_meta($post->ID, 'apls_video_youtube', true) != ''){             $url = 'http://www.youtube.com/watch?v=';             $url .= get_post_meta($post->ID, 'apls_video_youtube', true);             } else {                 $url = get_post_meta($post->ID, 'apls_video_hosted', true);             }             $output['posts'][] = array(                 'name' => get_the_title($post->ID),                 'url' => $url,             );             return $output;         }            }          foreach ($cats as $cat) {              $output['categories'][] = array(             'cat_id' => $cat->term_id,             'cat_name' => $cat->name,             collect_posts()         );     }          header("Content-type: application/json");     die(json_encode($output));      Output is:               {         "categories": [             {                 "cat_id": "555",                 "cat_name": "Articles",                 "0": {                     "posts": [                         {                             "name": "title",                             "url": "http://www.domain.com......."                         }                     ]                 }             },             {                 "cat_id": "15",                 "cat_name": "Crank",                 "0": {                     "posts": [                         {                             "name": "title examlple",                             "url": "http://www.domain.com/v......"                         }                     ]                 }             },             {......      The issue is: Only one post is being displayed Same post is being displayed in each category A 0(zero) was added So I need your suggestion to fix the issue. ==========================Previous Part========================= I want to get json output as                {         "categories": [             {                 "cat_id": "16",                 "cat_name": "Arm Lock",                 "posts": [                     {                         "name": "Video1",                         "url": "http://www.videourl1.com/"                     },                     {                         "name": "Video2",                         "url": "http://www.videourl2.com/"                     },                     {                         "name": "Video2",                         "url": "http://www.videourl3.com/"                     }                 ]             },             {                 "cat_id": "12",                 "cat_name": "Kick",                 "posts": [                     {                         "name": "Video1",                         "url": "http://www.videourl3.com/"                     },                     {                         "name": "Video2",                         "url": "http://www.videourl3.com/"                     },                     {                         "name": "Video2",                         "url": "http://www.videourl3.com/"                     }                 ]             }         ]     }      So coded as               // get all the categories from the database     $cats = get_categories();          header('Content-type: application/json');     echo '{        "categories": [';     foreach ($cats as $cat) {     // setup the cateogory ID     $cat_id= $cat->term_id;     query_posts("cat=$cat_id&posts_per_page=9999");     echo '           {         "cat_id": "'.$cat_id.'",';     echo '         "cat_name": "'.$cat->name.'",';     echo '         "posts": [';     if (have_posts()) : while (have_posts()) : the_post();     if (get_post_meta($post->ID, 'apls_video_youtube', true) != ''){         $url = 'http://www.youtube.com/watch?v=';         $url .= get_post_meta($post->ID, 'apls_video_youtube', true);     } else {         $url = get_post_meta($post->ID, 'apls_video_hosted', true);     }          echo '             {';     echo '               "name": "'.get_the_title().'", ';     echo '               "url": "'.$url.'"';     echo '             },';     endwhile; endif;      echo '          ]';     echo '        },';     }          echo '       ]';     echo '     }';      This worked for me but facing issue with "," at the last item of every loop, so JSON output is being invalid to purser. How can I fix it?


woocommerce product category tabs

Can someone help me how to generate dynamic tabs with product categories in woocommerce. \- product category as tab name, and their subcategories thumbnails as tab content


In creating a theme, how can i allow a user to change an image outside post/page content?

I'm creating a theme for a particular WordPress site. There's one spot in the sidebar that displays a photo. The user might want to change the photo once a week. He doesn't want to use FTP to upload the new photo, or edit any theme files. How can I set up the theme so he can upload a photo from within WordPress, e.g. to the media library, and have it replace the photo in the sidebar? The only thing I can think of is to have him upload the photo to the Media Library, click the hidden 'Edit' link under the photo in the media library, select and copy the file URL, then go to Appearance > Widgets and paste the URL into a widget that displays the photo. But this seems like a lot to ask of a non-technical user, and there's a lot that can go wrong. Is there a better way?


Wordpress(wpdb class) and mysql stored procedures

$query = "CALL ..........";      $result = $wpdb->get_results($query);      print_r($results);      Is returning an empty array and $wpdb->query does not return anything, how do you run stored procedures from the $wpdb class?


Removing any and all inline styles from the_content()

For one of my current projects, I had to transfer blogposts from an old Wordpress site to my project. Things went smoothly until I've seen that all the posts were copy pasted from Word, leaving this before pretty much every paragraph:                     And at some places things like these:

      So because I don't have the 40 hours (even less the patience) to just go into every post (there's about 100) and remove those unwanted tags, I'm looking for a filter that would just remove all style (except maybe if it contains text- decoration:underline) elements before outputting the_content() Is there such a thing?


Custom Meta Box with variable number of fields

Here is what I wanna do and I basically would just like some ideas from someone more experienced that would help to get started in the right direction. I have a custom post type (Exams) that has is supposed to have some custom location meta data. The idea is that an exam can have one or more locations and I would like to know how to go about this best. The location consists of a name and some more detailed data (basically in a textarea). I would like to have a single set of fields (name + description) with an add button beneath it, if a user clicks the add button the field is duplicated and one more location can be entered and so on. The problem here is not how to do the actual duplicating and appending of the fields, I can handle that via jQuery, but how to handle and save the data on the backend. How should I name the fields and how can iterate over them and store them best, etc.


How could a Widget behave differently depending on sidebar

if sitting on sidebar-1, I need my widget to behave differently than if it were on sidebar-2. How can i detect the sidebar it is sitting on from within the widget() function? The widget contains a list of links to posts. Depending on which sidebar, it should use a different custom image size version of its thumbnail. So what will change is the thumbnail size reference name. For instance, in one sidebar, "xs-square-thumb" will be used; in another "L-square-thumb" will be used. Ex: `get_the_post_thumbnail($post->ID,'xs-square-thumb');`


Assign Custom Taxonomy to Imported Articles

So I'm importing a few hundred HTML files as posts into wordpress. I've created a custom taxonomy field called 'authors' (this is different to whoever published the post) and I wish to have the author assigned automatically upon import. I'm using the HTML import 2 plugin and here's my meta code for the 'author' taxonomy `<meta name="authors" content="Author Name" />`. This works perfectly well using `<meta name="description" content="Meta Description to become excerpt" />` but that's a built in feature. I have already created a list of authors I just want this to automatically assign the correct one once imported. Here's my custom taxonomy authors code.               add_action( 'init', 'my_taxonomy_authors', 0 );          function my_taxonomy_authors() {         // Labels part of the GUI         $labels = array(             'name' => _x( 'Authors', 'taxonomy general name'),             'singular_name'=> _x( 'Author', 'taxonomy general name'),             'search_items' =>  __( 'Search Authors' ),             'popular_items' => __( 'Popular Author' ),             'all_items' => __( 'All Authors' ),             'parent_item' => null,             'parent_item_colon' => null,             'edit_item' => __( 'Edit Author' ),              'update_item' => __( 'Update Author' ),             'add_new_item' => __( 'Add New Author' ),             'new_item_name' => __( 'New Author Name' ),             'separate_items_with_commas' => __( 'Separate Authors with commas' ),             'add_or_remove_items' => __( 'Add or remove Authors' ),             'choose_from_most_used' => __( 'Choose from the most used Authors' ),             'menu_name' => __( 'Authors' ),         );         register_taxonomy( 'authors', 'post', array(             'hierarchical' => false,             'labels' => $labels,             'show_ui' => true,             'show_admin_column' => true,             'update_count_callback' => '_update_post_term_count',             'query_var' => true,             'rewrite' => array( 'slug' => 'topic' ),         ));     }      I also have some custom code to display this as a list in the admin area.


How to add a section to the menus configuration, offering hard coded items?

So, let me explain what I'm actually trying to do, maybe there's a better way to achieve it. I'm working on a theme, and I'd like the user to be able to easily position "special" items in the menu that will do something "special" in the themes frontend, in this case (amongst others) build nested menu structures based on custom taxonomies and their linked posts. So I thought of a new "section" in the WordPress " **Appearance > Menus** " configuration, where some hard coded items would be offered, something like this: ![Custom Menu Section](http://i.stack.imgur.com/G9OrL.png) Now I could think of two ways how to handle that, a custom post type that is only shown in the nav menu, or a custom meta box (which seems to be a lot of work, at least `wp_nav_menu_item_post_type_meta_box()` looks like hours of trial and error). I'm wondering whether any of these two options is the recommended way of solving this problem? btw, I wouldn't consider using `wp_update_nav_menu_item()` as an option since items created with it just seem to sit in the menu without an UI for re-adding them in case they are being removed. So this would require a custom meta box anyways, also it would save the items directly to the menu, breaking the " **add item > save menu** " convention people are used from the WordPress UI.


wpdb->get_row() / get_results - is it possible to return an object instances of my own class?

Is it possible to make wpdb->get_row return an object of a my own custom class instead of stdClass?