Custom post class, generate unique id from 1 to x depending on amount of posts?

I am building a custom post type, where I have a little trouble generating the ID:s the way I want to. The idea of the post class is to generate a table with ID and post title. I wonder if it is possible to generate unique ID depending on the amount of posts in the class, starting from 1. My plan with the post class or type is that it will be used as a FAQ where the title launches a boostrap modal with the answer. Here is the relevant code:               function cptModal_frontend($atts){     $id = rand(0, 999); // use a random ID so that the CSS IDs work with multiple on one page     $args = array( 'post_type' => 'cptModal', 'orderby' => 'menu_order', 'order' => 'ASC');     $loop = new WP_Query( $args );     $modals = array();     while ( $loop->have_posts() ) {         $loop->the_post();         if ( '' != get_the_title() ) {             $title = get_the_title( get_the_ID());             $content = get_the_excerpt();             $modals[] = array('title' => $title, 'content' => $content);         }     }     if(count($modals) > 0){         ob_start();         ?>

                 #	                 Fråga:

             <?php foreach ($modals as $key => $title) { ?>
               <?php echo $id;?>	               <a href="#cptmodal_<?php echo $id; ?>" data-toggle="modal"><?php echo $title['title'];?>
             <?php } ?>

                   <?php foreach ($modals as $key => $title) { ?>     <div id="cptmodal_<?php echo $id; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<?php echo $title['title'];?>

<?php $title['content'] ?>

     <button class="btn btn-custom" data-dismiss="modal" aria-hidden="true">Stäng</button>

     <?php } ?>              <?php }     $output = ob_get_contents();     ob_end_clean();          // Restore original Post Data     wp_reset_postdata();              return $output;      Complete code:               // Custom Post Type Setup     add_action( 'init', 'cptModal_post_type' );     function cptModal_post_type() {     $labels = array(         'name' => 'Modals',         'singular_name' => 'Modal',         'add_new' => 'Add New',         'add_new_item' => 'Add New modal',         'edit_item' => 'Edit modal',         'new_item' => 'New modal',         'view_item' => 'View modal',         'search_items' => 'Search modals',         'not_found' =>  'No modal',         'not_found_in_trash' => 'No modal found in Trash',          'parent_item_colon' => '',         'menu_name' => 'FAQ Modals'     );     $args = array(         'labels' => $labels,         'public' => true,         'exclude_from_search' => false,         'publicly_queryable' => false,         'show_ui' => true,          'show_in_menu' => true,         'query_var' => true,         'rewrite' => true,         'capability_type' => 'page',         'has_archive' => true,          'hierarchical' => false,         'menu_position' => 21,         'supports' => array('title','excerpt', 'page-attributes')     );      register_post_type('cptModal', $args);     }          // FRONT END          // Shortcode     function cptModal_shortcode($atts, $content = null) {     // Set default shortcode attributes     $defaults = array(         'backdrop' => 'true',         'keyboard' => 'true',         'show' => 'true'     );          // Parse incomming $atts into an array and merge it with $defaults     $atts = shortcode_atts($defaults, $atts);          return cptModal_frontend($atts);     }     add_shortcode('FAQ_modal', 'cptmodal_shortcode');     // Display latest WftC     function cptModal_frontend($atts){     $id = rand(0, 999); // use a random ID so that the CSS IDs work with multiple on one page     $args = array( 'post_type' => 'cptModal', 'orderby' => 'menu_order', 'order' => 'ASC');     $loop = new WP_Query( $args );     $modals = array();     while ( $loop->have_posts() ) {         $loop->the_post();         if ( '' != get_the_title() ) {             $title = get_the_title( get_the_ID());             $content = get_the_excerpt();             $modals[] = array('title' => $title, 'content' => $content);         }     }     if(count($modals) > 0){         ob_start();         ?>

                 #	                 Fråga:

             <?php foreach ($modals as $key => $title) { ?>
               <?php echo $id;?>	               <a href="#cptmodal_<?php echo $id; ?>" data-toggle="modal"><?php echo $title['title'];?>
             <?php } ?>

                   <?php foreach ($modals as $key => $title) { ?>     <div id="cptmodal_<?php echo $id; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<?php echo $title['title'];?>

<?php $title['content'] ?>

     <button class="btn btn-custom" data-dismiss="modal" aria-hidden="true">Stäng</button>

     <?php } ?>              <?php }     $output = ob_get_contents();     ob_end_clean();          // Restore original Post Data     wp_reset_postdata();              return $output;     }          ?>


update post meta front end

