How to change a post or page being edited to a file on the server

I am trying to change the post I am editing to a files file_get_contents() at the time of edit_form_after_title being called. I have tried using               function edit( $post_id ) {                $post_id = get_the_ID();                           $file = file.txt                 if (file_exists($file)) {                     $saved_edited_content = file_get_contents($file);                     ?>                     <script>                         window.onload = function() {                                  var content = document.getElementById("content");                             content.innerHTML = "<?php echo $saved_edited_content; ?>";                             var doc = document.getElementById('content_ifr').contentWindow.document;                             var body = doc.getElementsByTagName("body");                             body[0].innerHTML = "<?php echo $saved_edited_content; ?>";                         }                     </script>                     <?php                 }                  }     add_action( 'edit_form_after_title', 'edit' );      but this does not work if the file is long. So I am also trying               function edit( $post_id ) {                 $this->convert();             }             function convert() {                      $post_id = get_the_ID();                 $content =  get_the_content($post_id);                                if ($_SERVER['REQUEST_URI'] == '/wp-admin/post.php?post='.$post_id.'&action=edit') {                     $file = file.txt;                     if (file_exists($file)) {                              $saved_unedited_content = file_get_contents($file);                             $my_post = array(                                 'ID'           => $post_id,                                 'post_content' => $saved_unedited_content                             );                                  wp_update_post( $my_post );                     }                 }                 else {                     $file = editedfile.txt;                     if (file_exists($file)) {                         $saved_edited_content = file_get_contents($file);                             $my_post = array(                                 'ID'           => $post_id,                                 'post_content' => $saved_edited_content                             );                                  wp_update_post( $my_post );                     }                 }             }     add_action( 'edit_form_after_title', 'edit') );     add_action( 'the_post',  'convert') );      this way does not update the post when the edit page is used with the unedited content. I would like to be able to edit the post without changing what is shown to the website users until the edit is finished and then build the edited page and update the post. I would use shortcode but I am using slow apis and the load time with shortcodes is 60+ seconds. How can I update the post with the unedited content from the file when I am using the editor from wordpress. How do I make the post update when I go to edit the post?


How to get the parameters on page and avoid 404?

I have a page like http://mydomain.com/mypage and I want to set some $_GET parameter like that: http://mydomain.com/mypage/firstparameter/firstvalue I need "firstparameter" value but I always end in the 404 page. I've spent some hours with get_query_var(), add_query_vars_filter() and add_rewrite_rule() but no way... Thank you


How to make this menu drop down or like accordion

I am using sitesmile auction theme. Here is my working site. In home page there is a sidebar saying "Browse by Categories". I want to make this menu as drop down or like accordion. Whenever the user hover on the parent category, the sub category will appear. As it is the category of Custom Post Type, I can't figure that out. Here is an example, how I want mine:   ![Menu image](http://i.stack.imgur.com/TWli9.jpg)


Different plugins activated online and offline

I develop / add to / etc. my site offline, then transfer the updated database (in toto) to the live site. Some of the plugins I need / use offline, I don't need online, and vice versa. Is there a way to have one set of plugins active if the database is 'online' and a different set for 'offline'? Or do I just need to accept that whenever I upload a new version of the database I need to activate / deactivate as appropriate?


My WordPress menu based on Twitter bootstrap creates menu-item and not page-item

I've got a dynamic menu being generated, but instead of generating a **page- item** it generates a **menu-item**. What I would like it to do is generate page-items and all the rest of it so that I can show or highlight the current page a user is visiting. my code is :               // header.php          <?php // Loading WordPress Custom Menu         wp_nav_menu( array(             'container_class' => 'collapse navbar-collapse navbar-ex1-collapse',             'menu_class'      => 'nav navbar-nav',             'menu_id'         => 'main-menu',             'walker'          => new Cwd_wp_bootstrapwp_Walker_Nav_Menu()     ) ); ?>      And then in the functions.php I have               add_action( 'after_setup_theme', 'cwd_wp_bootstrapwp_theme_setup' );     if ( ! function_exists( 'cwd_wp_bootstrapwp_theme_setup' ) ):     function cwd_wp_bootstrapwp_theme_setup() {         // Adds the main menu         register_nav_menus( array(             'main-menu' => __( 'Main Menu', 'cwd_wp_bootstrapwp' ),         ) );     }     endif;


Incorporating Biology Database with Thousands of Records

I'm a WordPress newbie working on a Mac with MAMP. I have a series of database-driven websites that I'd like to incorporate into WordPress. My biggest website focuses on biology, especially animals. The main database table has over 50,000 records for vertebrates alone. I have it set up so that pages that don't have matching content in the database still display some kind of text through PHP includes (e.g. "Canis lupus (common name wolf) is a species in the family Canidae.") If I convert to WordPress, I obviously won't have time to create 50,000 blog pages, one at a time. Is there a way to import my database tables, or incorporate them into WordPress database tables, so that all 50,000 pages instantly display? And will I then be able to use a combination of PHP includes and database tables to insert text where no articles exist? If the answer's yes, I imagine the explanation is long and complex, but you don't need to go into the gory details. For now, I'd just like to know if it can be done, and it would help if you could offer a brief explanation or offer some key words I can use to Google for more information.


No option to add a 'featured image' in my wordpress installation

Hay, I've installed WordPress 3 on my server, and duplicated the stock theme and made some amends to it. However, when i add a post, i don't see an option to add a 'featured image'. Has this featured been removed? How do i reactivate it? Thanks


Meta box on options page save form problem

I have follow code from this link, https://gist.github.com/757903 and I have manage to create several metaboxes on my custom options page under Settings section. Stuff that doesn't work for me are :   1. I can't make it work, so save form work, I think that this hook doesn't exists "add_action('admin_post_save_howto_metaboxes_general', array(&$this, 'on_save_changes'));"   2. When I move boxes around, next time when I come back to that page, order of meta boxes is not saved, same thing for columns layout. Can someone help me with this please. Thank you in advance.


How can I customize "Pages" admin (edit.php) and "Edit Page" admin (post.php) for bulk edit of custom content type?

