question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I'm newbie in wordpress. I want to implement a page like stackexchange-url ("stackexchange-url no idea how to implement. The user listing, info, avatar,user search everything will same. any idea about the issue???
Take a look at Members List Plugin The Members Plugin allows you to create a post on your wordpress blog that lists all your wordpress members. When viewing the list of members you can also search through your members according to first name, last name, email address, URL or any other number of user meta fields you may specify. Employing pagination you can page through your search results and sort your results according to last name, first name, registration date, email or any other field you may specify I'm currently using it in a project and it works great.
Author page like wordpress answers
wordpress
I have a custom post type for portfolio. To create one, you need to create a page with a particular template that i'm making, named page-portfolio. Now, a portfolio post has custom fields as well. But, how can i make a custom field that is displayed in the post only if i select the 'portfolio' template ? That is, a custom field tied to the usage of the portfolio template ?
This is confusing you're mixing up the terminology of WordPress. A custom post type acts like a post and not a page . If you have a custom post type called "portfolio" and use the proper template hierarchy, you don't have to do anything special. But you will need to name it <code> single-portfolio.php </code> and not <code> page-portfolio.php </code> . http://codex.wordpress.org/images/1/18/Template_Hierarchy.png http://codex.wordpress.org/Post_Types If on the other hand, if you simply want to use "page" templates ( I think that is what you mean) you will need to write a conditional to display the post meta for only the <code> page-portfolio.php </code> . The logic is along the lines of: <code> if (is_page_template('page-portfolio.php')) the_meta(); </code> Your default page most likely already has <code> the_meta(); </code> though so you will most likely want to use <code> get_post_meta </code> or <code> get_post_custom </code> so you can have fields specific to your "portfolio". ps. It's much easier to just use a custom post type (not a page template) for this sort of thing . http://codex.wordpress.org/Custom_Fields#Function_Reference http://codex.wordpress.org/Function_Reference/is_page_template
Custom fields for custom post types
wordpress
I have a bunch of options that I'd like the user to be able to change in bulk. Here's my code example. When this option selection changes, <code> &lt;label&gt;Default author&lt;/label&gt; &lt;select name='default_author' id='default_author' class=''&gt; &lt;option value='1'&gt;user 1&lt;/option&gt; &lt;option value='5'&gt;user 5&lt;/option&gt; &lt;option value='4'&gt;user 4&lt;/option&gt; &lt;option value='6'&gt;user 6&lt;/option&gt; &lt;option value='2'&gt;user 2&lt;/option&gt; &lt;/select&gt; </code> These options below change too. The option selected is to match the one selected above. <code> &lt;select name='post_author[0]' id='post_author[0]' class=''&gt; &lt;option value='1'&gt;user 1&lt;/option&gt; &lt;option value='5'&gt;user 5&lt;/option&gt; &lt;option value='4'&gt;user 4&lt;/option&gt; &lt;option value='6'&gt;user 6&lt;/option&gt; &lt;option value='2'&gt;user 2&lt;/option&gt; &lt;/select&gt; &lt;select name='post_author[1]' id='post_author[1]' class=''&gt; &lt;option value='1'&gt;user 1&lt;/option&gt; &lt;option value='5'&gt;user 5&lt;/option&gt; &lt;option value='4'&gt;user 4&lt;/option&gt; &lt;option value='6'&gt;user 6&lt;/option&gt; &lt;option value='2'&gt;user 2&lt;/option&gt; &lt;/select&gt; </code> I'm trying to do this using jQuery. Before putting this into WordPress, I tested my code on a static HTML page and it works. But the moment I port it into WordPress it doesn't and I'm really at a loss. Here's what have in my .js file. <code> jQuery(document).ready(function() { jQuery("#default_author").change(function() { selected = jQuery('#default_author').val(); alert(selected); }); jQuery("#default_author").change(function() { selected = jQuery('#default_author').val(); jQuery("select[name^='post_author']").attr('selectedIndex',selected); }); }); </code> Yes, there are 2 change functions in there because I wanted to see if I'm actually getting the value or not and I am. The alert gives me the right value. I've been up and down this for hours not familiar with jQuery, I'm surprised I got this far. Does <code> attr('selectedIndex', value) </code> not work in WordPress? Using WP 3.2.1 by the way. Thank you so much for any help anyone can give me.
this isn't a WordPress thing, just an issue with your JS. this: <code> jQuery("select[name^='post_author']").attr('selectedIndex',selected); </code> should be: <code> jQuery("select[name^='post_author']").val(selected).attr('selected','selected'); </code>
Selecting multiple options onclick
wordpress
I am a trying to create a dashboard like custom page template that list post of of the current logged in user. I've tried to find a solution on the net. but none were appropriate
this should work for you: <code> if ( is_user_logged_in() ): global $current_user; get_currentuserinfo(); $author_query = array('posts_per_page' =&gt; '-1','author' =&gt; $current_user-&gt;ID); $author_posts = new WP_Query($author_query); while($author_posts-&gt;have_posts()) : $author_posts-&gt;the_post(); ?&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php the_title_attribute(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt; &lt;?php endwhile; else : echo "not logged in"; endif; </code>
How to display posts by current user/author in a custom page template?
wordpress
I need to divide a set of taxonomy terms by the first letter of the term name. I found a few bits of code that may help but when I implement my code I get no return values. I'm sure it has to be something fairly small in my code but I just cannot find it. This taxonomy contains brands and labels carried by shops listed on my site. So the number of terms is quite large. Some of the labels/brands/terms start with numbers, other letters and others are foreign characters like Russian and could be Japanese, Arabic etc as the site grows The following code is just my first run to show only the terms that begin with Letters. <code> $letters = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); $numbers = array(0,1,2,3,4,5,6,7,8,9); $chracters = array_merge( $letters, $numbers ); $args = array( 'orderby' =&gt; 'name', 'order' =&gt; 'asc' ); $terms = get_terms( $taxonomy, $args ); if( count($terms) &gt; 0 ): foreach( $terms as $term ): $firstchar = (string) substr( $term-&gt;name, 0 ); $firstchar = strtoupper( $firstchar ); $termlink = get_term_link( $term-&gt;slug, $taxonomy ); if( in_array($firstchar,$letters) ): ?&gt; &lt;div class="post-box alignleft"&gt; &lt;p class="post-title"&gt;&lt;a href="&lt;?php echo $termlink; ?&gt;"&gt;&lt;?php echo $term-&gt;name; ?&gt;&lt;/a&gt;&lt;/p&gt; &lt;/div&gt; &lt;!-- /end .post-box --&gt; &lt;?php endif;//is a letter endforeach;//$terms as $term endif;//count&gt;0 </code> I am not sure what is causing terms not to display. Here is the link to the development server http://obeliskwebdesign.com/sandbox/directorysexy/in-stock-sort/ Thanx for any insights or help. I've been stumped.
<code> $taxonomy </code> is possibly not set in this example? or maybe you've set it somewhere else in your code? also may want to check out php's ctype functions here.
How to list terms by first letter, as in A's then B's etc
wordpress
I'm having some trouble with a custom thing I'm doing. I've implented a custom image uploader into a metabox in a custom post type. Now I'm trying to work out a way that will let me reorder the uploaded images. I found that jQuery Sortable would be a convenient way for the user to be able to just drag and drop in which order the images should appear (in the frontend I'm using a jQuery image slider to show the images and the order of the images are decided by the attachment data "menu_order", so therefor I need some sort of functionality that saves the menu_order that I create with the jQuery Sortable. Now, this is a simplified example of what I have: http://jsfiddle.net/LN4sA/ Together with each attachment I have added hidden input fields with the attachment id and a field that will house the current position of the attachment in the menu order. The ID of the attachment is easily fetched with basic WP PHP ($attachment-> ID). However, I have not yet found an easy way to populate the #att_order with the proper menu_order. So here I'd like some help/input if someone would be so kind. To save the actual information I'm using ajax to pull the values from the input fields: <code> add_action('save_post', 'save_attachment_position'); function save_attachment_position(){ global $post; if ($post-&gt;post_type == 'work') { ?&gt; &lt;script type="text/javascript"&gt; //&lt;![CDATA[ jQuery.ajax({ type: 'post', url: ajaxurl, data: { action: 'order_attachment', att_ID: jQuery(this).parents('.attachment').find('#att_id').val(), att_order: jQuery(this).parents('.attachment').find('#att_order').val(), _ajax_nonce: jQuery('#ordernonce').val(), post_type: 'attachment' } }); //]]&gt; &lt;/script&gt;&lt;?php } } </code> And then use wp_update_post to update the attachment data: <code> add_action('wp_ajax_order_attachment', 'order_attachment'); function order_attachment($post) { $attachmentdata = array(); $attachmentdata['ID'] = $_POST['att_ID']; $attachmentdata['menu_order'] = $_POST['att_order']; wp_update_post($attachmentdata); } </code> I'm aware that I need some sort of loop here but I will work that out. Any ideas? Thanks
I'm not entirely sure what your intentions are for the code, and unfortunately i didn't find what you provided worked very well, so i rewrote parts of the code supplied to make it into a more workable solution. This code will work for saving the attachment order in the metabox on <code> save </code> , not via ajax, but realistically there's no reason to save those changes on every sort(is there?). I refactored the code so you can adjust the post type at the top of the code. I'm not sure what you aiming for with the enqueue call, and pretty sure it can't be called in the way you were doing, nor was it needed on the post editor page anyway(sortable and the necessary scripts are already available/loaded on the editor screen). Give this a shot and see how you get on.. (note this is a working sample).. <code> // Not applicable to my testing, but left it in because i'm sure it's appropriate to your usage add_theme_support( 'post-thumbnails' ); add_image_size( 'editor-thumb', 130, 72, true ); // Quicker to update one line than several, only reason it's defined here $my_post_type = 'book'; // Add metabox on the proper metabox hook add_action( 'add_meta_boxes_' . $my_post_type, 'add_image_sortable_box', 2000 ); // Fire jQuery only on the appliable pages add_action( 'admin_footer-post.php', 'add_sortable_to_elements', 2000 ); add_action( 'admin_footer-post-new.php', 'add_sortable_to_elements', 2000 ); function add_image_sortable_box() { global $my_post_type; add_meta_box( 'test-image-thing', 'Sortable Attachments Test', 'do_image_metabox_thingy', $my_post_type, 'side', 'default' ); } function add_sortable_to_elements() { ?&gt; &lt;script type="text/javascript"&gt; //&lt;![CDATA[ jQuery(document).ready(function($) { $('#attachmentcontainer').sortable(); }); //]]&gt; &lt;/script&gt; &lt;?php } function do_image_metabox_thingy( $p ) { // No global statement needed here, the hook this function is attached to gives you the post object $args = array( 'order' =&gt; 'asc', 'orderby' =&gt; 'menu_order', 'post_type' =&gt; 'attachment', 'post_parent' =&gt; $p-&gt;ID, 'post_mime_type' =&gt; 'image', 'post_status' =&gt; null, 'numberposts' =&gt; -1, ); $attachments = get_posts( $args ); if( $attachments ) : // Only need 1 nonce to cover the lot wp_nonce_field( 'my_attachment_sort', 'attachment_sort_nonce' ); ?&gt; &lt;div class="imageuploader"&gt; &lt;div id="attachmentcontainer"&gt; &lt;?php foreach( $attachments as $attachment ) : $attachmentid = $attachment-&gt;ID; $editorimage = wp_get_attachment_image_src( $attachment-&gt;ID, 'editor-thumb', false, false); ?&gt; &lt;div class="attachment" id="test-&lt;?php echo $attachment-&gt;ID; ?&gt;"&gt; &lt;div class="image"&gt; &lt;img width="100" height="auto" src="&lt;?php echo $editorimage[0]; ?&gt;" /&gt; &lt;input type="hidden" name="att_id[]" id="att_id" value="&lt;?php echo $attachment-&gt;ID; ?&gt;" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php endforeach; ?&gt; &lt;div style="clear: both;"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php endif; } // Updates the attachments when saving add_filter( 'wp_insert_post_data', 'test_meta_save', 1000, 2 ); function test_meta_save( $data, $_post_vars ) { global $my_post_type; if( $my_post_type != $data['post_type'] || !isset( $_post_vars['attachment_sort_nonce'] ) ) return $data; if( defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE ) return $data; if( !wp_verify_nonce( $_post_vars['attachment_sort_nonce'], 'my_attachment_sort' ) ) return $data; global $post_ID; if( !current_user_can( 'edit_post', $post_ID ) ) return $data; if( isset( $_post_vars['att_id'] ) ) { foreach( $_post_vars['att_id'] as $img_index =&gt; $img_id ) { $a = array( 'ID' =&gt; $img_id, 'menu_order' =&gt; $img_index ); wp_update_post( $a ); } } return $data; } </code> Of course make sure to switch the post type value, book is my testing post type.. :) Any questions, add them to your original question, then drop a comment onto this answer to let me know..
Custom function to rearrange attachments when creating posts – Almost there
wordpress
I've created a custom post type as a plugin and released it into the repository. One of the core features involves using a featured image. I've added <code> thumbnail </code> to <code> $supports </code> in <code> register_post_type() </code> , so the meta box shows up in the Administration Panel. I'm also hooking into <code> after_setup_theme </code> and calling <code> add_theme_support( 'post-thumbnails' ) </code> , but I don't think it's taking affect. The codex says you have to call it from the theme's functions.php file , but if that's true then it'll only work if the user's theme calls <code> add_theme_support( 'post-thumbnails' ) </code> (which would cover all post types. If the theme doesn't call it, or only calls it on a specific type, then it won't work. Does anyone see a way around this problem?
There are comments in core code that this should be improved, but they are there for a while already. Basically there is no native function to add or remove part of some feature, only feature altogether. Doing it manually would be running something like this after theme is done (late on <code> after_setup_theme </code> hook): <code> function add_thumbnails_for_cpt() { global $_wp_theme_features; if( empty($_wp_theme_features['post-thumbnails']) ) $_wp_theme_features['post-thumbnails'] = array( array('your-cpt') ); elseif( true === $_wp_theme_features['post-thumbnails']) return; elseif( is_array($_wp_theme_features['post-thumbnails'][0]) ) $_wp_theme_features['post-thumbnails'][0][] = 'your-cpt'; } </code>
Using add_theme_support inside a plugin
wordpress
I found the perfect slider for my needs, the only issue now that is that I cannot get it to work correctly. Problem that occur is that the function created doesn't work like it should. It ought to display three posts from a specific category but it ends up pushing more posts, presumedly via the loop in the function. And the slider effect won't work at all - probably because of this. Check the url below. It's step 2, at the bottom. The code for slideshow_featured_posts. I have a feeling something is missing in the code, because I already see that we're missing php-tags in it. But I can't see what. Can anyone who knows this better than me help out? http://www.paddsolutions.com/how-to-integrate-jquery-cycle-plugin-to-wordpress-theme/
replace <code> slideshow_featured_posts </code> function from that tutorial with this: <code> function slideshow_featured_posts() { $featured = 1; // Assuming that the name of the category ID number 1 is "Featured". $count = 3; // How many post to be shown as slides. Ideally, it should be more than 3 posts. add_filter('excerpt_length', 'hook_excerpt_featured_length'); $Silder_query = new WP_Query(array('cat' =&gt; $featured, 'posts_per_page' =&gt; $count)); ?&gt; &lt;div class="list"&gt; &lt;?php while ($Silder_query-&gt;have_posts()) : $Silder_query-&gt;the_post(); ?&gt; &lt;div class="item"&gt; &lt;a class="image" href="&lt;?php the_permalink(); ?&gt;" title="Permanent Link to &lt;?php the_title_attribute(); ?&gt;"&gt; &lt;?php the_post_thumbnail('slideshow'); ?&gt; &lt;/a&gt; &lt;div class="meta"&gt; &lt;h3&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;" title="Permanent Link to &lt;?php the_title_attribute(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h3&gt; &lt;?php the_excerpt(); ?&gt; &lt;/div&gt; &lt;div style="clear: both"&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;/div&gt; &lt;?php wp_reset_query(); remove_filter('excerpt_length','hook_excerpt_featured_length'); } </code> everything else is ok.
Problem with custom function from jQuery slider tutorial
wordpress
I'm trying to pass a post's content (which may contain HTML) to JavaScript via wp_localize_script(). wp_localize_script() can't handle multi-dimensional arrays, so I'm encoding it in JSON and then decoding it with jQuery . That works fine as long as you it's only text and you replace the <code> &amp;quot; </code> entity with a regular <code> " </code> before you call <code> $.parseJSON() </code> . If you try to parse a post with HTML in it, though, you get errors like, JSON.parse: expected property name or '}' http://redacted.local/wp/wp-includes/js/jquery/jquery.js?ver=1.6.1 Line 16 So, I'm guessing I need to do some more string manipulation before trying to parse it, to convert more entities back to the regular characters, but I don't want to just pick the few characters I'm having errors with because I'm sure there are dozens more that I might miss. Is there a comprehensive or standard way of doing this? I've done a lot of searching and having found any answers, so it makes me think I'm missing something obvious. Here's the PHP side: <code> public function loadResources() { // ... wp_register_script( 'bgmp', plugins_url( 'functions.js', __FILE__ ), array( 'googleMapsAPI', 'jquery' ), self::BGMP_VERSION, true ); // ... if( !is_admin() &amp;&amp; $this-&gt;mapShortcodeCalled ) { // ... wp_enqueue_script('bgmp'); $bgmpData = array( 'options' =&gt; $this-&gt;getMapOptions(), 'markers' =&gt; $this-&gt;getPlacemarks() ); wp_localize_script( 'bgmp', 'bgmpData', $bgmpData ); } // ... } public function getPlacemarks() { // ... foreach( $publishedPlacemarks as $pp ) { // ... $placemarks[] = array( // ... 'details' =&gt; $pp-&gt;post_content, // ... ); } return json_encode( $placemarks ); } </code> And here's the JavaScript side <code> // ... init : function() { // ... bgmpData.markers = $.parseJSON( bgmpData.markers.replace(/&amp;quot;/g, '"') ); // ... }, // ... </code>
While it's not exact answer to your precise question, I agree with method suggest in comment. Just skip trying to stuff data into single dimension and make use of <code> l10n_print_after </code> argument instead. See stackexchange-url ("pass object/JSON to wp_localize_script") question and answer there.
Passing JSON-encoded HTML from Wordpress to JavaScript
wordpress
I'm using the Wordpress SEO by Yoast plugin. I'm having problems getting the Sitemaps XML section to work properly. Google gives me the dreaded red X for the status of the sitemap. The error message Google gives is: 208 "Invalid URL This is not a valid URL. Please correct it and resubmit." The incorrect Google XML lists is: http://#/ . In the XML sitempap created by the plugin, I can see that that URL is listed. I'm not sure where the XML Sitemap generator came up with this URL. In order to get my dropdown menus to work, I set the URL to # on some blank pages that only have a title. For example, the first child in my navigation is a blank page with a URL set to # and a title of "A-C". The "A-C" page's children are the pages of all of the areas starting with A thru C. I set the "A-C" page's robot meta to noindex, nofollow. Does that have something to do with the problem? I don't have a page named http://#/ . As I don't have a page with this URL listed in my WordPress Pages section, I can't set it to noindex, nofollow. Any suggestions on how to solve this problem? Thank you.
Okay, I ended up using the Google XML Sitemap plugin. You can input the post id's of the pages you want excluded from the sitemap. I excluded the pages with null links and now Google accepts the sitemap.
Mystery URL http://#/ Listed in XML Sitemap Created by WordPress SEO by Yoast Plugin
wordpress
I'm making this wordpress theme, and I need to create a menu that is vertical but its submenus are horizontal, like this: <code> MenuItem SubmenuItem | SubmenuItem AnotherMenuItem SubmenuItem | SubmenuItem </code> Now using wp_nav_menu() and CSS I can get this effect, but I don't have any idea on how to add the pipe symbol to separate the submenu items. <code> wp_nav_menu(array( 'container'=&gt;false, 'after'=&gt; ' | ', 'theme_location'=&gt;'home-menu', 'menu_id'=&gt;'main_nav_left', 'menu_class'=&gt;'main_link', )); </code> is no good as it will turn out as <code> MenuItem | SubmenuItem | SubmenuItem | </code> (adding a | after every item, which is the documented behavior) I was wondering if there was a way to selectively add the pipe symbol so that it is added only between the submenuitems and not after anything else. According to WP documentation, there doesn't seem to be a built-in method to support this. So what is the best way to accomplish this effect (without editing wp core code)?
This is another case where a pure-CSS definition will work. For example: <code> #main_nav_left li:after { content: ' | '; } #main_nav_left li:last-child:after { content: ''; } </code>
How to append to menu items selectively
wordpress
I'm new to wordpress. Is it possible to say i would like to make this article public on this day and time AND have wordpress tweet it? Possibly tweeting the subject+link or a twitter msg i add in + link on that said time/date?
WordPress doesn't have "tweeting" functionality built in. However, post scheduling is built in. You just set the time when you want the post to publish on the edit post screen. If you use a twitter plugin like my own Simple Twitter Connect , and you schedule a post, then it will send the tweet at the same time as the post is published. STC requires some setup, but the STC-Publish module, using auto-publish, will support scheduled posts just fine. The only downside is that scheduling itself uses the WP-Cron mechanism, which is more a of "best-effort" mechanism than an actual scheduler. The WP-Cron system fires based on people visiting the site. So if nobody visits the site, then the schedule can vary. For example, say you schedule a post for 6pm. If nobody visits the site until 7pm, then the post publish doesn't happen until 7pm, and the tweet sent by STC also won't occur until 7pm. No way around this, really, the WP-Cron system relies on there being traffic to the site to trigger it into action.
Timed post and tweet?
wordpress
When do I use the following: home.php frontpage.php Under Settings > Reading Settings Front Page Posts Page I wish to clarify this as I find myself using "Placeholder Pages", empty pages just for the sake of a menu item and to display blog listings. If I use a Static Front Page (Set under Settings > Reading Settings > Front Page) how do I access my posts page? Do I need to have a "Placeholder Page" titled blog and use <code> page-blog.php </code> ?
You don't ever directly use (as in, select as a Page template) either <code> front-page.php </code> or <code> home.php </code> . WordPress uses these template files automatically, according to the Template Hierarchy rules. The <code> front-page.php </code> template file is used to display Site Front Page , whether you have set the site front page to display a static Page or the Blog Posts Index . The <code> home.php </code> template file is used to display the Blog Posts Index , whether the blog posts index is set to display on the Site Front Page or an a separate static Page . The <code> front-page.php </code> template file will override <code> home.php </code> on the Site Front Page . The <code> home.php </code> template file will override <code> page.php </code> (or any <code> page-{custom-template}.php </code> selections) on *non-front page static Pages`. If I use a Static Front Page (Set under Settings > Reading Settings > Front Page) how do I access my posts page? Do I need to have a "Placeholder Page" titled blog and use page-blog.php? To display the Blog Posts Index on a non-front page static Page: Create a new static Page, with any arbitrary title ("Blog", "News", or anything else you want), and leave the Page Content blank/empty Under <code> Dashboard -&gt; Settings -&gt; Reading </code> , set "Posts Page" to the static Page you just created. Really; that's it. If you want to customize the display of your static-page-as-blog-posts-index, simply modify the <code> home.php </code> template file. Creating a <code> page-blog.php </code> template file will have no effect.
Pages: frontpage.php, home.php, posts page etc
wordpress
I had asked a related question on Super User: A use case of a system "receiving" files over FTP would be, for example, the way WordPress plugins are installed via 1-click where WordPress initiates a file transfer to the local Linux box from the remote WordPress plugin repository using ftp(s) More specifically this screen: My initial understanding that WordPress would transfer the files from the WordPress plugin repository, like how a FTP client would do. But stackexchange-url ("further discussions on chat") have left me confused as to why would WordPress require the FTP details of the web server? What am I missing here?
When you do something that requires WordPress write to the filesystem, it does a check to see if it has permissions to do so by writing a temp file. If this check fails it will ask for FTP details in order to write the files to your server. EDIT look in <code> wp-admin/includes/file.php </code> , line 843, for the <code> get_filesystem_method </code> function that does this check.
Why does WordPress require a ftp server to be running on the webserver to transfer plugins?
wordpress
I am making a portfolio site where each portfolio entry is a subpage of "Work". In my template, I am trying to say something like: worked on 15 projects and counting, where 15 is the total number of subpages. Whats the easiest way to do this?
Use the following code, replacing the number after "child_of=" to the id of the parent page. <code> &lt;?php $count = 0; $pages = get_pages('child_of=681&amp;depth=1'); foreach($pages as $page) { $count++; } echo $count; ?&gt; </code> Reference: get_pages
Easiest way to show total number of subpages
wordpress
The home page displays the sidebar below the rest of all the latest posts, leaving a vacant sidebar area for the majority of the (long) page. The sidebar displays fine on any single post . My index.php and single.php are practically identical, apart from minor differences in the "next post", "previous post". There are no widgets deployed in the theme sidebar, which is called sidebar1; there are no other sidebars. All the elements of the sidebar are coded into sidebar.php, and there are no conditions to check which page is calling the sidebar, so it should (and is) displaying the same content on both the index page, and on individual posts, just in different locations. Category pages display the sidebar in the correct location too. I thought that there might be posts with <code> &lt;br clear="all"&gt; </code> listed on the home page, which were pushing the sidebar down, but the only post which has this content is not on the home page any more, and it displays the sidebar fine. None of the individual posts contain content which is too wide - they all display fine as individual posts, and even when the content is too wide, it just displays underneath the sidebar, it doesn't push it downwards. I use a caching plugin, but I have cleared the cache on the server and in my browser. When I display the site in IE8, I receive an error: <code> Webpage error details Message: 'ajaxurl' is undefined Line: 1 Char: 102 Code: 0 URI: http://www.superlogical.net/wp-includes/js/wp-lists.js?ver=20110521 </code> but I receive the same error on individual posts and the sidebar displays fine in IE8. I haven't made any template changes in the last 2-3 days I can think of, and it was displaying fine yesterday. There is nothing in Google Chrome CSS element inspector indicating any CSS issues that I can see. Any ideas about what is happening here?
This has nothing to do with the JS error. On the home page, you're missing a closing div tag for <code> #content </code> and that is throwing the sidebar down below. You have other code errors, too: [Invalid] Markup Validation of superlogical.net - W3C Markup Validator . Scroll down in the validation report to see line numbers and source code.
Sidebar missing from Homepage
wordpress
He Guys, i've been looking for a way to show a different Page-Template based on HTTP Referer or maybe the User Agent or what ever. I'm planning an Image-Gallery which should be shown in a Fancybox. My Idea is to use a template which contains only the <code> loop </code> and all the stuff i need to build the gallery correctly (without any Header and Footer files) and load it in my Fancybox. But what about the Search Engines und Users with disabled JavaScript. They don't see anything or only a page without the Pagecontext like Navi etc. How can i prevent this issue? Any ideas
Fancybox has built in fallback, it displays images without JavaScript. I don't see why you would want to remove the header ( or footer) since it usually contains some good info like your doctype, css, meta, title, etc. If you want it to look different ( aka strip it clean) you should still include it and use conditionals for your "Portfolio" page.
Different Template based on HTTP Referer
wordpress
In Settings--> Permalinks is there any difference between: checking Custom Structure and using: /%post_name%/ or /%postname%/ Are they both correct? Will they both work? Thank you. -Laxmidi
<code> /%postname%/ </code> is the correct one and if you are asking be cause it says post_name in the codex then its just to show that you will get the actual post name.
/%post_name%/ or /%postname%/ in Permalinks?
wordpress
I'd like to add the field "Company Name" to the add new user page in the admin panel. I've done quite a bit of searching and have been unable to find details on how to do this. I can easily add info to the profile page and registration with.. <code> function my_custom_userfields( $contactmethods ) { //Adds customer contact details $contactmethods['company_name'] = 'Company Name'; return $contactmethods; } add_filter('user_contactmethods','my_custom_userfields',10,1); </code> But no dice on anything else.
In order to do this you'll have to manually change the user-new.php page. It's not the correct way to handle it but if you're in desperate need this is how it's done. I added <code> &lt;tr class="form-field"&gt; &lt;th scope="row"&gt;&lt;label for="company_name"&gt;&lt;?php _e('Company Name') ?&gt; &lt;/label&gt;&lt;/th&gt; &lt;td&gt;&lt;input name="company_name" type="text" id="company_name" value="&lt;?php echo esc_attr($new_user_companyname); ?&gt;" /&gt;&lt;/td&gt; &lt;/tr&gt; </code> I also added the information to functions.php <code> function my_custom_userfields( $contactmethods ) { $contactmethods['company_name'] = 'Company Name'; return $contactmethods; } add_filter('user_contactmethods','my_custom_userfields',10,1); </code>
Adding fields to the "Add New User" screen in the dashboard
wordpress
I've created a child theme that is a wide version of twenty-ten, and it is working for the most part. But I am struggling to make the header logo wider. You can see the work in progress here at http://7d7d.net The CSS that is not working is (it still shows as 980px): <code> #branding { margin: 0 auto; width: 1140px; } </code> I can see that the generated html for the logo div is: <code> &lt;div role="banner" id="branding"&gt; &lt;img width="940" height="198" alt="" src="http://7d7d.net/wp-content/uploads/2011/07/cropped-header.jpg"&gt; &lt;/div&gt; </code> And that header.php defines the logo like so: <code> &lt;img src="&lt;?php header_image(); ?&gt;" width="&lt;?php echo HEADER_IMAGE_WIDTH; ?&gt;" height="&lt;?php echo HEADER_IMAGE_HEIGHT; ?&gt;" alt="" /&gt; </code> But I can't see where to set <code> HEADER_IMAGE_WIDTH </code> and <code> HEADER_IMAGE_HEIGHT </code> . The CSS file is here: http://7d7d.net/wp-content/themes/twenty-ten-wide/style.css
in your theme's functions.php, look for this: <code> // The height and width of your custom header. You can hook into the theme's own filters to change these values. // Add a filter to twentyten_header_image_width and twentyten_header_image_height to change these values. define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) ); define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 198 ) ); </code> Its best to creat a child theme , so you don't loose your customization when you next update WP/theme.
Making a 1140px wide header logo in the twenty-ten theme?
wordpress
Is there a plugin for this? Has anyone done it before?
I use the Auto Post Thumbnail plugin for doing just that on this site and it works fine. First image in a post becomes the featured image every time.
Any easy way to automatically set the first inline image in a post as the thumbnail?
wordpress
Ok i have a wordpress site network. I would like to setup a support forum for my site. But i don't want users to signup in different pages. I mean i want my users to use the same wordpress login credentials in forum too. Is there any forum plugin available there. Thanks PS: Is it possible using bbpress?
take a look at Mingle Forum plugin, which is nice, simple and did the job for me on a couple of sites. also bbPress looks promesing but its still in a beta stage like @Rarst pointed out. and last you have SimplePress which is by far the most feature rich forum plugin I've seen.
What is best forum script available to integrate with wordpress?
wordpress
This lists the posts in my custom taxonomy template page: <code> &lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt; </code> How can I order those posts by comment count?
A friend helped me with a solution that I could place in my functions.php file: <code> add_filter( 'pre_get_posts', 'my_pre_get_posts' ); function my_pre_get_posts( $query ) { if ( is_tax( 'locations' ) &amp;&amp; empty( $query-&gt;query_vars['suppress_filters'] ) ) $query-&gt;set( 'orderby', 'comment_count' ); return $query; } </code>
How to order posts by descending comment count on taxonomy page?
wordpress
In wp-signup.php there are these lines: <code> add_action( 'wp_head', 'wpmu_signup_stylesheet' ); get_header(); </code> I need to remove <code> wpmu_signup_stylesheet </code> from the <code> wp_head </code> action, but I seem to be struggling, I assume it is because the action is being called straight after. Here is what I've tried from a plugin: <code> // Called from an action that is added with: // add_action('wp_head', array($this, 'remove_signup_style', 11)); remove_action( 'wp_head', 'wpmu_signup_stylesheet'); </code>
The action is not right after actually. There is <code> get_header() </code> call, then <code> get_header </code> action and then locating and loading template file that has <code> wp_head() </code> in it. I try not to mess with removing things from inside of same hook you are at, so in this case I'd (ab)use that <code> get_header </code> action to hook function that will remove what you don't want from later <code> wp_head </code> .
Is it possible to remove this action? (as it's added just before it's called)
wordpress
I'm writing a plugin that will be using custom fields added by a theme. Because of this, it would be ideal if my plugin not be able to activate should these fields not exist. How do I go about displaying an error and forcing the activation to fail?
Code like this can do the trick. <code> function plugin_activation_check(){ if ( some_check_here() ) { // this is the fail case deactivate_plugins(basename(__FILE__)); // Deactivate ourself wp_die("Message to user."); } } register_activation_hook(__FILE__, 'plugin_activation_check'); </code>
Force plugin to fail activation
wordpress
I have custom post type <code> product </code> like wp ecommerce. There are 30k posts in it. Also have relate custom taxonomy. Basically am trying to export those posts in csv, but query_posts with so many records is giving me trouble... Any tips???
WordPress query mechanism drag whole set of results into memory so they are not suited for such large chunks of information. You can use <code> numberposts </code> and <code> offset </code> in <code> get_posts() </code> to split process into chunks. I am not sure if you will be able to do it in single run even then, so you might need to save how many chunks you processed and start from there next time.
Not able to export large no. of posts in csv
wordpress
Using Wordpress Stats on my site. On the admin bar when logged in and viewing the site, the spark image with daily stats is broken. It's not a critical issue, just an annoyance. Any ideas? Edit: Broken URL: http://www.denveroffthewagon.com/wp-admin/?page=stats&amp;noheader&amp;proxy&amp;chart=admin-bar-hours&amp;height=20&amp;hours=48
While this could be caused by a variety of different issues, here are some general steps to take to try and troubleshoot it. Completely delete the plugin (deactivate and then delete files) and then re-install it. Simple, I know, but often works wonders. Try uploading the plugin files manually as well as installing from within the admin panel using the search to see if either make a difference. Try installing the plugin using the Jetpack combo plugin. Look in the plugin's folder for a <code> .htaccess </code> file. If found, rename it to <code> htaccess </code> (drop the period) and see if that solves it. If so, your server configuration needs to change slightly. Rename the file back to <code> .htaccess </code> (put the period back) Add <code> AllowOverride FileInfo Limit </code> to the top of the <code> .htaccess </code> file Test again. For more info see here: http://wordpress.org/support/topic/plugin-wordpresscom-stats-stats-graph-missing-after-update#post-1366537 If none of the above work, then let us know what server and OS you're running, as well as any errors in your PHP and error logs that you may think are relevant.
Admin bar stats widget plugin image broken
wordpress
I have an events cpt with a slug "event" I am using it in several places but I am trying to create a "day" view that shows all the events for a given day. I also have the archive arg set in the CPT creation in functions.php I have been around and around on this one but essentially here is what I am trying to do: domain.com/index.php?post_type=event&amp;event-date=2011-07-25 this brings up a page that lists a whole bunch of crap(random posts), not the events for that day. Also if I change it to event_archive.php?post_type=event&amp;event-date=2011-07-25, I get a Page can't be found error. I am not even worried about custom rewrite rules at this point, I just want it to work.
You will have to use the rewrite API to get that to work. First you need to register the rewrite rule. <code> add_action( 'init', 'wpse23712_rewrites' ); function wpse23712_rewrites() { add_rewrite_rule( 'events/day/(\d{4}-\d{2}-\d{2})/', 'index.php?post_type=event&amp;event_date=$matches[1]', 'top' ); } </code> Then add your event_date to the query vars so wordpress understands it. <code> add_filter( 'query_vars', 'wpse23712_vars' ); function wpse23712_vars ( $vars ) { $vars[] = 'event_date'; return $vars; } </code> Then on the front end (in your archive-event.php) you can grab the event date with get_query_var() and use it in your query. I'd suggest you store something with a custom field (in the wp_postmeta table) for each even with the ISO formatted date. Then you can run a meta_query to retrieve those event posts. So when someone navigates to yoursite.com/event/day/2011-07-28/ it will show events for that day. I didn't test the above, but you should able to take it from here.
How does: /index.php?post_type=event&event-date=2011-07-25 work? What if it doesn't work?
wordpress
I'm using the migrate db plugin to do some find and replaces to the database after it's been exported. It continues to pester me with the directory isn't writeable error. I've went and chmod'd the whole /wp-content folder with the following command: <code> chmod -R 777 </code> which i know you're not suppoose to do; but it's driving me nuts. it still has the same silly error. Does anyone know which folder it's asking to give the correct permissions?
Ended up just exporting via command line. Neither answers were appropriate for the situation.
Migrate DB Plugin: Error "The directory needs to be writable"
wordpress
I've been looking for a video plugin in the plugin depository but couldn't find one that I'm looking for. Basically, I want visitors to be able to play the video in the home page but the issue here is that the home page is displaying post excerpts. So if I would just post the video as normal, it would be cut in the home page. So I think I would need to hard code the video code of the plugin inside the loop in the home template file, like where $video is the the video file in the post. Does anybody know a video plugin like this? Or is there a work around here, like how to show video in the home page having post excepts. Thanks.
The excerpt is not meant for content that is why it is called "the excerpt". Instead use a plugin like "Vipers Video Quicktags" or "Youtube shortcode" and add it to a template file and you'll probably want to get the url via a post meta field. for example ( using Youtube shortcode plugin and meta field called "video"): <code> $video = get_post_meta($post-&gt;ID, 'video', true); echo do_shortcode('[youtube_sc url='$video']'); </code>
Do you know a video plugin that allows embedding in the home.php file?
wordpress
i need to integrate facebook like button with some of additional features. those are.. every article/post has a 'Like' button (so that using this, when someone clicks 'Like' it'll appear in their Facebook news feed and add them to my Facebook page count direct from within my site) please help me to get all these features with like button. is there any plugin done? or how to achieve from code?
You can't do the multi-like thing, but I use my plugin Simple Facebook Connect for this sort of thing. It has some features that might help you out. The Like module lets you add the Like button to all the posts and such. The Fan Box widget lets you add a fan box to your sidebar. That like button in the Fan Box (Like box) is actually for your Facebook Page. When somebody likes it, then they're liking your page on FB. The Publish module lets your posts get published to your Facebook Page automatically, and users who have liked your page will thus see your new posts appear in their home streams. I recommend using the beta version of the plugin, it tends to work better and is getting very near release: http://plugins.svn.wordpress.org/simple-facebook-connect/branches/new-sfc/
Facebook like plugin with Multi Option-Needed
wordpress
Is there a coding doc or tutorial to create a SEARCH where it search post in all Blogs in WPMU that will place in WPMU primary site SEARCH?
Take a look at WPMU Global Search plugin which can easily search through all blogs into your WordPress MU posts by post title, post content or post author. and if you are not looking for a plugin then just take a look at the code and see how it's done.
Search post in all blogs in WPMU?
wordpress
I want to hide my WordPress site (or any website) from the world and only allow certain users to enter. What's the best way of doing this without setting up user accounts and passwords? Or perhaps more precise, what's the maximum protection I can get without using accounts? Of course, I've chosen to block search engines under settings-> privacy already. But I've thought about blocking people from linking directly to images and files, how can that be done? Is it by putting all the uploads (files/images) in a hidden folder somewhere outside of the WP structure? How do I do that? Thanks!
stackexchange-url ("How to restrict access to uploaded files ?") There's an answer there to help you restrict access to images and other downloadable files.
Maximum protection without using password/login
wordpress
I am running WP 3.2.1 on a dedicated server and having a little trouble with a second menu. I have a menu at the top of the page which is working fine but I've added a secondary left menu to the left column which is currently showing the top menu despite it being selected in the admin to show the left menu. In my functions.php I have: <code> register_nav_menu( 'left-menu', __( 'Left Menu', 'rsi' ) ); register_nav_menu( 'top-menu', __( 'Top Menu', 'rsi' ) ); </code> Then in my theme files I've called them up using: <code> &lt;?php wp_nav_menu( array('rsi' =&gt; 'left-menu' ));?&gt; &lt;?php wp_nav_menu( array('rsi' =&gt; 'top-menu' ));?&gt; </code> What am I missing?
You need to pass an array of menus to the <code> register_nav_menu </code> function like so: <code> register_nav_menus( array( 'menu-1' =&gt; 'Menu Top', 'menu-2' =&gt; 'Menu Bottom' ) ); </code> You then call them in your theme: <code> &lt;?php wp_nav_menu( array( 'theme_location' =&gt; 'menu-2' ) ); ?&gt; </code>
Second menu not showing
wordpress
I have a WP network and have found that users with roles other than "super user" (admins, editors, authors, etc.) are getting a 404 when trying to preview draft posts/pages/custom post types. Any idea why this would be? I have the following: Version 3.1.4 Subdomain network install Domain mapping plugin (if this matters) Thanks.
I Found this forum article . It was an issue with the domain mapping and cookies. I ended up making sure the following options were both checked in the Domain Mapping options: Remote Login Redirect administration pages to site's original domain (remote login disabled if this redirect is disabled)
Some users getting a 404 when previewing draft posts/pages
wordpress
Hi i am currently replacing my blog run on wordpress with another neat theme. I tried the preview template feature and everything is fine, just that i don't trust everything so easily when it comes to web-applications. So i want to use the same database currently used[meaning not to use same database for both sites, but make a copy of the database/something with the data/posts] with the post/article and then perfect the theme with the data then replace the old with new. I would like detailed steps for just the database part others i can handle :) thanks for any and every help
Just use the built-in exporter/importer . Export from the existing site, and import into the new site. You won't ever even need to touch the database.
Using the same database on another Subdomain
wordpress
I am using a recipe plugin that uses a custom post type of 'recipe'. I currently have multiple lists of recipes from each category on a page. I am trying to get the title of each category list to link to an archive list of those posts within each category. This is not working, and I'm not sure if I need to create a new archive template, or if I can do it within this code. <code> &lt;ul class="subcats-list"&gt; &lt;h2 class="subcats-title"&gt;&lt;a href="&lt;?php echo get_category_link(39); ?&gt;" title="No Cook"&gt;&lt;?php echo get_cat_name(39); ?&gt;&lt;/a&gt;&lt;/h2&gt; &lt;?php $recipes = new WP_Query(); $recipes-&gt;query('showposts=5&amp;orderby=rand&amp;cat=39&amp;post_type=recipe'); while ($recipes-&gt;have_posts()) : $recipes-&gt;the_post(); ?&gt; &lt;li&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;?php endwhile; ?&gt; &lt;/ul&gt;&lt;!-- subcat --&gt; </code> NOTE: the title for each category list does currently link to the category archive page, but there are no posts listed. Just a black archive page.
How did you create the link with your category '39'? Is it a custom taxonomy? Here's the test i just did and it works fine: In <code> functions.php </code> i created the custom post type ' recipe ': <code> add_action( 'init', 'create_recipe' ); function create_recipe() { register_post_type( 'recipe', array( 'labels' =&gt; array( 'name' =&gt; __( 'Recipes' ), 'singular_name' =&gt; __( 'Recipe' ) ), 'public' =&gt; true, 'show_ui' =&gt; true, 'publicly_queryable' =&gt; true, 'exclude_from_search' =&gt; false, 'menu_position' =&gt; 4, 'query_var' =&gt; true, 'supports' =&gt; array( 'title', 'editor') ) ); } </code> Then i created a custom taxonomy element to get some categories related to this custom post type: <code> add_action( 'init', 'register_cate_livro', 0 ); function register_cate_livro() { register_taxonomy( 'cate-recipe', array( 'recipe' ), array( 'public' =&gt; true, 'labels' =&gt; array( 'name' =&gt; __( 'Categorias' ), 'singular_name' =&gt; __( 'Categoria' ) ), 'hierarchical' =&gt; true, 'query_var' =&gt; 'cate-livro' ) ); } </code> I nammed it ' cate-recipe '. I wrote 3 news posts under ' recipe ' in the admin and created 2 custom categories ' cate-1 ' and ' cate-2 '. Then using your code, i loaded the posts from the custom post type. It works fine but doesnt take in account the custom taxonomy parameter. So here's how i made it in the end: <code> &lt;ul class="subcats-list"&gt; &lt;h2 class="subcats-title"&gt;&lt;a href="&lt;?php echo get_category_link(12); ?&gt;" title="No Cook"&gt;&lt;?php echo get_cat_name(39); ?&gt;&lt;/a&gt;&lt;/h2&gt; &lt;?php $recipes = new WP_Query(); $args = array( 'showposts' =&gt; 5, 'orderby' =&gt; 'rand', 'post_type' =&gt; 'recipe', 'tax_query' =&gt; array( array( 'taxonomy' =&gt; 'cate-recipe', 'field' =&gt; 'slug', 'terms' =&gt; 'cate-1' ) ) ); $recipes-&gt;query($args); while ($recipes-&gt;have_posts()) : $recipes-&gt;the_post(); ?&gt; &lt;li&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;?php endwhile; ?&gt; &lt;/ul&gt;&lt;!-- subcat --&gt; </code> I'm using the ' <code> tax_query </code> ' parameter to query the posts from my custom taxonomy ' cate-recipe ' with the term ' cate-1 ', that i created in the admin. And it loads just the posts that have this "special category". Hope this helps, let me know if it suits your needs.
Archive list for custom post type categories
wordpress
Several months ago my site (powered by WordPress) got hit by that webarh malware infection that set up a bunch of .htaccess redirects to its domain. Restoration of a good site backup nixed the problem, but apparently not entirely. Specifically, whenever I use Chrome, I log into my website's admin panel, and either edit an existing post or add a new post, as soon as the page finishes rendering I'm immediately kicked out to Chrome's warning page about my site containing content from this malware site. I've done a MySQL search of all post_content and comment_content, as well as ran a grep through all the PHP/JS/CSS files I can find, in addition to searching for any remaining rogue .htaccess or index.php files, to no avail. As I mentioned, it happens the moment the post.php or post-new.php finishes rendering and just before any existing text shows up in the box. This leads me to believe it's a plugin that's somehow associated with the text editor that's infected, but I'm not really sure where to look. Also, Firefox issues no warnings at all and allows me to edit as usual. Only Chrome does this (and has been ever since restoring the site). Any thoughts would be appreciated! Edit: In the interest of full disclosure, this is my site: www.magsolweb.net . Again, everything seems to be fine, except when adding a new post or editing an existing one.
Switch to twentyten or another theme for a second and make a test post. That will eliminate the theme. And replace all WP core files folders with ones of the same version; it could still be hiding there. Just upload them; don't do an install. This is a typical hack fix. Or, if you did completely clean the site, it could be a a fluke of the theme's js - or a plugin - that is throwing a signature that Chrome interprets as malware.
Cannot find webarh/malware redirect infection that only shows on Chrome
wordpress
The Professional WordPress Plugin Development book explains in detail how to properly use the Settings API, and it also demonstrates how to add Menus and Submenus, but unfortunately it doesn't provide any joined-up examples of this. Whilst I've managed to get most of it working, I can't figure out how to properly implement add_settings_error on custom Menu pages. Here is my code: <code> function settings_main_validate( $input ) { $valid['text_string'] = preg_replace( '/[^a-zA-Z]/', '', $input['text_string'] ); if ( $valid['text_string'] != $input['text_string'] ) { //add_setting_error: $title, $id, $error_message, $class add_settings_error( 'fields_main_input', 'texterror', 'Incorrect value entered!', 'error' ); } return $valid; } </code> The validation above will work great on setting rendered using <code> add_options_page </code> , but will not display the settings errors on pages rendered with <code> add_menu_page </code> .
There are several components to error/notice creation and display process: <code> add_settings_error() </code> call to add item to stack (global <code> $wp_settings_errors </code> variable). <code> settings_errors </code> transient that keeps the errors so they survive move from page to page. <code> settings_errors() </code> function <code> get_settings_errors() </code> to retrieve errors from memory or transient and then displays them. These work like a charm for Settings API, but unfortunately they aren't setup for generic use. On other hand it is trivial to work around that. Hook <code> settings_errors() </code> to <code> admin_notices </code> on your plugin's page, pass the error code to it so it only shows your stuff. Manually save errors to <code> settings_errors </code> transient (just stuff that global variable into it). Since <code> get_settings_errors() </code> expects hint in GET parameters ( <code> $_GET['settings-updated'] </code> ) that it should check transient instead of memory you can either provide that or get errors from transient yourself and save them back to global variable before your <code> settings_errors() </code> call. Update You are turning this into bit of a mess with multiple question, so I will try to address your concerns here. Settings API does work with admin pages, that don't use Settings section as base. Your real issue is that in that case error/notice reporting does not work. First here is what happens when you post form, set up with Settings API: Data gets posted to special <code> options.php </code> page. There data gets sanitized/validated using callback. Any error/notices that came up during sanitization/validation are collected and saved in transient. You are redirected back to wherever you came from . Now when you load admin page it checks if this page belongs to Settings section and if that case includes tiny <code> options-head.php </code> file, that deals with retrieving and displaying errors notices. So the only thing "not working" on other pages is this latter step, which is trivial to do yourself with overview of related function above (I probably went into too much details on transient, you won't need that for basic case).
How should one implement add_settings_error on custom menu pages?
wordpress
If your common with the code that wp_nav_menu function generates. You should know what im asking for. I need to add an indicator like a plus sign or an arrow to indicate that this menu-item has a sub-menu. I cant find a class or id that would allow me to do that. Im guessing ill need a plugin for this? BUT I need some opinion first. Thanks..
I would do this with JS I'm afraid. It's the quickest simplest form. Using jQuery I have this snippet. <code> jQuery(function($){ $('.menu li:has(".sub-menu")').addClass('has-sub-menu'); }); </code> Then you can use CSS to do what you need :)
How do I add an indicator to my .menu-item if it contains a .sub-menu?
wordpress
There are a lot of plugins that color code. But most java developers work with Eclipse and Eclipse has a very specific way of coloring code. Is there a plugin that colors code exactly the same way Eclipse does?
The majority of the Syntax Highlight plugins work in a way that they create divs,spans with classes styled by css and you can simply overwrite that style with your own css to match the eclipse colors. Update turns out someone has done the job for you, take a look at SyntaxHighlighter Evolved which has an eclipse theme.
Color java code the way it is colored in eclipse
wordpress
How can I generate a pretty permalink correctly for a post knowing the permalink structure? My posts where processed with the FeedWordPress plugin with the "Link" setting set to "Permalinks point to: The copy on the original website". So for all the posts in the admin area when editing a post the "Permalink" field under the post title shows an original, external site's URL, which is stored in the "syndication_permalink" meta data. What I would like to do is to generate a pretty permalink for all such posts that would point to a local host (i.e. the post will have a permalink of type "http://mysite.com/" rather than have an external link to a source), so that I can update the permalinks in DB. I can get the permalink structure using <code> get_option('permalink_structure') </code> . Is there a WP function that I can use to get a pretty permalink generated correctly for a post by its ID? Hope that makes sense. Thanks, Dasha
GUID and permalink are two completely independent things. GUIDs are usually based on permalinks, but they don't have to be. Permalinks are not based on GUIDs in any way in modern WP (it had been changed long ago). If you permalinks are not being generated correctly then that plugin (or some other) is breaking something in a bad way, it is unrelated to what your GUIDs contain.
Create pretty permalink for a post knowing the permalink structure
wordpress
am using Breadcrumb NavXT plugin. i want to show all the pages and subpages in breadcrumb.i know this is tough to understand, so am explain briefly here. i have the pages: -> mainpage ---> subpage1 ---> subpage2 ---> subpage3 if i select main page it need to show you are here> subpage1> subpage2> subpage3 if i select subpage3 it need to show mainpage> subpage1> subpage2> you are here if i select subpage1 it need to show subpage2> subpage3> mainpage> you are here i guess,now you got my question.breadcrumb need to show circularly with all pages. please help me to achieve this. any plugin do this? or any code?:)
That's not traditionally how breadcrumb navigation works, as I'm guessing you've discovered if you're trying to implement Breadcrumb NavXT. :) You might have better luck styling wp_list_pages so the links display horizontally and highlight the page you're on? Here's where it describes how to display the current page / ancestors / children . Best of luck!
breadcrumb need to show all pages and subpages
wordpress
I'm trying to add a new option to a theme options panel to hide/show the comments links in the theme template files. I've got the option to show up in the panel, but there's something wrong in that it doesn't work and there are no php errors. I've noted below in Main options code where I've added the option as an array and where it is sanitized and validated. And at the bottom is the php that shows/hides the comments links according to the options setting. Is this a php logic problem? And ideas? Main options code: <code> /** * Describe the available options **/ $vertigo_options_template = array( array( 'name' =&gt; __( 'Accent Color', 'vertigo' ), 'desc' =&gt; __( 'Change the accent color by entering a HEX color number. (ie: &lt;code&gt;EE3322&lt;/code&gt;)', 'vertigo' ), 'id' =&gt; 'accent_color', 'std' =&gt; 'ee3322', 'type' =&gt; 'colorpicker' ), array( 'name' =&gt; __( 'Font', 'vertigo' ), 'desc' =&gt; __( 'Enable Hitchcock custom font (Note: this font only supports basic Latin uppercase letters, numerals, and some punctuation.)', 'vertigo' ), 'id' =&gt; 'vertigo_font', 'std' =&gt; ( '1' == get_option( 'lang_id' ) ) ? 'true' : 'false', 'type' =&gt; 'checkbox' ), /** My new Option **/ array( 'name' =&gt; __( 'Comments', 'vertigo' ), 'desc' =&gt; __( 'Disable comment links)', 'vertigo' ), 'id' =&gt; 'disable_comments_link', 'std' =&gt; ( '1' == get_option( 'lang_id' ) ) ? 'true' : 'false', 'type' =&gt; 'checkbox' ), ); /** * Calculate default option values * * @return array **/ function vertigo_get_default_options() { global $vertigo_options_template; $default_options = array(); foreach ( $vertigo_options_template as $option ) $default_options[$option['id']] = $option['std']; return $default_options; } /** * Create the options form **/ function vertigo_theme_options_do_page() { global $vertigo_options_template; if ( ! isset( $_REQUEST['settings-updated'] ) ) $_REQUEST['settings-updated'] = false; ?&gt; &lt;div class="wrap"&gt; &lt;?php screen_icon(); echo "&lt;h2&gt;" . get_current_theme() . ' ' . __( 'Theme Options', 'vertigo' ) . "&lt;/h2&gt;"; ?&gt; &lt;?php if ( false !== $_REQUEST['settings-updated'] ) : ?&gt; &lt;div class="updated fade"&gt;&lt;p&gt;&lt;strong&gt;&lt;?php _e( 'Options saved.', 'vertigo' ); ?&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt; &lt;?php endif; ?&gt; &lt;form method="post" action="options.php"&gt; &lt;?php settings_fields( 'vertigo_options' ); ?&gt; &lt;?php $vertigo_options = vertigo_get_theme_options(); ?&gt; &lt;table class="form-table"&gt; &lt;?php foreach ( $vertigo_options_template as $option ) { // Use default value if no option exists $value = ( isset ( $vertigo_options[$option['id']] ) &amp;&amp; !empty( $vertigo_options[$option['id']] ) ? $vertigo_options[$option['id']] : $option['std'] ); ?&gt; &lt;tr valign="top"&gt; &lt;th scope="row"&gt; &lt;?php echo $option['name']; ?&gt; &lt;/th&gt; &lt;td&gt; &lt;?php switch ( $option['type'] ) { case 'colorpicker': ?&gt; &lt;input type="text" name="vertigo_theme_options[&lt;?php echo esc_attr( $option['id'] ); ?&gt;]" id="&lt;?php echo esc_attr( $option['id'] ); ?&gt;" value="&lt;?php echo esc_attr( $value ); ?&gt;" class="color { pickerPosition:'right' }" /&gt; &lt;?php break; case 'checkbox': ?&gt; &lt;input type="checkbox" name="vertigo_theme_options[&lt;?php echo esc_attr( $option['id'] ); ?&gt;]" id="&lt;?php echo esc_attr( $option['id'] ); ?&gt;" value="true" &lt;?php echo ( 'true' == $value ) ? 'checked="checked"' : ''; ?&gt; /&gt; &lt;?php break; default: break; } // END switch ?&gt; &lt;label class="description" for="&lt;?php echo esc_attr( $option['id'] ); ?&gt;"&gt; &lt;?php echo $option['desc']; ?&gt; &lt;?php if ( 'vertigo_font' == $option['id'] ) { ?&gt; &lt;img src="&lt;?php echo get_template_directory_uri(); ?&gt;/inc/images/hitchcock.gif" alt="Hitchcock" id="hitchcock-sample"/&gt; &lt;?php } ?&gt; &lt;/label&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php } // END foreach ?&gt; &lt;/table&gt; &lt;p class="submit"&gt; &lt;?php submit_button( __( 'Save Options', 'vertigo' ), 'primary', 'submit', false ); ?&gt; &lt;?php submit_button( __( 'Reset Options', 'vertigo' ), 'secondary', 'vertigo_theme_options[reset]', false, array( 'id' =&gt; 'reset' ) ); ?&gt; &lt;/p&gt; &lt;/form&gt; &lt;/div&gt;&lt;!-- .form-wrap --&gt; &lt;?php } /** * Sanitize and validate form input * * @param array options * @return array sanitized options **/ function vertigo_theme_options_validate( $input ) { global $vertigo_options_template; $defaults = vertigo_get_default_options(); // Check accent color input format // Valid = hexadecimal 3 or 6 digits $accent_color = preg_replace( '/[^0-9a-fA-F]/', '', $input['accent_color'] ); if ( 6 == strlen( $accent_color ) || 3 == strlen( $accent_color ) ) $input['accent_color'] = $accent_color; else $input['accent_color'] = $defaults['accent_color']; // Check that Vertigo font checkbox value is either true or false if ( ! isset( $input['vertigo_font'] ) ) $input['vertigo_font'] = ( $input['vertigo_font'] == 'true' ? 'true' : 'false' ); // My New Option: Check that Disable Comment Links checkbox value is either true or false if ( ! isset( $input['disable_comments_link'] ) ) $input['disable_comments_link'] = ( $input['disable_comments_link'] == 'true' ? 'true' : 'false' ); // Reset to default options if ( ! empty( $input['reset'] ) ) { $defaults = vertigo_get_default_options(); foreach ( $input as $field =&gt; $value ) { if ( isset( $defaults[$field] ) ) $input[$field] = $defaults[$field]; else unset( $input[$field] ); } } return $input; } </code> And I'm using this in my template files to show/hide the comments template: <code> &lt;?php if ( 'true' == $vertigo_theme_options['disable_comments_link'] ) { ?&gt; &lt;?php comments_template( '', true ); ?&gt; &lt;?php } ?&gt; </code> This is what the options look like in the DB called <code> vertigo_theme_options </code> : <code> a:3:{s:12:"accent_color";s:6:"EE3322";s:12:"vertigo_font";s:4:"true";s:21:"disable_comments_link";s:5:"true";} </code> Edit 7/25/11: This works in template file; need to call options first: <code> &lt;?php $vertigo_theme_options = get_option( 'vertigo_theme_options' ); ?&gt; &lt;?php if ( 'false' == $vertigo_theme_options['disable_comments_link'] ) { ?&gt; &lt;?php comments_template( '', true ); ?&gt; &lt;?php } ?&gt; </code>
To answer the first part of your question: your settings form already has the <code> checkbox </code> case covered; so if you add a new checkbox input, you don't need to add anything to the switch . This code will apply to all checkbox inputs you add: <code> case 'checkbox': ?&gt; &lt;input type="checkbox" name="vertigo_theme_options[&lt;?php echo esc_attr( $option['id'] ); ?&gt;]" id="&lt;?php echo esc_attr( $option['id'] ); ?&gt;" value="true" &lt;?php echo ( 'true' == $value ) ? 'checked="checked"' : ''; ?&gt; /&gt; &lt;?php break; </code> More on <code> switch </code> from the PHP.net manual and from w3schools . I'm a bit confused by the wording of your question: I've got the option to show up in the panel via the array vs. I've noted below... where it appears I need to add it in the "create form" section in the php that builds the form. So: does the new checkbox currently appear in the Settings page form, or does it not appear ? EDIT Since the setting field appears properly in the settings form, I'm going to try to tackle the next two issues: the option not saving properly, and the option not outputting properly. First things first: is the option saving its value properly in the DB, based on the settings form field selection? If it's not saving correctly , then the issue may be that you're not checking for it properly. With a checkbox, if the checkbox isn't enabled, then the entire parameter is omitted from the POST data. In that case, in order to save its value in the DB, you need to check for the option value being set, e.g.: <code> &lt;?php $vertigo_options['disable_comments_link'] = ( isset( $_POST['disable_comments_link'] ) ? true : false ); ?&gt; </code> Note: you'll want to adjust for however you are sanitizing the form data. If you were using the Settings API, it would look more like this: <code> &lt;?php $output['disable_comments_link'] = ( isset( $input['disable_comments_link'] ) ? true : false ); ?&gt; </code> Does this get us closer? EDIT 2 So we know that the option is saving properly in the DB. Now we just need to get it to output properly in the template. Next question: are the options stored in the DB discretely, or as an array? From your settings form markup, it appears that the options are stored as an array , so we need to call <code> get_option() </code> on the array , and then use values in that array: <code> &lt;?php $vertigo_theme_options = get_option( 'vertigo_options' ); ?&gt; </code> Note: to find the actual database entry name, refer to the <code> vertigo_get_theme_options() </code> function. You could also just call this function: <code> &lt;?php $vertigo_theme_options = vertigo_get_theme_options(); ?&gt; </code> Either way, now you should be able to reference your option in <code> $vertigo_theme_options </code> ; e.g.: <code> &lt;?php if ( 'true' == $vertigo_theme_options['disable_comments_link'] ) { ?&gt; &lt;?php comments_template( '', true ); ?&gt; &lt;?php } ?&gt; </code> Does that get us there? EDIT 3 option_name under wp_options is vertigo_theme_options Then try this: <code> &lt;?php $vertigo_theme_options = get_option( 'vertigo_theme_options' ); ?&gt; &lt;?php if ( 'true' == $vertigo_theme_options['disable_comments_link'] ) { ?&gt; &lt;?php comments_template( '', true ); ?&gt; &lt;?php } ?&gt; </code> I'm just about 100% sure this should do it.
Add a new checkbox in theme options
wordpress
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: <code> &lt;?php echo get_the_term_list( $post-&gt;ID, 'skills', '&lt;ul&gt;&lt;li&gt;', '&lt;/li&gt;&lt;li&gt;', '&lt;/li&gt;&lt;/ul&gt;' ); ?&gt; </code> 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: <code> $terms_as_text = get_the_term_list( $post-&gt;ID, 'skills', '&lt;ul&gt;&lt;li&gt;', '&lt;/li&gt;&lt;li&gt;', '&lt;/li&gt;&lt;/ul&gt;' ) ; echo strip_tags($terms_as_text); </code> Returns a list of all the terms used across all the custom post types: <code> &lt;ul&gt; &lt;?php $args = array( 'taxonomy' =&gt; 'skills', 'orderby' =&gt; 'ID', 'order' =&gt; 'ASC' ); $categories = get_categories( $args ); foreach($categories as $category) { echo '&lt;li&gt; '. $category-&gt;name . '&lt;/li&gt;'; } ?&gt; &lt;/ul&gt; </code> Returns nothing: <code> &lt;?php $args = array('orderby' =&gt; 'name', 'order' =&gt; 'ASC', 'fields' =&gt; 'all'); wp_get_object_terms( $post-&gt;ID, $skills, $args ); ?&gt; </code> 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.
Can try this: <code> $terms = get_the_terms ($post-&gt;id, 'skills'); if ( !is_wp_error($terms)) : ?&gt; &lt;?php $skills_links = wp_list_pluck($terms, 'name'); $skills_yo = join(", ", $skills_links); ?&gt; &lt;span&gt;&lt;?php echo $skills_yo; ?&gt;&lt;/span&gt; </code>
How do I list custom taxonomy terms without the links?
wordpress
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
You can turn off caching for your wp_list_comments template by placing <code> define('DONOTCACHEPAGE', true); </code> at the top of the page. Other constants available on a per page or template basis are: <code> define('DONOTCACHEDB', true); </code> Disables database caching for given page. <code> define('DONOTMINIFY', true); </code> Disables minify for a given page. <code> define('DONOTCDN', true); </code> Disables content delivery network for a given page. <code> define('DONOTCACHCEOBJECT', true); </code> Disables object cache for a given page.
Page comes up blank using w3 total cache
wordpress
I have an event scheduled to fetch feeds from different sources at midnight. I believe for some reason it is not being triggered. I use Core Control plugin for testing. When I 'Run Now' through it, it works fine. What could be possible reason? Any hint that could facilitate me to get to the cause? There is no argument to the handler and it is a reoccurring once daily task.
WP-Cron is not a guaranteed time task scheduler. The trigger for WP-Cron is somebody visiting the site itself, so if nobody visits the site at midnight, then the job doesn't run until somebody does visit the site later. Similarly, if you use a whole page caching mechanism like WP-Super-Cache, then anonymous users will not really be "visiting" the site since they're getting cached pages. So that can impact WP-Cron's ability to run on time as well. If you need to run timed events precisely, then you need to use a real cron mechanism instead.
Scheduled event does not run at midnight
wordpress
I came across this function to add image to rss feed. However, I keep getting lots of syntax errors. <code> /* Add RSS Logo */ function addRssImage() { echo "&lt;image&gt; &lt;title&gt;My Title&lt;/title&gt; &lt;url&gt;" . get_bloginfo('template_directory') . "/images/logo.png&lt;/url&gt; &lt;link&gt;" . get_bloginfo('url') ."&lt;/link&gt; &lt;width&gt;300&lt;/width&gt; &lt;height&gt;60&lt;/height&gt; &lt;description&gt;MyDomain.com&lt;/description&gt; &lt;/image&gt;"; add_action('rss2_head', 'addRssImage'); /* End RSS Logo */ </code>
The code you posted is missing an ending <code> } </code> here is a fixed and tested version of that code, so if you still get errors they are coming from another place <code> function addRssImage() { echo "&lt;image&gt; &lt;title&gt;My Title&lt;/title&gt; &lt;url&gt;" . get_bloginfo('template_directory') . "/images/logo.png&lt;/url&gt; &lt;link&gt;" . get_bloginfo('url') ."&lt;/link&gt; &lt;width&gt;300&lt;/width&gt; &lt;height&gt;60&lt;/height&gt; &lt;description&gt;MyDomain.com&lt;/description&gt; &lt;/image&gt;"; } add_action('rss2_head', 'addRssImage'); </code>
How to add logo to rss feed
wordpress
After the solution to stackexchange-url ("this question") was to get a function to launch BEFORE the <code> init </code> action is fired by taking the sequence out of its function, it got me thinking, is there any earlier in the WP load sequence that I can hook a function into?
<code> muplugins_loaded </code> is the very earliest: http://codex.wordpress.org/Plugin_API/Action_Reference (via: stackexchange-url ("stackexchange-url
What is the very earliest action hook you can call?
wordpress
After installation I've got a default root blog '/'. Then I've created a new one '/en'. I really don't want to use the default blog. How can I redirect all accesses from / to /en ?
In your .htaccess file in the main '/' directory, put: <code> # This allows you to redirect index.html to a specific subfolder Redirect /index.html http://example.com/en/ </code>
How to redirect root blog to a specific one in multilang WP?
wordpress
So, I've been building a theme options page, one of the purposes of which is to get some style values to pass to my php stylesheet in the url. Here's what I have: <code> /* Get all theme settings */ global $options; $options = get_option( 'theme_options' ); /* ...and set 'em up! */ $stylevar = '?ts='.$options['thumbsize'].'?bg='.$options['bg_color'].'?tc='.$options['text_color'].'?hc='.$options['heading_color'].'?nc='.$options['nav_buttons_color'].''; /* Enqueue */ if( !is_admin() ){ // This format works wp_register_style('style', (get_bloginfo('stylesheet_directory') . '/lib/css/style.php?ts='.$options['thumbsize'].'')); // This doesn't wp_register_style('style', (get_bloginfo('stylesheet_directory') . '/lib/css/style.php'.$stylevar.'')); wp_enqueue_style('style'); } </code> So two things are happening: I am getting a WP debug error I'd like to address: <code> Notice: Undefined index </code> etc. Presumably this has to do with not doing an <code> isset </code> check? Putting all the settings in a variable is failing, giving me: <code> "style.php?ts=200%3Fbg%3D%3Ftc%3D%3Fhc%3D%3Fnc%3D&amp;amp;ver=3.2.1" type="text/css" </code> . Here's where the schooling comes in. Is there a cleaner way of writing this? Could the options all be output with some king of loop? ... and how do I fix it? Willing to learn, please teach :-)
PHP (as usual) has some nifty stuff, namely <code> http_build_query() </code> for putting together URL requests. However for some reason (historically) PHP4 compatibility and encoding issues currently WP maintains fork of that function internally and offers <code> build_query() </code> wrapper, as well as nifty higher level function for URL manipulation <code> add_query_arg() </code> and <code> remove_query_arg() </code> .
Need some PHP schoolin'! passing var to url and the old options table
wordpress
I'm having a devil of a time getting my plugin settings to save. I've gone through the code so many times I have to think I've simply missed something. I'm following the Setting API, but any changes I make on the plugin settings page don't save. What did I miss? <code> function __construct() { self::$instance = $this; // Add "Settings" link to plugin page add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ) , array( $this, 'settings_link' ) ); // Creates the CEMB Seminar submenu add_action( 'admin_menu', array( $this, 'add_menu' ) ); // Register and define the settings add_action( 'admin_init', array( $this, 'settings_init' ) ); } // End of __construct() /***** Menus *****/ // Add "Settings" link to plugin page function settings_link( $links ) { $settings_link = sprintf( '&lt;a href="%s"&gt;%s&lt;/a&gt;', admin_url( 'options-general.php?page=cemb-seminar' ), __( 'Settings' ) ); array_unshift( $links, $settings_link ); return $links; } // Creates the CEMB Seminar submenu function add_menu() { add_submenu_page( 'edit.php?post_type=cemb_seminar', __( 'Course Requirements' ), __( 'Course Requirements' ), 'manage_options', 'cemb-seminar', array( $this, 'settings_page' ) ); } /***** Course Requirement Settings *****/ /* Creates new database fields */ function settings_init() { $options = array( 'cemb_seminar_seminars_college' =&gt; '0', 'cemb_seminar_showcases_college' =&gt; '0', 'cemb_seminar_writers_college' &gt; '0', 'cemb_seminar_aet_college' =&gt; '0', 'cemb_seminar_mbu_college' =&gt; '0', 'cemb_seminar_eis_college' =&gt; '0', 'cemb_seminar_sng_college' =&gt; '0', ); update_option( 'cemb_seminar_options', $options ); register_setting( 'cemb_seminar_options', 'cemb_seminar_options' ); add_settings_section( 'cemb_seminar_reqs_college', 'Course Requirements', array( $this, 'reqs_college_fn' ), 'cemb-seminar' ); add_settings_field( 'cemb_seminar_seminars_college_field', 'Seminars', array( $this, 'seminars_college_fn' ), 'cemb-seminar', 'cemb_seminar_reqs_college' ); add_settings_field( 'cemb_seminar_showcases_college_field', 'Showcases', array( $this, 'showcases_college_fn' ), 'cemb-seminar', 'cemb_seminar_reqs_college' ); add_settings_field( 'cemb_seminar_writers_college_field', 'Writer's Nights', array( $this, 'writers_college_fn' ), 'cemb-seminar', 'cemb_seminar_reqs_college' ); add_settings_field( 'cemb_seminar_aet_college_field', 'AET Seminars', array( $this, 'aet_college_fn' ), 'cemb-seminar', 'cemb_seminar_reqs_college' ); add_settings_field( 'cemb_seminar_mbu_college_field', 'MBU Seminars', array( $this, 'mbu_college_fn' ), 'cemb-seminar', 'cemb_seminar_reqs_college' ); add_settings_field( 'cemb_seminar_eis_college_field', 'EIS Seminars', array( $this, 'eis_college_fn' ), 'cemb-seminar', 'cemb_seminar_reqs_college' ); add_settings_field( 'cemb_seminar_sng_college_field', 'SNG Seminars', array( $this, 'sng_college_fn' ), 'cemb-seminar', 'cemb_seminar_reqs_college' ); } // End of settings_init() // Add note about the course requirements settings function reqs_college_fn() { echo '&lt;p&gt;The course requirement options below will apply to all students for all majors.&lt;/p&gt;'; } // Checks for the selected value in the drop menus function course_req_selected( $selected, $option ) { // Get options first $options = get_option( 'cemb_seminar_options' ); // Check if the option matches the input if ( $options['$option'] == $selected ) { echo ' selected="selected"'; } } // End of course_req_selected() // Add college-wide Seminars requirements Field function seminars_college_fn() { // Get options from database $options = get_option( 'cemb_seminar_options' ); $option = $options['cemb_seminar_seminars_college']; // Build the select form ?&gt; &lt;select id="cemb_seminar_seminars_college" class="cemb_seminar_settings_field" name="cemb_seminar_options[cemb_seminar_seminars_college]"&gt; &lt;option value="0" &lt;?php if ( $option == '0' ) { echo 'selected="selected"'; } ?&gt;&gt;0&lt;/option&gt; &lt;option value="1" &lt;?php if ( $option == '1' ) { echo 'selected="selected"'; } ?&gt;&gt;1&lt;/option&gt; &lt;option value="2" &lt;?php if ( $option == '2' ) { echo 'selected="selected"'; } ?&gt;&gt;2&lt;/option&gt; &lt;option value="3" &lt;?php if ( $option == '3' ) { echo 'selected="selected"'; } ?&gt;&gt;3&lt;/option&gt; &lt;option value="4" &lt;?php if ( $option == '4' ) { echo 'selected="selected"'; } ?&gt;&gt;4&lt;/option&gt; &lt;option value="5" &lt;?php if ( $option == '5' ) { echo 'selected="selected"'; } ?&gt;&gt;5&lt;/option&gt; &lt;/select&gt; &lt;?php } // End of seminars_college_fn() // Add college-wide Showcases requirements Field function showcases_college_fn() { // Get options from database $options = get_option( 'cemb_seminar_options' ); $option = $options['cemb_seminar_showcases_college']; // Build the select form ?&gt; &lt;select id="cemb_seminar_showcases_college" class="cemb_seminar_settings_field" name="cemb_seminar_options[cemb_seminar_showcases_college]"&gt; &lt;option value="0" &lt;?php if ( $option == '0' ) { echo 'selected="selected"'; } ?&gt;&gt;0&lt;/option&gt; &lt;option value="1" &lt;?php if ( $option == '1' ) { echo 'selected="selected"'; } ?&gt;&gt;1&lt;/option&gt; &lt;option value="2" &lt;?php if ( $option == '2' ) { echo 'selected="selected"'; } ?&gt;&gt;2&lt;/option&gt; &lt;option value="3" &lt;?php if ( $option == '3' ) { echo 'selected="selected"'; } ?&gt;&gt;3&lt;/option&gt; &lt;option value="4" &lt;?php if ( $option == '4' ) { echo 'selected="selected"'; } ?&gt;&gt;4&lt;/option&gt; &lt;option value="5" &lt;?php if ( $option == '5' ) { echo 'selected="selected"'; } ?&gt;&gt;5&lt;/option&gt; &lt;/select&gt; &lt;?php } // End of showcases_college_fn() // Add college-wide Writer's Night requirements field function writers_college_fn() { // Get options from database $options = get_option( 'cemb_seminar_options' ); $option = $options['cemb_seminar_writers_college']; // Build the select form */?&gt; &lt;select id="cemb_seminar_writers_college" class="cemb_seminar_settings_field" name="cemb_seminar_options[cemb_seminar_writers_college]"&gt; &lt;option value="0" &lt;?php if ( $option == '0' ) { echo 'selected="selected"'; } ?&gt;&gt;0&lt;/option&gt; &lt;option value="1" &lt;?php if ( $option == '1' ) { echo 'selected="selected"'; } ?&gt;&gt;1&lt;/option&gt; &lt;option value="2" &lt;?php if ( $option == '2' ) { echo 'selected="selected"'; } ?&gt;&gt;2&lt;/option&gt; &lt;option value="3" &lt;?php if ( $option == '3' ) { echo 'selected="selected"'; } ?&gt;&gt;3&lt;/option&gt; &lt;option value="4" &lt;?php if ( $option == '4' ) { echo 'selected="selected"'; } ?&gt;&gt;4&lt;/option&gt; &lt;option value="5" &lt;?php if ( $option == '5' ) { echo 'selected="selected"'; } ?&gt;&gt;5&lt;/option&gt; &lt;/select&gt; &lt;?php } // End of writers_college_fn() // Add college-wide AET Seminars requirements field function aet_college_fn() { // Get options from database $options = get_option( 'cemb_seminar_options' ); $option = $options['cemb_seminar_aet_college']; // Build the select form ?&gt; &lt;select id="cemb_seminar_aet_college" class="cemb_seminar_settings_field" name="cemb_seminar_options[cemb_seminar_aet_college]"&gt; &lt;option value="0" &lt;?php if ( $option == '0' ) { echo 'selected="selected"'; } ?&gt;&gt;0&lt;/option&gt; &lt;option value="1" &lt;?php if ( $option == '1' ) { echo 'selected="selected"'; } ?&gt;&gt;1&lt;/option&gt; &lt;option value="2" &lt;?php if ( $option == '2' ) { echo 'selected="selected"'; } ?&gt;&gt;2&lt;/option&gt; &lt;option value="3" &lt;?php if ( $option == '3' ) { echo 'selected="selected"'; } ?&gt;&gt;3&lt;/option&gt; &lt;option value="4" &lt;?php if ( $option == '4' ) { echo 'selected="selected"'; } ?&gt;&gt;4&lt;/option&gt; &lt;option value="5" &lt;?php if ( $option == '5' ) { echo 'selected="selected"'; } ?&gt;&gt;5&lt;/option&gt; &lt;/select&gt; &lt;?php } // End of aet_college_fn() // Add college-wide MBU Seminars requirements field function mbu_college_fn() { // Get options from database $options = get_option( 'cemb_seminar_options' ); $option = $options['cemb_seminar_mbu_college']; // Build the select form ?&gt; &lt;select id="cemb_seminar_mbu_college" class="cemb_seminar_settings_field" name="cemb_seminar_options[cemb_seminar_mbu_college]"&gt; &lt;option value="0" &lt;?php if ( $option == '0' ) { echo 'selected="selected"'; } ?&gt;&gt;0&lt;/option&gt; &lt;option value="1" &lt;?php if ( $option == '1' ) { echo 'selected="selected"'; } ?&gt;&gt;1&lt;/option&gt; &lt;option value="2" &lt;?php if ( $option == '2' ) { echo 'selected="selected"'; } ?&gt;&gt;2&lt;/option&gt; &lt;option value="3" &lt;?php if ( $option == '3' ) { echo 'selected="selected"'; } ?&gt;&gt;3&lt;/option&gt; &lt;option value="4" &lt;?php if ( $option == '4' ) { echo 'selected="selected"'; } ?&gt;&gt;4&lt;/option&gt; &lt;option value="5" &lt;?php if ( $option == '5' ) { echo 'selected="selected"'; } ?&gt;&gt;5&lt;/option&gt; &lt;/select&gt; &lt;?php } // End of mbu_college_fn() // Add college-wide EIS Seminars requirements field function eis_college_fn() { // Get options from database $options = get_option( 'cemb_seminar_options' ); $option = $options['cemb_seminar_eis_college']; // Build the select form ?&gt; &lt;select id="cemb_seminar_eis_college" class="cemb_seminar_settings_field" name="cemb_seminar_options[cemb_seminar_eis_college]"&gt; &lt;option value="0" &lt;?php if ( $option == '0' ) { echo 'selected="selected"'; } ?&gt;&gt;0&lt;/option&gt; &lt;option value="1" &lt;?php if ( $option == '1' ) { echo 'selected="selected"'; } ?&gt;&gt;1&lt;/option&gt; &lt;option value="2" &lt;?php if ( $option == '2' ) { echo 'selected="selected"'; } ?&gt;&gt;2&lt;/option&gt; &lt;option value="3" &lt;?php if ( $option == '3' ) { echo 'selected="selected"'; } ?&gt;&gt;3&lt;/option&gt; &lt;option value="4" &lt;?php if ( $option == '4' ) { echo 'selected="selected"'; } ?&gt;&gt;4&lt;/option&gt; &lt;option value="5" &lt;?php if ( $option == '5' ) { echo 'selected="selected"'; } ?&gt;&gt;5&lt;/option&gt; &lt;/select&gt; &lt;?php } // End of eis_college_fn() // Add college-wide SNG Seminars requirements field function sng_college_fn() { // Get options from database $options = get_option( 'cemb_seminar_options' ); $option = $options['cemb_seminar_sng_college']; // Build the select form ?&gt; &lt;select id="cemb_seminar_sng_college" class="cemb_seminar_settings_field" name="cemb_seminar_options[cemb_seminar_sng_college]"&gt; &lt;option value="0" &lt;?php if ( $option == '0' ) { echo 'selected="selected"'; } ?&gt;&gt;0&lt;/option&gt; &lt;option value="1" &lt;?php if ( $option == '1' ) { echo 'selected="selected"'; } ?&gt;&gt;1&lt;/option&gt; &lt;option value="2" &lt;?php if ( $option == '2' ) { echo 'selected="selected"'; } ?&gt;&gt;2&lt;/option&gt; &lt;option value="3" &lt;?php if ( $option == '3' ) { echo 'selected="selected"'; } ?&gt;&gt;3&lt;/option&gt; &lt;option value="4" &lt;?php if ( $option == '4' ) { echo 'selected="selected"'; } ?&gt;&gt;4&lt;/option&gt; &lt;option value="5" &lt;?php if ( $option == '5' ) { echo 'selected="selected"'; } ?&gt;&gt;5&lt;/option&gt; &lt;/select&gt; &lt;?php } // End of sng_college_fn() // Creates the course requirements page function settings_page() { ?&gt; &lt;div class="wrap"&gt; &lt;div class="icon32" style="background-image:url(&lt;?php echo WP_PLUGIN_URL . '/cemb-seminar/images/cemb-logo32x32.png'; ?&gt;); background-repeat:no-repeat;"&gt;&lt;br /&gt;&lt;/div&gt; &lt;h2&gt;Course Requirements&lt;/h2&gt; &lt;form method="post" action="options.php"&gt; &lt;?php settings_fields( 'cemb_seminar_options' ); ?&gt; &lt;?php do_settings_sections( 'cemb-seminar' ); ?&gt; &lt;br /&gt; &lt;input class="button-primary" type="submit" name="Submit" value=" &lt;?php _e( 'Save Settings' ); ?&gt; " /&gt; &lt;/form&gt; &lt;/div&gt; &lt;?php } // End of settings_page() </code>
the problem is you keep resting the values here: <code> $options = array( 'cemb_seminar_seminars_college' =&gt; '0', 'cemb_seminar_showcases_college' =&gt; '0', 'cemb_seminar_writers_college' &gt; '0', 'cemb_seminar_aet_college' =&gt; '0', 'cemb_seminar_mbu_college' =&gt; '0', 'cemb_seminar_eis_college' =&gt; '0', 'cemb_seminar_sng_college' =&gt; '0', ); update_option( 'cemb_seminar_options', $options ); </code> change it to <code> $options = get_option('cemb_seminar_options'); if ($options === false){ $options = array( 'cemb_seminar_seminars_college' =&gt; '0', 'cemb_seminar_showcases_college' =&gt; '0', 'cemb_seminar_writers_college' &gt; '0', 'cemb_seminar_aet_college' =&gt; '0', 'cemb_seminar_mbu_college' =&gt; '0', 'cemb_seminar_eis_college' =&gt; '0', 'cemb_seminar_sng_college' =&gt; '0', ); update_option( 'cemb_seminar_options', $options ); } </code> so it will only run if 'cemb_seminar_options' is not set in the database
Plugin settings not saving
wordpress
THIS WORKS: <code> &lt;script type="text/javascript"&gt; function fadeReview() { jQuery(".reviewPanel .reviewPanel2:hidden:first").fadeIn(500).delay(3000).fadeOut(500, function() { jQuery(this).appendTo(jQuery(this).parent()); fadeReview(); }); } fadeReview(); &lt;/script&gt; </code> BUT, THIS DOES NOT WORK: <code> &lt;script type="text/javascript"&gt; function fadeReview() { jQuery(".reviewPanel .reviewPanel2:hidden:first").fadeIn(500).delay(3000).fadeOut(500, function() { jQuery(this).appendTo(jQuery(this).parent()); fadeReview(); }); } fadeReview(); function fadeReviewName() { jQuery(".reviewName .reviewName2:hidden:first").fadeIn(500).delay(3000).fadeOut(500, function() { jQuery(this).appendTo(jQuery(this).parent()); fadeReviewName(); }); } fadeReviewName(); &lt;/script&gt; </code> Does it have to do with running two functions? It works ok in this fiddle .
"Won't work" doesn't say much. Use Firebug with Firefox, or in Chrome or Safari or IE8, use the developer tools to check for JS errors on your site. WP3.2 now includes jQuery 1.6 and your jsfiddle example uses 1.4, so there's a possible conflict.
Why won't this jQuery work in WordPress?
wordpress
I'm wanting to find a way to have all pages listed without paging and to do so in a method that isn't going to be over-written when I update WordPress, i.e. in the form of a hook. The page is in the administration: With all the pages being listed I can then use javascript to do collapsing to show/hide subpages, I'm not phased about load times of the page or anything, just cant have this method usable if paging is also used, all pages need to be listed on 1 page. As I'm wanting to do this in the admin area, I'm not even sure if this is do-able without breaking when updating.
If that listing has too many pages, maybe you'll run into troubles. You probably already know that this can be set in the Screen Options of the page <code> http://example.com/wp-admin/edit.php?post_type=page </code> . If you try to put a really high value there, this warning pops up and the system doesn't accept it: But the following permanently sets this value to 2000. I don't have more than 999 pages to test if that limit that WordPress is warning about will be overriden or not, but the 2k shows up after refreshing the page, and keeps there if you try to lower it. <code> add_filter( 'get_user_metadata', 'pages_per_page_wpse_23503', 10, 4 ); function pages_per_page_wpse_23503( $check, $object_id, $meta_key, $single ) { if( 'edit_page_per_page' == $meta_key ) return 2000; return $check; } </code>
How to list ALL Pages in the dashboard?
wordpress
I've created a custom post type that displays the individual entries collectively on a page. However, I've found that Google is not only indexing the page, but the individual posts as well. I only want the page to be indexed and followed, and not the posts. Is there any way to accomplish this?
Answering my own question here: The WordPress SEO plugin provides a menu for all posts and pages, including custom post types, that includes noindex and nofollow options.
How to noindex nofollow custom post type?
wordpress
How can i get the row counts in query post like mysql count(*). <code> $obj_name = new WP_Query($args); while ($obj_name-&gt;have_posts()) : $obj_name-&gt;the_post(); // here i want to predict looping counts endwhile; </code> How can i do this.
<code> $num = $obj_name-&gt;post_count; </code> Reference: wp_query
How can i get count from query post
wordpress
Is there a way to put a placeholder text in the category form label? Right now the label is empty and has a dropdown menu filled with categories. I want to make a dummy placeholder text which will be something to : CHOOSE THE CATEGORY! <code> &lt;option value="&lt;option value="&lt;?php wp_dropdown_categories('exclude=34, selected=0'); ?&gt; &lt;/option&gt; </code> Thanks in advance!
You can add it as an argument: <code> &lt;?php wp_dropdown_categories( 'show_option_none=CHOOSE THE CATEGORY!' ); ?&gt; </code> Reference: wp_dropdown_categories
placeholder text in category form label
wordpress
I've searched around and can't find anything on this, so thought I'd see if y'all could help. I am successfully scheduling posts and having them publish - no "missed schedule" problems - but when a scheduled post is published, WordPress does not ping Feedburner, and my feed is not updated. I can manually go into Feedburner and update the feed, but that's a pain (well, it's easy, but I forget to do it! that's the whole point of scheduling posts! :-) ). Does anyone know of a setting in either Feedburner or WordPress that I need to change to make this work? My 'privacy' settings are set to visible to search engines. Here's the site if that helps in any way: http://thegladdestthing.com/ Thanks for your help!
That's weird, but you can try this. Go to WordPress Dashboard > Settings > Writing administration screen, and to the existing URIs listed under Update Services , add this: <code> http://ping.feedburner.com </code> More Info: WordPress Codex — XML-RPC Ping Services
Feedburner doesn't update when "scheduled post" publishes
wordpress
I am using the date and time in the post dialogue to log the date and time of future events, and would like to change the text to reflect that. Is there an action hook I can tap into to achieve that? Also, it would be perfect if I could pull those controls out of the 'publish dialogue', and add it to my own meta box.
Use a <code> gettext </code> filter and match against the text. <code> add_filter( 'gettext', 'filter_published_on', 10000, 2 ); function filter_published_on( $trans, $text ) { if( 'Published on: &lt;b&gt;%1$s&lt;/b&gt;' == $text ) { global $post; switch( $post-&gt;post_type ) { case 'your-posttype': return 'Whatever on: &lt;strong&gt;%1$s&lt;/strong&gt;'; break; default: return $trans; break; } } return $trans; } </code> The alternative would be to copy the publish metabox code, and change the callback function for that metabox to your copied(and modified) version of the function, so you can do what you want with the callback code.
Change the 'published on' text?
wordpress
I want to know how to import my YouTube channel into my WordPress website? Example: I have a YouTube channel with 7 videos . I want to bring all the videos into my WordPress website's sidebar. If I click the listed videos from my channel's list, it'll need to play. For more reference this is the sample output that I need:
I'd use the plugin Tubepress . It has a lot of options to suit your needs, such as a sidebar widget that can play your videos in a lightbox for example. I used it a few times, it's quite powerfull and customizable.
How to import my YouTube channel into WordPress?
wordpress
I need a bit of quick help. How do I exclude category ID number 50 for example in drop down list form in Wordpress? I have this code and I need to just insert the excluded category id. <code> &lt;?php $cate_id = retrieve_cat_data(true); $cate_name = retrieve_cat_data(false); for ($i = 0; $i &lt; count($cate_name); $i++ ) { ?&gt; &lt;option value="&lt;?php echo $cate_id[$i]; ?&gt;"&gt;&lt;?php echo $cate_name[$i]; ?&gt; &lt;/option&gt;&lt;?php } ?&gt; </code> Thanks in advance to everyone :)
try: <code> &lt;?php $cat_to_EXCLUDE = 50; $cate_id = retrieve_cat_data(true); $cate_name = retrieve_cat_data(false); for ($i = 0; $i &lt; count($cate_name); $i++ ) { ?&gt; if ($cate_id[$i] != $cat_to_EXCLUDE){ &lt;option value="&lt;?php echo $cate_id[$i]; ?&gt;"&gt;&lt;?php echo $cate_name[$i]; ?&gt; &lt;/option&gt;&lt;?php }} ?&gt; </code> update: if you search your theme's functions.php file i bet you will find a function named <code> retrieve_cat_data </code> anyway you can simple create a dropdown using <code> wp_dropdown_categories </code> and you can exclude a category with its <code> exclude </code> argument : <code> &lt;?php wp_dropdown_categories('exclude=50'); ?&gt; </code>
Exclude category from drop down list form
wordpress
I was trying to create a shortcode for a multiple tabs panel. The user can set the number of tabs, the titles and the content for each. It would be something like : <code> [tabs number='4'] [tab title='First_tab_title']first tab content[/first_tab] ... ... [/tabs] </code> Now, i am wondering. Although it can be done like this, i don't like that i have to create separate shortcodes, like tabs and tab. Is there another better way to pass all this information to a single [tabs] shortcode ?
You might be able to hack a conditional for 1 shortcode but it seems wonky. Typically you use 2 parameters just like you were using raw html. There is a smart way around this using custom fields ( which I just happened to do recently). It does not use any shortcodes at all, the logic is simple it has a custom fields called "tab 1, tab 2, tab 3 , etc" , if no data is entered no tab panels shows up, if there is data in the tab field the panels shows up and dynamically adds tabs per field that is filled out. I just use jquery tools for the tab panel and default WordPress conditionals for the meta fields, <code> get_post_custom_values </code> specifically.
Multiple Content Shortcodes
wordpress
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.
I would create a separate Reviews CPT. In the Reviews write screen, I would add a metabox with a select input contain each Game CPT as an option. Using the metabox, you can associate the Game ID as postmeta with the Review. Finally, in your template page that displays the review, you can easily retrieve the Game ID, which will allow you to display all of the relevant Game information on the Review page. For an even easier solution than the metabox, you can simply add a custom field like "game_id" and manually add the game id. It's simpler than creating a metabox, but it's not as pretty :)
attach CPT data to a taxonomy
wordpress
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
you can do this very easily with jQuery simply wrap your comment form in a div and hide, add a button or a link and on his click event show the comment form so smoothing like this: <code> &lt;a href="#" ID="Leave_a_comment"&gt;Leave a Comment&lt;/a&gt; &lt;div id="comment_form_wrapper" style="display: none;"&gt; &lt;?php comments_template( '', true ); ?&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $('#Leave_a_comment').click(function() { $('#comment_form_wrapper').show(); }); }); &lt;/script&gt; </code>
just show the field comment by clicking button
wordpress
Hi I have a VPS and one particular site is apparently causing the server to crash and I am getting alerts about lots of IO going on. How can I troubleshoot to see what is causing the extra load?
1) Try WordPress › WPDB Profiling « WordPress Plugins to see what is running all the queries. 2) Clearing post and page revisions will greatly reduce the size of a WP database - up to 90% in some cases - with a huge return in speed and lower server load. Run as SQL query in phpmyadmin to delete revisions; change table prefix as necessary: <code> DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision' </code> Then optimize all tables. And then add <code> define ('WP_POST_REVISIONS', FALSE); </code> near the top of wp-config.php to disable future revisions. 3) Check your permalink structure: Category in Permalinks Considered Harmful » Otto on WordPress
WordPress site causing lots of server IO
wordpress
I would like to know the procedure to put my categories in the left menu on the widget in the same style of yahoo I like this style: ScreenShot-> http://broalliance.com.br/kafra/image-1ED5_4E270F69.jpg what is the best option? html and use a field to do manually? how would the css?
Check your site source to see what classes do your category links have on them, then style these classes with CSS, like: <code> .category-5 a{ background:transparent url(images/...) no-repeat left top; padding-left: 25px; } </code>
Menu in widget with yahoo style
wordpress
I'm using switch_to_blog() and restore_current_blog() to perform some functions across a multi site install. One of the things I'm trying to do is select a very specific post using get_row(). My function looks like this: <code> $prefix = $wpdb-&gt;prefix; $tbl = $prefix; $product = $wpdb-&gt;get_row("SELECT * FROM {$tbl}_posts WHERE ID = 4253"); print_r($product); exit; </code> The post with ID 4253 definitely exists, and I know for sure that the prefix is correct, however print_r returns absolutely nothing, nor does <code> echo $product-&gt;post_title; </code> Any ideas?
Edit: You have an extra underscore in your table name, it becomes <code> wp__posts </code> in your case. Better use like how I have shown below :) First, use table names like the following and try var_dump to see if it returns NULL. In case the Post ID doesn't exist, <code> $product </code> will be <code> NULL </code> , which only var_dump can show. <code> $product = $wpdb-&gt;get_row("SELECT * FROM $wpdb-&gt;posts WHERE ID = 4253"); var_dump( $product ); </code>
Trouble with SQL SELECT inside switch_to_blog()
wordpress
I'm trying to redeclare a function in a wordpress child theme that is already in use by the parent theme. However, I get a "Fatal error: Cannot redeclare" message when trying to do so. Also, I've tried using the following with no luck: <code> if (!function_exists('jr_load_scripts')) { // do fancy things here... } </code> Here's the link if you want to have a quick look... EDIT: Here's the full code: <code> if (!function_exists('jr_load_scripts')) { function jr_load_scripts() { global $app_abbr; $http = (is_ssl()) ? 'https' : 'http'; // load google cdn hosted scripts if enabled if (get_option($app_abbr.'_google_jquery') == 'yes') : wp_deregister_script('jquery'); wp_register_script('jquery', (''.$http.'://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'), false, '1.4.2'); wp_register_script('jquery-ui-custom', ''.$http.'://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js', false, '1.8'); else : wp_register_script('jquery-ui-custom', get_bloginfo('template_directory').'/includes/js/jquery-ui-1.8.custom.min.js', false, '1.8'); endif; wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-custom'); wp_enqueue_script('jquery-tag', get_bloginfo('template_directory').'/includes/js/jquery.tag.js', array('jquery'), ''); wp_enqueue_script('smoothscroll', get_bloginfo('template_directory').'/includes/js/smoothscroll.js', array('jquery'), ''); wp_enqueue_script('lazyload', get_bloginfo('template_directory').'/includes/js/jquery.lazyload.mini.js', array('jquery'), '1.5.0'); wp_enqueue_script('elastic', get_bloginfo('template_directory').'/includes/js/jquery.elastic.js', array('jquery'), '1.0'); wp_enqueue_script('fancybox', get_bloginfo('template_directory').'/includes/js/jquery.fancybox-1.3.4.pack.js', array('jquery'), '1.3.4'); wp_enqueue_script('qtip', get_bloginfo('template_directory').'/includes/js/jquery.qtip.min.js', array('jquery'), '1.0.0-rc3'); wp_enqueue_script('general', get_bloginfo('template_directory').'/includes/js/theme-scripts.js', array('jquery'), '3.0'); $jr_enable_indeed_feeds = get_option('jr_enable_indeed_feeds'); if ($jr_enable_indeed_feeds=='yes') : wp_enqueue_script('indeed-api', ''.$http.'://www.indeed.com/ads/apiresults.js'); endif; } </code>
It is somewhat counter-intuitive but WordPress loads child's theme code before parent's theme. So wrapping anything in <code> function_exists() </code> in child theme does nothing, it's parent theme that needs to have that. Better option is to unhook parent's theme function (unless it's run right at load, which it should not do) and hook your own.
Wordpress Child Themes
wordpress
Can I get the term by it's id without knowing to whish taxonomy it belongs? I have a meta field that stores term ids, but doesn't store the taxonomy. However, all the <code> get_term </code> function have taxonomy parameter marked as required. Maybe I can get the taxonomy of the term by it's (term's) id somehow?
Yes, but you need you make your own SQL query. A modified version of WP's get_term(): <code> function &amp;get_term_by_id_only($term, $output = OBJECT, $filter = 'raw') { global $wpdb; $null = null; if ( empty($term) ) { $error = new WP_Error('invalid_term', __('Empty Term')); return $error; } if ( is_object($term) &amp;&amp; empty($term-&gt;filter) ) { wp_cache_add($term-&gt;term_id, $term, 'my_custom_queries'); $_term = $term; } else { if ( is_object($term) ) $term = $term-&gt;term_id; $term = (int) $term; if ( ! $_term = wp_cache_get($term, 'my_custom_queries') ) { $_term = $wpdb-&gt;get_row( $wpdb-&gt;prepare( "SELECT t.* FROM $wpdb-&gt;terms AS t WHERE t.term_id = %s LIMIT 1", $term) ); if ( ! $_term ) return $null; wp_cache_add($term, $_term, 'my_custom_queries'); } } if ( $output == OBJECT ) { return $_term; } elseif ( $output == ARRAY_A ) { $__term = get_object_vars($_term); return $__term; } elseif ( $output == ARRAY_N ) { $__term = array_values(get_object_vars($_term)); return $__term; } else { return $_term; } } </code> Probably not a good idea. Try to handle the tax too in your meta fields...
get term by id without taxonomy
wordpress
I am presently learning PHP and Linux simultaneously. And I want to blog my notes not only for my future reference, but also because it could help others. I just noticed an issue with Wordpress - - it automatically adds <code> &lt;pre&gt;&lt;/pre&gt; </code> tags in the background (HTML-side I mean, in the visual editor I see the code's background highlighted) as soon as I paste some code, be it HTML, PHP etc. I have searched a lot, and could find nothing about this. Looks like nobody thinks this as an issue, or it's something too easy to resolve. Either way, I am on the other side of things. So, please help me out. I want Wordpress to stop highlighting the code like that. I Just want it to keep whatever I paste as it is.
The only way to keep it the way you paste it is by switching to the HTML tab - this will show you the raw code as you formatted it. Wrapping code in tags is also a good idea because it tells the browser that the code is literally 'precomposed', and it therefore won't render it. In terms of WP actually altering your code it is likely it will change characters such as '&lt;' for their HTML entity equivalent, meaning browsers will render it as text rather than code. Why exactly do you want to keep it without the tags? It shouldn't alter that much.
Wordpress automatically adds tags when pasting code, how to stop it?
wordpress
I downloaded a widget for my blog, which works just like the calendar widget but displays a custom post type instead. It correctly marks my CPT-posts and creates links, such as http://localhost:8888/wp/?m=201105 for a certain month and http://localhost:8888/wp/?m=20110510 for a certain day. Now I want to create the required archive template, but it keeps falling back to index.php instead of date.php or archive.php - and the loop in index.php returns empty. I am flabbergasted, has anyone seen this before? My hypothesis: it returns empty because I does not include custom post types. It does not explain why date.php / archive.php isn't being used (and is_date() appears to return false), but it would explain why the loop is empty because I have no other articles yet. If this is the case, how can I include CPTs?
The problem is that the plugin only handles the calendar part, and not the archive query. What you need to do: Change the main query on archive pages if the post_type argument is present, eg: http://localhost:8888/wp/?m=201105&amp;post_type=candy : <code> add_filter('pre_get_posts', 'atom_include_cpt_in_archives'); function atom_include_cpt_in_archives($query){ // validate if(is_archive() &amp;&amp; isset($_GET['post_type']) &amp;&amp; post_type_exists($_GET['post_type'])) $query-&gt;set('post_type', $_GET['post_type']); return $query; } </code> Next, you'll have to make your own get_calendar() version, because the native function is not hookable: add a <code> $post_type </code> argument to the function and change all the db queries: <code> WHERE post_type = 'post' </code> to <code> WHERE post_type = $post_type </code> append the current post type that's being requested to get_month_link() / get_day_link(): <code> add_query_arg('post_type', $post_type, get_month_link($previous-&gt;year, $previous-&gt;month)) </code> ... maybe override the $post_type function argument with the query argument if it's set: <code> if(isset($_GET['post_type']) &amp;&amp; post_type_exists($_GET['post_type'])) $post_type = $_GET['post_type']; </code> I did a calendar widget like this which among other things, supports CPT. I could post the code, but since it's part of a theme framework you'd have to figure it out yourself how to separate it :)
A problem with date archives
wordpress
In this wordpress blog , one can vote the comments. I am wondering how can I set up this function in my wordpress blog?
If your blog is self-hosted, the easiest way to add a comment voting system is to install a plugin (e.g. Comment Rating ). If your blog is on WordPress.com, then you'd need to go through the options the options on WordPress.com to see where you could enable that functionality.
How can I set a vote on the comments?
wordpress
I made this website for my client using WordPress. It's all great but now he's asked me that when someone loads the website, before all the WP goodness, there's a page showing just the logo, then you click the logo and go to the main page. I'm thinking I could either do this by changing WP's index to some other name and have the actual index file be the logo thing etc; or have a pop-up* on the actual WP index that darkens the rest of the page, then you click the logo and it's gone, allowing you to navigate the page normally. It would have to appear only the first time the user loads the page and not when you 'come back' to it from another page. *Like when you click a screenshot here panic.com/coda for example. Can anyone help me with either option or show me a new one? Thanks!
Just tell him that doing so is bad for SEO and no one has done this since 1998.
Need 'logo page' before wordpress page!
wordpress
I'm trying to restore a Wordpress blog from a backup. Unfortunately, all I have is an SQL dump of the database as generated by phpMyAdmin. The dump was created when the blog was running Wordpress 2.9/2.9.1/2.9.2. The new blog is a brand-new installation of Wordpress 3.2.1. How can I import the contents of the SQL dump into the new Wordpress installation? I tried importing the dump into the database using phpMyAdmin before installing Wordpress, but then install.php tells me that Wordpress seems to be already installed and that I should delete the database tables.
If it is an older version of WP, you need to find out what version of WP generated the database, as WP upgrades the DB most times the files are upgraded and you should incrementally upgrade to also upgrade the database. Look in the wp_options table for option 711 and see what the version is; option name will be site_transient_update_core and the value will be the download link, i.e. http://wordpress.org/wordpress-3.2.1.zip which means the version is 3.2.1 Find the version and leave a comment below. Depending on the age of the version, you need to do manual, incremental upgrades to get to at least 3.0 where you can use auto-update. If you import/move a DB, no need to run install.php. Just upload all WP files and folders. See Moving WordPress « WordPress Codex
Import old SQL dump into new Wordpress version
wordpress
I am trying to remove the admin bar from a theme front end of a theme. I found the following code block: <code> add_filter( 'show_admin_bar', '__return_false' ); remove_action( 'personal_options', '_admin_bar_preferences' ); </code> Which works fine. However I wanted to add a choice for the user, so that I can add a permanent code block to my boilerplate theme, and allow users to toggle the admin bar off and on. I have successfully added the toggle in the admin area, and called back the value successfully, however, when I test for the value in order to control the callback of the admin bar, the admin bar goes, but the CSS applied to the HTML element ( <code> margin-top: 28px !important; </code> ) remains, leaving a 28px gap in the top of my theme. Here is the code block I am using to call the value back, and respond accordingly: <code> function block_admin(){ $show = get_option('admin_bar_'); $show = $show['admin_bar_toggle']; if (!$show || $show != 'on'){ add_filter( 'show_admin_bar', '__return_false' ); remove_action( 'personal_options', '_admin_bar_preferences' ); } } add_action('init', 'block_admin'); </code> Suggestion By requirement, my custom option (using <code> register_setting </code> ) is not initialised until the <code> admin_menu </code> hook is launched, whilst the <code> block_admin </code> is launched on <code> init </code> . However, I don't think this is the issue as I don't think <code> get_option </code> is dependent on the setting being registered, but rather the option existing (or not) in the database.
Just launching the function at an earlier point solved the issue <code> function block_admin(){ $show = get_option('admin_bar_'); $show = $show['admin_bar_toggle']; fb::log($show,'shoe'); if (!$show || $show != 'on'){ add_filter( 'show_admin_bar', '__return_false' ); remove_action( 'personal_options', '_admin_bar_preferences' ); } } add_action('after_setup_theme','block_admin'); </code>
Problems with removing admin bar
wordpress
I'm trying to work with an API that expects an XML string in the body of the post. Additionally, the docs for the API specify: Please post with mime-type text/xml with the XML in the body of the post I want to use the WordPress HTTP API to make this work, but I'm running into some problems. So far I have code like the following that seems to be failing. <code> $url = 'https://www.testurl.com'; $xml = &lt;&lt;&lt;TESTED XML HERE&gt;&gt;&gt;; $response = wp_remote_post( $url, array( 'method' =&gt; 'POST', 'timeout' =&gt; 45, 'redirection' =&gt; 5, 'httpversion' =&gt; '1.0', 'headers' =&gt; array( 'mime-type' =&gt; 'text/xml' ), 'body' =&gt; array('xml' =&gt; $xml), 'sslverify' =&gt; false ) ); </code> My question is, am I properly setting the mime-type and am I sending the XML in the right place? It's surprisingly tough to find examples of the WordPress HTTP API utilizing XML requests.
I figured it out. The WordPress HTTP API was doing it's job; my problem was with the API I was working with. I just modified my code like: <code> $url = 'https://www.testurl.com'; $xml = &lt;&lt;&lt;TESTED XML HERE&gt;&gt;&gt;; $response = wp_remote_post( $url, array( 'method' =&gt; 'POST', 'timeout' =&gt; 45, 'redirection' =&gt; 5, 'httpversion' =&gt; '1.0', 'headers' =&gt; array( 'Content-Type' =&gt; 'text/xml' ), 'body' =&gt; array('postdata' =&gt; $xml, 'postfield' =&gt; 'value'), 'sslverify' =&gt; false ) ); </code> Again...this was just a misunderstand of the API I was working with, not the HTTP API provided my WordPress. Edit: POST data should be supplied as an array, according to http://codex.wordpress.org/Function_API/wp_remote_post The array will be transformed into a string like this: key1=val1&amp;key2=val2&amp;...
Posting an XML request using HTTP API
wordpress
I would like to just get the HTML that comments_popup_link generates, and echo it later on. I don't see the comments_popup_link has an <code> $echo </code> parameter, and I don't see a get_comments_popup_link function, like there is get_the_ID, that returns HTML istead of displaying it. I'm using WordPress 3.1.2 What can I do?
I found this ticket that addresses my problem exactly: http://core.trac.wordpress.org/ticket/17763
comments_popup_link without echo?
wordpress
Hi I set up wordpress on a VPS and I'm running into two problems: Either WordPress asks for ftp details in order to update plugins or delete them or Through FTP I cannot delete files as I get a permission denied error. Problem 1 is solved by running: sudo chown -R www-data public_html Problem 2 is solved by running: sudo chown -R myusername public_html Solving one problem creates the other apparently. I want to be able to login with my user to ftp and modify anything, while I also want wordpress to be able to update plugins and such things. Am I doing something wrong?
you can run something like <code> sudo chown -R myusername:www-data public_html </code> it will solve both the problems together
WordPress folder ownership issues
wordpress
I found a patch I want here: http://core.trac.wordpress.org/ticket/17763 I can see the diff , but what do I do now? How can I get that code into my Wordpress? Do I have to copy it manually? Is there anywhere to download it from?
You can download the diff file from the bottom of the diff page. The program to apply a diff is called "patch". It's widely available for various platforms. Example usages: http://en.wikipedia.org/wiki/Patch_(Unix)#Usage_examples
How to apply a patch?
wordpress
I am seeing that in the last 2 months blocked spam comments in Akismet have jumped from around 8k to more than 100k in each of the last two months. Is there any way to stop them being posted in the first place?
You can prevent some hits by blocking bots before akismet catches them, these plugins can be very effective. Plugins : Bad Behavior plugin: http://wordpress.org/extend/plugins/bad-behavior/ Honeypot Traps: http://wordpress.org/extend/plugins/project-honey-pot-spam-trap/ WP-Hashcash http://wordpress.org/extend/plugins/wp-hashcash/ Zig Trap http://wordpress.org/extend/plugins/zigtrap/ Stop bots with no user agents from posting and directory browsing (this goes in your .htaccess) <code> RewriteEngine On RewriteCond %{REQUEST_METHOD} POST RewriteCond %{HTTP_USER_AGENT} ^$ RewriteRule .* - [F] Options All -Indexes Options +FollowSymLinks </code> If it's still a problem consider contacting your host and using a firewall to block persistant bots or IP ranges ( for instance here is a list of bad bots, http://www.wpsecure.net/bad-bot-list/ ). This is not super effective as is, but an example of what your logs can tell you ( most bad bots use common browser user-agents). Check out services like Cloudflare.
Getting thousands of spam comments
wordpress
I have the following: <code> $query = 'SELECT * FROM wp_pod_tbl_add_questions WHERE id LIKE '. $id; $row = $wpdb -&gt; get_results($query); </code> How do I get the columns named 'id' and 'name' from $row?
<code> foreach( $wpdb-&gt;get_results("SELECT * FROM your_table_name WHERE id LIKE' . $id . ';") as $key =&gt; $row) { // each column in your row will be accessible like this $my_column = $row-&gt;column_name;} </code> More info here
How to parse row results from $wpdb -> get_results
wordpress
I have a page that is password protected, and I wish to removed some parts of the theme, and add others. Can I do that? Is there a check I can do in the theme files to see if a user has entered the password or not?
Just use the <code> post_password_required() </code> conditional: <code> &lt;?php if ( post_password_required() ) { // Post is password-protected; do something } else { // Post is NOT password-protected; do something else } ?&gt; </code>
Using password protection to load different page elements?
wordpress
Can i make it possible for an excerpt to be displayed in the index page but that part of the excerpt will not be displayed in the single post anymore?
Certainly: use the "Excerpt" textarea on the Post Edit screen. It should be immediately beneath the "Content" textarea; if not, check Screen Options (tab in the upper right-hand corner), and ensure that the "Excerpt" checkbox is enabled/checked.
Display a paragraph in the index page that won't be displayed in the single post
wordpress
I have a members section on my site and they see specific custom menu items. I'm seeking a way to simply apply a star to the <code> &lt;li&gt; </code> based on it's permission level and what the user's role is. Something to the effect of. <code> if( current_user_can('integrator') || current_user_can('distributor')) : </code> This is what I have so far and it applies a class to every menu item if the user's role is (whatever). I essentially need to apply the class if another class is present and the user's role is (whatever)... <code> add_filter('nav_menu_css_class' , 'my_nav_special_class' , 10 , 2); function my_nav_special_class($classes, $item){ if (current_user_can('integrator') || current_user_can('distributor')){ $classes[] = 'PARTNER_STAR'; } return $classes; } </code> Courtesy stackexchange-url ("Bainternet") from stackexchange-url ("this post") Any ideas would be appreciated Update: I also want to note that I'm using " Role Scoper " to handle permissions. They do have a template function <code> is_restricted_rs() </code> but I'm honestly unsure how to use it currently.
WRT to your question "need to apply the class if another class is present and the user's role is (whatever)" The easiest was to do this, isn't in the code, but yet in the CSS. You can target an element that has more then once class. So, using your class <code> PARTNER_STAR </code> and if your other class is say <code> another </code> you can have your css such that <code> .another { /* targets all elements with another set */ } .PARTNER_STAR { /* targets all elements with PARTNER_STAR set */ } .another.PARTNER_STAR { /* targets elements that have BOTH PARTNER_STAR and another set */ } </code> Tying in the idea of @robertwbradford you can just set one parent element, and don't need it on every single one. If you have multiple roles, that just need one style, you can still have your if statement, just apply the css to a high-level parent element. <code> .PARTNER_STAR .another { /* targets all elements with another inside PARTNER_STAR */ } </code>
How do I apply a class to custom menu items based on user roles
wordpress
Say, for example, I have the following custom taxonomy: <code> Term 1 Term 1.1 Term 1.2 Term 1.2.1 Term 1.2.2 Term 1.3 Term 2 Term 2.1 </code> How can I get the children terms of Term 1, not including grandchildren? That is, I want my results to include only Term 1.1, Term 1.2, and Term 1.3. Thanks.
possibly with <code> get_terms() </code> and the <code> 'parent' </code> parameter: http://codex.wordpress.org/Function_Reference/get_terms
Get only immediate children (and not grandchildren) of a hierarchical custom taxonomy term
wordpress
Does anyone know how to get 1 or 2 specific posts on top of my wordpress blog all the time? I mean just like in a forum where you can sticky a post so they are always on top of the other posts. Is this maybe a simple line of code (i am not realy a coder) or does anyone knows a good plugin for this? Any help would be realy appreciated.
Set it as a sticky post:
How to get 1 or 2 specific posts on top of my wordpress blog?
wordpress
I want to retrieve a specific post_meta of all posts contained in a specific category. I want to build a search form at the top of each category with a select field which would be filled up by the required post_meta of all the post contained in the category the user is currently in. Is this doable? Maybe it's possible with a loop which would look like: <code> For each post_meta called "City" in all posts contained in category 'X', you must put it in &lt;option value="City's name"&gt;City's name&lt;/option&gt; </code> So far, here is what I have been able to do. <code> &lt;select&gt; &lt;option value="" selected="selected"&gt;Please pick a city below...&lt;/option&gt; &lt;option value="&lt;?php echo get_post_meta($post-&gt;ID, 'City', true) ?&gt;"&gt; &lt;?php echo get_post_meta($post-&gt;ID, 'City', true) ?&gt; &lt;/option&gt; &lt;/select&gt; </code> Not much, I know. Any help, please ? Thank you in advance.
Thank you very much for your answers! I finally found what I wanted here : http://sixrevisions.com/wordpress/custom-fields-search/ Here is the code : <code> &lt;form name="search" action="" method="get"&gt; &lt;select name="City"&gt; &lt;?php $metakey = 'city'; $cities = $wpdb-&gt;get_col($wpdb-&gt;prepare("SELECT DISTINCT meta_value FROM $wpdb-&gt;postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) ); if ($cities) { foreach ($cities as $city) { echo "&lt;option value=\"" . $city . "\"&gt;" . $city . "&lt;/option&gt;"; } } ?&gt; &lt;/select&gt; &lt;input type="submit" value="search" /&gt; &lt;/form&gt; </code> This is a brilliant article and it helped me a lot! I hope it'll help others too.
echo get_post_meta of all post in a category to fill up a select field
wordpress
I have a custom search which is a form that submits to the same page and uses wp_query to filter the results for a jobs site that I would also like the keyword search to also search in custom fields and a custom taxonomy but I am unsure how to use posts_join to do this. I want to allow the user to type in the reference number into the keyword box and for it to search in all custom fields and the custom taxonomy but not filter the results as they won't always match so if i search for a skill i dont want it to not return results if it doesnt match the skill custom field as the keyword maybe in the main description does that make sense? UPDATE: I found this code: stackexchange-url ("Include custom taxonomy term in search") But it doesnt work correctly for some reason rather than bringing back 11 results it is showing 114 so somethihng is not quite right Hover it is searching in the custom taxonomy so this is a starting point. I just need it to search the custom taxonomy and custom fields but fix the amount of results
Managed to figure it out by adapting that code from the link i posted: <code> function atom_search_where($where){ global $wpdb; if($_SESSION['js'] != '') $where .= "OR (t.name LIKE '%".trim($_SESSION['js'])."%' AND {$wpdb- &gt;posts}.post_status = 'publish')"; $where .= "OR ($wpdb-&gt;postmeta.meta_key = '_job_ref' AND $wpdb-&gt;postmeta.meta_value = '".$_SESSION['js']."')"; return $where; } function atom_search_join($join){ global $wpdb; if($_SESSION['js'] != '') $join .= "LEFT JOIN {$wpdb-&gt;term_relationships} tr ON {$wpdb-&gt;posts}.ID = tr.object_id INNER JOIN {$wpdb-&gt;term_taxonomy} tt ON tt.term_taxonomy_id=tr.term_taxonomy_id INNER JOIN {$wpdb-&gt;terms} t ON t.term_id = tt.term_id"; $join .= "LEFT JOIN $wpdb-&gt;postmeta ON ($wpdb-&gt;posts.ID = $wpdb-&gt;postmeta.post_id)"; return $join; } </code>
how to search in custom fields & custom taxonomy for custom search
wordpress
I want the exact output of this site . I want to edit the marker and hover options in the Google map, but I don't know how to do that. Please also list any ideas for Google Map plugins
Mappress allows for custom markers, but you need to pay for the pro version. http://wordpress.org/extend/plugins/mappress-google-maps-for-wordpress/ Google Map Shortcode also supports custom markers in a shortcode http://wordpress.org/extend/plugins/google-map-shortcode/ Getting custom overlays on Google maps is actually pretty easy, you can read the docs here if you choose to work directly with the API, http://code.google.com/apis/maps/documentation/javascript/overlays.html There are plenty of options here: http://wordpress.org/extend/plugins/tags/google-map
Integrating Google Maps with custom marker and hover?
wordpress
Hi I am using a plugin to view the cron jobs that are run by wordpress. I am noticing that there are jobs related to plugins I have deactivated and even deleted. Why is this so and how can I remove them?
This might be because the plugins you were using didnt deregister the crons it setup. To remove the crons use the following code in your functions file: <code> add_action("init", "clear_crons_left"); function clear_crons_left() { wp_clear_scheduled_hook("cron_name"); } </code> Once thats run once you can safely remove it
Cron jobs for deactivated plugins
wordpress
I have a client that has a current WordPress installation in their website root, and they are creating a new WordPress site which is in a subdirectory during development. My question is, what do I do when they are ready to go live and replace their current WordPress install with the new dev version? Can they just point their main URL to the subdirectory instead of having to move the entire dev site into the root of their website? Will this work with WordPress?
WordPress allows for this setup, and they have complete instructions here: Giving WordPress its Own Directory While Leaving Your Blog in the Root Directory I personally would move the files because to me it's cleaner, but the above mentioned solution should work for you.
Can I setup WordPress in a subdirectory and then point my URL to the subdirectory when I'm ready to go live?
wordpress
How does WordPress know a plugin has an available update? Is the process handled by the readme.txt file? I am trying to manage 3rd party plugins that I alter in an effort to better fit/meet the needs of my instance of WordPress but I would like to maintain the functionality that alerts the CMS user that an update is available for the 3rd party plugin. If I alter a plugin’s title will WordPress still know if there is an update to that plugin's code base? E.g. ‘Plugin Name’ (changed to) ‘Plugin Name – Modified’
Basically it sends a list of your plugins to the wordpress.org API server, which does some black magic to try to figure out if any of the plugins you have match the ones it has, then it returns version info back for them. The API uses a rather elaborate mechanism to match plugins against plugins it knows about, but these are the main things checked for: Plugin URI, Plugin Name, and Plugin slug (the directory name the plugin is in) Change any of those and you reduce the chances of it finding a match, but it might still get it if two of them match, for example. Info in the readme.txt is not used for this. The header of the plugin's PHP file itself is used.
What Triggers a Plugin Update Alert
wordpress
Ok This is what i'm trying to achieve. A site network where user can post their articles and get rewarded for each post. For example, Lets say i have a main site example.com. I created a network like site1.example.com, site2.example.com, etc. So lets say i have around 10 subsites in my network. Each subsite have one custom post type. For example site1.example.com has custom post type videos and only dedicated for videos, site2.example.com has custom post type pictures and only dedicated for pictures, etc. Likewise i created 10 custom post types in 10 of my subsites. Now i want user access in all network sites with one registration. I mean user who register in site2.example.com should able to access all my network sites and create new posts. They all should be able to access even if i add a new site in my network. Is there any plugin available for this feature?. Please help me. Thanks
There sure is: Multi Site user Management The plugin syncs your users across sites. I've used it extensively and it works really well.
Single-user registration to access all sites in WordPress MultiSite Network
wordpress
I am still looking for a solution for this and can't seem to find it. I have the following code to start, but am not sure how to write the function to fire off a .js file. I need this to work on one specific page ID. <code> function ipad_alert() { if( preg_match('/ipad/i',$_SERVER['HTTP_USER_AGENT'])) {?&gt; // link to .js file? &lt;?php } } add_action('init','ipad_alert'); </code>
use <code> wp_enqueue_script() </code> to add a js file. I've hooked <code> wp_enqueue_scripts </code> so I can check <code> is_page() </code> for a specific page. <code> function ipad_alert() { if( preg_match('/ipad/i',$_SERVER['HTTP_USER_AGENT']) &amp;&amp; is_page(7) ) { wp_enqueue_script('my_script', get_bloginfo('template_directory') . '/js/my_script.js'); } } add_action('wp_enqueue_scripts','ipad_alert'); </code>
Message box when accessed from iPad
wordpress
I am trying to only show a single post per month on a query. I can set the date as a variable and use something like the php array_unique function to check the dates and only echo out unique ones, however this feels a bit 'hacky'. Is there a built in query variable, or something built in WordPress I can use instead? As for the 'hacky' option, I am quite new with PHP and struggling with using the aforementioned function. Checking the date is unique and only echoing out said variables when it is already inside a while loop is confusing me somewhat. Below is the query I am using currently. <code> &lt;? $news_archive = array( 'post_type'=&gt; 'news', 'posts_per_page' =&gt; 6, 'orderby' =&gt; 'date' ); query_posts($news_archive); echo '&lt;ul class="related_links"&gt;'; while ( have_posts() ) : the_post(); $date = the_date('F m Y','','',false); $date = explode(' ', $date); $month_str = $date[0]; $month_int = $date[1]; $year = $date[2]; echo '&lt;li&gt;&lt;a href="/archive/news/' . $year . '/' . $month_int . '/"&gt;'; echo $month_str . ' ' . $year; echo '&lt;/a&gt;&lt;/li&gt;'; endwhile; echo '&lt;/ul&gt;'; endif; wp_reset_query(); ?&gt; </code>
Maybe a bit less hacky: <code> $months = array(); while(....){ list($month, $year) = explode('/', get_the_date('n/y')); // eg. 7/11 if(in_array($month, $months)) continue; // skip $months[] = $month; echo '&lt;li&gt;&lt;a href="'.get_month_link($month, $year).'"&gt;'.get_the_date('F Y').'&lt;/a&gt;&lt;/li&gt;'; } </code> If you're only getting 6 posts and you don't need pagination that I guess it's OK to go this way. Otherwise you need to build your own SQL query to pull out only one post for each month... You could also try to make 6 queries for each month, like: <code> $january_posts = new WP_Query('monthnum=1&amp;posts_per_page=1')); </code>
Query pulling a single post per month
wordpress
I have created a twenty-eleven child theme, I want to know if its possible to only load that child theme on certain pages, maybe with the custom page templates? I have looked via google and on here and have found nothing on the twenty-eleven or very outdated posts. Thanks
you can use page templates for that if you have a page template within your them, and if its a different theme all together then you can use Page Theme which is a plugin that can be used to display a different theme (not template) for each page/post of your blog.
Use child theme on certain pages and not others?
wordpress
I have a site which is essentially a blog carrying alerts to Doctors. The idea is that the Doctors will get an SMS alerting them to the fact that a new alert has been posted and a link to the alert. The alert will contain images. It is public, hidden from SE but might contain some sensitive info. I was wondering if there was any way of authenticating a user by mobile phone number, or any easy way for a mobile phone user to log in to a Wordpress site?
This is complex and considering the sensitive nature of the application and the usage "doctor alerts" I would really consider not using a blog platform. There are a lot of systems out there that support secure sms with options for media. If you must for some reason use WordPress, to authenticate users have a look at some of the HTTP authentication plugins, OAuth, XML-RPC, or just regular logins with cookie support and a mobile friendly theme. ps. You cannot get a mobile number unless the user gives it to you.
Quick login from mobile phone
wordpress
For some reason, my menu items are showing tooltips on hover-over- In other words, the menu links have "title" attributes being added to them. Looking at my other, older WordPress sites, this is not the case. I can't remember having this issue before- Why would this be happening? Thanks-
Here’s the code to remove it from wp_page_menu(), wp_nav_menu() and wp_list_categories() function: <code> function my_menu_notitle( $menu ){ return $menu = preg_replace('/ title=\"(.*?)\"/', '', $menu ); } add_filter( 'wp_nav_menu', 'my_menu_notitle' ); add_filter( 'wp_page_menu', 'my_menu_notitle' ); add_filter( 'wp_list_categories', 'my_menu_notitle' ); </code> Source
Disabling tooltip on menu items
wordpress
I recently developed a small plugin for my site, that uses AJAX, and now I am trying to implement the same AJAX techniques for the same site's templates, but I keep getting <code> -1 </code> as the result, here is my code, functions.php: <code> //Front end AJAX functions function eu_custom_query(){ global $post; global $wpdb; echo "yo"; die(); } function enque_template_scripts() { wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', 'http://code.jquery.com/jquery-1.6.2.js'); wp_enqueue_script( 'jquery' ); // embed the javascript file that makes the AJAX request wp_register_script( 'scripts.js', get_bloginfo('template_directory').'/scripts/scripts.js'); wp_enqueue_script( 'scripts.js' ); // declare the URL to the file that handles the AJAX request (wp-admin/admin-ajax.php) wp_localize_script( 'scripts.js', 'wp_ajax', array( 'ajaxurl' =&gt; admin_url( 'admin-ajax.php' ) ) ); } add_action('wp_ajax_custom_query', 'eu_custom_query'); add_action('wp_ajax_nopriv_custom_query', 'eu_custom_query'); add_action('get_header', 'enque_template_scripts'); </code> scripts.js: <code> $(document).ready(function(){ $("#do_ajax").click(function(){ $.post(wp_ajax.ajaxurl, { action: 'eu_custom_query' }, function(data){ alert(data); }); }); }); </code> I'm using Wordpress version 3.2.1 Any ideas on what I'm doing wrong?
You are passing 'eu_custom_query' as the action in your AJAX. It should be 'custom_query'. You decide the action name, when you add the action i.e. 'wp_ajax_my_action' would be called 'my_action' You are confusing it with the callback method. Hope that makes sense. p.s. to fix your code change: <code> add_action('wp_ajax_custom_query', 'eu_custom_query'); add_action('wp_ajax_nopriv_custom_query', 'eu_custom_query'); </code> to: <code> add_action('wp_ajax_eu_custom_query', 'eu_custom_query'); add_action('wp_ajax_nopriv_eu_custom_query', 'eu_custom_query'); </code>
AJAX function returning -1
wordpress
Is it possible to search in custom post type meta fields? I have posts, with many custom meta fields. Wordpress by default search only in title and in content. How can I change it? If you didn't understand what I am saying, please take a look at my screenshot .
Take a look at my answer to how to filter post listing (in WP dashboard posts listing) using a custom field (search functionality) ? Its just what you are looking for.
Custom post type admin search
wordpress