title: wordpress plugin JSON API search within specific category

text: From the JSON API plugin doc I notice that I can get the post within some category               http://abc.com/?json=get_category_posts&id=9      And I can also search the post               http://abc.com/?json=get_search_results&search=keywords      However, are there anyway to implement search within some category? Thanks


title: Excerpt all post content Content Same Size without word cutting off

text: On my category page there are list of 24 posts with title and excerpt content. To display specific lengths of content, I am using **substr** function. Now the issue is that each post excerpt content are displaying in different lengths. To display specific lengths of content I am using substr to cut string of specific length.                 $content = strip_tags(get_the_content());            $content = substr($content, 0, 100);            echo $content . '[..]';      for example:                     post title one          post content size post content size post content size post content           size post content size[..]             post title two        post content 1'50" 0 size post content 55 size post content th[..]             post title three        post content size post "content 55" size checkk post content s[..]      Here in example you can see each post has different content lenght. Now what I am looking for is each post display specific lenght of content. Second and third post content lengths should be same as **first post.** Also spelling should not cut. For that I've tried                    $words = explode(' ', $string, ($word_limit + 1));              if(count($words) > $word_limit) {             array_pop($words);       //add a ... at last article when more than limit word count       echo implode(' ', $words)."..."; } else {      //otherwise      echo implode(' ', $words); }      but it is not working . I need help to display same length content without word cut off.


title: Query seems to be duplicated

text:
I'm just hit a development brick wall and can't seem to find a solution to this problem. I've running two WP_Query's the aim is one displays premium stockists and the other one displays the none premium stockists. I've added a tick-box that allow's me to use a conditional to check if its a premium stockist or not.   1. How do I add the correct logic in *if the user is a premium member display the premium stockists. These must appear at the top of the page above the other stockists due to them been premium.   2. I'm using a plugin called Advanced custom fields to generate the premium true/false field. website is enter link description here Code I've got.               <?php          $args = array(         'orderby' => 'title',         'order' => 'ASC',         'posts_per_page' => 5,         'paged' => get_query_var('paged'),         'tax_query' => array(             array(                 'taxonomy' => 'store-category',                 'field' => 'id',                 'terms' => array($_POST['region'])                 )             )         );          $query = new WP_Query($args);          if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();          $mapurl = get_post_meta($post->ID, 'lj_mapurl', true); ?>

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

             <?php   if ( has_post_thumbnail() ) {                 $postthumnail_count++;                 the_post_thumbnail('stock');             }             ?>

     <a class="viewMap" href="<?php echo $mapurl; ?>" title="Find <?php the_title(); ?> on a map (opens in a new window)" target="_blank">View Map

     <?php endwhile; ?>     <?php else: ?>
Sorry, content not found
          <?php endif; ?>     <?php wp_reset_query(); ?>          <?php          $args = array(         'orderby' => 'title',         'order' => 'ASC',         'posts_per_page' => 5,         'paged' => get_query_var('paged'),         'tax_query' => array(             array(                 'taxonomy' => 'store-category',                 'field' => 'id',                 'terms' => array($_POST['region'])                 )             )         );          $query = new WP_Query($args);          if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();          $mapurl = get_post_meta($post->ID, 'lj_mapurl', true);      $premium = get_field('premium_stock_supplier');     if ( ! $premium ) { // this is basically short for $premium == false         ?>

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

                           <a class="viewMap" href="<?php echo $mapurl; ?>" title="Find <?php the_title(); ?> on a map (opens in a new window)" target="_blank">View Map

                 <?php  } ?>                            <?php endwhile; ?>         <?php else: ?>
Sorry, content not found
          <?php endif; ?>      updated code for displaying premium stockists (doesn't work)               <?php                   $args = array(         'orderby' => 'title',         'order' => 'ASC',         'meta_query' => array(             array(                 'meta_key' => 'premium',                 'meta_value' => '0',                 )             ),         'posts_per_page' => 5,         'paged' => get_query_var('paged'),         'tax_query' => array(             array(                 'taxonomy' => 'store-category',                 'field' => 'id',                 'terms' => array($_POST['region'])                 )             )         );      code for displaying none premium stockists (doesn't work)               $args = array(         'orderby' => 'title',         'order' => 'ASC',         'meta_query' => array(             array(                 'meta_key' => 'premium',                 'meta_value' => '0',                 )             ),         'posts_per_page' => 5,         'paged' => get_query_var('paged'),         'tax_query' => array(             array(                 'taxonomy' => 'store-category',                 'field' => 'id',                 'terms' => array($_POST['region'])                 )             )         );


title: WordPress Custom URL Rewrites

text: I am trying to add a custom rewrite rule with a single variable to a specific page. The 'ugly' version is `http://example.com/used-cars/car/?carname=name- of-car` and the 'pretty' version I'm going for is `http://example.com/used- cars/car/name-of-car`. `http://example.com/used-cars/car/` is a page with a custom template that doesn't display anything if the `carname` variable is not set. This is the code I have so far:               add_filter('query_vars', 'ip_add_rewrite_query_vars');     function ip_add_rewrite_query_vars($query_vars) {         $query_vars[] = 'carname';         return $query_vars;     }          add_action('init', 'ip_add_rewrite_rules');     function ip_add_rewrite_rules() {         add_rewrite_rule(             'used-cars/car/([^/]+)/?$',             'index.php?p=403&carname=$matches[1]',             'top'         );     }      With this, when I go to `http://example.com/used-cars/car/name-of-car` it just redirects to `http://example.com/used-cars/car` and `get_query_var('carname')` returns `null`. I have tried a couple of different variations on ways to do this (like modifying `$wp_rewrite` directly, using `add_rewrite_tag()`), but I either get the same result or a 404 error. I flush the rewrite rules and my browser's cache every time I try to test the page again. I installed the rewrite analyzer plugin and my rewrite appears there and looks correct compared to the default ones. As far as I can see from all the examples on the web the code I have should work - it's pretty much the same example from the codex page - and I have no idea why it doesn't. This is a multisite setup (each site on a different subdomain) - I'm not really familiar with multisite but I don't think there's anything in that that would affect custom rewrites?


title: Caption and title in img alt tag are the same?

text: I'm currently on WP 3.6 and noticed an unpredictable behaviour with the alt attributes generated by WP. If I have an image title, the title appears in the alt. If I have a caption, the caption replaces the alt. What can I do to prevent the image title from appearing in the alt field? I want to keep it empty if there are no image captions.


title: Get title of post image is attached to

text: So I found this post: Find the post an attachment is attached to and implemented Chip's suggestion but having a weird outcome. I am trying to pull the title of the post that the specific image is attached to. This is my query:               <?php         $args = array(             'post_type' => 'attachment',             'posts_per_page' => -1,             'post_status' => 'any',             'post_parent' => null,             'tax_query' => array(                 array(                     'taxonomy' => 'post_tag',                     'field' => 'slug',                     'terms' => 'logo'                 )             )         );              $attachments = get_posts( $args );         foreach ( $attachments as $image ) {             // Get the parent post ID             $parent_id = $image->post_parent;             // Get the parent post Title             $parent_title = get_the_title( $parent_id );             // Get the parent post permalink             $parent_permalink = get_permalink( $parent_id );         }                   if ( $attachments ) {             foreach ( $attachments as $post ) {                      $logoimg = wp_get_attachment_image($post->ID, 'Work Gallery');      This is the line where I am calling the title: `echo ' ' . $parent_title . ' ';` This kind of works but it is outputting 1 post title in particular and for all the images on the page. Any thoughts as to why its not dynamically picking up each images associated post title? Thanks!


title: how to implement a site like this in wordpress?

text: I want to develop a site like http://www.webpresent.biz/ Should I develop in wordpress? How much effort is required? Plugins available? Help would be appreciated.


title: Changing domain

text: I set my domain in the WordPress without www i.e xyz.com but realised after setting that xyz.com wasn't redirecting to www.xyz.com. Now I am unable to login into the admin panel. I grepped through the code but saw that the domain is not set as a value to any variable. Is it saved in the DB? How can I change it?


title: Displaying errors with settings api

text: I'm not using the full settings api, just this code:               register_setting( 'my_options', 'my_options', 'my_options_validate' );      Then my validation:                 $options = get_option('my_options');            if(error_found){              add_settings_error( 'my_options', 'settings_updated', 'error_message_here', 'error');            }            return $options;      But on postback no errors are displayed. So my questions are: does simply setting an error message result in its display? do I have to use the full settings api to have errors displayed? do I have do anything to disable the "settings updated" message on postback? I've tried using settings_errors but no errors show.


title: How can I change my meta_query to SQL wpdb query?

text: I want to extract post related to 3 meta_data fields called bed_value, bath_value, rob_value the variable data is $bedrooms, $bathrooms, &rob, I got some confused with join and like structure. The unworking metaquery is this               $args = array(         'meta_query' => array(         'relation' => 'OR',                  array(             'key' => 'beds_value',             'value' => $bedrooms,             'compare' => '=',                             ),             array(             'key' => 'baths_value',             'value' => $bathrooms,             'compare' => '=',                             ),             array(             'key' => 'rob_value',             'value' => $rob,             'compare' => '=',                             ),                   ),     );          $args = array_merge( $args , $wp_query->query );      query_posts( $args );      So it is better and easier to do a SQL wpdb query I will change the code. prior wpdb query with $wpdb->get_results($query, OBJECT); does not allow to paginate the results, thats why I tried to change to meta_query I need more knowledge!


title: Filter Posts by current Month

text: Ok, I have a client that wants to only display posts by the current month. I've tried a few different variations but none have worked. Here's where I'm at now. Any help is appreciated!                   <?php         $current_year = date('Y');         $current_month = date('m');         $args = array(             'year'     => $current_year,             'monthnum' => $current_month         );           $custom_query = new WP_Query('$args');                  if ($custom_query->have_posts()) : while ($custom_query->have_posts()) : $custom_query->the_post();                           // The following determines what the post format is and shows the correct file accordingly                     $format = get_post_format();                     get_template_part( 'includes/post-formats/'.$format );                          if($format == '')                     get_template_part( 'includes/post-formats/standard' );                   endwhile; else:                   ?>


title: Multiple loops in same page, without duplicate content

text:
I'm trying to make a page with multiple loops, I need every loop to display a predefined number of posts from the same category (every loop displays X number of posts from Category CATS). But I also need the second loop, the third loop and so on to display the posts from where the last loop stopped, without duplicating content (example: loop 1 from post 1 to 5. loop 2 from post 6 to 10. loop 3 from post 11 to 15 etc.). Here's what I've tried so far (I also gave a try to the code in the wordpress codex, but nothing seems to work) Can you help me? here's my code so far;               <?php   if (have_posts()) : ?>     <?php   $mosaics = new WP_Query('category_name=mosaics&posts_per_page=5'); ?>     <?php   while ($mosaics->have_posts()) : $mosaics->the_post(); ?>     <?php   if( $post->ID == $do_not_duplicate ) continue; ?>          <?php   echo get_the_content(); ?>     <?php   endwhile; ?>     <?php   endif; ?>     <?php   wp_reset_query(); ?>
          <?php   if (have_posts()) : ?>     <?php   $mosaics = new WP_Query('category_name=mosaics&posts_per_page=4'); ?>     <?php   while ($mosaics->have_posts()) : $mosaics->the_post(); ?>     <?php   if( $post->ID == $do_not_duplicate ) continue; ?>          <?php   echo get_the_content(); ?>     <?php   endwhile; ?>     <?php   endif; ?>     <?php   wp_reset_query(); ?>
          <?php   if (have_posts()) : ?>     <?php   $mosaics = new WP_Query('category_name=mosaics&posts_per_page=3'); ?>     <?php   while ($mosaics->have_posts()) : $mosaics->the_post(); ?>     <?php   if( $post->ID == $do_not_duplicate ) continue; ?>          <?php   echo get_the_content(); ?>     <?php   endwhile; ?>     <?php   endif; ?>     <?php   wp_reset_query(); ?>
          <?php   if (have_posts()) : ?>     <?php   $mosaics = new WP_Query('category_name=mosaics&posts_per_page=2'); ?>     <?php   while ($mosaics->have_posts()) : $mosaics->the_post(); ?>     <?php   if( $post->ID == $do_not_duplicate ) continue; ?>          <?php   echo get_the_content(); ?>     <?php   endwhile; ?>     <?php   endif; ?>     <?php   wp_reset_query(); ?>


title: How to use first tag in permalinks

text: i have tried `%tag%` in permalinks but it dont showing tag name in the permalinks... What i wanna do is to use the first tag name in the permalinks. So, how to do it? Thanks


title: Contact form with Jquery and PHP don't work

text:
<?php/*    Template Name: Contact  */?>     <?php get_header(); ?>         <?php               wp_enqueue_script( 'jquery.validate.min', get_bloginfo('template_directory') . '/js/jquery.validate.min.js', array('jquery') , 3.1, true );           wp_enqueue_script( 'jquery.form', get_bloginfo('template_directory') . '/js/jquery.form.js');           wp_enqueue_script( 'contact', get_bloginfo('template_directory') . '/js/contact.js');           wp_enqueue_style('contactstyle', get_template_directory_uri() . '/css/contactstyle.css');              ?>
                     <form id="contactform" action="processForm.php" method="post">

                             Name:	                             <input type="text" id="name" name="name" />

                             Email:	                             <input type="text" id="email" name="email" />

                             Message:	                             <textarea id="message" name="message" rows="5" cols="20"></textarea>

                             	                             <input type="submit" value="Send!" id="send" />

                 </form>

      also i have the `processForm.php`                  <?php         // Clean up the input values         foreach($_POST as $key => $value) {             if(ini_get('magic_quotes_gpc'))                 $_POST[$key] = stripslashes($_POST[$key]);                  $_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));         }              // Assign the input values to variables for easy reference         $name = $_POST["name"];         $email = $_POST["email"];         $message = $_POST["message"];              // Test input values for errors         $errors = array();         if(strlen($name) < 2) {             if(!$name) {                 $errors[] = "You must enter a name.";             } else {                 $errors[] = "Name must be at least 2 characters.";             }         }         if(!$email) {             $errors[] = "You must enter an email.";         } else if(!validEmail($email)) {             $errors[] = "You must enter a valid email.";         }         if(strlen($message) < 10) {             if(!$message) {                 $errors[] = "You must enter a message.";             } else {                 $errors[] = "Message must be at least 10 characters.";             }         }              if($errors) {             // Output errors and die with a failure message             $errortext = "";             foreach($errors as $error) {                 $errortext .= "
".$error."
";             }             die("The following errors occured:
". $errortext ."
");         }              // Send the email         $to = "MY-EMAIL";         $subject = "Contact Form: $name";         $message = "$message";         $headers = "From: $email";              mail($to, $subject, $message, $headers);              // Die with a success message         die("Success! Your message has been sent.");              // A function that checks to see if         // an email is valid         function validEmail($email)         {            $isValid = true;            $atIndex = strrpos($email, "@");            if (is_bool($atIndex) && !$atIndex)            {               $isValid = false;            }            else            {               $domain = substr($email, $atIndex+1);               $local = substr($email, 0, $atIndex);               $localLen = strlen($local);               $domainLen = strlen($domain);               if ($localLen < 1 || $localLen > 64)               {                  // local part length exceeded                  $isValid = false;               }               else if ($domainLen < 1 || $domainLen > 255)               {                  // domain part length exceeded                  $isValid = false;               }               else if ($local[0] == '.' || $local[$localLen-1] == '.')               {                  // local part starts or ends with '.'                  $isValid = false;               }               else if (preg_match('/\\.\\./', $local))               {                  // local part has two consecutive dots                  $isValid = false;               }               else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))               {                  // character not valid in domain part                  $isValid = false;               }               else if (preg_match('/\\.\\./', $domain))               {                  // domain part has two consecutive dots                  $isValid = false;               }               else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',                          str_replace("\\\\","",$local)))               {                  // character not valid in local part unless                   // local part is quoted                  if (!preg_match('/^"(\\\\"|[^"])+"$/',                      str_replace("\\\\","",$local)))                  {                     $isValid = false;                  }               }               if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))               {                  // domain not found in DNS                  $isValid = false;               }            }            return $isValid;         }              ?>      and the `contact.js`                 $(function() {             // Validate the contact form           $('#contactform').validate({             // Specify what the errors should look like             // when they are dynamically added to the form             errorElement: "label",             wrapper: "td",             errorPlacement: function(error, element) {                 error.insertBefore( element.parent().parent() );                 error.wrap("