I think its probably easier than I think to do this, but currently its beyond me. If there are any plugins out there I'd prefer to start there rather than develop from scratch, but I'll do what I have to do. I have already created a custom content type called "biblio" that I will use to hold and display Bibliography info. Each entry will contain: **Title** : Will re-use page title field   **Abstract** : Will re-use content field   **Tags** : Will re-use Tags field   **Authors** : Custom field (with ability to add multiple)   **Date** : Custom field   **Publication** : Custom field   **Doc ID** : Custom field   **Link to external article** : Custom field   **Keywords** : Custom field (with ability to add multiple) **What I need**   1. A way to customize the edit post page for my custom content type to show only specified default and custom fields (may not be needed if I can get #2 below)    2. A way to be able to bulk edit these in a user friendly way (not using my PHPMyAdmin). I have tried a number of plugins. One really useful one is Custom Content Type Manager (thanks fireproofsocks, whoever you are). But I still need to be able to do the 2 things I mentioned above. By way of example there is a great set of plugins next gen gallery plus custom fields for next gen gallery that works how I would like the admin side of my custom content type. Any info leading to a way to do #1 #2 above would be greatly appreciated.


Get a button for <hr> in the Editor

Somehow the WordPress editor doesn't have a button to insert a horizontal line (`<hr />` in html). Is there a plugin that adds this button? Or an easy way to add such a button myself?


Row actions is removed

I want to show only edit, trash, view and clone as row actions. I add this code:               /** delete row actions quick edit and new draft**/           function remove_quick_edit( $actions ) {          unset($actions['inline hide-if-no-js']);          unset($actions['edit_as_new_draft']);          return $actions; } add_filter('page_row_actions','remove_quick_edit',99,1);      add_filter('post_row_actions','remove_quick_edit',99,1);                /** change name row action edit**/ function      rename_edit_action($actions) {          if (isset($actions['edit']))              $actions['edit'] = preg_replace('@>(.*)<@', '><b>bewerk</b><', $actions['edit']);          return $actions; }            if ('edit.php' === $GLOBALS['pagenow']) {          add_filter('post_row_actions', 'rename_edit_action');          add_filter('page_row_actions', 'rename_edit_action'); }           /** change name row action trash**/ function      rename_row_action($actions) {          if (isset($actions['trash']))              $actions['trash'] = preg_replace('@>(.*)<@', '>verwijder<', $actions['trash']);          return $actions; }            if ('edit.php' === $GLOBALS['pagenow']) {          add_filter('post_row_actions', 'rename_row_action');          add_filter('page_row_actions', 'rename_row_action'); }           /** change name row action view**/ function      rename_bekijken_action($actions) {          if (isset($actions['view']))              $actions['view'] = preg_replace('@>(.*)<@', '>bekijk<', $actions['view']);          return $actions; }            if ('edit.php' === $GLOBALS['pagenow']) {          add_filter('post_row_actions', 'rename_bekijken_action');          add_filter('page_row_actions', 'rename_bekijken_action'); }           /** change name row action clone**/ function      rename_kopieer_action($actions) {          if (isset($actions['clone']))              $actions['clone'] = preg_replace('@>(.*)<@', '>dupliceer<', $actions['clone']);          return $actions; }           if ('edit.php' === $GLOBALS['pagenow']) {          add_filter('post_row_actions', 'rename_kopieer_action');          add_filter('page_row_actions', 'rename_kopieer_action'); }      First it works, but now it doesn't show the row action 'clone' how can I add clone again as a row action Solved! the plugin duplicate-post must be activated.


Using WordPress publicize with main account and editor user accounts

I have a y.wordpress.com blog and I contribute to another x.wordpress.com under the role editor adding post contributions.The owner's account is set to publicize to Twitter any updates he/she makes. I do not have the credentials of the owner for x.wordpress.com. How can I publish a post so that it publicizes to their Twitter account and not mine ?


Widget Update Code Not Working

From what I can tell the widget API is pretty straight forward and simple, yet for some reason my update code isn't taking effect properly. When I press [save] from the backend all fields are blanked, and nothing is actually saved. When I drag my widget onto the sidebar region, an entry is created in the database for the widget.               1846, 0, 'widget_email-signup', 'a:2:{i:2;a:0:{}s:12:"_multiwidget";i:1;}', 'yes'      When I input values and save, none are saved. I've intercepted both `$new_instance` and `$old_instance` during the call to my update method and wrote their outputs to a file, but found nothing in them. Full Code: http://pastebin.com/gtrfuciZ **Update Method**               function update( $new_instance, $old_instance ) {       $instance = $old_instance;            $instance['title'] = $new_instance['title'];       $instance['script'] = $new_instance['script'];            file_put_contents( '/wp_results.txt', print_r( $old_instance, true ) );       file_put_contents( '/wp_results.txt', print_r( $new_instance, true ), FILE_APPEND );            return $instance;      }      **wp_results.txt** (data found within update method)               Array     (         [title] =>          [script] =>      )     Array     ( )


How can I add/append content to the_content on the home page via a plugin?

As a proof of concept, I'd like to create a simple plugin that loads some content, say "hello world" just after the_content on the home page only. How can I do this from a plugin?


Is Dreamweaver CS5 a serious choice for theme/plugin development?

I've heard that Dreamweaver has been improved significantly in latest versions. Does anyone have experience in developing a theme or plugin using Dreamweaver? What are the pros/cons? Thanks in advance


looking for navigation plugin (accordion)

does anyone know if there's a jQuery-navigation plugin with accordion animation which can be auto-applied to the wordpress default navigation? it should also support marking the current item (+ also its parent) - any ideas? thanks


What is best practice for writing/using custom PHP classes in a theme?

I want to use a custom PHP class in my theme, however I am not sure where to add it. Is there best practice used by the community for including PHP classes with a theme or is that an individual developer's decision? The first class I want to add is a custom menu Walker, however there will be more, and they will be tied to my theme. I am split between creating them in separate PHP files versus adding them to functions.php - or maybe there is any other ways please? Many thanks in advance for your input. Katrina


Exclude Sticky posts from Main Query break Pagination

I have a small problem with this function ! I would like to exclude all sticky post from my query but when I do it, it breaks my pagination. In the following code, when I remove the " **'post__not_in' => $sticky** " my pagination works like a charm... Any advice would be much appreciated ! Cheers.               /* Exculde STICKY from the main QUERY */     function exclude_cat(){         if (is_home()) {             $paged = (get_query_var('page')) ? get_query_var('page') : 1;             $sticky = get_option( 'sticky_posts' );             $args = array(             'category__not_in' => array( 71 ),             'ignore_sticky_posts' => 1,             'post__not_in' => $sticky,             'paged' => $paged             );             query_posts($args);         }     }


conditionally load javascript & CSS for do_action() calls from plugin

I am developing a plugin and using `do_action()` instead of shortcodes to display plugin content on the site. The plugin will only be used by me, but I am making the plugin to separate components of the site from the theme itself. How would I go about conditionally displaying javascript and css on a page, IF a specific do_action is called in a theme, from the plugin? I have found a ton on shortcodes but I wanted to avoid using shortcodes, as I will be calling the actions directly in the theme. I tried something like this               add_action('wp_footer', 'print_my_script');     function print_my_script() {         if(did_action('my_custom_action')) {             wp_enqueue_scripts('listings');             wp_enqueue_scripts('isotope');         }     }      **edit: its wp_enqueue_script() not scripts and changing that solved my problem** but it did not work. I also looked at Scribu's article on the subject for shortcodes and use globals, but that still did not work. I suspect that I might be able to rearrange priorities and make this work, but I am not sure.


Detecting post type within init action

I have an front-end ajax login on my site. I want to set the redirect url to `'/services/clientarea';` for every page that is not part of the blog. For blog pages i want the login redirect to be `$_SERVER['REQUEST_URI'];` Here is the code that I'm using which isn't working for me:               function ajax_login_init(){          wp_register_script('ajax-login-script', get_template_directory_uri() . '/library/js/ajax-login-script.js', array('jquery') );      wp_enqueue_script('ajax-login-script');          global  $post;     $posttype = get_post_type($post);          if ($posttype == 'post') {         $loginredirect = $_SERVER['REQUEST_URI'];     } else {         $loginredirect = '/services/clientarea';     }          wp_localize_script( 'ajax-login-script', 'ajax_login_object', array(          'ajaxurl' => admin_url( 'admin-ajax.php' ),         'redirecturl' => $loginredirect,         'loadingmessage' => __('Signing in, please wait...')     ));          // Enable the user with no privileges to run ajax_login() in AJAX     add_action( 'wp_ajax_nopriv_ajaxlogin', 'ajax_login' );     }          // Execute the action only if the user isn't logged in         if (!is_user_logged_in()) {             add_action('init', 'ajax_login_init');     }      It seems that the post type isn't loaded in the init hook. Is there any way to identify it?


Custom Taxonomy Term in Custom Permalink Gives 404

I developed a small plugin to be able to add a custom taxonomy as a string to a post. I've included the variable in a custom permalink string. This string is used by Apache to determine if external login is required. This part is working fine -- the permalink is being changed correctly, redirecting to Apache, and then causing the login to be prompted (it's our institution's flavor of PubCookie). I've looked at the database, and the custom permalink structure is correctly recorded in the wp_options table. I've tested other custom permalink structures, without variables, just to see that I had Permalinks set up correctly (mod_rewrite, etc.). So, in general, custom permalinks are functioning without 404 errors. However, once I put this particular variable string (the taxonomy term), whatever its value, into the permalink, I am getting a 404. Here is an example of a link that goes to a 404 with the proper taxonomy term in the the string (the variable, "unrestricted," indicates that it is public so does not prompt for a login): http://news.med.virginia.edu/deansoffice/latest/unrestricted/deans-welcome/ I have done the usual: gone to the Twenty-Thirteen theme, disabled plugins (except for the one I'm testing), and still nothing is working. I am now at a loss for what to do. Debug shows nothing. Does ANYONE have a clue? Here is the code:               //REGISTER THE TAXONOMY     add_action('init','uvasom_restriction_init');     function uvasom_restriction_init() {         if (!taxonomy_exists('uvasomrestriction')) {             register_taxonomy( 'uvasomrestriction', 'post',                array(   'hierarchical' => TRUE, 'label' => __('UVA SOM Restriction'),                     'public' => TRUE, 'show_ui' => TRUE,                     'query_var' => 'uvasomrestriction',                     'rewrite' => true,                     'capabilities'=>array(                     'manage_terms' => 'manage_options',//or some other capability your clients don't have                     'edit_terms' => 'manage_options',                     'delete_terms' => 'manage_options',                     'assign_terms' =>'edit_posts')                 )                 );          }          //ADD DEFAULT TERMS IF THEY ARE NOT THERE     $parent_term = term_exists( 'uvasomrestriction', 'uvasomrestriction' ); // array is returned if taxonomy is given     $parent_term_id = $parent_term['term_id']; // get numeric term id     wp_insert_term(       'UVA Only', // the term       'uvasomrestriction', // the taxonomy       array(         'description'=> 'Require UVA Netbadge credentials to read.',         'slug' => 'privatenbauth-uva-only',         'parent'=> $parent_term_id       )     );     }          //INSERT THE PROPER TERM INTO THE CUSTOM PERMALINK     add_filter('post_link', 'uvasom_restriction_permalink', 10, 3);     add_filter('post_type_link', 'uvasom_restriction_permalink', 10, 3);          function uvasom_restriction_permalink($permalink, $post_id, $leavename) {         if (strpos($permalink, '%uvasomrestriction%') === FALSE) return $permalink;              // Get post         $post = get_post($post_id);         if (!$post) return $permalink;              // Get taxonomy terms         $terms = wp_get_object_terms($post->ID, 'uvasomrestriction');         if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug;         else $taxonomy_slug = 'unrestricted';            return str_replace('%uvasomrestriction%', $taxonomy_slug, $permalink);     }      Thank you for any clues you may have.


How to add nav menu items to a specific position within a menu

I'm adding login/logout links to a nav menu using the following code:               function rp_add_login_logout_links( $items, $args ) {              $link = wp_loginout( get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ), false );              if ( 'Shop Menu' == $args->menu ) {             $items .= '
' . $link . '
';         }              return $items;     }     add_filter( 'wp_nav_menu_items', 'rp_add_login_logout_links', 10, 2 );      Since `$items` is a string, I can really only easily prepend or append the links to the list. I need this link to appear before a certain menu item in the list, it would end up being the third item from the end. Is there another filter or method I could use to accomplish this? I tried using `strpos` to find the nav item I was looking for and manipulate the `$items` string but couldn't get it to match the menu item HTML.


How to add a "last" class to the last post in loop.php?

I need to add a "last" class to the last post that appears in loop.php. Can someone tell me how to accomplish this?


add if statement to the featured image

I have a featured image. I want to add an if statement to the size. For example, if the featured image height exceeds 500px I want to add something. Is that possible ?


Wordpress count child posts of each parent custom post type and use in json array for google maps jquery plugin

So i have been looking for a couple of days now and cant find a solution to this anywhere. It is a fairly bespoke request from a client... I am using a jQuery google maps plugin to add markers for each post (area) that the admin creates using a custom meta box with lat and long coordinates. Each of these markers has a tooltip associated with it. In the tool tip i have got some text, the title of each post used to create the marker itself and a permalink to the post (area). But i would like to display a count of all children posts (deals) of each of the posts (areas). I have this working on the (area) posts themselves but cannot get them to display in my map tooltips. This is the code i have so far i dont think i am far away from a solution but my php skills are still at a novice level so any help would be much appreciated.


How to retrieve "sticky" post outside the "loop"?

I need to display the "sticky" post in a section that is outside the "loop". Can someone tell me how to do this?


When to use _e and __ for the translation?

What is difference between `_e()` and `__()` functions for the translation? In what cases `e()` and `__ ()`should be used?


How to create my own sidebar in Twenty Eleven child theme?

When I go to configure widgets in Twenty Eleven theme, there are 5 "sidebars" available:   * Main sidebar   * Showcase sidebar   * 1st col of footer   * 2nd col of footer   * 3rd col of footer In a child theme, I'd like to support sidebar on posts which is quite easy using these instructions but at the same time, main sidebar on the homepage should be different from the sidebar on the single pages. Can I create a new "sidebar area" so that widgets can be dragged and dropped to it in the admin section? Or should I maybe use something like the 3rd column of a footer area (which I don't use in my blog) to support this? Would I them replace `get_sidebar()` with something different in the modified `single.php` file?


