Event Calendar using insert_post_data after save_post and insert_post after post_transition draft_to_schedule

OK, I'm taking on the dreaded task of developing an event calendar for my site and have gotten a bit stuck. I'm open to any and all ideas but here's what I'm doing and what I'd like to do. I'm assuming that my main issue is the order of hooks and filters because i feel like I have a pretty good grasp on what I want to do. Also, I'd stick to wordpress hooks and filters rather than direct mysql database manipulation. The short is...   1. Save the first custom field and then change the current post_date to that custom field and change post_status to future, in that order, whenever a post is saved as draft or submitted for review.   2. Take the second custom field and insert a new post with that custom field as the date of the new post and change the post_status of the new post to 'future' and copy the title, content to that new post from the original post. (goal is to create an identical new post for each date submitted on the original post, make the new posts childs of the original post, and schedule them all as future posts) Now on to the long version. First, i have a custom post_type called 'events'. Registered for that I have some custom fields which for simplicity we'll call _start_date_one, _end_date_one, _start_date_two, _end_date_two. What I'd like to do is allow an 'events' post to be created and allow input of these fields, a title, and content. So far so good. Then when someone clicks "Save Draft" or "Submit for Review" I'd like to change the current post_date to _start_date_one and change the post_status to 'future'. Right now I can get this to occur only after the at least the second time I save most likely because I'm using add_action('save_post') to save custom fields and then add_filter('wp_insert_post_data') to update current post data I realize through some trac searching that insert_post_data happens prior to saving to allow me to update the $data and $postarr with new info and then saves the custom fields which is why the above happens. Number 2 listed above I've tried quite a few ways to get wp_insert_post to work but have only gotten to inserting a pending post with none of the dates correct and everything else copied. Any help is greatly appreciated.


where does my function output from load-* go?

I've got a function hooked into load-edit.php that prints out print content:               add_action('load-edit.php', array($this, 'generate_bulk_print_content'));          public function generate_bulk_print_content() {         //check for bulk action & print     }         I prepared the bulk action trigger with the following (common) hack:               add_action( 'admin_footer-edit.php', array(&$this, 'add_to_bulk_actions'));          public function add_to_bulk_actions() {         global $post_type;              if ( 'shop_order' == $post_type ) {             ?>             <script type="text/javascript">             jQuery(document).ready(function() {                 jQuery('<option>').val('custact').text('<?php _e( 'Custom action', 'woocommerce' )?>').appendTo("select[name='action']");                 jQuery('<option>').val('custact').text('<?php _e( 'Custom action', 'woocommerce' )?>').appendTo("select[name='action2']");                  });             </script>             <?php         }     }             all of this works like one would expect, except for the fact that I can _only_ see my print content when I do die() or exit() after the content. However, I would like this print content to be displayed in a thickbox on the admin page rather than on a new (otherwise empty) page. When I try to access the action variables in a different location, it cannot access the action variables anymore. What's happening in between my click on the action button and the next moment when I'm on the edit page again? Where does my print content go? Are there other ways to use the existing buttons and perhaps get my stuff into admin-ajax rather than the edit page (which is a full reload I think)? * * * edit: got a bit further, I realised I probably shouldn't use the default action of reloading the page when the button is clicked, and now I'm using the following JS:               $("#doaction, #doaction2").click(function (event) {         var actionselected = $(this).attr("id").substr(2);         if ($('select[name="' + actionselected + '"]').val() == "bulkprint") {             event.preventDefault();             var checked = [];             $('tbody th.check-column input[type="checkbox"]:checked').each(                 function() {                     checked.push($(this).val());                 }             );                  data = {                 action: 'bulkprint',                 orders: checked             };                  $.post(ajaxurl, data, function (response) {                 //how to output this to the standard thickbox?             });         }     });      Now the last piece of the puzzle is to get my ajax response into a thickbox. tb_show is not going to work because that requires a regular link, whereas I would like to pass post data to the admin-ajax (instead of using arguments).


External Rewrite Rules

I'm trying to add a rewrite rule to Wordpress. I want to rewrite: "http://www.domain.com/plm_check/var_a/var_b/var_c/" to actually use a file from "http://www.domain.com/wp- content/plugins/plm/webservices/plm_check.php?var_a=...&var_b=...&var_c=..." I've registered it like this:               /* Register rewrites for web service calls */     add_action( 'generate_rewrite_rules' , 'register_plm_rewrites');     function register_plm_rewrites() { //         global $wp_rewrite;               $wp_rewrite->add_external_rule( '^plm_check/([a-zA-z0-9_]+)/([a-zA-z0-9-]+)/([0-9]+)/?$' , PLM_PLUGIN_URL . 'webservices/plm_check.php' );              // Flush the rules         $wp_rewrite->flush_rules();      }      Instead of add_external_rule, I've tried add_rewrite_rule like this:               $wp_rewrite->add_rewrite_rule( '^plm_check/([a-zA-z0-9_]+)/([a-zA-z0-9-]+)/([0-9]+)/?$' , PLM_PLUGIN_URL . 'webservices/plm_check.php' , 'top' );      I've also tried it with and without $wp_rewrite. I think the problem is that Wordpress won't allow me to directly access that file as a URL. For instance, if I just put in "http://www.domain.com/wp- content/plugins/plm/webservices/plm_check.php", it takes me to the 404 page, even though the file actually exists. Am I using these functions wrong? Hooking to the wrong action? Trying to do something that WP isn't going to allow? Thanks!


Performance Gains of Relational DB Setup

Our team is working on the 3rd of large WP sites for a client, and contrary to most "typical" WordPress setups, our projects are generally experience lots of requests, data pulls, and general content - if you saw (and could see) our site, you would be hard [word]pressed to know it was even a WP site. I've been examining performance, particularly on the database level, and we've implemented some basic caching for larger data sets. My question is - would we gain much in performance by taking some steps to improve the database in terms of structure? Such steps would include:   * converting tables to InnoDB (our default is MyISAM)   * setting up proper foreign-key relationships, such as wp_postmeta.post_id => wp_posts.ID Those are the only ones I've come up with so far, but there may be others. I've done work with various SQL engines, but I'm by no means a master of optimization on the database level.


How to filter out an iframe from feed

Maybe i'm wrong but it seems that this question has not been previously solved yet: There is some iframe inside post content and I want to get rid of that iframe when the rss feeds are generated. To generate rss feeds, I'm showing full post content. I started looking at `strip_tags()` but it does pretty much the opposite: strip everything unless the desired tags. I'm wondering that maybe there is some hook and some wordpress-y form of solving this issue. I know I should do something like this:               function rss_noiframe($content) {         global $post;         // filter out iframe here         return $content;         }          add_filter('the_excerpt_rss', 'rss_noiframe');     add_filter('the_content_feed', 'rss_noiframe');      But I'm lost at this point. Any ideas? On demand by EAmann, here is some example code that isnt modified at all (it still appears in the feed, in fact):               <iframe src="http://somedomain.net/path/to/frame" frameborder="0" scrolling="no" width="500" height="375"></iframe>


Different profile page by role

I'm trying to set it so that when you view somebody's profile page you see a different template based on their role. So, everybody gets a regular "profile" page but if your also a author you also get a special "editor" page as well. Normally in Wordpress you get... www.mysite.com/author/person1 but what I want is... www.mysite.com/profile/person1   www.mysite.com/profile/person2   www.mysite.com/editor/person2 Below is what I've got so far in my functions.php file but the line that sets variable $curauth doesn't seem to work here. But it does work in my loop.php file???               function change_author_permalinks() {         global $wp_rewrite;              $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));         var_dump($curauth);         if ( !get_user_role( 'subscriber', $curauth->ID ) ) {             $wp_rewrite->author_base = 'editor';         } else {             $wp_rewrite->author_base = 'profile';         }              $wp_rewrite->flush_rules();     }     add_action('init','change_author_permalinks');


Next Ajax call doesn't work

