Filter and display a specific custom field value

I am developing a travel website for an agency. I'm trying to to make the user able to select an option like "Select your departure" and filter the loop with all the departures available for the chosen option. Ie: if I want to check all the departures from Chicago, so the loop will only show the Chicago departures!               <?php       $args = array(       'post_type'     => 'travel_packs',       'order'         => 'ASC',       );       $the_query = new WP_Query( $args );            if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();     ?>          //The loop:     <a href="<?php the_permalink(); ?>">       Destination: <?php the_field('destination'); ?>       Departing from:<?php the_field('departures'); ?>       Price:<?php the_field('price'); ?>     </a>          <?php endwhile; endif; ?>      I thought about the `$_GET` method, but I'm not sure how to assimilate it with the `the_field('departures');` Thank you!


How to create custom URL routes?

I have a very peculiar requirement, hopefully I can explain it without being too confusing. I created a page template where I list some properties I get from an external XML file, so far no problems, let's say the URL is like this: http://www.mysite.com/properties/ Each property has a link that should redirect the user to a "Single Property" page that displays more info about it, what I was wondering is if there's a way to make the link like this http://www.mysite.com/properties/123 ? Where "123" would be the id of the property, basically if I have the url like properties/some_id I want to be able to load a view file (like the single.php or page.php files) but specific to this url condition. Is this possible? Thanks in advance!


automatically create taxonomy with same name as post title

I have a custom post type called "Country Story". The title of which will be the name of the country. I want Wordpress to automatically create a new taxonomy called "country" of the same name, i.e. a Country Story called Thailand is created, so I want WP to create a Country taxonomy called Thailand as well. The Country taxonomy already setup. I have the code below so far. It does what I want except I don't know how to get the title during the action hook for publishing the post to pass on to the $cat variable. Can anyone help?               function add_country_category_automatically($post_ID) {     global $wpdb;     if(!has_term('','country',$post_ID)){         $cat = "get title of Country Story published to pass on to Country category";         wp_set_object_terms($post_ID, $cat, 'country');     }     }     add_action('publish_country-story', 'add_country_category_automatically');


custom gallery filter with image caption as link title?

I use a custom gallery function to alter the normal Wordpress markup. Usually it's fine but I can't quite figure out how to add the image caption as a TITLE attribute on the thumbnail link. (The lightbox I'm using turns the title attribute into a caption.) Here's the relevant code from the filter:               foreach ( $attachments as $id => $attachment ) {             $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);             $link = str_replace('><img','title="test caption" ><img',$link);              $output .= "<{$itemtag} class='item'>";             $output .= "                                 $link                 ";             if ( $captiontag && trim($attachment->post_content) ) {                 $output .= "                     <{$captiontag}>                     " . wptexturize($attachment->post_content) . "                     </{$captiontag}>";             }             $output .= "</{$itemtag}>";             if ( $columns > 0 && ++$i % $columns == 0 )                 $output .= '';         }         $output .= "                 <br>\n";         return $output;     }      That second `$link` line with `str_replace` is as far I've gotten. I thought maybe I could get wp_get_attachment_link to output a title attribute, and when I couldn't find a solution I used str_replace but I don't know how to get the image caption where the words "test caption" currently are.


Wordpress 3.5 Media Manager - Change loaded image Size

The new media manager loads the FULL size images which is REALLY inefficient for a thumbnail. I'd like to replace it with a different size thumbnail that is also stored for each source image. Can't seem to find a way to do that either. Anyone have any tips?


Single page theme

I am trying to create single page theme. What i have trouble with is understanding this whole wordpress query logic. There is query object and supposedly i get all published posts like this:               $query = new WP_Query( array (          'orderby' => 'menu_order',          'order' => 'ASC',          'post_type' => array( 'page' ),          'post_status' => array( 'publish' ) ) );      and can loop over them like this :               while ( $query->have_posts() ) {         $query->the_post();         echo '<li>' . the_title() . '</li>';     }      But then what? I cant even figure out that codex - where are all the functions of post object that i can use? Like the_title()? Where is that in codex? What i want to achieve seemed pretty simple and straightforward - load all pages with nested subpages and then just print them out on single page similar to the loop above... But this codex is driving me crazy :P But is this even best approach? Should i be defining my query somewhere else (as opposed to index.php like im doing now)? Should i be somehow using wordpress original page loading which displays pages using their templates (if they have one) or using something similar to content-page.php like the one that default themes have? Alan


meta box not display data input in the textarea

I've had multiple errors with this metabox, first I thought Id fixed a undefined index error with the code below but now that doesn't appear my metabox doesn't save any data. code before the error:               if ( !wp_verify_nonce($_POST['custom_meta_box_nonce'], basename(__FILE__)))                return $post_id;      I tried adding the following to fix the undefined index error on line 108                if ( !isset( $POST['excerpt_meta_box_nonce'] ) || !wp_verify_nonce($_POST['excerpt_meta_box_nonce'], basename(__FILE__)))                return $post_id;       after adding this now any data I put in the metabox doesn't save. any help would be appreciated code for excerpt meta box                <?php     // Add the Meta Box       function vs_add_excerpt_meta_box() {           add_meta_box(               'excerpt_meta_box', // $id               'Excerpt Meta Box', // $title                'vs_show_excerpt_meta_box', // $callback               'post', // $page               'normal', // $context               'high'); // $priority       }       add_action('add_meta_boxes', 'vs_add_excerpt_meta_box');            // Field Array       $prefix = 'custom_';       $excerpt_meta_fields = array(           array(             'label' => 'Custom post teaser',             'desc'  => 'Replace the default excerpt with the text of your choice',               'id'    => $prefix.'excerpt',               'type'  => 'textarea'              )     );            // The Callback       function vs_show_excerpt_meta_box() {       global $excerpt_meta_fields, $post;       // Use nonce for verification       echo '<input type="hidden" name="excerpt_meta_box_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />';                // Begin the field table and loop           echo '
';           foreach ($excerpt_meta_fields as $field) {               // get value of this field if it exists for this post               $meta = get_post_meta($post->ID, $field['id'], true);               // begin a table row with               echo '
                      '.$field['label'].'	                      ';                       switch($field['type']) {                           // case items will go here                    // textarea                   case 'textarea':                       echo '<textarea name="'.$field['id'].'" id="'.$field['id'].'" cols="60" rows="4">'.$meta.'</textarea>
'.$field['desc'].'';                   break;                           } //end switch               echo '
';           } // end foreach           echo '
'; // end table       }            // Save the Data       function vs_save_excerpt_meta($post_id) {           global $excerpt_meta_fields;                // verify nonce           if ( !isset( $_POST['excerpt_meta_box_nonce'] ) || !wp_verify_nonce($_POST['excerpt_meta_box_nonce'], basename(__FILE__)))                return $post_id;           // check autosave           if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)               return $post_id;           // check permissions           if ('page' == $_POST['post_type']) {               if (!current_user_can('edit_page', $post_id))                   return $post_id;               } elseif (!current_user_can('edit_post', $post_id)) {                   return $post_id;           }                // loop through fields and save the data           foreach ($excerpt_meta_fields as $field) {               $old = get_post_meta($post_id, $field['id'], true);               $new = $_POST[$field['id']];               if ($new && $new != $old) {                   update_post_meta($post_id, $field['id'], $new);               } elseif ('' == $new && $old) {                   delete_post_meta($post_id, $field['id'], $old);               }           } // end foreach       }       add_action('save_post', 'vs_save_custom_meta');         ?>


Getting wordpress admin email

I'm building a contactform that needs to send all queries to the admin mail adress. The php file which processes the entered data and sends the email has only contains this code:               <?php     $admin_email = get_option('admin_email');          if($_POST["name"] != "" && $_POST["contact"] != ""  && $_POST["comments"] != "")     {         echo "Uw bericht is verzonden! ";         $name = $_POST["name"];         $contactOption = $_POST["contactoption"];              $msg = "Bericht afkomstig van: \n";         $msg .= "Naam: " .$name;         $msg .= "\nE-mail of Telefoonnummer: " .$contactOption;         $msg .= "\n\n";         $msg .= "Bericht: \n";         $msg .= $_POST["comments"];         $msg .= "\n\n";              $subject = utf8_decode("Bericht via Contactformulier");         $headers = utf8_decode("From: " .$name."\r\n");              mail($mailTo, $subject, utf8_decode($msg), $headers);          }     ?>      The problem is, I cannot use get_option or get_bloginfo to get the admin mail adress. This allways returns a fatal error. This file resists in my childtheme folder. Why can't I use these functions? I've also tried adding get_header() and get_footer() to the file, but these functions are also not recognized. I'm relatively new to wordpress. Am I missing something obvious here?


I need to delete all posts from my homepage & create a static front page

I want my homepage to be clean and without any posts or comments from my visitors. I have tried to do almost everything, but it doesn't work. I don't want people to discus anything, all they have to do is view who we are and how to reach us. Can somebody tell me what to do.


custom post creation on front page - on submit a search is done

Using a child theme of WP 2013 theme... In Settings > Reading, 'Front page displays' I have selected 'static page' and assigned it a page titled Home. For that page, I've assigned a custom template. That template calls a custom shortcode that displays a form for creating a custom post. And a loop to show the 10 most recent post of that cpt. Everything works fine - except that on submit, it refreshes to the archive page for the category assigned when creating the custom post. So it searches for that category. If I call the same shortcode on a different page, such as Contact, that isn't a front page, then on submit it will refresh to that page. Why does it search for the category when submitted from the front page? And how can I stop it?


Advanced archive url structure (category, tag and date)

