title: How to Output which matched meta_keys were found from custom_type_posts?

text:
In WordPress on the single-player.php page which displays a single profile (from numerous other profiles) with information from around 10 different meta fields. Without using tags or categories.. What I want to do is at the bottom of the page, have a related section but comparing the other profiles (made from the same custom_type_post) with the current one on the page and if any of the 10 meta fields Values match any other profiles , show them in a slider at the bottom of the page.......but.... Show which Meta fields were matched. I believe Im currently showing matched profiles...But I m trying to find a way to show how they were matched, by showing The Meta Fields (almost like a tag cloud) IE: Profile One matched by --> Weight, height and on another profile page it may be matched by one or two of the other fields IE: Profile Seven matched by --> Position, height, Team Here is my code so far.

 Similar Players
                  <?php                       $wp_query = new WP_Query();                  $args = array(                          'post_type' => 'player',                          'posts_per_page' => '-1',                          'category_name' => '',                          'orderby' => 'rand',                          'meta_query' => array(                         'relation' => 'OR',                     array(                             'key' => 'player_position',                             'value' => $player_position,                             'compare' => 'LIKE'                     ),                     array(                             'key' => 'player_height',                             'value' => $player_height,                             'compare' => 'LIKE'                     )                 )                     );                      $wp_query->query($args);?>

                  <?php                 // The Loop                      //add a class to the first result                 $first = true;                      if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();?>                           <?php echo '
';?>
                 <a href="<?php the_permalink()?>" title="<?php the_title_attribute(); ?>" rel="bookmark">                 <?php if ( has_post_thumbnail() ) {the_post_thumbnail();}?>

                       <?php //////////////////// MATCHED META FIELDS HERE /////////////////////// ?>                   <?php                 $player_name = get_post_meta($post->ID, 'player_name', true);                             if (!$player_name =='')                             {                             echo '