");                 $("	").insertBefore(error);             },                  // Add requirements to each of the fields             rules: {                 name: {                     required: true,                     minlength: 2                 },                 email: {                     required: true,                     email: true                 },                 message: {                     required: true,                     minlength: 10                 }             },                  // Specify what error messages to display             // when the user does something horrid             messages: {                 name: {                     required: "Please enter your name.",                     minlength: jQuery.format("At least {0} characters required.")                 },                 email: {                     required: "Please enter your email.",                     email: "Please enter a valid email."                 },                 message: {                     required: "Please enter a message.",                     minlength: jQuery.format("At least {0} characters required.")                 }             },                  // Use Ajax to send everything to processForm.php             submitHandler: function(form) {                 $("#send").attr("value", "Sending...");                 $(form).ajaxSubmit({                     success: function(responseText, statusText, xhr, $form) {                         $(form).slideUp("fast");                         $("#response").html(responseText).hide().slideDown("fast");                     }                 });                 return false;             }           });         });      But the form only loading, and never sent the email. Also, o create a folder call php and put there the processForm.php but the result is the same. Any help for this? Thanks in advanced. **Updates:** **1st** I used the $.noConflict(); method with this uses:               $.noConflict();     $(function()      {         // Validate the contact form        $('#contactform').validate({      but i see an 404 error page. processForm.php **2nd:** `jQuery(document).ready(function($){` but not load the send email


title: Failed to invoke other hook from the init hook