Why doesent this work?! I want to update my postmeta "doors" from frontend               <?php     if ( isset( $_POST['submit'] ) )         { //if nonce check succeeds.             global $post;             $postid = $post->ID;             $data = $_POST['doors'];             update_post_meta($postid, 'doors', '2' );             echo self::$auto_id. 'doors'.'2';             echo $postid;          }               $doors = get_post_meta($auto->ID, 'doors', true);     ?>          <form method="post" action="">        <input type='text' name='doors' value='<?php echo $doors ?>' />        <input type='submit' value='save' />     </form>      This code display the door value in my input but if i write something else there then click save nothing happends... it doesent save my new value. Why?:(


Wordpress Domain Mapping shows new domain in place but takes me to the sub domain

I have multiple domains that run on the same IP address in media temple. I input this IP "8.5.06.06" into the "domain mapping" server ip. I then set up the "domains" section and selected the "id" of my subdomain "demo.abc.com" I would like mapped and put in my domain "cba.com" and deselected "primary" It displays the domain "cba.com" the subdomain "demo.abc.com" is mapped to, but when I go to "visit site" it takes me to the subdomain "demo.abc.com" I clicked on and not the mapped domain "abc.com" This is driving me crazy! Am I missing something? Thanks for your patience, I am a complete noob at this


Order posts by separate menu order for different sub-categories

My scenario is as follows: **Categories:**                1. Category A          - Sub-Category A1          - Sub-Category A2          - Sub-Category A3      2. Category B          - Sub-Category B1      3. Category C      4. Category D      The **Category** template has a list of all posts that belong to that relevant **Category** and are ordered by **Menu_Order**. My problem is that if a single Post happens to fall under multiple categories ( _Sub Category A1 and Category C_ ), I can only set a generic menu_order in Wp-Admin and it is not **Category** specific. I would like a **Post** to be ordered something like this: Single Post               - Category A: Menu_order 3     - Category A2: Menu_order 2     - Category C: Menu_order 11      Is there a way for me to set the menu_order for a post when it's under **Category A1** and then another menu_order for **Category C**? I've read this: Different post sort order within different categories and I think this may help, but I'd like to know if there is a quicker and simpler way. I'm using the latest WordPress 3.8, Advanced Custom Fields 4.2.2 (to populate post content) and I've created a CPT in my functions.php. **Edit:** I've begun constructing the custom fields in my **Category** Edit screen as suggested in the first answer. Currently it is a jQuery sortable ul list of Post titles, each with the relevant **post_ID** as the id of the li I think the best approach for me now would be to have an AJAX call after every jQuery re-sort that sends an array of post_IDs to a function that will write to the DB. **Edit 2:** I've successfully managed to store the sortable order in a database using a function. My next step is to look into WP_Query and seeing if we can use an array of posts to determine an output order.


Problems with permalinks (.htaccess not working)

I would like to use permalinks but they are not working. Whenever I use permanlinks like /%postname*/ are something else that differs from the default ... I get an 404-error. Calling php_info I can see that Loaded Modules contains mod_rewrite.               # BEGIN Better WP Security     Options -Indexes          <files .htaccess>     Order allow,deny     Deny from all     </files>          <files readme.html>     Order allow,deny     Deny from all     </files>          <files readme.txt>     Order allow,deny     Deny from all     </files>          <files install.php>     Order allow,deny     Deny from all     </files>          <files wp-config.php>     Order allow,deny     Deny from all     </files>          <IfModule mod_rewrite.c>     Options +FollowSymLinks     RewriteEngine On          RewriteRule ^wp-admin/includes/ - [F,L]     RewriteRule !^wp-includes/ - [S=3]     RewriteCond %{SCRIPT_FILENAME} !^(.*)wp-includes/ms-files.php     RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]     RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]     RewriteRule ^wp-includes/theme-compat/ - [F,L]          RewriteCond %{REQUEST_METHOD} ^(TRACE|DELETE|TRACK) [NC]     RewriteRule ^(.*)$ - [F,L]          RewriteCond %{QUERY_STRING} \.\.\/ [NC,OR]     RewriteCond %{QUERY_STRING} ^.*(bash|git|hg|log|svn|swp|cvs) [NC,OR]     RewriteCond %{QUERY_STRING} etc/passwd [NC,OR]     RewriteCond %{QUERY_STRING} boot\.ini [NC,OR]     RewriteCond %{QUERY_STRING} ftp\:  [NC,OR]     RewriteCond %{QUERY_STRING} http\:  [NC,OR]     RewriteCond %{QUERY_STRING} https\:  [NC,OR]     RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]     RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|%3D) [NC,OR]     RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [NC,OR]     RewriteCond %{QUERY_STRING} ^.*(\[|\]|\(|\)|<|>|ê|"|;|\?|\*|=$).* [NC,OR]     RewriteCond %{QUERY_STRING} ^.*("|'|<|>|\|{||).* [NC,OR]     RewriteCond %{QUERY_STRING} ^.*(%24&x).* [NC,OR]     RewriteCond %{QUERY_STRING} ^.*(%0|%A|%B|%C|%D|%E|%F|127\.0).* [NC,OR]     RewriteCond %{QUERY_STRING} ^.*(globals|encode|localhost|loopback).* [NC,OR]     RewriteCond %{QUERY_STRING} ^.*(request|select|concat|insert|union|declare).* [NC]     RewriteCond %{QUERY_STRING} !^loggedout=true     RewriteCond %{QUERY_STRING} !^action=rp     RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in_.*$     RewriteRule ^(.*)$ - [F,L]          </IfModule>     # END Better WP Security          # BEGIN WordPress     <IfModule mod_rewrite.c>     RewriteBase /     RewriteRule ^index\.php$ - [L]     RewriteCond %{REQUEST_FILENAME} !-f     RewriteCond %{REQUEST_FILENAME} !-d     RewriteRule . /index.php [L]     </IfModule>     # END WordPress      Whenever I change the permalink-structure a 404error occurs. The apache's error_log shows no errors regarding this problem. The OS is an Suse Linux. Apache/2.2.12. In the httpd.conf there are the following relevant entries:               # forbid access to the entire filesystem by default     <Directory /srv/www/htdocs>           Options +FollowSymLinks           AllowOverride All           Order deny,allow           Deny from all     </Directory>          <Directory />         Options +FollowSymLinks         AllowOverride All         Order deny,allow         Deny from all     </Directory>          # use .htaccess files for overriding,     AccessFileName .htaccess     # and never show them     <Files ~ "^\.ht">         Order allow,deny         Deny from all     </Files>      Does someone know what I could check to get the permalinks running? I cannot find out what I am missing.


What is the wordpress Git hub Repo master on beta?

I am fairly new to Wordpress and have started checking out the latest version from Github. I assumed that the latest version would be master but it seems the latest is 3.9-branch   1. Is the 3.9 branch the correct one to use?   2. Can I revert to the production version if I have installed beta on a site?   3. Is the Github version of Wordpress always up to date?


List all posts types in admin edit.php

I am trying to show a list of all posts types in the admin. For now i can only show a list of particular post type, for example: wp- admin/edit.php?post_type=video , but how can i show a list of all posts types (preferably using the "url filter", for example : wp- admin/edit.php?post_type=video&post_type=music (not working). I tried bunch of different variations : ?post_type=video&post_type=music and ?post_type=video&music, ?post_type=video;music , ?post_type=video,music none of those worked... Is there a way to do that? Will appreciate your help.


multisite - move main site to subdomain

I just started using Wordpress multisite. I have a development site set up on the main domain which I want to now move to a subdomain. How do I go about doing this? Ie. I need domain.com to become staging.domain.com, so I can set up a new main site. Any pointers would be a great help, thanks!


wordpress powered site's google search excerpt showing casino links

I have wordpress blog i just checked Google search result of my site, they are showing excerpt containing text like below > "best site should try out for demo mode of gaming variants to adopt good > gaming Participate in casino games online to take gamble online and increase > your ..." When I visit site page source shows nothing related to casino.I then used google structured data testing tool in Google Webmasters and checked Page Html it has that malicious code containing casino links .That Malicious code is attached here in following link. **Link to the malicious code** I do not know programming. Please help me get rid of this problem.


<!--nextpage--> assumed as comment line

I created very simple php loop which generates image links for given number. This is the code               <?php $im = stripslashes(get_option('tm_alim'));     for ($i=1; $i<=im; $i++)       {       echo "<img alt='' src='http://sitename.com/"  . $i . "/00"  . $i . ".jpg' />      <!--nextpage-->";       }     ?>      As you can see i am trying to print code right after every image which will make pagination. Each image will be shown in a page. This code is in a page template and the page is attached to that template. But the problem is code is assumed as comment line and it is not showing even in html page source. Is there anyway to fix this or any alternative would be great Or is there any way to tell wordpress total number of pages should be the $im or count the images and create pagination for each. i am sure there would be various ways to do it. thanks


How do I list custom taxonomy terms without the links?

I've searched far and wide to try and find an answer to my question. I'm hoping I can get help here. Here goes... I'm currently retrieving the terms of my custom taxonomy using: `<?php echo get_the_term_list( $post->ID, 'skills', '<ul><li>', '</li><li>', '</li></ul>' ); ?>` What I'm trying to do is retrieve these same post-specific custom taxonomy terms in a list without them being output as links. I've tried all of the following "solutions," but none of them work. Any help would be appreciated. **Returns the post-specific terms in one long string that can't be put in a list:** `$terms_as_text = get_the_term_list( $post->ID, 'skills', '<ul><li>', '</li><li>', '</li></ul>' ) ; echo strip_tags($terms_as_text);` Returns a list of all the terms used across all the custom post types: `<ul> <?php $args = array( 'taxonomy' => 'skills', 'orderby' => 'ID', 'order' => 'ASC' ); $categories = get_categories( $args ); foreach($categories as $category) { echo '<li> '. $category->name . '</li>'; } ?> </ul>` Returns nothing: `<?php $args = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all'); wp_get_object_terms( $post->ID, $skills, $args ); ?> ` I've even tried get_the_terms, get_terms, and get_categories to no avail. I'm strugglin' here. Any help would be appreciated. Thanks in advance.


Custom Post Type Category Link

I have a loop of posts for a custom post type I built. How can i call the link of the category/taxonomy for each post? Thanks


attach CPT data to a taxonomy

I'm trying to create a site where a 'Game' has a set of information (im thinking it will be a custom post type, with a 'link' field, 'developer' as a taxonomy, 'price', 'release date' and some other information. I want to be able to make a post, in a category (such as 'reviews') which links to the relevant game and can pull some of this metadata into a template. SO... the review is it's own post, it has it's own info, tags etc. BUT. is linked to the 'Game' so i can pull in the 'price', 'developer' information etc. AND when i go to the game page, i should be able to find the articles linked to it via the taxonomy. Is there a way to do this? I have given it some substantial googling to no avail. Any ideas, thoughts or links would be greatly appreciated.


Insert taxonomy slug into loop class

I am a loss here since I have looked at dozens of tutorials and posts all over the internet on how to get the slug for a taxonomy and nothing I try seems to work. The taxonomy shows up fine when I want to edit the post and everything seems to be working fine, however I cannot seem for the life of me to get Wordpress to give me the slugs I want. I am really frustrated and irritated on how complicated the process of saying "for the array of posts you already have, include the taxonomy for each one". _sigh_ In reality, all I want is to get the custom taxonomy slug that has been selected for each post. I have a portfolio page that I want to make interactive with jquery and I am trying to use the taxonomy slug as the anchors for the jquery script. All I need from Wordpress is to see the post it's already giving me all of it's information and to include the taxonomy it has been already linked to. Then echo that slug into the class of the LI tag. Here is the code:
         <?php         $post = 'project'; // custom post type         $i=1;         query_posts("post_type=$post&showposts=-1&order=asc");         $post_count = wp_count_posts();         while(have_posts()) : the_post();         $myExcerpt = get_the_excerpt();         $tags = array("
", "
");         $myExcerpt = str_replace($tags, "", $myExcerpt);         $terms = get_the_terms( $post->id, 'project-type' ); // get an array of all the terms as objects.              $terms_slugs = array();              foreach( $terms as $term ) {             $terms_slugs[] = $term->slug; // save the slugs in an array         }     ?>         <li class="project <?php echo $terms_slugs[$i]; ?>">             <a href="<?php the_permalink(); ?>" id="project_<?php echo $id; ?>" class="project_frame">                 <?php the_post_thumbnail('full', array('class' => 'project_img')); ?>
<?php the_title(); ?>
<?php echo $myExcerpt; ?>

         <?php              $i++;         endwhile;         wp_reset_query();     ?>
      Hopefully someone can help me with this. UPDATE: Figured it out. Here is the corrected code.
                         <?php                             $post = 'project'; // custom post type                             $i=0;                             $counter = 0;                             query_posts("post_type=$post&showposts=-1&order=asc");                             $post_count = wp_count_posts();                             while(have_posts()) : the_post();                             $myExcerpt = get_the_excerpt();                             $tags = array("
", "
");                             $myExcerpt = str_replace($tags, "", $myExcerpt);                                  $slugs = get_terms('project-type');                             foreach($slugs as $slug) {                                 $slug_array[$i] = $slug->slug;                                 $i++;                             }                         ?>                         <li class="project <?php echo $slug_array[$counter]; ?>">                             <a href="<?php the_permalink(); ?>" id="project_<?php echo $id; ?>" class="project_frame">                                 <?php the_post_thumbnail('full', array('class' => 'project_img')); ?>
<?php the_title(); echo $i;?>
<?php echo $myExcerpt; ?>

                         <?php                             $counter++;                             endwhile;                             wp_reset_query();                         ?>


Wordpress wp_redirect error

I am trying to redirect this page if the user is logged in or not be i keep getting this error               Warning: Cannot modify header information - headers already sent by (output started at /home/*******/*********.com/wp-content/plugins/graph2.php:54) in /home/*******/*********.com/wp-includes/pluggable.php on line 934      Im using this redirect method               <?php if ( is_user_logged_in() ) {              echo '';          }              else {          wp_redirect( 'http://www.example.com' );             }      ?>      I cant seem to figure out what is wrong. :) thanks


just show the field comment by clicking button

when we open a post, we at the bottom of the page field to post a comment   I would like to hide this field.   if there are comments, usually shows them   however to leave a comment, click a button   with this, the field appears to leave a comment      Anyone have a clue how to do this?   Through either normal or ajax


Unable to pass variable

I am trying to pass number of post show from widget.I stored it as $entry my code               <?php query_posts( array('post_type' => array('post'),'order' => 'DESC','posts_per_page' => '.$entry.') ); ?>      Thanks


I Made Wordpress Multisite. And Now Everything Doesn't Display Properly

I installed Ubuntu 10.4 then I installed Bitnami LAMP stack then I installed bitnami wordpress module then I tried to make the site into a multisite by following these instructions: http://wiki.bitnami.org/Applications/BitNami_WordPress_Multisite#How_to_add_several_WordPress_Multisite_blogs_with_different_domains.3f AND http://wiki.bitnami.org/Applications/BitNami_WordPress_Multisite I can elaborate if needed: I enabled multisite in my `wp-config.php` file. Then I created a network using the wordpress dashboard. I was given two blocks of text to copy and paste 1 block into my wp-config.php file and one into my `.htaccess` file. I did that and now I get this: When I go to my `mywebsite.com` I get this (this was there before I switched to multisite): ![before switch](http://i.stack.imgur.com/no2A9.jpg) If I go to `mywebsite.com/wordpress` I get this (this used to be a functioning wordpress theme): ![/wordpress](http://i.stack.imgur.com/Bbg65.jpg) If I click on "My Blog" it redirects to 1mywebsite.com (where the "1" came from I have no idea) If I try to login by going to `mywebsite.com/wordpress/wp-login` I get this: ![wp-login](http://i.stack.imgur.com/H5AcO.jpg) and if I enter my user and password it redirects me to mywebsite.com/wp- login.php and gives me "Not Found" The requested URL `/wp-login.php` was not found on this server.               NameVirtualHost *:80         <VirtualHost *:80>         DocumentRoot /opt/lampstack-5.3.16-0/apps/wordpress         ServerName mywebsite.com         ServerAlias www.mywebsite.com     </VirtualHost>


Page comes up blank using w3 total cache

Im using the W3 Total Cache plugin on my site, and I made page using the wp_list_comments and for some reason the page keeps coming up blank, it comes back after I disable the plugin but when i enable it everything goes blank again does anyone have a suggestion on how iI can fix this, im new to this plugin. thanks


Parent pages not found with pretty permalinks

I'm building a site and for some reason all the parent pages are 404ing, only sub-level pages are displaying with pretty permalinks. If I use default permalinks, everything works fine. I've tried disabling all the plugins & deleting htaccess and having Wordpress recreate the file, nothing works. Any ideas? Here's the site: http://www.855gotclog.com


How to stop comments widget conflicting with theme comments

I have a widget that retrieves and displays the latest comments for a WordPress site. It displays the comment author, Gravatar, comment and date / time. The function to display the comments is in a class. The issue that I am having is that whenever i display this widget it messes up or conflicts with the number of comments that are returned for my WordPress theme. Example. In the widget choose to display 5 comments. On a page on the site I have a post that has 8 comments. When the widget is enabled only 6 of those 8 comments are displayed. If I disable the widget, all the comments display. This is the function to display the comments               /**          * Retrieves the latest comments          *          * Shows a list of latest comments ordered by the date added          *          * @param int $limit - The number of posts to display          * @param int $chars - The number of characters to display for the post body          * @param int $size - Size of the comment Gravatar          * @param boolean $displayCommentsIcon - Whether to display the comment Gravatar          *          */          public function aaw_get_latest_comments($display_comments_icon = true, $comments_icon_size = 50, $comments_amount = 5, $comments_chars = 35, $display_comments_date = true) {             global $comments;                  $com_excerpt = '';                  $aaw_comments = get_comments(array('number' => $comments_amount, 'status' => 'approve'));                  if($aaw_comments){                 foreach((array)$aaw_comments as $aaw_comment){                     if($comments_chars > 0) {                         $com_excerpt = self::aaw_snippet_text($aaw_comment->comment_content, $comments_chars);                     }                          echo '
';                              if($display_comments_icon == 'true'){                             echo 'comment_ID) ).'" title="'. __('Commented on: ', $this->hook). $aaw_comment->post_title.'">';                             echo get_avatar($aaw_comment, $comments_icon_size);                             echo '';                         }                         echo '
';                         echo 'comment_ID) ).'" title="'. __('Commented on: ', $this->hook). $aaw_comment->post_title.'">';                             echo ''.strip_tags($aaw_comment->comment_author).': '.strip_tags($com_excerpt).'...';                         echo '';                         if($display_comments_date == 'true'){                             echo ''.get_comment_date('j M Y',$aaw_comment->comment_ID).' '.__('at', $this->hook).' '.get_comment_date('g:i a',$aaw_comment->comment_ID).'';                         }                         echo '
';                     echo '
';                      }             } else {                 echo '
'.__('No comments available', $this->hook).'
'."\n";             }                   }      This is how I call the function:               <?php $advanced_activity_widget->aaw_get_latest_comments($display_comments_icon == 'true' ? 'true' : 'false', $comments_icon_size, $comments_amount, $comments_chars, $display_comments_date == 'true' ? 'true' : 'false'); ?>      At first I thought is was the Gravatar causing the conflict however I removed it and it didn't make a change. Any help would be greatly appreciated. Thanks