I'm submitting a form via Ajax:                   <form id="ajax-form-next" method="post" action="">             <input type="hidden" name="nextPosts" id="nextPosts" value="<?php echo $postIDs; ?>"/>             <input type="hidden" name="actualPosts" id="actualPosts" value="<?php echo $actualPostIDs; ?>"/>             <input type="submit" name="next" value="=>"/>         </form>      In `functions.php`:               function theme_name_scripts() {              wp_enqueue_script( 'mi-script-ajax',get_bloginfo('stylesheet_directory') . '/js/ajax-search.js', array( 'jquery' ) );              wp_localize_script( 'mi-script-ajax', 'MyAjax', array( 'url' => admin_url( 'admin-ajax.php' ) ) );     }          add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );     add_action('wp_ajax_next_posts', 'next_posts_callback');     add_action('wp_ajax_nopriv_next_posts', 'next_posts_callback');          function next_posts_callback() {              global $post;         $nextPostIDs = array_map('intval', explode(',', $_POST['cadenaNext']));         $prevPostIDs = preg_match( '/[0-9,]/', $_POST['cadenaPrev'] ) ? $_POST['cadenaPrev'] : '';         $actualPostIDs = '';         $counter = 0;         $postIDs = '';         foreach ( $nextPostIDs as $key => $value ) {             $mypost = get_post( $value );             $counter++;             if( $counter <= 8 ) {                 $actualPostIDs .= $mypost->ID.',';                 // Page thumbnail and title.                 ?>                 <article id="post-<?php echo $mypost->ID; ?>" <?php echo $mypost->post_class; ?> style="display: inline-block; width: 20%; margin: 3px; padding: 0px; vertical-align: text-top;">                 <?php                 echo '
ID ).'">'.get_the_post_thumbnail( $mypost->ID, 'thumbnail' ).'
';                 $audioFiles = get_post_meta($mypost->ID, "pistas-de-audio-mp3", array('output' => 'html'));                 echo '
'.$audioFiles.'
';                 $audioFiles = get_post_meta($mypost->ID, "pistas-de-audio-ogg", array('output' => 'html'));                 echo '
'.$audioFiles.'
';                      add_filter( 'the_title', 'max_title_length', 30);                 echo '
';                 echo get_the_title( $mypost->ID );                 echo '
';                      //max longitud artistas                 $max = 20; //define your max characters here                     $terms = get_the_terms( $mypost->ID, 'Artistas' );                      if ( $terms && ! is_wp_error( $terms ) ) :                    echo '
';                   foreach ( $terms as $term ) {                     $term_name = $term->name;                     if( strlen( $term_name ) > $max ) {                       $term_name = substr( $term_name, 0, $max ). " …";                     }                     echo 'slug, 'Artistas' ).'" title="'.$term->name.'">'.$term_name.'';                   }                   echo '
';                 endif;                 echo '
';                 remove_filter( 'restrict_manage_posts', 'max_taxonomy_length');                 remove_filter( 'the_title', 'max_title_length');                  } else {                 $postIDs .= $mypost->ID.',';             }         }                  echo '
';                  //botones de siguientes y anteriores reviews             $actualPostIDs = substr( $actualPostIDs, 0, strlen( $actualPostIDs ) - 1 );                  if( $postIDs ) {                 $postIDs = substr( $postIDs, 0, strlen( $postIDs ) - 1 );             }             if( $prevPostIDs ) {                 $prevPostIDs = substr( $prevPostIDs, 0, strlen( $prevPostIDs ) - 1 );             }             if( $postIDs || $prevPostIDs ) {                      if( $postIDs ) {                     echo '<form id="ajax-form-next" method="post" action="">';                     echo '<input type="hidden" name="actualPosts" id="actualPosts" value="' . $actualPostIDs . '"/>';                     echo '<input type="hidden" name="nextPosts" id="nextPosts" value="' . $postIDs .'"/>';                     echo '<input type="submit" name="next" value="=>"/>';                     echo '</form>';                 }                 if( $prevPostIDs )  {                     echo '<form id="ajax-form-prev" method="post" action="">';                     echo '<input type="hidden" name="actualPosts" id="actualPosts" value="' . $actualPostIDs . '"/>';                     echo '<input type="hidden" name="prevPosts" id="prevPosts" value="' . $prevPostIDs .'"/>';                     echo '<input type="submit" name="prev" value="<="/>';                     echo '</form>';                 }                  }                  die();      }      And it works just the first time. The second time I submit the form, it is not sending an Ajax request. The original page is loaded. Any idea of what is going on? (I know I have to use nonces, but first I want to make it work) This is the `ajax-search.js` file:               jQuery(document).ready(function($) {         var cadenaNext='';         var cadenaPrev='';         $('#ajax-form-next').submit(function(e){                     e.preventDefault();                     jQuery.post(MyAjax.url, {action : 'next_posts' ,cadenaNext : $('#nextPosts').val(), cadenaPrev : $('#actualPosts').val() }, function(response) {                     $('#posts_container').hide(1000);                     setTimeout(function() {$('#posts_container').html(response).show(1000);}, 1000);                 });         });              $('#ajax-form-prev').submit(function(e){                     e.preventDefault();                     jQuery.post(MyAjax.url, {action : 'next_posts' ,cadenaNext : $('#prevPosts').val(), cadenaPrev : $('#actualPosts').val() }, function(response) {                     $('#posts_container').hide(1000);                     setTimeout(function() {$('#posts_container').html(response).show(1000);}, 1000);                 });         });          });


Wordpress Dashboard - Restricting Access

I'm new to WordPress and a bit confused with something. I'm trying to build a classified marketplace type of website for myself. I am NOT building this for a "client". I will probably be using a hack of several different plugins as my coding skills are not up to par. Eventually I will hopefully have lots of users who will be composed of buyers & sellers. My question pertains to the WP dashboard. When buyers/sellers sign up for my site, will they be able to see the WP dashboard? I would prefer that they NOT be able to access a back-end dashboard at all let alone a WP branded one. Is this possible? If so any clue as to how this might be accomplished?


How to display a specific post type name in a breadcrumb

I have this function:               function the_breadcrumb() {         if (!is_home()) {             echo "Start » ";             echo '';             bloginfo('name');             echo " » ";             if (is_category() || is_single() ) {             the_category('title_li=');             if (is_single()) {                 echo " » ";                 the_title();             }         } elseif (is_page()) {             echo the_title();         } elseif (is_single() && $post_type == 'partners') {             echo "IS THIS WORKING?";                 }         } elseif (is_home()) {         echo "Start » ";    bloginfo('name');         }     }      I also have created a custo post type called 'partners'. However, my breadcumb does not display my IS THIS WORKING TEXT Help appreciated. Alex


Problem with query_posts for a custom taxonomy in theme options

I am having some issues with querying the output of custom taxonomies in my theme options. I have included what I think are the necessaries below. Many thanks for your help in advance.               // Pull all the custom taxonomies into an array          $options_taxonomies = array();     $taxonomies_terms_obj = get_terms('portfolio_category');     foreach ($taxonomies_terms_obj as $taxonomy) {         $options_taxonomies[$taxonomy->term_id] = $taxonomy->name;     }          // Select a Featured Homepage Category          $options[] = array(         'name' => __('Featured Homepage Category', 'options_framework_theme'),         'desc' => __('Choose a category to feature on your homepage.', 'options_framework_theme'),         'id' => 'homepage_feature',         'type' => 'select',         'options' => $options_taxonomies);     }          //The query          if ( function_exists( 'of_get_option' ) ) :         query_posts( 'cat=' . $homepage_feature = of_get_option( 'homepage_feature' ) . '&posts_per_page=3' );


update_option() updating the option with an empty value?

I have a call to update_option() inside a class which edits some keys from the options array passed to it and then saves the updated array to the database, I don't have any fancy code, the function is only calling the `update_option()` function like this:               update_option( 'my_options', $this->updated_options );      Now this class is initialized in an admin page:               $instance = new My_Class($options_to_update);          $instance->init(); // the function that updates the option is called here      The thing is that `update_option()` is returning `true` and updating the option with an empty value. also I checked the array just before the call to this function and nothing is wrong:               print_r( $this->updated_options );      I also tried to update with a string:               update_option( 'my_options', 'any string' );      Now my questions are:   * Am I doing something wrong ?   * Is there a specific time to call `update_option()` ? because I have it in a function hooked to `admin_init` and it's working fine. **Update:** I found out that it's not working only if i's called inside the display function of `add_menu_page()` any reason why ? the passed value is always `null`.


Hereditary Subpages Nav

I'm trying to create an automatically generated navigation using Wordpress child pages - which will only show the next child pages down from the selected one (example page). You'll see that I can get it working using CSS rules for 3 generations of pages, but then I run out of child classes, so when it gets to 4th generation pages onwards it just show every child ... I'm possibly looking at it too simply just trying to use CSS to control this, but I can't find the WordPress PHP which will do this. Currently using:               <ul class="products-sidebar">         <?php         global $id;         wp_list_pages("depth=10&title_li=&child_of=10"); ?>     </ul>      Does anyone have any ideas please?


Pagination - works on local but not live dev!

Can anyone please shed some light as to why the following to print out page numbers works on my local dev server but not on my live server? Both server are running same version of PHP. My Loop               <?php     global $paged;     $args = array(         'orderby' => 'post_date',         'posts_per_page' => 5,         'paged' => $paged     );     $query = new WP_Query($args);     if($query->have_posts()) : while ($query->have_posts()) : $query->the_post();     //do stuff     endwhile; ?>      My Pagination               <?php echo '
     [First]';     for($i=1;$i<=$query->max_num_pages;$i++)     echo ''.$i.'';     echo 'max_num_pages).'">[Last]
     ';     endif;     wp_reset_query();     ?>      The issue clearly lies within:               for($i=1;$i<=$query->max_num_pages;$i++)      The first & last print out fine - the page numbers do not. Thanks in advance **EDIT** If i do this it works:               for($i=1;$i<=99;$i++)      So the issue is with:               $query->max_num_pages;      Any more thoughts?


Display custom text when comments are closed

When I close comments on a post it's showing "Comments are closed". Is there any way to edit this text and show a personal note instead of the pre- configured one? I would prefer to do this in a 'universal' type of thing, meaning that the same message would appear even if I change the wordpress theme.


Blur.js with WordPress - Enqueued, but server not finding file

So as the title suggests, I'm trying to run blur.js on my WordPress theme. I have enqueued the script in functions.php:                   function load_oves_methods(){         wp_enqueue_script( 'blur', get_stylesheet_directory_uri() . '/js/blur.js', array('jquery') );         wp_enqueue_script( 'flexcroll', get_stylesheet_directory_uri() . '/js/flexcroll.js', array('jquery') );     }          add_action( 'wp_enqueue_scripts', 'load_oves_methods' );      jQuery is loaded before this. In the header.php file, I am calling the blur.js function as such:               <script>     jQuery(document).ready(function($){         jQuery(".head").blurjs({             source:'body',             radius:5,             overlay:'',             offset:{                 x:0,                 y:0             },             optClass:'',             cache:false,             cacheKeyPrefix:'blurjs-',             draggable:false         });     });     </script>      The script is called after wp_head();. And the files in question are most assuredly on the server, in my themes /js folder. The error I get in the console is: "Failed to load resource: the server responded with a status of 404 (Not Found)" Previously I was calling said script via a tag in the header, and it was able to find the file, but it kept tossing errors in blur.js, and saying that it could not find the variable "jQUery", despite jQuery UI scripts working just fine on my theme. EDIT: Both scripts now have the array('jquery') dependency added to them, but still no dice. I have checked the file source via my browser and triple- checked all folder destinations - everything checks out as a-ok. My jQUery UI scripts work just fine, by the way, but neither blur.js or flexcroll.js work. Disabling plugins didn't have an effect, either. I checked file permissions as well, and those are set properly.


Localizing a string with html tag with word inside that tag

I have translated many string successfully previously, but this one gives me a headache. This part is used inside my content-related.php file which I use to display related posts Here is the current string I'm using `<?php echo 'Click <a href="'. esc_url( get_permalink() ) . '">here</a> to go and wacth the video.' ?>` My problem in the localization process is the `<a href="'. esc_url( get_permalink() ) . '">here</a>` part in the middle. The best I could come up with is `<?php printf(__('Click %s to go and wacth the video.', 'pietergoosen'), '<a href="'. esc_url( get_permalink() ) . '">here</a>'); ?>` OK, I know I can just create a variable for the `<a>` tag and rather use the variable in the `printf()` string instead of the whole `<a>` tag, but that is not the concern now, and that was only done to test the result first. With the string in its changed order, the string translates, except for the word "here" which is inside the `<a>` tag. How can I get the string to translate the word "here" as well. I've read somewhere, think it was in the Codex, that it is not a good idea breaking up a string into several strings as it may cause problems for certain languages as word order differ in some languages. Any more suggestions to solve this problem?


