How to add color picker to widgets?

I have some problems adding the wpColorPicker to a Widget. Does anyone have a working sample? It only works when I click on 'Save' or reload the page, but when I drag a new widget to the area it will not activate. Anyone any ideas? Below you can find my code so far.               class SampleWidget extends WP_Widget          {                  /**              * Register widget with WordPress.              */             public function __construct ()              {                 parent::__construct                 (                     'sample_widget',                     'Sample',                     array( 'description' => __( 'A sample description'), )                 );                        add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );             }                  public function admin_enqueue_scripts ( $hook_suffix )             {                 if ( $hook_suffix != 'widgets.php' ) return;                      wp_enqueue_style( 'wp-color-picker' );                           wp_enqueue_script( 'wp-color-picker' );              }                  /**              * Front-end display of widget.              *              * @see WP_Widget::widget()              *              * @param array $args     Widget arguments.              * @param array $instance Saved values from database.              */             public function widget( $args, $instance )              {                 extract( $args );                      echo $before_widget;                 echo $after_widget;             }                  /**              * Sanitize widget form values as they are saved.              *              * @see WP_Widget::update()              *              * @param array $new_instance Values just sent to be saved.              * @param array $old_instance Previously saved values from database.              *              * @return array Updated safe values to be saved.              */             public function update( $new_instance, $old_instance )              {                 $instance = array();                 return $instance;             }                  /**              * Back-end widget form.              *              * @see WP_Widget::form()              *              * @param array $instance Previously saved values from database.              */             public function form ( $instance )              {                 ?>                 <p>                       <label for="<?php echo $this->get_field_id( 'background-color' ); ?>">Achtergrondkleur:</label>                     <input type="text" id="<?php echo $this->get_field_id( 'background-color' ); ?>" name="<?php echo $this->get_field_name( 'background-color' ); ?>" value="<?php echo esc_attr( $backgroundColor ); ?>" />                                               </p>                      <script type="text/javascript">                 jQuery(document).ready(function($){                     $('#<?php echo $this->get_field_id( 'background-color' ); ?>').wpColorPicker();                 });                 </script>                 <?php             }         }


Filtering problem

I got the custom_post_type_data in which I store some variables when I make a new post. Variables likes Author, Price etc. I implemented a filtering by author, so when you click on James (for example), you will see all James`s products. All seemed nice until now. Today I discovered a little bug (At James products page, there are some other authors products listed). I do not know why exactly, but I guess I will need to be more specific, by adding a "%" after $author (James). The problem is that this will not work at all. Any idea why?                 'meta_query' => array(         array(             'key' => 'custom_post_type_data',             'value' => $author,             'compare' => 'LIKE',         )


Order custom posts by a date metabox

I have a custom metabox, where I store the date in plain text like this: `dd/mm/yy`and now I need to order the posts by that date.The custom field is called `event_informations_date`               <?php         $args = array( 'post_type' => 'Event','posts_per_page' => 1000 );         $loop = new WP_Query( $args );     ?>     <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>


Exclude current sticky post

I have the following query, trying to fetch the latest sticky posts but exclude the current one:               $sticky = get_option('sticky_posts');     rsort( $sticky );     $sticky = array_slice($sticky, 0, 3);          query_posts(         array(             'post__not_in' => array($post->ID),             'post__in' => $sticky,             'caller_get_posts' => 1,         )     );      Getting the posts works fine, but `post__not_in` doesn't. Is there an effective way to do this?


latest posts-widget displays all posts on archive page but works great anywhere else

I noticed the latest posts widget in my footer displaying all posts. Anywhere else on my page, it displays only the amount of posts it should. I am using a custom theme and this is my archive.php:               <?php get_header(); ?>
              <article id="page-<?php the_ID(); ?>" class="page">
Post Type Archive Title
                               <?php $posts = query_posts($query_string . '&orderby=meta_value_num&meta_key=premium&posts_per_page=6'); ?>             <?php if ( have_posts() ) : ?>
Filter

                      <?php echo do_shortcode('[ULWPQSF id=82 formtitle="0"]'); ?>                      close
                      <?php                     echo '
';                     echo '
';                     while ( have_posts() ) { the_post();                         get_template_part('content', 'my-post-type');                     }                     if(function_exists('wp_pagenavi')) :                         wp_pagenavi();                     endif;             endif;              echo '
';             echo '
';             wp_reset_query();             wp_reset_postdata();                  ?>

                   <?php get_sidebar(); ?>

          <?php get_footer(); ?>      Can you possibly spot the mistake?


Using Pages to handle calls for custom post types

I have created a page on which I would like to run queries exlusively for one custom post type in the same way I'm using Category.php, Author.php and index.php to run queries for regular posts. I can't seem to get anything to appear when I edit the page that is associated with the template I've created for this page, so I've edited the actual page template itself. This may or may not be related to the fact that I can't get this page to behave like index.php does, i.e. providing a running list of posts until someone does a more refined search such as by Category. I'm stumped - how can I get a page template to work just like index.php does, but for the custom post type only?


Heartbeat API oEmbed

By default running content through `the_content` filter automatically checks for oEmbed content. However when returning data through `heartbeat_received` the filter for oEmbed doesn't seem to work. For example -               function test_heartbeat_received( $response, $data ) {         if( $data['test_heartbeat'] == 'test' ) {             $content = "https://twitter.com/WordPress/status/456502643738030080";                  // Doesn't work             global $wp_embed;             $content = $wp_embed->autoembed( $content );             $response['test_heartbeat'] = $content;                  // Also doesn't work             $response['test_heartbeat'] = apply_filters( 'the_content', $content );         }         return $response;     }     add_filter( 'heartbeat_received', 'test_heartbeat_received', 10, 2 );     add_filter( 'heartbeat_nopriv_received', 'test_heartbeat_received', 10, 2 );      Doing the exact same without using Heartbeat seems to work. The content filter is being applied as the formatting exists, just without oEmbed. Any suggestions? Thanks!


How to pass variable to add_settings_section() callback?

I am attempting to automate, as much as possible, the Settings API function calls for each setting in a Plugin. Looping through the options array, and outputting `add_settings_section()` and `add_settings_field()` is simple enough: `add_settings_section()`:               $oenology_hooks_tabs = oenology_hooks_get_settings_page_tabs();     foreach ( $oenology_hooks_tabs as $tab ) {         $tabname = $tab['name'];         $tabtitle = $tab['title'];         $tabsections = $tab['sections'];         foreach ( $tabsections as $section ) {             $sectionname = $section['name'];             $sectiontitle = $section['title'];             $sectiondescription = $section['description'];             // Add settings section             add_settings_section(                 'oenology_hooks_' . $sectionname . '_section',                 $sectiontitle,                 'oenology_hooks_' . $sectionname . '_text',                 'oenology_hooks_' . $tabname . '_tab'             );         }     }      And `add_settings_field():               global $oenology_hooks;     $oenology_hooks = oenology_hooks_get_hooks();          foreach ( $oenology_hooks as $hook ) {         $hookname = $hook['name'];         $hooktitle = $hook['title'];         $hooktab = $hook['tab'];         $hooksection = $hook['section'];         add_settings_field(             'oenology_hooks_' . $hookname,             $hooktitle,             'oenology_hooks_setting_callback',             'oenology_hooks_' . $hooktab . '_tab',             'oenology_hooks_' . $hooksection . '_section',             $hook         );     }      With `add_settings_field()`, I can easily write a generic callback, by passing the `$hook` variable to the callback, as the fifth parameter in the function call:               function oenology_hooks_setting_callback( $hook ) {         $oenology_hooks_options = get_option( 'plugin_oenology_hooks_settings' );          $hookname = $hook['name'];         $hooktitle = $hook['title'];         $hookdescription = $hook['description'];         $hooktype = $hook['type'];         $hooktab = $hook['tab'];         $hooksection = $hook['section'];         $inputvalue = $hookname . '_hide';         $inputname = 'plugin_oenology_hooks_settings[' . $inputvalue . ']';         $textareaname = 'plugin_oenology_hooks_settings[' . $hookname . ']';         $textareavalue = $oenology_hooks_options[$hookname];         if ( 'Filter' == $hooktype ) {             ?>             <input type="checkbox" name="<?php echo $inputname; ?>" value="<?php echo $inputvalue;?>" <?php checked( true == $oenology_hooks_options[$inputvalue]  ); ?> />             Hide <?php echo $hooktitle; ?> content?
             <?php         }         ?>         <?php echo $hooktype; ?> Hook: <?php echo $hookdescription; ?>
         <textarea name="<?php echo $textareaname; ?>" cols="80" rows="3" ><?php              echo esc_textarea( $textareavalue );          ?></textarea>         <?php      }      However, it appears that `add_settings_section()` does not have an analogous `$args` parameter; thus, I cannot use the same method to pass the `$section` variable to the callback. **Thus, my question: is there any way to pass a variable to the`add_settings_section()` callback, or some other way to create a callback analogous to what I'm doing for `add_settings_field()`?** EDIT: @Bainternet nailed it! Here's my working code:               /**      * Callback for add_settings_section()      *       * Generic callback to output the section text      * for each Plugin settings section.       *       * @param   array   $section_passed Array passed from add_settings_section()      */     function oenology_hooks_sections_callback( $section_passed ) {         global $oenology_hooks_tabs;         $oenology_hooks_tabs = oenology_hooks_get_settings_page_tabs();         foreach ( $oenology_hooks_tabs as $tab ) {             $tabname = $tab['name'];             $tabsections = $tab['sections'];             foreach ( $tabsections as $section ) {                 $sectionname = $section['name'];                 $sectiondescription = $section['description'];                 $section_callback_id = 'oenology_hooks_' . $sectionname . '_section';                 if ( $section_callback_id == $section_passed['id'] ) {                     ?>
<?php echo $sectiondescription; ?>
                     <?php                 }             }         }     }


General question about Parent and Child Post type relationships