Image uploader with "Set Featured Image" link on front end

I am loading `upload-media.php` file using `thickbox` on front end where user can upload images to the post. **Question:** How to I trigger the `upload-media.php` so the link "set featured image" shows up on image manager, just like we see when we click on "set featured image" link on backend. ![Featured image](http://i.stack.imgur.com/0pAq6.jpg) **Here is the code for the thickbox:**               jQuery('.upload_media_button').live('click', function() {                 current_item = jQuery(this);                  container = "."+current_item.attr('rel');                  var request = url.media_upload+'?type=image&TB_iframe=true';                  //alert(request);                  tb_show('Image Manager', request);                  return false;             });                  window.send_to_editor = function(html) {                  var img_tag = jQuery('img',html);                  //var attachment_id = jQuery('img',html).attr('class').replace(/[^0-9]/g, '');                  current_item.siblings(container).prepend(img_tag).css("height: auto");                  tb_remove();             }      I know I can take the attachment ID and set the featured image after form submission but that's the **Plan B** ;)


conditional statement for profile pages

I'm using different headers for in my wordpress/buddypress setup and I need a conditional statement for member pages. So everything that comes after mysite.com/members/. How do I do that with something like is_page()?


Contact Form Security

Building my own contact form in Wordpress. Any there any security steps I need to consider other than the typical email etc validation and maybe a captcha. I am not sending any data to the database.


Engadget Like Featured Breaking Plugin

I am looking for a Engadget like **featured breaking** plugin. I have searched myself but did not found any relevant results. I would be very thankful for the help. ## EDIT: Here is a visual image of how it should look like. ![enter image description here](http://i.stack.imgur.com/sbmu6.png) Thanks in advance.


How can I create an upload page for (and only visible to) specific users?

I'm working on a WordPress site we have for some software my lab is developing. What I'd like to do is add a page that would allow collaborating groups to upload their data to us for testing, but that would be hidden from anyone else visiting the site (i.e. the collaborators would have to be logged in to see the page). Ideally they wouldn't see the dashboard when logged in, but that's not too much of an issue at the moment. Are there any plugins that would make this easy?


Have save_post write to database image meta

Programming rookie back again. I have been studying the `add_action('save_post','')` but I am having difficulty getting it to work for my needs. The concept is simple - update the database information for an attachment's meta info. Here's where I'm at. I have my `add_meta_box` working great with an input box that is pre-populated with the Camera information from image meta. If I make an edit in this Camera field and update the post, no matter what variation of `update_post_meta` I try, it's failing. For example:               $camera = $imgmeta['image_meta']['camera'];     $update = $_POST['exif_field_camera'];     update_post_meta($post_id, $camera, $update);      I am fearing a horrible rookie mistake here, since it's not working. The code I am using to retrieve the information and using it as part of my `add_meta_box` is:               $args = get_posts( array(     'post_type' => 'attachment',     'numberposts' => null,     'post_status' => null,     'post_parent' => $post->ID     ) );     foreach ($args as $attachment) {          $imgID = $attachment->ID;     $imgmeta = wp_get_attachment_metadata($imgID);     $camera = $imgmeta['image_meta']['camera'];     }      What would the code be to write the new Camera input box information?


Using new WP_Query in shortcode in a custom field causes the main post content to not display

I've got a custom post type of files I'm trying to list using a new WP_Query. It works fine when I add the shortcode within the main post content. However, when I add the shortcode to a custom field (which I have set to display on the page along with the main content as a secondary "column"), the main content disappears! If I comment out the "while...have_posts()" and "endwhile" lines, the main content displays; however, even after commenting out every other line, the main content disappears unless I also remove the "while". I am pretty certain it has to do with using WP_Query (somehow it hijacks the loop), even though it shouldn't. Is there something I'm missing? Here's the shortcode:                  function ia_news_display_test($atts){ // [ia_news cat='category' num='numbertodisplay']          extract(shortcode_atts(array(             'cat' => 'any',             'num' => '2',             ), $atts));          $dirloop = new wp_query( array(          'post_type' => 'ia_news',          'category_name' => $cat,         'posts_per_page' => $num,         'orderby' => 'menu_order',         'order' => 'ASC'     ));          if ($dirloop->have_posts()){         $content = "
\n";         while ( $dirloop->have_posts() ) : $dirloop->the_post();             $custom = get_post_custom($post->ID);             $file_id = $custom["upload_file"][0];             $file_begin = $custom["begin_date"][0];             $file_end = $custom["end_date"][0];             if ('' != $file_end){$file_end = " to ".$file_end;}             $file_url = wp_get_attachment_url($file_id);                      if ('' != $file_url) { //CHECK FOR EXISTENCE OF FILE URL                    $content .= "
".$cat." ".$file_begin.$file_end."
\n";                 }         endwhile;         $content .= "
\n";     } else { $content = "nothing"; }          return $content;      }


My post repeats itself on the second page

Hey the way i have my index coded is that it shows one full post and the rest of the post are excerpts, but when i click previous the 2nd page shows the same post from the first page, what can i do to change this. Here is my index.php file                                                                   <?php get_header() ?>
                <?php if (have_posts()) : ?>      <?php $count = 0; ?>           <?php       query_posts('cat=0'); while(have_posts()) : the_post();       ?>      <?php $count++; ?>           <?php if ($count <= 1) : ?>

<a href="<?php the_permalink() ?>" title="<?php printf( __('Permalink to %s', 'wpbx'), the_title_attribute('echo=0') ) ?>" rel="bookmark"><?php the_title() ?>

                         <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?>                         |                         Published in <?php the_category(','); ?>

      <span class='st_facebook_hcount' st_title='<?php the_title(); ?>' st_url='<?php          the_permalink(); ?>' displayText='share'><span class='st_twitter_hcount'     st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText='share'><span class='st_plusone_hcount' st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText='share'>

                     <?php the_content('
Read More     »
') ?>                     <?php wp_link_pages('before=
' . __( 'Pages:', 'wpbx' ) . '&after=
') ?>

       <?php the_tags( __( 'More On: ', 'wpbx' ), ", ", "\n" ) ?>
<span class='st_facebook_hcount' st_title='<?php      the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText='share'><span class='st_twitter_hcount' st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText='share'><span class='st_plusone_hcount' st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText='share'>

<?php comments_popup_link( __( 'Leave A Comment', 'wpbx' ), __( '1 Reaction', 'wpbx' ), __( '% Reactions', 'wpbx' ) ) ?>

           <?php else : ?>

                         <a href="<?php the_permalink(); ?>" title="    <?php printf(__( 'Read %s', 'wpbx' ), wp_specialchars(get_the_title(), 1)) ?>">                         <?php the_post_thumbnail(); ?>

<a href="<?php the_permalink() ?>" title="<?php printf( __('Permalink to %s', 'wpbx'), the_title_attribute('echo=0') ) ?>" rel="bookmark"><?php the_title() ?>

                          <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?>                     |                     Published in <?php the_category(', '); ?>
                  <?php the_excerpt(); ?>

<a href="http://twitter.com/home?status=<?php the_title(); ?> http://celebloid.com/?p=<?php the_ID(); ?>" title="Share This Article On Twitter!" target="_blank"> <a href="http://www.facebook.com/sharer.php?u=<?php the_permalink() ?>" title="Share this on Facebook" target="_blank">

<?php the_tags( __( 'More On: ', 'wpbx' ), ", ", "\n" ) ?>

<a href="<?php the_permalink() ?>" title="<?php printf(__('Continue reading %s'), wp_specialchars(get_the_title(), 1)) ?>"><?php _e( '', 'wpbx' ) ?>

                <?php endif; ?>
          <?php endwhile; ?>            <?php else : ?>      <?php endif; ?>

<?php next_posts_link(__( 'Previous Articles', 'wpbx' )) ?>

<?php previous_posts_link(__( 'Next Articles', 'wpbx' )) ?>

           <?php get_sidebar() ?>
      <?php get_footer() ?>      The reason i query my post is because i made a custom featured content slide that only gets post from a certain category. Without the post being query it only pulls post from the category on the content slide.


How can I force the Wordpress visual editor to preserve the line breaks after paragraphs?

If I write and put a line break, it make the paragraph tags appropriately, but on this one page the line breaks aren't there: http://jacksongariety.com/gundoglabs/jobs


Display custom widget value in header.php

I am using the code below for a custom widget. I have added some fields in the widget like: `Title`, `Name` and a checkbox. Now everything is fine but I want to show those values in header.php. Any idea or suggestions?               add_action( 'widgets_init', 'my_widget' );               function my_widget() {         register_widget( 'MY_Widget' );     }          class MY_Widget extends WP_Widget {              function MY_Widget() {             $widget_ops = array( 'classname' => 'example', 'description' => __('A widget that displays the authors name ', 'example') );                  $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'example-widget' );                  $this->WP_Widget( 'example-widget', __('Example Widget', 'example'), $widget_ops, $control_ops );         }              function widget( $args, $instance ) {             extract( $args );                  //Our variables from the widget settings.             $title = apply_filters('widget_title', $instance['title'] );             $name = $instance['name'];             $show_info = isset( $instance['show_info'] ) ? $instance['show_info'] : false;                  echo $before_widget;                  // Display the widget title              if ( $title )                 echo $before_title . $title . $after_title;                  //Display the name              if ( $name )                 printf( '
' . __('Hey their Sailor! My name is %1$s.', 'example') . '
', $name );                       if ( $show_info )                 printf( $name );                       echo $after_widget;         }              //Update the widget               function update( $new_instance, $old_instance ) {             $instance = $old_instance;                  //Strip tags from title and name to remove HTML              $instance['title'] = strip_tags( $new_instance['title'] );             $instance['name'] = strip_tags( $new_instance['name'] );             $instance['show_info'] = $new_instance['show_info'];                  return $instance;         }                   function form( $instance ) {                  //Set up some default widget settings.             $defaults = array( 'title' => __('Example', 'example'), 'name' => __('Bilal Shaheen', 'example'), 'show_info' => true );             $instance = wp_parse_args( (array) $instance, $defaults ); ?>                  //Widget Title: Text Input.
                 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'example'); ?>                 <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
                  //Text Input.
                 <label for="<?php echo $this->get_field_id( 'name' ); ?>"><?php _e('Your Name:', 'example'); ?>                 <input id="<?php echo $this->get_field_id( 'name' ); ?>" name="<?php echo $this->get_field_name( 'name' ); ?>" value="<?php echo $instance['name']; ?>" style="width:100%;" />
                       //Checkbox.
                 <input class="checkbox" type="checkbox" <?php checked( $instance['show_info'], true ); ?> id="<?php echo $this->get_field_id( 'show_info' ); ?>" name="<?php echo $this->get_field_name( 'show_info' ); ?>" />                  <label for="<?php echo $this->get_field_id( 'show_info' ); ?>"><?php _e('Display info publicly?', 'example'); ?>
              <?php         }     }     ?>