What are the disadvantages of using global variable?

I am a newbie at WordPress. In my "recent posts" shortcode, I used `global $post` variable, because `the_title()` function was giving me page's title, not post's title. I am not exactly sure, but I thought that's because of loop inside of a loop. Some advanced users here tell me not to use `global` variable, so using `global $post` variable inside my "recent posts" shortcode is good or not?


Redirect blog page to latest post?

How can I make it so when the blog link in the nav bar is clicked it redirects to the most recent post? I know how to display just the latest post on the blog page, but I want it to actually redirect to the post page itself as I'm displaying a full screen background image called in via a custom metabox on each post page. Is there perhaps a PHP query and redirect function I can apply to the blog page template, or is there a better way? UPDATE: the following redirect script works great but I just need a way to get the URL of the latest post:               $URL = "http://www.google.com";     wp_redirect( $URL, 301 );      exit;


Dynamically create check boxes for given post titles in WPAlchemy

I'm using WPAlchemy to create meta boxes. What I want to do is to dynamically create a group of check boxes with post titles. In other words, I want to replace `a`, `b` and `c` with the query of post titles.               <?php     $items = array('a', 'b', 'c');     while ($mb->have_fields('cb_ex', count($items))) {         $item = $items[$mb->get_the_index()];         ?>         <input type="checkbox" name="<?php $mb->the_name(); ?>" value="<?php echo $item; ?>"<?php $mb->the_checkbox_state($item); ?>/> <?php echo $item; ?><br/>         <?php     }     ?>      How can I do this?


ACF plugin categories bug in WordPress 3.9

i recently started using ACF plugin, i noticed that variables for custom fields i created and use in categories are saved in ‘wp_options’ tables, and although i am doing everything right they do not appear in the front-end i get a bool(false) for the field, i do not know if this has something to do with the WordPress update and the way it handles categories but i noticed that category metadata are stored in wp_postmeta table. So now i can not get the data to show on front-end everything works great in back-end. The interesting part is if i add the field in the first post of this category (maybe i should mention this is a custom section not the default category-post one that i use as a portfolio) the call on the category will start getting data, the ones that i specify on the post. Could anyone please help me or suggest anything else that i need to check, i am using WordPress 3.9 and ACF 4.3.6. This might even be a template related bug, but since i am not that familiar with WordPress architecture and i have yet to receive any answer from plugin developers i thought of asking here.


How to get specific string in explode array?

I have a shortcode where I'm trying to get a specific string from the $args array below. Query:               <?php     $args = array(     //'post_type' => $posttype,     'post_type' => explode( ', ', $posttype ),     );     $myquery = new WP_Query( $args );     ?>      Conditional:               <?php if( $posttype == 'cpt_press' ) : ?>       <?php the_content(); ?>     <?php else : ?>       <?php the_excerpt(); ?>     <?php endif; ?>      Shortcode:               [myquery posttype='cpt_press']      In the conditional above, I'm able to retrieve all posts with post type "cpt_press" if **I don't use explode**. The reason I used explode is so I could do this:               [myquery posttype='cpt_press, cpt_two, cpt_three, cpt_etc']      Any help? Thanks so much! UPDATED CODE BLOCK               <?php     function myshortcode( $params, $content = null ) {     global $post;     extract( shortcode_atts( array(     'posttype'      => '',     'meta_key'      => '',     'priority'      => '',     'meta_compare'  => '',     'layout'        => 'rows',     'cols'          => 1,      'tag'           => '',     'count'         => 10,      'orderby'       => 'date',     'order'         => 'DESC'     ), $params ) );          $args = array(     'post_type' => explode( ',', $posttype ),      );     $myquery = new WP_Query( $args );       ob_start();     ?>     <div class="row">     <?php     // The Loop     if( $myquery->have_posts() ) : while( $myquery->have_posts() ) :     $myquery->the_post();     ?>          <?php if( $posttype == 'cpt_press' ) : ?>       <?php the_content(); ?>     <?php else : ?>       <?php the_excerpt(); ?>     <?php endif; ?>          <?php endwhile; endif; wp_reset_postdata(); ?>     </div>     <?php      return ob_get_clean(); }     add_shortcode('myquery', 'myshortcode');


Define/declare new custom types with fields in plugin?

I want to develop a plugin using Pods but I want to create all the necessary custom types, fields, etc… on activation of my plugin. Is it possible? what are the good practices/approach? my plugin would depend on pods framework but everything done in code without the user having to create the custom types and fields via admin ui manually.


Adding onload to body

I'm currently trying to develop a plugin that will embed a Google Earth Tour into a WP post / page via a shortcode. The issue I am running into is that for the tour to load, I have to add an `onload="init()"` into the `<body>` tag. I can modify a specific template file, but since this is for release, I need to add it dynamically via a hook. Any ideas?


How can I make a Live Demo of my Premium Plugin? Are there security risks?

I'm glad to have the opportunity to ask my first question here. The scenario is this: My team and I released a Premium Plugin last week. We have since received a number of requests for a Live Demo. I'm considering creating a subdomain at demo.mysite.com, and modding the admin login page to display the demo username and password. Will it be sufficient, from a security standpoint, just to run it on a separate WordPress installation? Are there admin-level features I'll want to disable? I basically want the demo to be as realistic as possible without somehow compromising the security or integrity of my primary site. Any advice appreciated, SethMerrick


Random background image showing on website per click/load