text: Related to this question (Use wp init hook to call other hooks?) but not the same. Sometimes, I found that the hook will failed to run when I place inside the init hook, e.g. Not Work:               add_action('init','my_init');     function my_init() {         add_filter('locale', ...     }      Work:               add_action('init','my_init');     add_filter('locale', ...      Of course some hooks/filters will just work okay inside the init hook, but **definitely not all of them.** So it seems to me that **it is a bad practice to chain actions/filters together?**


title: Archive-Custom-Post-Type order by Event Date, ASC, and hide events that have completed

text: I am building a site for a personal project and I have a series of Events created via a Custom Post Type. I then need these events to be displayed by a custom meta value (Event Start Date) and in ASC order. I have managed to figure that out and the code I used is below:               /*CUSTOM ARCHIVE FOR EVENTS*/         function events_pagesize( $query ) {         // exit out if it's the admin or it isn't the main query         if ( is_admin() || ! $query->is_main_query() )         return;         // so its not admin, and its the main query, is it the tr-events post archive?         if ( is_post_type_archive( 'tr-events' ) ) {         // it is!! Set the posts_per_page to 6         $query->set( 'posts_per_page', 4 );         $query->set( 'order' , 'asc' );         $query->set( 'meta_key', 'wpcf-tr-order-date');         $query->set( 'orderby', 'meta_value');         return;         }         }         add_action( 'pre_get_posts', 'events_pagesize', 1 );      My question is how to hide posts past a specific date AND how would I also create an Archive view to display Events that have completed? I've seen tons of posts about this and most options break pagination. This option as a function in the functions.php gets me 70% there.


title: Custom Post Type, Taxonomy, and Geo-Coded Radius Search

text: I've been struggling with this for the last few days and just keep seem to get it right. Here's the situation: I have a provider directory (hospitals) in a custom post type. The 2,000+ providers were imported via CSV with location data, for which I then used the geomashup plugin to add coordinates as meta info. So all the posts have the necessary components to getting this done. Now what I need to do is build a search for on the frontpage that lets the user enter a zip code or city (text box), select a radius (in miles, from a dropdown list), and (optionality) a specialty (which is stored in a custom taxonomy). I've messed with a loop based on the query info in the geomashup docs, but to no avail. I've been plugging in specific lat/long coordinates which should return results, yet nothing shows up. Here's the query code I've been using:               <?php      $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;          $rq = new WP_Query( array(         'posts_per_page' => 9999,         'paged' => $paged,         'geo_mashup_query' => array(                 'near_lat' => 26.055,                 'near_lng' => -80.153,                 'radius_mi' => 50,         ),     ) );          while ($rq->have_posts()) : $rq->the_post(); ?>      Ultimately, I need help figuring out how to configure the search form on the homepage, pass the variables to the search results page, and get results to show up. There are various "find nearby" plugins and answers here related to radius searches, but there are simply too many of these items and they needed to belong in a CPT w/ custom taxonomy and not be plugin based.


title: Links on FAQ page aren't working

text: I apologize if this is a naive question. I'm a Ruby on Rails developer and I'm not yet very comfortable with WordPress. I built a WP site featuring an FAQ page using Q and A Focus Plus FAQ plugin. It works just fine except none of the links on the FAQ page, despite having valid `href` attributes, actually work. You can see what I'm talking about if you visit my site. I don't really know where to begin trying to debug such a funky problem. It of course seems like it should just work out of the box. Any advice?


title: Adding a "Sign In/My Account" link to an external app

text: I'm using (or I'm going to use) WordPress for my product's marketing site. I use Rails for the product's application. Right now on my marketing site, which is currently in Rails, I have a link that reads either "My Account" or "Sign In" depending on whether you're signed in or not. I'd like to duplicate this feature on my WP site but I of course won't have the privilege of doing it in as direct a way as I am on my Rails marketing site now. I'm thinking I'll want to keep track via a cookie whether the user is logged in, which I assume is possible because the application and marketing site will both be on the same TLD. What's not clear to me is what would be a good way to read that cookie in WP. Any suggestions?


title: How to enable Zend Optimiser+ with Batcache

text: I am using Batcache with APC Object Cache Backend so far. A lot of posts on internet claiming that using Zend Optimizer instead of APC would reduce CPU and memory usage. I could enable Zend Optimizer on my server. But I haven't found a plugin or workaround to make Batcache works with Zend Optimizer. Is that a "Zend Optimizer Object Cache Backend" for Batcache? How to make Batcache use Zend Optimizer? Thank you.


title: Wordpress Custom field Colors

text:
I came across this code and would like to use it in my project. It works fine, but the problem is, I need to change those colors in the array to instead pick transparent images from url since I am using it for background. My first option was to find if someone could change the solid color to a gradient, but due to the complexity in my project, picking background images will be simpler.               /* Define the custom box */     add_action( 'add_meta_boxes', 'wpse_61041_add_custom_box' );          /* Do something with the data entered */     add_action( 'save_post', 'wpse_61041_save_postdata' );          /* Adds a box to the main column on the Post and Page edit screens */     function wpse_61041_add_custom_box() {         add_meta_box(              'wpse_61041_sectionid',             'Title Color',             'wpse_61041_inner_custom_box',             'post',             'side',             'high'         );     }          /* Prints the box content */     function wpse_61041_inner_custom_box($post)     {         // Use nonce for verification         wp_nonce_field( 'wpse_61041_wpse_61041_field_nonce', 'wpse_61041_noncename' );              // Get saved value, if none exists, "default" is selected         $saved = get_post_meta( $post->ID, 'title_color', true);         if( !$saved )             $saved = 'default';              $fields = array(             'red'       => __('Red', 'wpse'),             'green'     => __('Green', 'wpse'),             'blue'      => __('Blue', 'wpse'),             'default'   => __('Default', 'wpse'),         );              foreach($fields as $key => $label)         {             printf(                 '<input type="radio" name="title_color" value="%1$s" id="title_color[%1$s]" %3$s />'.                 ' %2$s ' .                 '
',                 esc_attr($key),                 esc_html($label),                 checked($saved, $key, false)             );         }     }          /* When the post is saved, saves our custom data */     function wpse_61041_save_postdata( $post_id )      {           // verify if this is an auto save routine.            // If it is our form has not been submitted, so we dont want to do anything           if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )                return;                // verify this came from the our screen and with proper authorization,           // because save_post can be triggered at other times           if ( !wp_verify_nonce( $_POST['wpse_61041_noncename'], 'wpse_61041_wpse_61041_field_nonce' ) )               return;                if ( isset($_POST['title_color']) && $_POST['title_color'] != "" ){                 update_post_meta( $post_id, 'title_color', $_POST['title_color'] );           }      }      And the code link: Add a checkbox to post screen that adds a class to the title


title: Disable wordpress widget automatically on error

text: I have a small widget which gets some information from other websites. Now, at times it is possible that these other websites are not available. Is it possible to disable or hide a widget automatically (through the `WP_Widget` class, i.e. in my code that extends it) whenever I detect an error? I don't wish to disable it permanently, I just don't want to have failures that break my page and at the same time I don't want to display things like 'Error retrieving data' or whatever... I just want to hide the widget all along.


title: How to add categories to products in woocommerce programatically?

text: I have studies the database intensively and know which all tables are updated when a category is added to a product. Is there any inbuilt woocommerce function to add categories? It updates 2 or 3 tables but want to leave it to woocommerce. Thanks for your help.


title: Adding different classes to anchor in navigation menu

text:
Is this possible? I want to add different classes to the anchors, so not the same on all anchors. How can I do this? PS: I am using this:               function add_nav_class($output) {         $output= preg_replace('/<a/', '<a class="your-class"', $output, 1);         return $output;     }     add_filter('wp_nav_menu', 'add_nav_class');      But I want to add different classes to the links... So like this:

      and so on...


title: select post preview image from nextgen gallery

text: My website has a theme that uses the preview images in the post overview pages. However these images are neither automatically selected nor did I select an image in the past. However, even if I try to select an image. For example within a page that only shows a gallery such as this one I can not select any image for the nextgen gallery. The only images that I see are the ones directly within `/files`. Which were uploaded with the media library (which I dislike because it puts all files in a flat directory structure). My gallery files are in the sub folder (and its subfolders) `/files/gallery`. So how can I use gallery images for a post preview?


title: If modified on same day, show only time

text: I have a date on each post and comment which shows the date of placement. If I edit it, it shows me the date of the post and the modified date. That's fine, but now, I want to show only the post date AND the TIME of the modified date only if the post is edited on the same day as it's posted. So for example:               If a post is has been submitted on 8 march 2013 15:00, show me: 08-03-2013 15:00     If a post is edited on 8 march 2013 16:30, show me: 08-03-2013 15:00 - 16:30     If a post is edited on 9 march 2013 17:00, show me: 08-03-2013 15:00 - 09-03-2013 17:00      How can I do this? I am using something like this, except for the AM and PM.               <?php the_modified_date('F j, Y'); ?> at <?php the_modified_date('g:i a'); ?>      How can I only show the time if it's modified on the same date?


title: Just migrated site, and now it cannot find the WP-Contents folder

text: I use Backup Buddy a lot to migrate a dev site to production, but for some reason I'm having a problem on this one. The site seemed to install fine at the new location, but when I try and update a plugin via SSH in WP-Admin, it's telling me it is "Unable to locate WordPress Content directory (wp-content). Also, if I copy a new plugin into the plugins folder, WP-Admin doesn't pick it up. I've click on Permalinks to make sure that is working okay. The site acts like it's working fine, but something is screwed up, and I'm now sure what to do. My wp-config file has this for the path:               /** Absolute path to the WordPress directory. */     if ( !defined('ABSPATH') )     define('ABSPATH', dirname(__FILE__) . '/');          /** Sets up WordPress vars and included files. */     require_once(ABSPATH . 'wp-settings.php');      Anyone have any ideas? Thanks! Note: If this matters, the dev server was Ubuntu 12.04 LTS and the production server is Debian 7.3. Both using a LAMP stack.


title: Getting the author name on author archive page

text: My template not work for author name on author archive. I tried change to get_the_author but nothing changed. Hope someone help me out. Thank in advance. ![enter image description here](http://i.stack.imgur.com/ozxRo.png)


title: How to display a list of categories

text: I'm trying to set up a list of categories with clickable links to that category. I've looked at:   * Display list of Sub-Categories and the posts they contain, within one main Category and am not quite sure where to put the code or how to access it on the page. I understand the PHP well enough - it's pretty straightforward, I'm just relatively new to WP and need some help implementing.


title: Unautop / Sanitize content added to a post through a plugin

text: I am using the SimpleReach plugin that adds some content to every post using the content hook. The content that is being added is               <!-- SimpleReach Slide Plugin Version: {{srslide_plugin_version}} -->     <script type='text/javascript' id='simplereach-slide-tag'>         __reach_config = {           pid: '{{srslide_pid}}',           title: '{{title}}',           tags: {{{tags}}},           authors: {{{authors}}},           channels: {{{channels}}},{{slide_logo_elem}}           slide_active: {{srslide_disable_on_post}},{{slide_icon_elem}}           date: '{{published_date}}',           url: '{{canonical_url}}',           header: '{{srslide_header_text}}'         };         var content = document.getElementById('simplereach-slide-tag').parentNode, loc;         if (content.className){ loc = '.' + content.className; }         if (content.id){ loc = '#' + content.id; }         __reach_config.loc = loc || content;         (function(){         var s = document.createElement('script');           s.async = true;           s.type = 'text/javascript';           s.src = document.location.protocol + '//d8rk54i4mohrb.cloudfront.net/js/slide.js';           __reach_config.css = '{{srslide_css_url}}';           var tg = document.getElementsByTagName('head')[0];           if (!tg) {tg = document.getElementsByTagName('body')[0];}           if (tg) {tg.appendChild(s);}         })();     </script>      However Wordpress is sanitizing the content by adding extra breaks and paragraphs before and after. I want to disable autop only for this content so that breaks/paragraphs aren't added. Is there a way to do it?


title: Wordpress, alternative single post template

text: For a project of mine I need to define an alternative template for single posts. To be more specific I need each post to be displayed as usual when the website is browsed but I need to create different single pages reachable from different URL to create a sort of a mini-website for each post. (I'm actually using the WooCommerce plugin and what I need to do is to create a mini-website for each product. This needs to be something "outside" from the main website, with a complete different graphic template and is going to be reachable through a QR-code). Hope it makes a bit of sense. Thanks for your advices and/or suggestions. Angelo


title: Get publish post link?

text: Is there a way I can call a link so when clicked it publishes the post via the ID I provide? I have `get_delete_post_link( $postID )` set fine, and would like to do the same to make a draft go to published, or if you can't publish post, make it pending. I also have this code running in my functions.php file so may be also a way to call this if a link is clicked.


title: get_delete_post_link redirect

text: I am using this to allow users to delete their own posts on the front end of my site:               <a onclick="return confirm('Move this post to the trash? You can restore it later.');" href="<?php echo get_delete_post_link($postid); ?>">Trash Post      The problem is, this refreshed the current page and adds some query args to the URL (trashed=1 and ids=123). What I want to happen is that the user is redirected to a certain page with specific query args, like so:               mysite.com/yourarticles/?user=123&post=321&action=trash      How can I change where the get_delete_post_link function redirects to?


title: Custom URL rewrite rule for migrating to WordPress

text: I am trying to move my image gallery site from one CMS to Wordpress. On current CMS I have page with medium size image on it with URL: www.my-example-site.com/folder-one/subfolder-one/example-image-name.jpg.html and another page with full resolution of same image on it with URL like this: www.my-example-site.com/full-image/folder-one/subfolder-one/example-image- name.jpg-some-custom-keywords.html I managed to make same address on test WP for medium size image, I created same categories with, and used same URL slug for categories. After that, under settings --> permalinks I made custom URL structure like: www.my-example-site.com/%category%/%postname%.jpg.html and that made me the same urls for page with medium size image on it. But, problem is with page with full size image on it. Is there any way (some rewrite rule or something) to get another page to. It could be 301 redirect to something like this: www.my-example-site.com/folder-one/subfolder-one/example-image- name.jpg.html?-some-custom-keywords.html or anything similar, just to be able to use data as like on stardard page. than I can use custom url check (on very top of single.php) to see if page contains "?-some-custom-keywords.html" to include file for generating that new page, if there is no that variable to include file for generating standard post page. Please note that there are multiple different combination for "-custom- keywords.html" suffix (about 15) If you have any question or suggestion please ask. Regards.


title: Custom title for custom post types

text: I need to change the title for a custom post type ("movie") in my site. I added the following function to my functions.php file but I see no changes in the title:               function theme_wp_title( $title, $sep ) {         global $wp_query, $page, $paged;              if ( is_feed() )             return $title;              // Add the blog name         $title .= get_bloginfo( 'name' );              // Add the blog description for the home/front page.         $site_description = get_bloginfo( 'description', 'display' );         if ( $site_description && ( is_home() || is_front_page() ) )             $title .= " $sep $site_description";              if ($wp_query->query_vars['post_type'] == 'movie') {             $title .= "movie ";         }              // Add a page number if necessary:         if ( $paged >= 2 || $page >= 2 )             $title .= " $sep " . sprintf( __( 'Page %s', 'theme' ), max( $paged, $page ) );              return $title;     }     add_filter( 'wp_title', 'theme_wp_title', 10, 2 );      Any ideas? Thanks


title: What is the correct way to integrate wordpress with another php application?

text: I want to integrate wordpress blog with another php application so both will have same theme and when i do changes in wordpress menu or wordpress sidebar, the changes will apply automatically to the other php application pages.


title: Themes and Plugins page "not found"

text: When trying to access my Themes or Plugins page on the three Wordpress sites I run they are all listed as "Not Found". I am not sure when this started, but I recently set up my third site and was looking to change the base 2014 theme when I noticed this issue. I checked my other two sites and was given the same error. I checked other pages in the Dashboard and was able to navigate normally, I have no idea what is going on. Running version 3.8.1


title: wp_set_object_terms bugging

text: I'm working on a plugin where I set custom terms for posts on save. I use the save_post hook. It all works fine except when I for example also change the title of the post, the custom terms setting doesn't work. What's up with that?               function on_post_save($post_id) {         if (!isset($_POST['ccadmin-' . $this->box_id])) {             return;         }              if (!wp_verify_nonce($_POST['ccadmin-' . $this->box_id], 'ccadmin-action-' . $this->box_id)) {             return;         }              if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {             return;         }              if (isset($_POST['post_type']) && 'page' == $_POST['post_type']) {                  if (!current_user_can('edit_page', $post_id)) {                 return;             }              } else {                  if (!current_user_can('edit_post', $post_id)) {                 return;             }         }         ?>             <pre>         <?php             //var_dump($_POST);         ?>             </pre>         <?php         //die();         $child_taxonomy = $_POST['child_' . $this->taxonomy];         remove_action('save_post', array(&$this, 'on_post_save'));         wp_set_object_terms($post_id, (int)$child_taxonomy, $this->taxonomy, false);          }      Thanks in advance!


title: Menu not always using correct link

text: I moved a Wordpress install from /wordpress/ folder to root by just copying the index and .htaccess file to root and then updating the permalinks etc. All works fine but I have a problem with the menu in the top nav. The menu works fine while you're on the main page and scrolls down to the area it should be. But when you go to one of the posts under services like http://angrychickenmedia.com.au/filming/ and then press on for instance "team" in the menu it will point to http://angrychickenmedia.com.au/wordpress/#team thus suddenly adding the /wordpress/ to it and ending up at a blank page. Anyone have an idea how I can solve this?


title: CSS changes not taking effect

text: I make changes to my style.css file but they do not take effect on the website. Style.css is located here: /wp-content/themes/academy/style.css I have made changes to it previously and the changes did take effect, but now I'm making new changes and they're not. I have tried adding the CSS with the changes via FTP, and I have also tried using the "Editor" from the Wordpress menu. If I view the source of the CSS file in the browser the changes do not appear. I can pull the file off my server with FTP and look at the code and see that the CSS is there. I can also see the CSS in the Wordpress editor. I have cleared the cache and cookies, refreshed the browser, used different browsers (Firefox and Chrome). The CSS that I am entering is valid. Just a simple:               #bg-image {      position: fixed;       top: 100;       left: 0;       min-width: 100%;      min-height: 100%;      }      I've waited about an hour thinking there might be a delay. It's still not working. My main questions are: 1.) Do I need to somehow "trigger" the new file to actually take effect? 2.) Is Wordpress doing something internally to cache the old file and if so, can I turn this feature on/off when I need to?


title: Adding an Options Page to a Plugin

text: The first set of code adds a menu item to the sidebar. I'm attempting to add an options page (the type which shows up as a sub-page) under this. I tried to do so with the second code... but this isn't working. How do I add an options page under a plugin's menu?               // Add menu page in sidebar     function admin_menu_wlseo() {       add_menu_page('SEO', 'SEO', 'manage_options', 'wlseo', 'options_page_wlseo');     }          // Add options page in sidebar     function admin_stuff_wlseo() {       add_options_page('Stuff', 'Stuff', 'manage_options', 'wlseo-stuff', 'options_page_wlseo');     }


title: Sort All Posts by Category Name in the Admin Panel?

text: I'm working on a pretty complicated site where everything is managed by category type including automatic spinner image submission, etc.. Unfortunately, its doggone difficult to manage things when the admin panel "All Posts" sorts them by date (DESC) I'm thinking it sure would be handy to have the show "All Posts" in category name order. I Found this small routine, that works for sorting by Post name.                /*      Plugin Name: Set Post Order In Admin      Version: 0.1      Plugin URI: http://wordpress.org/support/topic/336715/      Description: In Posts->Edit, display posts in title order.      Author: MichaelH      Author URI: http://codex.wordpress.org/User:MichaelH/MyPlugins      check out: http://codex.wordpress.org/Class_Reference/WP_Query      in the section order and orderby parameters  */      function set_post_order_in_admin( $wp_query ) {         if ( is_admin() ) {                $wp_query->set( 'orderby', 'name' );              $wp_query->set( 'order', 'ASC' );  /* ASC or DESC */         }      }      add_filter('pre_get_posts', 'set_post_order_in_admin' );      That works okay for sorting by title, but I really need to be able to sort by category name. I tried playing with the $wp_query->set( 'meta_key', 'category' ); and $wp_query->set( 'orderby', 'meta_value' ); but when I started using those, I just got an empty return for All Posts within my admin panel. Any ideas on what is missing? I've tried a number of terms for 'meta_key' all of them fail. Anybody been here before? Any idea on how to achieve the goal of sorting All posts in the admin panel by category (parent)?? many thanks, zip.


title: Category location styling

text:
http://www.milknhny.co.uk/DVine/?page_id=19 Please can someone help, i have added the categories, however it appears to be off line. I have tried to style this in a class but this screws up the whole thing. I wrapped like the below but it seemed to apply to the whole of the div it was wrapped in
<?php get_category(); ?>
      Please can someone assist, do i edit the main style within the themes? Your help is greatly appreciated. Thanks


title: Want home page to click through to two different page types

text: Looking for correct vocabulary to accomplish the following: Home page to show small images for following pages. On click through, (editor chooses) to display distinct page type: EITHER 1: Page that displays in sequence: long text description, multiple images. OR 2. Page that displays image-only gallery with simple right-left arrow navigation to short series of images. Both types of pages will exist on the site. thank you!


title: wp_update_user isn't instantly?

text:
I'm trying to update a user mail recieved by $_POST and use it instantly. It gets changed, however it outputs the old one. What is the way to do it?               global $current_user;     get_currentuserinfo();          if (isset($_POST['email'])) {             wp_update_user( array('ID' => $current_user->ID, 'user_email' => $_POST['email']) );             get_currentuserinfo(); //just in case     }          echo '
You'll recieve a mail here: ' . $current_user->user_email . '
'; //outputs old mail      Maybe it has to be with the global $current_user var? EDIT: Chuncky fix,               global $current_user;     get_currentuserinfo();          $email = $current_user->user_email;          if (isset($_POST['email'])) {          wp_update_user( array('ID' => $current_user->ID, 'user_email' => $_POST['email']) );          $email = $_POST['email'];     }          echo '
You'll recieve a mail here: ' . $email . '
';


title: Breadcrumb not showing custom category post type

text:
I have an issue when it come to displaying the custom post type category in my breadcrumb menu on the page it looks something like the following Home / / Post Title _when it should be_ Home / Custom Cat Name / Post Title It shows the post on the page and the posts title but not the category? Breadcrumb menu code:                           /*********************                 breadcrumbs menu                 *********************/                 function the_breadcrumb(){                     echo '
';                     if (!is_home()){                         echo '
';                         echo 'Home';                         echo '

 |
';                         if (is_category() || is_single('post')){                             echo '
';                             the_category('

 |

 ');                             if (is_single()){                                 echo '

 |

';                                 the_title();                                 echo '
';                             }                         } elseif (is_page()){                             echo '
';                             echo the_title();                             echo '
';                         }                     }                     elseif (is_tag()){                         single_tag_title();                     }                     elseif (is_day()){                         echo"
Archive for "; the_time('F jS, Y'); echo'
';                     }                     elseif (is_month()){                         echo"
Archive for "; the_time('F, Y'); echo'
';                     }                     elseif (is_year()){                         echo"
Archive for "; the_time('Y'); echo'
';                     }                     elseif (is_author()){                         echo"
Author Archive"; echo'
';                     }                     elseif (isset($_GET['paged']) && !empty($_GET['paged'])){                         echo "
Blog Archives"; echo'
';                     }                     elseif (is_search()){                         echo"
Search Results"; echo'
';                     }                     echo '
';                 }      Thanks


title: What is the index [0] for on post meta fields?

text: Trying to improve my PHP knowledge through test and try! I am confused on [0] arguments at following WordPress PHP code               global $post;     $custom = get_post_custom($post->ID);     $price = $custom['price'][0];     $coMake = $custom['coMake'][0];          echo $custom['price'][0];      Are they for indexing/referencing inputs on the page? if so why they are same?! can you please let me know why and when to use them?


title: Get page id by title?

text: I'm using the following code to insert the content from another wp page into my main home page. Is it possible to make it work with a page **title** instead of an id number? Eg. Not $page_id = 518 but $page_id = 'about' instead????               $page_id = 518; //Your Page ID     $page_data = get_page( $page_id );     // Displays the title     echo '<h1>'. $page_data->post_title .'</h1>';     // Displays the content     echo apply_filters('the_content', $page_data->post_content);     ?>


title: Set parent theme language with custom .mo files

text: I am using Buttercream as my parent theme. I have translated the .mo file located in `themes\buttercream\languages` and saved it as `nl_NL.mo` and `nl_NL.po`. Now I want to display the parent theme in Dutch (`nl_NL`). I can't edit `functions.php` of the parent theme because if it gets updated I'll lose my changes. What do I have to do to get the theme in another language?


title: Database sync between local and production

text: I was watching Mark Jaquith's presentation at WCSF 2013 recently and in the Q&A Mark mentioned something about rsync - after a quick Google I can see this is done via SSH - my question is this: is this something that can be done to a local development environment? Do you still need to copy the database and change configuration, url references etc? For a local setup should I just stick to using a script to change the references?


title: Turn raw url into clickable links

text: I have a custom field that contains a bunch of urls in it. I want them to be clickable links in that custom field only. How can I do this? I could just manually convert them to html links but that's too time consuming for 100+ links


title: Does Akismet plugin expose any hooks, functions, class that can work with custom code?

text: I have custom code that handles comment insertions using `wp_insert_comment`. Does `Akismet plugin` expose any hooks, functions, class that can work with the same and possibly elsewhere where custom forms for user content submissions are involved? Or do I need to write custom code to make calls to Akismet API?


title: Order posts alphabetically: how to set order=asc in mysql query?

text: I have this `function`:                 global $wpdb;       // adjust the query to fit your needs         $posts = $wpdb->get_results( $wpdb->prepare(         "SELECT * FROM $wpdb->posts WHERE         post_type = 'post' AND post_status = 'publish' AND         post_title LIKE %s",      How do I set the order => ASC in this query? I want to show my `posts` alphabetically...


title: Show menu in sidebar if on specific page AND specific user role (is_page, current_user_can)

text:
I tried combining two conditions: is_page and current_user_can but it didn't work. Found an example at StackExchange where the user role was spelled out. But the Wordpress codex says "Do not pass a role name to current_user_can(), as this is not guaranteed to work correctly." On the same page, this link is included for reference/further reading: http://docs.appthemes.com/tutorials/wordpress- check-user-role-function/ I tried adapting that code, and added this to my functions.php               function plastics_check_user_role( $role, $user_id = null ) {          if ( is_numeric( $user_id ) )     $user = get_userdata( $user_id );     else         $user = wp_get_current_user();          if ( empty( $user ) )     return false;          return in_array( $role, (array) $user->roles );     }      Then, here's what I put in the sidebar.php file:               <?php         if (is_page(array('page1')) && plastics_check_user_role('Administrator')) :             echo '
Title 1
' . wp_nav_menu(array('theme_location'=>'menu1' ));         elseif (is_page(array('page2'))) :             echo '
Page 2
' . wp_nav_menu(array('theme_location'=>'menu2' ));         elseif (is_page(array('page 3'))) :             echo '
Page 3
' . wp_nav_menu(array('theme_location'=>'menu3' ));         endif;     ?>      Still not working. What am I missing? Is it because it's in the sidebar? * * * I prefer to spell out the role - not specify user capabilities - because my 5 custom user roles have exactly the same capabilities, but I restrict pages based on the role. (Hacky workaround: I could add custom capabilities to each role, but that seems like a strange way of doing it....)


title: frontend show edit profile with selected custom options

text: So I have many custom user profile fields. When I use `do_action( 'show_user_profile', $profileuser );` hook it displays all custom user profile fields.. But I would like to show only certain fields. For example               add_action('show_user_profile', 'add_extra_profile_fields1');          function add_extra_profile_fields1() {         // add extra profile fields to user edit page     }          add_action('show_user_profile', 'add_extra_profile_fields2');          function add_extra_profile_fields2() {         // add extra profile fields to user edit page     }      Now is there a way to display only `add_extra_profile_fields2` using `show_user_profile` hook?


title: How do I enable HTML5 prefetching on this page?

text: Site example: http://www.ianstuart-bride.com I currently have this bit of code in header.php, but it does not work as desired:               <?php if (is_archive() && ($paged > 1) && ($paged < $wp_query->max_num_pages)) { ?>         <link rel="prefetch" href="<?php echo get_next_posts_page_link(); ?>">         <link rel="prerender" href="<?php echo get_next_posts_page_link(); ?>">     <?php } elseif (is_singular()) { ?>         <link rel="prefetch" href="<?php bloginfo('home'); ?>">         <link rel="prerender" href="<?php bloginfo('home'); ?>">     <?php } ?>      The homepage prefetch points to a non-existent page. I would like to disable prefetching on the homepage. I want to enable prefetching on these pages, for the 'Next' dress. This is the code for the single dress pages. I tried this, but it linked to the current page instead of the next one:                   <link rel="prefetch" href="<?php echo get_permalink($next_dress) ?>">         <link rel="prerender" href="<?php echo get_permalink($next_dress) ?>">


title: How to add to cart via AJAX Woocommerce

text: I have been searching for a while, this. I want to add an item via AJAX. When you add an item to a cart in Woocommerce the page reloads with the GET parameter `add-to-cart="The current product ID"`. I want to do it via AJAX. In the admin area is a checkbox to enable that featured that is labeled "Enable AJAX buttons to add to cart on the product list" But it doesn't do anything, it stills reloading the page.


title: Custom product slider from woocommerce products

text:
I want to create a custom products slider for my woocommerce theme. I want to retrieve the thumbnails from my products with a custom taxonomy (`product_tag`) for example "t-shirt". I'm calling the "product_tag" like this :               <?php      $categories = get_terms( 'product_tag', 'orderby=count&hide_empty=0' );           $count = count($categories);      if ( $count > 0 ){          echo "
";          foreach ( $categories as $categories ) {            echo "
" . $categories->name . $categories->count . "
";               }          echo "
";      }          ?>       But how can I get the URL thumbnails from this `product_tag`? Something like `wp_get_attachment_url( $id )` but for products?


title: Child page Custom post type return 404

text: I have a custom post type with this structure > parent/child-1/child-2-of-child-1/child-3-of-child-2/ All child return 404 error. My CPT settings are:               $rewrite = array(             'slug'                => 'guide',             'with_front'          => true,             'pages'               => true,             'feeds'               => true,         );         $args = array(             'label'               => __( 'Guide', 'text_domain' ),             'description'         => __( 'Guide Description', 'text_domain' ),             'labels'              => $labels,             'supports'            => array( 'title', 'editor', 'custom-fields','author','page-attributes' ),             'hierarchical'        => true,             'public'              => true,             'show_ui'             => true,             'show_in_menu'        => true,             'show_in_nav_menus'   => true,             'show_in_admin_bar'   => true,             'menu_position'       => 100,             'menu_icon'           => '',             'can_export'          => true,             'has_archive'         => true,             'exclude_from_search' => false,             'publicly_queryable'  => true,             'rewrite'             => $rewrite,             'capability_type'     => 'page',         );      I flushed my rules but 404 is always returned


title: Three menus - parent / child / sibling

text: Firstly, apologies for the terminology used here, I will try to be as descriptive as possible. I am trying to create a menu system that will achieve the following:   1. List top level pages as one menu (level 1)   2. When on a top level page, list the child pages in a separate menu (level 2)   3. When on a child page, list the child pages of that child as a further separate menu (level 3) From the Codex this creates the menu which happily lists 3 levels of pages:               <?php if(!$post->post_parent){         // will display the subpages of this top level page         $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");        }             else{         // diplays only the subpages of parent level         //$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");              if($post->ancestors)         {          // now you can get the the top ID of this page          // wp is putting the ids DESC, thats why the top level ID is the last one          $ancestors = end($post->ancestors);          $children = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0");          // you will always get the whole subpages list         }        }             if ($children) { ?>         <ul>          <?php echo $children; ?>         </ul>        <?php } ?>      This is fine, but all page listings are in a single list, in one place. I need to split this out so I can just grab the child pages, and display that menu in a `<div>` in one part of my page, then i need to grab the third level pages, and display those in another part of my page, in a separate `<div>.` Any clues how to do this? Many thanks


title: Server B handling add_image_size() differently than Server A

text: I'm curious what dependencies `add_image_size()` has because I just copied a theme over to a new server and began adding thumbnails to custom post types only to find out that my request for hard-cropping is being ignored, and the images are kept proportional. **functions.php**               ...     set_post_thumbnail_size( 80, 80, true );     add_image_size( 'micro', 32, 32, true);     add_image_size( 'featured', 340, 225, true );     add_image_size( 'videowide', 460, 225, true );     ...      On my local server (WAMP Server on Windows Vista) the `true` is respected, and the images are cropped in such a way that extra pixels are lost - edges aren't respected. On my live server (CloudLinux Server 5.5 x64), the images are kept proportional. Is there some gdlibrary dependencies or something I am needing to change on the live server to get the expected results?


title: Is it possible to filter get_adjacent_post() with tags?

text: I've been using get_adjacent_post() to determine the previous and next posts. How would I go about determining the next and previous links to posts matching the same tag as the current post? It seems this function allows you to do this with posts in the same category, but not with the same tag.


title: Custom Comment Types

text: I have created a custom post type for a sort of gallery whereby users can upload work etc. In addition to this I have taxonomies for this type such as categories, tags, colors, etc. But I want users to be able to do two things. a) comment b) critique. As far as I know WordPress doesn't support Custom Comment Types so I can't create the critique comments, any ideas on how I could do this? Thanks.


title: Hook in a sidebar widget and add some markup

text: I'm looking to hook into a sidebar widget, this one in particular loads the members. All I'm looking to do is add a link into the widget, I managed to get a result but it's not quite right. It doesn't load the original function, instead it replaces it. Here's how I far I got:               function members_dir_link(){     echo 'View Members';     }     add_filter('bp_has_members','members_dir_link');


title: Change Permalink Structure for Tag.php template

text: Im using a custom post type to build a filterable gallery and taking advantage of the tags taxonomy within it. I am also using a custom taxonomy called years. at the moment, the permalink structure of the gallery page is `www.example.com/gallery` it is filtered by tags and years. i have made a `taxonomoy-years.php` template and used               'rewrite' => array('slug' => 'archive/projects', 'with_front' => false)      to change the permalink structure from www.example.com/years/2000 to www.example.com/archive/projects/2000 when you filter using years. When i filter using tags, its running off a the `tag.php` template, so the permalink structure is `www.example.com/tag/studentwork` but i would like it to be `www.example.com/archive/tag/studentwork`. This is the code that defines my custom post type:               function add_post_type($name){              add_action('init', function() use($name)  {              register_post_type($name,array(             'public' => true,             'label' => ucwords($name),             'labels' => array(                 'add_new_item' => "Add new $name item",                 'edit_item' => "Edit $name item"             ),             'supports' => array('title', 'editor', 'excerpt', 'comments', 'thumbnail'),             'taxonomies' => array('post_tag'),                   ));     });          }      Can anybody help?


title: Automatically adding a link to the next page link before '<!--nextpage-->' tag in posts?

text: I'm using the following snippet to automatically break a too long post into multiple pages               function filter_more_with_nextpage( $content ){              $content = str_replace( '<!--more-->', '<!--nextpage-->', $content );         $content = preg_replace( '/<!--nextpage-->/i', '<!--more-->', $content, 1 );              return $content;     }     add_filter( 'content_save_pre', 'filter_more_with_nextpage' );      works like a charm, but I'd like to add automatically a link `<a>` element before the page break to help directing users to the following page. I don't wish to put the link in the post content manually (from wp backend) nor have it inserted automatically in the post content (I don't want it saved along the post itself). Rather, I'd wish to have it generated just before `<! --nextpage-->` tag breaks the current page.


title: Weirdness in jQuery supplied with WordPress

text:
I've got a problem with the jQuery supplied with WordPress. The following HTML exhibits this problem:               <!DOCTYPE html>

                                      This is a typical situation in my WordPress site, where WordPress's jQuery is included (for the admin bar) at `<head>`, and my own CDN / fallback jQuery is included before the end of `</body>`. The console output of this page is:               window.jQuery     Uncaught TypeError: Property '$' of object [object Object] is not a function       I can solve this problem in several ways, for instance, I could replace the jQuery `<script>` part in `<body>` to:                     Without the `window.jQuery` check. But this is not optimal considering I've included jQuery twice. I then tried replacing the `<script>` in `<head>` to:                     Surprisingly, this also solved the problem. I knew about `wp_deregister_script`, but for admin, this also disables jQuery in the dashboard. I'd like to retain admin bar for admin. So currently the site only breaks (see console output above) when admin is logged in. I'm wondering if the jQuery supplied with WordPress is anything special. I'm using version 3.5.1, and I'm planning on using jQuery in my own theme. Should I just include it twice to address this issue?


title: Output shows a page instead of a list of blog postings

text:
I have the below code in `front-page.php` (with that page set in Settings > Reading); however, something is wrong because the posts aren't showing. The output is shown below. Can someone identify what the problem may be?                   <?php get_header();?>

Latest News
                              <?php if (have_posts()) : while (have_posts()) : the_post(); ?>                                  <article class="entry" id="post-<?php the_ID(); ?>">                                 <?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?>

<?php the_title(); ?>
                                     <time datetime="<?php the_time('c'); ?>"><?php the_time('F d, Y'); ?></time>                                     <?php the_content(); ?>
Categorized under: <?php the_category(', '); ?>
                                     <a class="read-more" href="<?php the_permalink() ?>" rel="bookmark" title="Read <?php the_title_attribute(); ?>">

                              <?php endwhile; ?>                              <?php my_paginate_links(); ?>                              <?php endif; ?>

              <?php get_sidebar(); ?>         <?php get_footer(); ?>      The code above outputs the html below. Note: "Home" is a page, not a post.

Home
             <time datetime="2012-08-29T06:38:44+00:00">August 29, 2012</time>
Categorized under:


title: site-description css is overriden

text: I'm trying to change the site-description color of my twentythirteen header to #220E10. My style.css file reads :               .site-description {         font: 300 italic 20px "Source Sans Pro", Helvetica, sans-serif;         color: #220E10;         text-align: center;         margin: 0;         padding-bottom: 25px;     }      However, the color of my header (viewable here) remains #FF6000. I know the css file is the used as a source for size, font and other details, since I can effectively change those and see the results happen. The color will not change however. I suspect the override has something to do with the basic Wordpress editor which allows you to change the color of your header text. I can't seem to be able to identify the location of the source css being used for this color. The #FF6000 color is not present in my style.css file, except for that intentional navbar. Could you help me edit the site-description to a different color ?


title: Custom post types and categories for my unique permalink situation

text: recently I've taken on a project that is a bit overwhelming due to the fact I have never made a website this big before. It's a travel website that features reviews, photos, user articles, etc. Anyways, I've been reading a lot of threads here about custom post types, categories, and taxonomies, but I'm a very indecisive person and would like some of your guys' advice on how I should tackle this specific permalink structure. So let's get down to it. There are currently 4 'post types' of the site that include: destinations / travel-logs / photo gallery / hotel reviews. I was also given a permalink structure that goes like this (with example):               site.com/post-type/continent/country/city/     site.com/travel-logs/europe/france/paris/      So my idea is to set each 'post type' as custom post types, then each continent/country/city as categories. For you skimmers:               'travel-logs,destinations,etc' => custom post type     'continent,country,city' => category      My question is this: will it work? If I have 5 custom post types and a ton of hierarchical categories for the locations, will it work and be efficient? Or should I use taxonomies instead of custom post types?


title: Need some hints for my own WP theme development

text: After taking some online tutorials I am willing to create my own custom theme for my myself. This is going to be an online Contact Lense store! So far I have learned how to generate and use Custom Post Types, Custom Taxonamyies, Metaboxes , and Option pages.but there is still one confusing part left for me(hopefully not more! :-))   I need to get some user inputs through HTML Select Options like following image to finalize the users orders: ![enter image description here](http://i.stack.imgur.com/k0IXT.jpg) Now my questions are:   1- Do I have to create some thing lik Metaboxes to manipulate these data from users?   2- can I handle these kind of data through simple Form ans Post function in PHP? If so where should I store these data? Do I have to create a table on my own to handle these things?   I really appreciate your time regrading this post,


title: Advanced Custom Fields: single-books.php works, books.php does not

text:
I'm using CPT UI to create the post type (books). I am running in debug mode. This is all happening on default, Wordpress 3.8, twenty twelve theme. I created a field group called Books in ACF and added three fields: book_title, book_author, pub_year. I set the field group to show if post type is books. I then copied page.php, renamed it books.php, and replaced the default header with Template Name: Books. I created a new page called Book Entries and set the template style to Books. I added this page to the menu. I added the necessary php script in books.php to show the post data. I then used Add Books to enter four different sample book titles using the custom fields and saved them. I am able to view them individually on single-books.php, but when I go to Book Entries I see... no post data. I see everything else, like title, header, footer, sidebars, comments, but no post data. Below is the code for books.php:               <?php     /**      * Template Name: Books      *      *      *      * @package WordPress      * @subpackage Twenty_Twelve      * @since Twenty Twelve 1.0      */          get_header(); ?>

     <?php if ( have_posts() ) : ?>
<?php the_field('book_title'); ?>

<?php the_field('book_author'); ?>

<?php the_field('pub_year'); ?>
                 <?php while ( have_posts() ) : the_post(); ?>                          <?php get_template_part( 'content', 'page' ); ?>                          <?php comments_template( '', true ); ?>                 <?php endwhile; // end of the loop. ?>     <?php endif; wp_reset_postdata(); ?>

          <?php get_sidebar(); ?>     <?php get_footer(); ?>


title: how to remove header from registration page?

text: How can i remove the header,search and my home,activity,forum etc from registration page.os there any plugin to modify registration page.I am using buddypress plugin.I do not want to call color.css for my registration page.


title: wpdb update add current timestamp not working

text: So using the $wpdb->update to add some data to a custom table, trying to add the current timestamp but it's not saving the right stuff(0000-00-00 00:00:00 this is saved). overview code                 $wpdb->update('mytable',           array(               'value' => 'hello world',                'edit'  => date("Y-m-d h:i:s") //saves 0000-00-00 00:00:00           ),           array(               'option_name' => 'the row'           ),            array('%s, %s')       );


title: Attempting to filter posts using get_terms

text:
Using get_terms I've created three lists of term links. What currently happens if I click on a term is to see the archive for that term, what I'm attempting to achieve now is when I click a second term I want to see an archive for both terms not just the latest term. Basically creating some level of filtering posts. My first guess is that I have to set some variable to affect the query, any suggestions on how to go about this? Or is there a better way of achieving this?
Filter By Deployment:
     <?php     $deployments = get_terms( 'deployments', array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1) );         echo '
';         foreach ( $deployments as $deployment ) {             echo '
slug, 'deployments').'">'.$deployment->name.'
';         }         echo '
';     ?>
Filter By Category:
     <?php     $categories = get_terms( 'category', array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1) );         echo '
';         foreach ( $categories as $category ) {             echo '
slug, 'category').'">'.$category->name.'
';         }         echo '
';     ?>
Filter By Keyword:
     <?php     $tags = get_terms( 'post_tag', array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1) );         echo '
';         foreach ( $tags as $tag ) {             echo '
slug, 'post_tag').'">'.$tag->name.'
';         }         echo '
';     ?>


