question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I need to run a background process in a plugin that does some work on ALL the posts in a person's database once the plugin is installed. I'm very new at working with wordpress so my research has shown that I can use the wp query or I can use "the loop". Since I'm going through absolutely every single post speed is of the essence. I need to check the title, body, categories, meta tags, publish state and password protected. So based on this, which one of these would be fastest?
"The Loop" is just a name given to the <code> while (have_posts()): the_post(); </code> loop used to iterate over an array of posts returned by <code> WP_Query() </code> . The other function used for querying posts is the get_posts() function, which returns a simple (non-extended) array which you can loop through with a <code> foreach </code> loop. I don't think it matters a whole lot; however, if you're nitpicking, the <code> get_posts() </code> method is slightly faster and less memory-intensive, since it doesn't call <code> setup_postdata() </code> (which populates the template tags, etc.) on every post it loops through. Either way, you're probably going to run out of memory on some setups with thousands of posts... Make sure you build in fallbacks in that case.
Fastest way to loop through all posts?
wordpress
How can I check if the current page is <code> wp-login.php </code> or <code> wp-signup.php </code> ? Are there more elegant solutions than using <code> $_SERVER['REQUEST_URI'] </code> ?
Use the global <code> $pagenow </code> ; <code> if ( in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ) run_my_funky_plugin(); </code>
Check if we're on the wp-login page?
wordpress
I've got a plugin that transfers some files over to the uploads folder of the site in which the plugin is installed. It works fine, however, the images are not appearing in the Media Manager. I expect some database registration is involved. Given the script below which copies the files into the directory, what command would I need to add to the loop to register each image for the media manager? <code> foreach(new RecursiveIteratorIterator($rdi) as $files) { if ($files-&gt;isFile()) { $imagepath = $files-&gt;getRealPath(); $image = basename($files-&gt;getPathname()); copy($imagepath, $my_target_folder.'/'.$image); } } </code>
add this to your for each and $filename to each file, <code> $wp_filetype = wp_check_filetype(basename($filename), null ); $attachment = array( 'post_mime_type' =&gt; $wp_filetype['type'], 'post_title' =&gt; preg_replace('/\.[^.]+$/', '', basename($filename)), 'post_content' =&gt; '', 'post_status' =&gt; 'inherit' ); $attach_id = wp_insert_attachment( $attachment, $filename, 0 ); // you must first include the image.php file // for the function wp_generate_attachment_metadata() to work require_once(ABSPATH . "wp-admin" . '/includes/image.php'); $attach_data = wp_generate_attachment_metadata( $attach_id, $filename ); wp_update_attachment_metadata( $attach_id, $attach_data ); </code>
How to get an image transferred via FTP or script to appear in Media Manager?
wordpress
I am creating multiple pages in Wordpress. I understand I can style these with page.php. Is there any way I can style specific pages with custom templates? So for example if I had page About Us I would want a sidebar that has links to our profiles. If I had page Contact Us I would want a sidebar that has links for emailing us.
there are a few way you can do that: Template Hierarchy - each page with is own theme file using page-{ID/slug}.php Custom Page Templates - Individual Pages can be set to use a specific custom Page Template from the edit screen. but if you are just looking to change whats on the sidebar then there are a few plugins that can help you with that: Widget Logic - lets you control on which pages widgets appear. Dynamic Widgets - lets you dynamicly place the widgets on WordPress pages. and there are even plugins that let you display the whole sidebar on a page to page basis: Sidebar Generator Per Page Sidebars Custom sidebars
Custom template for each page
wordpress
I'm creating a new Wordpress template and I have a question: I've added a custom Option Page to my new template (you can see what I'm doing stackexchange-url ("Here") and stackexchange-url ("Here")) but now I would like to add a new function. Do you know Si Contact Form? In this plugin the end user can download a backup of all the settings and Upload it on a different website. I would like to be able to add the same function into my new option page. I know how to backup my settings logging to phpMyAdmin but sometimes end-user can't login to phpMyAdmin or simply it's better that he/she doesn't login to phpMyAdmin :-). Have you got any solution to this? Actually all my custom functions are named: 'appaqua_ zona1c';'appaqua _zona1x' and so on... my theme shortname is appaqua. Please by kind with me, I'm not a professional programmer and I'm really sorry if I used wrong words to explain what I need. Thank you very much to all!
The easiest way would be to look at the code of Si Contact Form (since it already does what you want) and use the same kind of system. Shortly, you'll need methods to do the following: Create an XML (or other format) document of your theme options. Save/Export the XML document. Import the XML document (There's no point in exporting if you can't import it again). If you want to use Si Contact Form as an example, the backup routines are in: http://plugins.svn.wordpress.org/si-contact-form/trunk/si-contact-form-backup.php Basically, it just outputs a serialized version of your options in a file. You can then upload the file to your admin page, parse the serialized string of options, and restore whatever you need from a backup. The backup scripts for Si Contact Form are in the <code> si_contact_form_backup_restore() </code> function of this file: http://plugins.svn.wordpress.org/si-contact-form/trunk/si-contact-form.php (Most of the way down the page). It just reads the file, parses the options, and sets them in the database as needed.
How to add an export function to a custom Option Theme Page
wordpress
Is there a way to get my custom TinyMCE button to insert multiple lines of text? Ultimately I am making a "Premade Themes" button where a user will select a theme and it will insert about 6-8 different shortcodes with one click and they can edit the shortcodes accordingly.. A problem I'm having is that all of these shortcodes get put in one line. Here's the code I use that actually pastes the shortcodes: <code> tinyMCEPopup.editor.execCommand('mceInsertClipboardContent', false, {content : 'the shortcodes go here'}); </code> Any help is appreciated!
This should be as easy as adding <code> &lt;br /&gt; </code> between shortcodes or every time you want to add a new line and also if you are inserting content you should use <code> mceInsertContent </code> instead of <code> mceInsertClipboardContent </code> unless you are actually getting the content from the clipbard, so: <code> tinyMCEPopup.editor.execCommand('mceInsertContent', false, '&lt;p&gt;[shotcode1]&lt;br/&gt;[shotcode2]&lt;br/&gt;[shotcode3]&lt;/p&gt;')); </code>
TinyMCE Button to Insert Multiple Lines of Text?
wordpress
I always though the the image manager into wp is not really good... I need to be able to generate square or custom size when i like where i like, much like TimThumb that generate thum on the fly... but a little complicated... what do you use or what is the best plugin...
I have find this faboulous article... just copy/paste it here for future reference : http://webdeveloperplus.com/wordpress/how-to-use-thumbnails-generated-by-wordpress-in-your-theme/
Thumbnail and image management
wordpress
I'm creating a rather complex plugin that synchronizes posts from your server with a thirdparty server. I need to know, if you migrate your wordpress server to a new site, "can" the post ids change? If so is there another unique id? Also, is there any other instance where a post id could change? If the id does change and there is no other unique id then chances are I'll just do some complex md5 signature checking and string comparison if need be.
The <code> wp_posts </code> table has a <code> guid </code> field, which should be globally unique, and survive migrations. It is formed by taking the initial post URL, and never changed after that (when you change the title, change the website address, or migrate the posts). This should be pretty safe to base your synchronisation code on.
Will post id change when migrating to new site?
wordpress
I would like to display all agents a-z, except there is one agent who should always show up last. Ideally I'd like the ordering to be done from the value of a custom field, dName. I was looking around it seemed that meta_query was the new best way to do this but haven't figured it out yet. Current code that shows 10 last agents created. <code> &lt;?php $loop = new WP_Query( array( 'post_type' =&gt; 'agents', 'posts_per_page' =&gt; 10 ) ); ?&gt; </code> Thanks for looking. edit 3/27/2011, working code <code> &lt;?php $loop = new WP_Query( array( 'post_type' =&gt; 'agents', 'orderby' =&gt; 'meta_value', 'meta_key' =&gt; 'rw_dname', 'order'=&gt;'ASC', 'meta_query' =&gt; array( array( 'key' =&gt; 'rw_dName' ) ), 'post__not_in' =&gt; array( '98' ), 'posts_per_page' =&gt; -1 ) ); $loop2 = new WP_Query( array( 'post_type' =&gt; 'agents', 'post__in' =&gt; array( '98' ) ) );?&gt; &lt;?php if($loop-&gt;have_posts() || $loop2-&gt;have_posts()) { if($loop-&gt;have_posts()) { while($loop-&gt;have_posts()) { $loop-&gt;the_post();?&gt; &lt;div class="agentContent"&gt; &lt;div class="agentThumbnail"&gt; &lt;?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it. the_post_thumbnail(); }?&gt; &lt;/div&gt; &lt;div class="agentInfo"&gt; &lt;span class="agentInfoEntry"&gt; &lt;?php $meta = get_post_meta(get_the_ID(), 'rw_dname', true); echo $meta; // if you want to show ?&gt; &lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php } //endwhile } ?&gt; &lt;?php if($loop2-&gt;have_posts()) { while($loop2-&gt;have_posts()) { $loop2-&gt;the_post();?&gt; &lt;div class="agentContent"&gt; &lt;div class="agentThumbnail"&gt; &lt;?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it. the_post_thumbnail(); } ?&gt; &lt;/div&gt; &lt;div class="agentInfo"&gt; &lt;span class="agentInfoEntry"&gt; &lt;?php $meta = get_post_meta(get_the_ID(), 'rw_dname', true); echo $meta; // if you want to show ?&gt; &lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php } //endwhile } ?&gt; &lt;?php } else { echo 'No Agents.'; } ?&gt; </code>
I just wrote this up so I have not tested it but this is how I would go about forcing one post to be at the end. In the first loop it excludes the posts by its ID number and in the second loop it only includes the post by the ID number, essentially you will need to know the ID of the post. <code> &lt;?php $loop = new WP_Query( array( 'post_type' =&gt; 'agents', 'orderby' =&gt; 'meta_value', 'meta_key' =&gt; 'dName', 'post__not_in' =&gt; array( 00 ), 'posts_per_page' =&gt; -1 ) ); $loop2 = new WP_Query( array( 'post_type' =&gt; 'agents', 'post__in' =&gt; array( 00 ) ) ); if($loop-&gt;have_posts() || $loop2-&gt;have_posts()) { if($loop-&gt;have_posts()) { while($loop-&gt;have_posts()) { $loop-&gt;the_post(); echo the_title(); echo get_post_custom_values('dName'); //Post Content } //endwhile } if($loop2-&gt;have_posts()) { while($loop2-&gt;have_posts()) { $loop2-&gt;the_post(); echo the_title(); echo get_post_custom_values('dName'); //Post Content } //endwhile } } else { echo 'No Agents.'; } ?&gt; </code>
Display agents (custom post type) alphabetically, except one who always shows last
wordpress
I'm finding this string appended to the end of my URLs sometimes: <code> /?doing_wp_cron </code> Does anyone know what it for? How can I remove it?
It's a sign that you have <code> ALTERNATE_WP_CRON </code> defined in your <code> wp-config.php </code> In order to do some background processing (like publishing scheduled posts), WordPress redirects you to the URL with <code> ?doing_wp_cron </code> appended.
Why is ?doing_wp_cron being appended to my URLs
wordpress
when using "insert video" from the post-editor - i'm only getting a normal hyperlink to the video - is it possible to display a flash-videoplayer instead? is there a default videoplayer in wordpress or will i need a plugin? in that case - which plugin is recommended? thx
Indeed, the "Insert video" action does not do much beyond creating a link. WordPress does not contain a generic player that can play any video hosted anywhere on the internet, but it does support something better: embedding via oEmbed . This means you can put the URL of the video page in your content, and it will replace it with the proper embed code - if the video site supports oEmbed (most popular sites do), and if WordPress is configured to allow embed from this site (but you can enable oEmbed autodiscovery or use a plugin like Embedly to add more sites). The support in the editor could be better, but this is probably the most future-proof way to embed videos in your posts.
Wordpress 3.1: Videoplayer implemented?
wordpress
I'm a bit confused about <code> wp_list_pages() </code> function. Lets say I have 3 top level pages (with no parent) and each of them have some sub-pages: page 1 [sub-pages: 1.1, 1.2, 1.3]; page 2 [sub-pages: 2.1, 2.2, 2.3]; page 3 [sub-pages: 3.1, 3.2] What I'm trying to do is to display top level pages 2 and 3 with all their subpages: <code> wp_list_pages( 'sort_column=menu_order&amp;depth=0&amp;title_li=&amp;include=2,3' ); </code> I have also tried so specify the depth as depth=2: <code> wp_list_pages( 'sort_column=menu_order&amp;depth=2&amp;title_li=&amp;include=2,3' ); </code> However, the top level pages 2 and 3 are displayed with no subpages. I'm not sure if I understood the function description correctly. How do I achive such functionality when sub-pages can be added/deleted at any time. Many thanks, Dasha
Thanks to <code> @Bainternet </code> for pointing me to the <code> exclude_tree </code> , although I ended up using a bit different code. It was important to be able to add top-level pages that don't have to appear in the menu (for example for Improved Include Page Plugin . Using the <code> exclude_tree </code> I would need to update the code every time a new top-level page is added. Instead, I have an array of all top-level pages that need to appear in the menu. I then collect all their desendant pages and use <code> wp_list_pages </code> to display only secelted pages. Here is the code: <code> &lt;?php //main nav: use wp_list_pages to display cirtain parents pages and all thier descendant pages $parents = array(2,3); $children = array(); foreach($parents as $parent) { $child_pages = get_pages( "child_of=$parent" ); if($child_pages){ foreach($child_pages as $child_page){ $children[] = $child_page-&gt;ID; } } } //merge $parents and $children $menu_pages = array_merge((array)$parents, (array)$children); $menu_pages_str = implode(",", $menu_pages); ?&gt; &lt;ul id="main-nav"&gt; &lt;?php wp_list_pages( "sort_column=menu_order&amp;title_li=&amp;include=$menu_pages_str" ); ?&gt; &lt;/ul&gt; </code> Also, have a look at the Codex List parent Page and all descendant Pages for more examples.
confused about wp_list_pages() function - how to display selected top pages with all their subpages
wordpress
i'm using the default "insert video" function from wordpress (which inserts a normal hyperlink to the video only) and would like to replace that link with something else like a video player. my question: what's the regex pattern for grabbing all links inside a post? thx
I'll answer your question below, but have you looked at using embeds? Look here for more information: http://codex.wordpress.org/Embeds The simplest regex for this would look something like <code> http\:\/\/.*\b </code> Here's an example of it in action: <code> &lt;?php $file = 'test.txt'; $fp = fopen($file, 'r'); $contents = fread($fp, filesize($file)); $matches = array(); preg_match_all('/http\:\/\/.*\b/', $contents, $matches); print_r($matches); ?&gt; </code> Where the file I reference looks like this: stackexchange-url and the return looks like this: Array ( [0] => Array ( [0] => stackexchange-url [1] => http://www.youtube.com [2] => http://ca3.php.net/manual/en/function.preg-match.php ) )
Retrieving all Links from a Post?
wordpress
Is there a way to get a path to the themes directory without the current theme in the path? ie, in a standard WP install, I would want a reference to: C:\xampplite\htdocs\sitename/wp-content/themes/ But the TEMPLATEPATH constant returns... C:\xampplite\htdocs\sitename/wp-content/themes/currentActiveTheme
<code> dirname( STYLESHEETPATH ); </code> That will return the theme directory. Never assume <code> /wp-content/ </code> below ABSPATH. I’m using often a different directory and domain for <code> wp-content </code> to enable cookieless requests to theme files. Bad plugins and themes break terribly in such cases. Addendum Or use <code> get_theme_root() </code> for the file path and <code> get_theme_root_uri() </code> for the URI. Both are defined in <code> wp-includes/theme.php </code> .
TEMPLATEPATH without the theme name? No THEMEPATH constant?
wordpress
Has anyone effectively integrated GD star rating and Cube Points ? From the documentation: Plugin Integration CubePoints can also be easily integrated with other plugins. Other plugins can be coded such that certain actions trigger the cp_alterPoints() function to add or subtract points from a specified user. Function <code> cp_alterPoints( int $uid, int $points ) </code> Parameters int $uid: ID of a Wordpress user. To get the ID of the current logged in user, use the cp_currentUser() function. int $return: Number of points to add to the specified user. Example The following code will add 10 points to the current logged in user. If no user is logged in, no points will be added. You may input negative number to subtract points. <code> &lt;php if( function_exists('cp_alterPoints') &amp;&amp; is_user_logged_in() ){ cp_alterPoints(cp_currentUser(), 10); cp_log('hey', cp_currentUser(), 10, 1); } ?&gt; </code> In this case, I would like to add 10 points to the user, if his or her post is voted (GD star rating's thumbs rating system). But I have no idea how to do that. Any suggestions?
From this page , you can see that <code> gdsr_vote_rating_article </code> is the hook you need - it gets called when a post rating is saved.
Has anyone effectively integrated GD star rating and Cube Points?
wordpress
I'm working on a migration from another CMS to WordPress. The old site had terrible SEO-unfriendly URLs in the format <code> http://example.com?lid=1234 </code> . We have imported all the posts from the old site into WordPress and are storing the <code> lid </code> as a custom field. We would love the old URLs to still work if possible, but as there are about 3,000 posts using .htaccess is out of the question. So my question is: how would I create a rewrite rule that extracts the <code> lid </code> value from the URL and redirects to the post that contains it in the custom field? (the <code> lid </code> value is unique, so there are no worries about more than one post with the same custom field value) Many thanks Simon
here is an idea, first add <code> lid </code> to query_vars: <code> add_filter('query_vars', 'lid_query_vars'); function lid_query_vars($vars) { // add lid to the valid list of variables $new_vars = array('lid'); $vars = $new_vars + $vars; return $vars; } </code> then use <code> parse_request </code> hook to create your redirect <code> add_action('parse_request', 'lid_parse_request'); function lid_parse_request($wp) { // only process requests with "lid" if (array_key_exists('lid', $wp-&gt;query_vars) &amp;&amp; $wp-&gt;query_vars['lid'] != '') { $args = array('meta_key' =&gt; 'lid', 'meta_value' =&gt; $wp-&gt;query_vars['lid']); $redirect_to_post = get_posts($args); foreach($redirect_to_post as $p){ $link = get_permalink($p-&gt;ID); wp_redirect( $link , 301 ); exit; } } } </code>
URL rewrite based on a custom field value
wordpress
How would one move the sharedaddy buttons included in Jetpack to be placed before a post's or page's content, rather than after it? I see that in <code> sharing-service.php </code> the function that prints the buttons is hooked to the_content filter hook: <code> add_filter( 'the_content', 'sharing_display', 19 ); </code> I'm not sure what to place in my functions.php file to override that, though. I'm assuming I somehow need to cause the output from <code> sharing-service.php </code> to be prepended to <code> the_content </code> rather than appended to it.
Basically it line 480 in sharing-service.php where it says: <code> return $text.$sharing_content; </code> and it should be <code> return $sharing_content.$text; </code> now changing that file won't keep your changes on updates so you can copy that function (sharing_display) to your functions.php and rename it to something different say <code> my_sharing_display </code> and make the change there. Next you need to remove the filters that plugin adds and replace with your own so in your functions.php add: <code> //remove old remove_filter( 'the_content', 'sharing_display'); remove_filter( 'the_excerpt', 'sharing_display'); //add new add_filter( 'the_content', 'my_sharing_display', 19 ); add_filter( 'the_excerpt', 'my_sharing_display', 19 ); </code> Update the remove_filter hook is not actually removing because it's missing the priority parameter , from the codex: Important: To remove a hook, the $function_to_remove and $priority arguments must match when the hook was added. This goes for both filters and actions. No warning will be given on removal failure. so change : <code> remove_filter( 'the_content', 'sharing_display'); remove_filter( 'the_excerpt', 'sharing_display'); </code> to: <code> remove_filter( 'the_content', 'sharing_display',19); remove_filter( 'the_excerpt', 'sharing_display',19); </code>
Moving sharedaddy buttons (in Jetpack) to the top of a post?
wordpress
As the title says, I have not found any function to add an option page to a particular custom post type. I would like to keep the option page related to a custom post type grouped together in its own panel, instead of adding it to the "Setting" panel, for example. Any suggestion? Thank you
use add_submenu_page() and as the pass <code> add_submenu_page('edit.php?post_type=YOUR_POST_TYPE_NAME',....); </code>
How to add an option page to custom post type?
wordpress
Got a custom field called <code> startDate </code> but its only on a few events. I was wondering if it isn't set for a post I could use <code> post_date </code> to generate the posts list? <code> // if meta_key _postmeta.startDate isn't set get the rest by posts.post_date query_posts( array( array( 'posts_per_page' =&gt; 10, 'meta_key' =&gt; 'startDate', 'meta_value' =&gt; date('Y-m-d'), 'meta_compare' =&gt; '&lt;', 'orderby' =&gt; 'meta_value', 'order' =&gt; 'ASC' ), array( 'meta_key' =&gt; 'post_date', 'meta_value' =&gt; date('Y-m-d'), 'meta_compare' =&gt; '&lt;' ) ) ); </code>
If you can explain it in SQL, you can query for it! There are three places where we want to change the default query: <code> SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') AND wp_postmeta.meta_key = 'startDate' AND CAST(wp_postmeta.meta_value AS CHAR) &lt; '2011-03-23' GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value DESC LIMIT 0, 10 </code> The join should be a left join The where-clause The order The join and the where-clause are added via the <code> _get_meta_sql() </code> function . The output is filtered, so we can hook into it: <code> add_filter( 'get_meta_sql', 'wpse12814_get_meta_sql' ); function wpse12814_get_meta_sql( $meta_sql ) { // Move the `meta_key` comparison in the join so it can handle posts without this meta_key $meta_sql['join'] = " LEFT JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = 'startDate') "; $meta_sql['where'] = " AND (wp_postmeta.meta_value IS NULL OR wp_postmeta.meta_value &lt; '" . date('Y-m-d') . "')"; return $meta_sql; } </code> The order clause is filtered through <code> posts_orderby </code> : <code> add_filter( 'posts_orderby', 'wpse12814_posts_orderby' ); function wpse12814_posts_orderby( $orderby ) { $orderby = 'COALESCE(wp_postmeta.meta_value, wp_posts.post_date) ASC'; return $orderby; } </code> This gives us the following SQL query: <code> SELECT wp_posts.* FROM wp_posts LEFT JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = 'startDate') WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') AND (wp_postmeta.meta_value IS NULL OR wp_postmeta.meta_value &lt; '2011-03-23') GROUP BY wp_posts.ID ORDER BY COALESCE(wp_postmeta.meta_value, wp_posts.post_date) ASC LIMIT 0, 10 </code> Remember to unhook the filters after you did your query, otherwise you will mess up other queries too. And if possible query_posts() </code> yourself , but modify the main post query that is done by WordPress while setting up the page.
Order by meta value or date?
wordpress
actually I'm running a wordpress MU website and each website has its own "life" but now I would like to show last X posts of each blog of my network on the homepage. I know how to do it using Feeds and a plugin named FeedPress but this is a "dirty" way to do it. Is there anyone who knows how to do it? Please Step by Step instructions I'm not a Noob but.... not even a programmer. Thank you to all!
If you've already got a solution that works using FeedPress you might as well stay with that, there isn't a particularly clean way of aggregating multisite posts into a single blog. One alternative is to use the Sitewide Tags plugin , but given what you want to do, you should probably stay with what's working.
How to show last post of each website of a MU wordpress in HomePage
wordpress
i've just built my first plugin for wp, and even if it's not a great "code poetry" ;) it works as it should. It's a plugin that transform the default wp gallery using the GalleryView 3.0 jquery plugin ( http://spaceforaname.com/galleryview ). The only thing i'm not able to do is localization. Localization for this plugin in means translating the admin interface, where someone can configure the jquery plugin options to change the aspect of the resulting gallery. I've tried to follow the millions of tutorials present on the web, read a lot of posts about this issue on forums and followed the guidelinees of codex... but still with no luck. This is what i've done: Every text line is inside a gettext function ( <code> __ </code> and <code> _e </code> ) Using poedit i created the <code> .po </code> and <code> .mo </code> file scanning the plugin directory (everythig went ok), then i added translations on that file. I named the <code> .po </code> file like that <code> NAME-OF-THE-PLUGIN-it_IT.po </code> (the <code> .mo </code> file was generated with the same name) I've put the translations files inside the plugin folder <code> /languages </code> (name of the folder is the same of the plugin and of the translations files) Then i've tried to add the <code> load_plugin_textdomain </code> function inside the main plugin file. I've tried because there's no way to get it working. The only thing on which i'm not sure is the fact that the plugin i've created is not under a class + constructor funcions... just because i'm still not so good in coding. I've put the <code> load_plugin_textdomain </code> inside an <code> add_action </code> on init, like this: <code> add_action('init', 'gw_load_translation_file'); function gw_load_translation_file() { // relative path to WP_PLUGIN_DIR where the translation files will sit: $plugin_path = dirname(plugin_basename( __FILE__ ) .'/languages' ); load_plugin_textdomain( 'gallery-view-for-wordpress', false, $plugin_path ); } </code> The lines above are not inside a logic, they are just in the main plugin file, like that. This is an example of my use of gettext functions: <code> &lt;h3&gt;&lt;?php _e('Panel Options', 'gallery-view-for-wordpress') ?&gt;&lt;/h3&gt; </code> What did i not understand?
<code> $plugin_path = dirname( plugin_basename( __FILE__ ) ) . '/languages/'; </code>
Plugin Localization
wordpress
How do I add classes in the wp_list_category , I know the wp_list_categories('title_li='); generates classes , but I want to add a class in the parent category link <code> &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt; link1&lt;/a&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;link2 &lt;/a&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;link3 &lt;/a&gt; &lt;---how do I add a special class here &lt;ul class="children"&gt; &lt;li&gt;&lt;a href="#"&gt;link3 children &lt;/a&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt; link3 children&lt;/a&gt; &lt;/li&gt; &lt;/li&gt; &lt;/li&gt; &lt;/ul&gt; </code> Im planning to use a jquery UI accordion in here, please help. thank you -edit-- problem solved by Paul , thanks man
jquery accordion accepts an option called header that allows you to provide a selector to designate the items you want to act as the accordion headers. <code> $('li.categories &gt; ul').accordion({ header: 'li.categories &gt; ul &gt; li' }); </code>
How to add classes in the wp_list_category parent link
wordpress
Anyone has experience using the GD Star Rating plugin? and make a loop that sorts posts by vote/stars?
First 2 results on googling for "gd star rating sort posts by rating' are: How to Sort Post by Gd Star Rating Mirror How to reorder posts Mirror Few examples: <code> query_posts("gdsr_sort=rating"); query_posts("gdsr_sort=review&amp;sort_order=asc"); query_posts("gdsr_sort=rating&amp;gdsr_multi=3"); query_posts("gdsr_sort=votes&amp;sort_order=asc&amp;gdsr_multi=3"); </code>
Is it possible to sort posts by vote using the GD Star Rating plugin?
wordpress
I'm new to wordpress and trying to learn my way through from making a theme. Right now I am using wp_nav_menu to generate my menu My menu consists of pages and categories However, the default generation of the menu looks like <code> &lt;div id="navi"&gt; &lt;div class="menu-primary-container"&gt; &lt;ul id="menu-primary" class="menu"&gt; &lt;li id="menu-item-14" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-14"&gt;&lt;/li&gt; &lt;li id="menu-item-16" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-16"&gt;&lt;/li&gt; &lt;li id="menu-item-20" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20"&gt;&lt;/li&gt; &lt;li id="menu-item-15" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-15"&gt;&lt;/li&gt; &lt;li id="menu-item-17" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-17"&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; </code> I want to remove all the class and id from li and ul. I have been googling for awhile now. Tried different methods and no luck. Any help would be much appreciated. I'm currently using Wordpress 3.1 Thank you in advance!
If you look in the <code> wp_nav_menu() </code> function , you see the items are written by <code> walk_nav_menu_tree() </code> , which calls <code> Walker_Nav_Menu </code> to do the work (unless you specified your own walker class). This class contains a method <code> start_el() </code> that is called for each menu item. In this function, you see that the classes are filtered through <code> nav_menu_css_class </code> and the id is filtered through <code> nav_menu_item_id </code> . So if you attach your own code to these hooks, you can change them to anything you want. Submenus are always wrapped with <code> &lt;ul class="sub-menu"&gt; </code> , the main wrapper can be changed via the <code> menu_id </code> and <code> menu_class </code> arguments .
wp_nav_menu remove class and id from li
wordpress
I just realized, that i got a complete *empty WP_Query object* on my plain wordpress install. I reseted the DB, deactivated all plugins and activated TwentyTen as theme, but the complete Object simply is empty on every request (public &amp; admin facing). It doesn't matter if i request the " Hello World " post or a <code> 404 </code> . Everything is empty. What reason could this have? Edit 1 This is how i inspect WP_Query : <code> // inserted on top of the functions.php file, // so it's equal to a function hooked into the 'after_setup_theme' hook // i also tried other hooks (which should make no difference) and got the same result. echo '&lt;pre&gt;'; print_r($GLOBALS['wp_query']); echo '&lt;/pre&gt;'; </code> This is the result from the <code> print_r(); </code> <code> WP_Query Object ( [query] =&gt; [query_vars] =&gt; Array ( ) [tax_query] =&gt; [queried_object] =&gt; [queried_object_id] =&gt; [request] =&gt; [posts] =&gt; [post_count] =&gt; 0 [current_post] =&gt; -1 [in_the_loop] =&gt; [post] =&gt; [comments] =&gt; [comment_count] =&gt; 0 [current_comment] =&gt; -1 [comment] =&gt; [found_posts] =&gt; 0 [max_num_pages] =&gt; 0 [max_num_comment_pages] =&gt; 0 [is_single] =&gt; [is_preview] =&gt; [is_page] =&gt; [is_archive] =&gt; [is_date] =&gt; [is_year] =&gt; [is_month] =&gt; [is_day] =&gt; [is_time] =&gt; [is_author] =&gt; [is_category] =&gt; [is_tag] =&gt; [is_tax] =&gt; [is_search] =&gt; [is_feed] =&gt; [is_comment_feed] =&gt; [is_trackback] =&gt; [is_home] =&gt; [is_404] =&gt; [is_comments_popup] =&gt; [is_paged] =&gt; [is_admin] =&gt; [is_attachment] =&gt; [is_singular] =&gt; [is_robots] =&gt; [is_posts_page] =&gt; [is_post_type_archive] =&gt; [parsed_tax_query] =&gt; ) </code>
It's empty because you're looking at it before it has a chance to be populated. The top of functions.php is too early. You should be doing it in a 'template_redirect' action. Or, better yet, use the Debug Bar plugin.
empty WP_Query object on local install
wordpress
Is there a way to remove <code> wptexturize </code> only for a certain shortcode?
There is a clue in <code> wp-includes/formatting.php </code> in the function <code> wptexturize </code> : <code> $default_no_texturize_shortcodes = array('code'); ... $no_texturize_shortcodes = '(' . implode('|', apply_filters('no_texturize_shortcodes', $default_no_texturize_shortcodes) ) . ')'; </code> Try using this filter to add a shortcode to the array: <code> function my_no_tex( $shortcodes ) { $shortcodes[] = 'someshortcode'; return $shortcodes; } add_filter( 'no_texturize_shortcodes', 'my_no_tex' ); </code>
Remove wptexturize from a shortcode?
wordpress
I have a few plugins that I always set the configuration for exactly the same way. Every time I create a new site, the same plugins go in, and the same amount of time is needed to set them up. Would it be possible to create a config file that overrides whatever wp_options are set per plugin?
You could check which options they add (look at the source code) and then simply write a function like this: <code> /* Plugin Name: Mother of all plugins Plugin URI: http://wordpress.org/extend/plugins/ Description: Offers the &lt;code&gt;$all_plugin_options;&lt;/code&gt; var to access all predefined plugin options Author: Franz Josef Kaiser Author URI: http://say-hello-code.com Version: 0.1 License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html */ // Template Tag function get_all_plugin_options() { // First we call the class $class = new MotherOfAllPlugins; $data = $class-&gt;predefined_plugin_options() return $data; } if ( ! class_exists('MotherOfAllPlugins') ) { class MotherOfAllPlugins { protected $plugin_options; public function __construct( $plugin_options ) { // defaults $default_options = array( 'plugin_a' =&gt; array( 'deprecated' =&gt; '' ,'name' =&gt; 'value' ,'key' =&gt; 'value' ) ,'plugin_b' =&gt; array( 'deprecated' =&gt; '' ,'name' =&gt; 'value' ,'key' =&gt; 'value' ) ); // Now overwrite the $this-&gt;plugin_options = array_merge( $default_options, $plugin_options ); add_action( 'init', 'predefined_plugin_options' ); } function predefined_plugin_options() { // Set the flag if we have already done this // _EDIT #1:_ This sets an option in the wp_options table containing TRUE if your plugin predef options are already present in the DB if ( !get_option( 'predef_plugins_setup' ) === TRUE ) add_option( 'predef_plugins_setup', TRUE ); if ( !get_option( 'predef_plugins_setup' ) === TRUE ) { // Add the options for the plugins foreach ( $plugin_options as $plugin =&gt; $options ) { add_option( $plugin, $options, $options['deprecated'], 'yes' ); } } // _EDIT #2:_ return the initial array for use in a global return $plugin_options } } // END Class MotherOfAllPlugins } // endif; </code> To get your plugin options inside your theme: <code> // Now we take the return value &amp; add it into global scope for further useage. // This way we can access all options easily without a call to the DB. // You can now access these values from anywhere in your theme. $all_plugin_options = get_all_plugin_options(); </code> Be careful to really add the options exactly the way the plugins does it. Else stuff won't work.
Default plugin config to override wp_options?
wordpress
I feel like I've been banging my head against the keyboard for a week with this problem. I'm trying to change my current query on my home page to show only posts that are set as standard posts using the new post format. I've looked everywhere for answers (including stackexchange-url ("here") and stackexchange-url ("here")) and tried everything I've found, but I can't get it to work within the framework of my current query. My query is provided below. Any help is greatly appreciated. <code> &lt;?php query_posts( array( 'post__not_in' =&gt; $ids, 'showposts' =&gt; 10, 'cat' =&gt; '-4' ) ); ?&gt; &lt;?php while (have_posts()) : the_post(); ?&gt; -LOOP STUFF- &lt;?php the_excerpt(); ?&gt;&lt;BR&gt; &lt;?php endwhile; ?&gt; </code> UPDATE - March 30: Since I posted this I found out how to properly query for, we'll say, image posts using this code: <code> &lt;?php $args = array( 'post__not_in' =&gt; $ids, 'showposts' =&gt; 10, 'cat' =&gt; '-4,-1866,-27', 'tax_query' =&gt; array( array( 'taxonomy' =&gt; 'post_format', 'field' =&gt; 'slug', 'terms' =&gt; 'post-format-image' ) ) ); query_posts( $args ); ?&gt; &lt;!-- Look Stuff --&gt; &lt;?php endwhile; ?&gt; </code> But I still need to figure out how to do the opposite and only pull standard posts. Second Update - March 30: I found the answer after some more hunting. Apparently the only way to pull the standard posts is to add: 'operator' => 'NOT IN', So it looks for posts that aren't in the image post format. Or I have to add an array of terms to the terms line so it won't return any of those formats. Odd, but it works.
Okay, I found the answer after some more hunting. Apparently the only way to pull the standard posts is to add: <code> 'operator' =&gt; 'NOT IN', </code> So it looks for posts that aren't in the image post format. Or I have to add an array of terms to the terms line so it won't return any of those formats. Odd, but it works. <code> &lt;?php $args = array( 'post__not_in' =&gt; $ids, 'showposts' =&gt; 10, 'cat' =&gt; '-4,-1866,-27', 'tax_query' =&gt; array( array( 'taxonomy' =&gt; 'post_format', 'field' =&gt; 'slug', 'terms' =&gt; 'post-format-image', 'operator' =&gt; 'NOT IN' ) ) ); query_posts( $args ); ?&gt; &lt;!-- The Loop --&gt; &lt;?php endwhile; ?&gt; </code>
Help altering a query to exclude all but standard post format
wordpress
I'm using stackexchange-url ("bainternet's") method for stackexchange-url ("searching custom post_types") and it works great. However, I've recently been requested to return more than one "specific" post type and perhaps individual pages for a support section on our site. I thought adding additional hidden fields would do it, but that didn't work. And I have no clue how this will work with pages. Any help would be appreciated! In the template: <code> &lt;form action="http://apollo.website.net/" id="searchform" method="get" role="search"&gt; &lt;div&gt;&lt;label for="s" class="screen-reader-text"&gt;Search for:&lt;/label&gt; &lt;input type="text" id="s" name="s" value=""&gt; &lt;input type="submit" value="Search" id="searchsubmit"&gt; &lt;input type="hidden" name="post_type" value="software" /&gt; &lt;/div&gt; &lt;/form&gt; </code> In functions.php: <code> /* Custom Search Queries */ function SearchFilter($query) { $post_type = $_GET['post_type']; if (!$post_type) { $post_type = 'any'; } if ($query-&gt;is_search) { $query-&gt;set('post_type', $post_type); }; return $query; } </code>
change <code> &lt;input type="hidden" name="post_type" value="software" /&gt; </code> to <code> &lt;input type="hidden" name="post_type[]" value="software" /&gt; &lt;input type="hidden" name="post_type[]" value="books" /&gt; </code> i have to run but this should work , just add as many hidden fields as you need for each post type
Searching multiple custom post types and pages
wordpress
Would somebody mind postulating and possible reasons why their is an automated redirect on my homepage that adds /admin to the URL. Please visit www.divethegap.com/update. You will see that it instantly redirects to /admin and does not load the page. There is a folder called admin that is not accessible to a user, but their is no redirect to it anywhere on the site. What is going on. I have removed all recent function additions in the theme and unistalled plugins. There are several include-template-paths that I use but I don't use any redirects. What has caused this. Any ideas? Marvellous HT ACCESS // <code> # BEGIN WordPress &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase /update/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /update/index.php [L] &lt;/IfModule&gt; # END WordPress </code>
By a process of elimination we have determined that the error was caused by the plugin REDIRECTION. This plugin has now been removed. I must point out that it was never used and certainly never set up to carry out that action. I can only imagine that somehow the creation of themed files must have had similar names to the plugins files. After checking the plugin file names that is also not the case. This remains a mystery. It was only through trial and error that we determined that it was this plugin causing the problem. If anyone has any theories I would like to hear them. Case closed
Random and Erroneous Wordpress Redirect
wordpress
What are you experiences compiling Wordpress using Hip Hop? ( https://github.com/facebook/hiphop-php/wiki/running-hiphop ) Specific: is this maintainable with upgrades? is the performance increase bigger than using alternatives? update: also interesting: http://www.phpclasses.org/blog/post/168-Can-NET-make-PHP-run-faster-than-the-official-PHP-implementation.html
Original approach of static compilation in HipHop PHP-to-C++ has been since replaced by HipHop VM just-in-time compilation . Facebook prominently featured WordPress as example application and it no longer requires extensive (barely any by now) core edits. Old answer There is quite extensive presentation Rasmus Lerdorf - PHP Performance that uses WP as test subject and covers HipHop among many other things. The summary I can formulate from that presenation is that HipHop: requires WP core edits has limited PHP and libraries compatibility provides (on vanilla WP install at least) very mild performance gain for the effort it takes to implement. In that presentation compiling with HipHop bumped WP from 28.8 transactions per second to 33.6 . I think more common performance improving alternatives (like reverse proxy) can easily outperform that without such downsides.
Experiences with compiling WordPress using Hip Hop?
wordpress
I am looking for what params are passed to my filter function. Where can I find such info in the codex? http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content didn't provide much info I wanted to know if the post is a child of another
I don't think there are any additional parameters passed, per se, to <code> the_content </code> , but global variables like $post are accessible. So something like this would work: <code> add_filter( 'the_content', 'check_for_post_parent' ); function check_for_post_parent($content) { global $post; if ($parent_id == $post-&gt;post_parent) { //do what you want to $content here, //now that you know $parent_id //... } return $content; } </code>
What params are available with the_content filter?
wordpress
When user clicks on Reply button for a specific comment, how can I then hide the reply button under said comment? Do I have any access to the javascript onclick function that it calls?
Ended up using jQuery to solve this. The form moves around using javascript anyways so it doesn't break anything for users with js turned off. <code> //when reply button is clicked hide it $(".comment-reply-link").click( function() { $(this).hide(); }); //when cancel button is clicked reshow reply button $("#cancel-comment-reply-link").click( function() { $(".comment-reply-link").show(); }); </code>
Hide reply button after moveForm is called
wordpress
hey guys, i know there is something like <code> if ( function_exists('') </code> is it possible to use that with <code> next_posts_link() </code> and <code> previous_posts_link() </code> . The reason I'm asking that is that I have something like <code> &lt;div class="navigation"&gt; &lt;div class="next-posts"&gt;&lt;?php next_posts_link('&amp;laquo; older') ?&gt;&lt;/div&gt; &lt;div class="prev-posts"&gt;&lt;?php previous_posts_link('newer &amp;raquo;') ?&gt;&lt;/div&gt; &lt;/div&gt; </code> In my case div.navigation has a colored background and a fixed height. So even there is no next or perv post this div.navigation appears. I wonder if I can only display this if there exists a next or prev post? Any idea how to do that?
Check out this link: http://www.ericmmartin.com/conditional-pagepost-navigation-links-in-wordpress-redux/ :)
only show container with next/prev links if they exist?
wordpress
<code> &lt;?php echo get_the_term_list( $post-&gt;ID, 'people', 'People: ', ' ', '' ); ?&gt; </code> returns something like this: <code> People: &lt;a href="person1"&gt;Person1&lt;/a&gt;, &lt;a href="person2"&gt;Person2&lt;/a&gt;, ... </code> How can I make it return the same thing without links like this: <code> People: Person1, Person2 </code>
It may be easier to just write the list manually, something like: <code> &lt;?php $terms = wp_get_post_tags( $post-&gt;ID ); //For custom taxonomy use this line below //$terms = wp_get_object_terms( $post-&gt;ID, 'people' ); foreach( $terms as $term ) $term_names[] = $term-&gt;name; echo implode( ', ', $term_names ); </code>
How can I remove links from the function "get term list"?
wordpress
I'm trying to filter posts in a category by the year of the post's date. I also want to do this without being redirected to the year template so my ideal URL would be http://example.com/category/reports/2011/ which would load the template file category.php where I could then use query_posts to include only the posts that were published in 2011 and are in the reports category. Here is my rewrite rule code... <code> function filter_category_by_year_rewrite_rules( $wp_rewrite ) { /* Creates rewrite rules for filtering category archives by year (/category/reports/2011/)*/ $new_rules = array( "category/(.+?)/(\d\d\d\d)/?$" =&gt; "index.php?category_name=" . $wp_rewrite-&gt;preg_index(1) . "&amp;year=" . $wp_rewrite-&gt;preg_index(2) ); $wp_rewrite-&gt;rules = $new_rules + $wp_rewrite-&gt;rules; var_dump($wp_rewrite); } add_action('generate_rewrite_rules', 'filter_category_by_year_rewrite_rules'); </code> My problem is WordPress automatically redirects <code> index.php?category_name=reports&amp;year=2011 </code> to <code> /category/reports/ </code> with no trace of the year parameter. How can I intercept this redirect? I tried hooking in to the <code> template_redirect </code> action to no avail :( <code> function testing_redirect() { global $wp; if($wp-&gt;request['matched_rule'] == 'category/(.+?)/(\d\d\d\d)/?$') { load_template( 'category.php' ); //TEMPLATEPATH .'/category.php'; } } add_action('template_redirect', 'testing_redirect', 1); </code>
This should work: <code> add_action( 'init', 'wpa12742_init' ); function wpa12742_init(){ add_rewrite_rule( 'category/(.+?)/(\d{4})/?$', 'index.php?category_name=$matches[1]&amp;year=$matches[2]', 'top' ); add_rewrite_rule( 'category/(.+?)/(\d{4})/page/(\d+)/?$', 'index.php?category_name=$matches[1]&amp;year=$matches[2]&amp;paged=$matches[3]', 'top' ); } </code> EDIT On second thought, that's not enough, since you'll get caught by <code> redirect_canonical() </code> . Add this too: <code> add_filter( 'term_link', 'wpa12743_term_link', 10, 3 ); function wpa12743_term_link( $link, $term, $taxonomy ){ if('category' != $taxonomy &amp;&amp; !preg_match( '@^\d{4}$@', get_query_var('year') ) ) return $link; return trailingslashit( $link ) . get_query_var( 'year' ); } </code>
Preventing index.php?category_name=something from redirecting
wordpress
i'm running my web in english and german using the WPML plugin. my question: when in english mode - is it possible getting the page_title() but in german? thanks
Let's say the original language of your site is english, then when visiting a german post you would return the title of the corresponding english post like that : <code> // Get the post ID of original post $original_ID = icl_object_id( $post-&gt;ID, 'post', false, 'en' ); // Get original post title $original_title = get_the_title( $original_ID ); </code> Hope that helps, in any case check out the documentation for icl_object_id();
WPML: getting page title in different language
wordpress
I'm trying to add some checkbox options to a sidebar search box, similar to this , where the user has the option to choose whether to search <code> All Words </code> , <code> Some Word </code> , or the <code> Entire phrase </code> . I did find this after some searching - Wordpress Search Phrases . The 'sentence' option seems to work well, but the others not so good. The code below is what I'm working on at the moment, but would really appreciate some help to get this working properly. Many thanks in advance, S. (I do not wish to use plugins for this). <code> &lt;form action="&lt;?php bloginfo('home'); ?&gt;/" method="post"&gt; &lt;div class="search-icon"&gt; &lt;label for="search" accesskey="4" class="hidden"&gt;Search the site&lt;/label&gt; &lt;input type="text" name="s" id="search" value="Enter search term" onblur="this.value = this.value || this.defaultValue;" onfocus="this.value = '';" /&gt; &lt;input type="submit" name="submit" value="GO" class="s-btn" /&gt; &lt;p&gt;&lt;a href="#" id="search-anchor"&gt;Search Options&lt;/a&gt;&lt;/p&gt; &lt;div class="option-slide"&gt; &lt;input type="radio" name="sentence" value="" checked="checked" /&gt;&lt;label&gt;All Words&lt;/label&gt;&lt;br /&gt; &lt;input type="radio" name="sentence" value="or" /&gt;&lt;label&gt;Some Word&lt;/label&gt;&lt;br /&gt; &lt;input type="radio" name="sentence" value="and" /&gt;&lt;label&gt;Entire phrase&lt;/label&gt; &lt;/div&gt; &lt;/div&gt;&lt;/form&gt; </code> EDIT: The answer below doesn't actually work after all : ( Anybody else have any ideas please?
First things first: the name attribute for your "All Words" checkbox shouldn't be 's'. That replaces the search text with "1", so when that's checked, you're searching for "1", not for the search text. I don't think you want to use 'exact' if you're looking to replicate the example you gave in your question. Here's an example: <code> Search for "Two Things" in titles and content: Matches Does not match "Two" "Two Things More" "Things" "One or Two Things" "Two Things" "Two Things." </code> I could go on and on about what it won't match, but you get the idea. This is probably why you are getting unexpected results. Anyway, try changing the name of the 'all words' checkbox to something that won't get matched, like <code> 'fake_search_flag_name' </code> , since that flag is just describing WordPress' normal default search capabilities anyway. EDIT Ok, now that they're radios, here's something you can do: The first one is WordPress' default behavior, so you need to make the VALUE empty: <code> &lt;input type="radio" name="sentence" value="" checked="checked" /&gt; All Words </code> If that box is checked, since the value is empty, WordPress will ignore it and use its default functionality. The next part is somewhat tricky. Change the values of the other two radios, something like this: <code> &lt;input type="radio" name="sentence" value="or" /&gt; Some Word&lt;br /&gt; &lt;input type="radio" name="sentence" value="and" /&gt; Entire phrase </code> In and of itself this will make them both behave the same way: the way you want 'Entire Phrase' to work. So we need to get 'Some Word' working. I haven't tested this next part at all, but it should work. We need to filter the search query to allow for the search terms to match posts that have some of the words but not all of them: <code> add_filter( 'posts_search', 'my_awesome_posts_search_filter' ); function my_awesome_posts_search_filter( $sql, $wpq ){ if( !isset( $wpq-&gt;query_vars['sentence'] ) || 'or' != $wpq-&gt;query_vars['sentence'] ) return $sql; $new_search = str_replace( ') AND (', ') OR (', $sql ); return $new_search; } </code> That should do it.
Search options/filters
wordpress
Background I'm nearing the final stages of constructing my first fairly large WordPress site, and I'm now encountering some friction. For the most part, the site was developed on my local machine and I would push changes up to a staging server for review (stackexchange-url ("see this question for more background")). The solution I ended up with worked quite well when it was just me editing content, but now some other people are editing the content while I still have features to add. The idea was: we could get things done more quickly if the features and the content came together in concert... but now I'm not so sure. Currently there is different content in the database on the staging server than on my local machine. That's fine by itself, as I don't need the final body copy on my local machine, but I need to do more development which will affect the database (install/write a couple more plugins which need their own tables). My question is: Is there an easy way to automate the merging of databases so that multiple people can work on a WordPress install? I could, of course, just export the tables which I know have changed on my local machine and push them to the staging server, but it's possible that there are also things on the staging server I would like to bring down. I could grab the SQL output of both DBs and diff them... but that seems tedious and hackish. I'm wondering if this is a problem others have solved; if there's a community-accepted way to handle this sort of thing. Thanks!
I asked this question over a year ago, and during that time we've added more people to our team and developed a much larger number of sites in WordPress. I wanted to walk through our process in case it might help anyone else. Everything in Git This was something I was doing even as I asked the question, but it's good to call this point out. Using Git has not only helped us be more productive, but it's also saved our collective asses several times. Have you ever needed to make major structural renovations to a site, get approval for those renovations from a client, and all the while make minor updates to the non-renovated version? We have, and Git let us do it. Describing this setup would get a bit long-winded, but the basics are that we made a new branch, pulled that branch on to the server, and attached a subdomain to that branch. We've also been saved by Git. It of course allows us to roll back changes, which is great, but it also allows us to bring old versions of files back. This means that if a client asks, "Remember how this part of the site worked about a year ago? Can we bring that back?", the answer is yes -- even if the person being asked wasn't on that project a year ago. Beside these points, it also means that we're never stuck without the files we need. We can always pull down the newest version of the site from any machine and start making changes. Use Git to deploy We do our WordPress hosting on Media Temple, and we really like them. They're not the cheapest provider, but their service is excellent and their servers are really well set up. The also provide Git by default. This means we can set the server up as a Git repository, and pull changes in that way instead of using SFTP. It also means that doing work on the server isn't in danger of being overwritten (as those changes can just be merged and pushed back up). Because we use BitBucket as our Git host, there's a little bit of extra work required here. First of all we use .ssh/config files so that we we can type things like <code> ssh sitename </code> to log into our servers (we also use passwordless SSH, which makes this super easy). We also make sure to always use ssh passphrases (Mac OS X makes this very easy by allowing you to store your passphrase in Keychain.app). Finally, we add the a ForwardAgent line to the .ssh/config entry on hosts we want to pull from. This means that we only need each person's SSH public key in BitBucket, and not the public key of each server. We also make sure to keep the <code> .git </code> directory one directory above the public HTML directory. Automated database dumps Once the server is in production mode, we make sure to automatically back up our database, just in case. Everyone has their own wp-config Because we've all got our own local database usernames and passwords, and because we could use different names and serving mechanisms, we each keep our own wp-config file. Each of these is stored in Git with a name like <code> wp-config-gavin.php </code> , and when we want to use that config, we symlink it to <code> wp-config.php </code> (which is ignored by Git using .gitignore). This also allows us to override the <code> siteurl </code> option in the <code> wp_options </code> database table like so: <code> define('WP_SITEURL', 'http://sitename.localhost'); define('WP_HOME', 'http://sitename.localhost'); </code> This prevents WordPress from looking at the database for the server location, and means there aren't weird differences in location between local and server installs. One final note about wp-config.php files: make sure to store them above the public HTML directory and make the permissions read only for the web user. This makes a huge difference in securing WordPress. The database issue Finally, the meat of the matter. What I had to accept is, when using WordPress, there's no good way to "merge" database changes. Instead, we needed to develop rules of conduct to solve this. The rules are fairly simple, and have served us well so far. During development, there's a single person who "owns" the site. That person usually does the setup (getting the hosting package together, starting the Basecamp project, slicing the design, that sort of thing). Once that person is to a reasonable point, the dump the database for the WordPress install and put it into Git. From that point forward, everyone doing development uses that database dump, and the owner is the only one who makes changes to the database. Once the site build gets a bit further along, the site is put on a server. From that point on, the server's database is canonical. Everyone (including the owner) must make all database changes on the server and pull the changes down for local development and testing. This process isn't perfect. It's still possible that someone might need to make changes in the WordPress backend locally during development, and then have to make those changes again in production. However, we've found that sort of thing to be rare, and this process works fairly well for us.
Multiple developers / editors working on a site in progress
wordpress
I'd like to check if the server is running PHP5.2. To do this, I use a activation-hook which will be registered with "register_activation_hook". Instead of just returning a warning, i'd like to auto-disable the plugin and redirect to the plugins.php in WP-Dashboard. Unfortunately, this doesn't work. No error or other output. The activation-hook fires correclty, tested with a wp_die(). What I'm doing wrong here? <code> register_activation_hook(__FILE__, 'MyActivationHook'); function MyActivationHook() { if(version_compare(PHP_VERSION, '111.2', '&lt;')) { deactivate_plugins(plugin_basename(__FILE__)); wp_redirect(admin_url('plugins.php')); //wp_die(printf(__('Sorry, you need at least PHP version %1s to use this plugin. Your current PHP version is %2s.', 'textdomain'), '5.2', PHP_VERSION)); } } </code>
You always have to <code> exit; </code> after a redirect.
Deactivate plugin on registration
wordpress
How do I add custom variables to the wordpress query without having to hit the database twice. In the example below I want to add some meta filters. All this code works fine but I have been running query_posts() to execute it. I want to be able to add to the query before it is run by default so I don't have to query the db twice. In this I was hoping if I modify $wp_query-> query before it is executed my changes would be added to the query. The query is being changed fine, just not the output. Any ideas? Thanks. <code> add_action('pre_get_posts', 'my_custom_query'); function my_custom_query(){ if(isset($_SESSION['size']) &amp;&amp; $_SESSION['size'] != 'all'){ $cfilter[] = array( 'key' =&gt; 'cc_size', 'value' =&gt; $_SESSION['size'] ); } if(isset($_SESSION['gender']) &amp;&amp; $_SESSION['gender'] != 'all'){ $cfilter[] = array( 'key' =&gt; 'cc_gender', 'value' =&gt; $_SESSION['gender'] ); } $extraArgs = array( 'orderby' =&gt; 'post-title', 'paged' =&gt; get_query_var('paged') ); if(!empty($cfilter)){ $extraArgs['meta_query'] = $cfilter; } global $wp_query; $wp_query-&gt;query = array_merge( $wp_query-&gt;query, $extraArgs ); </code> }
As toscho said, you can modify the query in the <code> pre_get_posts </code> hook. That hook gets the query object passed as an argument, so you don't have to read a global variable. <code> add_action( 'pre_get_posts', 'wpse12692_pre_get_posts' ); function wpse12692_pre_get_posts( &amp;$wp_query ) { if( isset( $_SESSION['size'] ) &amp;&amp; $_SESSION['size'] != 'all' ) { $wp_query-&gt;query_vars['meta_query'] = array( 'key' =&gt; 'cc_size', 'value' =&gt; $_SESSION['size'], ); } if( isset( $_SESSION['gender'] ) &amp;&amp; $_SESSION['gender'] != 'all' ) { $wp_query-&gt;query_vars['meta_query'] = array( 'key' =&gt; 'cc_gender', 'value' =&gt; $_SESSION['gender'], ); } $wp_query-&gt;query_vars['orderby'] = 'post-title'; // The next line is redundant, get_query_vars reads it from the global $wp_query object $wp_query-&gt;query_vars['paged'] = get_query_var('paged'); } </code> I see that your query depends on session variables. This can make it harder to forward a link to a page to someone else. Have you considered putting this in the URL and reading it from there? You can do that by creating extra rewrite rules.
Adding Variables to post query
wordpress
If I click on a category in my Wordpress blog, it displays an excerpt of all articles in the category, and finishes with a word that says "continue" which has no hyperlink. Example here . How do I fix this?
Open the theme index.php (or other theme template file) and look for something like this: <code> &lt;div id="more_reading"&gt; ... &lt;/div&gt; </code> replace with: <code> &lt;?php if ( $wp_query-&gt;max_num_pages &gt; 1 ) : ?&gt; &lt;div id="more_reading"&gt; ... &lt;/div&gt; &lt;?php endif; ?&gt; </code> or just remove "Continue"
Category articles "read more" links not active
wordpress
I'm not able to make it work by adding custom rewrite rules into <code> functions.php </code> or adding custom permastructures either. I have this code in my <code> .htaccess </code> that is working fine. <code> # BEGIN WordPress &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / # BEGIN IPHONE RULES RewriteRule ^mobile/([^/]+)$ mobile/index.php?action=$1 [QSA,L] # END IPHONE RULES # BEGIN PDF RULES RewriteRule ^certificates/30-Days-Certificate-([0-9]+)$ pdf/index.php?type=30day&amp;period=$1 [QSA,L] RewriteRule ^certificates/12-Month-Certificate$ pdf/index.php?type=12Month [QSA,L] # END PDF RULES RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &lt;/IfModule&gt; # END WordPress </code> But every once a while it gets refreshed to defaults and I lose the iPhone and pdf rules. The mobile is called like this <code> /mobile/progress?userId=22&amp;date=2011-02-21 </code> where <code> progress </code> is the action and the others are just query vars. On the <code> .htaccess </code> is working fine but I can't manage to make it work by adding custom rules. Any help will be much appreciated.
The part between the <code> # BEGIN WordPress </code> and <code> # END WordPress </code> will always be rewritten when the permalinks are flushed. You can either place your extra rewrite rules before this segment, or you can add register them in WordPress as external rewrite rules . If you flush your rules now (by visiting the Permalinks page, for example), your extra rules will be added to the <code> .htaccess </code> file. <code> add_action( 'init', 'wpse12708_init' ); function wpse12708_init() { global $wp_rewrite; $wp_rewrite-&gt;add_external_rule( 'mobile/([^/]+)$', 'mobile/index.php?action=$1' ); $wp_rewrite-&gt;add_external_rule( 'certificates/30-Days-Certificate-([0-9]+)$', 'pdf/index.php?type=30day&amp;period=$1' ); $wp_rewrite-&gt;add_external_rule( 'certificates/12-Month-Certificate$', 'pdf/index.php?type=12Month' ); } </code>
Rewrite rules in .htaccess get overwritten?
wordpress
We are using CPT's to manage a frequently asked questions page on a site, where the question is the post title and the answer is the post content. There is a main page for the FAQs that shows all posts (FAQ archive page). With this structure we really have no need for the single view for any FAQ and in fact would like to omit it from the site structure. To address permalinks we'd like to set them to be something like example.com/faq/#uniqueIdentifier, thinking that we'll use the #uniqueIdentifier to match a div on the archive page containing the answer and call attention to it in some fashion. The uniqueIdentifier could be post ID, faq question title, data from a meta box, or something else. So let me recap what I need we need to accomplish: (1) rewrite the faq permalinks to be /faq/#something, and (2) make sure all /faq/ links route to archive template and not single I'm mostly a noob but pretty good at fumbling my way through things. Have never attempted any rewrites though so would appreciate some particular direction on that. Thank you.
Hi @daxitude: Let me first suggest you reconsider. If you don't have individual FAQ pages for each FAQ: You reduce your surface are for search engine optimization and reduce the potential traffic that you might get, and You make it impossible for someone to share a specific FAQ with a friend over email and/or share with their network on Facebook, Twitter, etc. (As a user I'm always frustrated by site developers who disallow me to have a direct URL to an item and instead force me to link to the page that lists all items.) However, if you still want to do so then do two things: 1.) Use the <code> 'post_type_link' </code> hook Use the <code> 'post_type_link' </code> hook to modify the URL like in the following example *(I'm assuming your custom post type is <code> 'faq' </code> ). Add the following to your theme's <code> functions.php </code> file: <code> add_action('post_type_link','yoursite_post_type_link',10,2); function yoursite_post_type_link($link,$post) { $post_type = 'faq'; if ($post-&gt;post_type==$post_type) { $link = get_post_type_archive_link($post_type) ."#{$post-&gt;post_name}"; } return $link; } </code> 2.) <code> unset($wp_rewrite-&gt;extra_permastructs['faq']) </code> This is a hack , but it's a required hack to do what you want. Use an <code> 'init' </code> hook to <code> unset($wp_rewrite-&gt;extra_permastructs['faq']) </code> . It removes the rewrite rule that <code> register_post_type() </code> adds. I'm including a call to <code> register_post_type() </code> so I can provide a complete example for both you and others: <code> add_action('init','yoursite_init'); function yoursite_init() { register_post_type('faq',array( 'labels' =&gt; array( 'name' =&gt; _x('FAQs', 'post type general name'), 'singular_name' =&gt; _x('FAQ', 'post type singular name'), 'add_new' =&gt; _x('Add New', 'faq'), 'add_new_item' =&gt; __('Add New FAQ'), 'edit_item' =&gt; __('Edit FAQ'), 'new_item' =&gt; __('New FAQ'), 'view_item' =&gt; __('View FAQ'), 'search_items' =&gt; __('Search FAQs'), 'not_found' =&gt; __('No FAQs found'), 'not_found_in_trash' =&gt; __('No FAQs found in Trash'), 'parent_item_colon' =&gt; '', 'menu_name' =&gt; 'FAQs' ), '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;'faqs'), 'capability_type' =&gt; 'post', 'has_archive' =&gt; 'faqs', 'hierarchical' =&gt; false, 'supports' =&gt; array('title','editor','author','thumbnail','excerpt') )); global $wp_rewrite; unset($wp_rewrite-&gt;extra_permastructs['faq']); // Removed URL rewrite for specific FAQ $wp_rewrite-&gt;flush_rules(); // THIS SHOULD BE DONE IN A PLUGIN ACTIVATION HOOK, NOT HERE! } </code> That's about it. Of course the above use of <code> $wp_rewrite-&gt;flush_rules() </code> in an <code> 'init' </code> hook is really bad practice and should really only be done once so I've implemented a complete and self-contained plugin called <code> FAQ_Post_Type </code> to do it right. This plugin adds a FAQ post type with the URL rules that you want and it uses a <code> register_activation_hook() </code> to flush the rewrite rules; activation being obviously one of the few things that requires plugin code instead of code that can run in a theme's <code> functions.php </code> file. Here's the code for the <code> FAQ_Post_Type </code> plugin; feel free to modify for your requirements: <code> &lt;?php /* Plugin Name: FAQ Post Type Description: Answers the question "Custom post type, no need for single view, plus want permalink rewrites that include hash in URI" on WordPress Answers. Plugin URL: stackexchange-url (!class_exists('FAQ_Post_Type')) { class FAQ_Post_Type { static function on_load() { add_action('post_type_link', array(__CLASS__,'post_type_link'),10,2); add_action('init', array(__CLASS__,'init')); } static function post_type_link($link,$post) { if ('faq'==$post-&gt;post_type) { $link = get_post_type_archive_link('faq') ."#{$post-&gt;post_name}"; } return $link; } static function init() { register_post_type('faq',array( 'labels' =&gt; array( 'name' =&gt; _x('FAQs', 'post type general name'), 'singular_name' =&gt; _x('FAQ', 'post type singular name'), 'add_new' =&gt; _x('Add New', 'faq'), 'add_new_item' =&gt; __('Add New FAQ'), 'edit_item' =&gt; __('Edit FAQ'), 'new_item' =&gt; __('New FAQ'), 'view_item' =&gt; __('View FAQ'), 'search_items' =&gt; __('Search FAQs'), 'not_found' =&gt; __('No FAQs found'), 'not_found_in_trash' =&gt; __('No FAQs found in Trash'), 'parent_item_colon' =&gt; '', 'menu_name' =&gt; 'FAQs' ), '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;'faqs'), 'capability_type' =&gt; 'post', 'has_archive' =&gt; 'faqs', 'hierarchical' =&gt; false, 'supports' =&gt; array('title','editor','author','thumbnail','excerpt'), )); global $wp_rewrite; unset($wp_rewrite-&gt;extra_permastructs['faq']); // Remove URL rewrite for specific FAQ } static function activate() { global $wp_rewrite; $wp_rewrite-&gt;flush_rules(); } } FAQ_Post_Type::on_load(); register_activation_hook(__FILE__,array('FAQ_Post_Type','activate')); } </code> You could also possibly kept the flush rules inside the <code> 'init' </code> by using a check for an option value if you prefer this: <code> // Add this code in your 'init' hook at your register_post_type('faq',...) if (!get_option('faq_rewrite_rules_updated')) { global $wp_rewrite; unset($wp_rewrite-&gt;extra_permastructs['faq']); // Remove URL rewrite for specific FAQ $wp_rewrite-&gt;flush_rules(); update_option('faq_rewrite_rules_updated',true); } </code> Your choice. Anyway, let me know if there are use-cases you discover that this does not address.
Custom post type, no need for single view, plus want permalink rewrites that include hash in URI
wordpress
Under each comment there is a link called 'Reply'. I want to add a class to this link. It's default class is <code> comment-reply-link </code> . How can I do so? I am creating my own theme and I don't want to manually edit files inside the wp-includes directory.
In your comments.php template file use <code> wp_list_comments </code> and set the parameter <code> callback </code> to your defined function that will generate the template. Inside the function you can style the comment reply link. wp_list_comments codex Further reading on comment display
Add class to Reply button in Comments area
wordpress
I have a blog running the latest stable version of WordPress on a dedicated virtual server with the following situation. (Replace [caching plugin] with W3 Total Cache, Hyper Cache, or Quick Cache, as I've tried all three with the same results.) [caching plugin] is disabled. I visit a known bad link on my site (http://example.com/xyzz/) and receive a 404 error page. I can verify in Chrome's Inspector and/or Firebug that the "404 Not Found" status is being properly served in the HTTP headers. I turn [caching plugin] on and visit the same URL. On the initial visit I am served a cached page (verified by the debugging comments inserted by the plugin at the bottom of the HTML source) with the proper "404 Not Found" status in the HTTP header. If I visit the page again (http://example.com/xyzz/), I'm served the same cached page from #2 above displaying the "404 - Page Not Found" error to the user, but with a "200 OK" status in the HTTP header. If I turn [caching plugin] off and visit the page again, I am again being served an uncached page with the correct "404 Not Found" status in the HTTP header. Any idea what might be going on here? This is seems to be causing some an issue where Google Bot is attempting to index some non-existent pages because its seeing the "200 OK" HTTP header instead of the proper 404.
Further troubleshooting leads me to believe this was somehow related to the theme I was using. After disabling it and enabling a different one I received the proper 404 headers while using a caching plugin. I still don't know what in the theme would be causing this, but at least there's a workaround.
Getting soft 404 errors (200 status) when caching plugins are enabled
wordpress
is it possible to hide the string: "Comments are disabled" from everywhere? I mean also from posts list, and post page :) Thanks :) EDIT: sorry, the theme is Journal Cruch by Site5.com However I resolved using <code> if (comments_open()) comments_popup_link(); </code> where the comments are displayed, but I don't like too much this solution :)
Popup link takes five parameters. <code> comments_popup_link('No Comments','One Comment','Many Comments','CSSclass','Comments Disabled'); </code> So you are on to the correct solution. Now just change the above strings to whatever you want them to be for each # of comments. Finally change 'Comments Disabled' to just <code> '' </code> . Or perhaps <code> '&amp;nbsp;' </code> if it requires you to put something in there.
How to hide "Comments are disabled"
wordpress
I just think about that... maybe it exist...you will tell me... Wordpressis a beautifull software, and the thing i like the most, is the instant install of the theme and plugin... So i though, why not have a onefile.html upload, and install wordpress ITSELF utomaticly fron the svn instead of having to upload a whole buch of file that take a looong time, and sometime failed... Maybe that file, will just select the language and the name of the folder... Or maybe, it exist ?... I know that the database must be done before... i do it, it's just the folder with 1000 files that weight 10 mg that bug me... autoinstall as plugin !
Update: You can use WordPress QI - http://wpquickinstall.com/download/ Not all servers can run SVN, and servers which have problem in WP 5minute install, can't be cope up with another solution because there is no solution, sometimes server settings are to blame. That said, on a server where everything works fine for a regular installation, WordPress install can be automated by how you want it (by uploading a single file and loading that in the browser provided that you provide database connection details to it somehow.
Instant install of wordpress
wordpress
I'm trying to create a new wordpress template and inside it I added a Control Panel, inside this control panel there is an option that allows user to choose where he want's to place a on a map, I try to explain: user can set div's left and top attributes via control panel. Now I know how to add an iframe that can show a preview of the changes but it doesn't work as I would like (how to add the preview? read here: stackexchange-url ("Modify CSS via Theme Control Panel")) What I would like to add is a real time preview. As soon as the user modify TOP or LEFT attribute preview has to show what it is happening without showing it to "live" blog. Here is my function.php: <code> array( "name" =&gt; "Before we start", "type" =&gt; "section"), array( "type" =&gt; "open"), array( "name" =&gt; "Where is the map?", "desc" =&gt; "Insert map page url", "id" =&gt; $shortname."_pama", "type" =&gt; "text", "std" =&gt; "http://examplepage.com"), array( "type" =&gt; "close"), array( "name" =&gt; "Zona 1", "type" =&gt; "section"), array( "type" =&gt; "open"), array( "name" =&gt; "Activate zona 1?", "desc" =&gt; "Choose yes or no", "id" =&gt; $shortname."_zona1c", "type" =&gt; "checkbox", "std" =&gt; "false"), array( "name" =&gt; "Zona 1 X-Axis", "desc" =&gt; "Where do you want it on x-axis?", "id" =&gt; $shortname."_zona1x", "type" =&gt; "text", "std" =&gt; "Left:???"), array( "name" =&gt; "Zona 1 Y-Axis", "desc" =&gt; "Where do you want it on y-axis?", "id" =&gt; $shortname."_zona1y", "type" =&gt; "text", "std" =&gt; "Top:???"), array( "type" =&gt; "close"), array( "name" =&gt; "Zona 1", "type" =&gt; "section"), array( "type" =&gt; "open"), array( "name" =&gt; "Activate zona 2?", "desc" =&gt; "Choose yes or no", "id" =&gt; $shortname."_zona1c", "type" =&gt; "checkbox", "std" =&gt; "false"), array( "name" =&gt; "Zona 2 X-Axis", "desc" =&gt; "Choose where you want it on X-Axis", "id" =&gt; $shortname."_zona2x", "type" =&gt; "text", "std" =&gt; "Left:???"), array( "name" =&gt; "Zona 2 Y-Axis", "desc" =&gt; "Choose where you want it on Y-Axis", "id" =&gt; $shortname."_zona2y", "type" =&gt; "text", "std" =&gt; "Top:???"), array( "type" =&gt; "close"), array( "type" =&gt; "close"), ); </code> This is the iframe that I use to show the preview inside Control Panel: <code> &lt;iframe src="&lt;?php echo clean_url(apply_filters('preview_post_link', add_query_arg('preview', 'true', get_option('appacqua_pama')))); ?&gt;" width="100%" height="600" &gt;&lt;/iframe&gt; </code> Ok, now the big question is there a STEP TO STEP way to add a preview on real time (I don't know how to explain it better, I'm really sorry...), what do you think will it be possible to use ajax? (I heard about it but I'm not a programmer so please write in a Dummy Proof way!!!) Will I need to add also a PREVIEW button instead of only SAVE button? How to add it? Do you know Mystique theme by digitalnature? something like this will be GREAT! If you can't write it here why don't you write a very good, and step to step, tutorial on your website? There is a lack of good articles about how to create a very good Theme-Option panel with a lot of functionalities for wordpress 3.x maybe you'll be the next and you'll also help us...poor noobs :-) Thank you very much for your time and patience!
If you look at Mystique theme (a great example of option panel with preview BTW) you can see that the main idea is to lavrage the form fields OnChange or change() events to load the theme's preview with Jquery and a bit of ajax. So you have one function to load by ajax the preview <code> function mystique_get_site_preview() { check_ajax_referer("site_preview"); ?&gt; &lt;iframe id="themepreview" name="themepreview" src="&lt;?php echo get_option('home'); ?&gt;/?preview=1"&gt;&lt;/iframe&gt; &lt;?php die(); } </code> and to create the auto preview effect you use some JQuery with PHP: <code> $nonce = wp_create_nonce('site_preview'); ?&gt; &lt;script type="text/javascript"&gt; jQuery(document).ready(function () { jQuery("#$zona1y").change(function() {// if a user changed the y-Axis check_preview_refresh(); } ); jQuery("#$zona1x").change(function() {// if a user changed the x-Axis check_preview_refresh(); } ); }); function check_preview_refresh(){ if (jQuery("#zona1y").val() != '' &amp;&amp; jQuery("#zona1x").val() != '' ){ jQuery.ajax({ type: "post",url: "admin-ajax.php",data: { action: 'site_preview', _ajax_nonce: '&lt;?php echo $nonce; ?&gt;' }, success: function(html){ jQuery("#themepreview").html(html); jQuery("#themepreview").show(); } }); } } &lt;/script&gt; </code> Now this code assumes that you have two input fields with the id of "zona1y" and "zona1y" and a div wrapping your Iframe with the id of "themepreview". and that should get you started. Update: I forgot you will need to add: <code> add_action('wp_ajax_site_preview', 'mystique_get_site_preview'); </code> Now the first part + the last line of code go in your functions.php and the second part needs to go on your theme option panel page.
Add a preview to a Wordpress Control Panel
wordpress
I'm looking for a plugin or a idea so that my WP 3.1 search engine can index PDF files. Has anyone be through that need too ? Thanks !
The standard WordPress search is pretty basic and only search the database, there are some plugins that extend the search functionality to search even more parts of the database like: Search Everything Search Unleashed but they do not have the ability to search files. There is one plugin that i know of that claims to support indexing PDF and DOC files Sphider for WordPress which is a bit outdated and i have tried before so you might want to check it out. But the best solution I have used for this kind of "Job" is Google custom search that searchs PDFs and DOCs and is fairly easy to set up.
How to make search engine index PDF files?
wordpress
Is there any free WordPress plugin or theme that sort posts as 'top this year' and 'top last month" or 'top 24 hours' based on voting? I'm using the Vote It Up plugin right now. But it doesn't have the capability of sorting post as a loop. Any suggestions?
Try GD Star Rating - I'm pretty sure it stores vote times and so can be used to do this - you'll probably need to extract the ordering yourself though. http://www.gdstarrating.com/
Plugin or theme that sort posts as 'top this year' and 'top last month"?
wordpress
The documentation for dealing with official WP repository is exclusively about using command line. While I have no bias against that, I do have little experience with VCS and two (or three) different ones I will have to figure out and use in nearest future. So for now I wing it with VCS integration features in IDEs (NetBeans, PHPStorm). Which often leaves me confused on specifics and ways of doing things properly. Are there any good articles/posts/guides on using official SVN repository (or at least SVN in general) with IDEs or other GUI-based tools? Something that focuses on concepts and workflow, rather than typing in arcane lines in console.
I don't use (widely recommended) TortoiseSVN at moment, but turns out it has very extensive manual, available online and for download in multiple languages . In its own words: This book is written for computer literate folk who want to use Subversion to manage their data, but are uncomfortable using the command line client to do so. ( Preface ) This document describes day to day usage of the TortoiseSVN client. It is not an introduction to version control systems, and not an introduction to Subversion (SVN). It is more like a place you may turn to when you know approximately what you want to do, but don't quite remember how to do it. ( Chapter 4. Daily Use Guide ) Pretty much what I was looking for, reading it now.
Any guides on using WP SVN with IDE clients?
wordpress
I'd like <code> get_the_category_list </code> to only display one or two categories instead of all the categories associated with the post. Haven't been able to find any results. <code> &lt;?php echo get_the_category_list(); ?&gt; </code> Any help would be appreciated
Quick idea would be to pass some simple separator like comma and cut from the start of result till it. But I think that if you want better control on output it would make more sense to use level deeper <code> get_the_category() </code> function and build markup yourself.
Display only one result from "get_the_category_list"
wordpress
Basic question, but I want to enable page templates. I have one theme which has page templates enabled. I switched to another but there is no option to change the template, even when creating a new page. How do I switch this option on? I've had a root around on the Codex and forum but can't find it.
Chances are that the theme you've switched to has no page templates defined - they exist on a per theme basis. Here's the Codex reference: http://codex.wordpress.org/Pages#Page_Templates
Enable page templates. How?
wordpress
I have always hosted my own websites on my own hardware, this includes WordPress. I always see on shared hosting sites "WordPress Hosting" which looks to be the exact same as their regular hosting plan. Am I missing something, or is there a difference, and how can I optimize my servers for WordPress?
Hi @Jeremy: Of course you can optimize your servers like the hosting companies do, it just depends on how much skill you have and how much effort you want to take on. Here's a community wiki that might give you an idea of what to consider doing: <a href="stackexchange-url Best-of-Breed Features of a High-End WordPress Web Host? One thing that comes to mind as a great feature is to use nginx as a caching proxy server .
WordPress hosting optimized servers - Is this just a sales gimmick?
wordpress
in mine network setup, the super admin has the ability to see the tinyMCE editing buttons in the option page, but when i switch to a regular adimin, i can see only the HTML editing buttons (the "rich text"). what can be the reason for that? i can find any thing in the functions.php that indicates that i registered a enqueue script just for super admins...
o.k. the problem is based on a conflict in some of the filters of the tinyMCE, maybe only when it's a network setup (i don't know exactly which filters are conflicted) but i managed to solved it by: 1. installing tinyMCE Advanced: i know this plugin isn't supposed to work in the network setup, but hey! it did the trick. some thing in the way its configured ran over the problem of the different editing buttons for different admins that i've mentioned above. and for adding a custom but permanent editing buttons (for all users, without exception) i coded this in my <code> functions.php </code> : function mce_btns1($orig) { return array('bold', 'italic', 'underline', 'bullist', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'link', 'unlink'); } add_filter( 'mce_buttons_1', 'mce_btns1', 999 ); function mce_btns2($orig) { return array('fontselect', 'fontsizeselect', 'forecolor', 'backcolor'); } add_filter( 'mce_buttons_2', 'mce_btns2', 999 ); function mce_btns3($orig) { return array(null); } add_filter( 'mce_buttons_3', 'mce_btns3', 999 ); this ran over the default and user-specific configuration of the tinyMCE for all users in the network. that's it.
in network setup super admin has the tinyMCE buttons and the regular admin has not
wordpress
How do you: 1) create a page and select "Blog Template" and also choose which category for the Blog's you want. 2) Then create a blog post and choose the category for that page....resulting in a page that shows all the blog posts for that category? Thanks!
Sounds like you are looking for the functionality of WordPress 3.0 Menus Subpanel . In Dashboard go to 'Appearance' then 'Menus' and you can create a page that will show the posts from a specified category.
Creating Pages that show specific blog categories
wordpress
I messed up the settings with W3 Total Cache (tried to import all the media to my library, didn't work out well, broke all my links to every picture). So I took my latest backup of the database, copy/paste the _post and _postmeta tables inside my phpmyadmin. It brought back the links and pictures as expected, but now all the french characters (à,é,è etc) are not displayed properly. I took the backup from the plugin WP-DBManager, which doesn't seem to handle UTF-8 properly. What's the fastest way to correct the issue ? Thanks Edited for more details: The SQL backup header is <code> DROP TABLE IF EXISTS `hojd_posts`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; </code> However I have those characters badly encoded coming directly in my sql commands (eg: français for "français")...
You might be able to solve this if you have a text editor with good encoding support. That way, you could switch between the Latin 1 and the UTF-8 encoding until you have the right combination. I use SubEthaEdit which can convert but also reinterpret a file when you change the encoding. The <code> ç </code> should be encoded as <code> c3 a7 </code> in UTF-8 when you view them as bytes. What could be happening here is that the file was interpreted as Latin 1 first, where <code> c3 a7 </code> means <code> ç </code> , and then saved as UTF-8, where <code> ç </code> is saved as <code> c3 83 c2 a7 </code> . You want the <code> c3 a7 </code> version. The way to get back to a nice <code> ç </code> is to open the file as UTF-8, save it as Latin-1, and then open it again as if it was UTF-8. Once you did this, you can import the file into MySQL, but specify it is UTF-8, otherwise MySQL might try to interpret it as Latin 1 and you will still have the <code> ç </code> characters.
Faulty restore of the database, encoding issue
wordpress
I've read the codex section on wp-enqeue, but am still struggling. Basically, I would like to get the following to display properly in my theme's widget area (on every page): <code> &lt;link rel="stylesheet" type="text/css" href="/wp-content/uploads/social_counter/css/styles.css" /&gt; &lt;link rel="stylesheet" type="text/css" href="/wp-content/uploads/social_counter/css/tipTip.css" /&gt; &lt;div id="social_counter"&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/wp-content/uploads/social_counter/js/jquery.tipTip.minified.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/wp-content/uploads/social_counter/js/social_counter.js"&gt;&lt;/script&gt; &lt;/div&gt; </code> I created a text widget into which I pasted the code, but it breaks a few things in the template as there is likely a conflict since jquery is already loaded by the theme and/ or other plugins. Could someone show me how to best form this using wp_enqueue, and where to paste the subsequent code (functions.php of theme?)? Thanks. I've tried the following: <code> if(!is_admin()){ wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'); wp_enqueue_script('custom_script',get_bloginfo('wpurl').'/wp-content/uploads/social_counter/js/jquery.tipTip.minified.js',false); wp_enqueue_script('custom_script',get_bloginfo('wpurl').'/wp-content/uploads/social_counter/js/social_counter.js',array('jquery'),'1.4.2',false); } </code> It seem to load two of the scripts when I view the page source, but not the google jquery, and the content does not show... now i have the following, still nothing (two scripts show up, but not the google jquery): <code> wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'); wp_enqueue_script( 'jquery' ); wp_enqueue_script('custom_script',get_bloginfo('wpurl').'/wp-content/uploads/social_counter/js/jquery.tipTip.minified.js',false); wp_enqueue_script('custom_script',get_bloginfo('wpurl').'/wp-content/uploads/social_counter/js/social_counter.js',array('jquery'),'1.4.2',false); </code> Latest Edit.. (i really wish stack overflow would adopt a mroe user-friendly threading system :/ ) <code> function add_scripts(){ // Load jQuery if ( !is_admin() ) { wp_deregister_script('jquery'); wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"), false); wp_enqueue_script('jquery'); } // Your Scripts wp_enqueue_script('custom_script',get_bloginfo('wpurl').'/wp-content/uploads/social_counter/js/jquery.tipTip.minified.js',false); wp_enqueue_script('custom_script',get_bloginfo('wpurl').'/wp-content/uploads/social_counter/js/social_counter.js',array('jquery'),'1.4.2',false); } add_action('init','add_scripts'); </code>
You actually don't need to worry about conflicting with the admin pages anymore. There is a "wp_enqueue_scripts" hook that makes sure the scripts aren't called on admin pages. From WP Codex: <code> &lt;?php function my_scripts_method() { wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js'); wp_enqueue_script( 'jquery' ); } add_action('wp_enqueue_scripts', 'my_scripts_method'); ?&gt; </code> But if you need a custom jQuery core (or add-on) for the admin pages, you'll need to use the "init" hook with the !admin conditional.
trying to enqueue script in wordpress
wordpress
I've almost finished coding up a function that allows contributers when they are the post author to manage comments left on their own post (portfolio) couldnt find a plugin to do it so had to get myself dirty. It will basically work like this: 1) User leaves a comment on post_authors portfolio. 2) Post_author is notified by email that they have a comment for moderation (this bit is handled by a plugin "notify-on-comments"). 3) Post_author logs in and goes to his/her portfolio page and in the comments are two links one for "delete" and one for "approve" comment. Now i can get the delete to work on already published comments , my problem is that i am wanting to show the unpublished comment along with the published comments (dont want folks having access to wp-admin dashboard to moderate comments, i want it all done on the front end), Does anyone know how i can do this part of showing the un-approved comment at front-end to contributers? Once completed i will be more than happy to share the code and credits should anyone else need it. Regards and thanks in advance
Easy: <code> function show_portfolio_comments( $post_ID ) { // NOT approved $comments_unapproved = get_comments( array( 'status' =&gt; 'hold', 'post_id' =&gt; $post_ID ) ); foreach ( $comments_unapproved as $comments) { if ( current_user_can( 'edit_published_posts' ) // maybe you'll have to switch to some other cap { ?&gt; &lt;div class="comment"&gt; &lt;h4&gt;Unapproved Comments on your portfolio&lt;/h4&gt; &lt;div class="comment-author"&gt;&lt;?php echo $comment-&gt;comment_author; ?&gt;&lt;/div&gt; &lt;div class="comment-content"&gt;&lt;?php echo $comment-&gt;comment_content; ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php } // endif; - current_user_can( 'edit_published_posts' ) } // ALREADY approved $comments_approved = get_comments( array( 'status' =&gt; 'approve', 'post_id' =&gt; $post_ID ) ); foreach ( $comments_approved as $comments) { ?&gt; &lt;div class="comment"&gt; &lt;?php if ( current_user_can( 'edit_published_post' ) { ?&gt; &lt;h4&gt;Approved Comments on your portfolio&lt;/h4&gt; &lt;?php } // endif; - current_user_can( 'edit_published_posts' ) ?&gt; &lt;div class="comment-author"&gt;&lt;?php echo $comment-&gt;comment_author; ?&gt;&lt;/div&gt; &lt;div class="comment-content"&gt;&lt;?php echo $comment-&gt;comment_content; ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php } } </code> Template Tag: <code> // Use it in your template like this &amp; don't forget to push the post ID into it: $post_ID = $GLOBALS['post']-&gt;ID; // or: global $post; $post_ID = $post-&gt;ID; // or: $post_ID = get_the_ID(); // or: $post_ID = get_queried_object_id(); show_portfolio_comments( $post_ID ); </code>
show un-approved comments at wordpress front end
wordpress
I have a custom post type for accessories. When you view the post it also shows related posts. It looks great, but it also shows the current post within related posts. Is there a way to exclude the current post from the loop? <code> &lt;div&gt; &lt;?php $category = get_the_category(); $model = $category[1]-&gt;cat_name; $accessory = array('numberposts' =&gt; 8, 'offset'=&gt; 1, 'post_type' =&gt; 'accessory', 'category_name' =&gt; $model, 'order' =&gt; 'DESC'); query_posts( $accessory ); ?&gt; &lt;?php if (have_posts()) : ?&gt; &lt;?php while (have_posts()) : the_post(); ?&gt; &lt;div&gt; &lt;?php wp_link_pages( array( 'before' =&gt; '&lt;div class="page-link"&gt;' . __( 'Pages:', 'openeye' ), 'after' =&gt; '&lt;/div&gt;' ) ); ?&gt; &lt;h4&gt;&lt;?php the_title(); ?&gt;&lt;/h4&gt; Part Number: &lt;?php echo get_post_meta($post-&gt;ID, "accessory-part-number", true); ?&gt; &lt;?php $desc = get_post_meta($post-&gt;ID, "accessory-description", true); ?&gt; &lt;p&gt;&lt;?php echo utf8_truncate( $desc ); ?&gt;&lt;/p&gt; &lt;a href="&lt;?php echo get_permalink(); ?&gt;"&gt;Learn more about the &lt;?php the_title(); ?&gt;&lt;/a&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;?php endif; ?&gt; &lt;/div&gt; &lt;/div&gt; </code>
Try this: For your single-accessory.php template: <code> &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt; &lt;?php // excludes this post from 'Related posts' in the sidebar $GLOBALS['current_id'] = $post-&gt;ID; ?&gt; </code> For your sidebar or where you want to show related posts: <code> &lt;?php if (is_singular('accessory') ) : global $post; $categories = get_the_category(); $exclude = $GLOBALS['current_id']; $args = array( 'post_type' =&gt; 'accessory', 'post__not_in' =&gt; array($exclude), 'posts_per_page' =&gt; -1 ); foreach ($categories as $category) : $posts = get_posts($args); if(count($posts) &gt; 1) { //do stuff } endforeach; ?&gt; </code>
Exclude current post from loop
wordpress
All theme styles are in style.css file. Let's say first line looks like: <code> body { background-color: #fff; } </code> Now, I've created an option in admin panel named body_bg. User types #000 there and I want the value in style.css to change. How do I achieve that? The easiest way to me looks like I have to rename style.css to .php, and just do: <code> &lt;?php header("Content-type: text/css"); ?&gt; body { background-color: &lt;?php echo get_option('body_bg');?&gt; ; } </code> And then just link style.php in empty style.css file. It's perfectly valid and works, but I've never seen a theme with style.php file, so how do people modify their stylesheets dynamically?
If you're wanting styles to be dynamic, then you'll have to emit your CSS file as you are suggesting. However, as WordPress often uses styles.css as a theme definition file, renaming styles.php might cause problems. It might be better to collect all the 'dynamic' definitions into a separate file (eg dynamic-styles.php) and import them from your main style.css file via <code> @import(url) </code> ,
How do you modify CSS files via admin panel?
wordpress
I'm using Facebook and Digg Thumbnail generator and [FaceBook Share (New)], 2 As you can see if the image is 100px the thumbail is displayed when I press the share button: But with an image with 300px of width: The thumb preview doesn't appear: front-page.php: <code> &lt;?php /** * Template Name: Front Page * @package WordPress * @subpackage Prominent * @since Prominent 1.0 */ get_header(); ?&gt; &lt;div id="tagline"&gt; &lt;div class="container"&gt; &lt;/div&gt;&lt;!-- .container --&gt; &lt;/div&gt;&lt;!-- #tagline --&gt; &lt;div id="content"&gt; &lt;div class="container"&gt; &lt;div id="mainbar"&gt; &lt;?php while ( have_posts() ) : the_post(); ?&gt; &lt;div class="content-block-2"&gt; &lt;?php the_content(); ?&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;?php /* Display navigation to next/previous pages when applicable */ ?&gt; &lt;?php if ( $wp_query-&gt;max_num_pages &gt; 1 ) : ?&gt; &lt;div id="prev"&gt;&lt;?php next_posts_link( __( '&amp;larr; Older posts', 'twentyten' ) ); ?&gt;&lt;/div&gt; &lt;div id="next"&gt;&lt;?php previous_posts_link( __( 'Newer posts &amp;rarr;', 'twentyten' ) ); ?&gt;&lt;/div&gt; &lt;?php endif; ?&gt; &lt;/div&gt;&lt;!-- #mainbar --&gt; &lt;/div&gt;&lt;!-- .container --&gt; &lt;/div&gt;&lt;!-- #content-bottom --&gt; &lt;?php get_footer(); ?&gt; </code> Any suggestion to solve this?
Finally figured out why. Facebook only allows images with 3:1 ratio.
Facebook is only displaying preview thumbnails that are 100px from my posts?
wordpress
When I try to get an archive for a custom taxonomy, WP searches for a page and doesn’t find anything. The Setup My code from the functions.php: <code> add_action( 'init', 'register_store_taxonomy' ); function register_store_taxonomy() { $args = array ( 'hierarchical' =&gt; TRUE , 'label' =&gt; 'Store' , 'public' =&gt; TRUE , 'query_var' =&gt; 'store' , 'rewrite' =&gt; TRUE , 'show_in_nav_menus' =&gt; TRUE , 'show_ui' =&gt; TRUE ); register_taxonomy( 'store' , array ( 'post', 'page' ) , $args ); } </code> Now I have a post tagged with store itunes . Clicking on the link to <code> /store/mac-store/ </code> should list all post in this taxonomy. And it does! On a local server (Win7). On the staging server (Debian with mostly identical settings), however, I get the 404 page (and the 404 status header). There are no pages with similar names or slugs, not even in trash. I’ve refreshed the permalinks several times. No active plugins. I tried Google but couldn’t find anything useful. Debugging I added the following code to my functions.php to track the error: <code> add_action( 'wp_footer', 'dump_query' ); function dump_query() { if ( current_user_can( 'edit_posts' ) ) { pre_dump( $GLOBALS['wp_query'] ); } } function pre_dump( $var, $print = TRUE ) { $out = '&lt;pre class="vardump"&gt;' . htmlspecialchars( var_export( $var, TRUE ) ) . '&lt;/pre&gt;'; if ( ! $print ) return $out; print $out; } </code> Output local, working query <code> WP_Query::__set_state(array( 'query_vars' =&gt; array ( 'store' =&gt; 'itunes', 'error' =&gt; '', 'm' =&gt; 0, 'p' =&gt; 0, 'post_parent' =&gt; '', 'subpost' =&gt; '', 'subpost_id' =&gt; '', 'attachment' =&gt; '', 'attachment_id' =&gt; 0, 'name' =&gt; '', 'static' =&gt; '', 'pagename' =&gt; '', 'page_id' =&gt; 0, 'second' =&gt; '', 'minute' =&gt; '', 'hour' =&gt; '', 'day' =&gt; 0, 'monthnum' =&gt; 0, 'year' =&gt; 0, 'w' =&gt; 0, 'category_name' =&gt; '', 'tag' =&gt; '', 'cat' =&gt; '', 'tag_id' =&gt; '', 'author_name' =&gt; '', 'feed' =&gt; '', 'tb' =&gt; '', 'paged' =&gt; 0, 'comments_popup' =&gt; '', 'meta_key' =&gt; '', 'meta_value' =&gt; '', 'preview' =&gt; '', 's' =&gt; '', 'sentence' =&gt; '', 'fields' =&gt; '', 'category__in' =&gt; array ( ), 'category__not_in' =&gt; array ( ), 'category__and' =&gt; array ( ), 'post__in' =&gt; array ( ), 'post__not_in' =&gt; array ( ), 'tag__in' =&gt; array ( ), 'tag__not_in' =&gt; array ( ), 'tag__and' =&gt; array ( ), 'tag_slug__in' =&gt; array ( ), 'tag_slug__and' =&gt; array ( ), 'meta_query' =&gt; array ( ), 'ignore_sticky_posts' =&gt; false, 'suppress_filters' =&gt; false, 'cache_results' =&gt; true, 'update_post_term_cache' =&gt; true, 'update_post_meta_cache' =&gt; true, 'post_type' =&gt; '', 'posts_per_page' =&gt; 10, 'nopaging' =&gt; false, 'comments_per_page' =&gt; '50', 'no_found_rows' =&gt; false, 'taxonomy' =&gt; 'store', 'term' =&gt; 'itunes', 'order' =&gt; 'DESC', 'orderby' =&gt; 'wp_posts.post_date DESC', ), 'tax_query' =&gt; WP_Tax_Query::__set_state(array( 'queries' =&gt; array ( 0 =&gt; array ( 'taxonomy' =&gt; 'store', 'terms' =&gt; array ( 0 =&gt; 'itunes', ), 'include_children' =&gt; true, 'field' =&gt; 'slug', 'operator' =&gt; 'IN', ), ), 'relation' =&gt; 'AND', )), 'post_count' =&gt; 1, 'current_post' =&gt; -1, 'in_the_loop' =&gt; false, 'comment_count' =&gt; 0, 'current_comment' =&gt; -1, 'found_posts' =&gt; '1', 'max_num_pages' =&gt; 1, 'max_num_comment_pages' =&gt; 0, 'is_single' =&gt; false, 'is_preview' =&gt; false, 'is_page' =&gt; false, 'is_archive' =&gt; true, 'is_date' =&gt; false, 'is_year' =&gt; false, 'is_month' =&gt; false, 'is_day' =&gt; false, 'is_time' =&gt; false, 'is_author' =&gt; false, 'is_category' =&gt; false, 'is_tag' =&gt; false, 'is_tax' =&gt; true, 'is_search' =&gt; false, 'is_feed' =&gt; false, 'is_comment_feed' =&gt; false, 'is_trackback' =&gt; false, 'is_home' =&gt; false, 'is_404' =&gt; false, 'is_comments_popup' =&gt; false, 'is_paged' =&gt; false, 'is_admin' =&gt; false, 'is_attachment' =&gt; false, 'is_singular' =&gt; false, 'is_robots' =&gt; false, 'is_posts_page' =&gt; false, 'is_post_type_archive' =&gt; false, 'parsed_tax_query' =&gt; true, 'query' =&gt; array ( 'store' =&gt; 'itunes', ), 'request' =&gt; ' SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (135,134,133,132,131,130,129,128,125) ) AND wp_posts.post_type IN ('post', 'page', 'attachment') AND (wp_posts.post_status = 'publish' OR wp_posts.post_author = 7 AND wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10', 'posts' =&gt; array ( /* cut out */), 'queried_object' =&gt; stdClass::__set_state(array( 'term_id' =&gt; '124', 'name' =&gt; 'iTunes', 'slug' =&gt; 'itunes', 'term_group' =&gt; '0', 'term_taxonomy_id' =&gt; '125', 'taxonomy' =&gt; 'store', 'description' =&gt; '', 'parent' =&gt; '0', 'count' =&gt; '1', )), 'queried_object_id' =&gt; 124, )) </code> Output staging server, broken query <code> WP_Query::__set_state(array( 'query_vars' =&gt; array ( 'page' =&gt; 0, 'pagename' =&gt; 'itunes', 'error' =&gt; '', 'm' =&gt; 0, 'p' =&gt; 0, 'post_parent' =&gt; '', 'subpost' =&gt; '', 'subpost_id' =&gt; '', 'attachment' =&gt; '', 'attachment_id' =&gt; 0, 'name' =&gt; 'itunes', 'static' =&gt; '', 'page_id' =&gt; 0, 'second' =&gt; '', 'minute' =&gt; '', 'hour' =&gt; '', 'day' =&gt; 0, 'monthnum' =&gt; 0, 'year' =&gt; 0, 'w' =&gt; 0, 'category_name' =&gt; '', 'tag' =&gt; '', 'cat' =&gt; '', 'tag_id' =&gt; '', 'author_name' =&gt; '', 'feed' =&gt; '', 'tb' =&gt; '', 'paged' =&gt; 0, 'comments_popup' =&gt; '', 'meta_key' =&gt; '', 'meta_value' =&gt; '', 'preview' =&gt; '', 's' =&gt; '', 'sentence' =&gt; '', 'fields' =&gt; '', 'category__in' =&gt; array ( ), 'category__not_in' =&gt; array ( ), 'category__and' =&gt; array ( ), 'post__in' =&gt; array ( ), 'post__not_in' =&gt; array ( ), 'tag__in' =&gt; array ( ), 'tag__not_in' =&gt; array ( ), 'tag__and' =&gt; array ( ), 'tag_slug__in' =&gt; array ( ), 'tag_slug__and' =&gt; array ( ), 'ignore_sticky_posts' =&gt; false, 'suppress_filters' =&gt; false, 'cache_results' =&gt; true, 'update_post_term_cache' =&gt; true, 'update_post_meta_cache' =&gt; true, 'post_type' =&gt; '', 'posts_per_page' =&gt; 10, 'nopaging' =&gt; false, 'comments_per_page' =&gt; '50', 'no_found_rows' =&gt; false, 'order' =&gt; 'DESC', 'orderby' =&gt; 'wp_posts.post_date DESC', ), 'tax_query' =&gt; WP_Tax_Query::__set_state(array( 'queries' =&gt; array ( ), 'relation' =&gt; 'AND', )), 'post_count' =&gt; 0, 'current_post' =&gt; -1, 'in_the_loop' =&gt; false, 'comment_count' =&gt; 0, 'current_comment' =&gt; -1, 'found_posts' =&gt; 0, 'max_num_pages' =&gt; 0, 'max_num_comment_pages' =&gt; 0, 'is_single' =&gt; false, 'is_preview' =&gt; false, 'is_page' =&gt; false, 'is_archive' =&gt; false, 'is_date' =&gt; false, 'is_year' =&gt; false, 'is_month' =&gt; false, 'is_day' =&gt; false, 'is_time' =&gt; false, 'is_author' =&gt; false, 'is_category' =&gt; false, 'is_tag' =&gt; false, 'is_tax' =&gt; false, 'is_search' =&gt; false, 'is_feed' =&gt; false, 'is_comment_feed' =&gt; false, 'is_trackback' =&gt; false, 'is_home' =&gt; false, 'is_404' =&gt; true, 'is_comments_popup' =&gt; false, 'is_paged' =&gt; false, 'is_admin' =&gt; false, 'is_attachment' =&gt; false, 'is_singular' =&gt; false, 'is_robots' =&gt; false, 'is_posts_page' =&gt; false, 'is_post_type_archive' =&gt; false, 'parsed_tax_query' =&gt; true, 'query' =&gt; array ( 'page' =&gt; '', 'pagename' =&gt; 'store/itunes', ), 'request' =&gt; ' SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND (wp_posts.ID = '0') AND wp_posts.post_type = 'page' ORDER BY wp_posts.post_date DESC ', 'posts' =&gt; array ( ), 'queried_object' =&gt; NULL, 'queried_object_id' =&gt; 0, )) </code> I feel that I miss something obvious, but I’m lost right now. So my questions are: How can I make WP search the taxonomy archive? Why does it work on one server, but not on the other? Update Permalinks are set to <code> /%year%/%postname%/ </code> on both servers and I flushed the rewrite rules on <code> init </code> per: <code> $GLOBALS['wp_rewrite']-&gt;flush_rules(); </code> Update 2 using the stackexchange-url ("Rewrite Analyzer plugin") from @ Jan Fabry I compared the rules on my local installation and on the staging server. On the latter, the rules are absent. Rewrite rules local <code> store/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ store: ([^/]+) feed: (feed|rdf|rss|rss2|atom) store/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ store: ([^/]+) feed: (feed|rdf|rss|rss2|atom) store/([^/]+)/page/?([0-9]{1,})/?$ store: ([^/]+) paged: ([0-9]{1,}) store/([^/]+)/?$ store: ([^/]+) </code> Do I really have to add the rules manually? Usually <code> register_taxonomy() </code> should do that, shouldn’t it? Workaround Bah! I used a workaround to add the missing rewrite rules per functions.php: <code> add_action( 'init', 'add_taxrules_manually' ); function add_taxrules_manually() { $tax = 'store'; $rewrite_rules = get_option( 'rewrite_rules' ); if ( isset ( $rewrite_rules[ $tax . '/([^/]+)/?$' ] ) ) { return; } $new_rules = array ( $tax . '/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' =&gt; 'index.php?' . $tax . '=$matches[1]&amp;feed=$matches[2]', $tax . '/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' =&gt; 'index.php?' . $tax . '=$matches[1]&amp;feed=$matches[2]', $tax . '/([^/]+)/page/?([0-9]{1,})/?$' =&gt; 'index.php?' . $tax . '=$matches[1]&amp;paged=$matches[2]', $tax . '/([^/]+)/?$' =&gt; 'index.php?' . $tax . '=$matches[1]', ); $update = array_merge( $new_rules, $rewrite_rules ); update_option( 'rewrite_rules', $update ); } </code> Important: The new rules must come before the page rules. Changing the order of arguments in <code> array_merge() </code> will not fix it. The question is still open, because I just have to understand what happens here.
Did you flush the rewrite rules?
Page queried instead of a custom taxonomy
wordpress
Trying to get Uploadify to work together with Wordpress. I've implented the code from documentation in a metabox in wordpress admin area. I can "select file" and upload it, and Uploadify will show progress, but when I check the destination folder, it's empty. The folder has chmod 777 so I don't understand what could be wrong.. All help appreciated. <code> &lt;link href="&lt;?php echo get_stylesheet_directory_uri() ?&gt;/uploadify/uploadify.css" type="text/css" rel="stylesheet" /&gt; &lt;script type="text/javascript" src="&lt;?php echo get_stylesheet_directory_uri() ?&gt;/uploadify/jquery-1.4.2.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="&lt;?php echo get_stylesheet_directory_uri() ?&gt;/uploadify/swfobject.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="&lt;?php echo get_stylesheet_directory_uri() ?&gt;/uploadify/jquery.uploadify.v2.1.4.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $('#file_upload').uploadify({ 'uploader' : '&lt;?php echo get_stylesheet_directory_uri() ?&gt;/uploadify/uploadify.swf', 'script' : '&lt;?php echo get_stylesheet_directory_uri() ?&gt;/uploadify/uploadify.php', 'cancelImg' : '&lt;?php echo get_stylesheet_directory_uri() ?&gt;/uploadify/cancel.png', 'folder' : '&lt;?php echo get_bloginfo('url') ?&gt;/wp-content/uploads', 'auto' : true }); }); &lt;/script&gt; &lt;input id="file_upload" name="file_upload" type="file" /&gt; </code> Uploadify.php <code> &lt;?php /* if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/'; $targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name']; // $fileTypes = str_replace('*.','',$_REQUEST['fileext']); // $fileTypes = str_replace(';','|',$fileTypes); // $typesArray = split('\|',$fileTypes); // $fileParts = pathinfo($_FILES['Filedata']['name']); // if (in_array($fileParts['extension'],$typesArray)) { // Uncomment the following line if you want to make the directory if it doesn't exist // mkdir(str_replace('//','/',$targetPath), 0755, true); move_uploaded_file($tempFile,$targetFile); echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile); // } else { // echo 'Invalid file type.'; // } } ?&gt; </code>
your uploadify.php is all inside a comment so its not really saving the file. change it with this: <code> &lt;?php if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/'; $targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name']; $fileTypes = str_replace('*.','',$_REQUEST['fileext']); $fileTypes = str_replace(';','|',$fileTypes); $typesArray = split('\|',$fileTypes); $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$typesArray)) { // Uncomment the following line if you want to make the directory if it doesn't exist // mkdir(str_replace('//','/',$targetPath), 0755, true); move_uploaded_file($tempFile,$targetFile); echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile); } else { echo 'Invalid file type.'; } } ?&gt; </code> and also make sure you validate the file type because i had a site hacked after a hacker uploaded a php shell script with uploadify.
Problem with implenting Uploadify with Wordpress
wordpress
I'm experimenting with adjusting permalinks (for purely educational experimentation). What would I need to place in the "Custom Permalink" option to get my post URLs in the form... /year/month/post-title-goes-here/
<code> /%year%/%monthnum%/%postname%/ </code>
Custom Permalink: /year/month/post-goes-here/?
wordpress
I'm looking for an answer from someone who's implemented HyperDB or has knowledge of it. I have a database which has just passed the 100mb mark a week or so ago, the problem is my host only allows databases of 100mb a time. I was looking to implement HyperDB but wanted to find out some information first. My current database is around 100mb alone on the posts table of the database. If I implement HyperDB will this table get split between two databases?
HyperDB lets you split whole tables across different databases but it won't split a single table. You wouldn't want that anyway because that means wordpress would have to query multiple databases to find a single post. However, depending on how your site is set up, you might be able to work around that by creating a multisite wordpress install using subdirectories. That means splitting your site up into subdirectories that are actually separate wordpress installs. Then you can use hyperdb to distribute those tables. Or an easier thing to do is find a web host that doesn't limit your database size :)
Is it possible to split database tables using HyperDB?
wordpress
I've created a custom post type named agent . I have a page that lists all agents. When I add an agent I have a whole series of custom meta boxes that can be filled out, region, specialty, language... I'd like to add a series of dropdown boxes on the front end that will populate with all the terms from each custom meta. For example a regions dropbox would populate with all the regions from all the agents. If I add a new agent in a new region, the dropbox will automatically pick that up. Thanks for looking.
If you'd try to do this, you'd end up with querying a maybe pretty big load of data, which should be avoided. Best would be to pre-collect the data in some <code> global (array) $prefix_meta_box_values </code> and use this later for front-end output. You could also populate some array on <code> save_post </code> hook. Simply grap the values with <code> get_post_meta( $post_id, 'key', 'value' ) </code> inside a function on your post edit screen in admin UI and add it to some db-field with <code> update_option('agents_data') </code> . This would allow you to call <code> get_option('agents_data'); </code> in the front end and populate your select boxes. Update: <code> // The updata agents option could look like this, asuming that you already added // some data with an add_option call somewhere. Else you could just grap the old // data, merge it with the new and update the post meta field. // This was fastly written out of my head, so don't expect it to work without any fixing. function my_agents_data() { $new_agents_data = get_post_meta( $GLOBALS[$post]-&gt;ID, 'key', 'value' ); $old_agents_data = get_option( 'agents_data' ); $resulting_agents_data = array_merge( $old_agents_data, $new_agents_data ); update_option( 'agents_data', $resulting_agents_data ); } add_action( 'save_post', 'my_agents_data' ); </code> This would allow you to get the option data from <code> get_option('agents_data') </code> option field in wp options table. Point with this is, that you then should avoid that the meta data get's into the post meta table.
Filter custom posts using auto populated dropdown selectors
wordpress
i'm displaying all posts by category in my template and i was wondering: is it possible to get a list of all tags used by that category? i only found out how to make a tag-dropdown but it's from all articles, i couldn't find out yet how to filter it by category - any ideas? here's the link http://wphacks.com/how-to-display-wordpress-tags-dropdown-menu/ thx in advance
This shows you how to get tags for a category: http://www.wprecipes.com/wordpress-trick-function-to-get-tags-related-to-category
get all tags from category
wordpress
Hi to all I'm trying to create an advanced control panel for my first Wordpress template but I'm not able to add a function that I will need. The function that I'm trying to add is the possibility to choose the position of a DIV (left and bottom) via Admin Panel. (Apologize me for my really bad english) Here is the code I have in my functions.php <code> $shortname = appacqua array( "name" =&gt; "Point on the map", "type" =&gt; "section"), array( "type" =&gt; "open"), array( "name" =&gt; "Have I to activate zona 1?", "desc" =&gt; "Select if you want to show the first zone", "id" =&gt; $shortname."_zona1c", "type" =&gt; "checkbox", "std" =&gt; "false"), array( "name" =&gt; "Zona 1", "desc" =&gt; "Choose the position", "id" =&gt; $shortname."_zona1x", "type" =&gt; "text", "std" =&gt; "Left:???"), array( "type" =&gt; "close"), </code> I can see "box" in my Admin Panel and I have no problems with Checkbox, if I echo $shortname."_zona1x" It shows the number, the only problem I have is when I try to add this to my style.css: <code> .zona1{width:27px;height:27px;background:url(icone/1.png) no-repeat;position:absolute;bottom:0;left:&lt;?php echo $appacqua_zona1x;?&gt;px;} </code> It doesn't work... If I use Google Chrome to Ispect the element it gives me something like this: <code> width: 27px; height: 27px; background: url(icone/1.png) no-repeat; position: absolute; bottom: 0; left: &lt;?php echo $appacqua_zona1x;?&gt;px; </code> What am I doing wrong? Thank you very much for you help. Do you know if there is a way to create also a preview of this modification INSIDE the control panel (like inside an iFrame or stuff like this). Let's say that I'm a "self-made programmer" :P so please write "slowly" (lol) and be kind with me, thank you a lot!
From the looks of it your adding php right in the css which will not work. You need to write to the css file itself or dump it right into the html as Jeremy said as I am writing this:) Writing a new CSS file every time you make any changes can tax your system, but works well if your not making lots of dynamic changes to a live site, for instance the twentyten weaver theme does this. An easy way to do this is to actually turn your .css file into a .php file with the following at the top, and your php/css after. <code> header('Content-Type: text/css'); </code> The alternative it to write it in the header of your html, lots of plugins do this, and it can be annoying to alter the markup since it is not semantically separate, but it's also very easy. Typically this is done using the Options API : http://codex.wordpress.org/Options_API Here is an example that has used add_option in the backend for the background color (this is put in the header.php for example). <code> body { background-color: &lt;?php echo get_option('background_color'); ?&gt;; </code> For previews you can hook into the default preview_post_link and use an iframe, here is an example. <code> &lt;iframe src="&lt;?php echo clean_url(apply_filters('preview_post_link', add_query_arg('preview', 'true', get_permalink($post-&gt;ID)))); ?&gt;" width="100%" height="600" &gt;&lt;/iframe&gt; </code> Please remember there are performance issues when writing dynamic styles and you should do more research into this topic depending on the context.
Modify CSS via Theme Control Panel
wordpress
I currently have a Blogspot blog and I'm thinking of making the leap to a self-hosted WordPress one instead. Everything I've seems to suggest this is the best way to go for the best possible experience, but main concern is customizability. I've messed around with a few Blogspot blogs and I know that you're given pretty much full access in terms of changing the look of your blog. I can get in there pretty "deep" and do whatever I like. When I've read about WordPress, though, a lot of people complain about the lack of customization. Is this true? Are they getting confused with the non-self-hosted version? Just how much visual customization will I get in a self-hosted WP blog? I'd really like to know that I have full control over how things look before I take the plunge! Thanks a for any help.
The front-end customization options in self-hosted WordPress are absolute. You can edit whatever you want in PHP/HTML templates and CSS style sheets. While WordPress comes with single theme ("Twenty Ten" at moment) the availability of third party free and paid themes for it is huge . See: stackexchange-url ("Where can I download WordPress themes from?") for good list of sources for ready-made themes; stackexchange-url ("WordPress frameworks and parent themes") if you are more into developing or deeply customizing one yourself.
How customizable is a self-hosted WordPress blog compared to a Blogger blog?
wordpress
I'm looking for a good tutorial on how to create a popup window with a TinyMce button that would allow the user to select from multiple options, enter text into inputs, etc. I know how to create a button that displays a single prompt window, but that's about it and I've been searching for hours. Anyone know some links? Thanks!
Here is a nice and fairly new (a year old) tutorial i've read a few days ago http://www.garyc40.com/2010/03/how-to-make-shortcodes-user-friendly/ He as a great example and you cal also download the source files and get a better understanding.
Add popup window to TinyMCE buttons
wordpress
I'm trying to get text only content of posts by ID. I modified this function as follows, but at the moment it returns nothing. I cannot see what's wrong with it. <code> function get_the_excerpt_id($post_id) { $find = get_posts($post_id); $excerpt = $find-&gt;post_content; $excerpt = strip_tags($excerpt); $output = substr($excerpt, 0, 100); return $output; } </code> Any ideas what's missing? Marvellous
Instead of using <code> get_posts </code> , which you would use if you wanted to retrieve multiple posts in a loop, you should use <code> get_post </code> , which only retrieves one post by an ID . There is also a built-in excerpt so you might want to go with retrieving <code> post_excerpt </code> . <code> function get_the_excerpt_id($post_id) { $find = get_post($post_id); $excerpt = $find-&gt;post_excerpt; $excerpt = strip_tags($excerpt); $output = substr($excerpt, 0, 100); return $output; } </code>
Function to get content by ID
wordpress
I was wondering how to display just the following buttons: bold italic underline unordered list ordered list insert link unlik blockquote -- Thanks in advance.
Hi @José Pablo Orozco Marín: If you are looking for how to code the custom buttons yourself, WordPress' Codex has a great example that shows you how: http://codex.wordpress.org/TinyMCE_Custom_Buttons The example is complicated because it shows you how to add your own controls but if you are using the standard buttons you don't need to make is to complex. Here's a list of the standard buttons: http://tinymce.moxiecode.com/wiki.php/Buttons/controls To illustrate I've modified the example to show only the buttons you wanted. This code can be placed in your theme's <code> functions.php </code> file or in a <code> .php </code> file for a plugin that you might be writing: <code> function myplugin_addbuttons() { // Don't bother doing this stuff if the current user lacks permissions if ( ! current_user_can('edit_posts') &amp;&amp; ! current_user_can('edit_pages') ) return; // Add only in Rich Editor mode if ( get_user_option('rich_editing') == 'true') { add_filter('mce_buttons', 'register_myplugin_button'); } } function register_myplugin_button($buttons) { $buttons = array( 'bold', 'italic', 'underline', 'bullist', 'numlist', 'link', 'unlink', 'blockquote', ); return $buttons; } // init process for button control add_action('init', 'myplugin_addbuttons'); </code> And here's what it looks like when add a New Post:
Showing only certain buttons on tinymice content editor
wordpress
I'm using an API which is accessed with ID/Secret, etc. and use it in different widgets. In each widget however, I'm repeating the entire JSON process (i.e. file_get_contents, decode, etc.). I can't help but think this must be slowing the entire process down. What would be the best way of going about only calling this API once and then grabbing various data from it in different widgets, theme components, etc.? Thank you! Noel
Use Transients API - http://codex.wordpress.org/Transients_API I would also suggest you to use WordPress HTTP API - http://codex.wordpress.org/HTTP_API instead of <code> file_get_contents </code>
Best Practice for re-using API Data in WordPress?
wordpress
I've been trying to limit the amount of posts a user can create in a specific custom post type, and I had some help from Bainternet by checking out his plugin . I read over that and then came up with my own, but it doesn't seem to be working. I want to make my code much more lightweight than an entire new plugin so I am just adding it to mine, but what am I doing wrong here? The name of my custom post type will be lets say.. <code> newpages </code> . And we'll pretend <code> $custom = 'Developer'; </code> has been placed before the function. <code> function efpd_limit_posts(){ global $pagenow,$custom; if (is_admin() &amp;&amp; $pagenow=='post-new.php?post_type=newpages'){ $theposts = get_posts(array('post_type'=&gt;'newpages')); if (count($theposts) &gt;= '1'){ wp_die('You have reached the maximum amount of 'newpages' you can create.'); } } } add_action('admin_head','efpd_limit_posts'); </code>
Your array phrasing is wrong, cange <code> $count_posts = count(get_posts(array('author'=&gt;$current_user-&gt;ID,'post_type','newpages'))); </code> To <code> $count_posts = count(get_posts(array('author'=&gt;$current_user-&gt;ID,'post_type' =&gt; 'newpages'))); </code>
Limiting Amount of Posts in a Custom Post Type again
wordpress
I want to build a plugin that grabs certain url params from the query string to build a new query string for the same page. I'm following the excellent the Professional WordPress Plugin Development book, but I'm not sure which hook to use for this action. Here is my action function: <code> add_action( 'init', 'tccl_redirect' ); function tccl_redirect() { header ( "Location: http://www.mysite.com/$mypage?$newparam=$newvalue" ); ?&gt; </code> Which hooks are suitable for header redirects?
Like kaiser answered <code> template_redirect </code> hook is indeed appropriate for redirects. Also you should use <code> wp_redirect() </code> function, rather than setting header.
Which hook should be used to add an action containing a redirect?
wordpress
Usually facebook share gets an image from the site to post and shows it as thumbnails. If you press the share this on facebook link in my test page it doesn't. This is my test site: http://alexchen.info/taiwantalk/ This is the code: <code> &lt;?php /** * Template Name: Front Page * @package WordPress * @subpackage Prominent * @since Prominent 1.0 */ get_header(); ?&gt; &lt;div id="tagline"&gt; &lt;div class="container"&gt; &lt;/div&gt;&lt;!-- .container --&gt; &lt;/div&gt;&lt;!-- #tagline --&gt; &lt;div id="content"&gt; &lt;div class="container"&gt; &lt;div id="mainbar"&gt; &lt;?php while ( have_posts() ) : the_post(); ?&gt; &lt;div class="content-block-2"&gt; &lt;?php the_content(); ?&gt; &lt;/div&gt; &lt;a href="http://www.facebook.com/sharer.php?u=&lt;?php the_permalink();?&gt;&amp;t=&lt;?php the_title(); ?&gt;" target="blank"&gt;Share on Facebook&lt;/a&gt; &lt;?php endwhile; ?&gt; &lt;?php /* Display navigation to next/previous pages when applicable */ ?&gt; &lt;?php if ( $wp_query-&gt;max_num_pages &gt; 1 ) : ?&gt; &lt;?php next_posts_link( __( '&amp;larr; Older posts', 'twentyten' ) ); ?&gt; &lt;?php previous_posts_link( __( 'Newer posts &amp;rarr;', 'twentyten' ) ); ?&gt; &lt;?php endif; ?&gt; &lt;/div&gt;&lt;!-- #mainbar --&gt; &lt;/div&gt;&lt;!-- .container --&gt; &lt;/div&gt;&lt;!-- #content-bottom --&gt; &lt;?php get_footer(); ?&gt; </code> EDIT: I added all necessary meta tags and links: <code> &lt;meta charset="&lt;?php bloginfo( 'charset' ); ?&gt;" /&gt; &lt;meta name="title" content="Article headline here" /&gt; &lt;meta name="description" content="Article summary here" /&gt; &lt;title&gt;&lt;?php /* * Print the &lt;title&gt; tag based on what is being viewed. * We filter the output of wp_title() a bit -- see * twentyten_filter_wp_title() in functions.php. */ wp_title( '|', true, 'right' ); ?&gt;&lt;/title&gt; &lt;link rel="profile" href="http://gmpg.org/xfn/11" /&gt; &lt;link rel="stylesheet" type="text/css" media="all" href="&lt;?php bloginfo( 'stylesheet_url' ); ?&gt;" /&gt; &lt;link rel="pingback" href="&lt;?php bloginfo( 'pingback_url' ); ?&gt;" /&gt; &lt;link rel="image_src" href="http://alexchen.info/taiwantalk/wp-content/uploads/2011/03/cheating.png" /&gt; </code> But this is the only thing that is shown: asdasd | Taiwan Talk http://alexchen.info/taiwantalk/2011/03/ ... You may use these HTML tags and attributes: any suggestions?
<code> &lt;meta property="og:image" content="http://alexchen.info/taiwantalk/wp-content/uploads/2011/03/cheating.png" /&gt; </code> Visit http://developers.facebook.com/docs/reference/plugins/like/ and see "Step 2 - Get Open Graph Tags" There's also a lot of WP plugins out there that can help you to generate Open Graph tags.
Facebook sharing link is not showing a thumbnail of the images within the post?
wordpress
I need to import more than 1000 users from joomla to wordpress. I can do that with csv. My main concern are passwords. I did some googling and found out that it is possible to change wordpress password formats. Can anyone show me some code examples how to do that?
First of all you need to find out which hashing algorithm has been used on the Joomla site to store the passwords. Joomla - different to Worpdress - ships with a variety of hashing algorithms. If you have found out how the hashes have been generated, you can port the hashing function over into wordpress and make use of a pluggable function called <code> wp_check_password() </code> to check against the password hash. Pluggable function means, that you can define a function with the same name inside your own plugin-in, so to overwrite the standard functionality. Now here is the simple trick: You compare against both, the Joomla hash and the Wordpress one (PHPASS). Additionally you can take care of MD5 as well (the old Wordpress hashing algorithm). If a user logs in with a password that is in the old hash format, you update the users hash in the database with the standard wordpress hash (PHPASS). So each user that logs in will be automatically converted. The current <code> wp_check_password() </code> function btw. does already something similar. So what you need is Find out which algorithm was used to generate the hashes. Port that algorithm over to worpdress, so you can invoke it per one function. Extend the wp_check_password() function to test against Joomla hashes as well.
how to use joomla password format in wordpress?
wordpress
There are plenty of articles which explain how to create a wordpress plugin. I'm not looking for that, I'm looking for a schema of the core architecture of a wordpress plugin (an UML class diagram and sequence for example). Has somebody seen anything like that somewhere ? Update: I know plugin can be as simple as a function. It's not my question. My question is about the architecture of the CALLER that calls the plugin, that is the architecture of the SYSTEM pertaining to the call of the plugin. At least in which PHP module(s) is it implemented by the Wordpress Core System files ?
There is not much to it, really. During the loading of WordPress engine <code> wp-settings.php </code> file is processed. Among other things this files calls <code> wp_get_active_and_valid_plugins() </code> function, that gets list of activated (through admin interface) plugins from <code> active_plugins </code> option (stored in database). For each active plugin its main file (the one holding plugin header) is <code> include </code> d and from there it is up to plugin how it uses Plugins API (more commonly known as hooks) to integrate with WordPress. Basically it is only a thin layer of active/inactive controls on top of straight PHP <code> include </code> .
Where can I find a schema of wordpress plugin core architecture?
wordpress
Did this feature chang in 3.1? I recall that I could change the class of the link in the thickbox popup.
The link window was completely redesigned in 3.1 to make it easier to link to other posts in your blog. The "title" and "class" attributes were removed from this window, probably because the UI team thought they were not used as often?
Can't add a class to links in the visual editor since WP 3.1?
wordpress
So I'm not sure what would be the best way to go about this in terms of best practices and optimization. Scenario: I have query that parses an external XML feed and stores the data using the transient API every 24 hours. This is stored in wp_options and the whole feed is stored in the option_value, one of the numerical values in the feed is for "weight". For example here is what the feed looks like for the this value. <code> &lt;weight type="string"&gt;&lt;![CDATA[120]]&gt;&lt;/weight&gt; </code> The posts have a meta_box with a key called "meta_weight" with a numerical value. The query compares these 2 values by grabbing the xml as an array and the meta value with something rather simple like: (I have simplified this example, it is working). <code> $xml_weight = $xml-&gt;weight; $meta_weight = get_post_meta($post-&gt;ID, 'meta_weight', true); if $xml_weight &gt; $meta_weight { echo "Your heavy";} </code> Now for the actual question:) This value comparison is just done on the fly with php, I need to store it in the database using just false/true to tally all posts where this value is true. Should I just add this value incrementally using $wpdb class and insert it into wp_postmeta. Or is there some better method to just grab the value out of the DB and compare it to the meta box value for every post? My sql knowledge is very poor.
I would do the following: Create WP-Cron task (or just use daily <code> wp_scheduled_delete </code> one to tag along) and hook your function to it. In that function: fetch XML file; fetch all posts with <code> meta_weight </code> set, using <code> get_posts() </code> ; loop through posts and save comparison result in another meta field for each.
Compare transient data with a meta box value
wordpress
Assuming I have this URL: <code> http://site.com/?get=something </code> How can I change it to a nice URL that looks like: <code> http://site.com/get_something </code> using WP's URL rewriting system?
First add get to query vars array: <code> function add_query_vars_wpa12572($vars) { $vars[] = 'get' return $vars; } add_filter('query_vars', 'add_query_vars_wp12572'); </code> then add the rewrite rule <code> function author_rewrite_rules_wpa12572( $wp_rewrite ) { $newrules = array(); $new_rules['get_(\d*)$'] = 'index.php?get=$matches[1]'; $wp_rewrite-&gt;rules = $new_rules + $wp_rewrite-&gt;rules; } add_filter('generate_rewrite_rules','author_rewrite_rules_wpa12572'); </code>
Custom rewrite rules for a $_GET request
wordpress
I've tried to follow the example for Testing for paginated Pages but i don't know why it isn't working. i put it in the single.php file for post detection. i don't know why the page_test is broken. example code here: <code> &lt;?php get_header(); ?&gt; &lt;div id="content" class="narrowcolumn" role="main"&gt; &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt; &lt;div &lt;?php post_class(); ?&gt; id="post-&lt;?php the_ID(); ?&gt;"&gt; &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt; &lt;div style="margin-top:5px"&gt; &lt;div style="padding:5px; float:left; margin-right:50px;"&gt;&lt;fb:share-button href="&lt;?php the_permalink(); ?&gt;" class="url" type="button_count"&gt;&lt;/fb:share-button&gt;&lt;/div&gt; &lt;?php $page_test = $wp_query-&gt;get( 'paged' ); if ( ! $page_test || $page_test &lt; 2 ) { something here... &lt;?php } else { ?&gt; another here... &lt;?php } ?&gt; </code>
the above solution i tried already. Never mind, i solved it, even i don't know why. if some body knows...: this: <code> // not working $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : false; if ( $paged === false ) { </code> didn't worked, but this: <code> // works $paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : false; if ( $paged === false ) { </code> did work. the difference is "page" instead of "paged". i don't know why everywhere i looked i've found the code with "paged" and it didn't worked (even it the conditional tags page in the codex!), but here , in a simple topic i found it. nevertheless, it is solved.
can't use the page_test method to check pagination
wordpress
Wordpress uses the Observer Pattern for its plugin system and operates on the premise of checking if a plugin is activated, scanning the plugins directory and storing everything in an array in the plugins class. Once it gets the activated plugins, it then proceeds to include the plugin script files, however I am curious as to how Wordpress un-includes plugins when they are deactivated in the admin? If Wordpress is merely including the file via a standard include_once or require_once, how does Wordpress deactivate a plugin and therefore un-include it? It's from my understanding that you cannot include and then un-include a file in PHP (not that I know of). Can anyone point to me specific files where the plugins are included, and the appropriate functions and files where they are deactivated? If Wordpress is storing activated plugins in an array of activated plugins, then including them; how does Wordpress know not to let a function inside of a deactivated plugin be called if it's already included?
The active plugins are stored in the 'active_plugins' option, like this: <code> array( 'akismet/akismet.php', 'hello-dolly.php', ); </code> On each page load, WP just loops through that array and includes those files. It's up to each plugin to include any additional files that it may have. When a plugin is deactivated, it's just removed from that array. On the next page load, it won't be included anymore. No "un-including" required.
How Does Wordpress Uninclude/Deactivate A Plugin?
wordpress
I am trying to accomplish something somewhat simple I think. I have a menu item at the top of my page that I want to link to the latest post in a certain category. I just need to get the post ID of the latest post in the category so I can pass it to the menu. I want to do this outside of the loop and create a function in functions.php that will return the post ID. Does anyone have any suggestions on how to do this?
here is a function that does just that: <code> function get_lastest_post_of_category($cat){ $args = array( 'posts_per_page' =&gt; 1, 'order'=&gt; 'DESC', 'orderby' =&gt; 'date', 'category__in' =&gt; (array)$cat); $post_is = get_posts( $args ); return $post_is[0]-&gt;ID; } </code> Usage: say my category id is 22 then: <code> $last_post_ID = get_lastest_post_of_category(22); </code> you can also pass an array of categories to this function.
Get post ID outside of the loop
wordpress
STEPS: Don't forget to use different id numbers in each accordion. For example: id="5" (1 to 10) The title goes between the The lyrics before the Place 2 accordions per posts (like the example below). Or they will mess up. <code> &lt;div class="basic" style="float:left;" id="5"&gt; &lt;a&gt;There is one obvious advantage:&lt;/a&gt; &lt;div&gt; &lt;p&gt; You've seen it coming!&lt;br/&gt; Buy now and get nothing for free!&lt;br/&gt; Well, at least no free beer. Perhaps a bear,&lt;br/&gt; if you can afford it. &lt;/p&gt; &lt;/div&gt; &lt;a&gt;Now that you've got...&lt;/a&gt; &lt;div&gt; &lt;p&gt; your bear, you have to admit it!&lt;br/&gt; No, we aren't selling bears. &lt;/p&gt; &lt;/div&gt; &lt;a&gt;Rent one bear, ...&lt;/a&gt; &lt;div&gt; &lt;p&gt; get two for three beer. &lt;/p&gt; &lt;p&gt; And now, for something completely different.&lt;br/&gt; And now, for something completely different.&lt;br/&gt; And now, for something completely different.&lt;br/&gt; And now, for something completely different.&lt;br/&gt; And now, for something completely different.&lt;br/&gt; And now, for something completely different.&lt;br/&gt; And now, for something completely different.&lt;br/&gt; And now, for something completely different.&lt;br/&gt; Period. &lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="basic" style="float:left;" id="6"&gt; &lt;a&gt;There is one obvious advantage:&lt;/a&gt; &lt;div&gt; &lt;p&gt; You've seen it coming!&lt;br/&gt; Buy now and get nothing for free!&lt;br/&gt; Well, at least no free beer. Perhaps a bear,&lt;br/&gt; if you can afford it. &lt;/p&gt; &lt;/div&gt; &lt;a&gt;Now that you've got...&lt;/a&gt; &lt;div&gt; &lt;p&gt; your bear, you have to admit it!&lt;br/&gt; No, we aren't selling bears. &lt;/p&gt; &lt;/div&gt; &lt;a&gt;Rent one bear, ...&lt;/a&gt; &lt;div&gt; &lt;p&gt; get two for three beer. &lt;/p&gt; &lt;p&gt; And now, for something completely different.&lt;br/&gt; And now, for something completely different.&lt;br/&gt; And now, for something completely different.&lt;br/&gt; And now, for something completely different.&lt;br/&gt; And now, for something completely different.&lt;br/&gt; And now, for something completely different.&lt;br/&gt; And now, for something completely different.&lt;br/&gt; And now, for something completely different.&lt;br/&gt; Period. &lt;/p&gt; &lt;/div&gt; &lt;/div&gt; </code> My client said is too complicated. How can I turn this into a shortcode? EDIT This is a jQuery accordion the title goes in the anchor tags and the lyrics before the break tags and the ID of the divs have to change eacdh time.
What you're asking for is likely to be possible using a plugin to handle the shortcode. However, I cannot work out from what you've posted what you're trying to achieve. Can you be a bit more detailed in what you're trying to achieve? Rather than giving us the desired outcome, a bit of information on how to get there might be more useful. Dave
How to turn this HTML code into a shortcode? (adding song lyrics and giving an id to a div)
wordpress
I'm not very familiar with Wordpress' pagination so I'm not sure if this a stupid question. Layout: Code: <code> &lt;?php /** * Template Name: Pictures Page * @package WordPress * @subpackage Prominent * @since Prominent 1.0 */ get_header(); ?&gt; &lt;div id="tagline"&gt; &lt;div class="container"&gt; &lt;?php // Run main loop (The Loop). ?&gt; &lt;?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?&gt; &lt;div class="content0"&gt; &lt;?php the_content(); ?&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;/div&gt;&lt;!-- .container --&gt; &lt;/div&gt;&lt;!-- #content-bottom --&gt; &lt;div id="content"&gt; &lt;div class="container"&gt; &lt;div id="mainbar"&gt; &lt;?php $custom_posts = new WP_Query(); ?&gt; &lt;?php $custom_posts-&gt;query('category_name=Pictures'); ?&gt; &lt;?php while ($custom_posts-&gt;have_posts()) : $custom_posts-&gt;the_post(); ?&gt; &lt;div class="content-block-2"&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?&gt;" rel="bookmark"&gt;&lt;?php the_content(); ?&gt;&lt;/a&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;/div&gt;&lt;!-- #mainbar --&gt; &lt;?php get_sidebar(); ?&gt; &lt;/div&gt;&lt;!-- .container --&gt; &lt;/div&gt;&lt;!-- #content-bottom --&gt; &lt;?php get_footer(); ?&gt; </code> Don't know how to add pagination, it is out of my comprehension.
To make your life easier use one of the many pagination plugins or ones that i use all the time: WP-PageNavi WP-Paginate and in the case of these two its a matter of activating the plugin , setting up a few options and just drop a line of code to your page, for example if you use WP-PageNavi then in your code change <code> &lt;?php $custom_posts = new WP_Query(); ?&gt; &lt;?php $custom_posts-&gt;query('category_name=Pictures'); ?&gt; &lt;?php while ($custom_posts-&gt;have_posts()) : $custom_posts-&gt;the_post(); ?&gt; &lt;div class="content-block-2"&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?&gt;" rel="bookmark"&gt;&lt;?php the_content(); ?&gt;&lt;/a&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; </code> to <code> &lt;?php $custom_posts = new WP_Query(); ?&gt; &lt;?php $custom_posts-&gt;query(array('category_name' =&gt; 'Pictures', 'paged' =&gt; get_query_var('paged'))); ?&gt; &lt;?php while ($custom_posts-&gt;have_posts()) : $custom_posts-&gt;the_post(); ?&gt; &lt;div class="content-block-2"&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?&gt;" rel="bookmark"&gt;&lt;?php the_content(); ?&gt;&lt;/a&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; wp_pagenavi( array( 'query' =&gt; $custom_posts ) ); wp_reset_postdata(); </code> as you can see i added the "paged" parameter to the query and after your loop ended i called <code> wp_pagenavi(); </code> but in a smarter way to a void errors and wp_reset_postdata(); to reset the query. Now if you don't want to use a plugin you can use this fine function: <code> function pagination( $query, $baseURL = get_bloginfo( $url ) ) { $page = $query-&gt;query_vars["paged"]; if ( !$page ) $page = 1; $qs = $_SERVER["QUERY_STRING"] ? "?".$_SERVER["QUERY_STRING"] : ""; // Only necessary if there's more posts than posts-per-page if ( $query-&gt;found_posts &gt; $query-&gt;query_vars["posts_per_page"] ) { echo '&lt;ul class="paging"&gt;'; // Previous link? if ( $page &gt; 1 ) { echo '&lt;li class="previous"&gt;&lt;a href="'.$baseURL.'page/'.($page-1).'/'.$qs.'"&gt;« previous&lt;/a&gt;&lt;/li&gt;'; } // Loop through pages for ( $i=1; $i &lt;= $query-&gt;max_num_pages; $i++ ) { // Current page or linked page? if ( $i == $page ) { echo '&lt;li class="active"&gt;'.$i.'&lt;/li&gt;'; } else { echo '&lt;li&gt;&lt;a href="'.$baseURL.'page/'.$i.'/'.$qs.'"&gt;'.$i.'&lt;/a&gt;&lt;/li&gt;'; } } // Next link? if ( $page &lt; $query-&gt;max_num_pages ) { echo '&lt;li&gt;&lt;a href="'.$baseURL.'page/'.($page+1).'/'.$qs.'"&gt;next »&lt;/a&gt;&lt;/li&gt;'; } echo '&lt;/ul&gt;'; } } </code> which is pretty self explanatory all you need to do is call it with the query as first argument and the current page permalink as the second.
Adding pagination to a custom template that uses custom post types?
wordpress
Basically, I would like to know how to make a post appear on facebook (like when you press a facebook share button.) the right instant you click 'Publish'?
There are several plugins you can use. One of such plugin is Wordbook.
How to automatically share posts on facebook?
wordpress
Did anyone test if this action is being executed on theme upgrade? Are there any other actions I could use to attach a theme uninstall function?
My educated guess is that process is implemented in Theme_Upgrader class. It does some stuff with <code> upgrader_post_install </code> hook (seems like a good candidate) and it does run <code> switch_theme() </code> under some conditions (that I am too lazy to make sense of at moment).
Does the switch_theme action run when you're upgrading a theme?
wordpress
I like to create child plugin.. Explanation :- I have one parent plugin named X. This will work independently (like other existing plugins). Now I decided to add some extra features to that plugin X (think of it as an upgrade). So I want to create extra features by way of another plugin Y, which will depend on (and inherit from) X. This plugin Y will not work with out plugin X. How can I do this?
the Best way to do this is have your X plugin made with its own hooks for actions and filters so new plugins (in your case Y) could interact with plugin X's functions and data. Defining your own hooks is fairly easy and simple. Action Hook from the codex: Actions are the hooks that the WordPress core launches at specific points during execution, or when specific events occur. Your plugin can specify that one or more of its PHP functions are executed at these points, using the Action API. example of a new action hook: <code> Function whatever(){ //regular stuff you do normally do_action('Name-Of-Your-Action-hook', $args1,$args2) //regular stuff you do normally } </code> Now we can interact with that function and use its arguments ($args1,$args2) using 'Name-Of-Your_hook' hook <code> add_action('Name-Of-Your-Action-hook','hook_function_callback'); </code> Filter Hook from the codex: Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen. Your plugin can specify that one or more of its PHP functions is executed to modify specific types of text at these times, using the Filter API. example of a new filter hook: <code> Function whatever(){ //regular stuff you do normally $output = apply_filters('Name-Of-Your-Filter-hook', $output,$args1,$args2) //regular stuff you do normally } </code> Now we can interact with that function , filter $output use and its arguments ($args1,$args2) using 'Name-Of-Your-Filter-hook' hook <code> add_filter('Name-Of-Your_hook','hook_function_callback'); </code> A good example to that would be contact form 7 Contact Form 7 - Campaign Monitor Addon Contact Form 7 Dynamic Text Extension Contact Form 7 Calendar Contact Form 7 Textarea Wordcount Contact Form 7 Customfield in mail Contact Form 7 to Database Extension and many more which all (most) are plugins that extend the functionality of Contact Form 7 based on its hooks.
how to create child WordPress plugin
wordpress
I've got a self hosted blog and yesterday (18th March) the stats package stopped working. I'm getting the message: Your WordPress.com account, [account] is not authorized to view the stats of this blog. where <code> [account] </code> is the name of my Wordpress.com account. I deleted and reinstalled the plugins package and got the following message when I entered my API key: The API key "[apikey]" belongs to the WordPress.com account "[account]". If you want to use a different account, please enter the correct API key. Note: the API key you use determines who will be registered as the "owner" of this blog in the WordPress.com database. Please choose your key accordingly. Do not use a temporary key. The recommended action is to "Recover stats" The other choice is to recover the stats of my blog. However, what ever I do results in the same error. If I log into Wordpress.com with [account] I get an error message: You are not a member of this site. This is the only account I have registered with WordPress.com. How do I link my blog back to WordPress.com? I should add that I'm am running WordPress 3.1.
Switch to the new jetpack plugin and you will be fine.
I have a self hosted blog but now the WordPress.com stats plugin has stopped working
wordpress
I'm using the SoulVision WordPress theme, I'm trying to add a bottom sidebar to the already existing Top, Left and Right sidebars, however, I can't get it to successfully work. Any help would be appreciated. My coding is below. style.css <code> /*-- Sidebar settings --*/ #sidebar { float:right; width:400px; color:#DEDABF; margin-top:0px; position:relative; font-size:11px; } #sidebar a:hover { color: #C58556; text-decoration: none; } #sidebar h2 { font-size:14px; font-weight:bold; border:1px solid #8E6140; margin:0; padding:3px 0 6px 8px; background: url(images/h2-bg.jpg) repeat-x left top; } #sidebar ul li strong { color:#FC0; } #sidebar-top { width:390px; padding:5px; } .sidebar-top-box { margin-bottom:10px; padding:0; border-top: none; border-right: 1px solid #8E6140; border-bottom: 1px solid #8E6140; border-left: 1px solid #8E6140; } .box-padding { padding:7px; } .sidebar-top-box p { margin-top:3px; margin-bottom:3px; } #sidebar-top h2 { margin-top:10px; color:#CFA97E; } #sidebar-top .textwidget { margin-bottom:10px; padding:7px; border-right: 1px solid #A1674F; border-bottom: 1px solid #A1674F; border-left: 1px solid #A1674F; } #sidebar-top ul ul { list-style-type:none; margin-bottom:10px; padding:10px 7px 7px 12px; border-right: 1px solid #8E6140; border-bottom: 1px solid #8E6140; border-left: 1px solid #8E6140; } #sidebar-top ul ul li { padding-left:10px; list-style-type:none; background-image:url(images/lidot.gif); background-repeat:no-repeat; background-position:left top; padding-bottom:3px; } #sidebar-top ul li a { text-decoration:none; } #sidebar-top .box-ads a{ text-decoration:none; } #sidebar-left { float:left; width:215px; padding:0 10px 0 5px; } #sidebar #sidebar-left h2, #sidebar #sidebar-right h2 { margin:15px 0 10px; color: #CFA97E; } #sidebar-right { float:right; width:153px; padding:0 5px 0 10px; } #sidebar-left ul ul, #sidebar-right ul ul { padding-left:5px; } html, #sidebar ul, #sidebar-wrap ul, .rel-posts ul { margin:0; padding:0; } #sidebar-right li, #sidebar-left li { background:url(images/lidot.gif) no-repeat left top; list-style:none; margin:0; padding:0 0 5px 8px; } #sidebar-left .children, #sidebar-right .children { padding-top: 8px; } #sidebar-left ul.children li, #sidebar-right ul.children li { padding-bottom: 3px; padding-top: 0px; } #sidebar h2 a.rsswidget { color: #CFA97E; text-decoration: none; } #sidebar .rsswidget img { float: left; margin-top: 2px; margin-right: 7px; } /*-- Bottom Sidebar --*/ #sidebar-bottom { width:390px; padding:5px; } .sidebar-bottom-box { margin-bottom:10px; padding:0; border-top: none; border-right: 1px solid #8E6140; border-bottom: 1px solid #8E6140; border-left: 1px solid #8E6140; } .box-padding { padding:7px; } .sidebar-bottom-box p { margin-top:3px; margin-bottom:3px; } #sidebar-bottom h2 { margin-top:10px; color:#CFA97E; } #sidebar-bottom .textwidget { margin-bottom:10px; padding:7px; border-right: 1px solid #A1674F; border-bottom: 1px solid #A1674F; border-left: 1px solid #A1674F; } #sidebar-bottom ul ul { list-style-type:none; margin-bottom:10px; padding:10px 7px 7px 12px; border-right: 1px solid #8E6140; border-bottom: 1px solid #8E6140; border-left: 1px solid #8E6140; } #sidebar-bottom ul ul li { padding-left:10px; list-style-type:none; background-image:url(images/lidot.gif); background-repeat:no-repeat; background-position:left top; padding-bottom:3px; } #sidebar-bottom ul li a { text-decoration:none; } #sidebar-bottom .box-ads a{ text-decoration:none; } </code> sidebar.php <code> &lt;div id="sidebar"&gt; &lt;div id="sidebar-top"&gt; &lt;ul id="top-sidebarwidgets"&gt; &lt;?php if ( function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('Sidebar_top') ) : else : ?&gt; &lt;?php endif; ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div style="clear:both;"&gt;&lt;/div&gt; &lt;div id="sidebar-left"&gt; &lt;ul id="l_sidebarwidgets"&gt; &lt;?php if ( function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('Sidebar_left') ) : else : ?&gt; &lt;?php endif; ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div id="sidebar-right"&gt; &lt;ul id="r_sidebarwidgets"&gt; &lt;?php if ( function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('Sidebar_right') ) : else : ?&gt; &lt;?php endif; ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div id="sidebar-bottom"&gt; &lt;ul id="bottom-sidebarwidgets"&gt; &lt;?php if ( function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('Sidebar_bottom') ) : else : ?&gt; &lt;?php endif; ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; </code> With the following code, my sidebars display like this - i.imgur.com/omMfa.png But if I change the sidebar.php code to this <code> &lt;div id="sidebar"&gt; &lt;div id="sidebar-top"&gt; &lt;ul id="top-sidebarwidgets"&gt; &lt;?php if ( function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('Sidebar_top') ) : else : ?&gt; &lt;?php endif; ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div style="clear:both;"&gt;&lt;/div&gt; &lt;div id="sidebar-bottom"&gt; &lt;ul id="bottom-sidebarwidgets"&gt; &lt;?php if ( function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('Sidebar_bottom') ) : else : ?&gt; &lt;?php endif; ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div id="sidebar-left"&gt; &lt;ul id="l_sidebarwidgets"&gt; &lt;?php if ( function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('Sidebar_left') ) : else : ?&gt; &lt;?php endif; ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div id="sidebar-right"&gt; &lt;ul id="r_sidebarwidgets"&gt; &lt;?php if ( function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar('Sidebar_right') ) : else : ?&gt; &lt;?php endif; ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; </code> Then the sidebar will display like this - i.imgur.com/UATs6.png So, it appears to me that there's an issue when adding it below the existing ones. Any help would be wonderful. The site can be previewed live at http://www.itsdaniel0.com Update functions.php <code> // Widget Settings if ( function_exists('register_sidebar') ) register_sidebar(array( 'name' =&gt; 'Sidebar_top', 'before_widget' =&gt; '', 'after_widget' =&gt; '', 'before_title' =&gt; '&lt;h2&gt;', 'after_title' =&gt; '&lt;/h2&gt;', )); if ( function_exists('register_sidebar') ) register_sidebar(array( 'name' =&gt; 'Sidebar_left', 'before_widget' =&gt; '', 'after_widget' =&gt; '', 'before_title' =&gt; '&lt;h2&gt;', 'after_title' =&gt; '&lt;/h2&gt;', )); if ( function_exists('register_sidebar') ) register_sidebar(array( 'name' =&gt; 'Sidebar_right', 'before_widget' =&gt; '', 'after_widget' =&gt; '', 'before_title' =&gt; '&lt;h2&gt;', 'after_title' =&gt; '&lt;/h2&gt;', )); if ( function_exists('register_sidebar') ) register_sidebar(array( 'name' =&gt; 'Sidebar_bottom', 'before_widget' =&gt; '', 'after_widget' =&gt; '', 'before_title' =&gt; '&lt;h2&gt;', 'after_title' =&gt; '&lt;/h2&gt;', )); //GsL98DGtpo0W add_theme_support( 'post-formats', array( 'aside', 'gallery', 'video' ) ); ?&gt; </code>
For future askers with the same problem, the solution was to add before the new sidebar : <code> &lt;div style="clear:both;"&gt;&lt;/div&gt; </code> To prevent sidebars from overlapping each other.
Add Dynamic Sidebar to Exisiting WordPress Theme
wordpress
I was updating the codex page example for action hooks , while playing around to get some reuseable functions done (originally for some Q over here @WA). But then i ran into a problem i wasn't aware of before: After hooking into a function to modify the output of a variable, i can't anymore decide if i want to echo the output or just return it. The Problem: I can modify variables that i pass to a <code> do_action </code> hook with a callback function. Everything i modify/add with the variable is only available inside the callback function, but not after the <code> do_action </code> call inside the original function. FOR YOUR PLEASURE: I reworked it to an working example, so you can just copy/paste it in some <code> functions.php </code> file and see/test the problem without any efforts. Example: Handle data function This is the handle_data_fn. A little over documented as it should serve as a guide on how to parse and merge default with other arguments. You can see the problem at the end of the function right after the do_action() call. <code> /** * The "global" data handle function * * This function can serve a lot of different purposes. * Incl. merging db values from an options entry with input arguments. * * Throws a fully translateable Error if no database option name was specified. * Tells you from which file the Error was triggered and in which line you should search it. * Also tells you the "hook_data_handle_$args['UID']" name of the action hook where the Error occured. * * Uses of external function calls in order of their appearance inside the function: * @uses: isset() - @link: http://php.net/manual/en/function.isset.php * @uses: wp_die() - @link: http://codex.wordpress.org/Function_Reference/wp_die * @uses: printf() - @link: http://php.net/manual/en/function.printf.php * @uses: _e() - @link: http://codex.wordpress.org/Function_Reference/_e (i18n function) * @uses: apply_filters() - @link: http://codex.wordpress.org/Function_Reference/apply_filters * @uses: wp_parse_args() - @link: http://codex.wordpress.org/Function_Reference/wp_parse_args * @uses: extract() - @link: http://php.net/manual/en/function.extract.php * @uses: get_option() - @link: http://codex.wordpress.org/Function_Reference/get_option * @uses: do_action() - @link: http://codex.wordpress.org/Function_Reference/do_action * @uses: return - @link: http://php.net/manual/en/function.return.php * * @param: (array) mixed $args | array of arguments - `$args['UID']` is always a must have * @param: $database | true if you want to get and modify some db-option - `$args['name']` then is a must have * @param: $output | result from the function - @internal: should not get set */ function handle_data_fn( $args = array() ) { // abort if we ain't got some unique identifier as argument if ( !isset( $args['UID']) ) return; // Trigger Error if an option should get retrieved from the database, // but no option name was specified if ( !isset( $args['name'] ) ) wp_die( printf( _e( 'You have to specify the "name" of a db-entry as argument inside a handle_data_fn at for the action hook: %1$s.'."\n". 'Error triggered inside: file name %2$s (line number %3$s)' ) ,'some_textdomain' ) ,'hook_data_handle_'.$args['UID'].'`' ,__FILE__ ,__LINE__ ); // setup default arguments $defaults = ( array( 'UID' =&gt; null // DB/css: #id | used to identify the data inside your database - $name[$ID] - can be used as css #id too ,'name' =&gt; null // name of DB field, should be a constant when fn get's triggered - just here for completeness, not needed ,'args' =&gt; array( // $arguments the function can handle - put default arguments in here as array data // 'classes' =&gt; null // css: .class - example ) ,'output' =&gt; '' ,'echo' =&gt; false // if you want to echo the output or just save it in a var for later modifying ) ); // filter defaults $defaults = apply_filters( 'filter_defaults_'.$args['UID'], $defaults ); // merge defaults with input arguments $args = wp_parse_args( $args, $defaults ); extract( $args, EXTR_SKIP ); // in case you want to call the global function again, // but for some reason need to modify the merged result of defaults &amp; arguments $args = apply_filters( 'filter_args_'.$args['UID'], $args ); // retrieve the database option if ( isset( $args['name'] ) ) $options = get_option( $args['name'] ); # &gt;&gt;&gt; start building $output // if true, echo the $output if ( isset( $args['echo'] ) ) { if ( $args['echo'] === true ) { // do stuff here - your argument is the initial array do_action( 'hook_data_handle_'.$args['UID'], $args, $options ); // Test output inside handle_fn: echo '&lt;pre&gt;From inside handle_fn: '; print_r($args); echo '&lt;/pre&gt;'; return; } } // else just return the $output // HOW CAN I NOT ECHO THE DATA HERE. // STORING THE do_action return VALUE DOESN'T WORK. // NEITHER DOES JUST returnING IT INSIDE THE CALLBACK FN 'modify_args_fn' BELOW do_action( 'hook_data_handle_'.$args['UID'], $args, $options ); return; # &lt;&lt;&lt; end building $output } </code> Callback functions Those are used to a) build the initial array and b) modify the output. <code> /** * EXAMPLE for how to add initial data to the handle_data_fn function. * * @param (array) mixed $args */ function build_args_fn ( $args ) { // build initial array $args = array( 'UID' =&gt; 'whatever_UID' ,'name' =&gt; 'some_options_name' ,'args' =&gt; array( 'class' =&gt; 'example-wrap' ) ,'echo' =&gt; true ); handle_data_fn( $args ); } // 'some_hook' is some hook in a template file where the output should get echoed. add_action( 'some_hook', 'build_args_fn', 0, 1 ); /** * EXAMPLE for how to add content and modify the options from the DB inside a handle_data_fn function. * * @param (array) mixed $args * @param (array) mixed $options | db-options retrieved inside the oxo_parse function */ function modify_args_fn ( $args, $options ) { $args['output'] .= '&lt;div class="container"&gt;'; $args['output'] .= '&lt;div class="'.$args['args']['class'].'"&gt;'; $args['output'] .= $options; $args['output'] .= '&lt;/div&gt;'; $args['output'] .= '&lt;/div&gt;'; // Test output inside callback fn echo '&lt;pre&gt;From inside callback: '; print_r($args); echo '&lt;/pre&gt;'; // HERE'S THE PROBLEM. I CAN'T SIMPLE return IT, BECAUSE IT WOULDN'T BE AVAILABLE INSIDE MY 'data_handle_fn'. # return $args['output']; // I HAVE TO PRINT IT TO GET SOME OUTPUT. THE $args['output'] IS NOT AVAILABLE INSIDE THE 'handle_data_fn' AFTER THE do_action CALL. return print $args['output']; } // Name of the hook comes from 'UID' argument in 'build_args_fn' combined with 'hook_data_handle_' add_action ( 'hook_data_handle_whatever_UID', 'modify_args_fn', 10, 2 ); </code> Thanks for any info &amp; help about this issue.
If you want to return the data, the best solution is to use apply_filters() and instruct the callback to always return: <code> $output = apply_filters( 'hook_data_handle_'.$args['UID'], $args, $options ); if ( $args['echo'] ) echo $output; else return $output; </code> A less elegant solution would be to use output buffering .
hooks & filters and variables
wordpress
Why is it that one cannot get the excerpt by ID like with the title and most other elements. eg. get_the_excerpt(ID). I know how to use it with the $post-> post_excerpt function but that does not return part of the content if no excerpt was entered it simple returns nothing. So what I am trying to do is get the excerpt by ID if there is an excerpt, and if there isn't an excerpt with that ID but there is some content, to get some of the content instead. How would one do that. Any ideas, Marvellous ... EDIT -- Loop Source Code as Requested. <code> &lt;?php $stories = get_posts('category_name=feedback&amp;numberposts=4'); foreach ($stories as $post) : $title = $post-&gt;post_title; $excerpt = get_the_excerpt_id($post-&gt;ID); $thumb = get_the_post_thumbnail($post-&gt;ID,array(60, 60, true));?&gt; &lt;div class="textstandard_white" style="font-size:14px; line-height:22px; padding-top:10px;"&gt;&lt;b&gt;&lt;a href="&lt;?php echo get_permalink($post-&gt;ID);?&gt;"&gt;&lt;?php echo $title;?&gt;&lt;/a&gt;&lt;/b&gt;&lt;/div&gt;&lt;div align="left" style="height:18px; width:82px; background:url(http://www.divethegap.com/update/z-images/structure/icons/stars.png) left top no-repeat;"&gt;&lt;div id="stars&lt;?php echo $post-&gt;ID;?&gt;" align="left" style="height:18px; background:url(http://www.divethegap.com/update/z-images/structure/icons/stars_glow.png) left top no-repeat;"&gt; &lt;/div&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; var width&lt;?php echo $post-&gt;ID;?&gt; = ((&lt;?php $Rating = get_post_meta($post-&gt;ID, "Rating", true); echo $Rating; ?&gt; * 20) + '%') $('#stars&lt;?php echo $post-&gt;ID;?&gt;').css('width', width&lt;?php echo $post-&gt;ID;?&gt;); &lt;/script&gt;&lt;div class="textstandard_white" style="padding-top:6px; font-size:10px; color:#BBB; padding-bottom:10px; border-bottom:1px dotted #BBB; min-height:70px;"&gt;&lt;div style="float:left; padding-right:6px; padding-bottom:6px;"&gt;&lt;div style="background:#FFF; border:1px solid #FFF; border-radius: 4px; -moz-border-radius: 4px ; -webkit-border-radius: 4px; padding:4px;"&gt;&lt;a href="&lt;?php echo get_permalink($post-&gt;ID);?&gt;"&gt;&lt;?php echo $thumb;?&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt; &lt;?php echo $excerpt;?&gt;&lt;/div&gt; &lt;?php endforeach;?&gt; </code>
Hi @Robin I. Knight: I view <code> get_the_excerpt() </code> as a function with legacy design. As WordPress usage has grown there are many newer use-cases where it doesn't fit but where the newer functions for getting different data do. One example is the now frequent use of an <code> $args </code> array of function options. But it's easy to fix for your needs. Here's an alternative function you can use which you can put anywhere in your theme's <code> functions.php </code> file: <code> function robins_get_the_excerpt($post_id) { global $post; $save_post = $post; $post = get_post($post_id); $output = get_the_excerpt(); $post = $save_post; return $output; } </code> I've not tested it but am pretty sure I got it right. If this doesn't meet your needs please elaborate and maybe I can make other suggestions.
GET the excerpt by ID
wordpress
I'm doing up a WordPress theme at the moment, and I want users to be able to add Google Analytics to their site by just adding their tracking code -- you know, the <code> UA-20149670-1 </code> -type number thing. At the moment I have all the Google Analytics JavaScript code sitting in the <code> &lt;head&gt; </code> of my pages, with the tracking code being set by the user via a theme option text input form. However, if the user doesn't add a tracking code, then all the Google JavaScript is still left sitting in the <code> &lt;head&gt; </code> , without a tracking code, bloating up the header. How can I code this so that the Google Analytics code only appears after the user puts in their tracking code? Additionally, at the moment the Google Analytics code is all still in <code> header.php </code> -- ideally I'd like to move it instead to <code> functions.php </code> . How best would I do that? Thanks.
Take the GA code from your header and wrap it in a function hooked to <code> wp_head </code> ; <code> function __analytics_head() { $options = get_option( 'themename_theme_options' ); if ( !empty( $options['analytics'] ) ) : ?&gt; &lt;script type="text/javascript"&gt; var _gaq = _gaq || []; _gaq.push(['_setAccount', '&lt;?php echo esc_js( $options['analytics'] ) ; ?&gt;']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); &lt;/script&gt; &lt;?php endif; } add_action( 'wp_head', '__analytics_head', 100 ); </code> Obviously, this is only guideline code - the way you retrieve your options may vary - but the idea is to check if a GA account has been set, and if so, proceed to print the script.
Hiding Google Analytics code based on theme options
wordpress
Considering using flot for graphs in plugin and a little lost with dependencies and licensing here. WordPress repository demands GPLv2-compatible . flot is under MIT license , which is GPL-compatible. flot uses excanvas (for IE compatibility) under Apache License 2.0 which is compatible to GPLv3, but not v2. So is or is not flot compatible to repository? Aside - I had started wiki-style question if you want to suggest and discuss alternative libraries stackexchange-url ("Graphing libraries for WordPress")
As of May 2012 plugin repo rules have been updated, allowing Apache License 2.0 and some other previously incompatible licenses: The plugin directory’s licensing guidelines have been updated. The guidelines will now allow code that is licensed under (or compatible with) version 3 of the GPL. The guidelines still encourage use of “GPLv2 or later,” the same license as WordPress. However, we understand that many open source libraries use other licenses that are nonetheless compatible, such as GPLv2 only, GPLv3, and Apache 2.0. Nacin
Hosting plugin with excanvas (dependency of flot, jqPlot and more) in official repository?
wordpress
I read several articles about configuring the WordPress editor. For example, this snippet shows how to permanently set the editor to HTML or WYSIWYG for all contents . I'm wondering if it's possible to disable the WYSIWYG only when the user is creating a page, leaving it enabled for any other WordPress content type.
The best way to do this is by adding 'user_can_richedit' filter, like so: <code> add_filter( 'user_can_richedit', 'patrick_user_can_richedit'); function patrick_user_can_richedit($c) { global $post_type; if ('page' == $post_type) return false; return $c; } </code> Hope it's useful ;)
Disable WYSIWYG editor only when creating a page
wordpress
In a situation where one has 20 posts per page. I would like to get the current page number in order to make some nice page links at the bottom. How do you get the current page. I tried this <code> &lt;?php echo '(Page '.$page.' of '.$numpages.')'; ?&gt; </code> and it just says page 1 of 1 on every page. Any ideas, Marvellous
When WordPress is using pagination like this, there's a query variable <code> $paged </code> that it keys on. So page 1 is <code> $paged=1 </code> and page 15 is <code> $paged=15 </code> . You can get the value of this variable with the following code: <code> $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; </code> Getting the total number of pages is a bit trickier. First you have to count all the posts in the database. Then filter by which posts are published (versus which are drafts, scheduled, trash, etc.). Then you have to divide this count by the number of posts you expect to appear on each page: <code> $total_post_count = wp_count_posts(); $published_post_count = $total_post_count-&gt;publish; $total_pages = ceil( $published_post_count / $posts_per_page ); </code> I haven't tested this yet, but you might need to fetch <code> $posts_per_page </code> the same way you fetched <code> $paged </code> (using <code> get_query_var() </code> ).
Get the Current Page Number
wordpress
Hey, im not sure why but php files other then wordpress either redirects to homepage or gives a 404. for example i have a timthumb.php in directory /js/ it was working fine and generating thumnails for me.. but it started to give 404 on even running the direct url. You can take a look here : www.designzzz.com/js/ you will see timthumb.php available, but on clicking or running that file it gives 404 :( . Help is appreciated :) cheers Ayaz
Check the permissions on the JS folder against the folders for the rest of the site.
File available but giving 404 in wordpress
wordpress