Non-Recursive get_term_children()

I have a custom taxonomy called `product_category`. There are child terms 3 levels down. They look like this:               Term1         Term2             Term3      When I am on the taxonomy page for Term1, I wish to use `get_term_children()` to retrieve Term2, without retrieving Term3. If that makes sense... Can this be achieved with get_term_children() or is there another function I can use?


Category Archive

What's is the best way to make an archive page have editable text, as opposed to hardcoding text into the template file? Here is what I am trying as per suggestion below.               <?php     if(is_category( '1' ))       echo category_description( );           ?>      Am trying this but for some reason I can not get it to work. This is on an ARCHIVE page and Codex suggests using is category for archive pages.


Custom Post Types. Are there any disadvantages/advantages in using a plugin to develop them?

There are a few plugins which can assist you in building your CPT's, and these can usually handle your taxonomies and sometimes postmeta also. Some even take it further than that. I know that as with any plugin it's possible that development may cease; but aside from that are there any reasons why it's better to code your own CPT's taxonomies etc. **Here are some of the plugins I'm referring to**   * Custom Post Type UI   * Types   * WCK    * Custom Post Type Maker **Here's my Advantage/Disadvantage list** _Advantages_   * Quicker and Easier    * Developers have hopefully considered security so no need to worry about nonces or protecting the database etc _Disadvantages_   * Might be a performance issue for some applications   * Depending on development to continue.   * Possibly Less Flexible Does anyone want to add to or take away from this list?


Get the selected custom taxonomy value for a specific post in the WordPress admin panel

I'd like to get the term value of a custom taxonomy attached to a post inside the wp-admin area, specially on the post edit page. Only one term value can be (is) selected for that specific taxonomy. I've tried the following functions without success: http://codex.wordpress.org/Function_Reference/wp_get_post_terms http://codex.wordpress.org/Function_Reference/get_the_terms I'm getting only errors or empty arrays. I know this must be tackled as outside the loop, but I'm stucked right now.


Hide featured post on second page

I have a index.php with a featured post and a number of other posts and the standard wp_pagenavi at the bottom. I'm using the 2 loops from the wordpress codex like this:               <?php $my_query = new WP_Query('category_name=featured&posts_per_page=1');     while ($my_query->have_posts()) : $my_query->the_post();     $do_not_duplicate = $post->ID;?>       <!-- Do stuff... -->     <?php endwhile; ?>       <!-- Do other stuff... -->     <?php if (have_posts()) : while (have_posts()) : the_post();      if( $post->ID == $do_not_duplicate ) continue; ?>      <!-- Do stuff... -->     <?php endwhile; endif; ?>      If I've read the theme hierarchy correctly, an archive.php page should be used when clicking "Previous" in the pagination section... (correct?) However, this is not the case, clicking previous is showing me a page with the same layout as my index.php and thus with the same featured post. (pagination on the other posts does work though) I've been messing around with `is_paged` but haven't been able to get it working... Thanks for the help!


How to show custom post type in hierarchy

I want to show my custom post type in list pattern like ## S.No Title   * 6 samplePost1               - replypost      - replypost        * 5 samplepost2               - replypost        * 4 samplepost3 Here i am setting post_per_page count from admin so If admin set post count to 4 then on list page it should show 4 post including reply post. I am posting my code below please let me know how can i resolve this issue.                  <?php                  $args  = array(                     'post_type' => 'customposttype',                     'posts_per_page' => $posts_per_page,                     'paged' => $paged,                     'orderby' => 'post_date',                     'order' => 'DESC',                     'post_status' => 'publish',                     //'post_parent'=>0,                     'tax_query' => array(                         array(                             'taxonomy' => 'custompostcategory',                             'field' => 'slug',                             'terms' =>  $cat                         )                      )                     );              $my_query = new WP_Query($args);              $max_num_pages =  $my_query->max_num_pages;         $post_count =  $my_query->found_posts;         $i = $post_count - (($paged - 1 ) * $posts_per_page) ;         ?>
           <?php if ( $my_query->have_posts() ) : ?>

Sno.

Title

                  <?php while ( $my_query->have_posts() ) : $my_query->the_post();?>
                <?php //if($my_query->post->post_parent < 1) :?>
<?php echo $i; ?>

 <?php echo mb_substr(get_the_title(),0,30)?>
                  <?php  $i--;// else: ?>                 <?php //if($my_query->post->post_parent > 1) :?>                 <?php                      $r_args  = array(                         'post_type' => 'customposttype',                         'orderby' => 'post_date',                         'order' => 'DESC',                         'post_status' => 'publish',                         'post_parent' => $my_query->post->ID                            );                          $Rquery = new WP_Query($r_args);                  ?>                  <?php if ( $Rquery->have_posts() ) : ?>
                      <?php while ( $Rquery->have_posts() ) : $Rquery->the_post(); ?>

<?php echo mb_substr(get_the_title(),0,30)?>

                       <?php endwhile; ?>
                   <?php endif;//endif;?>
                 <?php   endwhile; // End While?>


Display only first level children of my custom taxonomy categories

I'd like to display only first level children of my custom taxonomy categories I'am using wp 3.8 I've something like for my taxonomy "listing_category": Category 1 SubCattegoy1 Subsub category1 I'd like to display only a link to "sub category1" when I'am on "Category 1" (not "subsub category1"). With the code below It displays all sub cat and subsub cat :               $taxonomy_name = 'listing_category';     $queried_object = get_queried_object();     $term_id = $queried_object->term_id;     $termchildren = get_term_children( $term_id, $taxonomy_name );       echo '
';        foreach ( $termchildren as $child ) {        $term = get_term_by( 'id', $child, $taxonomy_name );       echo '
' . $term->name . '
';      }       echo '
';      Any ideas to help me ? Thanks


Organization of time insensitive content

I'm planning to use WordPress to maintain and publish a role-playing system. Is there a best practice for managing content in WordPress that isn't time sensitive? Should I use pages and make short notification posts when those are updated? I know posts and pages are stored the same, it's handling the creation and presentation that's giving me trouble. I want updates to be obvious, but without republishing entire sections of content.


I dont want to show shortcode in <pre> tag

I have a theme and I want to show vistors how shortcode format is in `<pre>` tag. But when I add shortcode in `<pre>`, it shows what shortcode does. I just want to show shortcode format in plain text. How to do that?


Custom Post Type and Breadcrumbs Conflict

![An example of the extra space](http://i.stack.imgur.com/mRcFl.png) I have a custom post type. It seems the breadcrumbs have an extra space for a parent page (which does not exist) inserted. You can see this in the image I attached. What is happening with theis custom post type that is causing this extra, non- existent parent? Here is my custom page type:               add_action( 'init', 'register_cpt_result' );          function register_cpt_result() {              $labels = array(              'name' => _x( 'Case Results', 'result' ),             'singular_name' => _x( 'Result', 'result' ),             'add_new' => _x( 'Add New', 'result' ),             'add_new_item' => _x( 'Add New Result', 'result' ),             'edit_item' => _x( 'Edit Result', 'result' ),             'new_item' => _x( 'New Result', 'result' ),             'view_item' => _x( 'View Result', 'result' ),             'search_items' => _x( 'Search Case Results', 'result' ),             'not_found' => _x( 'No case results found', 'result' ),             'not_found_in_trash' => _x( 'No case results found in Trash', 'result' ),             'parent_item_colon' => _x( 'Parent Result:', 'result' ),             'menu_name' => _x( 'Case Results', 'result' ),         );              $args = array(              'labels' => $labels,             'hierarchical' => true,             'description' => 'My firm\'s case results',             'supports' => array( 'title', 'editor', 'excerpt' ),             'public' => true,             'show_ui' => true,             'show_in_menu' => true,                       'show_in_nav_menus' => true,             'publicly_queryable' => true,             'exclude_from_search' => true,             'has_archive' => true,             'query_var' => true,             'can_export' => true,             'rewrite' => true,             'capability_type' => 'post'         );              register_post_type( 'result', $args );     }      Here is my breadcrumbs function:               function crumbs() {         if ((is_page() && ! is_category()) || is_archive() || is_single() || is_single()) {             $crumbs = '';             $crumbs .= '
';             $crumbs .= 'Home';             $post_ancestors = get_post_ancestors($post);                  if ($post_ancestors) {                 $post_ancestors = array_reverse($post_ancestors);                 foreach ($post_ancestors as $crumb)                     $crumbs .= ''.get_the_title($crumb).'';             }             if (is_category() || is_single()) {                 $category = get_the_category();                 $crumbs .= 'cat_ID).'">'.$category[0]->cat_name.'';             }             if (!is_category())                 $crumbs .= ''.get_the_title().'';             $crumbs .= '
';             $close_crumb = '';             $open_crumb = '';             $separator = '→';             echo str_replace($close_crumb.$open_crumb, $close_crumb.$separator.$open_crumb, $crumbs);         }     }


