INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Custom Widget function in Plugin not working? I took a code straight out of one of my themes I created, and it's a list of all 50 states in an unordered list packed into a widget you can just drag and drop on the sidebar. The problem is, when I try using this code in a PLUGIN file, I get the following error: `Fatal error: Call to a member function register() on a non-object in C:\xampp\htdocs\wordpress\wp-includes\widgets.php on line 431` Why would it work in the theme, but not in the plugin? By the way, the active theme is NOT the theme I took the code out of. Here's my code: < Thanks.
try replacing : register_widget('States_Widget'); with: add_action('widgets_init', 'register_states_widget'); function register_states_widget() { register_widget('States_Widget'); }
stackexchange-wordpress
{ "answer_score": 16, "question_score": 15, "tags": "plugin development, widgets" }
Shortcode attributes don't appear? I'm working on my first shortcode, examples in Shortcode API are not suitable for starters, so I'm almost sure I'm doing it wrong! My shortcode: function hello( $atts ) { extract( shortcode_atts( array( 'foo' => 'something', 'bar' => 'something else', ), $atts ) ); return 'Hello, World!'; return $foo; } add_shortcode('hw', 'hello'); And I want [hw foo=HEHEHE] to output: Hello, World! HEHEHE. But it displays only Hello, World! How to access & echo shortcode attributes and eventually how to set the default value (I guess I've already set the default values to "something" and "something else" but I'm not sure since I have no idea how to output them.
You are return two times! The first return exit the function, so your shortcode outputs always "Hello World". Correct code: function hello( $atts ) { extract( shortcode_atts( array( 'foo' => 'something', 'bar' => 'something else', ), $atts ) ); print_r($atts); // Remove, when you are fine with your atts! return 'Hello, World: '.$atts['foo']; } add_shortcode('hw', 'hello'); For the second question: do a `print_r($atts)` after the extracts part!
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "shortcode" }
Empty space instead of admin bar So I upgraded to 3.1 now I have a white band above the header of my website in the frontend when I'm logged in, I know this should be the control menu, but just a white band :-(
you are correct, that is for the admin bar. add this code to functions.php to disable the admin bar if you wish <?php /* Disable the Admin Bar. */ remove_action( 'init', 'wp_admin_bar_init' ); ?> if you want to use it then check your source for <div id="wpadminbar"> <div class="quicklinks"> If so, then the output is good, After that, it may be css or js conflicts perhaps
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "upgrade" }
Return array of categories to php function I am looking for a function that will retrieve the names and ids of all categories that will output a checkbox, or give me the data so I can perform a loop. <input type="checkbox" name="category" value="category_id" /> Category 1 <input type="checkbox" name="category" value="category_id" /> Category 2 <input type="checkbox" name="category" value="category_id" /> Category 3 <input type="checkbox" name="category" value="category_id" /> Category 4 <input type="checkbox" name="category" value="category_id" /> Category 5
this should do it: $categories = get_categories(); foreach( $categories as $category ) { echo '<input type="checkbox" name=' . $category->slug . '" value="' . $category->term_id . '" /> ' . $category->name . '<br />' . "\n"; } and you can change/order the list by feeding arguments to `get_categories()`: <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "categories, array" }
Is there any plugin which enables users to rate comments in thumbs up-down way? * The plugin should work with un-registered users also. * Its not mandatory for plugin to add rating system to posts/pages. I need thumbs up-down rating system only for comments.
i bet there are a lot but i have used Comment Rating plugin before and its very good just for that.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, rating" }
How to make post templates to include shortcodes only? I used to post same shortcodes every time (shortcodes loads dynamic contents). So, I want to pack these shortcodes in a template for my posts. How can I do this?
You might want to check out... < But the gist for using shortcodes in a template is as follows... ` // Use shortcode in a PHP file (outside the post editor). do_shortcode('[gallery]'); `
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, templates, shortcode" }
WordPress v3.1 Has Character Encoding Issue With Title/Permalink? I was on the latest v3.0.x series and had no issues. Once I upgraded to WP v3.1, I am having a strange issue with character encoding in permalinks. If my title was "I have $50 today" in WP 3.0.x, the month/date permalink would be example.com/2010/05/i-have-50-today/ However, here's what is happening in WP 3.1 example.com/2010/05/i-have-%e2%80%93-50-today/ I tried replicating the problem on a clean install of WordPress and was able to replicate the same issue. Can anyone confirm whether this is a bug or expected?
I solved the problem. The permalink slug under the title of a new post would not let me tweak the slug for some reason. I was able to get rid of the unwanted '-' in the permalink by heading to the posts list and clicking quick edit to edit the slug over there.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "slug, encoding" }
Sorting posts ordered by custom field value I have a series of posts (using a wp-zoom theme). I would like to create a custom field called `order` and sort by that field. Here is part of my homepage code: <?php $z = count($wpzoom_exclude_cats_home); if ($z > 0) { $x = 0; $que = ""; while ($x < $z) { $que .= "-".$wpzoom_exclude_cats_home[$x]; $x++; if ($x < $z) { $que .= ","; } } } query_posts( $query_string . "&cat=$que" ); if (have_posts()) : ?>
You can use the "orderby" parameter of query_posts. You must specify your custom field and you must give it a numeric value. Short example: query_posts($query_string . "&cat=$que&orderby=meta_value_num&meta_key=your_custom_field")
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom field, sort" }
How to make alert for new version on theme options? Let say my theme host on my server. User download my theme and use it. Now I want notify @ alert for new version of my theme. Example to show "New version has been release. Please download at ..." How to do that?
see: < Basically the idea is to hook your update checking function to the `pre_set_site_transient_update_themes` filter. The version array key you return from this function will be compared by WP to the current theme version from style.css.... Use the `admin_notices` action to make your alert message more noticeable
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "themes, php, theme options, wordpress version" }
How can I check for malware in a Theme? There are so many free, freemium and premium Themes out there. How can I be sure that a Theme I download doesn't have malware in the code? Is there an (relatively) easy way to check for malicious code without going through every line of code?
You should try using the theme check plugin at <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "themes" }
How to get any type posts include attachments by ids? I need to get any posts by an id list ($id_list), here is my codes query_posts(array('posts_per_page'=>-1, 'caller_get_posts'=>1, 'post_type'=>'any', 'post__in'=>$id_list) ); i got posts and pages by this query, but attachments don't get included, i found they are filtered by 'post_type=any' which actually doesn't include attachment. How do i get them all without have to do an extra query?
'post_type'=>'any' should get you all types except revisions so you should get the attachments but if you don't try: query_posts( array( 'posts_per_page' => -1, 'ignore_stickies' => 1, 'post_type'=> array( 'post', 'page', 'attachment' ), 'post_status' => array( null ), 'post__in'=> $id_list ) ); ## Update As t31os pointed out that: > Attachments don't have a publish status, which is default for the query so i added to the query_posts array `'post_status' => null` and that should fix your query
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "query posts, attachments" }
Create multiple Search functions for posts / custom post types and everything I'm currently working on a search function in a wp site. The plan is to have a search function on the news page which just searches posts. I'm achieving this by adding the below to my functions.php file: /* search just posts */ function SearchFilter($query) { if ($query->is_search) { $query->set('post_type', 'post'); } return $query; } add_filter('pre_get_posts','SearchFilter'); which works fine. BUT. I also need to create a search on a custom post type listing - for just the custom posts and also one for the entire site to live on the 404 page. Any ideas how to go about this greatly appreciated?
you can change your search filter to this: function SearchFilter($query) { $post_type = $_GET['post_type']; if (!$post_type) { $post_type = 'any'; } if ($query->is_search) { $query->set('post_type', $post_type); }; return $query; } add_filter('pre_get_posts','SearchFilter'); then on your news search form add : <input type="hidden" name="post_type" value="post" /> on your custom post type listing search form add <input type="hidden" name="post_type" value="customtypename" /> and on the entire site search for don't add anything an you are set.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "search, location search, pre get posts" }
Display posts starting from today date How to display a list of posts from today date to future? I am actually using this code: <div id="news-loop"> <?php if (have_posts()) : ?> <?php query_posts('cat=4&showposts=6&orderby=date&order=DESC&post_status=future&post_status=published'); while (have_posts()) : the_post(); ?> <p><?php the_time('j F, Y') ?></p> <p><a href="<?php the_permalink() ?>" ><?php the_title(); ?></a></p> </div> <?php endwhile; ?> <?php else : ?> <?php endif; ?> This is showing correctly all the posts and future posts for that category. An additional problem is: since I'm using "post_status=future&post_status=published" I have to trash the old posts to avoid them being displayed. Thanks for your help!
According to query_posts you could do a filtering function like: function filter_where( $where = '' ) { // where post_date > today $where .= " AND post_date >= '" . date('Y-m-d') . "'"; return $where; } add_filter( 'posts_where', 'filter_where' ); And then your `query_posts` doesn't need to have `post_status`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "date time" }
How to grab first image attached to post and display in RSS feed? I've seen the tutorials on how to grab the first image and display it in a post, and those on grabbing the post_thumbnail and using that in the RSS feed, but does anybody know how to grab the first image attached to a post and use that in the RSS feed? Thanks!
I ended up using a plugin called "RSS Custom Field Images" and it worked out of the box for me. I could even edit it to change the size of the image to something more manageable for me.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 3, "tags": "images, rss, feed, post thumbnails" }
WP already installed is asking to install Hey guys, i did a mistake on a wp site, i uploaded a wrong wp-config.php file on the server during a 3.1 update, saw the mistake, recreated a good one with the good infos, uploaded the file and didnt get back the site! Now wordpress askes me to install it! Which i dont want to, cos it's all already installed. I backuped the database and checked it online, it's all fine, with for exemple the good infos for 'home' and 'url' tables. If anyone knows what's going on (the install question) and i could get it back, it'd be more than welcome (am kinda stressed a lot now). Second question, if i do reinstall it, will it crash the existing datas in the database? EDIT: i checked the english version which is on the same database on the same server, site.com/en, it works fine.
Got it back, the `$table_prefix` line was wrong in my wp-config.php. Fiu.
stackexchange-wordpress
{ "answer_score": 14, "question_score": 1, "tags": "upgrade, installation" }
Is it possible to read a result if wp_update_user or update_user_meta fails? I am using both wp_update_user() and update_user_meta() and I want to be able to check for an error, and if one occurs, output it to the user. Is this possible using something like $result = wp_update_user()? I don't want an integer though I want to read the text of the error.
Not really. Deep down such functions are essentially writes to database. So either database write fails (which doesn't produce meaningful message to return) or data is somehow wrong and function just returns `false` to escape. Your best bet is probably to control data user inputs, not result of WP trying to process that data. PS worth mentioning that for debug `WP_DEBUG` and `wpdb` error echoing rock, but it's not exactly what you are asking for.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "user meta" }
Search results with custom loop don't update when paged I have the following code in my search results page to split up posts per category. When I go to the 2nd page of pagination, the results are exactly the same as the first. I'm assuming $paged has to be inserted but i'm not sure where. Any help would be appreciated Code: <
In line 51: query_posts("s='$s'&cat=177"); change to this: $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("s='$s'&cat=177&paged=$paged");
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "search, loop, customization, pagination" }
Is it OK to move admin menu items? I have a site with eight custom post types. Each is registered with `'menu_position' => 5` (below the Post menu). A side effect of having more than four CPTs is that the Media menu now appears in the middle of the list of CPTs (see image). !Admin menu with many custom post types My solution is to duplicate the Media menu item in a lower position, then unset the original Media menu item: add_action( 'admin_head', 'change_menu_items' ); function change_menu_items() { global $menu; $menu[14] = $menu[10]; unset( $menu[10] ); } My question is: is this likely to cause any unforeseen side effects? I haven't come across any yet, but just wanted to make sure. Thanks!
this might work: add_filter('custom_menu_order', 'my_custom_menu_order'); add_filter('menu_order', 'my_custom_menu_order'); function my_custom_menu_order($menu_ord) { if (!$menu_ord) return true; return array( 'index.php', // the dashboard link 'edit.php?post_type=custom_post_type', 'edit.php?post_type=page', 'edit.php' // posts // add anything else you want, just get the url ); }
stackexchange-wordpress
{ "answer_score": 8, "question_score": 4, "tags": "custom post types, wp admin, admin, admin menu" }
Adding custom post type archives to a WordPress menu Is there a way (besides adding a Custom Link) to add a custom post type archive to a menu in WordPress? If it's added using a custom link (e.g. /cpt-archive-slug/), WordPress does not apply classes like `current-menu-item` to the list element, which presents challenges when styling the menu. If the custom link contains the entire URL (e.g. < those classes are added. However, that's probably not a 'best practice'.
your best opption is custom link with full url as Custom post types archives are different form taxonomy based archives (categories,tags,any custom taxonomy) and date based archives which have there own archive slug.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 10, "tags": "custom post types, menus, custom post type archives" }
Wordpress and Htaccess Removing RewriteBase / from my htacess has sped up my site which is still working correctly. Is it really required and what is it for?
'RewriteBase /' is not needed. RewriteBase allows you to change your internal directory structure to something other than what a browser sees. IE: If all your files are in ' but you wanted ' to be the path browsers see, you would use a `RewriteBase /site` and apache's mod_rewrite would happily add that substitution for you. A `RewriteBase /` is not necessary.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "mod rewrite, htaccess" }
Recommend a flexible lightbox that allows an image or HTML to be used Can anyone recommend a flexible lightbox plugin that allows the popup lighbox to use an image and/or HTML? I want to overlay some sort of help instructions on top of my WP home page. Thanks!
any of the folowing should do just fine: * Overlay * FancyBox for WordPress * Simple Lightbox * WP Multibox * TopUp Plus and my personal favorite Highslide 4 WordPress _reloaded_
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "plugins" }
New Admin Bar Not Functioning With WP 3.1, as we all know, the admin bar is a new feature on your blog when you are logged in as an administrator, but for some reason on my theme, the admin bar is not there. In it's place is a grey bar about 30 pixels tall (matching my pages background color). What could be hiding it? If it's useful, the theme is at wphax.com
Check `footer.php` and make sure it contains `<?php wp_footer(); ?>`.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "admin bar" }
Is there any tool to find lines of codes responsible to generate front-end HTML elements? Dreamweaver CS5 is very useful to design or modify a Wordpress theme. It inspects CSS elements in Live view (after seting up a test server), but its unable to trace original wordpress code responsible for generating front-end HTML. So, I'm looking for a smart dev tool which could trace internal PHP code responsible for generating selected front-end HTML.
Any decent IDE for PHP comes with search capabilities. It is usually rather easy to find code responsible if it uses specific ids and/or class names. Personally I use NetBeans for PHP, also see Software for WordPress Theme and Plugin Development? question. A tons of good tools mentioned there.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "theme development, php, templates, html" }
Categories widget show empty? Is there a way I can display all categories in the categories widget that comes with wordpress. I do not want to have to edit the core files and I want to stay away from rewriting the widget, but if need be I will. Is there anyway to hook into the widget just to get this functionality.
Not sure what you mean by 'display all categories', i thought it does that by default? Anyways...you can hook into it, using the following filter hooks: * `widget_categories_args` * `widget_categories_dropdown_args` Both hooks pass the query args to get the categories as an array. The default is `array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h)`, wherein `$c` and `$h` are booleans and represent if the user selected 'Show post counts' and 'Show hierarchy' in the widget's options, respectively. The dropdown version gets another value: `$cat_args['show_option_none'] = __('Select Category');`, setting the label for the 'none selected' state. You'll can hook the same callback to both filters, so that the result is the same no matter if `Show as dropdown` is selected or not. BTW: The widgets that come with WP out of the box are defined in `wp-includes/default-widgets.php`, the code in there is quite readable.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "categories, widgets, hooks" }
Google Site and WordPress Can WordPress be used through Google Sites? Instead of creating a blog at WordPress itself, I'm considering to make a mesh of a website and blog using Google Sites and WordPress source code, but I'm not sure how to do this, or even if it's possible. What do you think?
Because Google Sites does not have databases sorry you have to use another site. Also becuase I don't think they have PHP on them.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "hosting" }
How can I use more than 2 DB's Say I buy a hosting package with GoDaddy and they allow 1GB max databases. So my question is how can I combine and use 2 DB's in WordPress? Is there a plug=in or do I need to edit the wp-config.php file? Benny, Age 12.
1GB is quite large, you won't get there too quickly. Furthermore, there's plenty of cheap hosting plans out there with unlimited db size. Doing what you want is in theory possible by hooking into the `query` and a whole bunch of other filters, but it's pretty complex, as you will hardly know which db to query to get certain records unless you also keep a meta database. Even then you'll still often have to query both databases and then merge the results by hooking into further WP hooks. You get the picture.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "hosting" }
How do I combine my shortcodes? Example I want combine shortcode for first paragraph and dropcap. function st_dropcap( $atts, $content = null ) { return '<span class="dropcap">'.$content.'</span>'; } add_shortcode('dropcap', 'st_dropcap'); function st_paragraph( $atts, $content = null ) { return '<p class="first-paragraph">'.$content.'</p>'; } add_shortcode('paragraph', 'st_paragraph'); On post I tried something like this [paragraph][dropcap]W[/dropcap]elcome to my blog[/paragraph] Only paragraph is working. How do I combine this code? Let me know
Change `st_paragraph()` to this: function st_paragraph( $atts, $content = null ) { return '<p class="first-paragraph">'.do_shortcode($content).'</p>'; } See Codex documentation.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "shortcode" }
Display latest post of taxonomy I have custom post type (entertainment) and I set up a taxonomy (review) as hierarchal so there are check boxes under the taxonomy. Most of the post in the entertainment are just post but we also have reviews. What I was hoping is that if it's a review then you can just check what type of review in the review taxonomy box, an example is "movie". I am trying to display the latest review using query_posts( array('tax_query' => array(array('taxonomy' => 'review','field' => 'slug','term' => 'movie')), 'posts_per_page'=>'1', 'caller_get_posts'=>'1') ); But it's showing the latest post and not the one selected as movie. I'm on WP 3.1
You can do a straight query for the taxonomy term: query_posts( array( 'review' => 'movie' ) ); To query multiple terms you can use tax_query: 'tax_query' => array( 'taxonomy' => 'review', 'field' => 'slug', 'terms' => array( 'movie', 'term', 'term' ), ),
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, custom taxonomy" }
add_filter to post-gallery and remove all <br>'s? hey guys, i really need your help. Whenever I use a gallery in wordpress and set it's columns to just 1 Wordpress automatically adds `<br style="clear: both"/>` after every `<dl class="gallery-item">`. I really need to prevent this behaviour and therefore I'd like to add a filter to my functions.php The following to examples don't work. add_filter( 'post_gallery', 'remove_br_gallery', 9); function remove_br_gallery($output) { return preg_replace('#\<br*.?\>#is', '', $output); } add_filter( 'the_content', 'remove_br_gallery', 9); function remove_br_gallery($output) { return preg_replace('#\<br*.?\>#is', '', $output); } Neither does this: return str_replace('<br style="clear: both">', '', $output); Any idea how I could solve that? I just don't want to have any `<br style="clear: both"/>` inside of my galleries.
EDIT: you must call your filter after the shortcode is processed, giving it priority > 10, and you must match on a multiline expression. Try this work with my installation and using the standard gallery shortag: add_filter( 'the_content', 'remove_br_gallery', 11, 2); function remove_br_gallery($output) { return preg_replace('/<br style=(.*)>/mi','',$output); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "php, functions, filters" }
How to migrate Wordpress Blogs into Multisite without using the GUI-Import/Export Feature I'd like to migrate some quite huge Wordpress-Blogs into one Multisite Installation. The Export-Wizard and the Import Wizard are bound to PHP-Limits (Memory, Execution-Time) and so the Export and Import often fails. There must be a way to do it by hand (only using MySQL and or the command line).
< <
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "multisite, import, migration, export" }
How to bring files from the upload directory to the media gallery? My wordpress theme creates thumbnails of media files that I upload into my posts. These thumbnails are not accessible inside the media gallery, they exist only in the media upload directory. I want to access these thumbnail files in my media gallery. How do I import files in my upload directory into media gallery?
For a one-off batch operation, you can use this plugin: < But first you should figure out why they don't show up in the first place. Maybe complain to the theme developer.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "post thumbnails, media, media library" }
JQuery Wordpress gallery I would like to know if it's possible to create a gallery like that one using WordPress: < Is there any plugin close to that?
Of course it's possible. Galleria is a jQuery plugin that is similar, but better (fancy slide transition effects and more). You could include it yourself (see their documentation) or if you prefer WordPress plugins look at Photo Gallery which seems like it's based on galleria (haven't tried it). Another really popular gallery plugin is the NEXTGen Gallery. I'm not sure if it supports the slideshow functionality seen in your link out of the box, though. I guess some coding is required for that.
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "jquery, plugin recommendation, gallery" }
If a post belongs to two categories how do I choose the main category? When I assign a post to two categories always one of categories becomes the main category. Is there any way to specify which category out of the two or more is the main category not a secondary category?
If by "main" category you mean the category that is used to create the permalink, the default is to use the category with the lowest ID. You can access the post also with an URL that contains another category, but the `rewrite_canonical()` function will kick in and redirect you to the "canonical" URL with the "main" category. However, if you hook into the `get_permalink()` function and return a URL based on another category, the canonical rewriter will notice this and it won't redirect. So you will need to create a UI in the post creation screen to select the "main" category, and hook into `post_link` to create URLs with this category.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "categories" }
Check child/parent categories if exists i am serching a WP function that controls is there any child category/ies of current category (in category.php outside of the loop) and if there is, just add link list for that category/ies to page, otherwise (there is no child category for current) list all post(s) in this category. Thanks in advance...
You can get the current posts category outside the loop by using the get_the_category function. < When you have the actual category ( however you got it) you can use get_categories, specifically the 'child_of' parameter and pass it the parent cat ID. < Also have a look at wp_list_catagories, < where you can do something simple like the following to grab the children. <?php wp_list_categories('orderby=id&show_count=1&use_desc_for_title=0&child_of=8'); ?> You would probably do an "if" statement to get the children if they exist and if not just show the category.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "categories, posts, list, functions" }
Is it possible to add taxonomies to user profiles? I would like to know if it's possible to add taxonomies in the user profile, without hacks. So far I have been able to add taxonomies to custom post types and all, but now I would like to add it to the user profile. I know how to add custom fields to the user profile, but so far failed on taxonomies. The closest I got to find a solution was: < As a newbie trying to find it there is a better solution. Thank you for reading and helping out.
The solution you linked seems about right but i can't tell if its scalable and won't crash on a large scale, another solution would be to create a non public custom post type with no UI and to act as a "stub" post for each user and keep that post ID in a user meta table, that way you can: * make easier queries. * use other post features for users like: comments,tags,categories, **custom taxonomies** and all the functionality built for posts. * use post based plugins on a user profile like: voting, rating, ranking... and i believe its a much better approach. take a look at Mike's answer to a similar question to get you started.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 3, "tags": "custom taxonomy, users" }
WP 3.1 upgrade breaks AutoFocus+ theme I run WP for my photoblog ShutterScape using the awesome theme AutoFocus+. Recently, I upgraded to 3.1 and now, it refuses to show the featured images in the individual post pages. I am suspecting a jQuery conflict, as the Error Console shows this error. Error: a.attributes is null Can someone provide some pointers to fixing this error?
There's an update available.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "theme development, themes, jquery, upgrade, customization" }
Fix threaded comments < I have looked all day for a solution but whenever you click on reply to this comment, instead of the comment box being displayed underneath you are redirected to the anchor. Also when I am in this theme, and you reply to a post, it does not register as a reply to a reply, instead it is just a regular reply. There is no doubt that I have missed something, can somebody point me in the right direction?
You don't have the comment reply Javascript being enqueued. Add this to your header, just before the wp_head() call: if ( is_singular() && get_option( 'thread_comments' ) ) wp_enqueue_script( 'comment-reply' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "themes, comment form" }
how to download all media files into my computer How do I "download" all my photos from my media library to my local computer? I can do this one at a time, but is there a way to grab them all at one time? Sort of like a "download all" process.
Your best way of doing that would be downloading the wp-content/uploads directory, by ftp access.
stackexchange-wordpress
{ "answer_score": 8, "question_score": 2, "tags": "media library" }
How to change the main site url on a multisite installation (network)? My multisite (network) installation has 3 sites. * the main site (nothing there, just very brief information) * client 1 site -- siteurl/client1 * client 2 site -- siteurl/client2 With domain mapper, siteurl/client# changed to clientdomain.com. Up to that point all is good. Now I want to change siteurl to mydomain.com How do I do that?
For those of you without the required sql knowledge. The steps below can be used to change your main site url variable on a network installation. Assumption: * Windows Operating system * MySQL Admin basic tasks * WinGrep * * * Steps: 1. Download mysql dump.sql of your full wordpress database 2. While using wingrep find all matches for @url then replace with @newURL 3. Upload the dump file with the new variables replaced 4. Change your wp_config.php file to the newURL You are done!
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "url rewriting, urls, multisite" }
W3 Total Cache can't create files I want to use W3 Total Cache plugin. Installed plugin succesfully but i'm trying to enable Page Caching and i'm getting this error : > Page caching is not available: advanced-cache.php is not installed. Either the /home/content/92/7450992/html/wp-content directory is not write-able or you have another caching plugin installed. This error message will automatically disappear once the change is successfully made. Plugin can't create advanced-cache.php to wp-content. wp-content's CHMOD is 777 but still same error. Do you have any idea ?
Had you verified that there is no `advanced-cache.php` already there from another plugin (or as leftover of one)? You can try to copy this file manually from W3TC folder: `wp-content\plugins\w3-total-cache\wp-content\`
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "cache, plugin w3 total cache" }
What is the most comprehensive backup plugin for WordPress (it does not have to be free)? Related to this question I am currently using Automatic WP backup. It works ok. Now I am looking for something more comprehensive and granular. A plugin that let's me choose the sites to backup inside my network, the type of content, the granularity on restores. ETC. Examples of things that I will like to do: * Schedule a backup, with notification to owners (site owners) * Verification of the backup (that it will work once I need it). * That I can change variables important to restore in different webhost
Since you guys haven't mentioned it yet then i'll have to **BackWPup** a free site and database backup plugin packed with features and easy to configure * Database Backup * WordPress XML Export * Optimize Database * Check\Repair Database * File Backup * Backups in zip,tar,tar.gz,tar.bz2 format * Store backup to Folder * Store backup to FTP Server * Store backup to Amazon S3 * Store backup to RackSpaceCloud * Store backup to DropBox * Send Log/Backup by eMail when ever i have a client that is a bit too cheap on hosting and a propper backup server i just set him up with a dropbox account and this plugin creates and uploads the backup there, and if the plugin runs into trubles it sends the admin a log by mail. i defintly recommend this as a free solution.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "multisite, backup" }
Find out Requires WP tag for a plugin when submitting it I am going to submit my first plugin to the repository. How do I find out the Requires tag value for which my plugin would work? I know its somewhat vague, but how do you guys figure out? Like my plugin just add some info in the head section. The only thing required for its functionality is `wp_head` hook. So I just did a grep and checked the inline documentation that it was introduced in WP v1.2 So am I right? This is how I should be doing it? Any tips?
Yepp, if you really only use that hook, that would be the way to go. But it's pretty likely you also use a couple of WP functions...if so, you should check these functions, too, before going too low with your required version. Generally, i wouldn't go below 2.0 (which i smore than 5 years old) for any new plugin. I think even going lower than 2.5, which is about 3 years old, is unnecessary.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugin development" }
Get paged outside of loop? Is it possible to get paged outside of the standard WP loop? I already use this inside the loop: <?php if ( $paged >= 2 ) { ?> Some text for the 2nd page on up <?php } ?> But I'd like to be able to echo some text outside the loop on all pages two and greater. Possible? Or a better way?
Here you go: <?php if ( is_paged() ) echo 'some text'; See <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "loop, paged" }
Remotely identify the version of a WordPress installation? How does DD32's tool determine the WordPress version of an installation. Its not working fine for WP 3.1 but it doesn't uses meta generator tag or the readme.txt of WP. So what else can it be?
I'm just assuming here but this is usually done by fingerprinting for specific version files/directory's/code and sometimes even size. For example you can remove all the meta versions tags ( isn't there like 12 places) and .txt file for 3.1 but since 3.1 is the only version to include the following new file by default, it is rather easy to fingerprint. wp-includes/js/l10n.js Since each release has many new additions, if you spend enough time writing a smart bot, it not very hard to find release specific data. Hiding all this info would be a lot of work for every release.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "wordpress version" }
How to have search results page sorted by post date On this search results page: I'd like to inverse the order of the results to start by newest post date first at the top of the page. Right now it's showing older posts first. Is there a way to specify that in the WP search function through a URL parameter? BTW, I am had to install the Relevanssi plugin to get WP (or the theme?) to search using tags. Thanks! Noel
WordPress will order search results by newest post first by default, so if your results are in a different order then it looks like another plugin is affecting them. Have you tried searching with all other plugins disabled? If you're using Relevanssi, then it won't order results by date as Relvanssia overrides this with its own weighting algorithm instead (which is the whole point of using Relevanssi).
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "search, date time" }
How can I show some standard html code across any theme I install? I have some custom code that sits inside `<head></head>`. When I install a new WordPress theme I have to edit the `header.php` script each time. Is there a way to always include my custom code inside the head tags even when installing a new WordPress theme?
You want to create a new plugin for this. See: < 1. Create a new file in /wp-content/plugins/ called headerstuff.php (or whatever) 2. Drop the following code in it: > > <?php > function header_code() { > $output .= ""; //code segment > echo $output; > } > add_action('wp_head', 'header_code'); > ?> > 3. Add your code between the quotation marks on the line starting with "$output". 4. Activate, done!
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "themes, custom content" }
creating a dynamic menu in wordpress I'm trying to use the dynamic menu of wordpress! So I try to create an dropdown based on category, my question is... I need to block the first (title/category name) for being access .... right now it will take a page with all post of that category, I only need to display the categories in the menu but users cannot click on it!! Do you guys know which function I should use in order to do that? Kind Regards
Use a # for the URL in a Custom Links item and then the menu item will not link anywhere, but can be used for a top menu item. See <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "menus, multisite" }
How to find the posts page (home page) programatically What php code can be used to find the page object that hosts the blogs? Note that this may not be the same as the first page of the web site. In the admin section we can specify in which page to display the blog posts. The hard part from what I can see is how to get this info programatically. I can cycle through all the pages using get_pages() but the is_home() is only available within the context of the loop. I don't see a field on the page objects returned by get_pages() which indicates that it is a page with blog posts.
Hi **@Alkaline:** I think you are looking for this: // $page is a post where post_type=='page' if (get_option('show_on_front')=='page') { $page_id = get_option('page_for_posts'); $page = get_post($page_id); } else { $page = false; }
stackexchange-wordpress
{ "answer_score": 13, "question_score": 8, "tags": "templates, homepage" }
remove theme's name from dashboard .. How? How are you every body how can remove name of theme in dashboard .. please .. !enter image description here You are using K2 RC-8 theme with 10 widgets. how can remove 'K2 RC-8 theme' .. please
Your options are to hide the right now widget or to change the theme name in style.css To remove the right now widget that shows the theme name. !enter image description here To change the theme name open style.css and change the theme name in the header. If your using the WordPress file editor activate another theme before you change the name in the header. /* Theme Name: Your Theme Name Theme URI: Description: My WordPress theme description Version: .99 Author: My Name Author URI: */
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "themes, dashboard" }
Add parent template name to body class filter when visiting subpage or single post how would I go about creating a filter for the `body_class()` tag that allows me to add the the parent pages slug name as a class to the body whenever visiting a subpage or post?
here: add_filter('body_class','body_class_slugs'); function body_class_slugs($classes) { global $posts,$post; if(is_single() || is_page()){ //only on a single post or page if (isset($posts)){ $classes[] = $post[0]->post_name; //posts is an array of posts so we use the first one by calling [0] } elseif (isset($post)){ $classes[] = $post->post_name; } } return $classes; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "slug, filters, functions" }
WP plugin repository didn't parse readme.txt correctly I just added a plugin on WP repository but it seems like my readme.txt wasn't parsed correctly. I even ran it through the validator but on the plugin page it shows `Description` text under all tabs - `Installation, Changelog, FAQ` Plugin - < Readme.txt - < So did I do something wrong? Or readme file parser is to blame?
You can add a short piece of text above the description that will be the "short description". You may need a blank line above and below. If it is not there, then the wp parser uses the first x characters of the description like this < <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin development" }
permalinks on title tag Is it possible to have my custom permalink structure on title tag of my blog? my current permalink structure is this `/%postname%/%location%/%mba_courses%/` where my location and mba_courses are custom taxonomies Now I want this on my title tag, can I write something like this in title tag? <title><?php echo (/%postname%/%location%/%mba_courses%/); ?><title> I know this is a wrong code, and it won't work, but is their any way, where I can have this kind of title tag?
There is no way to cause your permalink structure to be reflected automatically in the title tag. Instead, you must create it yourself. This might get you started: (I had to make a lot of assumptions in this code.) function my_title() { $post = get_queried_object(); $locations = wp_get_object_terms( $post->ID, 'location' ); $mba_courses = wp_get_object_terms( $post->ID, 'mba_courses' ); $postname = $post->post_title; $location = $locations[0]->name; $mba_course = $mba_courses[0]->name; return "$postname | $location | $mba_course"; } Then, in your single post template: <title><?php echo my_title(); ?><title>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "permalinks, title" }
show/hide toggle for subpages in wordpress admin area We have a wordpress site using many subpages to each page - I'm looking to create a show/hide accordion toggle within the backend to show and hide subpages allowing us to keep the page listings clear. Does anyone know of a plugin to do this? I've had a google but not much joy so far..
PageMash looks like it does that: < and <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "wp admin, pages" }
Wordpress Vote Plugin - Vote Once and Track User I've been looking through voting plugins and cannot seem to find one that works for me. I'm hoping you can help me out before I have to build my own as I'm tight on time. I have a page that will be full of (custom) posts, and I want users to be able to vote for their favorite. They should only be able to vote once, and I would like to track the username of the person who voted. WP-Polls is a great poll plugin that has the same features that I need (track voter and limit to one vote based on username), but I want to have a small 'vote' button below each listed post. Vote It Up can add a voting button at the bottom of each post, but does not track users or limit them to one vote. Anyone have any ideas where I could find something like that? Thanks in advance.
Here is exactly what you need, < As you can see you can track the user(s) and vote(s), also you can add some extra columns in your users admin area to track the votes.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "plugins, plugin development" }
Is there a quick way to inject i18n domain into theme/plugin files? I do have prepared theme files (with __(), and _e(), etc), but they lack domain argument. There are lots of such string scattered around the theme files, editing by hand seems to be a dreadful perspective. Is there any tool to do this quickly? I remember there was a script somewhere, but I can't find it now.
Ok, I finally found what I was looking for - Marking strings in themes and plugins. And here is the actual SVN repository for tools in question.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "plugins, theme development, themes" }
Suggestions to prepare a site which is 90% based on a plugin that's still on beta stage? I want to make a forum site which uses the bbPress plugin for Wordpress (it turns Wordpress into a forum platform). The forums say that the beta plugin shouldn't be used in production. I want to get some things done, I thought about some elements that may not be affected by changes in the core of the plugin: * The graphic design part * The UI part * The CSS * Some features Any other suggestions?
If you are not going to use a ready made forum platform like : * SMF * phpBB * Vbulletin * myBB * Vanilla becuase that site is not all forum but also a forum and you want wordpress as your platform then i would suggest you look at **SimplePress** as your forum plugin which is very mature and is constantly updated, packed with features and I can safely recommend it as a forum plugin form wordpress.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "bbpress, development strategy" }
Disable plugin only for one post It's possible to disable a plugin just for a post? I'm displaying a post in my footer but I've installed **Simple Facebook Share Button** and I don't know how to remove that button. Unfortunately I can't use css to hide the button :( How can I do this? Thanks
Do you have a custom query in the footer that includes the post? If so, please try the following code before the loop the displays the footer post: <?php remove_filter( 'the_content', 'SFBSB_auto' ); ?>
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, customization" }
How do I get W3 Total Cache not to cache sidebars? At the moment I run PHP code in my side bars. Even though I have the following header("Pragma: no-cache"); header("cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past It still appears to serve cached content.
This can be accomplished with fragment caching feature that W3TC has. Had been asked/answered couple times.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "plugin w3 total cache" }
How to show custom posts We're creating a site to showcase a series of archival recordings covering a wide variety of topics. We'd like to have a page in the main navigation (e.g. recordings) to display these by title, w/a browse by category option, and have heard the best way to do this is w/custom post types. We're able to start this setup by editing the functions.php page, as well as using the 'custom post UI' plugin, but do not understand how to actually show the custom posts, either in a list style on the recordings page, or otherwise. What is the next step? Any and all help is appreciated. don
In the template for your recordings page you'll want to specify a custom query for the post type in question. $rec_query = new WP_Query('post_type=recording'); And then later in your template, you will refer to the query object you created directly instead of relying on the default. For example: while ($rec_query->have_posts()) : $rec_query->the_post();
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, custom taxonomy" }
Posts wont expire I am having some trouble with scheduling posts to automatically expire (either by deleting or going to draft), every plugin I have tried does nothing and when it reaches the scheduled time nothing happens, which is making me think its probably some simple thing I keep overlooking.. I thought I might be a problem with wp-cron, but I don’t seem to have any trouble setting up a publish date in the future through wordPress. I have the latest version of Wordpress running, with multi-sites set-up. All plugins were at the latest version available at the moment. Does anyone have any ideas?? I am running out of things to try... Thanks in Advance Tafts
I got it working using the Post Expirator plugin, which also had the same problem, but by adding the following code to each loop right after 'the_post();' it checks the posts status on each page load, it is a temporary solution which seems to work for the moment. // check to see whether post has expired $expiration = get_post_meta($post->ID, "expiration-date", true); if ($expiration && (time() > $expiration)) { $postSettings = array( 'post_status' => 'draft' ); wp_update_post($postSettings); } else { // normal content goes here }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, multisite, customization, wp cron" }
attach several images to post + gallery i'm wondering if its possible to attach several images to a post then display those images in a thumbnail/fading gallery? By the way, the images should also be resized to a fixed size + thumbnail. thanks
Yes, you can use the standard wordpress [gallery] shortcode, after having attacched the images to your post. To attach images to your post, you can use the button "Upload Media". Upload the image from your disk and the press "Save Changes". The image will be attached to your post. Then use the gallery shortcode to insert the gallery in your post.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "images, posts, post thumbnails, gallery" }
How to control contextual help section by code? I had added some content to contextual help section for plugin options page. Now I'd like that page defaulted/toggled to contextual help section open on specific condition in my PHP code. My only issue is that I am not strong with JS and don't see clear approach to coding that (I know how to pass variable to JS through localize, but not what code will actually get it done). I had found relevant JS functions in source, but not sure how to properly reuse them for my task.
You could also trigger/simulate the help button being clicked by binding to the ready event. **Pre jQuery 1.7** <script type="text/javascript"> jQuery(document).bind( 'ready', function() { jQuery('a#contextual-help-link').trigger('click'); }); </script> **jQuery 1.7+** (bind deprecated as of 1.7) <script type="text/javascript"> jQuery(document).on( 'ready', function() { jQuery('a#contextual-help-link').trigger('click'); }); </script> The difference here is that you'll see the help section slide down as the page finishes loading, as if a user had clicked the link. Can't hurt to have another option though. :)
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "wp admin, javascript, contextual help" }
Formatting error with source code on WordPress.com? I've been trying to post some Java code to my blog, but it seems like it has some problems with the formatting. First, whenever I copy/paste code into the editor, it's pasted as pre-formatted, which means that it converts the indents to spaces, all on a single line. And when I try to separate the lines by making each line of code on a single physical line, it doesn't indent them automatically. I'm using the visual editor, and I've checked the HTML code, and nothing seems to be wrong with it. What am I doing wrong? Or is this a bug I should report to WordPress?
Paste the code in the HTML editor, it probably won't try to convert indents and linebreaks. Surround it with the `[sourcecode]` shortcode and only then return to the visual editor.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wordpress.com hosting, code, formatting" }
how to display post content without post image? i've implemented a jQuery gallery for displaying several images within a post. the problem is that the_content(); also displays the post image. any ideas how to filter it? thanks
you can add a filter to the_content hook to strip the images something like: add_filter('the_content', 'strip_images',2); function strip_images($content){ return preg_replace('/<img[^>]+./','',$content); }
stackexchange-wordpress
{ "answer_score": 9, "question_score": 2, "tags": "posts, images, filters" }
get_post_meta of multiple posts? I'm trying to get the key values for multiple posts with get_post_meta but am having no luck so far. In short, I have a function that adds 'votes' and 'thevoters' to each post. I want to check to make sure if someone's UserID is in any one of the 'thevoters' fields (spanning across multiple posts) they will not be able to vote again. The following query gets the value of a specific post. I need to get the values across all posts with that key. $voters = get_post_meta($id, 'thevoters', true); My SQL query is: SELECT * FROM `carcrazy_postmeta` WHERE meta_key='thevoters' I am using this voting code as a reference - < Any ideas?
why not add a filed to user meta once they have voted and just check to see if that specific user can vote? add to your add vote function this lines: global $current_user; get_currentuserinfo(); add_user_meta( $current_user->ID , 'voted', true ); now if a user votes it saves a usermeta filed. then you can create a simple function to check if a user can vote again: function has_he_voted($user_id){ $v = get_user_meta( $user_id , 'voted', true ); if ($v = true){ return true; }else{ return false; } } and to use it and check if the user has voted you just call that function passing a user_id: if (has_he_voted(12)){ //can't vote again ,you can only vote once //user has already voted }else{ //you can vote //user has never voted before }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "post meta, custom field" }
"Members only" section of a WordPress site - self signup and no backend access I'm working on a site which is mostly static content and one main blog. Because of this, WordPress looks like the best option to construct this site. However, the client is now looking for the following feature: * There needs to be a "members only" section, with sub-pages, containing some slightly sensitive information * Users need to be able to request an account and have their email address verified * After verification, the admin wants to manually say "yes" or "no" to each registration request before the users are added as members * Members shouldn't ever have access to the backend, but should stay on the site after registerring and logging in Is there some plugin, or series of plugins, which makes this more straightforward? Does anyone have advice on how this is best set up? Thanks!
Take a look at **theme my login** which covers: * Redirect users upon log in and log out based upon their role * Require users to be approved and confirm e-mail address upon registration and in order to create you member only pages you can use your regular pages and simply add this function to your theme's functions.php is_user_logged_in() add_shortcode('member_only','member_only_shortcode'); function member_only_shortcode($content){ if ( is_user_logged_in() ) { return $content; } else { return __('You must log-in to see this content '); } } usage: `[member_only]content to show your members[/member_only]`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, membership" }
Change default admin page for specific role(s) I was wondering if anyone knew of a plugin or a way programmatically to change the the default admin page for a specific user/role? I have a master panel page for my plugin currently setup with custom roles and permissions for the plugin using the Members Plugin and would like to force users that are in these custom roles to use my master control panel for their dashboard because they don't necessarily need access to the Dashboard. **Minor Edit** : Along with changing the default dashboard for the roles, is there a way to disable the WordPress dashboard? -Zack
In your theme's _functions.php_ : function hide_the_dashboard() { global $current_user; // is there a user ? if ( is_array( $current_user->roles ) ) { // substitute your role(s): if ( in_array( 'custom_role', $current_user->roles ) ) { // hide the dashboard: remove_menu_page( 'index.php' ); } } } add_action( 'admin_menu', 'hide_the_dashboard' ); function your_login_redirect( $redirect_to, $request, $user ) { // is there a user ? if ( is_array( $user->roles ) ) { // substitute your role(s): if ( in_array( 'custom_role', $user->roles ) ) { // pick where to redirect to, in the example: Posts page return admin_url( 'edit.php' ); } else { return admin_url(); } } } add_filter( 'login_redirect', 'your_login_redirect', 10, 3 );
stackexchange-wordpress
{ "answer_score": 12, "question_score": 6, "tags": "plugin development, user roles, dashboard" }
Google maps plugin Please recommend a google maps wp plugin that can put a map inside a wp page while other text will be situated near it (right or left hand side).
Try Google Maps Embed and use CSS to float the iframe. Nice plugin. It gives you a button in the MCE Editor of Wordpress. You simple paste your maps url!
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugin recommendation" }
How to modify the "after" of last element in wp_nav_menu When using wp_nav_menu how do I make it so 'after' => does not show on the last element of the list?
You can hide it with CSS. For example, if your `after` looks like: <?php wp_nav_menu(array('after' => '<span>|</span>')); ?> Then your css: .menu-item-num span { display: none; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 4, "tags": "navigation" }
A way to count logged in users and display count? Is there a possibility to get the count of users currently logged in and display it somewhere?
You can get the logged in users using wp_get_current_user(); . < But your probably better off just using a plugin or looking at the the following plugins code. <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "users, login" }
Failed media import I sat up MAMP on my mac and installed wordpress 3.1. Then, I exported my wordpress.com ina tried to import to my local wordpress.... I ticked import media option and I was hoping that I will get all my posta and attachments copied across but I got only posts imported properly... For each and every attachment at wordpress.com I got error saying media import failed!! Am I doing something wrong? Please help I have thousands of PDF/jpg attachments which I want imported...
I solved the problem... my source blog was private i.e. required password... I made it public for couple of minutes, and importer plugin did it's job properly!
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "media, import, permissions, uploads" }
WordPress documentation - WP_Query arguments I've been looking for a list all WP_Query arguments. This looks obvious, but < isn't helpful at all, "post_type" is mentioned only in an example, and arguments like "posts_per_page" aren't even there.
I believe this is what you're looking for. (You're right to look for it on the class documentation...i think the reason why it's on `query_posts()` is because that (and `get_posts()`) is meant to be the primarily used function to get posts.)
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "wp query, documentation" }
When will be the next major update for wordpress? My client isn't a great fan of updates so I want to assure him that the next major upgrade will be at least 3-4 months down the line. I just upgraded his blog to 3.1 - (YAY!) Would anyone concur with this or is this just wishful thinking on my part?
You may also wish to inform your client that the reason for updates is they include security fixes and patches that will only make their site better. Not running updates can have a very negative impact on their site.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "upgrade" }
How to deal with different jQuery versions? For example If you have a plugin on a site that uses jQuery 1.5.x and want to create a new plugin by implementing a script which uses an older version of jQuery, for example 1.3.x or 1.4.x. I know it probably depends on jQuery functions that are called, but if you really had to use both 1.5 and some older version of jQuery.. how would you deal with this kind of situation? Is it even possible to use 2 different versions of jQuery at the same time without drawbacks? Thanks.
You could use jQuery.noConflict in your new plugin.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin development, jquery" }
custom image dimensions (for gallery) when uploading an image into the mediapool, wordpress will auto-resize it in several dimensions. unfortunately i'm requiring a special format which is kinda between thumbnail + medium. any ideas if it's possible to do that? thanks
You can call add_image_size in your functions.php: add_image_size( 'medium', 240, 160, true ); Reference here: <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "images" }
Shortcode displays always first. Once again OK, I've had a problem with echoes in my last shortcodem, but everything works fine now. But I have another one: function myWidget_shortcode( $atts ) { extract( shortcode_atts( array( 'title' => 'My Widget', 'value' => '5', ), $atts ) ); return the_widget(myWidget,'title='.$title.'&value='.$value); } add_shortcode('myWidget', 'myWidget_shortcode'); Can you tell me wy this shortcode always displays first on pages? There's no echo etc., all the data is being returned... [found the answer - edit] **This resolves the problem:** ob_start(); the_widget(popularPosts,'title='.$title.'&number='.$number); return ob_get_clean(); Anyways I don't understand why it's always first in this case. Because the_widget is a function itself and echoes something? :>
Yes, look at the `widget()` method in your `MyWidget` class. Does it echo? Most likely it does, because that's how widgets are normally written. In fact, I'd be surprised to see a widget that didn't echo output in its `widget()` method. And when you call `the_widget()`, it fetches an instance of the widget you ask for, and calls `$widget_obj->widget($args, $instance);`. So it echos, and doesn't return anything.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "widgets, shortcode" }
the_widget() and widget's ID Let's assume I have a widget that displays only its name: <p> <?php echo $args['widget_id'] ?> </p> So when I drag & drop my widget to any sidebar it shows: <p> myWidget-number </p> The problem is I want to call this widget with a shortcode: (...) ob_start(); the_widget(MyWidget); return ob_get_clean(); } add_shortcode('myWidget_short', 'myWidget_shortcode'); And when i do [myWidget_short] it shows only <p> </p> Any ideas how to call widget's ID with a shortcode?
I believe @One Trick Pony was right. Shortcode widgets have no ID, so I've found a way around. Firstly I used PHP rand function: $var = rand(); And then added the "var" to the ID, so it doesn't collide with other shortcodes calling the same widget (each one has different random number at the end of the ID): <div id="myWidget-<?php echo $var?>;"></div>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "widgets, sidebar, shortcode" }
Page displays content from different query? How can I reset all variables in order to get the actual page content? I keep getting the last post's content I've called from a news-box I've implemented - but need the actual page's content .. thanks
Sounds like your news-box isn't using clean methods for pulling posts. I'm guessing that you are not using the get_posts() function. You're probably creating a new `WP_Query` object from scratch? Try using `get_posts()`, as it will take care of keeping the original page query clean for you.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "pages, wp query, query, get posts, content" }
query if on page/2/? hey guys, is there a way to check if i'm currently not on the frontpage of my blog? I know there are conditional tags like is_home(). However that won't work if I'm on myblog.com/page/2/ I have a pagination on my frontpage that let's users jump to the next page. If I'm on the second page i want to show a "Back Home" link. any idea how I could achieve that? thank you.
Use the conditional Tag `is_paged()` for this purpose Look at: Codex WordPress
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "php, tags" }
advice on creating a 'related posts' query like the one used on stackexchange One of the things that I most enjoy about the stackexchange website is the 'related questions' that show up on the sidebar when I am viewing a question (or show up as I am typing my question). It is readily apparent to me that the logic being used there is much more advanced than 'normal' wp functionality. I know this would be a very proprietary kind of question, but is there any available documentation on the functions being used to generate the list? I am looking for something a bit more advanced than simply using tags for relating posts. *I was going to use YARPP but after reading a number of comments on how that plugin can bring a site to its knees, I figured it would be best to ask first.
I know it will be not regular answer and maybe not helpful. On big site (more 16k posts) we use SOLR server with module MLT (more like this) and results are more than good.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "query posts" }
Fixing category count Somehow my post counts are incorrect due to inserting rows via php. I have the following code to update the count, is it correct? global $wpdb; $result = mysql_query("SELECT term_id,term_taxonomy_id FROM $wpdb->term_taxonomy where taxonomy = 'category'"); while ($row = mysql_fetch_array($result)) { $term_taxonomy_id = $row['term_taxonomy_id']; $countresult = mysql_query("SELECT object_id FROM $wpdb->term_relationships WHERE object_id IN (SELECT ID FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish') AND term_taxonomy_id = '$term_taxonomy_id'"); $count = mysql_num_rows($countresult); mysql_query("UPDATE $wpdb->term_taxonomy SET count = '$count' WHERE term_taxonomy_id = '$term_taxonomy_id'"); }
If you just want to update the counts of posts in each term, `wp_update_term_count_now( $terms, $taxonomy )` should do it... just pass the terms affected as an array and run it once for each taxonomy you have. You can also call `wp_defer_term_counting( true )` before inserting new rows, and then after adding your posts, catch up on the counts by calling `wp_defer_term_counting( false )`.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 5, "tags": "categories, terms" }
Using source control with WordPress I just recovered from a pretty bad crash using Server 2008 Shadow copy. Ultimatly I didn't lose more than a few hours of work but a loss is a loss. I've decided to move to version control to prevent this from happening again. What I'm interested in knowing is how does one handle the mysql directory? And how do you handle a development site and a live site (trunk and branch) running at the same time? I assume you wouldn't be able to move a development database to production with the posts being consistently updated. Any thoughts would be appreciated.
Have a look at this older question: How to: Easily Move a WordPress Install from Development to Production?. It covers migration and deployment of WP installations. For your more immediate issue, do backups of your database. Use a backup plugin (WP-DB-Backup is what I use, find it on the WP plugins repository) to handle this for you. You needn't worry as much about the core WP files as those can be loaded up again. You do need to keep backups of your theme files. Also take a look at this article: < It's about using source control to simplify deployments. It's something I want to give a try!
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "mysql, version control, svn" }
Is there a method or plugin that will allow posts to be sortable by Facebook likes? I'm just wondering if anyone knows of a method or plugin that I can implement that will keep track of Facebook likes within Wordpress posts, and allow me to show posts in order of "most liked"?
Similar question: Top 3 posts in last week ordered by Facebook and Twitter share counts Basically, you have to write something to get the like count and store it as metadata with the posts every so often. Then you can order based on that count.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "facebook" }
Shortcode empty attribute Is there a way of creating an empty attribute for a shortcode? Example: function paragraph_shortcode( $atts, $content = null ) { return '<p class="super-p">' . do_shortcode($content) . '</p>'; } add_shortcode('paragraph', 'paragraph_shortcode'); User types > [paragraph] something [/paragraph] and it shows `<p class="super-p"> something </p>` How to add an empty attribute functionality to my first code? So when user types > [paragraph last] something [/paragraph] It will output: <p class="super-p last"> something </p> I believe adding a: extract( shortcode_atts( array( 'last' => '', ), $atts ) ); is a good start, but how to check if user used the "last" attribute while it doesn't have a value?
There could be a couple ways to do this. Unfortunately, I don't think any will result in exactly what you're going for. ( `[paragraph last]` ) 1. You could just create separate shortcodes for `[paragraph_first]` `[paragraph_last]` `[paragraph_foobar]` that handle $content without needing any attributes 2. You could set the default value for last to `false` instead of `''`, then require users to do `[paragraph last=""]content[/paragraph]` 3. You could add a more meaningful attribute such as `position` which could then be used like `[paragraph position="first"]` or `[paragraph position="last"]` Because of the fact that WordPress discards any atts not given defaults, and the fact that an att without an `="value"` is given the default value same as if it's not listed at all, I don't see any way to achieve `[paragraph last]` Hopefully one of my 3 workaround will prove useful. Good luck!
stackexchange-wordpress
{ "answer_score": 1, "question_score": 7, "tags": "shortcode" }
htaccess redirect dynamic posts Probably not the correct fora to ask, but.. Also probably a simple question.. We are changing our site to Wordpress, and need to redirect old posts. Previously structure: ` Needs to go to `
Use this before any mod_rewrite directives: RedirectMatch Permanent ^/art/(\d+).html /?p=$1
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "redirect, htaccess" }
How to add a button that enables the user to insert a link in a textarea located in the front-end? I'm using the following plugin: < It as a textarea which enables the user to post a question. The author told me how to allow html on it. But I was wondering how to add a buttons which enables the user to use html, say, attaching a link to a word (like you do here at StackExchange sites). I think the same should apply to commenting forms. Any suggestions?
It's a JavaScript editor just like the one used in a new/edit post/page editor only here the editor is: WMD-Editor (i think) and WordPress uses an editor named: TinyMCE In both cases it's a matter of attaching the editor to a textarea. you can use Dean's FCKEditor For WordPress which uses the powerful WYSIWYG CKeditor and integrates it into the comments textarea. **Update** i just saw this < which is just what you need.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "html, forms" }
Disallow categories from this MySQL query I'm trying to modify a plugin that generates an archive listing so it shows only one category, making it a single category archive. The old version of the plugin used a get_posts query, and so it was easy to disallow categories of posts: $rawposts = get_posts( 'numberposts=-1&category=-4,-6,-7,-9' ); The new version of the plugin uses that database query: SELECT ID, post_date, post_date_gmt, comment_status, comment_count FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND post_password = How do I disallow several categories from a database query?
You could use the get_tax_sql() function introduced in WP 3.1: $tax_query = array( array( 'taxonomy' => 'category', 'terms' => array( 4, 6, 7, 9 ), 'operator' => 'NOT IN' ) ); $clauses = get_tax_sql( $tax_query, $wpdb->posts, 'ID' ); ... "SELECT ID, post_date, post_date_gmt, comment_status, comment_count FROM $wpdb->posts {$clauses['join']} WHERE post_status = 'publish' AND post_type = 'post' {$clauses['where']} " ... (not tested)
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "categories, mysql, query" }
taxonomies or categories w/custom post We are creating a custom post type to showcase a series of archival recordings. They will cover many topics, and be tagged with ideas/phrases from the talks, similar to a regular post. Is it better to create custom taxonomies such as--for example--topics and themes in place of categories and tags, or does it make any difference? Also, the individual recordings need to be marked w/info such as date recorded, length of recording(s) etc., but this is info that doesn't necessarily need to be searchable. Is it 'better form' (for lack of a way to explain) to create custom taxonomies for these bits of info, or just add them to the description meta box? thanks for your help.. Don
That depends on the volume of posts you are going to have for recordings and regular posts. if you are talking about a few of each then using the built-in categories and tags will do and you can leverage all of the built-in functions for tags and categories, otherwise there is no harm in using your own taxonomies. And as for the individual recordings info( date, lenght) if its not needed to be searchable you can use the post's custom fileds for that.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types" }
Using a rich text editor for category description? is it possible in Wordpress to have the category description use a rich text editor rather than a standard text area? If so any idea how to make it use one? Thanks!
Two plugins that i know: * **Rich Category Editor** * **Category Description Editor** but I haven't tried them on the new 3.1 so check them out.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "categories" }
trying to use wp_handle_upload with ajax I've used this tutorial to build an option page form with Ajax. Now, i want to use the wp_handle_upload to upload an image. i tried this < but with no success. help will be appreciated. Asaf.
I found a very simple solution here. It Exceeds any external Ajax solution, in my opinion.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme development, functions, uploads, ajax" }
How put links in wordpress dynamic sidebar? i would like put link after each widget in dynamic sidebar. I thinks is possible if i use static sidebar, but i don't found any tutorial for this. Thanks you
If you useWidget Logic it adds a new filter widget_content which you can hook your function to and add link to it somthing like: add_filter('widget_content','add_link_to_widgets'); function add_link_to_widgets($content){ return $content . '<br /><a href=" link</a>' } ## Update You are missing the point, the plugin is great if you want to use his ability to limit the display of widgets, **Beside** that it add a new filter. so you can use that filter like i said to add your links, each widget has an id you can add the link based on that.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "html, css, widgets, sidebar" }
Check if a script/style was enqueued/registered Is it possible to test whether a script or a style was registered using `wp_register_script/_style` or `wp_enqueue_script/_style`? All functions doesn't return a value and I'm completely clueless. I need it to switch between different functions depending on stylesheet-libraries and scripts I offer. Thank you!
There is a function called `wp_script_is( $handle, $list )`. `$list` can be one of: * 'registered' -- was registered through `wp_register_script()` * 'queue' -- was enqueued through `wp_enqueue_script()` * 'done' -- has been printed * 'to_do' -- will be printed Ditto all that for `wp_style_is()`.
stackexchange-wordpress
{ "answer_score": 53, "question_score": 33, "tags": "wp enqueue script, wp register style, wp register script, wp enqueue style" }
Query Posts or Get Posts by custom fields, possible? If I were to take a standard query post. <?php query_posts('post_type=payment'); while (have_posts()) : the_post();?> Only this time I would like to query the post by 2 custom fields that it may contain. <?php query_posts('post_type=payment'.get_post_meta($post->ID,'bookingref', true).get_post_meta($post->ID,'customerref', true) ); while (have_posts()) : the_post(); ?> That doesn't work. Is something like this possible and how is it done? Any ideas? Marvellous
To query posts by custom fields you can use the 'meta_query' parameter <?php $args = array( 'post_type' => 'payment', 'meta_query' => array( array( 'key' => 'bookingref', 'value' => 'the_value_you_want', 'compare' => 'LIKE' ), array( 'key' => 'customerref', 'value' => 'the_value_you_want', 'compare' => 'LIKE' ) ) ); query_posts($args); while (have_posts()) : the_post(); ?> you can't use get_post_meta inside the query because it gets you the value and not the key and also it accepts a Post ID to get that value of and before the query $post->id is not in the scope.
stackexchange-wordpress
{ "answer_score": 18, "question_score": 9, "tags": "custom field, query posts, get posts" }
Custom post_type search pages So I have a section on my site that specifically searches a custom post type for YouTube videos. I'm absolutely able to search the custom type. However, I'm unsure how to create a search page that has custom formatting geared toward this type of search. I've created a custom loop-youtube.php and modified within search.php `get_template_part( 'loop');` to `get_template_part( 'loop', 'youtube');` however, it affects the search results globally. Is there a way to create a custom search.php page for a specific post_type? Thanks for any help.
How are you restricting the search to your custom post type? If you are doing it by passing an additional argument, i.e. &type=myCustomPostType, you could use a conditional test, like: if(isset($_GET['type'] && $_GET['type'] == 'myCustomPostType')): get_template_part('loop','youtube'); else: get_template_part(loop); endif;
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom post types, templates, search" }
What are the better WYSIWYG post editor replacement alternatives? I hate the built-in WYSWIG editor for WordPress. (EDIT: Editors of the sites I support hate it, which in turn makes more work for me. Hence, I hate it.) I know there are some alternatives out there, but I'm curious what the more functional and usable ones are? Issues that I hear: * The text auto formatting either a) adds html or b) strips html. This is annoying. * The view within the preview section doesn't use the stylesheets of the web site itself, so it's not really WYSIWYG
when one of my clients have doesn't like the TinyMCE editor i add the Dean's FCKEditor For WordPress plugin that integrates the ckeditor and install the office 2003 skin for it so they find it easier to use.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "wysiwyg, visual editor, post editor" }
Listing all sub-pages? I'm wondering how to write a list of sub-pages of actually visited page. So I have 2 pages and 3 sub-pages for each: Colors [page] - Red [child of Colors - subpage] - Blue [child of Colors - subpage] - Green [child of Colors - subpage] Numbers [page] - One [child of Numbers - subpage] - Two [child of Numbers - subpage] - Three [child of Numbers - subpage] And when user visits "Colors" page then my code outputs Red/Blue/Green and if he does vist Numbers it shows One/Two/Three. I'm sure wp_list_pages will do the thing easy, but I'm not sure about parameters.
easy just pass it the $id off which to get the children global $id; wp_list_pages("title_li=&child_of=$id"); of if you want in the loop then wp_list_pages("title_li=&child_of=$post->ID");
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "php, functions, pages, list, listing" }
Exporting and importing my Wordpress database, but none of the plugin settings are importing I'm dumping my entire WordPress database, changing all necessary references, and then importing it into another domain. Everything works fine, except my plugin settings are not being set in the new domain. Does anyone know if Wordpress saves plugin settings locally somewhere? Or a reason why it would activate all the plugins, but not set the settings? The plugins I am specifically having trouble with are Adminimize, Admin Menu Editor, and User Roles. This is the closest plugin I could find to solving the issue, but it doesn't work for Wordpress 3.1 - < Thanks in advance for any help you can give me.
Very likely your settings are there but during your find and replace in sql you may have corrupted the serialised options. If you are doing a mysql dump from site #1 and importing dump to database for site #2, you might want to use my WordPress migration script. Using the WordPress migration script you can have all the options updated with one click, migrating all your settings for plugins, themes, widgets and other options.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "plugins, import, export" }
Custom Permalinks Break Search Pagination So I'm having a weird issue that I've never seen. I have a search.php set up like this: $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts($query_string . '&paged;=' . $paged); if ( have_posts() ) : while ( have_posts() ) : the_post(); // post stuff endwhile; else: endif; pagination(); If I use anything but the default permalink structure, it breaks the pagination and returns a 404 and the second page. Ant ideas?
Alright, I've solved the problem. Turns out that you should never use action="" for searchform.php. It will work perfectly fine in terms of search results, but it will break the pagination, when using 3.1. Instead, you should use for the form action.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "search, query, pagination, paged" }
Problem enabling the user to edit Markdown and displaying the HTML output (WMD Editor plugin for Wordpress) Here is the WMD Editor implementation for Wordpress. **When the users writes a post everything is displayed OK:** !enter image description here !enter image description here **The problem is when the user clicks EDIT:** !enter image description here The HTML version is the one displayed (I think it is a normal behaviour since WMD Editor turned the Markdown version of the post into HTML). What are the steps to fix this? or IS there a new version which solves this? (I checked other questions but no one gives a concrete solution).
that is the normal way for it to work, when you save it turns the markdown text to html, so when you edit you need to reverse the html back to markdown text. there is an outdated plugin that has most of the functions you need it < that would be a good place to start.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, visual editor" }
How to add URL-Parameter for Javascript Widgets? I need to add pamarameters to URLs that are read by javascript widgest/gadgets run on the site. Whenever I just add them e.g. the original URL is ` and the parameter is called _foo_ with a value called _bar_. The new URL becomes: ` The original URL is working fine, **but the new URL is giving a 404**. I assume that I need to register any additional parameter so that this works first. Is this true? How can I make new URL parameters not triggering 404s?
I found the answer to my question. There is no need register query vars for this but instead to take care to not use some of the core query vars as this will break things. In my case it was the **year** query variable which caused the 404.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "urls, pages, parameter" }