Is it possible to create a permalink structure like this:               mysite.com/category/books/tag/read/2010/01      Or at least something like this:               mysite.com/category/books/?tag=read&year=2010&month=01      To elevate this question even further, would it be possible to do it for custom post types and taxonomies as well? Something like this:               mysite.com/movies/actor/john-cusack/genre/thriller/2010/01


Using file extensions in image titles

I need to find some way to either update all the titles of my images to use the file extensions, or update the caption with all my images to be the file name. I have over 900 images, so doing this one by one isn't really an option. I have searched for scripts, plugins, etc, to no avail.


Average Rating per Post based on Comment Rating

I have created Custom Post Types. In that i have a rating system in comments, for each comment user can rate 1-5 Stars. Now , i want the average of all ratings in comments of that post to show. How can i do that. Here is the link to the code file related to My rating System. Current Users can rate and comment. But i want the average of all comment ratings in that post. And this is a custom Post type. Please Help. [I have Added the rating.php to my dropbox ][1]https://www.dropbox.com/s/a544cj13nji1jtb/templatic_post_rating.php


Wordpress registration page template

I'm very new in wordpress, and I have a client that needs a custom registration/login form on the front-end side. I also need custom user fields. (phone, company name, about, blog url, etc). For the custom fields I found the `add_user_meta` function on Wordpress Codex, but I didn't find any information about the custom registration/login page templates. I finished my first Wordpress template, so I have idea how does it work, but I don't know where to start this registration/login thing. p.s. I would like to do this without plugins.


wp_get_attachment_image_src problem

I'm have a problem with the wp_get_attachment_image_src function returning the incorrect url for an image. My code looks like this: `$image_main_ar = wp_get_attachment_image_src( $image_ID, 'product_image_main' );` product_image_main is a registered image size: `add_image_size( 'product_image_main', 334, 385, false );` but when I print the $image_main_ar array I get: `Array ( [0] => http://www.website.com/wp-content/uploads/2011/07/Screen- shot-2011-07-27-at-15.03.07.png [1] => 334 [2] => 226 [3] => )` which shows the url for the original image I uploaded, not the resized version, and I've checked the resized version is in the upload folder, and the dimension in the array are correct for the resized version. The weird thing is the fourth key in the array [3] is empty, but on the images where it returns the correct url it is set to '1'. I've looked in the docs but can't find anything about this fourth value. Does anyone have any ideas? Many thanks for any advice.


Redirect Restricted Page to 404

Is there a way to show a 404 page if the current logged in user does not have the right clearance to view the page? I am looking for a PHP method, something like               if( !current_user_can('administrator') ) { show_404(); exit(); }      I have thought about using a redirect, but I would like to keep the url the same.


How can I conditionally show different home page templates based on whether or not the user is logged in?