I'm hardly an expert on the matter but from reading around this Q&A site i have the following notion that one Post Type cannot be the Parent of another Post Type. What i can't seem to answer is why? If i have a post type of Neighborhoods because they tend to have a lot of specific information relevant to them wouldn't that make sense to be a Post type? If i have a post type of Places because there is a lot of information relevant to a place (building, memorial, eatery, etc) wouldn't that make sense to be a Post type? Then wouldn't it make sense that places are within neighborhoods and therefore have a Parent/Child relationship where Neighborhood is the parent of Places? Why is it not possible then to structure them that way then in a simple manner, or am i missing something here? Finally why are the same types of Custom Post Types able to be parents of another (ex: Neighborhood1 can be the parent of Neighborhood2 and vice versa) how does that make any sense? Why would there be a need to make another post of the same post type a child of itself? When what seems more logical is to have one post type be the parent of another. My entire understanding, from what i've read and from what i've been working on, is that one would create a Custom Post Type when a specific kind of repeatable data type will have to be created (neighborhoods, teachers, cars, computers, etc) why then would it ever make sense to have those be hierarchical within themselves? Thanks


Is there a WordPress boolean for "theme_customizer_active()"?

Looking to add an action to `wp_head` but only if the user is in "theme customizer" mode. Does anyone know if there's a conditional for this?


Filter list by a unique meta value dilemma

I'm been racking my head at this for a while now, and I can't figure out how to fix the code. Here's the issue; I found a snippet of code online to filter my post results in edit.php based on predetermined info. I've already modified the code to fit the needs of my wordpress theme. In this case, it's Property Types. Predetermined values being '1 Bedroom, 2 Bedroom, 3 Bedroom, Bachelor, Executive' The values are entered through the theme options, and the dropdown with filter options DO work however, it will only filter the values that have an integer. (ie. 1 Bedroom, 2, Bedroom, etc) Bachelor, Executive, etc will not filter correctly. Here is the original code: **functions.php**               function restrict_articles_by_propertytype_value() {         global $wpdb;         $propertytype_values = $wpdb->get_col("             SELECT DISTINCT meta_value             FROM ". $wpdb->postmeta ."             WHERE meta_key = 'propertytype_value'             ORDER BY meta_value         ");         ?>         <select name="propertytype_value_restrict_articles" id="propertytype_value">             <option value="">Show All Property Types</option>             <?php foreach ($propertytype_values as $propertytype_value) { ?>             <option value="<?php echo esc_attr( $propertytype_value ); ?>" <?php if(isset($_GET['propertytype_value_restrict_articles']) && !empty($_GET['propertytype_value_restrict_articles']) ) selected($_GET['propertytype_value_restrict_articles'], $propertytype_value); ?>>             <?php                    echo $propertytype_value;             ?>             </option>             <?php } ?>         </select>         <?php     }     add_action('restrict_manage_posts','restrict_articles_by_propertytype_value');      Followed by the function to filter the results on the table. **functions.php**               function posts_where( $where ) {         if( is_admin() ) {             global $wpdb;            if ( isset( $_GET['propertytype_value_restrict_articles'] ) && !empty( $_GET['propertytype_value_restrict_articles'] ) && intval( $_GET['propertytype_value_restrict_articles'] ) != 0 ) {                 $propertytype_value_number = intval( $_GET['propertytype_value_restrict_articles'] );                      $where .= " AND ID IN (SELECT post_id FROM " . $wpdb->postmeta ."      WHERE meta_key='propertytype_value' AND meta_value=$propertytype_value_number )";             }     }            return $where;     }     add_filter( 'posts_where' , 'posts_where' );      I can see the cause being the function intvar(as seen below) but I can't get the filter to work with strvar or a different method as I'm still very new to PHP development. I need the filter to work even if there is no number/integer value present. Been looking around google for hours here, and I can't seem to find the answer. I'm probably missing something very trivial.


How to display posts on a static page? (like search loop)

How do I display the loop inside a static page? Like the loop when I use the search (which in this theme it's actually working) or on index.php An example for what I'm saying can be seen here: http://www.gaganews.com.br/noticias/ I want a page like this, showing all my posts with pagination, since my home page is kinda like the homepage here: http://www.gaganews.com.br/ I tried creating a template page, this way:               <?php           /*     Template Name: Noticias     */          get_header(); ?>
<?php if ( have_posts() ) : ?>             <?php                 get_template_part( 'loop', 'index' );             ?>       <?php endif; ?>

<?php get_sidebar(); ?>
     <?php get_footer(); ?>      I'm almost 100% sure that it's not the right way, but that's what I tried - like it was a "classic" index.php. Then I created a blank page with this template, but with it instead of showing the latest posts on the page, it ONLY shows the PAGE TITLE itself: _"News, posted on 1 de abril de 2013 by admin | Leave a comment | Edit"_ etc, but with all the CSS configuration from the loop (which means it's actually calling it, right?). What could I do to achieve what I'm looking for?


Trying to combine a variable together