Without using a plugin I would like to have a big background image changing on every click/load (or later on maybe every hour). So, I created a random_img.php file and put some code into header.php. Do not wonder about that header code! It is neccessary because some browsers (Safari, Chrome) otherwise do not accept background image changes because of caching purposes. random_img.php:               <?php     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");     header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1     header("Cache-Control: post-check=0, pre-check=0", false);     header("Pragma: no-cache"); // HTTP/1.0     header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past     header('Content-Type: image/jpeg');     $bilder = glob( "../is/images/*.jpg" );     shuffle( $bilder );     $zufall = imagecreatefromjpeg($bilder[0]);     imagejpeg($zufall);      ?>      head of header.php:               <?php echo '<style type="text/css">        body {background: url(http://www.xxx.de/wp-content/themes/is/random_img.php?'.rand().') no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;}     </style>'; ?>      This is working so far, but I have some problems/questions:   1. Right now I have declared a certain location for images with `$bilder = glob( "../is/images/*.jpg" );`, but this is bad, because once more I have to do something, meaning I have to upload pictures there. Instead I want to use a certain format/size, which I have defined before with `add_image_size( 'hintergrundbild', 1500, 1500 );` in functions.php. How to do/connect that?   2. Is there a cleaner way to do that instead of putting that line above into the head of header.php? I have a feeling, something is wrong about that, BUT on the other hand I could not find a solution for the caching problems with Safari and Chrome.   3. Instead on loading a new picture EVERY click/load, how to code it to change automatically every full hour or so? I think, that might be nicer and less aggressive. Thank you very much in advance, guys.


apply_filters, EMBEDS and AJAX not a friends?

I encountered a problem... There is content that contains a YouTube link > Lorem ipsum bla bla bla http://www.youtube.com/watch?v=nTDNLUzjkpg My plugin display this content with that code in the view:               <?php echo apply_filters( 'the_content', $data['meta']->start_page_content ); ?>      The problem is that if you open a page with usual GET method via the browser - the link becomes a YouTube player, but when i loaded the same template via AJAX - it seems that apply_filters does not work - at the output I get just a link, not a YouTube player code. How can i fix it?


Host a blog engine in my wordpress site

Hi I have a website like www.shankpress.com, it is wordpress v3, and i want my users to have blogs hosted in my site and have url like: blogs.shaknpress.com...and I can show who got the most popular blog entry etc... users can openly register, create a blog, start blogging and so on ... I am willing to buy solutions if no free stuff is available...


Featured Image Size

I am in the process of developing a new theme for my blog and am making a featured content slider. The issue that I am having is getting wordpress to force the image to the dimensions that I want it to be. The exact dimensions are 494px x 168px. I've tried simple using `the_post_thumbnail( array(494, 168) );`, but that didn't work. I also tried adding a custom image size to my functions file. This would sometimes get the height right (but not always), but didn't get the width right a single time. Could somebody please give me a way to force the dang image to be 494px X 168px?


Use translated taxonomy labels in plugin

I'm writing a plugin that works with taxonomy terms. It has, among other things, the capability to create new terms. I'm going to suppose that if users have custom taxonomies, they have taken care of having the singular and plural names set up and translated. The question is: How do I format my plugin messages to use translated labels for taxonomies? I need to output messages such as:   * "Created 1 category."   * "Matched 2 tags."   * "Updated 5 movies." (Supposing "movies" is a custom taxonomy.) In my understanding, the (translated) singular and plural labels for a taxonomy are available as `$term_object->labels->singular_name` and `$term_object->labels->name`. Is it correct to assume that these properties contain translated strings? Or is it necessary to wrap them with some i18n function? The `_n()` and the `_nx()` functions provide for singular and plural forms, but it doesn't make sense using them. I've been using:               $message = sprintf(          'Created %d %s',          count($created),          count($created) == 1 ?             $term_object->labels->singular_name             : $term_object->labels->name      );      What is the best practice here?


Gallery image doesn't show up after exporting and importing, how to fix?

I am trying to merge my multisite child sites to parent site. One of my blog (child site) is gallery based site and most of the post has wordpress media gallery attached to it. I have exported from the child site using wordpress export tool and imported using wordpress import tool. Import got failed at many times due to time out...finally one fine day that got imported, I have move all the media from child to parent (uploads folder) using c-panel, corrected urls. All feature image showing up, NextGen Gallary showing up but missing is images attached to post using wordpress media gallery. I am wonder if there is way to export media details and able to import so that all the media attachment information will be up again. Another thing what I notice is, post id are changing after importing to parent id, please please provide a solution.


How to change the order in which users are displayed in admin?

I would like to change the order in which users are displayed in the admin. At the moment it seems that they are order by the username. I think I have found the right place in the wp-admin/users.php, which is around line 187:               ORDER BY user_login");      I am not 100% sure if this is right as I don't know much about the code. Could anyone confirm if I am in the right place and what I should do to change the order. Also is it only possible that I could have an ascending or descending order for example, A,B,C,D,E or E,D,C,B,A? It would be idea if I could specify the order differently, for example, C,A,D,B,E or similar. Thanks


A function that returns true when the Author is a certain role is_author(admin)?

I need a function that returns true when the author is an admin or an editor or of a certain role. I can't use is_single because I have set up a forum and there are a million singles out there and I need a different layout for THE posts (the ones written in the blog by admins and editors) than from the forum entries


How to have "Page Title" different than "Menu Title" in wordpress 3.0.3?

I'd like to have the home page have a menu title of "Home" and a different page title "What we can do for you". How to do this without going into code. Is there any plug in to do this?


Count widgets of a certain type

How can I get the number (count) of, let's say, text widgets from a sidebar? for eg. if I drop 4 text widgets in the sidebar, I want to get this number somehow from another widget


How to Embed a post Automatically without having to write down the data all the time

hello when i click on create new post ![Wordpress](http://i.stack.imgur.com/YLVpE.png) I want this automatically Embed Is there any way i can do it ? So i dont have to manually do it all the time for creating new posts. Can you please help me?


Override Theme Customizer Cookie Expiration

I'm working on a Multisite network which has a forked/custom signup form. As part of the signup success process the user is automatically logged in, given a password, etc. I've got this all strung together successfully with `wpmu_activate_signup()`, `wp_signon()`, and `wp_redirect($newSiteAdminUrl . '/wp-admin/customizer.php')`. Unfortunately, while the user is logged in successfully (I can redirect them to the main dashboard without issue), the session is somehow immediately timing out and asking the user to log in, when they already are. Any ideas the source of this behavior? Part of me wonders if it's part of some behavior that pivots on a boolean related to "first-time logged-in users" and WordPress insisting they see the admin dashboard before anything else. Sorry I don't have any more info just now, would be grateful if anyone else has insight! ![screenshot](http://f.cl.ly/items/0L040K142Q072z3y2a2X/Screen%20Shot%202013-11-10%20at%201.52.27%20AM.png)


Fatal error after changes to functions.php, even with original file

Getting `Fatal Error: Cannot redeclare theme_feature_setup()` message after code changing in the functions.php file. I've tried deleting functions.php file and uploading the previous version but I still get the same error message.               define( 'WP_DEBUG', true );     define( 'WP_DEBUG_LOG', true );      included in config.php file. Also NO error.log file is created in wp-content. ERROR MESSAGE:               Cannot redeclare bean_feature_setup() (previously declared in htdocs/wp-content/themes/koi-child/functions.php:33) in htdocs/wp-content/themes/koi/functions.php on line 33      How should I proceed?


Delete posts without category with SQL

A website I am working on has a 'lost' category uncategorized. It got deleted and now I have thousands of posts without category. Those posts are old an need to be deleted. How can I do this with SQL if I don't have a term_ID? (term_ID = NULL). I need to delete the posts, the meta, and everything else connected to those posts.


Where is the "Posts"/"Blog" template?

I want to modify the "Posts" template. But I can't find it's location, I believe it's unrelated to my theme. Where is it located? Could I copy it and create an identical template in my theme so as to not mess around with the original?


Profiling wordpress performance

I am migrating a wordpress site from a shared hosting to a dedicated cloud virtual server. In theory the latter should be better however, with the same data, plugins and setup the cheap shared hosting has a much better response time. When I do Network profiling using Chrome, the shared hosting index page comes through in less than 2 seconds and the full document is loaded in less than 5 seconds. The new virtual server takes 7 seconds to deliver the index page's HTML and nearly 10 seconds to transfer the rest of the resources to complete the page load. There seems to be a bottleneck somewhere which I can't identify. When I put a simple PHP file doing something like `phpinfo()` it loads in a few milliseconds, so it doesn't seem to be a PHP issue. I have installed APC to supposedly improve performance (to no avail) and on both the shared hosting and the new virtual server I have W3 Total Cache configured too. The virtual cloud server is not loaded at all, CPU 99.3% idle with load average 0.01 if not less most of the time. Physical memory is not used up either (786Mb of 1Gb). When I used the Debug Queries plugin to find if Mysql was the problem it seemed that most queries return really fast and it gave this final report: `Page generated in 6.90618s, 94.32% PHP, 5.68% MySQL` Which seems to suggest that there is something not related to the database that is introducing delays. No idea what that 94% is doing. Is there a way to effectively understand what is going on in a situation like this?


"Price Not Announced" removal in JigoShop

Can you tell me How to remove **"Price Not Announced"** in JigoShop shop page?


Can you manage multiple domain names from a single WordPress multisite network?

My Main Purposes   * To centralise all of my WordPress sites (different domains - different clients) in one place controlled by the main dashboard. Be able to choose which site is in need of a theme, plugins, or core file updates.   * Saving loads of time by not updating and maintaining each site one by one.   * Only one core WordPress file update affecting the rest. Questions   1. Can I create a Network within the MultiSite (WP v3.7.1 to-date) configuration but NOT based upon subdirectories or sub-domain basis as each site has its own theme, plugin, and domain name: **Site1.com, Site2.com, Site3.com** for example?   2. The main site will not be under "root" directory but dwell within /subfolder instead, if the question#1 above is achievable, all the rest of the sites will be within /subfolder/wp-contents/theme << each theme per site in different folders, is it possible?   3. Is this the good solution in terms of a security issue as it seems all the sites are under one roof?   4. Each client, each site, each domain has their own login screen and could be able to claim their rights over their site only, what if they do have multiple users who need a log-in, will it mess up with another client site including my own main site as well?   5. Don't quite see the whole picture how InfiniteWP plugin could help me either to minimise the WP core installation or centralise all the sites in one place? Any recommendations in order to achieve all of my main purposes are welcome as it's quite a chaotic to update one by one and wasting hosting space by installing the core file on each site.


If Media Type .GIF

Been looking for a way to do this but cant seem to find anything, not even here. I am using timthumb to re-size my sites images. As most of you know after re- sizing a animated gif its not going to work any more. So i need a way to skip over the image if its a .gif file type. Something like               <?php if( typegif() ) { ?>     <img src="<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID),'full' ); echo $src[0]; ?>" alt="Image# <?php the_ID(); ?> "/>       <?php } else { ?>      <img src="<?php bloginfo( 'template_url' ); ?>/thumbs/timthumb.php?src=<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' ); echo $src[0]; ?>&w=280" alt="Image# <?php the_ID(); ?> "/>       <?php } ?>      After some more digging i found this code, however its not working.                 $attachment_mime = wp_check_filetype(wp_get_attachment_url($post->ID) );        if ( $attachment_mime['type'] == 'image/gif') {             echo 'this is gif';            }            else {            echo 'this aint gif';            }


Is it a bad practice to use switch_to_blog in the frontend?

From Wordpress Codex (although related to the same function in WPMU and not WP3.0+): http://codex.wordpress.org/WPMU_Functions/switch_to_blog it says: > _This switch is to be used for internal and admin area functions. It's too > expensive a query to run on the front end._ in the new page for the same function in WP3+ there's no such mention. So, is it a normal or a bad practice to use switch_to_blog in themes? I have a multisite setup with 4 blogs and would like to use this function often to pull content from one to another.


Is it possible to get_terms by author?

I get terms from all my posts with `get_terms`,               $tags = get_terms( 'mytags', '&number=5&orderby=date&order=desc&hide_empty=1' );     foreach ( $tags as $tag ) {         echo 'slug.'">'.$tag->name.'';     }      Is it possible to get_terms included to the posts made by author? I try to add a list with all the terms (tags) in author.php template, thanks a lot!


Testing performance of WordPress files

I would like to test the performance of PHP files in my installation, to find any bottlenecks. I already use plugins like Debug Queries and WPDB Profiler to watch the SQL Queries being generated, but I would like something that shows me the execution time of each php file to identify if some plugin is not optimised. Is there any plugin for this?


How to link to featured image to media file URL

I have enabled a function when I uploaded an image, it auto create a post with that image as the featured image. Now I wish to link to that featured image to that of the image file/media file URL so that lightbox effects can work on it. But not sure how to implement this? Any help will be highly appreciative. The function that I have used is -               add_action('add_attachment', 'create_post');     function create_post( $attach_ID ) {          $attachment = get_post( $attach_ID );          $my_post_data = array(     'post_title' => $attachment->post_title,     'post_type' => 'post',     'post_category' => array('0'),     'post_status' => 'publish'     );     $post_id = wp_insert_post( $my_post_data );          // attach media to post     wp_update_post( array(     'ID' => $attach_ID,     'post_parent' => $post_id,     ) );          set_post_thumbnail( $post_id, $attach_ID );          return $attach_ID;     }


Sorting Posts by Date - get_blogs_of_user_id()

I am a newbie who needs to produce a chronological list of recent posts from all sites to which a user is subscribed on a WordPress multisite network. Using the code below, I am able to produce a list where the posts are ordered chronologically (DESC) but grouped by site:   1. Site A Wednesday   2. Site A Tuesday   3. Site A Monday   4. Site B Wednesday   5. Site B Tuesday   6. Site B Monday I need to produce a list where all posts are ordered chronologically:   1. Site A Wednesday   2. Site B Wednesday   3. Site A Tuesday   4. Site B Tuesday   5. Site A Monday   6. Site B Monday                      $user = get_current_user_id();             $blogs = get_blogs_of_user( $user );                  if( $blogs ) {                  foreach( $blogs as $blog ) {                     switch_to_blog( $blog->userblog_id );                             $query = new WP_Query ('posts_per_page=2');                                     if ($query->have_posts()) :                                             while ($query->have_posts()) : $query->the_post();                                                  <li>                                             <a href="<?php echo $string; ?>$                                             </li>                                                   <?php                                             endwhile;                      $                     restore_current_blog();                                  }          }     ?>      ?> When I have attempted to apply 'order by' to the WP_Query using (new WP_Query( array( 'order by' => 'date' ), I'm producing the first list above (a list ordered chronologically, grouped by site). I have the feeling that I'm supposed to be sending the output of WP_Query to an array, sorting the array, and then printing this to the page, but as I am extremely new to all of this, I could really use some guidance at this point. Thanks.


A form in a custom widget

I'm trying to build a contact form custom widget. So i would like to display a contact form with a WordPress widget and send a message. No problem to display the form with my widget but when i click on the send button i can't retrieve my data. The isset($_POST['my_data']) doesn't work. When I put my form code out of the widget in a simple php file, everything is ok, the isset($_POST['my_data']) work well. I do the test with this simple snippet:               <?php          //$form_action = '';     $form_action = get_bloginfo('url').'#contactBox';          if (isset($_POST['send'])) {     echo "The isset 'send' work well      ";     $name = (isset($_POST['name'])) ? $_POST['name'] : '';     echo "name = ".$name." ";     } else {     echo "There is something WRONG !!!";     }          // Display the form     echo '<form method="post" action="'.$form_action.'">'."\n";     echo '
'."\n";     echo '  Name'."\n";     echo '  <input type="text" name="name" value="'.$name.'" />'."\n";     echo '
'."\n";     echo '
<input class="submit" type="submit" name="send" value="Send" />
'."\n";     echo '</form>'."\n";          ?>      Is it possible to implement a form with a WordPress custom widget ? This is the complete code of my custom widget with the contact form: www.pixenjoy.com/documents/widget.zip I add two echo messages in this code to test the retrieve of my data form (if(isset...) > line 145 "ok" line 190 "ko"


How do I get Link for Oldest Custom Post Type (dynamically)

Anyone know how I could take the below script that was answered for retrieving the latest permalink for a Custom Post Type and flip it to get the oldest post instead? This is the link for retrieving custom post type latest post


Adding extra info via GET while registeration in wordpress

i am trying to make a little referral sort of system for my site. so for that i settuped an extra parameter in the registeration url as : www.domain.com/wp-login.php?action=register`&register_me=site_name` and one is adding ip address while registeration, at first i thought it would be a simple form in wp-login.php but i just found out its all based on filters etc.. very complicated stuff. I did setuped two extra fields in the wp_user table. called `'reg_ip' and 'referral'` .. now i need to understand how to add these two things in wp-login.php so they will be inserted in teh database while registeration. Help is really really appreciated :) cheers Ayaz


Is there a way to 'Lock' a Taxonomy?

I was wondering if there was a way to prevent the addition of new categories into a taxonomy, essentially 'locking' the taxonomy. I'm programatically registering a taxonomy and filling it with terms via functions.php and would like it so you cannot add anymore into it. ## The Vision, REALIZED... Heres how my solution ended up looking, and it works great! THANKS to everyone who helped. Upvotes all over the place up in your face!               // some stuff happens before this...         $labels = array(             'name' => _x( 'Attendees', 'taxonomy general name' ),             'singular_name' => _x( 'Attendee', 'taxonomy singular name' ),             'search_items' =>  __( 'Search Attendees' ),             'all_items' => __( 'All Attendees' ),             'edit_item' => __( 'Edit Attendee' ),              'update_item' => __( 'Update Attendee' ),             'add_new_item' => __( 'Add New Attendee' ),             'new_item_name' => __( 'New Attendee Name' ),             'menu_name' => __( 'Attendees' )         );         $rewrite = array(             'slug' => 'attendee'         );         $capabilities = array(             'manage_terms' => 'nobody',             'edit_terms' => 'nobody',             'delete_terms' => 'nobody',             'assign_terms' => 'nobody'         );         $args = array(             'hierarchical' => true,             'labels' => $labels,             'show_ui' => true,             'query_var' => 'attendee',             'rewrite' => $rewrite,             'capabilities' => $capabilities         );         register_taxonomy('attendees', 'meetings', $args);     }     add_action( 'init', 'todo_create_taxonomies', 1);     function todo_register_attendees() {         $users = get_users();         foreach ( $users as $user ) {             wp_insert_term( $user->display_name, 'attendees', array('description'=> $user->display_name, 'slug' => $user->user_nicename) );             $lockdown[] = $user->user_nicename;         }         $terms = get_terms('attendees', array('get' => 'all') );         foreach ($terms as $term) {             if ( !in_array($term->slug, $lockdown) ) {                 wp_delete_term( $term->term_id, 'attendees' );                 $message = new WP_Error('force_terms', __('Only Registered Users can be Attendees, ' . $term->name . ' has been deleted.'));                 if ( is_wp_error($message) ) { ?>                     <div id="aphid-error-<?php echo $message->get_error_code(); ?>" class="error aphid-error">
<?php echo $message->get_error_message(); ?>

                 <?php }             }         }     }     add_action( 'admin_notices', 'todo_register_attendees' );


Show button only for certain Woocommerce Product Categories

I'm trying to add a button to my product pages which allows the user to request a sample, however I only need this to be seen on products within certain catagories. I've managed to get the button working by adding this code into the meta.php file:
     Request a Sample

<?php echo do_shortcode( '[contact-form-7 id="269" title="Request Sample"]' ); ?>

      But I'm not sure how to get it to only show on products within these categories. I tried wrapping my code in:               <?php if (in_category('11,12,13')) { } ?>      But this didn't work. I'm thinking maybe it's because my categories were created in woocommerce. Any help will be greatly appreciated! Thanks in advance! EDIT I've just tried this but still nothing...               <?php if ( is_product_category() ) {     if ( is_product_category( 'coving' ) ) {     echo '
Request a Sample

<?php echo do_shortcode( '[contact-form-7 id="269" title="Request Sample"]' ); ?>

';     } elseif ( is_product_category( 'skirting-boards' ) ) {     echo '
Request a Sample

<?php echo do_shortcode( '[contact-form-7 id="269" title="Request Sample"]' ); ?>

';     } elseif ( is_product_category( 'dado-rails' ) ) {     echo '
Request a Sample

<?php echo do_shortcode( '[contact-form-7 id="269" title="Request Sample"]' ); ?>

';     } elseif ( is_product_category( 'indirect-lighting-by-orac' ) ) {     echo '
Request a Sample

<?php echo do_shortcode( '[contact-form-7 id="269" title="Request Sample"]' ); ?>

';     } else {     echo ' ';     }          }?>      Anyone have any other ideas? Thanks


Separate Wordpress themes for each category page

I've read http://codex.wordpress.org/Category_Templates, which tells you how to change your index.php for each category. But I want to load a whole different theme directory in for my site when a particular category is viewed. So for example, if I go to: http://www.mysite.com/mycategory/ It will load a separate theme. Is this possible?


Multiple Category Query

Is it possible to display a wordpress category page but have it pull posts from mulitple categories? For example, let's say I need to pass in params for `cat_id` in this fashion               /category/dining/?location=2&activity=2      And have the resulting page produce a list of posts from the categories specified by `location` and `activity`. Thanks!


How to hook into unregistering a widget instance?

I would like to hook into a widget instance after it is removed from a sidebar panel on the Appearances -> Widgets admin page. So if the instance was an active widget and then removed, I would like to hook into that instance before it is removed. Can it be done?


Featured Image Size Conditional Tag?

Is it possible to check what image size has been selected for the featured image and only display that image.. For example.                   <?php if(has_post_thumbnail('small-image')): ?>                          <?php the_post_thumbnail('small-thumb') ?>small image is showing                  <?php elseif(has_post_thumbnail('full-thumb')): ?>                          <?php the_post_thumbnail('full-thumb') ?>large image is showing                  <?php endif ?>                  <?php the_post_thumbnail() ?>default image if none selected      Not sure if that makes sense..?


Conditional Ajax inclusion

I have a custom interface that uses 30+ ajax files while running...   some files are only used in category.php while othere's are only   used in page.php... i include the ajax loader php files in my functions.php file **example:**               include TEMPLATEPATH . '/ajaxLoops/ajax-open_client_editform.php';     include TEMPLATEPATH . '/ajaxLoops/ajax-submit_client_editform.php';      It all works great but when i tried to conditionally load them   using is_page or is_category directly in my functions.php the ajax   functions stop working. example:               if(is_page()) {         include TEMPLATEPATH . '/ajaxLoops/ajax-open_client_editform.php';     }         include TEMPLATEPATH . '/ajaxLoops/ajax-submit_client_editform.php';      i guess this is a matter of loading order or some other issues i am   unaware of.... Could you help me understand the problem with my approach   or an alternative way of conditionally loading this files?... Cheers,   Sagive. **EDIT 1 (.PHP AJAX LOADER FILE):**               <?php     wp_enqueue_script( 'ajax-simple-example', get_stylesheet_directory_uri().'/ajaxLoops/ajax-simple_example.js', array('jquery'), 1.0 ); // jQuery will be included automatically     wp_localize_script( 'ajax-simple-example', 'ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); // setting ajaxurl          add_action( 'wp_ajax_action_simple_example', 'ajax_simple_example' ); // ajax for logged in users     function ajax_simple_example() {              // just an empty example for my question         // in stackexchange              echo '
'.$successMsg.'
';              die(); // stop executing script     }     ?>


Apply permissions per post

We have a WordPress site where we have external authors for whom we have created usernames at the `Editor` level. We want these editors to be able to create new posts and modify their own posts, but occasionally we have posts in progress that we'd rather keep more private. It is a very small pool of users, and an even smaller number of posts to "protect," so I am okay with any technique that requires explicit GRANT for our own users or explicit DENY for the external users. DENY would be easier of course, but I am not going to get fussy.


Use PHP in stylesheet to specify a background image based on Category ID

In my stylesheet I'm hoping to use code like this...               background-image: url(/wp-content/images/' . $category->cat_ID . '.jpg);      ...to pull in a different background image for each category. So I'll have an image called 1.jpg and it'll show that image as the background to the li element I'm trying to style for Category 1. That approach works fine in template files like this...               <img src="/wp-content/images/' . $category->cat_ID . '.jpg">      ...but in the stylesheet it's not working for me. Any tips?


How to save WP widget instances and options

I'm a little confused about this, even though I have read all of the API and searched for hours. When I activate my plugin I add some values to the options database, e.g.               add_option('code','24');      How do I update that value or use it in the widget? I only see "instances" now, like the example on this page: http://wpcoderz.com/creating-a-multi-instance-widget-with-wordpress-2-8/ I don't really understand what instances are, the WP documentation doesn't provide much explanation about it.


how to stop wordpress from parsing specific urls?

I have this custom search url example.com/find?q=foo that I respond to by hooking into parse_request, but when, for example, echo some test phrase, WP still continues to parse that request and eventually throw 404 along with my echoed text. How can I stop WP from doing any sort of parsing on that specific url and instead do my custom handling and return my own template from plugin folder?


Delete old JetPack Site Stats? encrypted_search_terms in top search terms

I created a new baseball website. To create the site, I basically just duplicated my football site and changed/modified the theme. Being that I simply copied a site, all of the JetPack Site Stats reference the old football site stats. So, top posts, top seaches, total views, busiest, etc. all refer to the football traffic. How can I delete these old stats, everything prior to March 26, 2012? I should note that the old site used the Wordpress.com Site Stats plugin, but I updated to Jetpack after copying to the new site. I don't know if this makes a difference, but figured I should mention it. Also, encrypted_search_terms shows in the dashboard widget for "Top Searches". I imagine this is from the old search and traffic results. # UPDATE I contacted the JetPack developers about this. Their reply: > I can confirm that the two sites are establishing separate connections at > this point, so your stats should be correctly reported moving forward. > Unfortunately, there isn't a way to separate stats once they've already been > combined. > > In the future, please be sure to set up databases and install WordPress for > each instance separately. > > Feel free to drop us a line if we can be of any further assistance. I then asked: > Which table in the database controls the stats? So I can exclude it from > export when I decide to copy the site again? Their reply makes me believe that it is possible to remove old entries, but after multiple emails exchanged when I asked the initial question, they have not replied to my last question for three days.


404 error on homepage when using Nginx proxying to Apache

I generally use Nginx to serve static content on my server, with Apache handling PHP content using PHP-FPM. However, I'm not able to get a Wordpress blog homepage to display and I've tried all the configuration examples I can find on the web without much luck. Here is my Nginx config:               server {                  listen   XXX.XXX.XXX.XXX:80;             server_name wptest.mydomain.com;              access_log  /var/log/nginx/testblog_access.log combined;         error_log /var/log/nginx/testblog-error.log;              proxy_set_header X-Real-IP  $remote_addr;         proxy_set_header Host $host;         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;              location / {                         proxy_pass http://127.0.0.1:80;         }              location = /50x.html {                 root   /var/www/nginx-default;         }              # No access to .htaccess files.         location ~ /\.ht {                 deny  all;         }          }      My Apache config is as follows:               <VirtualHost 127.0.0.1>         ServerName wptest.mydomain.com         ServerAdmin webmaster@mydomain.com         LogLevel warn         ErrorLog /var/log/apache2/testblog-error.log         CustomLog /var/log/apache2/testblog-access.log combined              Options +FollowSymLinks +ExecCGI -Indexes -MultiViews         AddHandler php-fastcgi .php         Action php-fastcgi /wordpress         Alias /wordpress /var/www/wordpress         FastCgiExternalServer /var/www/wordpress -host 127.0.0.1:9000         RewriteEngine on              DocumentRoot /var/www/wordpress         DirectoryIndex index.php                              <Directory />                                 DirectoryIndex index.php                                 AllowOverride All                                 Options +FollowSymLinks +ExecCGI +SymLinksIfOwnerMatch                         </Directory>                              <Directory /var/www/wordpress>                                 AllowOverride All                                 Options +FollowSymLinks +ExecCGI +SymLinksIfOwnerMatch                         </Directory>     </VirtualHost>      I am not able to view "http://wptest.mydomain.com/" or "http://wptest.mydomain.com/wp-admin" but "http://wptest.mydomain.com/wp- login.php" does work. What am I doing wrong? Version information: + OS: Debian 5/Lenny + Apache: 2.2.9 + Nginx: 0.7.65 + Wordpress: 3.1.2


Wordpress and event-driven programming - what is it about?

I want to state very clearly that this does **not** intend to revive the discussion about functional/procedural programming versus object-oriented programming. There is plenty said about that, on WPSE and all over the net. **But** a while ago I'm reading over some of the discussions about the programming foundations of Wordpress and I read something - I have to rephrase because unfortunately I didn't bookmarked it at the time - roughly like this: > One of the appealing things about using Wordpress is that they are > additionally working based on the **event-driven paradigm** of programming. From what I understand _event-driven programming_ in this context is pretty much _synonym_ to _signal_ or _dataflow_ _programming_. Furthermore - most likely oversimplifying it a lot - maybe the main apparent characteristic is the use of _hooks_ - actions and filters - as linchpin for the method. So far so good. Seems easy enough, but I'm not coming from a computer science background, so I'm pretty sure there is more to be said. I'm really interested in some input, like: What is it really about or is the above said pretty much it? Is it an extra paradigm? How does it relate to the other ones? Is it a core principle or just an addition? Those are just off the top of my head, clearly breaching the rules, by not asking one singular question that has one distinct answer, but maybe this will be forgiven for once.


Wordpress cache a menu with Transients_API

I want to plain to cache a page menu, that takes about 50 queries on page load. At the moment i have cahche setting code with `Transients_API`               <?php                             $housemenu = get_transient('housemenu_key');                                          if (!$housemenu) {                                              $housemenu = wp_nav_menu( array('menu' => '','menu_class' => 'sf-menu','menu_id' => 'nav','walker' => new description_walker()));                                         echo 'not-set';                                              set_transient('housemenu_key', $housemenu, 60*60*3);                                     }                                  echo $housemenu;                             ?>      `$housemenu = get_transient('housemenu_key');` returns a nothing. If i set like this:               $housemenu = 'return corrent'l     echo 'not-set';      All works perfect. Why this menu is not working? Menu can be a walker transient? Use: Wordpress 3.8


is_home() returns TRUE on page template

I'm wondering why my link: `http://localhost/?page_id=3433` returns TRUE on `is_home()` usage:               if(is_home()){         var_dump(is_home());                                     die('test');                                 }      It clearly has template-mycustomtemplate.php set under Pages > This Page in Admin Panel. Can anyone shed some light on that? UPDATE: it returns TRUE in the loop but FALSE outside the loop. So, I can use workaround but nonetheless, it looks like a bug to me if it returns TRUE in the loop that is present in that template file.


Removing a post from the results of a WP Query

We have a complicated database query and we would like to exclude some posts. We've tried to do it with SQL, but it's really complicated. The simplest solution seems to loop through the results after the query's made and then exclude a few posts. The problem is, i don't know where to do it! I've tried to unset posts in $wp_query->posts, but they still show up. Is there a proper way to do this? Is there another array WordPress uses that I should unset from?


the_excerpt - want to modify password protected output

I'm looking to modify the output of the_excerpt when there isn't an excerpt specified and the post is password protected. I already can modify the password protected form to whatever I want, but the_excerpt is outputting "There is no excerpt because this is a protected post.". The code for this lies in wp-includes/post-template.php:               function get_the_excerpt( $deprecated = '' ) {         if ( !empty( $deprecated ) )             _deprecated_argument( __FUNCTION__, '2.3' );              global $post;         $output = $post->post_excerpt;         if ( post_password_required($post) ) {             $output = __('There is no excerpt because this is a protected post.');             return $output;         }              return apply_filters('get_the_excerpt', $output);     }      An easy solution would be to simply change the code in there and move on, but as well all know, changing core files deserves more than a slap across the face! Can anyone help me figure out how to modify this code in my functions.php file? Thanks! **EDIT** : Here's the code I tried out, but it isn't working :(               add_filter('get_the_excerpt', 'improved_get_the_excerpt');     function improved_get_the_excerpt( $deprecated = '' ) {         if ( !empty( $deprecated ) )             _deprecated_argument( __FUNCTION__, '2.3' );              global $post;         $output = $post->post_excerpt;         if ( post_password_required($post) ) {             $output = __('This is some test content.');             return $output;         }     }      I'm completely new to the concept of filters, actions, hooks, etc so please bear with me! I appreciate the help!


Display title for search engine visitors

I read somewhere*) that there's some `q` part inside the wp_query object, that identifies search engine visitors and shows the keywords they searched for. I'm currently developing local, so i can't access/see `$GLOBALS['wp_query']->q;`. Could someone varify if this exists and/or has some alternate solution for retrieving:   * the search engine _name_   * the _search string_ searched inside the engine? *) Can't remember where, but it had something to do with "better search results page" & "hightlighting search terms". -- **EDIT** -- This is what i got so far:               // declare the server itself as invalid to only catch search engine results     $http_referer   = explode( "/", $_SERVER['HTTP_REFERER'] );     $http_referer   = $http_referer[2];     $home_url       = explode( "/", home_url() );     $home_url       = $home_url[2];          // Coming from a search engine: modify to a search string     if ( isset( $_SERVER['HTTP_REFERER'] ) && $home_url !== $http_referer )     {         // remove previous "s" search query args         remove_query_arg( 's' );              $string = parse_url( $_SERVER['HTTP_REFERER'] );         $query = $string['query'];         $query = explode( "&", $query );         foreach ( $query as $q )         {             $q = urldecode( $q );             $arr = explode( "=", $q );             if ( (string) 'q' === $arr[0] )                 $search_string = $arr[1];         }              // build a new "s" search query arg: if isset, from the string entered in the search engines input form         // in theory that should allow treating it like a normal search result         // the draw back is, that a search engine visitor would never get directly to a post or page          if ( isset( $search_string ) )             add_query_arg( array( 's' => $search_string ) );     }      Aside from the drawback that no search engine visitor would come to a result directly, i wouldn't catch all search engines that way. Google & Altavista got a `q=searchstring` query argument. Yahoo for eg. uses `p=`...


Website Address Keep redirect to website after migration attempt

I have a loclhost site that I heard I can migrate the site by just copy and paste the whole site from local to host if I changed WordPress Address (URL) and Site Address (URL) to my current hosted site address and then upload it to the host (which I am doing now) Problem is that now when I try to login my local site it will always redirect to my actual website. How can I fix my loclhost site setup so it back to its original loclhost address? ============UPDATE==================================== Added below files into the wp-config of the Wordpress:               define('WP_SITEURL', 'http://localhost/a02business');     define('WP_HOME', 'http://localhost/a02business');      Result: When try to login, the page will still be directed to the actual website not my local site.... Help plz


Custom Post Type Dilema - How do I categorise by country?

In a site I'm building currently I have a custom post type "story". Each story can be assigned a country. Now country could easily be a taxonomy- term but I'm thinking in the future of creating an editable profile page for each country using custom post type call "country" while retaining a list of stories on that page. What is the best way to do this? Dan


What problems maybe happen if I remove "wp-" prefix from wordpress folders and files?

I want to hide wordpress signs from my site. So I don't want other people know that I built the website via WordPress. So I decided to remove `wp-` prefixes from all wordpress folders and files. And I also removed `wp-` prefixes from file contents with Notepad++. So my question is what problems maybe happen if I removed `wp-` prefixes ? Thanks in advance.


Sub-Pages only of menu items in current branch using a custom menu

Although I did a thorough research I could not find a solution. Only solutions coming close. My custom menu ("top") shows this structure (you see a part of it):               page 1       subpage 1.1         category A         subsubpage 1.1.1         subsubpage 1.1.2       subpage 1.2         category B         subsubpage 1.2.1         subsubpage 1.2.2       subpage 1.3         category C         subsubpage 1.3.1         subsubpage 1.3.2     page 2     page 3      Without using CSS (the real structure is by far bigger) I would like to display this in the sidebar, when a user currently looks at page 1 (only its children items):                 subpage 1.1       subpage 1.2       subpage 1.3      And when the user currently looks at subpage 1.1 or any of its custom menu children (incl. posts in category A):                 subpage 1.1         category A         subpage 1.1.1         subpage 1.1.2       subpage 1.2       subpage 1.3      To put it in words: Visible menu items:   * menu items on level 2 (if there are any)   * children of level 2 menu items only for items in the current branch (current-menu-ancestor, current-menu-parent, current-menu-item) I tried a few Custom Walker classes presented in that forum, none of them did the trick. I also tried the plugin Advanced Menu Widget (http://wordpress.org/extend/plugins/advanced-menu-widget/), which comes very (!) close, but there seems to be a bug in it. Use of these settings would do the job generally:   * Show hierarchy: Only related sub-items   * Starting depth: 1 Unfortunately it does not provide the result looking at category A or it's posts in my example. Thank you in advance.


WordPress search: pretty URLs (permalinks), custom post types and pagination

I have three separate search boxes on my website: `species` CPT search, `glossary` CPT search and a general search which I'd like to search `post` and `species` post types. My questions are threefold,   1. What's the most efficient/effective code to make pretty search URLs, and is there a reason that WordPress doesn't activate these by default?   2. Bearing #1 in mind, what code do I need to use in `searchform-species`, `searchform-glossary`, `search` and `searchresults` to specify that my species search will only return species results, glossary will return glossary results, etc.   3. How do I incorporate pagination? * * * The code I'm currently attempting is as follows: **CODE FOR #1**               add_action( 'template_redirect', 'my_rewrite' );     function my_rewrite() {              if ( is_search() and false === strpos( $_SERVER['REQUEST_URI'], '/search/' ) ) {             wp_redirect( get_bloginfo( 'home' ) . '/search/' . str_replace( ' ', '+', str_replace( '%20', '+', get_query_var( 's' ) ) ) );             exit();         }          }      **CODE FOR #2 & #3** _searchform.php_               <?php         $search_query = get_search_query();         if (!$search_query) {             $search_query = "SEARCH";         }     ?>     <form id="topbar_search" action="<?php echo home_url( '/' ); ?>" method="post">
SEARCH
         <input type="text" size="50" value="<?php echo $search_query; ?>" name="s" id="s" class="topbar_longinput default-value" />         <input type="submit" value="GO" class="topbar_submit" />
advanced search
     </form>      _searchform-species.php_
PROFILESEARCH
     <form id="profilesearch" action="<?php echo home_url( '/' ); ?>" method="post">         <input type="hidden" name="type" value="profile" />              <input type="text" size="50" class="default-value" value="SEARCH" name="s" />         <input type="submit" value="GO" class="profilesearch_submit" />                  <input type="checkbox" name="showthumbnails" id="showthumbnails" class="checkbox" <?php if ($_POST["showthumbnails"] == "on") { echo 'checked="checked" '; } ?>/>HIDE THUMBNAILS     </form>      _search.php_                   if (isset($_REQUEST["type"])) {             switch ($_REQUEST["type"]) {                 case "profile" :                     $post_type = "species";                     break;                 case "glossary" :                     $post_type = "glossary";                     break;                 default :                     $post_type = array( 'post', 'species' );                     break;             }         } else {             $post_type = array( 'post', 'species' );         }              $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;              $args = array(             's' => $search_term,             'post_type' => $post_type,             'paged' => $paged         );     ?>          <?php get_template_part('searchresults'); ?>      * * * **What's currently happening is this:** The individual searches work, but the pagination doesn't. When I click my `next/previous_posts_link` button, it adds `/page/2/` to the URL and does nothing. If I try to echo out the `get_query_var('page')` it returns `NULL`. If I try to echo out `'paged'` instead, it returns `0`. Additionally when a user clicks this link, the `$search_query` variable from _searchform.php_ is displaying as `page/bettas` (where `bettas` is the original query). * * * **Ideally what I'd like to happen is this:**   1. In the "general search", a user enters _betta_. The URL changes to `/search/betta` which lists any `post` or `species` content containing the word _betta_.   2. In the "species search", a user enters _betta_. The URL changes to `/search/betta/species` (or whatever is best for SEO) and displays a list of only `species` content containing the word _betta_.   3. The same user as #2 then clicks the **Next** button (`previous_posts_link`). The URL changes to `/search/betta/species/page/2` and the user gets to see the next 25 species listed. I'm a complete novice at WP rewriting and pagination so any assistance would be greatly appreciated.


How to make a textarea accept javascript in my settings apge?

I'm building a simple plugin that will allow us to add code to our site header by defining it on our settings page. However I haven't been able to make it allow scripts. This is my current code:               public function sanitize( $input )     {         $new_input = array();              if( isset( $input['code'] ) )             $new_input['code'] = sanitize_text_field( $input['code'] );              return $new_input;     }          public function code_callback()     {         printf(             '<textarea type="text" id="code" name="pl-analytics[code]">%s</textarea>',             isset( $this->options['code'] ) ? esc_attr( $this->options['code']) : ''         );     }      How can this be done?


Resize Admin Featured Image Thumbnail

I have a custom post type for a slider and I'm using the Featured Image thumbnail uploader to set the image. I've relocated the Featured Image meta box to be underneath the title section in the admin, and now I would like the Featured Image "thumbnail" to display in the admin post editor screen, at the proportionate dimensions of the image uploaded (in this case a slider image that's 800px wide by 300px high). Currently the image shows up at 266px width and I believe it is this function that is controlling it. I do realise that modifying this is only for ascetics and it won't affect the 'output' size of the image on the front end (I know how to control that). This is simply to show the user the image they have uploaded, in the right proportions. Currently I am using this to shift the featured image meta-box;               // move the featured image box and rename to      add_action('do_meta_boxes', 'wpse33063_move_meta_box');          function wpse33063_move_meta_box(){     remove_meta_box( 'postimagediv', 'slider-image', 'side' );     add_meta_box('postimagediv', __('Add Your Slider Image'), 'post_thumbnail_meta_box', 'slider-image', 'normal', 'high');     }      I have seen in this post, this one and this one (more related to TwentyTen), where others have suggested methods to show a re-sized "thumbnail" in the admin custom post edit screen. I've tried these methods and none of them seem to work / all return server error. I just want to show a larger featured image in the admin CPT edit screen! Seems simple, but am I seeking the Holy Grail ;-)


Common categories for two custom post types

can I use a category as common for more than one custom post types? In this case same category will have more than one type of posts..


How can I include scripts in a jquery loaded page, for a jquery wordpress widget?

Iam writing a wordpress widget with the following pages 1) I have master page (master.php) - is the main plugin page - Loads a second page (slave.php) with jQuery 2) The slave page - has php, jquery, css etc. - is an external page Below is part of master.php               <?php         add_action('init', 'register_masterscript');         function register_masterscript() {             wp_register_script( 'master_jquery', plugins_url('/js/master-script.js', __FILE__), array('jquery'), '2.5.1' );                 wp_register_script( 'master_jquery2', plugins_url('/js/master.js', __FILE__), array('jquery'), '2.5.1' );             wp_register_style( 'master_style', plugins_url('/css/master_style.css', __FILE__), false, '1.0.0', 'all');         }              // using the registered jquery and style above         add_action('wp_enqueue_scripts', 'enqueue_masterstyle');              function enqueue_masterstyle(){            wp_enqueue_script('master_jquery');            wp_enqueue_script('master_jquery2');            wp_enqueue_style( 'master_style' );         }         ?>      master.php loads slave.ph successfully but my problem is non of the jquery actions or links work. As slave.php is external I have tried               define('WP_USE_THEMES', false);         require('../../../wp-blog-header.php');      then                <?php          add_action('init', 'register_slavescript');         function register_slavescript() {             wp_register_script( 'slave_jquery', plugins_url('/js/jQuery1.7.1.js', __FILE__), array('jquery'), '2.5.1' );                 wp_register_script( 'slave_jquery2', plugins_url('/js/highlight.pack.js', __FILE__), array('jquery'), '2.5.1' );                 wp_register_script( 'slave_jquery3', plugins_url('/js/combined.js', __FILE__), array('jquery'), '2.5.1' );             wp_register_style( 'slave_style', plugins_url('/css/slave_style.css', __FILE__), false, '1.0.0', 'all');                  wp_register_script( 'slave_jquery4', plugins_url('/js/jquery.mousewheel.js', __FILE__), array('jquery'), '2.5.1' );                  wp_register_script( 'slave_jquery5', plugins_url('/js/jquery.jscrollpane.min.js', __FILE__), array('jquery'), '2.5.1' );          }                // use the registered jquery and style above         add_action('wp_enqueue_scripts', 'enqueue_slavestyle');              function enqueue_slavestyle(){            wp_enqueue_script('slave_jquery');            wp_enqueue_script('slave_jquery2');            wp_enqueue_script('slave_jquery3');            wp_enqueue_style( 'slave_style' );            wp_enqueue_script('slave_jquery4');            wp_enqueue_script('slave_jquery5');         }         ?>      If running the pages without wordpress and without enqueue - ing scripts, the whole code is working fine It looks like for slave.php enqueue -ing is not working, how can i do this the right way ?


How to 301 all posts

I am currently using domain/%postname%/ but I am looking to change it to domain/folder/%postname%/ - I unsure how to 301 all posts. If I was to use something like Redirect 301 /$ domain/folder/$ I am thinking this would probably also redirect all pages, archives etc to the same structure, which I do not want. How can I do this for posts only? Thanks


Custom taxonomy and WP User Frontend

I faced with the following problem: I have custom taxonomy ‘Countries’, which has been defined as:               /* Taxonomies */     add_action( 'init', 'build_taxonomies', 0 );           function build_taxonomies() {          register_taxonomy(           'cf_country',           'post',           array(               'hierarchical' => true,               'label' => 'Country',               'query_var' => true,               'rewrite' => true           )       );       }      /*Taxonomies */      After a few manipulations in function.php in my template, it appeared in admin bar. If I am making posts from dashboard, it works perfectly. BUT An idea of the site is to give ability for users to post their own posts from frontend. This function is realiseted with WP User Front End Plugin. So, I added the following: *** wp-user-frontend/wpuf-functions.php***               function custom_taxonomy_dropdown( $taxonomy, $orderby = 'date', $order = 'DESC', $limit = '-1', $name, $show_option_all = null, $show_option_none = null ) {         $args = array(             'orderby' => $orderby,             'order' => $order,             'number' => $limit,                     'hide_empty'    => false,          );         $terms = get_terms( $taxonomy, $args );         $name = ( $name ) ? $name : $taxonomy;         if ( $terms ) {             printf( '<select name="%s" class="postform">', esc_attr( $name ) );             if ( $show_option_all ) {                 printf( '<option value="0">%s</option>', esc_html( $show_option_all ) );             }                  foreach ( $terms as $term ) {                 printf( '<option value="%s">%s</option>', esc_attr( $term->slug ), esc_html( $term->name ) );             }             print( '</select>' );         }     }      And : *** wp-user-frontend/wpuf-add-post.php***
               Country(-es):          <?php custom_taxonomy_dropdown( 'cf_country', 'date', 'ASC', '5', 'cf_country', 'Select All', 'Select None' ); ?>