Name: '.''.$player_name.'
';                             }                              ?>                 <?php                 $player_tech_char = get_post_meta($post->ID, 'player_tech_char', true);                             if (!$player_tech_char =='')                             {                             echo $player_tech_char;                             }                  ?>

                 <?php                 if ($first) {                     $first = false;                             }                 ?>                           <?php endwhile;endif;?>

                            In short               $matchedCustomGetPostMeta =  get_post_meta($post->ID, "MATCHED_KEY_FROM_WP_QUERY->have_posts");      Longer Version and Full Code Function to Create the Custom Post Type and Custom Feilds                           <?php                 /**                 *Creates ADD Player post type                  */                 add_action('init', 'player_register_post_type');                      function player_register_post_type() {                     register_post_type('player', array(                         'labels' => array(                             'name' => 'Player',                             'singular_name' => 'Player',                             'add_new' => 'Add New Player Profile',                             'edit_item' => 'Edit Player Profile',                             'new_item' => 'New Player Profilee',                             'view_item' => 'View Player Profile',                             'search_items' => 'Search Player Profile',                             'not_found' => 'No Player Profiles found',                             'not_found_in_trash' => 'No Player Profiles found in Trash'                         ),                         'public' => true,                         'show_ui' => true,                         'rewrite' => true,                         'capability_type' => 'post',                         'has_archive' => true,                         'supports' => array(                             'title',                             'excerpt',                             'comments',                             'thumbnail',                             'editor',                             'author',                             'page-attributes'                         ),                         'taxonomies' => array('category', 'post_tag') // this is IMPORTANT                     ));                 }                      /**                  * Add player custom fields                  */                 function add_player_meta_boxes() {                   add_meta_box("player_contact_meta", "Player Details", "add_player_details_player_meta_box", "player", "normal", "low");                 }                 function add_player_details_player_meta_box()                 {                      global $post;                   $custom = get_post_custom( $post->ID );                  ?>
                 Player Current Team
                 <input type="text" name="player_current_team" value="<?= @$custom["player_current_team"][0] ?>" class="width99" />

                 Player Name
                 <input type="text" name="player_name" value="<?= @$custom["player_name"][0] ?>" class="width99" />

                 Player Position:
                 <input type="text" name="player_position" value="<?= @$custom["player_position"][0] ?>" class="width99" />

                 Player Age (enter Date of Birth from Date Picker)
                 <input type="text" id="player_dob" name="player_dob" value="<?= @$custom["player_dob"][0] ?>" class="width99" />

                 Player Height:
                 <input type="text" name="player_height" value="<?= @$custom["player_height"][0] ?>" class="width99" />

                 Player Weight:
                 <input type="text" name="player_weight" value="<?= @$custom["player_weight"][0] ?>" class="width99" />

                 Player Laterality:
                 <input type="text" name="player_lat" value="<?= @$custom["player_lat"][0] ?>" class="width99" />

                 Player Domain Legs:
                 <input type="text" name="player_dom_leg" value="<?= @$custom["player_dom_leg"][0] ?>" class="width99" />

                 Player Standing Number:
                 <input type="text" name="player_stand" value="<?= @$custom["player_stand"][0] ?>" class="width99" />

                 Player Body Mass Index:
                 <input type="text" name="player_bmi" value="<?= @$custom["player_bmi"][0] ?>" class="width99" />

                 Player Medical Warnings:
                 <input type="text" name="player_meds" value="<?= @$custom["player_meds"][0] ?>" class="width99" />

                 Player Nationality:
                 <input type="text" name="player_nat" value="<?= @$custom["player_nat"][0] ?>" class="width99" />

                 Player European passport:
                 <input type="text" name="player_eu" value="<?= @$custom["player_eu"][0] ?>" class="width99" />

                 Player Last Team:
                 <input type="text" name="player_last" value="<?= @$custom["player_last"][0] ?>" class="width99" />

                 Technical Characteristics
                 <textarea rows="5" name="player_tech_char" class="width99"><?= @$custom["player_tech_char"][0] ?></textarea>

                 Video Links
                 <textarea rows="5" name="player_vid_link" class="width99"><?= @$custom["player_vid_link"][0] ?></textarea>

                 MEDICALLY AND PSYCHOLOGICAL CHARACTERISTICS
                 <textarea rows="5" name="player_med_char" class="width99"><?= @$custom["player_med_char"][0] ?></textarea>
                 <?php                 }                 /**                 * Get Age from DOB ( datepicker)                  */                 function get_age( $birthdayIn )                 {                 $now      = new DateTime();                 $birthday = new DateTime($birthdayIn);                 $interval = $now->diff($birthday);                 $playerAge =  $interval->format('%y'); // age                 return $playerAge;                 }                      // manipulate $_POST                 $birth_date1 = get_age( $_POST["player_dob"] );                 $_POST["player_dob"] = $birth_date1;                      /**                  * Save custom field data when creating/updating posts                  */                 function save_player_custom_fields(){                   global $post;                        if ( $post )                   {                   update_post_meta($post->ID, "player_current_team", @$_POST["player_current_team"]);                   update_post_meta($post->ID, "player_name", @$_POST["player_name"]);                   update_post_meta($post->ID, "player_position", @$_POST["player_position"]);                   update_post_meta($post->ID, "player_dob", @$_POST["player_dob"]);                   update_post_meta($post->ID, "player_height", @$_POST["player_height"]);                   update_post_meta($post->ID, "player_weight", @$_POST["player_weight"]);                   update_post_meta($post->ID, "player_lat", @$_POST["player_lat"]);                   update_post_meta($post->ID, "player_dom_leg", @$_POST["player_dom_leg"]);                   update_post_meta($post->ID, "player_stand", @$_POST["player_stand"]);                   update_post_meta($post->ID, "player_bmi", @$_POST["player_bmi"]);                   update_post_meta($post->ID, "player_meds", @$_POST["player_meds"]);                   update_post_meta($post->ID, "player_nat", @$_POST["player_nat"]);                   update_post_meta($post->ID, "player_eu", @$_POST["player_eu"]);                   update_post_meta($post->ID, "player_last", @$_POST["player_last"]);                   update_post_meta($post->ID, "player_tech_char", @$_POST["player_tech_char"]);                   update_post_meta($post->ID, "player_tech_char", @$_POST["player_tech_char"]);                   update_post_meta($post->ID, "player_vid_link", @$_POST["player_vid_link"]);                   update_post_meta($post->ID, "player_med_char", @$_POST["player_med_char"]);                   }                 }                 add_action( 'admin_init', 'add_player_meta_boxes' );                 add_action( 'save_post', 'save_player_custom_fields' );                 ?>      And A shortened Version of the Out Put of a single Custom Post Type Page                                           <?php                                  /// Get Meta Key of this Profile Page Currently on                                   $key_1_value = get_post_meta( get_the_ID(), 'player_position', true );                                 // check if the custom field has a value                                 if( ! empty( $key_1_value ) ) {                                   echo "
This Page Key :" . $key_1_value."
";                                 }                                  ?>

  INFORMATION
                                 <?php                                  $player_name = get_post_meta($post->ID, 'player_name', true);                                 if (!$player_name =='')                                 {                                 echo '
Name: '.''.$player_name.'
';                                 }                                  ?>                                 <?php                                 $player_position = get_post_meta($post->ID, 'player_position', true);                                 if (!$player_position =='')                                 {                                 echo '
Position: '.''.$player_position.'
';                                 }                                  ?>                                 <?php                                 $player_dob = get_post_meta($post->ID, 'player_dob', true);                                 if (!$player_dob =='')                                 {                                 echo '
Age: '.''.$player_dob.'
';                                 }                                  ?>                                 <?php                                 $player_height = get_post_meta($post->ID, 'player_height', true);                                 if (!$player_height =='')                                 {                                 echo '
Height: '.''.$player_height.'
';                                 }                                  ?>                                 <?php                                 $player_weight = get_post_meta($post->ID, 'player_weight', true);                                 if (!$player_weight =='')                                 {                                 echo '
Weight: '.''.$player_weight.'
';                                 }                                  ?>                                 <?php                                 $player_lat = get_post_meta($post->ID, 'player_lat', true);                                 if (!$player_lat =='')                                 {                                 echo '
Laterality: '.''.$player_lat.'
';                                 }                                  ?>                                 <?php                                 $player_dom_leg = get_post_meta($post->ID, 'player_dom_leg', true);                                 if (!$player_dom_leg =='')                                 {                                 echo '
Domain Legs: '.''.$player_dom_leg.'
';                                 }                                  ?>                                 <?php                                 $player_stand = get_post_meta($post->ID, 'player_stand', true);                                 if (!$player_stand =='')                                 {                                 echo '
Standing Number: '.''.$player_stand.'
';                                 }                                  ?>                                 <?php                                 $player_bmi = get_post_meta($post->ID, 'player_bmi', true);                                 if (!$player_bmi =='')                                 {                                 echo '
Body Mass Index: '.''.$player_bmi.'
';                                 }                                  ?>                                 <?php                                 $player_meds = get_post_meta($post->ID, 'player_meds', true);                                 if (!$player_meds =='')                                 {                                 echo '
Medical Warnings: '.''.$player_meds.'
';                                 }                                  ?>                                 <?php                                 $player_nat = get_post_meta($post->ID, 'player_nat', true);                                 if (!$player_nat =='')                                 {                                 echo '
Nationality: '.''.$player_nat.'
';                                 }                                  ?>                                 <?php                                 $player_eu = get_post_meta($post->ID, 'player_eu', true);                                 if (!$player_eu =='')                                 {                                 echo '
European passport: '.''.$player_eu.'
';                                 }                                  ?>                                 <?php                                 $player_last = get_post_meta($post->ID, 'player_last', true);                                 if (!$player_last =='')                                 {                                 echo '
Last Team: '.''.$player_last.'
';                                 }                                  ?>
                                 <?php endwhile; ?>                                           <?php endif; ?>                                 <?php wp_reset_query(); ?>
                                                                                <?php                                                   $wp_query = new WP_Query();                                              $args = array(                                                      'post_type' => 'player',                                                      'posts_per_page' => '-1',                                                      'category_name' => '',                                                      'orderby' => 'rand',                                                      'meta_query' => array(                                                     'relation' => 'OR',                                                 array(                                                         'key' => 'player_position',                                                         'value' => $player_position,                                                         'compare' => 'LIKE'                                                 ),                                                 array(                                                         'key' => 'player_height',                                                         'value' => $player_height,                                                         'compare' => 'LIKE'                                                 )                                             )                                                 );                                                  $wp_query->query($args);?>                                      <?php                                 // The Loop                                 $first = true;                                 if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();?>                                           <?php echo '
';?>
                                  <a href="<?php the_permalink()?>" title="<?php the_title_attribute(); ?>" rel="bookmark">                                 <?php if ( has_post_thumbnail() ) {the_post_thumbnail();}?>

                                               <?php                                       //// COMPARE THE PAGE META KEY WITH OTHER POSTS IF IT MATCHES THEN STYLE                                 $key_2_value = get_post_meta( get_the_ID(), 'player_position', true );                                 // check if the custom field has a value                                 if(( ! empty( $key_2_value ) )  && ($key_2_value == $key_1_value)) {                                   //echo "
Matched by :" . $key_1_value."
";                                   $classH6_style ='style="color:deeppink;font-weight:bold;"';                                   $classSpan_style ='style="color:dodgerblue;font-weight:bold;text-decoration:underline;"';                                 }                                  else                                 {                                     //echo "No Match For";                                     $classH6_style='';                                     $classSpan_style = 'style="color:grey;"';                                 }                                 ?>                                 <?php                                                      $player_name = get_post_meta($post->ID, 'player_name', true);                                             if (!$player_name =='')                                             {                                             echo '
Name: '.''.$player_name.'
';                                             }                                       $player_position = get_post_meta($post->ID, 'player_position', true);                                             if (!$player_position =='')                                             {                                             echo '
Position: '.''.$player_position.'
';                                             }                                       $player_dob = get_post_meta($post->ID, 'player_dob', true);                                             if (!$player_dob =='')                                             {                                             echo '
D.O.B: '.''.$player_dob.'
';                                             }                                       $player_height = get_post_meta($post->ID, 'player_height', true);                                             if (!$player_height =='')                                             {                                             echo '
Height: '.''.$player_height.'
';                                             }                                  ?>

                                 <?php                                 if ($first) {                                             $first = false;                                         }                                         ?>                                           <?php endwhile;endif;?>
                                 <?php get_footer(); ?>      This part is what Im trying use to take in multiple keys to match then if on e does then style differently                                                   <?php                                       //// COMPARE THE PAGE META KEY WITH OTHER POSTS IF IT MATCHES THEN STYLE                                 $key_2_value = get_post_meta( get_the_ID(), 'player_position', true );                                 // check if the custom field has a value                                 if(( ! empty( $key_2_value ) )  && ($key_2_value == $key_1_value)) {                                   //echo "
Matched by :" . $key_1_value."
";                                   $classH6_style ='style="color:deeppink;font-weight:bold;"';                                   $classSpan_style ='style="color:dodgerblue;font-weight:bold;text-decoration:underline;"';                                 }                                  else                                 {                                     //echo "No Match For";                                     $classH6_style='';                                     $classSpan_style = 'style="color:grey;"';                                 }                                 ?>


title: Get tags specific category

text:
I use this code to get tags from category. get all tags from category I want to display in the category page the specific tags. I have 8 categories and this is my code:                       <?php if (is_category('10')) { ?>         <?php $args = array(       'categories'        => '10'     );     $tags = get_category_tags($args);     $content .= "
";     foreach ($tags as $tag) {       $content .= "
tag_link\">$tag->tag_name
";     }     $content .= "
";     echo $content; ?>               <?php } elseif (is_category('4')) { ?>     <?php $args = array(       'categories'        => '4'     );     $tags = get_category_tags($args);     $content .= "
";     foreach ($tags as $tag) {       $content .= "
tag_link\">$tag->tag_name
";     }     $content .= "
";     echo $content; ?>      .....      Do that for each category I thinks is not the best way, any idea?


title: How do I add a new string to a .po or .pot file?

text: I have a .pot file that came with my Wordpress theme. Now I want to add strings to it, that weren't there in the original theme. How do I do that? Do I have to update the .pot file? but 1) How do I do that, and 2) How do I make sure that the strings that were translated won't get erased? (I'm currently using Poedit and I can't see a feature to add a string.)


title: Getting two versions of CSS

text: I was using `WP Super Cache` plugin to apply `style.css` file changes that I am doing all the time. But I found the following code which working much better:               <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); echo '?' . filemtime( get_stylesheet_directory() . '/style.css'); ?>" type="text/css" media="all" />      The problem now that server having two CSS files named like that: `style.css?1402153121` which belong to code I have added, and another file named `style.css?ver=3.9.1` which has very old changes. I don't know if it a plugin issue or what! I have already deactivated the `WP Super Cache` plugin, but the file still existed. I am also using `cloudflare` plugin, I deactivated but nothing happened. So how to get rid of that file `style.css?ver=3.9.1`?


title: How can I hide my section title if there is no data in custom fields?

text:
I wrote this function with a foreach and I'm not able to figure out how to hide the section title if there are no custom fields in $lista. Where should I place the section title?               function opening_hours_custom_fields() {          /*Define custom fields in this case with Genesis*/     $lista = genesis_get_custom_field('_happy_day', $post->ID);          /*Section title */     echo '
Happy Day
';     /* the rule to display items in foreach loop */     if( $lista )      {          foreach( $lista as $key => $value ){         /* if value is nothing the display none */         if( $value != '')         {                     echo "
 $value
";         }          }     echo '
';      }     }


title: WordPress Theme Migration Local to Live Assets Not Loading

text: I have a fully working custom WordPress theme built off underscores served up locally via MAMP. Normally when migrating to a live server, I move over the wp-content directory and the .sql file, find/replaced with the appropriate live url. Sometimes I have to update permalinks to get everything working properly on the live server. I have followed these steps with my current site and the theme is showing up broken. The theme image doesn't display, and no hosted assets are loading (CDN assets are coming through). I'm getting no PHP errors and the rest of the site works fine, meaning the pages all link up. I've tried this process multiple times with no success, with plugins and with plugins disabled. Default themes are loading fine. Anyone encountered anything like this before or know what I'm doing wrong?


title: Get meta value from blog page

text: How to get meta vaules from page set to be the main post page? I have a template that shows sidebar that is chosen in the meta box of every page/post. I'm getting the value like this: `$options = get_post_custom(get_the_ID());` and then depending on the value retrieved I display proper sidebar (they are generated in the backend so user have unlimited sidebars).                           if ( isset( $options['custom_sidebar'] ) ) {                       $sidebar_choice = $options['custom_sidebar'][0];                   } else {                       $sidebar_choice = "default";                   }                        if ( $sidebar_choice != "default" ) {                       get_sidebar("custom");                   } else {                       get_sidebar();                   }       Everything works fine until I set the page to be main post page. Then I can not get the value. If I put the sidebar code in the loop it shows several sidebars - so it's kinda working as it gets the values of every single post on the blog page. When I set it outside the loop - so I want it to get the value of just this page it does nothing. Any suggestions?


title: Arrays not working on a WP-Ecommerce product page

text:
I am using WP-ecommerce to build a shop, and have a random product generator on the left and right sidebar. So the same product doesnt appear twice on the page, I have got the post id's from each product in the left sidebar, and excluded them from the product query in the right sidebar. I am doing this using an array with array_push:               <?php $leftids = array(); ?>          <?php query_posts('post_type=wpsc-product&showposts=2&orderby=rand&wpsc_rand=i-want-this-product-to-be-random'); if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_title(); ?>
          <a href="<?php the_permalink();?>"><?php the_post_thumbnail('sidebarimg');?>
<?php the_title(); ?>
          <?php  array_push($leftids, $post->ID); ?>     <?php echo $leftids[0]; ?>     <?php endwhile; endif; ?>     <?php wp_reset_query(); ?>       The problem is I cant access this array when on a product page at all. It works fine on a normal wordpress page such as home or contact us. Any ideas? Thanks


title: Get the content inside shortcode and apply external function to it?

text:
function t_shortcode($atts, $content = null){     $lang = strtolower($atts['lang']);          $content = "
".$content."
";     if($lang == $_SESSION['language']):              return $content;     endif;          }      I'm trying to get the content between the shortcodes, apply a function to it in index.php and the return back the $content of the shortcode with the divs included. the second function that i'd like to apply to the shorcode function is:               function display($shortcodecontent, $noofchars){     $content2 = mb_substr($shortcodecontent,0,$noofchars);     return $content2;     }      so that I can use: // 13 is the number of characters


title: How to detect and move all inline styles to the footer?

text: For some reasons, I need a function to detect all **inline** styles generated by theme options or plugins and move them to the footer and convert this snippet into a small plugin. Basically I need that all these kind of styles printed or enqueued to the header to be detected and moved to the footer with a very low priority:               <style type="text/css">     body {     color: #000;     }     </style>      or               <style>     body {     color: #000;     }     </style>      I guess this can be done using str_replace and wp_footer but how? Thank you!


title: Plugin for loading comments on-demand

text: Is there a plugin which would allow visitors to load comments when they want to, rather than always showing them by default? Preferably through an AJAX call or something to prevent page reload. I'm thinking a nice and visible link or button with `View n comments` or something along those lines. Hope I'm making sense :)


title: Create entire wordpress as a github repositery?

text: In my IDE (Flash Builder for PHP), I can't find a way to create sub project inside Wordpress project as I did with NetBeans. Seems I need to make entire WordPress as a github local repo in order to add version control for my small plugin. Is there other ways I can import git repo as a project inside main project?


title: Wordpress 2.7 upgrade protocol

text: I have been entrusted with this site http://equanimityconcepts.com.au and it's running wordpress 2.7. It's theme is a custom designed theme and hasn't had any plugin updates since about 2010. I am hesitant to update anything until I know if and/or how it can be done. Will I need to source every version from 2.7 and update one by one? Should I export all posts etc and try and recreate it in 3.3? Essentially how to get 2.7 to latest


title: Unique widget id in sidebar

text:
This is my sidebar code               register_sidebar(array(             'name' => 'Post Sidebar',             'before_widget' => '
',             'after_widget' => '

',             'before_title' => '
',             'after_title' => '

',         ));      The above code displays widget title and widget content in separate divs. I want them in separate div because i want to implement collapse feature in widget. Now here is my problem. I don't want that `id` before widget. I need it after title. I modified the code like this               register_sidebar(array(                 'name' => 'Post Sidebar',                 'before_widget' => '
',                 'after_widget' => '

',                 'before_title' => '
',                 'after_title' => '

',             ));      But its not working. Can anyone help me? Thanks


title: Where exactly does the edit_{taxonomy} hook fire?

text: I'm at my wits end. I'm beginning a project that may involve using an action hook in WP that is not well-documented: edit_{$taxonomy} I'm trying to determine exactly when this hook runs, so I just wrote a basic function with an echo for testing. Then, I added it to functions.php in a child theme. Invariably, the line with the echo causes a "Headers already sent" error. If I comment out the echo, it's fine. I thought it might have something to do with the order in which php files are loaded when using child themes, so I went head and pasted it into the bottom of the parent theme functions.php. Same issue. Here's the code:               add_action('edit_expedited-status', 'category_status_email');     function category_status_email() {     echo "Testing";     }      Any thoughts or ideas appreciated. ### Update _Note: Update not from author_ On /wp-includes/taxonomy.php, you'll find (v3.3) on line 1586 the following filter under the context/action `edit`:               $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id);


title: Change the post date from a meta box

text: I'm having a problem with updating the post_date in a custom function I've written. I'm trying to change the "post_date" to my custom "meta_date" value. Here is the function:               function cfc_reset_postdate( $data, $postarr ) {      // If it is our form has not been submitted, so we dont want to do anything     if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;          if($data['post_type'] == 'scripture-memory') {     $date = get_post_meta( get_the_ID(), 'cfc_date', true );         $date = DateTime::createFromFormat('D - M j, Y', $date);         $date = $date->format('Y-m-d');              $data['post_date'] = $date;         return $data;     }     add_filter( 'wp_insert_post_data', 'cfc_reset_postdate', '10', 2);      I've tried linking it to all these filters but none seem to work... It works, except I have to press the "Update" button twice to change the post_date to match my new meta date. What am I doing wrong?


title: Objective Best Practices for Plugin Development?

text: Starting a community wiki to collect up **_objective_** best practices for plugin development. This question was inspired by @EAMann's comments on wp- hackers. The idea is to collaborate on what objective best practices might be so that we can potentially eventually use them in some community collaboration review process. **UPDATE:** After seeing the first few responses it becomes clear that we need to have only one idea/suggestion/best-practice per answer and people should review the list to ensure there are no duplicates before posting.


title: Displaying Post Attachment(s) at Top of single.php

text: I'm using the latest build of WP and would like to display the first image attached to the post at the top of the post content. What code do I have to add to single.php to make this happen?


title: Changing the priority of a custom taxonomy's metabox

text: I'm creating a new custom taxonomy ( _not_ a custom post type). On the edit post page, this custom taxonomy is showing up above all of my other meta boxes. I'd like it to sink down lower in the group. I know that the priority can be added via add_meta_box(). Unfortunately, I'm using the default meta box created by my call to register_taxonomy(), so I have no way of changing the priority value. How can I change the priority of my custom taxonomy so that its associated meta box appears lower in the group of meta boxes? Thanks! :)


title: Change wording of default thumbnail metabox

text: I want to change the wording in the Default thumbnail metabox to 'Set default thumbnail' instead of 'Set featured image'. How can I do this?


title: How to make a page unsearchable in blog search?

text: I want to make a specific page unsearchable. I don't want it's text to show up when i'm searching some text in the search box (on the sidebar on most themes).


title: Combine two foreach Arrays into one table row

text:
right now I have two foreach arrays - one outputs the artist, the other a track title I would like to combine both so there is a row for each artist and corresponding track for example: Row 1 - Artist 1 Track 1   Row 2 - Artist 2 Track 2               <?php // Get duplicate fields     $duplicate_field = get_post_custom_values('Artist', $post->ID);     foreach ( $duplicate_field as $key => $value ) {     echo $value . '
';      }     ?>          <?php // Get duplicate fields     $duplicate_field = get_post_custom_values('Track', $post->ID);     foreach ( $duplicate_field as $key => $value ) {     echo $value . '
';      }     ?>


title: filter just a portion of plugin function

text:
I'm trying to edit just a few pieces of bbpress' breadcrumb default settings, but the filters I've tried end up replacing the whole function. How do you replace only bits? Here is the filter as it stands now               function custom_bbp_breadcrumb() {         $args = array (             'before'  => '
',             'after'   => '
',             'sep'     => __( '›', 'bbpress' ),         );         return $args;     }          add_filter('bbp_get_breadcrumb', 'custom_bbp_breadcrumb' );      I could copy + paste the whole function and filter that, but that would be extremely inefficient.


title: Transition Post status not working

text: I have a plugin which uses the `transition_post_status` hook, to fire a custom function on post update. But I don't know why its not working. Here is the code                add_action('transition_post_status', 'pmc_update_notification',10,3);          function pmc_update_notification($new_status, $old_status, $post) {     echo 'function checkpoint 1';     $options = get_option('pmc_setting');     if($options['snpi'] != false && is_single()){        if ( $old_status == 'publish' && $new_status == 'publish' ) {       echo 'function checkpoint 2';     $post_title = get_the_title($post);     $post_url = get_permalink($post);     $message = __('Post updated','pmc').":\n";     $message .= $post_title . ": " . $post_url;          // Send notification     pmc_send($message);       }      }     }


title: Custom loop with multiple taxonomy queries

text: Apologies -- new to the stackexchange and actually posted this over in Stack Overflow because I didn't know there was a WP specific joint. My issue-- **What I Have:** I've got the code for a working events list. There's a single custom post (events) and three taxonomies (location, month, type). The following code lists future events and orders them by a custom field (start_date). The events list is also sortable by taxonomy. For instance, you can look at just events in December (month) or for events by location (Montana). **What I Can't Figure Out:** How to sort lists by two different taxonomies. For instance: Events in December (month) that are also in Montana (location). It just seem to pick one or the other. **Other Info:** When using the standard Wordpress loop, not the custom one below, there's no problem with multiple queries with this CPT and taxonomies, but of course, it posts every event that ever happened, including the ones in the past. Also, this is my first wp_query, so I'm hoping it's something obvious. File: (archives-events.php)               <?php      $today = date('Ymd');            $my_query = new WP_Query( array(         'post_type' => 'events',             'tax_query' => array(             'relation' => 'OR',               array(                 'taxonomy' => 'location',                 'terms' => $term,               ),                  array(                 'taxonomy' => 'month',                 'terms' => $term,               ),               array(                 'taxonomy' => 'type',                 'terms' => $term,               )),          'posts_per_page' => 10,         'meta_compare' => '>',             'meta_value' => $today,         'orderby' => 'meta_value',          'meta_key' => 'start_date',         'order' => 'ASC',         'paged'=> $paged,      )); ?>          <?php if ( $my_query->have_posts() ) : while ($my_query->have_posts() ) : $my_query->the_post();?>          <!-- OUTPUT OF QUERY -->          <?php endwhile;      wp_reset_postdata();     endif; ?>


title: Really slow WordPress site

text: I am almost done creating a website running with WordPress and WooCommerce. Unfortunately, the site is loading really, really slow. Loading a page easily takes 8-10 seconds. I have 33 WordPress plugins running on the site, and at first I thought that one of these was the problem. After having disabled everything and then enabled one at the time, it is clear that it isn't one particular plugin causing the problems. The load time just becomes a little longer for each plugin being enabled, and ends with the 8-10 seconds. I have tried using W3 total cache, and cdn from CloudFlare which doesn't change much. Also, I thought the server might be the problem, but I have earlier been involved with another website that runs on the same server, which runs really smooth, even though it is a forum with some 2000 users. The theme used is Aware, with some changes http://themeforest.net/item/aware- responsive-wordpress-portfolio-theme/1049029 Any ideas to make the site load faster would be really, really appreciated!


title: Copy SEO Meta Desc "Custom Field" to Excerpt field?

text: I'd really like to take all of my old posts, and automatically use the meta descriptions we have written – currently done for each post using All In One SEO Pack – and copy them to also be our post excerpts. The custom field used by AIO SEO description is `_aioseop_description`. Would anyone have any idea how to accomplish this?


title: Can I add a widget to the <head> of my site?

text: I need to add a small bit of JavaScript to the `<head>` section of my site (on every page). I thought Widgets would cover this but I am only able to add widgets to the sidebar and nowhere else. I've searched around a bit and one solution on Stack Overflow appears to be modifying the functions.php file in my theme. The problem I have with this is that I am using a standard WP theme (Twenty Twelve) so unless I am mistaken, any theme updates would overwrite my changes to the file. I'm sure I must be missing something simple... I don't really understand why widgets can only go in the sidebar. That's different to every other system I've used.


title: Appending numbers to url do not break the link

text: I'm doing some url and meta cleanup and have found a strange problem(?) where, when adding a number to a url, the url still works. For example: The following uris both work and retrieve the same information: `/2012/06/21/graduation` `/2012/06/21/graduation/29/` This numeral addition works with any url on the site. I'd love to know a couple things:   1. is this normal?   2. if this is normal, how can I be more strict with url formation?


title: prevent caching during tinymce custom button development

text: I'm following this turial on how to add a custom button to TinyMCE editor in WordPress. Trying to edit author's JS to include my functionality, yet it seems to have gotten cached. Article author has a hack for it (code snippet below), and it did work for the first time (the button is in the toolbar now), although it doesn't work for subsequent refreshes.               // "This will intercept the version check and increment the current version number by 3.     // It's the quick and dirty way to do it without messing with the settings directly..."     function my_refresh_mce($ver) {       $ver += 3;       return $ver;     }          add_filter( 'tiny_mce_version', 'my_refresh_mce');      What can I do to **disable the caching**? Latest fresh WordPress localhost install, no plugins activated.


title: How to get Wordpress to NOT alter the permalink structure when adding a static page?

text: This is driving me nuts and I'm hoping someone knows of a way around it. Say I have a permalink structure of `/%postname%/` and I have URLs like `www.domain.com/blog/post-name/`. So I go about linking and what have you out in the big bad internet. But, now I decide I want to add a static home page. Say it's a page called "my page". Suddenly WP changes ALL my permalinks to look like `www.domain.com/blog/my-page/post-name/`! So all the links I have created now point to the wrong place, and my plugin which does some things by retrieving the `post_id` of the requested url, utterly breaks because that page no longer exists. Why on earth the WP team would think this is a great idea is beyond me, I simply want to set a specific page to appear when someone visits the root of my blog, not insert that page into the path of all my links. How can I disable this "feature" or otherwise work around it?


title: Pagination on single post page?

text: I've found many pagination tutorials/plugins that work on pages displaying a list of posts such as index.php E.g. - http://design.sparklette.net/teaches/how-to-add-wordpress-pagination- without-a-plugin However I want this to display on single post pages (single.php) so you can navigate through to the next/prev post. Any ideas?


title: Create New Admin Menu Section - Like how custom post type works, in a way

text: I've been working with Wordpress off and on for years now, but I haven't gotten entirely immersed with the framework. I have no problem creating plugins that use custom post types, but I'm looking to add a new section in the admin that isn't for posts, but rather my own custom tables. I know how to create the custom tables on installation of the plugin, I'm just looking for the right information to create a new menu section with subsections, but I'm having a hard time finding the answer. What functions/hooks do I need? I'll figure out the rest after that.


title: Can I change what fields are displayed in the Comments form?

text: Is it possible to change the fields that are available in the comments form? By default my comments form is asking for Name, Email, Website, and then the actual message. I'd like to remove website and replace it with a new field of my choosing. What's the best way to accomplish this?


title: Adding an editable field to template?

text: I'm making a theme for a client (first time using Wordpress), and the client would like to have multiple site "descriptions" to be available. The first one as the main description, and the second one as another block of text in the header which can be changed. Is there any way to add such functionality to a theme? I can instruct the client to manually edit the `.php` files, but I'd like to do something a bit more elegant, like adding an option to the Dashboard. Thanks!


title: How to retrieve the postID in a "image_send_to_editor" hook function?

text: Here is my function:               function insert_img_rel_attrib( $html, $id, $caption, $title, $align, $url  )     {       $postID = ???       $rel = "<a rel='shadowbox[".$postID."]'";       if ($url) {$html = str_replace("<a",$rel,$html);}       return $html;     }     add_filter( 'image_send_to_editor', 'insert_img_rel_attrib', 10, 6 );      How do I get the current post ID? I've tried the obvious, `global $wp_query; $postID = $wp_query->post->ID;` etc.


title: url for posts for a date within a category

text: I am trying to create something like a newsletter. I'd like to show a set of categories with hyperlinks. however, I want to restrict that to the specific date. Clicking on the hyperlink will show the posts within that category and a specific date. Can I use the a permalink to achieve this?


title: Create a WordPress administrator without access to back-end

text: My site recently got hacked, and all my admin users lost their administrator level access. But when I access mySQL database, I saw all the users still exist. How can I create an administrator when I can access the database only?


title: Custom fields: dropdown values depending on other custom field value

text: i have custom fields like this:   * "country" - values: "USA", "Russia", "China"   * "city" - values: "Chicago", "Moscow", "Beijing" I want when user in custom field "country" choose value "USA" after that in custom field "city" show only "chicago". Is it possible? And how can I do this?


title: Trying to display posts by authors in with specific user meta

text: Ok here's the solution:               <?php      $wp_user_search1 = new WP_User_Query( array(     'meta_key' => 'state' ,      'meta_value' => 'NM',     ));     $listers1 = $wp_user_search1->get_results();          $lister_ids1 = array();     foreach($listers1 as $lister1) {         $lister_ids1[] = $lister1->ID;     }          $ids1 = implode(',', $lister_ids1);          $wp_user_search2 = new WP_User_Query( array(     'meta_key' => 'state' ,      'meta_value' => 'TX',     ));     $listers2 = $wp_user_search2->get_results();          $lister_ids2 = array();     foreach($listers2 as $lister2) {         $lister_ids2[] = $lister2->ID;     }          $ids2 = implode(',', $lister_ids2);          $wp_user_search3 = new WP_User_Query( array(     'meta_key' => 'state' ,      'meta_value' => 'OK',     ));     $listers3 = $wp_user_search3->get_results();          $lister_ids3 = array();     foreach($listers3 as $lister3) {         $lister_ids3[] = $lister3->ID;     }          $ids3 = implode(',', $lister_ids3);          $wp_user_search4 = new WP_User_Query( array(     'meta_key' => 'state' ,      'meta_value' => 'TX',     ));     $listers4 = $wp_user_search4->get_results();          $lister_ids4 = array();     foreach($listers4 as $lister4) {         $lister_ids4[] = $lister4->ID;     }          $ids4 = implode(',', $lister_ids4);          $wp_user_search5 = new WP_User_Query( array(     'meta_key' => 'state' ,      'meta_value' => 'TX',     ));     $listers5 = $wp_user_search5->get_results();          $lister_ids5 = array();     foreach($listers5 as $lister5) {         $lister_ids5[] = $lister5->ID;     }          $ids5 = implode(',', $lister_ids5);          $wp_user_search6 = new WP_User_Query( array(     'meta_key' => 'state' ,      'meta_value' => 'TX',     ));     $listers6 = $wp_user_search6->get_results();          $lister_ids6 = array();     foreach($listers6 as $lister6) {         $lister_ids6[] = $lister6->ID;     }          $ids6 = implode(',', $lister_ids6);          $ids = $ids1.",". $ids2.",". $ids3.",". $ids4.",". $ids5.",". $ids6;     $args = array(     'post_type' => 'listing',     'author' => $ids,     'posts_per_page' => 10,     'paged' => $paged     );          $your_query = new WP_Query( $args );     if ( have_posts() ) : while ( $your_query->have_posts() ) : $your_query->the_post();?>


title: What is the best practice to localize content? (Geographic not langauge)

text: I have a website that needs to display state-specific versions, for a few states. Obviously, I will need to parse the IP address to gain geographic information. Before I start making that plug-in, I figured I'd shoot a question out to the collective. To further explain my situation, the website has a different "version", depending on if customers are coming to it from Texas, California, New York and Canada. The language will be English throughout, but the content for Texas is different (think: compliance) from California. I was thinking of using a splash page (cringe) with a drop-down, should all else fail.


title: If custom image header does not exist display text header

text: I've added a theme options page to my site (in my functions.php file):               add_custom_image_header('', 'admin_header_style');      My header.php contains this code, which displays the Featured Image as the banner. If a Featured Image isn't provided it uses the uploaded image banner from the custom image header.               <?php //Custom header     // Check if this is a post or page, if it has a thumbnail, and if it's a big one     if ( is_singular() &&     has_post_thumbnail( $post->ID ) &&     ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' )) &&     $image[1] >= HEADER_IMAGE_WIDTH ) :     // We have a new header image!     echo get_the_post_thumbnail( $post->ID, 'post-thumbnail', array('usemap' => '#Map') );     else : ?>     <img src="<?php header_image(); ?>" alt="<?php bloginfo('name'); ?>" usemap="#Map" />     <?php endif; ?>      My question is, how can I modify this code to output an h1 text header (i.e. `bloginfo('name');`) if no banner image has been uploaded (to the site or post)?


title: How to display categories of my Custom Post Type?

text:
I have a custom post type for a portfolio: Link to the test site. What I'd like to do is to display the project categories just on top of the projects so visitors could then filter projects accordingly. In my functions.php I have:               <?php          require_once('portfolio-type.php');     add_filter('excerpt_length', 'my_excerpt_length');          function my_excerpt_length($length) {     return 25;      }          add_filter('excerpt_more', 'new_excerpt_more');       function new_excerpt_more($text){            return ' ';       }            function portfolio_thumbnail_url($pid){     $image_id = get_post_thumbnail_id($pid);       $image_url = wp_get_attachment_image_src($image_id,'screen-shot');       return  $image_url[0];       }     ?>      In portfolio-type.php:                <?php           if ( function_exists( 'add_theme_support' ) ) {      add_theme_support( 'post-thumbnails' );     set_post_thumbnail_size( 270, 170, true ); // Normal post thumbnails     add_image_size( 'screen-shot', 720, 540 ); // Full size screen      }           add_action('init', 'portfolio_register');             function portfolio_register() {        $args = array(           'label' => __('Portfolio'),           'singular_label' => __('Project'),           'public' => true,           'show_ui' => true,           'capability_type' => 'post',           'hierarchical' => false,           'rewrite' => true,           'supports' => array('title', 'editor', 'thumbnail')          );            register_post_type( 'portfolio' , $args );        }            register_taxonomy("project-type", array("portfolio"), array("hierarchical"  =>  true, "label" => "Project Types", "singular_label" => "Project Type",   "rewrite" => true));      ?>      And finally in my index.php I have:
                                <?php if (have_posts()) : while (have_posts()) : the_post(); ?>                                      <?php                                     $title= str_ireplace('"', '', trim(get_the_title()));                                     $desc= str_ireplace('"', '', trim(get_the_content()));                                 ?>
                                      <a class="project-wrp fancybox" title="<?=$title?>" rel="lightbox[work]" href="<?php print portfolio_thumbnail_url($post->ID) ?>">

f
<?php the_post_thumbnail(array('230','170'),array('alt' => '')); ?>

<?php echo $title; ?>

<?php echo $desc; ?>

                             <?php endwhile; endif; ?>


title: Show label for value only when value exists, basic php

text: I currently have this,               <?php     $meta = get_post_meta(get_the_ID(), 'rw_agentPhone', true);     echo "office:";     echo $meta; // if you want to show     ?>      Which is fine provided there is a value for rw_agentPhone, but if the profile has no value entered it still displays office:, how can I rewrite this so that office: only dispalys if there is a value for rw_agentPhone. I know this is basic php but I just haven't been able to crack this.


title: Custom Taxonomy link out the loop

text: how can i get Custom taxonomy URL by taxonomy ID outside the loop like get_category_link();


title: Jquery checkbox -show posts with checked tags

text: Using jquery, How do I show a checkbox with the list of tags in the sidebar, and only show posts of the checked tag? I cant seem to find this anywhere


title: Relative URLs and hide /wp-content/themes/

text: in my header and other sections I would like to use               <script src="/incs/js/script.js"></script>      While maintaining the default theme folder structure in server as below               /wp-content/themes/theme-name/incs/js/script.js      file need to be accessed via browser/html source if need be so that it hides **/wp-content/themes/theme-name**               http://website.com/incs/js/script.js      This is also applicable to images I may have under /incs/images/imagname.jpg I've seen solutions where defining the directory located outside of theme folder... but need a solution that does this within. Is this possible? Thanks


title: Enqueue Wordpress jQuery after it's been deregistered by a plugin

text: I'm looking after a Wordpress install that makes use of a plugin that deregisters jQuery and replaces it with it's own ancient version. I'm aware of why loading your own jQuery is irresponsible and would like to use the version of jQuery bundled with Wordpress. I'm currently deregistering the plugin's version of jQuery and enqueuing the Wordpress version. However my approach makes some assumptions about the location and version of jQuery. Is there a better way to do this and ensure things don't break when Wordpress is updated?               wp_deregister_script( 'jquery' );     wp_enqueue_script( 'jquery', '/wp-includes/js/jquery/jquery.js', array(), '1.10.2', false );


title: Redirect to first child on Custom Post Type (without template)

text: I need to redirect to the first child page in a hierarchical Custom Post Type. For the love of me I have scoured high and low, but all the solutions seem to involve applying a template to the parent that kicks off redirection. I need to bypass the template and redirect to the first child with a nice, clean bit of code in functions.php. Can someone help? Thanks!


title: Plugin Not Working, But Only On GoDaddy Hosted site

text:
I'm creating a plugin for a friend to log search terms on his site. It's very basic. It creates a new table to store terms entered in the search box. It converts the search term to lower case, checks the database for a matching term and either inserts the term into the database or increases the count of a matching term. It was working as expected on my hosting account. Then I installed it on a WP install on a GoDaddy hosting account... As long as I'm logged in it seems to work whether or not there is a matching term in the database. When I search the site as a guest, it will add a new unique search term to the database but if there is an existing term it does nothing. Well, that's not entirely true. I've seen it increase the count a few times but not by 1, by 2. It seems to function very sporadically on GoDaddy. I can't make sense of this. The actual plugin can be found here. I appreciate any time spent looking at this. Thanks               // Register function to be called when plugin is activated     register_activation_hook( __FILE__, 'mac_search_log_activation' );          function mac_search_log_activation(){         global $wpdb;         $prefix = $wpdb->prefix;         $creation_query =             'CREATE TABLE ' . $prefix . 'mac_search_log (                 `id` mediumint(8) NOT NULL AUTO_INCREMENT,                 `full_search_term` text NOT NULL,                 `count` mediumint(8) NOT NULL,                 PRIMARY KEY (`id`)                 );';              require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );         dbDelta( $creation_query );     }          // Register function to be called when administration pages init takes place     add_action( 'admin_init', 'mac_search_log_admin_init' );          function mac_search_log_admin_init(){         add_action('admin_post_delete_mac_search_log_term', 'delete_mac_search_log_term');     }          // Register function to be called when admin menu is constructed     add_action( 'admin_menu', 'mac_search_log_settings_menu' );          // Add new menu item for Search Term History     function mac_search_log_settings_menu() {         add_menu_page( 'Search Term History',             'Search Term History', 'manage_options',             'search-term-history',             'mac_search_log_config_page',             null,             4.7);     }          // Function to render plugin admin page     function mac_search_log_config_page() {         global $wpdb;         ?>

Searched Terms
                  <form method="post"                   action="<?php echo admin_url( 'admin-post.php' ); ?>">                 <input type="hidden" name="action" value="delete_mac_search_log_term" />                 <?php wp_nonce_field( 'mac_search_log_term_deletion' ); ?>                  <?php             $term_query = 'select * from ';             $term_query .= $wpdb->prefix;             $term_query .= 'mac_search_log ORDER by count DESC';                  $term_items = $wpdb->get_results( $wpdb->prepare( $term_query ), ARRAY_A );             ?>

                     Delete	Search Term	Count

                      <?php                 // Display search terms if query returned results                 if ( $term_items ) {                     foreach ( $term_items as $term_item ) {                         echo '
';                              echo '<input type="checkbox" name="terms[]" value="';                         echo esc_attr( $term_item['id'] ) . '" />	';                              echo '' . $term_item['full_search_term'] . '	';;                         echo '' . $term_item['count'] . '
';                     }                 } else {                     echo '
';                     echo 'No Searches Yet
';                 }                 ?>

                      <input type="submit" value="Delete Selected"                        class="button-primary"/>             </form>
         <?php }              add_filter('pre_get_posts','MACSearchLog');              function MACSearchLog($query) {             if ($query->is_search) {                 global $wpdb;                 $term = strtolower($query->query_vars['s']);                      $term_query = 'select * from ';                 $term_query .= $wpdb->prefix;                 $term_query .= 'mac_search_log';                 $term_query .= ' WHERE full_search_term = "'.$term.'"';                      $term_items = $wpdb->get_row( $wpdb->prepare( $term_query ), ARRAY_A );                      if(empty($term_items)){                     // insert term and set count to 1                     $term_item = array(                         'full_search_term' => $term,                         'count' => 1                     );                     $wpdb->insert($wpdb->prefix.'mac_search_log', $term_item);                      }else{                     // update existing row count++                     $new_query = 'UPDATE ';                     $new_query .= $wpdb->prefix;                     $new_query .= 'mac_search_log';                     $new_query .= ' SET count = count+1 ';                     $new_query .= 'WHERE id = '.$term_items['id'];                     $wpdb->query($wpdb->prepare($new_query));                 }                  }              }              function delete_mac_search_log_term(){             $deleted_terms = array();             // Check that user has proper security level             if ( !current_user_can( 'manage_options' ) )                 wp_die( 'Not allowed' );             // Check if nonce field is present             check_admin_referer( 'mac_search_log_term_deletion' );             // If search terms are present, cycle through array and call SQL             // command to delete entries one by one             if ( !empty( $_POST['terms'] ) ) {             // Retrieve array of search term IDs to be deleted                 $terms_to_delete = $_POST['terms'];                 global $wpdb;                 foreach ( $terms_to_delete as $term_to_delete ) {                     $deleted_terms[] = get_search_term_by_id(intval($term_to_delete));// TO GET SEARCH TERMS FOR EMAIL                     $query = 'DELETE from ' . $wpdb->prefix;                     $query .= 'mac_search_log ';                     $query .= 'WHERE id = ' .                         intval( $term_to_delete );                     $wpdb->query( $wpdb->prepare( $query ) );                 }             }             // UNCOMMENT THE FOLLOWING 2 LINES TO DISPATCH EMAIL WITH DELETED SEARCH TERMS         //    $terms = print_r($deleted_terms, true);         //    wp_mail( get_option('admin_email'), 'Search Terms Deleted', $terms);                  // Reload the search term history page             wp_redirect( add_query_arg( 'page', 'search-term-history',                 admin_url( 'admin.php' ) ) );             exit;         }              function get_search_term_by_id($id){             global $wpdb;             $term_query = 'select * from ';             $term_query .= $wpdb->prefix;             $term_query .= 'mac_search_log ';             $term_query .= 'WHERE `id` = '.$id;                  $term_item = $wpdb->get_row( $wpdb->prepare( $term_query ), OBJECT );                  if($term_item){                     return $term_item->full_search_term;             }else{                 return null;             }         }      Edit: I've been logging queries and everything else involved. Nothing looks off. I replaced the SQL query with $wpdb->update() and replaced `if(empty($term_items)){` with `if($term_items)` while swapping the associated actions, and that seems to have cleared up some of the anomolies with the count, but it just will not update on the GoDaddy account unless I am logged in. On one hand I find it hard to believe that a different hosting account would have an effect on this, but I've seen stranger things from GoDaddy in the past.


title: How to change author base without front

text: I am currently using this code:               function change_author_permalinks() {         global $wp_rewrite;         $wp_rewrite->author_base = 'connect/member';     }     add_action('init','change_author_permalinks');      but my current `front` set on my blog is: `share` So the above generates a URL like so: `http://example.com/share/connect/member/john-smith` But I don't want `/share/` as part of this author URL. I cannot remove the `/share/` front as it is needed for other parts of the site. How do I set the author URL to not use `front`?


title: Using get_terms() to list terms from one custom taxonomy AND from one specific built-in category

text:
I'm trying to get the terms of a taxonomy (kind) and the number of content they have but only for a specific category (get_parent_page_slug() = city name = category slug). This is what I have so far:                   $args = array(         //          'taxonomy' => 'tipo',                     'hide_empty' => 1,                 );         $terms = get_terms('kind', $args);              //var_dump($terms);exit;              $count = count($terms);         echo '
';         echo '
name) . '">Todos (' . $count . ')
';         foreach ($terms as $term) {             echo '
slug . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $term->name . ' ('. $term->count .')
';         }         echo '
';      Just in case I clarify: I'm doing this in a page template. The results I expect are these: > Accommodation in City Name > >   * All (5) >   * Hotel (1) >   * Inn (2) >   * Log cabin (1) >   * Camping (1) > Thanks in advance


title: Why am I getting and error from wp_get_attachment_image_src?

text:
This Code:     <div id="canvas" class="plan-page"               style="background-image: url('<?php echo wp_get_attachment_image_src( stripslashes($options['sitePlan']), 'full')[0]; ?>');">
           is causing a Parse error: syntax error, unexpected '[' in C:\wamp\www\wordpress\wp-content... any help appreciated!


title: Showing a post depending on the Custom Field value

text: <?php if (get_post_meta($post->ID, 'coach_location', true) == "Austria"): ?>      ...this works, but manually checking each country and repeating the post content code is getting arduous, is it possible to do the country check automatically show the post content? So instead of checking each country like so:               if austria: echo title & the_content     if australia: echo title & the_content     if south_africa: echo title & the_content     ... all 196 countries of the world      is it possible to automate this so I echo the title and content just once?


title: A call to list all Custom Post Types?

text: My theme currently uses this code to call all Categories into a list to pull posts from (in the backend) for a thumbnail widget.               $mx_categories_obj = get_categories('hide_empty=0');     $mx_categories = array();     foreach ($mx_categories_obj as $mx_cat) {     $mx_categories[$mx_cat->cat_ID] = $mx_cat->slug;     }     $categories_tmp = array_unshift($mx_categories, "Select a category:");      How could I arrange this so that it lists all custom post types instead? I tried using this and it did not work:               $cpt_post_types_obj = get_post_types('hide_empty=0');     $cpt_post_types = array();     foreach ($cpt_post_types_obj as $cpt_apt) {     $cpt_post_types[$cpt_apt->apt_ID] = $cpt_apt->slug;     }     $post_types_tmp = array_unshift($cpt_post_types, "Select a category:");


title: Best way to pass arguments to another page in Wordpress

text: What is the best way to pass arguments to another page in wordpress. I did it this way :               <a href="get_permalinka(id_of_page).'/&i=2&j=3&k=4'">Link/a>      I get this arguments with $_GET['i'],$_GET['j'],$_GET['k'],problem is : this works just with default permalinks,but when I change it to some other permalink type,it does not work any more.Note - I'm passing these arguments from homepage to another page(template page). Thank you for your time.


title: How is the `get_sidebar` function meant to be used to call a 2nd sidebar?

text: What's the proper way to call a second sidebar in the main home of my blog? And I mean 2 sidebars at the same time.... I might edit the question when I get further info, but now I'm feeling completely lost.


title: Using hooks to place content in theme dynamically

text:
Alright, so I think I may be getting a little too complicated on this, but I basically want to know if this is possible. I am using a content slide function where I display some thumbnails within the main content area, but after the #container ID, I need to put almost the same information, and a little bit more, and I thought maybe I could do a custom action hook for this. so I have this               <?php          function the_maps() {     while( $maps->have_posts() ) : $maps->the_post();              $content .= "
";             $content .= '';                 $content .= get_the_post_thumbnail( get_the_ID(), 'featured-map', $attr );             $content .= '';             $content .= "
" . get_the_title() . "
";                $content .= "
";                                     // ADD CUSTOM HOOK HERE TO DISPLAY ADDITIONAL DATA AT A SPECIFIC PART OF THE THEME         // stuck here              $footer_content = get_the_post_thumbnail( get_the_ID(), 'featured-map', $attr );             // This is where I would like to use an action or hook to push the $footer_content on the footer.php file         add_action( 'after_wp_footer', 'slide_content', 10, 1);         do_action( 'after_wp_footer', $footer_content );                   endwhile;          }          function slide_content( $arg ) {     // stuck here too     }      So at the end of it all, I want the html to look like this. It's dumbed down, but hopefully you'll get the picture.

title

                                                This is based off the following demo: http://tympanus.net/Development/FullscreenOverlayStyles/index7.html I am trying to push myself more on wordpress, and just wanted to know if any WP experts would know if this can be done. I am sure this are many techniques to accomplish this, but I just wanted to know if I could push content to a hook or function in my theme files TIA!


title: The best place of the code for creating a robots.txt file

text: I'm using the Option-Tree framework for the options of my theme. Now I want to add the option to create and edit the robots.txt file. First, I have the function to get the content of the file or create it with a default content; is this:               function get_robots($path)     {     $robots_file = $path . DIRECTORY_SEPARATOR . 'robots.txt'; //The robots file.     if(file_exists($robots_file)){         return file_get_contents($robots_file);          } else {         $default_content = "User-agent: *\nDisallow:";         file_put_contents($robots_file, $default_content);         return $default_content;     }     }          get_robots(getcwd());      If I use this function on `functions.php`, it will run on every page load, and that's a tiny waste. I'm planning to use this function on `robots.php` and then I will call it when I need it. But, when it's the best moment, where is the best place of the code to run it once? Every time when I load the options page, for example? Edit: No, it's not working, because the options settings are included on `functions.php` so it creates the file on every page view.


title: Wordpress Update Plugin Hook/Action? Since 3.9

text: I've researched this a few times, yet my searching does not reveal much except custom code which may or may not be good wordpress practice. As of the latest releases, **has a hook been added to the plugin update process?** I'm asking because its a very basic need, yet I do not see it added to the codex (yet). If not, what is the common and best practice developers employ? EDIT: Just to clarify, I'm not talking about activation - but about updating - that way if there are changes in database or otherwise it can be addressed.


title: custom configuration for a mathjax-latex installation

text: I'm experimenting with a bitnami wordpress service on an amazon hosted VM, and have installed the mathjax-latex plugin. This works when I configure it to use the 'Use MathJax CDN Service', but I'd like to have some of my own macros. Per the readme, I put a copy of the MathJax tree under plugins/mathjax- latex/MathJax:               wget https://github.com/mathjax/MathJax/zipball/v2.3-latest     mv v2.3-latest ~/tmp/mathjax-v2.3-latest.zip     unzip ~/tmp/mathjax-v2.3-latest.zip     mv mathjax-MathJax-78ea6af MathJax      so that it sits here:               /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/mathjax-latex/MathJax      Under 'Custom MathJax location, if you are not using the CDN' in the mathjax- latex plugin configuration I have tried all of:               /wp-content/plugins/mathjax-latex/MathJax/default.js     /wp-content/plugins/mathjax-latex/MathJax     http://localhost/wp-content/plugins/mathjax-latex/MathJax     http://localhost/wp-content/plugins/mathjax-latex/MathJax/default.js     /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/mathjax-latex/MathJax/default.js     /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/mathjax-latex/MathJax      with default selected under 'MathJax Configuration', but my downloaded version of MathJax fails to load when I access a page with some mathjax markup. I presume that I'm specifying the 'Custom MathJax location' incorrectly. Anybody know how to properly specify this, or if anything else is required to install my own customized mathjax configuration?


title: Is it possible for a child-site of a multisite to be a multisite itself?

text: I have a multisite with a sub-directories structure like this: HQ-domain/site1/ HQ-domain/site2/ HQ-domain/site3/ etc. and I am trying to find a way to get a sub-directories structure like this: HQ-domain/site1/branch1 HQ-domain/site1/branch2 HQ-domain/site1/branch3 HQ-domain/site2/branch1 HQ-domain/site2/branch2 HQ-domain/site2/branch3 HQ-domain/site3/branch1 HQ-domain/site3/branch2 HQ-domain/site3/branch3 etc. Super Admin will be able to access everything, site-Admins will be able to access their own site and all the branches, branch-Admins will be able to access only their own branch's site. I have already tried the WP Multi Network plugin (https://wordpress.org/plugins/wp-multi-network/) but it doesn't do what I wish to, which is to create that 2nd nesting of branches. Hope I explained my question logically and thank you in advance.


title: Can I use multi (sub) levels of relation (AND | OR) on custom query?

text: I'm tryng to do the equivalent of:               $args = array(         'post_type' => 'post',         'tax_query' => array(             'relation' => 'OR',             array(                 'relation' => 'AND',                 array(                     'taxonomy' => 'movie_genre',                     'field' => 'slug',                     'terms' => 'action'                 ),                 array(                     'taxonomy' => 'actor',                     'field' => 'id',                     'terms' => 103,                 )             ),             array(                 'relation' => 'AND',                 array(                     'taxonomy' => 'movie_genre',                     'field' => 'slug',                     'terms' => 'horror'                 ),                 array(                     'taxonomy' => 'actor',                     'field' => 'id',                     'terms' => 14                 )             )         )     );      Can I use these kind of multi levels of relation (AND | OR)? It doesn't seem to work on my code. I want to request posts with `(genre action AND author 103) OR (genre horror AND author 14)`. The following query:               $args = array(         'post_type' => 'post',         'tax_query' => array(             'relation' => 'AND',             array(                 'taxonomy' => 'movie_genre',                 'field' => 'slug',                 'terms' => array( 'action', 'horror' )             ),             array(                 'taxonomy' => 'actor',                 'field' => 'id',                 'terms' => array( 103, 14 ),             )         )     );      It is wrong because it would give me `(genre action AND author 14) OR (genre horror AND author 103)` beyond `(genre action AND author 103) OR (genre horror AND author 14)` The Codex doesn't show anything about it. Only one level:               $args = array(         'post_type' => 'post',         'tax_query' => array(             'relation' => 'AND',             array(                 'taxonomy' => 'movie_genre',                 'field' => 'slug',                 'terms' => array( 'action', 'comedy' )             ),             array(                 'taxonomy' => 'actor',                 'field' => 'id',                 'terms' => array( 103, 115, 206 ),                 'operator' => 'NOT IN'             )         )     );      If it really doesn't work, what is the solution? It will need to code a 'the Loop' after another 'the Loop'? Sorry if it is duplicated, I tried several searchs but I think I don't know how to look for it. **EDITED** If it really doesn't work, I've thought a better solution than Loop after Loop is convert everything to a MySQL query and use **Custom Select Query** as described here: Displaying Posts Using a Custom Select Query. Is that the way?


title: No comments on static front page

text: I have had this problem before. I want my homepage to be very simple, and I don't want it to be a discussion forum or a place where you can leave your comments. I wrote yesterday and got some good answers. However, I had to change the theme, because what I wanted to do, wasn't possible with the theme Alexandria. I have made a very simple front page, but when I want to erase the comment area from my page 2, it's just not possible. I have chosen a static page, I have unchecked all the markings in discussion. But nothing helps. Underneath the comments area there is a lot of writing about the HTML and what attributes and codes are legal. I would love to be able to remove it all. What can I do to remove it all?


title: Directly open page in text editor

text: In wordpress, currently I am facing one problem that, when I'm clicking on page edit the editor directly opens in visual tab so, How to directly open page editor in text tab??? Does anyone have a solution for this.


title: Proper way to run wp_query from inside a plugin

text: I am developing a plugin that needs to make a query of a custom post type and retrieve data and meta data from these posts. But anytime I run that query inside my plugin, no matter what admin new post page I pull up (in any post, custom post type, or page) there is data that is pre-filled in, and it is from the first custom post type I am querying in my plugin. So, for example, inside my plugin I have:               add_action('wp','myfunction');     function myfunction(){     $mcpt_query = array();          $the_query = new WP_Query('post_type=mcpt');          if ( $the_query->have_posts() ) :     while ( $the_query->have_posts() ) : $the_query->the_post();         $mcpt_query[] = array(             'id'       => get_post_meta(get_the_ID(), 'idkey', true ),             'field1'   => get_post_meta(get_the_ID(), 'field1key', true ),             'title'    => get_the_title($post->ID)         );     endwhile;     endif;     return $mcpt_query;     wp_reset_postdata();     }          And if the above is in my plugin, any post-new.php page pulled up in admin will be prefilled with the first post from that custom post type (mcpt), instead of giving me a blank new post page to fill out. Any ideas what is causing this?


title: Add version parameter to all scripts/stylesheets

text: I want to add a custom value as parameter to every script/stylesheet that is loaded, this to cache and get rid of the caching whenever I want to. Is there an easy way to achieve this?


title: Cannot publish posts, but can create new pages

text: I am building a site on WordPress. I can't publish posts: when I attempt to do so, the site just hangs and then I get a time out page. However, I can add new pages without a problem. I have tried:   * Upgrading the WP build.    * Switching my theme to Twenty Ten. I still cannot publish posts.   * Deleting all plugins and the plugin folder. None of this has resolved the issue. Should I contact my host or is this a WP issue? Thank you for any help, Jeff


title: Conditional Meta Boxes

text: I am creating multiple meta boxes in WordPress, and I want the user to be able to toggle certain boxes on or off. So, they click a radio button (in a separate meta box), update the options, and an additional meta box attached to that radio value will appear. So it basically goes from one meta box (the selector box) to two meta boxes (the selector box, AND the new box they just selected). In my code, you can create a meta box by setting something like this up (this is the radio box where the user selects for other meta boxes to toggle on/off):               // Create meta box that gives user ability to select additional meta box,        which will then show upon saving the post          $meta_boxes[] = array(         'id' => 'meta_box_id',         'title' => 'Box title',         'pages' => array('page'),         'context' => 'side',         'priority' => 'low',         'fields' => array(             array(                 'name' => 'Select:',                 'id' => $prefix . 'meta_box_id',                 'type' => 'radio',                 'options' => array(                     array('name' => 'Value 1', 'value' => 'value_one'),                     array('name' => 'Value 2', 'value' => 'value_two'),                 )             )         )     );      Here is what it looks like in WordPress: http://i.stack.imgur.com/xR69s.png And here is another meta box that, once selected in the meta box above (let's say value_one is selected), will appear on the post screen:               // This meta box will only show if 'value_one' is selected from      the radio box above          $meta_boxes[] = array(         'id' => 'standard_lead',         'title' => 'Standard Lead',         'pages' => array('page'),         'context' => 'normal',         'priority' => 'high',         'lead' => 'value_one',         'fields' => array(             array(                 'type' => 'text',                 'id' => $prefix . 'standard_title',                 'name' => 'Lead Title',                 'desc' => 'The title of your Standard Lead',                 'width' => '100'             ),             array(                 'type' => 'textarea',                 'id' => $prefix . 'standard_content',                 'name' => 'Lead Content',                 'desc' => 'The content of your Standard Lead (you can use HTML)',                 'width' => '100'             )         )     );      The important piece from that code is this:               'lead' => 'value_one',      My plan was to have the ['lead'] value (from the meta box code directly above) to match the ['value'] value (from the radio meta box), so they could be connected, and then test with an IF statement to make sure they equal the same thing, and then display ONLY if they both equal value_one. The function below is what actually adds the meta boxes into WordPress. Within that function, I tried creating this IF statement to match those two together:               if($this->_meta_box['value'] == $this->_meta_box['lead'])      ...but it doesn't work, and I'm not sure how to target ['value'] as it's nested within multiple arrays (or I assume, is the problem). Here's the full function:               function add_meta_boxes()     {         $this->_meta_box['context'] = empty($this->_meta_box['context']) ? 'normal' : $this->_meta_box['context'];         $this->_meta_box['priority'] = empty($this->_meta_box['priority']) ? 'high' : $this->_meta_box['priority'];              foreach($this->_meta_box['pages'] as $page)         {             if($this->_meta_box['value'] == $this->_meta_box['lead'])             {                 // adds meta box to WP                 add_meta_box($this->_meta_box['id'], $this->_meta_box['title'], array(&$this, 'show_meta_boxes'), $page, $this->_meta_box['context'], $this->_meta_box['priority']);             }         }     }      Hope I explained well enough what the issue is. I have looked all around and have tried hacking a few things around, but I'm not sure if this a problem I can solve myself. Any input on this, or a nudge in the right direction would be a HUGE help. Thank you! PS: I was also thinking of doing this through JS instead, but not sure where to start from there.


title: Check if post has specific tag_ID in custom post type

text:
I am using Event Manager and they have a custom post type of events, with a taxonomy of event-categories (separate from regular post categories). In that taxonomy I have created terms(?) or event categories, "Education" and "Research". I want a specific `<div>` to show up if a post is in the event- categories taxonomy with the term/category of "Education". The slug is "education" and the tag_ID is 8. Currently I'm trying to use this code snippet, but I'm not getting it. I know there's more to it, but I haven't been successful with other tutorials. Most are for category archives. I need it conditionally for single posts.               <?php        if(in_category('education')) {           echo '
test
';        }     ?>


title: Simple Math Quiz or Captcha to hide whois query form

text: I have a whois form in my site that enables users to query for domain name availability and if available gives them the option to request for registering it. The whois form is inserted via shortcodes. My problem is that I want to protect this form from spam bots by hiding the form until the user solves a simple math question or enters a captcha. I made a lot of research on the internet but found nothing on hiding content for visitors until they prove their humanity. All I found is to hide content for un-logged-in users, which is not my case, because I want to give general visitors (not members) the ability to use the whois form and prevent spam bots at the same time. Any help or guide lines is greatly appreciated. Many Many Thanks, Kri Kab


title: How to use a newly registered setting with a checkbox and the default value 'true'

text: I'm currently working on a plugin in which I would like to have a new setting (called 'show_introduction') that has the default value 'true'. I did this by the following which is hooked into 'admin_init'               register_setting('tf-song-list-settings-group', 'show_introduction');     if (get_option('show_introduction') == '') update_option('show_introduction', 'true');      On the settings page I have the following to incorporate the above setting into a checkbox               <input name="show_introduction" type="checkbox" id="show_introduction" value="true" <?php checked('true', get_option('show_introduction')); ?> />      Now the problem is that I cannot UNcheck the checkbox and thus set the value to false. What am I doing wrong, and how is it done right? If I give the setting 'false' by default, all is working nicely. But that's not what I want the default value to be. Of course, I could rename the setting from 'show_introduction' into 'hide_introduction', give the input the value 'false', check for 'false', and hence do it all the other way around. Most probably, that would work. But that's more like a workaround to the actual problem, isn't it? Thanks in advance. **// edit** I think I got what I wanted. Here's the code               if (!class_exists('tf_song_list')) {         class tf_song_list {             public function __construct() {                 add_action('admin_init', array(&$this, 'init_options'));             } // public function __construct                  function init_options() {                 register_setting('tfsl_options', 'tfsl_options', array(&$this, 'validate_options'));                 $options = get_option('tfsl_options');                 if (false === $options)                     $options = $this->get_default_options();                 update_option('tfsl_options', $options);             } // function init_options                  function get_default_options() {                 $options = array(                     'show_introduction' => 1                 );                 return $options;             } // function get_default_options                  function validate_options($options) {                 $validated_options['show_introduction'] = ($option = $options['show_introduction']) ? $option : 0;                 return $validated_options;             } // function validate_options         } // class tf_song_list     } // if (!class_exists('tf_song_list'))      The clue, I guess, is   A) to use a validation/sanitizing function to set the specific values in case it is not the default value,   and B) to check with (false === MY_OPTIONS) and only then set default values. Now, I can use the following on my settings page and all is working fine:               <input name="tfsl_options[show_introduction]" type="checkbox" id="tfsl_options[show_introduction]" value="1" <?php checked(1, $options['show_introduction']); ?> />      Thanks for your input! BTW, if there's something wacky with my above code, feel free to enlighten me. I didn't use the settings API until two days ago.


title: Show two random posts from custom post type

text:
I've set the code below to show info from the latest two posts of a custom post type (it also loops through and adds a class of first to alternate items for layout purposes). How would I amend this to show two random posts?               <?php     $counter = 1;     $args = array( 'post_type' => 'custom_advert', 'posts_per_page' => 2 );     $loop = new WP_Query( $args );     while ( $loop->have_posts() ) : $loop->the_post();     echo '

';     $counter++;     endwhile; ?>


title: mod_rewrite loop, redirecting http to https on certain section of wordpress blog

text:
I'm trying to rewrite 3 sections of a wordpress site to https if they are accessed over http:               /cart/          /my-account/          /checkout/      As well as these rewrite's worpress has added a rewrite to remove index.php out of the url. The index.php rewrite is about the only thing that is working. here is my .htaccess               <IfModule mod_rewrite.c>     RewriteEngine On     RewriteBase /          RewriteCond %{HTTPS} off     RewriteCond %{REQUEST_URI} (checkout|cart|my-account)     RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=302,L]          # BEGIN WordPress     RewriteRule ^index\.php$ - [L]     RewriteCond %{REQUEST_FILENAME} !-f     RewriteCond %{REQUEST_FILENAME} !-d     RewriteRule . /index.php [L]     # END WordPress          </IfModule>          # END WordPress      ## Some Curl tests In the below you can see my access the http version of /cart to be rightly told that this has moved to https /cart, So I then try the https version to be told that it has moved to the very same https version thus a loop.               PS C:\Users\Stephen> C:\Users\Stephen\Downloads\curl-7.23.1-win64-ssl-sspi\curl.exe -k -i http://www.mysite.com/cart     HTTP/1.1 302 Found     Date: Wed, 20 Feb 2013 09:07:06 GMT     Server: Apache     Location: https://www.mysite.com/cart     Vary: Accept-Encoding     Content-Length: 285     Content-Type: text/html; charset=iso-8859-1          <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">          <title>302 Found</title>
Found

The document has moved here.

     <address>Apache Server at www.mysite.com Port 80</address>               PS C:\Users\Stephen> C:\Users\Stephen\Downloads\curl-7.23.1-win64-ssl-sspi\curl.exe -k -i https://www.mysite.com/cart     HTTP/1.1 302 Found     Date: Wed, 20 Feb 2013 09:07:06 GMT     Server: Apache     Location: https://www.mysite.com/cart     Vary: Accept-Encoding     Content-Length: 285     Content-Type: text/html; charset=iso-8859-1          <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">          <title>302 Found</title>
Found

The document has moved here.

     <address>Apache Server at www.mysite.com Port 80</address>           It redirects to the https but then gets stuck in a loop and the browser will complain of a loop. Any rewrite guru's in here.


title: Placing a featured image into header

text: 1. How can I place featured images into the header, so each post has it's featured image within the main header?   2. Also on category archive pages and the main news page, the featured images are being used in the traditional way, using the custom post image so is there a way around that too, where I can use the featured image for both posts and header.   3. Maybe there is a way of having two custom thumbnail images and calling one up for the featured image and the other for the header?


title: How can I tell what category I'm in-- in the header?

text: How can I identify what category the current page is showing in the `<head>`? Here's the code I have now:               <?php if ( is_home() ) { ?>         <!-- set up for home page ad -->     <?php } elseif ( in_category( 'Restaurant Reviews' )) { ?>         <!-- set up for restaurant reviews ad -->     <?php } else { ?>         <!-- set up for run of site ad -->     <?php } ?>      This code fails on my "Restaurant Reviews" page... it always selects the "run of site" option. As a test, lower down in the page, I used `the_category()` to see what categories WP thought the current page used, and I got "Chelsea, Manhattan, New York, Restaurant Reviews". And of course, the `in_category()` command works correctly there in the lower part of my page, and properly recognizes when it's in the "Restaurant Reviews" category. So-- up there in the `<head>`, how can I tell when I'm in the "Restaurant Reviews" category?