wp_get_attachment_url not working

I have a template file which shows the posts of a category called downloads. for each posts i have attached a pdf file. I have given a link to download the pdf file on the page. But when i click the download link it goes to the post page and from there i have to click to download the file. Is there any way to directly download without going to the post. ? I have tried using wp_get_attachment_url as the hyper-reference.but it is not working.The code that i have used is below:               <?php /*     Template Name: Downloads Template     */     ?>     <?php get_header(); ?>     <?php      $recent = new WP_Query("cat=7&orderby=title&order=ASC");      while($recent->have_posts()):$recent->the_post();     $desc_values = get_post_custom_values("description");     ?>     <div id="download_featured_image" class="<?php the_ID(); ?> download_image_title_desc">              <a href="<?php the_permalink() ?>" rel="title">         <?php             if ( has_post_thumbnail() )  {                  the_post_thumbnail();             }         ?>       <?php if ( is_user_logged_in() ) {             echo "Download";          }?>          <?php if( !(is_user_logged_in()) )         {             echo "Please signup/login to download this file";         }         ?>
             <?php                  if( is_array( $desc_values ) )                 {                     foreach($desc_values as $key => $value );                     echo "$value</n>";                  }             ?>

     <?php endwhile ?>     <?php get_footer(); ?>      I want to give the link to the uploaded pdf in the href which i have left blank. Can someone help me?


Hook into the loop via a plugin, and output something after every X post?

I have a plugin where I want to output ads after X number of posts on the home page. The home page is step 1, but things like archives should be possible too once I get the code for the home page. How do I hook in to post loops and say something like "after every loop, increment a counter, and then if the counter = my number, output an ad". I can write all the logic for this code myself, but where to hook/implement my code is confusing.


Restrict Search Results to Post Author

Is there a way to restrict search results to only those posted by the logged in user? I have a front-end form the user fills out. Every user has a front-end dashboard and is able edit their own post. Since they may have many posts I would like them to be able to search for their own posts, but not display posts from other authors (this would only complicate things) Is there a way to do this?


Script loaders vs wp_enqueue_script

My Wordpress theme has a lot of .js scripts running and it takes plenty of time to load them all one by one. I would love to use a script loader like HeadJS or yepnopejs to speed things up. But... what about wp_enqueue_script? I'm using it to load every single script (and I believe that's the BEST & ONLY way to go?). Won't loading scripts using script loader instead of wp_enqueue_script create any conflicts with plugins, widgets etc.? What about enqueuing the script loader itself?


Can a shortcode included in post content add styles to the <head>?