How can I conditionally load HTML for the home page based on whether or not the user is logged in? Currently my theme has an index.php file. In that file I tried to create:               <?php     if(is_user_logged_in()) {      get_header(); ?>

             <?php              if ( have_posts() ) :                  while ( have_posts() ) : the_post();                      get_template_part( 'content', get_post_format() );                  endwhile;                 dw_minion_content_nav( 'nav-below' );              else :                  get_template_part( 'no-results', 'index' );              endif;              ?>

     <?php get_sidebar('secondary'); ?>     <?php get_footer(); ?>     <?php } else { ?>         // load plain ol' static boring HTML here with a login widget area.     <?php     } ?>      However, this doesn't work. In fact, no matter what I change in the index.php file, nothing else changes. I can even delete the file and it works fine!! I can see that I have a header.php file. If I modify that file, then I can see changes appear. But, that means I'd have to modify that, footer.php, page.php, content.php etc etc, ultimately having multiple files that have conditional logic in them. I'm new to developing in Wordpress. There has to be a better way to do this right? If the person is not logged in, a completely different home page template / design should show up that has one single widget area where the WP login form (bp login widget) shows up. Once that person is logged in, the normal home page with default template should appear. In Reading, a static page is set and it has a template of "Default Template."


WPMU - SuperAdmin / plugin install permissions

let's suppose I have Wordpress Multisite install and I have there SuperAdmin. I need to restrict "install_plugin" capability in Network Admin for SuperAdmin mentioned above. How can I do that? I have **no** problem to set _install_plugin_ capability to zero on single site install for admin. That's working, but on multisite I have problem.. I tried to set _manage_network_plugins_ cap to zero (add_cap($cap, false)) for SuperAdmin account but I am still able to install plugins on network...


Inserting posts to database

I want to import a bunch of posts directly into the database and I'm wondering how I can do this? I found this script http://www.phpsuperblog.com/wordpress/wordpress-auto-create-post-into-the- mysql-database-from-excel-data-file/ but it's missing on how to import custom fields. Does anyone know how I can import custom fields with that script?


Create Logout Link Wordpress Admin Menu

I'm looking at creating a Logout link in the Wordpress admin menu that when clicked the user is logged out immediately. I don't want the Logout link to be a submenu of an existing menu, I just want it to be the last item that appears on the menu. Any ideas? Thanks in advance.


Name and password development/offline mode plugin

I have found this: http://wordpress.org/extend/plugins/restricted-site-access/screenshots/ But, I need something a little different. Something like Jommla has for off- line mode e.g.: http://www.cloudaccess.net/joomla-2-5/89-global- configuration/207-offline-mode-joomla-2-5.html But I need to be able to access the frontend and NOT ONLY THE BACKEND!


How to insert link to the default post archive into a menu

I can add categories, I can even add a custom post type archive, but I can't add the original posts archive. It's not among the page list. I worked around this by creating a page, creating a page-pagename.php file, displaying the posts there and linking to that page, but when that page is shown, the menu item doesn't have the 'current-menu-item' class.


Have multiple category queries from the URL been fixed yet?

Is it now possible to query multiple categories from the URL? http://www.mywpsite.com/?cat=1+7 ? I think this has worked for tags for some time. If not, is there another way to achieve this?


Is it possible to animate the Twenty Eleven menu?

I have a menu in my Twenty Eleven child theme that has some hierarchical items. Twenty Eleven handles it just fine, of course, but my client likes the fancy-looking menu animation that you can see on this site. I don't need the horizontal style that shows up under the "Resources by Topic" item, just the on-hover expansion like the "Who We Are" heading. I have used jQuery quite a bit before in other (non-WordPress) websites, but don't know where to begin in this case. Is this animation possible with Twenty Eleven?


Add text to wordpress admin 'Add Post' edit

I'd like to add some descriptive text underneath the page title on both the list and edit post screens for the default post and also custom post types - e.g. "Below is a list of your recent blog posts." What's the best way to do this? I need to make add a list of instructions as in: xxxx 2. xxxxx 3. xxxx I'm guessing I'll need to add html for this? And ideally I can change the font and make it bold. Thanks! This is the text I need: > "To add a video, you need to make sure that the video is first uploaded to > Youtube or Vimeo or Google Videos.   1. In the 'Video Embed Code', enter the video embed code (`http://support.google.com/youtube/bin/answer.py?hl=en&answer=171780`) The thumbnail will Automatically be added   2. Enter title and text in the main panel below   3. Choose which continent and category that is most fitting for your video   4. Press "Publish"


Genesis framework comments broken?

I got a really weird problem. Im using a Child theme which using the Genesis framework. I was using Akismet plugin to stop the spammers and it was workin just fine. Recently i just made a comment by myself to test it and this is where the problem start.   * The comment is showing inside the dashboard and its awaiting moderation, but i cant delete, approve, unapprove, move or do anything with it. Shortly the only way to make it disappear is deleting the comment in phpmyadmin.   * Other thing is, Even if i do 5 comment, only one appearing in the dashboard the other 4 just disappear. Not even phpmyadmin showing it. Thank you in advance for your help.


Tags as a dropdown with set tags

Sorry if this is a silly question but is it possible to have a taglist as a dropdown? I have a page where users can post theyre own content, and I would like them to be able to choose certain tags as a dropdown, is this possible? Heres the page so you can see http://wordpress.art-williams.com/add- destination I appreciate any help what so ever, anything is a huge help! Thanks


Widget options - where to put them?

I have a widget which I want to add a couple of options. The options are effectively 'global' for the widget - username and password details to a secured web service. So in effect, wherever the widget is used the same parameters will be used. I presume I should use an add_options_page? Or ... Add options on the widget itself? Or ... can you do both?


Using different size thumbnails on different parts of my site... with functions.php?

Two years ago in StackOverflow there was an interesting question about using specific thumbnails, small, medium or large images on different parts of the site. The question, available here, was well answered by one of the users, Doug Neiner, who proposed to use the following code:               <?php       function get_attached_images(){         // This function runs in "the_loop", you could run this out of the loop but         // you would need to change this to $post = $valid_post or something other than         // using the global post declaration.         global $post;          $args = array(           'post_type' => 'attachment',           'numberposts' => 1,           'post_status' => null,           'post_parent' => $post->ID,           'order' => 'ASC',           'orderby' => 'menu_order'           );          $attachment = get_posts($args); // Get attachment         if ($attachment) {           $img = wp_get_attachment_image_src($attachment[0]->ID, $size = 'full'); ?>           <img alt="<?php the_title(); ?>" src="<?php echo $img[0] ; ?>" width="<?php echo $img[1] ?>" height="<?php echo $img[2] ?>"/>       <?php }       }     ?>      But that is not what I exactly need, because this code has to be inserted in every loop on my index.php or single.php (for example) to work. Could it be possible to create that code on the functions.php and then call that code from each loop? This would be smarter and more elegant, I guess, because using all that code everytime on each loop seems a bit inelegant... Are there other ways to do this?


How to filter by post-format in admin?

I need to filter my posts by Post-Formats in admin ? How can I do that ? For now, Wordpress allows to filter by Categories and Dates.


Remove parent from custom post type

I've created a new custom post type with WordPress. However, the slug adds the post to a parent, like so: `http://example.com/UNNCESSARY-PARENT/post-title` However, I'd like it to create: `http://example.com/post-title` Is this possible? This is how I've registered the post type:               function create_films() {       register_post_type( 'films',         array(           'labels' => array(             'name' => 'Films' ,             'singular_name' =>  'Films'                ),         'public' => true,         'has_archive' => false,         'taxonomies' => array('category', 'post_tag')          )       );          }          add_action( 'init', 'create_films' );      And this is the documentation.


How to display only the posts with category that match the current page URL

I'm trying to get the loop below to display only the posts with the name that matches the current page's **absolute** name. E.G: if the URL of the current page is mysite.com/ **current** , then the post to be displayed will be the one with the category " **current** ". Thereby matching the name of the current page. The problem is that it displays all post instead of the one that matches just the absolute name of the current page.               <?php       global $current_page;             $page = $current_page->ID;             $category  = $page;     ?>          <?php         // assign the variable as current category        $category = $page;            // concatenate the query       $args = 'cat=' . $category;            // run the query       query_posts( $args );            if ( have_posts() ) : while ( have_posts() ) : the_post();              pthe_content();            endwhile;          endif;               ?>


Two single.php files?

I have a custom post type "people". For each person, I can enter the following custom fields: "address", "occupation" and "pictures". In the single-people.php I display the address and the occupation. In addition, this single template contains a gallery button - when the website user clicks on it I want to takes the user to a separate page where only the pictures of the person he just looked at are displayed. How do I achieve that? I cannot just create a second single.php file, right?


Session problem in PHP - trying to create a simple CAPTCHA

I found a CAPTCHA script online for a self-made contact form on my site. In my theme folder I have a file called `captcha_code_file.php`:               <?php      /*     *     * this code is based on captcha code by Simon Jarvis      * http://www.white-hat-web-design.co.uk/articles/php-captcha.php     *     * This program is free software; you can redistribute it and/or      * modify it under the terms of the GNU General Public License      * as published by the Free Software Foundation     *     * This program is distributed in the hope that it will be useful,      * but WITHOUT ANY WARRANTY; without even the implied warranty of      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the      * GNU General Public License for more details:      * http://www.gnu.org/licenses/gpl.html     */          session_start();          //Settings: You can customize the captcha here     $image_width = 110;     $image_height = 35;     $characters_on_image = 6;     $font = './monofont.ttf';          //The characters that can be used in the CAPTCHA code.     //avoid confusing characters (l 1 and i for example)     $possible_letters = '23456789bcdfghjkmnpqrstvwxyz';     $random_dots = 0;     $random_lines = 20;     $captcha_text_color="0x#B9B098";     $captcha_noice_color = "0x#CEC7BA";          $code = '';               $i = 0;     while ($i < $characters_on_image) {      $code .= substr($possible_letters, mt_rand(0, strlen($possible_letters)-1), 1);     $i++;     }               $font_size = $image_height * 0.75;     $image = @imagecreate($image_width, $image_height);               /* setting the background, text and noise colours here */     $background_color = imagecolorallocate($image, 255, 255, 255);          $arr_text_color = hexrgb($captcha_text_color);     $text_color = imagecolorallocate($image, $arr_text_color['red'],              $arr_text_color['green'], $arr_text_color['blue']);          $arr_noice_color = hexrgb($captcha_noice_color);     $image_noise_color = imagecolorallocate($image, $arr_noice_color['red'],              $arr_noice_color['green'], $arr_noice_color['blue']);               /* generating the dots randomly in background */     for( $i=0; $i<$random_dots; $i++ ) {     imagefilledellipse($image, mt_rand(0,$image_width),      mt_rand(0,$image_height), 2, 3, $image_noise_color);     }               /* generating lines randomly in background of image */     for( $i=0; $i<$random_lines; $i++ ) {     imageline($image, mt_rand(0,$image_width), mt_rand(0,$image_height),      mt_rand(0,$image_width), mt_rand(0,$image_height), $image_noise_color);     }               /* create a text box and add 6 letters code in it */     $textbox = imagettfbbox($font_size, 0, $font, $code);      $x = ($image_width - $textbox[4])/2;     $y = ($image_height - $textbox[5])/2;     imagettftext($image, $font_size, 0, $x, $y, $text_color, $font , $code);               /* Show captcha image in the page html page */     header('Content-Type: image/jpeg');// defining the image type to be shown in browser widow     imagejpeg($image);//showing the image     imagedestroy($image);//destroying the image instance     $_SESSION['6_letters_code'] = $code;          function hexrgb ($hexstr)     {       $int = hexdec($hexstr);            return array("red" => 0xFF & ($int >> 0x10),                    "green" => 0xFF & ($int >> 0x8),                    "blue" => 0xFF & $int);     }     ?>      I can't seem to store the session created. What do I need to do to make this work? And how do I get the session in another file, e.g. `if(empty($_SESSION['6_letters_code'])`?


Change admin defaults for reading settings

I have customised index.php to display 6 posts:               <?php     // Get header     get_header(); ?>
     <?php // Begin paginate and loop       $temp = $wp_query;        $wp_query = null;        $wp_query = new WP_Query();        $wp_query->query('showposts=6'.'&paged='.$paged);        if ($wp_query->have_posts()) : while ( have_posts() ) : $wp_query->the_post();      ?>

<a href="<?php the_permalink(); ?>"><?php the_title(); ?>
      <?php the_excerpt(); ?>
          <?php endwhile; // End while ?>                   <?php previous_posts_link('« Newer Posts') ?>         <?php next_posts_link('Older Posts »') ?>               <?php // Reset       $wp_query = null;        $wp_query = $temp;       ?>          <?php else: ?>
<?php _e('Please add some posts.'); ?>
     <?php endif; // End loop and primary ?>
          <?php get_sidebar(); ?>     <?php get_footer(); ?>      For this to work correctly, I need to set "Blog pages show at most" from 10 posts to 6. As the theme I'm building will be used on a multisite environment, I'd like to set the default reading setting to 6 posts. Is it possible to change the default setting via functions.php? I've taken a look at options-reading.php within the core of WordPress. Line 126 shows the following:               <?php _e( 'Blog pages show at most' ); ?>      Changing this value obviously doesn't update the database value without updating the settings page within WP Admin. If you could point me in the right direction, that would be great.


sidebar troubles, taxonomy trouble

can you help me with two things :   * i have different movies, to classify into different "genre", should i use "taxonomies" or the already built in "category"? is taxonomy more appropriate in this case? i saw so many tutorials about taxonomies, but also some website only using categories for several things, what should i do?   * i'm trying to show my personal sidebar, so i built "mysidebar" into "functions.php",it is editable in my dashboard, but it doesn't work when i try to show it with : > get_sidebar ('mysidebar'); why? i tried another way, it works with : > if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('mysidebar') ) > : dynamic_sidebar( 'mysidebar' ); ?> isn't 'get_sidebar' the method to "call" the sidebar? Ok so now i would like to customize my sidebar, so i created a php page named "sidebar-mysidebar.php" and i just echoed some text, that is not shown, could you tell me how to put some text with the code, and not only through the dashboard? Thanks a lot


Unsure how to add simple checkboxes that write to a small table to admin

I've been doing a lot of reading on the add_meta_boxes...but there's so much information that I'm confused about when to use them. I have a little plugin that writes out some checkboxes and then when a post is saved with those checkboxes checked, a row is saved in a separate table I created to enforce post_id to image relationship. My checkboxes show up fine in wp_admin, but I have a front facing way to edit some custom post types for qualified users and the checkboxes don't show up in that case. I was trying to hook them into dbx_post_sidebar, but further research shows that may be deprecated. I just don't know if add_meta_boxes would add my checkboxes to my front facing edit screens (the front facing part is Event Manager and it let's users submit events without going into wp-admin), in this case, and how to really implement them in the easiest way possible. Frankly, they seem quite complicated. I can't get my head around whether or not I need to use callbacks or how to hook into a page (by name? do I need to specify a page?). My plugin code is here: http://pastebin.com/Ztp01k0q Here's where I do my add_action stuff:               # actions we use to get stuff done     add_action('activate_ixp-amenities-icons/ixpposticon.php', array(&$this, 'install'));           // install     add_action('deactivate_ixp-amenities-icons/ixpposticon.php', array(&$this, 'uninstall'));       // uninstall     add_action('wp_head', array(&$this, 'style'));                                                                          // load style     add_action('dbx_post_sidebar', array(&$this, 'checkboxes'));                                                    // checkboxes     //add_action('dbx_post_advanced', array(&$this, 'checkboxes'));     //add_action('admin_menu', array(&$this, 'checkboxes'));     //add_meta_box( 'hello', 'hello', 'None', 'location', 'normal', 'default', null);     add_action('publish_post', array(&$this, 'save'));                                                                      // publish     add_action('save_post', array(&$this, 'save'));                                                                         //save     add_action('edit_post', array(&$this, 'edit'));                                                                         // edit...this sin't firing yet     add_action('delete_post', array(&$this, 'delete'));                                                                     // delete     add_action('admin_menu', array(&$this, 'adminMenu'));                                                           // adminMenu


How to block a category from one user and enable the category for the rest of the users

I have a site in which all categories are open to anyone, except for 2 categories that are password protected: Students, and Teachers. They are open only to specific users types, as follows: The Students category is open to a user of type student, and to user of type teacher. The Teachers category is open to a user of type teacher, but _not_ to user of type student. How do I go about implementing that in Wordpress?


Installing WP on localhost

This is maybe a beginner question, but as Codex Installing WP says, I use to install WP on the server directly and then I do the changes on-line, instead of begin installing on my localhost and do the changes there. However, I'm guessing this is not a good option. Could anyone confirm me that I should begin installing WP on my localhost? So instead of `http://example.com/wp-admin/install.php`, I should go to `http://localhost/example/wp-admin/install.php`


