Using wp_filesystem in Plugins

I wrote a plugin (https://github.com/bassjobsen/custom-bootstrap-editor) this plugin writes a stylesheet to `wp-content/uploads/cbe`. I will use something like the code below to do this:               $upload_dir = wp_upload_dir();     $this->folder = trailingslashit($upload_dir['basedir']).'cbe/';     if( !is_dir( $this->folder ) ) wp_mkdir_p( $this->folder );     if ( is_writable( $this->folder ) ){         file_put_contents( $this->folder.$this->filename, $css);     }      My first question about the above, what will be the best place to check if wp_upload_dir() is writable? Will there be a standard check (plus error) for this? After reading http://ottopress.com/2011/tutorial-using-the-wp_filesystem/ i got some other questions too. The post mentioned tell i should use the Filesystem API to replace the code above. Will this observation still be true? `request_filesystem_credentials` seems to work as expected but to login for every file change seems some kind of overkill. Could my plugin skip the login screen? Althought the credits seems valid my `$wp_filesystem->mkdir( $folder )` and `$wp_filesystem->put_contents( $folder.'/'.$filename, $css, FS_CHMOD_FILE)` seems always return false. How can i debug the Filesystem API calls? **update** thanks to @otto file writing works now:               if (isset($_POST['SaveCBESettings'])) {                  if ( !empty($_POST) && check_admin_referer( 'cbe-nonce') )              {                                $SaveCBESettings = 1;                 $in = true;                 $url = wp_nonce_url('options-general.php?page=filewriting','cbe-nonce');                 if (false === ($creds = request_filesystem_credentials($url, '', false, false, array('SaveCBESettings')) ) ) {                     $in = false;                 }                 if ($in && ! WP_Filesystem($creds) ) {                     // our credentials were no good, ask the user for them again                     request_filesystem_credentials($url, '', true, false,array('SaveCBESettings'));                     $in = false;                 }                 if($in)                 {                 // by this point, the $wp_filesystem global should be working, so let's use it to create a file                 global $wp_filesystem;                 $contentdir = trailingslashit( $wp_filesystem->wp_content_dir() );                  $wp_filesystem->mkdir( $contentdir. 'cbe' );                 if ( ! $wp_filesystem->put_contents(  $contentdir . 'cbe/test.txt', 'Test file contents', FS_CHMOD_FILE) )                  {                     echo "error saving file!";                 }                     unset($_POST);                 }             }     }


Conditionally load child themes

I am wondering how to conditionally load child themes? I have a site that is going to change with the seasons. The underlying architecture will remain the same, just different styles and a few minor changes. It seems that child themes is my best bet for this, vs using a bunch of conditional statements within my main theme and loading different stylesheets and what not. What I am stuck on is how to properly load a specific child theme based on a date?


How to pass a parameter to this add_filter example

I have a class with this function to provide a user language based on $user_id               function provide_user_language($user_id) {          return apply_filters('get_user_language',$user_id);          }      So in my script, I can simply get the user language by doing this:               $user_language=$this->provide_user_language($user_id);      But I need to associate this $user_language to a "set_current_language". I can do this by doing an add filter hook, but add_filter does not accept parameters. This is the add_filter line with the function itself but I don't know how to pass the $user_id or the $user_language so that set_current_language will be set to $user_language:               add_filter('set_current_language', array(&$this,'provide_user_language'));       I tried following this one but it won't work: Passing a parameter to filter and action functions I appreciate any tips. Probably there is an easy way.


Checking for existence of constants before defining them

I am seeing many plugins use the following format for defining their constant:               /* Set the constant path to the plugin's javascript directory. */     if( !defined( 'MY_ETS_JS' ) )         define( 'MY_ETS_JS', MY_ETS_URI . trailingslashit( 'js' ), true );          So basically there is a check before we define the constant. My question is why is this check necessary? What if I make a new version of the plugin and want to change the name of the javascript folder from 'js' to 'javascript'? I would have to include that change in an upgrade routine. Why not just define the constants without checking for their existence?


Display different header images based on current page

I want to display, based on the current page another header image. Short example:   * Home -> Image A    * PageId 1,2,3,4 -> Image B (2,3,4 are childs of page 1)    * PageId 5, 6 -> Image C   * ... I tried to edit the header.php of my theme, because there is the coding block which displays the header image:               <?php                         // The header image                         // Check if this is a post or page, if it has a thumbnail, and if it's a big one                         if ( is_singular() && has_post_thumbnail( $post->ID ) &&                                 ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( $header_image_width, $header_image_width ) ) ) &&                                 $image[1] >= $header_image_width ) :                             // Houston, we have a new header image!                             echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );                         else :                             // Compatibility with versions of WordPress prior to 3.4.                             if ( function_exists( 'get_custom_header' ) ) {                                 $header_image_width  = get_custom_header()->width;                                 $header_image_height = get_custom_header()->height;                             } else {                                 $header_image_width  = HEADER_IMAGE_WIDTH;                                 $header_image_height = HEADER_IMAGE_HEIGHT;                             }                             // echo "here";                             ?>                              <img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="" />                     <?php endif; // end check for featured image or standard header ?>      So I try to hook in with following elseif: _(I removed the`<?php ?>` for easier reading)_               if(is_home()){     <img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="" />     }else if(is_page(1){     <img src="http://.../ImageB.png" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="" />     }else{     <img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="" />     }      But that didn't work, instead no header image was shown. How can I achieve this? BR, mybecks


Post attachments doesn't show after manual db import

I have wp db exported from domain www.domain1.com. I did manual database import using phpmyadmin to domain www.domain2.com. In database for particular post on new domain I have attachment image link that points to www.domain1.com/wp-content/uploads/2014/01/1.jpg. In front end somehow that link is changed to www.domain2.com/wp-content/uploads/2014/01/1.jpg returning 404 for that image even if db has good link. What can I do to fix that issue? Just to be clear I need that link to point to old domain because I want to keep those images in one place


How to Javascript/jQuery

I am trying to turn an HTML 5 template into a Wordpress theme. The jQuery/Javascript combo seems not to be working, what should I do? (I just used `<?php echo get_template_directory_uri(); ?>` so the .js files are correctly linked)


How can I fix the even/odd child classes comments so that the comments are unaffected by the top-level even/odd?

Sorry if the title was confusing, I'm having a bit of trouble explaining here. I'm working on a theme for my site, and I'm using a slightly modified version of a custom comments template found here. The style I have in mind for comments is this:   1. Top Level comment 1 **1\. Child comment 1** _2\. child comment 2_ **3\. Child comment 3**   2. Top level comment 2   3. Top level comment 3 AKA I want the child comments to be even/odd, but I want the main thread comments all to be alike. My problem is that when a new comment is added at the top, the child comments get offset. So instead of being the above, it turns into:   1. Top Level comment 1 _1\. Child comment 1_ **2\. child comment 2** _3\. Child comment 3_   2. Top level comment 2   3. Top level comment 3 Which is undesirable. How can I make it so the child even/odd classes are unaffected by new main comments? Thanks.


Best way to extends core classes in theme?

I need to add functions to my WP_User objects, to be used like this :               <?php     // in my templates :     $user = new User($id);     $user->sendHelloWorldEmail();          // in my functions.php     class User extends WP_User {         public function sendHelloWorldEmail(){             // do stuff ...         }     }      My question is : what is the best way to overload Core Classes (WP_Post/WP_User...) ? And : is it a good idea, or is there a better way to achieve this (with objects programming) ?


An image on my site is showing as the wrong image

I have an image on my site, which is showing up as the wrong image. When I "inspect element" in chrome, and click on the link to the image, it shows up as the right image. How can this be? Here's the page: http://goinspire.com/israel-family-tours/ The image is the blue triangle that appears when you scroll down. The image: http://goinspire.com/wp-content/uploads/arrow2.gif Thanks!!


Custom bulk action for media gallery items

I'm trying to add custom "Bulk Actions" to WP 3.5 new media gallery items. I started from this excellent tutorial which does exactly what I need, but with regular posts; so i tried to adapt it to work with media gallery items. Starting from the original plugin code, here's what I came up until now (in my functions.php):               /*     Plugin Name: Custom Bulk Action Demo     Plugin URI: http://www.foxrunsoftware.net/articles/wordpress/add-custom-bulk-action/     Description: A working demonstration of a custom bulk action     Author: Justin Stern     Author URI: http://www.foxrunsoftware.net     Version: 0.1              Copyright: © 2012 Justin Stern (email : justin@foxrunsoftware.net)         License: GNU General Public License v3.0         License URI: http://www.gnu.org/licenses/gpl-3.0.html     */              if(is_admin()) {             // admin actions/filters             add_action('admin_footer', 'custom_bulk_admin_footer');             add_action('load-upload.php', 'custom_bulk_action');             add_action('admin_notices', 'custom_bulk_admin_notices');         }          /**      * Step 1: add the custom Bulk Action to the select menus      */     function custom_bulk_admin_footer() {         global $pagenow;              if($pagenow == 'upload.php') {             ?>                              <?php         }     }               /**      * Step 2: handle the custom Bulk Action      *       * Based on the post http://wordpress.stackexchange.com/questions/29822/custom-bulk-action      */     function custom_bulk_action() {         global $typenow,$pagenow;         $post_type = $typenow;              //if($post_type == 'post') {         if($pagenow == 'upload.php') {                  // get the action             $wp_list_table = _get_list_table('WP_Media_List_Table');  // depending on your resource type this could be WP_Users_List_Table, WP_Comments_List_Table, etc             $action = $wp_list_table->current_action();                  $allowed_actions = array("appr_1","appr_2");             if(!in_array($action, $allowed_actions)) return;                  // security check             check_admin_referer('bulk-posts');                  // make sure ids are submitted.  depending on the resource type, this may be 'media' or 'ids'             if(isset($_REQUEST['post'])) {                 $post_ids = array_map('intval', $_REQUEST['post']);             }                  if(empty($post_ids)) return;                  // this is based on wp-admin/edit.php             $sendback = remove_query_arg( array('exported', 'untrashed', 'deleted', 'ids'), wp_get_referer() );             if ( ! $sendback )                 //$sendback = admin_url( "edit.php?post_type=$post_type" );                 $sendback = admin_url( "post.php" );                  $pagenum = $wp_list_table->get_pagenum();             $sendback = add_query_arg( 'paged', $pagenum, $sendback );                  switch($action) {                 case 'appr_1':                          // if we set up user permissions/capabilities, the code might look like:                     //if ( !current_user_can($post_type_object->cap->export_post, $post_id) )                     //  wp_die( __('You are not allowed to export this post.') );                          $exported = 0;                     foreach( $post_ids as $post_id ) {                              if ( !$this->perform_export($post_id) )                             wp_die( __('Error exporting post.') );                              $exported++;                     }                          $sendback = add_query_arg( array('exported' => $exported, 'ids' => join(',', $post_ids) ), $sendback );                 break;                      default: return;             }                  $sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status',  'post', 'bulk_edit', 'post_view'), $sendback );                  wp_redirect($sendback);             exit();         }     }               /**      * Step 3: display an admin notice on the Posts page after exporting      */     function custom_bulk_admin_notices() {         global $post_type, $pagenow;              if($pagenow == 'upload.php' && isset($_REQUEST['exported']) && (int) $_REQUEST['exported']) {             $message = sprintf( _n( 'Post exported.', '%s posts exported.', $_REQUEST['exported'] ), number_format_i18n( $_REQUEST['exported'] ) );             echo "

{$message}

";         }     }          function perform_export($post_id) {         // do something         return true;     }      The code should do nothing (see perform_export() function) and return a "Post exported" message, but is not working. The new bulk actions correctly displays, but I get a security error ("Are you sure you want to do this?"). And if I disable the security check               check_admin_referer('bulk-posts');      I don't see the confirmation message. I think that my problems could be in this hook I'm using (I'm quite a noob in hooks handling!!)               add_action('load-upload.php', 'custom_bulk_action');      and in the $sendback variable which holds the page that handles the actual work:               $sendback = admin_url( "post.php" );      Can you help me firguring out which hooks and sendback page should I use? Thanks :)


Thickbox in Plugin settings page?

I adding the default wordpress thickbox in the admin page to show some information inside the div. Everything seems ok when i click that link it appear in popup now               Popup Load      But actually what i am trying is to show this popup when that plugin settings page load. I tried this way like what i mentioned here is                     But it shows like dim in settings page of my plugin how can i show the div content inside the popup automatically on settings page load. Any suggestion would be great.


How to get posts ordered by using their categories?

I have a page where I've got all the products on a single page. -- Link to the test site. What I'd like to do is to get the products ordered using their categories. _Juices, nectars, concentrates, etc._ The usual               $orderby =          id     name      slug     count     term_group       doesn't get them ordered the way needed. Is it even possible and if so, how would I achieve this? My products.php:               <?php     /*     Template Name: Products     */     get_header();     ?>
          <?php     $orderby = 'name';     $show_count = 0; // 1 for yes, 0 for no     $pad_counts = 0; // 1 for yes, 0 for no     $hierarchical = 1; // 1 for yes, 0 for no     $taxonomy = 'mahlakategooriad';     $title = '';     $args = array(     'orderby' => $orderby,     'show_count' => $show_count,     'pad_counts' => $pad_counts,     'hierarchical' => $hierarchical,     'taxonomy' => $taxonomy,     'title_li' => $title     );     $term_obj =  get_terms($taxonomy,$args);     $type = 'produktid';     $args = array( 'post_type' => 'produktid', 'posts_per_page' => 1);     $loop = new WP_Query( $args );     while ( $loop->have_posts() ) : $loop->the_post(); ?>         <?php         echo '
';         echo '
'.get_the_title().'
';         the_content();         echo '
';     ?>
<?php echo get_the_post_thumbnail( $loop->post->ID, 'tooted-big' ); ?>
     <?php     endwhile;     $args=array(         'post_type' => $type,         'post_status' => 'publish',         'posts_per_page' => -1,         'caller_get_posts'=> 1,         'orderby' => 'date',          'order' => 'ASC'      );     $my_query = null;     $my_query = new WP_Query($args);     if( $my_query->have_posts() ) {     ?>
     <?php          while ($my_query->have_posts()) : $my_query->the_post(); ?>         <?php          $toote_thumb = get_the_post_thumbnail( $page->ID, 'tooted-thumb' );          $toote_big = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'tooted-big' );         if ($toote_thumb) {             echo '
';             echo ''.$toote_thumb.'';         }         ?>         <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>" class="toote-title"><?php the_title(); ?>
         <?php         endwhile;     }     wp_reset_query();     ?>


Connect to database using wordpress wp-config file

How can I connect to the database using the wp-config.php file ? I'm trying to make a script more Wordpress friendly, and I need to connect to the database, but without installing the script as a plugin. Basically I have on my script               $host = "xxxxxxxxxxx"; //database location     $user = "xxxxxxxxxxx"; //database username     $pass = "xxxxxxxxxxx"; //database password     $db_name = "xxxxxxxx"; //database name          //Database Connection     $link = mysql_connect($host, $user, $pass);     mysql_select_db($db_name);      The script can not be installed as a plugin (which can make things more easy), so I need to connect to the database using the existing wp-config.php on the installation... Any ideas ??? Thanks in advance **Edit and Clarification** 1- I need to use wp-config.php as it is, no modifications. 2- The script will be located at www.example.com/script/ 3- It can't be done as a plugin since the core of the script require to be publicly accessed without any login screen jumping around. 4- My question basically is how to connect to the database using the wp-config.php file by modifying the script above.


How do you create %post_type%/%postname%/ permalink structure? **This is what is not working:** eg. ( domain.com/blog/ ) -> _"click on post"_ -> ( domain.com/post-name ) **How do I make "blog post" permalinks work like this...** eg. ( domain.com/blog/ ) -> _"click on post"_ -> ( domain.com/ **blog** /post- name ) * * * **Although other custom post types work?...** eg. ( domain.com/portfolio/ ) -> _"click on portfolio piece"_ -> ( domain.com/portfolio/project ) Also, should I reflush the Permalinks? Here is the Custom Post Types code & Taxonomies code in my functions.php file:                 // Add Custom Post Type "Portfolio"     register_post_type('portfolio', array(  'label' => 'Portfolio',     'description' => '',     'public' => true,     'show_ui' => true,     'show_in_menu' => true,     'capability_type' => 'post',     'hierarchical' => false,     'rewrite' => array('slug' => 'portfolio'),     'query_var' => true,     'supports' => array('title',     'revisions',),     'taxonomies' => array('Portfolio Category',),     'labels' => array (       'name' => 'Portfolio',       'singular_name' => 'Project',       'menu_name' => 'Portfolio',       'add_new' => 'Add Project',       'add_new_item' => 'Add New Project',       'edit' => 'Edit',       'edit_item' => 'Edit Project',       'new_item' => 'New Project',       'view' => 'View',       'view_item' => 'View Portfolio Piece',       'search_items' => 'Search Portfolio',       'not_found' => 'No Portfolio Pieces Found',       'not_found_in_trash' => 'No Portfolio Pieces found in Trash',       'parent' => 'Parent Project',     ),) );          // Add Custom Post Type "Testimonials"     register_post_type('testimonials', array(        'label' => 'Testimonials',     'description' => '',     'public' => true,'show_ui' => true,     'show_in_menu' => true,     'capability_type' => 'post',     'hierarchical' => false,     'rewrite' => array('slug' => ''),     'query_var' => true,     'supports' => array('title',     'revisions',),     'labels' => array (       'name' => 'Testimonials',       'singular_name' => 'Testimonial',       'menu_name' => 'Testimonials',       'add_new' => 'Add New',       'add_new_item' => 'Add New Testimonial',       'edit' => 'Edit',       'edit_item' => 'Edit Testimonial',       'new_item' => 'New Testimonial',       'view' => 'View',       'view_item' => 'View Testimonial',       'search_items' => 'Search Testimonials',       'not_found' => 'No Testimonials Found',       'not_found_in_trash' => 'No Testimonials Found in Trash',       'parent' => 'Parent Testimonial',     ),) );          //Add Taxonomy for Portfolio Category     add_action( 'init', 'portfolio_create_taxonomies', 0 );          function portfolio_create_taxonomies()     {         //Porfolio Category         $portfolio_labels = array(             'name' => _x( 'Portfolio Category', 'taxonomy general name' ),             'singular_name' => _x( 'Portfolio Category', 'taxonomy singular name' ),             'search_items' =>  __( 'Search in portfolio category' ),             'all_items' => __( 'All portfolio categories' ),             'most_used_items' => null,             'parent_item' => null,             'parent_item_colon' => null,             'edit_item' => __( 'Edit portfolio category' ),             'update_item' => __( 'Update portfolio category' ),             'add_new_item' => __( 'Add new portfolio category' ),             'new_item_name' => __( 'New portfolio category' ),             'menu_name' => __( 'Portfolio Categories' ),         );         register_taxonomy('portfolio-category',array('portfolio'),array(               'hierarchical' => true,             'labels' => $portfolio_labels,             'show_ui' => true,             'query_var' => true,             'rewrite' => array('slug' => 'portfolio-category')         ));     }      EDIT: I think this problem is occuring because of a template heirachy issue the blog page is using "index.php" when it should be using "template-blog.php" file.


template_include (overriding default plugin templates via current theme)

This is an extension of this question/answer. A comment on that question references that `template_include` is preferred to `template_redirect` when loading templates from a plug-in. However, hanging this to template_include is breaking everything on the site (any other page view) except the layouts that using the layout override http://pastebin.com/LWpSrfim but using template_include just prepends content (to any template files placed in the theme directory override) -- the standard single view for example is still output below. * * * ### Edit: source code               <?php     class moulding_templates {         public static function determine_template(){             global $post,$wp_query;                  // custom post types             $post_type_array = array('moulding_profiles','moulding_combination','moulding_collection','idea_gallery');             foreach ($post_type_array as $post_type_single) {                 global $post;                 if (is_singular($post_type_single)) {                     moulding_templates::loadSingleTemplate($post);                 }             }             // custom taxonomies             $taxonomy_array = array('profile_categories','combination_categories','wood_types');             foreach ($taxonomy_array as $taxonomy_single) {                 if (is_tax($taxonomy_single)) {                     moulding_templates::loadTaxonomyTemplate($taxonomy_single);                 }             }         }              private static function loadSingleTemplate($post) {             $template_name = 'moulding-templates/single-'.$post->post_type.'.php';             $template = locate_template(array($template_name), true);             if(empty($template)) {                 include(MOULDINGS_BASE_DIR . 'includes/' . $template_name);                 exit();             }         }         private static function loadTaxonomyTemplate($taxonomy) {             $template_name = 'moulding-templates/taxonomy-'.$taxonomy.'.php';             $template = locate_template(array($template_name), true);             if(empty($template)) {                 include(MOULDINGS_BASE_DIR . 'includes/' . $template_name);                 exit();             }         }     }     add_action('template_include', array('moulding_templates', 'determine_template'));


If Elseif Query

I'm trying to work this query - the first if clause works, and the else works, but the middle clause, elseif, doesn't work.               <?php if(get_post_meta($post->ID, 'TourURL', true)) {

Book or Inquire
                 This tour can be booked online.
          } elseif (get_post_meta($post->ID, 'bhid', true)){                 echo

Book
                 This tour can be booked online via the form on the right hand side of this page.
     } else {

                             Fill out my online form.
     }?>


What are 'authors' in Wordpress, and is there an author 'metabox class' available anywhere?

I am trying to outline a new project where I want to give my users the ability to customize their 'profile' pages in my website theme. Concepts like adding in their own background images, choosing templates etc. It seemed logical to me to store this information in the author meta, as that seems to be the only table that stores unique information for each user. Once I have input boxes setup then I can easily make the calls in my theme. Users don't appear to be post-types, or taxonomies, but I can't figure out what they 'really' are. Could someone take a moment to describe what 'users' really are in the eyes of WordPress? What I was ultimately hoping for is to find a class where I can easily add metaboxes to the edit author profile pages. I do know how to extend profile fields via forms, but I am looking for something much more flexible. *I use the farinspace metabox class for my post-types and absolutely love how it works, really hoping I can use something similar for the author pages.. Is any of this possible, or is there a better route I should take?


Can I create a new comment type?

I want to add different custom fields to comments that belongs to different user group, and display different types of comments in different ways. But WP has some default comment types that shows the type column probably is not for this job. Would anybody make this clear for me?


How to organise this data within WordPress

I have a dilemma in how the data in this scenario should be organised, as well as queried. The main elements in the scenario are the following:   * Competition   * Team   * Player Each player plays for one particular team. Each team participates in one or more competitions. First I'd like to know how this data should be stored within WordPress, using Custom Post Types, Taxonomies, or maybe custom tables? Next comes querying. Let's say I want to display all players who play in the |Eurocup| competition, and I also want next to each player displayed, his team name and info about team. Finally, the whole system should prevent redundancy of data. That is, if for example I remove a team from one of the competitions, the players within the team should be automatically disassociated from that competition. Same if the team description changes, the player list should also display the updated team description. Maybe there is a simple solution to this data storage and relationship in WordPress and I'm missing it, so I'd really appreciate some tips on how to implement this.


WooCommerce Always Include Shipping Information in Checkout

I have virtual products in my store but I still want to collect the shipping information from my customers so that I can mail them a card at the end of the year. But a cart with virtual products automatically hides the shipping information on the checkout page. How can I force the shipping fields to show up? Is there a hook I can use?


What is the difference between front-page.php and home.php?

When developing a theme wordpress grant us to use front-page and home page templates, so what is the major difference between these two templates as they seems like identical. I also want to know what will be the purpose of index.php file if we have front-page.php or home.php to work like our main index file, I mean server accepts the index file to index as main page or home page so if we name the file front-page or home how it will possible for site indexing.


add_action not using 'delete_post' action with wp_delete_post

I am using wp_delete_post function to delete the selected posts shown on the front-end (in my theme page). Posts are being deleted successfully.               // delete all selected posts     foreach( $_POST['list_id'] as $listID ) {        if( wp_delete_post( $listID ) ) {           echo 'hi';        }     }      In my function.php file i added the following hook for the delete_post.               // Delete Post Attachment     function abc_delete_attachment($post_id) {         $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null,                         'post_parent' => $post_id );          $attachments = get_posts($args);         if ($attachments) {             foreach ( $attachments as $attachment ) {                if( wp_delete_attachment( $attachment->ID,true ) ) {                   // Just to check if the hook is called or not i used wp_redirect                        wp_redirect(site_url());                }             }         }     }     add_action('delete_post','abc_delete_attachment');      But for some reason, this action is not being called. and the attachments are not being deleted permanently rather they are left unattached (the default behavior). Can anyone help me out?


How to reuse parts of WordPress site e.g. header, footer, part of header for multiple WordPress sites?

I am looking for a solution to reuse the header and footer navigation links (with style, of course) in one of my WordPress website for several other WordPress sites. Please note that I'm trying to share header and footer among WordPress sites, not from WordPress site to a PHP page. The sites I'm referring to are on the same server. I have the following directory structure:               example.com/ #main site is here        some-other-site/           wp-admin/           wp-content/           wp-include/           ...        wp-admin/        wp-content/        wp-include/        ...      I would really appreciate some direction on how to achieve this goals and best practices, if possible since I am still new to WordPress. I have a few ideas in mind but I am not sure which one is best programming practice or how much effort each approach requires (for cost benefit analysis) 1) Write a custom get_header() function in the main site's functions.php to allow extraction of navigation links file_get_contents() to get the navigation links from wp-content/themes/my-theme/inc/footer.php in some-other-site/ I use               define('WP_USE_THEMES', false);     require($_SERVER['DOCUMENT_ROOT'] . '/wp-blog-header.php');      Currently, I get `"<a href="<?php bloginfo('siteurl'); ?>/articles/category/editorial_team">Background</a>"` as output so it doesn't work for me yet. I found one similar topic but the question is a bit unclear to me and the solution of using absolute urls is not a good practice, I was told. 2) Expose those navigation links as web service. I have a feeling that web service is not even relevant here but I still put it here just in case. 3) Use Multisite settings or create a network for all my WordPress sites. While this appears to be the best way, it seems quite complicated and there are actually issues with my main site being setup in a network currently. I doubt it's necessary to got through this complication to achieve my goal. As far as I know, sites in WordPress network shares certain databases and therefore I'm so afraid of losing some or whole of the huge data in my main site. It would definitely be relevant to point out the best practices in sharing CSS stylesheets and Javascripts file among WordPress sits as well, if you are kind enough :) Sorry my long post. Thank you very much! Eric P.S.: Sorry for duplicating this post from StackOverflow.com. I have found the answers for all of my WordPress related questions on StackOverflow.com so far so I just don't know which is the more appropriate place to ask. Please advise if I need to merge the 2 topics on 2 sites. Thanks!


Next / Previous Posts not working

So I have a page that display posts from a certain category. If that is the category, its outputs one way, otherwise, it outputs another. The problem is, the pagination is only working on the 'other' catgeories. The code for the pagination, and all the data is exactly the same. The only things thats changing is the display. On the Category it doesn't work on, the pagination links appear, the url goes to the appropriate page/2, but the posts don't update to the second page of posts. Seems odd thats is the same code, and yet, one Category display fine and another doesn't Here's the gist of the code:               <!-- Grab the Category from Custom Field -->     <?php $category = get_post_meta($post->ID, 'Category', true); ?>     <?php $cat = get_cat_ID($category); ?>          <!-- Set up Paging -->     <?php $paged = (get_query_var('page')) ? get_query_var('page') : 1; ?>          <!-- Query Arguments -->     <?php $args = array(             'cat' => $cat,             'paged' => $paged             );     ?>          <!-- Query Posts -->     <?php query_posts($args); ?>          <!-- Begin Loop -->     <?php if (have_posts()) : ?>              <?php while (have_posts()) : the_post(); ?>                  <?php if ($cat == 1): ?>                                <!-- Print certain format -->                  <?php else: ?>                                <!-- Print in a different format -->             <?php endif; ?>              <?php endwhile; ?>              <!-- Posts Nav Links -->         <?php posts_nav_link(' | ', '« Newer Entries', 'Older Entries »'); ?>          <?php endif; ?>


I just did a clean install of Wordpress. But I have a problem when I install or use the WordPress API. So send me a sign > An Unexpected HTTP Error occurred during the API request. The strange thing is that I have looked everywhere. And the solutions do not work for me porponen Wordpress 3.2.1 and do not know how to solve the problem


Dynamic Title for custom post types

I use a custom post called "abschreibungstabelle". For all posts, I want to set the meta title dynamically: "This is a test: " & the post title Is there any easy way to do this: Actually I use the following snippet in my header:               <title>             <?php if ( is_plugin_inactive('wordpress-seo/wp-seo.php') ) {                    bloginfo( 'name' );                   } ?> <?php wp_title("|", true); ?>     </title>      The result is "post title" | my blog Thank you, cheers!


Add WP NONCE Inside Plugin Option Page

I have very simple plugin options page. Somebody told me this admin options page is insecure and vulnerable XSS Attacks. He told me to add **wordpress nonce** , where I should put it? and how to make sure wordpress nonce works to prevent XSS Attacks? **               <?php          /*     |--------------------------------------------------------------------------     | Sanitize and validate input.     |--------------------------------------------------------------------------     */       function mmdia_validate_options($input) {          // strip html from textboxes         $input['text'] =  wp_filter_nohtml_kses($input['text']);         $input['textarea'] =  wp_filter_nohtml_kses($input['textarea']);         return $input;     }          function register_easy_setting() {         register_setting( 'e_options_group', 'media_opt', 'mmdia_validate_options' );      }      add_action( 'admin_init', 'register_easy_setting' );               /*     |--------------------------------------------------------------------------     | Update / Reset Options     |--------------------------------------------------------------------------     */       function spgadmin() {     global $plugprefix, $opt;              if ( is_admin() && ( isset( $_GET['page'] ) == 'page_settings' ) && ( isset( $_GET['post_type'] ) == 'galleria' ) ){                  if ( isset( $_REQUEST['action'] ) && 'save' == $_REQUEST['action'] ) {                 $curtosv = get_option( 'media_opt' );                 foreach ( $opt as $val ) {                     $curtosv[ $val['id'] ] = $_REQUEST[ $val['id'] ];                     update_option( 'media_opt', $curtosv ); }                     header("Location: edit.php?post_type=galleria&page=page_settings&saved=true");                     die;                     }                      else if ( isset( $_REQUEST['action'] ) && 'reset' == $_REQUEST['action'] ) {                     restore_to_default($_REQUEST['action']);                     header("Location: edit.php?post_type=galleria&page=page_settings&reset=true");                     die;                     }             }                   add_submenu_page(             'edit.php?post_type=galleria',             __('Settings', 'mmdia' ),             __( 'Settings', 'mmdia' ),             'manage_options',             'page_settings',             'e_generate_form'         );          }               /*     |--------------------------------------------------------------------------     | ENQUEUE SCRIPTS/STYLES     |--------------------------------------------------------------------------     */               if ( is_admin() && ( isset( $_GET['page'] ) == 'page_settings' ) && ( isset( $_GET['post_type'] ) == 'galleria' ) ){              add_action( 'admin_enqueue_scripts', 'e_cp_script' );              function e_cp_script() {             wp_enqueue_script( 'jquery-ui-core' );             wp_enqueue_script( 'jquery-ui-widget' );             wp_enqueue_script( 'jquery-ui-mouse' );             }     }               /*     |--------------------------------------------------------------------------     | MAIN FORM      |--------------------------------------------------------------------------     */           function e_generate_form() {         global $plugprefix, $opt;         $i=0;          ?>
     <form method="post">

               <?php settings_fields('e_options_group'); ?>          <?php foreach ( $opt as $val ) {     switch ( $val['type'] ) {         case "open":         ?>         <?php break;         case "close":         ?>

               <?php break;     case 'text':     ?>
         <label for="<?php echo $val['id']; ?>"><?php echo $val['name']; ?>         <input name="<?php echo $val['id']; ?>" id="<?php echo $val['id']; ?>" type="<?php echo $val['type']; ?>" value="<?php if ( e_get_option( $val['id'] ) != "") { echo stripslashes( e_get_option( $val['id'] )  ); } else { echo $val['std']; } ?>" />      <?php echo $val['desc']; ?>

     <?php     break;                    case 'textarea':     ?>
         <label for="<?php echo $val['id']; ?>"><?php echo $val['name']; ?>         <textarea style="vertical-align:top !important;" name="<?php echo $val['id']; ?>" type="<?php echo $val['type']; ?>" cols="" rows=""><?php if ( e_get_option( $val['id'] ) != "") { echo stripslashes(e_get_option( $val['id'] ) ); } else { echo $val['std']; } ?></textarea>      <?php echo $val['desc']; ?>

          <?php     break;               case 'select':     ?>
         <label for="<?php echo $val['id']; ?>"><?php echo $val['name']; ?>          <select name="<?php echo $val['id']; ?>" id="<?php echo $val['id']; ?>">     <?php foreach ( $val['options'] as $option ) { ?>             <option <?php if ( e_get_option( $val['id'] ) == $option) { echo 'selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?>     </select>              <?php echo $val['desc']; ?>

     <?php     break;               case "section":     $i++;     ?>

<?php echo $val['name']; ?>
<input name="save<?php echo $i; ?>" type="submit" value="Save Changes" class="button button-primary" />

          <?php break;          }     }     ?>

              </form>
               <?php     }          add_action('admin_menu', 'spgadmin');                    ?>      **


Wordpress refuses to show oembed URL

I need WP to show an embedded representation of a url such as http://domain.com/1121 using oembed. I have setup http://domain.com/1121 with a discovery link:               <link href="http://www.domain.com/generator/oembed/?url=http%3A//domain.com/1121" rel="alternate" type="text/xml+oembed" />      I'm aware that WP no longer automatically discovers embeddable URLs, so I installed enable-oembed-discovery plugin to re-enable this feature. I have monitored my apache logs and confirmed that WP does hits the link to discover - so I guess the enable-oembed-discovery plugin works, but the URL is NEVER converted. I even wrote a plugin to whitelist my custom URL (really should not be needed since enable-oembed-discovery plugin should enable auto-discovery, but what the heck):               add_action( 'init', 'my_oembed_provider' );          function my_oembed_provider() {         wp_oembed_add_provider( 'http://domain.com/*', 'http://www.domain.com/generator/oembed/', false);     }      and still nothing. The API endpoint (http://www.domain.com/generator/oembed/) is hard coded to generate the following XML:                       <?xml version="1.0" encoding="UTF-8"?>             <OEmbed>                 <type>rich</type>                 <width>400</width>                 <height>342</height>                 <html><![CDATA[<b>HELLO WORLD FROM OEMBED </b>]]></html>             </OEmbed>      The API endpoint sends the right content-type header (`header("Content-type: text/xml");`) as required by the oembed spec The user adding the post has admin privileges and therefore is allowed `unfiltered_html` I'm out of ideas and at wit's end. What am I missing?


How can I enqueue protocol relative external (//ajax.googleapis.com/...) scripts?

According to the Codex, wp_enqueue_script supports protocol relative, or protocol agnostic external links: "Remote assets can be specified with a protocol-agnostic URL, i.e. '//otherdomain.com/js/theirscript.js'." But I'm not seeing it:               wp_enqueue_script('google-maps', '//maps.googleapis.com/maps/api/js?&sensor=false', array(), '3', true);      Output:               <script type='text/javascript' src='http://localhost:25898//maps.googleapis.com/maps/api/js?sensor=false&ver=3'></script>      Notice that the protocol relative URL is appended to the site URL.


Targeting custom post type

I have the following loop working as I want it but I need the 'activists' list item to include `<?php the_post_thumbnail(); ?>`. What would be the best way to write this?               <?php                  $terms = array('news', 'activists', 'resources', 'posts' );                  if ( !empty( $terms ) && !is_wp_error( $terms ) ){                      foreach ( $terms as $term ) {                          $my_query = new WP_Query('posts_per_page=5&post_type='.$term);                          while ($my_query->have_posts()) : $my_query->the_post();                          echo '
'; ?>                          <a href="<?php the_permalink(); ?>"><?php echo the_title(); ?>                          <?php echo '
';                          endwhile; wp_reset_query();                 }                  }                  ?>      Thanks in advance.


Widget dropdown always displays first option

I have a custom widget that I have made but whenever I change the dropdown value it always reverts to the first option when I save the widget. How can I have it display whatever option the user selects?                 // update widget       function update($new_instance, $old_instance) {             $instance = $old_instance;             // Fields             $instance['category'] = strip_tags($new_instance['category']);            return $instance;       }            // widget form creation       function form($instance) {         // Check values         if( $instance) {              $category = esc_attr($instance['app_category']);              $instance['category'] = strip_tags( $new_instance['category'] );         } else {              $category = '';         }         //Set up some default widget settings.         $defaults = array( 'category' => '');         $instance = wp_parse_args( (array) $instance, $defaults );     ?>
           <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e('App Category: ', 'AppManager_plugin'); ?>
<?php echo $category ?>

<?php echo $instance['category'] ?>
           <select id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('Category'); ?>" >             <?php foreach(get_terms('app_category','parent=0&hide_empty=0') as $term) { ?>               <option <?php selected( $instance['category'], $term->term_id ); ?> value="<?php echo $term->term_id; ?>"><?php echo $term->name; ?></option>             <?php } ?>           </select>


W3TotalCache and Javascript -- what should go where, when?

I'm just starting to use W3TotalCache and am a little perplexed by how I should load the gobs of javascript and CSS rendering on the site in the question. Adding some of the pre-minified jQuery scripts via the Minified wizard in W3TotalCache breaks them when loading on the site; same with CSS. When you have a boatload of modules, what are some good rules of thumb when moving around javascript/css for minification? Thanks!


Remove nav menu or menu item

I try to remove a nav menu programmatically but I didn't find the way to do it. I knwo how to create it but I don't know how to delete it... I've got the menu name and I wan't to delete it like in wp admin panel but programmatically. Or I want to delete all the menu item inside it.


Including 'cat' => $cat breaks meta_query

so, i have a custom loop that seems to be working everywhere but one place.               $args = array(          'post_type' => 'post',          'meta_key' => 'wpcf-post-weight',          'orderby' => 'meta_value_num title',          'meta_query' =>             array(                  array(                     'key' => 'wpcf-featured',                     'value' => -1,                 ),                 array(                     'key' => 'wpcf-news-expire-date',                     'value' => $today,                     'compare' => '>=',                 ),            ),          /*'cat'=> '8',*/          'posts_per_page' => 1      );     $alertloop = new WP_Query( $args );      with the cat=>8 commented out, the query vars look like this               Array     (         [post_type] => post         [meta_key] => wpcf-post-weight         [orderby] => meta_value_num title         [meta_query] => Array             (                 [0] => Array                     (                         [key] => wpcf-featured                         [value] => -1                     )                      [1] => Array                     (                         [key] => wpcf-news-expire-date                         [value] => 1383047207                         [compare] => >=                     )                  )              [posts_per_page] => 1         [error] =>          [m] =>          [p] => 0         [post_parent] =>       However, as soon as I uncomment the cat=>8, it's dropping the first meta_query.               Array     (         [post_type] => post         [meta_key] => wpcf-post-weight         [orderby] => meta_value_num title         [meta_query] => Array             (                 [0] => Array                     (                         [key] => wpcf-news-expire-date                         [value] => 1383046582                         [compare] => >=                     )                  )              [cat] => 8         [posts_per_page] => 1         [error] =>          [m] =>       This is in Wordpress 3.7. I don't think it makes a difference, but I tried rearranging the $args order, all to no avail. Any insight would be most appreciated. Thank you.


Facebook Share Thumbnail

From the past few weeks I am noticing that when I share my posts on facebook, the thumbnail is not coming, I am keeping a featured image for my posts, but when I share it on facebook it shares the link without thumbnail, I tried using several code which I found on google, but none of them works. I am using twenty eleven theme with latest WP Anyone who can help me?


wp_list_bookmarks display

I have a question about code on wordpress: I am trying to use code wp_list_bookmarks to list my featured communities that I have setup in "links categories." I want to be able to separate each link like the following: San Diego | La Jolla | Rancho Santa Fe | Del Mar I am currently using: `<?php wp_list_bookmarks('title_li=&category_before=&category_after=&category=21'); ?>` It does work, but displays like this:   * San Diego   * La Jolla   * Rancho Santa Fe   * Del Mar Again, I want this: San Diego | La Jolla | Rancho Santa Fe | Del Mar Any code recommendations?


Make parent categories not selectable

I'd like that my categories having child-categories don't be selectable on the post article page. What I want to do is to remove the checkbox before their label. I've looked the filter documentation but I wasn't able to find any filter that suits my need.


Show more than one category in custom coded breadcrumbs

I'm using a custom breadcrumbs (without plugin), and it outputs like this: **Home > Category > Post Name** So far so good, but there are posts with more than one category, so I was trying to modify it to look like: **Home > Category 1, Category 2 > Post Name** Here's the corresponding piece of code:                   $cat = get_the_category(); $cat = $cat[0];           $cats = get_category_parents($cat, TRUE, $delimiter);           if ($show_current == 0) $cats = preg_replace("#^(.+)$delimiter$#", "$1", $cats);           $cats = str_replace('<a', $link_before . '<a' . $link_attr, $cats);           $cats = str_replace('', '' . $link_after, $cats);           if ($show_title == 0) $cats = preg_replace('/ title="(.*?)"/', '', $cats);           echo $cats;           if ($show_current == 1) echo $before . get_the_title() . $after;      And here is the full code Thanks!


3.1 post formats and specific categories/custom taxonomies

Is there a way to have a specific custom taxonomy for new 3.1 post formats? Let's say for example we want to categorize the "gallery" post format with two categories —only available for those kind of posts— as in "portfolio" and "others". How can we do that? Going even further how can we sub-categorize those with a bunch of tags only available for those custom posts (as for example "people", "landscape", "cityscape", etc.)? Is it better to switch to custom post types + custom taxonomies to do this?


Add items to a menu dynamically

I'm doing a site in WP with dynamic and static content. I'd create the menu from the admin panel. I have 5 sections (Home, about, Boats, News(blog), contact). I'd create a custom post type with new taxonomies for the boats. What I want to do now is, display every new boat model as a sub menu of boats automatically. How can I do that?


Single Page Wordpress Theme - Using page templates

Well I am lost, its late and I have been searching google all night. Heres the problem I am running into. I am trying to create a singe page website using wordpress "pages". How I have initially setup the theme is there are several page templates for ex ('page-contact.php, page-gallery.php, page-map.php etc.'). Each of these page templates are customized with different meta-boxes and the corresponding page template calls those metaboxes and creates the page. This part is fine and the individual pages display well, however when I try to query all the pages to one single page, thats where I am having problems. So far I am able to get all the pages to display but only with one template so then my pages don't post properly with their custom meta and custom template file. I have attached the code below, I am wondering if there is a way to call a variable into the get_template_part('page', $template_name_of_page) to display the proper template for each page.                   <?php get_header(); ?>     <?php                $args = array (         'post_type'                => 'page',         'post_parent'            => '29',         'orderby'                => 'menu_order',         'order'                  => 'ASC',     );          $query = new WP_Query( $args );               if ( $query->have_posts() ) {         while ( $query->have_posts() ) {                  $query->the_post();                  get_template_part('page', 'countdown');         }     } else {          }               wp_reset_postdata();              ?>     <?php get_footer(); ?>      **_TEMPLATE HIERARCHY_** 1.LANDING PAGE OF WEBSITE - Want to pull all pages and display them with their individual template here   * LANDING PAGE - page-home.php (this has the above section of code)      * Portfolio - page-portfolio.php ( Child of Landing Page - has custom meta boxes called in template file )     * map - page-map ( Child of Landing Page )      * Contact - page-contact ( Child of Landing Page )


Hover images and Videos

I got this code to show video loops on my blog. It's working nicely. Function.php               function catch_video() {       global $post, $posts;       $first_vid = '';       ob_start();       ob_end_clean();       $output = preg_match_all('//i', $post->post_content, $matches);       $first_vid = $matches [1] [0];       echo '';     }      It is shown by the code in the loop: `<?php catch_video();?>` Now, I would like that when it was posted a featured image instead of the video, it showed a code of mouse hover (I already have it ready), so I created this code but something is wrong with it:               <?php $blog = new WP_Query($args); ?>     <?php while( have_posts() ): the_post(); ?>             <?php if(has_post_thumbnail()): ?>
                          <?php the_post_thumbnail('large');?>
                        <?php else ?>                <?php catch_video();?>             <?php endif ?>      Anyone knows what is wrong?


Get product category name in Jigoshop

I am using the Jigoshop plugin and I try to modify `single_product.php` file as:               <?php $pcatname="category-of-current-product" ?>     <?php echo do_shortcode('[jigoshop_category per_page="12" columns="8" slug="'.$pcatname.'"]');?>      But this is not working at all. I tried in all ways but it only works if I use a static category name. How can I use a dynamic category name?


Using the loop inside admin

I have the following issue: I am creating a custom-meta-box for the user to add custom fields in a friendly way.   I want to generate a drop-down box with all posts that fall under category 10.   I have created a loop inside the functions file for retrieving the posts I want and to create a dropdown select list. So when I go to admin -> posts and select a post to edit, I get the following issue:   the last post will load no matter which one I select. Here is the code used inside the functions file and then called when generating the html code for the custom meta-box:               function get_project_ids($proj_cat = 10) {          $output = '';          $catt = get_categories('parent='.$proj_cat.'&hide_empty=0');              foreach ($catt as $c) :                  $output .= '<optgroup label="'.$c->name.'">';             $d = get_categories('parent='.$c->cat_ID.'&hide_empty=0');                      foreach ($d as $e) :                 $output .= '<optgroup label="'.$e->name.'">';                          $args = array( 'nopaging' => true, 'cat' => $e->cat_ID );                     $project_query = new WP_Query( $args );                              while ( $wp_query->have_posts() ) : $wp_query->the_post();                             $project_id = (get_post_meta($post->ID, 'project_code', true) != "")?get_post_meta($post->ID, 'project_code', true):"";                             $output .= '<option value="'.$post->ID.'">'.$project_id.'-'.get_the_title().'</option>';                             endwhile;                           wp_reset_postdata();                     $wp_query = null;                     $wp_query = $original_query;                      $output .= '</optgroup> <!-- END level-b -->';             endforeach;                  $output .= '</optgroup> <!-- END level-a -->';         endforeach;          return $output;


Need to capture "keyword" added to the end of the post, even with "pretty permalinks"

I have a script that I wrote some time ago, and have just decided to "port" it into a WP plugin. Everything works great, except for one piece of vital core functionality. The script uses mod_rewrite to allow for virtual URLs to be used, that include a "keyword" that the script then uses later for other functions. In particular, it allows for URLs like this: www.domain.com/page-name/my-keyword/ it will then use "page-name" to generate the actual page content, and "my- keyword" is passed to other functions in the script for other purposes. If WP is on default permalinks, then everything works just fine. But as soon as "pretty permalinks" are in use, my rewrite rules conflicts with the WP rules, and this feature ceases to work. WP instead generates a 404 as you would probably expect, since the requested page URL doesn't exist. So I need a way to have custom permalinks enabled, such as /%postname%/ for example, but still be able to add information after the post name in the URL. My original script could even do this: www.domain.com/page-name/bunch/of/stuff/can-go/in/here/and/will/be/ignored/my- keyword/ and it would still use "page-name" for the content, and "my-keyword" as the keyword, ignoring everything between. I would like this functionality with WP as well but as yet have not been able to figure out the solution. Here's my script's original rewrite code:               RewriteBase /wp     RewriteCond %{REQUEST_FILENAME} -f     RewriteRule ^.*$ - [S=44]     RewriteCond %{REQUEST_FILENAME} -d     RewriteRule ^.*$ - [S=44]     RewriteRule ^(.*)$ index.php?k=$1&%{QUERY_STRING}      And here is what WP generates by default when I set my permalinks to /%postname%/:               RewriteBase /wp/     RewriteRule ^index\.php$ - [L]     RewriteCond %{REQUEST_FILENAME} !-f     RewriteCond %{REQUEST_FILENAME} !-d     RewriteRule . /wp/index.php [L]      I would prefer to not require the user to do any htaccess editing, handling this instead through my plugin itself if possible. Have gotten close but not quite there. Any ideas? Thanks! Jonathan


How to verify nonce from Bulk/Quick Edit in save_post?

I need to do something specific in my `save_post` callback for bulk and/or quick edits, so how do I check the nonce for that? I can only find `_wpnonce` in the `edit.php` html source, but can't find an action to match it with. I also tried `check_admin_referrer()` (no arguments) but it fails.   1. What nonce whould I check for? OR   2. Should I check for something else in `save_post` to know it's being fired from a a. bulk edit or b. quick edit action? I read that `DOING_AJAX` is there for quick edit, but is that enough on its own? what about for bulk edit?


How can I automatically delete comments that contain chinese / russian signs?

Once in a while, I get comments like these: > 苍天有眼啊,让我在有生之年得以观得如此精彩绝伦的帖子。 They are absolutely useless to me. I don't even know if it's Chinese / Japanese / Korean / ... How can I tell WordPress to automatically delete (not just spam) those messages?


Continue Reading link with the_content filter

I am trying to get the read more link with the `the_content` filter.               $post = get_post( $v['post_id'] );          $content = $post->post_content;     $content = apply_filters('the_content', get_the_content( 'More', false, $content ));     $content = str_replace(']]>', ']]>', $content);          echo $content;      But i get noting with this code but if i tried with :               $post = get_post( $v['post_id'] );          $content = $post->post_content;     $content = apply_filters('the_content', $content );     $content = str_replace(']]>', ']]>', $content);          echo $content;      I i get whole page content without read more / continue reading link :( Can anyone please help me to tell me where and what is wrong i have done in my first section code?


delay function on publish?

I have this function where I call a custom function through the add_action hook: `add_action('publish_post', 'custom_function');` ... now it works perfectly, but the I want the custom_function to be delayed so it runs AFTER the post has been published. BUT, if I add `sleep(20)` inside the `custom_function` it delays the post itself. What I want is the post to be published, and THEN run this function after x seconds. Thanks!


how to display post content without post image?

i've implemented a jQuery gallery for displaying several images within a post. the problem is that the_content(); also displays the post image. any ideas how to filter it? thanks


getting issue with custom advance fields plugin

I am using Magic Fields for custom fields. I am not able to retrieve data from my post type. I have this fields inside my post type: ![fields](http://i.stack.imgur.com/dgnVC.jpg) Now I have Page and Page template is releases.php Inside releases.php i have this code:

         <?php if(have_posts()): while(have_posts()) : the_post(); ?>         <?php             $data = get_group('Releases');             print_r($data);         ?>         <?php endwhile; endif; ?>

      You can I am trying to `print_r($data)` but nothing display from my page. I also refer this document but not worked for me. http://wiki.magicfields.org/doku.php?id=dealing_with_groups_duplicate_groups_and_duplicate_fields


How to store multiple input values with same meta_key

is there a way to store the input value from multiple custom meta box fields with the same `meta_key`? I use the following code to store ONE value for the `meta_key` 'startdate':               function startdate() {       global $post;       $custom = get_post_custom($post->ID);       $startdate = $custom["startdate"][0];       ?>          Startdate
     <input type="text" name="startdate" value="<?php echo $startdate; ?>"/>          <?php }          add_action('save_post', 'save_details');     function save_details(){       global $post;       update_post_meta($post->ID, "startdate", $_POST["startdate"]);     }      If i had a second input field, how can i store its value with a different `meta_id` but the same `meta_key` (startdate)? Thank you very much! _(If i use the built-in custom field functionality i can save multiple values for the same meta key...)_


Posts with duplicate meta descriptions

I am having issues with Duplicate meta description with posts on my wordpress site. When I create a new blog, the system creates duplicate links in webmaster tool. So for example, I create a new blog called new techniques, webmaster tools displays the following links domain.com/new-techniques/ domain.com/new-techniques/201310/ Both the links go to the same page. Seo plugin is All in One Seo Any clue why it is happening? Let me know if you need to view the actual links of the website! Thanks in advance


Wordpress post editor change & to &

Wordpress editor seems to change every ampersand (&) to & is there any way to get rid of that function or something? I really need the only & to make my variables work. Thanks!


get_posts() with pagination problem

     <?php         $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;         $args = array(             'category'      => '8',             'orderby'       => 'post_date',             'order'         => 'DESC',             'post_type'     => 'post',             'post_status'       => 'publish',             'posts_per_page'    => 9,             'paged'         => $paged,         );              $postslist = get_posts( $args );         foreach ($postslist as $post) :  setup_postdata($post);     ?>

<a href="<?php the_permalink() ?>"><?php the_title(); ?>

     <?php endforeach; ?>
          <?php wp_paginate(); ?>     <?php wp_pagenavi(); ?>     <?php next_posts_link() ?>     <?php previous_posts_link() ?>      The code above successfully list the most recent 9 posts, however none the pagination works. I have installed WP-Paginate and WP-PageNavi plugins for testing.


Does meta_query work within get_posts array?

I can't seem to get this to work — I'm trying to show posts that have the meta 'featured_image' value set to anything. From what I can tell, it's set up correctly, but I'm in a little over my head. Here's what I have:
       <?php         global $post;         $myposts = get_posts(array(           'showposts' => 5,           'offset' => 7,           'meta_query' => array(             array(               'key' => 'featured_image',               'value' => '',               'compare' => 'NOT LIKE'               )             )         ));         foreach($myposts as $post) {           setup_postdata($post);           $meta = get_post_meta($post->ID, '');       ?>
           <img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php if (isset($meta['featured_image'][0]) && !empty($meta['featured_image'][0])): echo $meta['featured_image'][0]; else: ?>/wp-content/themes/SSv2011/images/review-default.gif<?php endif; ?>&w=84&h=60" alt="" />
       <?php unset($myposts); ?>       <?php } ?>
      Updated to show the entire query. Any ideas? :\ * * * Updated to WP_Query and I'm getting posts to appear, but they're not ONLY posts that have something inside 'featured_image'. Any ideas with that? The new query:                     <?php           $args = array(             'showposts' => 5,             'meta_query' => array(               array(                 'key' => 'featured_image',                 'value' => '',                 'compare' => '!='                 )               )           );           $ft_pagination = new WP_Query( $args );           ?>           <?php while ($ft_pagination->have_posts()) : $ft_pagination->the_post(); ?>             <?php $ftimage = get_post_meta(get_the_id(), 'featured_image', TRUE); ?>

                                  <?php if ($ftimage): ?>                   <img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo $ftimage; ?>&w=84&h=60" alt="" />                 <?php else: ?>                   <img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=/wp-content/themes/ssv/images/review-default.gif&w=84&h=60" alt="" />                 <?php endif; ?>

           <?php           endwhile;                wp_reset_query();           ?>


Menu li on hover reveals a Div styled with CSS special effects like transform shapes gradients or a background image

I was asked to make this a more obvious WP question, sorry. It is about the WP NAV MENU I think... Is there a way to have every menu item get listed and have a div correspond to it that is within the CSS range to influence the div via css? This is an important WP feature that must be possible with the WP Nav Menu. Here is my question earlier: I can not figure out how to make a div appear when user hovers over a menu item. I made Divs that cover the menu items. Then I made Divs right under those Divs that change with the transition, transform and gradient attributes using CSS. I understand that the Divs that are changing, are functioning because of their placement, because they are right under the MenuCover Div that gets hovered over. So when my CSS says: #cover1:hover + #hilite1 {whatever-transition} it is because the hilite div is right under the cover div that this can work. When I say "right under," I mean that the Div that changes is just under in terms of it's Html/CSS hierarchy. The visual location of the Div is placed using absolute positioning -- somewhere that looks good (not visually right under the menu item). (The divs appear due to the CSS transformations using the hover attribute.) Anyway, I would like to have the Divs, the ones that appear, do their tricks because of the user hovering over the li (menu item), not over my div cover! But I can figure out how to write the code. I have read all about wp_nav_menu and looked into how to make a menu, but I do not see an open spot in the code where I can attain this aim. Am I missing something? It works with the darn menu cover divs, why can't I get it to work with the menu itself? I want to do this with CSS and would accept Java. I tried it with Java and found a little success but I did not perfect it. Another main problem is that when the special effect divs appear, they Cover the Menu Item (and my menu div covers), so the Menu itself can not be clicked. I am using the z-index to create these layers. Is there a way to trigger the menu item when the user clicks on the div? I would prefer that the special effects div appears, covers the menu item AND when the user clicks on the Div, the click is received by the underlying menu! Looking into this I found a pointer attribute in CSS that may not work with all browsers.... I think this problem is one that others would also need solutions for, so I am posting this with great hopes. (I am messing with this here, and this example will be gone someday: http://seattle-edmonds-realestate.com )


Classic Custom Post Types and WP-PageNavi

Has anyone made this work? I am searching for a solution for 2 days now, and it won`t work. I have...               $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;     $updates = new WP_Query(array( 'posts_per_page' => 10, 'paged' => $paged, 'post_type' => array('review', 'news') ));      Then i begin the loop...                while ( $updates->have_posts() ) : $updates->the_post()      bla bla bla               <?php endwhile; ?>         <nav class="pagination">             <?php wp_pagenavi( array( 'query' => $updates ) ); ?>             <?php wp_reset_query();?>         </nav>      The thing is that pagination works (just because I don`t have a 404 page). The title is Page Not found - but the pagination works as it should. If i add the 404 page, I would just get the error. My website is http://fantappstick.com \- just in case you want to see this. I don`t know what else to do...


How to shorten length of auto generated password sent during registration?

is there a way to shorten the length of the 'auto generated password' which is sent during registration of a new user? I would like to shorten this password to 5 characters max and also remove the numbers '0' and '1' as they can be confused for letters 'O' and 'L'. My users are not very tech savvy and most don't know how to copy and paste a password. They type each character instead which can be time consuming and frustrating at the same time which is why I am looking to shorten the password. My wordpress version is: 3.5.1


Archive custom template from search

I'm using this code for a dropdown of categories. On selection of the dropdown the desired category is displayed using the archive template. I cannot for the love of me get the template hierarchy to work.               <form>     <select name="tag-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">     <option value='#'>Select Taxonomy terms</option>     <?php $taxonomies = array('service-category');     $args = array('orderby'=>'name','hide_empty'=>true);     echo get_terms_dropdown($taxonomies, $args); ?>     </select>     </form>      I am using a custom post type called 'services' and a custom taxonomy 'service-category'. Is there a way to tell the search to use a different archive.php template?


How to copy post titles to post slug in phpmyadmin

I just imported 1000 post into a custom post type on a site and the slugs are all blank. There is a problem with the importing plugin i'm using. My SQL is weak :-/ know what i need to do but not sure who to write the query. **I need help writing a query to run in phpmyadmin to copy post_title to post_name where post_type is people.** Thanks for the help


pre_get_posts : 'post__not_in' doesn't work with global variable

I'm trying to set a `post__not_in` which use a global `$popular` variable, defined in the `index.php`. -index.php-               $popular[] = 1 //post id=1     $popular[] = 2 //post id=2     $popular[] = 3 //post id=3      -functions.php-               function modify_query_exclude_popular($query) {         if ($query->is_main_query() && $query->is_home()){             global $popular;             $query->set('post__not_in', $popular);         }     }     add_action('pre_get_posts', 'modify_query_exclude_popular' );      I just can't make it work, the loop is working, but popular post_ids aren't exluded. I tried everything: define a constant, using "create_function" etc... PS: If I set `$popular` array inside the function `modify_query_exclude_popular()` it does work, but I absolutely need to set the array in `index.php` (the `$popular` use post_id of another loop).


Book plugin to record books read and write my own reviews

I trying to find a plugin where-by I can keep an inventory of all the books I have read (I currently record them in a paper dairy) and also write little reviews for them. I've seen a few plugins but they don't seem quite right for what I'm after. Some of the features I was interested in include:   * Categorizing my books by author, genre   * Being able to search my book library   * Being able to write my own review as well as point to official reviews   * Perhaps linking the book to an official page (much like the OpenBook Book Data plugin) I would use the OpenBook Book Data plugin but that doesn't seem to offer the search and categorizing capabilities I'm after. Does anyone know of any plugin that offers these features?


How do I access variables outside a function

I have a custom function which defines a bunch of variables. I would like to be able to call this function from inside a loop so I can have access to all its variables, like so: **functions.php**               function get_album_info() {       $album_art = wp_get_attachment_image_src( get_sub_field('album_art'), 'full' );       $album_date = get_field('album_date');       // ...10 more variables here     }      **Template**               <?php while (have_posts()) : the_post(); ?>            <?php       // Get all the variables here to use them below       get_album_info(); ?>            <img src="<?php echo $album_art; ?>">
<?php echo $album_date; ?>
          <?php endwhile; /* End loop */ ?>      I want to use a function here because I will be using it across several templates and don't want to have to define these multiple times. I know I can use global variables, but this requires having to include them at the top of the template, which means a lot of repetition across templates. What options are available to me?


Ordering by meta_key

I'm trying to order the main query on the 'Jobs' post type archive page. I want to order them by a meta_key so the ones which have a value (i.e. are checked as Featured') are shown first. Here's what I have at the moment..               function featured_jobs_order( $orderby ) {              if( !is_post_type_archive('jobs') ) {             return $orderby;         }              global $wpdb;         $orderby = $wpdb->postmeta . '.meta_value DESC, ' . $orderby;         return $orderby;          }          add_filter('posts_orderby', 'featured_jobs_order' );          function change_jobs_query( $query ) {              if ( is_post_type_archive( 'jobs' ) ) {             $query->set( 'meta_key', 'featured' );             return;        }     }          add_action( 'pre_get_posts', 'change_jobs_query', 1 );      At the moment it only brings back the ones that are featured and doesn't bring back the rest at all. Cheers, Steve


How can I make a widget to work only for the products from the current category?

I have an ecommerce wordpress website with Woocommerce plugin. On category pages, I have a widget that filters the products by attributes. But the problem is that the filter works for all the products from all categories, and I need it to work only for the products from the current category. Any idea regarding how can I make a widget to work only for the products from the current category?


Fastest Server Config, Whats your suggestion?

If you were configuring a new VPS for a WP website that hasn't launched yet, What technologies would you choose? (website specs below) **Website**   Targeting 50-60k hits /mo. and more The website is designed to categorize embedded YouTube videos using a chained select menu (1 query for multiple boxes). Using less than 5 "static" pages. I would like to keep the homepage fairly static so the server can cache it easier. **Server**   Starting with a Linode 512mb VPS, can scale up as needed. **What I have planned so far**   After scouring the web, it seems that Apache with an Ngnix reverse proxy does not offer any benefits with unless you need Apache for cPanel, or are more comfortable with it (i'm not, just starting out).   Latest Nginx   PHP-FPM   X-Cache   (also using W3 Total cache in WP)


Cannot upload to S3 using CDN Sync Tool

I'm trying to synchronise my files with the Amazon S3 server for distribution using CloudFront, as the CDN. I am currently having troubles syncing the files though. I've verified that the details are correct, though, when I click on sync it says it is syncing 1 item of many, but looking at the S3 bucket, it doesn't seem to do that. There are no errors in the PHP log to help me either. I'm running WordPress 3.1.2, on Windows Server 2008 R2, IIS 7.5 - PHP 5.3.6. cURL is installed, as per PHPInfo Any ideas what's going on here? Thanks, Shamil


Custom Taxonomy: Parent still counting deleted Child

I have this weird situation when I deleted two child taxonomies but they still seem to be assigned to their parent. I need a overview site for all our products with the taxonomy title ahead. If there is a child taxonomy the products should display under the child, and not under the parent taxonomy. **the code**               $args = array(         'type'                     => 'anco_produkt',         'orderby'                  => 'menu_order',         'order'                    => 'ASC',         'taxonomy'                 => 'produkt_category'     );      $taxonomies = get_categories($args);          foreach ($taxonomies as $taxonomy) {       if($taxonomy->parent == 0) {         echo '
'.$taxonomy->name.'
';       } else {         echo '
'.$taxonomy->name.'
';       }            // Get the children of current taxonomy       $tax_children = get_term_children($taxonomy->term_id , 'produkt_category');            if(count($tax_children) == 0) { // Are there children?         // Do something with the posts       }      It works great! But I have a taxonomy with two former child-taxonomies. I deleted them and assigned all the affected posts to the parent category, but the posts don't show up under the parent category. I tested if I get any children with:               print_r($tax_children);     echo count($tax_children);      And voilà, I get their IDs (19 and 22) and a count of 2 children for this "childrenless" parent. In the DB are no taxonomies/categories with these IDs. I tried `wp_delete_term()` and `wp_delete_category()`, this parent just can't let go of it's children :(( **the problem in action:** http://ch-de.ancotech.com/produkte/ **the taxonomies** ![the taxonomies I currently use](http://i.stack.imgur.com/DhKzw.png) There should be 15 products under 'Spezialbewehrungen'... Has someone a idea? Ps. Should I send the parent to therapy to accept the loss of its children?


Editing the contents of just one div on a page from wordpress

On the homepage of the design I am integrating into Wordpress, this little area (as highlighted in the attached screenshot) needs to be editable for the client to update whenever needed, now this is literally the only piece needed to be editable on the homepage, so I didn't think you'd need to create an entire page for the contents of this div, I however am unsure what's the normal/best approach to make this editable. ![enter image description here](http://i.stack.imgur.com/hXtzR.png) Suggestions welcome. Thanks. *My first Wordpress integration.


Prevent publishing the post before setting a featured image?

As the title says , I want a plugin/function to prevent/inform the user when he tries to publish the post without setting the featured image. ANY HELP ???


Best practice for including plugin output in a template without using shortcode?

I need your **recommendation for the best practice** here:   * A custom post type I have created needs a list of attachments at the end of the post content.   * I have created a series of functions that handle displaying the list of appropriate attachments for a post.   * I don't want to use shortcode to insert this attachment list, since every post of this post type should have the list   * I'm looking for a portable, reusable approach My initial approach was to encapsulate the attachment functions into a standalone plugin. But how to integrate the plugin output into the page if I don't use shortcode? My solution was to create my own pseudo-template-tag ("the_attachments()") which is defined in the plugin. Then my custom-post-type.php template page uses this pseudo-template-tag right after the_content() and we get our nice list. But is this really the best approach? Now we have a template that's dependent on an external plugin. If the plugin isn't there, the template "breaks". It's tough to "require" a plugin, from a template perspective because is_plugin_active() is only available at the admin level, and that's probably for a reason (because it's a stupid idea to make a template dependent on a plugin!) So I'm left with either: A) decouple the plugin output from the template, similar to the way a widget works (if so, how do I pass the $post information to that widget?), or B) embed the "plugin" code within the template functions (but is this then truly portable?)


Deleting Widgets in sidebar in Panthea theme

How can I delete the side widgets in WP Panthea theme. I have Search, Archives, Categories and Blog roll. I am used to HTML but am lost in Php. Thanks.


Order by custom field in query multiple

After performing this question, I went to the next step and I wanted to sort the query results by another custom field. I want to sort the results by a custom field that consists of a date and want to get the order from lowest to highest date The problem is that I do not get what I ordered. I've tried several ways with no success, I googled several sites and nothing. It gives me much trouble to ask you again but I can not solve this problem. Anyone can help me? : '( I leave my code to see where you should embed the orderby:                   $group_1 = get_posts(         array(             'posts_per_page' => 30,             'fields'         => 'ids',             'meta_query'     => array (                 array (                     'key'   => 'field1',                     'value' => 'data1,                 ),                 array (                     'key'   => 'field2',                     'value' => 'data2',                 ),             ),         )     );          $group_2 = get_posts(         array(             'posts_per_page' => 30,             'fields'         => 'ids',             'meta_query'     => array (                 array (                     'key'   => 'field1',                     'value' => 'data2',                 ),                 array (                     'key'   => 'field2',                     'value' => 'data1',                 ),             ),         )     );          $the_query = new WP_Query(         array(             'post__in' => array_merge( $group_1, $group_2)         )     );      Thanks!


How to Get Admin Settings for a widget when using the_widget() with custom widget

I have searched around for an answer to this question and I found this: Manual display of widget which gave me a solution of:               if(function_exists('the_widget')) {        $instance = get_option( 'widget_backspikewidget' );         the_widget('BackSpikeWidget', $instance[2]);     } Which works. But as the @greatwitenorth points out in his answer, it includes the issue that if the array key changes this solution breaks. So does anyone know of a more secure way to pull the settings for the widget set in the admin panel when using the_widget? EDIT: So I am not sure I was being clear enough in my question. Here is what I am doing. I am creating a plugin that includes a widget. The plugin is going to be used on multiple websites. Each user has a bunch of options they can set for the widget in their admin dashboard. I then want to make sure that the widget, with the users selected options, is always present on a page that is also created by the plugin. So I have hardcoded the widget in the page using the_widget() and I have grabbed the options set by the user to set up the instance of the widget to match the same configuration the widget will have if they install the widget elsewhere in the site. Is there anyway the user could break this without deactivating or uninstalling the plugin? Thanks again!


Pods - display link to relationship post

I'm using Pods to set up custom post types. I have two custom post types: Car and Garage. In Car I have set up a relationship field with Garage, so when editing a Car post I can select one of the Garage posts available from the drop-down. When viewing a car post I would like to display the name and the link to the garage post selected. How would I do that? Usually I would do like               $field = get_post_meta( get_the_id(), 'garage_name', true );     echo $field;      in template, but in this case I only get "array".


Latest news mini images

I tried to find an answer on websites and other forums, but found nothing. I will try to explain my problem. I need to change my WordPress website so that it displays a small image for all news articles, that is in the "latest news" on the main page. I'm using headway theme editor if that is important. upd: As was requested in the comments, here is my website.


Randomize Users

I'm trying to randomly display my users and I was wondering if I could edit the answer on this page to suit my needs (multiple users instead of a single user): Sidebar random author spotlight Here's my code (I can easily switch to `WP_user_query` if need be)               <?php         $args = array(             'fields' => 'all_with_meta',             'exclude' => array(1),         );         $users = get_users( $args );     foreach( $users as $user ) { ?>


How to exclude the word "class" from being matched in search?

I would like to exclude the word "class" from being matched to the search term "lass". On a site I'm helping manage, the search term "lass" is quite prominent. Unfortunately, that matches the common usage of "class" within the content of many, many WP posts, returning plenty of irrelevant results. However, I still want posts with the word "class" in to be possible matches, I just don't want it to match "lass" to "class". Here are three possible posts:               1.               Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum et veritatis pariatur deleniti excepturi beatae voluptatum aspernatur voluptates rerum numquam.          2.               Lass is lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum et veritatis pariatur deleniti excepturi beatae voluptatum aspernatur voluptates rerum numquam.          3.     Lass is lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum et veritatis pariatur deleniti excepturi beatae voluptatum aspernatur voluptates rerum numquam.      If I was to search for "lass", I would like results 2 and 3 to be returned, but not result 1. I've seen the excellent results in these two questions, but they didn't quite meet everything I'm looking for. Any suggestions would be appreciated.


Retrieve Image Attachments Getting Post Thumbnail Image First

I have written a funtion to get post image attachments, is there any way of ordering these images such that the first is always the post_thumbnail? Code below Thanks John               function oliver_single_gallery_thumbs() {          global $post;          $args = array(         'post_parent'    => $post->ID,          // For the current post         'post_type'      => 'attachment',       // Get all post attachments         'post_mime_type' => 'image',            // Only grab images         'order'          => 'ASC',              // List in ascending order         'orderby'        => 'menu_order',       // List them in their menu order         'numberposts'    => -1,                 // Show all attachments         'post_status'    => null,               // For any post status     );          $attachments = get_posts($args);         if ($attachments) {              $count = 0;             $the_thumbs = '
';             foreach ($attachments as $attachment) {                 $ze_count = $count+1;                 $the_thumbs .= '
';                     if ($count==0) {                         $thumb_attr = array(                             'class' => "image-radius selected",                         );                     } else {                         $thumb_attr = array(                             'class' => "image-radius",                         );                     }                     $the_thumbs .= wp_get_attachment_image($attachment->ID, 'single-thumb', false, $thumb_attr);                 $the_thumbs .= '
'."\n";                 $count = $count + 1;             }             $the_thumbs .= '
';         }         echo $the_thumbs;     }


How can I make an auto-fill search box auto-completing with the tags?

I want to mimic stackexchange's method of selecting tags by typing first letters. Any ideas? All instant search plug ins I tried dont work, dont know why. I have latest WP version.


Automatically create featured image on post publish

I know how to make an image display IN PLACE OF a featured image if the post has no featured image, however, as far as the database is concerned, the post still has no featured image. In my theme, everything looks fine, and the default placeholder image shows if a post does not have a featured image. However, there are some widgets and plugins I use which incorporate the use of the post's featured image. What I have been searching everywhere for is some way to actually legitimately set a default featured image when a post is published if it has no featured image specified. That way, instead of just SHOWING a image IN PLACE OF the featured image, it actually assigns a featured image to the post. I assume something in my functions.php and hook to the post being published, but I have no idea how to write this function, and have seen no such examples anywhere. How can I do this?


Custom taxonomy and post type with same slug

I'm using the plugin "types" to register the custom taxonomy and post types, and got 404 when using the same slug for them to display them hierarchy, like this:                site.com/tax    //taxonomy archive      site.com/tax/post-type    //entry      how to make this url structure work ? (notice i'm using a plugin to register tax, types and rewrite) Thanks


How to hide admin account in BuddyPress? (for security reasons)

I have been working with WordPress for the past 3-4 years, but I am new to BuddyPress. I would like to hide the admin account completely from BuddyPress for security reasons. For example with a regular WordPress blog I would have two separate accounts (one with admin privileges that remains hidden, and another one with only an Editor role to publish all the articles). That way the admin account would be hidden from the public and anyone trying to break in would have to guess both the password AND username. In BuddyPress this is not so easy, since the admin account is very much exposed to the public. One thing I managed to do is exclude the admin profile from the members directory by editing the /bp-themes/bp-default/members/member_loop.php file. (Yes I know I shouldn't edit the default theme and make a child theme or a stand alone theme instead! I will get to it once I get this resolved.) I added the &exclude=1 parameter (1 being the user ID of the admin account) as such:               <?php if ( bp_has_members( bp_ajax_querystring( 'members' ).'&exclude=1' ) ) : ?>      But I would need some help with the following:   1. ~~**Hiding the admin profile** (i.e. making it only visible to themselves, but not to anyone else).~~   2. **Preventing the admin's activity from appearing publicly on the site.**   3. Or did I miss something else as well? PS. I am thinking of installing BuddyPress in a MultiSite network so it is very important for me to not expose the super-admin account in such a manner. EDIT: So here is what I came up with for #1 (it goes into the theme's `functions.php` page):               // Hide admin profile pages     add_action( 'wp', 'hide_profile_template', 1 );     function hide_profile_template() {     global $bp;          if(bp_is_profile && $bp->displayed_user->id == 1 && $bp->loggedin_user->id != 1) :             global $wp_query;             $wp_query->set_404();             status_header(404);             include(locate_template('404.php'));             exit;         endif;     }      So now I still need help with **hiding admin activity** (#2).


including jquery

I know that wordpress ships with jquery. I have built my site first in html and every script that I have running in the html version works fine running version 1.4.2. I included this same jquery script and now one of my features don't work. This is how I am loading jquery into the head of my site               function register_savior_scripts(){         wp_deregister_script('jquery');         wp_enqueue_script('prettyPhoto', get_template_directory_uri().'/js/jquery.prettyPhoto.js', array('jquery'));         wp_enqueue_script('js-scripts',get_template_directory_uri().'/js/jquery.js');         wp_enqueue_script('slider', get_template_directory_uri().'/js/coin-slider.min.js', array('jquery'));     }     add_action('wp_head','register_savior_scripts', 0);      If I check the head, I see the script. It looks like this               <script type='text/javascript' src='full path removed/js/jquery.js?ver=3.4.1'></script>      It's not version 3.4.1. Not sure that matters. The script that it is running I put directly into the head and is this code               <script>     $(document).ready(function(){             $(".controls").click(function(e){                 if($(this).hasClass('down-arrow')) {                     $(this).addClass('up-arrow').removeClass('down-arrow');                 }                 else {                     $(this).addClass('down-arrow').removeClass('up-arrow');                 }                 e.preventDefault();                 $("#logo-background").slideToggle("slow");             });     });      Is there a better way to load the script above into the head? Do you know why it would work on the html but not wordpress? All it does is slide a div up or down to hide it if you press a link.


How to wrap an element around an iframe or embed in content automatically?

Id like to have wordpress automatically wrap a div around any `iframe` or `embed` when they are used in `the_content`...how might this be achieved?


WP_Query - meta fields numeric

I'm having trouble with the code below. Attempting to do a query against meta data stored with the posts, in the mls post type. I think I know what the issue is, but not how to fix it. I am guessing it has something to do with the value being stored as a string. I've searched and found other people confused about this, but not a solution. Here are two examples I've attempted with no luck.               <?php $args = array(             'post_type' => 'mls',             'meta_query' => array(                 relation => 'AND',                  array(                     'key' => '_city',                     'value' => 'Clarkson',                     'compare' => '='                 ),                 array(                     'key' => '_price',                     'value' => '200000',                                         'type' => 'numeric',                     'compare' => '>='                 )                 //array(                 //  'key' => '_price',                 //  'value' => array( 200000, 1000000 ),                 //  'type' => 'numeric',                 //  'compare' => 'BETWEEN'                 //)             )         ); ?>


Custom registration form page/template

I am trying to create a registration page on my site to allow visitors to register on the site and have access to special contents.   * I installed Cimy User Extra Fields to add extra fields to `wp-signup.php`   * In my registration page I make an Ajax call to `wp-signup.php` to grab the form and style it. The problem is that if registration fails (e.g. use an existing email in database), you are redirected to the default WordPress registration page, with the WordPress template... Is there a way to create a page for registration with extra-fields with a custom template? I've also tried using the Simplr User Registration Form plugin but is not working...