I have a shortcode that iterates through a list of custom post types and, as part of displaying them, creates a block. In HTML5, it is illegal to have a style block outside the header (maybe in other versions too, but we are using HTML5). I am looking for a way that my shortcode can insert its block into the head. Any suggestions? This is the page: http://2011.solarteam.org/sponsors/gift-recognition/view-of- living-room The shortcode is called twice on a page.   Once like this `[interactive slug='sponsor-map-living-room' show="image"]Select an item to learn more about its sponsor.[/interactive]` to make the image.   Once like this `[interactive slug='sponsor-map-living-room' show='list' headertitle='WaterShed Featured Sponsors: Living Room' /]` to make the list at the bottom. I can't put it in the template because the template does not know which `slug` goes on which page. * * * Here is a simplified version of the shortcode processing code:
<?     foreach($map->points as $point){         $result = "";         if(!in_array($point->pointer_type, $all_styles['regular'])){             $all_styles['regular'][$point->pointer_type] = "                 .pointer_style_" . $point->pointer_type . " {                     width: " . $point->pointer_width(). "px;                     height: " . $point->pointer_height(). "px;                     background: transparent url('/images/interactive/pointers/" . $point->pointer_URL() . "');                 }             ";         }         ob_start(); ?>         <li class="tag_point sponsor_data_point pointer_style_<?php echo $point->pointer_type?>" id="point_<?php echo $point->ID ?>" data-in="#point_<?php echo $point->ID ?>_info" data-hover-style="pointer_s_style_<?php echo $point->selected_pointer_type?>" style="left:<?php echo $point->x - ($point->pointer_width()/2) ?>px;top:<?php echo $point->y - ($point->pointer_height()/2)?>px;">         <div class="tag_info" id="point_<?php echo $point->ID ?>_info">
<?php echo $point->contribution ?>

<?php echo $point->description ?>

         <?         $result .= ob_get_clean();         $result .= "
\n";         echo $result;     }     ?>
           The `<style>` tag is not allowed there in HTML5, so I want to get it into the head of the page.


Retrieve or Query Pages by ID

I have a problem with my code, I want to display 3 specific pages on my homepage but my code is not working.. here's the code..               <?php $args = array(                           'post_type' => 'page',                           'post__in' => array(3,5,7)                           );                         query_posts($args);                         while (have_posts()) : the_post();                         $do_not_duplicate = $post->ID; ?>

<?php the_time('M j, y');?>

<a STYLE="text-decoration:none" href = "<?php the_permalink();?>"><?php           the_title();?>
                              <?php the_excerpt();?>                              <?php endwhile; ?>


Show Social Sharing Buttons And Facebook Comments In Lightbox Modal Dialog (Image Overlay)?

I would like to show Facebook comments and share buttons in the lightbox modal dialog (image overlay) that pops-up when I click on an image in gallery. A lot like what they have done on this website for instance (if you click on one of the thumbs nails you will see what i mean.) How do I do it?


Is it bad to use a lot of Custom Meta Fields?

I am curious without doing a ton of benchmarks, how others feel about using several custom meta fields on a blog post? I am talking strictly performance wise, does it slow things down a lot if using a lot of fields, should we try to keep them to a minimum? Currently for a regular blog post, I have a custom meta field for...   * Title: Used for page title   * Description: Used for meta description and social share description/text for Facebook and Twitter shares   * Keywords: Used for meta keywords So I have 3 extra meta fields which are used so every article will have relevant SEO meta, also for when a user shares the article on Social networks, I can set the title and description easily. I am wanting to add another field for Twitter #hashtags which I can then insert on Twitter shares, these will be similar to my articles tag taxonomy but may differ some so that is why I am thinking a custom meta field is the way to go. I am also in the process of doing a custom post type for a portfolio which would also in addition to the above custom meta would add several more meta fields for this post type. That is why I am curious about the performance impact of adding several meta fields? Please share your thoughts


Add /demo/ slug with rewrite rule

> **Possible Duplicate:**   >  Add extra parameters after permalink? I need to add a slug to every post. **Current permalinks** http://www.my-domain.com/2012/01/01/my-post-title/ or   http://www.my-domain.com/my-post-title/ **Rewritten permalinks** http://www.my-domain.com/2012/01/01/my-post-title/demo/ or   http://www.my-domain.com/my-post-title/demo/ **Additional information**   * My demo-page should not return a 404-page.   * I should be able to get the current ID of the post "my-post-title" from my demo-page.


Using redirection plugin to pass URLs as lowercase to wordpress

have been experiencing a problem yesterday. My site is in Hebrew language. MY site is built on Wordpress. The problem is related to escaped encoded posts URL only. IF the post URL has escaped encode in uppercase it works, if in lowercase, it returns 404. I want both to pass without a problem. For example: http://domain.com/%d7%9e%d7%a6%d7%9c%d7%9e%d7%95%d7%aa/ (this is what my site have) Google crawled it as: http://domain.com/%D7%9E%D7%a6%D7%9C%D7%9E%D7%95%D7%AA/ (this returned 404) Is there any option to use the REDIRECTION plugin for wordpress to PASS (not redirect) the URLs o wordpress will see them as lowercase?


Can you have seperate sidebars for multiple taxonomy archives?

I have a site that uses multiple query taxonomy archives. i.e www.sitename.com/taxonomy1/taxonomy2/taxonomy3 Is there a plugin or method to create a dedicated sidebar for each queried taxonomy archive? Essentially, there will be 1000 or so archives and i would like to be able to create a unique sidebar for each. Is this possible? Thanks in advance Paul


Activate blog hook

I want to hook a function upon activation of a blog in wordpress multisite. I have this,               add_filter( 'add_signup_meta', 'custom_add_signup_meta' );          function custom_add_signup_meta ( $blogmeta = array() ) {                  $the_country = $_POST['country-origin'];             $d_currency = $_POST['user_currency'];             $d_zone = $_POST['state-origin'];                  $blogmeta['countries_id'] = $the_country;             $blogmeta['default_currency'] = $d_currency;             $blogmeta['zone_id'] = $d_zone;              return $blogmeta;          }          add_action( 'wpmu_activate_blog', 'insert_custom_datas1', 10, 3 );          function insert_custom_datas1($blog_id, $blogmeta) {             global $wpdb, $blogname, $blog_title, $errors, $domain, $path;             $wp_blogs = $wpdb->base_prefix . "blogs";                  $wpdb->query("UPDATE `" . $wp_blogs . "` SET `countries_id`='".$wpdb->escape($blogmeta['countries_id'])."', `default_currency`='".$wpdb->escape($blogmeta['default_currency'])."', `zone_id`='".$wpdb->escape($blogmeta['zone_id'])."' where `blog_id` = '" . (int)$blog_id . "'");          }      However, its not working.. what suppose to be the problem? Thanks.


Displaying only posts from a certain category on my custom page template

I want to create proper pages for my post categories, rather than just a default category page. So for example, I'm going to create a Video page and have a load of information about my videos, and then below this info, bring in the loop of posts that appear in the Video category. So I'm attempting to do the following:   * Copying my themes page.php and calling it page-categoryname.php and adding a title to the new page template.   * Finding the loop and limiting the categories that can display in that loop. Does that sound like the right way to go about it? And how exactly would you edit the loop in the below page code to only display posts from a certain category id?                  <?php get_header(); ?>     <?php while ( have_posts() ): the_post(); ?>          <div class="main group <?php echo wpb_option('general-sidebar','sidebar-right'); ?>">

                 <article id="entry-<?php the_ID(); ?>" <?php post_class('entry group'); ?>>                          <?php get_template_part('partials/page-image'); ?>                     <?php get_template_part('partials/page-title'); ?>
                         <?php the_content(); ?>

                      <?php comments_template(); ?>

                <?php get_sidebar(); ?>

          <?php endwhile; ?>     <?php get_footer(); ?>      Any help would be great. R


ACF Gallery & mqTranslate, Title and Description not displaying in other languages

I am using mqTranslate and ACF Gallery to build a gallery. Below is the code.               <?php $images = get_field('home_slides', 'options'); ?>

             <?php foreach( $images as $image ): ?>
                     <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php echo $image['title']; ?>

<?php echo $image['description']; ?>

             <?php endforeach; ?>

      How can I display Title and Description in other languages? Since both [:en] and `<!--:en-->Title<!--:-->` are not working.


alternating classes on wp_list_pages

I'm trying to have alternating classes on the list created by wp_list_pages. Currently I have extended the Walker_page class updating the start_el function as follows:               class Sidebar_walker extends Walker_page {          var $alternate = 'background_1';          function start_el( &$output, $page, $depth, $args, $current_page = 0 ) {         if ( $depth )             $indent = str_repeat("\t", $depth);         else             $indent = '';              extract($args, EXTR_SKIP);         $css_class = array('page_item', 'page-item-'.$page->ID);              $alternate = ($alternate != 'background_1') ? 'background_1' : 'background_2';         $css_class[] = $alternate;              if ( !empty($current_page) ) {             $_current_page = get_post( $current_page );             if ( in_array( $page->ID, $_current_page->ancestors ) )                 $css_class[] = 'current_page_ancestor';             if ( $page->ID == $current_page )                 $css_class[] = 'current_page_item';             elseif ( $_current_page && $page->ID == $_current_page->post_parent )                 $css_class[] = 'current_page_parent';         } elseif ( $page->ID == get_option('page_for_posts') ) {             $css_class[] = 'current_page_parent';         }              $css_class = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );              $output .= $indent . '
ID) . '">' . $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after . '';              if ( !empty($show_date) ) {             if ( 'modified' == $show_date )                 $time = $page->post_modified;             else                 $time = $page->post_date;                  $output .= " " . mysql2date($date_format, $time);         }     }     }      Only background_1 is printing. how do I get $alternate to actually update.


How do I pass data from page content to the underlying PHP template

Pretty much all of the content on the site is going to be dynamically generated (php + db backend) What is the preferred "wordpress way" of passing data to a php template (set up as a template in a wordpress theme) So the template would be something like               <?php          generate_content_based_on_this_variable(page);          ?>      and I'd need to be able to pass it `page` for each different page * * * Edit 1 So I have a page that, for simplicity, looks something like this > Hi everyone, this is page X The content here is generated from a db call: > > SELECT * FROM db WHERE page=X > > [Spit out db resultset here] and the template would be something like               <?php          the_content()          $query='SELECT * FROM db WHERE page=X'     $result=$db->execute($query)     foreach($result as $row){     echo $row     }          ?>


How do I change the author of a custom post type?

I have made a custom post type and need to be able to create posts and assign them to authors. It is easy to do this with posts as you can go to the bulk edit screen and immediately change the author. However, when I try to do this with my custom post type the author box is not there. How do I add the functionality to change the author of my custom post type? EDIT: I found a solution, see answer below.


WordPress Multisite Question

I want to add a subdomain to all my WordPress sites in a WP MU. For example, I have: `example.com`. When adding a new site to be: `demo.example.com/newsite1` I don't want to create a new user or WordPress Installation. Is this possible?


Error when using plugin QuickCache with plugin Mobile Smart ?

When I using 2 theme(`theme_1 for PC, theme_2 for mobile`), when run as PC is theme is `theme_1`, but when run as mobile is theme is `theme_1`, I think this error plugin `Quick Cache`, When I setting plugin Quick Cache, I find this row: ![Quick Cache](http://i.stack.imgur.com/tfWAm.png)               => How to fix this row to when run as mobile is theme_2, when run as PC is theme_1


Problems with pagination for a custom post type

My pagination links are failing for a custom post type here http://mjw.view- wireframes.com/about-us/press/ the page reloads http://mjw.view-wireframes.com/about-us/press/page/2/ but this has no effect on the displayed posts. Flushing the permalink structure has no effect so my guess is the problem is in the query.               <?php      $paged = (get_query_var('paged')) ? get_query_var('paged') : 10;     $temp = $wp_query;     $wp_query= null;     $wp_query = new WP_Query();     $wp_query->query(array( 'post_type' => 'press',                                     'orderby'   => 'post_date',                                     'posts_per_page' => $paged,                                     ));     while ($wp_query->have_posts()) : $wp_query->the_post();                         // The following determines what the post format is and shows the correct file accordingly         $format = get_post_format();         get_template_part( '/lib/includes/post-formats/'.$format );              if($format == '')         get_template_part( '/lib/includes/post-formats/standard' );          endwhile;               global $wp_query;          $big = 999999999; // need an unlikely integer          echo paginate_links( array(         'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),         'format' => '?paged=%#%',         'current' => max( 1, get_query_var('paged') ),         'total' => $wp_query->max_num_pages     ) );          $wp_query = null; $wp_query = $temp; ?>       Pagination function               <?php $wp_query = null; $wp_query = $temp;?>           function pagination($pages = '', $range = 4)     {          $showitems = ($range * 2)+1;                 global $paged;          if(empty($paged)) $paged = 1;               if($pages == '')          {              global $wp_query;              $pages = $wp_query->max_num_pages;              if(!$pages)              {                  $pages = 1;              }          }                  if(1 != $pages)          {              echo "

Page ".$paged." of ".$pages."
";              if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "
« First
";              if($paged > 1 && $showitems < $pages) echo "
‹ Previous
";                   for ($i=1; $i <= $pages; $i++)              {                  if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))                  {                      echo ($paged == $i)? "
".$i."
":"
".$i."
";                  }              }                   if ($paged < $pages && $showitems < $pages) echo "
Next ›
";              if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "
Last »
";              echo "

\n";          }     }


Linking to Post Types from wp-admin

Morning all, I'm having a bit of trouble finding a function I can use to link to a post type from the admin area. I'm actually using something as simple as: `<a href='edit.php?post_type=slides'>Slides</a>` in another area, but didn't know if there was a better way of handling it (since I'm still technically hardcoding in the first part of the URL). The post type name being hardcoded isn't the issue, really just generating that first part of the URL. Thanks!