Use different archive template for plugin

In my blog, I'm using a plugin for an encyclopedia. Unfortunately, the plugin uses the archive template from my blog. How can I use a different page / template for the encyclopedia? Here is the function of the plugin: (From the plugin-author I didn't get any support).               function Define_Rewrite_Rules(){     $post_type = Get_Post_Type_Object($this->post_type);     $archive_url_path = $post_type->rewrite['slug'];     $this->rewrite_rules[SPrintF('%s/filter:([^/]+)/?$', $archive_url_path)] = SPrintF('index.php?post_type=%s&filter=$matches[1]', $this->post_type);     $this->rewrite_rules[SPrintF('%s/filter:([^/]+)/page/([0-9]{1,})/?$', $archive_url_path)] = SPrintF('index.php?post_type=%s&filter=$matches[1]&paged=$matches[2]', $this->post_type);     }


wordpress simple loop, huge issues

Im having a problem where for some reason, a basic loop im trying to add to a sidebar keeps....keeps looping on interior pages (single and page .php ) but not on index.php. on index.php (home page) is fine. for example, i wanted the loop to populate an unordered lists line items, so i went about it like this:

title4sidebar

                       <?php                  query_posts( array ( 'category_name' => 'left_sidebar', 'posts_per_page' => 4, 'orderby=menu_order' ) );                 if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink();  ?>"><?php the_title(); ?>
                 <?php endwhile; endif; ?>

      A few things are happening. 1. the MOST problematic is that when this loop is in place, it breaks the navigation and all. i click on a page and the page loads up with one of the list line items on the header...so if i click "about us" on the main nav, a page loads with "line item title" instead..... also happens on any item clicked. 2 - is that on the (page/single.php pages), on the sidebar, it will post the first 4 posts with the category "left_sidebar" how it should be displayed, css in place and all but after the fourth line item, it will repeat the loops one more time. 3 - My sites content area has 2 columns, the sidebar on the left, and the main content area on the middle. On the part that's being wrongfully repeated (after the loops repeats), when i checked with FireBug, on the repeated line items, its also taking the H tag properties from i assume, an h-tag thats next to it on another column. So the first 4 line-items come out fine with the styles given to them via CSS, link colors, rollovers etc, and the next buggy 4 line items come out un-styled, permalink also isnt being applied to them like the first 4 etc. 3 - i removed all html from that php loop like the divs and ul / lis etc so no css is being applied, this way only text come up from the loop but the same thing happens, Since i removed the html portion of the loop, the first 4 li's come up with the standard default blue link text etc, and the following buggy 4 come up the same as before all big with htags attached.... Troubleshooting it all, - theres only one loop on the page which stems from the sidebar. - ive properly cleared all floats - when checking on W3C for errors etc, there are none. green lights through and through. - no errors on the php side of things. (ive checked every page and have errors enabled) on local server. im lost. Any ideas as to what can be happening? NOTE: thinking ahead, although there is one loop ONLY on the sidebar.php page, once imported technically theres 2 loops which i guess is the sidebar wp loop, and the page.php / single.php loops which get the content. is there anything different as of the latest wp maybe? Ive always done it like this and now i have problems...... any ideas? im lost. Thanks in advanced.


Is the wp_enqueue method efficient?

I had a quick question regarding how you are supposed to load in scripts with Wordpress. I am developing a theme and I know that the best way to do this is to use the "wp_register_script/wp_register_style" methods and then to enqueue them with "wp_enqueue_script/wp_enqueue_style". Lastly, you add them to the action "wp_enqueue_scripts". My question is because I'm developing a theme, I have several javascript files I'm enqueueing. Is this a good practice to separate javascript files and enqueue each of them singlely, or should I combine all my javascript files into one file and enqueue just that one file? Ideally, I'd like to be able to keep the files separated for ease-of-future updating, but does this slow Wordpress down when serving your site if it has to enqueue all of those files every time? Does everytime Wordpress serves a page/post, does it have to run through these files, or after it runs once does it cache the files in some way? I guess I'd like a little more insight on how this action works. Just trying to streamline things best I can. Thanks in advance for the input guys!


What URL do you pass to wp_remote_get to load the body of the current post's preview?

In the code below, I'm attempting to get a reference to the body content of the current post's fully rendered preview...               $response = wp_remote_retrieve_body(wp_remote_get('http://localhost/mysite/test-post/?preview=true&preview_id=28&preview_nonce=640bc54ca4'));     $post->post_content =  $response;      I'm just sending it to $post->post_content so that I can easily see it. Here's part of what it returns...
You do not have permission to preview drafts.
           I'm logged in as the administrator, so obviously I'm calling the preview wrong. How can I pass the URL in wp_remote_get to obtain the body section of the preview stream? When I use...               $post->post_content =  "
".$response['body']."
";      I get
<


How do I make wp_get_archives show me months where only pages were created?

I am creating a plugin and have a problem, this code gives my all months that post were added:                       <select name="sdate" id="sdate">         <?php wp_get_archives('format=option'); ?>             </select>       the problem is that i dont get dates that only pages were added. basicaly, i want dropdown thats gonna list every year+month (for example "September 2010") that something was added with value like "year-month" (for example "2010-05") Something that you can see working on Wordpress Export page, but copied code is not working for me.


get_term and get_term_by returning null or false eventhough the term exists

I am trying to use the action hook delete_term, delete_$taxonomy, among other hooks that delete a term but they are presenting the same issue. For example: `1234` is an existing term in the `favorite` custom taxonomy.               add_action( 'delete_favorite', function($term, $tt_id ) {              $get_term1 = get_term( $term, 'favorite' );         $get_term2 = get_term( 1234, 'favorite' );              $get_term_by1 = get_term_by( 'id', $term, 'favorite' );         $get_term_by2 = get_term_by( 'id', 1234, 'favorite' );         $get_term_by3 = get_term_by( 'name', 'term-name', 'favorite' );             $output = 'get_term1: ' . $get_term1 . ' get_term2: ' . $get_term2 .          ' get_term_by1: ' . $get_term_by1 . ' get_term_by2: ' . $get_term_by2 .          ' get_term_by3: ' . $get_term_by3;             ob_start();         var_dump($output);         $contents = ob_get_contents();         ob_end_clean();         error_log($contents);          }, 10, 2);      They all return nothing. So, how can I get the term inside this type of functions?? Please help me, this is driving me crazy. The functions get_term and get_term_by work everywhere else but inside these hooks. What is wrong?


WP_Query: Mixing category__in and tag__in together

I'm creating a "Related posts" section for my theme, based on a tutorial from wpbeginner.com. It offered two options in selecting posts: those in the same category(ies), using `category__in`, or those with the same tag(s), using `tag__in`. Is it possible to put of them into one big mixing pot, if you will, and select posts from all of them? I don't mean those that have the same category(ies) AND the same tag(s), but those that have either or.


Breadcrumbs using the Menu Structure.

I know there are several questions regarding how to use the menu hierarchy for breadcrumbs and I followed the instructions doing the following... I added this code to my theme's functions file:               /** Breadcrumbs from Menu Structure     -----------------------------------------------------------*/          function menu_breadcrumbs($theme_location = 'main', $separator = ' » ') {              $items = wp_get_nav_menu_items($theme_location);         _wp_menu_item_classes_by_context( $items ); // Set up the class variables, including current-classes         $crumbs = array();              foreach($items as $item) {             if ($item->current_item_ancestor || $item->current) {                 $crumbs[] = "url}\" title=\"{$item->title}\">{$item->title}";             }         }         echo implode($separator, $crumbs);     }      Then I added this to the page template:               <?php menu_breadcrumbs('primary-menu'); ?>      All this works, BUT... I really need the breadcrumbs to show all options for each main category, if that makes sense... For examples on my events page (http://www.sciotomile.com/events/), the code above creates a breadcrumb trail consisting of the main category and then the current page (like this: Events >> Events Calendar). For many sites this would be perfect, but my site doesn't have any subpages of subpages (in other words there are only 2 levels to my page structure). So I would like the breadcrumbs to show all options under the current category or tier and then underline or bold or whatever the current page... So instead of this: Events >> Events Calendar I would see this: Events >> **Events Calendar** >> Rhythm on the River >> FountainSide >> Jazz & Rib Fest >> Grand Illumination >> Plan an Event I would also like to see the option for "Home" provided... Anyway, if anyone can help me, I would really appreciate it :)


Alternative to wp_get_nav_menu_items?