Function returns different value when called from 'save_post' than when called on page load

The "word_count" function below returns different values depending on where its called from. Why?               add_action('save_post', 'my_custom_save', 10, 2);          function myPlugin($post)     {         global $rockScore;         global $text;         $text = strip_tags($post->post_content);         echo word_count($post); //returns "350"     }          function word_count($post)     {         global $text;         $word_count = explode(' ', $text);         $word_count = count($word_count);     return $word_count;     }          function my_custom_save($postID, $post){         if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {             return $postID;         }         else         {             if($parent_id = wp_is_post_revision($postID))             {             $postID = $parent_id;             }             echo word_count($post);die; //still returns "1"         }     }          register_activation_hook(__FILE__, 'myPlugin');


How to show beneath posts the full category path?

My portal has the following category structure: **CategoryLevel1=>CategoryLevel2=>CategoryLevel3=>CategoryLevel4** I assign posts to CategoryLevel4 but I want to show the full category path beneath each post. Each node should be clickable. Thanks.


cannot find cforms action handler page

I'm not able to find the action handler page for the cforms plugin anywhere. I want to write some function in the action handler page of the cforms plugin using the post values.


How can I disable the comments page display from one of two comment fields

I have a Wordpress blog with a second textarea added as a additional field. Both comment boxes are generating comments in the post. The additional textarea comment box is populating the wp_metacomment database table and the main default message box is populating the wp_comments database table by default. I want to turn off the comments coming from the main default Wordpress comments field and keep them from displaying in the page, but keep the data going into the wp_comments table. I was thinking I could delete the main comments box and create another meta-field comments textarea box so I can more easily control comments display using get_comment_meta, but I was thinking there was a more elegant solution.


Link to large image version instead of original?

How can I best make WP link to the large version of the image in all posts (instead of the original one) without modifying all the data in the database? I'm probably looking for the best filter to attach to.


How can I pass $post object to 'save_post' add_action?

I have several functions that are called from inside a `save_post` function. However, all of the functions that use the `$post` object are returning incorrect values because it appears that the default value being passed to `save_post` is the post ID rather than the post object. How can I pass the post object to the `save_post` function in addition to the post ID?               add_action('save_post', 'my_save_function');


How do I grab specific posts (by post id) and display the title, featured image, and excerpt?

I'm trying to help a friend get his site in order and he wants me to swap out the "services" posts on the front page with 4 specific posts. Thing is, I don't know the right way to do this dynamically. How do I call up the content of just the post id, the featured-image (with the right dimensions) and a short excerpt from the beginning of the post? Any suggestions would be greatly appreciated; thanks.


Examples of WordPress being used as a CMS in a B2B market (Business-to-Business)

Can anyone provide me with some links to high profile sites that are using using WordPress as their CMS as a B2B marketing site? The reason why I am asking is that I'm putting together a proposal document and would like to give some examples of other B2B sites that are using WordPress as their whole website and not just their blog. I've been looking on the WordPress Showcase but cannot find any high profile B2B websites. There are a fair amount of high profile sites but those sites don't use WordPress as their main corporate site. Rather they use WordPress as a micro site or side blog. Examples of high profile B2B sites for me would be:   * Bloomberg   * KPMG   * Ernst & Young Do you know of any high profile B2B sites using WordPress as their main site?


Comments feed - Undefined named entity: ndash

I used to have a rss comment feed at the url /comments/feed which doesn't work anymore. I checked the feed on feedvalidator and I've an error > line 111, column 29: Undefined named entity: ndash [help] The line in question is comment where the content is               <guid isPermaLink="false">http://mart-e.be/?p=1694#comment-9711</guid>     <description>Ou mettre des – à la place des -     Mais oui la solution de rcommande fonctionne bien :)</description>      In the context, it is normal that there was an `–` there (explaining to write `\--` with `––`). Any idea how to fix this feed error ?


I have a custom post type that I want to query a dynamic category name from a custom meta field

So this is my Query. where category 17 is, I want this to by dynamic based on the page you're on. So I have a custom meta field called city_name but when I just put that in there. it obviously doesnt work. How do I get the 'cat' to show the custom meta name               // WP_Query arguments     $args = array (     'post_type'              => 'advertisement',     'category_name'          => 'city_name',     'posts_per_page'         => '2',     'order'                  => 'DESC',     'orderby'                => 'date',      );          // The Query     $search_ads = new WP_Query( $args );          // The Loop     if ( $search_ads->have_posts() ) {     while ( $search_ads->have_posts() ) {         $search_ads->the_post(); ?>
<a href="<?php the_permalink() ?>"><?php the_title(); ?>
          <?php }     } else {     // no posts found     }      EDIT: I started doing this:               $key_1_value = get_post_meta( get_the_ID(), 'city_name',   true );          // WP_Query arguments     $args = array (     'post_type'              => 'advertisement',     'category_name'          => '$key_1_value',      doesn't seem to work. If I make category name "toronto" which is the "city_name" I am looking for, it works perfect. Just need that city_name to be drawn dynamically.. EDIT PROBLEM SOLVED. ok so this turned out to be almost perfect. however, you have to reset the query, before drawing the value. Good thing it didn't take me 100 billion hours to figure out. Thanks India.               wp_reset_query      Add the reset right after the $key_value line before the arguements, then you can draw your custom meta field into the arguments.


How to make a theme unable to be used on a multisite network?

I have run across a WordPress theme that the developers intentionally set to not be usable on a multisite network. The theme was installed on my single site and then when I configured it to be a multisite network and did the initial log out and log back in I got a message that the theme could not be used on multisite networks but only standard single sites. I'm curious how I could achieve this on a theme I'm developing, to make it unable to be used on a multisite network?


Schedule cron event from widget

Can I use wp_schedule_event() to set up a cron job from within a widget? I tried, but I can't make it work, The problem seems to be the $hook parameter. The function I'm trying to hook is located within the widget class so my guess is that WP can't find it. neither of these work:               wp_schedule_event(time(), 'daily', 'my_widget_cron');     wp_schedule_event(time(), 'daily', array(&$this, 'my_widget_cron'));      any ideas?


Adding a Custom Post Type into the menu screen

I need a way of adding custom post types to the "Appearance-->Menus" option in Wordpress. i have created a custom post type with: `register_post_type('produksjoner',$args);` All examples I find just add the pages to the menu by manually adding the URL into a custom menu item. I want it to be able to add this automatically by choosing it like any other page. I have been searching for two days now... please help me :-/


Random white space before doctype

I'm working on a very very simple theme, it's only a one page site. I'm off for holiday tomorrow morning and I've been asked to set this site live last night. Well, everything was going great until I opened IE (I've tested the html in IE before I developed the theme) - for some reason IE triggered Quirks Mode and everything looked like a mess. I viewed source in IE and apparently there's some extra space before the doctype. Then I checked the site in chrome dev tools and looks like my header stuff went inside the body element? ![enter image description here](http://i.stack.imgur.com/oyUIl.jpg) I had similar problem before but I've fixed it by removing `?>` in my functions.php and all the include files. This doesn't seem to work here. Here's the code: header.php               <!DOCTYPE html>                                    <html class="no-js" <?php language_attributes(); ?>>                        <meta charset="<?php bloginfo( 'charset' ); ?>" />         <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">         <meta name="viewport" content="width=device-width" />                           <link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,700,800" rel="stylesheet">         <link href="<?php bloginfo('template_directory'); ?>/style.css" rel="stylesheet" />         <?php wp_head(); ?>

                     <a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?>

Login

      index.php / page.php (pretty much the same, except there's no heading or date in page.php)               <?php get_header(); ?>
             <?php if ( have_posts() ) :                       while ( have_posts() ) :                           the_post(); ?>                  <?php the_content(); ?>                  <?php endwhile;                   else: ?>
Sorry, no posts matched your criteria.
                  <?php endif; ?>
     <?php get_footer(); ?>      footer.php

Contact Details

Telephone:

                             0844 357 9970

Email:

                             sales@retailview.com

Learn More

                             Learn more about Retail Data

                             Learn more about Brand View

Retail View ® is a registered trademark. © Retail View 2013.

                                                           <?php wp_footer(); ?>                         functions.php               <?php         require_once('lib/shortcodes.php');         require_once('lib/filters.php');              // ==================================================         // Register Menus         // ==================================================         register_nav_menus(              array(                  'primary'               => 'Primary Navigation'             )         );               // Add post thumbnails (feature image)         add_theme_support( 'post-thumbnails' ); ?>      filters.php               <?php         // ==================================================         // Hide Admin Bar         // ==================================================         add_filter( 'show_admin_bar', '__return_false' );              // ==================================================         // Body Class Modification         // ==================================================              function custom_classes($classes) {             global $wp_query;                  // if there is no parent ID and it"s not a single post page, category page, or 404 page, give it             // a class of "parent-page"             if( $wp_query->post->post_parent < 1  && !is_single() && !is_archive() && !is_404() ) {                 $classes[] = "parent-page";             };                  // if the page/post has a parent, it"s a child, give it a class of its parent name             if($wp_query->post->post_parent > 0 ) {                 $parent_title = get_the_title($wp_query->post->post_parent);                 $parent_title = preg_replace("#\s#","-", $parent_title);                 $parent_title = strtolower($parent_title);                 $classes[] = "parent-pagename-".$parent_title;             };                  // add a class = to the name of post or page             $classes[] = $wp_query->queried_object->post_name;                  return array_unique($classes);         };              add_filter( 'body_class', 'custom_classes' );                   // ==================================================         // Search blog posts only         // stackoverflow.com/questions/4198842/wordpress-search-function-to-only-search-posts#answer-9885744         // ==================================================              function SearchFilter($query) {             if ($query->is_search) {                 $query->set('post_type', 'post');             }             return $query;         }              add_filter('pre_get_posts','SearchFilter');      and shortcodes.php               <?php         // ==================================================         // Clean Shortcode         // ==================================================              function parse_shortcode_content( $content ) {                  /* Parse nested shortcodes and add formatting. */             $content = trim( do_shortcode( shortcode_unautop( $content ) ) );                  /* Remove '' from the start of the string. */             if ( substr( $content, 0, 4 ) == '' )                 $content = substr( $content, 4 );                  /* Remove '' from the end of the string. */             if ( substr( $content, -3, 3 ) == '' )                 $content = substr( $content, 0, -3 );                  /* Remove any instances of ''. */             $content = str_replace( array( '

' ), '', $content );             $content = str_replace( array( '

' ), '', $content );                  return $content;         }              // move wpautop filter to AFTER shortcode is processed              remove_filter( 'the_content', 'wpautop' );              add_filter( 'the_content', 'wpautop' , 99);              add_filter( 'the_content', 'shortcode_unautop',100 );                   // ==================================================         // Columns         // ==================================================              function create_column($atts, $content = null) {             extract(shortcode_atts(                 array(                     'size'  => 'third',                     'class' => ''                 ), $atts             ));                  $class = $class == 'first' ? 'first-column' : '';                  $output = '
' . $content . '
';                  return $output;         }              add_shortcode("column", "create_column");                   // ==================================================         // Pop up Window         // ==================================================              function popup_window($atts, $content = null) {             extract(shortcode_atts(                 array(                     'id'  => null                 ), $atts             ));                  $output = '
                                 ' . do_shortcode($content) . '
';                  return $output;         }              add_shortcode("window", "popup_window");                   // ==================================================         // Vimeo         // ==================================================              function insert_video($atts) {             extract(shortcode_atts(                 array(                     'id'        => '0',                     'align'     => 'right',                     'width'     => '400',                     'height'    => '230'                 ), $atts             ));                  $align = $align != 'left' && $align != 'right' && $align != 'center' ? 'right' : $align;                  $output = '';                  return $output;         }              add_shortcode("vimeo", "insert_video");      I can also send a .zip theme if that helps. One thing that I've noticed, when you remove the functions and the header, Wordpress inserts some default html and there's no trailing white space or other bugs so I guess it can have something to do with these 2 files? I've spent a night trying to sort it out but I can't... The only reason I gave up and posted here is because I need to set this live before I go on my holiday (my flight is in couple of hours). EDIT #1: I've just looked at the raw html on the resources tham (chrome dev tools): ![enter image description here](http://i.stack.imgur.com/cXFI8.jpg)


term meta query

I add custom fields to attributes like "paint". The attribute will have `paint` as name and `colorcode` as meta term field. Before `get_terms`, `terms_clauses left join` the woocommerce term meta to get terms that matches the color code. But it is not working as expected. No terms are fetched.               foreach($add_fields as $add_field) {             $term_meta_query[] = array(                 'key'        => $add_field['id'],                 'value'      => $search,             );     }          add_filter('terms_clauses','woocommerce_autocomplete_terms_clauses', 10 , 3);          $terms = get_terms( $attribute, array( 'name__like' => $search ,'meta_query' => $term_meta_query ) );             function woocommerce_autocomplete_terms_clauses( $clauses, $taxonomies, $args ) {         global $wpdb, $woocommerce;              // query fields         if ( strpos('COUNT(*)', $clauses['fields']) === false ) $clauses['fields']  .= ', tm.* ';              //query join         $on_cond = '';         if(count($args['meta_query'])) {              $meta_query = $args['meta_query'];             foreach($meta_query as $query) {                 if(isset($query['key']) && $query['key'] !='') {                     if(strlen($on_cond) > 0 ) {                         $on_cond .= " OR ";                     }                     $on_cond .= " ( tm.meta_key = '" . $query['key'] ."' ";                     if(isset($query['value']) && $query['value'] !='') {                         $on_cond .=  " AND tm.meta_value LIKE '%".$query['value']."%' ";                     }                     $on_cond .= ") ";                 }             }             if(!empty($on_cond)) {                 // default to ASC                 if ( ! isset($args['menu_order']) || ! in_array( strtoupper($args['menu_order']), array('ASC', 'DESC')) ) $args['menu_order'] = 'ASC';                      $order = "ORDER BY tm.meta_value+0 " . $args['menu_order'];                      if ( $clauses['orderby'] ):                     $clauses['orderby'] = str_replace('ORDER BY', $order . ',', $clauses['orderby'] );                 else:                     $clauses['orderby'] = $order;                 endif;                      $clauses['join'] .= " LEFT JOIN (SELECT * FROM {$wpdb->woocommerce_termmeta} WHERE  ".$on_cond . " ) AS tm ON (t.term_id = tm.woocommerce_term_id) ";             }         }         return $clauses;     }      (I am using a autocomplete function with variation attributes in woocommerce.)


Count posts or custom post types from last 24 hours (or from today)

I would like to display count for custom post types (or posts) which was published that day (last 24 hours or TODAY). I use this snippet to get count of all posts from "posts" or from "custom post types"               <?php         $numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE (post_status = 'publish' AND post_type = 'post')");         if (0 < $numposts) $numposts = number_format($numposts);     ?>      in templates:               <?php echo $numposts ?>      but I don't know how to display count only for last 24 hours or TODAY (it means from midnight to midnight)


Template Tag not available in real Cron Jobs

I have very simple file with one line:               echo file_get_contents( get_template_directory_uri().'/scheduler.php' );      This file is called by cpanel cron using php -q. When I put full link without get_template_directory_uri function everything works fine, with this function cron returns Call to undefined function `get_template_directory_uri()`


How to display posts on template

I've added a page template that is my new home page and I would like to be able simply list the last 5 blog entries. My home page currently looks like...               <?php     /**         * This file controls the layout of your homepage         *         * @package WordPress         * @subpackage Pytheas WordPress Theme         * Template Name: Custom Home     */          get_header(); ?>          <?php get_template_part('content','slider'); ?>

          <?php             $wp_query = new WP_Query(                 array(                     'post_type' => 'post',                     'showposts' => of_get_option('home_blog_count','4'),                     'no_found_rows' => true,                     'ignore_sticky_posts' => true                 )             );                  if( $wp_query->posts ) { ?>
                            <?php                     // Display heading                     if( of_get_option('home_blog_title') ) { ?>
                             <?php echo of_get_option('home_blog_title'); ?>
                     <?php } ?>
                             <?php                         // Begin Loop                         $wpex_count=0;                         foreach( $wp_query->posts as $post ) : setup_postdata( $post );                             $wpex_count++;                                               $wpex_clr_margin = ( $wpex_count == 1 ) ? 'clr-margin' : NULL; ?>                                    <div <?php post_class('home-blog-entry span_6 col '. $wpex_clr_margin); ?>>                             <?php                             //featured image                             if( has_post_thumbnail() ) { ?>                                 <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" class="home-blog-entry-img-link">                                     <img src="<?php echo aq_resize( wp_get_attachment_url( get_post_thumbnail_id() ), wpex_img('blog_related_entry_width'),  wpex_img('blog_related_entry_height'),  wpex_img('blog_related_entry_crop') ); ?>" alt="<?php echo the_title(); ?>" class="blog-entry-img" />                                                              <?php } ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?>

                                 <?php                                  // Display excerpt                                 echo ( !empty( $post->post_excerpt ) ) ?                                     apply_filters('the_content', get_the_excerpt() ) :                                         wp_trim_words( strip_shortcodes( get_the_excerpt() ), of_get_option('portfolio_entry_excerpt_length','200') ); ?>

                         <?php                         if( $wpex_count==4) {                             echo '

';                             $wpex_count=0;                         }                         endforeach; ?>

                    <?php             }             wp_reset_postdata();?>

          <?php get_sidebar(); ?>          <?php get_footer();?>      I'm unclear why I'm not able to do something like...                           <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                         <?php the_content(); ?>                         <?php wp_link_pages( array( 'before' => '
', 'after' => '
', 'link_before' => '', 'link_after' => '' ) ); ?>
                                                   <?php edit_post_link( __( 'Edit Page', 'wpex' ), '', '' ); ?>
                      <?php comments_template(); ?>             <?php endwhile; ?>      which is what I see on many other template files. Can someone help me understand how I can query the most recent X posts and display them using `the_content();` (which I think will display the post with the author, post date, etc.)


Displaying results from custom taxonomy query

I have created a custom taxonomy Region and I would like to query this taxonomy for all results and display them. My query is:               $args = array(     'tax_query' => array(         array(             'taxonomy' => 'region',             'field' => 'slug',             'terms' => array( 'north', 'east', 'west', 'south' )         )     )     );     $query = new WP_Query( $args );      How do I then display this result as html? Something along the lines of this:
        <img src="<?php echo get_template_directory_uri(); ?>/images/region1.jpg" alt="" />        TAXONOMY TITLE HERE


Top Level pages in wordpress giving 404, but child pages working fine

Basically everything works fine except for the top level pages ( e.g. category, archives, single post, custom post type, etc...). I have 3 custom post types and 4 custom taxonomies (each custom taxonomy is attached to a post type respectively and there is one more taxonomy that is attached to all of the post types). Here is the set up for both of them:               register_taxonomy(         'newsroom-topics',         array ( 0 => 'news-post',),         array (             'hierarchical' => true,              'label' => 'Newsroom Topics',             'show_ui' => true,             'query_var' => true,             'rewrite' => array('slug' => '/'),             'singular_label' => 'Newsroom Topic'         )       );          register_post_type(         'news-post',         array(               'label' => 'Newsroom Posts',             'description' => '',             'public' => true,             'show_ui' => true,             'show_in_menu' => true,             'capability_type' => 'post',             'hierarchical' => false,             'rewrite' => array('slug' => 'newsroom'),             'query_var' => true,             'has_archive' => true,             'exclude_from_search' => false,             'menu_position' => 5,             'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes','post-formats',),             'taxonomies' => array('content-type','newsroom-topics',),                   'labels' => array (                   'name' => 'Newsroom Posts',                   'singular_name' => 'Newsroom Post',                   'menu_name' => 'Newsroom Posts',                   'add_new' => 'Add Newsroom Post',                   'add_new_item' => 'Add New Newsroom Post',                   'edit' => 'Edit',                   'edit_item' => 'Edit Newsroom Post',                   'new_item' => 'New Newsroom Post',                   'view' => 'View Newsroom Post',                   'view_item' => 'View Newsroom Post',                   'search_items' => 'Search Newsroom Posts',                   'not_found' => 'No Newsroom Posts Found',                   'not_found_in_trash' => 'No Newsroom Posts Found in Trash',                   'parent' => 'Parent Newsroom Post',     ),) );      Any thoughts as to why this is happening? UPDATE: So after having just post this after a while of looking for why this was happening, i found out the problem. In the reading settings, my front page was set to be displayed as a static page, and when i changed it back to the default, everything worked fine.


Show only items from user_role in code

I need add this code to this code http://itweb.sk/script.txt                      $user = new WP_User( $item->post_author );             if ( !user_can($user->ID,'directory_4') ) {             echo "hello";             }      "hello" will be showed all items except "directory_4" . I know that It will be connect with                      {foreach $items as $item}               {/foreach}      Very thank you for your help!


AJAX search posts and pages

Im trying to make a plugin where i need to create an AJAX search. Im using the method described in http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in- wordpress/ to perform the ajax calls. So far all good. Problem is not sure how to retrieve the search results in my ajax function. First attempt was using WP_Query like these:               $query= new WP_Query( array( 'post_type'=> 'any','post_status' => 'publish','posts_per_page' => '8','s' => wp_specialchars($string)) );      Problem here is as soon as i pass the string to "s" the query changes from post_type => 'any to post_type = 'post' which is no good for my purposes. If i dont pass the 's' everything works fine. Then i also tried by creating my own query like this:               $pageposts = $wpdb->get_results($wpdb->prepare("                 SELECT wp_posts.*                  FROM wp_posts                 WHERE 1=1 aND wp_posts.post_type IN  ('post', 'page', 'attachment')                 AND (wp_posts.post_status = 'publish')                  AND (((wp_posts.post_title LIKE %s) OR (wp_posts.post_content LIKE %s)))                 ORDER BY wp_posts.post_date DESC LIMIT 0, 8              ",array('%'.$string.'%')));                 $wpdb->show_errors();                 $wpdb->print_error();      But i just keep getting:

WordPress database error: []
                 SELECT option_value FROM wp_options WHERE option_name = 'aiosp_post_title_format' LIMIT 1

      There is any proper way to do what im trying? MY plugin consist on a simple form that should show ten titles => hiperlink for a given ajax search. Thanks All for the help!


Why Wordpress w/ Nginx Multisite Only Lets Admin Upload ZIP Plugins But Not Themes?

Wordpress 3.3 multisite / NginX. I can upload all the plugins I want in ZIP format but I cant upload a zipped theme and it can't be over 2megs in size. I cant find where these moronic rule are located. Is there a way to just use the SFTP? At this point I will take my chances with hackers, but life with ssh alone is just miserable hell. Please give me a hint as to how do i get a theme onto the server in a zip file from my pc. thank you.               user www-data;     worker_processes 4;     error_log  /var/log/nginx/nginx.log info;     pid /var/run/nginx.pid;          events {         worker_connections 1024;         # multi_accept on;     }          http {         sendfile on;         tcp_nopush on;         tcp_nodelay on;         server_tokens off;         include mime.types;         default_type  application/octet-stream;         index index.php index.htm index.html redirect.php;              #Gzip         gzip  on;         gzip_vary on;         gzip_proxied any;         gzip_comp_level 6;         gzip_buffers 16 8k;         gzip_http_version 1.1;         gzip_disable "MSIE [1-6].(?!.*SV1)";         gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;              #FastCGI         fastcgi_intercept_errors on;         fastcgi_ignore_client_abort on;         fastcgi_buffers 8 16k;         fastcgi_buffer_size 32k;         fastcgi_read_timeout 120;         fastcgi_index  index.php;              limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;              ##         # Virtual Host Configs         ##         include /etc/nginx/sites-enabled/*;


Get used terms by an author as array of strings

I am using `list_author_used_terms` function below to get the terms used by a specific author (terms of a custom taxonomy 'wossom' for a custom post type 'aya-bi-aya').               function list_author_used_terms($author_id){              $posts = get_posts( array('post_type' => 'aya-bi-aya', 'posts_per_page' => -1, 'author' => $author_id) );              $author_terms = array();              foreach ($posts as $p) {             $terms = wp_get_object_terms( $p->ID, 'wossom');                  foreach ($terms as $t) {                 $author_terms[] = (string)$t->name;             }              }         return array_unique($author_terms);     }      In `author.php` template file, I want to display the terms used by the given author. I do like this:               <?php     $user = get_user_by('login',get_query_var('author_name'));          $used_terms=list_author_used_terms($user->ID);          foreach ($used_terms as $ut) {     ?>     <a href="<?php echo get_term_link( $ut,"wossom"); ?>"><?php echo  $ut; ?>     <?php     }      ?>      When I `print_r` the `$used_terms`, I get the correct array, but the `foreach` loop is displaying nothing. I get the following error when I try to print seperately `get_term_link( $ut[0],"wossom");` :               Catchable fatal error: Object of class WP_Error could not be converted to string in C:\xampp\htdocs\blog\wp-content\themes\twentyten\author.php on line      I know it is a pure php problem but I am really tired trying to resolve it. Your help is appreciated.


How to save an integer as taxonomy term?

I've written a custom meta box such that taxonomy terms will always be integers (Unix timestamps), and I'd like to keep them as integers so I can sort these posts by their Unix Timestamp in the post_type's archive. The problem is that if an integer is passed to the `$term` parameter in `wp_set_object_terms()`, WordPress assumes it is the ID of the term you want to set, not the value. The only way to get the integer to set is to pass it as a string, which means the callback looks something like this:               // input data from the meta box     $year = 2013;     $month = "January";     $day = 12;     $date strval(strtotime($month . ' ' . $day . ' ' . $year)); // Convert the string to                                                                  // an integer and then back                                                                  // to a string!          wp_set_object_terms($post_id, $date, $taxonomy);      Which is fine, except now I have numbers stored as strings in the database when I wanted numbers. When I write the archive page I'll have to convert them back to numbers before running `date()` to display them. It'd be nice to save some of those keystrokes. Ideas?


Getting the current post number / make posts increment

I'm creating a site similar to http://thegreatdiscontent.com/ in that there's a bunch of posts on the site, and only one post gets shown per page. I want to add a counter that says something like: "Issue #210" at the top of each post, as they have done with http://alistapart.com/. This would increment with each new post. I've seen it out there to use `wp_query->current_post`, but that only works when you run through a loop. I'm only showing one post per page, so `wp_query` always returns 0. Any ideas how I can make my posts increment? Thanks!


Remove the Edit button in posts for permalinks on certain user roles? WP 3.3

I am using Wordpress 3.3.2 with the following plugin: - http://wordpress.org/extend/plugins/advanced-access-manager/ The plugin works perfectly but the author said there is currently no way to achieve this from the plugin, So I am wondering if there is either another plugin or any code modifications I can make to achieve them.   1. I created a custom user role Called "Member"   2. I applied certain permissions so the user can only sees options to make posts in the backend.   3. When making a post, the user does not see the "Edit" option to change the permalink.   4. The problem comes after the user submits the Post. Right below the post title field it shows the permalink and shows an "Edit" button which allows the user to change the permalink. Is there any way to remove either the "Edit" button so they can't edit the permalink, or removing that entire line altogether so the permalink doesn't show for them at all? Thank you in advance!


How to map a specific multi-site blog to a folder?

I have a multi-site set up in a sub folder called sites, like:               domain/sites/blog1     domain/sites/blog2      I would like a specific blog called `mag` to be accessible at `domain/mag` without revealing the real structure. Can it be done with URL rewrites?


Enqueue script only if page has an oembed

I have a script that adds some styles to OEmbedded content. At the moment its running on every page. I was wondering if anyone knew how to only enqueue the script if the page has an OEmbed on it. I have no code to show as google doesn't return anything on the topic


Show default content if custom WP_Query has no posts

I have a custom loop to show posts that meet a certain set of $args like this:               <?php $recent = new WP_Query( $orderargs );                  while($recent->have_posts()) : $recent->the_post();?>      This works great when the $orderargs bring up posts, but in some situations, there will be no posts, and I want to show some default content then. So what do I add to this / how do I restructure this so that if the query has no posts, display default content instead. Thank you, Ian


How to show a hierarchical terms list?

I have a hierarchical taxonomy called 'geographical locations'. It contains continents on a first level, and then the countries for each one. Example :               Europe     - Ireland     - Spain     - Sweden     Asia     - Laos     - Thailand     - Vietnam      etc. Using get_terms() I managed to output the full list of terms, but the continents get mixed up with the countries, in one big flat list. How can I output a hierarchical list like above?


Why is style.css not being enqueued?

I got a pretty basic theme and just found out my **style.css** file doesn't get loaded into the `<head>`. I already searched around but can't find out, why it's not loading. I inspected the `global $wp_styles` object already but couldn't find anything:               function style_test()      {          $wp_styles = new WP_Styles();              echo '<pre>';              // $wp_styles->enqueue == completely empty             print_r( $wp_styles->registered );          echo '</pre>';      }      add_action( 'wp_print_scripts', 'style_test', 0 );      Inside the object i also can't find my registered/enqueued stylesheets (they get loaded), so i guess i'm doing something wrong on inspecting this too. Any ideas? **Note:**   If i enqueue it manually, my **style.css** file get's loaded. Just the automatic loading doesn't work. Further more i can access the file with `get_theme_data( TEMPLATEPATH.'/style.css' );` without a problem.


Adding a content rating system

I run a multiple author site and the content is directed to various age groups. Instead of forcing the writer to manually note which age group the post is appropriate for, I want to add a content rating system with the following labels: > G — Suitable for all audiences > > PG — Possibly offensive, usually for audiences 13 and above > > R — Intended for adult audiences above 17 > > X — Even more mature than above What would be a good way to add such feature? Ideally, on the post page, there is an area with radioboxes where the writer can make their selection. There must be a way to echo the choice in the post template. Please provide code example if you choose to answer as my coding knowledge is limited.


Exclude custom function content from certain pages

I have added a small custom function to display a little author bio blurb at the bottom of each blog entry in my functions.php file inside the current theme that I am using. So far so good, it is working great but I noticed that this function is being applied to every page, for example it is showing up at the bottom of my "Contact" page. Here is an example of what I'm talking about to give a visualization of what is happening: ![enter image description here](http://i.stack.imgur.com/XehVg.jpg) Here is the code I am using for my function:               function get_author_bio ($content=''){              global $post;              $post_author_name=get_the_author_meta("display_name");         $post_author_description=get_the_author_meta("description");         $html.="
\n";         $html.="
About the Author: ".$post_author_name."
\n";         $html.= $post_author_description."\n";         $html.="
\n";         $html.="

\n";         $content .= $html;              return $content;     }          add_filter('the_content', 'get_author_bio');      How can I make this function only be applied to my home page for blog posts and not other pages on my site? Hopefully that is enough to help me, but I can update this questions to provide any other information that you may need. Thanks.


User management missing after migration to new host

I just moved my WordPress 3.9 site to a different host by making a mysql dump and restoring it on the new server and uploading the files over. Pretty standard. However, now I've lost the ability to manage users. On the old server, the left hand menu in the dashboard reads   * Appearance   * Plugins   * Users   * etc... But the new site reads,   * Appearance   * Plugins   * Profile   * etc... If I manually try to navigate to the `/wp-admin/users.php` page, I get the "Cheatin', huh?" message. I checked the `wp_usermeta` table and it is exactly the same on the new database as the old database. What happened? How do I restore the user management section.


Only show authors with posts

I thought the code below would work... but no dice. Something like "AND post_count > 0" function contributors() { global $wpdb;               $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users WHERE display_name <> 'admin' AND post_count > 0 ORDER BY display_name");          foreach ($authors as $author ) {          echo "
";     echo "ID);     echo "/\">";     echo get_avatar($author->ID, 12);     echo "";     echo "ID);     echo "/\">";     the_author_meta('display_name', $author->ID);     echo "";     echo "
";     }     }


wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); Getting thumb from wrong loop

I am using a plugin which sets the thumbail for your fb share image. The src is               <?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>      Which was working fine, but not it's showing thumb X on every page (rather then the currect thumbnail) I found the problem is I have a loop in the sidebar. Is there a way to make               <?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>      Get its attachment from the FIRST loop (as this code is at the bottom of the page) Or is there some other hack to make it get it from the first loop?


Get attachments by user

Is there a way to get attachments by user? I need a way to display all the images uploaded by a specific user. (I probably need the attachment IDs so that I can use `wp_get_attachment_url` to display them.)


Combining media queries with image sizes

I have a set of image sizes for WordPress that look like this:               add_image_size('1039', 1039, 697);     add_image_size('960', 960, 644);     add_image_size('800', 800, 537);     add_image_size('768', 768, 515);     add_image_size('640', 640, 429);     add_image_size('480', 480, 322);     add_image_size('320', 320, 215);     add_image_size('240', 240, 161);      So basically each defined image size has the name of it's own width (and I forced the '1039' to be the maximum allowed upload size), and these widths correspond to eight different media sizes, which I set using this:               div.container {width: 1039px;}     @media only screen and (min-width: 960px) and (max-width: 1038px) {div.container {width: 960px;}}     @media only screen and (min-width: 800px) and (max-width: 959px) {div.container {width: 800px;}}     @media only screen and (min-width: 768px) and (max-width: 799px) {div.container {width: 768px;}}     @media only screen and (min-width: 640px) and (max-width: 767px) {div.container {width: 640px;}}     @media only screen and (min-width: 480px) and (max-width: 639px) {div.container {width: 480px;}}     @media only screen and (min-width: 320px) and (max-width: 479px) {div.container {width: 320px;}}     @media only screen and (max-width: 319px) {div.container {width: 240px;}}      Now, I with this basic setting and any chosen image as background-image (with a size of 1039x697) it will just resize the `div.container` when a different media views it. However, I want to apply the image-sizes I added, so that it applies the correct image-size to fit the size of the media used (rather than load the huge image and resize it with CSS, it should load the image that is fitted for that resolution). At current I use this solution:               var body = jQuery('body').css("width");     var body = parseInt(body);     var image = jQuery('.container').css("background-image");     if (body >= 1039) {         var img_width = 1039;         var img_height = 697;     } else if (body >= 960 && body < 1039) {         var img_width = 960;         var img_height = 644;         var image = image.replace('.jpg")', '-'+img_width+'x'+img_height+'.jpg")');     } else if (body >= 800 && body <= 960) {         var img_width = 800;         var img_height = 537;         var image = image.replace('.jpg")', '-'+img_width+'x'+img_height+'.jpg")');     } else if (body >= 768 && body < 800) {         var img_width = 768;         var img_height = 515;         var image = image.replace('.jpg")', '-'+img_width+'x'+img_height+'.jpg")');     } else if (body >= 640 && body < 768) {         var img_width = 640;         var img_height = 429;         var image = image.replace('.jpg")', '-'+img_width+'x'+img_height+'.jpg")');     } else if (body >= 480 && body < 640) {         var img_width = 480;         var img_height = 322;         var image = image.replace('.jpg")', '-'+img_width+'x'+img_height+'.jpg")');     } else if (body >= 320 && body < 480) {         var img_width = 320;         var img_height = 215;         var image = image.replace('.jpg")', '-'+img_width+'x'+img_height+'.jpg")');     } else if (body >= 240 && body < 320) {         var img_width = 240;         var img_height = 161;         var image = image.replace('.jpg")', '-'+img_width+'x'+img_height+'.jpg")');     } else if (body < 240) {         var img_width = 240;         var img_height = 161;         var image = image.replace('.jpg")', '-'+img_width+'x'+img_height+'.jpg")');     }     jQuery('.container').css("background-image", image);      And this does in fact apply the correct image for the right media, but it is fully dependent on JavaScript being enabled. Is there some way I could achieve the same result using just CSS? Or perhaps there is a more elegant solution to this? If so I would love to hear how!


