INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Add a Meta Box for uploading a SECOND Featured Image? I'd like to add a meta box to my posts and page editor that will allow me to upload an image and use it as sort of a SECOND featured image. The idea is that my client will be able to upload an image to this meta box to customize the page/posts header image. Here is an example of what the final result would be: < As you can see at the top of the page there is a large banner of a dancer. Right now this is hardcoded with CSS. I'd like for this to instead be editable by my client from within the Wordpress post/page edit screen on a per page and per post basis. How do I get started?
The functionality you want may be built from scratch but definitely a custom fields plugin will make your life much easier. I use Advanced Custom Fields, and it gives amazing results and the possibilities are endless. I haven't used this one, but it seems pretty good too.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 18, "tags": "metabox, uploads" }
how to deactivate a plugin without using a WP function? I wish to deactivate my plugin, but WITHOUT using update_option() or any other core WP function. What's the best way to go about this? Direct DB connection and modification?
The simplest way is probably renaming the plugin file or folder. But if you're trying to handle it directly from the database, you'd have to grab the 'active_plugins' value from the wp_options table, unserialize it, remove your plugin from the array and reserialize it and update. You don't necessarily have to use update_option. You could also look into a command line tool like WP-CLI. With that installed, deactivating a plugin is a simple command from the BASH shell, like **wp plugin deactivate plugin-name**.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugins, deactivation" }
Upgrade to WP 3.2/ and Server to php5 breaks theme? I upgraded to Wordpress 3.2 and my server from php4 to php5 and now my site outputs this error; **Warning: getimagesize() [function.getimagesize]: URL file-access is disabled in the server configuration in /homepages/35/d289582498/htdocs/wp-content/themes/NovatorixFullArchive_Version1.4/novatorix/index.php on line 98 Warning: getimagesize( [function.getimagesize]: failed to open stream: no suitable wrapper could be found in /homepages/35/d289582498/htdocs/wp-content/themes/NovatorixFullArchive_Version1.4/novatorix/index.php on line 98** This is what's on line 98 as the error is stating; **list($width, $height, $type, $attr) = getimagesize($logo_url);** How Can I fix it?
Is your theme compatible with the new version of WP? May be that it uses a deprecated function name somewhere. But I've had updates go wrong previously. The only thing that eventually sorted it out was to re-upload all the files of the new version using FTP, and overwriting what was there. Won't have impact on your theme or other data, it just overwrites the core.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "theme development, php, errors" }
Is there a filter/action to add content to WP admin metaboxes? I want to add an instruction into a custom term meta-box. !enter image description here Is there a hook to add this or is it easiest just to use JavaScript?
I couldn't find a hook so I went with the JS option. add_action( "admin_head-post-new.php", 'meta_box_instruction' ); //new post add_action( "admin_head-post.php", 'meta_box_instruction' ); //edit post function meta_box_instruction($d) { global $post; if($post->post_type == '{YOUR POST TYPE}' || $_GET['post_type'] == '{YOUR POST TYPE}'): ?> <script type='text/javascript'> jQuery(document).ready(function(){ jQuery('<p>Some instruction</p>').insertBefore('#taxonomy-{YOUR TAXONOMY NAME}').parent(); }); </script> <?php endif; }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "metabox, hooks, terms" }
How to change default position of WP meta boxes? Im wondering if there is a way to change the default position of Wordpresses meta boxes such as "featured image" for custom post types without having to drag them manually? **Example:** !Meta Box Positioning Example
You can remove the default meta boxes with remove_meta_box and re-add them in a different position with add_meta_box: add_action('do_meta_boxes', 'wpse33063_move_meta_box'); function wpse33063_move_meta_box(){ remove_meta_box( 'postimagediv', 'post', 'side' ); add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', 'post', 'normal', 'high'); } This will remove it from the side column and add it to the main column. change `post` in this example to whatever your custom post type is named.
stackexchange-wordpress
{ "answer_score": 23, "question_score": 18, "tags": "custom post types, functions, metabox" }
Add extra menu to theme What's the best way to add an extra menu location to a theme that already has one? I want to add an extra menu in a child theme of a theme that currently has a single custom menu (what is the correct terminology here?!). Do I just use `register_nav_menu()` to create an additional menu?
To answer my own question Both `register_nav_menu()` and `register_nav_menus()` are **additive** , ie they add to the existing menu set (as long as you use a different location identifier). You don't need to redeclare an existing custom menu location that was created with either one of those calls.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "menus" }
How Do I Set the Page Title Dynamically? Is it possible to change the page title with code? For example, let's say the page's name is "Book your Order", but I want to change it to "Book Order #123". I Google'd a bit and looked here and didn't see anything. Anyone know of a plugin or hack? wp_title returns the page title but doesn't allow setting the page title: <
There is no documentation on it but you could always apply a filter to `the_title` like this: add_filter('the_title','some_callback'); function some_callback($data){ global $post; // where $data would be string(#) "current title" // Example: // (you would want to change $post->ID to however you are getting the book order #, // but you can see how it works this way with global $post;) return 'Book Order #' . $post->ID; } See these: < <
stackexchange-wordpress
{ "answer_score": 26, "question_score": 27, "tags": "seo, title" }
Only retrieve posts where post_excerpt has been filled out I'm trying to use get_posts to only return posts that have an excerpt. Done lots of searching and have been trying to use "posts_where" filter on the query but my SQL is lacking. This is what I'm using which in theory I think should work, but really I have no idea on the sql and can't work out how to print the sql string for this query to debug... $args = array( 'post_type' => 'testimonial', 'numberposts' => 1, 'orderby' => 'rand', ); add_filter( 'posts_where' , 'posts_where_excerpt_not_empty' ); $post = get_posts($args); remove_filter( 'posts_where' , 'posts_where_excerpt_not_empty' ); [...] function posts_where_excerpt_not_empty( $where ) { $where .= " post_excerpt NOT NULL"; return $where; }
The `post_excerpt` column is a string and is not filterable using "IS NOT NULL" . To query for an empty string you can use the `!=` operator. function posts_where_excerpt_not_empty( $where ) { $where .= " AND post_excerpt != '' "; return $where; } Also get_posts suppresses filters by default so you will need to call it with suppress filters set to false or use another query method. $posts = get_posts( array( 'suppress_filters' => FALSE ) );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "get posts, excerpt, posts where" }
Add a custom meta box for client to order CPT posts how they want Im looking for a way to add a custom meta box to a custom post type that will allow the user/client order the posts to show up how they want on the site. Is this possible? Basically using a very similar functionality to "page attributes"...
You can add `page-attributes` support to the post type. This will cause a meta box to appear with an "order" field to do just what you want. eg. <?php add_post_type_support('your_custom_post_type', 'page-attributes'); Or you add `page-attributes`to the `supports` argument in register_post_type.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom post types, custom field, metabox, order, page attributes" }
How to customize WordPress Plugin installation? I have a WordPress plugin which I've built. This plugin contains a Pro version. When user sign-up for the Pro version, he is getting a unique key.php file which he required to replace in the plugin directory. **The problem is when Pro users upgrade to newer versions, the key.php file is deleted and they need to re-upload it (every upgrade).** Is there any way to specify that this file shouldn't be deleted by WordPress installation process?
Two possible approaches: File based: Standard procedure for anything that you do not to get overwritten is to use the uploads folder. Then it will not get overwritten by any kind of update. I have several plugins that need to save data in files for one reason or another - cached ics files, customised css snippets. I have the plugin create a subdir in the uploads folder and save the files there. Nothing gets overwritten. Database: Presumably your unique key.php has their 'key'. You could have them enter it in a field and save it in the database rather as an option - it will be safely hidden then - files can be found, especially if others figure out where you have them.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "installation, plugins" }
Is it possible to have pagination with an offset loop? I am developing a blog page that requires 3 different post styles (Ie; one full page width with featured image and content, one full page width without featured image and the rest are half page width) so I have been using an offset query. The problem I'm having is that I can't figure out how to force page 2,3, etc. to only use the half page width styles. On top of that I can't get pagination to work anyway Is this even possible?
Offset explicitly doesn't work with pagination. You can have either, but not both in same query.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "pagination, loop, query" }
Use premade array as categories in wp_query? I have a theme options panel that the user can set which categories they want to use which is then saved as an array $blog_cat[0] etc. They can select as many categories as they want for the array and it saves the category number not slug. I am having trouble when I go to make a wp_query using these settings. How can I take that array and use it in the wp_query? If I use the following bit of code it will output all of the categories: $catnum = 0; foreach($blog_cat as $blogcats) {echo $blog_cat[$catnum]; $catnum++;} However, I can't use this in the actual wp_query which looks like this: $wp_query = new WP_Query('category_name=' . $blog_cat . '&showposts=3'); I can target them individually but not dynamically regardless of how many are set. I'm guessing this isn't a very hard problem to fix but I don't know enough about the syntax to figure out how.
You can use the category__in parameter and that will do exactly what you're looking for. Codex: WP_Query - Category Parameters
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "categories, wp query, array" }
Get menu links only I'm creating a template in HTML5. On navigatiom menu i need to implement something like this <nav> <a href="url1">url1</a> <a href="url1">url2</a> <a href="url1">url3</a> <a href="url1">url4</a> ... <a href="urln">urln</a> </nav> If i use 'wp_nav_menu', it prints <div><ul><li><a> when i need just <a> There is a way to get that? Thanks!
Use a custom walker: class WPSE_33175_Simple_Walker extends Walker { public function walk( $elements, $max_depth ) { $list = array (); foreach ( $elements as $item ) $list[] = "<a href='$item->url'>$item->title</a>"; return join( "\n", $list ); } } … and then call `wp_nav_menu()` like this: wp_nav_menu( array ( 'theme_location' => 'your_registered_theme_location', 'walker' => new WPSE_33175_Simple_Walker, 'items_wrap' => '<nav>%3$s</nav>' ) );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "menus, html5" }
Where to insert get_comments? I'm trying to setup a page and extract comments from an external post. I took this advice how to pull wordpress post comments to a external page and now I have this get_comments code at my disposal: <?php $comments = get_comments('post_id=15'); foreach($comments as $comment) : echo($comment->comment_author); endforeach; ?> Where on the page do I place this? Sorry for the noob question!
I would rarely use 'echo' in WordPress template themes because it can cause output to appear before the loops are even executed (aka, at the top of the page). In this instance, I used the get_comments function within a function that hooked onto the content output: add_filter('the_content', 'includePosts', 1); Within the function includePosts, I have set $Comments to appear in the $content variable and I return $content just before adding the filter. $content is used within the wp core function 'the_content' (includes/wp-page-template). function the_content($more_link_text = null, $stripteaser = 0) { $content = get_the_content($more_link_text, $stripteaser); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]&gt;', $content); echo $content; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "comments" }
What is the best way to enable nested shortcodes? Is this the best way to enable nested shortcodes?: `add_filter( 'the_content', 'do_shortcode' );` I keep finding mixed results and want to be sure I won't break anything else!
< Everything you need to know about nested shortcodes in WP
stackexchange-wordpress
{ "answer_score": 4, "question_score": 6, "tags": "shortcode" }
First item in each category list is not a link After the last update of the plugin "List Category Posts" the first post item under each category is just text, no link. This request is made at the request of the plugin author as per the help file associated with the plugin as the means to get answers from HIM. See example here: < So the category links work but the post links are not working on the first link...
The first link was displaying incorrectly because of a bug with a " sign. On line 60 of ListCatDisplayer.php, there was a wrong ": $this->lcp_output .= '<' . $tag; if (isset($this->params['class'])): $this->lcp_output .= ' class="' . $this->params['class']; endif; $this->lcp_output .= '">'; As you can see, I was always adding the " when closing the tag. So this produced: !enter image description here And if you specified a class and added more parameters, the wrong " made the whole markup to be wrong. I've fixed it to add the " only on the class line: $this->lcp_output .= '<' . $tag; if (isset($this->params['class'])): $this->lcp_output .= ' class="' . $this->params['class'] . '"'; endif; $this->lcp_output .= '>'; It was fixed in version 0.20.2, now ready for update. Sorry for the inconvenience, and sorry you didn't get much help in the comments. Usually users tend to be friendlier over here.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin list category post" }
Premium Members Section of website Have used emember in the past and looked at Tadlock's membership as well as another premium offering by jigowatt. However, I don't want to just hide the post's content.... I want to hide the entire post... and entire categories/taxonomies. I'd like the menu to show "Products" and when you visit that particular page you are prompted to log in to view it. Logging it would also "unlock"/reveal sections of the site that weren't previously visible. For instance, the menu might now have widgets and gizmos underneath the main "products". to me this seems different than what the plugins i mentioned before can handle. is there a plugin that does this or am i looking at creating my own?
The best way to have complete control is to use conditionals in your templates. Look at current_user_can() for specific permissions - or if its simply for being logged in you could use is_user_logged_in(). eg: if( is_user_logged_in() ){ // echo product details }else{ //echo login form and message } That we you have complete control over what is displayed to whom.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "membership, content restriction" }
Sharing changes to a post (preview changes) with another user We would like to be able to share changes to an existing post with other wp users without saving the changes (making them live). A nounce currently makes it impossible to share a previewed post. Is there a way around this? a plugin maybe? If not, what would be a good approach if I where to develop a plugin with this functionality?
Don't know of a plugin but a good approach would be: 1. to crate a custom post type (shared_revisions). 2. add a metabox to post edit screen which will have an option to save the post changes as a sheared_revision and store the original post id as postmeta of the sheared_revision post. 3. add a metabox to your sheared_revision edit screen which will have an option to overwrite the original post. Hope this make sense.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin development, previews" }
Multiple endpoints to same page I'm doing a bit of AB testing, and am looking for a way to point multiple endpoints to the same page in wordpress. My site is using wordpress as it's CMS tool. I want the above URL's to point to the about page generated through wordpress The specific use case is to track hits through google analytics. I've tried doing 301 redirects, but searching through referrers for your site doesn't always work. Any idea's?
Okay... here's how you add the rule. <?php add_action('init', 'add_my_rule'); function add_my_rule() { add_rewrite_rule('^test\/link.*$','index.php?pagename=about','top'); } ?> This rule will ensure that when you visit a url like ` or ` you are redirected to the `about` page (please make sure the slug for about page is 'about'). Also, ` will take you the `test` page and not the `about` page. Let me know if this works for you.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 7, "tags": "url rewriting, urls" }
Automatically send an email to list when blog is updated I am trying to implement a system where a user makes a blog post (to a set category) and as part of that sequence, or in addition to, it does the following: 1. Create a new email based on a template 2. Populate the email with a snippet, or the excerpt text 3. Send to a predefined list To labour the point; it isn't to email everyone, just the people in the aforementioned list. Does anybody know of a plugin or email system to do this? We currently use aweber but I cannot find the functionality to dynamically insert content from the post. It seems to only be able to do send a "Blog Updated, go here to enjoy it's awesomeness" type deal. EDIT: Had a look at Subscribe2 as detailed here to no avail.
There is a list of possible plugins here < I responded to your other post too. You don't say whether your 'list' is something you control, or whether users can subscribe to it. I don't know mailpress well, in S2 one can manually add subscribers to the list (and not show the s2 subscribe widget for example)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, plugin recommendation, email" }
Subscribe2 Configuration I am trying to configure Subscribe2 to have the user select which categories they want rather than the "all or nothing" approach it seems to have. Essentially I am using WP as a CMS as opposed to a blog roll, but I currently have 2 "blogrolls" represented by displaying the most recent post on the page (they are page length posts). I would like to send an email when Cat 1 OR Cat 2 is updated, likewise with future categories, but have the user be able to select only Cat 1 emails. I have read the FAQ to no avail, is this actually supported?
Sure it is joshau Thee S2 admin interface could be better, but it is stable, has been around a long time. You can exclude categories (eg all except your 2) and can allow users to select which categories they want from within that. I'm not the author, but I have it in use in a few sites and am nearly done writing an 'add-on' that sits on top and tweaks a few things the way I want them..... (html, unsubscribe, cron job visibility etc)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, plugin recommendation" }
Multiple Paginations on one Page I have a page template which aggregates multiple CPT's in different areas of the page and displays the first post from each CPT. I'd like to add a separate pagination for each of them. Is it possible with or, preferably, without a plugin? !enter image description here
Its possible! When i find myself in need of multiple paginations in a page i usually use ajax. take a look at this tutorial which with a little modification can do what you want.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 4, "tags": "custom post types, pagination, archives" }
what is the way to see the currently executing query in wordpress? I am working on wordpress which is new to me Now I have been provided with site completely designed in wp But the problem is I am unable to search the query for each functionality/page I found $wpdb->get_results used for getting result from database also this is not working $wpdb->queries Is there any way to print each query currently executing?. Please Help.
Debug bar is one of the recommended (by WordPress) plugins to install for theme and plugin development. I also use debug-bar-extender: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 12, "tags": "wpdb" }
Not Found (404) error on admin page, CSS gone on blog I manually installed wordpress on my server and the wordpress files are located in "www.mydomain.com/wordpress/", however I wanted my "www.mydomain.com" to be the address for my wordpress blog instead of "www.mydomain.com/wordpress/" so I went to the "Settings->General" screen in my dashboard and changed the "Home" url to "www.mydomain.com/wordpress" and the "Site" url to "www.mydomain.com" thinking it would make my home address the blog address. When I went back to the admin page I get a "Not Found (404)" error message and all the CSS formatting is gone from my blog. Is there a way to reset my settings?
If you've got access to the database (via phpMyAdmin or the like) you can change those two values in the `wp_options` table. Look for _siteurl_ and _home_ in the `option_name` column.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "wp admin, 404 error, site url, home url" }
is_front_page, is_page('slug'), is_page(id) not working None of the following are working to display conditional format in the sidebar when the current page is the home page: * is_front_page, * is_page('home'), * is_page(id) I added an else clause which is implemented on the home page. In Options > Reading, I have specified a page called Home to be the front page. The slug 'home' and the page id of 13 (obtained from the URL when editing the Home page) all return false. If I place `<?php the_ID(); ?>` in the sidebar, it displays the post ids of blog posts which are also displayed (title only) by home.php (which is the template assigned to the home page). I don't know how else to explicitly display the page id on the front end so I know I'm using the correct id.
Try putting a wp_reset_query function call after your loop on the homepage template. If you're using a custom query on the home page and not used `wp_reset_query`, then the conditional check will always point to the last post fetched by that custom query hence failing to check if homepage.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "conditional content" }
Can't see themes for Multi-site wildcard subdomain I have successfully enabled wildcard subdomains and everything is working except for enabling themes besides the default. All of the plugins in the root plugin directory are available but none of the other themes I have in the theme folder are showing up. Any ideas?
In a multisite set up you have to enable themes for use on the sites within the multisite. 1. Get to the network admin area by clicking on your name in the top right to open the menu and clicking 'Network admin'. 2. Go to Themes 3. Network enable any themes you want available to all your sites If you want some themes to only be available to a single site then edit that site under 'Sites' section and go to the Themes tab, then enable the theme(s) you want for that site.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "themes" }
how to activate a plugin inside a theme Iam trying to activate a plugin which is inside my theme template directory, ie : i have a folder called plugin inside my current theme, which has some plugins how can i activate those plugins from the current plugins options.
**TGM Plugin Activation Class** looks awesome!* > [...] the TGM_Plugin_Activation class can automatically install and activate multiple plugins that are either pre-packaged with a theme or downloaded from the WordPress Plugin Repository. And here's an introduction to it: < *Disclaimer: I haven't had a chance to try it out for myself... yet.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, themes, hacks" }
What is a good free subscribe list? I tried 3 different plugins and they ALL didn't work. I would like a plugin that allows me to put a widgit into the sidebar. Configure a redirect page to say thank you and a way to get a list of the emails (preferably with signup date and name. csv is nice) Is that so much to ask for... If it can shoot everyone an email on signup that be nice too
Here is what you could do. It is more of like three plugins. One main plugin and two that are sub plugins First you will want to get Contact Form 7 ... if you don't already have it. Here is the link if you need it: Download Contact Form 7 Here Then download Contact Form 7 to Database. This will store whatever information you collect in the form in your database. Download Contact Form 7 to Database Here Our last and final plugin download is the Contact Form 7 Sidebar widget. You can get it here: Contact Form 7 Widget After you have all that where you edit the contact form just add this bit of a javascript hook in the additional settings for the redirect: on_sent_ok: "location = ' Replace " with your own url.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugin recommendation, email, signup" }
Check if a field is capitalized? I want to check the if the first letter of a field is capitalized. Example: If (First Name field) is capitalized { Capitalized! } else { Not Capitalized! } Thanks Thank you
$field = 'First Name'; if(ucwords($field) !== $field){ // not capitalized }else{ // capitalized } see `ucwords()`
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "custom field, captions, customization" }
Check & remove special characters in a field? I would like to check whether a field has special characters, remove those characters and output (save) the value to another field. I am creating a user search function that search various fields, but those fields might (or might not) have special characters in them that will return unexpected results, or no results at all. I need to be able to remove any special characters and save/output the clean value to another field, which I will then include in my search function. **Example:** **Original value:** G-P's Bargain Shop **After removing special characters:** GPs Bargin Shop Then **save new value** (GPs Bargain Shop) to **another field** Can someone tell me how to achieve this? Or of a better solution for what Im trying to accomplish. Thanks for any help with this.
You could use regex to only allow alphanumeric characters. $string = preg_replace("/[^A-Za-z0-9 ]/", '', $string);
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom field, text, customization, characters" }
How to define template directory in this widget code How can I define the template directory (So I can reference and image in the 'images' folder) from within this php widget code? // WIDGET CODE GOES HERE query_posts('posts_per_page=1&post_type=testimonial&orderby=rand'); if (have_posts()) : echo "<div class=\"testimonial-widget group\">"; while (have_posts()) : the_post(); the_post_thumbnail('widget-test-thumb'); echo "<p><span class=\"left\">\"</span>"; $excerpt = get_the_excerpt(); // IMAGE WOULD GO HERE echo string_limit_words($excerpt,15); echo "<span class=\"right\">\"</span></p>"; echo "<h2>".get_the_title()."</h2>"; endwhile; echo "</div>"; endif; wp_reset_query();
You can use `get_template_directory_uri()` and it will return the url up to the template directory then you can just append the `'/images/FILENAME.EXT'` to it to pull in the image.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, widgets" }
using wp_update_post on save_post im trying to update a posts date (-1 year), when you hit update. but it causes an infinite loop. any other ways of doing this? thanks. function change_year($post_id, $post){ if ( $post->post_type == 'post' ) { $format = 'Y-m-d H:i:s'; $id = $post->ID; $old_date = $post->post_date; $old_gmt_date = $post->post_date_gmt; $new_date = date( $format, strtotime( '-1 year' , strtotime( $old_date ) ) ); $new_date_gmt = date( $format, strtotime( '-1 year' , strtotime( $old_gmt_date ) ) ); $new_values = array ( 'ID' => $id, 'post_date' => $new_date, 'post_date_gmt' => $new_date_gmt ); wp_update_post( $new_values ); } } add_filter('save_post', 'change_year',10,2);
The reason it's going to be infinite is that every time you save the post, it's calling `change_year`...which then calls `wp_update_post` ... which fires the `save_post` filter. After some review and research, I'm thinking that you should probably avoid the `save_post` filter. Try using this filter: < It gives you really what you want. Here's an example of it editing posted data: function filter_handler( $data , $postarr ) { $data[ 'post_title' ] = $postarr[ 'post_title' ] . 'RAWR!'; return $data; } add_filter( 'wp_insert_post_data' , 'filter_handler' , '99', 2 ); That will take any post that I save and add 'RAWR!' to the end of the string. Hope this helps.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 5, "tags": "posts, date, customization" }
Does WordPress keep track of a post's URL history and provide automatic redirects? I just changed the URL of one of my posts from > < to > < Now, if I go to the old url, I get redirected to the new one. This is great of course! ...But is this a feature of WordPress, or what's going on here? Does WP keep track of a post's URL history, providing rewrites/redirects for former URLs? Looking at the response header I see WP is sending out a SEO friendly 301 redirect... Yes!? I thought I'd have to set up those redirects using rewrite rules in my `.htaccess`, so I'm curious to know how it happens that WP is giving me my new URL when I type in the old one. Any light on how WP handles this would be appreciated.
> Does WP keep track of a posts url history, providing rewrites/redirects for former urls? Yes it does. If you change a post slug, wordpress 301 redirects the old to the new URL (if your server setup allows it). > Any light on how WP handles this would be appreciated. Unfortunately, I've never seen this feature properly documented in the codex. Hence I cannot tell you which wp core function does this and where in the core it is located. What I can tell you though is this: The previously used slug(s) are stored in the database in the _wp_postmeta_ table. Check for __wp_old_slug_ in the _meta_key_ column (the actual slugs being stored in the _meta_value_ column). Hence should you ever want this default behavior not to happen in a particular case, this is where to delete a value. More often than not this feature is very helpful. It screws up though, when you rename a post and later on create a new post with the same name the other one had had earlier.
stackexchange-wordpress
{ "answer_score": 21, "question_score": 19, "tags": "url rewriting, urls" }
Dynamic Rating Plugin to Add Anywhere I need to add ratings to a page for a few different fields (ex: color, quality, etc.) - not just per post or comment. I'm generating the page using a template, so I have access to the php file that generates the html. Is there any pre-existing rating plugin where I can add the rating feature anywhere on the page? (For example, by saying [rate id=5 field=color]) I've looked at GD Star, but I don't think it works outside of pages and posts. If this is possible with GD Star, I'd love a link to how to do it - I've looked through their documentation and have come up empty. Thanks!
You should install the plugin and reference it inside of a function within your theme. Be sure to check to make sure the expected plugin/function actually exist. Then you can just use it's functionality as you see fit!
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, plugin recommendation, rating, plugin gd star rating" }
YARPP php question I'm trying to put a border under `related_posts()` ,it works, but the border is showing even when the there are no posts. How do I make the border show only when there are related posts to show?
Are you setting the border using CSS? If so, you should set "Default display if no results:" under Settings to nothing. If that is nothing, YARPP will show nothing.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, css" }
Get content from one page and show it on another page So, I've been googling and reading and testing and failing. I'm fairly new to php, so don't expect to much :) I'm working on a new design, and I want to show content from the about page on my homepage, which is dynamic. So, I've been looking into that the_content thing, but I havent gotten any luck so far. <?php $id=about; $post = get_page($id=); $content = apply_filters('the_content', $post->post_content); echo $content; ?> the ID of the page is "about", if that is any help. Please get back to me :)
First off: The ID of a post or page is always an integer. "about" is either your about page's title, slug or both. Including the following in your "homepage's" page template or in the sidebar combined with conditional tag(s) will display the about page's content: <?php // query for the about page $your_query = new WP_Query( 'pagename=about' ); // "loop" through query (even though it's just one page) while ( $your_query->have_posts() ) : $your_query->the_post(); the_content(); endwhile; // reset post data (important!) wp_reset_postdata(); ?> **Edit:** The above works, IFF your page's slug is indeed "about", otherwise adjust accordingly.
stackexchange-wordpress
{ "answer_score": 11, "question_score": 9, "tags": "posts, pages, content, the content" }
Taxonomy template for all taxonomies attached to certain post type For instance, I have a product post type and I would like all the taxonomies associated w/ this type, such as size, color, material etc to display using the same template without having to 1. create a catch all taxonomy.php that might interfere w/ taxonomies on other post types and 2. without having to manually create taxonomy-size.php, taxonomy-color.php, etc since new taxonomies can be created at any time. can i do this by hijacking template redirect?
the answer is yes, yes i can. do love it when i find the answer w/in minutes of posting here. add_action('template_redirect', 'my_template'); function my_template() { if ( is_tax() && in_array(get_query_var('taxonomy'), get_object_taxonomies('product') ) ){ include (get_stylesheet_directory(). '/product_taxonomy.php'); exit; } }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "taxonomy, templates, get template part" }
GPL 2 Theme using a framework for commercial Theme? I'm new to WordPress and I have a question about license. Can I use a GPL 2 Theme (downloaded from < as a framework for Commercial Theme? I searched and I found that Yes as long I keep the same License, but what are the changes I can make? Can I modify the Author.... Name ... from style.css? What are the credits I have to add?
Short answer: You may change everything as long as you keep the same license. No credit is actually required. But it is polite. I would add it in the stylesheet under the notes section with a link back to the original. * * * Provide the original author and link to the source. Something like "Based on the original work of John Doe: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "themes" }
Can i put 'page' at the bottom of each page? I would like to use wp-admin to make a "page" which is used at the very botton of each pages. The bottom part would look like the below > Home | Tips | Services | Downloads | Workshops | Testimonials | Resources | Contact us but on top of that it will be complex. A logo+links+images. Something you would find on a page rather then a menu How do i create a page with the editor and have it display at the bottom of each page?
I don't quite grasp why you'd want to include a page "on the bottom of each page", rather than putting the "logo+links+images" in the footer and creating a menu below that. That being said, in order to achieve what you want, create the page and include the following in your theme's _footer.php_ (the below code example assumes that that page's ID is 83 and/or its slug "bottom-page", change it accordingly): // query for the page using either (not both!) one of the two following lines $bottom_page_query = new WP_Query( 'page_id=83' ); $bottom_page_query = new WP_Query( 'pagename=bottom-page' ); // loop through the query (even though it's just one page) while ( $bottom_page_query->have_posts() ) : $bottom_page_query->the_post(); the_content(); endwhile; // reset post data (important, don't leave out!) wp_reset_postdata();
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "footer" }
How do i pick the pages in 20-11 header? With the 20-11 theme when i add a page it shows in the header. I like this. I found and changed the order of them in quick edit. Now i would like to hide a few pages from the header. How do i do this? -edit- i see i can do it in css by writing `.page-item-NUMBER { display: none; }` this is acceptable since i have root access (all my files are readonly) but how might i do this through the admin panels?
Twenty Eleven uses wp_nav_menu() and supports one Primary Menu. If you haven't defined one, it falls back to wp_page_menu(), which displays all pages. You can create your own custom menu in the admin area under _Appearance > Menus_. Select that menu to be the _Primary Menu_ in the upper left _Theme Locations_ box and you're set.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "pages, headers" }
Events Plugin that works with existing categories? I have a series of categories on my website that are fixed, i.e. The client has specifically asked that I leave them. Now however, they would like me to add an events plugin so they are able to add events. Every plugin I've found insists that you create your own event specific categories, thus losing the permalinks structure and the menu structure that is already in place. If I wanted to add an event to Category 1 because it's subject matter is related to Category 1, then I can't. Does anyone know of a way to either modify an existing events plugin to this purpose, or of a plugin that already implements it?
My plugin (amr-events) will work with existing categories (and you can choose standard posts or custom post types) There is also a way to convert any existing posts into 'event' posts in case there is alot of content already built into a post for an event. It is a paid plugin (the free version at test) works with ics files, They share the same recurring and listing engine for event data. See the rating at wp. You can test out amr-events out for free at test.icalvents.com
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, categories, events" }
Cause of Blank Lines Being Added to WP FIles? **Does anyone know why some of my websites add a blank line after every line of code, while others on the same host and server leave the files untouched?** A few details that might help: * PHP Version 5.3.5 * Linux Servers * MySQL- Client API version 5.1.56 * SERVER["HTTP_ACCEPT_CHARSET"] (ISO-8859-1,utf-8;q=0.7,*;q=0.7) **NOTE** : I can provide additional config info, I wasn't sure which details if any would be helpful. I can download the file via FTP and the additional lines are present, but if I copy and paste from the WP Theme Edit page the additional lines aren't there. This is more of an annoyance than a problem. I don't believe any problems are caused by the odd behavior, but I am curious to know if anyone else has noticed this and if anyone knows the cause. I'm not sure if this is a WordPress or simply a server config issue. Any input is appreciated. Regards, JJ
I think the difference is probably something to do with the editor you use to edit files, and specifically the line ending characters. DOS machines (like Windows) use a carriage return character and a line feed ("\r\n") as a line ending, and Unix-based machines (newer Macs and Linux included) use just a single line feed character ("\n"). When files are transferred back and forth between the two different systems and through different text editors, those line breaks get converted in different ways. I wouldn't worry about it, unless it really seriously bugs you. Most text editors can be configured to recognize different EOL characters and account for them or convert them to your desired format. And if not, there's always find/replace.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "php, code" }
User role editor - Add download files capability I've got User Role Editor plugin installed and i want to add a capability for download files. I've got some downloads in a custom post type called 'products'. I want only people who are logged in to be able to download or view these files. If a user isn't logged in they get redirected to a login/registration page, then they log in and get redirected back to the product page. User role editor has a capability for upload files so was wondering if it can be used to download files as well. Or should i use some other plugin or something to get this?
Since you're just checking to see if they are a logged in use, you can just use the `is_user_logged_in()` function to check if they are logged in and if so, display the download link, if not, don't display the download link.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "user roles, plugin recommendation, capabilities" }
How do i make a sidebar background color? With the 20-11 theme i would like to make the sidebar one long color. I have no idea how long my page are and i need the sidebar height to be the same as the post height. Right now when i do `#secondary { background-color: green; }` the green is only as long as it needs to be so it is extremely short. How do i get it all the way down?
The simplest way to create the solid color side bar is with this CSS: #branding { background-color: #ffffff; } #page { background: #ffffff url(path_to_image) repeat-y; } Replace #ffffff with the appropriate color used in your template (if they are different). The "path_to_image" would need to be pointed to an image file that is 1000px wide and 1px high. The image itself would contain the sidebar color starting about 800px from the left.
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "css, sidebar" }
Reasonable Size Limit to options entry I have a set of ~4700 records that I need to have locally searchable for my plugin via an auto-complete (it's the Google Product Search categories). Would it be okay to store this data in the options table as an array or would it be better to actually create a separate table in which to store this data? It's about 317k. Would I be asking for trouble if I just stored it as an array in the options table? Does each page load cache all the site options?
Each page load triggers a database query that reads all the options (from what I'm aware the option records are all auto-loaded). Anyway 317 K is not something you should worry about, but there are better ways to store your data, for example a simple text file that gets read trough ajax only when the search is being made (first character typed I guess). You can cache the data after the first load if you want, using `wp_cache_set()` (and delete it when you're updating the list). You need some persistent object cache plugin to keep it across page requests.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "cache, performance" }
Fixing media links after importing to multisite When i imported all posts and media from a old site to new site which on wordpress multisite. The image links on posts are got broken because how media are stored on a multisite is quite different from a single installation wordpress site. And also the links in the contents are static so it don't change when imported. Single installation example: ` Multisite installation example: ` So, you see if i can go through all posts replace old links with the new links in all image/media links it is going to work. We need to change the first part of the url. the name and the date of the media will be same as the importer will use the same publish date and name when imported. **My question is:** Is there any plugin which can do that? or some other way i can do it?
Try **`Search and Replace`** plugin which is A simple search for find strings in your database and replace the string. You can search in ID, post-content, GUID, titel, excerpt, meta-data, comments, comment-author, comment-e-mail, comment-url, tags/categories and categories-description.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "multisite, plugin recommendation, media, export, bulk import" }
register user only with specific Host name Hii i want to that whenever any user register at my wordpress that just accepet email of specific host for example if I want to accept only User register with [email protected] this email format otherwise that show some error that you can only register with @gmail.com so how to apply this condition and in which file thanks
I think the User Domain Whitelist plugin is exactly what you want: > The User Domain Whitelist/Blacklist plugin limits user registration to only registrants with an email address from the domain white list below OR prevents registrants with an email address from the domain black list below from registering.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "user registration" }
Use $wpdb in wordpress theme files I want to use $wpdb in a theme file, but it doesn't work. My code is bellow: <?php $action = $_POST['action']; $updateRecordsArray = $_POST['recordsArray']; if ($action == "updatelist") { $listingCounter = 1; $column = $_GET['column']; foreach ($updateRecordsArray as $key=>$value) { $wpdb->update('wp_postmeta', array('meta_value'=>$column), array('post_id'=>$value, 'meta_key'=>'dbt_text') ); $wpdb->update('wp_posts', array('menu_order'=>$listingCounter), array('ID'=>$value) ); $listingCounter = $listingCounter + 1; } } ?> I think that $wpdb must be declared global or I must include certain files. Can someone please help me on this?
You need to connect your script to Wordpress before you can use `$wpdb`. The usual way to do this is to include `wp-blog-header.php`: include "/path/to/wordpress/wp-blog-header.php";
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "wpdb" }
How to display number of page views on a post? Is there any currently supported plugin to display the number of page views on a post? wp-postviews seems to be the most commonly used, but it requires modifying the theme (which would require creating a child theme to avoid being overwritten by theme updates), and does not seem to work with caching plug-ins. It seems like this should be straight-forward to extend the wp-statistics / jetpack API to display this information, but I haven't found a plugin that will do so. Seems like a common feature, surely this has been done somewhere?
Using WP-PostViews with Ajax-the-Views and a child theme for both the index.php and single.php files of my theme is the best solution I have at the moment. Pity that this does not call the wp-stats API with my API key, so that the counters would not start at zero but reflect the history stored by the stats plugin. Thanks @EAMann for suggestions, and happy to hear of other solutions.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, statistics, views" }
Getting metabox value within a shortcode? Is it possible to get page's metabox value within shortcode that is executed on that page? Scenario: * I have a sidebar metabox for every page. * I have some kind of custom gallery shortcode. My gallery shortcode outputs 600x200 images (I'm using timthumb here). BUT I want it to display 900x300 if there's no sidebar. Normally I'd use: $sidebar = get_post_meta($post->ID, 'metabox_sidebar', true); if($sidebar == "true") { do something } else { do something else } But get_post_meta returns nothing within the shortcode body.
`$post` is outside the scope of your shortcode function, you have to globalize it first: global $post; $sidebar = get_post_meta($post->ID, 'metabox_sidebar', true);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "metabox, shortcode" }
Create a custom post type based on 'Post' I would like to create a custom post type, but all the tutorials I've found are geared towards making a brand new one and creating meta boxes from scratch. Whereas all I would like to do is copy an existing and add one or two extra entities. I would like to go through the motions of creating a new post type because it'll show up in the admin menu as a separate entity as you would expect, but I would like this custom post type to use pretty much all of the meta boxes associated with a normal 'post' type, plus one or two more I'd add. How could I duplicate the post type for 'post'? How could I go about making these adjustments?
If you created a new post type, it would behave like a post unless specified. The problem you have is that the 'post' post type is built in. I suspect you want the other post type to simply be another type of post, and show up in the archives etc etc This isn't possible with a custom post type, and the Wordpress developers have stated in the past, if you want that sort of behaviour, just use posts, custom post types were not added for that purpose. Instead it sounds more like custom post formats is a better choice for you. You can add your own post format, and add UIs for the different formats. Alex King built such a UI that shows different things depending on the different kind of format the post is: < But I'm afraid without further information about your context and why you asked this question, a satisfactory answer is not possible.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, posts, metabox" }
WordPress plugins not showing after switching servers So I recently moved my site to a new server, and now some of my plugins will show only if you are logged in as admin, but will not show to the regular user. However, some plugins still show and work fine. I have already reinstalled and that hasn't done anything. Any ideas? Thanks!
I found the issue. The problem was that there were two plugins I was using (A facebook likebox and a twitter plugin) and apparently these plugins are pretty well known to break other plugins on the site if they are installed. I removed those to plugins and then the rest of my plugins all started working fine.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, admin" }
Changing bloginfo description from a plugin How can I change the site's bloginfo description in runtime from a plugin? I tried these, but none of them work: add_filter('description', 'ab_arq_generate'); add_filter('blogdescription', 'ab_arq_generate'); My point would be to make a random quote in the place of the description regardless of the actual template.
You're lookign for the `bloginfo` filter. <?php add_filter( 'bloginfo', 'wpse33522_change_bloginfo', 10, 2 ); function wpse33522_change_bloginfo( $text, $show ) { if ('description' == $show) { $text = 'Some New Description'; } return $text; }
stackexchange-wordpress
{ "answer_score": 6, "question_score": 2, "tags": "plugin development, filters" }
Wordpress database nonsense error I'm very confused. What i did was change my hostfiles so i can access my website on an alternative website and checked it in case i had hardcoded values (i did and they were corrected). I had to use the defines below to get the check to work define('WP_HOME',' define('WP_SITEURL',' Anyways, after i checked everything i did some select queries in my db (confirmed by looking at history). When i undid the define and change my host files back so my original url isnt poiting to home i tried visiting my wp site and i got "Error establishing a database connection". copied pasted the login data into mysql -u name -p (pass) and i was able to log in... i dont know why wp cant login. I tried reseting my server, mysql server and php-fastcgi. All didnt fix it :(. How do i fix this?
Nevermind, i actually accidentally didnt put back the url in nginx config file so i only had the new url. I wonder why i got a DB error instead of my generic "Nothing to see here" page
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "site url" }
How to get a list of all the possible thumbnail sizes set within a theme What function can I use in a plugin to get the dimensions of every image size (in an array preferably) that is defined in a child theme? Just for clarification I am not asking how to _create_ a new image size.
Found it here. The answer is: global $_wp_additional_image_sizes; print '<pre>'; print_r( $_wp_additional_image_sizes ); print '</pre>';
stackexchange-wordpress
{ "answer_score": 59, "question_score": 37, "tags": "images" }
embed video and display in pop up I have installed lightbox plus plugin. I want to display my video in a popup. Or you can suggest me any alternate plugin that can display my video in a pop up. video source is from my own local server.
I will suggest you to use pop up generator plugin.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "video player" }
Troubleshooting white screen when editing specific posts I've run into a bit of a perplexing challenge. I'm working on a WordPress installation where certain posts, without a yet apparent rhyme or reason, throw a white screen when you attempt to edit them in the admin area. Its a large site with _lots_ of plugins. I've tried disabling all plugins to see if that made a difference. None. I've been comparing the good posts to broken posts in the database, comparing wp_postmeta and wp_posts entries to see if I can spot any obvious difference. There are differences, but I don't see a consistent pattern and I'm not even sure that it would matter. Any ideas on how you would troubleshoot this next?
I wound up doing a repair database via phpMyAdmin and that solved the trouble.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "admin, troubleshooting, fatal error" }
How to rewrite URI of custom post type? The site that I am working on uses the following "pretty" permalink structure: But for a custom post type my client would like to avoid having a "pretty" slug: How can the post ID be used in place of the slug for the custom post type? I believe that this might be possible using WP_Rewrite, but I do not know where to begin.
This is what I use to rewrite custom post type URLs with the post ID. You need a rewrite rule to translate URL requests, as well as a filter on `post_type_link` to return the correct URLs for any calls to `get_post_permalink()`: add_filter('post_type_link', 'wpse33551_post_type_link', 1, 3); function wpse33551_post_type_link( $link, $post = 0 ){ if ( $post->post_type == 'product' ){ return home_url( 'product/' . $post->ID ); } else { return $link; } } add_action( 'init', 'wpse33551_rewrites_init' ); function wpse33551_rewrites_init(){ add_rewrite_rule( 'product/([0-9]+)?$', 'index.php?post_type=product&p=$matches[1]', 'top' ); }
stackexchange-wordpress
{ "answer_score": 37, "question_score": 17, "tags": "custom post types, permalinks, url rewriting" }
How to use tinyMCE for user “biographical info” without messing with any core file? I noticed when you typein the user's “biographical info” on the profile, it shows up in one page! Looks really terrible. So: Is there a way to use tinyMCE or other solution for user “biographical info” without messing with any core file, and without any plugin? Thanks a lot.
Just adding this to the theme's functions.php solve the problem (prevent stripping of the html from the author's bio): remove_filter('pre_user_description', 'wp_filter_kses'); add_filter( 'pre_user_description', 'wp_filter_post_kses' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "users, tinymce, bloginfo" }
Clean links in: the_author_meta('description') I need to clean any links returned from the_author_meta('description') The code I use is simply that: <p><?php the_author_meta('description'); ?></p> I Searched old question but could not find the right anwer.. ideas anyone?
<?php // grab description, // note the "get_", we're not echoing the author meta, we're returning it $user_description = get_the_author_meta('description'); // removing all HTML tags: echo strip_tags($user_description); // removing all tags apart from paragraphs: echo strip_tags($user_description,'<p>'); // removing just anchors (i.e. <a> tags): echo preg_replace(array('{<a[^>]*>}','{</a>}'),array('',''),$user_description); // removing all links including their text (i.e. <a href="...">...</a>): echo preg_replace('{<a[^>]*>(.*?)</a>}','',$user_description); ?> Reference: * strip_tags() * preg_replace()
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "author, links, description, customization" }
Secure Wordpress: Change admin I'm sorry if this is an extremely stupid question. I've been looking for ways how to secure my WP and a lot of websites suggest to create a new admin user account and delete the old one. Now, if I use a different screenname as author (when writing comments etc.) - how could hackers still find out what my admin username is anyways? I'm just wondering if this step really makes sense unless your administrator username is "admin". Thanks a lot for clarification.
Sorry, if your username isnt admin (older versions) you really dont need to do that. What i would reccomend is for you to install 2-3 plugins ordered here by their importance: 1. wordpress firewall 2 2. Limit Login attempts 3. Wp Security Scan Wordpress Firewall should stop must hack attempts directly on your site, Limit login should end any change of a brute login attemp and wp security should show you any loop holes in your file permission structure and othere stuff... . Hope this helps :)
stackexchange-wordpress
{ "answer_score": 5, "question_score": 0, "tags": "security" }
Tips for managing code when developing a parent theme framework I have started work on an open source theme framework that pulls in lots of great code & resources from elsewhere. For example it uses: * jQuery * Option Framework Theme * LESS etc etc. Most of these external projects are hosted on Github or SVN. Rather than continually download and integrate the latest versions of these other libraries into my framework I am looking for a way to automate this process. I would be prepared to change the way I work considerably to accomodate an automated work flow that ensures I am always up to date and not always downloading or duplicating files. Any suggestions are greatly appreciated.
What you're looking for is git submodules: > Git's submodule support allows a repository to contain, as a subdirectory, a checkout of an external project. PS: Always try to use the jQuery bundled with WordPress.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "themes, customization, code, workflow" }
How to Debug: My Plugin Interferes With My Theme I'm learning how to write a plugin. My plugin is a google map that places markers based on the selected criteria. It works fine. The problem is that it interferes with one part of the theme I'm using. The theme is called Superb. The theme has a uBillboard, basically, it's a slider. For some reason, my plugin prevents the uBillboard from appearing-- the first maybe 30 pixels of the image are visible. I'm not sure where to begin in order to debug this. What should I be looking for? What are common reasons for plugins interfering with themes? I can post code, but I don't think that it makes sense to post the whole theme and my plugin. Thank you.
The most common problem are JavaScript conflicts, you can debug this by making sure you are using no conflict wrappers. Another thing you can adjust is the load order, sometimes there are errors when one script is loader before/after another. If you are relying on many 3rd party scripts it can be difficult, you might have to completely re-do some functionality. Also check to see if there are any CSS selectors clashing, make sure all the CSS the JavaScript references is unique and separate. Google chrome's inspect element is a great tool to debug and step through JavaScript.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugin development, themes" }
Making a Plugin work based on URL Location Is there any way to make my plugin work based on a URL instead of creating a page and attaching a shortcode? IE < and that would bring up the starting page of the plugin
You can do this by using the actions generate_rewrite_rules & template_redirect more info can be found at <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins" }
using custom taxonomies on non wp table? I'm building a program registration system that will have a complex data structure. There are programs (custom post type, CPT), teachers (CPT), registrations (custom table and meta table), payments (custom table and meta table), and later accommodations (CPT) and lastly Users (wp users table). I want to be able to use nice wordpress taxonomy features with my custom registration and payment tables. But I'm assuming I can't because the taxonomy system is only for the posts table. Is this correct? Basically I want to easily assign categories to registrations, and later be able to search on that, and have it flexible so the user can create their own categories. I ruled out using custom post type for the registrations and the payment tables only because then I would need a separate plugin to link everything up (scribu's post to post plugin) and it would make any mysql queries incredibly complicated. any advice would be greatly appreciated.
You can assign taxonomies to objects saved in tables other than the posts table. WordPress explicitly supports that (e.g. there is the function `_update_generic_term_count` to update the term count for those types of taxonomies) and even use it for links. I have used it once. Just register your taxonomies as you would for regular post types ( `register_taxonomy( 'your_taxonomy', 'registration', $args );` ). `register_taxonomy_for_object_type( 'your_taxonomy', 'registration' )` won't work though. I need to fill a bug report for that... (well, that's what I said to myself last time and I forgot... :) )
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "custom post types, custom taxonomy, wpdb" }
Customizing WP user profile with custom fields I want to allow the admin of a site I'm building to highly customize the WordPress user. This will be a highly advanced plugin so I'm fine creating a whole new page in the admin to do this customization (to avoid the weak hooks in the current user admin page). How can I enable the admin to easily create custom fields of different types without coding? It is kind of like a custom meta box, but for users instead of posts. I know BuddyPress does this for the front end, the latest version 1.5 is quite powerful. I'm sure it could be adapted for the admin area, but that might be a lot of work. I also have coded a custom solution, but it is feature poor at the moment and I'm wondering if there is a better solution out there.
There is an excellent plugin solution for this: CIMY user extra fields I'm all for control and pro writing your routines, if ready-made solutions are not 100% satisfactory, but in the case of extended user profiles I have never seen the need. I am using this plugin myself on 2 production sites, very happy with it.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom field, wp admin, users" }
Migrating Wordpress blog to New Webhosts, something is adding a # and gibberish I just migrated a WordPress blog from one host provider to another. Did a clean install on the new server, and everything seems to be working fine except all the permalinks for some reason add a string on the end like this: < That #.Tpq5DpzpP-g shouldn't be there. Any idea where this is coming from and how to eliminate it?
Actually, I just figured it out. In the migration, the settings were slightly different in the "Add This" plugin. I had selected "Track address bar shares" which added the # and the characters for tracking purposes. That is now removed.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "permalinks, migration" }
Is there a simple way to only show ads on a WordPress page once it becomes popular? I am looking for a simple way to minimize ads on a website I'm developing in WordPress by only showing ads (Google Adsense, to be precise) on the site upon a large influx of traffic. A large influx as defined as, say, more than 2x the normal hourly traffic (though the exact metric used to determine popularity is not that important to me). In other words, if ever the site sees a huge influx of traffic, I would like to begin delivering ads (to attempt to cover the incremental server costs). Otherwise, I would like to keep the site ad-free for the casual visitors. Is there a simple way, or plug-in, to do this in WordPress?
There is one wordpress plugin called "Search ads" that lets you do this. You can show adsense ads only to search engine users, which usually click on ads. As for regular readers from sources like bookmarks and manual address typing, ads will not show. Another plugin is "ad injection". If you wish to do adsense tracking on any website then you have to connect google adsense with google analytics profile. You have to use the tracking code of that profile on site which has adsense enabled.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "ads" }
How can I wrap html around the output of the_time function? My current code in functions.php: echo '<div class="post_date">'.the_time('d', '<div class="month">', '</div>').the_time('F', '<div class="day">', '</div>').the_time('Y', '<div class="year">', '</div>').'</div>'; But it only returns: 20April2011 No html around it, why? how can I fix this?
Please see this documentation for the usage about `the_time()`. You are not supposed to add html inside the parameter of `the_time()`. (edit: use `get_the_time()` with in string concatenation) To solve this, try this code: echo '<div class="post_date"><div class="month">'.get_the_time('F').'</div>'.'<div class="day">'.get_the_time('d').'</div><div class="year">'.get_the_time('Y').'</div></div>'; edit: corrected to the use of `get_the_time()`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme development, tags, html, date time" }
Wordpress Categories: Function using custom SQL to return array of specific category IDs I'm developing a custom theme which uses categories for positioning, all of which begin with an underscore (e.g. _position1). I have an SQL query as below to get a list of these categories (those starting with an underscore). SELECT name,term_id FROM `wp_terms` WHERE name LIKE '\_%'; How would I go about turning this into a function which returns a list of the category IDs? The idea being that this list of IDs can be passed to `wp_list_categories()` to be excluded e.g. (where get_positional_ids would use the SQL above to return a list of IDs) <?php $excludeids = get_positional_ids(); $args = array('exclude'=> $excludeids); wp_list_categories($args); ?> Any ideas on how to do this? Thanks.
If you use the built in **`get_terms`** function you end up with a quick one liner: function get_positional_ids(){ return get_terms( 'category', array('fields' => 'ids', 'name__like' => '_')); } no custom SQL, safe and simple.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "functions, sql, categories" }
Why does the first page of one category redirect to empty page 4? When I load this URL on my WP e-ecommerce site, it 301 redirects to page 4 which does not exist, and appears as a page with empty contents: Go to this URL: < And there will be a 301 redirect to: Which gives a 404 Not found error. It should display the first page of the category instead. Why does this happen? I can provide admin login details if that will help. This is a fresh installation with barely any changes, but with 4000 products imported in from a wordpress format XML file. Other categories work just fine and return some content.
I really hate the wp-e-commerce plugin. It turns out that the only products in that category were 'pending', i.e. not published yet. Even if they were moved to trash, and 'hide_emtpy => 1' was used on the categories list, the error still occurred. Only when the products were completely emptied out of the trash did the category disappear from the menu, and the problem was resolved that way. The reason it forwarded to page 4 is still unknown.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin wp e commerce, wp redirect, redirect" }
wp_nav_menu with default pages menu i'm using wp_nav_menu to generate a navigation menu for my theme. It works fine by selecting my created menus. But, what if i want to generate a list from my already created pages and subpages in wordpress ? I tried using wp_page_menu, which does what i want, but i cannot pass a css class parameter to the inside ul, in order to stylize my menu. Does anyone know how i can do that ?
I faced that problem in the past, however I remember my problem was the first link didn't have a class, after some research I solved it working with a structure similar to this one, take a look and let me know if it works :) <ul> <?php wp_list_pages('title_li='); ?> </ul> UPDATED....
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "theme development" }
Create a Static HTML Site from WordPress A friend of mine is investigating the use of WordPress for a dynamic site with some hierarchy. Really, at the moment he just wants "nothing fancier than photos and links between pages," but knowing him, it's going to get more complex from there. The tricky requirement, though, is that he needs to be able to archive the site. As in, output a static HTML version with embedded resources (photos) to a CD for manual distribution from time-to-time. I'm pretty sure this is possible with WP, since that's actually how several caching systems work. But I don't know of any plugins that give you a simple "export site to disc" function. Is there such a plugin?
Turn on pretty permalinks, and run a spider/archiver on the address of your website. This should give you a static site you can place on a CD/DVD/USB drive. You can use a tool such as < to do the latter part. If you're on linux you can use the following command: # Mirror website to a static copy for local browsing. # This means all links will be changed to point to the local files. # Note --html-extension will convert any CGI, ASP or PHP generated files to HTML (or anything else not .html). wget --mirror -w 2 -p --html-extension --convert-links -P <dir> You can also run a portable wordpress install off of a USB drive <
stackexchange-wordpress
{ "answer_score": 7, "question_score": 4, "tags": "plugin recommendation, export, static website" }
Deleting old posts I have around 30 old posts that I want to delete on my blog. Can I just delete them permanently or should I worry about the "errors" I will get on my google webmasters tools and redirect them somehow?
You should submit a request for Google to stop indexing them as soon as possible (accessible through the Google Webmaster Tools interface). I'm sure you know the purpose of posts, but is is that important to delete them? You could just leave them as an archive as posts were originally meant for. If you don't link to them, you don't have to worry about most viewers ever seeing them, just tell Google not to index the specific ones. There's no guarantee they won't continue to be crawled, but you can keep an eye on it and if they are still getting indexed you could delete them at that time.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, customization" }
How do I get WooCommerce to automatically recreate pages? I had to uninstall WooCommerce plugin (I deleted the tables it created as well) and now I reinstalled the plugin and I doesn't automatically recreate the WooCommerce Pages. Am I stuck having to manually create the pages myself? Is there a way to have it automatically regenerate the pages?
Just had the same problem. First uninstall the plugin. Then you have to delete all rows containing "woocommerce" in the table "wp_options" on your database. Especially "skip_install_woocommerce_pages". Now install the plugin again. The notification for automatically creating pages will pop up.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 11, "tags": "plugins, plugin recommendation, woocommerce offtopic, e commerce" }
Determine image height within Fancybox I have single.php rendered within Fancybox. For the purpose of resizing an image within single.php I am obtaining the image height in javascript using: var contentheight = jQuery('.postimage').height(); The first load of single.php within Fancybox successfully populates the "contentheight" variable and I am able to resize the image as per my needs. However, when I use Fancybox's left/right navigation buttons to navigate to next post, the "contentheight" variable never gets populated. Any ideas on what could be causing this erratic behavior?
Finally I came up with the solution to retrieve the image height using PHP getimagesize() and printing it as the ID of the image. Later, in JS I used: var contentheight = jQuery('.fluidimage').attr('id'); to retrieve the height and perform the necessary action. Here's the PHP code: <?php $imageurl = $pathtoimage; $image_size = getimagesize($imageurl); $image_height = $image_size[1]; // For image width, use $image_width = $image_size[0]; ?> <img id="<?php echo $image_height; ?>" class="fluidimage" src="<?php echo $imageurl; ?>" /> Here's JS code to transfer the image height to JS variable, which you use in your own function within the JS: var contentheight = jQuery('.fluidimage').attr('id');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "jquery" }
Run a plugin just 'once' per page reload I'm making a plugin that counts the number of times a visitor visits my site. I want to run the code in the plugin once per page load. What's a good action hook I can use ?
Basic idea is to use javascript to make an AJAX call back to the site which in turn save the hit because if you use PHP alone, then hits for cached pages won't be counted because no PHP is processed at that time. Study the code of WP-Postviews plugin < **Edit:** Hook may be fired twice in Firefox because it prefetches URL specified in HTML source as `<link rel='next' href=' />` Use this to remove that line from source `remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');`
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "plugins, actions" }
Nginx rewrite rules I am having some problems with the Nginx rewrite algorithm for WordPress. I am using this for the rewrite and it works good; server_name www.domain.com domain.com; if ($host != 'domain.com') { rewrite ^/(.*) permanent; } it makes this url; to this; which is good but with an url like this; it makes it; and i am not getting any error but the query is not working. What i am missing?
## The correct Nginx rewrite rules for WordPress are: location / { try_files $uri $uri/ /index.php?q=$uri&$args; } This sends everything through index.php and keeps the appended query string intact. If your running PHP-FPM you should also add this before your fastcgi_params as a security measure: location ~ \.php { try_files $uri =404; // fastcgi_param .... // fastcgi_param .... fastcgi_pass 127.0.0.1:9000; }
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "url rewriting, query, nginx" }
How many 'wp_insert_post' calls can be performed in one shot, in a very long 'for' loop? I'm working on a plugin which has bulk post inserts using a spreadsheet. This spreadsheet can have multiple thousand rows, each row corresponding to a post. I'm parsing this spreadsheet, looping over the parsed data and using `wp_insert_post` to insert the posts. I noticed that when I used a spreadsheet with around 2000 entries, only around 600 posts were inserted. Is there a limit on the number of `wp_insert_post` calls in one shot? Or could it be a limit on one shot `mysql` inserts? _(edited title for more clarity)_
Something tells me that it could be the maximum script execution timing out perhaps. The amount of memory your inserts are consuming could also be the culprit. Are you getting any error messages, blank screens or anything like that? You could try adding the following above where you're calling the wp_insert_post() function: set_time_limit(0);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "mysql, wp insert post" }
get_image_tag filter not working I'm trying to get the custom field data off an attachment and display it following the image tag in a page/post using the get_image_tag filter. I'm using the same function to get the same data and display it on the attachment field as well. That works perfectly using the the_content filter so I know the function is working ok and the data is being stored and retrieved. I feel like I'm missing something really obvious. Based on the few other questions I can find about the get_image_tag filter, it seems like there's either something buggy about its implementation or it doesn't run where it seems like it should. I can't even get it to append a string to the resulting $html variable and I don't get an error with wp_debug = true either. The code is on Pastebin at <
Turned out my "answer" was that I didn't really understand "get_image_tag." It only runs when you first insert an image. I was thinking that it ran every time the edit interface was loaded. From researching and talking with others, it seems the only way to get the metabox data onto existing images is some kind of regex on the database, probably adding a shortcode around imagines that don't have a caption and do have metabox values. Fun!
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "attachments, images, filters" }
and custom post_types to custom menu managed to create a custom menu area in the admin but now want to place 2 post types to it. They already exist - questions & answers, but can't find a way to put their menu links into the custom menu. add_action('admin_menu', 'mt_add_pages'); function mt_add_pages() { add_menu_page(__('Competition','comp'), __('Competition','comp'), 'manage_options', 'mt-top-level-handle', 'test_func', '', 5 ); add_submenu_page('mt-top-level-handle', __('Answers','comp-answers'), __('Answers','comp-answers'), 'manage_options', 'sub-page', 'test_func2'); } function test_func(){ echo 1; // question post_type links } function test_func2(){ echo 2; // answer post_type links } any help appreciated!
ended up defining it in the register_post_type function... 'show_in_menu' => 'mt-top-level-handle'
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, menus, add menu page" }
how to remove mandatory required fields in buddypress registration i have installed buddypress 1.5.1, wp 3.2.1. the registration field shows 5 mandatory fields to be filled, i need to limit this to 3, my site needs username, email, password( just like in tumblr ), how to remove these mandatory registration fields in buddypress registration. Is their any snippet/plugin to accomplish that
Finally i did find an hack for this problem Make the field fullname, confirm password as display:none Bind the data from username to fullname and from password to confirm password For eg ( a simple binding example ) <html> <head> <script src=" <script> $(document).ready(function(){ $('#target').bind('keyup keypress blur', function() { $('#target1').val($(this).val()); }); }); </script> </head> <body> <form> <fieldset> <label for="target">Type Something:</label> <input id="target" type="text" /> <input id="target1" type="text" /> </fieldset> </form> </body> </html> Do the above for your criteria I dont know whether its a perfect solution, but this solves my problem.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "buddypress, user registration, hacks" }
How to check via conditional tags for a single plugin page? I am developing a plugin. To embed the stylesheet I used `wp_enqueue_style()`. I want the CSS file to be only implemented at the plugin's page. I have already seen solutions with conditional tags, but neither `is_page()` nor `is_admin()` are fitting my request. I am able to implement the stylesheet only in the backend, but it is possible to implement it only on the plugin's page?
Check out this part of the WP Codex: Loading scripts only on plugin pages. The key is to hook in on the `admin_print_styles-{page}` action. The {page} part, aka hook suffix, is returned from the `add_submenu_page` function.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugin development, conditional tags, wp enqueue style" }
Add more rows on media picker I'm trying to add more rows in the media picker modal window. Is there any clean way to achieve doing this ? Thanks !
my plugin: < **I found a way to fix the pagination** There is a way you can 'hook' into paginate_links. There is no official hook for it, but you can change the $wp_query->found_posts variable. What I did here is 'hooking' into the paginate_links by abusing the media_upload_mime_type_links filter and setting a new value for $wp_query->found_posts. This filter is triggered just before paginate_links is called. function set_paginate_limit_mediapicker( $type_links ) { global $wp_query; $new_limit = 30; // set your limit $wp_query->found_posts = $wp_query->found_posts / ( $new_limit / 10 ); return $type_links; // not used } add_filter( 'media_upload_mime_type_links', 'set_paginate_limit_mediapicker', 1 ); I have made a WordPress plugin for the complete solution, which you will find in the repository. <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 4, "tags": "customization, media library" }
Anyone know a php snippet for showing the first 200 characters of the most recent post? I wish I knew PHP as well as I do Rails. I'd imagine this is fairly intuitive. Thanks!
Wordpress has an inbuilt function called `the_excerpt()` which echoes an excerpt of the post content. By default an excerpt is 55 characters. You can set it to 200 like so: function your_excerpt_length( $length ) { return 200; } add_filter( 'excerpt_length', 'your_excerpt_length' ); This should go into your theme's _functions.php_ , ideally. **EDIT:** To manipulate the excerpt more string, use the following: function your_excerpt_more($more) { return ''; } add_filter('excerpt_more', 'your_excerpt_more'); Given that you commented that `the_excerpt()` does not output the native _[...]_ , it is likely your theme already makes use of that filter somewhere else to replace the normal output with the described " _… Continue reading →_ " link. So rather than adding it again, find that in your theme.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, query" }
Why does get_term() require taxonomy? Are term_ids not unique? A related WPSE question asks how to get the term by specifying ID only, without specifying taxonomy. My question is more philosophical. Generally, stuff in WP core is there for a reason. I'm trying to understand why term_id can't be the primary key for the term - why do we need the taxonomy as well? Can a single term record be a member of multiple taxonomies? That's certainly not currently supported in the API. Is there a use case where this might be desirable? Or is the required `$taxonomy` parameter in `get_term()` a vestigial tail from an earlier incarnation of the database structure?
I've logged a ticket against this with trac: < However, it turns out that for the time being it IS necessary, as WordPress currently (since 2.x) has a bug that DOES associate two terms with the same name to the same term_id! So it IS possible (though incorrect) for a single term to be associated with more than one taxonomy. See this bug: < It's pretty wide-reaching so implementing the fix will need to be unit-tested very thoroughly. I'll try to remember to update this question if there are any developments.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 8, "tags": "taxonomy, database, core" }
Problem with special character WordPress I have a WordPress and everything seems perfectly fine but I have this page that has title 77% and it shows error 404 page. How can I fix this? I am kind of sure it is because of the % in the 77%. The permalink uses the 77 but for some reason wordpress still doesn't like that % in the title. What can I do to fix this while keeping the % there?
There is nothing you can do, the % symbol is not a neutral character and whatever 2 characters immediatly follow it are used to represent a character. This is called percent encoding. < For example, to encode a % you would use %25. Thus the answer is: **No, it is not possible to fix this while keeping the % there, because URLs are percent encoded.** Should by some stroke of luck you manage to get it working, I would recommend still avoiding it due to the misuse of the % symbol
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "permalinks, 404 error" }
Changing "Lost Password Email Link" to custom password reset page On the Wordpress site I am working on, subscribers will not be allowed to see anything in the backend at all. Because of that I am creating a custom pages for the Wordpress login page that subscribers can access. On the login form there is a "Lost Password" link. I have managed to redirect most things to my own custom pages, but when someone enters their username in the lost password field, it sends the user an email with a link in it, which redirects them to the Wordpress backend to reset their password. I want to be able to edit that link in the email and redirect them to my own password reset page, but I can't find anywhere to hook in. Can someone give me the right action for hooking into that? I don't want to change any of the Wordpress Core code. Any help would be appreciated. Thanks!
The filter you're looking for is `retrieve_password_message`. The relevant function can be found in _wp-login.php (starting on line 165, wp 3.2.x)_ , the filter is applied in line 231.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "redirect, login, hooks" }
Jquery checkbox -show posts with checked tags Using jquery, How do I show a checkbox with the list of tags in the sidebar, and only show posts of the checked tag? I cant seem to find this anywhere
Grab and go, buddy! Had fun figuring this one out :) * Create a file and upload to your plugins. * Call list_ajax_tags() in theme where you want to display these tags. * Modify to suit your needs < (had trouble formatting the code here)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "widgets, jquery, tags" }
Custom Taxonomy link out the loop how can i get Custom taxonomy URL by taxonomy ID outside the loop like get_category_link();
The function you're looking for is: get_term_link(); Here is the Codex entry on it: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "taxonomy" }
How to add the same widget twice? I noticed that if you put the same widget in two different widget slots (primary and secondary for instance) only the first one will appear on the page. The second slot will be empty. How to solve that problem and allow my widget (a custom menu) to appear twice on my page ?
It sounds like a problem with that particular widget or if not that then your theme. Try again with a default theme and one of the wp widgets. Works fine with those.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "widgets" }
How do i put a sidebar on my post permalink page? I am using the twenty-eleven theme and every page (except the 404) has a sidebar. However the post permalink page (/2011/11/post-name/) does not. How do i put the sidebar onto it? I tried looking for its php file on codex but it is very unclear which file is the correct one.
The template for the display of a single post is `single.php` Add `<?php get_sidebar(); ?>` in the second last line of that file just above `<?php get_footer(); ?>` and the sidebar will show. **Note:** This will get overwritten, if you ever update the theme.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts" }
How do i put a dropdown list of ALL my post in the sidebar menu? In "Main Sidebar" i would like to add a dropdown list of ALL my post. How can i do that? I found various plugins and none of them did what i wanted (for example one only list the post i have on that page). How might i put all my post into a dropdown/menu list in the sidebar?
<?php // query for all posts $your_query = new WP_Query( 'posts_per_page=-1' ); echo '<select>'. '<option value="" selected="selected">Select a post</option>'; // loop through posts while ( $your_query->have_posts() ) : $your_query->the_post(); echo '<option value="'; the_permalink(); echo '">'; the_title(); echo '</option>'; endwhile; echo '</select>'; // reset post data wp_reset_postdata(); ?> Obviously, that does nothing unless you bind some js/jQuery to the change event.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, menus" }
wp_schedule_event only when admin is visited On the documentation page it says "The action will trigger when someone visits your WordPress site, if the scheduled time has passed." Is it possible to make this action trigger only when the admin is visited? I am trying to prevent a slow operation from impacting users on the front side.
In your event callback function check to see if the user id the admin then run the function else just reschedule it. So using the example from the codex's page you linked in the question it would be something like this: function my_activation() { if ( !wp_next_scheduled( 'my_hourly_event' ) ) { wp_schedule_event(time(), 'hourly', 'my_hourly_event'); } } add_action('wp', 'my_activation'); function do_this_hourly() { // do something every hour only if this is the admin if (!current_user_can('administrator')){ // time()+1800 = 1/2 hour from now. wp_schedule_single_event(time()+1800, 'my_hourly_event'); return; }else{ //do your thing } }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "admin, cron" }
How to deal with a GET variable of 'name'? I'd like to have a custom registration confirmation page live within a WordPress site. I can provide a URL for this page to an external site. When the registration is successful the URL has several parameters, one of which is 'name' (which of course is a reserved word in WordPress) and a 404/page not found results. The URL (get variables are coming from an external site, so I have no control over them) is something like: What is the best way to handle such a situation? I'd like to be able to use the 'name' value in the page, so I don't want to just discard. Thanks for any suggestions.
In case it's useful for someone else in this situation, I ended up creating a page outside WordPress which renames the 'name' parameter (to 'username') and then redirects to the page I originally wanted to hit. My code for this external page is: <?php $data = array('UID' => $_GET['UID'], 'username' => $_GET['name'], 'ANI' => $_GET['ANI'], 'PIN' => $_GET['PIN'], 'conferenceUID' => $_GET['conferenceUID'], 'role' => $_GET['role'], 'email' => $_GET['email'], 'notes' => $_GET['notes'], 'custom2' => $_GET['custom2'], 'custom1' => $_GET['custom1'], 'inboundAccessID' => $_GET['inboundAccessID'], 'time_created' => $_GET['time_created'], 'callinNumber' => $_GET['callinNumber']); header( 'Location: ) ; ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "php, url rewriting, urls" }
Style custom columns in admin panels (especially to adjust column cell widths) I am using Wordpress as a CMS for a project which makes extensive use of custom post types. I need to display columns in admin panels for each custom post type in a different way. I've already created the necessary columns and populated them. What I need to do is to adjust the CSS a bit. Most importantly I'm trying to tweak the width of certain columns. For example I don't need a column listing the post ID to be as wide as the post name. I enqueued a stylesheet in the admin panels for my custom post types but I can't get it right to style the column widths. I tried to adjust the max-width of th or td elements, but it's ineffective. From firebug I can see the css style is there, but it's doing nothing. While I could find a lot of tutorials to add/edit custom columns, I didn't really gather much information about how to style such columns. Any hint? Thank you!
I found a solution that works for me! I dropped this code in functions.php : add_action('admin_head', 'my_column_width'); function my_column_width() { echo '<style type="text/css">'; echo '.column-mycolumn { text-align: center; width:60px !important; overflow:hidden }'; echo '</style>'; }
stackexchange-wordpress
{ "answer_score": 33, "question_score": 18, "tags": "custom post types, css, cms, columns, wp enqueue style" }
How to get posts using category slug in ClassiPress? I'm using the ClassiPress theme as a base for a new theme. If you have worked with classipress, you should know that classipress handles its own category using the taxonomy `ad_cat`. That said, I have a category named `7star` and the following query to get the posts inside that category: $the_query = new WP_Query( array('post_type'=>'ad_listing','category_name'=> '7star') ); Unfortunately this query does not work. It only fetches the posts withing categories that are of type `category` not `ad_cat`. Anybody got any idea how to solve this? I'm trying to avoid using manual sql query.
Well, I should have used the `tax_query` parameter. Something like the following: $the_query = new WP_Query( array('post_type'=>'ad_listing', 'tax_query' => array( array( 'taxonomy' => 'ad_cat', 'field' => 'slug', 'terms' => '7star' ) ) ) );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "categories, custom taxonomy, taxonomy, loop" }
jquery: getting contents of #content field on post page I managed to get the #content field html with this jquery call: jQuery("#content").html() This seems to be failing though on "Add New Post" pages. Any tips on how to get the contents of the #content div? Cheers
The div `#editorcontainer` contains a regular textarea `#content` and an iframe `#content_ifr`. The `#content` is filled with the saved contents of the post when the page loads. This means that any live edits of the content won't be returned when calling `jQuery("#content").html()`. For the same reason, you get an empty string in the case of a new post. Where you really need to look for the live updated contents is in the iframe, which is used by the WYSIWYG editor. Here's how: jQuery('#content_ifr').contents().find('#tinymce').html(); Also see: jquery/javascript: accessing contents of an iframe.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, jquery, content" }
custom data in url Inside a WordPress site I load a external xml file parse it and show some links. The link looks like this: `domain.com/prof/vac/item?guid=1234&title=foo` This works, but now i would like the url to look like this: `domain.com/prof/vac/item/1234-bar` when I create a link to that url and click it it says it kind find the page. However if i just put the guid in and forget about the title it works: `domain.com/prof/vac/item/1234` can anyone point me in the right direction?
You can use the details here in this answer to solve your problem : Pretty URL with add_query_var Something along the lines of add_rewrite_endpoint('item', array(EP_PAGES)); resulting in a rewrite rule that would let you use /prof/vac/item/1234 which you would then check in the vac pages template for a query variable 'item' and pull its value ( in this case 1234 ) Of course one must then avoid having a page with the slug 'item' else bad things will happen.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, permalinks" }
Why does WP allow to view and media item as a page Every media item that is uploaded to Wordpress can be viewed in a page. This can be seen if you browse to the Media section, hover on any item and click view. Are there any benefits to this because I am not seeing any at the moment. Can this feature be edited (or removed)?
It is desirable because you can modify that page, to introduce extra functionality. e.g.: * Comments * Meta data * custom fields * titles * descriptions * Image EXIF * showing geolocation data * video/audio players * thumbnails of other images attached to the post, e.g. the other pictures in the gallery If it troubles you, you can 'remove' the feature, by making an attachment.php template, and putting a wp_redirect() to the images full size URL. I would avoid this however, as this is a good opportunity to show off and make the most of your content, e.g.: < Here, Matt Mullenwegs site uses attachment pages for gallery posts individual images, you can comment on images, you can navigate to the next image in the gallery and back, and upwards.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "images, media, media library" }