I have tried out a technique to implement the `wp_get_nav_menu_items`, however, a child on the level 1 is being nested inappropriately on the menu. Kindly suggest an alternative of how this issue can be handled.               <?php         $args = array (             'order'                  => 'ASC',             'orderby'                => 'menu_order',             'post_type'              => 'nav_menu_item',             'post_status'            => 'publish',             'output'                 => ARRAY_A,             'output_key'             => 'menu_order',             'nopaging'               => true,             'update_post_term_cache' => false );              $menu_name = 'header_menu';         $locations = get_nav_menu_locations();         $menu = wp_get_nav_menu_object( $locations[ $menu_name ] );         $menuitems = wp_get_nav_menu_items( $menu->term_id, $args );?>
              <?php            foreach ( $menuitems as $item ) :             // get page id from using menu item object id             $id = get_post_meta( $item->ID, '_menu_item_object_id', true );             $page = get_page( $id );             $title = $page->post_title;             $link = get_page_link( $id );             // item does not have a parent so menu_item_parent equals 0 (false)?>                  <?php if ( $item->menu_item_parent == "0" ):                     // save this id for later comparison with sub-menu items                $parent_id = $item->ID;                     switch (strtolower($title)){                case 'home': $icon='home.png';                             break;                case 'about us': $icon='about_us.png';                                 break;                case 'services': $icon='services.png';                                 break;                case 'products': $icon='products.png';                                 break;                case 'energy solutions': $icon='energy_solns.png';                                         break;                case 'contact us': $icon='contact_us.png';                                   break;                default: $icon='';                }                ?>
             <a href="<?php echo $link; ?>" class="title">                 <img src="<?php echo bloginfo( 'template_url' ).'/images/icons/'.$icon; ?>" />                 <?php echo $title; ?>                          <?php endif;?>                  <?php if ( $parent_id == $item->menu_item_parent ):?>                      <?php if ( !$submenu ): $submenu = true; ?>                 <ul class="sub-menu" par_id="<?php echo $parent_id; ?>" count="<?php echo $count; ?>">                 <?php endif; ?>                          <?php                      // Retrieve second level menu through appropriate query                     $args = array (                                 'sort_order'   => 'ASC',                                 'sort_column'  => 'menu_order',                                 'child_of'     =>  $parent_id,                                 'parent'       => -1,                                    'post_type'    => 'page',                                 'post_status'  => 'publish'                             );                     $pages_under = get_pages($args); ?>
                         <a href="<?php echo $link; ?>" class="title"><?php echo $title; ?>                         <?php if ( count($pages_under)>0 ): ?>
                                      <?php foreach($pages_under as $page):                                          $id    = $page->ID;                                               $title = $page->post_title;                                          $link  = get_page_link($id); ?>
                                     <a href="< ?php echo $link; ?>" class="title">< ?php echo $title; ?>
                                 <?php endforeach; ?>
                         <?php endif; ?>
                     <?php if ( $menuitems[ $count + 1 ]->menu_item_parent != $parent_id && $submenu ): ?>
                 <?php $submenu = false; // endif; ?>                  <?php // if ( !$menuitems[ $count + 1 ]->menu_item_parent || !$menuitems[ $count + 1 ]->menu_item_parent==0 ): ?>
                                        <?php endif; ?>         <?php endif; ?>          <?php $count++; endforeach; ?>


Sortable Attachments Using 3.5 Media Uploader with Custom View

I'm using the tutorial by Mike Jolley to integrate the media uploader introduced in 3.5 into a custom post type edit page. The pertinent HTML on the page is this:

             <button class="button manage-images">Manage Images</button>             Click the button above to add or edit images.

      And the following JS is called on the page:                   jQuery(document).ready(function() {             if(jQuery('.post-type-collection').length > 0) {                 iaa_collection_manager.setup();             }         });              var iaa_collection_manager = {                      setup: function() {                          var file_frame;                          jQuery('.manage-images').click(function(e) {                              e.preventDefault();                              if (file_frame) {                             file_frame.open();                             return;                         }                              file_frame = wp.media.frames.file_frame = wp.media({                             title: 'Manage Images',                             button: {                                 text: 'Finish',                             },                             multiple: true,                             library: {                                 type : 'image',                                 uploadedTo : wp.media.view.settings.post.id                             }                         });                              file_frame.on('open', function(){                             console.log(file_frame);                         });                              file_frame.on('close', function(){                             location.reload();                         });                     });                 }           }      It's working quite well except the images aren't sortable. What would be the best way to manage this?


Timeout While Upgrading Network in Multi-site

I updated from 3.8 to 3.8.1 on a Multi-site setup. The initial upgrade was fine. When I clicked "Upgrade Network" ... It fails after some time and prompts me with: > Your server may not be able to connect to sites running on it. Error > message: Operation timed out after 120000 milliseconds with 0 bytes > received. or > Your server may not be able to connect to sites running on it. Error > message: connect() timed out! The upgrade to 3.8 went just fine. However, the upgrade from 3.8 to 3.8.1 doesn't let me "Upgrade Network". Any idea why that would happen? I tried deactivating all plugins just in-case they might be interfering with the network upgrade. The problem still exists.


// Nonce generated 0-12 hours ago

[x-post: SO] In wordpress there's a nonce generating-verifying mechanism, and I'm having trouble understanding why it's not working correctly... At a point it checks for whether the nonce was generated 0-12 hours ago.               // \wp-includes\pluggable.php:1260      function wp_verify_nonce($nonce, $action = -1) {         $user = wp_get_current_user();         $uid = (int) $user->ID;         if ( ! $uid )             $uid = apply_filters( 'nonce_user_logged_out', $uid, $action );              $i = wp_nonce_tick();          >>> // Nonce generated 0-12 hours ago         if ( substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) == $nonce )             return 1;         // Nonce generated 12-24 hours ago         if ( substr(wp_hash(($i - 1) . $action . $uid, 'nonce'), -12, 10) == $nonce )             return 2;         // Invalid nonce              return false;     }      How does that `if` work? I see that `wp_hash($i . $action . $uid, 'nonce')`=`8ae70558afac4a6951e3bc0f9ef1f59a`   and `$nonce`=`3551`. How is `$nonce` being compared to `-12,10`th part of `8ae70558afac4a6951e3bc0f9ef1f59a` supposed to be a check for "0-12 hours ago"?


How to exclude uncategorized from permalink structure /%category%/%postname%/

I'm using a custom permalink structure:               /%category%/%postname%/      So that my posts are listed like:               mysite.com/widgets/blue-widget      This works fine as long as "blue-widget" exists in one and only one category. However, when it appears in more than one category, like perhaps a child of uncategorized, the resulting URL becomes:               mysite.com/uncategorized/child-of-uncategorized/blue-widget      Even though the post is still in "widgets", it appears that there is something that makes uncategorized trump it. I believe its because it has the lower id. I need to know if its possible to exclude uncategorized and any children of uncategorized from appearing in the permalink structure. **UPDATED EXAMPLE:** So, if a post is in 3 categories for example: Widgets (parent_id=0), Uncategorized (parent_id=0), Child of Uncategorized (parent_id=1) I want the filter to use "Widgets" as the permalink slug and exclude "uncategorized" and all of its children. If the post is in 2 or more categories that are not uncategorized or a child of uncategorized, then just use the newest category as the permalink slug. If the post is assigned solely to uncategorized or one of its children, then do not display a category slug permalink


URLs to images get messed up after migration

I migrated a website from one host to another, and I am having a weird issue I never encountered before. The urls to images in html are fine, but the full path to the image has a broken url, the domain outputs twice. So here is the code generated for an image: `<img src="subdomain.domain.com/wp-content/uploads/2013/12/aleksandra.jpg" class="attachment-full wp-post-image" alt="aleksandra">` And here is the full path to the image in inspector: `http://subdomain.domain.com/subdomain.domain.com/wp- content/uploads/2013/12/aleksandra.jpg` If you need more info please do not hesitate to ask. Any help is much appreciated. Thanks


Wordpress URLs changed to relative on transferring server

I have developed a Wordpress site on staging server. It is working absolutely fine. When I moved the site to live server, media upload URLs changed to relative. Staging media URL as image source:                     Live media URL as image source:                     Did I need to take care of something while moving site? Or this issue may be server dependent. Another cause what I think can be from the SEO plugin installed, I'm not sure about this. **Note:** Both servers are at different domains. Thanks in advance.


Code Highlighting in BlockQuote