Is there a way to parse shortcodes in PHP?

Many plugins don't provide a documented way to access their functions from within PHP (e.g. when building a custom theme), but only shortcodes to insert in posts. Is there a standard way of executing shortcode from within PHP as if it were part of the content? Like so (this is made up):               $gallery_html = execute_shortcode("{gallery}");  //  this would return the HTML                                                        //  that the gallery plugin returns                                                      // in the context of the current post


How to create a word press user with hashedpassword

I have set of user data from another wordpress site and i want o create users for each of them in a another wordpress web site..,it is works fine with `wp_insert_user($user)` but problem is the password is hashed agin..,so i can't log with that login information,so how can i create user with hash password or stop creating hashed password


Hierarchical custom fields

I need to display press statements as a custom post type (" **statement** "). Associated with each **statement** post type is one or more Authors, which is currently implemented also as a custom post type (" **sauthor** "). Each Author is supposed to have a title/post/position, e.g. Vice President of ABC, which is currently implemented as **sauthor** 's custom field (" **position** "). I use a third party plugin called "Posts to Posts" to associate **sauthor** post types with **statement** post types. I have all of the above set up but I have a problem because the title/post/position of the Author(s) may change. Today, John Doe might be Vice President of ABC but next year, he might be Chief Janitor but I need the statements that he issued this year to still be displayed as "Vice President of ABC". Any ideas on how this could be done? One solution that I thought of is to do away with the **sauthor** to **statement** relationship and just have the Author and his/her title as custom fields. However, I'd like the data to be related. As in each Author custom field has a Position custom field as a child to show that the data is related. But could this be done?