Wordpress members-only page with link visible only to members

How to achieve Wordpress members-only page functionality with a link in the primary menu visible only to members? Is there a plug-in for that? The Wordpress version is 3.2.1. It is self hosted.


How to display custom content in post with category XXX

Let’s say I have one post with tittle "Dummy one" and that post is filed under "Category one" and i have other post eg : "dummy two, dummy tree, etc" and category two, category three etc. and now I create other post with title "helper for category one" how to display permalink to "helper for category one" in all post with "category one" I want to put it under `the_content();` in `single.php`. Let’s say my `single.php` is like this               if( have_post()):     while( blah blah ):     the_content();     endwhile;     endif;      i want to like this.               if():     while():     the_content();     if(category == "category one"):     display_helper_for_category_one     else:     display_nothink     endif;     endwhile;     endif;      How can I do that?


Search another database with wp_query using new wpdb

I currently have a simple `wp_query` search working on my wordpress site. I now want that same search to look for results in it's own database and another one on same server. I found that I could use `new wpdb()`and then `$mydb->get_results()` to get the posts. I managed to pull a title of one of the posts but now I want to integrate this into my `wp_query`. Is this even possible? Here is a breakdown of the code:               $args = array(     'post_type' => 'post',      'show_posts' => '10',      'paged' => $paged     );          $the_query = new WP_Query($args);           // Testing the new wpdb instance (RESULT: title echoed out. Working)     $mydb = new wpdb('USR','PSWD','DB','localhost');     $rows = $mydb->get_results(" SELECT * FROM wp_posts WHERE id = '5509' ");     foreach ($rows as $obj) :         echo $obj->post_title;     endforeach;     // So now, how do I use my wp_query to get these results too?          // Loop     if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post();


W3 Total cache "empty all caches" and no stylesheets render

I have the w3 Total cache plugin installed and so far its been great as I'm sure you will all agree, so thanks to the author for an amazing plugin. However, I used the "empty all caches" button on the general settings page and when the plugin is activated none of my stylesheets are loading so the page appears without any styling? I have to deactivate the plugin for the stylesheets to load. How can I reactivate W3 so that the stylesheets all render properly again?


Get a sidebar at the top of the page

I want to get a sidebar ( `get_sidebar( 'mySidebar' )` ) at the top of the page, so I can't call it after `get_header()` in the content template. How could I do it?


Cannot Search | Featured | Popular | Newest | Favorites in wordpress working

I am working on a Wordpress 3.8 site hosted by Parallels and uploaded via the plex panel. When I want to search, featured, popular, newest favorites a new plugin, I get an error message saying > Warning: An unexpected error occurred. Something may be wrong with > WordPress.org or this server’s configuration. If you continue to have > problems, please try the support forums. (WordPress could not establish a > secure connection to WordPress.org. Please contact your server > administrator.) in /var/www/vhosts/fixskinproblems.com/httpdocs/wp- > admin/includes/plugin-install.php on line 77 I had spent 2 days on googling with this issue.


Best way to allow manageable social media URLS?

I am working on a site and it is possible that the site will have a number of pages which feature links to the client's social networking sites (Twitter, Facebook, LinkedIn...). Now I know that the URLs to their profile shouldn't change too often, but they would like the option to update the URLs if they ever needed to. My question is what the best method would be to allow my client to simply visit one page in the Admin area where they can copy and paste the new URLs into the fields for each social media site? I thought about using Custom fields, but I guess there must be a way I can create a small widget that just allows me to echo whatever has been placed in the fields for each social media site. That way I can just echo that particular widget in the 'href' of the social media button and I can use it anywhere I want in my theme files. Problem is, I don't delve much into custom widgets yet and I am not sure whether 1) it's the best way to achieve this and 2) Whether you can create a widget that simply allows you to echo whatever has been place in that field (almost just like a custom field). Any clarification would be greatly appreciated. Thanks,


Custom fields won't update

I have a small problem with custom fields. This is what I am trying to do:   * Whenever a new post is added, I check what category is selected, grab the sub categories and create custom fields with a "0" value based on the sub categories.   * On each post I grab the sub categories, put them in a form and create checkboxes for each. If the checkbox is checked when the submit button is pressed, the value of the custom field is changed to "1". So I basically toggle the 1 and 0. If the value is 1, I use that particular custom field as a title and add some data to the post, and it also adds `checked="yes"` to the checkbox. Everything works great. The only problem I am facing is for custom fields with more than one word. Ex. "Firefox" works, but if the custom field is "Firefox Browser" it won't update. If I manually edit the post and add "1" to the "Firefox Browser" custom field, the checkbox is checked and my div shows up with the "Firefox Browser" title. Unchecking the checkbox and hitting submit changes the value to "0" but checking the checkbox won't change value to "1". Does anybody have any ideas why this happens? Thank you! This is my code:               <?php      //Get the first category of the post     $post_category = get_the_category();     $args = array('parent' => $post_category[0]->cat_ID, 'hide_empty' => 0);     $categories = get_categories( $args );            <form action="http://mysite.com/checkform" method="post">               foreach($categories as $category) {     $chkchk = get_post_meta($post->ID, $category->name, true);     if ($chkchk != "0"){$i = 'checked="yes"';}else{$i = "";}     echo '<input type="checkbox"' . $i . 'name='.'"'.$category->name.'"'.'value=""  />'.$category->name;          }          <input type="hidden" name="post_id" value="<?php echo $post->ID; ?>">     <input type="hidden" name="post_cat" value="<?php echo $post_category[0]- >cat_ID; ?>">     <input type="submit" value="Submit" />     </form>     ?>      * * *               <?php      //Get hidden     $post_id = $_POST['post_id'];     $post_cat = $_POST['post_cat'];                //Get current custom field values     $post_catt = get_the_category();     $args = array('parent' => $post_cat, 'hide_empty' => 0);     $cats = get_categories( $args     );               foreach($cats as $cat) {     $checkthis = get_post_meta($post_id, $cat->name, true);          if (isset($_POST[$cat->name])) {     if($checkthis != 1){     update_post_meta($post_id, $cat->name, 1);}     }else{     if($checkthis != 0);{     update_post_meta($post_id, $cat->name, 0);}     }}`     ?>      * * *               <?php             foreach($categories as $category) {                     $dropthis = get_post_meta($post->ID, $category->name, true);                     //echo $category->name;                     //echo "=";                     //echo $dropthis;                     $abcd = str_replace (" ", "", $category->name);                     $cat_php = strtolower($abcd);                 if($dropthis != 0){                     include 'drops/'.$cat_php.'.php';                 }              } ?>


How do i replace the sidebar to use pages instead of blogs?

I want to use wordpress as a CMS and not as a blog. I am using the default twentyeleven theme and i would like to remove 'archive' (the blog ToC) and 'Meta' (login) and replace it with a sidebar seen on a traditional site. The part i am having trouble is how do i do it in a way were i can add pages to the sidebar from within the admin area rather then hardcoding in php? I also would like it to be in the format below where the heading is not clickable and the entries i can add/remove from the admin area. # About person one   person two # Services Service A   Service B


Get next post when using pagination with WP_Query?

How do i specify which "page" to get when using WP_Query? I'm using pagination and i only display three posts per page, but i need to manually set which page to get, because Wordpress doesn't do that by default it seems. Is there an argument i can send with `WP_Query()` to get a specific page?


Want to use credit card in wordpress, paypal is working fine

I m using wp-ecommerce plugin in which paypal is working fine by developer's account. i want to integrate credit card in wp-ecommerce is any service offers developer credit card testing like in sandbox in paypal?


display only the wp_nav_menu, which has the current-menu-item

