Custom query with category exclusion and post-meta "whitelist"

I have two widgets, one shows **News** while the other shows everything except News (We'll call the second one **Blog** ). The blog portion is currently working correctly. The News posts are either categorized as `In the News` OR have the custom post meta `in-the-news`, set to 1. It's important to note that not all posts will have the custom post meta defined. The main problem I am facing is that I need to compare post meta based on whether the post is categorized one way or another. **I may need to do a custom database query for this behavior, at least for the News.** Is it possible to do a custom query and convert it to a standard WP_Query object? * * * ## What I have tried Query for **News**. **Problem:** Only shows posts within category 75 that have `in-the-news = 1`. **Desired result:** Show all posts from category 75 regardless of the value of `in-the-news`, and any additional posts from outside the category which have `in-the-news = 1`               query_posts(array(       'ignore_sticky_posts' => true,       'posts_per_page' => 3,       'cat' => "75", // Only posts within category 75 (News)            // Including posts tagged to show "In the News"       'meta_query' => array(         'relation' => 'OR',         array(           'key' => 'in-the-news',           'value' => '1',           'compare' => '=',         ),         array(            'key' => 'in-the-news',           'compare' => 'NOT EXISTS',           'value' => '',         ),       )     ));      Here is the query for the **Blog** : This query appears to be working correctly, showing all posts outside of category 75, and hiding posts with `in-the-news = 1`.               query_posts(array(       'ignore_sticky_posts' => true,       'posts_per_page' => 3,       'cat' => "-75", // All posts EXCLUDING those in category 75 (News)            'meta_query' => array(         'relation' => 'OR',         array(           'key' => 'in-the-news',           'value' => '0',           'compare' => '=',         ),         array(            'key' => 'in-the-news',           'compare' => 'NOT EXISTS',           'value' => '',         ),       )     ));      * * * ## Solution Thanks to `s_ha_dum` for the amazing examples, here is the final query I am using. The logic here is that we do a custom MySQL query for an array of post IDs, then do a standard WP_Query using the returned IDs. **Note:** The logic here was a bit more complicated than the original post. Basically, we originally had "News" and "Blog". But now we also have "Risk". Also, the `in-the-news` post meta was changed to `show-in-blog` as we reverse the functionality. I can't expect anyone else to ever understand the reasoning for this in the first place, as even I think it is ridiculous (But the client wants it, so be it!) Here is my query, for the "Blog" widget. Slight variations are made for the "News" area. I'm not sure if the query could be cleaned up. I'm also not sure if it's a bad idea to perform so many SELECTs within the same query.               global $wpdb;          $query = // Splitting the SQL query to it's own code block for syntax highlighting!      * * *                 SELECT `ID`       FROM {$wpdb->posts} posts       WHERE (              /* Exclude posts in News (94)             Ignore show-in-blog option for News here,             as News is displayed on the same page */         94 NOT IN (            SELECT `term_taxonomy_id`            FROM {$wpdb->term_relationships}           WHERE `object_id` = posts.`ID`         )              AND              /* Exclude posts in Risk (96),             But show Risk posts that have the postmeta "show-in-blog" */         (                96 NOT IN (              SELECT `term_taxonomy_id`              FROM {$wpdb->term_relationships}             WHERE `object_id` = posts.`ID`           )           OR           (             96 IN (                SELECT `term_taxonomy_id`                FROM {$wpdb->term_relationships}               WHERE `object_id` = posts.`ID`             )             AND             1 IN (               SELECT `meta_value`                FROM {$wpdb->postmeta}               WHERE                `meta_key` = 'show-in-blog'               AND `post_id` = posts.`ID`             )           ) /* OR */              ) /* AND */            ) /* WHERE */            ORDER BY `post_date` DESC;      * * *               $args = array(       // Only include IDs returned by the above query       'post__in' => $wpdb->get_col( $query ),       'posts_per_page' => 10,     );          $wp_query = new WP_Query( $args );          get_template_part('loop', 'frontpage');


best way to run a php script away from the template?

I'm looking for some inspiration on the best way to run a php script away from the template. I know that the wordpress core files won't have loaded, so I am wondering what workgflow you follow when doing this? cheers


How to: Simple Nested Shortcode

Im trying to wrap a shortcode inside of a "user loggeed in" shortcode. Here are the two shortcodes and my setup in WYSIWYG               function wpfc_logged_in( $atts, $content = null ) {         if (is_user_logged_in() )           {             return do_shortcode($content);           }     }          add_shortcode('loggedin', 'wpfc_logged_in');               function info_box( $atts, $content = null  ) {             extract( shortcode_atts( array(             'type' => 'tip',             'icon' => ''         ), $atts ) );           $return = '

'.$content.'

';         return $return;      }     add_shortcode('info_box', 'info_box');      WYSIWYG:               [loggedin]     [ info_box type='setting' ]content text[ /info_box]     [/loggedin]


open graph image being overwritten by gravatar logo?

example page; http://www.c-art.org.uk/2011/07/01/jenny-abbot/ some reason the gravatar image is overwriting the posts featured image thumb (100x100). Nnot sure how its doing it! How can i get rid of it?               <meta property="og:title" content="Jenny Abbot" />     <meta property="og:description" content="C-Art — Cumbria Artist Open Studios, Jenny Abbot Artist Index PaintingC-Art"/>     <meta property="og:url" content="http://c-art.modernactivity.co.uk/?p=1254"/>     <meta property="og:image" content="http://www.c-art.org.uk/wp-content/uploads/Summer-at-Sea-Wood-100mm-100x100.jpg"/>     <meta property="og:type" content="article"/>     <meta property="og:site_name" content="C-Art"/>      best, dc.


how to show images without passing it to timthumb.php file for resizing

currently I m showing post image and it's exceprt on my index page of website. Beacuse of this site is slow downs as each image is passed to timthumb.php file. I want to change in code so that image is displayed direct without passing to timthumb.php file for resizing. Is there any way to achieve this?? Thanks in advance..


Making a parent directory writable by the server

Uploading an image to add to a page, I got a message saying: Unable to create directory... Is its parent directory writable by the server? Assuming the issue is that the parent directory needs to be made writable by the server, how do I make the parent directory writable by the server? Thanks, Richard


How can I abstract code out of a template by using functions.php

I'm creating a template, and one of the files is getting overloaded with pig- ugly mixed html and php. At first I thought that maybe I should cut out chunks of the code, and call them using include(). Then I thought - maybe there is a wordpress way to do things. Perhaps I should abstract out my logic from the templates, by putting the custom loop in functions.php, and then calling it somehow from the template. How do I do this?


Can a thumbnail of an animated gif be animated?

I have an animated gif I want to show in two places, having two different sizes. I am creating two sizes in my functions.php, using               add_image_size( 'small-feature', 500, 300 );     add_image_size( 'gallery-thumb', 120, 9999 );      If the uploaded file is 500 x 300 px, it will keep the animation, as it no resizing happens. If the image is to be resized, the animation is lost. Is there a way I can resize these images and still keep the animation in the original .gif file?


bulk post_content update

I need to replace all post_content in a particular tag/category to the desired one i have. is their a plugin to accomplish it or is their a query to finish this. Iam sick of doing this manually, is their a way to accomplish it.


Widget editor not displaying in Dashboard

I'm not sure if this is because of the new 3.9 update, because I haven't had to mess with any widgets in a while, but my active widgets won't display in the editor anymore. I've uploaded a screen shot of how it looks here: http://i.imgur.com/Ctbzo3S.png This may or may not be related, but my Screen Options drop-down does nothing when I click on it and neither does anything else within that widget window. Here are the errors I'm getting: >   * PHP Fatal error: Call to undefined function select_input() >   * PHP Notice: Trying to get property of non-object PHP Strict Standards: > Only variables should be passed by reference >   * PHP Notice: has_cap was called with an argument that is **deprecated** > since version 2.0! >   * PHP Deprecated: Assigning the return value of new by reference is > deprecated >   * PHP Notice: get_settings is **deprecated** since version 2.1! >


Is there a WP Way of getting a filehandle?

I'm using an external CSV reading library that takes a filehandle (resource) as an argument. I'm using wp_handle_upload() to actually process and store the file in the Uploads directory, but that returns the file path, not a resource. Is `$filehandle = fopen( $file['file'], 'r' )` acceptable here, or is there a better WP alternative? I don't see anything that fits the bill in `file.php`, or anywhere else I've looked.


I am trying to make a page in the admin section similar to the appearance of the Profile page for users

I am working on a plugin and would like to know the correct way I go about creating a page that will look like the users page (image attached at the buttom) The fields will be different and will add data(the data is unrelated to user information) to a new table created by the plugin . So it does not seem like the Settings API will help me. I am strictly talking about appearance. Should I just use the css built in wordpress or is there some sort of function that will help me create all the fields?![enter image description here](http://i.stack.imgur.com/t7Fo7.png)


Which Membership Plugins Allow Registered Users To Bookmark Posts?

I'm having some trouble finding plugins (free & premium ok) that would allow a registered member to essentially bookmark any post of interest to them while searching, and then revisit that bookmark through their user profile whenever their logged back in. The only plugin that I'm aware of that has a related feature is the premium Wishlist Member plugin. Specifically, what are other membership plugins that can achieve this? Thank you in advance!


How to insert an array of terms using wp_insert_term?

WP provides a function to insert terms:               <?php wp_insert_term( $term, $taxonomy, $args = array() ); ?>       I have 60 $terms, each has its own $args, I want to prepare the 60 terms as an array, then, insert them at once. Is this posible? How?


wp_mail function timing out

I have the following function. This is part of a membership-based site. When a post of the type "message" is moved to Publish status, it should send an email to all users who belong (custom user meta) to the district(s) that are checked (taxonomy) when the post is drafted. If I send to a small group, it seems to work. If I send to all the districts, it hangs and no messages appear to go out. I tried limiting it into chunks (25) to ease the pain, but does not help. Any thoughts besides telling the client to only send to one group at a time?               add_action('publish_messages', 'messages_notify', 10, 3);     function messages_notify() {         global $post;         // if post already published, abort         if($post->post_status == 'publish') {             return;         }         // get districts ticked, else abort         $districts = get_the_terms($post->ID, 'message_district');         if(empty($districts)) return;              // query members who belong to one of the districts ticked         $the_districts = array();         $district_args = array('relation' => 'OR' );         foreach($districts as $district){             $the_districts[] = $district->name;             if ($district->name == 'Northeast') {                 $district_args[] = array('key' => 'whprms_district_ne', 'value' => 1);             }             if ($district->name == 'North Central') {                 $district_args[] = array('key' => 'whprms_district_nc', 'value' => 1);             }             if ($district->name == 'Southeast') {                 $district_args[] = array('key' => 'whprms_district_se', 'value' => 1);             }             if ($district->name == 'Southwest') {                 $district_args[] = array('key' => 'whprms_district_sw', 'value' => 1);             }             if ($district->name == 'West') {                 $district_args[] = array('key' => 'whprms_district_w', 'value' => 1);             }         }         $district_members = get_users(                  array(                 'meta_query' => $district_args,                 )         );              $attachment_args = array('post_type' => 'attachment', 'orderby' => 'date', 'order' => 'ASC', 'numberposts' => -1, 'post_status' => NULL, 'post_parent' =>$post->ID);         $attachments = get_posts($attachment_args);         if ($attachments) {             $att_array = array();             foreach ($attachments as $attachment) {                 $att_array[] = get_the_title($attachment->ID);             }         }              // message only users with desired role(s)         $bcc = array();         foreach($district_members as $district_member) {             if(user_can($district_member->ID, 'board_members') || user_can($district_member->ID, 'members')) {                 $bcc[] = $district_member->user_email;             }         }              $subject = 'WHPRMS Message: '.$post->post_title;         $message = 'New message posted by ';         if(user_can($post->post_author, 'administrator')) {             $message .= get_the_author_meta('user_nicename', $post->post_author)."\n\r";         }         else {             $message .= get_the_author_meta('first_name', $post->post_author).' '.get_the_author_meta('last_name', $post->post_author)."\n\r";          }              $message .= 'Excerpt: '.stripslashes(substr($post->post_content, 0, 240)).'...'."\n\r";         $message .= 'Link: '.get_permalink($post->ID)."\n\r";              $message .= 'District(s): '.implode(', ', $the_districts)."\n\r";         if (!empty($att_array)) {             $message .= 'Attachment(s): '.implode(', ', $att_array)."\n\r";         }              $message .= 'You are receiving this message because you belong to one of the districts mentioned above.';              $chunked_bcc = array_chunk($bcc, 25);              foreach($chunked_bcc as $bcc_chunk){             $headers = array();             $headers['Bcc'] = 'BCC: '.implode(', ', $bcc_chunk);             wp_mail('no-reply@whprms.org', $subject, $message, $headers);         }          }


Use the_content outside the loop

I was trying to get first 100 words of the content in the header, and I use the following snippet to get the first 100 words in the loop, but is it possible to get the value outside the loop:               $cstring = get_the_content( '' );     $newcString = substr( $cstring, 0, 100 );     echo'<p>' . $newcString . '</p>';


Change the Permalink for wordpress attachment

My attachments are currently rewritten from   `http://localhost/?attachment_id=3` to   `http://localhost/images/image-title` using @Bainternet's answer here.                $new_rules['images/(\d*)$'] = 'index.php?attachment_id=$matches[1]';        However, wordpress still refers to the link as the default `http://localhost/?attachment_id=3`. Wordpress functions such as the_permalink, get_attachment_url, get_attachment_image_src, etc. all use the default format of `http://localhost/?attachment_id=3`. I am able to access the image as intended if I manually type in the rewritten format `http://localhost/images/image-title`. How can I get wordpress to use my custom rewrite for the permalink especially on the admin page? **EDIT:** reworded question for specificity and correctness:   How do I override `the_permalink` to use the format `/images/image-title` instead of `/?attachment_id=ID`?   I can get image-title using `$post->post_title`. **EDIT #2:**   For anyone reading this question in the future, I found it best to use `$post->post_name` for the link to insure uniqueness.   `/images/post_title`


Define custom Page Template without its own .php file

Is there any way of defining a Page Template from some function/filter/hook, without having any .php file containing the comment at the top of the page to declare the Template Name? * * * For example, instead of doing this: ### some-custom-page-template.php               /**     * Template Name: Some Custom Page Template     */      ### another-custom-page-template.php               /**     * Template Name: Another Custom Page Template     */      I wonder if I can do something like: ### functions.php               wp_some_function_to_define_templates( 'Some Custom Page Template' );     wp_some_function_to_define_templates( 'Another Custom Page Template' );      * * * **_EDIT_** : I'm writing a _complex_ and kind of _experimental_ WP theme - It is as Object-Oriented as WP lets it to be, I have Controller classes to decide what to display in each page, DAO classes to retrieve data from DB, Twig templates to generate the views and so on... I've spreaded the code so much, that my Page Templates have become just a line of code where I call some Controller and let it do the job, to finally render a Twig template. So I decided to move that call to the Controller, to inside the `template_include` filter, so that I don't even need to put any code in the Page Templates... I might get rid of Page Templates, but I still need them to _group_ pages somehow, to set some Advanced Custom Fields groups for them, etc... So I ended up with about 15 PHP files that contain only a comment at the top with some Template Name, which is exactly what I'd like to avoid by defining those templates from some function... Am I trying to _reinvent the wheel_? Maybe in some sense, but I think it's becoming a really _cool_ theme, very maintenable and modifiable...


Setting posts per page in query_posts

Bear with me here.. The default posts per page in the admin area is 10. During some testing I wanted to change the posts per page for my custom post archive to 2 (in WP 3.1). The problem is that I only have 4 posts, so there should be 2 pages with 2 posts on each, but because the default is at 10, going to /page/2 returns error-404 (assuming because with 10 posts per page there wouldn't be a second page) The only way to get around this was to set the default in the admin area to 1, but it's not really ideal as i now have to do a custom query_post for all post type archives to set the posts per page. Does anyone have a better way to do this, or any ideas? Thanks. archive-project.php:               <?php get_header(); ?>              <?php             global $wp_query;             query_posts(array_merge($wp_query->query, array(                 'paged'          => get_query_var('paged'),                 'posts_per_page' => 2             )));         ?>
<?php _e('Previous work', 'fullycharged'); ?>
              <?php if (have_posts()): while(have_posts()): the_post();?>             <a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>" <?php post_class('launch col col-' . $i); ?>>                 <?php the_title(); ?>                 <?php the_content(); ?>                      <?php endwhile; endif; ?>              <?php if ($wp_query->max_num_pages > 1): ?>

<?php next_posts_link( __( '← Older posts', 'twentyten' ) ); ?>

<?php previous_posts_link( __( 'Newer posts →', 'twentyten' ) ); ?>

         <?php endif; ?>          <?php get_footer(); ?>      register post type:               register_post_type('project', array(         'capability_type' => 'post',         'has_archive' => true,         'hierarchical' => false,         'labels' => array(             'name' => __('Projects', 'fullycharged'),             'singular_name' => __('Project', 'fullycharged'),             'all_items' => __('All Projects', 'fullycharged'),             'add_new_item' => __('Add New Project', 'fullycharged'),             'edit_item' => __('Edit Project', 'fullycharged'),             'update_item' => __('Update Project', 'fullycharged')         ),         'menu_icon' => get_stylesheet_directory_uri() . '/images/monitor-off.png',         'menu_position' => 5,         'public' => true,         'publicly_queryable' => true,         'exclude_from_search' => false,         'rewrite'  => array('slug' => 'work', 'with_front' => false),         'supports' => array('title', 'editor', 'thumbnail', 'custom-fields')     ));


I'm receiving this error: [27-Jun-2012 18:22:39 UTC] PHP Fatal error: Call to undefined function plugin_basename() in /XXXX/public_html/wp- content/plugins/price-update/price-update.php on line 68:                           //We set the plugin basename here, could manually set it, but this is for demonstration purposes                 $this->plugin_basename = plugin_basename(__FILE__);      in this block of code:               class PriceUpdate extends mtekk_admin     {             protected $version = '0.0.1';             protected $full_name = 'Price Update';             protected $short_name = 'Price Update';             protected $access_level = 'manage_options';             protected $identifier = 'pr_upate';             protected $unique_prefix = 'prud';             protected $plugin_basename = 'price-update/price-update.php';             protected $opt = array();             /**              * __construct()              *              * Class default constructor              */             function __construct()             {                     //We set the plugin basename here, could manually set it, but this is for demonstration purposes                     $this->plugin_basename = plugin_basename(__FILE__);                     register_deactivation_hook(__FILE__, array($this, 'deactivate'));                     add_action($this->unique_prefix . '_cron_hook', array($this,'cron_handle'));                     //Register some of our custom taxonomies                     add_action('init', array($this, 'wp_init'), 0);                     add_action('wp_footer', array($this, 'footer'));                     //We're going to make sure we load the parent's constructor                     parent::__construct();             }      However, its defined above:                       protected $plugin_basename = 'price-update/price-update.php';      any ideas?


Saving custom fields to a custom taxonomy

I am trying to create a custom field for a custom taxonomy. update_post_meta works great with posts. Taxonomies are not posts so this won't work.               <?php update_post_meta($post_id, $meta_key, $meta_value, $prev_value); ?>       How would I save a custom field within a custom taxonomy? Other solutions include the options_table (bad!) or creating a custom table (cumbersome). Is there another, canned solution or function to help with this?


How to filter get_avatar?

I want to use local avatar system for my wp website , I want to filter the `get_avatar()` function so it will return the avatar from my server instead of the default gavatar . I have the following code :               class local_avatar{                  function __construct(){                 add_filter('get_avatar',array($this,'get_avatar'));             }                  public function get_avatar($avatar , $id_or_email , $size = '96'  , $default , $alt = false){                      global $wpdb;                 $upload = wp_upload_dir();                      if(is_numeric($id_or_email)){                     // the user id                     $image = get_user_meta($id_or_email,'_ahaali_avatar',true);                     if($image){                         $image_path = $upload['baseurl'].'/avatar/'.$image;                         $ahaali_avatar = '';                     }else{                         $image_path = 'http://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s='.$size;                         $ahaali_avatar = '';                     }                 }elseif(is_string($id_or_email)){                     // the user email                     $user_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM wp_users WHERE user_email = %s",                     $id_or_email));                     $image = get_user_meta($user_id,'_ahaali_avatar',true);                     if($image){                         $image_path = $upload['baseurl'].'/avatar/'.$image;                         $ahaali_avatar = '';                     }else{                         $image_path = 'http://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s='.$size;                         $ahaali_avatar = '';                     }                 }                 return $ahaali_avatar;             }              }      And it returns the following errors : > Warning: Missing argument 2 for local_avatar::get_avatar() in > /home/subhi/public_html/work/example.com/wp- > content/plugins/ahaali_avatar/core.php on line 40 > > Warning: Missing argument 4 for local_avatar::get_avatar() in > /home/subhi/public_html/work/example.com/wp- > content/plugins/ahaali_avatar/core.php on line 40 How can I solve this?


Display a random customposttype2 excerpt in single-custompostype1.php that shares same taxonomy

OK - Looked everywhere for this one. **Details:** Custom Post Type #1 = 'product' > registered taxonomy 'productranges' Custom Post Type #2 = 'testimonial' > registered taxonomy 'testimonials' Both CPTs share categories 'Complete Food' , 'Treats', etc.. for example **Question:** How can I display a random post excerpt of the same shared-category from a 'Testimonial' post into 'Product' post? In a sense linking the Testimoinals to the Products. I've used the following but it only shows a random post from all the categories, I need it to output from the current-shared category being viewed:               <?php     $posts = get_posts('post_type=testimonial&issue=$issueid&post_status=publish&numberposts=1&orderby=rand');          foreach ($posts as $post) : setup_postdata($post); ?>
<?php the_title(); ?>
     <?php the_excerpt('
'); ?>read more...           <?php endforeach; ?>     <?php          //Reset Query     wp_reset_query();?>      Cheers if you can help!


next_posts_link returns same content of 1st page

Pagination seems to work fine... I have 21 posts... and it will go to 3 pages... however... every page shows 10 posts and the same content as the first page....               <?php     $temp = $wp_query;     $wp_query= null;          $args = array(         'post_type' => 'a-reports',         'post_status' => 'publish'     );     $wp_query = new WP_Query( $args );     if ( $wp_query-> have_posts() )     {     while ($wp_query->have_posts()) : $wp_query->the_post();      ?>     <a target="blank" href="<?php the_permalink(); ?>">Report     <?php     endwhile;          <?php next_posts_link('Older Entries »');           //clear again     $wp_query = null;     //reset     $wp_query = $temp;     ?>


User Registration Allow Same Email

Have researched this problem and can't find a solution for Wordpress 3.7.1 running as a single site. Problem: Allow a user to register on the site and ignore the error WP throws back if email is already registered - "This email is already registered, please choose another one." Have tried writing my own plugin, something in the way of               if($errors['field'.$field->id] == 'This email is already registered, please choose another one.')     unset($errors['field'.$field->id]);      Any help on this would be greatly appreciated. PS. i) I know its not ideal to allow same email for registration but can't see another solution to allow same family members to register under different usernames but same family email. ii) The answer on a previous question did not work on single site, using the code               add_filter('pre_user_email', 'skip_email_exist');      this is why I had to ask this question for single site solution.


Search filter triggered & sort by custom post type

I am using a plugin (Relevanssi) and a custom function to sort the search results by custom post types (see below). _This is working great_.               add_filter('relevanssi_hits_filter', 'separate_result_types');     function separate_result_types($hits) {         $types = array();              // Split the post types in array $types         if (!empty($hits)) {             foreach ($hits[0] as $hit) {                 if (!is_array($types[$hit->post_type])) $types[$hit->post_type] = array();                                         array_push($types[$hit->post_type], $hit);             }         }              // Merge back to $hits in the desired order         $hits[0] = array_merge((array)$types['cats'], (array)$types['dogs'], (array)$types['horses']);        return $hits;          }      The problem arises when I want to display search results on a per-type basis. For example, when on the "Search Pets" page (which is a page template, search- pets.php) I want to display only search results for the above CPTs. When on the "Blog" page (standard WP posts), I want to display only blog posts, and if on a non custom CPT page, display page results. I thought that by adding an if/else statement (see below) that would work.               add_filter('relevanssi_hits_filter', 'separate_result_types');     function separate_result_types($hits) {         $types = array();              // Split the post types in array $types         if (!empty($hits)) {             foreach ($hits[0] as $hit) {                 if (!is_array($types[$hit->post_type])) $types[$hit->post_type] = array();                                         array_push($types[$hit->post_type], $hit);             }         }              // If post type = dogs, cats, horses         if (in_array( get_post_type(), array('dogs','cats','horses'))){         // Merge back to $hits in the desired order         $hits[0] = array_merge((array)$types['dogs'], (array)$types['cats'], (array)$types['horses']);        // return $hits;              } else {               // If post type = posts, page         if (in_array( get_post_type(), array('post','page'))){         // Merge back to $hits in the desired order         $hits[0] = array_merge((array)$types['post'], (array)$types['page']);         //return $hits;              }}         return $hits;     }      But it only seems to return the top filter results. Any idea where I'm going wrong, or if my logic will even work? Very much a PHP noob. Thanks! Ramsey


How do I setup htaccess for 301 redirects, post Joomla to Wordpress migration?

I've almost completed the tedious task of migrating a relatively complex Joomla site over to Wordpress. The (more or less) final stage I am wishing to figure out is the 301 redirections. I've spent the past few hours researching this topic, but I've not found any tips specific to my situation (particular the sub-directory structure). I'd greatly appreciate some hand-holding. I don't wish to mess this up because I realise it could impact the hundreds of incoming links from search engines. **Here's the background information:**   * Joomla was installed in `www.domain.com/site/`   * Wordpress has been installed in `domain.com/wordpress/`   * All Joomla articles were migrated to Wordpress installation, and post IDs were maintained.   * Joomla URI permalink structure for articles is: `www.domain.com/site/YYYYMMDD###/...` **e.g.** `www.domain.com/site/20110623398/articles/category-slug/article- slug.html` The ### is the unique ID of the article on Joomla (aka post ID).   * The posts in Wordpress have the same unique ID. Thus `www.domain.com/site/20110623398/articles/category-slug/article-slug.html` can be redirected to `domain.com/?p=398`   * There are a few other URI structures I'll need to handle. But I will address that once I have the redirection of the articles figured out. **MY QUESTION (IN PARTS)**   1. How do I set up the .htaccess file so that all incoming links to joomla articles have the unique ID extracted and then redirect to `/?p=UID` (as a 301 redirect)?   2. How do I do this in such a way that the site will always use or display `domain.com/` as the home directory (with and without the www), whilst keeping the site located in `/wordpress` (or in `/site`, if that works better for the redirects - which I suspect it will). I don't, however, want the site to ever load up and show a `/wordpress/post- name-etc/` type URI (or `/site/post-name-etc/` URI). Meaning I want the `/wordpress/` or `/site/` part to always be removed from the end user point of view (including search engines). I believe the .htaccess file is also used for this.   3. Along with many other sites and posts, I have read the info related to Giving Wordpress It's Own Directory on the WordPress Codex. Point #4 on that article says, "Copy (NOT MOVE!) the index.php and .htaccess files from the WordPress directory into the root directory of your site (Blog address).", but I have a .htaccess file in the root already, and it has lots of code in it. Is it okay to just copy the index.php and not the WP htaccess file? * * * Points **(2)** , combined with **(1)** , is where I came a bit unstuck. Getting all the articles on `domain.com/site/` to redirect to `domain.com/`, and for the correct page to come in from `domain.com/wordpress` without displaying the `/wordpress/` part. As mentioned above, I suspect it may be best if I move the wordpress site to `domain.com/site` (and change it's configuration file home directory settings accordingly).


WP_Query not retrieving by random order under parent

I currently have TWO subpages under parent page ID 43. Client testimonials.. Anyway. I have the random order thing in the query $args but the order never changes. What could I be missing?               wp_reset_query();     $args=array(       'post_parent' => 43,       'post_type' => 'page',       'post_status' => 'publish',       'posts_per_page' => 2,        'orderby'=>'rand'     );     $my_query = new WP_Query($args);     if( $my_query->have_posts() ) {         while ($my_query->have_posts()) : $my_query->the_post();         ?>
<? echo get_post_meta($post->ID,'subtitle', true);?>

<? echo get_the_excerpt(); ?>
         <?         endwhile;     }     wp_reset_query();  // Restore global post data stomped by the_post().


allow photo/video in comments

I have a request to allow subscribers to upload/embed photos or video in comments. Is anyone aware of an existing plugin to handle this, I couldn't find anything suitable. I found examples of code to change the tags that are stripped from comments which would allow embedding, but I'm not sure that really fits the bill and would require change to a core file.


When to use the Filesystem API? Should I use it at all?

I'm wondering when it is recommended to use the Filesystem API, and whether it's useful at all? WordPress seems a little inconsistent when it comes to Filesystem API usage, it uses the API only in a few places when uploading and unpacking files, and that doesn't make much sense to me, I mean, where's to point in using it at all when there are a lot of other situations where the PHP filesystem functions are used for direct access? Uploading packages would work even when there are ownership "problems", however I'm pretty sure that these "problems" won't go away 5 minutes later when I'm utilizing any of the functions that are using for example fwrite directly. So why should I as a plugin/theme developer care about it anyways when half of the WordPress functions I'm using does not rely on the Filesystem API, my plugin/theme wouldn't work correctly anyways, wouldn't it?


How to parse a custom url (within WP site) and obtain params passed to that URL

In my WP site-- eg. http://www.mydomain.com-- a request has to be passed to a custom URL-- http://www.mydomain.com/custompage?param1=abc&param2=def Now, I wish to obtain the parameters passed to that URL from a function in functions.php of that theme. This function is executed when the above (example) URL is loaded... How do I do this? For above eg. I wish to obtain first parameter=abc and second parameter=def-- I already know that the parameters are named param1 and param2.


Save custom post type not working

I'm having a strange problem with same code not working on localhost vs production server. The code is simple and I am trying to save a custom post type, but none of the data in my metaboxes are saved. I have some `echo` statements in my `save_custom_type` for debugging to see how the data looks like. Not even those print statements are echoed when I press "Publish" on production environment. The custom post type is created in my theme, I hook into the action 'init'. Code for creation and first lines up to the first echo statement in the save method.               function create_omgang_post_type() {         $labels = array(                 'name' => 'Omgång',                 'add_new' => 'Lägg till ny omgång',                 'add_new_item' => 'Lägg till ny omgång',                 'not_found' => 'Inga omgångar inlagda'                 );         $args = array(                 'description' => 'En omgång för denna säsong',                 'public' => true,                 'hierarchical' => true,                 'show_in_menu' => false,                 'show_in_admin_bar' => true,                 'label'=>'Omgångar',                 'labels' => $labels,                 'supports' => array(                         'title', 'page-attributes')                  );         register_post_type('omgang', $args);      }     add_action('init', 'create_omgang_post_type');           /*-------------------------------------*/          function save_custom_post_omgang($post_id) {         $slug = 'omgang';         $post = get_post($post_id);               if($post->post_type == "omgang" ) {             if(! $_POST)                 return;                  if(!wp_post_revision_title($post_id)) {                  $lag = get_all_lag();                       $data = array();                 foreach($_POST as $key => $value) {                     //key#type                     $explodedID = explode('#', $key);                          if($explodedID[0] != $key) {                         $key = $explodedID[0];                         $type = $explodedID[1];                              $data[$key][$type] = $value;                     }                 }                 print_r($data); //this line is not even printed in PRD             }         }     }


Remove "posts" from admin but show a custom post

After checking out: http://codex.wordpress.org/Function_Reference/remove_menu_page,   I successfully use the following code to hide some stuff from the menu:               add_action( 'admin_menu', 'my_remove_menu_pages' );          function my_remove_menu_pages() {         remove_menu_page('link-manager.php');         remove_menu_page('tools.php');         remove_menu_page('users.php');         remove_menu_page('edit-comments.php');       }      However both the "posts page" and a custom post types page seems to run on `/wp-admin/edit.php`. So I'm looking for a way to _hide_ the posts menubar but still show the menu for a custom post type I've added.


woocommerce add variable after price

I am kind of new to woocommerce but finding this plugin amazing so far.. I am trying to figure out how to add a variable right after the price which will give the buyer additional information about how many credits he purchased (using stars) There is an option of adding attributes and showing them as variables but it all shows underneath in the "Additional information" tab and I want that to appear right after the price the following screenshot better describe what I am looking for: ![enter image description here](http://i.stack.imgur.com/nsb9Q.png) * **This "stars" additional information must be added to the checkout page as well as sent to the customer as additional important information** Thanks in advance   Gil


Get all children titles of a page as a link to them

I want to pull all the children titles of certain page and put them as a link. This is what i got so far:               $my_wp_query = new WP_Query();                         $all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));                              // Get the page as an Object                         $oferta =  get_page_by_title('Oferta');                              // Filter through all pages and find Portfolio's children                         $all_children = get_page_children( $oferta->ID, $all_wp_pages );                              echo '<pre>' . print_r( $_children, true ) . '</pre>';      Now, how can I get page titles from $all_children ?


How to get new post URL?

I'm wondering... how can I get the new post URL in my theme? Is there a built- in function for this? So, it should return something like http://example.com/wp-admin/post- new.php?post_type=post. Connor.


Logging into multiple Non-Wordpress sites through one Wordpress login

I'm trying to connect my partner sites with my main site. Is it possible for me to be able to log into my partner sites (they aren't running on WordPress) AND my WordPress site simultaneously with one login on my WordPress site, and if so, how can this be done? I've searched for plugins but to no avail. I'd like to save my clients time, so they don't have to login to each site separately. The issue is that my partners aren't running on WordPress. I really have no idea where to even start, so I figured an open-ended question would be best. Thanks in advance for any suggestions or ideas.


wordpress str_replace the content with tag

it is possible to find tag in the content and replace with link?               function replace_content($content){       foreach(get_the_tags() as $tag) {         $out .= $tag->name .',';         $csv_tags .= '"slug . '">' . $tag->name . '"';       }       $find  = array($out);       $replace = array($csv_tags);       $content = str_replace($find, $replace, $content);       return $content;     }     add_filter('the_content', 'replace_content');


is_home() and is_front_page() not working in sidebar

I'm trying to display a custom widget in the sidebar of my homepage (which is a static front page defined in `Settings > Reading`). Here is the relevant part of my `sidebar.php`:               if ( is_front_page() || is_home() ) {         if ( is_active_sidebar( 'sidebar_lecture' ) ) : ?>             <div id="secondary" class="widget-area" role="complementary">                 <?php dynamic_sidebar( 'sidebar_lecture' ); ?>             </div>         <?php      endif;      The sidebar does not display because the conditional tag does not recognize my homepage as being a homepage. When I `print_r($wp_query)` in the sidebar, it reveals that `[is_page] => 1` and that the post's `[ID] => 32`, which is correct. However, `[is_home]` is null. For the record, I did use a custom query (`query_posts()`) in my `page.php` template, but I did reset it afterwards using `wp_reset_query()`. Any pointers?


Adding unit ammount after WooCommerce price. Example $ 24 /m2 and $24 / m

So hey guys, I'm trying to get my WooCommerce price per unit done. Some of the items I'm selling are floortiles, and as of such they're sold per square metre. I have added the following code to display /m2 behind every price               .amount:after{         content: "/m2";         text-size: 13px;     }      This adds the /m2 after each price. However, some of the items I am currently selling are not floortiles. For example decorating strips are sold per metre. And I'm selling column blocks, which are sold per piece. How can I add the price units correctly? Does the WooCommerce CSS recognize SKU? and if so, how to implement it?


Is it possible to change the log file location for WP_DEBUG_LOG?

I use WP_DEBUG_LOG in my development environment and have no issues with debug.log being in the wp-content directory. Sometimes I turn on WP_DEBUG in production when I need to debug something, and I still want to use the log but would like to redirect it to something outside my web root. Is this possible using WP_DEBUG_LOG?


Check if email address exists front end with AJAX in a plugin

I am pulling my hair out trying to figure this out. I have followed the wordpress codex here for AJAX: http://codex.wordpress.org/AJAX_in_Plugins All I keep returning is 0, I never get a 1. Any idea why? My code is as follows. PHP:               add_action('wp_enqueue_scripts', 'live_validation' );     add_action('wp_ajax_validate_email', 'validate_email_input');     add_action('wp_ajax_nopriv_validate_email', 'validate_email_input');          function live_validation() {         wp_enqueue_script( "validate_email", STRIPE_BASE_URL . 'inc/js/check-email.js', array( 'jquery' ) );         wp_localize_script( "validate_email", "validateEmail", array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );     }          function validate_email_input() {         $email = $_POST['email'];         if ( email_exists($email) ) {             echo 1;          } else {             echo 0;         }         exit;     }      JS:               jQuery(document).ready(function($) {         $('input[name=email]').keyup(function() {                  var input_value = $(this).val();                  $.post( validateEmail.ajaxurl, { action:'validate_email', email:input_value }, function(data) {                 $('.message').html(data);             });         });     });      HTML:
         <?php _e('Email', 'oe'); ?>         <input type="text" size="20" id="email" name="email" />


Select Menu for Custom post Type does not save

I posted a discussion on CSS-Tricks the other day. Explaining that my Videos were not displaying on my Video page from my custom post type that I created using this tutorial. I thought I fixed the issue but it turns out the issue wasn't resolved. Anyway, so I thought maybe the way I setup my CPT/Fields were messing things up. So I found another tutorial and redid the CPT and Fields, here is the new code. I was able to get my Video ID field to save, but when I select "Youtube" or "Vimeo", then save, it just goes back to it's default option "Select". So when I view my page the container where the video should be placed is blank. I am new to all of this Wordpress PHP so I have no idea if the select menu code is correct...or whatever the issue is. I'd appreciate any help to find the cause of this. **EDIT//** After editing this line:               $ret .= '
';      to this:               $ret .= '
';      The Selected Video Type can now be saved, but my issue with a blank container remains... I pasted the PHP section which should display the video in this pastebin.


adding new posts into wordpress DB automatically

I want to create a php script that reads the rss feed content from another website and then adds those read information into my WordPress website's database so that when you go to my WordPress website you will see those inserted posts via my php code. **The problem is:** I want to use built in codes of WordPress for adding new posts and I don’t want to go through writing my own code for inserting data into MySQL.   Is there a fast way?   I want to be able to add these information into WordPress by my php script:   1. Post content   2. Post title   3. Tags   4. Post categories   5. Date: for this I want to add the time and date when the new post is inserted into database.   6. Writer At the beginning of my php script that I am writing, I first connect to the wordpress's Database using username and password of that database. Is there a fast way for adding new content by php into wordpress's database? Is there any special function for doing this? And for using that function what should I do in my php script? What should I include in it?


How to include wp-postviews plugin directly in the theme

I don't want to ask the user to install this and that plugin, I want my theme to be 100% active active without the need to install a plugin like wp- postviews plugin, so how can i do that. I want to include it directly in functions.php file? Thanks in advance.


How to isolate code to the post edit screen

I've got some jQuery that interacts with items on the post and page editor screens. However, the script is also loading on other admin screens that are driven by post.php Is there a way to target the post/page editor screen exclusively? I'm currently using:               global $pagenow;     if( 'post.php' == $pagenow )     {       //jQuery blocks go here     }      However, since the jQuery has refences to objects that only appear on the post/page editor screens, I'm getting console errors on other pages that are driven by post.php For example, this code throws a console error of "Uncaught TypeError: Cannot read property 'length' of undefined":               var charactersMeta = jQuery("#excerpt").val().length;


A static page view call every custom page templates

I use wordpress 3.9.1 and I get this strange issue: I created a static page with slug `customer-order` and I created a template `page-customer-order.php` and Permalink: `http://localhost/thanassis/src/customer-order/` I also created a static page with slug `zipfile` and I created a template `page-zipfile.php` and Permalink: `http://localhost/thanassis/src/zipfile`. I also use child theme and these templates are in the child-theme folder. The problem is that when I view `customer-order` page the wordpress not run only the correct template but also run the `zipfile` page template. Is this correct Wordpress's sequence?


trying to do if post meta !=0

im trying to do a simple if function on my code but for some reason it just isnt working correctly, ive gone over it several times to see if there is anything im missing but no luck, im trying to say my value is 0 then echo nothing if not else the_ratings. very simple...               <?php if( get_post_meta( $post_id, 'ratings_users', true ) === '0' ) {     }else{     the_ratings();     } ?>     <?php if(!get_post_meta( $post_id, 'ratings_users', true ) !='0' ) {     }else{     the_ratings();     } ?>     <?php if(get_post_meta( $post_id, 'ratings_users', true ) =='0' ) {     }else{     the_ratings();     } ?>      edit: at this point ive tried 3 different ways to get this stupid thing to output nothing if the value in the custom field is 0 and still it doesnt work correctly


How to get to blog flow and a specific post?

How do I get to a specific blog post in the flow without getting inside the specific post? I mean from my homepage i can see a excerpt of the post. When i click on that post i come right to that specific post and cant scroll done if I want to read another post. I want to be able to click on that post and come right to my blog page that already showing the content and still be able to scroll down or up to read more. How do I do that? This is my site: http://d29190245.u193.surf-town.net/ and the post im talking about is the one with a picture saying no image and i want to come to "BLOGG" and not inside the post.


Include CSS with PHP without including wp-load?

I have a CSS-file generated from PHP. **In my file it says...**               header("Content-type: text/css");     define('WP_USE_THEMES', false);     include '../../../../wp-load.php';      I've read that including wp-load.php like this is not good. Why I do this is to get the environment in there. What is the "correct" way of doing this?


Wordpress or plugin need tomcat?

I have a managed VPS. It's a CentOS 6.4 + Apache 2.2 + Nginx admin 4.4. When I'm running **top** process in SSH, I can see there's a tomcat process (uses 1.9% RAM). This VPS has only wordpress sites. I want to know Wordpress or its plugin need the tomcat to run? How do I check if a plugin need tomcat?                PID   USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND     24085 tomcat     20   0  657m  50m 8728 S  0.0  2.0   0:02.57 jsvc


Organize media uploads in folders - I have a physical access to (my) server

I'm very new to Wordpress. With the help of my friend I installed Wordpress on my server and finally we have our web online. However, I would like to upload some content in media library but I need to organize it in folders. Now we organized it with date-time hierarchy but its not enough. Is it possible having an access to the physical server where I have my site to create some directories and upload files to it using wordpress (I would like to create them inside the date-time directories)? Where do I need to create such folders, how can I check where my friend installed wordpress and find the directory I can create some subdirectories? Do I need a wordpress plugin or can it be done manually on server? We installed our wordpress on Ubuntu 12.04 Server.


Pagination stops at page 6

The loop below works fine, apart from the fact that the pagination will always stop on page 6. No matter what arguments i specify, it will never show more than 6 pages. Does anyone know why?               <?php          $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;                     $idxargs = array(             'posts_per_page' => '1',             'paged' => $paged,         );              $idxloop = new WP_Query( $idxargs );                        ?>              <?php if ($idxloop->have_posts()) : while ( $idxloop->have_posts() ) : $idxloop->the_post(); ?>                               <?php the_title(); ?>                             <?php endwhile; ?>             <?php next_posts_link( __( 'Next') ); ?>        <?php previous_posts_link( __( 'Prev' ) ); ?>              <?php endif; ?>         <?php wp_reset_query(); ?>


register_taxonomy for both 'Post' & 'Page'

I'm using following code to register new taxonomy for WP-Post.               function qc22_build_taxonomies(){             register_taxonomy(__( "fullscreen-tags" ), array(__( "fullscreen" )), array("hierarchical" => true, "label" => __( "Fullscreen Tags" ), "singular_label" => __( "Skill Type" ), "rewrite" => array('slug' => 'fullscreen-tags', 'hierarchical' => true)));          }         function qc22_fullscreen_edit_columns($columns){                        $columns = array(                       "cb" => "<input type=\"checkbox\" />",                       "title" => __( 'fullscreen Item Title' ),                     "type" => __( 'type' )                 );                        return $columns;           }           function qc22_fullscreen_custom_columns($column){                   global $post;                   switch ($column)                   {                         case __( 'type' ):                           echo get_the_term_list($post->ID, __( 'fullscreen-tags' ), '', ', ','');                           break;                 }           }                add_action( 'init', 'qc22_build_taxonomies', 0 );         add_filter("manage_edit-fullscreen_columns", "qc22_fullscreen_edit_columns");           add_action("manage_posts_custom_column",  "qc22_fullscreen_custom_columns");       I want to appear this taxonomy on WP-Pages also. I'm new to wordpress. Any help will be appreciated. Thanks


Fatal error: Cannot redeclare when switching themes

I've built a theme from scratch which is named "core". Core has a child theme called "core_child". My child theme works perfectly and only contains the following:   1. /images   2. screenshot.png   3. style.css Today I needed to activate "core" to make some changes. I received the following error upon activation:               Fatal error: Cannot redeclare add_slug_body_class() in /Applications/MAMP/htdocs/fresh_install/wp-content/themes/core/functions.php on line 3      The error indicates that I have a functions conflict. This prompted me to open up my `functions.php` file. I renamed the function `add_slug_body_class` to `body_slug_core` and this re-produced the error:               Fatal error: Cannot redeclare body_slug_core() in /Applications/MAMP/htdocs/fresh_install/wp-content/themes/core/functions.php on line 3      Here's the function which is causing the problem:               // Page slug body class     function body_slug_core( $classes ) {     global $post;     if ( isset( $post ) ) {     $classes[] = $post->post_type . '-' . $post->post_name;     }     return $classes;     }     add_filter( 'body_class', 'body_slug_core' );      Next I deleted the function completely. This produced the following error:               Fatal error: Cannot redeclare remove_default_image_sizes() in /Applications/MAMP/htdocs/fresh_install/wp-content/themes/core/functions.php on line 23      This error is referring to the next function within `functions.php`. Here's the code:               // Remove WP default image sizes     function remove_default_image_sizes( $sizes) {         unset( $sizes['medium']);         unset( $sizes['large']);         return $sizes;     }     add_filter('intermediate_image_sizes_advanced', 'remove_default_image_sizes');      I repeated what I had tried for the first function (renaming and then deleting the function completely), but it simply flagged the next function as a conflict. I have read that this can be caused by WordPress websites that have been compromised. This is not the case as I've only been running the themes locally via MAMP. I've changed the names of the functions which rule out any conflict with the WordPress core files. I have tried a fresh install of WordPress with a clean database without any plugins running. To regain control of wp-admin, I have renamed the core theme folder to core_. This produces a further warning in wp-admin which may be unrelated:               Warning: implode(): Invalid arguments passed in /Applications/MAMP/htdocs/fresh_install/wp-includes/class-wp-theme.php on line 675      The warning disappears when I refresh the page. WordPress Version: 3.8.3


get_pages - Display child then grandchild pages

I have a page structure like this.                   Portfolio         - Residential         - - Resident 1         - - Resident 2         - - Resident 3         - Commercial         - - Commercial 1         - - Commercial 2         - - Commercial 3      The grandchild pages Resident 1 - Commercial 3 have post thumbnails I have a template for the Portfolio page where i would like to display the 'Residential' and 'Commerical' pages with their child pages like so.

Residential

  Resident 1 post_thumbnail

  Resident 2 post_thumbnail

  Resident 3 post_thumbnail

Commercial

  Commercial 1 post_thumbnail

  Commercial 2 post_thumbnail

  Commercial 3 post_thumbnail

      I'm using get_pages and I have the div's created for 'Residential' and 'Commercial'                   <?php                  $portfolio_sections = array(                 'post_type'     => 'page',                 'child_of'      => $post->ID,                 'sort_column' => 'menu_order',                 'sort_order'    => 'ASC',                 'parent'            => $post->ID             );                  $sections = get_pages($portfolio_sections);                  foreach($sections as $section){                  ?>

<?php echo $section->post_title; ?>
                        //Create Child pages
                  <?php                }         ?>      My problem is creating the child pages in the 'ul' list I tried using a second foreach loop but this didn't work and I don't know if this is the correct way                   <?php                  $portfolio_sections = array(                 'post_type'     => 'page',                 'child_of'      => $post->ID,                 'sort_column' => 'menu_order',                 'sort_order'    => 'ASC',                 'parent'            => $post->ID             );                  $sections = get_pages($portfolio_sections);                  foreach($sections as $section){                  ?>

<?php echo $section->post_title; ?>

                     <?php                         $portfolio_pages = array(                             'post_type'     => 'page',                             'child_of'      => $section->ID,                             'sort_column' => 'menu_order',                             'sort_order'    => 'ASC',                             'parent'            => $section->ID                         );                              $pages = get_pages($portfolio_pages);                              foreach($pages as $page){                             ?>
<a href="<?php echo get_the_permalink($page->ID);?>"><?php echo get_the_post_thumbnail($page->ID, "thumbnail"); ?><?php echo get_the_title($page->ID);?>
                             <?php                         }                     ?>

                  <?php                }         ?>      --- UPDATE ---- The structure I wanted. A div around each ul list

Residential

  Resident 1 post_thumbnail

  Resident 2 post_thumbnail

  Resident 3 post_thumbnail

Commercial

  Commercial 1 post_thumbnail

  Commercial 2 post_thumbnail

  Commercial 3 post_thumbnail

      The structure from the code is one surrounding div.

Residential

  Resident 1 post_thumbnail

  Resident 2 post_thumbnail

  Resident 3 post_thumbnail

Commercial

  Commercial 1 post_thumbnail

  Commercial 2 post_thumbnail

  Commercial 3 post_thumbnail


Knowing blog name using blog id

I would like to get the blog name using the given blog_id, how would I do this? I tried to search for the codex but cannot find the right information


Archive page display all posts which are listed under multiple categories or tags

Say I have some posts that I want to display which are listed under the categories "Video Games" and "Reviews". Or I have some posts under the tags "Mario" and Four-Stars". I initially came to ask a question on how to create an archive page that contains posts that are in more than one category but while researching, I figured this out: I can use any of the following links to display posts which only fall into the two categories or tags below:               example.com/category/Video-Games+Reviews/     example.com/tag/Mario+Four-Stars/     example.com/?tag=Mario+Four-Stars      However, on the example pages above, wordpress outputs at the top of the page: "You are here: Home / Archives for Mario", additionally, the title tag of the page reads "Mario Archives - example.com". There is no mention of the tag "Four-Stars" anywhere on the page. Same goes for the category example, it mentions the category listed first, "Video Games", but does not mention "Reviews". I did find a forum where a 'solution' to this problem was offered but it did nothing for the output on my site. I included the following in Functions.php               function my_get_the_tag_query() {     $nice_tag_query = $_SERVER['REQUEST_URI'];     $nice_tag_query = str_replace('/tag/','', $nice_tag_query);     $nice_tag_query = str_replace(',', ', ', $nice_tag_query);     $nice_tag_query = str_replace('/','', $nice_tag_query);     return $nice_tag_query;     }      And I included this in the header.php               is_tag( $nice_tag_query );      and also tried               is_tag();      As I said above, this code did not make it so both tag names appeared on the page. Is there something I am doing wrong? Also I tried adding the following code to my functions.php page https://gist.github.com/certainlyakey/7dd680dbb1235e1560c9 Same thing, this did not work for me either. Please any suggestions would be helpful. I am using a StudioPress created, Genesis Child Theme.


wordpress simple post multi rating with post_meta and user_meta

I am trying to create a multi criteria post rating function with simple form and post_meta and user meta. ## The Goal when users submits their ratings 2 things should happen: 1.the ratings is stored in the post_meta called 'wpd_rating' like this:               array(user id => array(               field1 => 5               field2 => 3               field3 => 4               ),           another user id => array(               field1 => 2               field2 => 5               field3 => 4               )          )       2.the ratings is stored in the user_meta called 'plgn_rating' like this:               array(post id => array(               field1 => 5               field2 => 3               field3 => 4               ),           another rated post id => array(               field1 => 2               field2 => 5               field3 => 4               )          )       ## The Code (Not working Obviously) **In single.php:** the header part:               <?php // top of page     if ( isset( $_POST['drw_inventory'] ) && wp_verify_nonce($_POST['drw_inventory'],'update_drw_postmeta') )         { //if nonce check succeeds.             global $post;             $postid = $post->ID;             $data = $_POST['wpd_function_rating'];             $data2 = $_POST['wpd_feature_rating'];             $data3 = $_POST['wpd_support_rating'];             $currentusr = get_current_user_id();                  //*******************The post meta field Part****************************             //Get the Existing user ratings of this post             $ls_up_votes = get_post_meta($postid, 'wpd_rating');                  //if the current user already rated, unset the rating             foreach ( $ls_up_votes as $key => $value )               {                 if ( $key == $currentusr )                   {                     unset( $ls_up_votes[$key] );                   }               }              //Add post meta 'wpd_rating' with this structure:          //array(userid => array('wpd_function_rating' => '3','wpd_feature_rating' => '5','wpd_support_rating' => '4',))             $up_vote = array($currentusr => array('wpd_function_rating' => $data,'wpd_feature_rating' => $data2,'wpd_support_rating' => $data3));                  //appending new user ratings after one another             $ls_up_voted = array_merge($ls_up_votes, $up_vote);             update_post_meta($postid,'wpd_rating',$ls_up_voted);                            //*******************The user field Part****************************             //Get the Current user ratings of this post             $user_rated_posts = get_user_meta($currentusr, 'plgn_rating',true);             foreach ( $user_rated_posts as $key => $value )               {                 if ( $key == $postid )                   {                     unset( $user_rated_posts[$key] );                   }               }             //add a user field 'plgn_rating' with this structure             //(postid => array('wpd_function_rating' => '3','wpd_feature_rating' => '5','wpd_support_rating' => '4',))             $usr_vote = array($postid => array('wpd_function_rating' => $data,'wpd_feature_rating' => $data2,'wpd_support_rating' => $data3));             //appending new user ratings after one another             $ls_up_voted = array_merge($user_rated_posts, $usr_vote);             update_user_meta($currentusr,'plgn_rating',$ls_up_voted);              }          ?>      The Form:               <form method="post" action="">        <?php wp_nonce_field('update_drw_postmeta','drw_inventory'); ?>        <label>This is label</label>        <input type='text' name='wpd_function_rating' value='' />        <input type='text' name='wpd_feature_rating' value='' />        <input type='text' name='wpd_support_rating' value='' />        <input type='submit' value='save' />     </form>      **Issues with the current code**   1. The array is not saving as I structured. I am pretty sure I am using the array_merge wrong. or the calling the get_post_meta wrong.   2. The code is not checking for the existing user rating and replacing the old ratings with the new one. ## Update as s_ha_dum suggested tried this with no avail:               foreach ( $ls_up_votes as $key => $value ){      var_dump($key,$value);             if ( $key == $currentusr ){            unset( $ls_up_votes[$key] );        }     }       When I add the user input 2 times, the unset commands should remove the previous array that was added by the same user and add the new one, instead its adding all 2 times.Here is what I am getting:               Array ( [0] => Array ( [0] => [1] => Array ( [wpd_function_rating] => 33 [wpd_feature_rating] => 23 [wpd_support_rating] => 66 ) ) [1] => Array ( [wpd_function_rating] => 44 [wpd_feature_rating] => 11 [wpd_support_rating] => 32 ) )


How to get only 1 role from user

I have this code that will display all the roles for that particular user, but I only need to display 1 role from the user. I have installed bbpress so the code below will display out 2 roles.               $user = new WP_User( 1 );          if ( !empty( $user->roles ) && is_array( $user->roles ) ) {     foreach ( $user->roles as $role )     echo $role;                      }      Result: Administrator Participant How to display only the first role?


Creating a Digital Download facility and track downloads

I need to make available Documents for download and I need to track the document name/number of downloads for each user and list of downloaders for each download, is this possible with WordPress, if so any suggestions ? Praveen


How to overwrite orderby with add_query_var

So I would like to have an archive that displays its posts in a random order.               <?php             $query = new WP_Query($query_string."&orderby=rand");     ?>      But also then if the user chooses they can order the posts differently by clicking a button.               <?php         $sort_date = add_query_arg(array('orderby'=>'date','order'=>'asc'));         $sort_name = add_query_arg(array('orderby'=>'title','order'=>'asc'));     ?>
         Sort by: <a href="<?php echo $sort_date; ?>">Date Listed | <a href="<?php echo  $sort_name; ?>">Name
      These 2 things work separately but when I try and use them together the archive just keeps display the posts randomly. How can I get these 2 to work together?


Link to previous month's posts

On my homepage I am showing only the current month's posts. I'd like to include a link to the previous month's posts at the bottom of the page. Wordpress has `get_month_link` (http://codex.wordpress.org/Function_Reference/get_month_link). I can use this function like so to get the month number, minus 1 = previous month:               $archive_year  = get_the_time('Y');      $archive_month = get_the_time('m');     $previous_month = $archive_month - 1          <a href="<?php echo get_month_link( $archive_year, $previous_month ); ?>">Last month's posts      This will output a link like "/?m=201308" if the month is September. In most cases this will work, but when I get to January, the `$previous_month` var will be "01 - 1", and won't give me "12" for December's posts. Any ideas how to make this a little more fail-safe for situations like December? Many thanks


Populate a slideshow list of images from images in a wordpress page?

I'm using the "flexise" slideshow script to automatically scroll a list of images. The list is hard-coded along with the script in a wordpress template page. While this works fine, how could you make it so that the slideshow pulled any images added to a special (private) wordpress page instead of having to add each img src manually??

        Many thanks Trying your suggestion now, I've replaced the above with this:               $attachments = get_posts(array(     'post_type' => 'attachment',     'numberposts' => -1,     'post_status' =>'any',     // This is where you specify the ID of your private image page     'post_parent' => 6909,     ));          if (count($attachments)) {     // We have attachments     ?>
         <?php         // Now we loop through them         foreach ($attachments as $attachment) {             ?>
                 <?php echo wp_get_attachment_image($attachment->ID, 'full'); ?>
             <?php         }         ?>
     <?php     }       But it's throwing an error. Probably something simple, but I'm not experienced enough to debug?               Parse error: syntax error, unexpected '<' in /home4/speedyp/public_html  /speedypancake.com/tmc/wp-content/themes/sirens/page_f.php


user_login vs. user_nicename

When you call the `get_users()` functions, a list of user objects are returned. Each of those users has a number of properties. What is the difference between `user_login` and `user_nicename` in those returned properties for each user? And which of those two properties are displayed in the URL? (I am asking because both properties are the same in my case!).


How to programatically create a simple HTML page using the permalink of a Wordpress post?

I want a create a simple HTML page (not Wordpress Page) programmatically by using the permalink structure of another already existing post. E.g. Already existing post is `www.example.com/this-is-example-post` I want to create 3 more pages viz.               www.example.com/this-is-example-post/index1     www.example.com/this-is-example-postindex2     www.example.com/this-is-example-post/index3      These URLs need not be real pages. I just need three different pages to store different Facebook meta. I'm building a plugin. Please guide. How can I achieve it? Am I thinking twisted? I'm going crazy thinking about it. :( Please help. **-------------EDIT---------------** After working on suggestions from Rahil, here's where I'm now               <?php      add_action( 'init', 'xx_add_endpoint' );          function xx_add_endpoint()     {         add_rewrite_endpoint( 'index', EP_PERMALINK );     }          add_action( 'template_redirect', 'xx_render_endpoint' );          function xx_render_endpoint()     {         if ( ! is_singular() or ! get_query_var( 'index' ) )         {             return;         }              // Do somthing here         exit;     }               add_filter( 'request', 'xx_set_endpoint_var' );          function xx_set_endpoint_var( $vars )     {         isset( $vars['index'] ) and $vars['index'] = true;         return $vars;     }          ?>      But I'm trying to understand how I can pass variables to this request e.g. `www.example.com/this-is-example-post/index/20/1`, `www.example.com/this-is- example-post/index/20/2`, `www.example.com/this-is-example-post/index/20/3` and so on. p.s. I intend to pass two values viz. `/index/a/b` where `a`,`b` are the two values to be sent and handled under `xx_render_endpoint` function. Please guide.


Wordpress site interfering with another site on same server (Surftown)

I have a server at surftown.com, and on that I have 3 WP sites. The main/root folder, where you usually put your index file and so on, does not contain anything, other than 3 different folders called 1, 2 and 3. In these folders I have 3 different WP sites. Now, the first WP site (1) is setup with Duplicator in WP, which makes it a duplicate of another WP site I have. The two others are made from the OneClick Toolbox in surftown admin menu, where it just creates a WP site for you, and then you can install whatever you need. So here comes the problem: The first WP site (1) doesn't have any problems at all. But, the other two to interfere with each other. Sometimes when I try to login at site 3, it doesn't recognize the user/pass at all, and if I finally get it, it's like I'm on the site 2. Besides that, when I visit the site 3, and click on a menu link or something, it takes me to the site 2 instead (They have the same link names, since I'm just making different designs to show). And then, sometimes it works, but most often not. I have no idea why this is happening. The databases are not called the same thing. I do use the same user/pass on both sites, but as I said, it doesn't interfere with the site 1. So am I doing something wrong. Maybe it's not optimal to have more WP sites on the same server ? Thanks in advance.


how to limit edit_form_after_title hook to page and post edit only?

heelo, I want to use this great hook **edit_form_after_title** it was announced on December 1, 2012:   http://make.wordpress.org/core/2012/12/01/more-hooks-on-the-edit-screen/ **it curreclty hook for : post-new, post, page-new, page.** how do I make it to work only in edit page/post ( **only post, page** ) thanks all


wp_localize_script problem for shortcode

I have developed a shortcode with wp_localize_script like the below code `               wp_enqueue_script( 'twi_carousel_tooltip_main_option_js', plugins_url( '/js/main_tooltip.js' , **FILE** ) , array( 'jquery') , false, true);     wp_localize_script( 'twi_carousel_tooltip_main_option_js', 'tooltip_setting', array(                     'twi_tooltip_the' => $twi_tooltip_themes,                          'ulidli' => '.'.$ulid.' '.'.'.$id_s                      )                 );                     ` and run these value with jquery each loop like that               jQuery(document).ready(function($){     var ulidli = tooltip_setting.ulidli;                               $(ulidli).each(function() {                      var theme = tooltip_setting.twi_tooltip_the;                      jQuery(this).tooltipster({                          theme:theme                      });                  });              });      I got CDATA like that                    var tooltip_setting = {"twi_tooltip_the":"tooltipster-punk","ulidli":".twi_carousel_97 .twi_carousel_tooltip"};     var tooltip_setting = {"twi_tooltip_the":"tooltipster-light","ulidli":".twi_carousel_1 .twi_carousel_tooltip"};           But did not work both of them 2nd one is working but another is not. Can you please tell me which is best way to work with wp_localize_script with multi shortcode ??? Thanks


Posts not listing out sub category in hierarchy

I have a magazine like post structure like so: `Parent -> Sub category -> Article`. The parent is the issue, the sub categories are the sections within the magazine like news and interviews etc and then the articles are within those sections. I have background images which are associated with the sub category and then articles within that sub category inherit the background image. Code in single.php which retrieves the background image from its sub category hence [1] not its top level parent [0].               <?php      $category = get_the_category();     $hierarchy = array_reverse( get_ancestors( $category[0]->term_id, 'category' ) );     $hierarchy[] = $category[0]->term_id;      ?>          <body style="background:url('<?php echo z_taxonomy_image_url($hierarchy[1]); ?>')" class="background-img">      For the most part this works just fine, however on a few articles the background image doesn't show. I have breadcrumbs showing the category structure and the posts that work show the full `parent -> sub category -> post name` structure, however on the ones that don't work just shows `parent -> post name.` There is the standard wordpress breadcrumbs and meta info at the bottom which always displays the correct heirachy for the post which is why I am confused. How come some posts how their correct heirachy whilst others don't? My permalink structure is `index.php/category/postname` You can check the bug out here post with background and proper taxonomy at the top post with incorrect hierarchy here so no background and incorrect breadcrumbs at the top


Adding pub_Date to an RSS feed hosted on Wordpress

I am trying to use the FaceBook application RSS Grafitti to link my RSS feed from my Wordpress installation to a FaceBook Fanpage. It finds the feed OK, but cannot post to the Fan page because there is apparently no pubDate field in the RSS feed. I am not even sure where to find the file to edit in my WordPress installation. I have WordPress 3.0.1 installed on a shared Linux host.


Post images deseappeared from homepage after run query for delete related images

I run a wp blog that shows lasts posts in its homepage, but after run a query to delete the related images from all posts my images disappeared from the homepage, but it is still appearing in categories and single pages. Does anyone have an idea in how to make it shows the images again? btw: the images showed in home weren't related images, because it used to show the images before even without a related image set. Page: http://www.vidaloka.net Thanks a lot.


Default Display Name As Username

I don't know why it's so hard to find a solution for this but nothing seems to work when i finally find an answer.. I want to simply make the default display name as the users login/username.. I know I can edit each user, but I want it to be set like that for everyone and everyone that registers in the future. Any ideas? Thanks


Custom query_vars and parse_request on wp-admin

I've read this post http://wordpress.org/support/topic/query-vars-in-admin and although it's quite an old question, it suits me perfectly. I'm trying to accomplish what I already posted here: Rewrite rule for admin-ajax.php But in the code below, only the first filter gets called while in wp-admin:               add_action('init', array('MYCLASS', 'add_custom_rewrite_rules'), 10, 1);     add_action('query_vars', array('MYCLASS', 'add_custom_query_vars'), 10, 1);     add_action('parse_request', array('MYCLASS', 'add_custom_parse_request'), 10, 1);      I can't get this to work. It seems the two last filters are not called while navigating inside wp-admin. Is that true? How can I get around this?


How to use tax_query other than by slug or id or solve custom taxonomy tags conflicts with pre-existing tags?

I just encountered a problem and realized that all tags must be globally unique. Here is what just happened to me: I created a taxonomy called `writer` and added each author and collaborator to the post they have written or/and collaborated to. For this, I was getting `post id as the $object_id` and `user nicename as the $term` for the `wp_set_object_terms` function. After filling up my new taxonomy with the writters, I wanted to display a list of posts using WP_Query and tax_query. The arguments for the tax_query would be as follows:               'tax_query' => array(         array(             'taxonomy' => 'writer',             'field' => 'slug',             'terms' => $array_of_nicenames         )     )      So each item in the array would be matched against the taxonomy slug. Everything was working fine until I hit and already created slug. Thus, the writer slug would read `user_nicename-2` instead of `user_nicename`. The post made by this user would not be displayed on my list. I hope I am making myself clear; otherwise, ask me to clearify anything. I was thinking about using the user id instead of the user nicename; however, eventually I would come up with the same problem. For example, I could have a tag called 2003 and a user with the same id. A _possible solution_ I came up with but I would like to avoid is this one: For each new user, create a meta tag that would include the user nicename attached to a preffix like this `uniquepreffix-user_nicename`, thus incrementing my chances to have a really unique username/slug for later use. Is there any other way I can accomplish what I want without encountering this problem? Can I use tax_query by name instead of slug?


Advanced Custom Fields - Check if multiple get_fields exist?

I can only really seem to find documentation on wether one get_field exists or not. Is it possible to put multiple get_field's into one variable and use that variable to check if any of the singular get_field variables exist? So for example I have these variables below, and then put them all into one: `$promotions`               <?php               $rider_plan_code        = get_field('rider_plan_code');         $low_rate_finance_code  = get_field('low_rate_finance_code');         $custom_promo_code      = get_field('custom_promo_code');              $promotions = isset( $rider_plan_code, $low_rate_finance_code, $custom_promo_code );          ?>         Then I am using this... `<?php if ($promotions) { ?>` to check if any of those variables exist, but its not working. Can anyone point out what I'm doing wrong? Many Thanks * * * See below how I am using this...
               Post to wall              <a class="btn <?php if ($promotions) { echo 'dropdown-toggle'; } ?> pricing-btn" href="#" title="Pricing" <?php if ($promotions) { echo 'data-toggle="dropdown"'; } ?>>             £<?php the_field('rrp-pound-sterling'); ?><?php if ($promotions) { echo ' '; } ?>                       <?php if ($promotions) { ?>
                 <?php if ($rider_plan_code) { ?>
Rider Plan
<?php } ?>                 <?php if ($low_rate_finance_code) { ?>
Low Rate Finance
<?php } ?>                 <?php if ($custom_promo_code) { ?>
<?php echo $custom_promo_name; ?>
<?php } ?>
              <?php } ?>


Get custom field value from not-current page

What is the best way of getting a custom field value from a page which is not the one currently displayed? I know the title of the page i want to get custom field value from, but not the pageID. Thanks!


Why does WP recommend against custom favicon functionality in themes?

I am developing a WordPress theme, and when reading the Codex article on Theme review, WP recommendeds against allowing custom favicons in a theme. Does anyone know the reason for this recommendation? From the Codex: > Favicons   >  Themes are recommended not to implement custom favicon functionality.   >  If implemented, favicon functionality is required to be opt-in, and > disabled by default.   >  If implemented, favicon functionality is required to support user-defined > favicon images


Compare two numeric custom fields

I use Advanced Custom Fields and have a custompost-type "matches". This post- type contains two fields "goals-made" and "goals-against". I want to query wordpress to show only the matches that were won. So where "goals made" > "goals-against". Can anyone help me get started on this one. The goal is to have a statistics page in the end. Thx a lot for helping me out


First Byte Time (back-end processing)

Do you have any tips for reducing First Byte Time back end processing... I disabled most of the plugins I could, I am using CDN, W3 Total Cache.. but still the back-end processing time is around 3 seconds. Is this time acceptable? What else could be done? thanks Andy


The content not wrapped in paragraph tags with get_page_by_title()

I am using `$page = get_page_by_title('name')`; to get the contents of a page. When I echo `$page->post_content;` none of the content is wrapped in p tags like it is when run threw the normal wordpress loop using `the_content(`). Is there a different way I should get this data so it will contain the proper tags?


Custom field values in permalink

Is there a way to add a custom field value (if it exists) to the permalink?


"Matching" or "Linking" Two WordPress Pages: Custom Fields?

I'm helping with a custom multi language site. We have one page in English, then an equivalent page in French. I've got a "SWITCH LANGUAGE" link in the main container (next to the breadcrumbs) that takes you to the English home page if on any French page, and vice versa. Aside from using a plugin, how can I make this link more dynamic by having it point to the _equivalent page_ , whether French or Engligh? E.g. when a user is on the "Events" page, the l ink points to the "Evènements" page, but when on the "Fundraising" page, it points to "Levée de fonds" page. Here's the code I'm using now to switch languages, using custom fields to give all Engligh pages a Name of "MenuName" and a Value of "English". This then serves either the breadcrumbs.php or my new breadcrumbs-en.php, which has the appropriate link to it. I don't think this is the best way to do this however, since it is dependent on the breadcrumbs.               <?php          if (get_post_meta($post->ID,'MenuName', true))       {       get_template_part('includes/breadcrumbs-en','page');       }     else       {       get_template_part('includes/breadcrumbs','page');       }     ?>      So I'm looking more for the theory of linking the two pages, by way (I think) of assigning custom field values for each page(?)


Sidebar menu based on user role

This is a follow up to my own topic: Show menu in sidebar if on specific page AND specific user role (is_page, current_user_can) It didn't quite work as intended. To recap, I want to show a different sidebar menu depending on the role of the currently logged in user. Some pages overlap. For example, page: **my-account/same-page-for-all** may be in both sidebar menus - for CustomRole1 and for CustomRole2. This went into the functions.php               function get_user_role() {     global $current_user;          $user_roles = $current_user->roles;     $user_role = array_shift($user_roles);          return $user_role;     }      Then, in the sidebar.php I use this:               <?php     if (is_page(array('page1','same-page-for-all')) && get_user_role('Administrator','CustomRole1')) :         echo '
Title 1
' .         wp_nav_menu(array('theme_location'=>'menu1' ));          elseif (is_page(array('page2','same-page-for-all')) && get_user_role(array('CustomRole2','Administrator') :         echo '
Page 2
' .         wp_nav_menu(array('theme_location'=>'menu2' ));          endif;     ?>      The problem with this is that **when the same page is in both statements** , it defaults to the first menu. Even if I'm logged in as CustomRole2 user, it still shows the menu for the CustomRole1 users.


Hide/Show panel not showing - ACF

I came across strange thing. I have been using ACF for a quite a long time now and I love this plugin, but I tried to use it for new project and when I create group of fields for my pages show/hide panel is not displaying and all fields are floating, i'm not sure what might be causing that unless there is some option which isn't selected. http://grab.by/h50W


How to check if I am in admin_ajax?

Right now for my plugin, I am using `in_admin()` to determine if the user is in the frontend of the site or in the admin area. However, the problem occurs when plugins use `admin_ajax.php` to process ajax requests. I need a way to register hooks and plugins only when processing `admin_ajax.php` or in the frontend of the site. What is the best way to go about doing that?


Can I have Post Types under other Post Types in Admin menu?

Lets say I have created two custom post types `A` and `B`. Those post types are displayed in the Admin menu one after another. (After `Posts` for example) Is there a way to display `B` under `A`? The only similar behavior I am aware of is to assign Taxonomies to Post Types. This forces the first to be displayed under the second. I am looking for a way to do this using custom post types. It's like having relationships across post types. _I am managing post types and taxonomies using the excellent`GD CPT Tools` plugin. Wordpress 3.4.2_


Show Sitename on Yoast SEO Title tag

I am using Yoast SEO plugin on a site. Right now if a Post's Title is left empty in the metabox for a post, then the Title tag will output in this format...               %%title%% %%page%% %%sep%% %%sitename%%      Now if that same post does have a custom title text saved in it's meta field...then it shows only the text from the meta. What I need to do is show `%%sitename%%` after the titlte text no matter what! So even a title that is saved as `This is my title` the output on the HTML page will be...   `This is my title - SITENAME` Does anyone know how to do this?


One Login details in 2 E-commerce website

I've created 2 ecommerce websites the Chinese version and English version. What I want to happen is to have 1 login details in both sites. Is this possible? How? Please can anyone help me with this?


How do I add a current class to the current post?

I have this list set up of the latest 7 posts:
                 <?php                 global $post;                 $args = array( 'numberposts' => 7 );                 $myposts = get_posts( $args );                 foreach( $myposts as $post ) :  setup_postdata($post); ?>
                         <a href="<?php the_permalink(); ?>"><?php the_title(); ?>
<?php the_author(); ?>
                 <?php endforeach; ?>
      How can I have a class of 'current' be displayed for the current post?


WordPress Screwing Up 'orderby' => 'meta_value_num' in 'pre_get_posts'

I have a bunch of `_ai_price_int` meta values set up as just numbers. This is how the table looks:               meta_id, post_id, meta_key,      meta_value     1309,    1111,    _ai_price_int, 6550     1310,    1115,    _ai_price_int, 7100     1311,    1113,    _ai_price_int, 7500     1312,    1103,    _ai_price_int, 6000     etc.      I'm using a `pre_get_posts` filter to modify a particular query, like this:               public function filterQuery($query) {         $query->set('post_type', 'sponsorship');         $query->set('meta_key', '_ai_price_int');         $query->set('meta_value', '4000');         $query->set('meta_compare', '<=');         $query->set('orderby', 'meta_value_num');         $query->set('order', 'DESC');         return $query;     }     add_action('pre_get_posts', Array($this, 'filterQuery'));      But playing around with `$query->set('meta_value', '4000');`, it turns out that the results are incorrect.   * When using `2000`, I'm getting a post that has an _ai_price_int value of `15000`.   * When using `4000`, I'm getting a post that has an _ai_price_int value of `35000`. I tried using:                   $query->set('post_type', 'sponsorship');         $query->set('meta_key', '_ai_price_int');         $query->set('orderby', 'meta_value_num');         $query->set('order', 'DESC');         $query->set('meta_query', array(             array(                'key' => '_ai_price_int',                'value' => array(0, 4000),                'compare' => 'BETWEEN'             )         ));      instead, but the results are the same. Looking at the performed query, I can see that it has this portion:               ...AND ((wp_13postmeta.meta_key = '_ai_price_int'AND CAST(wp_13postmeta.meta_value AS CHAR) <= '4000') )...      **Don't tell me that WordPress is ordering these values alphabetically?!** I'm also saving this custom value as an integer explicitly:               $price = (int)preg_replace("/([^0-9\\.])/i", "", $match[1]);     update_post_meta( $post_id, '_ai_price_int', $price );      What am I doing wrong? I'm testing on WP version: 3.5.2


How to add download to post & more?

What is the correct way of adding downloadable content to posts? More complex situation: I have a portfolio, and sometimes I do stuff that is meant to be freebie and I want it to be downloadable. Additionally, I want my portfolio page (custom portfolio archive page) to show a little icon on each portfolio item (custom post type element). And of course perfectly, without using any plugin. I was thinking of adding additional custom field, with download link and on archive page just make an if statement: if custom field download not empty - show icon... However this solution is not really flexible. In case I would ever decide to show download count or do anything else with it (also, maybe any suggestions what could be relevant to track in downloads?) I am just looking for best practice and great ideas. Thanks!


Widgets in PHP files?

IS it possible to make every Widget on Wordpress in a different .php file?   I have one page that contains 12 elements, I want to make each of them   a Widget so it would be easier to manage/edit them later on, but it would be better   if it's from a php page rather then from a code block on the Admin panel.


Only show upcoming event or current events

I've been working on this website event page > http://aishaarab.com/events/ everything is working but I have 2 problems:   1. I can't get it to only show upcoming event meaning when an event is past to not shoe it or not display it.   2. When I output the post_meta onto my page using `<?php meta('event-end-date'); ?>` my result format is 08-12-2014 i would like the month to be letters like this august 12, 2014. here is code:
              <?php // Let's get the data we need to loop through below     //$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;     $d = date("m-d-Y");     $today = date('Y-m-d', strtotime('-6 hours')); //define "today" format; note timezone offset of -6 hours     $args = array(         'post_type' => 'event',         'posts_per_page' => '3',         'post_status'  =>  'publish',         'meta_key' => 'event-start-date',         'orderby' => 'meta_value_num',         'order' => 'ASC',         'meta_query' => array(         'relation'  =>   'AND',         array(                 'key' => 'event-end-date',              'meta-value' => date('Y-m-d', strtotime('-6 hours')), //value of "order-date" custom field              'compare' => '>=', //show events greater than or equal to today              'type' => 'CHAR'             )         )     );     $the_query = new WP_Query( $args ); ?>               <?php if ( $the_query->have_posts() ) : ?>                                     <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

               <?php if ( '' != get_the_post_thumbnail() ) { ?>     <a class="post_img" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">     <?php the_post_thumbnail('event-thumbnail'); ?>          <?php } else { ?>     <a class="post_img" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">               <?php } ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?>

      Start Date: <?php meta('event-start-date'); ?>
     End Date: <?php meta('event-end-date'); ?>
     Time: <?php meta('event_time'); ?>

Location :
<?php meta('event_address'); ?>, <?php meta('event_city'); ?>, <?php meta('event_state'); ?>, <?php meta('event_country'); ?>

     <a class="read_more" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">Read More

                                  <?php endwhile; else: ?>
              <?php _e('Sorry, no events matched your criteria.'); ?>
             <?php endif; ?> <?php //wp_reset_query(); ?>


VideoJS in a Widget?

I'm trying to get VideoJS plugin to work in a Widget.   I tried to add a PHP widget and write, as it said in the manual:                 [video mp4="http://video-js.zencoder.com/oceans-clip.mp4"]      But it just shows the code as is, any ideas?


How to set post expiration date and time and move the page to archive after expiration

My requirement is to move the certain posts from home page category after specified date and time. I have two category News and Events. Both have so many posts and i dont want to show all the posts on home page. So how can i set the date and time to move the post from home page to archives.