Please, choose the right Country, where you want to put your banner.

      Now I have a custom dropdown menu in Add-Post form. And here I’ve got the trouble. When I am submitting the post, my custom choise does not apper in the post. I took the solution for the problem from the (Custom Field as Custom Taxonomy?) And it looks like this:               function save_taxonomy_data($post_id) {              /*           * verify this came from our screen and with proper authorization.         * your form should have a nonce <?php wp_nonce_field('wpuf-add-post','_wpnonce'); ?>         */         if ( !wp_verify_nonce( $_POST['_wpnonce'], 'wpuf-add-post' )) {             return $post_id;         }              // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything         if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )              return $post_id;                   // Check permissions         if ( 'page' == $_POST['wpuf_post_type'] ) { // post type is a hidden field in wpuf_             if ( !current_user_can( 'edit_page', $post_id ) )                 return $post_id;         } else {             if ( !current_user_can( 'edit_post', $post_id ) )             return $post_id;         }              // Work on all post types         if ( isset( $_POST['cf_country'] ) )              wp_set_object_terms( $post_id, $_POST['cf_country'], 'country' );               }     add_action('wpuf_add_post_after_insert', 'save_taxonomy_data');      May be I missed something? Please, Help me! Q_Q


Optimizing multiple WP_querys into one call?

I have finished building my website and noticed due to the structure it takes 3 seconds to load the data due to each WP_query bouncing between different post types. I was wondering if I put these into one function run so I do not have to run a array each time, if this would have any beneficial effect? Sadly at moment i have tried:               function get_gametitle_info() {          global $post;          $game_terms = get_the_terms($post, 'games_titles');     $game_con = wp_list_pluck( $game_terms, 'slug' );          $game_info = array(         'post_type'=> 'game_information',         'posts_per_page' => 1,         'post_status' => 'publish',         'order'    => 'ASC',         'tax_query' => array(             array(             'taxonomy' => 'games_titles',             'field' => 'slug',              'terms' => $game_con,             ),          )     );                $game_info_query = new WP_Query( $game_info );     while ( $game_info_query->have_posts() ) : $game_info_query->the_post();          $gametitleID = get_the_ID();           if (has_term('3pegi', 'age_ratings', $post)){         $age_terms = array('3pegi'); }          if (has_term('7pegi', 'age_ratings', $post)){         $age_terms = array('3pegi', '7pegi'); }          if (has_term('12pegi', 'age_ratings', $post)){         $age_terms = array(array('3pegi', '7pegi', '12pegi')); }         if (has_term('16pegi', 'age_ratings', $post)){         $age_terms = array('3pegi', '7pegi', '12pegi', '16pegi'); }         if (has_term('18pegi', 'age_ratings', $post)){         $age_terms = array('3pegi', '7pegi', '12pegi', '16pegi', '18pegi'); }     endwhile;          return $gametitleID;     return $age_terms;     return $game_info_query;     }      This gives me a - Warning: Invalid argument supplied for foreach() in D:\xampp\htdocs\wp-includes\functions.php on line 2721 The game_info array only needs to be ran once, i would then love it to be able to use that data instead of doing a new run each times on all other matching querys when i switch the post type back after using a wp_reset_postdata(); Sorry if it is not clear. Another way to explain is I have: [post [A post] post post [A post] post [B post] [A post] ] The constant switching seems abit pointless to me when in truth I only need to do the wp_query once for A and B. Would this save on resources and reduce the 3 second load? Thanks Normal structure inside post file:               $currentID = get_the_ID();     $game_terms = get_the_terms($post->ID, 'games_titles');     $game_con = wp_list_pluck( $game_terms, 'slug' );     $args = array(         'post_type'=> 'game_information',         'posts_per_page' => 1,         'post_status' => 'publish',         'order'    => 'ASC',         'tax_query' => array(             array(             'taxonomy' => 'games_titles',             'field' => 'slug',              'terms' => $game_con,             ),          )/*Search above post type for taxonomy and if matches then proceed*/     );                  $the_query = new WP_Query( $args );     if($the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();     $gametitleID = get_the_ID();           if (has_term('3pegi', 'age_ratings', $post->ID)){         $age_terms = array('3pegi'); }          if (has_term('7pegi', 'age_ratings', $post->ID)){         $age_terms = array('3pegi', '7pegi'); }          if (has_term('12pegi', 'age_ratings', $post->ID)){         $age_terms = array(array('3pegi', '7pegi', '12pegi')); }         if (has_term('16pegi', 'age_ratings', $post->ID)){         $age_terms = array('3pegi', '7pegi', '12pegi', '16pegi'); }         if (has_term('18pegi', 'age_ratings', $post->ID)){         $age_terms = array('3pegi', '7pegi', '12pegi', '16pegi', '18pegi'); }         endwhile; else:  endif;  wp_reset_postdata();      To further clarifiy I am looking for a way to call the wp_query once on page load (specific to that page) and save the data as a variable to be used within the header, main, sidebar and footer. But NEEDS to be refreshed for each unique page load as the data is highly dynamic and needs to be the latest. At the moment i call multiple wp_query then reset the postdata each time (even if the wp_query calls the same data) due to the way I am required to switch between post types. Simplest way I can possibly manage to explain - Looking for a way to optimize multiple wp_query's of the same data into one call, but able to be used at multiple locations within a template.


how to get the post attachement image in full size?

Hi i am using the normal loop to get the post content. Objective is to show images or videos in the blog. I tried `the_content()` for the loop but am getting the thumbnail image i belive, What i want is the original image should be there. Here is the code               <?php if ( have_posts() ) :                   while ( have_posts() ) : the_post();                        the_content();//by this am getting the medium sized images from the post content as it is uploaded through add media                   endwhile;                   endif;             ?>      Now i want to show full size of the image for each post. How to do it. can anybody help?


using wp_tag_cloud with custom taxonomy

I'm building a site for an architect and each Project page has a custom taxonomy called Project Services where the client can add various tags. I want to display them in a tag cloud so I'm using this:               <?php wp_tag_cloud( array( 'taxonomy' => 'project_services', 'separator' => ', ') ); ?>      But - the problem is that on each Project page, it's displaying _all_ the various Project Services tags in the database, instead of on a per page basis. Any ideas?


How to modify specific parts of a post content in WordPress

I'm trying to insert some custom code in each post in Wordpress, provided that it complies wit certain conditions. My problem is that the content needs to be added in an specific location that is not the top or the bottom. I know the HTML structure of the posts, since all follow a pattern. I'm guessing that I can use a filter, but I don't know how to actually access and modify the part I want. This is how the structure looks before the modification:

             ...My Content here

      ...and this is how I want it to look afterwards:

             ...My Content here

             ...more content here, added dynamically

      **[EDIT]** To provide a better idea, this is how the code in the template looks (only the relevant part):
         <?php the_content() ?>

                 <?php if(get_post_meta( $post->ID, '_pdf_lesson_version', true )) { ?>
<a href='<?php echo get_post_meta( $post->ID, '_pdf_lesson_version', true ) ?>'>SAVE LESSON
                 <?php } ?>                 <?php if(get_post_meta( $post->ID, '_word_lesson_version', true )) { ?>
<a href='<?php echo get_post_meta( $post->ID, '_word_lesson_version', true ) ?>'>CUSTOMIZE LESSON
                 <?php } ?>
                     <div class="fb-share-button" data-href="<?php echo get_the_permalink() ?>" data-width="200" data-type="button">

      Everything inside the `<ul class="lesson-right lesson-button navigation"></ul>` I need to move into the content of the post. It is outside now, but needs to be contained in the content structure. **[/EDIT]** Any help is appreciated. Thank you for taking the time to read.