i have a problem displaying only the menu with wp_nav_menu, in which the _current-menu-item_ is in. Heres what i got:               function register_menus() {       register_nav_menus(         array(           'sidebar-menu' => __('Sidebar Menu'),           'first-menu' => __('Menu 1'),           'second-menu' => __('Menu 2'),           'third-menu' => __('Menu 3')         )       );     }     add_action('init', 'register_menus')      and on the page.php i'm doing               <?php wp_nav_menu(array('theme_location' => 'first-menu')); ?>     <?php wp_nav_menu(array('theme_location' => 'second-menu')); ?>     <?php wp_nav_menu(array('theme_location' => 'third-menu')); ?>      when i now open up a page, which is in Menu 2, i can style it with _.current- menu-item_ - so no problem here. but i want to display only the one menu, which has the _.current-menu-item_ in it (Menu 2). the other ones (Menu 1, Menu 3) should be _display: none;_ is there a way to accomplish that? i thought of a walker, a filter or a simple if-statement, which checks for the menu, which has the _.current-menu-item_ but i can't handle it myself :-( thank you very much


Is using eval() ok in this scenario

I am trying to include user input includes using "get_template_part()" The includes are added in the theme options eg a user inputs.               get_template_part('content/block', 'branding');     get_template_part('content/block', 'footer');      I need to execute this code as php and have a custom hook for add_before_content() which runs just before content and sidebars. In my layouts class, I have a method that checks the user input and then uses this to add the includes using eval()               function add_before_content() {         global $options;         $string = "get_template_part('content/block', 'branding');";         return eval($string);     }          add_action('before_content', 'add_before_content');      This works perfectly, however I get nervous when using eval() especially when it involves user entered content. My thinking in this scenario is that it should be avoided because it allows users to enter any php code and it will be executed. However, the only access is from the admin login. I have actually since implemented a different solution, but wanted to put this question out there as it will be good to get some feedback. Would eval() be a bad idea in this scenario? ## Further clarification I am trying to achieve the same result as opening the index.php file of the theme and adding `get_template_part()` to include a template file. For example: `<?php get_template_part('content/block', 'header'); ?>` But allowing the user to do this from the theme options without having to open the themes files. The contents of the file are not really important, its just a normal php include that should be included and run when called. In my theme options I have an editor element (extended textarea) I use for a few features so code can be added into the theme from the theme options without the user needing to open the theme files. This works perfectly fine for html that I have added so far. The value is stored in the database and when its echoed in the theme, it echoes the html, no problem. However, when I wanted to allow the user to add the includes which is php from the theme editor its where I got stuck. There are 2 places the user would add these includes. Above and Below the content which there are also hooks for which is why I use them. Here is a screenshot of the editor with the includes defined. http://cl.ly/3n3r3H381g1U1a2t3T3g What I need is for the files branding and header to be included, just as if I had opened the index.php file and entered the get_template_part includes in the file manually, instead of the editor. Just echoing the value using the way you explained outputs it on the page as a string like this http://cl.ly/3I251I0B282i0c0E0U2j Instead of actually including those template files. Using eval() means that the saved value of the editor which is a string, would be evaluated as php and it adds the includes just as if I added it in the index.php, hence why it works and is the only way I could figure it out. I hope this makes things a lot clearer. Thanks for your patience :) ## The concept This particular feature I am talking about here is the only place I was doing something quite like this where I am trying to add php and have since gone a different route, but posted this question about eval() as I wanted to confirm my thinking. This is a parent theme and when first installed only has a content area and sidebars… nothing above or below. Like a "clean slate" to start from when building a site. The theme has something called a "block builder" which allows users to define and add/remove "building blocks" to their website and then define the content to show in these building blocks. eg: they can add a block called "branding" A building block is just like any "section" of content on a website. A logo area, a navigation area, footer shelf, toolbar etc. The building blocks concept is taken from the Joomla template framework we developed which has building blocks at its core. www.getmorph.org Once a block is defined, it can be set to output in one of 4 ways.   1. Widgets (if set to widgets a new widget pos with the block name is created)   2. Featured posts (can featured any posts on the post page to the block or pull from set categories and display as a grid, carousel, slider etc)   3. Custom html (they can enter any html and some [tags] for popular elements like [logo] [sitename] etc that come with the theme. Yes this can be done using widgets as well, so they can set widgets as the output and put html in the widget.. its the same result, this is just a little easier but open to user preference.   4. Disable block.. turns it off and unpublishes it. The block creation is fully automated, when a new block is added, a new include with all the relevant options is created and a theme options page is also created on the fly using ajax. Obviously this will not work without actually calling the block in the theme somewhere… this is the only manual step and where the whole point of my original question comes to light. It is easy for any user to open the index.php or better create a child theme and add an index.php and add the code to call the block `<?php get_template_part('content/block', 'header'); ?>` This is even how it is explained in the documentation and a code snippet is even generated with the block name, they just click to copy it. Instructions are given on how to add the block.. this is the only thing they need to do. Very simple indeed. However, while doing alpha testing with a closed team of users, a few asked if it would be possible to not have to open the theme files to add the block include… hence my question. Note: the building blocks are optional to use.. users don't have to use them, they can just use the theme like any other theme, but for many users this will make building and modding their website a lot!! easier. It means instead of defining 70 widget positions just in case a user needs it. Our approach is scalable, it starts off with only the sidebar widget position. As a theme is developed using slate as a base, unlimited widget positions can be added as needed by adding the required blocks.


Get all meta boxes values

I want to list all the values of a custom metabox in a custom post type. Here is the code to get the one meta box in a single post               <?php echo get_post_meta($post->ID, 'institution_location', true);?>      but say I want to list all the meta boxes in the home page or a dropdown menu in a search form not just in a single page the metabox code                add_meta_box(         'Location_metabox',         __( 'Location ', 'twentyeleven' ),         'institution_location_metabox_output',         'institution',         'side'     );      Thanks # Solution I tried to use WP_Query and it works fine.               <?php         $args = array('post_type' => 'institution');         $the_query = new WP_Query($args);              while ( $the_query->have_posts() ) : $the_query->next_post();         $id= $the_query->post->ID;         $location = get_post_meta($id, 'institution_location', true);         echo $location;         endwhile;     ?>


How to pass variable via $callback_args for add_meta_box

I trying to pass some variable to the callback function through add_meta_box. Knowing that there is $callback_args that can be use to pass the variable. But somehow I just can't get it work within a class. This is my codes               class myclass{      //.....blah blah....adding action       function add_ex_field() {          add_meta_box( 'apextadmin', __( 'My Custom Field', 'myplugin_textdomain' ),array($this,'the_callback_function'),post,array('test'=> $param));}//the $param is some value that saved in my option table.     }           function the_callback_function($post, $metabox){//do I need to include these two parameters? because they gave me error!       echo '
testing field
';      echo $metabox['args']['test'];      }          }     global $myclas;      $myclas = new myclas();      Thanks.


How to load a template without it being assigned to a page/post?

Can I create a template and load it without associating a page/post to it in WordPress? The template will list custom posts in XML. [update] I have a jquery carousel that loads an XML file through ajax. I am storing each slide as a custom post type call 'carousel_slide'. I want to create an XML feed with these custom post types. At first I created the feed outside wordpress, including wp-load.php and using WP_Query. This worked fine but I now realize that I need a multi-lingual plugin (WPML) to be loaded as well. This is why I want to create a wp template instead. However if I create a template, I need to assign a page to it to be able to load it. I'd rather not create an empty page simply to be able to call a template. I am new to WordPress development and might have overlooked an obvious solution.


Customize the Wordpress Default Gallery Output

I want to customize the Wordpress default gallery so that it would format as something like this for each item:

      Basically I want the link (`<a>`) to have:   * `rel` for activating lightbox script (defined as "lightbox-cats" by user manually in each gallery)    * `href` that links to direct URL of the image (e.g.: http: // mydomain.com/link/to/image.jpg)   * `title` that is for Wordpress image caption   * `name` which is the image file name (e.g.: image.jpg) I've been trying to create the formatting through modifying snippets I got from [here] and [here], but it gets very messy because I don't know how to remove unncessary stuff. For example, I don't need the `<a>` to link to the attachment page (something like http :// mydomain.com/?attachment=20). I only need it to link _directly_ to the image URL. Using filter and adding it to `functions.php`, here is what I have done so far (it's very messy): http: // pastebin.com/Q51W1BVr I put it into pastebin because it's a bit too long (I'm sorry I can't make it a link because I don't have enough reputation point here :/ ) Though I believe the parts which modifies the output is only from here:               $i = 0; // Modified output from here     foreach ( $attachments as $id => $attachment ) {              $link = wp_get_attachment_link($id, $size, true, false);         if( ! empty($rel) ) { !!! // Add rel injection             $link = str_replace('<a href=', "ID ). " alt=", $link);         } else {             $link = str_replace('<a href=', "post_excerpt) . "' name='", $link);              $output .= "<{$itemtag} class='gallery-item imgteaser'>         ";         $output .= $link;         $output .= "</{$itemtag}>         ";              if ( $columns > 0 && ++$i % $columns == 0 )             $output .= '
';     }          $output .= "

\n";          return $output;     }      * * * Here is how messy the output result is:
                  <img width="150" height="150" src="http://localhost/test/wp-content/uploads/2012/09/002-150x150.jpg" class="attachment-thumbnail" alt="002" title="002"
      It works, but it has the unnecessary `alt="http://localhost/test/?attachment_id=36"` because I don't know to remove it. And I feel my code is really unefficient/unclean. :/


Manage custom menu for an Editor?

I've a problem with permission. Is there a specific permission to let an user with Editor Role, manage the custom menu of a theme, and _only this options?_ The item that is under Appereance -> Menu, to be clear. I'm using the capability plugin. Must I write a custom hook to enable only the use of custom menu editor ? TIA Edit: I've code a simple solution. See below my answer!


Problem with W3 Total Cache Interfering with Cron Jobs

I'm having an issue on a site where I schedule posts and they all miss their schedule every time and end up having to be manually published later in the day. I have WP cron disabled (`define('DISABLE_WP_CRON', true);`) and have a manual cron job (`wget -q -O - http://example.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1`) set up instead. W3 Total Cache is set to Disk for Object Cache a Disk: Enhanced for Page Cache. I tried setting `define('ALTERNATE_WP_CRON', true);` instead and no luck - posts still miss schedule.


Posts 2 Posts: Display custom types connected to the same other custom type but with another connection

I'm creating a Tennis website. I've got 2 custom types : players and tournaments. I would like to display the result of the finals on the tournaments page and players page. That is to say, on each page of tournament I want to display the name of the finalists (winner and loser) and on each page of player, I want to display the name of the tournaments for wich this certain player was finalist (and display his corresponding opponent). I hope I'm understandable! With the help of the plugin Posts 2 Posts, I created 2 connections between the players and the tournaments:                   p2p_register_connection_type( array(                 'name' => 'won_final',                 'from' => 'player',                 'to' => 'tournament'             ) );     and         p2p_register_connection_type( array(                 'name' => 'lost_final',                 'from' => 'player',                 'to' => 'tournament'             ) );      I have no idea of what code I can use to find and the display the corresponding opponent of a certain player when I display the tournaments for which the player was finalist. Any help to put me on a track ? Thanks!


How to prevent apostrophes and quotes from appearing in permalinks?

I'm using custom permalinks "/%category%/%postname%/". Whenever a post title contains quotes or apostrophes they appear in the URL. Can someone tell me how prevent them from appearing in the slug? I am running WordPress 3.0.4.


Errors when uploading images in WP 3.5

I'm trying to upload images in WP 3.5 to set featured images for posts. Unfortunately I get the following error message: > An error occurred in the upload. Please try again later. The installed theme is Minimatica. I've tried Googling the issue, but couldn't find any solution except downgrade to WP 3.4.2.


Hide plugin list

I want to hide my plugin list. Suppose anyone can see which plugin I use from this site. How can I hide my plugin list from here? I use WordPress new version, and I want to always update my plugin but don't want anyone can see my plugin name. How can I do that?               function cws_hidden_plugin_12345( $r, $url ) {         if ( 0 !== strpos( $url, 'http://api.wordpress.org/plugins/update-check' ) )     }


Add description text under input field for new profile fields

How can I modify my following code to add some description text under the input fields? I tried modifying it as you can see with the facebook url field but the text shows up under the field label and not the actual input field --               function modify_contact_methods($profile_fields) {         // Add new fields         $profile_fields['address'] = 'Address';         $profile_fields['city'] = 'City';         $profile_fields['state'] = 'State';         $profile_fields['zipcode'] = 'Zip Code';         $profile_fields['phone'] = 'Phone Number';         $profile_fields['fax'] = 'Fax';         $profile_fields['gplus'] = 'Google+ URL';         $profile_fields['twitter'] = 'Twitter URL';         $profile_fields['facebook'] = 'Facebook URL
Ex: www.facebook.com/username';         // Remove old fields         unset($profile_fields['aim']);         unset($profile_fields['yim']);         unset($profile_fields['jabber']);              return $profile_fields;     }     add_filter('user_contactmethods', 'modify_contact_methods');


How to put custom admin setting field into a shortcode

I set up an admin settings menu and I'd like to output the fields as a short code. The way I learned to output the fields from a tutorial was with:               <?php $input_examples = get_option('sandbox_theme_input_examples'); ?>     <?php echo sanitize_text_field( $input_examples[ 'textarea_example' ] ); ?>       But putting that into the shortcode doesn't work:               function shortcode()     {          return '<?php $input_examples = get_option('sandbox_theme_input_examples'); ?>';     return '<?php echo sanitize_text_field( $input_examples[ 'textarea_example' ] ); ?>';          }     add_shortcode('shortcode', 'shortcode');      I'm guessing there is a specific way to put php code into the shortcodes that I'm not understanding? I've looked all over and can't find a solution to this.


How to get/display specific WP page with beloning page template in DIV (fullPage.js)

I've recently been trying out the really neat JavaScript snippet for fullPage- design from Alvaro Trigo. http://www.alvarotrigo.com/fullPage/. I use it togheter with WordPress with the purpuse of creating a sleak and minimalistic publishing tool for portfolios and alike. The script makes you divide the website into different DIVs with every DIV representing a new page. In my startpage I've got my regular loop from WordPress wich gets all the regular posts. Now I need to make a "About" page where everything needs to be editable from the back end. I use custom meta- boxes to make the fields for all the different text-objects. For this "About" page i also made a specific page template to suit my needs and here comes my problem. I can't seem to get the specific page with this specific page template. Is it possible? The only thing I've been able to achieve is to get the content, pagetitle and specific metaboxes. But just the content of these and none of the page template. To get this content information I've used this php code:

          <?php     $page_id = 23;  //Page ID     $page_data = get_page( $page_id );           //Store page title and meta-boxes in variables     $title = $page_data->post_title;      $meta_box1 =  get_post_meta($post->ID, '_wpb_offer_module', true);     $meta_box2 =  get_post_meta($post->ID, '_wpb_for_module', true);     $meta_box3 =  get_post_meta($post->ID, '_wpb_love_module', true);           //Display the title and meta-boxes     echo $title;     echo $meta_box1;     echo $meta_box2;     echo $meta_box3;     ?>
      This code is as you can se inserted in the DIVs regulated by the fullPage.js så appear on a individuall page. The next div instead includes my loop like this:
          <?php get_template_part('loop'); ?>
       I know that i could make the `echo`command could just output my values into DIVs but i would like to have it more customizible for a person without knowledge of HTML and such later. Is it possible to get my specific page with ID 23 with the beloning "page- about.php" template somehow? In the same way as I `only use get_template_part` with the loop? In that way i could have the loop for the page inside of the page-about.php instead. This would also make it easier to create some of my other pages as they otherwise will encounter the same problem.


Pasting formatted text from MS-Word

I want to paste into Wordpress posts large amounts of text stored in MS-Word files. When I directly copy-paste from MS-Word, the page usually breaks because of various MS-Word control characters. So I prefer to save my text as .txt and then copy pure text and paste it in Wordpress. However, I then lose all formatting, like bold and italics. Any ideas?


Add a DropDown Taxonomy Filter on Archive Page

I need to add a taxonomy dropdwon filter in archive page so that I can display the posts assigned to selected taxonomy. Here is the HTML Output for taxonomies:               <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">       <select name="services" id="selectservice" class="postform" onchange="submit();">         <option value="">Select Service</option>         <option value="intensive-support">Intensive Support</option>         <option value="recovery-work">Recovery Work</option>         <option value="tenant-support">Tenant Support</option>       </select>     </form>      Below is the Query Code :

           Name	           Location	           Website	           Service(s)
         <?php $service_query = new WP_Query('post_type=ptype_service&posts_per_page=-1'); ?>         <?php $j = 0 ?>         <?php while ($service_query->have_posts()) : $service_query->the_post(); ?>         <?php $additional_class = (++$j % 2 == 0) ? 'even' : 'odd'; ?>         <tr class="<?php echo $additional_class ?>">           <?php the_title()?>	           <?php echo (get_post_meta($post->ID, 'pir_groups_location', true))?>	           <a target="_blank" href="http://<?php echo (get_post_meta($post->ID, 'pir_groups_website', true))?>"><?php echo (get_post_meta($post->ID, 'pir_groups_website', true))?>	                        <?php             $terms = get_the_terms( $post->ID, 'services' );             if ( $terms && ! is_wp_error( $terms ) ) :                       $services_links = array();                   foreach ( $terms as $term ) {                     $services_links[] = $term->name;                 }                                                $on_draught = join( ", ", $services_links );             ?>             <?php echo $on_draught; ?>             <?php endif; ?>
         <?php endwhile; ?>
      Regards


Separate blog on one WordPress

I have created few static web pages for my small coaching institute using WordPress. We have three faculty and I want that each faculty should have their blog. So I want `http://myinstitute.com/faculty1` as a blog of Faculty 1, and Faculty2 and Faculty3 respectively for each faculty. And I want this to integrate on my WordPress site. Also I want that all post should NOT club under one head of coaching institute. Is it possible using simple customization, and if _yes_ , how?   If _not_ by simple customization, then what all changes need to be done?


display a dynamic calculated value on each of the post wordpress

i am working on wordpress based coupon site. I have to create a amount calculator which would work on all the individual category pages . I would be having a amount slider which would be having $ values. Once a value is selected and on clicking the submit button, i want the percentage deals (under that respective category) to calculate a amount with respect to the $ amount selected using the slider. and then displaying it on their respective deals. I hope the idea is clear. Till now, i have managed to, take all the posts title of the current category page into an array, and then using the preg_match feature, i have managed to extract out the '%' deal amount. Also i have created a simple slider which the user will need to input their $ amount.               <?php     $array = array();     global $post;     $category = get_the_category($post->ID);     $category = $category[0]->cat_ID;     $myposts = get_posts(array('numberposts' => 1, 'offset' => 0, 'category__in' => array($category), 'post_status'=>'publish'));     foreach($myposts as $post) :     setup_postdata($post);          $title = get_the_title();     array_push($array,$title);           endforeach; ?>      <?php wp_reset_query(); ?>            <?php             foreach($array as $str) {     if(preg_match('/(\d+)\%/i' ,$str,$m)) {                  echo $m[1],"\n"; ?>            <input type="text" name="a" value="<?php echo $m[1]; ?>" size=5>           <?php  }     } ?>      the above code is used to fetch all the post under the current category and extracting the % value from the respective post title. The extracted number is in '$m[1]' which i would like to pass against the respective post. I am not able to define the respective post and passing that '%' amount and in return sending the calculated amount and saving it back to that particular post. that is, on clicking the submit button, i would want that each post having percentage value would get calculated and get displayed against that particular post. Sorry for such a huge explanation. I didnt want any detail to get missed out. Any help would be appreciated.


is_home() not working in functions.php file

I'm using woo themes and trying to use some woo hooks to hook into the index.php file from my child theme. I'm using the following code:               function content_woo_main_before() {         if  (is_home() || is_front_page()) {             include('includes/home-news.php');         }     };     add_action('woo_main_before', 'content_woo_main_before', 15 );          function content_woo_main_after() {         if  (is_home() || is_front_page()) {             include('includes/home-news-after.php');         }     };     add_action('woo_main_after', 'content_woo_main_after', 15 );      The strange thing about this is that the first function loads as it should on the home page, but the second one does not. I tried a few things like changing the order that the functions are run, changing the names, I tried wrapping the functions in the conditional statement. Nothing worked. Am I doing something wrong here? I found a few other posts that had something similar to this, about how the `is_home()` won't work in functions.php, because it runs before we know if we're on the home page, but that wouldn't explain why the first function works properly, and the second one doesn't. Anyone have any ideas? **UPDATE:** So, based on the feedback I've gotten, I've updated the following using `get_template_part()` http://www.re-electsusanguidry.com/admin/ here's the code:               function content_woo_main_before() {         echo 'is_home1 =' . is_home();         echo 'is_front_page1 = ' .  is_front_page();              if  (is_home()) {             get_template_part('home', 'news');         }     };     add_action('woo_main_before', 'content_woo_main_before', 20 );                    function content_woo_main_after() {         echo 'is_home2 = ' . is_home() . '<br />';         echo 'is_front_page2 = ' .  is_front_page();         if  (is_front_page()) {             echo 'is_home3 =' . is_home();             echo 'is_front_page3 = ' .  is_front_page();             get_template_part('home', 'after');         }     };     add_action('woo_main_after', 'content_woo_main_after', 21 );      Here's what I don't get. If I have both of these functions with both using `is_home() || is_front_page()`, the first returns "1", but the second functions return nothing at all. So, "is_home1" returns 1, "is_front_page1" returns 1, therefore it's true and the content loads. However, "is_home2" and "is_front_page2" returns nothing, the conditional statement returns false, and the content doesn't load. I tried various numbers for the loading sequence, but that didn't do anything. I put some crazy long number and it still didn't return true. What's also weird is that if I take out the first function (woo_main_before), the second one works as expected. Only when both of them are there does the second one not work. I can't seem to find anyone else with this problem online. I have no idea what's wrong. Any ideas?


Loading jQuery library from WordPress admin

When we are developing Themes, we are taught to enqueue the **jQuery library** if necessary, because no jQuery library is available on the front-end of WordPress (if I'm not wrong). But when we are into the Admin Panel of WordPress, WP is using jQuery for various purposes -- WordPress back-end, by core, already loading jQuery into its admin area. So, when we are developing Back-end features for a Theme or Plugin, and we are in need of loading jQuery, is that possible to load jQuery library from WordPress bundle? I'm asking this because in one of my under-dev. plugin, I added jQuery library-   * from the jQuery CDN,   * and as a fallback, from the plugin bundle (using this SO thread) Now, on every page-refresh my admin panel hits the jQuery CDN, and takes the jQuery lib file from the CDN. If there's no internet connection the php-file- read throws a debug error, but the jQuery loads from my plugin bundle. But if we can load jQuery from the WP bundle, it'll save time and load of a page, I think.


Change the layout of user-edit.php profile

I've got a website with over 200 users, and they all use their profiles to display up to date information on themselves and services that they offer. Is there anyway to change the layout / style of user-edit.php? In a non-destructive way, I don't want to avoid updating. I've been adding extra fields to the user profile page, fields, wysiwyg's and images, but they're laid out in one huge list and it looks ugly and confusing to say the least. I'd love to be able to put it in a nice format, perhaps with tabs so they've got better content management for their profile.


addaction hook cause redirection problem

I have added the hook in my wp functions:               add_action('pa_taxname_edit_form_fields',  'woocom_edit_attribute_chk_field', 10, 2);               function woocom_edit_attribute_chk_field($term, $taxonomy) {          //////////////// My code here          }          add_action('edited_term', 'woocom_attribute_chk_field_save', 10, 3);          function woocom_attribute_chk_field_save($term_id, $tt_id, $taxonomy) {                     metas = $_pOST['aa'];                      update_woocommerce_term_meta($term_id,'_designparent', $metas);          }      Here the field saved successfully. But it is not redirect to the edit- tags.php. Here the query strings are missed. Actual url = `edit- tags.php?action=edit&taxonomy=pa_taxname&tag_ID=1036&post_type=product` But after save the page redirected to `edit-tags.php` (Query strings missed)


Print string to footer using wp_footer option

add_action('wp_footer','slider_option');           function slider_option() {         $option ="<script>script function data                         </script>";          echo $option;       }      I want to print or you can say insert data in `$option` variable to footer menu Any suggestions?


Settings API - save multiple tabs at once

In the attached screenshot you can see the structure of the theme options we are working with. There are 8 tabs and for each tab, we have created custom fields using code similar to what can be seen below.This is how we are setting the default values for each field. ( ie. default = 'http://facebook.com/samplefacebooktitle')               function facebook_callback() {              $item ='facebook';         $default ='http://facebook.com/samplefacebooktitle';         $group = 'general_display_options';         $input = create_input($item,$default,$group);         echo $input;     }      and then the create_input function:               function create_input($item,$default,$group) {              $obj = $group.'['.$item.']';         $options = get_option($group);          if ($options[$item] != '') {              $value= $options[$item];          } else {              $value = $default;          }         return '<input type="text" id="'.$item.'" name="'.$obj.'" value="'. $value .'" />';          }      In order to initialize the defaults though, we need to save each tab individually the first time the theme loads and this theme is to be customized for internationalization by many companies in other countries. So, the question is, Is there a simple way to pre-load these default values and have them saved automatically before the theme options are saved the first time. And if not, does anyone know a way to save all theme options at once when you click save on any given tab? ![](http://i.stack.imgur.com/1VLxH.jpg) ------- EDIT --------------------- Thanks to Chip Bennett for helping me get this working! The below code is a bit gnarly, but it works, and sets up the defaults on theme activation. Also added is a check to see if values are '' and if so, we re-set them to the defaults created in the create_general_defaults() function. Please feel free to let me know ways to optimize this code.               <?php          function theme_menu() {         add_theme_page(             'My Theme',             'My Theme',             'administrator',             'theme_options',             'theme_display'         );          }      add_action('admin_menu', 'theme_menu');          function theme_display( $active_tab = '') {     ?>

Theme Options
             <?php settings_errors(); ?>             <?php                 if(isset($_GET['tab'])) {                     $active_tab = $_GET['tab'];                 } else if ($active_tab == 'nav_options') {                      $active_tab = 'nav_options';                 } else {                     $active_tab = 'display_options';                 }             ?>
                 <a href="?page=theme_options&tab=display_options" class="nav-tab <?php echo $active_tab == 'display_options' ? 'nav-tab-active' : ''; ?>">General                 <a href="?page=theme_options&tab=nav_options" class="nav-tab <?php echo $active_tab == 'nav_options' ? 'nav-tab-active' : ''; ?>">Nav
             <form method="post" action="options.php">                     <?php                         if( $active_tab == 'display_options' ) {                             settings_fields( 'theme_display_options' );                             do_settings_sections( 'theme_display_options' );                         } else if( $active_tab == 'nav_options' ) {                             settings_fields( 'theme_nav_options' );                             do_settings_sections( 'theme_nav_options' );                         }                         submit_button();                     ?>             </form>
     <?php     }          /* -------------------- *       *  register settings      *  -------------------- */     //global $theme_display_get_options;     // $theme_display_get_options = theme_display_get_options();          function initialize_theme_options() {              // verify if the options exist         if(false == get_option('theme_display_options')) {             add_option('theme_display_options');         }              add_settings_section(             'display_settings_section','General Options','display_options_callback','theme_display_options'         );              add_settings_field('facebook_alt','Facebook Alt Tag','facebook_alt_callback','theme_display_options','display_settings_section');              register_setting('theme_display_options','theme_display_options');          }     add_action('admin_init','initialize_theme_options');               function display_options_callback() {         echo '
Enter the necessary values for the following fields.
';     }          function create_general_defaults() {         global $general_defaults;         $general_defaults = array(             'theme_title' => 'My Title Yo',             'facebook' => 'http://facebook.com',             'facebook_alt' => 'My default'         );              //save these in case something is blank and it will return to its default value         $general_orig_defaults = apply_filters('my_options_defaults', $general_defaults);         return $general_orig_defaults;     }      create_general_defaults();          function get_general_defaults() {         $option_defaults = create_general_defaults();         global $the_theme_options;         $the_theme_options = wp_parse_args( get_option('theme_display_options', array() ), $option_defaults );         return $the_theme_options;     }     get_general_defaults();          function facebook_alt_callback() {              global $general_defaults;         global $orig_defaults;              $orig_defaults = $general_defaults;         $item ='facebook_alt';         $group = 'theme_display_options';         $form_object = 'text';         callback_standard($item, $group, $form_object, $orig_defaults);          }          function callback_standard($item, $group, $form_object) {         global $the_theme_options;         global $orig_defaults; // defaults set in the               $default = $the_theme_options[$item];         if($default == '') {             $default = $orig_defaults[$item];         }              $obj = $group.'['.$item.']';         if ($form_object == 'text') {             echo '<input type="text" id="'.$item.'" name="'.$obj.'" value="'. $default .'" style="width:300px;" />';         } else if ($form_object == 'textarea') {             '<textarea id="'.$item.'" name="'.$obj.'" rows="5" style="width:500px" />'. $value .'</textarea>';         }     }               /*  --------------------------------------------------------     *   Navigation Options     *   --------------------------------------------------------*     */          // left off for abbreviated example               /*  ----------------------------------------------------     *   Templated settings field output     *   ----------------------------------------------------     */     function create_input($item,$default,$group) {              $obj = $group.'['.$item.']';         $options = get_option($group);         if ($options[$item] != '') {             $value= $options[$item];         } else {                  $value = $default;         }         return '<input type="text" id="'.$item.'" name="'.$obj.'" value="'. $value .'" style="width:300px;" />';          }     function create_textarea($item,$default,$group) {              $obj = $group.'['.$item.']';         $options = get_option($group);         if ($options[$item] != '') {             $value = $options[$item];         } else {             $value = $default;          }         $value = stripslashes($value);         return '<textarea id="'.$item.'" name="'.$obj.'" rows="5" style="width:500px" />'. $value .'</textarea>';          }               ?>


Setup login/register buttons for bbPress?

I installed bbPress and for the most part it was a fairly simple setup. I just had to activate the plugin and the forums showed up automatically on /forums. One thing I wasn't sure about (and I did look through the documentation) was how to set up login/register buttons for unregistered users. Currently, if you go to this forum as an unregistered user, it says "You must be logged in to create new topics." Am I supposed to use shortcodes for the login/register buttons? If so, where do I insert them?


Weird Code Being Added to Wordpress Site [Thesis]

Ok, so I'm totally confused on this and am looking for help. I have a site that is loading really slowly. I tracked the source of the slow load time is this call right here:                     Funny thing is that it's getting added right after the html code. I've looked all through my code in the Thesis theme, and I can't find where that code is being added. While looking at my thesis code, in the /lib/html/header.php file, I found this:               function thesis_header() {         echo "\t
\n";         thesis_hook_header();         echo "\t
\n";     }      so I thought maybe that a piece of code was using the add_action('thesis_hook_header') call, however I did one more tweak. I changed the output from id="header" to id="header1". As soon as I did this, the script code went away. So I'm thinking that there is some code that is looking for div id="header" and then putting the script right after it. But for the life of my, I cannot find the piece of code that is doing it. Has anyone had this problem before?


Save users last visited blogs within whole network

I have a big network with subdomains (many of which use domains). I thought about solving this problem with cookies but after some research I don't think that crossdomain cookies is a best Idea. So I imagine this happing by saving in users meta some array of blogs and then displaying them on main page. I came across **update_user_meta()** which is very handy in my case.               global $blog_id;     $current_blog_details = get_blog_details( array( 'blog_id' => $blog_id ) );          if (is_user_logged_in()) {         $user = wp_get_current_user();         update_user_meta($user->ID, 'last_visited_blogs',  $current_blog_details->blogname);     }      I save this function inside admin-bar.php so every blog shares this code. Now I want to remake this code to use save 5 last visited blogs as an array and then get those values and display on some place. First question would be how to save 5 sites. I guess update is not my case no?