Many of my Wordpress Blog(http://subinsb.com/) posts have code snippets which is wrapped in **blockquote** elements. I need to highlight these code snippets. I tried using **GeSHi** , **Prettify Code Syntax** , **CodeColorer** but none of them works for **blockquote** elements. Is there any plugin that supports code highlighting for **blockquotes** ? OR How can I customize the current highlighting plugins to highlight blockquote elements too ?


Why are previous_post_link/next_post_link skipping some posts?

I have a single page template for one of my custom post types. Are the top of this page I have...               <?php previous_post_link('%link', 'Prev Project'); ?>          <?php next_post_link('%link', 'Next Project'); ?>      These links seem to skip some posts, but not all of them. Any idea?


Adding Custom Post Type Counts to the Dashboard

The dashboard conveniently tells me how many posts, pages, and comments I have. I would like it to tell me how many articles, videos and cartoons I have too (three custom post types registered with my theme). How would I go about including these into the _"Right Now"_ panel on the dashboard? ![alt text](http://i.stack.imgur.com/f8LWg.jpg)


Query to display Posts based on custom field (event date) not working

Searched all the posts here related to using custom event dates in queries and didn't find an answer to my specific problem, hoping someone can help. I have a custom post type for events, with custom fields to hold the event start date and end date. I have query that finds all matching posts and lists them in order of their start date as long as the start date is a future date (old events don't show), however I have two problems:   1. The events drop off on the date that they start even though I'm using <= in my query, not just < (they should display through that date and drop off on the following date); and    2. For multi-day events, they should remain in the list until the event has ended (the day after the date the event ends) but they still drop off the list on the date that they start; Here's my code:               global $post;          $eventdate = get_post_meta($post->ID,'event_date_start',true);     $eventdate2 = get_post_meta($post->ID,'event_date_end',true);     $eventlocation = get_post_meta($post->ID,'event_location',true);     $eventaddress = get_post_meta($post->ID,'event_location_address',true);     $eventdirections = get_post_meta($post->ID,'event_location_directions',true);     $eventcontact = get_post_meta($post->ID,'event_contact',true);     $eventcontactph = get_post_meta($post->ID,'event_contact_phone',true);     $eventcontactem = get_post_meta($post->ID,'event_contact_email',true);     $eventnumdays = get_post_meta($post->ID,'event_number_of_days',true);          $myposts =           get_posts('post_type=event&meta_key=event_date_start&orderby=meta_value_num&order=ASC&posts_per_page=-1');      foreach ( $myposts as $post ) : setup_postdata( $post );          $today = time();       if ( $eventnumdays == "Multiple Days" ) {             $exp_date = strtotime(get_post_meta($post->ID,'event_date_end',true));       } else {             $exp_date = strtotime(get_post_meta($post->ID,'event_date_start',true));       }     if ($today <= $exp_date) {      If the custom field for the event_number_of_days is set to Single Day, then there is no custom field stored for the end date, so my attempts to use event_date_end failed and bombed out the query, which is why I'm using the custom field for number of days instead. This does display the events correctly, just not through the date they need to be still on the list…. For example, I have an event going on this weekend - it should show on the list until after midnight on Sunday, since the event goes through Sunday, but since it starts today, it already dropped off the list. What am I doing wrong?


get_posts() and global variables

I was reading this post: When should you use WP_Query vs query_posts() vs get_posts()?, which seems to have become the go-to post for understanding the difference between the different functions for making custom loops. In the article, it says that > [get_posts] doesn't modify global variables and is safe to use anywhere Nonetheless, when I inserted into within another loop (I wanted to have a home page showing 3 columns, 2 done with custom fields, one with latest blog posts), I had to preserve the original $post, like so:               <?php global $post; // required     $tmp_post = $post; // save original post     args = array('numberposts' => 2); // Retrieve just 2 posts     $custom_posts = get_posts($args);     foreach($custom_posts as $post) : setup_postdata($post);     ?>         //My posts code here (removed to simplify)     <?php     endforeach;     $post = $tmp_post; //go back to original post     ?>      Before I saved the original post, my third column, with the custom field, was blank, but after resetting, as above, it works fine. Did I misunderstand what that line in the post meant? Did I do something I wasn't supposed to?


Multiple keyword search

I have a custom search where I want to enter a keyword or phrase into the search box, and then by pressing enter it adds it to a 'search storage' (already coded, see below). Asume I have 3 posts, one about cars, another and bikes and the final about planes. When this search is made I want all three to display in the results. Currently it would not find anything because there are no posts that contain car, bike and plane keywords individually. Is it possible to display posts that match each of these keywords? Would I need to do a `wp_query()` for each keyword maybe, inside a `foreach`? Or is there a cleaner way? ![screenshot](http://i.stack.imgur.com/ykCqf.png)


Custom query object with Simple-Fields custom date field

I'm currently using the simple-fields plugin to add an event start date field that is a `date` type field to a custom post type called an 'event'. On my homepage I'm looking to display the three closest events to today's date that haven't passed today's date. I currently have: `$recent_events = new WP_Query(array('post_type' => 'phelps_event', 'posts_per_page' => 3, 'order' => 'DESC'));` but that just gives me the first 3 events in the order they were created. I'm not sure how I would filter by the date field I created with the simple-fields plugin. Thanks for looking!


Query for posts in 2 taxonomies

I am currently using the following code to display a list with links to posts in a specific CPT and taxonomy:                 <?php     $custom_terms = get_terms('videoscategory');          foreach(array($custom_terms as $custom_term) {         wp_reset_query();         $args = array('post_type' => 'product',             'tax_query' => array(           'relation' => 'AND',         array(             'taxonomy' => 'videoscategory',             'field' => 'slug',             'terms' => $custom_term->slug         ),         array(             'taxonomy' => 'product_category',             'field' => 'slug',             'terms' => $other_custom_term->slug         ),          )               );               $loop = new WP_Query($args);          if($loop->have_posts()) {             echo '
'.$custom_term->name.'
';                  while($loop->have_posts()) : $loop->the_post();                 echo '
'.get_the_title().'
';             endwhile;          }     } ?>      It's working fine like it should, however I want to only display posts that is in both my taxonomies. What do I have to add to do so? Any help is appreciated, thanks.


Custom template for password protected page

I have a password-protected page, for whom I'd like to use a custom template to query posts from a specific category. How can I achieve that query_posts should work only after users submit the password of the page? I'm trying with this but doesn't work (page only displays header and footer)               <?php     /*     Template Name: xxxx     */     ?>                  <?php get_header(); ?>                 <?php if ( post_password_required() ) : ?>                 <?php query_posts('cat=9'); ?>                 <?php while ( have_posts() ) : the_post(); ?>                           <a href="<?php the_permalink(); ?>">
<?php the_title(); ?>

<?php the_content(); ?>

                         <?php edit_post_link( __( 'Edit', 'twentyeleven' ), '', '' ); ?>
                           <?php endwhile; ?>                 <?php endif; ?>                       <?php get_footer(); ?>


Do Cookies Need to be Sanatized Before Being Saved?

I recently wrote a plugin and now I'm backtracking a bit to sanitize any and all user input. I know that I should sanitize anything that comes from `$_GET` or `$_POST` as a user can insert malicious scripts into that. I also am sanitizing anything I'm calling via `get_options` that the user inputted just to be safe (not sure if the `options.php` API sanitizes but that's another question). But what about cookies? Do these need to be sanitized? If so how? Here is my function:               $get_cookie_check = wp_kses($_GET['view_full_site'],null); //sanitize user input     $site_url  =  site_url();      $domain  =  parse_url($site_url, PHP_URL_HOST);         if($get_cookie_check =='true'){             //set the cookie             setcookie("nifty_cookie", 1, time()+86400, "/", $domain);             $_COOKIE['nifty_cookie'] = 1;         }     }     //cookie variable     $full_site_cookie= $_COOKIE['nifty_cookie'];       I'm not thinking I need to sanitize anything here because I'm the one setting the cookie value (in this case to 1) via PHP. Is this a correct thought?


How to change wordpress news root url

I have a site and my customer has decided the url for what used to be news should now be renamed to tips-and-tricks, but we want to keep the old urls too because we don't want to lose old links. I've tried several .htaccess settings but that's really not my field of expertise, and I'm not even sure if this is the right way to achieve this with WordPress. So, for example:               site.com/news      should become               site/tips-and-tricks      but /news should point to /tips-and-tricks as well. Can I do this and what is the best way to do it with WordPress?


Iteratively add sub shortcodes to php array

I have this shortcode structure:               [component]        [type1]some content[/type1]        [type2]some more content[/type2]        ...        [typeN]some other content[/typeN]     [/component]      I would like to have the `$content` of the sub shortcodes stored in an array. What I am doing at the moment is, in their function, I pass `$content` to a global variable and then create an array out of them, but it is not very elegant. Also, I cannot have them as attributes of the main shortcode tag as this:               [component type1="some content" type2="some more content"]      as I need to have the attributes on new lines for readability - something I'm trying to get addressed here: wpautop() when shortcode attributes are on new lines break args array EDIT - I'm not looking for a list-like structure, but to have these values in a key-value array to populate a complex markup, and also use the array as a JSON object in my javascript functions.


How to make custom client Login page for a specific page

I want to make client login form on the home page and when client login, I want the client to land into to specific page. Unless logged in, if tried to land to that page must be redirected to home page. I have tried to use, Theme my login but did not get desired solution. I have tried to create my own widget area, and by password protecting the page. There are few problems that I faced.   1. How to take user input and sanitaize it, I tried to use, wordpress esc_attr, esc_js, esc_html method, [Is that sufficient]      1. I redirected the page to password protected page, but the password did not trigger the login.     2. once I login to password protected page, it does not seem to log out even if I clear the cache or cookies. So, basically, I want to have the solution. Thanks


Create a custom attachment thumbnail for quick page load

I've been trying to find a way to create a custom image attachment thumbnail. I want to display an image attachment thumb and link to the full size. (FYI The thumb is to get quick page loading speed instead of a full size that would slow down things.) so i'm trying to:   1. create an Image Attachment Thumbnail   2. keep it Small Size   3. be able to set a max width The other options that I have figured out:   * to use the attachment as background-image, but that gives me a big file size.   * to manually create a thumbnail for the attachment and upload it.   * use the thumbnail setting for featured-image and change that to meet my needs, but i'm using it for the featured-image. Is there a way to get wordpress to do this?


Fancybox type popup window that's not an iframe

I'm a bit stuck and need some help to get me going in the right direction. I'm trying to do something similar to the lightbox style popup on this website: http://cargocollective.com/montessori I want to build a popup window, with the scrollbars off to the side at the normal location (which, to my knowledge, rules out an iframe), and a URL that updates. I can figure out how the css will work, and that I can update the URL with html5 orjs, but here is where I am stuck: **What is the best way for me to bring the information from a project page into the popup window with Wordpress? Is it AJAX? Is there a way to do it with php? Or is an iframe the right method?** I tried using Fancybox, but the scrollbars end up in the page. Any help would be appreciated!!


What is the most efficient way to execute recursive complex queries?

There's a "Jobs" section on my website (custom post type), with various associated taxonomies (language spoken, type of contract, location, etc.) The website also has a very big user base (about 10 000 subscribers). These users have access to a form where they chose "jobs" criterias they are interested in, in order to receive a daily email with the list of "jobs" that correspond to their criterias. I'd like to have your opinion on the best way to implement that functionality. My first approach is this :   1. Loop through all the "subscriber" users   2. For each user, get the criterias they have chosen (language, type of contract, city, etc.)   3. with these criterias, make a WP_Query on all the "jobs" published that day   4. send the results by email This function would be triggered daily thanks to wp cron. My worry is that this is perhaps a very ressource intensive way (that's a loop executing 10 000 different wp_queries in a row!) The website is hosted on a dedicated webserver (quad core with about 8Gigs of ram) Is there a more efficient way ?


media_handle_upload weird thing

I am using a front end script to upload images , all works fine but recently i noticed the uploaded images are not saved in proper directory. My settings are to Organize my uploads into month- and year-based folders. my folders are 2011->03,04,05 (march , April , may). The problem is that if i upload a file today it saves in folder 03(March). If i use wp_handle_upload then the image is saved in proper folder 05 (May) , but then the image is not shown in media library and the different sizes are not made. Code i am using is               $image = media_handle_upload('async-upload', '');


How do you protect a premium theme from being copied?

I'm thinking of doing up a couple of premium themes, and selling copies of them. I've never done anything like this before, so I have a couple of questions. I appreciate that this is mainly a forum for asking technical questions, so if anyone wants to point me in the direction of somewhere that might be more appropriate for these questions, please let me know. My main question is about copies of a theme. If I sell a copy of a premium theme, and the end result is that a person gets a zip file of my theme, is there any technical way to limit them to only using it in one installation of WordPress? Or do I just rely on the goodness of their hearts? Also, a related question: What kind of license, if any, should I include with a premium theme? Thanks.


Using wp-cron in backpress - problems with wp_remote_post, fsockopen error

I'm working on a BackPress project where I need to schedule cron tasks. The cron_uri for BP is stored in options, rather than hardcoded as it is in WP core. I've tried setting the option to **mysite.com/wp-cron.php** (where **wp- cron.php** is essentially a copy of the same file from WordPress, modified to include only the relevant files to my purposes. The problem is, when this address is called from the wp_cron() function, it returns the following fsockopen error: > fsockopen() **[function.fsockopen]** : unable to connect to :80 > (php_network_getaddresses: getaddrinfo failed: Name or service not known) in > **/home/gad/public_html/backpress/class.wp-http.php** on line 646 I can open the cron uri directly using fsockopen and it doesn't return any error. As best as I can figure out, the problem is somewhere in the HTTP Transport API, maybe in the WP_http->request() function, where BackPress checks the `cron_uri` against the `application_uri` option, to see if the request is a local one or not (and possibly treat the different requests differently?). Strangely enough, if I just set the `cron_uri` to my home url, it works fine - I can intercept the request based on the GET request and include wp-cron.php before outputting anything. I'm mainly confused as to why wp_remote_post doesn't seem to work with this file, as it seems to work with most everything else I've tried to do with it.


Parked domain redirect

I'm a bit lost on how to handle this redirect requirement. So far I have:   * www.domain-B.com parked on www.domain-A.com    * So, requests for www.domain-B.com/page1 resolve to www.domain-A.com/page1 and so on   * So far so good However I would like one exception to this:   * If user requests the root of www.domain-B.com, I would like them to go to www.domain-A.com/pageX So everything works as normal with a parked domain _except_ when a user goes to the root url of the parked domain. I've tried the redirect plugin for WP but when redirecting www.domain-B.com to www.domain-A.com/pageX it actually redirects www.domain-A.com to that page as well. (because its properly parked I guess!) Thanks in advance for any advice.


Feedburner closing </head> error

This is the error I get from feedburner. > "The URL does not appear to reference a valid XML file. We encountered the > following problem: Error on line 573: The element type "link" must be > terminated by the matching end-tag ""." `http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.cmchatlive.com%2F` There is an opening `<head>`, tag but for some reason it is begin bypassed. Please advise.


Meta description ellipsis

I have a function that puts a meta description in my theme's `<head>`. It works well but I have a small issue. It just cuts off words in the description once it reaches the 160 character limit. I was hoping there was a 'cleaner' way of doing it. Here is the function:               function add_meta_description() {         global $post;              if ( is_single() ) {             $post_object = get_post(get_the_ID());             $content= $post_object->post_content;             $desc = substr( strip_tags( $content ), 0, 160 );                  echo '<meta name="description" content="' . esc_attr( $desc ) . '" />';         }     }      Is there anyway to not cut off words and put an ellipsis instead?


Should I ask a theme developer to use locate_template rather than require_once

I was creating a child theme today and needed to overwrite a php file which was included using this code in the themes functions.php file `require_once( get_template_directory() . '/function-includes/theme- functions.php' );` I tried using `require_once( get_stylesheet_directory(). '/function- includes/theme-functions.php' );` in my child themes functions file but it caused an error and didn't load the site at all. So I ended up using `locate_template( '/function-includes/theme- functions.php', true );` in the parent themes functions.php file Is `locate_template` a better method for theme developers to use to allow child theme development? Is there an alternative way for me to use only my child themes functions.php to overwrite that theme-functions.php file?


I am trying to upgrade my version of Wordpress but I get this error: _Destination directory for file streaming does not exist or is not writable._


How to call wp_list_comments() with callback outside the loop

the template function as a callback argument of `wp_list_comments` function, and the template function takes three args:`$comment, $args, $depth`, like the template function that defined in the theme `twentyeleven`'s functions.php,               function twentyeleven_comment( $comment, $args, $depth ) {     $GLOBALS['comment'] = $comment;     switch ( $comment->comment_type ) :         case 'pingback' :         case 'trackback' :     ?>

<?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '', '' ); ?>
     <?php          /** and more ... **/      I want to invoke this function in another place, and I have the `$comment` reference to a comment, but I don't know how to set the `$args` and `$depth` variables. I know the value of `$depth` or `$args` can be changed in the admin settings, so, I can't just set `$depth` to 5 or whatever a number. How can I get the `$args` and `$depth` ??? Thanks in advance.


What's $object->filter for?

I keep seeing this pattern, and wonder what it's for, how WP uses it internally:               if ( empty($post) ) {             if ( isset($GLOBALS['post']) )                 $_post = & $GLOBALS['post'];             else                 return $null;         } elseif ( is_object($post) && empty($post->filter) ) {             _get_post_ancestors($post);             $_post = sanitize_post($post, 'raw');             wp_cache_add($post->ID, $_post, 'posts');         } else {             if ( is_object($post) )                 $post_id = $post->ID;             else                 $post_id = $post;      The specific line in question is `is_object($post) && empty($post->filter)`. I've seen this `filter` property associated with other objects as well. Wondering what it does and how it can be used? EDIT I'm hoping to get more input on this! Unfortunately, a Google search with "filter" in it only turns up Filter hooks etc. This is a tough one to get independent info on. Buehler?


How to include post count in this "get_tags" snippet

Can anyone tell me how I can show a post count in this code snippet?               <?php $tags = get_tags();        if ($tags) {        foreach ($tags as $tag) {        echo '
term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'
 ';        }     };?>


In Loop, if a Gallery, Only Pull First Image

I'm trying to create a loop that only displays the post types: "photo" and "gallery". If it's a gallery I would like to display only one of the images, preferably the first. I'm a little confused because the codex says that the "standard" post format is really the absence of any declared format, but if I'm making a custom loop, and the user does not select a format, will standard posts get through? Thanks very much.


Remove # from a Variable

I am using WordPress WooCommerce plugin as a store management. When I echo with `<?php echo $order->get_order_number(); ?>` I get #6453 as a result but I need only numbers so how do I strip out # from the number?


Having trouble initializing wordpress within plugin

I'm new to Wordpress plugins. I've been asked to improve an existing plugin we have (make it more portable, etc). When installing the plugin and trying to use it the first thing I get is a fatal error about a missing file.               require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );      My install is at /wp, so this immediately fails. I'm having trouble figuring out the correct way to load or initialize wordpress within my plugin to give me access to the database connection, etc. I assumed this would already be working. From my brief searching on the topic people are recommending NOT including that file, but I haven't seen a good way to do it another way. I've tried these approaches as well. This fails since ABSPATH is not yet defined.               require_once( ABSPATH . '/wp-load.php' );      This fails since it's not yet defined.               get_home_path()      I'm using the latest version and a clean install. The plugin I'm working with is probably a year or two old at least. Any help would be great. EDIT: More specifically, the code wants to connect to the database to pull some info to display.               require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );     global $wpdb;     $sql = "some query";     $result = $wpdb->get_results($sql);      But the require fails since the file doesn't exist at that location. I just need to know how to include the file safely for any install. I was assuming since Wordpress is loading the plugin that I would have access at that point to ABSPATH and get_home_path(), but that doesn't seem to be the case. EDIT 2: OK, looks like the plugin is adding functionality to the tinymce editor. This code calls the problem file, webform-select.php, which needs to connect to the db, that's what the include is for.               (function() {         tinymce.create('tinymce.plugins.tinyplugin', {             init : function(ed, url){                 ed.addButton('tinyplugin', {                     title : 'title',                     cmd : 'command',                     image: url + "/images/icon.gif"                 });                 ed.addCommand('mceWebform', function() {                     ed.windowManager.open({                             file : url + '/webform-select.php',                             width : 420 + ed.getLang('example.delta_width', 0),                             height : 315 + ed.getLang('example.delta_height', 0),                             inline : 1                     });                 });             },         ...


create submenu page - error function not found or invalid function name

I have created a plugin with a top level page. I created a sub menu underneath that. When I run the plugin on my site everything works. But when I test it on a separate site I get an error and I'm not sure why. This is the the code that is in question and the error that is getting thrown. I can't for the life of me figure out what the error is from. function custom_plugin_add_menu_page(){                    add_menu_page( 'My Custom Plugin',                               'My Custom Plugin',                               'manage_options',                               'top_level_parent_page',                               'top_level_parent_page',                              plugins_url( '/my-custom-plugin/includes/images/menu-icon.png' )                              );                                          add_submenu_page(              'top_level_parent_page',              'Custom Submenu Page',              'Custom Submenu Page',             'manage_options',              'custom_plugin_submenu_page',              'custom_plugin_submenu_page_callback'          );                       }     add_action('admin_menu', 'custom_plugin_add_menu_page');      and the error: > Warning: call_user_func_array() expects parameter 1 to be a valid callback, > function 'custom_plugin_submenu_page_callback' not found or invalid function > name in D:\xampp\htdocs\localtestsite\wp-includes\plugin.php on line 429


Intercepting 'Add Media' button click

I'm trying to simplify a little the media uploader for one of my clients. To do so, I'm trying to generate a new media uploader frame using 'wp.media...' on client side js. But when I click the 'Add Media' button on the edit post page, both media uploaders (wp and mine) open. Is there a way to avoid the 'default' media uploader so only mine is shown?


How does Wordpress remember which editor is being used?

Hey so I am trying to determine how Wordpress remembers which editor is being used for a particular post (HTML or Visual Editor (tinyMCE)). When you write a post, and then come back, it goes to the last used editor. I am assuming its a cookie of some sort (because I couldn't find any info in the database), but does anyone know where the code for this is?