title: output button depending the taxonomy

text: I'm trying to display two different buttons depending on the taxonomy the post is related to. I have a custom post type called "project". I have a taxonomy called "villes" (cities). For example if i'm on the city "lausanne" i need the red button displayed and if i'm in any other city i need the green button. I've added a metabox in my post for my button link and it work well (the button is shown only if the metabox is filled. Now i want to make this condition I made my code to display my button like this.                  /* store post ID and metadata in variables */     $postid = get_the_ID();     $website_link = get_post_meta( $postid, '_inscr', true );          /* output the button on the condition of $website_link being meaningful */     if ( ! empty( $website_link ) ) {        echo do_shortcode('[reveal_modal text="Je m\'inscris" size="medium" button="true"] <iframe src='. get_post_meta($post->ID, '_inscr', true).' height="1200" width="960"></iframe>[/reveal_modal]');     }      do I have to declare another condition like : if > website link if filled and my taxonomy = "lausanne" .... ? Any help would be appreciated.


title: Protect wp-login, but get an internal server error

text: I am trying to protect my wp-login by               #Protect wp-login     <Files wp-login.php>     AuthUserFile ~/.htpasswd     AuthName "Private access"     AuthType Basic     require user myusername     </Files>      after the password protect I get a 500 internal server error and not the wp- admin How can I fix this? And how can I logout and try again to see if it works?? ps: source from the codex


title: WP Multisite development with Mamp Pro and wildcard subdomains, not really working for me

text: I´m trying to set up a local development environment for me to work on a Wordpress multisite that I´m building. I use Mamp Pro with default ports (Apache: 80, MySQL: 3306), and I also added a new host with the same domain name as the page will have when going live. So, now when I go to http://mylivedomain.com I get to my development page, and database entries seem to use the same url as it should when going live as well. Enabling multisite from here was no problem, but I´m struggling to get Wildcard subdomains to work. In the advanced tab under Host in Mamp Pro, I added: "ServerAlias *.mydomain.com", but that doesn't work for me. I´m able to add a new site from the Admin dashboard, but when trying to visit it I just get a 404. Can anyone steer me in the right direction? I´m the 'design guy' so all this techinical jizz is really over my head, but I try...:)


title: Variable scope producing undefined variable notices in included files

text:
I'm building a Wordpress Theme and on the front page the user is able to select how they would like to order their posts. I've then created two functions that take the users selection through the variable `$user_choice` and develop a query based off of that choice. However, I'm having trouble with scope and getting the following notices/errors: > Notice: Undefined variable: user_choice in /Users/Chappell/Websites/LFB/wp- > content/themes/lfb/front-page-loop.php on line 3 > > Notice: Undefined variable: user_choice in /Users/Chappell/Websites/LFB/wp- > content/themes/lfb/front-page-loop.php on line 5 > > Notice: Undefined variable: header_query in /Users/Chappell/Websites/LFB/wp- > content/themes/lfb/front-page-loop.php on line 7 > > Fatal error: Call to a member function have_posts() on a non-object in > /Users/Chappell/Websites/LFB/wp-content/themes/lfb/front-page-loop.php on > line 7 _front-page.php_                   <?php get_header(); ?>

                          <?php                               $user_choice = 'most-recent';                              echo $user_choice;                              if (isset($_GET['formSubmit'])) {                                  $user_choice = $_GET['options'];                              }                              switch ($user_choice) {                             case $user_choice === 'most-commented';                                 $title_text = 'most commented';                             break;                             case $user_choice === 'most-recent';                                 $title_text = 'most recent';                             break;                             case $user_choice === 'most-viewed';                                 $title_text = 'most viewed';                             break;                             case $user_choice === 'featured';                                 $title_text = 'featured';                             break;                             default:                                  echo 'No posts were found matching this query.';                         }                                 ?>

Now displaying <?php echo $title_text . " Liverpool articles"; ?>

                                 <form role="form" class="form-inline pull-right orderer">
                                         Order By:                                         <select class="form-control order-select" name="options">                                             <option value="most-recent" <?php if ($user_choice === 'most-recent') { echo 'selected'; }?>>Most Recent</option>                                             <option value="most-commented" <?php if ($user_choice === 'most-commented') { echo 'selected'; }?>>Most Commented</option>                                             <option value="most-viewed" <?php if ($user_choice === 'most-viewed') { echo 'selected'; }?>>Most Viewed</option>                                             <option value="featured" <?php if ($user_choice === 'featured') { echo 'selected'; }?>>Featured</option>                                         </select>

                                         <input type="submit" class="btn btn-default" id="orderer" value="Submit" name="formSubmit">
                                 </form>

                              <?php get_template_part('front-page-loop'); ?>
                          <?php get_sidebar(); ?>

              <?php get_footer(); ?>      **Front-page-loop.php**               <?php           /*  Takes the user choice from the home page select button and produces     *   a WP_Query relevant to that choice. Displays 1 posts per query.     *   @param string $user_choice     */          function main_post_arg_finder($user_choice) {              switch ($user_choice) {             case $user_choice === 'most-commented';                 $args = array(                     'orderby' => 'comment_count',                     'posts_per_page' => 1                     );             break;             case $user_choice === 'most-recent';                 $args = array(                     'orderby' => 'date',                     'posts_per_page' => 1,                     'cat' => 239                     );             break;             case $user_choice === 'most-viewed';                 $args = array(                     'meta_key' => 'lfb_post_views_count',                     'orderby' => 'meta_value_num',                     'posts_per_page' => 1                     );             break;             case $user_choice === 'featured';                 $args = array(                     'orderby' => 'date',                     'posts_per_page' => 1,                     'category_name' => 'featured'                     );             break;             default:                  echo 'No posts were found matching this query.';         }                 $header_query = new WP_Query($args);              return $header_query;     }          /*  Takes the user choice from the home page select button and produces     *   a WP_Query relevant to that choice. Displays an unlimited amount of posts per     *   query.     *   @param string $user_choice     */          function posts_arg_finder($user_choice) {         switch ($user_choice) {             case $user_choice === 'most-commented';                 $args = array(                     'orderby' => 'comment_count',                     );             break;             case $user_choice === 'most-recent';                 $args = array(                     'orderby' => 'date',                     'cat' => 239                     );             break;             case $user_choice === 'most-viewed';                 $args = array(                     'meta_key' => 'lfb_post_views_count',                     'orderby' => 'meta_value_num',                     );             break;             case $user_choice === 'featured';                 $args = array(                     'orderby' => 'date',                     'category_name' => 'featured'                     );             break;             default:                  echo 'No posts were found matching this query.';         }                 $query = new WP_Query($args);              return $query;          }           ?>
              <?php echo $user_choice;              main_post_arg_finder($user_choice);                  if ( $header_query->have_posts() ) : while ( $header_query->have_posts() ) : $header_query->the_post() ?>                          <?php $do_not_duplicate = $post->ID; ?>
                                  <a href="<?php the_permalink();?>">
<?php the_title();?>
                             <?php the_post_thumbnail('thumbnail', array('class' => 'img-responsive')); ?>                             <?php post_meta(); ?>                             <?php the_excerpt(); ?>

                      <?php endwhile;                  else :                      echo '
No main post found
';                  endif; ?>

                   <?php posts_arg_finder();                  $i = 0;                    if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();                          if ( $post->ID == $do_not_duplicate ) continue;                          if ($i != 0 && $i % 1 == 0) { // add new row after 1 post                         echo '

';                     }                          $i++; ?>
                              <a href="<?php the_permalink();?>">
<?php the_title();?>
                         <?php post_meta(); ?>                         <?php the_excerpt(); ?>

                   <?php endwhile;                  else :                      echo '
No posts found
';                  endif; ?>


title: Updating post meta for custom post types

text: I'm writing a plugin for work (still) and having one more issue. I've added my meta boxes as needed. However, the problem I'm having occurs when _saving_ the post. My snippets for saving pretty much come from this post. I've also recieved a similar answer here, but it's just not working for some reason. :/                 protected function __update_post_meta( $post_id, $field_name, $value = '' )       {        if ( empty( $value ) OR ! $value )        {         delete_post_meta( $post_id, $field_name );        }        elseif ( ! get_post_meta( $post_id, $field_name ) )        {         add_post_meta( $post_id, $field_name, $value );        }        else        {         update_post_meta( $post_id, $field_name, $value );        }       }      The above is called using the following. However, I'm not sure my problem lies with the actual saving now that I think of it. I'm thinking it might be the `nonce` which may be throwing it off.                 public function _wp_save_post( $post_id, $post )       {        if ( empty($_POST)          OR !isset($_POST['argus_edit_visitor'])          OR !wp_verify_nonce( $_POST['argus_edit_visitor'], 'argus_edit_visitor' ) )        {         return $post->ID;        }             if ( ! current_user_can( 'edit_post', $post->ID ) ) return $post->ID;             // v_f_name | v_l_name | v_workstation | v_id        // Argh!             $this->__update_post_meta( $post->ID, 'v_f_name', $_POST['v_f_name'] );        $this->__update_post_meta( $post->ID, 'v_l_name', $_POST['v_l_name'] );        $this->__update_post_meta( $post->ID, 'v_workstation', $_POST['v_workstation'] );        $this->__update_post_meta( $post->ID, 'v_id', $_POST['v_id'] );       }      The nonce is used like the following: `<input type="hidden" name="argus_edit_visitor" id="argus_edit_visitor" value="{$nonce}" />` and created using `$nonce = wp_create_nonce( plugin_basename( __FILE__ ) );`. The input field is inside block of html being stored in variable $html. Stackexchange was parsing my html otherwise I'd paste it here. -Zack **EDIT:** Just tested it, and it **is** the nonce's fault.   **EDIT2:** Typo on my part, but still doesn't work.


title: wordpress domain setup with ec2 apache

text: I'm struggling to get my WP domains to display correctly. I'm using ec2 apache with a domain from namecheap. In namecheap, I've done the "pointing," putting my elastic IP for both the @ and www, and selected "A (Address) for both. Right now, www.mysite.com directs to the homepage of my WP. But as soon as I click links in my WP, the url goes back to xxx.ElasticIP.xx/sub-page instead of www.mysite.com/sub-page The General settings in my WP still have the xxx.elasticIP.xx for both the site URL and WP URL. Any help greatly appreciated!


title: Custom Links in Walker Class

text: I am creating a custom walker class. I need to identify the custom links that will be added to the menu from **Appearace > Menu > Custom Link** so that they will have a different format to the page/post links Any thoughts on how I can do this within walker class possibly using if statement? something like               if (link = custom-link) {       // Do something     }


title: WordPress 3.5: Switch back to Old Media Uploader?

text: Is there any way to switch back to the old media uploader in WordPress 3.5? The new one is very slow for me, as I have thousands and thousands of images across my site, and I have a few plugins that only work with the old uploader.


title: Author's Id from wp list authors function

text: I'm new in wordpress. I want to display all author list with its ID. I'm using `wp_list_authors` function but didn't get any author id from the author list. So, How can I get Author's ID in listing of all author?


title: 2 language CPT content

text: I'm working on a CPT Portfolio to present my job I wish to be able to have it in 2 languages but I would prefer not to use an additional plugin since that is only 2 fields that would be in 2 language my idea is : # on the back office of this CPT   * remove original excerpt   * remove original text editor   * create a custom meta box for language 1   * add to this meta box a custom text area 'intro language 1'   * add to this meta box a custom text editor 'intro language 1'   * create a custom meta box for language 2   * add to this meta box a custom text area 'intro language 2'   * add to this meta box a custom text editor 'intro language 2' # on the front end   * have a lang switcher with a cookie   * use the correct PO/MO file according to lang   * call the right text area / text editor content according to the lang is that the correct way to do it? Thank you in advance for all your help, I'm just scratching the admin section customisation


title: Creating 'posts page' loop based on the page itself

text: The setting `Settings -> Reading -> Posts Page` is set to my 'News' page, and the loop for the `home.php` template is populated with posts... great. However I want to also be able to create another loop (even with `WP_Query` if needed) of which contains the actual page of which I've specified my `Posts Page` to be. Whenever I try and and instantiate this loop it returns loads of posts instead of the page I've asked for, here's my code, compare the args with the request SQL:               <?php              $page = new WP_Query(array('post_type' => 'page', 'page_id' => 39));         print_r($page);              // REQUEST: SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'page' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC LIMIT 0, 10          ?>      You can see the request SQL query is wrong, I'm guessing because I've set the page as the `Posts Page` it's preventing me from using it within a loop. Is there a way around this? I want to use the title, content and custom fields within the `home.php` template. Thanks


title: Display latest 5 posts on homepage

text:
I'm currently using a custom made Twentytwelve child theme and would like to display the last 5 posts on the homepage using a shortcode. I have tried using the code below (added to `functions.php`) but to no avail - when I add the shortcode to the homepage, it doesn't display anything although as far as I can see, it should and I have a test post live.               function custom_prev_posts($limit = 5){     global $wpdb, $post;     $html = '';     $prev_posts = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.post_date < '%s' AND $wpdb->posts.post_type = 'post' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.post_date DESC LIMIT $limit", $post->post_date ) );           if($prev_posts){     $html .= '
';     foreach ( $prev_posts as $prev_post  ) {     $html .= '
ID ) . '">' .$prev_post->post_title . '
';     }     $html .= '
';     }     return $html;     }          add_shortcode('last5', 'custom_prev_posts');      I'm thinking the issue may be related to the Twentytwelve theme. Any ideas what I'm doing wrong or does anyone know of a working way to display the latest 5 posts inside a page?


title: a one-off rewrite rule

text: I have _one_ page that I need to change the URL for. Currently, the page resides at example.com/departments/human-resources/ (human-resources is a sub-page of /departments/ ) My client wants to maintain the legacy url for the hr department which is: http://example.com/hr/ How can I rewrite any request for `^/hr/?$` to `^/departments/human- resources/$` but keep the URL the same? That is, nobody will ever see /departments/human-resources/. My current .htaccess looks like this:               <IfModule mod_rewrite.c>     RewriteEngine On     RewriteBase /     RewriteRule ^index\.php$ - [L]     RewriteCond %{REQUEST_FILENAME} !-f     RewriteCond %{REQUEST_FILENAME} !-d     RewriteRule . /index.php [L]     </IfModule>      I've tried adding a rewrite rule that writes /hr/ to /dept/h-r/ before the index.php line, but this gives me a 404.


title: How to update wp_posts with just the returned comment count from wp_comments (SQL GROUP BY)

text: I am doing a special migration from someone's custom CMS to a WP installation. I successfully got the posts and comments migrated into their respective tables. Now I need to get the comment count into the wp_posts table for each matching id. I have something like this. I'm close, I think:               SELECT COUNT(comment_content) AS total_comments, comment_post_ID AS commentID     FROM wp_comments     GROUP BY comment_post_ID;     --mysql won't let me run the group by on just the returned count column, so I'm stuck with    two columns of data when I just want to insert one          UPDATE wp_posts SET comment_count = total_comments WHERE wp_posts.ID = commentID;     --So I tried to set my returned data to variables and assign them into the update statement..which doesn't work      Anyway, perhaps I need to iterate all the posts, find a matching ID and update it by moving the cursor? Or is there an easier way i'm missing somehow?