INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
WordPress Custom Query to get Most Commented Posts in the Past 7 Days I'm trying to do a query on wpdb to get the posts commented on most in the past week... Any ideas what I'm doing wrong? $querystr = "SELECT comment_count, ID, post_title FROM $wpdb->posts wposts, $wpdb->comments wcomments WHERE wposts.ID = wcomments.comment_post_ID AND wcomments.comment_date >= CURDATE() - 7 GROUP BY wposts.ID ORDER BY comment_count DESC LIMIT 0 , 10 "; $pageposts = $wpdb->get_results($querystr); Thanks in advance. **EDIT** Query changed to something that _sort of_ works I'm still not getting the date range right... it is returning the posts that are most commented on of all time, and not only the posts that have been commented on in the past week.
This should do it: $querystr = "SELECT comment_count, ID, post_title FROM $wpdb->posts wposts, $wpdb->comments wcomments WHERE wposts.ID = wcomments.comment_post_ID AND wposts.post_status='publish' AND wcomments.comment_approved='1' AND wcomments.comment_date > DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 YEAR) GROUP BY wposts.ID ORDER BY comment_count DESC LIMIT 0 , 10 ";
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "query posts" }
Automatically wrap post image in div _In regards to image attachments inserted into a post_ , I would like to wrap the **img** tag inside a **div** tag for specific design purpose. Is there a way to do this **automatically** after attaching the image file, like through _hooks/filters_ maybe? Thanks in advanced!!
It's the image_send_to_editor filter: if(is_admin()){ add_filter('image_send_to_editor', 'wrap_my_div', 10, 8); function wrap_my_div($html, $id, $caption, $title, $align, $url, $size, $alt){ return '<div class="mydiv" id="mydiv-'.$id.'">'.$html.'</div>'; } } For existing images/posts you can try the regex in the function below
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "customization, attachments, uploads, images" }
Making $ globally accessible with jQuery.noConflict() The Codex promotes this method of using `$` inside a plugin/theme JavaScript file: jQuery(document).ready(function($) { // $() will work as an alias for jQuery() inside of this function }); But if you do that you only have access to `$` inside ready(). I think functions should be broken into small modules which are called from ready(), not all lumped together inside ready(), so if I use the Codex's method then I have to pass $ to each function, which is annoying and crude. Writing out `jQuery` all the time instead of just using `$` is also annoying. I can just do `$ = jQuery.noConflict();` at the start of my JavaScript file and then `$` is available everywhere, but I suspect that that might cause problems with other plugins/themes in some situations. My searches haven't turned up any thorough explanations or definitive answers. Does anyone have any thoughts?
You don't need `$ = jQuery.noConflict();` Just wrap any functions outside document.ready() within: (function($){ // use $ here safely })(jQuery);
stackexchange-wordpress
{ "answer_score": 9, "question_score": 6, "tags": "jquery, customization" }
Redirect wrong links Wordpress I am using the following permalinks structure: /%postname%/ and I also have some multi-page posts that look like /%postname%/2. The problem is I see a lot of 404 errors in webmaster tools for urls like /post-name/random stuff here How can I redirect all wrong URLs to the correct ones ?
Have you tried the Smart 404 plugin? <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "htaccess, redirect" }
[Plugin: Posts 2 Posts] Changing display order of connections Can I change the order in which connections are displayed ? If I create say three connections and then display them at the bottom of my article, I will get them in reverse order. How can I change that ? I tried to use 'orderby' and 'order' but it has no effect whatsoever : $connected_titles = new WP_Query( array( 'post_type' => 'as_title', 'nopaging' => true, 'orderby' => 'title', 'order' => 'DESC', 'suppress_filters' => false, 'connected_from' => get_queried_object_id() ));
Just replace `'order' => 'DESC'` with `'order' => 'ASC'`.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom post types, posts, customization" }
Hide Overflow on a Specific WordPress Template I'm trying to hide the overflow in CSS for specific template pages but can't seem to get it to work - I know that template pages are prefixed with a class but this doesn't seem to help targeting. I think I could use the is_page_template() function to hide the overflow with JS but this should be simpler with CSS. So this works... html { overflow: hidden; } but this doesn't work... html .page-template-showreel-php { overflow: hidden; } Any ideas why? Surely this should be possible with CSS.
This: html .page-template-showreel-php { overflow: hidden; } ...will target `body.page-template-showreel-php`. So, two questions: 1. Do you have the `<?php body_class(); ?>` template tag inside of the `<body>` HTML tag? 2. Is hiding overflow on the `<body>` tag _really_ what you're after, or do you need to target a descendant element? **EDIT** There is no semantic or programmatic reason that you can't re-use the `<?php body_class(); ?>` template tag inside the `<html>` tag also. So, you might consider: `<html <?php body_class(); ?>>` and then: html.page-template-showreel-php { overflow: hidden; } Worth a shot...
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "css, page template" }
Where do you upload images on a wordpress site? I am very new to wordpress and learning on my own.I have started to create a website where I need to **upload images**. I want to ask if you all usually use the same database to store the image(if so, how?) or use a image uploading site? Thanks
Wordpress images are stored in your wp-content/uploads folder no need for storing in the database, only the img uris get stored there. When you create an new wordpress post or page with your text editor you will notice several icons above it, use the first one to upload images and it will give you the option to add it to your post. Its realy very simple but there are other things to take note of before you do this like setting images sizes etc, i suggest you read up on the **codex for image handling**..
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images" }
How to Use WordPress as Static CMS Without Blog Posts I am very new to **wordpress**. I want to edit a wordpress theme and remove the blogpost area from it so it can be converted into a website. I also want to make some other changes. How I am trying to do it is, > " I viewed the HTML code of my page and pasted in Dreamweaver and edited it. Now I am stuck with how to upload it." Please help me out. If there is a better way to do it please suggest. Thanks
Thats not really an ideal way to do it (and will bring all kinds of problems), what your real aim is, is to make **wordpress into a CMS** this way you can manage it as website from the wp-admin panel, add new pages etc, etc, the link i have added is just to give you an idea of whats involved, there are other Wordpress to CMS tutorials out there that will also help you.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 5, "tags": "themes, cms" }
Using "Read More" link with custom excerpt The following functions.php edit (contributed by helgatheviking on the themeshaper forums) allows the use of a "Read More" link with custom excerpts. My problem is simply this: I'm inept at editing functions.php code, but I'd like to safely remove the "wrap excerpt in p tag" portion of this script. How would I do so? Thanks. Original script is found here: < // excerpt read more links and wrap excerpt in p tag function all_excerpts_get_more_link($post_excerpt) { return '<p>' . $post_excerpt . '</p>' . '<p class="readmore"><a href="'. get_permalink($post->ID) . '">' . 'Continue Reading &raquo' . '</a></p>'; } add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');
This should remove the `<p>` tags, but leave the styling by replacing the paragraph tag with a `<span>` class: function all_excerpts_get_more_link($post_excerpt) { return '' . $post_excerpt . '' . '<span class="readmore"><a href="'. get_permalink($post->ID) . '">' . 'Continue Reading &raquo' . '</span>'; } add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "functions, excerpt" }
I'm trying to find a basic plugin for displaying images in a widget I've tried and installed loads of free WP plugins that can't do what I would like them to do. I write a fictional news blog and I'd like to be able to display about a dozen or so adverts that I've made myself. They are each going to be 250x250px and need to be in the sidebar of my site. I figured it would be easier if it was in a widget. I'm not using a external service like Adsense. It's not necessary that my adverts keep record of impressions and they don't have a hyperlink.
Create a new folder in your WP directory called 'Adverts' Upload all your banner images to this folder as well as a PHP image randomising script I had found with a quick Google search. Place a text widget in your sidebar and add a html img tag linking directly to PHP file.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "widgets, plugin recommendation" }
Videopress Short Tags not working when pulling page into template Videopress doesn't work for me when I drag multiple pages into a template e.g. pulling them in by their path name... $page = get_page_by_path('Showreels/Excerpts'); Does anyone know how I can paste a videopress link directly into the php since the shortcode doesn't seem to work?
I've got it... for anyone else having this problem... 1. Go to where your media is kept on your WordPress.com account i.e. Media > Library 2. Go to edit the video and make sure that 'Display share menu and allow viewers to embed or download this video' - this is so that you can click the 'share' menu on the embedded video on an actual page, grab the embed link and paste it into your html code 3. Go back to your media page and disable the share menu again if you want to protect your videos.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "page template" }
Building Forums with Custom Post Types I'm trying to build some sort of a discussion boards by using custom post types and the built in comments. The structure is as following: An archive page to list all the pages of the Forum type, so each page is a "forum" Each "forum" has a title , a small description and then some threaded comments as threads with replies I think I'm at the right direction here, but I have a couple of question and maybe some one could assist me with them: 1. Is it possible to have user to be associated with specific pages? **Example:** I'd like user A, B, C to be able to view "Forum" (page) 1; user D, E, F -> "Forum" (page) 2; etc. 2. Is it possible to have users to be redirected on sign up to their profile page, but disable all other menus in the admin area for them? 3. Is it possible to allow some users to be able to moderate comments only but not to see the other options on the site? Any help would be great.
Check out User Access Manager for point 1). For stripping back the menus & controlling access, check out the User Role Editor. You can strip user capabilities down to the bare essentials, and a lot of the items in the menu will disappear for them. For example, removing all `*_themes` privileges will hide the Appearance item. You may find you can't quite hide all the menus you want, so you can hook into `admin_menu` and conditionally use `remove_menu_page` and `remove_submenu_page` depending on `current_user_can( 'role_name_or_capability' )`. For the redirect, check out `wp-login.php` \- there should be a decent hook or filter in there for you to use and change where the user gets redirected; either after logging in or registering.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom post types, user roles, user access, forum" }
adding multiple sidebars on pages I am using twentyten theme and I want there to be two sidebars on my page - one on the left and the second on the right. Can any one tell me how to do that?
Thirty Ten is a child theme of Twenty Ten and could be excellent for you as it comes with 3 columns as you want.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "themes, widgets, sidebar, register sidebar" }
Importing posts from XML into custom post type I need to be able to create posts in a custom post type with custom taxonomies from an XML file. It is from a job feed so when a job is added I need to be able to import it into wordpress. Do I just use wp_insert_post() ?
I did a job like this. Essentially it is parse and `wp_insert_post()`, but there are couple of fragile things to be aware of: * you need some way to reliably track items to prevent duplicates, my approach was to ~~save unique identifier from XML as post's GUID in WP~~ for some obscure reason WP wants GUID to be URL-like (not _valid_ URL, but _formatted_ like one) so it's more reliable to go with custom field for identifiers that are not URLs; * `wp_insert_term()` checks for some user capabilities here and there. And in WP cron there is no user set up. I vaguely remember this caused me troubles with assigning custom taxonomy and since you need that - check source and properly test that code does work in cron.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types" }
What function can I use to override the multisite maximum file size upload restriction? What function can I use to override the multisite maximum file size upload restriction? I have already maxed out the kb upload size and ensured that the max file upload size in php.ini is over 50mb, yet still I'm getting an error uploading an 11mb file. !WP multisite max file size ![](
Make sure you've also boosted post_max_size to at least the same or greater. Check out the other precautions you should also take when doing so.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "uploads" }
Need webcam chat plugin for my client I am developing a website where I need a webcam chat plugin. I have tried many plugins from wordpress.org but none of them worked. Can anyone please suggest me a working plugin. Plugins that did not work: 1. TokBox OpenTok Plugin **Problem** : > In the dashboard,it only pops up once i.e the first time the plugin is used and still the button to start webcam did not work(Also note that it did not show up my webcam.) **Resolved:** The problem was with the dashboard. I uploaded the files and it started to work . Thanks 2\. Tinychat** **Problem** : > Was unable to find API for it. 1. VideoWhisper Video Presentation **Problem** : > Keeps on loading and does not work Thanks.
Here's the link to the API for Tinychat. It was hidden in the footer. You could also take a look at this thread on WeekendHackers, where someone is searching for the same solution. Maybe you can put your heads together :)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugin recommendation" }
Delete post with all files attached to it On my site I have multiple authors, who can add/edit/delete custom posts and upload (attach) images to those posts. The problem is - when they delete their posts, attachments stay on the server. So, I would like to get rid of all files attached to the post when it gets deleted. Can anyone share and example how it's done?
WP does not do this by default since there is no guarantee that attachment isn't still being used by some other post. Basic logic would be to hook into `delete_post`, query for child attachments and run `wp_delete_attachment()` on each. I did quick search in plugin repository and came up with tiny plugin that does just that (seems unmaintained so test before use) - Post Data Delete Advanced.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 7, "tags": "posts, attachments" }
Completely disable editor How should I completely disable the visual _and_ html editor from pages? I know I can disable the visual editor in my profile, but I am trying to lock down the content input areas so that my client doesn't muck things up.
Why not use custom post types and don't add any support for the editor, that is afterall what they are for and the easiest way . The answer in this post covers how to do that, Hide content box with Custom Post Type? < To remove that functionality for pages or posts (and custom types) you can try and use `remove_post_type_support` . For pages; add_action('init', 'my_remove_editor_from_post_type'); function my_remove_editor_from_post_type() { remove_post_type_support( 'page', 'editor' ); } Ref: < A hacky solution is to use CSS `display:none;` for the `#editorcontainer` or one of the sub id or classes. You can also then enqueue that style only for particular users.
stackexchange-wordpress
{ "answer_score": 8, "question_score": 4, "tags": "editor" }
set_post_thumbnail_size in percent, not pixels? I've created a new custom post type and I need the post thumbnails or featured images generated by the `get_the_post_thumbnail()` function to be set in percent, rather than pixels, as I'm using a fluid grid. Ideally I would only set the width (to 100%). Is there a way to do this? Potentially using `add_image_size()`?
have you tried, if(has_post_thumbnail()) { $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'full' ); echo '<img src="' . $image_src[0] . '" width="100%" />'; }
stackexchange-wordpress
{ "answer_score": 11, "question_score": 4, "tags": "custom post types, images, post thumbnails" }
Make first letter of my taxonomy uppercase I'm using echo get_the_term_list( $post->ID, 'trpropcity', '', ' ', '' ); to show a taxonomy link, I'd like to make this instance of it only have the first letter capitalized, Cleveland not CLEVELAND, I realize I could just change the taxonomy, but I actually want it all caps everywhere else on the site, so I figured it would be best to just change it once. I've been playing with ucwords and strtolower but haven't had any success yet.
Build the links yourself: $terms = get_the_terms($post->ID, 'trpropcity'); if($terms) foreach($terms as $term) echo '<a href="'.get_term_link($term, 'trpropcity').'">'.ucwords(strtolower($term->name)).'</a>';
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "php, taxonomy" }
explode array within shortcode This functions at the moment but it only returns the first value from the array. I've been struggling to echo, print, explode, or whatever the multiple custom field values that share the same key (mp3). The shortcode is looking for comma-separated urls aka `tracks=" http:/url2.mp3"` I know i've created a bit of mess here. Wading into deeper waters... <div id="post_meta_player"> <? global $post; if(get_post_meta($post->ID, 'mp3', false)) { foreach(get_post_meta($post->ID, 'mp3', false) as $mp3) { $mytracks = print_r($mp3, ','); } } $shortcodes = '[mp3-jplayer tracks="'.$mytracks.'"]'; mp3j_put( $shortcodes); ?> </div>
Kind of confusing question, but I think you want: `[mp3-jplayer tracks="'.implode(', ', get_post_meta($post->ID, 'mp3', false)).'"]` Assuming you get a array of meta key values this will join the into a comma-separated string
stackexchange-wordpress
{ "answer_score": 3, "question_score": 5, "tags": "custom field, attachments, shortcode" }
Adjust which tempalte a page uses with a function? I know if I had a page that had a permalink such as `/stories/` then I could create a page in my template called `page-stores.php` and it would load in place of the default `page.php` when that page loaded (see Template Hierarchy) What I want to know is if I had that two page templates, maybe `page.php` and `page2.php`, if I could use the `functions.php` file to specify that if a page had a permalink of `/stories/` it would use `page2.php`? I know there is an option when editing a page to let the end user choose the page template, but in this case I would like to set it specifically.
This might work: add_filter('page_template', 'custom_page_template'); function custom_page_template($template){ // check your permalink here if(get_query_var('pagename') === 'stories') return locate_template(array('page2.php', 'page.php')); return $template; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "functions, templates, page template, permalinks" }
display all posts in wordpress admin Is there any reason why Wordpress restricts the amount of posts you can administer at once to 20? Is there a way to display all posts? I want to change the category for about 1800 posts. I don't have the ability to change the post amount under screen options; see here: tinyurl.com/3npm5yz Using WP v3.1.3
It doesn't, in the top right under screen options it says, **Show on screen** , you can set this to a max of 999 ( I have never tried 999 just fyi) and you can select all, then bulk actions--->edit--->apply. ![]( Also I think there are plugins that do this that use direct `wpdb` functions, so you can effectively do it to more posts at once.
stackexchange-wordpress
{ "answer_score": 17, "question_score": 8, "tags": "posts, admin" }
Is there a plugin that makes extnernal links open in new window, BUT Is there a plugin that makes external links open in new window, BUT only on the pages or domains or links I specify?
Simple Popup Plugin . this plugin helps to made external links open..WordPress Popup Scheduler
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "plugins, plugin recommendation" }
Can somebody tell me how I am supposed to be using blogs.dir for network / MU sites? I think `blogs.dir` is supposed to be used to separate content for the different blogs on a network install of Wordpress (MU or 3.0+ with networks enabled), however, I've not been able to find a clear guide to using it. Can someone shed some light and maybe post a few links to information on how to set it up, what to put in there, what the permissions should be set to, etc. ?
`blogs.dir` was the way to handle specific blog plugins and themes when it was WordPress-MU but since version 3 came out and the WordPress-MU was integrated into WordPress Core and introduced WordPress Multisite, that's no longer the story. WordPress Handles the creation of the new blogs/sites in the database and mainly in the background so you won't see too many things changing, but it also includes a new menu in the admin "Super Admin" !enter image description here which lets you handle the content for all sites in one place and they all site in one place. so basically WordPress handle this issue of `blogs.dir' for you.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "content, multisite, configuration" }
how to write short code in word press I am new in WordPress, I want to write short code with parameters in function. That is in add_shortcode('short code name','function name','parameter1,parameter2'); In `add_shortcode()`, I want to pass parameters and this must get in function used for creating short code. Here is the function function function name('parameter1','parameter2') { } how is it possible?
According to the WordPress documentation, "a minimal example of the PHP code required to create shortcode with attributes" is // [bartag foo="foo-value"] function bartag_func( $atts ) { extract( shortcode_atts( array( 'foo' => 'something', 'bar' => 'something else', ), $atts ) ); return "foo = {$foo}"; } add_shortcode( 'bartag', 'bartag_func' ); You can find more detailed information on creating shortcodes in the above referenced documentation.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "shortcode" }
Migrate posts into a different category I have about 1500 posts I want to change category for. Is there a quick way to do this in Wordpress Admin?
No quick way exists in the WordPress admin for 1500 posts, the better way would be to do it with MySQL directly either by custom queries and updated or by PhpMyAdmin and his friends.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "categories" }
wp E-commerce featured product plugin with muliple option? I'm Using E-commerce featured product plugin.in this plugin we have a options to select a single product from product list but not able to select multiple options at same time. * * * so any suggest to improve this plugin?
Check the plugin < its free and has many possibilities. <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugin development" }
2nd button row from WP Super Edit or TinyMCE Advanced doesn't show to 2nd admin I'm currently using WP Super Edit. But the same problem persists with TinyMCE Advanced. This is how it is configured: This is how I (admin) see it: This is how my friend (2nd admin) sees it: I'm getting desperate figuring out why the hell the 2nd button bar doesn't show.
Try click the " **show/hide kitchen sink** " button that looks like this: !enter image description here
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "posts, editor, tinymce, post editor, plugin tinymce" }
Debugging WP routing For some posts, I see 404 page, even though posts exist, where is the place in WP where using permalink is decided what object needs to rendered? Thanks!
Jan Fabry wrote a very useful plugin that I think it would be helpful for you to analyze your rewrite rules.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "posts, 404 error, routing" }
search serialised meta_value for date value? i've saved and array of 'open days' as a serialised array in a meta value. I was hoping i could then just search this field for the selected dates but i can't seem to create a match. serialised = a:2:{i:0;s:10:"2011-09-16";i:1;s:10:"2011-09-17";} ; // two open dates and was trying this and some variation without luck ; $values_serialized = serialize(array('2011-09-16')); // need to serialise??? $args = array ('meta_query' => array( array( 'key'=>'v-openDays', 'value'=>$values_serialized,'compare'=>'IN' ) ) ) // IN or LIKE? will also be searching for multiple days but need to get one working first! Help appreciated, Dc
Don't serialize the search value, just use `'value' => '2011-09-16' 'compare' => 'LIKE'`. Otherwise you're essentially looking for; a:1:{i:0;s:10:"2011-09-16"} Which of course doesn't actually match anywhere in; a:2:{i:0;s:10:"2011-09-16";i:1;s:10:"2011-09-17";}
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "wp query, post meta, array" }
is it possible to get next_post_link I have come across a problem whilst using the next_post_link() function. It seems that this function automatically echo's, for position reasons I need this to just return the link. Is there any available function or workaround that I can use to achieve this result?
try to work with < example: $next_post_link_url = get_permalink( get_adjacent_post(false,'',false)->ID ); $prev_post_link_url = get_permalink( get_adjacent_post(false,'',true)->ID );
stackexchange-wordpress
{ "answer_score": 21, "question_score": 10, "tags": "posts, next post link, previous post link" }
Is there a is_user_logged_in() for multisite? Is there a is_user_logged_in() function for Wordpress MU / Multisite (3.0+) where I can add in the network site ID like `is_user_logged_in(2)` where `2` would be the site_id? ### Update: After a little digging I came up with the code below. Unfortunately it does not work. //don't use this. does not work. function mu_logged_in($blog_id){ switch_to_blog($blog_id); $status = is_user_logged_in(); restore_current_blog(); return $status; } anu's answer and comments are good. also, make sure you have the cookie domain set correctly in the wp-config.php file :)
Yes, and no! The way users work in a multisite scenario is that there is a single pool of users, who are then associated with blogs. So, logged in status is common across all the blogs, but you can use `is_blog_user($blog_id)` to determine whether the **current logged in user** is a member of that blog. An example: if (is_user_logged_in()) { if (is_blog_user(4)) echo "Current user is a member of blog 4"; } Codex page for `is_blog_user()`
stackexchange-wordpress
{ "answer_score": 10, "question_score": 11, "tags": "multisite, functions, users, login" }
WordPress Widget multiple use I created this widget using a simple example on WordPress Codex: <?php function widget_container_latest_posts() { global $wpdb; global $post; get_template_part( '/includes/containers/container-latest-posts' ); } wp_register_sidebar_widget( 'widget_container_latest_posts_1', 'Container Latest Posts', 'widget_container_latest_posts', array( 'description' => 'Container Latest Posts - Adds recent posts.' ) ); ?> It works fine, but I want this widget to be used multiple times not only one time after I drag it on a sidebar widgets place, and so I can add it on all the other sidebars for example. Thank
You need to implement your Widget using the Widgets API, so that WordPress knows how to make multiple instances of the Widget. Your Widget declaration should take the following format: class My_Widget extends WP_Widget { function My_Widget() { // widget actual processes } function form($instance) { // outputs the options form on admin } function update($new_instance, $old_instance) { // processes widget options to be saved } function widget($args, $instance) { // outputs the content of the widget } } register_widget('My_Widget');
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "widgets, sidebar" }
Find page IDs with specific meta tag key value pairs Is there a way to find the ids of the pages who contain meta tags/custom fields with a certain key-value pair? Say, for instance, that I wanted to find all of the pages who had a meta-tag/custom-field key of "weather" with a value of "raining", is there a way to do that?
Why not? Same custom field parameters in query should apply and you can use `post_type` argument to limit query to pages alone.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom field" }
What is the significance of _e("Some String", 'String')? I have seen this in lots of wordpress themes and using it for a while but don't know what is the significance of it. It seems it does the same work as echo something out. Look for it in codex but failed to find anything about it. May be i have looked in wrong place. So, my question is what does `_e("Some String", 'String');` means? And is it different from `echo "Some String";` ?
it's for localisation/translation WPEngineer Has a great writeup on how it all works....
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "codex" }
Loading different stylesheet on Wordpress pages? I have one stylesheet linked to my Wordpress page in header section: <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/style.css" /> Now, I want to load different stylesheets on a few pages or sub-pages. What's the best/correct way of achieving this? I'm thinking about writing my own shortcode calling "wp_enqueue_style", is that a good idea?
Don't use a shortcode for `wp_enqueue_style()`; it won't do any good, because by the time the shortcode is parsed, all the relevant hooks ( `wp_head`, `wp_print_styles`) will have already fired. Write a function, in `functions.php`, to enqueue different style sheets based on `is_page( $id )` (where `$id` can be an ID, slug, or title). Then hook that function into `wp_enqueue_scripts`. p.s. note also: you should be using `get_stylesheet_uri()` in your default stylesheet link, e.g.: <link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_uri(); ?>/style.css" />
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "css, wp enqueue style" }
Plugin Expires Headers - W3 Total Cache Using the Google PageSpeed Online, it looks like the CSS/Images/JS files of most of my plugins (including wp-nivo-slider) do not get their expires-headers set. Is there a solution for this so that W3 Total Cache will set the expires headers on all the media on my page?
Make sure your hosting provider offer `mod_expires`. Because many shared hosting providers doesn't offer `mod_expires` . Just contact your hosting support.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "plugins, cache, plugin w3 total cache" }
Is Wordpress fast enough for a heavy traffic project? I was always a WP guy, built many small sites with it. I will create a new community with a big fanbase and I was wondering if 3.1.3 is fast enough? I didnt have the opportunity to work with it since 3.0. How does it react with heavy traffic web sites? Is it something that will make me worry enough to search for a lighter CMS or should I rely on it even with hundreds of visitors per day? I know about the tricks/tips to make it feels faster but is it by default ?
I don't think there is **any** considerably advanced CMS that you can throw high traffic at and expect it to handle it without any configuration effort. Can WP be used for high-traffic site? Of course and it is being used as such by many sites. But it should be WP on decent hosting and well-configured software stack, rather than WP on cheap shared hosting with Apache defaults and no caching whatsoever.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 3, "tags": "performance" }
How to enable all Tag Descriptions in loop? As the title states all I'm trying to do is get the descriptions for all tags inside the loop on my INDEX.php page to show up. I know you can use code to call specific tag descriptions but I want to avoid that if possible since I'll have hundreds of tags all of which I want to show descriptions for. Is there a way to modify the `get_tags` tag in the loop to display descriptions following each tag?
_Modified from the`get_tags()` Codex Example_ $tags = get_the_tags(); // for the specific post // $tags = get_tags(); // all tags $html = '<div class="post_tags">'; foreach ( $tags as $tag ) { $tag_link = get_tag_link( $tag->term_id ); $html .= "Describtion for ".ucfirst( strtolower( $tag->name ) ).": $tag->description"; $html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>{$tag->name}</a>"; } $html .= '</div>'; echo $html;
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "tags" }
Is wordpress big enough for my project I have a site some having job postings running using jobber base. Now I am going to shift it in WP using jobroller theme that is of 99 USD. I am a developer who always like MVC rather than these CMS. I was thinking of doing it in Yii. But now I came to know about job roller. So I have 2 questions. Is jobroller worth 99 USD and will it work for my product? Can WP handle this if I want to do changes every week. As I told earlier, I am also a developer. So I will be doing changes in it but I doubt that I will not be able to do this in such friendly way as it can be easily done in an MVC framework. I am always in favor of OOP and MVC. But I actually don't have much time to develop my own. So guys please advise me that should I spend some more time and do it in MVC once or I should once continue with WP? Can any one tell me about big sites that are developed in WP?
**_About OOP Themes)_** There are dozens of Theme- & Plugin-"Frameworks" out there. And some are OOP. **_About custom coding)_** You could also try libraries like WP Alchemy for meta boxes and custom content. "Rilwis" offers another one. Then you could use some front end code to insert stuff into Custom Post types. **_About "Jobroller")_** You should post/ask your Q about "Jobroller" in detail at their page. Furthermore is it hard to know if it's a) commercial and b) you didn't explain your needs in detail. **_About WP & Performance)_** Take a look at this Q for a more in depth look.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 0, "tags": "themes, plugin recommendation, theme recommendation" }
Nothing Found for Index Php Error I moved my word press blog from Apache to IIS 7 shared hosting. my database connection is fine. I can access the admin module but I get an empty index.php with "Nothing Found for Index Php Error" in the title bar. Can someone please help.
Start by going to _Settings>Permalinks_ , now click on the default radio button and click save. You probably used .htaccess to enable pretty permalinks, IIS doesn't use an .htaccess file. If the default structure fixed the problems you are having, but you want the old permalink structure, click this link to the WP-Codex page explaining how: Link to Codex Page _(about half way down)_.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "iis" }
admin : search custom fields One year ago @t31os answered a post with a code I can't access: < His answer... I was feeling adventurous, so i wrote a simple plugin to do it.. < The post search in the admin will now also check against the meta keys and meta values when checking for matching posts... ;) Is there a way to get that code so I can use it? Thank you very much Patricia
Don't know what's wrong with that link but you can see an answer to a similar question how to filter post listing (in WP dashboard posts listing) using a custom field (search functionality) ? Its just what you are looking for.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "admin, search" }
How can i customize the comment list I am using **wp_list_comments()** function to draw the comment list.But,I want change many things in the form like class,styles, reply link and etc... so please help me, How can i customize the comment listing function Thanks
The `wp_list_comments()` call accepts a _callback_ argument, in which you can define the _specifc_ comment-list markup that you want. I would suggest taking a look at how TwentyTen handles the `wp_list_comments()` callback.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "theme development, customization, comment form" }
How can I rename the element <dc:creator> to <author> in my RSS? I need to change the author element of the feed from dc:creator to author. How does this is possible?
Bearing in mind my comment about, you can use the `rss_item` hook to add a filter that will let you add the `<author>`element to your feed function add_author_to_feed($feed) { $feed .= '<author>' . the_author_meta('user_email') . '</author>'; return $feed } add_filter('rss_item', 'add_author_to_feed'); (note - this code is not tested)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "feed" }
how to get list of post formats supported by theme? After adding support for a selection of post formats like this: add_theme_support( 'post-formats', array( 'aside', 'video' ) ); how can I then get the list of supported post formats back? I'm building a theme where the user can toggle support for postformat, and I want other admin elements to reflect what post formats the user has configured the theme to support. so I'm looking for something like current_theme_supports( 'post-formats'); // outputs boolean but that outputs just true or false, whereas I want to get an array of the post formats actually registered.. what would be the correct WordPress function to call (or constant/global var) to look at for this? I want something like this: get_supported_post_formats(); // out: array('aside', 'video')
Taken from `post_format_meta_box`; if ( current_theme_supports( 'post-formats' ) ) { $post_formats = get_theme_support( 'post-formats' ); if ( is_array( $post_formats[0] ) ) { print_r( $post_formats[0] ); // Array( supported_format_1, supported_format_2 ... ) } }
stackexchange-wordpress
{ "answer_score": 5, "question_score": 0, "tags": "post formats" }
How can HTML be allowed in Author Bio? Is there a way to prevent WP from stripping the HTML from the author bio? I need it to keep my paragraphs. Thanks in advance! :) Edit - Although this question has been answered, I will clarify that I was referring to the Bio textarea when editing individual users.
remove the filter that formats the description. put this in your theme's functions.php: remove_filter('pre_user_description', 'wp_filter_kses'); EDIT - I should mention, if you allow random people to register and add their own bio for display on the site, not filtering that text could enable bad things.
stackexchange-wordpress
{ "answer_score": 12, "question_score": 11, "tags": "author, html" }
Calling Permalinks With PHP I'm developing a theme which supports WordPress' post formats. As a result I am using a big if statement, which can be found below. * I would like to link my post titles to the posts while maintaining my theme as XHTML valid. * I would like to call images (with classes) in the if statement while maintaining my theme as XHTML valid. * I would appreciate if somebody could add the appropriate code to the following code to do so _ if ( has_post_format( 'video' )) { echo the_title(); echo the_excerpt(); } **EDIT: Basically, the most important thing I'm looking for is that it calls the post name as a link which links to the actual post.**
I don't know what you mean by "call images", but this will display the title as a link. if ( has_post_format( 'video' )) { ?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><?php the_excerpt(); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, excerpt" }
Alternative to query_posts for main loop? > **Possible Duplicate:** > When to use WP_query(), query_posts() and pre_get_posts I just noticed today that the documentation for query_posts() mentions some "disadvantages" of using query_posts for altering the main Loop, notably: 'causes additional SQL queries'. This seems to imply that there's another way / a better way. Obviously there's get_posts() and WP_Query for secondary loops, but I don't see them as addressing the "disadvantages" listed in the Codex documentation. I can see that by waiting until you're in the template to run query_posts, WordPress has already run a query once and this is now a second query that clobbers the first one (the first one being basically ignored). This definitely DOES sound inefficient (though perhaps not a big deal, who knows?) My question is: is there an alternative to query_posts that does NOT add "additional SQL queries" or is the Codex documentation simply deceiving?
When I added the drawbacks to the Codex, I was mainly thinking of using the 'request' filter as an alternative to query_posts(). That filter is only run for the main query, so that solves the problem with 'pre_get_posts', which fires for every query. The downside is that you don't have access to query flags like is_single() etc. Here's one way you could get access to them, without actually doing the SQL queries: function alter_the_query( $request ) { $dummy_query = new WP_Query(); // the query isn't run if we don't pass any query vars $dummy_query->parse_query( $request ); // this is the actual manipulation; do whatever you need here if ( $dummy_query->is_home() ) $request['category_name'] = 'news'; return $request; } add_filter( 'request', 'alter_the_query' );
stackexchange-wordpress
{ "answer_score": 20, "question_score": 15, "tags": "query posts, codex, documentation" }
How to retrieve sticky post in raw sql? How I could made a sql query who retrieve all the sticky post in a wordpress database? This is because we use a new app over the old wordpress website database, and I don't know where Wordpress "store" the sticky attribute. Thanks in advance
It's not stored as attribute, but as list of all stickies. Snippet from core: $sticky_posts = get_option('sticky_posts'); So look for the option and then use IDs to retrieve posts.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "sql, sticky post" }
Which is the simplest theme for Wordpress to use it as your base? I am building a new theme for my site, and I was wondering which is the simplest/lite theme with only the files needed like single.php index.php author.php and so on. I have read about wordpress themes and what files I have to include but I will have to code the default functions like wp-comments if I start from here. So I am looking for a lite theme to start over.
asked a few times, this link has some good answers Opinions and recommendations on the best barebones base theme
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme development, themes" }
how to show posts that are missing a meta_value How can I build a query to find posts that DO NOT contain a certain meta key or meta value? for example: query_posts( array( 'meta_query' => array( array( 'key' => 'feature', 'value' => '_wp_zero_value', 'compare' => '!=' ) ) ) );
Getting posts without a certain meta _key_ is a little tricky, namely due to the database design and the nature of SQL joins. AFAIK, the most efficient way would be to actually grab the post IDs that _do_ have the meta key, and then exclude them from your query. // get all post IDs that *have* 'meta_key' with a non-empty value $posts = $wpdb->get_col( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'my_key' AND meta_value != ''" ); // get all posts *excluding* the ones we just found query_posts( array( 'post__not_in' => $posts ) );
stackexchange-wordpress
{ "answer_score": 9, "question_score": 8, "tags": "wp query, meta query" }
When you create a custom post type, does that also create capabilities for editing/deleting that post type automatically? For example, if I create a post type called "destinations" does that automatically create capabilities like "edit_destinations" or "delete_destinations"?
It does not automatically create that capability in the sense that there is no new capability registered with WordPress. Instead it defaults to use the capabilities assigned to creating/editing posts. For example, if an author logs in they will be able to create and publish a new destination entry by default. You can override this with the `capabilities` value when using `register_post_type`. See Justin Tadlock's excellent tutorial here <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "custom post types, capabilities" }
Creating a path in a plugin to call a function Okay, let's assume that I want to create a dynamic "printable" page using a system that doesn't play well with wordpress's theming engine, is there a way for me to define a "permalink" in my plugin that will call a predefined function, also in my plugin? If you're familiar with Drupal it's similar to how their hook_menu works, but I only need it on a very limited basis, so it doesn't have to be that robust.
Something along the lines of this would probably do it: function wpse21372_init(){ add_rewrite_rule( 'your-page-regex/?$', 'index.php?wpse21372=1', 'top' ); add_rewrite_tag( '%wpse21372%', '([^&]+)' ); } add_action( 'wp', 'wpse21372_wp' ); function wpse21372_wp( $wp ){ if( isset( $wp->query_vars['wpse21372'] ) && !empty( $wp->query_vars['wpse21372'] ) ){ //You're on your custom page. //you may want to exit page //execution when you're done //so the rest of WordPress' //normal execution doesn't take //over from here. } } After you're done adding that code, make sure you flush the rewrite rules by going to Settings -> Permalinks.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "plugin development, permalinks" }
Associate custom post types with normal posts I have a custom post type, called App. This has details like the name, description, thumbnail image, and some custom fields. Then I have posts about this app, that I'd like to associate with it. In the end, I'd like to be able to view the custom post type and all the posts that are associated with it. But I don't see any way to associate a post with anything besides a category or tag. But categories and tags don't allow for custom fields, images, etc. Is the only way to create a category with the same name as the custom post type, and then do something like have a custom field in that custom post type that has the ID of that category? Thanks!
No you don't really have to create a category to associate your different post types. You can use this great Post 2 Post plugin by scribu. It does exactly what you are trying to do.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "custom post types, custom taxonomy" }
How to display both home.php and index.php Hey guys i recently created a theme. I want to show home.php when a visitor visit home page but all my blog posts are listed in index.php file. Can someone suggest me how to display index.php i tried < but it redirecting me to < Please advise me. Thanks
I don't think you fully understand the meaning of templates in WordPress. You do not choose template by including it in URL, WordPress deals with choosing template by making sense of URL request. See Template Hierarchy in Codex.
stackexchange-wordpress
{ "answer_score": 2, "question_score": -3, "tags": "homepage" }
How to update post taxonomies (Creating a custom UI for Custom Taxonomy) I have a taxonomy eg. authors. I want to create a custom UI for. I think integrating with a Meta Box together with other post meta will make things easier for the user. Also I think a jQuery UI AutoComplete (Multiple comma separated values) is more appropriate So I will need to know how I can "update_post_taxonomy". I suppose I will need to * if taxonomy does not exists * create it * if post does not have the taxonomy term * add it * remove terms that are not specified by user I am sure there are functions for this?
The function you are looking for is **`wp_set_post_terms()`** which can create the terms if they don't exists and you can specify if to appended or replace existing terms. so you can remove all none user terms. as for > if post does not have the taxonomy term , add it you can use **`wp_get_post_terms()`** to check if the post has any terms of that taxonomy and if not then you can create and add using `wp_set_post_terms()` once again
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom taxonomy" }
Absolute path to stylesheet_dir/images/my_img.jpg does not work? I am manipulating an img element in functions.php using jQuery by changing the src attr on hover. How do I make so the absolute path works? Currently, when I view the image directly in the browser it brings me to 404 page. Relative path doesn't work either.
i always start every theme w/ some constants ` define('THEME', get_bloginfo('stylesheet_directory')); //or you could use this one: //define('THEME', get_stylesheet_directory_uri()); define('IMAGES', THEME . '/images'); ` and some others, but the point is that at any place in my code i can point to my theme's image folder ` img src = "<?php echo IMAGES . '/image.png';?>" `
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "jquery, images" }
The revisions table in my database is at 70% capacity and growing. What should I do? I installed the Wordpress System Health Plugin and it says that the revisions table in my database is at 70% capacity with 994 rows. I don't fully understand what this means. I anticipate that my site will get much larger than it is today. Questions * Am I going to run into trouble or is there some way I can increase that table's capacity? * Is it a hosting issue? One proactive thing I have done is set a max number of post revisions to 4. Any solution or an explanation to help me understand what's going on would be really appreciated. Thanks for your help.
SQL query to run via phpmyadmin DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision' That query will remove all post revisions from your wp database,, **But remember always back up your database before running any direct SQL query..** you can also add a line into wp_config.php that will disable revisions (optional, i use it as i find revisions a bit of a pain) `define('WP_POST_REVISIONS', false);`
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "database" }
Why isn't is_page working when I put it in the functions.php file? I have page called "Apple", the page's ID id 2533. In page.php file I have line: echo $bannerimg And this function in functions.php: if ( is_page( '2533' ) ) { // also tested with 'Apple' $bannerimg = 'apple.jpg'; } elseif ( is_page( 'test' ) ) { $bannerimg = 'test.jpg'; } elseif ( is_page( 'admissions' ) ) { $bannerimg = 'admissions.jpg'; } else { $bannerimg = 'home.jpg'; } The point is the $bannerimg echoes "home.jpg" on every page, including Apple, test and admissions. I've even checked all the IDs using the_ID & $page->ID. Nothing. So I guess there's something wrong with the code above?
`functions.php` is processed way before you can know which page is being loaded. Instead of assigning value to variable put your code into function and use that function in `page.php` template.
stackexchange-wordpress
{ "answer_score": 17, "question_score": 15, "tags": "functions, pages, conditional content" }
how can i use custom field in query post I want to get all featured items using query post. featured is meta_key using custom field plugin. I tried bellow,but it failed $featured_item = new WP_Query('posts_per_page=-1&cat=3&meta_key=>Featured List&meta_value=>Yes'); my wp version is 3.1.3 **EDIT:** $arg2 = array( 'posts_per_page'=>'5', 'cat'=>'3', 'orderby'=>'rand', 'meta_query'=> array( 'key'=>'Featured List', 'value'=>'Yes', 'compare'=>'LIKE' ) ); $featured_random_item = new WP_Query($arg2); This query also failed. How can i do this Thanks in advance !
Your `meta_query` needs to be a _nested_ array, like so; $args = array( 'posts_per_page' => '5', 'cat' => '3', 'orderby' => 'rand', 'meta_query' => array( array( 'key' => 'Featured List', 'value' => 'Yes' ) ) ); And I get the feeling you don't actually need a `LIKE` match - this'll perform a loose comparison, and isn't as efficient as an exact match.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom field, query posts" }
How to control what jQuery version to include, with wp_enqueue_script I'm using a script that is based on jQuery, so I'm not enqueue-ing jQuery directly, but via passing it in the array of dependent scripts: wp_enqueue_script("jquery-plugin-name",' array('jquery'), '1'); This is loading jQuery v1.4.4, and it weighs 76kb, which seems very heavy, although the file looks compressed. I have 2 questions: 1. Is there I way in which I can make it load the latest version of jQuery? 2. How can I make sure that the loaded file if minified?
That's the size of the minified jQuery nowadays :) You can load the latest from Google: wp_deregister_script('jquery'); wp_register_script('jquery', (" false, '1.8.2'); Please keep in mind that this can cause issues moving forward, as you are forcing WordPress to load a certain version of jQuery instead of the version bundled with it. There are plugins out there that may be better suited for your needs, like WP JQuery Plus, which make sure to load the same version number as WordPress does, but with the benefit of loading it from Google.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 6, "tags": "jquery, wp enqueue script" }
Alter required message using comment form api I prefer not to use asterisk markers on required fields in the comment form. So I'd like to remove or alter the 'required fields are marked (*)' message. Being a good wordpress user, I'd like to do it with my functions.php. I can work out how to filter most areas of the form, but not this. I'm guessing it will involve modifying the 'comment-notes-before' field of the 'defaults' array, but I can't quite see how to do that.
What you need to use is `comment_form_defaults` filter that has large and nested `$defaults` array passed. That array will have (among other things) something like this in it: fields author << this will have something like <span class="required">*</span> in it email << this will have something like <span class="required">*</span> in it url comment_notes_before << this will have something like Required fields are marked<span class="required">*</span> in it So in your filter you need to change these fields in array you got passed and return whole array.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "php, functions, comments, filters, array" }
tag search using WP_Query I need to find only posts with a tag `forest gump`. I've tried: `new WP_Query('tag=forest+gump');`, `new WP_Query('tag=forest gump');`. However they both return ALL the posts and not only the posts with `forest gump` tag. Single tags (without spaces) work fine, though. Alternatives (like plain SQL) will work as well. The entry tag line is `forest gump, forrest gump, questend`.
new WP_Query(array('tag_slug__in' => array('forrest-gump', 'forest-gump', 'questend'))); `new WP_Query('tag=forrest+gump,forest+gump,questend');` should work too...
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "php, tags, mysql" }
What action hook updates post meta? Is there an straight-forward example anywhere of using wp_update_post() to edit post_meta on the front end? I have not been able to find any good learning resources. What I want to do is display post meta in an input field and when a user clicks _submit_ trigger `wp_update_post();`. !post meta in input field with save button Thanks!
`wp_update_post` isn't used for updating custom fields (ie postmeta content) - you should use `update_post_meta`
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "post meta, wp update post" }
How to send data to sidebar? I have a sql database of historical events, I would like it to post data into the sidebar area of a wordpress site. As I am very new to it I do not have any idea how to proceed. I would be thankful if anyone could help me out. Thanks in advance
You can edit the `sidebar.php` (or any `sidebar-xxx.php` file, depends on your theme) and interface with your database using the wpdb class. If your historical events are in the same DB as wordpress you can use the wpdb class straight away, if they are in another DB you can instanciate a new wpdb class with : $my_db = new wpdb('user','pass','dbname','host');
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "sidebar" }
google xml sitemap won't work on directory install I have installed wordpress in directory above the root called "wp". I'm having issues with the google xml sitemap generator. I cannot rebuild the xml code and write it the sitemap.xml file. I have been on the phone with my hosting company and they assure me the file does have full control for its file permissions. Does anyone have any advice for this?
Hate to self promote BUT ;) My WordPress SEO plugin actually fixes this by not generating a static file at all. It works in all circumstances.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "directory, installation, google xml sitemaps" }
How do I change the upload file size limit in single-site wordpress install? In the multi-site wordpress install, you get a very nice "upload settings" in the network admin settings. (see attached image). I am trying to change these settings without using php.ini for a single-site wordpress install and I can't find them anywhere... help? Tim Attached: Network Admin Settings Example: !Network admin example
create an file `php.ini` and copy via ftp or ssh to wp-admin; inside this file the follow values; play with values for test and see the result. memory_limit = 32M upload_max_filesize = 32M post_max_size = 32M file_uploads = On
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "wp admin, media, uploads, network admin" }
Why does the HTML editor not wrap my code in paragraph tags when I press enter Normally when using a rich text editor, when you hit return (i.e. do a full paragraph return) Your text is wrapped i.e. `<p> my text </p>` however this does not happen in wordpress. Is there any way to trigger this functionality?
This happens at the time the content is output the browser. At that point, the content is passed through several filters, one of which is called `wpautop`. This filter function is defined in `wp-includes/formatting.php`. In combination with the other default WordPress filters, this generally means that you can compose content in the HTML (non-wysiwyg) editor as if you were writing plain text, and it will format the final HTML output in a logical, intuitive manner. On the other hand, you can also feel free to manually compose HTML tags in your output, and WP will preserve your tags. There are some edge-cases that can get you sometimes (using non-standard tags or attributes), but for the most part, the editor and the filters are pretty smart.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "html, visual editor" }
How to wrap every image in a post with a div? When I add an image to a post I want it to be in a div e.g. , and I want that to be done automatically, so I don't have to do that in HTML editor. I don't want to use js to accomplish this and by the way I want to know how to automatically add custom classes to a image in a post. Cheers!
By default images already have unique class's but this depends on your theme. Use firebug and hover over the images and you should see stuff like `class="aligncenter size-full wp-image-1525"`. If you want to change the class or id or alter any attributes of the image you can use the `get_image_tag` filter. For example, add_filter('get_image_tag_class','my_custom_class'); function my_custom_class($class){ $class='my_custom_name'; return $class; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "posts, customization, html, images" }
What's the safest way to switch and restore a post global? I need to switch WordPress's post context, sort of like `switch_to_blog()` but for posts. What's the safest way to alter WordPress's global state and switch it back?
Use `setup_postdata()` to change and `wp_reset_postdata()` to roll back to original.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "posts, globals" }
SELECT field options disappear when saving widget I'm having an interesting problem that I can't seem to solve. While creating a widget, I have created a select field with options that can be chosen on the widget screen. It all works perfectly fine, except when I save the widget, all of the options in the select field vanish. They all come back, with my chosen option saved, as soon as I refresh. The code for each of the select options looks like this: `foreach ($posttypes as $option) { echo '<option id="' . $option->name . '"', $posttype == $option->name ? ' selected="selected"' : '', '>', $option->name, '</option>'; } ` In this case, $posttypes is an array of post types. When the select fields are rendered, they look like this: `<select name="option-name" id="option-name"> <option value="option-value">Option Value</option> <option value="option-value">Option Value</option> <option value="option-value">Option Value</option> </select>` Any ideas why they would vanish like this?
Found it. There was an extra closing slash on the opening select field.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "widgets, options, select, customization" }
Second Level Menu I'm trying to figure out how to do, Second Level Menu as a template function, that persistent when visiting any level, whether its a top level page, or a grand children Page. Any Ideas?
example: <?php //get top level page ID; $top = ( $post->post_parent ) ? array_pop(get_post_ancestors($post->ID)) : $post->ID; echo '<ul>'; wp_list_pages('title_li=&child_of='.$top.'&depth=1'); echo '</ul>'; ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "menus, template tags" }
Add custom fields within meta box class "on the fly" I'm one of the contributors for the Meta Box Class here on Github (link) and before I get too deep, I wanted to ask if anyone knew of a straight forward way to allow users to add additional fields "on the fly", having an "add" button with a text field to add additional fields (i.e. list items). I've seen this done a few ways in the past, but I'm all for not reinventing the wheel.
Agreed, I've seen it too, but I don't think there's any readily available API or method. For me, I use a lick of jQuery; <input type="text" class="list-item" name="list_items[]" /> <input type="button" class="button-secondary" id="add-list" /> <script type="text/javascript"> ( function( $ ) { $( '#add-list' ).click( function() { var $item = $( '.list-item:last' ), $new = $item.clone(); $item.after( $new.val( '' ) ); } })( jQuery ); </script> Note that you might wanna tweak those selectors if you plan on having multiple 'instances' of these.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 5, "tags": "post editor, custom field, metabox" }
Use of Javascript with Dojo/Dijit on a WordPress page I just created a web page that uses a lot of JavaScript to build a fancy form that helps build an build the object/html behind an mp3 player for a user. I got it working and tested in a plain-html page outside of WordPress. I then copied into a WordPress "page", took out the <head> tag, changed <body> to a <div>, but no luck. Can it even be done? I also want to use a small javascript to open up a video-player in a new small browser-window. Working on raw html page: < Not working in WP page: <
You'd be much better off creating a custom page template, pasting your HTML into the file, then simply attaching the template to a page in the admin. WordPress applies a lot of filtering on post/page _content_ , and it's probably wreaking havoc with your code (not to mention you've got things there that belong in the `<head />`). **UPDATE:** Create a PHP file in your theme folder (name it template-something.php); <?php /* Template Name: My Template Something */ ?> <!-- any PHP & HTML goes here!! --> <!-- Note: Should be a complete HTML document if not calling get_header() -->
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "javascript" }
how to get context information inside my funcion What processing is done by wordpress when a page is accessed that loads all contextual information into $post and other variables? and is it possible to trigger this process manually (or simulate it) so function calls have this context? The reason I'm asking is because I have written a small plugin that allows users to call wordpress functions via Ajax. The plugin works great with context-less functions. It has a big limitation however: calling a function via ajax loses the context information (e.g. $post) that the called function would otherwise have, had it been placed from within a template. However, the ajax call does send across the HTTP Referrer information. I can easily extract the referrer info, so I know e.g. on which page the user is on. The problem is I'm not sure how to use it further. Any tips/ideas would be greatly appreciated.
* you're requesting _index.php_ which I guess it's the homepage; if I call for example is_category() trough your ajax from the category page I'll get false because the function is being ran on the homepage. Use `$_SERVER["REQUEST_URI"]` instead (don't forget to sanitize it) * you're hooking your handler on the `init` action, which I think runs before the post data is set up. Use a different one, like `wp` or `template_redirect`
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugin development, functions, ajax" }
Option to show/hide widget depending on is_home? Is it possible to add a checkbox to all widgets loaded into sidebars? For example, I'd like to allow the site owner to choose whether any widget should appear on the home page, inside pages, both or neither. I'm thinking a checkbox interface appended to the widget control interface. Has anyone done something like this and what level of complexity are we talking?
There are plugins that can do this like Widget Context or Widget Logic. If you want your own solution then it's pretty easy: * hook your function with the checkbox on `in_widget_form` * hook your widget update function `widget_update_callback` (update the widget option) * check if the option was checked using the `widget_display_callback` hook (return false if it is) Post what you have so far if you need sample code. I've implemented a feature like this in one of my themes...
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme development, widgets" }
Displaying NextGen Gallery using value from meta not working When a user creates a new post there is a meta field on the back end where they can enter the id of the nextgen gallery to display. I want to then display in their post the gallery which corresponds to the id they entered. When I run the code below $meta echoes as #3 and the gallery shows, so I know that for this post rw_propGallery is set to 3, and that three is the id of an existing gallery. $meta = get_post_meta(get_the_ID(), 'rw_propGallery', true); echo $meta; echo do_shortcode('[nggallery id=3]') But if I switch it to echo do_shortcode('[nggallery id=$meta]') I get the number 3, and "Gallery not found". Any suggestions?
Perhaps try: echo do_shortcode('[nggallery id=' . $meta . ']');
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "php, plugin nextgen gallery" }
Wordpress Shortcode wrap around div Is there a way to wrap a wordpress shortcode around a div in a template file? Here is my code: <div id="subscription"> <?php do_shortcode('[subscribe]');?> <p>This is subscription text</p> </div> I've also tried <div id="subscription"> <?php do_shortcode('[subscribe]');?> <p>This is subscription text</p> <?php do_shortcode('[/subscribe]');?> </div>
If by template file you mean a php file in the themes folder, you can call do_shortcode to have the shortcode processor do its magic on your div. EDIT: not entirely sure I understand what you want, but you could try this: <div id="subscription"> <?php do_shortcode('[subscribe]'.call_php_function().'[/subscribe]');?> </div>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "templates, shortcode" }
Query custom type posts by array of IDs I can't seem to get `post__in` to work with custom post types. Is this true? What's the alternative? $args = array('post_type' => array( 'post', 'page', 'tf_events', 'duka' ), 'orderby' => 'menu_order', 'showposts' => -1, 'post__in' => explode(',',$mtheme_featured) ); query_posts($args); `$mtheme_featured` has two ids separated by commas, one post and one tf_event; only the post is shown.
You said the post type is called 'tf_event', but in the 'post_type' array it's 'tf_events'.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, query posts" }
How to make category RSS feeds show full content I'm trying to fix a friend's feed to show full content in the category feed instead of only a summary. He's already done the setting bit, but it still doesn't seem to work. Thoughts? EDIT: The feed in question is <
Full Text Feed plugin shows full content....follow the installation steps there,and then goto settings->Reading->For each article in a feed, show=>select Full text and save.it'll work.if you want to implement via the code means, <?php if (get_option('rss_use_excerpt')) : ?> <description><![CDATA[<?php the_excerpt_rss() ?>]]></description> <?php else : ?> <description><![CDATA[<?php the_excerpt_rss() ?>]]></description> <?php if ( strlen( $post->post_content ) > 0 ) : ?> <content:encoded><![CDATA[<?php the_content() ?>]]></content:encoded> <?php else : ?> <content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded> <?php endif; ?> <?php endif; ?>
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "categories, feed, multisite" }
Customizing wordpress default widgets? Is there anyway to customize the default WordPress widgets or do i need to create my own? For example, I want my recent post widgets to display date aswell. Thanks in advance! /Richard
You'll have to create your own but you can copy the code and customize from /wp-includes/default-widgets.php If you edit the defaults they'll screw up when you update WP.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "widgets, date, recent posts" }
Wordpress plugin for activating other plugins Hi iam developing a plugin to activated a couple of plugins. i.e: the plugin jetpack has six plugins and all gets activated on a single install,like wise i need to activate a group of plugins from acivating this plugin. for example consider a plugin called 'site plugin' which has sub folders of other plugins. when i activate 'site plugin' it should show options to activate other plugins in it. I hope some one could help me.
You're main pluggin can use register_activation_hook and use the function you register thru the hook to activate you're necesary pluggins. Smth along these lines : // get already activated plugins $plugins = get_option('active_plugins'); $puginsToActiv = array('Plugin1', 'Plugin2', 'Plugin3'); if($plugins) { $changed = false; foreach ($puginsTostActiv as $plugin) { if (!in_array($plugin, $plugins)) { $changed = true; array_push($plugins,$plugin); } } if ( $changed ) update_option('active_plugins',$plugins); } // code not tested
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugins, plugin development" }
WPML : how to pick a featured image only once for different languages? I've got 3 languages on my site. Picking the same featured image 3 times for the 3 versions of each article is boring. Is there any way to do it only once ? (same for picking a tag)
You'll find the answer here : <
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "attachments, multi language, plugin wpml" }
If Statement Post Formats: No post format selected I'm working with post formats, most of my code looks similar to this: if ( has_post_format( 'standard' )) { echo '<?php get_sidebar(); ?>'; } if ( has_post_format( 'aside' )) { echo 'this is an aside'; } if ( has_post_format( 'chat' )) { echo 'this is the video format'; } But I also want one of the if statements to include how to call it if the user **did not** select a post format. Anybody know?
use `get_post_format`: $format = get_post_format(); if ( false === $format ) echo "no post format"; EDIT - an example using a switch statement: $format = get_post_format(); switch( $format ){ case "aside": echo "aside"; break; case "chat": echo "chat"; break; default: echo "standard"; }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "php" }
Global site feed plugin/function for custom post type? Is there a well-coded plugin or function that will enable me to create a global feed for only one post type in a multisite setup?
Perhaps you might be able to achieve your goal by combining the feeds of the posts you are interested and create a new feed this way? That's what I did for a multisite setup. In this setup I created a page template which would load the rss feed which I created using Simple Pie (to combine all rss feeds into one cached feed).
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "multisite, feed" }
What is your take: TimThumb vs. WordPress Thumbnails? The great debate When it comes to excerpts, do you believe TimThumb or WordPress thumbnails is the way to go? And why? Answers will not be graded (but may be criticized).
In my opinion the built in `<?php add_image_size( $name, $width, $height, $crop ); ?>` function is much more flexible, easy and with less overhead. It does resize-crop, so I don't see a reason to go back to TimThumb (which I used extensively in the past).
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "post thumbnails, timthumb" }
Editing Complex Pages in Visual Mode This might be a stupid question, and maybe I've missed some best practices thing, but I've been having this problem with clients using sites on WordPress. Let's say we have a fairly complex page that requires some good amount of HTML code inside the page itself. We put it up and it looks great. Now, month later client wants to edit couple words there, goes in and edits them in Visual Mode, and of course all markup that we did is now screwed up, so stuff is all over the place. What are the approaches we can use to handle cases like that?
One thing you could do is create page templates for complex pages and simply add the content through the editor, leave as little mark-up as possible in the editor. Another thing that might help is using the editor style (activated with `add_editor_style()` in `functions.php`) and defined in `editor-style.css` so the client has a better sense of what's going to be displayed (if you mimic your theme pretty closely) right in the editor. Add custom fields with descriptive names for information which needs to be displayed in a certain way, in a certain place, rather than lumping it in the main content. The simple fields plugin simplifies this a lot, permits repeatable fields and file uploads. It gives flexibility while avoiding letting your client shoot himself in the foot so easily. Or you could make your own metaboxes,etc.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 5, "tags": "pages, content, customization" }
Add TinyMCE to CPT metaboxes in 3.1? Been looking around for an alternative to this method: < To add the WYSIWYG capability to custom metaboxes. You get so little control with this method, is there any other way?
Use this class: < and then call the metabox like this (don't forget to read the manual and view some examples): $meta_boxes[] = array( 'id' => 'textmetabox', 'title' => 'Your Meta Box Title', 'pages' => array('post', 'slider', 'whatever-your-cpt-is'), 'fields' => array( array( 'name' => 'Your thoughts about Deluxe Blog Tips', 'id' => $prefix . 'thoughts', 'type' => 'wysiwyg', 'std' => '<b>It\'s great!</b>', 'desc' => 'Do you think so?', 'style' => 'width: 300px; height: 400px' ) ) );
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "custom post types, metabox, tinymce, wysiwyg" }
Cannot login due to incorrect password right after registration? I am using Register Plus Redux. I don't know what happened exactly but after I upgraded to 3.1.4, the password provided on registration isn't recognized. I have to go in using admin account and set the password again. This does not happen with the default registration form though. I don't where to contact the author, if this isn't appropriate feel free to delete it.
This is a bug in the Register Plus Redux and has nothing to do with other plugins. Normally when you register with normal wordpress, it sends you a temporary password that you can modify after.. what happens with RPR is it sends you by email the temporary password generated by wordpress but puts in the database the password you have registred with! causing this bug. I advise you to disable this plugin now while waiting for an update from author. some users advised to edit the file _register-plus-redux.php_ but this is risky since when plugin is updated it will overwrite your edits.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "user registration" }
WPML : how to determine manually the language in which a given page is displayed Somewhere in my code I need to know what is the current language and display a certain custom field or another one based on this knowledge. How can I know this information ?
WPML defines constants that you can use go get the current language: * `ICL_LANGUAGE_CODE` \- current language code (eg: en,fr,sp). * `ICL_LANGUAGE_NAME_EN` \- Name of the current language in English (eg: English, French. Spanish). * `ICL_LANGUAGE_NAME` \- Name of current language, in the current language (eg: English, Français, Español).
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "plugin wpml" }
Simple rich text editor in Text widget? I've seen a few plugins that add rich text editing to the default "Text" Widget. However, all of the ones I've tested are either too complicated (or try to do too much) or don't work properly with the latest WP versions. I'm just looking for a simple rich text toolbar with a minimal feature set (basic formatting and lists), image upload and hyperlink tool. Ideally, I'd like to find one that does not require a separate window to handle rich text. Just a simple tab to switch between html and wysiwyg. Any suggestions or recommendations?
I've never found one that was reliable and/or not a huge resource/memory drain. :( I ended up using the very handy "Page in Widget" plugin instead - it has the advantage of all the functionality of a regular editable page and your widget content won't accidentally get wiped, which has happened to me far too often. Sorry not to have the perfect solution. Will check back to see if others do! :) Michelle
stackexchange-wordpress
{ "answer_score": 4, "question_score": 7, "tags": "plugins, widgets, wysiwyg" }
Help Combine These Two PHP Codes I have my WordPress post format codes: <?php if ( has_post_format( 'image' )) { echo 'This is a image post'; } ?> And my code to grab the first image from a post... <a href="<?php the_permalink() ?>"> <?php $image = catch_that_image(); if( $image ) { ?> <img src="<?php echo get_template_directory_uri(); ?>/scripts/timthumb.php?src=<?php echo $image; ?>&amp;h=240&amp;w=280" class="index" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /> <?php } ?> </a> So how do I put the image which is grabbed into the first code? Thanks for all the help guys and gals, I really do appreciate it.
here: <?php if ( has_post_format( 'image' )) { ?> <a href="<?php the_permalink() ?>"> <?php $image = catch_that_image(); if( $image ) { ?> <img src="<?php echo get_template_directory_uri(); ?>/scripts/timthumb.php?src=<?php echo $image; ?>&amp;h=240&amp;w=280" class="index" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /> <?php } ?> </a> <?php } ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, php, post formats" }
What can I expect when moving from a hosted (WordPress.com) blog to one hosted by Page.ly As I mentioned here, I'm planning to moving my blog to a new hosting provider from WordPress.com. I think I've settled on Page.ly as the new home for it, and I was hoping to get the benefit of experience from any of you who have transitioned an existing blog specifically from **WordPress.com** to **page.ly**. **Some examples of the potential issues I'm trying to ferret out:** * Am I going to lose any WordPress.com specific features in the transition? * Any new maintenance issues/headaches that weren't there on Wordpress.com? * Any surprise "Upgrade" fees for things I'm used to getting for free? * What information can I expect to lose in an export/import process (Site stats, dates on comments/posts/subscribed users/something else?) * General tips, advice, whatever that you wish you knew before you did the move.
* You can expect to lose your site stats. * You can expect your site to be harder to find. * You can expect to have greater freedom in terms of customization and possible features. * You can expect to have to upgrade your WordPress version periodically. * You can expect less users commenting, as WordPress.com uses a social networking style bar that won't be on your normal WordPress blog. * You can expect to pay money for a really good theme, if you so choose.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "import, customization, hosting" }
How do I hardcode a WordPress shortcode into my theme? I am using WooTheme's Canvas theme and would like to "hardcode" in the [post_comments] shortcode into my theme. [post_comments] displays a comment link with comment count (ie Comments 10) in my post. Right now I am inserting the [post_comments] shortcode into my theme's meta "Meta Manager"; however, this is not ideal for me as I have limited control over the placement of where the this shows up in my post. What type of function or such should I be looking for to do this within my .php files? Thank you
Check out do_shortcode(): < do_shortcode('[shortcode option1="value1" option2="value2"]'); So your example would be: do_shortcode('[post_comments]'); What might be easier is to tap into the underlying comment functions: < <p> This post currently has <?php comments_number( 'no responses', 'one response', '% responses' ); ?>. </p> You can also use `get_comments_number` which returns the value rather than printing it to the screen. This function however needs to be in the Loop for it to work, however I have a feeling it is.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "php, themes, shortcode" }
How to Get the title of a custom field? I know how to get the value of a custom field, using code like `get_post_meta($post->ID, 'company', true);`. Is there a way to get the name of the custom field?
to get a post custom fields name you can use **get_post_custom** eg: $post_meta = get_post_custom($post->ID); foreach ( $post_meta as $key => $value ) echo $key . " => " . $value . "<br />"; this will print a list of custom_field_name => custom_field_value
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "custom post types, custom field" }
Detect tag page and include an Image for that specific tag I'm trying to figure out a way to include a div(which will contain a background image) for a specific tag. This block of code works but fails when a post has more than 1 tag. I'm using a page called tag.php which is the default template for all tags. I'll have quite a few tags so I don't want to create template files for them all, ie: tag-name.php <?php if( has_tag('books') ) { include 'tags/books.php';} elseif ( has_tag('tables') ) { include 'tags/tables.php';} ?> It's always possible there is an easier way to do this. I essentially need a script that detects which tag is being viewed, as a page, then displays the correct image for it. So when the page for the tag "table" is loaded that tag will always use an image named "table.jpg" Does anyone have any suggestions or know of a way I can modify the script above to do what I described?
Here are 2 solutions: Using Tag titles <?php switch( single_tag_title( '', false ) ) { case 'Books' : include 'tags/books.php'; break; case 'Tables' : include 'tags/tables.php'; break; default : break; } ?> Using tag slugs: <?php if ( is_tag( 'books' ) ) { include 'tags/books.php'; } else if ( is_tag( 'tables' ) ) { include 'tags/tables.php'; } ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "tags, conditional tags" }
Insufficient permissions to save options Hi I have built a settings page which from the menu leads to: < The problem is that when I go to save the options and I am an EDITOR user I get this error: You do not have sufficient permissions to access this page. I am using User Role Editor plugin and edit_theme_options capability is enabled for the Editor user type. What can I do to fix this? thanks
I am not sure this is the issue here, but if I remember right the current limitation of Settings API is that `manage_options` capability is required for everything to be saved properly. Quick search shows it might get fixed in 3.2, see this trac ticket.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "options" }
What do spammers gain by signing up as a user? The majority of new user signups I receive on my Wordpress blog look dodgy, with `@someblog.com`, `@somearticle.com`, or `@gmail.com` addresses. What do they gain by signing up as a new user?
Some are attempting to leave their links behind, they believe the quantity not quality approach will actual help increase SEO rankings. The other reason would be affiliate marketing garbage links trying to make a penny.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "users, security, spam" }
return get_the_tag_list with whitespace removed I need to `get_the_tag_list` but want to remove whitespace **within** individual tags. Thus, `firefox, internet explorer, opera` becomes `firefox, internetexplorer, opera` All the filters I found removed whitespace from the HTML, not the content itself.
$tags = get_the_tags(); $tag_links = array(); foreach((array)$tags as $tag) $tag_links[] = '<a href="'.get_tag_link($tag->term_id).'" rel="tag">'.str_replace(' ', '', $tag->name)).'</a>'; echo implode(', ', $tag_links);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "filters, tags" }