question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I'm dumping my entire WordPress database, changing all necessary references, and then importing it into another domain. Everything works fine, except my plugin settings are not being set in the new domain. Does anyone know if Wordpress saves plugin settings locally somewhere? Or a reason why it would activate all the plugins, but not set the settings? The plugins I am specifically having trouble with are Adminimize, Admin Menu Editor, and User Roles. This is the closest plugin I could find to solving the issue, but it doesn't work for Wordpress 3.1 - http://wordpress.org/extend/plugins/sk-wp-settings-backup/ Thanks in advance for any help you can give me.
Very likely your settings are there but during your find and replace in sql you may have corrupted the serialised options. If you are doing a mysql dump from site #1 and importing dump to database for site #2, you might want to use my WordPress migration script. Using the WordPress migration script you can have all the options updated with one click, migrating all your settings for plugins, themes, widgets and other options.
Exporting and importing my Wordpress database, but none of the plugin settings are importing
wordpress
I'm wondering how to write a list of sub-pages of actually visited page. So I have 2 pages and 3 sub-pages for each: <code> Colors [page] - Red [child of Colors - subpage] - Blue [child of Colors - subpage] - Green [child of Colors - subpage] Numbers [page] - One [child of Numbers - subpage] - Two [child of Numbers - subpage] - Three [child of Numbers - subpage] </code> And when user visits "Colors" page then my code outputs Red/Blue/Green and if he does vist Numbers it shows One/Two/Three. I'm sure wp_list_pages will do the thing easy, but I'm not sure about parameters.
easy just pass it the $id off which to get the children <code> global $id; wp_list_pages("title_li=&amp;child_of=$id"); </code> of if you want in the loop then <code> wp_list_pages("title_li=&amp;child_of=$post-&gt;ID"); </code>
Listing all sub-pages?
wordpress
So I'm having a weird issue that I've never seen. I have a search.php set up like this: <code> $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts($query_string . '&paged=' . $paged); if ( have_posts() ) : while ( have_posts() ) : the_post(); // post stuff endwhile; else: endif; pagination(); </code> If I use anything but the default permalink structure, it breaks the pagination and returns a 404 and the second page. Ant ideas?
Alright, I've solved the problem. Turns out that you should never use action="" for searchform.php. It will work perfectly fine in terms of search results, but it will break the pagination, when using 3.1. Instead, you should use for the form action.
Custom Permalinks Break Search Pagination
wordpress
Is it possible for Wordpress to work from two databases? The reason I ask is that we're approaching our 100mb limit for database size on our host (1and1) but have up to 100 databases, so what I was hoping to do is essentially 'add on' another database for when the limit is reached?
Yes, but that is out of quick and easy realm. See HyperDB in Codex and repository for starters.
Split WP install between 2 databases?
wordpress
Basically I have a custom post type of 'products' which has two taxonomies attached to it...the normal 'category' and a custom taxonomy called 'brands'. I have a page which is 'brand' specific. On this page I'd like to list all the 'categories' that have a 'product' in them with a term of the 'brand' whos page I'm on attached. Eg. say I'm on the "Nike" page. I want it to list all categories that have a 'product' in them with the 'brand' of "Nike" attached to them. My initial thoughts are to use get_categories but theres now way to define a specific taxonomy or 'brand'? <code> $categories = get_categories('orderby=name&amp;depth=1&amp;hide_empty=0&amp;child_of='.$cat); </code> Anyone done this before or knows a way to query the database directly to get the required results? Any help is much appreicated, Thanks
Hi @daveaspi: What you want to do is common but not well handled in WordPress core. There are probably ways to do it without custom SQL but I don't think they would scale for a large number of posts. Below is a function I wrote called <code> get_cross_referenced_terms() </code> that will get what you want, complete with an example how to use it. This following code can be placed in the root of your WordPress site in a <code> test.php </code> file to see it work. You can then copy the function <code> get_cross_referenced_terms() </code> into your theme's <code> functions.php </code> file or into a <code> .php </code> file of a plugin you might be working on: <code> &lt;?php include('wp-load.php'); $nike = get_term_by('slug','nike','brand'); // This here just to illustrate $terms = get_cross_referenced_terms(array( 'post_type' =&gt; 'product', 'related_taxonomy' =&gt; 'brand', 'term_id' =&gt; $nike-&gt;term_id, )); foreach($terms as $term) { echo "&lt;p&gt;{$term-&gt;name}&lt;/p&gt;"; } function get_cross_referenced_terms($args) { global $wpdb; $args = wp_parse_args($args,array( 'post_type' =&gt; 'post', 'taxonomy' =&gt; 'category', 'related_taxonomy' =&gt; 'post_tag', 'term_id' =&gt; 0, )); extract($args); $sql = &lt;&lt;&lt;SQL SELECT DISTINCT {$wpdb-&gt;terms}.*, COUNT(*) AS post_count FROM {$wpdb-&gt;terms} INNER JOIN {$wpdb-&gt;term_taxonomy} ON {$wpdb-&gt;terms}.term_id={$wpdb-&gt;term_taxonomy}.term_id INNER JOIN {$wpdb-&gt;term_relationships} ON {$wpdb-&gt;term_taxonomy}.term_taxonomy_id={$wpdb-&gt;term_relationships}.term_taxonomy_id INNER JOIN {$wpdb-&gt;posts} ON {$wpdb-&gt;term_relationships}.object_id={$wpdb-&gt;posts}.ID INNER JOIN {$wpdb-&gt;term_relationships} related_relationship ON {$wpdb-&gt;posts}.ID=related_relationship.object_id INNER JOIN {$wpdb-&gt;term_taxonomy} related_term_taxonomy ON related_relationship.term_taxonomy_id=related_term_taxonomy.term_taxonomy_id INNER JOIN {$wpdb-&gt;terms} related_terms ON related_term_taxonomy.term_id=related_terms.term_id WHERE 1=1 AND (related_term_taxonomy.taxonomy&lt;&gt;{$wpdb-&gt;term_taxonomy}.taxonomy OR related_terms.term_id&lt;&gt;{$wpdb-&gt;terms}.term_id) AND {$wpdb-&gt;posts}.post_type='%s' AND {$wpdb-&gt;term_taxonomy}.taxonomy='%s' AND related_term_taxonomy.taxonomy='%s' AND related_terms.term_id=%d GROUP BY {$wpdb-&gt;terms}.term_id SQL; $sql = $wpdb-&gt;prepare($sql,$post_type,$taxonomy,$related_taxonomy,$term_id); $terms = $wpdb-&gt;get_results($sql); return $terms; } </code>
get_categories for custom post type with a specific custom taxonomy attached
wordpress
(repost from Theme Hybrid Community ) Let's assume a plugin or multiple-plugins are hosted on WordPress.org. Can you automatically activate plugins with the functions.php of a child theme? Is there any problem with doing such a thing? What's the best way to add plugin functionality to a child theme?
include this function in your theme and use this hookfunction <code> wp_register_theme_activation_hook($code, $function) { $optionKey="theme_is_activated_" . $code; if(!get_option($optionKey)) { call_user_func($function); update_option($optionKey , 1); } } </code> functions and examples: <code> &lt;?php /** * Provides activation/deactivation hook for wordpress theme. * * @author Krishna Kant Sharma (http://www.krishnakantsharma.com) * * Usage: * ---------------------------------------------- * Include this file in your theme code. * ---------------------------------------------- * function my_theme_activate() { * // code to execute on theme activation * } * wp_register_theme_activation_hook('mytheme', 'my_theme_activate'); * * function my_theme_deactivate() { * // code to execute on theme deactivation * } * wp_register_theme_deactivation_hook('mytheme', 'my_theme_deactivate'); * ---------------------------------------------- * * */ /** * * @desc registers a theme activation hook * @param string $code : Code of the theme. This can be the base folder of your theme. Eg if your theme is in folder 'mytheme' then code will be 'mytheme' * @param callback $function : Function to call when theme gets activated. */ function wp_register_theme_activation_hook($code, $function) { $optionKey="theme_is_activated_" . $code; if(!get_option($optionKey)) { call_user_func($function); update_option($optionKey , 1); } } /** * @desc registers deactivation hook * @param string $code : Code of the theme. This must match the value you provided in wp_register_theme_activation_hook function as $code * @param callback $function : Function to call when theme gets deactivated. */ function wp_register_theme_deactivation_hook($code, $function) { // store function in code specific global $GLOBALS["wp_register_theme_deactivation_hook_function" . $code]=$function; // create a runtime function which will delete the option set while activation of this theme and will call deactivation function provided in $function $fn=create_function('$theme', ' call_user_func($GLOBALS["wp_register_theme_deactivation_hook_function' . $code . '"]); delete_option("theme_is_activated_' . $code. '");'); // add above created function to switch_theme action hook. This hook gets called when admin changes the theme. // Due to wordpress core implementation this hook can only be received by currently active theme (which is going to be deactivated as admin has chosen another one. // Your theme can perceive this hook as a deactivation hook. add_action("switch_theme", $fn); } </code> for more information see this post
How do you auto-activate plugins from child themes
wordpress
We are creating a custom post type to showcase a series of archival recordings. They will cover many topics, and be tagged with ideas/phrases from the talks, similar to a regular post. Is it better to create custom taxonomies such as--for example--topics and themes in place of categories and tags, or does it make any difference? Also, the individual recordings need to be marked w/info such as date recorded, length of recording(s) etc., but this is info that doesn't necessarily need to be searchable. Is it 'better form' (for lack of a way to explain) to create custom taxonomies for these bits of info, or just add them to the description meta box? thanks for your help.. Don
That depends on the volume of posts you are going to have for recordings and regular posts. if you are talking about a few of each then using the built-in categories and tags will do and you can leverage all of the built-in functions for tags and categories, otherwise there is no harm in using your own taxonomies. And as for the individual recordings info( date, lenght) if its not needed to be searchable you can use the post's custom fileds for that.
taxonomies or categories w/custom post
wordpress
So I have a section on my site that specifically searches a custom post type for YouTube videos. I'm absolutely able to search the custom type. However, I'm unsure how to create a search page that has custom formatting geared toward this type of search. I've created a custom loop-youtube.php and modified within search.php <code> get_template_part( 'loop'); </code> to <code> get_template_part( 'loop', 'youtube'); </code> however, it affects the search results globally. Is there a way to create a custom search.php page for a specific post_type? Thanks for any help.
How are you restricting the search to your custom post type? If you are doing it by passing an additional argument, i.e. &amp;type=myCustomPostType, you could use a conditional test, like: <code> if(isset($_GET['type'] &amp;&amp; $_GET['type'] == 'myCustomPostType')): get_template_part('loop','youtube'); else: get_template_part(loop); endif; </code>
Custom post_type search pages
wordpress
i have some difficulties with the new Facebook like feature. usually, each one of my blog post has an image in it. when i use the facebook share feature everything is going well: it lets me choose as a thumbnail between the images embedded in my post and in the description it shows the entire first paragraph (or at least most of it). recently i've added the new facebook like feature to my blog but i can't make it behave like the share feature - when i like a post it doesn't use the post embedded image as a thumbnail. i managed to to make it display a default thumbnail by inserting this to header.php - <code> &lt;meta property="og:tag name" content="tag value"/&gt; </code> however, this is is only a partial solution. is there a way to make it use the post image as a thumbnail? in addition to the thumbnail issue, the like shown on my news feed doesn't grab the first paragraph as a description but only the 85 characters of it. is there a way to make it show the whole paragraph or at least more characters? thanks!
Use my plugin - http://wordpress.org/extend/plugins/facebook-like-thumbnail/ or the code manually in your functions.php that I have here on my post with explanation - http://blog.ashfame.com/2011/02/wordpress-plugin-fix-facebook-like-thumbnail/ Edit: It will use the first image of your post. Also Facebook will refresh all of your pages in max 24hours, so if you need to force refresh a page manually, try the linter tool - https://developers.facebook.com/tools/lint/ Edit: Regarding the description, if you have a meta named description which you should, because that way you can tell search engines the description of the current page, Facebook will pick that up. Its good both ways, as this is the text people will see below title both on search engines, and on Facebook.
facebook like - image display and description
wordpress
I'm working on a site at the moment for an orchestra. The various members need to be listed, according to their instrument. The members have a custom post type of biography and I'm capturing the instrument value via a custom field. The only way I can figure out how to display the relevant people in their relevant sections is to loop again and again through the custom post type, displaying the people that play a particular instrument by comparing the meta value. Code looks like this: <code> &lt;?php $args = array( 'post_type' =&gt; 'biographies', 'posts_per_page' =&gt; -1 ); ?&gt; &lt;ul class="no-bull hijax"&gt; &lt;?php $biog = new WP_Query($args); if( $biog-&gt;have_posts() ) : while( $biog-&gt;have_posts() ) : $biog-&gt;the_post(); $player = get_post_meta($post-&gt;ID, 'player', true); if ($player == 'yes') : $instrument = get_post_meta($post-&gt;ID, 'instrument', true); if ($instrument == 'violin') : ?&gt; &lt;li&gt;&lt;a id="artist_id_&lt;?php the_ID(); ?&gt;" class="nb" href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt; : &lt;?php echo($instrument); ?&gt;&lt;/li&gt; &lt;?php endif; endif; endwhile; endif; wp_reset_query(); $biog = new WP_Query($args); if( $biog-&gt;have_posts() ) : while( $biog-&gt;have_posts() ) : $biog-&gt;the_post(); $player = get_post_meta($post-&gt;ID, 'player', true); if ($player == 'yes') : $instrument = get_post_meta($post-&gt;ID, 'instrument', true); if ($instrument == 'viola') : ?&gt; &lt;li&gt;&lt;a id="artist_id_&lt;?php the_ID(); ?&gt;" class="nb" href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt; : &lt;?php echo($instrument); ?&gt;&lt;/li&gt; &lt;?php endif; endif; endwhile; endif; wp_reset_query(); $biog = new WP_Query($args); if( $biog-&gt;have_posts() ) : while( $biog-&gt;have_posts() ) : $biog-&gt;the_post(); $player = get_post_meta($post-&gt;ID, 'player', true); if ($player == 'yes') : $instrument = get_post_meta($post-&gt;ID, 'instrument', true); if ($instrument == 'cello') : ?&gt; &lt;li&gt;&lt;a id="artist_id_&lt;?php the_ID(); ?&gt;" class="nb" href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt; : &lt;?php echo($instrument); ?&gt;&lt;/li&gt; &lt;?php endif; endif; endwhile; endif; wp_reset_query(); </code> etc. etc. ad nauseum. (there are currently 12 loops on the page!!) This is clearly totally inefficient, but quite simply, I don't know how to write better code that this and need some help!
You could do it with one loop, you just need a valid sort order right? Players with one instrument, followed by the next and so on.. UPDATE: Following on the asker's comment, you can still use one query and use <code> rewind_posts() </code> to iterate the loop as many times as you need, ie. do something like this to get a custom sort.. <code> &lt;?php // Add the instruments into the array below, in the order you want them in. $instruments = array( 'violin', 'viola', 'cello' ); $args = array( 'post_type' =&gt; 'biographies', 'posts_per_page' =&gt; -1, 'nopaging' =&gt; true, 'surpress_filters' =&gt; true, 'meta_query' =&gt; array( array( 'key' =&gt; 'player', 'value' =&gt; 'yes', 'compare' =&gt; '=', 'type' =&gt; 'CHAR' ), array( 'key' =&gt; 'instruments', 'value' =&gt; $instruments, 'compare' =&gt; 'IN', 'type' =&gt; 'CHAR' ) ), ); $bios = new WP_Query( $args); ?&gt; &lt;?php if( $bios-&gt;have_posts() ) : ?&gt; &lt;ul class="no-bull hijax"&gt; &lt;?php foreach( $instruments as $instrument ) : while( $bios-&gt;have_posts() ) : $bios-&gt;the_post(); $player_instrument = get_post_meta( get_the_ID(), 'instrument', true ); if( $instrument != $player_instrument ) continue; ?&gt; &lt;li&gt;&lt;a id="artist_id_&lt;?php the_ID(); ?&gt;" class="nb" href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt; : &lt;?php echo $player_instrument; ?&gt;&lt;/li&gt; &lt;?php endwhile; rewind_posts(); endforeach; wp_reset_query(); ?&gt; &lt;/ul&gt; &lt;?php endif; ?&gt; </code> See if that has the desired effect.. :)
Grossly inefficient wordpress loops!
wordpress
I just downloaded the WMD Editor plugin . For some reason is not showing up in the Plugins menu. the folder is called <code> wmd-editor/ </code> wmd-editor.php: <code> &lt;?php /* Plugin Name: WMD Editor Plugin URI: http://c.hadcoleman.com/wordpress/wmd-editor Description: Adds the &lt;a href="http://wmd-editor.com/"&gt;WMD Editor&lt;/a&gt; to the comment field, to make life easier for your commenters. Version: 1.0 Author: Chad Coleman Author URI: http://c.hadcoleman.com */ /* This is a simple plugin that just adds the javascript call to the header of your template. You can gather more info on this project at http://code.google.com/p/wmd/ */ // function for head output sytles function wmd_header() { global $cb_path; $cb_path = get_bloginfo('wpurl')."/wp-content/plugins/wmd-editor"; //URL to the plugin directory $hHead = "\n"."&lt;!-- Start WMD Editor --&gt;"."\n"; $hHead .= " &lt;script language=\"javascript\" type=\"text/javascript\" src=\"{$cb_path}/wmd.js\" &gt;&lt;/script&gt;\n"; $hHead .= "&lt;!-- End WMD Editor --&gt;"."\n"; print($hHead); } add_action('wp_head', 'wmd_header'); ?&gt; </code>
Must be something you have installed or custom code causing the issue, it appears just fine for me. If your question was actually why there's no additional menu item on the admin side then the answer would be because not every plugin has an admin page, some provide configuration options, others just do something with no configurable options(depends on the intent of the author i suppose). Hope i could help in any case..
WMP Plugin not showing up in the plugin panel?
wordpress
Is it possible to test whether a script or a style was registered using <code> wp_register_script/_style </code> or <code> wp_enqueue_script/_style </code> ? All functions doesn't return a value and I'm completely clueless. I need it to switch between different functions depending on stylesheet-libraries and scripts I offer. Thank you!
There is a function called <code> wp_script_is( $handle, $list ) </code> . <code> $list </code> can be one of: 'registered' -- was registered through <code> wp_register_script() </code> 'queue' -- was enqueued through <code> wp_enqueue_script() </code> 'done' -- has been printed 'to_do' -- will be printed Ditto all that for <code> wp_style_is() </code> .
Check if a script/style was enqueued/registered
wordpress
If I were to take a standard query post. <code> &lt;?php query_posts('post_type=payment'); while (have_posts()) : the_post();?&gt; </code> Only this time I would like to query the post by 2 custom fields that it may contain. <code> &lt;?php query_posts('post_type=payment'.get_post_meta($post-&gt;ID,'bookingref', true).get_post_meta($post-&gt;ID,'customerref', true) ); while (have_posts()) : the_post(); ?&gt; </code> That doesn't work. Is something like this possible and how is it done? Any ideas? Marvellous
To query posts by custom fields you can use the 'meta_query' parameter <code> &lt;?php $args = array( 'post_type' =&gt; 'payment', 'meta_query' =&gt; array( array( 'key' =&gt; 'bookingref', 'value' =&gt; 'the_value_you_want', 'compare' =&gt; 'LIKE' ), array( 'key' =&gt; 'customerref', 'value' =&gt; 'the_value_you_want', 'compare' =&gt; 'LIKE' ) ); query_posts($args); while (have_posts()) : the_post(); ?&gt; </code> you can't use get_post_meta inside the query because it gets you the value and not the key and also it accepts a Post ID to get that value of and before the query $post-> id is not in the scope.
Query Posts or Get Posts by custom fields, possible?
wordpress
I'm trying to modify a plugin that generates an archive listing so it shows only one category, making it a single category archive. The old version of the plugin used a get_posts query, and so it was easy to disallow categories of posts: <code> $rawposts = get_posts( 'numberposts=-1&amp;category=-4,-6,-7,-9' ); </code> The new version of the plugin uses that database query: <code> SELECT ID, post_date, post_date_gmt, comment_status, comment_count FROM $wpdb-&gt;posts WHERE post_status = 'publish' AND post_type = 'post' AND post_password = </code> How do I disallow several categories from a database query?
You could use the get_tax_sql() function introduced in WP 3.1: <code> $tax_query = array( array( 'taxonomy' =&gt; 'category', 'terms' =&gt; array( 4, 6, 7, 9 ), 'operator' =&gt; 'NOT IN' ) ); $clauses = get_tax_sql( $tax_query, $wpdb-&gt;posts, 'ID' ); ... "SELECT ID, post_date, post_date_gmt, comment_status, comment_count FROM $wpdb-&gt;posts {$clauses['join']} WHERE post_status = 'publish' AND post_type = 'post' {$clauses['where']} " ... </code> (not tested)
Disallow categories from this MySQL query
wordpress
I'm using the following plugin: http://wordpress.org/extend/plugins/question-and-answer-forum/ It as a textarea which enables the user to post a question. The author told me how to allow html on it. But I was wondering how to add a buttons which enables the user to use html, say, attaching a link to a word (like you do here at StackExchange sites). I think the same should apply to commenting forms. Any suggestions?
It's a JavaScript editor just like the one used in a new/edit post/page editor only here the editor is: WMD-Editor (i think) and WordPress uses an editor named: TinyMCE In both cases it's a matter of attaching the editor to a textarea. you can use Dean's FCKEditor For WordPress which uses the powerful WYSIWYG CKeditor and integrates it into the comments textarea. Update i just saw this http://c.hadcoleman.com/wordpress-plugins/wmd-editor-wordpress-plugin/ which is just what you need.
How to add a button that enables the user to insert a link in a textarea located in the front-end?
wordpress
I've used this tutorial to build an option page form with Ajax. Now, i want to use the wp_handle_upload to upload an image. i tried this http://pastebin.com/35HW8RSZ but with no success. help will be appreciated. Asaf.
I found a very simple solution here . It Exceeds any external Ajax solution, in my opinion.
trying to use wp_handle_upload with ajax
wordpress
is it possible in Wordpress to have the category description use a rich text editor rather than a standard text area? If so any idea how to make it use one? Thanks!
Two plugins that i know: Rich Category Editor Category Description Editor but I haven't tried them on the new 3.1 so check them out.
Using a rich text editor for category description?
wordpress
I am using the following code to create a short permalink for one of my custom post types. I have another cpt that I wish to just use the default permalink structure, so what would be the best way to restrict this filtering to just cpt1? to be honest I thought one of the functions here would already handle this (add_permastruct?) but the same permalink rewrite is applied to other cpts. the documentation in the codex is a little thin on this… thanks Rhys <code> function cpt1_rewrite() { global $wp_rewrite; $queryarg = 'post_type=cpt1name&amp;p='; $wp_rewrite-&gt;add_rewrite_tag('%cpt1_id%', '([^/]+)', $queryarg); $wp_rewrite-&gt;add_permastruct('cpt1name', '/cpt1/%cpt1_id%', false);} function cpt1_permalink($post_link, $id = 0, $leavename) { global $wp_rewrite; $post = &amp;get_post($id); if ( is_wp_error( $post ) ) return $post; $newlink = $wp_rewrite-&gt;get_extra_permastruct('cpt1name'); $newlink = str_replace("%cpt1_id%", $post-&gt;ID, $newlink); $newlink = home_url(user_trailingslashit($newlink)); return $newlink;} add_action('init', 'cpt1_rewrite'); add_filter('post_type_link', 'cpt1_permalink', 1, 3); </code>
The <code> post_type_link </code> hooks gets called for all links to custom post types, you are responsible for checking the link type. Remember to use the passed <code> $post </code> object (not post ID), otherwise you check the current global <code> $post </code> variable, which may not be the post for which you are creating a link now. So the code you added in your comment is almost correct, I would write it like this: <code> function cpt1_permalink( $post_link, $post, $leavename ) { // Yoda condition to be safe // stackexchange-url if ( 'cpt1name' != $post-&gt;post_type ) { return $post_link; } // Rest of your code } </code>
restricting custom rewrite to just one custom post type
wordpress
i would like put link after each widget in dynamic sidebar. I thinks is possible if i use static sidebar, but i don't found any tutorial for this. Thanks you
If you use Widget Logic it adds a new filter <code> widget_content </code> which you can hook your function to and add link to it somthing like: <code> add_filter('widget_content','add_link_to_widgets'); function add_link_to_widgets($content){ return $content . '&lt;br /&gt;&lt;a href="http://www.domain.com"&gt;my link&lt;/a&gt;' } </code> Update You are missing the point, the plugin is great if you want to use his ability to limit the display of widgets, Beside that it add a new filter. so you can use that filter like i said to add your links, each widget has an id you can add the link based on that.
How put links in wordpress dynamic sidebar?
wordpress
I hate the built-in WYSWIG editor for WordPress. (EDIT: Editors of the sites I support hate it, which in turn makes more work for me. Hence, I hate it.) I know there are some alternatives out there, but I'm curious what the more functional and usable ones are? Issues that I hear: The text auto formatting either a) adds html or b) strips html. This is annoying. The view within the preview section doesn't use the stylesheets of the web site itself, so it's not really WYSIWYG
when one of my clients have doesn't like the TinyMCE editor i add the Dean's FCKEditor For WordPress plugin that integrates the ckeditor and install the office 2003 skin for it so they find it easier to use.
What are the better WYSIWYG post editor replacement alternatives?
wordpress
Is there a way of creating an empty attribute for a shortcode? Example: <code> function paragraph_shortcode( $atts, $content = null ) { return '&lt;p class="super-p"&gt;' . do_shortcode($content) . '&lt;/p&gt;'; } add_shortcode('paragraph', 'paragraph_shortcode'); </code> User types [paragraph] something [/paragraph] and it shows <code> &lt;p class="super-p"&gt; something &lt;/p&gt; </code> How to add an empty attribute functionality to my first code? So when user types [paragraph last] something [/paragraph] It will output: <code> &lt;p class="super-p last"&gt; something &lt;/p&gt; </code> I believe adding a: <code> extract( shortcode_atts( array( 'last' =&gt; '', ), $atts ) ); </code> is a good start, but how to check if user used the "last" attribute while it doesn't have a value?
There could be a couple ways to do this. Unfortunately, I don't think any will result in exactly what you're going for. ( <code> [paragraph last] </code> ) You could just create separate shortcodes for <code> [paragraph_first] </code> <code> [paragraph_last] </code> <code> [paragraph_foobar] </code> that handle $content without needing any attributes You could set the default value for last to <code> false </code> instead of <code> '' </code> , then require users to do <code> [paragraph last=""]content[/paragraph] </code> You could add a more meaningful attribute such as <code> position </code> which could then be used like <code> [paragraph position="first"] </code> or <code> [paragraph position="last"] </code> Because of the fact that WordPress discards any atts not given defaults, and the fact that an att without an <code> ="value" </code> is given the default value same as if it's not listed at all, I don't see any way to achieve <code> [paragraph last] </code> Hopefully one of my 3 workaround will prove useful. Good luck!
Shortcode empty attribute
wordpress
Probably not the correct fora to ask, but.. Also probably a simple question.. We are changing our site to Wordpress, and need to redirect old posts. Previously structure: <code> http://url.com/art/12345.html </code> Needs to go to <code> http://url.com/?p=12345 </code>
Use this before any mod_rewrite directives: <code> RedirectMatch Permanent ^/art/(\d+).html /?p=$1 </code>
htaccess redirect dynamic posts
wordpress
I am using the get_posts tag to get 4 random posts from a custom post type. However, I only want to get a post IF it has the $pic_url set. I´ve tried using... <code> if(!$pic_url) {continue;} </code> But that won´t work since i sometimes end up with displaying fewer than 4 posts (I allways want to display 4 posts). <code> $rand_posts = get_posts(array( 'numberposts' =&gt; 4, 'orderby' =&gt; 'rand', 'post_type' =&gt; 'ansatte', 'order' =&gt; 'ASC' )); foreach( $rand_posts as $post ) : $pic_url = get_post_meta($post-&gt;ID, 'employee_pic', true); $name = get_post_meta($post-&gt;ID, 'employee_name', true); $title = get_post_meta($post-&gt;ID, 'employee_title', true); ?&gt; &lt;div class="alignleft employee_outer"&gt; &lt;div class="employee_container"&gt; &lt;img src="&lt;?php if($pic_url) { echo $pic_url; } else { echo bloginfo('template_url') . '/images/default_profile_pic.png'; } ?&gt;" /&gt; &lt;/div&gt; &lt;p class="employee_name"&gt;&lt;?php echo $name; ?&gt;&lt;/p&gt; &lt;small class="employee_title"&gt;&lt;?php echo $title; ?&gt;&lt;/small&gt; &lt;/div&gt; &lt;?php endforeach; </code>
only retrieve posts with that meta key: <code> $rand_posts = get_posts(array( 'numberposts' =&gt; 4, 'orderby' =&gt; 'rand', 'post_type' =&gt; 'ansatte', 'order' =&gt; 'ASC', 'meta_key' =&gt; 'employee_pic', )); </code> or maybe use WP 3.1's meta_query: <code> $rand_posts = get_posts(array( 'numberposts' =&gt; 4, 'orderby' =&gt; 'rand', 'post_type' =&gt; 'ansatte', 'order' =&gt; 'ASC', 'meta_query' =&gt; array( array( 'key' =&gt; 'employee_pic', 'value' =&gt; '', 'compare' =&gt; 'NOT LIKE' ), ) )); </code>
If clauses in get_posts query
wordpress
I am merging Wordpress into a existing system and require our users to be able to make posts to a multi-site WP install. I have a database table that will link our own member to specific blog IDs and stuff, so there will be no need for user/logins as far as WP is concerned. What I really need to know is how to run certain WP functions outside of WP itself - on a completely different domain infact (but same server). I have tried simply including wp-load.php in our existing admin panel but as soon as I do it redirects to the main site - I assume because the domains do not match: domain1.com and domain2.com are both on the same server, domain1.com is the WP MU setup, on domain2.com in our own admin area I am including wp-load.php and as soon as I do it redirects me straight to the homepage of domain1.com. Is it even preferable to do it this way? I have seen a few examples where people have directly queried the WP database to insert posts. but if that's the case I have to ask myself why I am even using WP for this project at all?! I am thinking about using WP XMLRPC API but I need more power than that and don't wish to turn in on really.
Ok I have cracked it, by spoofing the $_SERVER variable and pre-defing some constants, I was able to prevent Wordpress from redirecting after the inclusion of wp-load.php. <code> define('WP_USE_THEMES', false); define( 'DOMAIN_CURRENT_SITE', $siteRow['domain'] ); define( 'PATH_CURRENT_SITE', '/' ); define( 'SITE_ID_CURRENT_SITE', 1 ); define( 'BLOG_ID_CURRENT_SITE', $siteRow['wp_blog_id'] ); $_SERVER = array( "HTTP_HOST" =&gt; $siteRow['domain'], "SERVER_NAME" =&gt; $siteRow['domain'], "REQUEST_URI" =&gt; "/", "REQUEST_METHOD" =&gt; "GET" ); require_once WP_PATH.'wp-load.php'; switch_to_blog($siteRow['wp_blog_id']); </code> $siteRow contains details about the target site. Note : This cannot be inside a function due to global variable restraints.
Creating a Post form outside of the Admin
wordpress
I'm working on a BackPress project where I need to schedule cron tasks. The cron_uri for BP is stored in options, rather than hardcoded as it is in WP core. I've tried setting the option to mysite.com/wp-cron.php (where wp-cron.php is essentially a copy of the same file from WordPress, modified to include only the relevant files to my purposes. The problem is, when this address is called from the wp_cron() function, it returns the following fsockopen error: fsockopen() [function.fsockopen] : unable to connect to :80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /home/gad/public_html/backpress/class.wp-http.php on line 646 I can open the cron uri directly using fsockopen and it doesn't return any error. As best as I can figure out, the problem is somewhere in the HTTP Transport API, maybe in the WP_http-> request() function, where BackPress checks the <code> cron_uri </code> against the <code> application_uri </code> option, to see if the request is a local one or not (and possibly treat the different requests differently?). Strangely enough, if I just set the <code> cron_uri </code> to my home url, it works fine - I can intercept the request based on the GET request and include wp-cron.php before outputting anything. I'm mainly confused as to why wp_remote_post doesn't seem to work with this file, as it seems to work with most everything else I've tried to do with it.
From quick look at source mechanics seem very similar, my first suggestion for WP would be to try and bump HTTP transport to curl (I do it with plugin in WP so no idea about specific code). curl seems to be considerably more robust for corner cases and it's not WP's first choice.
Using wp-cron in backpress - problems with wp_remote_post, fsockopen error
wordpress
I'm using custom fields to pull a secondary description. I'd like to use the built in WordPress truncate but can't seem to figure it out. <code> $desc = get_post_meta($post-&gt;ID, "youtube-desc", true); echo '&lt;p&gt;' . $desc . '&lt;/p&gt;'; </code> Any help would be appreciated.
See the discussion for Taxonomy Short Description for a better way to shorten a string. I’m not aware of a WP function that is getting truncation right. Here is my code based on the linked discussion: <code> /** * Shortens an UTF-8 encoded string without breaking words. * * @param string $string string to shorten * @param int $max_chars maximal length in characters * @param string $append replacement for truncated words. * @return string */ 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> Test <code> print utf8_truncate( 'ööööö ööööö' , 10 ); // prints 'ööööö …' </code> Add the function to your <code> functions.php </code> and change your code to: <code> echo '&lt;p&gt;' . utf8_truncate( $desc ) . '&lt;/p&gt;'; </code>
Truncating custom fields
wordpress
I set the jQuery Datepicker format to D d.m. displayed as Th 3.3. for a custom meta field that I want to use to sort posts. In SQL, the custom meta field is saved as D d.m. I would like to display the D d.m. format on the front end and store it as mm-dd-yy or 03-03-2011 in my SQL database. Any ideas? My input field for the custom meta field cp_date: <code> &lt;input name="&lt;?php echo $result-&gt;field_name; ?&gt;" id="&lt;?php echo $result-&gt;field_name; ?&gt;" type="text" minlength="2" value="&lt;?php if(isset($_POST[$result-&gt;field_name])) echo $_POST[$result-&gt;field_name]; ?&gt;" autocomplete="off" class="datepicker &lt;?php if($result-&gt;field_req) echo 'required' ?&gt;" /&gt; </code>
Firstly you'll need to stop storing the dates in <code> D d.m </code> format, the queries aren't going to be able to sort based on that data. As wyrfel pointed out, you'll need to use the alternate field option to have two fields, one that shows the pretty(or your chosen) date format, and another that holds the value you store in the DB(in a format that the queries can sort on correctly, like <code> yy-mm-dd </code> ). Based on the one line of code you posted, give this a shot.. PHP/HTML: (to replace the code you posted) <code> &lt;?php $date_valid = false; if( isset( $_POST[$result-&gt;field_name] ) ) { $date_parts = explode( '-', $_POST[$result-&gt;field_name] ); $date_valid = ( 3 == count( $date_parts ) ) // Validate date - checkdate returns true/false ? checkdate( $date_parts[1], $date_parts[2], $date_parts[0] ) : false; } $display_date = ( $date_valid ) ? date( 'D d.m', strtotime( implode( '-', $date_parts ) ) ) : ''; $storage_date = ( $date_valid ) ? $_POST[$result-&gt;field_name] : ''; $req = $result-&gt;field_req ? ' required' : ''; ?&gt; &lt;input type="text" value="&lt;?php echo $display_date; ?&gt;" class="datepicker&lt;?php echo $req ?&gt;" /&gt; &lt;input name="&lt;?php echo $result-&gt;field_name; ?&gt;" type="hidden" value="&lt;?php echo $storage_date; ?&gt;" class="date_alternate" /&gt; </code> Datepicker jQuery: (just pull what you need from this) <code> jQuery(function($) { $( ".datepicker" ).datepicker({ dateFormat: 'D d.m', altField: ".date_alternate", altFormat: "yy-mm-dd" }); }); </code> That way all your dates get stored in <code> yy-mm-dd </code> format, but the user sees the date in <code> D d.m </code> . I tested this approach locally and was able to get the functionality needed, here's a few screenshots of my theme options page using a date field and with your chosen date format(my code was obviously a little different to what's above, but the approach was the same). Selecting a date: Current values are at the bottom under the "Live Fetch" section. What you see after clicking a date in the calendar: Visual and stored values: I thought it might just be nice to see the code put into practice and hope that helps.. :)
Convert jQuery Datepicker Format to SQL Date Format
wordpress
I'm trying to 'break apart', (think explode is the correct terminology), wp_list_pages in order to add some definition list code into it, (dl, dt, dd). Here is the html code that I'm trying to output: <code> &lt;div id="nav"&gt; &lt;ul id="drop-nav"&gt; &lt;li&gt;&lt;a href="#"&gt;About Us&lt;/a&gt; &lt;div class="subnav"&gt; &lt;div class="subnavTop"&gt; &lt;ul class="subnavContent"&gt; &lt;li&gt; &lt;dl&gt; &lt;dt&gt;&lt;a href="#"&gt;Help Desk&lt;/a&gt;&lt;/dt&gt; &lt;dd&gt;&lt;a href="#"&gt;Email your question&lt;/a&gt;&lt;/dd&gt; &lt;dd&gt;&lt;a href="#"&gt;Text a question&lt;/a&gt;&lt;/dd&gt; &lt;/dl&gt; &lt;dl&gt; &lt;dt&gt;&lt;a href="#"&gt;Life stories&lt;/a&gt;&lt;/dt&gt; &lt;dt&gt;&lt;a href="#"&gt;Statistics&lt;/a&gt;&lt;/dt&gt; &lt;dd&gt;&lt;a href="#"&gt;World Statistics&lt;/a&gt;&lt;/dd&gt; &lt;dd&gt;&lt;a href="#"&gt;UK Statistics&lt;/a&gt;&lt;/dd&gt; &lt;dd&gt;&lt;a href="#"&gt;South West Statistics&lt;/a&gt;&lt;/dd&gt; &lt;dd&gt;&lt;a href="#"&gt;Research projects&lt;/a&gt;&lt;/dd&gt; &lt;/dl&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Talk to us&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;br style="clear: left" /&gt; &lt;/div&gt; </code> Here is my current outputted html code: <code> &lt;div id="nav"&gt; &lt;ul id="drop-nav"&gt; &lt;li&gt;&lt;a href="#"&gt;About Us&lt;/a&gt; &lt;div class="subnav"&gt; &lt;div class="subnavTop"&gt; &lt;ul class="subnavContent"&gt; &lt;li class="page_item page-item-15"&gt;&lt;a href="#"&gt;Child of About&lt;/a&gt; &lt;ul class='children'&gt; &lt;li class="page_item page-item-28"&gt;&lt;a href="#"&gt;Grandchild of About&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Talk to us&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;br style="clear: left" /&gt; &lt;/div&gt; </code> Which is generated using the following code from within my header.php, (can't remember which site I found this on): <code> &lt;div id="nav"&gt; &lt;ul id="drop-nav"&gt; &lt;?php // Query the database for all top-level page IDs, and store them in the $menuPages array under the [ID] sub-array $menuPages = $wpdb-&gt;get_results("SELECT ID FROM $wpdb-&gt;posts WHERE post_parent=0 AND post_type='page' AND post_status='publish' ORDER BY menu_order ASC"); // For each element in the $menuPages array, get the value from the [ID]-subarray to create the top-level menu and it's children foreach($menuPages as $menuItem){ $menuItemTitle = get_the_title($menuItem-&gt;ID); $menuItemClass = strtolower(trim($menuItemTitle)); $menuItemClass = preg_replace('/[^a-z0-9-]/', '-', $menuItemClass); $menuItemClass = preg_replace('/-+/', "-", $menuItemClass); $menuItemPermalink = get_permalink($menuItem-&gt;ID); if (isset($menuItemTitle) &amp;&amp; $menuItemTitle != 'Home'){ _e('&lt;li class="'.$menuItemClass.'"&gt;'.PHP_EOL); _e('&lt;a href="'.$menuItemPermalink.'"&gt;'.$menuItemTitle.'&lt;/a&gt;'.PHP_EOL); // Run wp_list_pages to fetch any children, and put the HTML &lt;LI&gt; list results into $menuItemChildren as a string $menuItemChildren = wp_list_pages('title_li=&amp;echo=0&amp;depth=1&amp;sort_column=menu_order&amp;child_of='.$menuItem-&gt;ID); // If results were returned, $menuItemChildren is now a string with HTML in it, so create a drop-down and echo out the HTML if($menuItemChildren){ _e('&lt;div class="subnav"&gt;'.PHP_EOL); _e('&lt;div class="subnavTop"&gt;'.PHP_EOL); _e('&lt;ul class="subnavContent"&gt;'.PHP_EOL); echo $menuItemChildren . PHP_EOL; _e('&lt;/ul&gt;'.PHP_EOL); _e('&lt;/div&gt;'.PHP_EOL); _e('&lt;/div&gt;'.PHP_EOL); } _e('&lt;/li&gt;'.PHP_EOL); } } ?&gt; &lt;/ul&gt; &lt;br style="clear: left" /&gt; &lt;/div&gt; </code> To be honest, this is confusing the life out of me. I can see that it should work, just not sure how to make it work. I somehow need to change each child page/item into a , the grandchildren into 's, all wrapped up nicely in 's. Hope this makes sense. Any ideas/help greatly appreciated, S. (The code is being used to dynamically generate a 'mega-menu') /*Updated Walker Class code below 08-03-11, as originally provided by wyrfel - many thanks */ <code> class My_Walker_Page extends Walker { var $tree_type = 'page'; var $db_fields = array ('parent' =&gt; 'post_parent', 'id' =&gt; 'ID'); function start_lvl(&amp;$output, $depth) { $indent = str_repeat("\t", $depth); switch ($depth) { case 0: $output .= "&lt;div class=\"subnav\"&gt;\n"; $output .= "&lt;div class=\"subnavTop\"&gt;\n"; $output .= $indent."&lt;ul class='subnavContent'&gt;\n"; $output .= "&lt;li&gt;\n&lt;dl&gt;\n"; break; case 1: break; default: break; } } function end_lvl(&amp;$output, $depth) { $indent = str_repeat("\t", $depth); switch ($depth) { case 0: $output .= "\n&lt;/dl&gt;\n&lt;/li&gt;\n"; $output .= "&lt;/ul&gt;\n"; $output .= "&lt;/div&gt;\n"; $output .= "&lt;/div&gt;\n"; break; case 1: break; default: break; } } function start_el(&amp;$output, $page, $depth, $args, $current_page) { if ( $depth ) $indent = str_repeat("\t", $depth); else $indent = ''; extract($args, EXTR_SKIP); $css_class = array('page_item', 'page-item-'.$page-&gt;ID); if ( !empty($current_page) ) { $_current_page = get_page( $current_page ); _get_post_ancestors($_current_page); if ( isset($_current_page-&gt;ancestors) &amp;&amp; in_array($page-&gt;ID, (array) $_current_page-&gt;ancestors) ) $css_class[] = 'current_page_ancestor'; if ( $page-&gt;ID == $current_page ) $css_class[] = 'current_page_item'; elseif ( $_current_page &amp;&amp; $page-&gt;ID == $_current_page-&gt;post_parent ) $css_class[] = 'current_page_parent'; } elseif ( $page-&gt;ID == get_option('page_for_posts') ) { $css_class[] = 'current_page_parent'; } $css_class = implode(' ', apply_filters('page_css_class', $css_class, $page)); $page_link = '&lt;a href="' . get_permalink($page-&gt;ID) . '" title="' . esc_attr( wp_strip_all_tags( apply_filters( 'the_title', $page-&gt;post_title, $page-&gt;ID ) ) ) . '"&gt;' . $link_before . apply_filters( 'the_title', $page-&gt;post_title, $page-&gt;ID ) . $link_after . '&lt;/a&gt;'; $top_class = strtolower(trim($page-&gt;post_title)); $top_class = preg_replace('/[^a-z0-9-]/', '-', $top_class); $top_class = preg_replace('/-+/', "-", $top_class); switch ($depth) { case 0: $output .= $indent . '&lt;li class="' . $top_class . '"&gt;'.$page_link . PHP_EOL; break; case 1: $output .= $indent . '&lt;dt&gt;'.$page_link.'&lt;/dt&gt;' . PHP_EOL; break; default: $output .= $indent . '&lt;dd&gt;'.$page_link.'&lt;/dd&gt;' . PHP_EOL; break; } if ( !empty($show_date) ) { if ( 'modified' == $show_date ) $time = $page-&gt;post_modified; else $time = $page-&gt;post_date; $output .= " " . mysql2date($date_format, $time); } } function end_el(&amp;$output, $page, $depth) { switch ($depth) { case 0: $output .= "&lt;/li&gt;\n"; break; case 1: break; default: break; } } } </code>
This is one of those question where solid answer is not an easy one to follow. This function is powered by <code> Walker_Page </code> class and you can replace it with your own walker (extended from <code> Walker_Page </code> or just <code> Walker </code> ) by passing its name in <code> walker </code> argument to <code> wp_list_pages() </code> . In a nutshell it is very highly flexible way to do it, but not very convenient and easy to grasp, especially when not messing with walkers regularly.
Break apart wp_list_pages in order to customise it
wordpress
I'm trying to create a loop of explicity ordered posts, for example: <code> &lt;?php $args = array( 'include' =&gt; '1,3,8,4,12' ); ?&gt; &lt;?php get_posts( $args ); ?&gt; </code> The results are ordered by date by default, and there is no orderby option to return the posts in the order they were entered. There have been multiple bug/feature requests posted about this in Trac, but so far no luck. I've mucked around in the core files a bit but haven't gotten anywhere with it. Can anyone suggest a workaround for this behavior? Cheers, Dalton
Okay, I was determined to find a way to do this, and I think I've got it. I had hoped to find a simpler solution and avoid having to use a new WP_Query object, but it's just too ingrained into how the loop works. First, we have a couple of utility functions: <code> // Set post menu order based on our list function set_include_order(&amp;$query, $list) { // Map post ID to its order in the list: $map = array_flip($list); // Set menu_order according to the list foreach ($query-&gt;posts as &amp;$post) { if (isset($map[$post-&gt;ID])) { $post-&gt;menu_order = $map[$post-&gt;ID]; } } } // Sort posts by $post-&gt;menu_order. function menu_order_sort($a, $b) { if ($a-&gt;menu_order == $b-&gt;menu_order) { return 0; } return ($a-&gt;menu_order &lt; $b-&gt;menu_order) ? -1 : 1; } </code> These will allow us to set the <code> menu_order </code> property based on our own list, and then sort the posts in a query object based on that. Here's how we query and sort the posts: <code> $plist = array(21, 43, 8, 44, 12); $args = array( 'post_type' =&gt; 'attachment', 'post_status' =&gt; 'any', 'post__in' =&gt; $plist ); // Create a new query $myquery = new WP_Query($args); // set the menu_order set_include_order($myquery, $plist); // and actually sort the posts in our query usort($myquery-&gt;posts, 'menu_order_sort'); </code> So now we have our own query object, and the <code> $myquery-&gt;posts </code> is sorted according to our custom <code> menu_order_sort </code> function. The only tricky part now, is that we must construct our loop using our custom query object: <code> while($myquery-&gt;have_posts()) : $myquery-&gt;the_post(); ?&gt; &lt;div&gt;&lt;a id="post_id_&lt;?php the_ID(); ?&gt;" class="nb" href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt; Post ID: &lt;?php the_ID(); ?&gt; &lt;/div&gt; &lt;?php endwhile; wp_reset_postdata(); </code> Obviously, you'd fix up the loop template code there. I was hoping to find a solution that didn't require the use of a custom query object, perhaps by using <code> query_posts() </code> and replacing the <code> posts </code> propery on the global <code> $wp_query </code> , but I just couldn't get it to work right. With a little more time to work on it, that might have been doable. Anyhow, see if that will get you where you need to go?
How to return results of a get_posts() in explicitly defined order
wordpress
How can I reset all variables in order to get the actual page content? I keep getting the last post's content I've called from a news-box I've implemented - but need the actual page's content .. thanks
Sounds like your news-box isn't using clean methods for pulling posts. I'm guessing that you are not using the get_posts() function. You're probably creating a new <code> WP_Query </code> object from scratch? Try using <code> get_posts() </code> , as it will take care of keeping the original page query clean for you.
Page displays content from different query?
wordpress
I created a custom post type "landing_page" to hold content I want to display on the top of category archive pages. So for each category, I have one landing_page entry tagged with that category. What do I have to add to the category archive.php template to get it to show that category's (or custom taxonomy term's) landing_page content? <code> query_posts( array( 'posts_per_page' =&gt; 1, 'post_type' =&gt; landing_page, 'category' =&gt; [[???]] )); while (have_posts()) : the_post(); the_content(); endwhile; ?&gt; </code>
I'd suggest adding something like this to the top of the theme file or wherever you want this content to appear in the archive, category or whatever.. <code> // Check if it's a category or taxonomy archive if( is_category() || is_tax() ) { // Grab the queried data, slug, tax, etc.. $queried = $wp_query-&gt;get_queried_object(); // Check taxonomy and slug are set if( isset( $queried-&gt;taxonomy ) &amp;&amp; isset( $queried-&gt;slug ) ) { // Look for a landing page post type with a slug that matches the current queried slug $landing_page = get_posts( 'name=' . $queried-&gt;slug . '&amp;post_type=landing_page&amp;posts_per_page=1&amp;nopaging=1' ); // If the result wasn't empty if( !empty( $landing_page ) ) { // Output the title and content using the same filters WP uses in the loop echo apply_filters( 'the_title', get_the_title( $landing_page-&gt;ID ) ); echo apply_filters( 'the_content', get_the_content( $landing_page-&gt;ID ) ); } } } </code> This will should do what you want without interupting the main category query for the archive. Hope that helps.
Show a Category X's custom post type on Category X archive page?
wordpress
For example If you have a plugin on a site that uses jQuery 1.5.x and want to create a new plugin by implementing a script which uses an older version of jQuery, for example 1.3.x or 1.4.x. I know it probably depends on jQuery functions that are called, but if you really had to use both 1.5 and some older version of jQuery.. how would you deal with this kind of situation? Is it even possible to use 2 different versions of jQuery at the same time without drawbacks? Thanks.
You could use jQuery.noConflict in your new plugin.
How to deal with different jQuery versions?
wordpress
Since 3.1 I've had an issue with custom taxonomies for a site. it seems that my user (admin level) can't edit the taxonomies from any screen. I see them on under the custom post type and can see them when adding a new post to the custom post type. I can even add currently available taxonomies to the post but I can't create new terms or access the custom taxonomy on it's edit page. Below is my code to set up the taxonomy. <code> &lt;?php add_action( 'init', 'fvww_custom_taxonomies'); function fvww_custom_taxonomies() { $labels = array( 'name' =&gt; __( 'River Classes', 'taxonomy general name' ), 'singular_name' =&gt; __( 'River Class', 'taxonomy singular name' ), 'search_items' =&gt; __( 'Search River Classes' ), 'all_items' =&gt; __( 'All River Classes' ), 'parent_item' =&gt; __( 'Parent Class' ), 'parent_item_colon' =&gt; __( 'Parent Class:' ), 'edit_item' =&gt; __( 'Edit River Class' ), 'update_item' =&gt; __( 'Update River Class' ), 'add_new_item' =&gt; __( 'Add New River Class' ), 'new_item_name' =&gt; __( 'New River Class' ), 'menu_name' =&gt; __( 'River Class' ), ); register_taxonomy( 'Class', array( 'fvww-river-guide' ), array( 'hierarchical' =&gt; true, //operates like a category 'labels' =&gt; $labels, 'rewrite' =&gt; true, 'public' =&gt; true, 'show_ui' =&gt; true, ) ); // ends class taxonomy } /* end function */ ?&gt; </code> If I click on the 'Class' taxonomy under River Guides I get the 'Cheatin uh?' message from wp-admin/edit-tags.php line 12.
Hi @curtismchale: Try <code> 'river-class' </code> instead of <code> 'Class' </code> , i.e.: <code> register_taxonomy( 'river-class', array( 'fvww-river-guide' ), array( 'hierarchical' =&gt; true, //operates like a category 'labels' =&gt; $labels, 'rewrite' =&gt; true, 'public' =&gt; true, 'show_ui' =&gt; true, ) ); // ends class taxonomy </code> Actually what caused you to stumble was your choice of a capitalized taxonomy name (i.e. "Class" vs. "class") although I'd really recommend against such a generic name as "class" to avoid potential conflict which is why I suggested "river-class" instead.
Custom Taxonomies Cababilities
wordpress
when uploading an image into the mediapool, wordpress will auto-resize it in several dimensions. unfortunately i'm requiring a special format which is kinda between thumbnail + medium. any ideas if it's possible to do that? thanks
You can call add_image_size in your functions.php: <code> add_image_size( 'medium', 240, 160, true ); </code> Reference here: http://codex.wordpress.org/Function_Reference/add_image_size
custom image dimensions (for gallery)
wordpress
Ok I have a WP site using the permalink structure of <code> /%category%/%postname%/ </code> I have built it in the way of page templates, using category queries inside, i.e. page-help.php <code> &lt;?php $my_query = new WP_Query('category_name=help'); while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt; &lt;!--content--&gt; &lt;?php endwhile; wp_reset_query(); ?&gt; </code> page-about.php <code> &lt;?php $my_query = new WP_Query('category_name=about'); while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt; &lt;!--content--&gt; &lt;?php endwhile; wp_reset_query(); ?&gt; </code> Pretty simple. The problem I have is, I need an archive by year for the news section. I did this by just making the archive.php have the same layout as page-news.php and just query the posts in the news category. *-this is fine in my case because news is, and will only ever be the content to be archived. My news category (latest-news) is a child of the about category (about), so when I go to the news section, the url is: www.example.com/about/latest-news/ On the news page is use the following code to list the archives; <code> &lt;!-- Gets archive for news--&gt; &lt;?php $my_query = new WP_Query('category_name=news_article'); while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt; &lt;?php wp_get_archives('type=yearly'); ?&gt; &lt;!--Ends archive for news--&gt; &lt;?php endwhile; wp_reset_query(); ?&gt; </code> The links it generates naturally lead me to www.example.com/2000 www.example.com/2001 etc. I want the rewrite to change them to www.example.com/about/latest-news/2000 www.example.com/about/latest-news/2001 I have modified the .htaccess in the WP route to this: <code> # BEGIN WordPress &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] RewriteRule /([0-9]+/?)$ /about/latest-news/$1 [NC,L] #Added this line &lt;/IfModule&gt; </code> But I am having no luck, the url remains as www.example.com/2000 I have the issue of not knowing wether my re-write is wrong, wether I should be putting this line of re-write in a different htaccess elsewhere, or if WordPress is overwriting it. Any help would be really appreciated.
First, your additional line comes too late. The rule before catches everything you want to match. Second, it doesn’t what you want. Your … <code> RewriteRule /([0-9]+/?)$ /about/latest-news/$1 [NC,L] </code> … matches requests like <code> example.com//0000000000000000000/ </code> or <code> example.com/about/latest-news/2010/ </code> (infinite loop!). The first argument for <code> RewriteRule </code> omits the starting <code> / </code> . To match year archives you need rather: <code> RewriteRule ^(\d\d\d\d)/?$ /about/latest-news/$1 [NC,L] </code> I’m not sure if you really need mod_rewrite for that. Try the following line above the rewrite block: <code> RedirectMatch Permanent ^/(\d\d\d\d)/?$ /about/latest-news/$1 </code> You have to tell WordPress about your custom archive stackexchange-url ("permalinks"). You should find enough good examples under the tag.
Why is my mod_rewrite not working?
wordpress
OK, I've had a problem with echoes in my last shortcodem, but everything works fine now. But I have another one: <code> function myWidget_shortcode( $atts ) { extract( shortcode_atts( array( 'title' =&gt; 'My Widget', 'value' =&gt; '5', ), $atts ) ); return the_widget(myWidget,'title='.$title.'&amp;value='.$value); } add_shortcode('myWidget', 'myWidget_shortcode'); </code> Can you tell me wy this shortcode always displays first on pages? There's no echo etc., all the data is being returned... [found the answer - edit] This resolves the problem: <code> ob_start(); the_widget(popularPosts,'title='.$title.'&amp;number='.$number); return ob_get_clean(); </code> Anyways I don't understand why it's always first in this case. Because the_widget is a function itself and echoes something? :>
Yes, look at the <code> widget() </code> method in your <code> MyWidget </code> class. Does it echo? Most likely it does, because that's how widgets are normally written. In fact, I'd be surprised to see a widget that didn't echo output in its <code> widget() </code> method. And when you call <code> the_widget() </code> , it fetches an instance of the widget you ask for, and calls <code> $widget_obj-&gt;widget($args, $instance); </code> . So it echos, and doesn't return anything.
Shortcode displays always first. Once again
wordpress
One of the things that I most enjoy about the stackexchange website is the 'related questions' that show up on the sidebar when I am viewing a question (or show up as I am typing my question). It is readily apparent to me that the logic being used there is much more advanced than 'normal' wp functionality. I know this would be a very proprietary kind of question, but is there any available documentation on the functions being used to generate the list? I am looking for something a bit more advanced than simply using tags for relating posts. *I was going to use YARPP but after reading a number of comments on how that plugin can bring a site to its knees, I figured it would be best to ask first.
I know it will be not regular answer and maybe not helpful. On big site (more 16k posts) we use SOLR server with module MLT (more like this) and results are more than good.
advice on creating a 'related posts' query like the one used on stackexchange
wordpress
Somehow my post counts are incorrect due to inserting rows via php. I have the following code to update the count, is it correct? <code> global $wpdb; $result = mysql_query("SELECT term_id,term_taxonomy_id FROM $wpdb-&gt;term_taxonomy where taxonomy = 'category'"); while ($row = mysql_fetch_array($result)) { $term_taxonomy_id = $row['term_taxonomy_id']; $countresult = mysql_query("SELECT object_id FROM $wpdb-&gt;term_relationships WHERE object_id IN (SELECT ID FROM $wpdb-&gt;posts WHERE post_type = 'post' AND post_status = 'publish') AND term_taxonomy_id = '$term_taxonomy_id'"); $count = mysql_num_rows($countresult); mysql_query("UPDATE $wpdb-&gt;term_taxonomy SET count = '$count' WHERE term_taxonomy_id = '$term_taxonomy_id'"); } </code>
If you just want to update the counts of posts in each term, <code> wp_update_term_count_now( $terms, $taxonomy ) </code> should do it... just pass the terms affected as an array and run it once for each taxonomy you have. You can also call <code> wp_defer_term_counting( true ) </code> before inserting new rows, and then after adding your posts, catch up on the counts by calling <code> wp_defer_term_counting( false ) </code> .
Fixing category count
wordpress
I just recovered from a pretty bad crash using Server 2008 Shadow copy. Ultimatly I didn't lose more than a few hours of work but a loss is a loss. I've decided to move to version control to prevent this from happening again. What I'm interested in knowing is how does one handle the mysql directory? And how do you handle a development site and a live site (trunk and branch) running at the same time? I assume you wouldn't be able to move a development database to production with the posts being consistently updated. Any thoughts would be appreciated.
Have a look at this older question: stackexchange-url ("Easily Move a WordPress Install from Development to Production?"). It covers migration and deployment of WP installations. For your more immediate issue, do backups of your database. Use a backup plugin (WP-DB-Backup is what I use, find it on the WP plugins repository) to handle this for you. You needn't worry as much about the core WP files as those can be loaded up again. You do need to keep backups of your theme files. Also take a look at this article: http://www.noeltock.com/web-design/wordpress/fast-furious-wordpress-theme-development-pt1/ . It's about using source control to simplify deployments. It's something I want to give a try!
Using source control with WordPress
wordpress
hey guys, is there a way to check if i'm currently not on the frontpage of my blog? I know there are conditional tags like is_home(). However that won't work if I'm on myblog.com/page/2/ I have a pagination on my frontpage that let's users jump to the next page. If I'm on the second page i want to show a "Back Home" link. any idea how I could achieve that? thank you.
Use the conditional Tag <code> is_paged() </code> for this purpose Look at: Codex WordPress
query if on page/2/?
wordpress
Three people have already tried to solve this, and we're coming up nil. I want to show only posts that have a value in the meta_key 'featured_image'. So... if 'featured_image' is not empty, show the post. Here's the code: <code> &lt;ul&gt; &lt;?php $args = array( 'showposts' =&gt; 5, 'meta_query' =&gt; array( array( 'key' =&gt; 'featured_image', 'value' =&gt; '', 'compare' =&gt; '!=' ) ) ); $ft_pagination = new WP_Query( $args ); ?&gt; &lt;?php while ($ft_pagination-&gt;have_posts()) : $ft_pagination-&gt;the_post(); ?&gt; &lt;?php $ftimage = get_post_meta(get_the_id(), 'featured_image', TRUE); ?&gt; &lt;li&gt; &lt;article&gt; &lt;a href=""&gt; &lt;?php if ($ftimage): ?&gt; &lt;img src="&lt;?php bloginfo('template_directory'); ?&gt;/timthumb.php?src=&lt;?php echo $ftimage; ?&gt;&amp;w=84&amp;h=60" alt="" /&gt; &lt;?php else: ?&gt; &lt;img src="&lt;?php bloginfo('template_directory'); ?&gt;/timthumb.php?src=/wp-content/themes/ssv/images/review-default.gif&amp;w=84&amp;h=60" alt="" /&gt; &lt;?php endif; ?&gt; &lt;/a&gt; &lt;/article&gt; &lt;/li&gt; &lt;?php endwhile; wp_reset_query(); ?&gt; &lt;/ul&gt; </code> We have tried literally every combination we can think of, the deprecated meta_* options, query_posts, get_posts, instead of WP_Query... Nothing. Printed the select statement, no meta value field is showing. It exists - for the posts (for every post) and it exists in the db. We've seen every post out there on the topic right now, including these: stackexchange-url ("query_posts and only show results if a custom field is not empty") http://scribu.net/wordpress/advanced-metadata-queries.html Zilch. Please help...
Hi @Rob: The reason you can't figure out how to do it is because it's not possible, at least not without resorting to SQL. Try adding the following to your theme's <code> functions.php </code> file: <code> add_filter('posts_where','yoursite_posts_where',10,2); function yoursite_posts_where($where,$query) { global $wpdb; $new_where = " TRIM(IFNULL({$wpdb-&gt;postmeta}.meta_value,''))&lt;&gt;'' "; if (empty($where)) $where = $new_where; else $where = "{$where} AND {$new_where}"; return $where; } </code> If you have custom <code> 'featured_image' </code> fields with empty values the above will filter them out. If you problem is something else, we'll have to see what your data looks like to solve it. One thing I'm curious about; how did you get empty values for <code> 'featured_image' </code> ? The admin UI in WordPress 3.1 does its best to keep you from entering empty values. Hope this helps.
How can I show posts only if meta_value is not empty
wordpress
I'm just wondering if anyone knows of a method or plugin that I can implement that will keep track of Facebook likes within Wordpress posts, and allow me to show posts in order of "most liked"?
Similar question: stackexchange-url ("Top 3 posts in last week ordered by Facebook and Twitter share counts") Basically, you have to write something to get the like count and store it as metadata with the posts every so often. Then you can order based on that count.
Is there a method or plugin that will allow posts to be sortable by Facebook likes?
wordpress
Let's assume I have a widget that displays only its name: <code> &lt;p&gt; &lt;?php echo $args['widget_id'] ?&gt; &lt;/p&gt; </code> So when I drag &amp; drop my widget to any sidebar it shows: <code> &lt;p&gt; myWidget-number &lt;/p&gt; </code> The problem is I want to call this widget with a shortcode: <code> (...) ob_start(); the_widget(MyWidget); return ob_get_clean(); } add_shortcode('myWidget_short', 'myWidget_shortcode'); </code> And when i do [myWidget_short] it shows only <code> &lt;p&gt; &lt;/p&gt; </code> Any ideas how to call widget's ID with a shortcode?
I believe @One Trick Pony was right. Shortcode widgets have no ID, so I've found a way around. Firstly I used PHP rand function: <code> $var = rand(); </code> And then added the "var" to the ID, so it doesn't collide with other shortcodes calling the same widget (each one has different random number at the end of the ID): <code> &lt;div id="myWidget-&lt;?php echo $var?&gt;;"&gt;&lt;/div&gt; </code>
the_widget() and widget's ID
wordpress
Is it possible to order my list of custom posts, after filtering it with meta_query, by the meta data of my choice? For example, I have a custom post type called webinars. I am trying to list all upcoming webinars, and have them ordered by the custom meta field called webinar_startDate. Using the following query, I was able to return the webinars succesfully excluding the old webinars. However, they still come out in the order they were published, and not by webinar_startDate. <code> &lt;?php $my_array = array( 'meta_query' =&gt; array( array( 'key' =&gt; 'webinar_startDate', 'value' =&gt; date("Y-m-d H:i:s"), 'compare' =&gt; '&gt;=', 'type' =&gt; 'DATETIME' ) ), 'orderby' =&gt; 'meta_value', 'post_type' =&gt; 'webinars', 'posts_per_page' =&gt; 20, 'order' =&gt; 'ASC' ); ?&gt; </code> I suspect that due to the change from 3.0 to 3.1, the use of orderby => meta_value is probably different, but I can't find an answer within the WordPress documentation to explain this. Can anyone help? Thanks in advance.
the new <code> meta_query </code> array selects which posts the query returns. So yes, you are indicating the 'key' within that <code> meta_query </code> , but you can still use the old method of <code> 'orderby' =&gt; 'meta_value', 'meta_key' =&gt; '_events_meta', </code> in addition to the meta_query, as these lines indicate how to sort the resulting query. So yes, you might indicate the same meta_key twice.
How do you use orderby with meta_query in Wordpress 3.1?
wordpress
There is a page template called "All Bookmarks" for displaying all links grouped by category. I want to modify it 2 ways: each category of links should be collapsible/expandable by clicking on the category header the template should accept a list of categories to either include or exclude For the collapsible part, assumably I need only add a class to each category header so that my jQuery code can affect them. For the category limiting, assumably I need a way to pass parametres to the template. However, I'm a complete noob to WP and I don't know where to put the jQuery code whether to add the class to the template, or to create a new template where to store a new template so that it will be available to Pages if templates can take parametres or if a template needs to refer to a custom PHP function where to store custom PHP functions I've been wandering around WordPress.org for a while becoming more and more frustrated. I'd appreciate it if someone could address the above questions and perhaps point me to a good explanation of WP code structure. Thanks! <code> Version: WP 3.1 Theme: Suffusion 3.7.7 </code>
Rather than modifying the template, since you're going to need jQuery anyway, you can do this.. Add to the functions.php <code> add_action( 'wp_enqueue_scripts', 'blogroll_toggles' ); function blogroll_toggles() { if( is_page_template( 'bookmarks.php' ) ) wp_enqueue_script( 'blogroll-toggle', get_bloginfo( 'stylesheet_directory' ) . '/blogroll-toggle.js', array( 'jquery' ) ); } </code> Or create a new folder in the <code> wp-content/plugins/ </code> folder, create a file inside the new folder, eg. blogroll-plugin.php , and add the following. <code> &lt;?php /* Plugin Name: Suffusion Blogroll Toggles */ add_action( 'wp_enqueue_scripts', 'blogroll_toggles' ); function blogroll_toggles() { if( is_page_template( 'bookmarks.php' ) ) wp_enqueue_script( 'blogroll-toggle', plugins_url( '/blogroll-toggle.js', __FILE__ ), array( 'jquery' ) ); } </code> The function will basically enqueue in the script whenever a page is loaded with the bookmarks template attached to it. jQuery is set as a dependancy for the script, so there's no need to load that seperately. Create a file in the theme(or plugin) folder and call it blogroll-toggle.js , then place the following code into that file. <code> jQuery(document).ready( function($) { // Hide the blogroll lists $('div.entry ul.blogroll').hide(); // Attach a click function to the headings $('div.entry h4').click( function() { // Make sure we're targeting the blogroll heading, if not, stop here(do nothing) if( !$(this).next('ul.blogroll') ) return false; // Toggle the blogroll list that follows the heading $(this).next('ul.blogroll').toggle(); }); }); </code> The jQuery is untested, but it should work(i've done toggles dozens of times). NOTE: If using as a plugin, remember to activate it like you would any other plugin. Any problems with the code, let me know. :)
modifying a template and adding jQuery to it
wordpress
My client isn't a great fan of updates so I want to assure him that the next major upgrade will be at least 3-4 months down the line. I just upgraded his blog to 3.1 - (YAY!) Would anyone concur with this or is this just wishful thinking on my part?
You may also wish to inform your client that the reason for updates is they include security fixes and patches that will only make their site better. Not running updates can have a very negative impact on their site.
When will be the next major update for wordpress?
wordpress
I've been looking for a list all WP_Query arguments. This looks obvious, but http://codex.wordpress.org/Function_Reference/WP_Query isn't helpful at all, "post_type" is mentioned only in an example, and arguments like "posts_per_page" aren't even there.
I believe this is what you're looking for. (You're right to look for it on the class documentation...i think the reason why it's on <code> query_posts() </code> is because that (and <code> get_posts() </code> ) is meant to be the primarily used function to get posts.)
WordPress documentation - WP_Query arguments
wordpress
I am creating a plugin which uses a custom post type. My question is two folds: (1) upon activation of my plugin how do I create the items of my custom post types. For example: if my post type was say... "Best Restaurants". I want to create 10 custom post types items since my plugin will need this information. How would I do that? Is there a function I can use which adds a post item along with its custom data? and (2) When my plugin is updated, say I released a new version, what is the best way to modify this list? I was thinking of deleting all items with a certain post type and then inserting the new ones, but that might be overkill. Thanks in advance.
Hi @rxn: Yes @wyrfel is right, you use <code> wp_insert_post() </code> to create your posts. Using your 50 US States example I've created some code you can drop into your theme's <code> functions.php </code> to see how it works (although you'll probably not want to call <code> add_states_if_not_yet_added() </code> for every page load, but the example is easier to show it this way): <code> &lt;?php add_action('init','init_us_states'); function init_us_states() { register_us_states_post_type(); add_states_if_not_yet_added(); } function add_states_if_not_yet_added() { foreach(get_50_us_states() as $state_code =&gt; $state_name) { if (!get_page_by_path($state_code,OBJECT,'us-state')) wp_insert_post(array( 'post_type' =&gt; "us-state", 'post_content' =&gt; "Information about {$state_name}", 'post_title' =&gt; $state_name, // i.e. 'Georgia' 'post_name' =&gt; $state_code, // i.e. 'GA'; this is for the URL 'post_status' =&gt; "publish", 'comment_status' =&gt; "closed", 'ping_status' =&gt; "closed", 'post_parent' =&gt; "0", )); } } function register_us_states_post_type() { register_post_type('us-state',array( 'labels' =&gt; array( 'name' =&gt; _x('States', 'post type general name'), 'singular_name' =&gt; _x('State', 'post type singular name'), 'add_new' =&gt; _x('Add New', 'us-state'), 'add_new_item' =&gt; __('Add New State'), 'edit_item' =&gt; __('Edit State'), 'new_item' =&gt; __('New State'), 'view_item' =&gt; __('View State'), 'search_items' =&gt; __('Search States'), 'not_found' =&gt; __('No States found'), 'not_found_in_trash' =&gt; __('No States found in Trash'), 'parent_item_colon' =&gt; '', 'menu_name' =&gt; 'States' ), 'public' =&gt; true, 'publicly_queryable' =&gt; true, 'show_ui' =&gt; true, 'show_in_menu' =&gt; true, 'query_var' =&gt; true, 'rewrite' =&gt; array('slug'=&gt;'states'), 'capability_type' =&gt; 'post', 'has_archive' =&gt; 'states', 'hierarchical' =&gt; false, 'supports' =&gt; array('title','editor','author','thumbnail','excerpt') )); } function get_50_us_states() { return array( 'AL' =&gt; 'Alabama', 'AK' =&gt; 'Alaska', 'AZ' =&gt; 'Arizona', 'AR' =&gt; 'Arkansas', 'CA' =&gt; 'California', 'CO' =&gt; 'Colorado', 'CT' =&gt; 'Connecticut', 'DE' =&gt; 'Delaware', 'FL' =&gt; 'Florida', 'GA' =&gt; 'Georgia', 'HI' =&gt; 'Hawaii', 'ID' =&gt; 'Idaho', 'IL' =&gt; 'Illinois', 'IN' =&gt; 'Indiana', 'IA' =&gt; 'Iowa', 'KS' =&gt; 'Kansas', 'KY' =&gt; 'Kentucky', 'LA' =&gt; 'Louisiana', 'ME' =&gt; 'Maine', 'MD' =&gt; 'Maryland', 'MA' =&gt; 'Massachusetts', 'MI' =&gt; 'Michigan', 'MN' =&gt; 'Minnesota', 'MS' =&gt; 'Mississippi', 'MO' =&gt; 'Missouri', 'MT' =&gt; 'Montana', 'NE' =&gt; 'Nebraska', 'NV' =&gt; 'Nevada', 'NH' =&gt; 'New Hampshire', 'NJ' =&gt; 'New Jersey', 'NM' =&gt; 'New Mexico', 'NY' =&gt; 'New York', 'NC' =&gt; 'North Carolina', 'ND' =&gt; 'North Dakota', 'OH' =&gt; 'Ohio', 'OK' =&gt; 'Oklahoma', 'OR' =&gt; 'Oregon', 'PA' =&gt; 'Pennsylvania', 'RI' =&gt; 'Rhode Island', 'SC' =&gt; 'South Carolina', 'SD' =&gt; 'South Dakota', 'TN' =&gt; 'Tennessee', 'TX' =&gt; 'Texas', 'UT' =&gt; 'Utah', 'VT' =&gt; 'Vermont', 'VA' =&gt; 'Virginia', 'WA' =&gt; 'Washington', 'WV' =&gt; 'West Virginia', 'WI' =&gt; 'Wisconsin', 'WY' =&gt; 'Wyoming', ); } </code> And here's some screenshots showing it in use:
Dynamically creating custom post type items and updating them
wordpress
I had added some content to contextual help section for plugin options page. Now I'd like that page defaulted/toggled to contextual help section open on specific condition in my PHP code. My only issue is that I am not strong with JS and don't see clear approach to coding that (I know how to pass variable to JS through localize, but not what code will actually get it done). I had found relevant JS functions in source , but not sure how to properly reuse them for my task.
You could also trigger/simulate the help button being clicked by binding to the ready event. Pre jQuery 1.7 <code> &lt;script type="text/javascript"&gt; jQuery(document).bind( 'ready', function() { jQuery('a#contextual-help-link').trigger('click'); }); &lt;/script&gt; </code> jQuery 1.7+ (bind deprecated as of 1.7) <code> &lt;script type="text/javascript"&gt; jQuery(document).on( 'ready', function() { jQuery('a#contextual-help-link').trigger('click'); }); &lt;/script&gt; </code> The difference here is that you'll see the help section slide down as the page finishes loading, as if a user had clicked the link. Can't hurt to have another option though. :)
How to control contextual help section by code?
wordpress
I've been trying to post some Java code to my blog, but it seems like it has some problems with the formatting. First, whenever I copy/paste code into the editor, it's pasted as pre-formatted, which means that it converts the indents to spaces, all on a single line. And when I try to separate the lines by making each line of code on a single physical line, it doesn't indent them automatically. I'm using the visual editor, and I've checked the HTML code, and nothing seems to be wrong with it. What am I doing wrong? Or is this a bug I should report to WordPress?
Paste the code in the HTML editor, it probably won't try to convert indents and linebreaks. Surround it with the <code> [sourcecode] </code> shortcode and only then return to the visual editor.
Formatting error with source code on WordPress.com?
wordpress
Please recommend a google maps wp plugin that can put a map inside a wp page while other text will be situated near it (right or left hand side).
Try Google Maps Embed and use CSS to float the iframe. Nice plugin. It gives you a button in the MCE Editor of Wordpress. You simple paste your maps url!
Google maps plugin
wordpress
Is there a possibility to get the count of users currently logged in and display it somewhere?
You can get the logged in users using wp_get_current_user(); . http://codex.wordpress.org/Function_Reference/wp_get_current_user But your probably better off just using a plugin or looking at the the following plugins code. http://wordpress.org/extend/plugins/wp-useronline/
A way to count logged in users and display count?
wordpress
I sat up MAMP on my mac and installed wordpress 3.1. Then, I exported my wordpress.com ina tried to import to my local wordpress.... I ticked import media option and I was hoping that I will get all my posta and attachments copied across but I got only posts imported properly... For each and every attachment at wordpress.com I got error saying media import failed!! Am I doing something wrong? Please help I have thousands of PDF/jpg attachments which I want imported...
I solved the problem... my source blog was private i.e. required password... I made it public for couple of minutes, and importer plugin did it's job properly!
Failed media import
wordpress
i've implemented a jQuery gallery for displaying several images within a post. the problem is that the_content(); also displays the post image. any ideas how to filter it? thanks
you can add a filter to the_content hook to strip the images something like: <code> add_filter('the_content', 'strip_images',2); function strip_images($content){ return preg_replace('/&lt;img[^&gt;]+./','',$content); } </code>
how to display post content without post image?
wordpress
is there a way to store the input value from multiple custom meta box fields with the same <code> meta_key </code> ? I use the following code to store ONE value for the <code> meta_key </code> 'startdate': <code> function startdate() { global $post; $custom = get_post_custom($post-&gt;ID); $startdate = $custom["startdate"][0]; ?&gt; &lt;label&gt;Startdate&lt;/label&gt;&lt;br/&gt; &lt;input type="text" name="startdate" value="&lt;?php echo $startdate; ?&gt;"/&gt; &lt;?php } add_action('save_post', 'save_details'); function save_details(){ global $post; update_post_meta($post-&gt;ID, "startdate", $_POST["startdate"]); } </code> If i had a second input field, how can i store its value with a different <code> meta_id </code> but the same <code> meta_key </code> (startdate)? Thank you very much! (If i use the built-in custom field functionality i can save multiple values for the same meta key...)
Change your form as suggested: <code> function startdate() { global $post; $custom = get_post_custom($post-&gt;ID); echo "&lt;label&gt;Startdates&lt;/label&gt;&lt;br/&gt;"; for ($i=0; $i&lt;count($custom["startdate"]);$i++) { echo "&lt;input type=\"text\" name=\"startdate[".$i."]\" value=\"".$custom["startdate"][$i]."\" /&gt;"; } } </code> You'll have to remove and reinstate your individual postmeta entries: <code> add_action('save_post', 'save_details'); function save_details($post_id) { if ($parent_id = wp_is_post_revision($post_id)) $post_id = $parent_id; if (!empty($_POST['startdate']) &amp;&amp; is_array($_POST['startdate'])) { delete_post_meta($post_id, 'startdate'); foreach ($_POST['startdate'] as $startdate) { add_post_meta($post_id, 'startdate', $startdate); } } } </code> Then, of course, you'll need to add some sort of add/remove mechanism to your metabox form, probably through JS.
How to store multiple input values with same meta_key
wordpress
We're creating a site to showcase a series of archival recordings covering a wide variety of topics. We'd like to have a page in the main navigation (e.g. recordings) to display these by title, w/a browse by category option, and have heard the best way to do this is w/custom post types. We're able to start this setup by editing the functions.php page, as well as using the 'custom post UI' plugin, but do not understand how to actually show the custom posts, either in a list style on the recordings page, or otherwise. What is the next step? Any and all help is appreciated. don
In the template for your recordings page you'll want to specify a custom query for the post type in question. <code> $rec_query = new WP_Query('post_type=recording'); </code> And then later in your template, you will refer to the query object you created directly instead of relying on the default. For example: <code> while ($rec_query-&gt;have_posts()) : $rec_query-&gt;the_post(); </code>
How to show custom posts
wordpress
I am having some trouble with scheduling posts to automatically expire (either by deleting or going to draft), every plugin I have tried does nothing and when it reaches the scheduled time nothing happens, which is making me think its probably some simple thing I keep overlooking.. I thought I might be a problem with wp-cron, but I don’t seem to have any trouble setting up a publish date in the future through wordPress. I have the latest version of Wordpress running, with multi-sites set-up. All plugins were at the latest version available at the moment. Does anyone have any ideas?? I am running out of things to try... Thanks in Advance Tafts
I got it working using the Post Expirator plugin, which also had the same problem, but by adding the following code to each loop right after 'the_post();' it checks the posts status on each page load, it is a temporary solution which seems to work for the moment. <code> // check to see whether post has expired $expiration = get_post_meta($post-&gt;ID, "expiration-date", true); if ($expiration &amp;&amp; (time() &gt; $expiration)) { $postSettings = array( 'post_status' =&gt; 'draft' ); wp_update_post($postSettings); } else { // normal content goes here } </code>
Posts wont expire
wordpress
I am trying to query for all posts with a post format of 'quote.' I have added the post formats to my functions.php with <code> add_theme_support( 'post-formats', array( 'image', 'video', 'gallery', 'quote' ) ); </code> I have selected 'quote' as the format for the post in the admin. The last example under Taxonomy_Parameters shows how to display posts that have the 'quote' format but when I run it in my theme no posts are returned. Here is the code: <code> $args = array( 'tax_query' =&gt; array( array( 'taxonomy' =&gt; 'post-format', 'field' =&gt; 'slug', 'terms' =&gt; 'post-format-quote' ) ) ); query_posts( $args ); </code> When I just query all posts and place <code> echo get_post_format(); </code> in the loop it returns the word 'quote' on the front-end. Also, when I var_dump() the query I do not see anything in the array about post format. Does anyone know if it is possible to query by post format? If so how? EDIT - See 5 comment under Bainternet's answer: This is the code found on index.php of the twentyten theme of a fresh install trying to return format type quotes. I return 'no' instead of 'quote'. Can you see anything that I should change. <code> get_header(); ?&gt; &lt;div id="container"&gt; &lt;div id="content" role="main"&gt; &lt;?php $args = array( 'tax_query' =&gt; array( array( 'taxonomy' =&gt; 'post-format', 'field' =&gt; 'slug', 'terms' =&gt; array('quote') ) ) ); query_posts( $args ); if ( have_posts() ) : while ( have_posts() ) : the_post(); echo get_post_format(); endwhile; else: echo 'no'; endif; wp_reset_query(); ?&gt; &lt;/div&gt;&lt;!-- #content --&gt; &lt;/div&gt;&lt;!-- #container --&gt; &lt;?php get_sidebar(); ?&gt; &lt;?php get_footer(); ?&gt; </code> EDIT 2 - It appears that the WordPress Codex has now changed and the portion on Taxonomy Parameters is only found in Google cache. EDIT 3 - FINAL WORKING CODE <code> $args = array( 'tax_query' =&gt; array( array( 'taxonomy' =&gt; 'post_format', 'field' =&gt; 'slug', 'terms' =&gt; 'post-format-quote' ) ) ); query_posts( $args ); </code> The twenty-ten edit form the first edit will be... <code> get_header(); ?&gt; &lt;div id="container"&gt; &lt;div id="content" role="main"&gt; &lt;?php $args = array( 'tax_query' =&gt; array( array( 'taxonomy' =&gt; 'post_format', 'field' =&gt; 'slug', 'terms' =&gt; 'post-format-quote' ) ) ); query_posts( $args ); if ( have_posts() ) : while ( have_posts() ) : the_post(); the_title(); echo get_post_format(); echo '&lt;br /&gt;'; endwhile; else: echo 'no'; endif; wp_reset_query(); ?&gt; &lt;/div&gt;&lt;!-- #content --&gt; &lt;/div&gt;&lt;!-- #container --&gt; &lt;?php get_sidebar(); ?&gt; &lt;?php get_footer(); ?&gt; </code>
This code is incorrect! You have <code> 'taxonomy' =&gt; 'post-format' </code> But it really needs to be: <code> 'taxonomy' =&gt; 'post_format' </code> Without the underscore, the query will be invalid. I just tested this on my WordPress 3.1 install after pulling my hair out for hours. Hope that helps!!
How do I query by post format in WordPress 3.1
wordpress
I've got some custom fields that I would like a user to be able to edit in Quick Edit, I can manage the columns but I'm unable to edit them if Quick Edit is clicked current code with custom fields I'd like to be able to edit: <code> /* custom columns */ add_filter("manage_edit-programmes_columns", "edit_columns" ); add_action("manage_posts_custom_column", "custom_columns"); function edit_columns($columns) { $columns = array( "cb" =&gt; "&lt;input type ='checkbox' /&gt;", "title" =&gt; "Schedule id", "programme" =&gt; "Programme", "channel" =&gt; "Channel", "onair" =&gt; "On Air", "catchup" =&gt; "Catchup", "popularity" =&gt; "Popularity", "onair" =&gt; "On Air", "date" =&gt; "Date" ); return $columns; } function custom_columns( $column ) { global $post; switch ( $column ) { case "programme": echo get_post_meta($post-&gt;ID, 'Programme Name', true); break; case "channel": echo get_the_term_list($post-&gt;ID, 'channelnames', '', ', ', ''); break; case "onair": echo get_post_meta($post-&gt;ID, 'Date Time Start', true); break; case "catchup": echo get_post_meta($post-&gt;ID, 'linktovideocatchup', true); break; case "popularity": echo get_post_meta($post-&gt;ID, 'popularityfig', true); break; } } </code> Help very much appreciated.
A couple things, Make sure in your <code> save_post </code> hook you're checking for <code> DOING_AJAX </code> which is used for saving in quick-edit. Check out my other question: stackexchange-url ("Quick edit screen customization"). The answer I received worked, but I haven't actually implemented it into my plugin quite yet as it's not a priority of mine yet . Hope that helps you out. ;)
How to get and edit custom fields if in Quick Edit
wordpress
i'm wondering if its possible to attach several images to a post then display those images in a thumbnail/fading gallery? By the way, the images should also be resized to a fixed size + thumbnail. thanks
Yes, you can use the standard wordpress [gallery] shortcode, after having attacched the images to your post. To attach images to your post, you can use the button "Upload Media". Upload the image from your disk and the press "Save Changes". The image will be attached to your post. Then use the gallery shortcode to insert the gallery in your post.
attach several images to post + gallery
wordpress
I'm trying to get the key values for multiple posts with get_post_meta but am having no luck so far. In short, I have a function that adds 'votes' and 'thevoters' to each post. I want to check to make sure if someone's UserID is in any one of the 'thevoters' fields (spanning across multiple posts) they will not be able to vote again. The following query gets the value of a specific post. I need to get the values across all posts with that key. <code> $voters = get_post_meta($id, 'thevoters', true); </code> My SQL query is: <code> SELECT * FROM `carcrazy_postmeta` WHERE meta_key='thevoters' </code> I am using this voting code as a reference - http://bavotasan.com/tutorials/simple-voting-for-wordpress-with-php-and-jquery/ Any ideas?
why not add a filed to user meta once they have voted and just check to see if that specific user can vote? add to your add vote function this lines: <code> global $current_user; get_currentuserinfo(); add_user_meta( $current_user-&gt;ID , 'voted', true ); </code> now if a user votes it saves a usermeta filed. then you can create a simple function to check if a user can vote again: <code> function has_he_voted($user_id){ $v = get_user_meta( $user_id , 'voted', true ); if ($v = true){ return true; }else{ return false; } } </code> and to use it and check if the user has voted you just call that function passing a user_id: <code> if (has_he_voted(12)){ //can't vote again ,you can only vote once //user has already voted }else{ //you can vote //user has never voted before } </code>
get_post_meta of multiple posts?
wordpress
I'm working on a site which is mostly static content and one main blog. Because of this, WordPress looks like the best option to construct this site. However, the client is now looking for the following feature: There needs to be a "members only" section, with sub-pages, containing some slightly sensitive information Users need to be able to request an account and have their email address verified After verification, the admin wants to manually say "yes" or "no" to each registration request before the users are added as members Members shouldn't ever have access to the backend, but should stay on the site after registerring and logging in Is there some plugin, or series of plugins, which makes this more straightforward? Does anyone have advice on how this is best set up? Thanks!
Take a look at theme my login which covers: Redirect users upon log in and log out based upon their role Require users to be approved and confirm e-mail address upon registration and in order to create you member only pages you can use your regular pages and simply add this function to your theme's functions.php is_user_logged_in() <code> add_shortcode('member_only','member_only_shortcode'); function member_only_shortcode($content){ if ( is_user_logged_in() ) { return $content; } else { return __('You must log-in to see this content '); } } </code> usage: <code> [member_only]content to show your members[/member_only] </code>
"Members only" section of a WordPress site - self signup and no backend access
wordpress
I was wondering if anyone knew of a plugin or a way programmatically to change the the default admin page for a specific user/role? I have a master panel page for my plugin currently setup with custom roles and permissions for the plugin using the Members Plugin and would like to force users that are in these custom roles to use my master control panel for their dashboard because they don't necessarily need access to the Dashboard. Minor Edit : Along with changing the default dashboard for the roles, is there a way to disable the WordPress dashboard? -Zack
In your theme's functions.php : <code> function hide_the_dashboard() { global $current_user; // is there a user ? if(is_array($current_user-&gt;roles)) { // substitute your role(s): if(in_array('custom_role', $current_user-&gt;roles)) { // hide the dashboard: remove_menu_page('index.php'); } } } add_action('admin_menu', 'hide_the_dashboard'); function your_login_redirect( $redirect_to, $request, $user ) { // is there a user ? if(is_array($user-&gt;roles)) { // substitute your role(s): if(in_array('custom_role', $user-&gt;roles)) { // pick where to redirect to, in the example: Posts page return admin_url('edit.php'); } else { return admin_url(); } } } add_filter('login_redirect', 'your_login_redirect', 10, 3); </code>
Change default admin page for specific role(s)
wordpress
I've created my own shortcode. I'm unable to share the code unfortunately ;/ When I use it on my pages it behaves strange. It always has the highest priority. I mean something like that in page editor: <code> Text [shortcode] </code> Outputs on the page: <code> &lt; shortcode contents &gt; Text </code> And this in page editor: <code> [shortcode] Text [shortcode] </code> Gives: <code> &lt; shortcode contents &gt; &lt; shortcode contents &gt; Text </code> So I'm unable to put anything before and between my shortcodes. To say more, my shortcodes use a few ifs, foreachs and a loop (they're grabbing and displaying data from custom post type). Any ideas why it happnes? [edit] OK, so I've been using echoes instead of return. My bad. Is there any way of return my whole function without editing every single line and adding $output etc.?
I think your problem is that your shortcode echos it's output rather than returning it. So in your shortcode function, remove any direct output (that is stuff between <code> ?&gt;.....&lt;?php </code> and any <code> echo </code> s and rather gather your output in a variable and return that: <code> function my_shortcode_cb($atts) { .... $output = .... $output .= .... return $output; } </code> More detail: So instead of <code> while ($a != $b) { echo "&lt;ul&gt;"; if ($c == $d) { foreach ($e as $k =&gt; $v) { ?&gt; &lt;li class="item-&lt;?php echo $k; ?&gt;"&gt;&lt;?php echo $v; ?&gt;&lt;/li&gt; &lt;?php } } echo "&lt;/ul&gt;"; } </code> you do: <code> $output = ''; while ($a != $b) { $output .= "&lt;ul&gt;" if ($c == $d) { foreach ($e as $k =&gt; $v) { $output .= "&lt;li class=\"item-".$k."\"&gt;".$v."&lt;/li&gt;"; } } $output .= "&lt;/ul&gt;"; } return $output; </code> Or, if you wanna be cheap ;-), you can do this: <code> ob_start(); while ($a != $b) { echo "&lt;ul&gt;"; if ($c == $d) { foreach ($e as $k =&gt; $v) { ?&gt; &lt;li class="item-&lt;?php echo $k; ?&gt;"&gt;&lt;?php echo $v; ?&gt;&lt;/li&gt; &lt;?php } } echo "&lt;/ul&gt;"; } return ob_get_clean(); </code> BTW: If your shortcode callback is really really long, then chances are that it's got lots of potential for refactoring. And if you'd do that, chances are that you'd assemble your output from strings returned by function calls, anyways.
Shortcode leaves no space for other elements?
wordpress
I have a blog which relies heavily on user generated content. I would like my users to be able to create posts, but the posts must only have specific fields: title content an attached image two metadata fields (latitude, longitude from Google Maps) tags (only pre-existing tags) Is it better to: a) give users access to the Edit Post screen and style it differently (Is this possible?) or b) develop a custom page/ form to submit the post? So far, I have opted for the second option (code below), but I am unsure of whether I am going about it the right way. <code> if (isset($_POST['photo-title']) &amp;&amp; !empty($_FILES) ) { // The user submitted the form. // Create the post object. $post = array( // Forget the lack of validation for now ;) 'post_title' =&gt; $_POST['photo-title'], 'post_content' =&gt; $_POST['photo-description'], 'post_status' =&gt; 'publish', 'post_type' =&gt; 'post', 'post_author' =&gt; $user_ID, 'post_category' =&gt; array(5) ); // Insert the post into the database. $post_id = wp_insert_post( $post ); // If the post was successful if ($post_id) { // Add metadata for the photo add_post_meta($post_id, 'ob_latitude', $_POST['latitude']); add_post_meta($post_id, 'ob_longitude', $_POST['longitude']); } // Handle the photo upload. $attach_id = media_handle_upload('photo', $post_id ); } </code>
You are way on the safer and less effort involved side if having them access the admin interface is an option. In that case you could implement a custom post type for your needs, disable most of the 'support' flags when registering it, and add your own metabox to support latitude and longitude, as well. With some extra plugins (like Members or any other one that's capable of editing roles and capabilities) you can even assign permissions to only edit that post type to these users that should be able to. All this is pretty well documented on the Codex and relatively easy to do. If you go for the front-end form option, you're basically left with digging through the code and trying to re-implement it on the front-end, which isn't such a bad thing for your learning experience, but it will take you way longer. Update: Developing post form on the front-end. First up, i'd still recommend creating a separate custom post-type. It allows you to more easily separate your user input from the rest of your content and above mentioned flexibility in assigning specific capabilities. Where to find things What i'd do to get started is have a good look at the following files, make sure you understand what's going on: <code> wp-admin/post.php </code> - particularly the part that processes the actions <code> wp-admin/includes/post.php </code> - particularly <code> edit_post() </code> and <code> wp_write_post() </code> <code> wp-admin/edit-form-advanced.php </code> - good to understand the relation between UI and the actions it triggers Since you want to allow uploads as well, you'll also need to learn about the media side of things: <code> wp-admin/includes/media.php </code> - particularly <code> media_handle_upload() </code> , <code> media_upload_form_handler() </code> and <code> media_upload_form() </code> <code> wp-admin/includes/file.php </code> - make sure you understand <code> wp_handle_upload() </code> <code> wp-admin/includes/image.php </code> - at least good to have a look to know what happens to your attachments on upload, and you'll have to include this, of course How to go about it Your best starting point is making a copy of <code> wp-admin/post.php </code> and stripping everything but what you need to save the post. Try to get rid of as many unnecessary dependencies as you can, but keep the function calls involved in saving the post. Remember that the more you keep using core WP functions and the more high-level they are, the more you'll stay compatible across different versions and the more sanity checks you get for free. Then have a look at <code> wp-admin/edit-form-advanced.php </code> and it's dependencies with the aim of determining what you may need for your UI and how you can provide that while using as much WP code as possible. At the same time have a look at the <code> comment_form() </code> function for inspiration on front-end form implementation. A part of all that will be understanding the nonce-mechanism (which isn't that complex, really). Make sure your post stuff works first...that is that your user can create and possibly edit/delete their posts and that you get all the data stored properly. Then add your meta data UI and store that, too. When doing so, try to use hooks. For instance, if you use WP functions to store the posts to the db, the <code> save_post </code> hook will be run. Use it to store your meta data. This is because the more you do this kind of stuff the easier it will be to accommodate changes in WP down the track or even change the way you do things, your self. Using hooks implicitly modularizes your functionality. After all that works, implement the upload form and the upload processing script. The media functions take a little to really get a hang of, i find. This is due to a lot of them being entangled in the AJAX driven admin side Media Thickbox. However, once you figured how to split the crop from the crap, you'll only need to make a few calls to get your media uploads running. Use the function Bainternet provided in his answer to stackexchange-url ("this question"). Finally, make sure you provide good user feedback for each and every operation. Naturally, this is way more important on the front-end than on the admin side, so make sure you let your users know what's going on. Again, try to understand how WP handles that itself (it uses two different mechanisms to get messages across from one page to the next). Form Example Finally, here's an example of a post and upload form i wrote for a Photo Contest plugin i'm gonna release sometime soon, hopefully. The plugin doesn't use regular attachments, though, but creates it's own attachment-like post-type for them, so this is a bit more involved than your case. And it also uses the cookie based commenter identification mechanisms as it's eventually open for users who aren't log in. All this you probably won't need, however, it may be good to look at for inspiration, anyways (except that you'd want to re-use <code> media_upload_form() </code> , probably).
Edit Post VS Custom Form
wordpress
I have a submission form where users can submit posts on my site. I have three steps (3 form pages) and in the first one user selects the post category, clicks the submit button and moves on to the next page which loads a form assigned to that category. Now, is there a way to have the categories as links (buttons) so that when user clicks on one, the form is submitted and he moves on to the next step without needing to click the actual submit button? This is how the submit button looks: <code> &lt;input type="submit" name="getcat" id="getcat" class="btn_catstep" value="&lt;?php _e('Continue'); ?&gt;" /&gt; </code> And this is how the form per category is handled: <code> &lt;?php $Category = get_term_by('id',$_POST['cat'],'p_cat'); $_POST['catname'] = $Category-&gt;name; ?&gt; &lt;form name="mainform" id="mainform" class="form_step" action="" method="post" enctype="multipart/form-data"&gt; &lt;ol&gt; &lt;li&gt; &lt;label&gt;&lt;?php _e('Category');?&gt;:&lt;/label&gt; &lt;strong&gt;&lt;?php echo $_POST['catname']; ?&gt;&lt;/strong&gt;&amp;nbsp;&amp;nbsp;&lt;small&gt;&lt;a href=""&gt;&lt;?php _e('(change)') ?&gt;&lt;/a&gt;&lt;/small&gt; &lt;/li&gt; &lt;?php echo show_form($_POST['cat']); ?&gt; &lt;p class="btn"&gt; &lt;input type="submit" name="step1" id="step1" class="btn_next" value="&lt;?php _e('Continue'); ?&gt;" /&gt; &lt;/p&gt; &lt;/ol&gt; &lt;input type="hidden" id="cat" name="cat" value="&lt;?php echo $_POST['cat']; ?&gt;" /&gt; &lt;input type="hidden" id="catname" name="catname" value="&lt;?php echo $_POST['catname']; ?&gt;" /&gt; &lt;input type="hidden" id="fid" name="fid" value="&lt;?php if(isset($_POST['fid'])) echo $_POST['fid']; ?&gt;" /&gt; &lt;input type="hidden" id="oid" name="oid" value="&lt;?php echo $order_id; ?&gt;" /&gt; &lt;/form&gt; </code> I currently have the categories in a basic dropdown with the submit button below it. If I have to hard code the links one by one, no problem, just don't know how to go about with this.
Once you retrieved your categories, let's say in <code> $categories </code> , you can do something like this: <code> &lt;?php foreach ($categories as $catgory) { ?&gt; &lt;form id="cat-button-form-&lt;?php echo $category-&gt;ID; ?&gt;" action="&lt;?php echo $url_to_step_2; ?&gt;" method="POST"&gt; &lt;input type="hidden" name="mycat" value="&lt;?php echo $category-&gt;ID; ?&gt;" /&gt; &lt;input type="submit" name="getcat" id="getcat_&lt;?php echo $category-&gt;ID; ?&gt;" class="btn_catstep" value="&lt;?php printf(__('Select %s &amp;amp; Continue'), $category-&gt;name); ?&gt;" /&gt; &lt;/form&gt; &lt;?php } ?&gt; </code> In step 2 you then read <code> $_POST['mycat'] </code> and go from there.
Categories as selectable links on submission form
wordpress
I've been looking through voting plugins and cannot seem to find one that works for me. I'm hoping you can help me out before I have to build my own as I'm tight on time. I have a page that will be full of (custom) posts, and I want users to be able to vote for their favorite. They should only be able to vote once, and I would like to track the username of the person who voted. WP-Polls is a great poll plugin that has the same features that I need (track voter and limit to one vote based on username), but I want to have a small 'vote' button below each listed post. Vote It Up can add a voting button at the bottom of each post, but does not track users or limit them to one vote. Anyone have any ideas where I could find something like that? Thanks in advance.
Here is exactly what you need, http://bavotasan.com/tutorials/simple-voting-for-wordpress-with-php-and-jquery/ As you can see you can track the user(s) and vote(s), also you can add some extra columns in your users admin area to track the votes.
Wordpress Vote Plugin - Vote Once and Track User
wordpress
I noticed that WP 3.1 supposedly has ' new CMS capabilities like archive pages for custom content types ', however, I can't see that implemented yet? I've been using a plugin called 'Simple Custom Post Type Archives' to view custom posts at the url http://www.domainname.com/custom-post-type/ , but wanted to use the in-built capability considering it is 'now possible'. Has anyone else had the same issue? Thanks osu PS. I'm using archive-custom_post_type_name.php to try and style my custom post type archive page
Yes, you'll just need to set the <code> has_archive </code> parameter to true or your chosen slug when registering your custom post type. So firstly add the <code> has_archive </code> parameter to your post type, here's an example... <code> add_action( 'init', 'question_10706_init' ); function question_10706_init() { register_post_type( 'example', array( 'labels' =&gt; array( 'name' =&gt; __('Examples'), 'singular_name' =&gt; __('Example') ), 'public' =&gt; true, 'show_ui' =&gt; true, 'rewrite' =&gt; array( 'slug' =&gt; 'example', 'with_front' =&gt; false ), //'has_archive' =&gt; true // Will use the post type slug, ie. example //'has_archive' =&gt; 'my-example-archive' // Explicitly setting the archive slug ) ); } </code> The <code> has_archive </code> parameter supports the following settings. false (default) No archive true The archive url is formulated from the post type slug <code> www.example.com/example/ </code> ' string ' The archive url is explicitly set to the slug you provided <code> www.example.com/my-example-archive/ </code> Once you've added the parameter visit the permalink page, this will cause a regeneration of the rewrite rules, accounting for the custom post type archive. Lastly, create an <code> archive-{$post_type}.php </code> template to handle that archive (it could be a straight copy-> paste of your existing archive, make adjustments as necessary). Noting, that <code> {$post_type} </code> would of course represent the slug of your actual post type. Sourced information: Mark McWilliams also wrote about this on his blog: WordPress 3.1 Introduces Custom Post Type Archives Trac ticket that introduced the new post type archives. Ticket #13818 - There should be index pages for custom post types Hope that helps. :)
WP 3.1 - archive pages for custom content types possible now without a plugin?
wordpress
What php code can be used to find the page object that hosts the blogs? Note that this may not be the same as the first page of the web site. In the admin section we can specify in which page to display the blog posts. The hard part from what I can see is how to get this info programatically. I can cycle through all the pages using get_pages() but the is_home() is only available within the context of the loop. I don't see a field on the page objects returned by get_pages() which indicates that it is a page with blog posts.
Hi @Alkaline: I think you are looking for this: <code> // $page is a post where post_type=='page' if (get_option('show_on_front')=='page') { $page_id = get_option('page_for_posts'); $page = get_post($page_id); } else { $page = false; } </code>
How to find the posts page (home page) programatically
wordpress
Please advice a google picasa plug that will have similar to original look, but with more styles or that will simply look better.
Hands Down best one i have use is Picasa Express x2 Use Picasa user to get albums ( username can be stored in settings ) Show albums cover and name for get images. Images from album with caption or filename for selection Select and insert single image or banch for gallery. Enhanced Private Picasa albums after granting access via Google service WordPress MU support - sidewide activation, users, roles Gallery shortcodes for selected images or for get all images from Picasa album Additionaly setting is managing: Image link: none, direct, Picasa image page, thickbox,lightbox and highslide with gallery Sorting images in dialog and in inserted gallery Caption under image or/and in image/link title Alignment for images and gallery Additional style or CSS classes for images and gallery Define Roles which capable to use the plugin Switch from blog to user level for store Picasa user and private access token And by design: Support native WordPress image and link dialog for alignment, caption, description, style and CSS class Thumbnail images size defined in WordPress native properties Multilanguage support Another good one would be Picasa Albums which uses the new "custom post types" feature.
Google picasa plugin
wordpress
I'm having a serious issue with Wordpress 3.1 with Multi Site enabled and my themes custom shortcode generator. For some reason, I'm getting the following error whenever I create a new page/post/custom post type page, etc. It is specifically an issue with radio buttons and the 'name' tag. When its removed, everything works fine. When it is set to a variable, I get the error. However, setting the variable to a constant (such as text) causes it to work again. This is the error I am getting; I have no clue what it means and what is causing it: <code> Warning: Invalid argument supplied for foreach() in /home/matthew/public_html/wp-admin/includes/post.php on line 197 Warning: Cannot modify header information - headers already sent by (output started at /home/matthew/public_html/wp-admin/includes/post.php:197) in /home/matthew/public_html/wp-includes/pluggable.php on line 897 </code> Here is the PHP code (check line 892): http://pastebin.com/BNK7wE2W I'm a bit skeptical about releasing too much information before the theme is released, but if access to the admin panel is required then if possible get in touch with me. Thanks in advance, Matthew.
I did spot one problem in your <code> case </code> clause for radio buttons: In your <code> &lt;label&gt; </code> tag, you use <code> $val </code> , but I think you meant <code> $option['id'] </code> . I don't see how it could be related to the <code> foreach </code> error you're getting, but it won't hurt to fix it. The odd thing is that the real error is coming from core code: <code> wp-admin/includes/post.php </code> , line 197. It looks like you're passing in some post meta, but you aren't passing in an array, like it wants. Does that help you narrow things down?
WordPress MS wp-admin/includes/post.php error with shortcode generator
wordpress
I'm trying to use the dynamic menu of wordpress! So I try to create an dropdown based on category, my question is... I need to block the first (title/category name) for being access .... right now it will take a page with all post of that category, I only need to display the categories in the menu but users cannot click on it!! Do you guys know which function I should use in order to do that? Kind Regards
Use a # for the URL in a Custom Links item and then the menu item will not link anywhere, but can be used for a top menu item. See http://codex.wordpress.org/WordPress_Menu_User_Guide
creating a dynamic menu in wordpress
wordpress
Setup: WordPress v 3.0.4, multisite network enabled, Theme: Twentyten child, local installation with MAMP 1.9.4, PHP 5.3.2, using SUBFOLDERS (not subdomains) for 4 sub sites Problem: Same global navigation menu, but sub sites construct urls for categories different to urls constructed in main site. In main site, an instance of a category link in the main navigation menu: -- http://localhost/BHAKTIVEDANTAS-dev/public_html/blog/category/asides/ Note the '/blog/' directory. Selecting the link returns a page with the category's list of posts. This is as it should be. Whereas in sub sites, using the same main site navigation menu for global navigation, the link for the same category is constructed differently: -- http://localhost/BHAKTIVEDANTAS-dev/public_html/category/asides/ Note the absence of the '/blog/' directory. Selecting the link returns a 404 page. :( In order to integrate the 4 sub sites together with the main site, I am using the main site's navigation menu for all by inserting the following code in the 'header.php' file for each of the sub sites. All other links on the navigation menu are working sitewide. &lt;?php /* for main site menu to display globally or sitewide */ switch_to_blog(1); ?&gt; &lt;?php /* Our navigation menu. If one isn't filled out, wp_nav_menu falls back to wp_page_menu. The menu assiged to the primary position is the one used. If none is assigned, the menu with the lowest ID is used. */ ?&gt; &lt;?php wp_nav_menu( array( 'container_class' =&gt; 'menu-header', 'theme_location' =&gt; 'primary' ) ); ?&gt; &lt;?php /* restore settings for current blog */ restore_current_blog(); ?&gt; Can it have anything to do with how the 'Categories' link was added to the menu? In the Super Admin &gt; Appearance &gt; Menus panel, I created a custom link, typed '#' in the URL field and 'Categories' for the label, then added to the menu. Next I added various Categories as children of the custom link.
This problem has been resolved by use of the plugin 'Remove Blog Slug' available at buddydev.com/plugins/remove-blog-slug-plugin/.
Global navigation in multisite: problem with categories
wordpress
I've created a custom query to pull all posts from a custom post type, ordered by comment count. It's your run-of-the-mills custom query: <code> &lt;?php $querystr = " SELECT wposts.* FROM $wpdb-&gt;posts wposts, $wpdb-&gt;postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wposts.post_status = 'publish' AND wposts.post_type = 'Tutorials' ORDER BY wposts.comment_count DESC "; $tutorialposts = $wpdb-&gt;get_results($querystr, OBJECT); ?&gt; &lt;?php if ($tutorialposts): ?&gt; &lt;?php global $post; ?&gt; &lt;?php $i = 0; ?&gt; &lt;?php foreach ($tutorialposts as $post): ?&gt; &lt;?php $i++; ?&gt; &lt;?php setup_postdata($post); ?&gt; &lt;h2&gt;&lt;?php echo $i ?&gt;:&amp;nbsp;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="Permanent Link to &lt;?php the_title(); ?&gt;"&gt; &lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt; &lt;?php endforeach; ?&gt; &lt;?php endif; ?&gt; </code> It has a little code added to it to number the posts. But I took this code out and the same problem persisted. It actually does what it's supposed to do! In fact, it's so excited about doing what it's supposed to do, that it does it twice. Also if anyone could tell me how to parse this code so it only shows the top 10 posts retrieved by the query that would be excellent. But I could probably figure that out on my own, that's just me being kind of lazy. I really just need to know why it's pulling each post and displaying it twice o.0
There is really no reason to use raw sql to query posts. You can accomplish just about any type of query using the WordPress API. For full reference see the codex, Function Reference query posts . Try the following: <code> global $post; $args=array( 'post_type' =&gt; 'tutorial', 'orderby' =&gt; 'comment_count', 'posts_per_page' =&gt; 10 ); $posts= query_posts($args); foreach ($posts as $post) : //do stuff endofforeach; </code>
Each post is showing twice in my custom query...?
wordpress
how would I go about creating a filter for the <code> body_class() </code> tag that allows me to add the the parent pages slug name as a class to the body whenever visiting a subpage or post?
here: <code> add_filter('body_class','body_class_slugs'); function body_class_slugs($classes) { global $posts,$post; if(is_single() || is_page()){ //only on a single post or page if (isset($posts)){ $classes[] = $post[0]-&gt;post_name; //posts is an array of posts so we use the first one by calling [0] } elseif (isset($post)){ $classes[] = $post-&gt;post_name; } } return $classes; } </code>
Add parent template name to body class filter when visiting subpage or single post
wordpress
Is it possible to have my custom permalink structure on title tag of my blog? my current permalink structure is this <code> /%postname%/%location%/%mba_courses%/ </code> where my location and mba_courses are custom taxonomies Now I want this on my title tag, can I write something like this in title tag? <code> &lt;title&gt;&lt;?php echo (/%postname%/%location%/%mba_courses%/); ?&gt;&lt;title&gt; </code> I know this is a wrong code, and it won't work, but is their any way, where I can have this kind of title tag?
There is no way to cause your permalink structure to be reflected automatically in the title tag. Instead, you must create it yourself. This might get you started: (I had to make a lot of assumptions in this code.) <code> function my_title() { $post = get_queried_object(); $locations = wp_get_object_terms( $post-&gt;ID, 'location' ); $mba_courses = wp_get_object_terms( $post-&gt;ID, 'mba_courses' ); $postname = $post-&gt;post_title; $location = $locations[0]-&gt;name; $mba_course = $mba_courses[0]-&gt;name; return "$postname | $location | $mba_course"; } </code> Then, in your single post template: <code> &lt;title&gt;&lt;?php echo my_title(); ?&gt;&lt;title&gt; </code>
permalinks on title tag
wordpress
We have a wordpress site using many subpages to each page - I'm looking to create a show/hide accordion toggle within the backend to show and hide subpages allowing us to keep the page listings clear. Does anyone know of a plugin to do this? I've had a google but not much joy so far..
PageMash looks like it does that: http://wordpress.org/extend/plugins/pagemash/ and http://joelstarnes.co.uk/blog/pagemash/
show/hide toggle for subpages in wordpress admin area
wordpress
i'm probably breaking a few common sense rules here. is there a way to utilize wordpress' bake in attachment file handling for an upload form within a theme template? yes, the front end -- i know. i’m creating a memorial site and i want people to be able to leave textual photographic "comments" for a dear person our community has lost. but these aren't wordpress users. they're aunts and kids and everything in between. these people are not going to be able to figure out WP default media UI and i don't want them having to log in and futz around. too confusing for them. if this weren't such a specific and delicate project, i wouldn't be trying to bend the rules so much. i understand that i'm opening up security holes by allowing anyone to upload a file, but i think it's somewhat necessary. all uploaded attachments will be "pending." i have both the text and photos set a custom post type, not as comments, so that i can utilize some built in post data. and it would be great if i could utilize worpdress built in file checking, handling, naming, size... etc. even though the file handling is on the front end. i thought that perhaps i could use: wp_handle_upload() by including '../wp-admin/includes/file.php' but that didn't work. i get a fatal error when i try to include it. is it just TOTALLY against the rules to include admin includes within templates... probably. i could just do all the file handling myself, but thought perhaps there's a way to utilize wordpress' functionality and that it may be safer. or are there suggestions on another route i should be going on altogether? unfortunately this is pretty time sensitive... the memorial service is coming up in a few days. thank you so much jonah
here is the function i use whenever i accept uploads from front end and you can use it in your template files: <code> function insert_attachment($file_handler,$post_id,$setthumb='false') { // check to make sure its a successful upload if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false(); require_once(ABSPATH . "wp-admin" . '/includes/image.php'); require_once(ABSPATH . "wp-admin" . '/includes/file.php'); require_once(ABSPATH . "wp-admin" . '/includes/media.php'); $attach_id = media_handle_upload( $file_handler, $post_id ); if ($setthumb) update_post_meta($post_id,'_thumbnail_id',$attach_id); return $attach_id; } </code> Usage: <code> // set $post_id to the id of the post you want to attach // these uploads to (or 'null' to just handle the uploads // without attaching to a post) if ($_FILES) { foreach ($_FILES as $file =&gt; $array) { $newupload = insert_attachment($file,$post_id); // $newupload returns the attachment id of the file that // was just uploaded. Do whatever you want with that now. } } </code>
exposing attachment uploading to the front end -- delicate
wordpress
I just added a plugin on WP repository but it seems like my readme.txt wasn't parsed correctly. I even ran it through the validator but on the plugin page it shows <code> Description </code> text under all tabs - <code> Installation, Changelog, FAQ </code> Plugin - http://wordpress.org/extend/plugins/facebook-like-thumbnail/ Readme.txt - http://plugins.svn.wordpress.org/facebook-like-thumbnail/tags/0.1/readme.txt So did I do something wrong? Or readme file parser is to blame?
You can add a short piece of text above the description that will be the "short description". You may need a blank line above and below. If it is not there, then the wp parser uses the first x characters of the description like this http://plugins.svn.wordpress.org/amr-ical-events-list/trunk/readme.txt http://plugins.svn.wordpress.org/amr-ical-events-list/trunk/readme.txt
WP plugin repository didn't parse readme.txt correctly
wordpress
I need a way to automatically export all WordPress posts from a specific date and have it output the file on the server that can be downloaded daily. The reason the XML format is needed is because the site is part of a large network of blogs and the parent site does not use WordPress but indexes the content in its search results. The parent company uses an XML parser that can't handle increments. It needs the full content of posts all at one time. My approach is to create a cron job using <code> wp_schedule_event </code> that fires export_wp and outputs the buffers into a file. The problem is that the file created is empty. My current code is: <code> register_activation_hook(__FILE__, 'c3m_my_activation'); add_action('c3m_export_daily', 'c3m_export_xml'); function c3m_my_activation() { wp_schedule_event(time(), 'daily', 'c3m_export_daily'); } function c3m_export_xml() { $ob_file = fopen('server_path_to_my_file.xml','w'); $args=array( 'content' =&gt; 'posts', 'start_date' =&gt; 'october 2008', 'status' =&gt; 'published'); function ob_file_callback($buffer) { global $ob_file; fwrite($ob_file,$buffer); } ob_start('ob_file_callback'); export_wp($args); ob_end_flush(); } </code> I have also tried it without adding any $args to export_wp but the file is still empty. I'm hoping this can be accomplished with export_wp so the whole thing doesn't have to be written from scratch.
Your problem is that <code> ob_file </code> ain't global. You only define it in <code> c3m_export_xml() </code> . Setting <code> global $ob_file </code> in <code> ob_file_callback() </code> gives you an empty file handle. Try this instead: <code> function c3m_export_xml() { $args=array( 'content' =&gt; 'posts', 'start_date' =&gt; 'october 2008', 'status' =&gt; 'published'); ob_start(); export_wp($args); $xml = ob_get_clean(); file_put_contents('server_path_to_my_file.xml', $xml); } </code>
Problem: Create a cron job to export posts to a WordPress XML file on server
wordpress
How are you every body how can remove name of theme in dashboard .. please .. You are using K2 RC-8 theme with 10 widgets. how can remove 'K2 RC-8 theme' .. please
Your options are to hide the right now widget or to change the theme name in style.css To remove the right now widget that shows the theme name. To change the theme name open style.css and change the theme name in the header. If your using the WordPress file editor activate another theme before you change the name in the header. <code> /* Theme Name: Your Theme Name Theme URI: http://example.com Description: My WordPress theme description Version: .99 Author: My Name Author URI: http://example.com */ </code>
remove theme's name from dashboard .. How?
wordpress
Plugin queries remote API and under certain circumstances (mostly errors) displays textual messages from API responses. All messages in API responses are in English, but since they are more or less integrated in plugin it would make sense to make them localized and display-able in different language to match plugin's interface. Theoretical question - should such messages be localized at all or are they out of scope for localization? Coding question - how do you even localize such and retain compatibility with related tools? Does something like <code> __( $message ); </code> even make sense? In the past I used Codestyling Localization which relies on scanning plugin's source to extract strings... But there is nothing to extract since strings are not contained in plugin's body.
Should such messages be localized at all or are they out of scope for localization? Yes, they should be localized ... but don't depend on the text returned by the API. Does something like <code> __( $message ); </code> even make sense? Not really. First of all, you're not providing a text domain for the string to use in localization. It should really be <code> __( $message, 'my-text-domain' ); </code> . Even then, if you don't have a static list of values for <code> $message </code> , localaization is a moot point. What You Can Do Instead The Robustness Principle is a great thing to keep in mind whenever you integrate content from an external API. You can never fully trust what the API gives you ... the original owners might change things around without notifying you, or their system might break and provide erroneous information. So you should always: Be conservative in what you send; be liberal in what you accept. If you already know what content the API will return (i.e. a static list of strings), put that in your plug-in. Then use a sanitation method to map what the API returned to your localized strings. For example: <code> $map = array( 'This is one return' =&gt; __( 'This is one return', 'my-text-domain' ), 'This is another' =&gt; __( 'This is another', 'my-text-domain' ) ); sanitize_api_feedback( $api_sent ) { return $map[$api_sent]; } </code> In this way, you never actually use the raw output of the external API but always run it through your own filter. You have complete control over the text strings used and can run them through the standard localization filters as well. If the API Return is Free-form If you don't have a list of static strings returned by the API, this won't work. Then again, if the API returns free-form content you should either: Leave localization up to the API itself (if possible) Provide you end user with some other translation service ... maybe Google Translate There's no way your plug-in can be responsible for translating free-form strings on the fly. But a static list of easily-expected error messages? That's definitely something you can, and should, do.
Localizing strings that come from outside of plugin?
wordpress
It's possible to disable a plugin just for a post? I'm displaying a post in my footer but I've installed Simple Facebook Share Button and I don't know how to remove that button. Unfortunately I can't use css to hide the button :( How can I do this? Thanks
Do you have a custom query in the footer that includes the post? If so, please try the following code before the loop the displays the footer post: <code> &lt;?php remove_filter( 'the_content', 'SFBSB_auto' ); ?&gt; </code>
Disable plugin only for one post
wordpress
( Moderator's note: Original title was "Remove Admin from User Menu") I have created a client administrator role which is essentially an Editor with ability to add/remove users. The article "stackexchange-url ("Editor can create any new user except administrator")" was excellent in helping keep my new client admin role from editing or creating a True admin user. However what would be ideal is to hide administrators from client admins when they are viewing users. I want them to "believe" that they are the admin of their site but I do not want them to be able to even view my role/user--essentially hiding the "administrator" role from them when they are in the "Users" panel.
Hi @Carlos: Try adding the following to your theme's <code> functions.php </code> file, or in a <code> .php </code> file within a plugin that you might be writing (which works for WordPress 3.1.x): <code> add_action('pre_user_query','yoursite_pre_user_query'); function yoursite_pre_user_query($user_search) { $user = wp_get_current_user(); if ($user-&gt;ID!=1) { // Is not administrator, remove administrator global $wpdb; $user_search-&gt;query_where = str_replace('WHERE 1=1', "WHERE 1=1 AND {$wpdb-&gt;users}.ID&lt;&gt;1",$user_search-&gt;query_where); } } </code> If you have WordPress 3.0.x try this instead (since WordPress didn't add the <code> 'pre_user_query' </code> hook until 3.1): <code> add_action('pre_user_search','yoursite_pre_user_search'); function yoursite_pre_user_search($user_search) { $user = wp_get_current_user(); if ($user-&gt;ID!=1) { // Is not administrator, remove administrator global $wpdb; $user_search-&gt;query_where = str_replace('WHERE 1=1', "WHERE 1=1 AND {$wpdb-&gt;users}.ID&lt;&gt;1",$user_search-&gt;query_where); } } </code>
Remove Ability for Other Users to View Administrator in User List?
wordpress
I do have prepared theme files (with __(), and _e(), etc), but they lack domain argument. There are lots of such string scattered around the theme files, editing by hand seems to be a dreadful perspective. Is there any tool to do this quickly? I remember there was a script somewhere, but I can't find it now.
Ok, I finally found what I was looking for - Marking strings in themes and plugins . And here is the actual SVN repository for tools in question.
Is there a quick way to inject i18n domain into theme/plugin files?
wordpress
I'm trying to filter my posts using multiple custom taxonomies for my custom posts with the following code, but I keep getting blanks with my new code i.e. no posts appear in the loop. It works like this: the user chooses a term for custom taxonomies 'fttype', 'ftperiod' and 'ftduration' from three different dropdowns in a form, and this is passed to the code below as: $ft_t_ns $ft_p_ns $ft_d_ns I originally had this code (which works, albeit without pagination), but the new code I'm trying to implement so that I can use WP 3.1's in-built capability of filtering by multiple custom taxonomies isn't working (see my new code further down). Can anyone see what I'm doing wrong here? Been fighting with this for a while... Thanks osu OLD CODE <code> // Set todays date to check against the custom field StartEventDate $todaysDate = date('Y/m/d'); // Convert spaces in taxonomies and terms into hyphens so that search works correctly (uses slug) $ft_t_ns = osu_convert_spaces($ft_t); $ft_p_ns = osu_convert_spaces($ft_p); $ft_d_ns = osu_convert_spaces($ft_d); // Build query // NOTE: AS OF WP 3.1, SEE V2 FOR HOW TO PASS AN ARRAY TO query_posts(). YOU PROBABLY WON'T NEED // QUERY MULTIPLE TAXONOMIES PLUGIN EITHER FOR V2'S APPROACH OF PASSING AN ARRAY TO WP_Query() TO WORK. // READ MORE ON 'MULTIPLE TAXONOMY HANDLING' HERE: // http://codex.wordpress.org/Function_Reference/query_posts#Taxonomy_Parameters $ft_args = 'post_type=ftevent'; $ft_args .= '&amp;fttype=' . $ft_t_ns; $ft_args .= '&amp;ftperiod=' .$ft_p_ns; $ft_args .= '&amp;ftduration=' . $ft_d_ns; $ft_args .= '&amp;posts_per_page=' . $ft_ppp; $ft_args .= '&amp;meta_key=StartEventDate&amp;meta_compare=&gt;=&amp;meta_value=' . $todaysDate; $ft_args .= '&amp;orderby=meta_value&amp;order=ASC&amp;paged=' . $paged; // Create query query_posts($ft_args); </code> NEW CODE <code> $ft_args = array( 'post_type' =&gt; 'ftevent', 'posts_per_page' =&gt; 5, 'paged' =&gt; $paged, 'orderby' =&gt; 'meta_value', 'order' =&gt; 'ASC', 'meta_query' =&gt; array( array( 'key' =&gt; 'StartEventDate', 'value' =&gt; $todaysDate, // Custom field type. Possible values are 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', // 'SIGNED', 'TIME', 'UNSIGNED'. Default value is 'CHAR'. 'type' =&gt; 'DATE', // Operator to test. Possible values are 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'. // We choose 'BETWEEN' because we need to know the date has not passed to show the event 'compare' =&gt; 'BETWEEN' ) ), 'tax_query' =&gt; array( 'relation' =&gt; 'AND', array( 'taxonomy' =&gt; 'fttype', 'field' =&gt; 'slug', 'terms' =&gt; $ft_t_ns, // Operator to test. Possible values are 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'. // We choose 'IN' because we need to make sure the term is in the current array of posts 'operator' =&gt; 'IN', ), array( 'taxonomy' =&gt; 'ftperiod', 'field' =&gt; 'slug', 'terms' =&gt; $ft_p_ns, 'operator' =&gt; 'IN', ), array( 'taxonomy' =&gt; 'ftduration', 'field' =&gt; 'slug', 'terms' =&gt; $ft_d_ns, 'operator' =&gt; 'IN', ), ) ); // Create query query_posts($ft_args); </code>
<code> $todaysDate </code> needs to be an array of two values to be <code> BETWEEN </code> for the compare. For example if you wanted to use a date range from today to a week in the future, then you might use something like.. <code> $todaysDate = array( date('Y/m/d'), date('Y/m/d', strtotime('+1 week') ) ); </code> Or if you wanted to go back in time, then maybe.. <code> $todaysDate = array( date('Y/m/d'), date('Y/m/d', strtotime('-1 week') ) ); </code> Following on from the comments: try this as the <code> meta_query </code> part of your code. <code> 'meta_query' =&gt; array( array( 'key' =&gt; 'StartEventDate', 'value' =&gt; date('Y/m/d'), 'type' =&gt; 'DATE', 'compare' =&gt; '&gt;=' // more than or equals ) ) </code> NOTE: It's still possible to use the old <code> &gt; </code> (more than), <code> &lt; </code> (less than) and other meta comparisons with the new <code> meta_query </code> args, or at least it looks that way by looking directly at the source. http://core.trac.wordpress.org/browser/trunk/wp-includes/meta.php#L355 Hope that helps.
WP 3.1 getting tax_query to work in query_posts()
wordpress
I want to make a forum site which uses the bbPress plugin for Wordpress (it turns Wordpress into a forum platform). The forums say that the beta plugin shouldn't be used in production. I want to get some things done, I thought about some elements that may not be affected by changes in the core of the plugin: The graphic design part The UI part The CSS Some features Any other suggestions?
If you are not going to use a ready made forum platform like : SMF phpBB Vbulletin myBB Vanilla becuase that site is not all forum but also a forum and you want wordpress as your platform then i would suggest you look at SimplePress as your forum plugin which is very mature and is constantly updated, packed with features and I can safely recommend it as a forum plugin form wordpress.
Suggestions to prepare a site which is 90% based on a plugin that's still on beta stage?
wordpress
I'm experiencing an internal server error on a site, but only on the publicly facing site, and on certain pages in the admin section, including posts ( <code> /wp-admin/edit.php </code> ) and anything else accessing <code> /wp-admin/edit.php </code> (e.g. pages and custom post types), and media ( <code> /wp-admin/upload.php </code> ). Every other admin page seems to work properly. I realize this is likely a server issue, but it's so strange (some pages are fine, others not), that I thought it would be worth asking about. I've deactivated all plugins and checked the <code> error_log </code> files (especially in /wp-admin), but haven't found anything. I should also note that I'm seeing core dump files written to the server each time a page returns an error, but I'm not sure how/if I can analyze those. This did happen after attempting to move the site to a different domain, if that helps. I believe I did everything correctly, but it's possible (and even likely, given the problem) that I didn't.
I get internal server errors quite often in my everyday coding work if i misspell PHP function names in my code. So try deactivating your plugins and re-enabling one by one.
Internal Server Error only on frontend and certain admin pages
wordpress
At the moment I run PHP code in my side bars. Even though I have the following <code> header("Pragma: no-cache"); header("cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past </code> It still appears to serve cached content.
This can be accomplished with fragment caching feature that W3TC has. Had been stackexchange-url ("asked/answered") couple times.
How do I get W3 Total Cache not to cache sidebars?
wordpress
As responsible professionals there has to be a line where we say, WordPress is not supposed to be used for that. When is WordPress not the answer?
Hi @Geo: As a huge proponent of using WordPress for content management use-cases that surprise the many people who believe WordPress is only a blog, I've had many opportunities to defend it's use which has also allowed me to recognize where it is not useful. Here are the main areas where I've come to believe WordPress is in-fact not the best solution: Non CMS-related Software-as-a-Service: If you are building a solution that is primarily not about content management, or your content architecture looks very different from posts, pages and comments then you are probably better off building a fully custom website architecture on a framework such as CodeIgnitor. Examples could include Twitter, Twillio, MailChimp, FreshBooks, etc. Complex and/or Innovative e-Commerce: If you need an eCommerce website with very complex requirements (multi-currency, multi-sourcing, multi-payment, etc.) or if innovations in online retailing are core to your success, such as Esty.com don't plan to use WordPress. WordPress rocks for setting up a basic online store, but if your business lives and dies by it's online sales, especially if your online revenues exceed US$1 million then WordPress is probably not your best solution. Enterprise Intranet Solutions: While WordPress can be easily coerced into doing many things I would instead recommend something like SharePoint for large, complex use-cases, regardless of how much I dislike SharePoint. Complex and Enterprise-Scale Content Management: If you need to track and management tens of thousands of documents with hundreds of complex workflow rules and tens of distinct roles for thousands of people, you'll want to kill yourself for trying to manage it with WordPress. WordPress simply does not have the tools built in yet to make this viable, although someday in the not too distant future it may. Highly Collaborative/Social Sites: This last one may be controversial but I'll run with it and I'm not talking about use-cases that including commenting; clearly WordPress excels at that. But if you need a site that is highly collaborative such as for wikis-style editing and or for a community hub, I don't think WordPress can do a good job ( yet? ) Yes WordPress has some wiki features but it simply hasn't been optimized for that use-case. And yes there is BuddyPress but I'm not yet sold on it's utility. I've tried to set it up but really struggled with it. Unlike WordPress, which is lean, focused and flexible, BuddyPress seems to me to be highly coupled, complex and constrained making it a risky move unless "out-of-the-box" BuddyPress fits the use-case to a "T" . All in my opinion, of course. :) So that's what I've identified as use-cases for which I can't (currently?) recommend WordPress. And there are probably use-cases I didn't capture. However, for most use-cases on the web WordPress IS the best solution . And even for some of those anti-use-cases above, you may still want to use WordPress for (a portion of) your corporate website and/or for microsites, just don't try to use it as key critical infrastructure component for one of the use-cases mentioned above.
When Should we NOT Recommend a Client use WordPress?
wordpress
My multisite (network) installation has 3 sites. the main site (nothing there, just very brief information) client 1 site -- siteurl/client1 client 2 site -- siteurl/client2 With domain mapper, siteurl/client# changed to clientdomain.com. Up to that point all is good. Now I want to change siteurl to mydomain.com How do I do that?
For those of you without the required sql knowledge. The steps below can be used to change your main site url variable on a network installation. Assumption: Windows Operating system MySQL Admin basic tasks WinGrep Steps: Download mysql dump.sql of your full wordpress database While using wingrep find all matches for @url then replace with @newURL Upload the dump file with the new variables replaced Change your wp_config.php file to the newURL You are done!
How to change the main site url on a multisite installation (network)?
wordpress
I would like to know if it's possible to add taxonomies in the user profile, without hacks. So far I have been able to add taxonomies to custom post types and all, but now I would like to add it to the user profile. I know how to add custom fields to the user profile, but so far failed on taxonomies. The closest I got to find a solution was: http://wordpress.org/support/topic/applying-custom-taxonomies-to-user-profiles As a newbie trying to find it there is a better solution. Thank you for reading and helping out.
The solution you linked seems about right but i can't tell if its scalable and won't crash on a large scale, another solution would be to create a non public custom post type with no UI and to act as a "stub" post for each user and keep that post ID in a user meta table, that way you can: make easier queries. use other post features for users like: comments,tags,categories, custom taxonomies and all the functionality built for posts. use post based plugins on a user profile like: voting, rating, ranking... and i believe its a much better approach. take a look at stackexchange-url ("Mike's answer") to a similar question to get you started.
Is it possible to add taxonomies to user profiles?
wordpress
http://anasianscreations.co.cc/jeffman/blog/uncategorized/hello-world/ I have looked all day for a solution but whenever you click on reply to this comment, instead of the comment box being displayed underneath you are redirected to the anchor. Also when I am in this theme, and you reply to a post, it does not register as a reply to a reply, instead it is just a regular reply. There is no doubt that I have missed something, can somebody point me in the right direction?
You don't have the comment reply Javascript being enqueued. Add this to your header, just before the wp_head() call: <code> if ( is_singular() &amp;&amp; get_option( 'thread_comments' ) ) wp_enqueue_script( 'comment-reply' ); </code>
Fix threaded comments
wordpress
I run WP for my photoblog ShutterScape using the awesome theme AutoFocus+. Recently, I upgraded to 3.1 and now, it refuses to show the featured images in the individual post pages. I am suspecting a jQuery conflict, as the Error Console shows this error. <code> Error: a.attributes is null </code> Can someone provide some pointers to fixing this error?
There's an update available .
WP 3.1 upgrade breaks AutoFocus+ theme
wordpress
I want to use W3 Total Cache plugin. Installed plugin succesfully but i'm trying to enable Page Caching and i'm getting this error : Page caching is not available: advanced-cache.php is not installed. Either the /home/content/92/7450992/html/wp-content directory is not write-able or you have another caching plugin installed. This error message will automatically disappear once the change is successfully made. Plugin can't create advanced-cache.php to wp-content. wp-content's CHMOD is 777 but still same error. Do you have any idea ?
Had you verified that there is no <code> advanced-cache.php </code> already there from another plugin (or as leftover of one)? You can try to copy this file manually from W3TC folder: <code> wp-content\plugins\w3-total-cache\wp-content\ </code>
W3 Total Cache can't create files
wordpress
stackexchange-url ("Related to this question") I am currently using Automatic WP backup. It works ok. Now I am looking for something more comprehensive and granular. A plugin that let's me choose the sites to backup inside my network, the type of content, the granularity on restores. ETC. Examples of things that I will like to do: Schedule a backup, with notification to owners (site owners) Verification of the backup (that it will work once I need it). That I can change variables important to restore in different webhost
Since you guys haven't mentioned it yet then i'll have to BackWPup a free site and database backup plugin packed with features and easy to configure Database Backup WordPress XML Export Optimize Database Check\Repair Database File Backup Backups in zip,tar,tar.gz,tar.bz2 format Store backup to Folder Store backup to FTP Server Store backup to Amazon S3 Store backup to RackSpaceCloud Store backup to DropBox Send Log/Backup by eMail when ever i have a client that is a bit too cheap on hosting and a propper backup server i just set him up with a dropbox account and this plugin creates and uploads the backup there, and if the plugin runs into trubles it sends the admin a log by mail. i defintly recommend this as a free solution.
What is the most comprehensive backup plugin for WordPress (it does not have to be free)?
wordpress
I'm not very familiar with the bbPress plugin. I would like to list two or three recent topics below the title of the forum (as well as the number of their replies): This is loop-bbp_forums.php : <code> &lt;?php /** * Forums Loop * * @package bbPress * @subpackage Theme */ ?&gt; &lt;?php if ( bbp_has_forums() ) : ?&gt; &lt;table class="bbp-forums"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th class="bbp-forum-info"&gt;&lt;?php _e( 'Forum', 'bbpress' ); ?&gt;&lt;/th&gt; &lt;th class="bbp-forum-topic-count"&gt;&lt;?php _e( 'Topics', 'bbpress' ); ?&gt;&lt;/th&gt; &lt;th class="bbp-forum-topic-replies"&gt;&lt;?php _e( 'Replies', 'bbpress' ); ?&gt;&lt;/th&gt; &lt;th class="bbp-forum-freshness"&gt;&lt;?php _e( 'Freshness', 'bbpress' ); ?&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tfoot&gt; &lt;tr&gt;&lt;td colspan="4"&gt;&amp;nbsp;&lt;?php // @todo - Moderation links ?&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/tfoot&gt; &lt;tbody&gt; &lt;?php while ( bbp_forums() ) : bbp_the_forum(); ?&gt; &lt;tr id="bbp-forum-&lt;?php bbp_forum_id(); ?&gt;" &lt;?php bbp_forum_class(); ?&gt;&gt; &lt;td class="bbp-forum-info"&gt; &lt;a class="bbp-forum-title" href="&lt;?php bbp_forum_permalink(); ?&gt;" title="&lt;?php bbp_forum_title(); ?&gt;"&gt;&lt;?php bbp_forum_title(); ?&gt;&lt;/a&gt; &lt;?php bbp_list_forums(); ?&gt; &lt;div class="bbp-forum-description"&gt;&lt;?php the_content(); ?&gt;&lt;/div&gt; &lt;/td&gt; &lt;td class="bbp-forum-topic-count"&gt;&lt;?php bbp_forum_topic_count(); ?&gt;&lt;/td&gt; &lt;td class="bbp-forum-reply-count"&gt;&lt;?php bbp_forum_reply_count(); ?&gt;&lt;/td&gt; &lt;td class="bbp-forum-freshness"&gt; &lt;?php bbp_forum_freshness_link(); ?&gt; &lt;p class="bbp-topic-meta"&gt; &lt;?php bbp_author_link( array( 'post_id' =&gt; bbp_get_forum_last_active_id(), 'size' =&gt; 14 ) ); ?&gt; &lt;/p&gt; &lt;/td&gt; &lt;/tr&gt;&lt;!-- bbp-forum-&lt;?php bbp_forum_id(); ?&gt; --&gt; &lt;?php endwhile; ?&gt; &lt;/table&gt; &lt;?php endif; ?&gt; </code>
scribu is correct. The code to do this does exist within the plugin, but that code is subject to change as the bbPress plugin continues to be developed. If you're comfortable snooping through code and finding the functions to make this happen, we're happy to fix any bugs you might find along the way. You may also have more luck asking your question at the bbPress.org support forums, as there are a few people there currently testing the bbPress plugin and keeping up with its daily developments.
How to show recents topics below the forum's title (Wordpress + bbPress plugin)?
wordpress
This is how you do it for Wordpress posts: <code> $my_query = new WP_Query( "cat=3" ); if ( $my_query-&gt;have_posts() ) { while ( $my_query-&gt;have_posts() ) { $my_query-&gt;the_post(); the_content(); } } wp_reset_postdata(); </code> I would like to know how to do that in bbPress (say, listing topics).
bbpress has its own query class called BB_Query() and it accepts: <code> $ints = array( 'page', // Defaults to global or number in URI 'per_page', // Defaults to page_topics 'tag_id', // one tag ID 'favorites' // one user ID ); $parse_ints = array( // Both 'post_id', 'topic_id', 'forum_id', // Topics 'topic_author_id', 'post_count', 'tag_count', // Posts 'post_author_id', 'position' ); $dates = array( 'started', // topic 'updated', // topic 'posted' // post ); $others = array( // Both 'topic', // one topic name 'forum', // one forum name 'tag', // one tag name // Topics 'topic_author', // one username 'topic_status', // *normal, deleted, all, parse_int ( and - ) 'open', // *all, yes = open, no = closed, parse_int ( and - ) 'sticky', // *all, no = normal, forum, super = front, parse_int ( and - ) 'meta_key', // one meta_key ( and - ) 'meta_value', // range 'topic_title', // LIKE search. Understands "doublequoted strings" 'search', // generic search: topic_title OR post_text // Can ONLY be used in a topic query // Returns additional search_score and (concatenated) post_text columns // Posts 'post_author', // one username 'post_status', // *noraml, deleted, all, parse_int ( and - ) 'post_text', // FULLTEXT search // Returns additional search_score column (and (concatenated) post_text column if topic query) 'poster_ip', // one IPv4 address // SQL 'index_hint', // A full index hint using valid index hint syntax, can be multiple hints an array 'order_by', // fieldname 'order', // *DESC, ASC 'count', // *false = none, true = COUNT(*), found_rows = FOUND_ROWS() '_join_type', // not implemented: For benchmarking only. Will disappear. join (1 query), in (2 queries) // Utility // 'append_meta', // *true, false: topics only // 'cache_users', // *true, false // 'cache_topics, // *true, false: posts only // 'post_id_only', // true, *false: this query is only returning post IDs 'cache_posts' // not implemented: none, first, last ); </code>
How to create a custom nested loop in bbPress (Wordpress + bbPress plugin)
wordpress
I must be blind but I can't find for the life of me the full instructions for getting Disqus comment count to work. All I want displayed is just the comment count number. I've checked the "Output JavaScript in footer" option. I have custom loops but I have no idea what I supposed to put in them to activate the comment count. My loop.php file is: <code> &lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt; &lt;?php if ( comments_open() ) : ?&gt; &lt;a href="&lt;?php echo get_permalink($post-&gt;ID); ?&gt;#disqus_thread" class="post-disqus"&gt; &lt;span class="dsq-postid"&gt;&lt;/span&gt; &lt;?php echo $post-&gt;comment_count; ?&gt; &lt;/a&gt; &lt;?php endif; ?&gt; &lt;?php endwhile; ?&gt; &lt;?php endif; ?&gt; </code> Disqus's footer javascript code is: <code> &lt;script type="text/javascript"&gt; // &lt;![CDATA[ var disqus_shortname = 'mysite'; var disqus_domain = 'disqus.com'; (function () { var nodes = document.getElementsByTagName('span'); for (var i = 0, url; i &lt; nodes.length; i++) { if (nodes[i].className.indexOf('dsq-postid') != -1) { nodes[i].parentNode.setAttribute('data-disqus-identifier', nodes[i].getAttribute('rel')); url = nodes[i].parentNode.href.split('#', 1); if (url.length == 1) url = url[0]; else url = url[1] nodes[i].parentNode.href = url + '#disqus_thread'; } } var s = document.createElement('script'); s.async = true; s.type = 'text/javascript'; s.src = 'http://' + disqus_domain + '/forums/' + disqus_shortname + '/count.js'; (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s); }()); //]]&gt; &lt;/script&gt; </code>
I have the same problem with displaying number of comments in the loop. I solve this by turn off two filters in file plugins/disqus/disqus.php at line 1124: <code> &lt;?php #add_filter('comments_number', 'dsq_comments_text'); #add_filter('get_comments_number', 'dsq_comments_number'); </code> And I have added to my template span with disqus elements: <code> &lt;?php if ( function_exists( 'dsq_identifier_for_post' ) ) { global $post; echo '&lt;span class="'.$css_class.' dsq-postid" rel="'.htmlspecialchars(dsq_identifier_for_post($post)).'"&gt;'; } else { echo '&lt;span class="'.$css_class.'"&gt;'; } </code>
How to add Disqus comment count
wordpress
Is it possible to get paged outside of the standard WP loop? I already use this inside the loop: <code> &lt;?php if ( $paged &gt;= 2 ) { ?&gt; Some text for the 2nd page on up &lt;?php } ?&gt; </code> But I'd like to be able to echo some text outside the loop on all pages two and greater. Possible? Or a better way?
Here you go: <code> &lt;?php if ( is_paged() ) echo 'some text'; </code> See http://codex.wordpress.org/Conditional_Tags#A_Paged_Page
Get paged outside of loop?
wordpress