How to edit a wordpress plugin without break its update process

I would like to add some additional features/functionality with already available WordPress plugin. Is it possible to carry over my customization while updating the plugin?


Use wordpress functions in another PHP file

I have created in my theme folder a PHP file named gallery.php. In this file I want to use WP_Query function, but I can't do this because it shows error. Is possible to do this? Thanks in advance!


Menu Limitations

I am coming here for advice mainly, because I am stuck on what to do next. Within my latest project, I am using Wordpress at the backbone, as a fully fledged CMS system. I have styled every single page, and the theme is looking great! One problem however: I am going to be posting _not so news-y posts as guides, information and video compilations_. I don't want to be adding hundreds of wordpress pages, I would much prefer have posts categorized and then display them in the navigation. Yep, that is the problem. I am just wondering if it is possible to, without much code, and without hacking away at core files, be able to have the navigation like this:   * Home   * Guides      * Posts in the Guides category displayed   * Videos      * Posts in the videos category displayed I wouldn't want this for every single category however. So how long would this take me, would it require much coding and is there already and existing plugin that does this? Thanks!


How can I make use of WP Mobile Detect conditions from within a plugin?

I recently downloaded the WP Mobile Detect plugin and integrated it to my theme (the original mobile detect library I include from the theme folder and the matching WP-functions I pasted directly into functions.php). Now I have one Social Share Plug-In I only want to appear when the site gets requested by desktop devices. So I tried modifying the core files of that plugin, wrapping the output function inside a condition of WP Mobile Detect like               if ( ! wpmd_is_phone() ) { // output my share buttons }      Unfortunately, this will return a `Call to undefined function`. How can I fix this?


How to set the default options on an existing plugin in a WP MU new user install

When a new user signs up in WP MU install I would like to set the default options for a plugin that I have installed in the super admin account. I've read through so many posts but have not found out how to do this.


Delete attachment with post

I'm trying to post a delete Link for a user so he can delete his own entries:               global $post;              if ( !current_user_can( 'delete_bkroadkill', $post->ID ) )             return;          $link = "ID, 'delete-post_' . $post->ID) . "'>".$link."";     echo $before . $link . $after;      How can I also delete the attachment of the post with this?


Getting error when using wp_insert_post()

When I use wp_insert_post() I get a white page that says "Are you sure you want to do this?". I get no PHP errors. I am using this outside of wordpress and have wp-load.php as well as /wp-admin/includes/file.php included. My code looks like this.               require_once $_SERVER['DOCUMENT_ROOT'] . "/wp-load.php";     require_once $_SERVER['DOCUMENT_ROOT'] . "/wp-admin/includes/file.php";     $imagePost = array(             'post_title' => "Test",             'post_content' => 'Content added later.',             'post_status' => 'publish',             'post_author' => 1,             'tags_input' => "'test'",             'post_category' => array(1),             'post_type' => 'post'     );          $postID = wp_insert_post($imagePost, true);      Any help is much appreciated.


Redirect from domain.com to subdomain.domain.com

Lets say my site domain is **main.com** and this is a wordpress site.   I have 4 subdomains,say, cat1,cat2,ca3,cat4.      Random posts and pages are displayed on main.com.They come into either of 4 categories ie cat1,cat2,ca3,cat4.   Now whenever I click on any page under category cat1 its URL should be displayed as **cat1.main.com/pagename**.   Similarly this should happen for other pages in every category.   Does this require any redirection or something else?   How can I achieve this?Please help me!   Thanks in advance!


What is the difference between using global $current_screen and get_current_screen()?

I have been looking at `get_current_screen();`. I have seen there is also a global `$current_screen;` that I could use. Here are two examples:               // Using function     function wpse_post_notice() {              $screen = get_current_screen();              // Only run in post/page creation and edit screens         if ( $screen->post_type === 'post' ) {             return 'This is a post';         }          }          // Using gloabl     function wpse_post_notice() {              global $current_screen;              // Only run in post/page creation and edit screens         if ( $current_screen->post_type === 'post' ) {             return 'This is a post';         }          }      Is one method considered better than the other? If so why?


Bizarre behavior of get_author_posts_url()

So I've been developing a site where I list a custom post type associated with a member in their profile page. It was all working fine until I imported about 150 users (at least that's when I noticed). Bear in mind I used the same email address for most of them, by using a filter               add_filter('pre_user_email', 'skip_email_exist');     function skip_email_exist($user_email){         define( 'WP_IMPORTING', 'SKIP_EMAIL_EXIST' );         return $user_email;     }      So to the point, I'm using               get_author_posts_url($coauthor->ID, $coauthor->user_nicename)       to retrieve the author URL, and it worked fine by outputting the URL with it's `nice_name` associated. Now it is outputting the URL with the id associated (`?author=$auth_ID`) Checking into the WordPress function thing get plain weird. The `$wp_rewrite->get_author_permastruct();` used in the function actually returns the URL with the nice_name associated. The problem resides in the empty check.               if ( empty($link) ) {      Commenting this if actually solves the whole deal, but I don't want to break WP updates. So my question is: What is going on and why this causing to return empty even though it's not and how can I fix it?


How do I create a sticky sidebar?

How do I give the three posts here different div classes? I'm working with twitter bootstrap and I'm trying to give the first post and the last one               <?php query_posts('category_name=Menucard'); ?>         <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
             <?php                 //echo post here                 the_content();             ?>
               <?php             $counter++;             if ($counter % 3 == 0) {             echo '

';             }         ?>


Remove menu items from admin page and limit capabilities

By default, I am allowing people to subscribe as contributors to my site which allows them certain actions. What I then want to do is remove Posts, Comments, Contact (ContactForm7) and Tools leaving them only options to add new Events (events plugin). I also want to be sure that even though these buttons are hidden, people cannot submit to these PostTypes if they knew how to. I am reading through the Professional WordPress plugins development book at the moment and it's a lot to take in so I'd like to do this just in my theme's functions page for now. Here's what I am trying according to the codex:                   add_action( 'admin_menu', 'jh_remove_menu_pages' );         function jh_remove_menu_pages() {             remove_menu_page('edit-comments.php');               remove_menu_page('tools.php');               remove_menu_page('edit.php');                remove_menu_page('wp-contact-form-7.php');           }      I've managed to do a find on this page to fins all the php files I need to hide but I am not sure about the ContactForm7 file. EDIT: Managed to find solution here to remove Contact Form 7 from Admin Menu According to the codex though, the code above does not remove the permissions for them to access the screens (posts, tools etc) directly and still submit if they knew how: _"Please be aware that this would not prevent a user from accessing these screens directly. Removing a menu does not replace the need to filter a user's permissions as appropriate."_ How would I remove the capabilities of all the above except the for Events and Profile? I'm reading through remove_cap in the codex, but I am concerned that I might inadvertently switch off posting Events if I remove the Posts capability? And lastly, how do I show only the related Events for the user who is logged in at the time? Many thanks.


Including Wordpress in RESTful API

I'm using a great little open-source product called Restler to provide a RESTful API to a Wordpress application. In order for this to work I want to be able to load the Wordpress environment within a set of PHP classes that Restler will run when a request comes in. The idea of loading the WP environment -- without the load of the UI elements -- is achieved by a script I have called AddWordpress.php:               <?php     error_reporting(E_ALL);     $site_name='yoursite';     $site_domain='www.yoursite.com';          /**     * Construct a fake $_SERVER global to get WordPress to load a specific site.     * This avoids alot of messing about with switch_to_blog() and all its pitfalls.     */     $_SERVER=array(     'HTTP_HOST'=>$site_domain,     'REQUEST_METHOD'=>'GET',     'REQUEST_URI'=>"/{$site_name}/",     'SERVER_NAME'=>$site_domain,     );          // Remove all our bespoke variables as they'll be in scope as globals and could affect WordPress     unset($site_name,$site_domain);          // Pretend that we're executing an AJAX process. This should help WordPress not load all of the things.     define('DOING_AJAX',true);          // Stop WordPress doing any of its normal output handling.     define('WP_USE_THEMES',false);          // turn on debugging     define('WP_DEBUG', true);     define('WP_DEBUG_LOG', true);          // Load WordPress - intentionally using an absolute URL due to issues with relative paths on the CLI.     include "/[path-to-root-www]/wp-load.php";      This works like a charm. I can now run scripts like this from the command line (`php test.php` where below script is test.php):               <?php     include "AddWordpress.php";     $terms = get_terms("actions");     echo json_encode($terms);      The problem I'm having is that if I want to include the "AddWordpress.php" not at the top of the file but inside of a method call -- I know this sounds like a terribly bad idea but there are good reasons for it ... please believe me -- then all shit breaks loose and my day turns badly very quickly. More specifically, the test file now looks like this:               <?php     function do_that_wordpress_thing() {         include "AddWordpress.php";     }     do_that_wordpress_thing();     $terms = get_terms("actions");     echo json_encode($terms);      and the errors I get are as follows:               Notice:  is_404 was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.) in /[path-to-www-root]/wp-includes/functions.php on line 2944     Notice:  is_home was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.) in /[path-to-www-root]/wp-includes/functions.php on line 2944     Notice:  is_search was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.) in /[path-to-www-root]/wp-includes/functions.php on line 2944     Notice:  is_archive was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.) in /[path-to-www-root]/wp-includes/functions.php on line 2944          ... etc ...      *** UPDATE *** On thing I picked up on PHP.net is this snippet on the include function def: > If the include occurs inside a function within the calling file, then all of > the code contained in the called file will behave as though it had been > defined inside that function. So, it will follow the variable scope of that > function. An exception to this rule are magic constants which are evaluated > by the parser before the include occurs. I think this must have an important role in why this isn't working but I'm still hopelessly lost. Can anyone explain why this could be happening? Any help would be VERY much appreciated.


Fatal Error wp-settings.php on line 119

Receiving this error message after a post update: > Warning: require(/home/thomwhite/wparch.com/wp-includes/post-template.php) > [function.require]: failed to open stream: Permission denied in > /home/thomwhite/wparch.com/wp-settings.php on line 119 > > Fatal error: require() [function.require]: Failed opening required > '/home/thomwhite/wparch.com/wp-includes/post-template.php' > (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in > /home/thomwhite/wparch.com/wp-settings.php on line 119 Any suggestions would be greatly appreciated!!!


How to inject a post within a loop

I'm trying to inject a post while the loop is running. This post will be injected on a condition, so `if(x == j){ //inject post here }` I see this would seem easy to do, but i have a posts_per_page argument in my query to use for paginating and i'm afraid that injecting a post would mess it up. Thanks in advance for any help!