question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I have a custom query to display random posts in my sidebar like this: <code> $newQuery = array( 'post__in' =&gt; get_option('sticky_posts'), 'post_type' =&gt; 'ad_listing', 'posts_per_page' =&gt; 10, 'orderby' =&gt; 'rand', 'post_status' =&gt; 'publish'); // Get new set of ads $smStickyPosts = new WP_Query($newQuery); if ($smStickyPosts-&gt;have_posts()) : while($smStickyPosts-&gt;have_posts() : $smStickyPosts-&gt;the_post(); //Display posts endwhile; </code> This works fine in all pages, except on the search page, for some reason the first post on the list is always the post that coincides with the search term (for example, if I search for foo and I have a post with the title "foo" it will show first followed by 9 random posts), it's like the search term is getting passed to the custom loop as well. Also I noticed that if I search for something that doesn't find any results the posts are always the same, it's like the orderby => rand is not doing anything, it works fine on the rest of the site though. Does anyone know what could be wrong? Thanks in advance.
Suggest you have a look at http://wordpress.org/support/topic/passing-current-single_tag_title-as-variable-into-new-wp_query - I suspect the very last comment which covers both backing up and reseting your query will help.
Problem with WP_Query loop and search term
wordpress
I'm using the TwentyTen theme to create a child theme, but I can't seem to get rid of the 'One column, no sidebar' page template that is in the TwentyTen parent theme. I thought just copying it over and deleting the contents would do the trick, but it seems not. Does anyone know how to do this? I'm sure it's very simple. Thanks osu
Overriding that template would be much easier than getting rid of it. Just the way logic goes. I make no claim it's efficient idea (late here), but this would get it nuked from edit screen: <code> add_action('admin_head-post.php','remove_template'); function remove_template() { global $wp_themes; get_themes(); $templates = &amp;$wp_themes['Twenty Ten']['Template Files']; $template = trailingslashit( TEMPLATEPATH ).'onecolumn-page.php'; $key = array_search($template, $templates); unset( $templates[$key] ); } </code>
How to *remove* a parent theme page template from a child theme?
wordpress
Hay Guys , I'm currently making a plugin so that the administrator can manage "Subscriptions" to the website. I have made a custom post type and activated it within WordPress and only allowed the title field. This works perfectly on the backend, but now i need a way for front end users to add their email address. How would i implement this, i need to add data to the database, i could easily just write some PHP to manually add the data, but does WordPress have any calls so that i can save data to the database?
Rake a look at wp_insert_post() which handles the insertion of new posts to the database. and there are many example how to create posts from the front end stackexchange-url ("here"), stackexchange-url ("here"), stackexchange-url ("here"), stackexchange-url ("here") and stackexchange-url ("here"):
Allow front end users to add data to a custom post type
wordpress
I am currently using a custom walker to customize the output of <code> wp_nav_menu() </code> , and I am trying to add additional information to the <code> &lt;a&gt; </code> tags. What I want the output for each menu link to look like is: <code> &lt;a class="boxPAGEID" href="#"&gt;About Me Page&lt;/a&gt; </code> Where <code> PAGEID </code> is the ID of the page I'm linking to. The reason is because I am developing a theme that opens page content in lightboxes, which are triggered by the class in the tag. Below is the code of the custom walker in my <code> functions.php </code> file (after the code I'll point to the area where I'm having trouble): <code> class description_walker extends Walker_Nav_Menu { function start_el(&amp;$output, $item, $depth, $args) { global $wp_query; $pageid = $wp_query-&gt;post-&gt;ID; $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; $class_names = $value = ''; $classes = empty( $item-&gt;classes ) ? array() : (array) $item-&gt;classes; $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ); $class_names = ' class="'. esc_attr( $class_names ) . '"'; $output .= $indent . '&lt;li id="menu-item-'. $item-&gt;ID . '"' . $value . $class_names .'&gt;'; $attributes = ! empty( $item-&gt;attr_title ) ? ' title="' . esc_attr( $item-&gt;attr_title ) .'"' : ''; $attributes .= ! empty( $item-&gt;target ) ? ' target="' . esc_attr( $item-&gt;target ) .'"' : ''; $attributes .= ! empty( $item-&gt;xfn ) ? ' rel="' . esc_attr( $item-&gt;xfn ) .'"' : ''; $attributes .= ! empty( $item-&gt;url ) ? ' href="' . '#' .'"' : ''; $prepend = '&lt;strong&gt;'; $append = '&lt;/strong&gt;'; $description = ! empty( $item-&gt;description ) ? '&lt;span&gt;'.esc_attr( $item-&gt;description ).'&lt;/span&gt;' : ''; if($depth != 0) { $description = $append = $prepend = ""; } $item_output = $args-&gt;before; $item_output .= '&lt;a'. $attributes . 'class="box' . $pageid . '"' .'&gt;'; $item_output .= $args-&gt;link_before .$prepend.apply_filters( 'the_title', $item-&gt;title, $item-&gt;ID ).$append; $item_output .= $args-&gt;link_after; $item_output .= '&lt;/a&gt;'; $item_output .= $args-&gt;after; $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); if ($item-&gt;menu_order == 1) { $classes[] = 'first'; } } } </code> Towards the end are a couple of lines that begin with <code> $item_output </code> . The second line is where I'm trying to generate the page ID: <code> $item_output .= '&lt;a'. $attributes . 'class="box' . $pageid . '"' .'&gt;'; </code> Where <code> $pageid </code> is according to: <code> global $wp_query; $pageid = $wp_query-&gt;post-&gt;ID; </code> This gives me a single, fixed ID for all the links generated. Alternatively, instead of <code> $pageid </code> I tried using <code> $item-&gt;ID </code> , but that gave me the ID of the menu item instead. Any suggestions?
The page ID (or object ID, since a menu item can link to any object) is stored in the <code> postmeta </code> table, with the key <code> _menu_item_object_id </code> . So you can get the page ID with the following code: <code> get_post_meta( $item-&gt;ID, '_menu_item_object_id', true ); </code>
Get the ID of the page a menu item links to?
wordpress
We have a custom type <code> music </code> . <code> /music/ /music/post-name/ </code> Also, we have a tag-like taxonomy <code> genres </code> . Its urls are: <code> /music-genres/genre-name/ </code> I'm trying to make urls like: <code> /music/ /music/post-name/ /music/genres/ /music/genres/genre-name/ </code> <code> /music-genres/ </code> should be replaced by <code> /music/genres/ </code> . Finally we should get url structure like: <code> /post-type/taxonomy/term/ /post-type/postname/ </code> How do I do this?
Yes, this is possible, because your <code> genres </code> structure is <code> /music/genres/[genre-name] </code> . If it was <code> /music/[genre-name] </code> it would be complicated because it would conflict with <code> /music/[post-name] </code> . You just have to keep the order in mind. The rewrite rules should be ordered from most specific to least specific. If you first register the post type and then the taxonomy, the post type rules will come first. The problem is that the post type rules contain a very generic rule to match attachments, and this would mess with our taxonomy terms. But it will work if you first register the taxonomy and then the post type. The confusing thing is that you normally pass the post types that will use the taxonomy you are registering, but you can just pass the empty array and make the connection later. <code> add_action( 'init', 'wpse13608_init' ); function wpse13608_init() { register_taxonomy( 'music-genre', array(), array( 'rewrite' =&gt; array( 'slug' =&gt; 'music/genre' ), ) ); register_post_type( 'music' ); register_taxonomy_for_object_type( 'music-genre', 'music' ); } </code> You can verify this and play with your rules with my stackexchange-url ("Rewrite analyzer plugin").
Custom permalinks
wordpress
I have a dilemma, well a new blog which im developing and a few of the posts titles are like this 'Tutorial: Build your first App' or 'Tutorial: Start your business with xensuithia' I have a page called tutorials that display the posts from this category. I need the title to not display the 'Tutorial:' part on this page, I tried: str_replace('Tutorial:',' ', the_title()); However it does not work. It just outputs the full title.
That's because the_title() echoes the title. Use this instead: <code> echo str_replace( 'Tutorial: ', '', get_the_title() ); </code>
str_replace the_title(); blues
wordpress
I want to add <code> &lt;code&gt; </code> tag to my post, easily. For example, Adding code is very easily in Stackoverflow and other sites. Basically, we can add codes between apostrophes (``) I need something like that for Wordpress . Maybe i can use shortcode function for this. For example : <code> [code="&lt;b&gt;Hello&lt;/b&gt;"] </code> will show exactly like this : <code> &lt;b&gt;Hello&lt;/b&gt; </code> In summary, i'm sharing a lot of HTML and PHP codes with my readers on my blog. I need an easily way to share them. Is it possible, like stackoverflow's apostrophe method ? Or maybe shortcodes ? Thanks...
I'd suggest using Syntax Highlighter Evolved . It's by Viper007Bond. You can use it like this: <code> [sourcecode lang="php"] &lt;?php echo 'Hello World!'; ?&gt; [/sourcecode] </code> Or even like this: <code> [php] &lt;?php echo 'Hello World!'; ?&gt; [/php] </code> A screenshot: EDIT An example of how you could do the backticks method that SE uses: <code> function wpse13653_content( $content ){ return preg_replace( '@`([^`]+)`@', '&lt;code&gt;$1&lt;/code&gt;', $content ); } foreach( array( 'the_content', 'comment_text' ) as $hook ) add_filter( $hook, 'wpse13653_content', 1 ); function wpse13653_excerpt( $content ){ $content = preg_replace( '@`([^`]+)`@', '&lt;code&gt;$1&lt;/code&gt;', $content ); return str_replace( '`', '', $content ); } add_filter( 'the_excerpt', 'wpse13653_excerpt', 1 ); </code> This would let you use backticks in comments and post text, but would also prevent the backticks from showing up in excerpts after the code's been stripped in automatic excerpts.
How can i share codes on my blog?
wordpress
I am working on a custom Wordpress theme for my bosses website. I have everything working perfectly so far except for one thing... the external javascript files will not work. I followed the exact advice from the links stackexchange-url ("here") and stackexchange-url ("here"), but it still does not work. I have searched the codex, checked source code, used firebug... i have no idea why this is not working. Unfortunately, due to an NDA, I am not allowed to give you any of the actual code from the site, or a link to it. So I will have to explain as best as I can. I have used the wp_enqueue_script() to include the files in the functions.php file. The script tags in the head are as follows: <code> &lt;script type='text/javascript' src='http://www.xx.com/wp-includes/js/jquery/jquery.js?ver=1.4.4'&gt;&lt;/script&gt; &lt;script type='text/javascript' src='http://www.xx.com/wp-content/themes/twentyten/scripts/custom.js?ver=3.1'&gt;&lt;/script&gt; </code> So the files are loading, but they just are not working. I was wondering if the "?ver=3.1" at the end of my custom.js file might have anything to do with it? The code from my functions.php file: <code> function twentyten_custom_scripts() { if ( !is_admin() ) // instruction to only load if it is not the admin area { // register your script location, dependencies and version wp_register_script('custom_script', get_bloginfo('template_directory') . '/scripts/custom.js', array('jquery') ); // enqueue the script wp_enqueue_script( 'jquery' ); wp_enqueue_script('custom_script'); } } add_action('template_redirect', 'twentyten_custom_scripts'); </code> I am really lost at this point. I even changed all my <code> $('#elem').hide(); </code> to <code> jQuery('#elem').hide(); </code> in the custom.js file according to the codex wp_enqueue_script no conflicts wrappers section here , still nothing. Oh, and I am needing this file to load into all of my PAGES, but not on my Blog, as I have multiple "static" pages set up for the main site. I hope that makes sense. Thanks in advance. Joe.
From my point of view, this should be working. Maybe you can post your custom.js file here. It could be possible that this file has a syntax error or something similar. You could also test if the built-in jquery is working out of the box by adding a simple jquery-command in your header.php . Some hints: The action-hook <code> template_redirect </code> is used to include the file only on the front-page (so i can remeber). If you want to load the script after the theme is loaded, you can use the <code> after_setup_theme </code> action-hook. You don't have to enqueue your jquery file manually, if you set jquery as a dependancy of your custom.js , like you did. The file will automatically be loaded from WordPress before your custom.js is attached. Do you have added the <code> jQuery.noConflict(); </code> at the beginning of your custom.js ? Some working example: functions.php <code> function twentyten_custom_scripts() { if ( !is_admin() ) // instruction to only load if it is not the admin area { wp_register_script('custom_script', get_bloginfo('template_directory') . '/scripts/custom.js', array('jquery') ); wp_enqueue_script('custom_script'); } } add_action('after_setup_theme', 'twentyten_custom_scripts'); </code> custom.js <code> jQuery.noConflict(); jQuery(document).ready(function() { // do your stuff e.g. jQuery("a[rel^='prettyPhoto']").prettyPhoto(); }); </code>
How to link external javascript files?
wordpress
I am having trouble adding a list box to the TinyMCE editor in Wordpress. I have already read entirely through this question but it did not get me all the way there: stackexchange-url ("How i can i add a split button or list box to the WordPress TinyMCE instance"). That solution only alerts the value in a dialog box. I want to actually insert the shortcode into the TinyMCE editor and I can't figure out how. I am successfully able to add custom buttons and listboxes to the TinyMCE editor, and the buttons work but the listbox does not. Here's my functions.php code: <code> // add shortcode buttons to the tinyMCE editor row 3 function add_button_3() { if ( current_user_can('edit_posts') &amp;&amp; current_user_can('edit_pages') ) { add_filter('mce_external_plugins', 'add_plugin_3'); add_filter('mce_buttons_3', 'register_button_3'); } } //setup array of shortcode buttons to add function register_button_3($buttons) { array_push($buttons, "dropcap"); array_push($buttons, "divider"); array_push($buttons, "quote"); array_push($buttons, "pullquoteleft"); array_push($buttons, "pullquoteright"); array_push($buttons, "boxdark"); array_push($buttons, "boxlight"); array_push($buttons, "togglesimple"); array_push($buttons, "togglebox"); array_push($buttons, "tabs"); array_push($buttons, "signoff"); array_push($buttons, "fancylist"); array_push($buttons, "arrowlist"); array_push($buttons, "checklist"); array_push($buttons, "starlist"); array_push($buttons, "pluslist"); array_push($buttons, "heartlist"); array_push($buttons, "infolist"); array_push($buttons, "columns"); return $buttons; } //setup array for tinyMCE editor interface function add_plugin_3($plugin_array) { $plugin_array['fancylist'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['arrowlist'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['checklist'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['starlist'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['pluslist'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['heartlist'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['infolist'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['signoff'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['dropcap'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['divider'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['quote'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['pullquoteleft'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['pullquoteright'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['boxdark'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['boxlight'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['togglesimple'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['togglebox'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['tabs'] = get_bloginfo('template_url').'/js/customcodes.js'; $plugin_array['columns'] = get_bloginfo('template_url').'/js/customcodes.js'; return $plugin_array; } add_action('init', 'add_button_3'); // add the add_button function to the page init </code> And here is my JS for adding the listbox to the TinyMCE editor: <code> // Creates a new plugin class and a custom listbox tinymce.create('tinymce.plugins.columns', { createControl: function(n, cm) { switch (n) { case 'columns': var mlb = cm.createListBox('columns', { title : 'Add a Column', onselect : function(v) { tinyMCE.activeEditor.windowManager.alert('Value selected:' + v); } }); // Add some values to the list box mlb.add('One Third', 'one_third'); mlb.add('One Third (last)', 'one_third_last'); mlb.add('Two Thirds', 'two_thirds'); // Return the new listbox instance return mlb; } return null; } }); tinymce.PluginManager.add('columns', tinymce.plugins.columns); </code> What do I need to change in the JS for it to actually add the shortcode to my editor instead of just displaying the value of the listbox in a modal dialog?
In the TinyMCE plugin i wrote, my listbox wraps selected text in HTML, i do that like this.. <code> onselect : function(v) { // Set focus to WordPress editor ed.focus(); // Get selected text var sel_txt = ed.selection.getContent(); // If no text selected if( '' == sel_txt ) return null; var active_style = toggle_styles[v]; if( 'undefined' == active_style || typeof( active_style ) != 'object' ) return null; tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, '&lt;'+active_style.tag+' class="'+active_style.classes+'"&gt;'+sel_txt+'&lt;/'+active_style.tag+'&gt; ' ); //alert( tinyMCE.activeEditor.selection.getNode().nodeName ); return false; } // close onselect function </code> You might notice my function is reading in some data from a JS var, that won't be available inside your own script, but here's a basic trimmed down version that should work for you. <code> onselect : function(v) { // Set focus to WordPress editor ed.focus(); // Get selected text var sel_txt = ed.selection.getContent(); // If no text selected if( '' == sel_txt ) return null; tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, '&lt;div class="someclass"&gt;'+sel_txt+'&lt;/div&gt; ' ); return false; } </code> Just to make sure i've been clear, the above would replace the following part of your code... <code> onselect : function(v) { tinyMCE.activeEditor.windowManager.alert('Value selected:' + v); } </code> Hope that helps... :) Follow-up #1 If you're creating your own TinyMCE instance and not just adding to the WordPress instance the <code> ed </code> var possibly won't be set. Change this.. <code> // Set focus to WordPress editor ed.focus(); // Get selected text var sel_txt = ed.selection.getContent(); </code> for.. (off the top of my head) <code> var sel_txt = tinyMCE.activeEditor.selection.getContent(); </code> See if that helps..
How do I add a listbox to the TinyMCE editor?
wordpress
I have developed a site in worpdress. I need to manage a different questions like "How would you rate our customer service", "How satisfied were you with our service" and more questions and rate these questions and have view on the admin. I tried to find the plugin but could not find. Can anyone let me know if that type of plugin exists or do I need to do with my own codes? Thank you in advance
Yes, there is a plugin - GD Star Ratings. I am using it here: http://apluginforthat.com/gd-star-ratings/ . You can customize your questions, type of ratings (thumbs up/down vs stars) and much more. You can also configure it to have the ratings appear in your dashboard.
Is there a plugin for rating of multiple questions for wordpress?
wordpress
i was using a wordpress install on an ubuntu server virtual machine. At first the adapter was host-only at an address of 192.168.55.55. The host had this on a vboxnet0 subnet. i changed to bridged adapter to try port forwarding from the router, and now i cant access the page with the new address. the new address is 192.168.1.5 and everything appears fine on routing tables of host. i also cleared the dnsCache on the host. but when i type in: 192.168.1.5/wordpress in the browser, the activity bar shows it is trying to contact the old ip of 192.168.55.55, which was the vboxnet0 host-only adapter.
The easiest way to do this is by using copy&amp;replace in the SQL file. Export the database. Use your favorite text editor and do a copy&amp;replace and import it into a new database. Then you go to wp-config.php and you change the WP_HOME and WP_SITEURL to the new host. Then you change the databasename. You also need to ensure that the same db user has access to the database. Btw: There is a separate stackexchange for wordpress. Check out stackexchange-url ("stackexchange-url
How do I reset a self-hosted Wordpress URL?
wordpress
I'm using Wordpress 3.1. I need to forbid users to change their first, last and screen names in their profile, but admin must still have this possibility. How can I do that?
Have a look at stackexchange-url ("this question - Preventing users from changing their email address").
How to forbid users to change their first, last and screen names?
wordpress
I have a need to make the Loop run through all of the children of a parent, all of the children of each child, etc. The reason I need the Loop instead of a listing tag like wp_list_pages is so that I can display any information associated with the pages using WP template tags and functions. It's for a showcase-style display that has hierarchical content and gets rearranged, so pages > posts for this usage. I've gotten as far as getting the loop to show children of the current page and an inner loop going to show grandchildren, but this is just a brute-force prototype, and I need to take it to the next level. What I think I need to do is use 1 loop that starts with post_parent (so that it shows child pages) but insert a function to change the post ID to each child page found so that the loop continues to drill down until it runs out, then backs out 1 level, goes to the next available ID, etc. My problem is that I'm not enough of a WP programmer (or real programmer at all) to get that going. If it were all out in code I bet I could work it out, but WP has obviously got hidden functions going with have_post and the_post to cycle through the available post IDs, and that has me lost as to how to integrate what I need. Here's where I am at the moment. Any help will be greatly appreciated! <code> &lt;?php $args = array( 'posts_per_page' =&gt; -1, 'post_parent' =&gt; $post-&gt;ID, 'post_type' =&gt; 'page', 'post_status' =&gt; '', 'orderby' =&gt; 'title', 'order' =&gt; 'ASC',); query_posts($args); ?&gt; &lt;?php if(have_posts()) : while (have_posts()) : the_post(); ?&gt; &lt;a href="&lt;?php the_permalink();?&gt;"&gt;&lt;?php the_title();?&gt;:&lt;/a&gt; &lt;?php $inner_query = new WP_Query("post_type=page&amp;posts_per_page=-1&amp;post_parent={$id}&amp;order_by=title&amp;order=ASC"); ?&gt; &lt;?php while ($inner_query-&gt;have_posts()) : $inner_query-&gt;the_post(); ?&gt; &lt;a href="&lt;?php the_permalink();?&gt;"&gt;&lt;?php the_title();?&gt;:&lt;/a&gt; &lt;?php endwhile; // end inner loop ?&gt; &lt;?php endwhile; //end outer loop ?&gt; &lt;?php endif; // end outer if have_posts?&gt; </code>
Sounds like you're looking for a recursive function, ie a function that calls itself. Here's a rough outline of how it can be done: <code> function wpse13669_show_all_children( $post_id, $current_level ) { $children = get_posts( array( 'post_type' =&gt;'page', 'posts_per_page' =&gt;-1, 'post_parent' =&gt; $post_id, 'order_by' =&gt; 'title', 'order' =&gt; 'ASC' ) ); if ( empty($children) ) return; echo '&lt;ul class="children level-'.$current_level.'-children"&gt;'; foreach ($children as $child) { /* Here would be the point where you do whatever you want to display the posts. The variable $current_level can be used if you want to style different levels in the hierarchy differently */ echo '&lt;li&gt;'; echo '&lt;a href="'.get_permalink($child-&gt;ID).'"&gt;'; echo apply_filters( 'the_title', $child-&gt;post_title ); echo '&lt;/a&gt;'; // now call the same function for child of this child wpse13669_show_all_children( $child-&gt;ID, $current_level+1 ); echo '&lt;/li&gt;'; } echo '&lt;/ul&gt;'; } </code> Note: edited my code to show the kind of nested <code> &lt;ul&gt; </code> lists it sounds like you're looking for. If you want to see how WordPress does stuff like this internally (its a lot more complicated than this, but worth figuring out if you need to do anything really custom in your code), you should look through the source code for the class-wp-walker.php file, where the Walker class that handles all the various nested lists (menus, comments, page lists, etc) throughout WP. If you define that function with the output structure you want and just call it from within your loop, it should do what you're looking for. I put a $current_level variable in there just so that you can easily style children different from grand-children, and so on. (within your main loop) <code> wpse13669_show_all_children( $post-&gt;ID, 1 ); </code>
Using the Loop to show all levels of subpages under a parent page? Halfway there
wordpress
Basically I wrote a function that lets me change the post status to draft depending of a field in the postmeta table: <code> /** * Remove ads if they have been sold for over 5 days */ function cp_remove_sold_ads(){ global $wpdb; // Get all sold ads $sold_ads = $wpdb-&gt;get_results("SELECT * FROM " . $wpdb-&gt;prefix . "postmeta WHERE `meta_key` = 'cp_ad_sold_date' AND `meta_value` &lt;&gt; ''"); foreach ($sold_ads as $ad) { $today = time(); // Get day, month, year $date = explode('-',get_post_meta($ad-&gt;post_id, 'cp_ad_sold_date', true)); $sold_date = mktime(null, null, null, $date[1], $date[2], $date[0]); $date_diff = $today - $sold_date; // Get the days difference $sold_day_diff = floor($date_diff / (60*60*24)); if ($sold_day_diff &gt;= 5) { wp_update_post(array('ID' =&gt; $ad-&gt;post_id, 'post_status' =&gt; 'draft')); } } } </code> This works fine, and if I add the function to the init action it does what its supposed to: <code> add_action( 'init' , 'cp_remove_sold_ads' ); </code> However I'd like to make this action execute daily instead, I've been looking around and found that WP uses wp_schedule_event to hanlde cron jobs, but I have no idea how to use it, does anyone know what do I have to add to handle it? Thanks in advance!
Just look at the examples in the WordPress Codex for: wp_schedule_event wp_schedule_single_event
Create cron job without a plugin?
wordpress
I was helped not long ago with a form of custom truncating by stackexchange-url ("Toscho") on stackexchange-url ("this post") it works very well but I'm finding that I need to create multiple length variations for different bits of content. For instance on my support page I need to 80 max_chars vs. my home page which I need 200 max_chars. I tried adding a second instance of this function but unsurprisingly it totally killed other aspects of my site. As always, any help would be appreciated. Thanks guys! <code> function utf8_truncate( $string, $max_chars = 200, $append = "\xC2\xA0…" ) { $string = strip_tags( $string ); $string = html_entity_decode( $string, ENT_QUOTES, 'utf-8' ); // \xC2\xA0 is the no-break space $string = trim( $string, "\n\r\t .-;–,—\xC2\xA0" ); $length = strlen( utf8_decode( $string ) ); // Nothing to do. if ( $length &lt; $max_chars ) { return $string; } // mb_substr() is in /wp-includes/compat.php as a fallback if // your the current PHP installation doesn't have it. $string = mb_substr( $string, 0, $max_chars, 'utf-8' ); // No white space. One long word or chinese/korean/japanese text. if ( FALSE === strpos( $string, ' ' ) ) { return $string . $append; } // Avoid breaks within words. Find the last white space. if ( extension_loaded( 'mbstring' ) ) { $pos = mb_strrpos( $string, ' ', 'utf-8' ); $short = mb_substr( $string, 0, $pos, 'utf-8' ); } else { // Workaround. May be slow on long strings. $words = explode( ' ', $string ); // Drop the last word. array_pop( $words ); $short = implode( ' ', $words ); } return $short . $append; } </code>
I know toscho doesn't like this very much, but anyway: Converted the input args to an array: <code> function utf8_truncate( $args = array( 'string' =&gt; null, 'max_chars' =&gt; 200, 'append' =&gt; "\xC2\xA0…" ) ) { $args['string'] = strip_tags( $args['string'] ); $args['string'] = html_entity_decode( $args['string'], ENT_QUOTES, 'utf-8' ); // \xC2\xA0 is the no-break space $args['string'] = trim( $args['string'], "\n\r\t .-;–,—\xC2\xA0" ); $length = strlen( utf8_decode( $args['string'] ) ); // Nothing to do. if ( $length &lt; $args['max_chars'] ) { return $args['string']; } // mb_substr() is in /wp-includes/compat.php as a fallback if // your the current PHP installation doesn't have it. $args['string'] = mb_substr( $args['string'], 0, $args['max_chars'], 'utf-8' ); // No white space. One long word or chinese/korean/japanese text. if ( FALSE === strpos( $args['string'], ' ' ) ) { return $args['string'] . $args['append']; } // Avoid breaks within words. Find the last white space. if ( extension_loaded( 'mbstring' ) ) { $pos = mb_strrpos( $args['string'], ' ', 'utf-8' ); $short = mb_substr( $args['string'], 0, $pos, 'utf-8' ); } else { // Workaround. May be slow on long strings. $words = explode( ' ', $args['string'] ); // Drop the last word. array_pop( $words ); $short = implode( ' ', $words ); } return $short . $args['append']; } </code> This allows to use it like this stackexchange-url ("(you possibily missed how to use arrays anyway)"): <code> $args = array( 'string' =&gt; 'bla' ,'max_chars' =&gt; 50 // INPUT LENGTH HERE ); echo '&lt;p&gt;' . utf8_truncate( $args ) . '&lt;/p&gt;'; </code> You could also switch this on demand: <code> if ( is_page() ) { $args['max_chars'] = 100; } elseif ( is_archive() ) { $args['max_chars'] = 50; } elseif ( is_whatever() ) ... etc ... } </code>
Truncating varying lengths of information
wordpress
I'm trying to create a search results listing for a custom post type and the problem I'm running in to is with the way the 'meta_query' parameter is stringing the passed values together. It appears to be treating each 'meta_query' value as an 'AND' rather than 'OR'. Here is the code I'm using: <code> $strsearch = 'lorem'; $args = array( 'post_type' =&gt; 'products', 'meta_query' =&gt; array( array('key' =&gt; '_product_make','compare' =&gt; 'LIKE','value' =&gt; $strsearch), array('key' =&gt; '_product_model','compare' =&gt; 'LIKE','value' =&gt; $strsearch) ) ,'s' =&gt; $strsearch); $resource_query = new WP_Query($args); </code> When I search anyone of the fields individually I get the desired results. When I use them together it comes up as not found since the string I'm searching for may only occur in one of the three fields listed below. Is there any way to have 'meta_query' treat each of the passed field comparisons as 'OR'?
Yes, since WP 3.2 you can set the 'relation' arg: <code> 'meta_query' =&gt; array( 'relation' =&gt; 'OR', array('key' =&gt; '_product_make','compare' =&gt; 'LIKE','value' =&gt; $strsearch), array('key' =&gt; '_product_model','compare' =&gt; 'LIKE','value' =&gt; $strsearch) ) </code> See http://core.trac.wordpress.org/ticket/17011
Search multiple custom fields by using meta_query
wordpress
I've two wordpress installs at <code> example.com/blog example.com/otherblog </code> What I want to do is install WP at the root, and have a network, but maintain the URLs. I'm confident I can install WP, and export the single installs, and import them to the network. My question is this: can I do all this, and keep the urls? And can the an old one run simultaneously with the new network site before it gets imported so I don't have to import both at once? I.e. could I have example.com/blog run under the multisite while example.com/otherblog runs on its own install? If this is possible what steps do I have to take beyond all the import/export business?
Short answer ... yes. When you install WordPress at the root of <code> example.com </code> you'll be creating a third blog. Don't worry too much about this, just recognize it's there. Create your network using subfolders for the different sites. Then create two new sites: <code> blog </code> and <code> otherblog </code> . By default, any posts on these sites will use the URL structure: <code> example.com/[sitename]/[permalink] </code> Then just import your old site into the new one and you'll have the same URLs. Unfortunately, there's not really a way you can have the old one run simultaneously with the new one. All requests to the root ( <code> example.com </code> ) will be eaten by WordPress and redirected to the appropriate site. So if you set up <code> blog </code> first, any requests to <code> example.com/otherblog </code> will result in a 404 error until you set up and import that site as well. If your sites were running on subdomains rather than in subfolders it would be possible ... it's an unfortunate circumstance many people who have shared hosting plans run into (and a good reason to upgrade your host).
Create new network instance, import old single installs AND keep the urls?
wordpress
Hey all, I see that get_the_excerpt() echoes the post excerpt if it is manually set, but not if it is automatically generated (with just the 55 words, for example). [and its use is deprecated] the_excerpt() on the other hand, echoes directly without giving me a string in return. Is there a function to return the excerpt of a post in Wordpress, including automatic excerpt if not manually defined, without echoing it?
Sure thing my friend, you see, the function "the_excerpt" (located at "WORDPRESSINSTALLDIR/wp-includes/post-template.php") is the one that makes the echo: <code> function the_excerpt() { echo apply_filters('the_excerpt', get_the_excerpt()); } </code> so, what you want is to use the same function "apply_filters" without the echo: <code> $myexcerpt = apply_filters('the_excerpt', get_the_excerpt()); </code> ...and there you have your excerpt.
How to return the_excerpt (without echo)?
wordpress
Most of the plugins I see also send the newsletter, which I don't need. I need a simple, customizable plugin that helps me get user e-mails, name, and other custom fields, and store it in the database. The plugin must also have an unsubscribe option, of course.
Contact Form 7 is pretty flexible. And there's the premium plugin, Gravity Forms , which a lot of people love. Or if you don't really need to keep the subscriber info in your own database, you could always use a service like MailChimp , for which there are WordPress plugins available for subscriber sign-up.
A plugin for newsletter registration (not sending, just gathering data)?
wordpress
I've installed a number of WordPress sites across many different platforms and I'm finding that when installed on IIS7 I'm getting the nasty default IIS7 404 error. I nuked Window's hold on the 404 and now I'm receiving the standard. The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. Is there an address I need to redirect to in order to display the WP404? Or does anyone have a better suggestion? Thanks a ton!
This resolved my 404 error. I essentially went into IIS and directed the 404s to a custom URL “/index.php?error=404“ Article that explained how to resolve the error
WordPress 404 page returning with default in IIS7
wordpress
Are there plugins or hooks to editing custom fields just from the posts listing in admin panel?
The easiest way is to use a plugin like Custom Field Template . This adds a custom field column to the "Manage Posts" page by default.
Adding custom Field To The Posts Listing
wordpress
I have a very simple site that I've modified a very small amount. After installing the Yoast SEO plugin I found that it broke the in post media attach/upload. I'm about 80% sure it's related to Jquery but I'm unable to find anything that refer's to it enqueuing anything. I tried forcing an enqueue from functions.php but it didn't help. Any assistance would be appreciated. <code> function my_init_method() { wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js'); wp_enqueue_script( 'jquery' ); } add_action('init', 'my_init_method'); </code>
You have introduced 2 additional problems by adding the jQuery from Google CDN. The admin interface needs jQuery called in no conflict mode so it won't interfere with the other scripts WordPress uses for the dashboard. The WordPress dashboard is not yet compatible with jQuery 1.5 thats why it was pulled from trunk right before 3.1 was released. See: WordPress Development Blog . If you want to use Google's jQuery register it like this: <code> function my_init_method() { if (!is_admin()) { wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js'); wp_enqueue_script( 'jquery' ); } } add_action('init', 'my_init_method'); </code> Also your using DDSlider and Magic gallery and both use timthumb.php which can cause problems with the default WordPress media functions. ThemeForest plugins and themes are well known to screw with anything having to do with jQuery even after deactivation. Almost all Themeforest plugins and themes add their own jQuery via script tags. I would suggest first removing your enqueue script or change it not to use it in the admin then use Firebug and find out where the breakpoint point is. Make sure your browsers cache is cleared after you disable any of the plugins for testing. Another thing you can try is disabling the Ajax meta descriptions in the Yoast plugin and see if that makes a difference.
Yoast SEO breaking media upload
wordpress
I've got some code inside functions.php which is designed to execute only when the theme is first activated: <code> if ( is_admin() &amp;&amp; isset($_GET['activated'] ) &amp;&amp; $pagenow == 'themes.php' ) { //this code only runs when the theme is first activated } </code> However, I'm pretty sure this code is not running if the theme is activated outside the normal activation process. For example, if a switch_theme() statement is called from a plugin. In that case, how might I alter my code above to execute on switch_theme()? <code> if ( is_admin() &amp;&amp; isset($_GET['activated'] ) &amp;&amp; $pagenow == 'themes.php') OR (switch_theme_called() ) ) { //this code only runs when the theme is first activated } </code>
Well, instead of using a $_GET parameter you could store a initiate state in your options-table. E.g. <code> $initialized = get_option('mytheme_initialized'); if ( (false === $initialized) && is_admin() && ($pagenow == 'themes.php') ) { //this code only runs when the theme is first activated update_option('mytheme_initialized', true); } </code> Unfortunately the "register_activation"-hook is only available for plugins -> http://core.trac.wordpress.org/ticket/13602
How can I run code in functions.php when switch_theme() is called?
wordpress
i have a stupid situation, where i somehow can't find a solution and would really need some help! So... i'm working on a project, where i have in addition to Post and Pages two Custom post types: Photos and Events. I have created a custom taxonomy named "Tags". This taxonomy is applied to Post, Pages, Photos and Events... so basically you can give everything a Tag and you can chose everywhere from tags, that are being used elsewhere (example: if you give some tags in the Events, then you can later chose the same Tags in Photos). The Idear is to show everywhere related stuff. So if you are on a Event, you will see in the sidebar related news, photos, even page entries...and so on... NOW i want to display in the Photo - section only the tags, that were already used in the Custom post type Photos. Not all of them (there are some tags in Events, that have never been used in photos). So one could chose to see only photos base on a Tag... I don't have any code yet... although i'm not a newbi in wordpress, a this point i don't even know where to start. how can one display a list of tags, that are a custom taxonomy, limited by a custom post type?! Any suggestion would be really nice!
To use the built-in tag functionality with a custom post type, you need to add this argument when registering your post type: <code> 'taxonomies' =&gt; array( 'post_tag' ), </code> So to register a post type events, you'd do (eg): <code> register_post_type( 'events', array( 'show_ui' =&gt; true, 'taxonomies' =&gt; array( 'post_tag' ) // etc ... ) ); </code>
display custom taxonomies limited to custom post type?
wordpress
How can I debug problems with WordPress Cron? I think it will trigger when users go to your site but any errors wont be shown to them, as the jobs are run "asynchronously". So how might I debug errors? I use <code> wp schedule event </code>
You can run WP cron manually by calling: http://example.com/wp-cron.php?doing_cron If you don't want the automatic cron to run while you're debugging, then add this to your <code> /wp-config.php </code> file: <code> define('DISABLE_WP_CRON', true); </code> If you're on a development environment and want to output debug information, calling it manually like that will show you your debug output. Alternatively you can use PHP's built-in error_log function to log message strings to the error log for debugging. You'd need to use this in conjunction with WP_DEBUG settings, as mentioned by Rarst.
How to debug WordPress "Cron" wp_schedule_event
wordpress
My theme is in a folder called "mytheme" and the "Theme Name" in the style.css is "My Theme". From that, I'm guessing that the option "template" in the options table is a reference to the folder, not the "Theme Name". I'm asking because I want to be sure that the value I should pass to switch_theme() is a reference to the foldername mytheme, not the theme name "My Theme" ? <code> switch_theme('mytheme', 'style.css') </code>
You'r right. The template-tag is based on your directory name. Same goes for a child-theme, which has a base theme as parent. Check out the search_theme_directories() function for more information.
Where are the options "template" and "current_theme" derived from
wordpress
I'm successfully adding buttons to the TinyMCE editor in Wordpress, but the problem is they all show up to the right of the Kitchen Sink button and I have so many that I need them to display on a new line. How do I make the buttons wrap to the next line and/or create a new row for my custom buttons? Here is my code: <code> tinymce.create('tinymce.plugins.boxlight', { init : function(ed, url) { ed.addButton('boxlight', { title : 'Add a light content box', image : url+'/images/box-light.png', theme_advanced_buttons3_add : 'boxlight', onclick : function() { ed.selection.setContent('[box_light]' + ed.selection.getContent() + '[/box_light]'); } }); }, createControl : function(n, cm) { return null; }, }); tinymce.PluginManager.add('boxlight', tinymce.plugins.boxlight); </code> That code just adds the buttons to the main TinyMCE toolbar and I can't figure out how to add the buttons to a new toolbar.
I imagine you're also adding a filter <code> mce_buttons </code> to add in the button to, something like.. <code> add_filter( 'mce_buttons', 'add_my_tinymce_buttons' ); function add_my_tinymce_buttons( $items ) { $items[] = 'your-button'; return $items; } </code> Just change the filter to hook onto <code> mce_buttons_2 </code> instead, and the button will appear on the second row , eg.. <code> add_filter( 'mce_buttons_2', 'add_my_tinymce_buttons' ); </code> Hope that helps.. :)
When adding buttons to the tinyMCE editor, how do I make them wrap to the next line and/or display in the "Kitchen Sink" area?
wordpress
I've been using drupal for a few years and it's overkill. I want to pay someone to migrate my content (blog posts and pages) over to wordpress without spending more than is necessary. Is there a specific site such as odesk, elance, guru, rentacoder, etc. that is popular with wordpress programmers and tends to have the best rates? Thanks...
oDesk has lot of WordPress developers that could migrate your site from Drupal to WordPress at low cost. I like oDesk because it takes screen shots every few minutes as the contractor's work on your job. You can monitor their work very effectively, particularly if you understand the work being done. In this case if you don't want any changes to the site, you could easily post this as a fixed price job, which would probably give you the lowest cost. Looking at the numerous other WordPress jobs listed on oDesk is a good way to see how to post your job - a well crafted job post will get you a better result. On a practical note I would suggest you consider selecting a WordPress theme you would like use before posting your migration job on oDesk. Take this chance to update your site and migrate to a solid, well supported WordPress theme which meets your functional and visual requirements. If the theme you select needs to customised in any way to meet your requirements, make sure the developer does this via a child theme, so that you can have easy upgrading of the parent theme.
Which freelance sites are recommended to find WordPress developers/programmers, etc
wordpress
Is it possible to make a template for all posts in a custom post type? For example I would like to be able to change an adsense ad or some other element on every post by simply editing a custom template. I have been experimenting with templates that are pretty static, but I am stumped on which one to copy/edit for the posts.
Yes it possible, take a look at Template Hierarchy codex entry to get a better idea but the simple answer is to create a template for all of you custom post type posts create a template and name it <code> single-{post_type}.php </code> so if your post type is named dogs then your template file should be named <code> single-dogs.php </code> and automatically this template file will be used to display all of the dogs post type posts and once you edit that file it will effect all of the posts of that type.
Troubles with making a custom template for posts
wordpress
http://core.trac.wordpress.org/browser/trunk/wp-includes/formatting.php#L2239 I'm confused about when should either of them be used. Assuming I have this URL: <code> http://site.com/?getsomejavascript=1 </code> , which is dynamically generated javascript: if I include the script with <code> esc_url(add_query_arg('apples', 420)) </code> , I get <code> http://site.com/?getsomejavascript=1&amp;#038;apples=420 </code> and it breaks because of those <code> #038; </code> references if I use <code> esc_url_raw(add_query_arg('apples', 420)) </code> I get the correct URL: <code> http://site.com/?getsomejavascript=1&amp;apples=420 </code> but in the documentation I find out that esc_url_raw should only be used to escape URLs inserted in the database...
From the Codex entry for Data Validation: URLs : <code> esc_url( $url, (array) $protocols = null ) </code> (since 2.8) Always use esc_url when sanitizing URLs (in text nodes, attribute nodes or anywhere else). Rejects URLs that do not have one of the provided whitelisted protocols (defaulting to http, https, ftp, ftps, mailto, news, irc, gopher, nntp, feed, and telnet), eliminates invalid characters, and removes dangerous characters. Deprecated since 3.0: clean_url() This function encodes characters as HTML entities: use it when generating an (X)HTML or XML document. Encodes ampersands (&amp;) and single quotes (') as numeric entity references (&#038, &#039). <code> esc_url_raw( $url, (array) $protocols = null ) </code> (since 2.8) For inserting an URL in the database. This function does not encode characters as HTML entities: use it when storing a URL or in other cases where you need the non-encoded URL. This functionality can be replicated in the old clean_url function by setting $context to db. So, the primary differences appear to be: <code> esc_url() </code> encodes HTML entities, while <code> esc_url_raw() </code> does not <code> esc_url() </code> is intended for output , while <code> esc_url_raw() </code> is intended for database storage EDIT: Since you are either hard-coding (or saving/storing separately) the actual URL from the query string, and then appending the query string via <code> [add_query_arg()][2] </code> , might it be better to escape your appended query string via <code> esc_js() </code> , rather than <code> esc_url() </code> ? For example: <code> add_query_arg( esc_js( 'apples' ), esc_js( '420' ), $myurl ) </code>
Difference between esc_url() and esc_url_raw()
wordpress
Hi when i try to <code> get_terms(); </code> in theme options via this code <code> $catalogs_terms = get_terms( 'catalogs' ); $mycatalogs = array( -1 =&gt; 'Select a catalog' ); if ( $catalogs_terms ) { foreach ( $catalogs_terms as $catalog_term ) { $mycatalogs[$catalog_term-&gt;term_id] = $catalog_term-&gt;name; } } </code> return empty but this code is working fine every where in pages etc. when i try to <code> print_r( $catalogs_terms ) </code> output i am getting errors <code> Array ( [errors] =&gt; Array ( [invalid_taxonomy] =&gt; Array ( [0] =&gt; Invalid Taxonomy ) ) [error_data] =&gt; Array ( ) ) </code> i don't understand where am i wrong? my function for register taxonomy <code> add_action( 'init', 'my_taxonomies', 0 ); function my_taxonomies() { // Add new taxonomy, make it hierarchical (like categories) $labels = array( 'name' =&gt; _x( 'Catalogs', 'taxonomy general name' ), 'singular_name' =&gt; _x( 'Catalog', 'taxonomy singular name' ), 'search_items' =&gt; __( 'Search Catalogs', 'mytextdomain' ), 'all_items' =&gt; __( 'All Catalogs', 'mytextdomain' ), 'parent_item' =&gt; __( 'Parent Catalog', 'mytextdomain' ), 'parent_item_colon' =&gt; __( 'Parent Catalog:', 'mytextdomain' ), 'edit_item' =&gt; __( 'Edit Catalog', 'mytextdomain' ), 'update_item' =&gt; __( 'Update Catalog', 'mytextdomain' ), 'add_new_item' =&gt; __( 'Add New Catalog', 'mytextdomain' ), 'new_item_name' =&gt; __( 'New Catalog Name', 'mytextdomain' ), 'menu_name' =&gt; __( 'Catalogs', 'mytextdomain' ), ); // register catalogs hierarchical (like categories) register_taxonomy( 'catalogs', array( 'news' ), array( 'hierarchical' =&gt; true, 'labels' =&gt; $labels, 'show_ui' =&gt; true, 'public' =&gt; true, 'query_var' =&gt; true, 'rewrite' =&gt; array( 'slug' =&gt; 'catalogs' ) ) ); } </code>
As i was mentioning before, it's a case of your term fetching occuring before the taxonomy has been registered. The init action occurs after the theme's functions file has been included, so if you're looking for terms directly in the functions file, you're doing so before they've actually been registered. Here's a portion of the code from <code> wp-settings.php </code> that includes the theme functions and does the <code> init </code> action. <code> // Load the functions for the active theme, for both parent and child theme if applicable. if ( TEMPLATEPATH !== STYLESHEETPATH &amp;&amp; file_exists( STYLESHEETPATH . '/functions.php' ) ) include( STYLESHEETPATH . '/functions.php' ); if ( file_exists( TEMPLATEPATH . '/functions.php' ) ) include( TEMPLATEPATH . '/functions.php' ); do_action( 'after_setup_theme' ); // Load any template functions the theme supports. require_if_theme_supports( 'post-thumbnails', ABSPATH . WPINC . '/post-thumbnail-template.php' ); register_shutdown_function( 'shutdown_action_hook' ); // Set up current user. $wp-&gt;init(); /** * Most of WP is loaded at this stage, and the user is authenticated. WP continues * to load on the init hook that follows (e.g. widgets), and many plugins instantiate * themselves on it for all sorts of reasons (e.g. they need a user, a taxonomy, etc.). * * If you wish to plug an action once WP is loaded, use the wp_loaded hook below. */ do_action( 'init' ); </code> As you can see the <code> init </code> action doesn't fire until after the theme functions file is included, therefore any term retrieval must occur after init. I can't really advise you any further though because you've only shown me a portion of your code, so i've not much of an idea of the context you're trying to use the term function in, but it certainly can't be called directly in the functions file(outside a callback hooked onto a specific action/filter because the code will run to soon). Hopefully the above illustrates the problem enough for you.. :) Additional note: This function is missing a var from the global statement(you'd see PHP notices if you had debug turned on). <code> function news_updated_messages( $messages ) { global $post; </code> That should read.. <code> function news_updated_messages( $messages ) { global $post, $post_ID; </code> .. because code inside that function references that var, but the variable doesn't have scope inside the function, my above suggested change will fix that. Follow-up #1 When creating a plugin or theme page, you first have to setup/register that page, this is typically done like so.. <code> add_action('admin_menu', 'my_theme_menu'); function my_theme_menu() { add_theme_page( 'Theme Settings', 'Theme Settings', 'manage_options', 'my-unique-identifier', 'my_theme_settings' ); } function my_theme_settings() { // Code to display/handle theme options would be here // You get_terms() call should work inside this function just fine } </code> If the theme page is created differently, specific to the premium theme you're using then i can't really help as they tend to use a framework that is entirely different to regular WordPress themes.
get_terms return errors
wordpress
We want the users to re-order the posts on a page similar to pagination but I can't find anything anywhere! It would be great to create a link to a url similar to <code> .../page/2/title/ </code> , <code> title </code> being the new order. Is this even possible?! Found several pagination scripts but none offer this option...
Adding a rewrite rule with an order part is very easy, if you do it for one site. It would be harder if you want to create a generic solution that works for all installations with all kinds of permalink structures and custom taxonomies. This short example works on a basic install of WordPress 3.1, with no extra custom taxonomies. I use the <code> orderby </code> prefix to prevent conflicts with existing post names: <code> add_action( 'init', 'wpse13483_init' ); function wpse13483_init() { add_rewrite_rule( 'category/(.+?)/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$', 'index.php?category_name=$matches[1]&amp;paged=$matches[4]&amp;orderby=$matches[2]', 'top' ); add_rewrite_rule( 'tag/([^/]+)/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$', 'index.php?tag=$matches[1]&amp;paged=$matches[4]&amp;orderby=$matches[2]', 'top' ); add_rewrite_rule( 'type/([^/]+)/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$', 'index.php?post_format=$matches[1]&amp;paged=$matches[4]&amp;orderby=$matches[2]', 'top' ); add_rewrite_rule( 'author/([^/]+)/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$', 'index.php?author_name=$matches[1]&amp;paged=$matches[4]&amp;orderby=$matches[2]', 'top' ); add_rewrite_rule( '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$', 'index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;day=$matches[3]&amp;paged=$matches[6]&amp;orderby=$matches[4]', 'top' ); add_rewrite_rule( '([0-9]{4})/([0-9]{1,2})/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$', 'index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;paged=$matches[5]&amp;orderby=$matches[3]', 'top' ); add_rewrite_rule( '([0-9]{4})/orderby/([^/]+)(/page/?([0-9]{1,}))?/?$', 'index.php?year=$matches[1]&amp;paged=$matches[4]&amp;orderby=$matches[2]', 'top' ); } </code>
Sorting archive pages with "pretty" URLs?
wordpress
How can I get all subcategories from a certain category?
Yes, you can use get_categories() using <code> 'child_of' </code> attribute. for example all sub categories of category with the ID of 17: <code> $args = array('child_of' =&gt; 17); $categories = get_categories( $args ); foreach($categories as $category) { echo '&lt;p&gt;Category: &lt;a href="' . get_category_link( $category-&gt;term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category-&gt;name ) . '" ' . '&gt;' . $category-&gt;name.'&lt;/a&gt; &lt;/p&gt; '; echo '&lt;p&gt; Description:'. $category-&gt;description . '&lt;/p&gt;'; echo '&lt;p&gt; Post Count: '. $category-&gt;count . '&lt;/p&gt;'; } </code> this will get all categories that are descendants (i.e. children &amp; grandchildren) . if you want to display only categories that are direct descendants (i.e. children only) the you can use <code> 'parent' </code> attribute. <code> $args = array('parent' =&gt; 17); $categories = get_categories( $args ); foreach($categories as $category) { echo '&lt;p&gt;Category: &lt;a href="' . get_category_link( $category-&gt;term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category-&gt;name ) . '" ' . '&gt;' . $category-&gt;name.'&lt;/a&gt; &lt;/p&gt; '; echo '&lt;p&gt; Description:'. $category-&gt;description . '&lt;/p&gt;'; echo '&lt;p&gt; Post Count: '. $category-&gt;count . '&lt;/p&gt;'; } </code>
List all subcategories from category
wordpress
i am creating a frontend dashboard where i need to show all the post by the current user. So i need to show posts with all post status. Mainly published, trashed and the pending. I am now using simple query post but it is returning only the published posts as expected. <code> $query = array( 'post_type' =&gt; 'my-post-type', 'post_author' =&gt; $current_user-&gt;ID ); query_posts($query); </code> Can anyone help what i need do extra?
You can use the post_status parameter: <code> * 'publish' - a published post or page * 'pending' - post is pending review * 'draft' - a post in draft status * 'auto-draft' - a newly created post, with no content * 'future' - a post to publish in the future * 'private' - not visible to users who are not logged in * 'inherit' - a revision. see get_children. * 'trash' - post is in trashbin. added with Version 2.9. </code> I'm not sure that it accepts 'any' so use and array with all of the types you want: <code> $query = array( 'post_type' =&gt; 'my-post-type', 'post_author' =&gt; $current_user-&gt;ID, 'post_status' =&gt; array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash') ); query_posts($query); </code>
How to Get All Posts with any post status?
wordpress
Is it possible to specify two usergroups (e.g. admins and editors) into the admin menu capability field ? I tried the following but it doesnt work: <code> add_submenu_page( 'my-top-level-handle', 'Page title', 'Sub-menu title', array('administrator', 'editor'), 'my-submenu-handle', 'my_magic_function' ); </code> error message: Warning: Illegal offset type in isset or empty in C:\wamp\www\wordpress\wp-includes\capabilities.php on line 712
Capability parameter of add_submenu_page() function can only take a single capability, so if you are using the built in roles you can select a capability fro the long list that both administrators and editors have any og these: moderate_comments manage_categories manage_links unfiltered_html edit_others_posts edit_pages edit_others_pages edit_published_pages publish_pages delete_pages delete_others_pages delete_published_pages delete_others_posts delete_private_posts edit_private_posts read_private_posts delete_private_pages edit_private_pages read_private_pages
Menu capability in Wordpress
wordpress
I am new to WordPress and I've seen this term passed around.
"Shortcode" is a user friendly way of inserting various WordPress plugins/scripts into a page without having to know a lot of fancy HTML/JavaScript/PHP in order to make it happen. Take, for example, embedding an mp3 file into a post on a hosted WordPress site. Instead of having to setup the proper code for a flash player or fiddle with some fancy JavaScript, you can use the following shortcode in the editor. You don't even switch to HTML mode... <code> [audio: http://www.pathtomyaudio.com/song.mp3] </code> ...and WordPress does the rest for you. You'll find a lot of plugins for WordPress (such as Contact Form 7 and others) use this convention.
What is a short code?
wordpress
I am using the following code to display a list of posts within a category, but I want to display the title in it's own h2 tag above the list. <code> &lt;ul class="subcats-list"&gt; &lt;?php $weightloss = new WP_Query(); $weightloss-&gt;query('showposts=5&amp;include=4'); while ($weightloss-&gt;have_posts()) : $weightloss-&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> EDIT: So I tried using <code> single_cat_title </code> , however, the title is coming up for the parent category for all the sub category divs. Here's an example of a div that I am replicating multiple times, where the query is pulling posts from different sub categories. I would like the title for each sub category above the posts. I realize it's not working because I'm returning the parent category with that function, I'm just can't figure out the php... <code> &lt;ul class="subcats-list"&gt; &lt;h2 class="subcats-title"&gt;&lt;?php single_cat_title(); ?&gt;&lt;/h2&gt; &lt;?php $weightloss = new WP_Query(); $weightloss-&gt;query('showposts=5&amp;cat=4'); while ($weightloss-&gt;have_posts()) : $weightloss-&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>
Since you already have the category ID (you use it in your call to <code> WP_Query::query() </code> ), you can just use that to request the category name. <code> get_cat_name( $cat_id ) </code> will do exactly that. It uses <code> get_category( $cat_id ) </code> in the background, which returns the full category object, which can be useful if you want to show more information about the category.
How do I get the title of a category in a custom loop?
wordpress
I'm developing a WordPress theme that allows users to toggle the visibility of the sidebars using Javascript in the same way that wikis allow users to show or hide a table of contents. When a user clicks the link to hide a sidebar I have a toggle() javascript toggle function that sets the visibility of the sidebar to "none" and also sets a document cookie so that the next time the users visits that page, the sidebar will remember the last toggle state. I have another javascript function setToggleFromCookie() that gets the cookie and sets the visibility based on that cookie. This all works except: If a sidebar is hidden (i.e. visibility of the sidebar div = "none" and the document cookie hidesidebar = 1), when the page is loaded, the sidebar appears briefly before the javascript overrides the visibility = "block" with visibility = "none." I have put setToggleFromCookie() in jQuery(document).ready(function(), but the page still seems to load and display the sidebar BEFORE setToggleFromCookie() jumps in to hide it...
While annoying, your plugin is functioning properly. The page completely renders itself first, showing the sidebar, and then the JavaScript code activates to hide the sidebar. The fix for this is to have your PHP code check/grab the user's cookie and set the display's sidebar status accordingly. That way when the page renders it will be set to none initially, and then any future image toggles can hide/show the sidebar dynamically. When the page is loaded again for whatever reason, the same PHP loading code will run again, and set the initial state of the sidebar accordingly, without any need to "follow up" after the initial page load to show/hide the sidebar. Hopefully this makes sense. If you need some specifics, you might try updating your question with the code involved.
Toggle Sidebar Display
wordpress
I'm creating a series of pages with iFrames embedded in them, but it seems the only way to do this within Wordpress (i.e. using the templating system) is to create pages in the admin end and then create individual templates for each of those pages. Is it possible to hide those pages from the admin without a plugin? I see no need for the client to see those pages when they can't edit anything in them. Thanks, osu
you can use <code> parse_query </code> filter hook to exclude your pages using post__not_in attribute <code> add_filter( 'parse_query', 'exclude_pages_from_admin' ); function exclude_pages_from_admin($query) { global $pagenow,$post_type; if (is_admin() &amp;&amp; $pagenow=='edit.php' &amp;&amp; $post_type =='page') { $query-&gt;query_vars['post__not_in'] = array('21','22','23'); } } </code> this will exclude pages with the ids of 21,22,23 and to make sure this pages will not be included on the front end using wp_list_pages you can use wp_list_pages_excludes filter hook: <code> add_filter('wp_list_pages_excludes', 'exclude_from_wp_list_pages'); function exclude_from_wp_list_pages($exclude_array){ $exclude_array = $exclude_array + array('21','22','23'); return $exclude_array; } </code>
Hide a page in the admin end without a plugin?
wordpress
I've got a plugin that I ship with my theme whose function is to jumpstart the process of launching site so that its optimized for the theme. It has all my default pages, plugins, settings, etc... For example, I'm using the following script to remove the default blogroll links... <code> $arr_args = array( 'hide_invisible' =&gt; 0 ); $arr_links = get_bookmarks( $arr_args ); foreach($arr_links as $obj_link){wp_delete_link($obj_link-&gt;link_id);} </code> However, now I want to create replacement links to go in this listing. I want my social media links to go here. Basically, I want to create a list of 4-5 links (YouTube, Facebook, Twitter, LinkedIn, etc) Once I know how to insert bookmark links via script, I can place the css bits in my theme that I need to effect the look. Any ideas or examples for doing this?
Use wp_insert_link() .
Script to replace default blogroll with links to my social media URLs
wordpress
pretty simple. I'm creating a plugin and I want to dynamically insert some text that will change every hour into the line that is directly below the title of a post (So filters are no good). It's the <code> &lt;div class="entry-meta"&gt; </code> . The <code> &lt;div class="entry-utility"&gt; </code> at the bottom of the post would be good too. I can't seem to find a hook for this and I'm guessing there is none. Right now the solution I have is to hook into "the_content" and place it as a footer, but it looks reaaally bad because it's a small piece of text with an entire line to itself. It would look considerably better if I could insert it into those lines mentioned.
The lines you mention are most likely part of your theme. You will need to either: figure out which functions/templates output them and if they have hooks to use; edit theme (create child theme) to add your own function to output what you want.
Hook for plugin to insert into entry-meta
wordpress
I'm developing a site where better is very quickly becoming the enemy of the good. I would like to make updating as simple for the client as possible by enabling them to populate boilerplate and images text using a shortcode. However, there is one word within the boilerplate text which needs to be unique for each page and must be added by the client. I was thinking of using a specific custom field key and value, as a way of capturing the unique information. Is it possible and reasonable to use custom fields for this purpose within the shortcode? I'm having trouble thinking through the syntax. Is there a better way to do this?
Not sure I understand your specifics, add details if I am off. I assume: Your shortcode inside post's content. You have custom field in that post with value you want. In this case declare in your shortcode function <code> global $post; </code> and use <code> $post-&gt;ID </code> to retrieve custom field.
Can data from a Custom Field data be used by a shortcode on a per page/post basis?
wordpress
It is highly recommended practice (that I completely agree with) to develop with <code> WP_DEBUG </code> enabled. However it is merely inconvenient to see not yet fixed warnings in pages, but in Ajax responses they ruin response completely. I am just starting with Ajax in WP, is there some appropriate hook to suppress errors for Ajax responses only? PS fix everything is not viable option at moment, because it is extremely extensive and complex environment :)
In <code> wp-config.php </code> : <code> if ( defined( 'DOING_AJAX' ) &amp;&amp; DOING_AJAX ) define( 'WP_DEBUG', false ); else define( 'WP_DEBUG', true ); </code>
How to override WP_DEBUG for Ajax responses?
wordpress
I have custom post type called <code> paintings </code> and it has a custom taxonomy called <code> paintings_category </code> . Currently I have this situation: <code> example.com/paintings/ </code> A page using <code> page-paintings.php </code> <code> example.com/paintings_category/landscape/ </code> Lists all <code> landscape </code> items in <code> taxonomy.php </code> <code> example.com/paintings/landscape/painting-title/ </code> Displays single painting post types, eg. <code> single-paintings.php </code> If I try changing the slug as below, I get a 404 error on: <code> example.com/paintings/landscape/painting-title/ </code> <code> register_taxonomy( 'paintings_category', array('paintings'), array( 'hierarchical' =&gt; true, 'label' =&gt; 'Categories', 'singular_label' =&gt; 'Category', 'rewrite' =&gt; array( 'slug' =&gt; 'paintings' ) ) ); </code> I'd like behaviour to be: <code> example.com/paintings/ </code> ideally list <code> paintings_category </code> as links <code> example.com/paintings/landscape/ </code> lists all items of <code> landscape </code> taxonomy <code> example.com/paintings/landscape/painting-title/ </code> displays single item Any thoughts on how I can achieve this? I tried adding <code> paintings </code> as a parent of <code> landscape </code> category in <code> paintings_category </code> but this still leaves me with a 404 on the single.
Well, it turns out it is indeed possible : ) I eventually found most of the answer in this post: stackexchange-url ("Custom post types, taxonomies, and permalinks.") Then I got <code> single-paintings.php </code> to paginate within selected taxonomy with this plugin: Ambrosite Next/Previous Post Link Plus (which looks like it could be dropped into <code> functions.php </code> if you wanted to do it without plugins). Hope this helps someone!
custom post type and custom taxonomy url conflict
wordpress
I want to keep a check if the user has a particular password, so I have been trying it with <code> wp_check_password </code> but the account for which it is checked gets logged out and can't login again till there is a call of <code> wp_check_password </code> in the code. Digging into the code, I found out that it sets the password by using the new hash. and moreover if I am using <code> wp_check_password( 'hello', md5('hello'), 1 ); </code> , it doesn't even check what is inside the database and returns true. Isn't that a bug? Any ideas how can I check the user's password?
Your example works correctly. You are checking if password <code> hello </code> matches hashed <code> hello </code> - which it naturally does. Hadn't thought it through. Your example causes following issue: You check if <code> hello </code> matches md5 of <code> hello </code> (instead of hash from user's profile). It does and then WP thinks this is correct, but outdated md5 hash - that must be updated. It re-hashes <code> hello </code> and updates user with it, locking him out (since his password is now <code> hello </code> instead of whatever it was before). See <code> wp_authenticate_username_password() </code> function for extensive example, but basic idea is: <code> $userdata = get_user_by('login', $username); $result = wp_check_password($password, $userdata-&gt;user_pass, $userdata-&gt;ID); </code>
Check the password of a user
wordpress
I recently updated my site to 3.1 and now the frontend of the site will not load. The weird thing is the admin section does load and is some what functional (sometimes the pages go blank and I have to reload, and sometimes reloads don't work). I had to install and activate a maintenance plugin while I try to trouble shoot the issue. I tried to recall anything that I mightve done to cause this and can't see what caused this. I notice that if I visit my domain, with my maintenance plugin activated, it will show the maintenance message, but if the maintenance plugin is not activate this site loads a blank page. In in the general settings, I changed the "wordpress address" to see if that would somehow load the site by putting the direct url location of the site, but that didn't work. With the actual domain in both fields (wordpress address and site address), the admin works but the frontend doesn't load except in maintenance mode. I would appreciate some advice with this. I just went in to do a little maintenance and I spending 4-5 hours on this problem. The link to my site is here Is this a common problem on updates? I hope this is fixable, if not is it possible to downgrade wp to the previous version (if its necessary)? Thanks in advance for any help with this.
I've had this same issue a couple of times now. Generally I've resolved it by manually downloading 3.1 and replacing the files in the directory. After the transfer is complete I was able to log in and update my database with the drop-down it presented.
Site DOES NOT LOAD after 3.1 update
wordpress
On editing the attachments of a post whith at least one attachment previously uploaded, how do I remove the From computer tab and redirect to the Gallery tab? This is my current code: <code> add_filter('media_upload_tabs','remove_medialibrary_tabs', 99); function remove_medialibrary_tabs($tabs) { if ($post_id = (isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : false)) { if (count(get_posts("post_type=attachment&amp;post_parent={$post_id}"))&gt;0) { // MY QUESTION } } unset($tabs['type_url']); unset($tabs['library']); return $tabs; } </code>
To remove the From Computer tab header , you unset the <code> type </code> key from that array . However, this will (confusingly) not remove the tab content , and because this is the default tab it will show it even if the tab header for it is gone. To change the default tab you must hook into the <code> media_upload_default_tab </code> filter . This gets called in multiple places, I did not research which one is called in which circumstances, so I moved the check for attachments to a separate function and rewrote your code like this: <code> add_filter('media_upload_tabs','wpse13567_media_upload_tabs', 99); function wpse13567_media_upload_tabs( $tabs ) { if ( wpse13567_post_has_attachments() ) { unset( $tabs['type'] ); } unset( $tabs['type_url'] ); unset( $tabs['library'] ); return $tabs; } add_filter( 'media_upload_default_tab', 'wpse13567_media_upload_default_tab' ); function wpse13567_media_upload_default_tab( $tab ) { if ( wpse13567_post_has_attachments() ) { return 'gallery'; } return $tab; } function wpse13567_post_has_attachments() { static $post_has_attachments = null; if ( null === $post_has_attachments &amp;&amp; $post_id = (isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : false) ) { $post_has_attachments = count(get_posts("post_type=attachment&amp;post_parent={$post_id}"))&gt;0; } return $post_has_attachments; } </code>
Remove "From computer" media tab for posts with existing attachments?
wordpress
In the course of converting a blog from Blogger to WP and running a script to grab hot-linked images for hosting, I ended up with some funky images names like <code> act%252Bapandas-210x290.png </code> These image names prevent the image from displaying on a webpage, due the url encoding ending up in the file name itself (don't ask!). I renamed them on the file server, no prob, but the names are also in the attachment metadata for each post. How can I remove the "%" from all the image references in the wp_postmeta table? *Most of them occur in serialized arrays in meta_values for the meta_keys of _wp_attachment_metadata*. I've had no luck finding a plugin, and am unsure how to institute a pure SQL/PHP solution. Here is an example of a serialized array entry (further gummed up by the Smush.it plugin, ugh): <code> a:7:{s:5:"width";s:3:"210";s:6:"height";s:3:"339";s:14:"hwstring_small";s:22:"height='96' width='59'";s:4:"file";s:27:"2011/02/act%252Bapandas.png";s:5:"sizes";a:6:{s:9:"thumbnail";a:4:{s:4:"file";s:27:"act%252Bapandas-210x290.png";s:5:"width";s:3:"210";s:6:"height";s:3:"290";s:10:"wp_smushit";s:271:"Smush.it error: Could not get the image while processing http://new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-210x290.png (/home/xxxxxxxxx/new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-210x290.png)";}s:14:"soft-thumbnail";a:4:{s:4:"file";s:27:"act%252Bapandas-179x290.png";s:5:"width";s:3:"179";s:6:"height";s:3:"290";s:10:"wp_smushit";s:271:"Smush.it error: Could not get the image while processing http://new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-179x290.png (/home/xxxxxxxxx/new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-179x290.png)";}s:14:"mini-thumbnail";a:4:{s:4:"file";s:25:"act%252Bapandas-60x60.png";s:5:"width";s:2:"60";s:6:"height";s:2:"60";s:10:"wp_smushit";s:267:"Smush.it error: Could not get the image while processing http://new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-60x60.png (/home/xxxxxxxxx/new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-60x60.png)";}s:5:"slide";a:4:{s:4:"file";s:27:"act%252Bapandas-210x290.png";s:5:"width";s:3:"210";s:6:"height";s:3:"290";s:10:"wp_smushit";s:271:"Smush.it error: Could not get the image while processing http://new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-210x290.png (/home/xxxxxxxxx/new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-210x290.png)";}s:10:"soft-slide";a:4:{s:4:"file";s:27:"act%252Bapandas-179x290.png";s:5:"width";s:3:"179";s:6:"height";s:3:"290";s:10:"wp_smushit";s:271:"Smush.it error: Could not get the image while processing http://new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-179x290.png (/home/xxxxxxxxx/new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-179x290.png)";}s:10:"mini-slide";a:4:{s:4:"file";s:27:"act%252Bapandas-210x145.png";s:5:"width";s:3:"210";s:6:"height";s:3:"145";s:10:"wp_smushit";s:271:"Smush.it error: Could not get the image while processing http://new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-210x145.png (/home/xxxxxxxxx/new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-210x145.png)";}}s:10:"image_meta";a:10:{s:8:"aperture";s:1:"0";s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";s:1:"0";s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:1:"0";s:13:"shutter_speed";s:1:"0";s:5:"title";s:0:"";}s:10:"wp_smushit";s:255:"Smush.it error: Could not get the image while processing http://new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas.png (/home/xxxxxxxxx/new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas.png)";} </code> The issue is changing or removing the "%" character AND updating the array so it reports the correct number of characters (ie the s:13 would indicate yoursite.com is 13 char[]) I'm also open to using a php solution! Whatever can help me fix this mess. FINAL SOLUTION See my answer below.
General idea would be to loop through all attachments to retrieve, modify and write back their meta. Something like this (test thoroughly before using on anything important): <code> $posts = get_posts(array( 'post_type' =&gt; 'attachment', 'numberposts' =&gt; -1, )); foreach( $posts as $post ) { // retrieve data, unserialized automatically $meta = get_post_meta($post-&gt;ID,'_wp_attachment_metadata', true); // do stuff with $meta array // write it back update_post_meta($post-&gt;ID, '_wp_attachment_metadata', $meta); } </code>
Remove “%” from strings in serialized arrays in wp_postmeta
wordpress
Processing the following form in the admin area, but the database constantly returning an empty cell where the info should be. Help!! <code> &lt;form action="options.php" method="post"&gt; &lt;input type="hidden" value="admin_bar" name="option_page"&gt;&lt;input type="hidden" value="update" name="action"&gt;&lt;input type="hidden" value="fd5754f034" name="_wpnonce" id="_wpnonce"&gt;&lt;input type="hidden" value="/accessibilitysite/wp-admin/options-general.php?page=admin_bar&amp;amp;settings-updated=true" name="_wp_http_referer"&gt; &lt;table class="form-table"&gt; &lt;tbody&gt;&lt;tr valign="top"&gt;&lt;th scope="row"&gt;Admin Toggle&lt;/th&gt; &lt;td&gt;&lt;input type="checkbox" value="admin_bar_toggle" name="admin_bar_[admin_bar_toggle]"&gt;&lt;p&gt;Turn Admin Bar On ?&lt;/p&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;p class="submit"&gt; &lt;input type="submit" value="Save Changes" class="button-primary"&gt; &lt;/p&gt; &lt;/form&gt; </code>
<code> options.php </code> does not automatically save in the database anything that you post to it. You must also tell the page which options it should look for in the posted data. I see that you have set <code> option_page </code> to <code> admin_bar </code> , which is half of the solution. The other half is to add the option names to the whitelist. You are using the form element name <code> admin_bar_[admin_bar_toggle] </code> which will show up as <code> $_POST['admin_bar_']['admin_bar_toggle'] </code> when the form is submitted with that box checked. This filter should tell <code> options.php </code> that you want this option saved: <code> function admin_page_whitelist_options( $whitelist_options ) { $whitelist_options['admin_bar'] = array( 'admin_bar_' ); return $whitelist_options; } add_filter( 'whitelist_options', 'admin_page_whitelist_options' ); </code> After that, you should find what you are looking for in the option named <code> admin_bar_ </code> .
my checkbox is not saving it's value
wordpress
I want to create an affiliate system on WordPress . What I mean is when "Member A" invite other to join (ex. "Member B") by using the ?referralId=MemberA querystring, then Member A get points or credits, and when Member B invite Member C, then Member B get points. Is there any WordPress plugin that can do that ? I already tried Affiliate Pro Plus (http://wordpress.org/extend/plugins/affiliate-pro-plus/) but It's not work as expected. When I try to register Member B using Member A's referral, Member B does not count as Member A downline.
Don't know about a plugin but this can be done easily with just two hooks and callback functions: First you add the refferer field to the registration form using <code> register_form </code> hook: <code> add_action('register_form','show_reff_field'); function show_reff_field(){ ?&gt; &lt;input id="ref" type="text" tabindex="20" size="25" value= "&lt;?php if (isset($_GET['ref'])){echo $_GET['ref'];} ?&gt;" name="ref" readonly="readonly"/&gt; &lt;?php } </code> Then you just need to save it using <code> user_register </code> hook <code> add_action('user_register', 'register_refferal'); function register_refferal($user_id) { $userdata = array(); $userdata['ID'] = $user_id; wp_update_user($userdata); $userdata['ref'] = $_POST['ref']; if (isset($userdata['ref']) &amp;&amp; !empty($userdata['ref']) &amp;&amp; $userdata['ref'] != ""){ //get reffering user id by his login $refuser = get_user_by('login',$userdata['ref']); //get current refferial credit that user has $current_ref_credit = get_user_meta($refuser-&gt;ID, 'ref_credit', true); //add credit for the newly created user $current_ref_credit[] = $user_id; //save the changes update_user_meta( $refuser-&gt;ID, 'ref_credit', $current_ref_credit); } } </code> So all that is left to do is to let your users share there referral link: <code> http://example.com/wp-login.php?action=register&amp;ref=my_login_name </code> So if my user name was "bainternet" then my referral link would be: <code> http://example.com/wp-login.php?action=register&amp;ref=bainternet </code> and to see how many members are in a users downline here is a simple function which accepts a user ID and returns an array of user ids which he has reffered: <code> function get_user_downline($user_id){ return $current_ref_credit = get_user_meta($user_id, 'ref_credit', true); } </code> and its usage is simple: <code> // to echo count of how many user with ID of 24 as reffered: echo count(get_user_downline(24)); // to list the users user with ID of 24 as reffered: &lt;ul&gt; &lt;?php $reffed = get_users(array('orderby' =&gt; 'registered', 'include' =&gt; get_user_downline(24)); foreach ($blogusers as $user) { echo '&lt;li&gt;' . $user-&gt;display_name . '&lt;/li&gt;'; } ?&gt; &lt;/ul&gt; </code> So just copy all of this code and you have a plugin for referral system
WordPress plugin for affiliate referral system
wordpress
I have a standard Wordpress loop displaying items: <code> $loop = new WP_Query( array( 'post_type' =&gt; 'images', 'orderby' =&gt; 'menu_order', ) ); while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); /* loop code, HTML mostly, a few if statements, nothing special */ endwhile; </code> Now I want to display CERTAIN data from meta boxes and here comes the trouble. the_meta() works just fine, but get_post_meta() doesn't work at all. Why is this happening? Any fixes? I need to do something like get_post_meta($post-> ID, 'metabox_field', true). Any ideas? [update] Alright. More details. I have a custom post type called "images". Each image item has it's own metabox with a few fields inside, let's call them image_date, image_author, copyrights. I want to display image author from field called image_author, so: <code> &lt;?php $author = get_post_meta($post-&gt;ID, 'image_author', true); echo $author; ?&gt; </code> The problem is it works ONLY when I open SINGLE image (single-image.php), but doesn't in loop (and I want to display this data for each item in loop also). The_meta() works in both places if it changes something. My loop looks exactly as above. I guess that's all :)
get_post_meta() function works In and Outside of the loop and you saying that you do see it working on a single image " but doesn't in loop " means that you probably did not add the code to the right loop. To be clear It works with all posts types.
Metadata in loops
wordpress
I've been working with widgets a lot lately and have amassed a ton of widgets in the inactive widgets collection. Can someone share a script or plugin that will remove all inactive widgets from the site?
something like: <code> $widgets = get_option('sidebars_widgets'); $widgets['wp_inactive_widgets'] = array(); update_option('sidebars_widgets', $widgets); </code>
Script to remove all inactive widgets?
wordpress
I randomly get high spikes in CPU and Memory. I have deactivated nearly all plugins trying to find the culprit. I have been turning on a few at a time then waiting 30 minutes to see how if the server says it is okay. Which it always does. I didn't touch it for 3 hours tonight and when I returned I realized that my VPS randomly spiked at around 8PM and 9PM. But from 6PM-8PM no issues and from 930PM-1230AM no problems. It says my issue is with index.php. This randomly started on the 26th. No new plugins, no script change, no difference at all. How do I figure out what the issue is? More Info: I have two wordpress installations on my VPS. One of which is my main site that me and about 3 other people write on and the other is kind of like a picture site where you submit pictures and I approve them and they get posted. I have about 330 people on that site. The subdomain (picture site) is the one I am having issues with. It is not the theme index file that is causing the problem but the WP index file. Between the two websites I get about 500k views a month (more on the main site than the picture site) Server info: Disk Space: 100gb Memory: 2GB Burst: 2GB Bandwidth: 1.5tb OS: CentOS 5.5 with Cpanel IP: 2 Proccessor info: 8 proccessors GenuineIntel Intel Core i7 CPU 870 @29.93 GHz Speed: 2933.46 MHz Cache: 8192kb Plugins (Currently activated) Advanced Random Posts, bbpress integration, Custom Post Templates, GD Custom Posts and Taxonomies Tools, GD Star Rating, Gravity Forms, Members, Ultimate Category Excluder, Wordpress.com Stats, WP-Paginate, WP-PostRatings, WP-PostViews, On that note, all of these and others were turned on and worked just fine. Then all of a sudden it went to heck. All plugins are updated and I have the most recent wordpress.
I think I found what the problem was. WP-Postviews. I deactivated the plugin and removed all code from it on the site and now everything is running smoothly (at least for the last 3 hours).
High CPU & Memory Spikes?
wordpress
Hey all, I'm using Jquery UI tabs with the WordPress Post Tabs plugin and it works like a charm. However, I'd like to auto disable or hide tabs that do not have any data. I've worked with Jquery quite a bit but I'm lost in this mess. Any help would be appreciated. Thanks! Jquery Tabs Information from the official site Initialize a tabs with the disabled option specified. <code> $( ".selector" ).tabs({ disabled: true }); </code> Get or set the disabled option, after init. <code> var disabled = $( ".selector" ).tabs( "option", "disabled" ); //setter $( ".selector" ).tabs( "option", "disabled", true ); </code> Found in wordpress-post-tabs.php line 105 <code> &lt;script type="text/javascript"&gt; jQuery(function() { &lt;?php if($wpts_count and $wpts_count!=0){ for($i=0;$i&lt;$wpts_count;$i++) { ?&gt; jQuery("#tabs_&lt;?php echo $i;?&gt;").tabs({ cookie: { expires: 30 } }); //getter var cookie = jQuery("#tabs_&lt;?php echo $i;?&gt;").tabs( "option", "cookie" ); //setter jQuery("#tabs_&lt;?php echo $i;?&gt;").tabs( "option", "cookie", { expires: 30 } ); &lt;?php if(isset($wpts['fade']) and $wpts['fade']=='1'){ ?&gt; //fx for animation jQuery("#tabs_&lt;?php echo $i;?&gt;").tabs({ fx: { opacity: 'toggle' } }); //getter var fx = jQuery("#tabs_&lt;?php echo $i;?&gt;").tabs( "option", "fx" ); //setter jQuery("#tabs_&lt;?php echo $i;?&gt;").tabs( "option", "fx", { opacity: 'toggle' } ); &lt;?php }}} ?&gt; }); &lt;?php if($wpts['reload']=='1') { ?&gt; function wptReload(ar) { location.href=location.href.split(/\?|#/)[0] + '#' + ar; location.reload(true); return false; } &lt;?php } ?&gt; &lt;/script&gt; </code>
* See edit history for previous comments I decided i'm going to write a plugin to do this, the plugin discussed i'm sure was written with the best intentions, but the code in my personal opinion needs a total rewrite, which is essentially what i'll be doing. The aim will basically be to emulate the functionality of the WordPress Post Tabs plugin. NOTE: This plugin includes jQuery cookie , which is dual licensed under the MIT and GPL licenses, just a heads up for those of you that need to know such things. Features The plugin will feature the following. Smart CSS and Script loading - Only loads CSS and JS when there's a post in the loop with the shortcode Skin selection - Choose from a list of jQuery UI styles Disable skin loading - Optionally turn off stylesheet loading, and just define your own Disabled tabs - Disable clicking on tabs that do not have any content yet jQuery cookie - Enable the jQuery cookie script to track selected tabs Tab navigation - Display clickable links to navigate between tabs Loading on archive pages - Choose whether to display the tabs on archive pages Translation ready - Supports other languages Live style preview - See a live preview of tab styles in the plugin settings page Filter hooks for navigation links - So you can change the navigation icons Utilises the settings API Screenshots Front side Admin side Have a few more bits to test, but it's almost ready, watch this space!.. :) Update: Just need to get stackexchange-url ("some things worked out") regarding using the plugin repository first, then we should be good to go.. Post UI Tabs (or PUT for short) http://wordpress.org/extend/plugins/put/
Disable Jquery UI post tabs
wordpress
I have a loop template called <code> loop-event-details.php </code> where I have code to display each event. My main page template is called <code> events-page.php </code> . I use the following code to include the loop template: <code> get_template_part( 'loop', 'event-details' ); </code> I have also trying this code: <code> include(TEMPLATEPATH . '/loop-event-details.php'); </code> However, when viewing a page it always complains about parsing error: <code> Parse error: syntax error, unexpected T_ENDWHILE in /&lt;my_templatepath&gt;/loop-event-details.php on line 1 </code> The <code> loop </code> isn't on line 1, but line 15. The code in the <code> loop </code> file is correct, because when I copy and paste all the code from the <code> loop </code> file into the <code> page </code> file it all works. As soon as I try to include it with either contract ( <code> get_template_part() </code> or <code> include() </code> ) it doesn't work and always complains about line 1. Any tips and help would be hugely appreciated. Thanks, Dasha WP 3.1.0 PHP Version 5.2.6-1+lenny9
I've created a new file, specified the encoding as "UTF-8" and retyped everything by hand - no copy/paste from the old file. Took a while, but all works now. It must have been some encoding errors playing up. Thanks to everyone who helped: @t31os, @kaiser, @Chip Bennett
strange parse error when including a loop template within another template
wordpress
In my WP admin's "Pages" section is a page called "Home" with a URL of /home. This page's content gets called by my index.php file. My problem is the /home page is coming up in search results, or someone could type in /home. Is it possible to redirect /home to index.php (or just "/")?
Change your index.php file back to normal, then set that home page as the front page instead. Then the /home will redirect to / as it should.
Redirect /home to home.php
wordpress
I'm listing all sidebars like that: <code> global $wp_registered_sidebars; echo '&lt;pre&gt;'; print_r($wp_registered_sidebars); echo '&lt;/pre&gt;' </code> So I'm getting something like: <code> Array ( [sidebar-1] =&gt; Array ( [name] =&gt; Sidebar #1 [id] =&gt; sidebar-1 [description] =&gt; Sidebar number 1 [before_widget] =&gt; [after_widget] =&gt; [before_title] =&gt; [after_title] =&gt; ) (...) ) </code> But I'd love to display them as a select list, like: <code> &lt;select&gt; &lt;option value ="SIDEBAR-ID"&gt;SIDEBAR-NAME/option&gt; &lt;option value ="SIDEBAR-ID"&gt;SIDEBAR-NAME/option&gt; (...) &lt;/select&gt; </code> Wordpress Codex isn't helpful at all. Thank you!
Loop through the global: <code> &lt;select&gt; &lt;?php foreach ( $GLOBALS['wp_registered_sidebars'] as $sidebar ) { ?&gt; &lt;option value="&lt;?php echo ucwords( $sidebar['id'] ); ?&gt;"&gt; &lt;?php echo ucwords( $sidebar['name'] ); ?&gt; &lt;/option&gt; &lt;?php } ?&gt; &lt;/select&gt; </code> Note: The <code> ucwords() </code> function is only there to display it exactly as you asked. Not sure if you really want that. How to access global arrays & objects: Anyway: Your Q mostly is about how to access arrays. I wrote a Q about that (for further explanation). stackexchange-url ("Please take a look over here.")
List all sidebar names?
wordpress
Running WordPress 3.1 with the free Boldy theme from Site5. Here is a working version of my website: http://www.dekhoforum.com I want to achieve something like this screenshot: i.e. Have a 2nd logo above the social media icons. EDIT - Screenshot shows moving an existing image to the new location. This is misleading, and I actually need a new placeholder for an image, and not to move the existing logo (which is the right image), as this will not be consistent on the other pages such as the blog . - In short, its a marketing requirement to get this logo at the top of each page, across the entire site. One option I did ponder, was somehow trying to add another social media icon, but link it to my main company website. I have tweaked PHP in the past on previous themes, but always had a little guidance from you wonderful lot. Was wondering if anyone could advise? I have been snooping in the header.php, but I imagine I will need to write a new line in somewhere? Any help would be great.
This can easily be accomplished with CSS. Sometimes it's better to use CSS to modify your theme. I use the Web Kit developer tools or Firebug to make live edits in the browser until it looks right then save it back to CSS. Edit the following lines in style.css. <code> /* line 201 pulled down the icons to make room for the 2nd logo */ #topSocial { position:absolute; right:0; top: 150px; } /* line 80 add relative positioning to the wrapper div to allow the logo to be positioned absolute */ #wrapper { margin:0 auto; width:960px; position: relative; } /* line 85 made the header a little taller to make room for the 2nd logo*/ #header { height: 220px; position:relative; background:url(images/bk_header.png) 0 0 no-repeat; } /* line 312 moved the logo in place using position absolute */ #blurb img { border:none; position: absolute; top: 90px; right: 15px; margin-top: 5px; } </code> The result: Edit after question was clarified that an additional logo was needed To add an additional logo open your header.php file and find the lines that look like this: Edit The 2nd logo code shown below should go at line 78 in your header.php file <code> &lt;!-- END TOP SEARCH --&gt; &lt;!-- BEGIN TOP SOCIAL LINKS --&gt; </code> Between those two line add the basic XHTML to display a linked image: <code> &lt;!-- END TOP SEARCH --&gt; &lt;!-- BEGIN 2ND LOGO --&gt; &lt;div id="new-logo"&gt; &lt;a href="http://link_you_want_image_to_point_to"&gt;&lt;img src="http://url_of_image" width="xx" height="xx" /&gt;&lt;/a&gt; &lt;/div&gt; &lt;!-- END 2ND LOGO --&gt; &lt;!-- BEGIN TOP SOCIAL LINKS --&gt; </code> Use the exact same CSS I gave you above except change <code> #blurb img { border:none; position:absolute; top: 90px; right: 15px; margin-top: 5px; } </code> to: <code> #new-logo img { border:none; position:absolute; top: 90px; right: 15px; margin-top: 5px; } </code>
Boldy Theme - Tweak PHP for 2nd Logo?
wordpress
I have a self-hosted blog, ( Code Repo - Code Snippets ) but for some reason when I search for it on google, it doesn't come up in the results. I posted an entry about 4 days ago, and by now I would have expected it come up in the results. When I search for things on my normal site (same domain), they do come up, its just things inside the blog that don't seem to be included. In the past, I have only had blogs hosted on wordpress.com and they have always automatically come up. What can I do to fix this? Thank you!
Googling "site:http://dougmolineux.com/wp/" seems to show that you blog is getting indexed and quick check doesn't find any settings prohibitive to indexing set. Other than latter there isn't really much that can be done, it's up to Google how it indexes and serves your site in results.
Self-Hosted Blog on Google Search
wordpress
How can i get the posts using get_posts from let's say post 10 and beyond?So if i have 200 posts i will get from post 10 to post 200(190 posts)? Because as i see if i use <code> &lt;?php $args = array( 'numberposts' =&gt; -1, 'offset' =&gt; 10 ); ?&gt; </code> i just get all the posts Cheers
It's strange, you'd have thought if you disable paging and grab all posts, that you could naturally set an offset to, eg. <code> array( 'nopaging' =&gt; true, 'offset' =&gt; 10 ) </code> or <code> array( 'posts_per_page' =&gt; -1, 'offset' =&gt; 10 ) </code> or <code> array( 'numberposts' =&gt; -1, 'offset' =&gt; 10 ) </code> This unfortunately doesn't appear to work(bug / oversight in core i'd guess), however the following works, which i'd agree is not perfect, but will work. <code> array( 'posts_per_page' =&gt; 100000, 'offset' =&gt; 10 ) </code> Just use a really high number, and it'll work around the issue of the <code> offset </code> not being respected when paging is disabled.
get_posts from post x(offset=> x) to end
wordpress
I am having a JavaScript which is used for marquee, I want to use this in my wordpress site. But this java script is conflicting with my wordpress, I am using this in footer, but just the <code> div </code> area is getting loaded, the marquee in it is not working. Here is my code: <code> &lt;div class="marq"&gt; &lt;script type="text/javascript"&gt; /*********************************************** * Conveyor belt slideshow script- © Dynamic Drive DHTML code library (www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code ***********************************************/ //Specify the slider's width (in pixels) var sliderwidth="900px" //Specify the slider's height var sliderheight="100px" //Specify the slider's slide speed (larger is faster 1-10) var slidespeed=5 //configure background color: slidebgcolor="#FFFFFF" //Specify the slider's images var leftrightslide=new Array() var finalslide='' leftrightslide[0]='&lt;a href="#" target="_blank" style="color:#FFFFFF;"&gt;&lt;img src="images/management-paradise-logo.jpg" style="height:80px; opacity:0.4;filter:alpha(opacity=40)"onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40"&gt;&lt;/a&gt;&lt;img src="images/line.png" style="height:80px; padding-left:30px; padding-right:30px; padding-bottom:10px;"/&gt;' leftrightslide[1]='&lt;a href="#" target="_blank" style="color:#FFFFFF;"&gt;&lt;img src="images/MBAS.IN.jpg" style="opacity:0.4;filter:alpha(opacity=40)"onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40"&gt;&lt;/a&gt;&lt;img src="images/line.png " style="height:80px; padding-left:30px; padding-right:30px; padding-bottom:10px;"/&gt;' leftrightslide[2]='&lt;a href="#" target="_blank" style="color:#FFFFFF;"&gt;&lt;img src="images/bms.co.in.jpg" style="height:80px; opacity:0.4;filter:alpha(opacity=40)"onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40"&gt;&lt;/a&gt;&lt;img src="images/line.png" style="height:80px; padding-left:30px; padding-right:30px; padding-bottom:10px;"/&gt;' leftrightslide[3]='&lt;a href="#" target="_blank" style="color:#FFFFFF;"&gt;&lt;img src="images/mbas.co.in.jpg" style="height:80px; opacity:0.4;filter:alpha(opacity=40)"onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40"&gt;&lt;/a&gt;&lt;img src="images/line.png" style="height:80px; padding-left:30px; padding-right:30px; padding-bottom:10px;"/&gt;' leftrightslide[4]='&lt;a href="#" target="_blank" style="color:#FFFFFF;"&gt;&lt;img src="images/MCAS.jpg" style="height:80px; opacity:0.4;filter:alpha(opacity=40)"onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40"&gt;&lt;/a&gt;&lt;img src="images/line.png" style="height:80px; padding-left:30px; padding-right:30px; padding-bottom:10px;"/&gt;' leftrightslide[5]='&lt;a href="#" target="_blank" style="color:#FFFFFF;"&gt;&lt;img src="images/casestudy.co.in.jpg" style="height:80px; opacity:0.4;filter:alpha(opacity=40)"onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40"&gt;&lt;/a&gt;&lt;img src="images/line.png" style="height:80px; padding-left:30px; padding-right:30px; padding-bottom:10px;"/&gt;' leftrightslide[6]='&lt;a href="#" target="_blank" style="color:#FFFFFF;"&gt;&lt;img src="images/ONLINEMBA.CO.IN.jpg" style="height:80px; opacity:0.4;filter:alpha(opacity=40)"onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40"&gt;&lt;/a&gt;&lt;img src="images/line.png" style="height:80px; padding-left:30px; padding-right:30px; padding-bottom:10px;"/&gt;' leftrightslide[7]='&lt;a href="#" target="_blank" style="color:#FFFFFF;"&gt;&lt;img src="images/BAF.jpg" style="height:80px; opacity:0.4;filter:alpha(opacity=40)"onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40"&gt;&lt;/a&gt;&lt;img src="images/line.png" style="height:80px; padding-left:30px; padding-right:30px; padding-bottom:10px;"/&gt;' leftrightslide[8]='&lt;a href="#" target="_blank" style="color:#FFFFFF;"&gt;&lt;img src="images/BBI.jpg" style="height:80px; opacity:0.4;filter:alpha(opacity=40)"onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40"&gt;&lt;/a&gt;&lt;img src="images/line.png" style="height:80px; padding-left:30px; padding-right:30px; padding-bottom:10px;"/&gt;' leftrightslide[9]='&lt;a href="#" target="_blank" style="color:#FFFFFF;"&gt;&lt;img src="images/BFM.jpg" style="height:80px; opacity:0.4;filter:alpha(opacity=40)"onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40"&gt;&lt;/a&gt;&lt;img src="images/line.png" style="height:80px; padding-left:30px; padding-right:30px; padding-bottom:10px;"/&gt;' leftrightslide[10]='&lt;a href="#" target="_blank" style="color:#FFFFFF;"&gt;&lt;img src="images/BMM.jpg" style="height:80px; opacity:0.4;filter:alpha(opacity=40)"onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40"&gt;&lt;/a&gt;&lt;img src="images/line.png" style="height:80px; padding-left:30px; padding-right:30px; padding-bottom:10px;"/&gt;' leftrightslide[11]='&lt;a href="#" target="_blank" style="color:#FFFFFF;"&gt;&lt;img src="images/U-K.IN.jpg" style="height:80px; opacity:0.4;filter:alpha(opacity=40)"onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40"&gt;&lt;/a&gt;&lt;img src="images/line.png" style="height:80px; padding-left:30px; padding-right:30px; padding-bottom:10px;"/&gt;' //Specify gap between each image (use HTML): var imagegap=" " //Specify pixels gap between each slideshow rotation (use integer): var slideshowgap=5 ////NO NEED TO EDIT BELOW THIS LINE//////////// var copyspeed=slidespeed leftrightslide='&lt;nobr&gt;'+leftrightslide.join(imagegap)+'&lt;/nobr&gt;' var iedom=document.all||document.getElementById if (iedom) document.write('&lt;span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-9000px"&gt;'+leftrightslide+'&lt;/span&gt;') var actualwidth='' var cross_slide, ns_slide function fillup(){ if (iedom){ cross_slide=document.getElementById? document.getElementById("test2") : document.all.test2 cross_slide2=document.getElementById? document.getElementById("test3") : document.all.test3 cross_slide.innerHTML=cross_slide2.innerHTML=leftrightslide actualwidth=document.all? cross_slide.offsetWidth : document.getElementById("temp").offsetWidth cross_slide2.style.left=actualwidth+slideshowgap+"px" } else if (document.layers){ ns_slide=document.ns_slidemenu.document.ns_slidemenu2 ns_slide2=document.ns_slidemenu.document.ns_slidemenu3 ns_slide.document.write(leftrightslide) ns_slide.document.close() actualwidth=ns_slide.document.width ns_slide2.left=actualwidth+slideshowgap ns_slide2.document.write(leftrightslide) ns_slide2.document.close() } lefttime=setInterval("slideleft()",30) } window.onload=fillup function slideleft(){ if (iedom){ if (parseInt(cross_slide.style.left)&gt;(actualwidth*(-1)+8)) cross_slide.style.left=parseInt(cross_slide.style.left)-copyspeed+"px" else cross_slide.style.left=parseInt(cross_slide2.style.left)+actualwidth+slideshowgap+"px" if (parseInt(cross_slide2.style.left)&gt;(actualwidth*(-1)+8)) cross_slide2.style.left=parseInt(cross_slide2.style.left)-copyspeed+"px" else cross_slide2.style.left=parseInt(cross_slide.style.left)+actualwidth+slideshowgap+"px" } else if (document.layers){ if (ns_slide.left&gt;(actualwidth*(-1)+8)) ns_slide.left-=copyspeed else ns_slide.left=ns_slide2.left+actualwidth+slideshowgap if (ns_slide2.left&gt;(actualwidth*(-1)+8)) ns_slide2.left-=copyspeed else ns_slide2.left=ns_slide.left+actualwidth+slideshowgap } } if (iedom||document.layers){ with (document){ document.write('&lt;table border="0" cellspacing="0" cellpadding="0"&gt;&lt;td&gt;') if (iedom){ write('&lt;div style="position:relative;width:'+sliderwidth+';height:'+sliderheight+';overflow:hidden"&gt;') write('&lt;div style="position:absolute;width:'+sliderwidth+';height:'+sliderheight+';background-color:'+slidebgcolor+'" onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed"&gt;') write('&lt;div id="test2" style="position:absolute;left:0px;top:0px"&gt;&lt;/div&gt;') write('&lt;div id="test3" style="position:absolute;left:-1000px;top:0px"&gt;&lt;/div&gt;') write('&lt;/div&gt;&lt;/div&gt;') } else if (document.layers){ write('&lt;ilayer width='+sliderwidth+' height='+sliderheight+' name="ns_slidemenu" bgColor='+slidebgcolor+'&gt;') write('&lt;layer name="ns_slidemenu2" left=0 top=0 onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed"&gt;&lt;/layer&gt;') write('&lt;layer name="ns_slidemenu3" left=0 top=0 onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed"&gt;&lt;/layer&gt;') write('&lt;/ilayer&gt;') } document.write('&lt;/td&gt;&lt;/table&gt;') } } &lt;/script&gt;&lt;/div&gt; </code> How can I integrate this with my wordpress site?
That script looks very old and obtrusive and it doesn't output a marquee, but a slideshow. There already are hundreads of themes with a slideshow built in, as well as many newer jQuery plugins which you can switch to. If you're still convinced this particular script is worth the time to fix, install Firebug to see the exact error.
javascript conflict
wordpress
I have my news in posts and I am trying to display the two latest news articles (posts) on my main page. I've got that solved by getting the title using <code> the_title() </code> and getting a little bit of the text using <code> the_excerpt() </code> . I want to show a more... link that takes you to the post. However, some of the news articles that I am posting have some text in the post body that's a link, how do I only get the link within the body of a post so that my more... link takes your there directly? For example, sometimes we will link to news articles in PDFs that are on another server. I'm using the following code. <code> &lt;?php query_posts('category_name=news2011'); ?&gt; &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt; &lt;?php /* the_ID(); */ ?&gt; &lt;?php /* the_date('F Y'); */ ?&gt; &lt;ol class="news"&gt; &lt;strong&gt;&lt;p&gt;&lt;?php the_title()?&gt;&lt;/p&gt;&lt;/strong&gt; &lt;li&gt;&lt;?php the_content(); ?&gt;&lt;/li&gt; &lt;/ol&gt; &lt;?php endwhile; endif; ?&gt; </code>
You can scan the content to see whether it contains a link and then parse it to find the <code> href </code> attribute. There are many ways to do this, this example uses the built-in kses functionality, as demonstrated by Otto : <code> $post_link = get_the_permalink(); if ( preg_match('/&lt;a (.+?)&gt;/', get_the_content(), $match) ) { $link = array(); foreach ( wp_kses_hair($match[1], array('http')) as $attr) { $link[$attr['name']] = $attr['value']; } $post_link = $link['href']; } </code>
Get link value only from the_content()?
wordpress
I'm having an issue with one site in which my plugin is installed. The "settings" page will not load. When I click on "settings", it loads the settings page but the page is blank after the "Upgrade to 3.1" nag div as if there was a die() there. I have two files, plugin.php and plugin-admin.php I've got code in plugin.php to set up the admin page: <code> $my_dir = plugins_url('/img', __FILE__); add_options_page( 'MY! Settings', 'MY! Settings', 'manage_options', 'my-plugin-admin.php', 'my_settings_admin', $my_dir.'/favicon.png', 'top' ); register_setting( 'my_settings_options', 'my_settings', 'my_settings_validate' ); function my_settings_admin(){ global $wp_rewrite; $wp_rewrite-&gt;flush_rules(); include_once dirname(__FILE__) . '/my-plugin-admin.php'; } define( 'my_BASENAME', plugin_basename( __FILE__ ) ); define( 'my_BASEFOLDER', plugin_basename( dirname( __FILE__ ) ) ); define( 'my_FILENAME', str_replace( my_BASEFOLDER.'/', '', plugin_basename(__FILE__))); </code> The "My Settings" link shows up under the "Settings" menu fine, and the link appears to be going to the correct page, but the script does not load and nothing will trace inside of my-plugin-admin.php Any ideas? UPDATE: with t31os help, here's the updated function that fixes the problem: <code> function my_settings_admin(){ include_once dirname(__FILE__) . '/my-plugin-admin.php'; global $wp_rewrite; $wp_rewrite-&gt;flush_rules(); } </code> I simply had to move the wp_rewrite and flush rules after the include statement. Although I don't know why.
If i had to venture a guess at the cause of the problem my initial thought would be toward the flush rules call. As Andy said, having debug on helps a great deal, and if you really don't want to see the errors, you can always use the debug log instead, using the following in your config file.. <code> define('WP_DEBUG', true); // Turn on debug mode define('WP_DEBUG_LOG', true); // Logs errors to wp-content/debug.log define('WP_DEBUG_DISPLAY', false); // Disable displaying errors </code> With regard to your settings update not redirecting, typically that occurs when the nonce(s) are missing or incorrect, though i'll admit it could be something else in your case. Any errors shown with debug on? (or in the log if you're using that method?)
What could cause my plugin's options/settings page not to load?
wordpress
The admin bar is appearing for non logged-in users on one of my sites, but only for two specific pages (/work and /contact, for what it's worth). Has anyone heard of this happening before? It appears as though one of the site's users is logged in (their username is displayed), but clicking any links on the admin bar lead to the login page. If I click Log Out under that users name in the admin bar, I get a prompt to ensure I want to logout, then a redirect to /wp-login.php. However, upon returning to /work or /contact, the admin bar still appears.
Since I think that mis-identifying all users not-logged in is extremely unlikely, my line of thought is that wrong non-public version of page was cached for some reason.
Why is the admin bar appearing (on certain pages) for non logged-in users?
wordpress
I'm facing a strange problem here with this custom login form: <code> &lt;form name="loginformfooter" class="loginform" id="loginformfooter" action="&lt;?php bloginfo('url'); ?&gt;/wp-login.php" method="post"&gt; &lt;input type="text" name="log" id="user_login" class="input" tabindex="1" /&gt; &lt;input type="password" name="pwd" id="user_pass" class="input" tabindex="2" /&gt; &lt;input type="submit" name="wp-submit" id="wp-submit" value="Login" /&gt; &lt;input type="hidden" name="redirect_to" value="http://&lt;?=$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];?&gt;" /&gt; &lt;input type="hidden" name="testcookie" value="1" /&gt; &lt;/form&gt; </code> The most of the times it redirect me to the correct page, but few other times, especially at first login, it redirects me to the admin page. I'm not able to determine precisely when the problem occours. Does anyone found a problem like that? Or is there a better solution to get the same result? Thanks!
Php Short tags are a "no-no" You shouldn't use short php like this: <code> value="http://&lt;?=$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];?&gt;" </code> Where does it come from? Different servers, different php.ini files. You simply ran into the problem that <code> short_open_tag = Off </code> is set. Not all servers have this set to true per default. Further more not all hosts allow editing the php.ini file - for good reasons. Check ini settings Try the follwing inside your code: <code> &lt;?php echo 'short open tag: ' . ini_get('short_open_tag'); ?&gt; </code> . Set ini settings If you see that it's off you can try turning it on in your php.ini file using.. <code> &lt;?php ini_set('short_open_tag', 'ON'); ?&gt; </code> . Alternatively (per t31os's suggestion) If the login page is the first page on your site you request, there is no request URI to pass along, so naturally a redirect won't happen because there's no request URI to send you to.
custom login form redirect problem
wordpress
I am writing a function that adds an ID number to an array and puts the array in the usermeta. $_GET['auction'] is the post_id. Here is the function: <code> $reminders = get_user_meta($current_user-&gt;ID,"reminders"); print_r($reminders); if(in_array($_GET['auction'],$reminders)) { echo "Failed: Auction already in list"; } else { array_push($reminders,intval($_GET['auction'])); if(update_user_meta($current_user-&gt;ID,"reminders",$reminders)) { echo "Success"; } else { echo "Failed: Could not update user meta"; } } print_r($reminders); </code> Here is the output after adding one auction: <code> Array ( ) Success Array ( [0] =&gt; 7 ) </code> Here is the output after adding two auctions: <code> Array ( [0] =&gt; Array ( [0] =&gt; 7 ) ) Success Array ( [0] =&gt; Array ( [0] =&gt; 7 ) [1] =&gt; 73 ) </code> And here is the output after adding three auctions: <code> Array ( [0] =&gt; Array ( [0] =&gt; Array ( [0] =&gt; 7 ) [1] =&gt; 73 ) ) Success Array ( [0] =&gt; Array ( [0] =&gt; Array ( [0] =&gt; 7 ) [1] =&gt; 73 ) [1] =&gt; 0 ) </code> Notice that adding a new element to the array using array_push works fine. But when the array is stored in the usermeta then retrieved again, the last element in the array has been put into an array of its own, creating an infinitely dimensional array. I'd prefer to keep this array one dimensional. Is there a way I can run update_user_meta and get_user_meta without it changing the structure of my array?
Haven't used the function for quite a time, but i guess your problem is that you are pushing an array into an array. So check if <code> intval($_GET['auction']) </code> is an array: <code> echo '&lt;pre&gt;'; print_r(intval($_GET['auction'])); echo '&lt;/pre&gt;'; </code> Edit #1: You maybe need to get the value from that array and then array_push it. So maybe something like <code> array_push( $reminders, $_GET['auction'][0]) ); </code> - if you're only adding one single value. You could also do something like <code> $reminders[] = $_GET['auction'][0]; </code> to add it to the end of your array. Edit #2: From a look at the core file: yes. <code> update_user_meta() </code> is just an alias of <code> update_metadata() </code> which takes the ID + the value and puts it into the database as and array. <code> // From /wp-includes/meta.php ~ line 135 $where = array( $column =&gt; $object_id, 'meta_key' =&gt; $meta_key ); if ( !empty( $prev_value ) ) { $prev_value = maybe_serialize($prev_value); $where['meta_value'] = $prev_value; } </code>
Problem storing arrays with update_user_meta
wordpress
Let's say I got the following categories: <code> Style | + Shoes + Pants </code> If I make a post and put it in the Style and Shoes category, it will list them alphabetically instead of hierarchically. So it would list it as Shoes, Style instead of Styles, Shoes. How can I do this? I tried using "the_category('> ', 'multiple')" but that outputs "Style, Shoes, Style" Thanks!
You could fetch the post categories, then pass them into <code> wp_list_categories </code> to take care of displaying them hierarchally. Something like.. <code> wp_list_categories( array( 'include' =&gt; array_keys( get_the_terms( $post-&gt;ID, 'category' ) ), 'title_li' =&gt; '' ) ); </code> Hope that helps.. :)
List categories of a post hierarchically?
wordpress
Every time I create a new site under 3.1, my first trip is to the Users > Admin User profile page to uncheck the "admin bar" checkbox. I'd like to place a script in my theme's functions.php to do this automatically. Anyone know what that would be?
You could use a function inside your theme's functions file to selectively disable it for specific users. <code> function disable_bar_for_user( $ids ) { if( !is_user_logged_in() ) return; global $current_user; if( is_numeric( $ids ) ) $ids = (array) $ids; if( !in_array( $current_user-&gt;data-&gt;ID, $ids ) ) return; add_filter( 'show_admin_bar', '__return_false', 9 ); } </code> Then call it for the user or users you want to disable the bar for.. Single user: <code> disable_bar_for_user(1); </code> Multiple users: <code> disable_bar_for_user(array(1,2,3)); </code> If you want to just turn it off altogether, then the following should do it(instead of the function). <code> add_filter( 'show_admin_bar', '__return_false', 9 ); </code> Hope that helps.. :)
How to disable 3.1 "Admin Bar" via script for the admin user?
wordpress
I am managing a Wordpress network and would like to add the unfiltered_html user capability to the already predefined user role of Admin. In a standard installation of Wordpress the Admin account would already have this capability but in an MU installation only Super Admins are afforded this capability. Wordpress Roles and Capabilities. How can I augment the Admin role from within a theme or plugin?
You can use WP_Role class, <code> // get the the role object $role_object = get_role( $role_name ); // add $cap capability to this role object $role_object-&gt;add_cap( $capability_name ); // remove $cap capability from this role object $role_object-&gt;remove_cap( $capability_name ); </code> or you can run this once in your functions: <code> /* Roles &amp; Capabilities */ add_role('professional', 'Professional User', array( 'read' =&gt; true, // True allows that capability, False specifically removes it. 'edit_posts' =&gt; true, 'delete_posts' =&gt; true, //'edit_published_posts' =&gt; true, //'publish_posts' =&gt; true, //'edit_files' =&gt; true, 'upload_files' =&gt; true //last in array needs no comma! )); </code>
How to add a Capability to a User Role?
wordpress
Hay, I'm making a WordPress template, and i have 4 main pages. <code> HOME BLOG CONTACT ABOUT US </code> As you can see "Blog" is a page (i need it to display when i call wp_list_pages()), but how do i edit this blog page? I assigned the "Blog" page a custom temeplate (called blog.php), but when "Blog" is set as the "Post page" in the Reading section of the WordPress admin, the page fails to render the template. How do i edit this "Blog" page?
Setting page to be "posts page" changes its template hierarchy to follow home page rules . So your custom template is ignored and it looks for <code> home.php </code> or <code> index.php </code> , which might or might not be the reason it fails to render.
What exactly does "Posts page" do in WordPress?
wordpress
The Dilemma I have a few custom post types: Portfolio Items Testimonials FAQs The URL structures for these custom post types are: mysite.com/ portfolio /name-of-custom-post mysite.com/ testimonial /name-of-custom-post mysite.com/ faq /name-of-custom-post I'd like to use the normal, built-in WordPress post type to control our blog entries, and have the URL for each blog entry be like this: mysite.com/ blog /name-of-post If I go to Settings > Permalinks and adjust the URL structure to be like... <code> /blog/%postname%/ </code> ...then the URLs for all of my post types are affected, which results in: mysite.com/ blog/portfolio /name-of-custom-post mysite.com/ blog/testimonial /name-of-custom-post etc... The Question What I'd like to know -- is it possible to adjust the URL structure for the built-in WordPress post type without affecting the URL structure of other custom post types? The only other way I see to solve my dilemma is to create another custom post type called "Blog." This seems wasteful, because then I won't be using the built-in WordPress post type at all. If anyone needs it, The Why If anyone wonders why I need "blog" in the URL so badly, it's because we're merging our blog into the same install as our site, and want to keep the URLs intact so we don't lose valuable Google juice. Any help is greatly appreciated -- thanks!
You could do this on custom post type registration. 1) Set your default permalink in the WordPress admin to your desired structure e.g.: /blog/%postname% 2) Add the "slug" and "with_front" parameter to the rewrite-array in the register_post_type function. "slug" must be the name of your post-type. <code> $args = array( // ... 'rewrite' => array( 'slug' => 'your_post_type', 'with_front' => false ), // ... ); register_post_type('your_post_type',$args); </code> This should generate the following rewrite-rules: Default Post: http://example.com/blog/%postname% Default Page: http://example.com/%postname% Custom Post Type: http://example.com/your_post_type/%postname% EDIT The "slug" parameter is optional. If you don't set it, the name of your custom post type is used. Check out the function reference about register_post_type: http://codex.wordpress.org/Function_Reference/register_post_type
Possible to change the URL for the regular post type without affecting the URL of other custom post types?
wordpress
I've got a very basic solution using <code> fetch_feed() </code> and SimplePie to pull in RSS items which is working on my localhost, but for some reason <code> is_wp_error() </code> persists as <code> true </code> on the live server. Is there anyway for me to get specific output about the nature of the error so as to work towards a solution on the live server? <code> &lt;?php include_once(ABSPATH . WPINC . '/feed.php'); $rss = fetch_feed( '[rss feed removed from example]' ); if (!is_wp_error( $rss ) ) : $maxitems = $rss-&gt;get_item_quantity(5); $rss_items = $rss-&gt;get_items(0, $maxitems); $isc = 'http://dtd.interspire.com/rss/isc-1.0.dtd'; endif; ?&gt; &lt;ul class="featured-products"&gt; &lt;?php if ( $maxitems == 0) : ?&gt; &lt;li&gt;No items.&lt;/li&gt; &lt;?php else : ?&gt; &lt;?php foreach ( $rss_items as $item ) : $image = $item-&gt;get_item_tags( $isc, 'thumb'); ?&gt; &lt;li&gt;...&lt;/li&gt; &lt;?php endforeach; ?&gt; &lt;?php endif; ?&gt; &lt;/ul&gt; </code>
add this to your feed <code> $rss = fetch_feed( $url ); if ( is_wp_error( $rss ) ) { echo $rss-&gt;get_error_message(); &lt;---this } else { // do your stuff here } </code> I would also suggest installing the debug toolbar extensions, like "debug-bar-extender".
Troubleshooting fetch_feed and SimplePie
wordpress
I have my blog under <code> blog.mydomain.com </code> . I am using pages for some static content that needs to be accessed from another subdomain. So <code> careers.mydomain.com </code> will show WordPress content from <code> blog.mydomain.com/careers </code> . My problem is that all the links on the page still reference <code> blog.mydomain.com </code> . Is there a way to ask WordPress to use relative links? Or a way to change the baseURL for pages?
There is a filter, <code> post_link </code> , that permalinks pass through before being returned from <code> get_permalink </code> in <code> wp-includes/link-template.php </code> . You can use that filter to alter the links. However, beware that making all permalinks relative may have unintended consequences in certain contexts, e.g. you might not want relative links when <code> is_feed() == true </code> . You may find that the <code> post_link </code> filter doesn't catch all of the URLs you need changed. In that case, you can try the <code> home_url </code> filter which has much broader effect. Another possibility (my favorite) is to use output buffering to relativize the links. (Example at bottom.) To be safe, you can change the links only when necessary. I don't know how you're getting the content from the actual blog to the static subdomain, but if you're using HTTP requests you can add a query arg: <code> ?rlz </code> and then look for that in your theme/plugin. <code> if ( isset($_GET['rlz']) ) { function my_ob_handler($HTML) { return str_replace( home_url('/'), '/', $HTML ); } ob_start( 'my_ob_handler' ); } </code>
Relative instead of absolute links in pages?
wordpress
My blog is painfully slow for the last few days, and I would like to pay someone (anyone?) 15 BitCoins to optimize it for me (I would do it myself, but I'm not sure I have the time right now). It's currently hosted at GoDaddy. What I'm thinking is giving him a snapshot of the filestructure of my blog, and asking him to setup an Amazon EC2 image that will run it. After I test his image, I will switch my domain to point to the new EC2 instance and change the admin password. My blog is rather small (only 80 readers), and I gather I don't have anything vital/precious/secret there. The private information I could think of that I wouldn't want leaked is perhaps a few emails addresses from some of my users (not that happy about it being leaked, but I assume that email addresses aren't that expensive, and nobody will have the incentive to do anything interesting with them). Do you think it's a viable option? Or instead, should I absolutely not do, in order to protect my user' privacy? What are security risks are there? BTW, I don't yet have anyone specific in mind. If you're interested, ping me at [email protected]. Edit - cross link to the post on bitcoin.org forums.
Yes, there is a risk! I can put up a check on date to change your password, create a new user and what not. Don't give access to someone you don't trust. Hire a professional to do the job. Edit: Okay! Upon request, I have explained two cases in a blog post - http://blog.ashfame.com/?p=903
Is there a security risk giving someone temporary access to my blog's code?
wordpress
I created a new post-type following this technique: (http://www.wpbeginner.com/wp-tutorials/how-to-use-custom-post-types/) After creating a a new post-type some of the feature of the a regular post also disappeared. I installed a plugin (SEO Pressor) that helps my seo on creating a new post. That plugin can be seen in the sidebar when you create a new post, Together with "Publish", "Categories" etc.. . currently the new post-type only contains the "Publish" and "Attributes" block. Any idea how I can call those plugin to my new post-type? Thanks!
The plugin would need to support custom post types. You might be able to ask the plugin developer to add that. The custom post type API's are fairly new and still don't have widespread support. You can see that they are adding the meta boxes only for posts and pages: <code> add_meta_box( 'WPPostsRateKeys-Keyword', 'SEOPressor Keyword', array(&amp;$this,'add_box_in_post_form'), 'post', 'normal', 'high' ); add_meta_box( 'WPPostsRateKeys-Keyword', 'SEOPressor Keyword', array(&amp;$this,'add_box_in_post_form'), 'page', 'normal', 'high' ); add_meta_box( 'seo_pressor_post_suggestions', 'SEOPressor Score', array(&amp;$this, 'show_score_box'), 'page', 'side', 'high' ); add_meta_box( 'seo_pressor_post_suggestions', 'SEOPressor Score', array(&amp;$this, 'show_score_box'), 'post', 'side', 'high' ); </code> But without knowing how much they rely on the different post types it's hard to say how easy it would be to add those meta boxes to custom post types.
new post-type how do i retain the plugins on my sidebar?
wordpress
I have this code which is located on the search.php page and retrieves all the categories for each post and echo's out a link to the first category: <code> $category = get_the_category(); //print_r($category); if ($category) { echo '&lt;a href="' . get_category_link( $category[0]-&gt;term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category[0]-&gt;name ) . '" ' . '&gt;' . $category[0]-&gt;name.'&lt;/a&gt; '; </code> What I need to do is use a similar code but that gets the child-most/deepest category in the array? This is the array thats printed out: <code> [0] =&gt; stdClass Object ( [term_id] =&gt; 170 [name] =&gt; ACS Series Suspended &amp;amp; Crane Scales - EC Approved [slug] =&gt; uwe-acs-series-suspended-crane-scales [term_group] =&gt; 0 [term_taxonomy_id] =&gt; 170 [taxonomy] =&gt; category [description] =&gt; [parent] =&gt; 3 [count] =&gt; 4 [object_id] =&gt; 1578 [cat_ID] =&gt; 170 [category_count] =&gt; 4 [category_description] =&gt; [cat_name] =&gt; ACS Series Suspended &amp;amp; Crane Scales - EC Approved [category_nicename] =&gt; uwe-acs-series-suspended-crane-scales [category_parent] =&gt; 3 ) [1] =&gt; stdClass Object ( [term_id] =&gt; 3 [name] =&gt; Crane Scales [slug] =&gt; crane-scales [term_group] =&gt; 0 [term_taxonomy_id] =&gt; 3 [taxonomy] =&gt; category [description] =&gt; [parent] =&gt; 0 [count] =&gt; 53 [object_id] =&gt; 1578 [cat_ID] =&gt; 3 [category_count] =&gt; 53 [category_description] =&gt; [cat_name] =&gt; Crane Scales [category_nicename] =&gt; crane-scales [category_parent] =&gt; 0 ) </code> As you can see, one category has parent-> 3 and the other has parent-> 0. How do I use the above query to print out the link only for a category with parent-> 3? Its probably quite simple but its a bit over my head. Any help would be greatly appreciated! Thanks Dave
got a result on stack overflow which worked spot on thanks to @poelinca. code is below incase anybody else has the same issue: Add this function in you're theme/functions.php file : <code> function get_deep_child_category( $categories ) { $maxId = 0; $maxKey = 0; foreach ( $categories as $key =&gt; $value ) { if ( $value-&gt;parent &gt; $maxId ) { $maxId = $value-&gt;term_id; $maxKey = $key; } } return $categories[$maxKey]; } </code> Then let's say as in you're example in theme/search.php you do <code> $categories = get_the_category(); if ( $categories ) : $deepChild = get_deep_child_category( $categories ); ?&gt; &lt;a href="&lt;?php echo get_category_link( $deepChild-&gt;term_id ); ?&gt;" title="&lt;?php echo sprintf( __( "View all posts in %s" ), $deepChild-&gt;name ); ?&gt;"&gt;&lt;?php echo $deepChild-&gt;name; ?&gt;&lt;/a&gt; &lt;?php endif; </code> From my knoledge there is no other way of sorting categories thru get_the_category() but i might be mistaken and the code above wouldn't be the best way of doing things if so . @chip bennett, thanks for your input, I did try this but struggled to get it working how I needed (removing the separators). Thanks, Dave
get_the_category and echo out link to child-most/deepest category
wordpress
I'm trying to add template page from a plugin,and my template page is in this plugin folder.Is this posible?Here is my code: <code> global $user_ID; $new_post = array( 'post_title' =&gt; 'Test Template Page', 'post_content' =&gt; 'Some text', 'post_status' =&gt; 'publish', 'post_date' =&gt; date('Y-m-d H:i:s'), 'post_author' =&gt; $user_ID, 'post_type' =&gt; 'page', 'post_category' =&gt; array(0) ); $post_id = wp_insert_post($new_post); if (!$post_id) { wp_die('Error creating template page'); } else { update_post_meta($post_id, '_wp_page_template', 'tp-file.php'); } </code> tp-file.php is my custom template page.When I put that file into the my-theme folder,it works fine,but I want to do this with file from plugin folder so I don't have to force users to copy that file from plugin folder to template folder. Is this possible?Any idea?
The article linked is on the right track, but i'll make it more simple for you.. ;) <code> add_filter( 'page_template', 'catch_plugin_template' ); function catch_plugin_template( $template ) { if( 'tp-file.php' == basename( $template ) ) $template = WP_PLUGIN_DIR . '/yourpluginname/tp-file.php'; return $template; } </code> The filter basically looks to see if your special page template is set for the current page, if it is, updates the path to point at your plugins template instead. Just be sure the path is right, else you'll be seeing include errors... :) Follow-up #1 Ok first problem is that WordPress validates any template set as a page template, ie. it checks to see if the file is in the theme folder, and is a valid template file, if not it skips past it and includes a more generic template, like page.php ... However, this doesn't change the fact that the meta field still holds the value of your custom template, and also <code> is_page_template( 'tp-file.php' ) </code> will correctly return true if used in place of my previous conditional statement, eg.. <code> // Filter page template add_filter('page_template', 'catch_plugin_template'); // Page template filter callback function catch_plugin_template($template) { // If tp-file.php is the set template if( is_page_template('tp-file.php') ) // Update path(must be path, use WP_PLUGIN_DIR and not WP_PLUGIN_URL) $template = WP_PLUGIN_DIR . '/tp-test/tp-file.php'; // Return return $template; } </code> NOTE: I've switched the code to use <code> WP_PLUGIN_DIR </code> as the <code> WP_PLUGIN_URL </code> constant is not suitable for paths ... (includes must use a path, not a URL). One issue, and this really isn't something you can fix, is that when viewing the page from the admin area, when editting the page, the template won't be listed as the active template, and saving changes could of course change the active template. There's much we can do there, the page template dropdown is generated from a function that scans theme files, there's no hooks in place that i can see that would allows us to extend the list with plugin templates. Personally what i'd suggest , as a work-around would be to save an additional meta field with every page that created using your special plugin page, then add a hook onto <code> save_post </code> or <code> wp_insert_post_data </code> and check if this meta field exists, if it does, also check the page template is set to <code> tp-file.php </code> , and if not, update it to <code> tp-file.php </code> . The additional meta field would just be a flag so to speak, to indicate which pages need to have your plugin template attached. Here's your plugin working in it's most basic form(yes i tested)... :) <code> &lt;?php /* Plugin Name: TP Test Plugin Plugin URI: Description: TP Test Plugin Version: 1.0.0 Author: Author URI: */ global $wp_version; if( version_compare( $wp_version, "2.9", "&lt;" ) ) exit( 'This plugin requires WordPress 2.9 or newer. &lt;a href="http://codex.wordpress.org/Upgrading_WordPress"&gt;Please update!&lt;/a&gt;' ); // Add callback to admin menu add_action('admin_menu', 'create_tp_menu'); // Callback to add menu items function create_tp_menu() { add_management_page('TP Test', 'TP Test', 'manage_options', 'tp-teste', 'wp_tp_test_fnc' ); } function wp_tp_test_fnc() { //include('tp-form-file.php'); if( !empty( $_POST['tp_name'] ) ) { $tp_name = $_POST['tp_name']; global $user_ID; $new_post = array( 'post_title' =&gt; $tp_name, 'post_content' =&gt; 'Some text', 'post_status' =&gt; 'publish', 'post_date' =&gt; date('Y-m-d H:i:s'), 'post_author' =&gt; $user_ID, 'post_type' =&gt; 'page', ); $post_id = wp_insert_post($new_post); if( !$post_id ) wp_die('Error creating template page'); else update_post_meta( $post_id, '_wp_page_template', 'tp-file.php' ); /* $pt = get_page_templates(); $pt['TP file test'] = WP_PLUGIN_URL . '/tp-test/tp-file.php'; echo "&lt;pre&gt;"; print_r($pt); echo "&lt;/pre&gt;"; */ } ?&gt; &lt;fieldset style="margin: 50px 100px;background-color: #cccccc;padding: 30px;border: 1px solid #ccc"&gt; &lt;legend style="background-color: #ccccff;padding: 20px;font-weight: bold;font-size: 18px"&gt;Create Template Page&lt;/legend&gt; &lt;form name="frm_main" action="" method="POSt"&gt; &lt;input class="text" type="text" name="tp_name" size="50" /&gt; &lt;br /&gt; &lt;input class="button" type="submit" value="Create Template Page" name="btn_submit" /&gt; &lt;/form&gt; &lt;/fieldset&gt; &lt;?php } // Filter page template add_filter('page_template', 'catch_plugin_template'); // Page template filter callback function catch_plugin_template($template) { // If tp-file.php is the set template if( is_page_template('tp-file.php') ) // Update path(must be path, use WP_PLUGIN_DIR and not WP_PLUGIN_URL) $template = WP_PLUGIN_DIR . '/tp-test/tp-file.php'; // Return return $template; } </code> Hope that helps clear things up.. :)
Add custom template page programmatically
wordpress
My code lists the child pages ordered by post title, pulling through the first image attachment of the child post as the thumbnail. The child pages contain custom fields created using the Magic Fields plugin. Can anyone help me adjust my code so that I can have my pages listed in descending order of a custom field called 'price'? This is my code: <code> &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt; &lt;div class="page" id="post-&lt;?php the_ID(); ?&gt;"&gt; &lt;div class="pagecontent"&gt; &lt;?php $child_pages = $wpdb-&gt;get_results("SELECT * FROM $wpdb-&gt;posts WHERE post_parent = ".$post-&gt;ID." AND post_type = 'page' ORDER BY post_title", 'OBJECT'); ?&gt; &lt;?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?&gt; &lt;div class="grid"&gt;&lt;a href="&lt;?php echo get_permalink($pageChild-&gt;ID); ?&gt;" alt="&lt;?php echo $pageChild-&gt;post_title; ?&gt;" title="&lt;?php echo $pageChild-&gt;post_title; ?&gt;"&gt; &lt;?php $attachments = get_children( array( 'post_parent' =&gt; $pageChild-&gt;ID, 'post_type' =&gt; 'attachment', 'numberposts' =&gt; 1, // show all -1 'post_status' =&gt; 'inherit', 'post_mime_type' =&gt; 'image', 'order' =&gt; 'ASC', 'orderby' =&gt; 'menu_order ASC' ) ); foreach ( $attachments as $attachment_id =&gt; $attachment ) { echo wp_get_attachment_image( $attachment_id, 'medium' ); } ?&gt; &lt;/a&gt; &lt;h1&gt;&lt;a href="&lt;?php echo get_permalink($pageChild-&gt;ID); ?&gt;" title="&lt;?php echo $pageChild-&gt;post_title; ?&gt;"&gt;&lt;?php echo $pageChild-&gt;post_title; ?&gt;&lt;/a&gt;&lt;/h1&gt; &lt;/div&gt; &lt;?php endforeach; endif; ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php endwhile; endif; ?&gt; </code> I would appreciate any help! Thank you.
I tested this code and it works great: <code> &lt;?php query_posts('meta_key=price&amp;orderby=meta_value_num&amp;post_parent='.$post-&gt;ID.'&amp;post_type=page'); ?&gt; &lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt; &lt;div class="page" id="post-&lt;?php the_ID(); ?&gt;"&gt; &lt;div class="pagecontent"&gt; &lt;div class="grid"&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php the_title(); ?&gt;"&gt; &lt;?php $attachments = get_children( array ( 'post_parent' =&gt; $post-&gt;ID, 'post_type' =&gt; 'attachment', 'numberposts' =&gt; 1, 'post_status' =&gt; 'inherit', 'post_mime_type' =&gt; 'image', 'order' =&gt; 'ASC', 'orderby' =&gt; 'menu_order ASC' ) ); foreach ( $attachments as $attachment_id =&gt; $attachment ) { echo wp_get_attachment_image( $attachment_id, 'medium' ); } ?&gt; &lt;/a&gt; &lt;h1&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php the_title(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h1&gt; &lt;/div&gt; &lt;!-- // grid --&gt; &lt;/div&gt; &lt;!-- // pagecontent --&gt; &lt;/div&gt; &lt;!-- // page --&gt; &lt;?php endwhile; endif; ?&gt; </code> A couple of notes: You don't actually need to use <code> get_results </code> . I combined your custom query restrictions with the <code> query_posts </code> call at the top The <code> query_posts </code> call is ordering by <code> meta_value_num </code> , which is ideal for sorting by numbers. If your "price" field is a string, replace <code> meta_value_num </code> with <code> meta_value </code> . This query will only return posts that have a "price" field defined. That is, if your price field is empty for a post, that post won't be returned.
Change Page Order by Custom Field (Magic Fields)
wordpress
how are you ? In my website I want to make the author's page and category(slug of it is country) to be in google reslut .. like this : http://rehlat-world.com/profile/saqaf , but when I search in google : site:rehlat-world.com , I didn't find authors page. how can include authors page in google result , this is my robort and this is my sitemap note: I change the slug of author ( http://rehlat-world.com/author/ ** from author to profile ( http://rehlat-world.com/profile/ ** ) .. how can include author page in google result ? ALSO , when I search in google (site:rehlat-world.com) some of posts repeated like this : http://rehlat-world.com/%D8%A7%D9%84%D9%8A%D9%85%D9%86-%D8%A7%D9%84%D8%B3%D8%B9%D9%8A%D8%AF-%D8%AC%D9%88%D9%84%D8%A9-%D8%B3%D9%8A%D8%A7%D8%AD%D9%8A%D8%A9-%D9%85%D8%B5%D9%88%D8%B1%D8%A9-%D8%AC2.html http://rehlat-world.com/%D8%A7%D9%84%D9%8A%D9%85%D9%86-%D8%A7%D9%84%D8%B3%D8%B9%D9%8A%D8%AF-%D8%AC%D9%88%D9%84%D8%A9-%D8%B3%D9%8A%D8%A7%D8%AD%D9%8A%D8%A9-%D9%85%D8%B5%D9%88%D8%B1%D8%A9-%D8%AC2.html?replytocom=37 same reslut but change in the last of like "?replaytocom=37" WHY?
The problem is that your author pages are marked with the noindex tag, look at the page source: It must be a plugin that is doing that, that is not the default setting. If you don't want the duplicate pages, try a plugin like Yoast WordPress SEO that let you add Nofollow to comment links.
I have two problems ( SEO )
wordpress
I'm working on a site that is going to be community powered. It's going to have the form for registered users to submit draft posts, which will then be approved or deleted by the site's editors. The way I'm trying to implement it is with a custom page template, which includes a form that will allow people to submit draft posts for review. I was wondering if anyone could point me to some code that does this and that works. I have tried searching, but so far the code I'm finding isn't working. I'm using wordpress 3.1 Thanks :)
http://voodoopress.com/2011/03/how-to-post-from-your-front-end-with-no-plugin/ I just finished a series of posts on it. Making the form work, adding custom meta boxes, adding images. Everything works on it (except validation). I'll be getting the validation thing figured out better soon. But the code I share is gleaned from a variety of posts on this site. Sure, I'll copy the reply to an answer. (I made it a comment rather than answer as I felt I was being a bit lazy just giving a link, and the form isn't 100%. Everything works great as far as posting, etc. I just can't get validation working quite right)
Front End Post Submit Form
wordpress
OK, there have been several posts on here about frontend posting forms. I've read them all, which got me to where I am. Now every form I come across has some form of validation which seems to check for a value for the fields you want to make required. I've tried them, and I can't get anything to work. I just can't make any fields required. Everything else about the form is perfect. But I would love to enforce my required fields (bonus for appropriate error messages). I've tried looking around on the google, I don't really think JS is what I want to use for this. And any other php validation I can't seem to make work either. I'm sure I'm incorporating them wrong somehow. Here's what I have: http://pastebin.com/rw4c6jZQ (full template lines 9-19 are supposed to be validation) MY processing script at the to of the template: <code> &lt;?php if( 'POST' == $_SERVER['REQUEST_METHOD'] &amp;&amp; !empty( $_POST['action'] ) &amp;&amp; $_POST['action'] == "new_post") { // Do some minor form validation to make sure there is content if (isset ($_POST['title'])) { $title = $_POST['title']; } else { echo 'Please enter the wine name'; } if (isset ($_POST['description'])) { $description = $_POST['description']; } else { echo 'Please enter some notes'; } $tags = $_POST['post_tags']; $winerating = $_POST['winerating']; // ADD THE FORM INPUT TO $new_post ARRAY $new_post = array( 'post_title' =&gt; $title, 'post_content' =&gt; $description, 'post_category' =&gt; array($_POST['cat']), // Usable for custom taxonomies too 'tags_input' =&gt; array($tags), 'post_status' =&gt; 'publish', // Choose: publish, preview, future, draft, etc. 'post_type' =&gt; 'post', //'post',page' or use a custom post type if you want to 'winerating' =&gt; $winerating ); //SAVE THE POST $pid = wp_insert_post($new_post); //KEEPS OUR COMMA SEPARATED TAGS AS INDIVIDUAL wp_set_post_tags($pid, $_POST['post_tags']); //REDIRECT TO THE NEW POST ON SAVE $link = get_permalink( $pid ); wp_redirect( $link ); //ADD OUR CUSTOM FIELDS add_post_meta($pid, 'rating', $winerating, true); //INSERT OUR MEDIA ATTACHMENTS if ($_FILES) { foreach ($_FILES as $file =&gt; $array) { $newupload = insert_attachment($file,$pid); // $newupload returns the attachment id of the file that // was just uploaded. Do whatever you want with that now. } } // END THE IF STATEMENT FOR FILES } // END THE IF STATEMENT THAT STARTED THE WHOLE FORM //POST THE POST YO do_action('wp_insert_post', 'wp_insert_post'); </code> The form and everything else can be seen in the pastebin to see it all in context. Thanks much!
The best way to do form validation is with a combination of JavaScript and PHP. The reason why you want to perform JavaScript validation is to give the users a chance to correct their errors without submitting the form. Plus, it will stop any casual mistakes. You will also want to ensure validation on the back-end in case JavaScript is turned off. Either way, sanitizing your data should be part of this process. Use any of these WordPress functions to help you there: Data Validation . For JavaScript validation, I recommend the jQuery Validation plugin . It's super easy to implement and customize. As for your PHP validation, you can try adding this to check for empty values: <code> $_POST['title'] != '' </code>
Frontend Post Form Validation
wordpress
I'm working with a blank theme and my nav.php looks like this <code> &lt;div class="navigation"&gt; &lt;div class="next-posts" style="float: left;"&gt;&lt;?php next_posts_link('&amp;laquo; Older Entries') ?&gt;&lt;/div&gt; &lt;div class="prev-posts" style="float: right;"&gt;&lt;?php previous_posts_link('Newer Entries &amp;raquo;') ?&gt;&lt;/div&gt; </code> My question is, how do I change the text links into image links?
Maybe my (edu) plugin can help you understanding the ways that are possible to display pagination a little better. I updated it after reading your Q. You can now more easily style your links. Just add your buttons as background-images to the stylesheet.
adding images to wordpress pagination?
wordpress
I have a main page that consists of 7 categories being output by wp_list_categories, each li specifically includes one ID. These categories are directed to a category-page.php specifically built for each category. Now, each category has sub categories. So on each of the category pages, I want to build out custom queries for each sub category. Example: the Weightloss category on the main page, links to the category-weightloss.php page. Within Weightloss, there are six sub categories. What is the best way, to create six different queries, in seperate div's, so I can style them? I have looked over WP_Query, but I am not sure of the best, and most appropriate, way to do this.
I figured this out on my own. I use the code below and duplicated it as many times as I needed without any issues so far. If anyone thinks this is incorrect than please comment. I was not using the main loop anywhere else on this page and used WP_Query. <code> &lt;ul class="subcats-list"&gt; &lt;?php $weightloss = new WP_Query(); $weightloss-&gt;query('showposts=5'); while ($weightloss-&gt;have_posts()) : $weightloss-&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>
Creating mulitple loops in a sub-category page
wordpress
I'm using <code> admin_footer-{$hook_suffix} </code> to selectively print scripts on the new post page and comments page. This hook is depreciated in 3.1. I see there's an <code> admin_print_scripts-{$hook_suffix} </code> but this does not print to the footer, rather to the header before any jQuery or other stuff is loaded. How can I selectively print scripts to the footer of certain admin pages?
There's an <code> in_footer </code> parameter that you can pass to wp_enqueue_scripts - does that work? I would hook to <code> admin_enqueue_scripts </code> , check the $page for location, and enqueue your script there, with 'in_footer' as true. Example: <code> add_action( 'admin_enqueue_scripts', 'enqueue_my_script' ); function enqueue_my_script( $page ) { if ($page !== 'edit.php') return; wp_enqueue_script( 'my-script', 'http://path/to/my/local/script', null, null, true ); } </code>
How can I selectively print scripts to the footer of certain admin pages?
wordpress
When creating a new post, by entering either manually or pasting from another document, TinyMCE (the default WordPress editor) does not seem to hold any type of formatting. For instance I create a two paragraph entry. When viewing it on the page it will come through as a single chunk of text within <code> &lt;div class="entry-content"&gt; </code> . It's forcing me to have to revisit posts quite a bit and manually entering paragraph tags <code> &lt;p&gt; </code> . I'm unsure what's causing this issue. Any help would be appreciated.
TinyMCE - at least, as-configured for WordPress - isn't explicitly designed for copying/pasting of text richly formatted in other word processors. That said: how are you pasting? Are you simply copy/pasting (i.e. via CTRL-C, CTRL-V; or else via right-clicking and using contextual menu commands), or are you using the "Paste From Word" button on the TinyMCE toolbar? If you're not using the "Paste From Word" button, please give it a try: 1) On the TinyMCE toolbar, click the "Kitchen Sink" button (last button on the right, on the top row of buttons) 2) Additional rows of buttons will appear 3) On the second row of buttons, click the "Paste From Word" button (the icon is a clipboard with a "Word" icon, "W") EDIT: Are you removing the wpautop() filter? Look for something like this in functions.php: <code> remove_filter( 'the_content', 'wpautop' ); </code> That would definitely cause the line-break issue you're seeing.
Wordpress no longer holding post formatting
wordpress
I have a custom metabox made using the code from Wordpress Reference: http://codex.wordpress.org/Function_Reference/add_meta_box <code> &lt;?php /* Define the custom box */ // WP 3.0+ // add_action('add_meta_boxes', 'myplugin_add_custom_box'); // backwards compatible add_action('admin_init', 'myplugin_add_custom_box', 1); /* Do something with the data entered */ add_action('save_post', 'myplugin_save_postdata'); /* Adds a box to the main column on the Post and Page edit screens */ function myplugin_add_custom_box() { add_meta_box( 'myplugin_sectionid', __( 'My Post Section Title', 'myplugin_textdomain' ), 'myplugin_inner_custom_box', 'post' ); add_meta_box( 'myplugin_sectionid', __( 'My Post Section Title', 'myplugin_textdomain' ), 'myplugin_inner_custom_box', 'page' ); } /* Prints the box content */ function myplugin_inner_custom_box() { // Use nonce for verification wp_nonce_field( plugin_basename(__FILE__), 'myplugin_noncename' ); // The actual fields for data entry echo '&lt;label for="myplugin_new_field"&gt;'; _e("Description for this field", 'myplugin_textdomain' ); echo '&lt;/label&gt; '; echo '&lt;input type="text" id="myplugin_new_field" name="myplugin_new_field" value="whatever" size="25" /&gt;'; } /* When the post is saved, saves our custom data */ function myplugin_save_postdata( $post_id ) { // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename(__FILE__) ) ) return $post_id; // verify if this is an auto save routine. // If it is our form has not been submitted, so we dont want to do anything if ( defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE ) return $post_id; // Check permissions if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id ) ) return $post_id; } else { if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id; } // OK, we're authenticated: we need to find and save the data $mydata = $_POST['myplugin_new_field']; // Do something with $mydata // probably using add_post_meta(), update_post_meta(), or // a custom table (see Further Reading section below) return $mydata; } ?&gt; </code> And I'm not sure how to display it's value on each page? <code> &lt;?php $meta = get_post_meta($post-&gt;ID, 'myplugin_new_field'); var_dump($meta); ?&gt; </code> Gives: array(0) {} In addition, metabox field doesn't update it's value after clicking updating post/or page. That's because input value="whathever" while it should be something like the code above. Any ideas? Thank you! [edit] Final code that is not updating inputs value: <code> /* Define the custom box */ add_action('add_meta_boxes', 'myplugin_add_custom_box'); // backwards compatible add_action('admin_init', 'myplugin_add_custom_box', 1); /* Do something with the data entered */ add_action('save_post', 'myplugin_save_postdata'); /* Adds a box to the main column on the Post and Page edit screens */ function myplugin_add_custom_box() { add_meta_box( 'metabox_sidebar_select', __( 'My Post Section Title', 'myplugin_textdomain' ), 'myplugin_inner_custom_box', 'post' ); add_meta_box( 'metabox_sidebar_select', __( 'My Post Section Title', 'myplugin_textdomain' ), 'metabox_sidebar_select', 'page' ); } /* Prints the box content */ function myplugin_inner_custom_box() { // Use nonce for verification wp_nonce_field( plugin_basename(__FILE__), 'myplugin_noncename' ); // The actual fields for data entry echo '&lt;label for="myplugin_new_field"&gt;'; _e("Description for this field", 'myplugin_textdomain' ); echo '&lt;/label&gt; '; echo '&lt;input type="text" id="myplugin_new_field" name="myplugin_new_field" value="'.get_post_meta($post-&gt;ID, 'myplugin_new_field',true).'" size="25" /&gt;'; } /* When the post is saved, saves our custom data */ function myplugin_save_postdata( $post_id ) { // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename(__FILE__) ) ) return $post_id; // verify if this is an auto save routine. // If it is our form has not been submitted, so we dont want to do anything if ( defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE ) return $post_id; // Check permissions if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id ) ) return $post_id; } else { if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id; } // OK, we're authenticated: we need to find and save the data $mydata = $_POST['myplugin_new_field']; // Do something with $mydata // probably using add_post_meta(), update_post_meta(), or // a custom table (see Further Reading section below) global $post; update_post_meta($post-&gt;ID, myplugin_new_field, $mydata); return $mydata; } </code>
there is you answer, in your code where it says: // Do something with $mydata probably using add_post_meta(), update_post_meta(), or a custom table (see Further Reading section below) you need to actually insert/update the data to the database so add something like: <code> global $post; update_post_meta($post-&gt;ID, 'myplugin_new_field', $mydata); </code> and the data will be saved so you could get it using your code: <code> $meta = get_post_meta($post-&gt;ID, 'myplugin_new_field'); </code> and the only other change you need is in the function that displays the metabox change: <code> echo '&lt;input type="text" id="myplugin_new_field" name="myplugin_new_field" value="whatever" size="25" /&gt;'; </code> to <code> echo '&lt;input type="text" id="myplugin_new_field" name="myplugin_new_field" value="'.get_post_meta($post-&gt;ID, 'myplugin_new_field',true).'" size="25" /&gt;'; </code> Update: To answer your question in the comments: to save a select list you save it just the save way as a text input and to display the previously selected option in the meta box you just loop over the option and see what was selected and you add "selected" attribute. for example : <code> //get last selected value if exists $selected = get_post_meta($post-&gt;ID, 'myplugin_new_select_field',true); echo '&lt;select name="myplugin_new_select_field"&gt;'; $x = 0; while ($x &lt; 4){ echo '&lt;option value="'.$x.'"'; //check if the last value is the same is current value. if ($x == $selected) echo ' selected="selected"'; echo '&gt;'.$x.'&lt;/option&gt;'; } echo '&lt;/select&gt;'; </code>
Getting metabox value?
wordpress
So, I've read through stackexchange-url ("this question") about licensing of PHP code under the GPL v2. As well as the compromise of the Thesis theme developer, as far as licensing all PHP under the GPL, but copyrighting js, css, images, etc. My question is does ALL php have to be GPL? Consider this scenario: the php that generates the wp content/layout is under GPL the JS is copyrighted (similar to the question linked above) the JS makes AJAX requests to php code that generates certain data this data-generating php code uses it's own datalayer (not wordpress's) and uses no wordpress code. Can the data-generating php (separated into a different folder within the theme) be licensed other than GPL?
The data generating PHP, if it truly stands alone and doesn't use any WordPress code or WordPress' data layer, can be licensed as a standalone library. You can use any license you want here without any problems. The only issues come when you start distributing your code. If you want your theme hosted in the theme repository on WordPress.org, it must be GPL-compatible. That means you have to use either GPL or a more permissible license on your extra library ... If you're distributing things yourself, you just have to make a very clear distinction between the parts of the theme that are GPL and the parts that aren't. But since you'll be bundling a part that's not GPL, you can't distribute the entire package as GPL. So no, all PHP does not have to be GPL unless you're distributing the entire package under the terms of the GPL.
Premium theme licensing of php called through AJAX
wordpress
hey guys, quick question. I'm using jquery for my current project (the latest release). A few plugins I'm using are using jquery as well and they are inserted through wp_head(). Since I want my website to ber fairly slim and fast this redundant scripts should be removed. is there any way I can filter for the string "jquery.js" in wp_head() and remove the tag that embeds the script? As you can see in the following screenshot jquery.js wouldn't be needed. Can I remove that with a hook?
There's no filter that covers the entire output produced during wp_head(). You would have to use a fairly complicated process of output buffering starting before wp_head, then filtering out what you don't want afterwards, before releasing the buffer. Lets assume that you're dealing with plugins that have registered their scripts properly> Try adding this to your functions.php and then viewing source of one of your pages: <code> add_action('wp_head', 'debug_scripts_queued'); function debug_scripts_queued() { global $wp_scripts; echo '&lt;!--- SCRIPTS QUEUED'."\r\n"; foreach ( $wp_scripts-&gt;queue as $script ) { echo "\r\nSCRIPT: ".$script."\r\n"; $deps = $wp_scripts-&gt;registered[$script]-&gt;deps; if ($deps) { echo "DEPENDENCIES: "; print_r($deps); } } echo "\r\n---&gt;"; } </code> That will list all the scripts actually registered, and their dependencies. If what you want to deregister is in that list, and not being called as a dependency of another script, the easiest thing to do is just call <code> wp_deregister_script </code> with the handle listed here. Most likely, though, you're dealing with a case where a plugin didn't follow best practices in adding a script. What it looks like from your output is that some plugin added jQuery 1.5 without first deregistering jquery and reregistering it with the different version. so anything that depends on jquery is forcing an include of the version bundled in WP.
wp_head() remove redundant scripts?
wordpress
<code> wp_list_pages('title_li=&amp;depth=&amp;exclude='); </code> lists all pages of my site. If there are childpages of a certain page the output looks like this: <code> &lt;li class="page_item page-item-2"&gt; &lt;a href="http://domain.com/about" title="About"&gt;About&lt;/a&gt; &lt;ul class="children"&gt; &lt;li class="page_item page-item-29"&gt; &lt;a href="http://domain.com/about/subpage" title="Subpage"&gt;Subpage&lt;/a&gt; &lt;ul class="children"&gt; &lt;li class="page_item page-item-39"&gt;&lt;a href="http://domain.com/about/subpage/subsub" title="SubSub"&gt;SubSub&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; </code> Is there a simple trick to print childpages without seperate 's so that the output looks like this: <code> &lt;li class="page_item page-item-2"&gt; &lt;a href="http://domain.com/about" title="About"&gt;About&lt;/a&gt; &lt;/li&gt; &lt;li class="page_item page-item-29"&gt; &lt;a href="http://domain.com/about/subpage" title="Subpage"&gt;Subpage&lt;/a&gt; &lt;/li&gt; &lt;li class="page_item page-item-39"&gt;&lt;a href="http://domain.com/about/subpage/subsub" title="SubSub"&gt;SubSub&lt;/a&gt; &lt;/li&gt; </code> I need that version just for a specific part of my page so it shouldn't be a filter that is added to wp_list_pages(). Any idea how to accomplish that?
you can use get_pages() function, something like this: <code> $mypages = get_pages(); echo '&lt;ul&gt;'; foreach($mypages as $page){ echo '&lt;li class="page_item page-item-'.$page-&gt;ID.'"&gt;&lt;a href="'.get_page_link($page-&gt;ID).'"&gt;'.$page-&gt;post_title.'&lt;/a&gt;&lt;/li&gt;'; } echo '&lt;/ul&gt;'; </code>
list child-pages as normal pages?
wordpress
hey guys, weird situation... I'm trying to use wp_ajax() for the first time. I'm normally using a normal jQuery ajax request but in my current case I get a lot of bugs so I thought about trying wp_ajax(). I don't get it though! The following piece of code... <code> // embed the javascript file that makes the AJAX request wp_enqueue_script( 'my-ajax-request', plugin_dir_url( __FILE__ ) . 'js/ajax.js' ); // declare the URL to the file that handles the AJAX request (wp-admin/admin-ajax.php) wp_localize_script( 'my-ajax-request', 'MyAjax', array( 'ajaxurl' =&gt; admin_url( 'admin-ajax.php' ) ) ); </code> ends in... <code> &lt;script type="text/javascript" src="http://example.com/wordpress/wp-content/plugins/myajax/js/ajax.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; /* &lt;![CDATA[ */ var MyAjax = { ajaxurl: "http://example.com/wordpress/wp-admin/admin-ajax.php" }; /* ]]&gt; */ </code> However I don't have a plugin or anything that should use this, but my whole page has to do this ajax request. Therefore the entire first line with <code> wp_enqueue_script() </code> doesn't make sens. I don't need to load a specific js-file for this because I have already my entire <code> script.js </code> file manually embedded in my <code> &lt;head&gt; </code> section. This is where the ajax request gets fired. However once I leave this line out ( <code> //wp_enqueue_script()... </code> ) the second part doesn't work. So there will no <code> &lt;script type="text/javascript"&gt; /* &lt;![CDATA[ */ var MyAjax = { ajaxurl: "http://example.com/wordpress/wp-admin/admin-ajax.php" }; /* ]]&gt; */ </code> be printed into my section of my page. What am I getting wrong here? I really need to be able to fire a ajax request from within my normal script.js file. Any ideas? update: my script.js file (manually emebedded in my should call a an ajax request: <code> var response; $.post( // see tip #1 for how we declare global javascript variables MyAjax.ajaxurl, { // here we declare the parameters to send along with the request // this means the following action hooks will be fired: // wp_ajax_nopriv_myajax-submit and wp_ajax_myajax-submit action : 'wp_ajax_nopriv_searchmap', }, function( response ) { $sr.html(response); </code> the function in my functions.php file I want to call looks like this: <code> // embed the javascript file that makes the AJAX request wp_enqueue_script( 'my-ajax-request', plugin_dir_url( __FILE__ ) . 'js/ajax.js' ); // declare the URL to the file that handles the AJAX request (wp-admin/admin-ajax.php) wp_localize_script( 'my-ajax-request', 'MyAjax', array( 'ajaxurl' =&gt; admin_url( 'admin-ajax.php' ) ) ); // this hook is fired if the current viewer is not logged in if (isset($_GET['action'])) { do_action( 'wp_ajax_nopriv_' . $_GET['action'] ); } // if logged in: if (isset($_POST['action'])) { do_action( 'wp_ajax_' . $_POST['action'] ); } if(is_admin()) { add_action( 'wp_ajax_searchmap', 'my_searchmap_function' ); } else { add_action( 'wp_ajax_nopriv_searchmap', 'my_searchmap_function' ); } function my_searchmap_function() { // Start output buffer ob_start(); ?&gt; div&gt; &lt;h3&gt;Pages&lt;/h3&gt; &lt;ul&gt; &lt;?php wp_list_pages('title_li=&amp;depth=0&amp;exclude='); ?&gt; &lt;/ul&gt; &lt;h3&gt;Posts&lt;/h3&gt; &lt;?php $first = 0;?&gt; &lt;ul&gt; &lt;?php $myposts = get_posts('numberposts=-1&amp;offset=$first'); foreach($myposts as $post) : ?&gt; &lt;li&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;?php endforeach; ?&gt; &lt;/ul&gt; &lt;h3&gt;Categories&lt;/h3&gt; &lt;ul&gt; &lt;?php wp_list_categories('title_li=&amp;orderby=name'); ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;?php $output = ob_get_contents(); // Stop output buffer ob_end_clean(); $response = json_encode($output); // response output header( "Content-Type: application/json" ); echo $response; // IMPORTANT: don't forget to "exit" exit; } </code> What do I missunderstand here? I simply want to be able to request data via ajax from within my normal javascript file. I need to process the html that comes back in my javascript file. Any idea what I'm doing wrong or better, what I have to do in order to make this work?
Ok, firstly let me just break it down a little, so you understand the purpose of these functions. wp_enqueue_script() Description: A safe way of adding javascripts to a WordPress generated page. Basically, include the script if it hasn't already been included, and load the one that WordPress ships. wp_localize_script() Description: Localizes a script, but only if script has already been added. Can also be used to include arbitrary Javascript data in a page. When you localize a script, all you're doing is setting up an action that prints out Javascript vars into the page, but these vars are tied to the script you register them to, it's the first parameter you pass to <code> wp_localize_script </code> and is otherwise known as the script handle . <code> wp_enqueue_script </code> is for queuing a javascript file, and <code> wp_localize_script </code> is designed to accompany scripts loaded via the enqueue system. You cannot localize nothing, so if you're not enqueuing, <code> wp_localize_script </code> is of no use to you here. Typically you'd likely use the two like this.. <code> $myvars = array( 'ajaxurl' =&gt; admin_url( 'admin-ajax.php' ), 'somevar1' =&gt; $somevar_from_somewhere, 'somevar2' =&gt; $somevar_from_elsewhere ); wp_enqueue_script( 'my-ajax-request', plugins_url( '/path/to/somefile.js', __FILE__ ) ); wp_localize_script( 'my-ajax-request', 'MyAjax', $myvars ); </code> Which then produces the following output in your page.. <code> &lt;script type="text/javascript" src="path/to/somefile.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; /* &lt;![CDATA[ */ var MyAjax = { ajaxurl: "http://example.com/wordpress/wp-admin/admin-ajax.php", somevar1: "somevalue", somevar2: "someothervalue" }; /* ]]&gt; */ &lt;/script&gt; </code> Which you can then reference in your script, eg. <code> jQuery(document).ready( function($) { alert( MyAjax.somevar1 ); // Produces somevalue alert( MyAjax.somevar2 ); // Produces someothervalue }); </code> Throwing this all together, your code could go a little something like this.. <code> // Setup the ajax callback for the "searchmap" action add_action( 'wp_ajax_searchmap', 'my_searchmap_function' ); add_action( 'wp_ajax_nopriv_searchmap', 'my_searchmap_function' ); // The callback function for the "searchmap" action function my_searchmap_function() { $myposts = get_posts('numberposts=-1&amp;offset=$first'); ?&gt; &lt;div&gt; &lt;h3&gt;Pages&lt;/h3&gt; &lt;ul&gt; &lt;?php wp_list_pages('title_li=&amp;depth=0&amp;exclude='); ?&gt; &lt;/ul&gt; &lt;h3&gt;Posts&lt;/h3&gt; &lt;ul&gt; &lt;?php foreach( $myposts as $post ) : setup_postdata( $post ); ?&gt; &lt;li&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;?php endforeach; ?&gt; &lt;?php wp_reset_postdata(); ?&gt; &lt;/ul&gt; &lt;h3&gt;Categories&lt;/h3&gt; &lt;ul&gt; &lt;?php wp_list_categories('title_li=&amp;orderby=name'); ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;?php die; } </code> The JS .. (assuming it was enqueued and localized) <code> jQuery(document).ready(function($) { $('a.myajax').click(function(){ var data = { action: 'searchmap' // &lt;--- this is the correct action name }; $.post( MyAjax.ajaxurl, data, function(response) { $('#myresult').html(response); }); return false; }); }); </code> And then the actual HTML needed in the page to trigger the action.. <code> &lt;a class="myajax" href="#"&gt;Click me to fetch ajax content&lt;/a&gt; &lt;div id="myresult"&gt;&lt;/div&gt; </code> Actual Answer With regard to needing to do your own thing, and get vars printed out for your script, i'd suggest doing something like this... <code> add_action( 'wp_head', 'my_js_vars', 1000 ); function my_js_vars() { // If it's not a specific page, stop here if( !is_page( 'my-page-with-ajax' ) ) return; ?&gt; &lt;script type="text/javascript"&gt; /* &lt;![CDATA[ */ var MyAjax = { ajaxurl: '&lt;?php admin_url('admin-ajax.php'); ?&gt;', somevar: 'somevalue', someothervar: 'someothervalue' }; /* ]]&gt; */ &lt;/script&gt; &lt;?php /* NOTE: Make sure not to leave a comma after the last item in the JS array, else IE(Internet Explorer) will choke on the JS. */ } </code> I left code that i previously posted for the sake of others reading.
wp_ajax() question.. not using wp_enqueue_script?
wordpress
I'm looking for a way to pull in photo albums from a Facebook Fan Page into a Wordpress site and have the photos open up in a Lightbox with Facebook comments. I've found a few plugins but nothing quite like what I'm looking for and I haven't seem any with comments. Anyone know whether this is possible? Thanks
I use Facebook Photo Fetcher to share all photos from my facebook fan page to wordpress(organizing by Album is not yet available). It works well except you need to refresh the code after every upload of new photos to facebook fan page, it's not automatic. Unfortunately for me, This plugin doesn't do what I want it to do... which is to display photos from my facebook fan page that my guests are posting (I don't post many photos).
Display Facebook photo albums and photo comments?
wordpress
I've come across a small bug with my yoast breadcrumbs. I've rebuilding a site and have imported some old posts and content and have come across a problem where yoast things the permalinks are still the old ones. I've flushed out all the old categories and tags, etc and have used flush_rewrite_rules() to try and fix it which has resulted in some broken links. Am I missing something in the DB?
There seems to be a bug in the Yoast Plugin, which was fixed by switching on to the NavXT Plugin to do breadcrumbs instead.
Posts picking up old Permalinks, how to reset?
wordpress
Is it possible, to search just for tags? Not any other taxonomies or post types, just tag titles.
Yes its very possible, you just need to create your own search form and processing function form: <code> &lt;form name="tag-search" method="POST" action=""&gt; &lt;input type="text" vlaue="" name="tag-q" id="tag-q"&gt; &lt;input type="submit" name="tag-submit" id="tag-submit" value="Search Tags"&gt; &lt;/form&gt; </code> processing: <code> &lt;?php if (isset($_POST['tag-submit']) &amp;&amp; $_POST['tag-submit'] == "Search Tags" &amp;&amp; isset($_POST['tag-q']) &amp;&amp; $_POST['tag-q'] != ""){ // @todo Sanity check and cleanup $_POST['tag-q'] here. $args = array('name__like' =&gt; $_POST['tag-q']); $tags = get_tags($args); $html = '&lt;div class="post_tags_search_r"&gt;'; foreach ($tags as $tag){ $tag_link = get_tag_link($tag-&gt;term_id); $html .= "&lt;a href='{$tag_link}' title='{$tag-&gt;name} Tag' class='{$tag-&gt;slug}'&gt;"; $html .= "{$tag-&gt;name}&lt;/a&gt;"; } $html .= '&lt;/div&gt;'; echo $html; } ?&gt; </code> No this is something i have used in the past, the only downside to this is that <code> name__like </code> is case-insensitive so you might want to add the strtolower version to the name__like.
Search for tags
wordpress
I noticed ShareDaddy has "Show sharing buttons on this post" for default post types but not for custom post types. I'm guessing I need to add something in <code> 'supports' =&gt; array('title','editor','thumbnail') </code> . Does anybody know what I need to add in order for "Show sharing buttons on this post" to show up for custom post types?
ShareDaddy uses two filter hooks either <code> the_content </code> or <code> the_excerpt </code> this means that your custom post type theme template file has to use one of these two functions <code> the_content(); </code> or <code> the_excerpt(); </code> . Update Ok I guess i didn't get the question. So to add the metabox to your custom post type add this: <code> // Hook things in, late enough so that add_meta_box() is defined and make sure you already registered you post type. if (is_admin()){ add_action( 'admin_init', 'add_plugin_meta_boxes' ); add_action( 'save_post', 'save_sharing_box' ); } // This function tells WP to add the sharing "meta box" function add_plugin_meta_boxes() { add_meta_box( 'sharing_meta', __( 'Sharing', 'sharedaddy' ), 'sharing_meta_box_content', 'CUSTOM POST TYPE NAME', 'advanced', 'high' ); } function save_sharing_box( $post_id ) { if ( defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE ) return $post_id; // Record sharing disable if ( 'CUSTOM POST TYPE NAME' == $_POST['post_type'] ) { if ( current_user_can( 'edit_post', $post_id ) ) { if ( isset( $_POST['sharing_status_hidden'] ) ) { if ( !isset( $_POST['enable_post_sharing'] ) ) update_post_meta( $post_id, 'sharing_disabled', 1 ); else delete_post_meta( $post_id, 'sharing_disabled' ); } } } return $post_id; } </code> and change <code> CUSTOM POST TYPE NAME </code> to you actual custom post type name.
Jetpack plugin (ShareDaddy): Prevent share buttons showing on custom post types?
wordpress
The original urls for users look like <code> /author/login/ </code> Is it possible to replace login by user's id? In my dream urls should become to <code> /users/34/ </code> (34 is user id). Thanks.
you need 3 simple functions and hooks first change the author base: <code> //change author/username base to users/userID function change_author_permalinks() { global $wp_rewrite; // Change the value of the author permalink base to whatever you want here $wp_rewrite-&gt;author_base = 'users'; $wp_rewrite-&gt;flush_rules(); } add_action('init','change_author_permalinks'); </code> then add users to query_vars: <code> add_filter('query_vars', 'users_query_vars'); function users_query_vars($vars) { // add lid to the valid list of variables $new_vars = array('users'); $vars = $new_vars + $vars; return $vars; } </code> then add the new rewrite rule: <code> function user_rewrite_rules( $wp_rewrite ) { $newrules = array(); $new_rules['users/(\d*)$'] = 'index.php?author=$matches[1]'; $wp_rewrite-&gt;rules = $new_rules + $wp_rewrite-&gt;rules; } add_filter('generate_rewrite_rules','user_rewrite_rules'); </code> Now if you don't know how to use this, just copy all of the code and paste in your theme's functions.php file.
Change author permalink
wordpress
I heard many times, that WordpPess's search doesn't work good. Are there any other search engines available for wordpress? I know about sphynx, seems its a good one, but available plugins are out of date. Thanks.
WordPress › Relevanssi - A Better Search « WordPress Plugins Key features: Search results sorted in the order of relevance, not by date. Fuzzy matching: match partial words, if complete words don't match. Find documents matching either just one search term (OR query) or require all words to appear (AND query). Search for phrases with quotes, for example "search phrase". Create custom excerpts that show where the hit was made, with the search terms highlighted. Highlight search terms in the documents when user clicks through search results. Search comments, tags, categories and custom fields. Advanced features: Adjust the weighting for titles, tags and comments. Log queries, show most popular queries and recent queries with no hits. Restrict searches to categories and tags using a hidden variable or plugin settings. Index custom post types and custom taxonomies. Index the contents of shortcodes. Google-style "Did you mean?" suggestions based on successful user searches. Automatic support for WPML multi-language plugin Advanced filtering to help hacking the search results the way you want.
How to improve WordPress search
wordpress
I have modified the buddpress admin bar by creating the following plugin which adds a simple text link to the bar: <code> function bp_adminbar_currentsite_menu() { global $bp; ?&gt; &lt;li&gt; &lt;!-- Insert your link url or relative url, and your link text below --&gt; &lt;a href="http://EXAMPLE.COM"&gt;EXAMPLE LINK TEXT&lt;/a&gt; &lt;/li&gt; &lt;?php } // Call The Function Above add_action('bp_adminbar_menus', 'bp_adminbar_currentsite_menu', 999); </code> However, I do NOT want the above link to be shown when logged into the wordpress admin backend (so for example when an admin is editing a post). I thought about just doing a <code> php_self </code> check to see if it contained "/wp-admin/" but figured that there has to be a more elegant wordpress/buddypress hook here. How can I get the above code to only show when you are viewing a normal blog page, NOT in the admin area? Thanks
You ca use the conditional tag <code> is_admin() </code> to check if you are on the front-end or back-end like this: <code> function bp_adminbar_currentsite_menu() { global $bp; if (!is_admin()){ ?&gt; &lt;li&gt; &lt;!-- Insert your link url or relative url, and your link text below --&gt; &lt;a href="http://EXAMPLE.COM"&gt;EXAMPLE LINK TEXT&lt;/a&gt; &lt;/li&gt; &lt;?php } } // Call The Function Above add_action('bp_adminbar_menus', 'bp_adminbar_currentsite_menu', 999); </code>
modify buddpress adminbar only in admin pages
wordpress
I have Wordpress 3.1 installed in a subdirectory of a shared hosting account, it's a linux server and mod_rewrite is enabled and working fine elsewhere. The contents of the .htaccess file disappear whenever I try and change the permalinks structure, leaving just the begin/end wordpress comments with nothing in between. I have no plug-ins installed. Thanks.
By default, this shouldn't be happening. My guess is that this is an oddity with your hosting provider. I would also guess that the <code> .htaccess </code> file is world writable. I would try making the <code> .htaccess </code> file mode <code> 644 </code> like so: <code> chmod 644 .htaccess </code> or by using your SFTP program of choice to make it only writable by Owner. Then, whenever you modify the permalinks settings, just copy and paste the results at the bottom of the permalinks page into the <code> .htaccess </code> file manually. Just as a note: having the <code> .htaccess </code> file world writable is a fairly substantial security issue on a shared hosting provider. Depending on how things are set up, it can be easy for someone on the same server to inject behaviours you don't want into your site by modifying this file. Edit: I had <code> 600 </code> originally, which works for me because I have the <code> .htaccess </code> file owned by the <code> www-data </code> user on my server... but I should have said something about that. As per the comment below, <code> 644 </code> or <code> 444 </code> makes more sense in most cases.
Wordpress 3.1 .htaccess contents keep dissappearing?
wordpress
I'm using <code> &lt;?php the_date('l jS F Y','&lt;h2&gt;','&lt;/h2&gt;'); ?&gt; </code> inside the loop in order to group/sort posts by date. This all works great but I would like to add a different class to the last post for each date, effectively seperating each date section. Does anybody know how to do this please? I can't seem to find anything! Many thanks, S. Code below: <code> &lt;?php while ( have_posts() ) : the_post(); ?&gt; &lt;?php the_date('l jS F Y','&lt;h2&gt;','&lt;/h2&gt;'); ?&gt; &lt;hr /&gt; &lt;div class="post"&gt; &lt;h3&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?&gt;" rel="bookmark"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h3&gt; &lt;?php the_excerpt(); ?&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;hr class="btm" /&gt; //want this to appear at the end of each date/section </code> Updated code based on Bainternet's answer below: <code> &lt;?php while ( have_posts() ) : the_post(); $curent_date = $post-&gt;post_date; $curent_date = substr($curent_date,0,strpos($curent_date," ")); $next_post = get_adjacent_post(false,'',false) ; if (!$next_post == ''){ $next_date = $next_post-&gt;post_date; $next_date = substr($next_date,0,strpos($next_date," ")); if ($next_date != $curent_date){ $hrbtm = '&lt;hr class="btm" /&gt;'; echo $hrbtm; } } else { $hrbtm = ''; } ?&gt; &lt;?php the_date('l jS F Y','&lt;h2&gt;','&lt;/h2&gt;'); ?&gt; </code> Then I echo <code> $hrbtm </code> just before the <code> endwhile </code> : <code> &lt;?php echo $hrbtm; ?&gt; &lt;?php endwhile; ?&gt; </code>
Its possible, you can get the next post date to compare using get_adjacent_post function change your code to this: <code> &lt;?php while ( have_posts() ) : the_post(); //hold current date $curent_date = $post-&gt;post_date; //fix the format to YYYY-MM-DD $curent_date = substr($curent_date,0,strpos($curent_date," ")); $next_post = get_adjacent_post(false,'',false) ; if (!$next_post == ''){ //get next post's date $next_date = $next_post-&gt;post_date; //fix the format to YYYY-MM-DD $next_date = substr($next_date,0,strpos($next_date," ")); if ($next_date != $curent_date){//last post of the date the_date('l jS F Y','&lt;h2 class="lats-of-date&gt;','&lt;/h2&gt;'); } }else{ the_date('l jS F Y','&lt;h2&gt;','&lt;/h2&gt;'); } ?&gt; &lt;hr /&gt; &lt;div class="post"&gt; &lt;h3&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?&gt;" rel="bookmark"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h3&gt; &lt;?php the_excerpt(); ?&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;hr class="btm" /&gt; </code>
Adding a class to last post in the_date
wordpress
we have set up a custom post type under the heading of custom post type along w/two custom taxonomies. (the following code has been added to our functions.php page:) add_action('init', 'create_seminar_post_type'); function create_seminar_post_type(){ register_post_type('seminars', <code> array( 'labels'=&gt; array( 'name' =&gt; 'Seminars', 'singular_name' =&gt; 'Seminar', 'add_new' =&gt; 'Add New Seminar', 'add_new_item' =&gt; 'Add New Seminar', 'edit' =&gt; 'Edit Seminars', 'edit_item' =&gt; 'Edit Seminar', 'new_item' =&gt; 'New Seminar', 'view' =&gt; 'View Seminar', 'view_item' =&gt; 'View Seminar', 'search_items' =&gt; 'Search Seminars', 'not_found' =&gt; 'No Seminars found', 'not_found_in_trash' =&gt; 'No Seminars found in Trash', 'parent' =&gt; 'Parent Seminar', ), 'supports' =&gt; array('title', 'editor', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'thumbnail', 'author', 'page-attributes'), 'public' =&gt;true, 'taxonomies' =&gt; array('post_tag', 'category') ) ); register_taxonomy ('trt', 'seminars', array( 'labels' =&gt;array( 'name' =&gt;'Total Running Time', 'singular_name' =&gt; 'Total Running Time', 'search_items' =&gt; 'Search Total Running Time', 'popular_items' =&gt; 'Popular Total Running Times', 'all_items' =&gt; 'All Running Times', 'parent_item' =&gt; 'Parent Running Time', 'edit_item' =&gt; 'Edit Running Time', 'update_item' =&gt; 'Update Running Time', 'add_new_item' =&gt; 'Add New Running Time', 'new_item_name' =&gt; 'New Running Time Name' ), 'hierarchical' =&gt; true, 'label' =&gt; 'Total Running Time')); register_taxonomy ('discs-in-set', 'seminars', array( 'labels' =&gt;array( 'name' =&gt;'# of Discs in Set', 'singular_name' =&gt; 'Total Discs in Set', 'search_items' =&gt; 'Search Discs in Set', 'popular_items' =&gt; 'Popular Discs in Set', 'all_items' =&gt; 'All Discs in Set', 'parent_item' =&gt; 'Parent Discs in Set', 'edit_item' =&gt; 'Edit Discs in Set', 'update_item' =&gt; 'Update Discs in Set', 'add_new_item' =&gt; 'Add New Discs in Set', 'new_item_name' =&gt; 'New Discs in Set' ), 'hierarchical' =&gt; false, 'public' =&gt; true, 'show_ui' =&gt; true, 'query_var' =&gt; 'discs-in-set', 'show_tagcloud' =&gt; true, )); </code> } and here's the code added w/the loop in our single-seminar page (derived from the single.php page): <code> &lt;?php $loop = new WP_Query( array( 'post_type' =&gt; 'seminars', 'posts_per_page' =&gt; 10 ) ); ?&gt; &lt;?php while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); ?&gt; &lt;?php the_title( '&lt;h2 class="entry-title"&gt;&lt;a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark"&gt;', '&lt;/a&gt;&lt;/h2&gt;' ); ?&gt; </code> what we'd like to have shown for each individual seminar is the seminar info, along w/the custom taxonomy info of running time and discs in set. But all that shows is the seminar post and its accompanying categories &amp; tags. what should I do to make this work? on a similar note, when viewing the seminars listing in the dashboard, it shows all the listings , with columns for title, author, categories, tags, comments and date. It would be nice to incorporate the custom taxonomies into this listing for the sake of simplicity. Can this be done w/custom taxonomies? Or is there a more direct mode in doing this? any help/insights are greatly appreciated.. don
For the dashboard post listing bit.... http://codex.wordpress.org/Plugin_API/Action_Reference/manage_posts_custom_column <code> // ADDS EXTRA INFO TO ADMIN MENU FOR PRODUCT POST TYPE add_filter("manage_edit-ve_products_columns", "voodoo_prod_edit_columns"); add_action("manage_posts_custom_column", "voodoo_prod_custom_columns"); function voodoo_prod_edit_columns( $columns ) { // Add the extra column for product categories instead of rebuilding the whole array $columns['prod_cat'] = "Product Category"; $columns['description'] = "Excerpt"; return $columns; } function voodoo_prod_custom_columns( $column ) { global $post; switch( $column ) { case "description": the_excerpt(); break; case "prod_cat": echo get_the_term_list( $post-&gt;ID, 'product_category', '', ', ', '' ); break; } } </code> I use this to add in 2 columns to my ve_products custom post type. the description column displays the excerpt, the prod_cat displays my custom taxonomy (product_category). Getting rid of: <code> $columns['description'] = "Excerpt"; </code> Would kill the excerpt portion and only bring in the taxonomy. You just have to swap in your own tax name. And also in the first filter, your own CPT (per the link I gave) As for your other question, are you just looking to spit out the taxonomy? I'm not sure, so I will just try to answer what I think you are asking. <code> &lt;?php // Let's find out if we have taxonomy information to display // Something to build our output in $taxo_text = ''; // Variables to store each of our possible taxonomy lists // This one checks for a Product Category classification $prodcat_list = get_the_term_list( $post-&gt;ID, 'product_category', '', ', ', '' ); // Add Product Category list if this post was so tagged if ( '' != $prodcat_list ) $taxo_text .= $prodcat_list; ?&gt; </code> I use this to store my taxonomy (product_category). I put this up at the top of my loop, above where I need to display the actual tax. Then I can spit it out using: <code> &lt;?php echo $taxo_text; ?&gt; </code> So the big block of code loads up the terms for product_category, and then echoing out taxo text spits out the terms, it behaves like the_category would. You would just need to swap in your tax name where I have product_category
showing custom taxonomies w/custom post type
wordpress