So I am not 100% sure if the is feasible so hopefully some one can point me in the appropriate direction. I am using the Advanced Custom Fields plugin and on my custom page template I am using the gallery field. I am trying to display the title of attachments post its assigned to (iv done this on another page) but I believe I need to combine a couple variables together. Using this on another page works:               <?php         $args = array(             'post_type' => 'attachment',             'posts_per_page' => -1,             'post_status' => 'any',             'post_parent' => null,             'tax_query' => array(                 array(                     'taxonomy' => 'post_tag',                     'field' => 'slug',                     'terms' => 'logo'                 )             )         );          $images = get_posts( $args );     if ( $images ) {         foreach ( $images as $image ) {             // Get the parent post ID             $parent_id = $image->post_parent;             // Get the parent post Title             $parent_title = get_the_title( $parent_id );             // Get the parent post permalink             $parent_permalink = get_permalink( $parent_id );             // Get image caption     ?>      Then I call the title with: `echo ' ' . $parent_title . ' ';` On my template that has the ACF gallery I am trying to use:               <?php         $args = array(             'post_type' => 'attachment',             'posts_per_page' => -1,             'post_status' => 'any',             'post_parent' => null         );              $images = get_posts( $args ) (get_field('gallery'));             if ( $images ) :                 foreach ( $images as $image ) :                     // Get the parent post ID                     $parent_id = $image->post_parent;                     // Get the parent post Title                     $parent_title = get_the_title( $parent_id );                     // Get the parent post permalink                     $parent_permalink = get_permalink( $parent_id );           ?>      This is where I am having a problem: `$images = get_posts( $args ) (get_field('gallery'));` Is it even possible to combine $images to use both get_posts($args) & get_field(gallery)? Thanks!


set up development environment windows

I have a live website (hosted by GoDaddy). I would like to set up a development environment on my local computer (Windows 8) so that I can make changes and see how things look, and then push them over to the live site. What's the best way to do that? I saw some similar questions, but none of them said how to get my live website set up on my local computer. Thanks!


Static page homepage not showing the_content

I must be doing something wrong here. I setup my site with a static front page using front-page.php. I created a page in the admin with a title and chose the front-page.php in the template dropdown. My title shows up fine, however the_content(); does not. I'm not doing anything special as shown below.               <?php     /*     Template Name: Homepage     */ ?>     <?php get_header(); ?>

<?php the_title('');?>

     <?php the_content(); ?>
      Any ideas why the content won't show?


I want to create a Weebly site and have it show up as static pages on a Wordpress site

My son knows how to use Weebly, but he is not familiar with Wordpress. He has been asked to create some static pages on an existing wordpress site (I believe it is Wordpress.org because he was given log-in information to get into the site.) Is there any way that he can create his pages using Weebly and have them redirected to show up as pages on the Wordpress site? This would buy him some time to come up to speed and learn Wordpress. Also, once he creates the site in Weebly, is it difficult to migrate it to Wordpress? He hasn't created the weekly site yet, but the Wordpress site already exists since there are a few people supporting and creating content for this site. Ideally, my son would create in Weebly and the pages he created would show up on the Wordpress site.


Modify Taxonomy pages to exclude items in child taxonomies

I found this question: Theres a way to use $query->set('tax_query' in pre_get_posts filter? which seems to indicate that yes, you can alter the taxonomy query on taxonomy archives via pre_get_posts(). so i came up with               add_action('pre_get_posts', 'kia_no_child_terms' );          function kia_no_child_terms( $wp_query ) {         if( is_tax() ) {          $wp_query->tax_query->queries[0]['include_children'] = 0;       }     }      as well as               add_action('pre_get_posts', 'kia_no_child_terms' );          function kia_no_child_terms( $wp_query ) {        if( is_tax() ) {             $tax_query = $wp_query->get( 'tax_query' );             $tax_query->queries[0]['include_children'] = 0;         $wp_query->set( 'tax_query', $tax_query );           }         }      to try to set the include_children parameter to false... and just about every combination of the two i can think of. so far however, the taxonomy archive is still showing the items in the child term and the following test just seems to ADD the additional tax queries instead of overwriting them... which just confuses me.               function dummy_test( $wp_query){     $tax_query = array(                  'relation' => 'OR',                  array(                    'taxonomy' => 'tax1',                    'terms' => array( 'term1', 'term2' ),                    'field' => 'slug',                  ),                  array(                    'taxonomy' => 'tax2',                    'terms' => array( 'term-a', 'term-b' ),                    'field' => 'slug',                  ),                );               $wp_query->set( 'tax_query', $tax_query );          );     add_action('pre_get_posts','dummy_test');      shouldn't SET overwrite the current value?


Custom Query: query by post custom meta data

So I have a custom post called event, but I need to query only those posts which have a custom metabox(is a checkbox) called `Show On The Homepage: and only if that checkbox is checked.               <?php         $args = array( 'post_type' => 'Event','posts_per_page' => 1000 );         $loop = new WP_Query( $args );     ?>     <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>      My question is there a way to query this, or I will have to do a `get_meta` in the loop and check each one with an if statement


$current_user var returns NULL

I am developing an wp plugin and I am trying to get the current user. If i return with an error print_r($current_user) returns the needed info. But the plugin is activated without an error it returns NULL. I tried to include some wp core files such as wp-load etc but this doesn't have any effect. this is my code(without the error):               class My_plugin_class{              var $user;              function __construct()          {             global $current_user;                  //Set the current user             $this->user = $current_user;                  print_r($this->user);              }          }      **EDIT:** Just edited my code to:               require_once(ABSPATH . '/wp-includes/pluggable.php');     global $current_user;     get_currentuserinfo();      The function get_currentuserinfo() does now a print_r(); and isn't going to stop? **EDIT:** _**Fixed it myself._**


WPML in custom page templates

I have a Wordpress site translated from dansk to english using WPML. In it, I have a page which uses a custom page template to display the titles of all the posts. Sadly, it's displaying all posts twice: the original, and the translated. This is the code I have: `<ul id="archive-list">` `<?php` `$args = array( 'lang' => ICL_LANGUAGE_CODE, 'numberposts' => '-1', 'post_type' => 'post', );` `$myposts = get_posts($args); foreach($myposts as $post) : ?><li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php endforeach; ?>` `</ul>` Does anyone have any idea what I need to do to get this page to display only the titles in the current language?


How to insert a logo in the header?

I am pretty new in WordPress world (I came from Joomla) I am finding some difficulties to insert a logo into this WordPress test site: http://onofri.org/example/ I want put my logo in the header of the website, instead the "EXAMPLE" text. Looking into the WordPress configuration panel I am not finding where I can upload the logo and automatically put it instead the "EXAMPLE" text in the header (I don't know if this is a standard WordPress function as in Joomla or if it is a feature that can be made available by some specific themes or if I have to put it directly into the code) However I am not finding it even in my theme settings. What have I to do to put my logo? Have I to insert it directly into my HTML code?


Creating an auto result search bar

I'm trying to create a search bar that will show me titles of posts when the user types into the text field. I'm completely new to this and I really don't know how to go about doing this. What would I do? Here is the text input html element:               <input type='text' id='searchField' class='pushLeft tabRight hide' onKeyUp="autoSearch('<?php echo esc_js(site_url()); ?>')"/>      And here is the javascript, which I'd like to point out is in a folder called "js" and in that is my javascript file "general.js:"               function autoSearch(link)     {         $("#searchResults").width($("#searchArea").width());         if($("#searchField").val() != "")         {             $.post(link,{autoSearch:"", value:$("#searchField").val()},function(data){                 $("#searchResults").show();                 $("#searchResults").html(data.everything);             },"json");         }         else         {             $("#searchResults").hide();         }     }      Then in functions.php I have the following section of code:               isset( $_POST['autoSearch'] ) && add_action( 'after_setup_theme', 'wpse_60353_autosearch' );         function wpse_60353_autosearch()         {             global $wpdb;                  $searchQuery = mysql_escape_string($_POST['value']);                  $mypostids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_title LIKE '$searchQuery' LIMIT 5");                  $args = array('post__in='.$mypostids);                  $res = new WP_Query($arg);                    $titles ="";                  while ( $res->have_posts() ) : $res->the_post();                 $titles .= get_the_title().'<br />';             endwhile;                  echo json_encode(array("everything"=>"hello"));                  wp_reset_postdata();                  exit; // All done, stop WP continuing         }      I get a POST response saying this:               301 Moved Permanently


Redirect within wordpress template/plugin

I've done a bit of googling, searching on forums, etc, and can't find a good answer. Here is what I'm doing: I need to pass a variable in the url to the page and have a rewrite to make it pretty. So, `"mysite.com/ninny/hello- world"` is really `"mysite.com/ninny.php?c=hello-world"`. This is currently in action on a non-wordpress site using `.htaccess` rewrites and php. I'm trying to create a plugin to do this. Have a file with all the code that is in the `"ninny.php"` file in the plugin and have it appear on the front- end, like a page, with `get_header(),` and other functions working, to visitors when they visit `mysite.com/ninny` or `"mysite.com/ninny/hello- world"`. A plugin is ideal, although a page template could suffice. The issue I'm having is that if you rewrite the url for a page that is in the plugin it doesn't load all the Wordpress functions - so you wind up with all kind of fun errors. I don't want to call wp-load within the site like that. What can I do so that the plugin is creating a "page" (not a real entry-in- the-database page), that doesn't go around wordpress like mine currently does. Is there any way to do a rewrite and have it loading the wordpress functions? Where should I be looking here? Thank you in advance for anything that points me in the right direction. If this all doesn't make any sense, feel free to ask questions.


How can I modify this blog loop to display custom post type posts?

Here's my code to generate a two columm blog index page. I want to modify it so that I can use it as an index page for my portfolio custom post type- query_posts('post_type=portfolio'). I know that I need to modify the first quater of the code, but I just don't know what to change. Can you please help me? Code:                <?php     /*     Template Name: 2 Column Blog Template     */     get_header();     ?>
              <?php         $counter = 1; //start counter         $grids = 2; //Grids per row         global $query_string; //Need this to make pagination work         $paged = get_query_var('paged');                  $offset = 0;                     if ($paged != 0 ) {                         $offset = ($paged-1) * get_query_var('posts_per_page') ;                     }                     query_posts('offset=' . $offset);                     if (have_posts()) : while (have_posts()) : the_post(); ?>     <?php     global $more;     $more = 0;     ?>     <?php     //Show the first post     if($counter == 1) :     ?>         <article class="eight columns" id="entry-<?php the_ID(); ?>"> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">             <?php the_post_thumbnail(); ?>
<a href="<?php the_permalink() ?>">                 <?php the_title(); ?>

                 By <?php the_author() ?> on:<?php the_time('F jS, Y') ?>

                 <?php the_excerpt(); ?>

     <?php     //Show the last post     elseif($counter == $grids) :     ?>         <article class="eight columns" id="entry-<?php the_ID(); ?>"> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">             <?php the_post_thumbnail(); ?>
<a href="<?php the_permalink() ?>">                 <?php the_title(); ?>

                 By <?php the_author() ?> on:<?php the_time('F jS, Y') ?>

                 <?php the_excerpt(); ?>

<?php $counter = 0; endif;?><?php $counter++; endwhile; //sets a clear:both and resets counter for next row of posts ?>

                 <?php previous_posts_link('Previous'); ?>

                 <?php next_posts_link('Next'); ?>
                  <?php endif; ?>

     <?php     get_footer();     ?>


Custom Post Type "Event" with custom permalink structure

I need some help about Custom permalinks for custom post types. I have created a custom post type called "evento" and 3 custom fields for storing date, month and year of the events. I would like to have a permalinks structure like this:               /eventos/2012/07/30      ... where the standard structure would be:               /?post_type=evento&ano=2012&mes=07&dia=30      How to make this magic happen in WordPress? I do not know much about .Htaccess =( Thanks in advance!!!


Menus like a CMS

Here is an example structure of some content:               Parent A     -- Child A     -- Child B     Parent B     -- Child C     -- Child D      `Parent A` should link to the content of `Child A` and `Parent B` should link to the content of `Child C`. Other than that, I'm not sure if this is something that should be managed completely by "menus" in wordpress, or if it should be a `Parent A` page with children pages. The only problem there is that `Parent A` isn't really content, just a link to `Child A`. If you need a real world example, it would be something like this: Main Navigation:               Home, Company, Products, Contact          Company     -- About Us     -- News     -- Careers      In this instance, there is not really a "Company" page, but the "Company" is really a link to "About Us". If "Child A" or "Child B" is selected, in the sidebar this section of the navigation should appear:               Parent A     -- Child A     -- Child B      If "Child C" or "Child D" is selected, in the sidebar this section of the navigation should appear:               Parent B     -- Child C     -- Child D      Hopefully this question makes sense. I'm trying to understand how to access the navigation items individually. I can't even find useful methods (closest I've come is `get_nav_menu_item_children`). How should this be organized and what methods does wordpress contain that can help me achieve it?


Archive.php filtered by pre-determined category

My archive.php template is formatted perfectly to list out posts from a certain month and year. However, I only want this template to show from a specific category. I can query for the specific category but then the month/year filter no longer works. How can I display posts on the archive.php template from one category?


Get meta value and associated user meta

I'm working on a site where users are able to publish posts with custom fields associated with them. I want to display meta values from all posts, and include which user created the post where the meta value is coming from. So far I have been able to display all meta values from all posts. My code:               function get_meta_values( $key = '', $type = 'workout', $status = 'publish' ) {         global $wpdb;              if ( empty( $key ) )             return;              $r = $wpdb->get_col(             $wpdb->prepare( "                 SELECT pm.meta_value FROM {$wpdb->postmeta} pm                 LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id                 WHERE pm.meta_key = '%s'                  AND p.post_status = '%s'                  AND p.post_type = '%s'",                 $key,                 $status,                 $type             )         );              return $r;     }          $workout_leader= get_meta_values( '1_rep', 'workout' );     foreach ( $workout_leader as $value ) {          echo $value;      }      How would I go about retrieving the user meta (e.g. username) for each meta value?


Change class name in Wordpress wp_list_page nav

I'm using Wordpress's wp_list_pages to display a nav of pages on the site. Some pages have children so I need a dropdown menu below those links. The html is something like this

Home

Profile

             Products & Services

Buying

Selling

Managing

      I wanted to use bootstrap to create the nav and dropdown menus. Something like - http://www.ttmt.org.uk/nav/ The html for this is something like this.

Home

Profile

             Messages

Inbox

Drafts

Sent Items

      I need to add a 'dropdown' class the li and ul containing the child pages. I also need to add a class and a data-toggle attribute to the 'a' tag. How can I add these clases when I using wp_list_pages and the nav is created dynamically. I'm using this function to add 'dropdown' to li containin the child pages               function add_parent_class( $css_class, $page, $depth, $args ){         if ( ! empty( $args['has_children'] ) )             $css_class[] = 'dropdown';         return $css_class;     }     add_filter( 'page_css_class', 'add_parent_class', 10, 4 );      How could I extened this function add the other classes I need


How do I remove the post format meta box?

Is it possible to remove the "Post Format" meta box from the edit/new post page? The blog in question has a lot of users that keep messing with that but it only uses the standard format post. I'm kind of new to wordpress so excuse me if this is a really obvious one. Thanks.


Accessing Variables Used In a Plugin Using PHPStorm + XDebug

I'm currently attempting to use XDebug 2.2.1 and PHPStorm 7.1 to debug my WordPress plugin. So far, I've successfully installed XDebug and breakpoints are working fine. However, I'm unable to access any of the variables being used in the functions in which I'm breaking. For instance, I break in this code:               function generateGoalCard($sub) {             $goalID = $this->CodeLibrary->convertStringToInt($sub->goalID);             $userID = $this->CodeLibrary->convertStringToInt($sub->userID);             print('goalID: '); // BREAK POINT HERE             // Other unimportant code ...     }      Below is a screenshot of the debugging window at the above break point. As you can see, `$goalID` and `$userID` are not accessible. How can I gain access to my plugin's variables? ![enter image description here](http://i.stack.imgur.com/bKq5s.png) Here's the screenshot in DropBox.


Get all posts containing a shortcode

I'm writing a WP plugin that involves using shortcode. One of the missions is to display all (publish) posts that contain my shortcode regardless of their post type. Is there a built-in function for this? Thanks in advance.


tumblr importer error wp 3.4.2

i'm trying to import content from tumblr, in wp 3.4.2 i get an error not found i can't get also the tumblr importer page http://wordpress.org/extend/plugins/tumblr-importer/ any idea? Error Data: _Import Tumblr Tumblr replied with an error: Not found. We couldn't find the page you were looking for. Find out why you may have encountered this error. Howdy! This importer allows you to import posts from your Tumblr account into your WordPress site. Firstly, you need to provide your email and password for Tumblr, so that WordPress can access your account. no php errors_ _tools - import - tumblr (An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.)_


How to tell if an option has been created vs an empty option?

What is the method to test for the existence of an option in the database? Not the value of the option, just that the option exists.


how to insert missing tags into the posts through mySQL?

I am looking for a SQL query to insert a tag to multiple posts from a specific category. A pseudo query looks something like this:               INSERT INTO POSTS     VALUES TAG = "tagName"     where Posts in_category("categoryName")      how would such sql look for WP tables?


Remove social media sharing buttons on a download page

I have a couple of social media sharing plugsin installed, but wonder if there is any way of removing them from one specific page that I have as a download page for a product?


Why is the `if else` not working?

I have this on my `header.php`. It checks whether the page is on homepage/frontpage, is on category/children of/has the category of "gamenews", or is on category/children of/has the category of "hobbynews". Basically, if it's on homepage/frontpage, it outputs nothing. On the other hand, if it's on gamenews, it outputs something. If it's on hobbynews, it outputs another thing. You could see in details below. I'm using a custom function there (`is_category_or_sub`).                       <?php if ( is_home() || is_front_page() ) { ?>                  <?php } elseif ( is_category_or_sub('gamenews') || has_category('gamenews') ) { ?>
                 <?php $category = get_category_by_slug( 'gamenews' );                 wp_list_categories(array(                       'child_of' => $category->term_id,                       'title_li' => '',                       'hide_empty' => 0,                       'orderby' => 'count',                       'walker' => new WPSE67791_Walker_Category                    )); ?>
                  <?php } elseif ( is_category_or_sub('hobbynews') || has_category('hobbynews') ) { ?>
                 <?php $category = get_category_by_slug( 'hobbynews' );                 wp_list_categories(array(                       'child_of' => $category->term_id,                       'title_li' => '',                       'hide_empty' => 0,                       'orderby' => 'count',                       'walker' => new WPSE67791_Walker_Category                    )); ?>
             <?php } ?>      Now the first check (is_home/is_frontpage) works just fine. So does the second (the one on "gamenews"). However, the last one ("hobbynews") doesn't work. Each time I visit page which has that requirement (is on category/children of/has the category of "hobbynews"), it displays stuff which is _supposed to be_ on gamenews. The one I want to display on hobbynews does not show up. Why is this happening? I've been trying to re-order, tried to use nested if, etc. But it's still not working and really confusing... * * * **EDIT:** This is my `is_category_or_sub`, located on `functions.php`:               function is_category_or_sub( $cat_slug = get_category_by_slug ) {         foreach (get_the_category() as $cat) {             if ($cat_slug || cat_is_ancestor_of($cat_slug->term_id, $cat)) return true;         }         return false;     }


Access to wordpress method inside of classes

How could I access an usually word-press method as example $this->get_current_site(); inside of a class?


Tabbed content with Pagination

I've stumble across an issue on a site Im building. I have tabbed content each holding a category for price ranges in seprate loops. The tabs work great filtering the categories, however some of the posts now have WP page-navi running the pagination, again works fine. However if I paginate to /page/2 on the first tab the other tabs are then blank/contentless. I can only assume this is a url problem in the pagination so loops are not grabbing the content or I'm not running the loops correctly.
          <?php          $cat_id = get_query_var('cat');          $limit = get_option('posts_per_page');          $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;          query_posts('showposts=' . $limit = 12 . '&paged=' . $paged .'&cat=' . $cat_id . '');          $wp_query->is_archive = true; $wp_query->is_home = false;          ?>             <?php if (have_posts()) : ?>                         <?php while (have_posts()) : the_post(); ?>

                            <a href="<?php the_permalink() ?>">
<?php the_title(); ?>Read More
                          <?php the_post_thumbnail( 'Full Size' ); ?>
                          <?php echo get_new_excerpt() . '...'; ?>                     <a href="<?php the_permalink(); ?>">more info →
                 <?php endwhile; ?>                 <?php wp_pagenavi(); ?>             <?php endif ?>

          <?php          $cat_id = get_query_var('cat');          $limit = get_option('posts_per_page');          $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;          query_posts('showposts=' . $limit = 12 . '&paged=' . $paged .'&cat=-16,-17,' . $cat_id . '');          $wp_query->is_archive = true; $wp_query->is_home = false;          ?>             <?php if (have_posts()) : ?>                         <?php while (have_posts()) : the_post(); ?>

                            <a href="<?php the_permalink() ?>">
<?php the_title(); ?>Read More
                          <?php the_post_thumbnail( 'Full Size' ); ?>
                          <?php echo get_new_excerpt() . '...'; ?>                     <a href="<?php the_permalink(); ?>">more info →
                 <?php endwhile; ?>                  <?php wp_pagenavi(); ?>               <?php endif ?>
      Any information on this is even possible or a kick in the right direction would be greatly appreciated. To see the example of the of page I'm testing


Pluck single parent category from get_the_category

I am working on a theme that displays a single category for each post. However to eliminate user error, I would like to pluck a single parent category out of a posts categories. Here is my code as of now:                  function thb_DisplaySingleCategory($boxed = true, $id = false) {      $categories = get_the_category();     $_id = (empty($id) ? $categories[0]->cat_ID : $id);     $_name = (empty($id) ? $categories[0]->cat_name : get_cat_name($id));          if ($boxed) {         $thecategory = ''.$_name.'';     } else {         $thecategory = ''.$_name.'';     }               return $thecategory;     }      This gives me a single category, but it can be children.


Get the menu name or location of current menu item

I am having a hard time trying to get the name of the active menu and, apparently, I cannot find any solutions to this issue. Basically, I have several menus that follow this pattern: **Menu Name**   * Menu Item 1   * Menu Item 2   * ...   * Menu Item n I want to display the menu name of the current page item, but I cannot find any way of doing it. I have tried using get_nav_menu_locations() in conjunction with get_term():               $theme_locations = get_nav_menu_locations();     $menu_obj = get_term($theme_locations["menu_1"], 'nav_menu');     $menu_name = $menu_obj->name;      However, I need to get the location of the current menu dynamically and after searching for answers/solutions and not finding anything concrete, I just assume that there may be at least a database relationship between the current menu item and the menu object to which is assigned; from where I would eventually get the menu location/term ID. Any ideas, please? I have already spent about 2 hours on this. Thank you in advance! PS: I want to output the active menu title without the use of JS


getting values from a shortcode with an include

I have a checked a few links but nothing seems to for me in getting the attribute value of a shortcode so that I can use it in a condition.               function bf_shortcode_slideshow($atts) {       extract(shortcode_atts(array(         'location' => ''       ), $atts));            ob_start();       if  ( $location = 'home' ) {       classslider = 'homeslider';     }       include(dirname(dirname(__FILE__)) . '/templates/slideshow.php');       return ob_get_clean();     }     add_shortcode('rotator', 'bf_shortcode_slideshow');      In the `slideshow.php` I have a               echo 'classslider=' . $classslider;      My result for `$classslider` is blank ( nothing is displayed ) Is there another way you should compare `$location` to a string value set ?


How to add different user account with different signup and login forms in buddypress or wordpress

I'm new to wordpress. I built a site in wordpress and i'm stuck in Different user account type in my site. please instruct me how to add different user account with different signup and login forms.. already used buddypress user account type lite but now it changed free version into pro version.. I need help from you.. Advance thank you, Regards, LaxmanveL


Hierarchy of Subcategories on Permalink

I'm new to Wordpress. My current permalink is set to /%category%/%postname%/ and a "." (dot) in the Category base. My categorys ID are bigger than the subcats IDs. So the URL looks like this: [site-root]/[category]/[postname] And when entering a subcat, it looks like this: [site- root]/[category]/[subcategory]/[postname] The problem is that when I open something like this: www.example.com/food/fruits - I don't get the posts that are related to fruits and instad get a "Not Found" page. They show up only when www.example.com/fruits. I read some tutorials and forum posts that are related, but nothing solved my problem. http://wordpress.org/support/topic/subcategories-not-showing-up-in-uri-with- pretty-permalinks http://wordpress.org/support/topic/how-to-change-category-ids-in- wordpress-27?replies=7 Hierarchy of Subcategories on Permalink (bug?) Please help me to solve this problem I'm stuck with this for too long :( What can be the problem?   * I changed the ID of the main category to a much bigger number than the subcats.    * I wrote what has to be written in Settings=>Permalinks    * I checked that I didn't forget to mark the subcategories under the main category (yeah, sometimes happens when you're stuck on something and it's because something stupid :P).   * I even deleted all the subcats from the menu and added them back again so it will maybe "refresh" something.  Am I missing something?


Creating button next to "add media" that allows you to choose a single post

I'm looking to create a button next to "add media" ( much like gravity forms "add form) that allows you to choose a custom post and then inserts that post id into a shortcode. I've bene looking at hooking into tinymce for the longest time, but realized that that wasn't the way to go (as those buttons aren't a part of the tinymce editor). anyone have any thoughts?


wp_logout_url() - WordPress Failure Notice

My `wp_logout_url()` working right from front-end. But when I change the new password from front end, then on change-password page when I click on logout, `wp_logout_url()` giving > You are attempting to log out of Do you really want. Any suggestions?


Perform a function when a user clicks register button in wordpress

I am kind of new to wordpress coding. I'm trying to edit the wp-login.php file, in which, if a user clicks register button, it registers the user and stores an information on a different table in the database. My code to insert new data into the database is below, how do I add it inside wordpress?               global $wpdb;     $wpdb->insert('wp_classes',     array( 'userlogin' => $user_id, 'classselect' => $_POST['class_select'])     );     $wpdb->show_errors();     $wpdb->print_error();      from what you said, i tried this code below, but no data was inserted into the database and no error               add_action('user_register', 'store_class', 200);               function store_class($user_id)     {     global $wpdb;     $wpdb->insert('wp_classes',     array( 'userlogin' => $user_id, 'classselect' => $_POST['class_select'])     );     $wpdb->show_errors();     $wpdb->print_error();     }


Subscribers to posts

Consider each post to be topic of conversation, and comments a conversation. For now it is fine. I created a post type called conversation. Now I want to list all the conversations a user is in. How can I extend wordpress for this functionality? In my idea was to create a new table called `wp_posts_users` with `user_id` and `conv_id`. Is there any best practice on this? My final aim is to list on the user page all the conversations he is in.


Is It Possible To A Link To The Homepage From The Admin Sidebar?

The closest I've managed to get is:               function redirect_to_local_110(){       wp_redirect("/", 302);       exit;     }          function add_home_link() {         add_menu_page( 'Course', 'Course', 'read', 'home', 'redirect_to_local_110', 'dashicons-welcome-learn-more');     }          add_action( 'admin_menu', 'add_home_link', 1001 );      However, even though the function `redirect_to_local_110` is called, the rendered link is `admin.php?page=home`. How can I have a top-level menu item that links to the homepage?


How to Check if a Child Category is Being Queried

I need to change the number of posts queried for specific categories 'Recipes' or 'Product Reviews'. The below code works great for this, I have it in functions.php:               function change_number_of_posts($query) {         if ($query->is_category && ( $query->is_category('recipes') || $query->is_category('product-reviews') ) )         $query->query_vars['posts_per_page'] = -1; // Show all posts         return $query; // Return our modified query variables     }          add_filter('pre_get_posts', 'change_number_of_posts'); // Hook our custom function onto the request filter      The problem is that the 'Product Reviews' category is a parent category, so the above code does not work when one of its child categories is being queried. I can use the `'cat_is_ancestor_of()'` function in my loop to do what I need to with these subcategories, but I cannot get it to work in functions.php and am thinking it cannot be called from there. I basically want to say "If the category is 'recipes' or 'product-reviews' or a child of 'product-reviews'..." from my functions.php file. I know I can hard code all the subcategories, but I don't want to have to edit the php every time I add a subcategory of Product Reviews. I have spent hours trying to find a solution, any help is greatly appreciated!!


disable reply comments on depth equals 2

Using budypress and I'm trying to disable comments on comments' comment, meaning depth 2. The structure would go like this. Main Comment. Someone made a comment <\-- Reply is possible Another person made a comment of this reply <\-- No1 can comment this Any ideas? Thanks in advanced.


How do you debug plugins?

I am pretty new to plugin authoring and was having a hard time debuging. I used lots of echo and it is sloppy and ugly. I am sure there is a better way to do this, maybe an IDE with a debugger that I can run the entire site in including the plugin?


Data validation for inline javascript

I try to save inline javascript(Google analytics code) in wp-options table. But i can't figure out what validation function i shall use. I have tried esc_js when saving to the database. But i can't figure out what to use when i shall echo it in the head section.


Run function from parent on child site

I'm running a Multisite WordPress installation and have a couple of child sites. I'm trying to run a script from the main page on one of the child sites. It can be a shortcode `[pro_display_zone id="3"]` or the PHP code `echo pro_display_zone( 3 );` I've got the following but it doesn't output anything:               <?php     function somename()      {         switch_to_blog( 1 );              // Do your stuff         $my_stuff = pro_display_zone( 3 );              // Back to original site         restore_current_blog();              // Return shortcode content         echo $my_stuff;     }     ?>


Include "registration.php" for custom registration form?

I’m creating a custom registration form for my website. Every tutorial has this call in the form               require_once(ABSPATH . WPINC . '/registration.php');      I’ve read that `registration.php` has been depreciated quite a long time ago. Which file must be called upon, what is the proper way?


PHP Call to External Database

I am using the Sleek child theme from Studio Press and want to do a PHP call to this external database for it to display just like this link: http://www.escort332.org/tuskegeecadets.php . The Theme page is this full width page: http://escort332.org/wordpress1/tusk...skegee-cadets/. Is there a way to add the PHP code that links to the database in the page itself? I would also need access the database for other pages as well. Is this possible in the Genesis framework or child themes. Any help would be greatly appreciated.


Customize The Events Calendar to Include an Option to Expand for More Events Listings

I think The Events Calendar for Wordpress by Modern Tribe does a splendid job and does a lot for to turn a drab calendar into a streamlined and professional looking one. I like the ease of the calendar, that you can show calendars by categories, and have the option to choose between grid and list view. There is one thing that I would like to make the calendar do, have the option to see more events that are posted on days in the month/grid view. Here's an example:               http://austin.culturemap.com/events/?view=month      Notice that for the days where there any many events happening/listed that instead of showing all on the calendar, there's the equivalent of the "show more" "read more" "continue reading" option. I would like to have this option available in The Events Calendar. Some days may hold eight or more events and for a clean looking calendar, you don't want all of the events to show. I know there's a way to limit the number of events to show in grid view, but while those events are hidden after limiting the number, it doesn't show that there are more events happening on that day. From the calendar listed above, there seems to be a function/html code that uses the following as a link:               http://austin.culturemap.com/events/?year=2012&month=9&day=1      When looking at the html in Firefox's Inspect Element, I see this:                +9 more      In the .css, it looks like this:               table#eventCalendarTable td .eventsCalShowMore {     color: #fff;     background-color: #8a7b68;     padding: 2px 8px 2px 4px;     }      but as far as to apply something similar to The Events Calendar, I don't know. I'm surprised to see in such a sophisticated calendar, that this isn't a standard option to have for a less cluttered calendar. I've searched The Events Calendar's site and nothing that would provide for this. Does anyone have any ideas how to implement this? This is the GIRDVIEW.php for the calendar:               <?php     /**      * Grid view template.  This file loads the TEC month view, specifically the       * month view navigation.  The actual rendering if the calendar happens in the       * table.php template.      *      * You can customize this view by putting a replacement file of the same name (gridview.php) in the events/ directory of your theme.      */          // Don't load directly     if ( !defined('ABSPATH') ) { die('-1'); }     $tribe_ecp = TribeEvents::instance();     ?>
                      <title><?php wp_title() ?></title>
                                                               <a href='<?php echo tribe_get_previous_month_link(); ?>'>                         ← <?php echo tribe_get_previous_month_text(); ?>                                                                        <?php tribe_month_year_dropdowns( "tribe-events-" ); ?>                                                   <a href='<?php echo tribe_get_next_month_link(); ?>'>                                        <?php echo tribe_get_next_month_text(); ?> →                                              <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading" id="ajax-loading" alt="" style='display: none'/>                                                                                <a class='tribe-events-button-off' href='<?php echo tribe_get_listview_link(); ?>'><?php _e('Event List', 'tribe-events-calendar')?>                     <a class='tribe-events-button-on' href='<?php echo tribe_get_gridview_link(); ?>'><?php _e('Calendar', 'tribe-events-calendar')?>
             <?php tribe_calendar_grid(); // See the views/table.php template for customization ?>           <?php if( function_exists( 'tribe_get_ical_link' ) ): ?>              <a title="<?php esc_attr_e('iCal Import', 'tribe-events-calendar') ?>" class="ical" href="<?php echo tribe_get_ical_link(); ?>"><?php _e('iCal Import', 'tribe-events-calendar') ?>           <?php endif; ?>             <?php if (tribe_get_option('donate-link', false) == true) { ?>
<?php echo apply_filters('tribe_promo_banner', sprintf( __('Calendar powered by %sThe Events Calendar%s', 'tribe-events-calendar'), '', '' ) ); ?>
             <?php } ?>
      Should look like the monthly calendar/grid view in Modern Tribe's demo


altering search terms

How can you filter or alter the search terms that users enter into a search field? Is there a hook available? The idea is to use this function to filter out 2-3 letter "filler" words ("on", "and", "the", etc.)               function prepSearchStr($str){         $str=preg_replace('©[^a-zA-Z0-9]©', ' ', $str);         $str=preg_replace('©(?<=\s|^)(([a-zA-Z]{1,3})|[0-9]{1,2})(?=\s|$)©', ' ', $str); //remove smaller groups of characters         $exploded=explode(' ', $str);         $exploded=array_filter($exploded);         return implode(' ', $exploded);      }


Assigning a category to a user role

I was looking for a plugin for this, but so far I cant find one that does what I want. I limited the user role capabilities with 'Restrict Capabilities'. But the authors still have to click the category when writing a post. For it to be idiot proof I'd like to have the right category be the default (even if it's the only category they can see). Is there a piece of code I can insert in functions.php to assign each user role to the right category? Appreciate any help I can get! Thanks.


Targeting all pages except top level pages

I have used `'0' == $post->post_parent` successfully in my templates to target top level pages. However, I cannot seem to target all pages EXCEPT top level pages:                   <?php          if ( '0' !== $post->post_parent ) {              include 'siblings.php';          }          ?>                     Using the code above, the file is still included in top level pages. Note, I can get it working using the code below, but I want to keep it flexible and not have to specify IDs:                   <?php          if ( !is_page( array( 8, 10, 12 )) && (is_tree(8) || is_tree(10) || is_tree(12)) ) {              include 'siblings.php';          }          ?>      Hope someone can help!


Add a 'guide' image to custom post type admin page

I've created a custom post type and on the admin page for that post type I want an image displayed that can act as a guide for the users uploading images. Is there a function that I can use to insert an image into the admin for just that custom post type. (I have tried to Google this but all the results seem to be related to uploading images).


Download statistics for Wordpress site?

I have a Wordpress site and would like to track the basic statistics for the site; visitor numbers, visitor numbers for specific pages on the site, download statistics etc. For that purpose, I have installed the "Google Analytics for Wordpress"-plugin (http://wordpress.org/extend/plugins/google- analytics-for-wordpress/), and this now tracks much of the information that I want via Google Analytics. However, the download statistics don't work as I want it to: It only tracks files that have been uploaded via the Wordpress Dashboard and that go into the default upload folders (e.g. .../wp-content/uploads/2013/04). I have my files for download in custom folders (e.g. in .../documents), but these are not tracked by Google Analytics with the above plugin. I have looked into setting this up manually in Google Analytics, but to be honest I don't quite understand how to do this. Alternatively, a Wordpress plugin that tracks the downloads of files from custom folders would work for me. There are a number of plugins for this purpose (e.g. http://wordpress.org/extend/plugins/simple-download-monitor/), but it is not clear to me if they are still maintained and are reliable. So what simple and reliable solution would you recommend for download statistics from custom folders on a Wordpress site? Thanks in advance for any help!


Plugin.php: PHP Notice: Undefined offset: 0 in

I moved a WordPress site from one domain to another and there were a lot of white spaces that needed to be removed. The only problem that is left are the following errors:   * PHP Notice: Undefined offset: 0 in /home/linguist/public_html/test/wp-includes/plugin.php on line 767    * PHP Notice: Undefined offset: 0 in /home/linguist/public_html/test/wp-includes/plugin.php on line 785 then further PHP Warning: Cannot modify header information - headers already sent by (output started at /home/linguist/public_html/test/wp-includes/plugin.php:767) Its all due to this code which hasn't been changed at all but is creating errors.               if (is_object($function[0]) ) {         // Object Class Calling         if ( function_exists('spl_object_hash') ) {             return spl_object_hash($function[0]) . $function[1];         } else {             $obj_idx = get_class($function[0]).$function[1];             if ( !isset($function[0]->wp_filter_id) ) {                 if ( false === $priority )                     return false;                 $obj_idx .= isset($wp_filter[$tag][$priority]) ? count((array)$wp_filter[$tag][$priority]) : $filter_id_count;                 $function[0]->wp_filter_id = $filter_id_count;                 ++$filter_id_count;             } else {                 $obj_idx .= $function[0]->wp_filter_id;             }                  return $obj_idx;         }     } else if ( is_string($function[0]) ) {         // Static Calling         return $function[0].$function[1];     }      } Could someone please help me with this?


Custom Post Type & Post Meta or Custom Table for Serial Number Delivery Project

I've trawled a ton of articles here, on wordpress.org, makeuseof.com, code.tutsplus.com, etc. - all very informative but I'm still not sure whether to use a custom table with my plugin project or not. The plugin is for this project only. No need to package for sale. (I'll share the code on github in case anyone else can use it.) **Scenario** : We're using WordPress with WooCommerce to sell specialist printer's softwares from multiple manufacturers. We have a lot of product variants. Sometimes the software is boxed, but 95% of the time it's downloaded and we want to deliver a serial number/key according to the product variant. The serial is _always_ created by the developer so we can't use systems that generate the numbers for us (which is a real shame - some are great). We'll generate a lot of "sold" serials in the table somewhere that I suspect shouldn't be stored in `wp_posts` or even `wp_postmeta` \- I simply don't know. But, in short, I need to integrate our serial numbers dataset with product variants. [Product variants to serials is a one-to-many relationship.] If I use a custom table it will look like this:               CREATE TABLE `wp_xc_serials` (       `serial_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,       `post_id` bigint(20) unsigned DEFAULT NULL,       `xc_SKU` tinytext NOT NULL,       `sold` tinyint(1) NOT NULL,       `serial` varchar(512) DEFAULT NULL,       `key_description` tinytext,       `key` varchar(1028) DEFAULT NULL,       PRIMARY KEY (`serial_id`),       KEY `post_id` (`post_id`),       KEY `used` (`used`)     ) ENGINE=InnoDB AUTO_INCREMENT=133 DEFAULT CHARSET=utf8;      where `post_id` would link it to the WooCommerce product variant stored in `wp_posts`. So, the question is: **Do I:**   * Go with a separate table for easy import, keeping WP's tables clutter free but tricky integration?   * Go with what's already in WP and risk a bloated `wp_postmeta`, slow queries but a far easier integration? (I like this last idea.)   * Use Custom Posts/Taxonomies with _Pods_ or _Posts 2 Posts_?   * Something else? I'm a newb so may not see the glaringly obvious. I guess **my core question** is, what decision would a really good developer make faced with this requirement? _ps - I've seen one solution that does approximately what we need, but it doesn't work with product variants and the feedback has at times been less than favorable:http://bit.ly/1lHnqqf_


Hijacking the URL for filtering

Right, here's the deal. I've got a loop of which displays news posts, these posts can belong to special categories (not normal categories) and I want to be able to filter by them. If I wasn't too interested in aesthetics I'd use a link like this:               domain.com/news?filter=cat1      But instead what I want to do is this (» rewritten):               domain.com/news/cat1 » domain.com/news/?filter=cat1      I've modified the `.htaccess` to pass the `cat1` value as a GET variable:               RewriteEngine On     RewriteBase /     RewriteRule ^news/(.*)/$ /news/?filter=$1 [L,QSA]          # BEGIN WordPress     <IfModule mod_rewrite.c>     RewriteEngine On     RewriteBase /     RewriteRule ^index\.php$ - [L]     RewriteCond %{REQUEST_FILENAME} !-f     RewriteCond %{REQUEST_FILENAME} !-d     RewriteRule . /index.php [L]     </IfModule>          # END WordPress      The problem is even though this is now successfully passing the `filter` variable in, WordPress treats the `/cat1/` as a page, it obviously cannot find it and thus throws a 404. Is there a way to allow this particular URL rewriting without WordPress firing a 404? It appears it's taking the URL in the address bar and parsing that, what I really want is for it to parse the rewritten URL. Thanks


Add 'has_children' class to parent li when modifying Walker_Nav_Menu

I'm writing a customised walker class for wp_nav_menu and want to be able to specify if an li contains a submenu. So I want my markup to be:
         Some item
      I know how to add and remove the classes fine, I just cant find anything to tell me if the current item has children items. Any ideas? Thanks in advance.


how build custom json api controller for all registered users

i use the json api! from wordpress. And try to build an own json api controller, i want return all registered users with the following controller but thats not give an array with all users, suggestions                 public function get_users_index() {         global $json_api;         $users = $json_api->introspector->get_users();         return array(           'count' => count($users),           'users' => array_values($users)         );       }


Attaching global meta to custom fields

I post music videos on my site and I add the artist name as a custom field to each post. I want to associate certain meta with that artist name so I dont have to enter it everytime like the artists twitter account and link to Facebook. So my question is how could I enter in their meta data once somewhere and call it to every post automatically where their artist name is entered for a field. Hope I explained that right.


Show greetings on first time visitors?

This seems pretty straightforward using cookies in straight HTML. In wordpress, how do I do this? AFAIK, wordpress only provides cookies functions for logging/logged in users. How about when I don't want the user to log in to show my greetings?


Declare a function before plugin does on the theme functions.php file

I'm working with a plugin that declares a function using this format:               if (!function_exists('ABdevDND_get_current_post_type')){         function ABdevDND_get_current_post_type() {            ...         }     }      I'm trying to declare it in my theme's functions.php file, by just using:               function ABdevDND_get_current_post_type() {         ...     }      But my timing is wrong, and I'm getting `Fatal error: Cannot redeclare ABdevDND_get_current_post_type()`. How and where can I declare this function so it's declared before the plugin?


Assign a Class to the Current "Tag" for Formatting

Essentially what I am hoping to replicate is something like the "current-menu- item" class that is applied to WP Menus. My client is wanting to use Tags as a sub-nav, and I've managed to get the tags for the category output as an unordered list, but now if someone selects the tag "Tag One", I'd like to have that particular tag to highlight as the currently selected Tag. It would be extra super cool if this could also work with the output generated by "the_tags" attached to the post as well. I hope this makes sense, and thanks! Cheers, John


Is there a plugin that will completely remove the category system?

I have no use in categorizing/tagging my posts with anything, at all, and it doesn't look very good to have every post say "filed under: uncategorized." Is there any plugin to do this, or do I need to do some manual editing?


Custom Menus: dynamic highlighting problem with custom home link

I'm currently implementing wp_nav_menu - all has gone well save for dynamic highlighting. The menu code looks like this (when home, which is a custom link, is selected):

Home

Information

Contact

About

      When a page other than home (which is a 'custom link') is selected this is written out:
Information
      As you can see this includes an active style 'current-menu-item' where the custom link only writes 'menu-item-type-custom menu-item-object-custom' So my question is is there any way to add a selected item style for custom links in wp3 menus?


How to display post title & excerpt when mouse hovers on an image?

I am bit busy with developing one fashion website, currently (http://test- domain.zakirsajib.co.uk/), where I have images come from posts and when mouse will hover on any image, the corresponding post title and post excerpt will de displayed. Couldn't make it happen though :) Any clue will be helpful. Site is developing in wordpress enviornment, so any php and css (though css parts are done, just need bit help from php part)


get all posts with certain meta data

I'm developing a plugin made on the original calendar. My wordpress is based on real events and I want to keep trace of theme on the calendar. So I added a custom field in the post which is the end of the events (or the last day for subriscribe) with the value of a date of course (like 25/02/2010). Now I want to display on the calendar all the events that ends on the days instead of the posts create in each days.   How to get the meta data value of the post in this query?                // Get days with posts     $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)         FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'         AND YEAR(post_date) = '$thisyear'         AND post_type = 'post' AND post_status = 'publish'         AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);      It have to select all the post with my custom meta value. Hope I'm not doing this for nothing, I googled and no plugin with this function came out.


Best way to show Dynamic Content on a Cached Wordpress Site?

I really want to use one of the Cache plugins so that I can serve up more Static pages on my WordPress theme/site. This is obviously the best performance upgrade you can do for a WordPress theme/site. There is a few dynamic elements to my theme that have held me back from making the Leap to Static/cached pages. I will outline these issues below and provide a possible way to solve each issue I have thought of so far. The goal of this post is to either get better ideas/methods to handle the issues I explain or to get some reassurance that I am on the right track at the least. I am a PHP veteran of more then 12-13 years but have only been using WordPress in the past 1-2 years and so far I am really impressed with the capabilities, I am a total WordPress Fanboy now if such a thing exists lol! Ok so the issues I have thought of so far when converting to cached pages... * * * ## Single Posts page   1. **Views Counter Problem** \- I have a function that will fetch a count value for a "View/hit Counter" on the Posts page to give an idea of the Posts Views for a user to see. These are not unique visitors but just a simple hit counter. I have created a separate MySQL table for these values, I am still trying to decide if I should continue with that or switch to use a Meta Field instead. Either way on a page view, the database value is fetched and increased by +1 on each page load. (Admin users views are not added.) The value is then showed on the page in the form of `988 Views` **Views Counter Possible Solution** \- I could make this Value/function be ran using Ajax. Once the new Cached/Static page is loaded, Javascript could then use Ajax to request and update the Views counter for that page. _Does this sound like the best solution for something like this?_   2. **Post Comments Problem** \- Using the default WordPress Comment System, every time a new comment is added to a post, it would require the Cached/Static page for that post to be _re-built_! From what I have seen, there is an option on the Caching plugins I have seen that will let you do just that, you can have it rebuild the page(s) every time a new comment is posted to it. This sounds good on paper but I can imagine it being a nightmare in a high traffic/active site where you might have multiple users commenting on the same article around the same time (all un-tested so I do not know)  **Post Comments Possible Solution** \- So for a solution to the Comments problem, I mentioned a solution above where you can set the Cache plugin to simply rebuild the Cached/Static page upon each new Comment. My concern was I am not really how well this will work in the long run. Now the other possible solution that I see being used more and more is to use a Javascript solution like Disqus Comments or a similar solution. For a long time I really was against this as I wanted all my Comments to not rely on any third-party for my comment system. I am still kind of on the Fence about this issue but have switched to using Disqus comments on my site and so far it's working out fairly good. I am open to other possible solutions though? Or do you think this is really the way to go? ## Site-wide Sidebar   1. **Sidebar Recent Articles Problem** \- I have Tabs in my Sidebar that are shown site-wide across every page on the site...one of the Tabs loads the 10 most recent posts on the blog, since this is shown on every page of the site, once a new article/post is added, it would require that every Cached/Static page on the site be re-built to reflect the addition of new posts in this "Most recent posts list" **Sidebar Recent Articles Possible Solution** \- Again I think I have come up with a good possible solution. I could use Javascript and Ajax to load this content into the Cached/Static pages so they would not ALL have to be re-built so often but could still show the most recent posts. _Does this sound like a good solution? Or more importanctly, can you think of another better or alternative solution to this problem?_ * * * Without getting my hands too dirty yet, this is all the possible problems I can see so far with converting my theme to be Cache/Static Friendly * * * ## UPDATE I just thought of another issue to think about. All Tag/Category as well as user pages will need to be updated every time a post is added that fits into that pages list of posts. I assume this must be a feature of the Caching plugins already I would imagine though


WSOD after upgrading to 3.1

I installed the new wordpress 3.1, but it gave me some problems and I had restore everything, you'd know it help me? Practically after updating the site was completely white and I could not access the dashboard. I do not know if it's in conflict with some plugin or theme ... but I do not risk coming back to update: ( Can you help me? www.talkischeap.it


Using Shortcodes in WP-Menus in WP 3.1 (via nav_menu_objects)?

I've found this new plugin http://wpsmith.net/wordpress/creating-multiple-custom-menus-in-wordpress-3-1 that is using a new 3.1 hook (wp_nav_menu_objects) to remove specific nav- menu-items from the nav-menu-item array before they are parsed by the walker class, if a user isn't logged in. The plugin uses a specific CSS-class as identifier to decide which items to remove. So I've been wondering if it couldn't be possible to use shortcodes in nav- menu-item descriptions, in order to have an advanced set of conditionals with respect to the display of specific menu items (like display on page x, don't display on page y, or, particularly useful: automatic inclusion of child pages/categories, etc. by inserting them into the nav_menu_item array before the array is parsed by the walker) But adding               add_filter(‘wp_nav_menu_objects’, ‘do_shortcode’);      is causing the page to not load correctly. Not a blank page error, but the page stops rendering right after the nav menu containter div. Is there any way to use native WP shortcode functionality for this purpose? Or would it be necessary to create a custom shortcode parser within the function analysing the nav-item-contents? Thanks for any ideas!


How can I custom order the results from wp_list_categories?

I am using wp_list_categories to return (you guessed it) a list of categories within a custom taxonomy. The `orderby` parameter accepts sorting by ID, name, slug, count, and term_group. Is there a way that I can custom sort the results? Ideally I could pass an array of category ID's in the desired order, but obviously I'll have to dig a bit deeper to get this sorted.


How to make alert for new version on theme options?

Let say my theme host on my server. User download my theme and use it. Now I want notify @ alert for new version of my theme. Example to show "New version has been release. Please download at ..." How to do that?


Automate Product Import with WooCommerce?

I'm going to be using the Product CSV Import suite with WooCommerce to import products from a CSV file, but I'd love to have an automated way to do this via Cron if possible. Has anyone seen examples of this being done, or know of any documentation for doing something like this? Thanks!


jQuery UI AutoComplete not working in wordpress?

To use jQuery UI AutoComplete, I loaded the following scripts:               wp_enqueue_script('jquery');      wp_enqueue_script('jquery-ui-core');     wp_enqueue_script('jquery-ui-widget');      wp_enqueue_script('jquery-ui-position');          wp_enqueue_style( 'jquery-ui-autocomplete',   $ul .'/css/jquery-ui-1.8.custom.css' );     wp_register_script('jquery-ui-autocomplete', $url .'/js/jquery-ui/jquery.ui.autocomplete.min.js', array( 'jquery-ui-widget', 'jquery-ui-position' ), '1.8.2', true );     wp_enqueue_script( 'jquery-ui-autocomplete', $url .'/js/jquery-ui/jquery.ui.autocomplete.min.js', '1.1', true );      After the above scripts, I loaded my own js which includes the following code:               $(function(){            $("#to").autocomplete({             // code...        });     });      Firebug shows all scripts and style are loaded and gives error message of "$ is not a function". How can I correct this error?


Evaluating a external rewrite rule before internal wordpress rewrite rule

I am been plucking out my hairs since last few days trying to solve this problem: I want to convert my urls from format               http://example.com/prodsearch/category/tag1-tag2-tag3-tag4      to               http://example.com/prodsearch/index.php?tag=tag1+tag2+tag3+tag4&cat=category      to start with I added following rules to my .htaccess               RewriteRule ^prodsearch/(.*)/(.*)-(.*)$ prodsearch/$1/$2+$3 [L]     RewriteCond %{REQUEST_URI} !^prodsearch/(.*?)/(.*)\-(.*)     RewriteRule ^prodsearch/(.*)/(.*)$ index.php?tag=$2&cat=$1 [R,QSA,L]      Here rule1 recursively replaces all '-' between tags by '+' and rule2 does the actual rewrite once there are no more '-' left between tags (checked by RewriteCond) These rules actually work, but the problem is they redirect (with url change) to new url pattern, I don't want an explicit redirection. On removing 'R' flag from last rule, the whole thing stops working and I start getting 404 page in my wordpress install. Can some one explain why this is happening and how to do this without explicit redirection. Also I tried including these rules into wordpress, hoping when called by wordpress rules may work without redirection. I used following add_rewrite_rule() calls:               add_rewrite_rule('prodsearch/(.*)/(.*)-(.*)$','price-list/$1/$2+$3','top');     add_rewrite_rule('prodsearch/(.*)/(.*)$','index.php?tag=$matches[2]&cat=$matches[1]','top');      Now wordpress detects my first rule as external rule and flushes it to .htaccess file, this screws my execution order, now first rule 2 gets evaluated first(being part of internal wordpress rewrite rule set) and rule 1 gets executed later, hence again 404 page. Is it possible to tell wordpress not to consider my first rule as a external rule and not to flush it to .htaccess, or to evaluate the external rewrite rule before internal wordpress rewrite rules. Finally can anyone help me make this kind of rewrite work? Thanks a lot.


How can I check for malware in a Theme?

There are so many free, freemium and premium Themes out there. How can I be sure that a Theme I download doesn't have malware in the code? Is there an (relatively) easy way to check for malicious code without going through every line of code?


SESSION in WordPress Plugin Development

I wondering the session was disable in wordpress. I try to find some information on using session variables in the wordpress. I tried the following method to implement session variables in the wordpress site. I tried this way.               <?php      session_start();          $_SESSION['firstname'] = $_POST['firstname'];          ?>      If i echoing the `$_SESSION['firstname']` is not come's up. So I googled to find the reason why it doesn't support.               function register_session() {         if (!session_id())             session_start();     }          add_action('init', 'register_session');      This above method i tried and implemented but it also doesn't work. Right now i integrating session in plugin so i don't want to edit the core file. Because i doing the custom plugin development. How to enable the session in wordpress plugin. Any Suggestion would be great Thanks.


How to get the db table row that has the biggest value in the meta value?

E.g. I have a meta field called `car_number`: So, normally I would try something like this to get this value:               $car_value = get_post_meta($post->ID, 'car_number');       But the porblem is that I need to get the row only where the `car_number` is highest e.g. 45. so I need somehow to get the highest value and do something like this:               $post_ID = .. // here I need to get the ID of the post that has the biggest value in the fild car_value          $car_value = get_post_meta($post_ID, 'car_number');       how can I get the post_ID of the post that has the highest value (number) in car_value meta field?


Two ".htaccess" Files Located in Different Directories?

I found two ".htaccess" files, one is located in '/httpdocs/.htaccess', another one is located in '/httpdocs/wordpress/.htaccess', the content is different, is it normal? The Wordpress was installed on '/wordpress/' dir, then never changed, but when users go to my site, the URL shows "http://www.mydomain.com", no 'wordpress' shown on the URL. Also, from Settings > General: WordPress Address (URL): http://www.mydomain.com/wordpress Site Address (URL): http://www.mydomain.com


wp_query within function within wp_query

I have a query which looks like this:               $args = arguments for the query     $query = new WP_Query($args);          while ($query->have_posts()): $query->the_post();     $post_id = get_the_ID();     echo my_function($post_id);     endwhile; wp_reset_query(); endif;      Then in `my_function` there's another query with a second function. This second function uses the `post_id` as input:               $args = arguments for the query, using `$post_id` as input     while ($query->have_posts()): $query->the_post();     // Do stuff     endwhile; wp_reset_query(); endif;      The problem is that the output of the first query (which uses `my_function`) isn't correct. The query in `my_function` seems to mess up the loop. As you can see I use `wp_reset_query()` and I've also tried `wp_reset_postdata()`. `my_function` outputs some post information, among which the title. It displays the title of the current page (the page on which the query is) instead of the title of the post queried, so I think I'm missing something regarding resetting the query.


Display a portion/ branch of the menu tree using wp_nav_menu()

I have a menu defined in WP Admin that looks like this: ![alt text](http://i.stack.imgur.com/XnmMh.png) I want to be able to display all the child links on the sidebar whenever I am at a parent page. For example, if the user is on my "About Us" page, I want a list of the 4 links highlighted in green to appear on the sidebar. I looked at the documentation for wp_nav_menu() and it doesn't appear to have any built-in way to specify a particular node of a given menu to use as the starting point when generating the links. I created a solution for a similar situation which relied on the relationships created by the page parent, but I am looking for one which uses the menu system specifically. Any help would be appreciated.


Link Attachment Image to Category

How do you link an attachment image to its category?               function wp_attachment_image($size = thumb) {         if($images = get_children(array(             'post_parent'    => get_the_ID(),             'post_type'      => 'attachment',             'numberposts'    => -1, // show all             'post_status'    => null,             'post_mime_type' => 'image',         ))) {             foreach($images as $image) {                 $attimg   = wp_get_attachment_image($image->ID,$size);                 $atturl   = wp_get_attachment_url($image->ID);                 $attlink  = get_attachment_link($image->ID);                 $postlink = get_permalink($image->post_parent);                 $atttitle = apply_filters('the_title',$image->post_title);                      echo ''.$attimg.'';             }         }     }     wp_attachment_image('thumb');


Custom post type archive page pagination

I have set up an archive page for my custom post type `reference`, where I use a query to get all posts of type `reference`. This works, but when I try to paginate the result, it doesn't work. Right now, it doesn't even print out the pagination links. EDIT: This was earlier used on a regular page, but I changed it to an archive page. That's when the pagination broke. Here is the source code; Custom post type `reference` (plugin)               <?php        /*        comments here removed         */     ?>     <?php          /* Custom post types */     function create_references_post_type() {         $labels = array(             'name'               => __( 'References', 'kasparabi' ),             'singular_name'      => __( 'Reference', 'kasparabi' ),             'add_new'            => __( 'Add New', 'kasparabi' ),             'add_new_item'       => __( 'Add new reference', 'kasparabi' ),             'edit_item'          => __( 'Edit reference', 'kasparabi' ),             'new_item'           => __( 'New reference', 'kasparabi' ),             'all_items'          => __( 'All references', 'kasparabi' ),             'view_item'          => __( 'View reference', 'kasparabi' ),             'search_items'       => __( 'Search references', 'kasparabi' ),             'not_found'          => __( 'No references found', 'kasparabi' ),             'not_found_in_trash' => __( 'No references found in the Trash', 'kasparabi' ),              'parent_item_colon'  => '',             'menu_name'          => __('References', 'kasparabi')         );         $args = array(             'labels'        => $labels,             'description'   => __('All the references', 'kasparabi'),             'public'        => true,             'menu_position' => 5,             'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt'),             'has_archive'   => __('references', 'kasparabi')/*,             'rewrite'       => array('slug' => __('references', 'kasparabi'))*/         );         register_post_type( 'reference', $args );        }     add_action('init', 'create_references_post_type');          function add_post_type_to_query( $query ) {         if ( is_home() && $query->is_main_query() )             $query->set( 'post_type', array( 'reference' ) );         return $query;     }     add_action( 'pre_get_posts', 'add_post_type_to_query' );          ?>      The way I query for the posts:               $wp_query = new WP_Query(array(                             'post_type' => 'reference',                              'posts_per_page' => 9,                             'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1                          ));      How I print out the pagination links:               <div class="col-xs-12">         <?php previous_posts_link(__('← newer', 'kasparabi')); ?>              <?php if ($loop->max_num_pages > $paged) :             next_posts_link(__('older →', 'kasparabi'), $posts_per_page);         endif; ?>     </div>      And as a bonus question; is there another way to get the posts than creating a new query every time?


How to find if a post with custom_field == X exists?

I need to find if a post with a custom field X equal to Y exists in a wordpress installation. Should I do it with a simple sql query or is there something build in that can help me achieve it?


Allowing users to add HTML to BP Groups Description how can I error check html of users?

I am trying to modify the Group Description field on Buddypress Groups so that they can take HTML but Buddypress has filters to prevent this. I used this; remove_filter( 'bp_get_group_description', 'bp_groups_filter_kses', 1 ); remove_filter( 'groups_group_description_before_save', 'wp_filter_kses', 1 ); These are the filters applied: https://buddypress.trac.wordpress.org/browser/tags/1.5.4/bp-groups/bp-groups- filters.php I experimented with removing them and was able to get the form to accept HTML. BUT, the problem is if someone enteres broken html and leaves a closing tag out for example it breaks the page. I put it in protective Tags so the page wont break but the form itself can be broken with bad html being used in the form. So my question is, is there a way to do error checking on the html and prevent open tags and bad code from being submitted? Thanks!


Custom field for image, not showing image!

In wordpress 3 you can create your own custom content types (without plugins) natively. I have done this and created a new "add image" field. However, I'm having trouble displaying this image in my page. In the loop I am doing:               <?php echo get_post_meta($post->ID, 'banner_image', true); ?>      But, this just returns '49' (which I assume is the ID of the post). I have tried setting it to false as well, which when using var_dump() reveals an array only with this number in it. Where is the image path? Many thanks for your help. Michael. EDIT: Here's a screenshot of the admin area and the image I need to output in the loop: http://i.imgur.com/hsllK.jpg               <?php              query_posts(array(               'post_status' => 'publish',         'post_type' => 'work',          //'orderby' => 'title',          'order' => 'DESC'              ));              while (have_posts()) : the_post();               ?>              <?php if( get_post_meta($post->ID, 'show_in_home_banner', true) == "yes" ) { ?>

                 <a href="<?php echo get_page_link($post->ID) ?>">                                        <?php echo get_post_meta($post->ID, 'banner_image', true); ?>

<a href="<?php echo get_page_link($post->ID) ?>"><?php echo get_post_meta($post->ID, 'sub_title', true); ?>

<?php echo the_title(); ?>

              <?php } ?>              <?php endwhile; wp_reset_query(); ?>


Sort a custom post type array numerically

We've set up drop down lists to allow people to filter posts based on custom post types. In order to populate the drop down list I am using:               <?php $terms = get_terms("ratios");     $count = count($terms);     if ( $count > 0 ){      foreach ( $terms as $term ) {          echo "<option value='" . $term->slug . "'>" . $term->name . "</option>";      }     }?>     </select>      The slug and the name are pretty similar, so I don't mind which one we are using. How can I list them as integers? The site is here if you need more of an idea: http://amigaeng.com.au/gearbox- list/


How to set search query for joining two tables in sql?

What's the wrong with this query?               SELECT l.company_name,DISTINCT c.sub_cat_name FROM tbl_listing l,tbl_sub_category c WHERE l.company_name LIKE '%cy%' and l.city_id='2' and l.area_id=23 ORDER BY l.company_name      I am using auto suggestion search and i want to check two table data with single filed input So how to set search query for two table? When i am enter any word that time company name search and also check enter word related category so please help me...


Protect changes made to the theme when updating

I customized the wordpress theme I'm using by changing php, css and even a js file. Is there a way to protect these changes, when updating the theme to a new version?