INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
"Folding" links in the blogroll I've got a site (this one) with too many links in the blogroll. I want to keep them there, but to maybe have them "fold" in the menu (after some of them showing without the unfolding of the menu) Any solutions for that? Update: When I wrote "folding" I meant that, for (a rough) example, there would be a shuffling of the links showing and that at some point there would be a "press here for more links" button - that will poll down more of the links.
there is a plugin called "better blogroll" I guess it would help you do what you want . I had it installed on one of my sites, but site currently down , so can't really test - but as far as i remember it does the work u asking for < give it a look anyway and when my site is back up , i will re-confirm this
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "sidebar, links, widgets, blogroll" }
Running WordPress on low-end hardware/resources? I knew about Atom-based dedicated servers, but these plug-class servers take it to whole new level of low-end extreme. Most of WordPress optimization talk is about surviving on shared hosting or scaling up. I got curious - how viable is it to run WordPress on such low-end, but dedicated hardware? At which point will CPU or slow storage become bottleneck? How will it compare to generic shared hosting (even lower resources, but no neighbors and freedom to optimize).
I think it really breaks down to your traffic. The slower the hardware, the slower (the already slow) page generation. It's not specific to WP, it's the same for all large php scripts. If you get a server hit every now and then, as on a dev box or a family blog, it's no big deal. It'll just spit out pages more slowly. If you get concurrent hits on a regular basis, your site will get knocked off of the web quite easily. Also note that many a low end shared host stuffs multiple sites on low end hardware. It's obviously not as low end as what you linked to, but I wouldn't expect that much of a difference in performance as compared to an overstuffed shared server.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 5, "tags": "hosting, optimization" }
How to override normal Wordpress search in Buddypress? hi i have wordpress and buddypress installed and i wanted to be able to search through forum posts, blog posts and other info all over the site. i found Search Engine (Wordpress Plugin) and installed it. after a brief indexing process i was able to perform all of my search requests but the problem is that when this plugin is enabled and i try to search for something inside the wp-admin, there are no results. when i turn the plguin off the wp-admin search runs. i also tried google search plugin but the outcome was the same. how can i keep my search plugin and the normal plugin work together? thanks
I've solved it by using this tutorial: Creating The sitewide global/unified search Page for your Buddypress Theme (28 Apr 2010; Buddy Dev)
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "plugins, plugin recommendation, buddypress, search" }
Custom WordPress Feeds operators? I wish to create a feed of my blog which is a feed of two categories OR the feed of some tag and not the feed of some other category I know how to do "have a feed of this1 + this2 categories", but how do you do "OR" in a feed URL? (and in general, is more complex operators on the URL possible, and how?) Links that don't answer the question (but help define it): * < * <
Feeds are essentially WordPress Loop with customized template. So it will take regular `query_posts()` arguments in URL. For example see `/wp-includes/feed-rss2.php` template. Since `query_posts()` doesn't handle OR logic you describe it isn't possible with URL alone. You will have to write your own feed template that runs and concatenates two sets of post. I think it will work simply as page template, but can also be hooked into existing feed mechanics, see `do_feed()`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "feed, customization" }
How can I combine posts of different types in one hierarchy? I'd like to create a custom post type and add this as a child post of some but not all existing standard posts (which are not pages). Is this possible? Can I, for example, create a custom post type and then include this in other posts using a shortcode? Is there a better way to do this using custom taxonomies?
> Is there a better way to do this using custom taxonomies? You're right on the money there. Rather than try to make a custom post into the child of a standard post (because you can't), I'd recommend using a custom taxonomy to order things. Essentially, you could build a custom hierarchical taxonomy and use it to "categorize" both standard posts and custom posts. You'd mark your standard posts as the parent in the taxonomy and your custom posts as the child. ### A second option Another option would be to use a custom field for parental inheritance. This might be a bit faster to code and more intuitive to use (plus it will give you some added control). Add a custom meta field to your custom post type called "parents." This can then be a list of post IDs the child post should be nested under. When you need to call up the list, you can do a quick query to `SELECT` all of your custom posts that have the parent ID in question in their "parents" list.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "custom post types, hierarchical" }
SQL query to select posts from multiple categories I have built a query to select posts within a category. Works fine. But when I choose to add a secondary filter to exclude a category, the query return the same result set, as if the secondary category filter is being ignored. In the following the query should select all posts in category 7 and exclude those in category 10: $querystr = "SELECT * FROM $wpdb->posts LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE ($wpdb->term_taxonomy.term_id = 7 AND $wpdb->term_taxonomy.term_id <> 10 AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->posts.post_type = 'post' AND $wpdb->posts.post_status = 'publish')"; Can someone help?
I would use the built in API like Rarst mentioned. You could do something like this: $just_seven = new WP_Query( array( 'category__in' => array( 7 ), 'category__not_in' => array( 10 ) ) ); You would then have those items in `$just_seven->posts`. However, if you MUST use a direct SQL statement, I'd suggest using `INNER JOIN` instead of `LEFT JOIN`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "query, mysql" }
How can I display a drop-down select of Post Names I would like to add a custom write panel to a custom post type. I'm looking at the the code here: < I can get the custom write panel to appear on a standard post edit page but not for my registered custom post type. add_meta_box( 'int_parent_meta', ucfirst( $key ) . 'Options', 'display_meta_box', 'name-of-custom-post-type', 'normal', 'high' ); If I replace 'name-of-custom-post-type' with 'post' in the above line, the panel appears on the post edit screen. Anyone know what I'm missing here? Wordpress version is 3.0.1
the fourth argument should be the name of the custom post type, as defined when you created the post type. see < For a clearer explanation of how to successfully create metaboxes, see this tutorial the second argument should be the callback function, you can create the drop down HTML in a function, and place the function name in this argument and you'll have your pull down menu.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom post types, post meta" }
Displaying Remote Data inside of Theme admin I would like to add a button under my theme manager which shows a thumbnail listing of available skins (that did not ship with the theme when it was installed). I'd like to feed this listing from a file on a central server that I maintain. Looking for some advice on how to best implement this within WordPress. I will periodically add new skins to the available listing and would like for users of my theme to be able to view them and perhaps even see a "new" icon when a new skin is first launched. _I'm also interested in the merits of hosting and serving the file from Amazon s3 vs my own server_
Your best bet here would be a specialized RSS feed set up on your server. You could bundle a dashboard widget with your theme that automatically pulls this RSS feed and displays the thumbnails and a description of the new skins that are listed on your site. ### Step 1: RSS Feed First, decide what information you want to display in the widget. I recommend a skin title, the thumbnail, a short description, and a link to further information. Store this information as XML on your server. ### Step 2: Dashboard Widget Create a dashboard widget that routinely checks this feed and displays updated items on the dashboard. You can use just about any existing RSS reader widget as a model here... updates to your server-hosted XML file will automatically appear on remote WordPress dashboards in this section.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "theme development" }
Resizing Uploading Images in Bulk? I have been running a blog for a friend and over the last months she has been adding insane amounts of images taken directly from a DSLR. Each takes up around 5-6 MB so the site is now slow to load and is consuming large amounts of bandwidth and disk size. I was looking on the smush.it plugin, but it doesn't seem to do it ad-hock and also, doesn't do bulk resize. Is there some easy way to fix this on the server with a plugin? Would prefer that instead of download all images and do bulk resize. Big thanks.
You need the bulk image resize utility: < I have used that numerous times and it does a fantastic job!
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "plugin recommendation, images" }
orderby in query_posts I have the following line to change my wp query slightly. The posts are by this ordered by the value in the custom field "wpfp_favorites". The value is allways an integer. Posts with value 0-9 is sorted correctly, but when a post has value 10 (or more i guess) its not listed above posts with 9. query_posts('meta_key=wpfp_favorites&orderby=meta_value'); What is wrong? You can see the problem in "action" here: <
take a look here: < you need to change orderby=meta_value to orderby=meta_value_num -> than you value gets treated as an integer not a string! query_posts('meta_key=wpfp_favorites&orderby=meta_value_num'); i would pass an array instead of a string like query_posts( array( 'meta_key'=>'wpfp_favorites', 'orderby'=>'meta_value_num' ); you dont have to but its easier to read and WordPress converts that string to an array anyway....
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "customization" }
wp_get_archives() display months even if there is no posts Hay, the example on the wp_get_archives documentation page shows how to show a list of all the posts, by months. However if there is no posts for a month, the month doesnt get displayed. So an example list could look like this Janauary (5) March (1) April (1) ... Is there a way to force the list to display a month, even if no posts exist? Thanks
I've looked over code and it doesn't seem possible with this function. Months and their post counts are fetched with raw SQL query, for months without posts there are simply no records in database. It doesn't make effort to skip empty month, it simply doesn't get those from database.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "archives, list, wp get archives" }
How would I create a plugin for my shortcodes? All tutorials I have found say to add your shortcodes to functions.php in your theme. I would like to break that away from my theme and put that in a plugin so I can share these shortcodes between my network of blogs. Is there a reference or tutorial on creating these shortcodes in a plugin?
Code in `functions.php` and plugins works in almost exactly same way (except than stage at which it is loaded and some plugin-specific hooks). Basically you just take your code out of `functions.php`, place it in plugin and it still works. It is good practice to use naming conventions and checking for functions definitions so it doesn't explode if you accidentally load both copies. But there will be no difference in how code actually works. See Writing a Plugin for a starting point.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 5, "tags": "plugin development, shortcode" }
How to increase the file size limit for media uploads? How can I change the Maximum upload file size? I would like to be able to upload 10Mb at a time. !alt text
This is due to the PHP limitations on file size uploads. If you have access to your php.ini file, you can modify the following lines: upload_max_filesize = 10M post_max_size = 10M max_execution_time = 300 If you don't have access to the php.ini file (such as a hosting situation), you may need to contact your webhost and see if they will increase it for you. I have also seen users create a php.ini file with just these values and place it in the file where WordPress is installed. If your PHP instance allows for "inherited configurations" it will allow these local settings to override the global. The other solution would be to add the code dynamically into WordPress to make this change for you. This article has a nice way of doing it through a "plugin". I've seen dubious results from this approach (some report success, some report no success) so I can't say for sure if it will work for you.
stackexchange-wordpress
{ "answer_score": 12, "question_score": 9, "tags": "wp admin, media, uploads" }
Easy lightbox effect inside of dashboard widget I've got a dashboard widget that pulls from an RSS feed on my central server and allows anyone using my theme to see newly available skins. Using the dashboard widget, I'm currently presenting a thumbnail image of the skin along with a description and a link to download. I'd like to enable the thumbnail so that when clicked, it will open the full size image in a lightbox over the wordpress dashboard. I want to install as little extras as possible to make this possible. My theme is already including jquery-1.4.2.min.js and I'd like to build off that if possible. Any ideas much appreciated.
WordPress already ships with both jQuery and jQuery UI. Rather than including them manually, you can call them by using `wp_enqueue_script`. I'm personally a big fan of the jQuery UI Dialog setup (which also ships with WordPress) ... it should be easy enough to attach a click handler to your thumbnail such that clicking launches a jQuery dialog.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme development, dashboard" }
How to change language? Sorry for this complete newbie question, but I googled it and cannot find this simple information. I just installed Wordpress today. Right now all text on my Wordpress Blog is in English: "Home", "About", "Comments", etc. How can I change the language? * * * Update: I am actually not out of the woods yet with this one. I have: 1. located the fr_FR.mo file and copied it into a new directory '/wp-content/languages/' 2. Modified the wp-config.php file to have the following line into it: > define ('WPLANG', 'fr_FR'); Unfortunately I still get the interface in English. Any help would be much appreciated. * * * Ok, I found the problem: I was adding the line: > define ('WPLANG', 'fr_FR'); when in fact there was _already_ another line of code: > define ('WPLANG', ); which was probably overriding my bit of code. Thank you for your help.
See Installing WordPress in Your Language in the codex.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "multi language" }
Survey plugin recommendations What is a good plugin to do surveys for wordpress. I can think of creating a custom contact form 7 - but i was having problem in the formatting and separating it from the body of the post visually. and it doesn't store survey result in some document or spreadsheet, so eventually i'll have to track everything manually. so - i am on the hunt for a survey specific plugin. the questions are simple, i need option buttons, check boxes, text boxes - and like 10 questions max - nothing fancy. Thanks in advance for the help Suggestions other than poll-daddy are welcomed :)
Have you try google docs? you can embed their form as iframe which is easiest solution.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "plugins" }
Assigning Multiple Layout Designs with Custom Pages in WordPress? ( **Moderator's note:** This question was previously titled _"How to add multiple custom page in wordpress"_ ) I am developing a WordPress site and right now I have a custom home page and others are default WordPress pages. Now I want to add one **another custom page** for some landing page. It will not be sub-page. This page's layout & design is different. How Can I add this to my wordpress website?
Sounds like what you want is a **Custom Page Template** It's quite simple, if you want to call your layout **"My Special Layout"** just create a file in your Theme Directory calling it whatever you like _(I'd call it "page-my-special-layout.php" but that's not required)_ and add the following comment to the top of the template file: <?php /* Template Name: My Special Layout */ After the comment put in whatever HTML you need to design your desired page. Then once you have the Template in your Theme directory and you load the Page Editor in the WordPress admin console you'll be given the option to assign it as your Page Template; simple as that: !WordPress Page Editor with Page Template Selection Highlighted
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "custom post types, theme development, design" }
How can I remove <div ="mceTemp"> using built in wordpress filters I'm getting image fields wrapped in tags and would like to remove the surrounding divs, but only if they are of class "mceTemp". Anyone know of an efficient way to do this? Also, should those Divs even be there?
I agree with hakre - something funky is going on elsewhere, those shouldnt be appearing. As a sidenote, you could use the jQuery unwrap() function to remove those divs. jQuery('div.mceTemp img').unwrap(); <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "tinymce" }
404 when fetching image from wp-content/uploads/ I get 404 status when fetching images, and the http still contains that image. Image shows up in a browser, but the 404 code breaks some applications. calls to wp-content/uploads/ are redirected in .htaccess: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteRule (.*) /index.php?getfile=$1 [L] </IfModule> Why do I get a 404 status if the image is in there and is served?
Problem solved. The plugin "User Access Manager" was found guilty of inserting a .htaccess file into `wp-content/uploads/` and not handling calls properly afterwards. I don't know how UAM plugin could be fixed, but It's ok to remove the .htaccess file. Nothing else depends on it. (at least in my case)
stackexchange-wordpress
{ "answer_score": 7, "question_score": 3, "tags": "404 error, mod rewrite" }
Horizontal scroller with post_thumbnail's Attempting to create a horizontal scroller using post_thumbnail's. I've made a filterable portfolio section using this tutorial: < but my attempts to make it a horizontal scroller have failed, i've tried several different jQuery image scroller plugins to attempt it but none have worked. Can anyone give advice on how to achieve what i'm looking to do? Thanks!
I did it on a few sites. An example is below. If you want the jQuery code for it, I can give it you. It is a list of post thumbnails with their post titles shown below them. paragonhondainfo.com
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "jquery, post thumbnails" }
How to set the cache for the built-in SimplePie feed parser? I'm using the built-in SimplePie, AKA `fetch_feed()`, to retrieve a feed, and I want to be able to adjust the cache time from an admin menu. SimplePie itself is well documented, but not so much the WordPress implementation of it. Any thoughts on the best way to set the cache duration?
Cache duration value (defaults to 43200 seconds) is set when feed object is generated and passed through `wp_feed_cache_transient_lifetime` filter with additional argument being feed URL. This allows to conveniently filter it both globally and for specific feeds. See fetch_feed() source for this and other hooks you can use to modify its behavior.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "rss, cache, simplepie, feed" }
Duplicate (or more) custom fields on many posts. Is there an easy way to clean them up? I am in the process of cleaning up a site after migrating it from a single install of WP to a multi-site install of WP. I have noticed many, many duplicate custom fields for each post. I assume this is from older versions of plugins that didn't check for the field before adding another. In the migration I am dropping these plugins. Could I just delete these fields in the back-end using SQL or is there a better way? SELECT * FROM `wp_5_postmeta` WHERE `meta_key` IN ("podPressPostSpecific", "aktt_tweeted", "podPressMedia") Only using `DELETE` obviously.
If you're not going to use those plugins, have at it. No reason to keep them around. Direct SQL query should be fine. Related: `add_post_meta()` has a nifty argument to prevent this very problem. The fourth argument is a boolean, declaring whether the meta should be singular: add_post_meta( $post->ID, 'my_foo_bar', 'value', true ); Source: Add Post Meta | WP Codex
stackexchange-wordpress
{ "answer_score": 6, "question_score": 0, "tags": "custom field" }
Can I refresh the thumbnails programmatically? I would like to be able to refresh the thumbnail cache programmatically, not sure where to hook it, but at present any design changes mean re-uploading loads of images!
You may want to look at the plugin Regenerate Thumbnails by Viper007Bond. Basically, this is how to do it: function regenerateThumbnails() { $images = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%'" ); foreach ( $images as $image ) { $id = $image->ID; $fullsizepath = get_attached_file( $id ); if ( false === $fullsizepath || !file_exists($fullsizepath) ) return; if ( wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $fullsizepath ) ) ) return true; else return false; } } Note: This function is not very scalable. It will loop through all the images and regenerate thumbnails one by one, which may consume a large amount of memory. So, you may want to enhance it.
stackexchange-wordpress
{ "answer_score": 13, "question_score": 8, "tags": "post thumbnails" }
Wordpress crop tool greyed out The wordpress crop tool is greyed out for me in Firefox 3.6 (and IE7/8). I have disabled firefox add-ons and tried the solution here: Wordpress Image Editor not working - conflict? But this hasn't resolved the issue. Anyone know how wordpress determines whether to enable the crop button? WP version is 3.0.1 thanks,
I'm 99% sure this was caused by the firephp plugin.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 13, "tags": "images, editor" }
$ not defined using jQuery in WordPress I know that jQuery is loaded, because I can switch out the `$` for 'jQuery' and everything behaves as expected, but this will be a messy script if I can't fix this This script: jQuery(document).ready(function(){ $("ul.vimeo_desc_feed li a").click(function(){ alert($(this).attr('href')); return false; }) }); Produces the error **`$ is not a function`** This script: jQuery(document).ready(function(){ jQuery("ul.vimeo_desc_feed li a").click(function(){ alert(jQuery(this).attr('href')); return false; }) }); works fine.
You can wrap your javascript inside a self-invoking function, then pass `jQuery` as an argument to it, using `$` as the local variable name. For example: (function($) { $(document).ready(function(){ $("ul.vimeo_desc_feed li a").click(function(){ alert($(this).attr('href')); return false; }) }); }(jQuery)); should work as intended. If I remember correctly the WP-supplied version of jQuery (the one you get if you `wp_enqueue_script('jquery')`) puts jQuery in no-conflict immediately, causing `$` to be undefined.
stackexchange-wordpress
{ "answer_score": 51, "question_score": 38, "tags": "jquery" }
How to add 'Insert HTML Table' button to TinyMCE in admin? I am trying to figure out how to change the default buttons on the TinyMCE editor in the Wordpress admin. Specifically, I would like to provide an 'insert table' button. How do I do that?
TinyMCE Advanced plugin. I almost never launch a site without it.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "wp admin, tinymce" }
How to find time last viewed? I want to run an update script on pages that haven't been viewed and updated within X days. I'm using post meta to cache some related RSS feed data, and I want it updated once a week or two, but only if the page has actually been viewed within the last two or three weeks, bots included. Is there an internal counter or whatnot that has this data, or am I going to have to build something that stores the UNIX timestamp as post meta upon page view?
Post views log/count is not available natively. It is resource-intensive (database writes are much more expensive than reads) and won't work (if done in pure PHP) with most caching plugins. There is number of plugins/services that offers Analytics via JS- or image-based tracking. Your best bet is to let such service handle analytics and pull data from there.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "cache, post meta, views, timestamp" }
Category slug field missing with registered custom taxonomy I have registered a new taxonomy term using the same code on two different sites. On one site (a vanilla install), If I go to my taxonomy term in the admin menu, I see a 'slug' option for the add category screen. On my other site, with all plugins disabled, this slug option does not appear. Anyone know what might cause this? Register taxonomy code: register_taxonomy( 'my_topics', array( 'post', 'page' ), array( 'hierarchical' => true, 'label' => 'my Categories', 'query_var' => 'topics', 'rewrite' => array('slug' => 'topics') ) );
The value for global_terms_enabled for multisite is stored in wp_sitemeta < I switched this to off and the category slug field reappears. If anyone can comment on whether its safe to switch this off, that would be greatly appreciated.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom taxonomy" }
Is there a quick way to find out what posts haven't been tagged? Basically exactly what the title says, I am running 3.0.1 and want to be able to quickly flag up posts that have no tags currently assigned to them.
I think this could get resource-intensive quickly, but fastest API way would be to create list of tags and query for posts that do not belong to any: $tags = get_tags(); $ids = array(); foreach ( $tags as $tag ) $ids[] = $tag->term_id; $posts = get_posts( array( 'tag__not_in' => $ids ) ); If you have large amount of tags or need to do this often it is probably better to look into building raw SQL query for this.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "wp admin, customization, tags" }
How to configure WP filesystem access in Linux (Ubuntu Server)? Ubuntu Server, LAMP stack, freshly self-installed WordPress. Apparently I can't use `direct` filesystem access method because files are owned by different owners (WP core unpacked by me and files WP creates by `www-data`). I tried my credentials for `ftp` method, but either something goes wrong or there is simply no FTP server installed in stack. Googled up suggestion to install `libssh2-php` and use `ssh` method. Filling my credentials (except keys, no idea what to put there) it worked for deleting plugins, but fails to install new ones with following error: Downloading install package from Unpacking the package… Could not copy file. /var/www/wp-content/upgrade/serverbuddy-by-pluginbuddy.tmp/ I am little lost which method to poke. Should I try to tweak and enforce `direct`? Or how to fix `ssh`? Or just install some ftp server?
Ideally, you install php-suexec, so that the php script runs as the file's owner. This allows the direct method to be used without requiring any permission changes.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "linux, filesystem, ssh" }
How do you get formatted content of a post using the WordPress API? I tried using <?php $my_id = 7; $post_id_7 = get_post($my_id); echo $post_id_7->post_content; ?> based on the documentation here. The article I'm trying to retrieve has Short Code, which is picked up by a plugin on my site, and then formatted into HTML. The problem is when I output the post_content to the site, the short code isn't picked up by the plugin, and I effectively just write out the short code straight to the browser. Is there a way to get the short code evaluated properly? Or am I using the wrong function?
Post's object field contains raw content as it is stored in database. This should format it to how it appears when retrieved with template tags: $content = apply_filters('the_content', $content); This filters runs number of formatting functions, including shortcodes parsing. Something close to this: >>>>> the_content 8 (object) WP_Embed -> run_shortcode (1) (object) WP_Embed -> autoembed (1) 10 wptexturize (1) convert_smilies (1) convert_chars (1) wpautop (1) shortcode_unautop (1) prepend_attachment (1) 11 capital_P_dangit (1) do_shortcode (1)
stackexchange-wordpress
{ "answer_score": 24, "question_score": 9, "tags": "customization" }
Recommended Themes for a Developer-related Topics Blog? _( **Moderator's note:** Was previously titled: "What is the best theme used for a developer like me?")_ I'm a developer and write a blog to share my knowledge with readers. I'm looking for a theme which is best suited with me but not sure which ones. Please share if you've ever visited a nice theme.
## Related Questions As this is a community wiki question, I'll start to link related questions in the hope of use. Not a real answer so far but probably of help. Feel free to extend: * What theme is good for posting code?
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "themes" }
How to totally get rid of Category in my blog? I prefer using tags and have no interest in using the categories. All my posts now are labeled with a category named "Uncategorized" and I want to turn them off! I want no more categories at all. How can I do that? Please help! **[Edit]** I'm using `wordpress.com`, not `wordpress.org`
There is no way at all to remove the _uncategorized_ category from a wordpress.com webblog. It's not even possible with a self hosted wordpress w/o extensively hack the theme and the core. The _uncategorized_ category is a placeholder for a post not having any category. You can't even delete that category to not have any categories. So sorry but the answer is **no, there is no way to remove categories**. Not on wordpress.com and only with a lot of changing the overall design of wordpress on a own copy.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "categories, wordpress.com hosting, tags" }
Is there any W3C compatible Share & Follow plugin? I'm trying to build a fully W3C compatible blog. But I couldn't find a fully W3C compatible plugin. I want a simple plugin that provides share, tweet and like icons, sociable style. I don't want my readers to click a button to show share buttons, only buttons i want the plugin to provide. Any suggestions?
Best way is to skip plugin, add share buttons manually and then tweak. There is usually some degree of flexibility to share buttons code. But plugins generally disregard that and go for defaults. If you want it to validate perfectly you will likely have to do it button by button.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, customization" }
why does this text overlaps in the sidebar? I've been trying, without success, to remove to sliding of the text: "ggplot+background+grid+colour" From the left sidebar here Any suggestions on how to do this?
Almost missed it, looks fine in Opera. :) Basically these words are not treated as words, but as one giant word. And browsers (well, except Opera) have trouble interpreting how to wrap it. Not sure how to achieve nice wrapping, but quick fix would be adding CSS rule `overflow: hidden;` to `.side-widget ul{}`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "css, sidebar" }
Order by menu_order and title? We can order pages by title. Also we can sort them by menu_order. **Is it possible, to order pages by menu_order and title at the same time?**
Use `'orderby' => 'title menu_order'` or `&orderby=title menu_order` (depending of the syntax you use for your query parameters).
stackexchange-wordpress
{ "answer_score": 13, "question_score": 4, "tags": "pages" }
how to add custom fields into new & update post page? I want to add new whole section of custom fields in admin UI of * new post page * edit post page Could somebody suggest any nice code example?
I think you'll find this a simple and useful tutorial to do what you want: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin development, custom field" }
Wordpress shopping cart that supports 2 tier product variation options I need a WordPress shopping cart that will produce 2 tier product variations. For example if you pick 'option 1' for a product, sub-options 'x' 'y' 'z' will be revealed and if you pick 'option 2', sub-options 'a' 'b' 'c' will be revealed. Im OK with a commercial cart, but I haven't found any that specifically list this functionality in their documentation and since they are commercial, I can't access their respective support forums to find out more with out first purchasing the cart. Is there a cart that supports this kind of functionality?
The e-commerce plugin Shopp for Wordpress seems to allow 2-tier product variation options. It used to be a bit buggy in the 2-tier product variation department, but I think that they've fixed those issues with the plugin now. Keep in mind that Shopp isn't free, but in my opinion it's worth every dollar. MarketPress is supposedly going to support this as well, but WPMU Dev might take a while to release a new version of it.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "plugins, plugin recommendation, e commerce" }
Any amazing Wordpress MultiSite sites? I'm just curious, because I love wordpress.
visit for demos <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "customization" }
WordPress custom post type Single.php? I have a WordPress custom post-type setup. I've created single-[customposttype].php However instead of displaying only the requested custom-post-type it goes to the URL, then displays all of the posts in the custom-type. Here's a copy of the code i'm currently using: <?php query_posts("post_type=shorts"); while (have_posts()) : the_post(); ?> <div class="header-promo"> <?php echo get_post_meta($post->ID, "mo_short_embed", true); ?> </div> <div class="content-details"> <h1><?php the_title(); ?></h1> <?php the_content(); ?> </div> Thanks in advance :)
Just remove `query_posts("post_type=shorts");` from your code.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "custom post types, page template" }
get_children() Not Working with orderby Parameter I am trying to use the `orderby` parameter in the `get_children` function as below: $navigation = get_children(array( 'post_parent' => $parent->ID, 'orderby' => 'menu_order' )); But it is having no effect on the result; it is still ordering by the default creation date. Any ideas?
Are you sure you need this specific function? Documentation (both Codex and inline) is verrry confusing. And it supposedly fetches things like attachments, which probably aren't relevant for navigation... Try this: get_posts( array( 'post_type' => 'page', 'post_parent' => $parent->ID, 'orderby' => 'menu_order' ) );
stackexchange-wordpress
{ "answer_score": 14, "question_score": 6, "tags": "posts, pages, get posts, get children" }
Highlight custom widgets in the admin area? I have created some custom widgets for my client to use, but I want to make them stand out amidst the fifteen or so standard widgets in the admin area. How can I do this? _I have solved this problem myself and will place the solution here, but please feel free it add a better solution if you have one._
All widgets in the admin area get an `id` in the style `widget-[global_counter]_[widget_key]-[widget_id]`, like `widget-59_monkeyman_widget_shortcut-5` (installed widget) or `widget-11_monkeyman_widget_shortcut-__i__` (an uninstalled widget in the list). If your widget key contains something unique for all your widgets (like your company name), you can use this and add a substring attribute CSS selector (which works in most browsers). In my case `div.widget[id*=_monkeyman_]` does the trick, so I add a little CSS snippet in the `widgets.php` admin page header: add_action('admin_print_styles-widgets.php', 'monkeyman_widgets_style'); function monkeyman_widgets_style() { echo <<<EOF <style type="text/css"> div.widget[id*=_monkeyman_] .widget-title { color: #2191bf; } </style> EOF; } This gives me the following result: !Highlighted widgets amongst regular widgets
stackexchange-wordpress
{ "answer_score": 8, "question_score": 5, "tags": "wp admin, widgets, sidebar, customization" }
Hosting WordPress on Azure? Can I host WordPress/WordPress MU installation on Microsoft's Azure cloud platform? Does anyone have any advice or experience hosting WordPress on Azure?
WordPress seems to be one of the poster children of PHP on Azure, so you can find many resources explaining how to install it.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 9, "tags": "hosting" }
Display All Post Attachments and Assign Class to the Last Image? I have a function `get_images()` in which I would like to display all image attachments for the current post (or page) in a list with the last image having a `class="last"` attribute to mark it as the last image in the list. The code below is my first pass at getting the attached images to display, however, its only listing one image out of the loop so my foreach is botched... function get_images() { global $post; $attachment = array_values(get_children(array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'numberposts' => 1 ))); if ( $attachment ) { foreach($attachment as $attachmentImage) { echo '<img src="' . wp_get_attachment_url($attachmentImage->ID) . '" class="post-attachment" />'; } } }
This should do it, I think: function get_images() { global $post; $attachment = get_children(array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'numberposts' => -1 ), ARRAY_N ); if ( $attachment ) { $attachment_count = count($attachment); foreach($i=0; $i < $attachment_count; $i++) { $last = ($i == ($attachment_count-1) ) ? ' last' : ''; echo '<img src="' . wp_get_attachment_url($attachment[$i]->ID) . '" class="post-attachment'.$last.'" />'; } } }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "php, post thumbnails" }
How can I customize the link when an attached image is clicked? I have attached several images to a post. When viewing the images in the theme, each image is linked to a larger version of itself. I would like to change this link to direct to a specific URL. However, when I change the URL under "Link URL" under attachment options, the link does not stick after clicking "Save All Changes". It always reverts to the link to the image itself. Is there another way to create custom links on attached images? Note: I'm not trying to alter the link TO the image, I'm trying to create a custom link href when the image is clicked.
You say you click the _Save All Changes_ button. I think this means you are trying to edit the images via the _Upload/Insert_ images button above the editor? It's confusing, but this is not the place to edit an individual image that you already inserted into the post. In the _Gallery_ tab you can edit settings for the image in the shared _Media browser_ , but not for already inserted images. You need to do that by clicking on the image and then clicking the first button that appears (showing an image). This will give you a slightly different editing window, with an _Update_ button at the bottom. If the `rel` attribute of the image link is set to `attachment`, `_fix_attachment_links()` will replace the link with permalinks to the attachment when you save the post. So make sure that when you edit the image link, you first click the _"None"_ button to clear this value, or go to the _Advanced Settings_ tab and edit _Link Rel_ so it doesn't contain `attachment`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "attachments" }
Why can't I exclude private posts from this query? My WP query to fetch some custom posts should exclude private posts, but this query is returning all posts, not just public ones: `$wp_query = new WP_Query( 'post_type=listing&post_status!=private&posts_per_page=9&meta_key=location_level1_value&orderby=location_level1_value&order=ASC&paged='.$paged);` I've also tried using post_status=-private, but that didn't work either... What have I done wrong?
I have to wonder if post_status=public would successfully exclude. That way it's just targeting the public posts.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "wp admin, query" }
anything like add_meta_box for categories? I want to add few custom fields to categories. So I am looking for something like `add_meta_box` but for categories. Is there any **WP function** like that for **categories**?
You can add content to the category edit pages by hooking into the `edit_category_form_fields` (still in the form table) or `edit_category_form` (outside the table but before the submit button). Similar hooks exist for tags or custom taxonomies, check the source. To handle these extra values you need to find a good hook yourself, make sure you handle it before `editedtag` redirects you. There are no clean meta box handlers, you need to write most code yourself. But please let us know how you did it, it might be interesting for others!
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "plugin development, categories, custom field" }
How to convert all links to no follow links of particlular section of a webpage I just wanna convert all links to no follow links which are being displayed in sidebar or footer or comments. How can i do this?
`wp_rel_nofollow()` does this for you. It is already called on `pre_comment_content`, so comments should be covered. For sidebars and footers, this depends on the widgets and other code you use there, but it should be possible to call that function there too.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "links" }
Make WordPress WYSIWYG not strip out iframe's I have a blog that I often need to insert iframes into posts for various reasons (don't ask why just trust me!) When I use the "visual" view to edit my posts the WYSIWYG constatantly strips out my iframes ... I know I can keep the iframes in the post if I use the "html" view and only view/save from the "html" view ... however I'd **_really_** like to be able to use the normal WYSIWYG to edit my post **_without_** having to resort to the "html" view. Is there anything I can do to disable this behavior? I've seen this post, that suggests editing `wp-includes/js/tinymce/tiny_mce_config.php`, but I'd really rather avoid doing something like that that would likely just break in a upgrade!
If you don't want to write your own code there is a plugin to allow embedding an `<iframe>`: * **Embed IFrame Plugin for WordPress** Then just use the shortcode like this: [iframe 400 500]
stackexchange-wordpress
{ "answer_score": 9, "question_score": 17, "tags": "wysiwyg, iframe" }
Including a JS source with an admin page The administration part for my plugin is divided into several pages and for some pages I would like to enqueue a JS source which would add jQuery functionality to various elements. Right now this is my approach: function admin_register_init() { if ($_GET['page'] == 'worldexplorer_admin_location_hub') wp_enqueue_script('worldexplorer_admin_hub', WP_PLUGIN_URL.'/worldexplorer/admin/admin_hub.js'); } add_action('admin_init', 'admin_register_init'); However, this requires me to check the page index of the $_GET array. Is there another way to achieve what I wish to do?
I believe there is a hook `admin_print_scripts-{$page}` which might fit. See this Load scripts only on plugin pages
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "plugin development, admin" }
plugin to search entire posts, blogs, forum, users hi can anyone recommend a good search engine plugin that allows the users to search for posts, blogs, forums, users, etc and shows the results as a combined result and not divided into categories? we need a good plugin in our site that will not override the normal wordpress search. we're using wordpress and buddypress. thanks
maybe this Premium Plugin can help you: <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "plugins, plugin recommendation, search, buddypress" }
comments are coming on improper posts If someone comments on any post on my site, that comment gets displayed under another post. Moreover, if I login to my site. And click on logout link (under comment section) it redirects me to another article after log out. One possible reason as I read on many places, may be showing related posts. I am using following code for this <?php do_action('erp-show-related-posts', array('title'=>'Most Related Post', 'num_to_display'=>10, 'no_rp_text'=>'No relevant article found.')); ?> Which is basically given by a wordpress plugin efficient related post.
It sounds to me like you mucked up the query and the comment form thinks the user's on the wrong post. Try adding wp_reset_query(); to your theme right before your theme adds the comment form. If that doesn't work, do this: wp_reset_query(); global $post, wp_query; $post = $wp_query->post; setup_postdata($post);
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "comments" }
What changes we need to make to a theme so it can be installed as a MU Theme? I downloaded the free Wootheme Irrestible and **if installed on a stand alone Wordpress** , works **very well**. Now, if we **enable Multiple Sites** on 3.x and set this theme to be the theme of a new site it simply **does not work** out-of-the-box. As WooThemes Support is only for paid customers, and being this a free theme, I can ask for support directly, so I'm kindly ask here for any help. current site with IrrestibleTheme using WP 3.0.1 multi site enable is located at > < website settings: !alt text As I don't know what might be wrong, here is all settings to this 2nd website: * settings * more settings * and more * and more * and more
You really need to specify how it does not work. There are no multisite-specific theme tags. 99% of the themes out there for WordPress work in a network. If you're getting errors, check your error logs. If it's not grabbing image th8umbnails, that's a known issue - not with multisite or the timthumb script, but how the theme itself calls the images. < Edit: actually, I have tested the Irresistible theme in mu. Worked for me. A quick checked reveals it's looking for images in a subfolder that is not there.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "customization, themes, multisite, options" }
Can Shopp Commercial Plugin be hacked to display radio buttons instead of Dropdowns? I need to know if the 'Shopp' e-commerce plugin can be modified to display radio buttons instead of drop down menus for the product options. I don't need you to tell me how this can be done (though that would certainly be welcome), just if it is possible. I don't want to invest in Shopp unless it is something that has been done before and there is a thread or article on the Shopp board that explains the hack. EDIT: Seriously, I just need someone w/ access to the Shopp user forums to login and run a quick search for that kind of mod.
This example highlights the versatility of interface options you can create by using radio inputs to select a product variation rather than the default menus. This section of code could be used in place of the variations code block in either the product.php template file or the category.php template file (if you want variation inputs in your category products list). <?php if(shopp('product','has-variations')): ?> <ul class="variations"> <?php while(shopp('product','variations')): ?> <li> <label> <input type="radio" name="products[<?php shopp('product','id'); ?>][price]" value="<?php shopp('product','variation','id'); ?>" /> <?php shopp('product','variation','label'); ?> </label> </li> <?php endwhile; ?> </ul> <?php endif; ?> **Warning** Using this will make it able to add empty products to your cart (if the product has variations)
stackexchange-wordpress
{ "answer_score": 3, "question_score": -1, "tags": "plugins, plugin recommendation, e commerce, plugin shopp" }
Feature Survey - What would you want in a resume theme? I've been toying with the idea of developing a custom resume/portfolio theme for some time ... but just haven't gotten around to it. Lately, though, I've fallen in love with a few new site designs and feel that it's time we had a truly interactive and dynamic theme to power resumes and portfolios with WordPress. So here it is, your opportunity to participate in a WP crowdsourcing project: What features would you _most_ like to see in a resume/portfolio theme for WordPress and why?
I would like to see dynamically expanding detail boxes, so you can provide optionally more details on specific areas of experience (such as a code snippet, or more complicated project information) should the interested party wish for more. That way you keep it simple and clean yet show them there is more under the hood should they wish to see it.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "theme development, customization" }
Drag & drop HTML5 file upload into the media library? Has anyone seen a drag&drop plugin for files into the media library for WP? Would be very interested with such a plugin. **Edit** \- Seems like Google will sponsor this project on GSoC 2011
It appears that this idea is being addressed in trac: <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 6, "tags": "plugin recommendation" }
Enabling Sessions in WordPress 3.0 Im using a wfcart in my WordPress site but for some reason on certain pages WordPress drops the session I'm wondering if there is a way to enable sessions in WordPress 3?
If you need to manually enable the session globally, use this in your functions.php (I included a line for manually setting a session variable as an example, not required): add_action('init', 'session_manager'); function session_manager() { if (!session_id()) { session_start(); } $_SESSION['foo'] = 'bar'; } and if you wanted to manually clear the session on an event (like logging out): add_action('wp_logout', 'session_logout'); function session_logout() { session_destroy(); }
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "customization, functions" }
Using wordpress template tags within an array A bit of a noob PHP question coming up. I am trying to create a generic archive style view for my custom post types. Ideally I want to create one generic template that can be used for all post-types. Currently I use this as my have_posts query to bring in all posts of 'custom-post-type' <?php $args=array( 'post_type' => 'custom-post-type.', 'post_status' => 'publish', 'posts_per_page' => -1, 'caller_get_posts'=> 1 ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> What I want to do is swap out custom-post-type with the slug of the page so that whenever this template is assigned to a page, it will look for a custom-post-type of that name & list them. Alternatively if you know of a better way of doing it - great! Cheers, George
As @Rarst mentioned in the previous comment this is going to be patched in WP3.1 The template hierarchy is "archive-customposttypename.php". WordPress 3.1 template hierarchy
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, templates, php" }
Personalized Gallery what are my options? In my game website I would like to implement a Screenshot page where my registered users can upload images to it (it might be more then 1 screenshot page, 1 for the users and 1 for the game in question what I mean is users can upload and the staff will be using the game website available images so it would be 2 different categories or w/e). Once an image is uploaded it will be pending for approval before becoming available on the gallery page. I would like that the page that will display the list of images will be displaying it as thumbnail or resized images to a smaller size and the bigger image will show uppon click or something alike. **What i would like to know is:** * Is there a plugin with such features ? * What are my options here ? * * * I've got a good programming background, if i were to make such changes what would be my best approch to it ? like creating a custom template page or what ?
I just found this plugin that entirelly fits my needs while I modificating the NextGen so I tought I should post it here in case some one was looking for something like this: < With this I can simple set the minimun access to subscribers and add a tag to a page and it will allow registered users to upload images to a pre-selected gallery.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "customization, images, users, uploads, gallery" }
Display some arbitrary HTML or content in a sidebar I need to have a bit of frequently changing content in a sidebar (the time and location of the next meeting of a club). What I'd really like is a nice widget that displays `the_content()` of a selected page or just has a rich text field and displays what's in that. I figured there would be something like this around, but I can't find it. (Maybe because the search terms are too cloudy and overloaded?) I wrote a widget that displays `the_content()` of a hardcoded page, but that's not an ideal solution.
How about the Rich Widget?
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin recommendation, widgets" }
How can I permanently cache or "archive" a WP blog without needing future maintenance I have a client who has an annual complete makeover of their website design and content, but they still want their old sites available to view (each with that year's respective design/CSS). Once these blogs are "archived", I don't want to have to maintain them any more w.r.t. updating plugins and core files. Previously, when I have left plugins un-updated for too long, I have had some security issues (or at least, that's what my host blamed the last few hack attempts on). I know there are auto-updating plugins out there, but I don't know about you - I always have to check that nothing is broken with each update (whether auto-updated or manual). I've considered just generating an html mirror, but are there any other "maintenance free" way I can "archive" my old blogs?
I think HTML mirror is the way to go here. There is no point keeping dynamic site that doesn't need to be. And leaving it unmaintained is not really possible on auto-pilot - even if updates are automatic there is no guarantee some plugin won't get just dropped by developer. Alternatively you can build multi-design site. It's not that hard to load stylesheets and templates conditionally. Of course that would be considerable amount of work comparing to HTML mirror.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "cache, archives, backup, maintenance" }
Blog page problems Right, please excuse the stupid question. On my new blog I want the home page to be the "home" page I've created, and not the list of articles... that's fine, I go to `Settings -> Reading -> Front page displays` and change `Front page` to `Home`. But now I want `/blog/` to list my articles, however I get a 404 :S I'm a bit stuck on this one, any help would be mucho appreciated.
This depends on how the index.php of your theme is coded. If it is a standard blog index page (as it is in 2010), all you need to do is: 1. create a page named "blog" (or whatever you fancy), no need to add any content or select any template, 2. in wp-dashboard > Settings > Reading: * tick "static front page" * select your "home" page as the Front Page * select the "blog" page you created as the Posts Page, again, it depends on the default index.php of your WordPress theme. It may also help to regenerate the permalinks, go to wp-dashbaord > Settings > Permalinks and click "save changes" (no need to change anything). Watch for any warning messages on updating .htaccess (and update manually if required), then check again.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "customization, theme development, blog page" }
Create a url structure for my blogs based on categories and sub-cats My blog design heavily relies on categories and sub-categories. I would like the url structure to be dependent on that. How can I make the url's support the same? I would like it to be like: ` It should also support further sub-categories if any. And if I have any pages, It should follow the same structure just that it should be substituted by the page name. _**Further info:_** > I am using Wordpress 3.0.1 and hence am using the custom menu feature which allows me to combine my pages and categories into one awesome menu.
With the following as a permalink structure; /%category%/%postname/ The category slug is added to the URL. Subcategories, if any, appear as nested directories. So you end up with ; * /category/your-post-slug/ And if subcategories are used * /category/subcategory/your-post-slug
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "customization, permalinks, menus" }
How does one flush rules on theme activation or deactivation only? Flushing rules is clearly an important part of creating themes with custom post types. See here and here. Does anyone have any example code of how to flush rules from functions.php? I'm a little surprised this isn't covered in the custom post type pages of the Codex. Update: I tried adding this to functions.php, but it didn't work: register_deactivation_hook( __FILE__, array(&$this,'deactivate' ) ); function deactivate() { global $wp_rewrite; $wp_rewrite->flush_rules(); }
While the solutions provided here do still work, WordPress has evolved since and does now (since 3.3, I believe) provide direct hooks for theme activation. `after_switch_theme` will fire on theme activation and `switch_theme` before deactivating an old theme. Hence the up-to-date answer is: function reflush_rules() { global $wp_rewrite; $wp_rewrite->flush_rules(); } add_action( 'after_switch_theme', 'reflush_rules' );
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "custom post types, permalinks" }
How do I set up "blog" posts to a page other than the main/home page? Someone set me up with some custom work on top od another them and now I want to add a "what's new"/"blog"/"latest news" type page that is accessible from the main menu and is NOT the home page. How can I do that? It is not obvious to me how that is done. Thanks.
In the admin area, Go to **Settings » Reading** , Choose ' **A Static Page** ' from the first set of options & select the two pages you would like to use as the front-page & blog/news page. Hope this helps, G
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "blog page" }
How often is functions.php loaded? Trying to get my head round functions.php and am wondering how often it is loaded?
Simple answer is once. As any other PHP file otherwise it would likely cause crash because of function redefinitions. More complex answer is there can be actually two different `functions.php` loading - one for parent theme and one for child theme. Tricky part here is that child theme's loads before the parent's, which can at times be counter-intuitive for some purposes (like working with hooks).
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "functions" }
Getting Post Comments for post ID using WP_Query() and a Custom Loop? _( **Moderator's note:** The original title was "Is there a way to get post comments by post ID on a custom loop using WP-Query()?")_ Hi! I'm running a custom loop **using WP_Query** , that only displays one post from a specific category on the **home.php** page, like so: <?php $pr_q = "cat=11&posts_per_page=1"; $pregunta_q = new WP_Query($pr_q); ?> <?php while ($pregunta_q->have_posts()) : $pregunta_q->the_post(); ?> <!-- post stuff here --> <?php endwhile; ?> Is there any way to have it show comments for that specific post? I tried including the comments template inside the loop and nothing. Is there a function that loads the comments for a specific post that I can use inside home.php or anywhere else?
To be able to use the comments template in your loops, add global $withcomments; $withcomments = true;
stackexchange-wordpress
{ "answer_score": 4, "question_score": 7, "tags": "comments, wp query, homepage, customization, loop" }
My Category is too big on the Menu what can i do? Currently I have a small amount of 100 categories and my MENU goes crazy big and I would like to be able to do 2 things if possible: * First category menu with limited amount categories sorted by hits * Second category menu with limited amount of categories choose by myself Is there any simple way to acomplish this either manually editing part of the code but yet allowing me to render the category by the wordpress code instead of having to type each by hand or a plugin with already such features ? PS: I was trying to use the search for this but even using "Category Menu too big" there were so many unrelated answer that it was hard to find anything good to my case.
I have moved away from looking for a plugin and adventured myself into making my own modifications, see Custom sidebar category listing? In regards my question here I have found the follow: * Yes, it is possible to limit the amount of items listed on the category by setting the number argument that can be used with wp_list_categories and get_categories. * A personalized menu can be create with only the categories you wish to allow on it on the Menu that code can be re-used on the sidebar, only problem is that it will be manually updated/controlled.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, multisite, customization, categories" }
In WordPress how do you create a custom post type with the author's name in the slug? I'm trying to build a new WordPress theme using register_post_type to create a custom post type called listings. I would like each listing to have the following permalink structure: < I'm not quite sure how to achieve this with the CPT controls listed in the Codex. Previously, I have a achieved a similar effect by creating a custom structure in Permalink Settings: /%author%/%postname%/ It has been suggested on the main forum that I use wp_rewrite, but wp_rewrite only seems to deal with incoming requests and does not change the way CPT posts are created. To illustrate further with an image, I want to change the /listings/ part of the permalink URL to the post author's name. See image below. !alt text
My plugin Custom Post Permalinks allows you to set permalink structures for custom post types and it supports post authors as part of a permastruct. However, while my plugin will enable you to set up that structure, I don't suggest using that structure. That structure will essentially make WordPress interpret all top-level pages as 404 errors (and second level pages, I think). You should be fine if you add the post type to anchor the beginning of the structure like this: /%post_type%/%author%/%postname%/
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "custom post types, url rewriting" }
Best Sitemap Plugin for 1M+ pages A client of mine has a VERY, VERY, VERY large WordPress site (over 1 million pages). Is there a sitemap plugin that can handle this (would need to create sitemap indexes)? Their site have very shallow crawldepth, so they figure a sitemap would help a lot.
Quick search shows that next major update of Google XML Sitemaps plugin will have index-based sitemap. Overall sitemap is not a guarantee that site will be crawled and I'd also look into other ways to improve (better and more extensive navigation, more internal links, etc).
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins" }
How can I alter the display of category listings via sidebar.php? I would like to alter the default categories widget code so that it does not show any categories which are children of the uncategorized (id=1) category. Can I do this via my sidebar.php or functions.php code?
If memory serves, there's an exclude argument, which isn't available in the widget but which should be around for the category list template tag. < It should hide subcategories if you're listing them hierarchically.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme development" }
Corrupt Wordpress Database The weirdest Wordpress problem ever I think. A clients site with a large database of posts has got a mind of it's own. One minute everything seems fine, the next posts, categories and tags are missing. At the minute the dashboard is telling me there's 2309 posts in 9 categories but when I click the categories link in admin there's none in the list. I can see all posts in admin but whereas they used to be assigned to categories and have tags listed, they're all now "Uncategorized" with "No Tags". Obviously the wordpress database is corrupt in some way but where to start to try fix it!? Here's what I've tested so far: Plugins – I turned off all current plugins. Theme – I tried a different theme/template. Wordpress Core – I re-uploaded the latest wordpress version. Updates – I updated all plugins and wordpress core. Repair Database - I checked and tried to repair the database in Cpanel but it timed out. Help!?
You're probably running into the joys of MySQL's MyISAM engine... From within MySQL (or PhpMyAdmin), use REPAIR TABLE xyz statements again, repeatedly, on each of your tables (or rather, your terms related tables, since these are the ones that sound corrupt) to see if this solves anything. If those fail, there are a few documented workarounds: < Once things are recovered, run OPTIMIZE TABLE xyz statements on each table, and then alter the engine of the database and each table to make it use InnoDB. InnoDB clutters the catalog somewhat (especially if you drop a database or large tables), but -- being ACID compliant -- it's a hell of a lot less error prone than MyISAM.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "database" }
Make posts 410 dynamically I have a site where posts get created and expired often. I want to add 410 status code to all posts that expire so that Search Engines remove them. I want to know if wordpress provides a provision to do this? or is this possible at all? Any suggestions how to achieve this would be very helpful. Thanks
Just did some testing and seems there is a bug here. Newly created draft posts are not accessible on front-end. Search bot (or anyone else not logged in and using special preview URL) gets 404 error on them. But if you publish and change back to draft then post remains available by direct link (does get removed from index). For this reason I would stay away from using draft for this purpose. I would try to use custom field to mark post as expired and filter `the_content` to show informational message and set headers with `status_header()` function.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "redirect" }
Can images be automatically compressed? having trouble educating clients to compress their images, and would quite like wordpress to compress images to predefined size (normally, 800px long edge, 72dpi) and discard the original
Use < Add this to your functions.php: function prune_image_sizes($sizes) { // You can add other size like that for remove those sizes // unset($sizes['medium']); unset($sizes['large']); return $sizes; } add_filter('intermediate_image_sizes_advanced', 'prune_image_sizes'); Set your large image option to 800px in media options panel. So what did you do? System will not create large size of image but will reduce original image size to large size ( 800px ) option. Most of developer dont like it but when client have to upload lots of image and dont have hosting space so much, this will helps. (Sorry for my english)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "images" }
Should everything in functions.php be hooked or filtered? Considering how often functions.php is called, shouldn't all of its contents be hooked or filtered into core WP functions like init?
It can be used for much about anything that requires php... You'd only use hooks if you don't want to execute the php logic immediately. This is usually the case, but not always. Likewise, you'd typically use the WP API. But not always either...
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "functions" }
Possible to "Attach" images to multiple posts without inserting or uploading twice? How can I attach images to a post which have already been attached to other posts without having to upload them twice? I don't want to insert the images into the post, I simply want to attach the same set of images to multiple posts. As of WP.3.0.1 it does not appear that this is possible, however, if the "Media Library" tab of the "Insert Image" wizard had a column labeled "Attach" with a checkbox next to each image in the media library, this could be easily done. How difficult a task would it be to add this functionality?
As you've noted it's not possible out of the box. The feature was supposed to make it into 2.9, got postponed until 3.2, and assuming they reject the post2post table mike and I crave for it'll probably be postponed again. You'll have better luck creating a custom taxonomy in the meanwhile, and "tagging" images tied to this or that post accordingly. That'll give you an n-n relationship. As for difficulty, I'd say not easy. Adding extra fields in the media upload/insert screens, in so far as I've experienced it (i.e. a huge media plugin) is a bloody mess.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 5, "tags": "theme development, media" }
Removing the "Website" Field from Comments and Replies? In an effort to combat comment spam, I'd like to hide or remove the _"Website"_ field from the _"Leave a Reply"_ section for page and site comments. I have no desire to increase others page rankings by having them embed their URLs in my sites comments, which seems to be what 99% of the comments on my site are wanting to do. I'm using the Twenty Ten theme if that makes any difference in the answer. Thanks!
Create a file in `wp-content/plugins/` with this code: <?php /* Plugin Name: Get Rid of Comment Websites */ function my_custom_comment_fields( $fields ){ if(isset($fields['url'])) unset($fields['url']); return $fields; } add_filter( 'comment_form_default_fields', 'my_custom_comment_fields' ); Normally, I'd say put it into your theme's functions.php file, but I wouldn't recommend doing that for a theme that could update like Twenty Ten. This way will let you add this functionality as a plugin which can be disabled.
stackexchange-wordpress
{ "answer_score": 13, "question_score": 8, "tags": "comments, spam, comment form" }
404 Error Problems with sCategory Permalink plugin Seems throughout the day my blog seems to show 404 page errors with no pattern. I have to manually change the permalinks from /blog/%scategory%/%postname%/ to default, then back to /blog/%scategory%/%postname%/ in order to fix the permalink issue. This has been a problem for us for the past six months, and our site gets 10k views a day. While that is not a lot, it does give us a huge problem when at certain periods of the day we have a huge issue where none of our Posts work, yet Pages continue to work fine. I have extensive conversation on this issue at this post ( where I have narrowed a few things down, and at this point I believe the sCategory Permalink is the issue. I need help understanding what is causing this issue, and more importantly fixing this so it never happens again. ANY help would be greatly appreciated.
I stopped using that plugin a long time ago. I don't think you really need it anymore honestly. I just remember it did the same thing that I was able to do when I disabled it, so I stopped using it. I don't think its still supported by the developer either, so may be out of date. I may be wrong, but then again I use the least amount of plugins as I can and build most things into my themes.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "permalinks, 404 error" }
Replicate network plugins without having to configure it for each subsite? I was wondering if there is a simple way to replicate my configurations for all the subsites once i have activated a network plugin without having to go thru each and configure it manually ? * Upgrade a set or single network plugin(s) with the same configuration to all subsites
I've had to write some custom stuff to copy settings across blogs. Currently I've got a plugin with two textareas: 1. A read-only box with a base64 encoded serialized string of all the blog options (`wp_options`) I care about (in this case, widgets, sidebars, and options from a specific plugin) 2. A field that can accept the same encoded string copied from another blog So, I don't know of a good way besides dumping the data via WordPress's `get_option()` or SQL queries, and loading the data back in on another database.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "multisite, customization" }
I changed post_type and now I receive 404 errors I changed a custom post_type to a different name. Now when I view a single page with the post_type I receive a 404 page. How do I debug? Is there a WP log I can view the functions call?
Just try to update permalinks (i.e. Trigger a flush of the rewrite rules).
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "custom post types, debug" }
Can I get an auto-populated dropdown list of other custom posts in a custom post edit page? I have a custom post type, and in one of the custom meta-fields, I would like to present a drop-down list of the other (published) custom posts in order to link two custom posts. Specifically, I have a Film type, and some Films are screened as double features with other films. Currently, I just have a field for the other film's post ID, and my template manually handles the URL linking for that. But it would be much more user friendly to offer a drop-down list with titles of previously published Films. How would I do this?
The Post 2 Post plugin by Scribu is exactly what I needed.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, customization" }
How to make sexy bookmarks plugin work in WPMU We have Wordpress 3.0 working as multi site, and we want all the blogs in the system to have the plugin "sexy bookmarks". But it seems to be working only in the main blog. Does anyone know how to make it work in all blogs (what code to add to make it work that way)? Or is there a plugin like sexy bookmarks that adds social network icons to each post that works in a multi site version of Wordpress 3.0?
If the plugin is alreayd activated, then you cannot network activate it. because you already turned it on. Turn it off. Network activate it. You still have to configure it for each blog.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "plugins, customization, multisite" }
Checking if a Page has an Associated Term? I am looking for a way to do some conditional logic on terms associated with a post. Essentially I created my own custom taxonomy for "age groups" and have created three terms for them. Kids, Teens, Adults... In the admin area I want to check the terms which apply to a specific post and on the frontend of the site within my page template I want to show a specific image if the term was associated with the post or a different one if the term was not associated. Does anyone have a solution for this... I thought the following code example would work but it does not. (BTW - what I am doing here is changing the image based off css). <li id="kids-<?php if ( is_term( 'Kids' , 'age_groups' ) ) { echo 'on'; } else {echo 'off';} ?>">Kids Programs</li>
Hi **@NetConstructor:** First thing, _assuming_ your logic worked you can use the ternary operator to simplify your example: <li id="kids-<?php echo is_term('Kids','age_groups') ? 'on' : 'off'; ?>">Kids Programs</li> The issue seems to be that `is_term()` is used to check if a term exists, not if it is associated with a particular post. I think what you really want is `is_object_in_term()` _(which assumes that you are inThe Loop, i.e. that `$post` has an appropriate value):_ <li id="kids-<?php echo is_object_in_term($post->ID,'age_groups','Kids') ? 'on' : 'off'; ?>">Kids Programs</li> P.S. Assuming `is_term()` had been the right function, it has actually been deprecated; `term_exists()` replaces `is_term()`; just fyi.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 2, "tags": "custom taxonomy, taxonomy, conditional content, terms" }
What is the http://go2.wordpress.com/ redirect? Hi I see a wordpress.com blog and on the latest post there is a redirect for the external links via " redirect. This redirect is obfuscated - on hovering the link it displays a " redirect instead. What is this and why is it suddenly on this post and not others? Also, I see the redirect type is a 302 - surely this is harmful in terms of SEO for the destination links?
It seems to be generated by API for affiliate service. See this topic Link redirection through go2.wordpress.com: > The redirection is for a skimlinks ad service we are running.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wordpress.com hosting, redirect" }
Add #content to next_image_link() I am almost completely happy with a new site I built - see < As a final touch, I want to add `#content` to the end of the link location for each `previous_image_link()` and `next_image_link()`. Any ideas on how to do this?
This is kinda dirty, but I can't find a better hook: function add_content_hash( $link ) { $link = str_replace("' title='", "#content' title='", $link); return $link; } add_filter( 'wp_get_attachment_link', 'add_content_hash' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "gallery, navigation" }
Include files in child theme functions file Typically in my theme function file I'll require other files to keep things neat. require_once("foo.php"); Now working in a child theme I'd like to do that same. I'm adding custom admin options and it seems impossible to include code. I've echoed out the path to make sure I'm calling the right file and it is calling the proper location but nothing inside that file seems to run. The code runs fine if placed inside the child theme functions file.
Child themes reference parent themes by directory name, and in a normal install all your themes live in `wp-content/themes/`, so I'd say it's fine to reference those themes by their relative path: include '../parent-theme/some-file.php'; If that makes you uncomfortable, I observe the following constants in WordPress 3.0.1 with a _twentyten_ child theme called _tt-child_ : TEMPLATEPATH /home/adam/public_html/wp3/wp-content/themes/twentyten STYLESHEETPATH /home/adam/public_html/wp3/wp-content/themes/tt-child So you can do the following in your child theme to reference the parent theme directory: include TEMPLATEPATH . '/some-file.php';
stackexchange-wordpress
{ "answer_score": 14, "question_score": 9, "tags": "functions, child theme" }
Adding rel="nofollow" to external links in posts? I've tried three plugins to do this, non of them worked (I'm using WP 3.01): * < * < * <
If you're experiencing bugs with my own plugin (sem-external-links), be so kind to say how it's not working...
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, nofollow" }
deleted users still show in count? I noticed that deleted users still show in the **count** of the users admin screen. On one blog I deleted 9 users only leaving the admin but it stil shows 9 in the count. In the physical database they are no longer present in the wp_users and wp_users_metadata so.... i guess that the counter is uhm... somewhere else in the database and I set it tot 1 manually in the database?? **update / fix** I notice that the records **wp_capabilities** and **wp_user_level** do not get deleted in the **wp_usermeta** table after deletion after I deleted those 2 records manually in the database the count was back to 1
Look no further, then. It's one of the joys of lack of referential integrity combined with workflow bugs. Please report this in the WP bug tracker.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 4, "tags": "customization, wp admin" }
Placing Admin Post Metaboxes in Tabs I am looking for what code one would need to add into the functions.php file which would allow specific metaboxes to show up in tags instead of within their individual metaboxes. Can anyone help with this?
Maybe you can inspect <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, menus, metabox, customization" }
Free swf files hosting for wordpress blog Picasa and Flickr provide Photo service. Is there any service for swf files so that i could share and use `swf` file in my blog? I don't like to upload `swf` on my wordpress hosting. I believe Google, Microsoft and Yahoo services only.
Would a generic file sharing and hosting site work? If you place the file in a public Dropbox folder and reference it from your site? See the Web Applications Stack Exchange for more online file storage providers. Make sure you check the Cross-domain policy: if the Flash file hosted on `dropbox.com` needs to access data from `yourdomain.com`, you need a `crossdomain.xml` file on `yourdomain.com` that specifies that Flash files from `dropbox.com` are allowed to access data.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "hosting" }
blog posts sorting doesnt work while using get_query_var I'm trying to show the latest posts using the `get_query_var` function. The function filters the posts according to their category. When I'm displaying the posts on the page they appear unsorted although I've added the `$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;` `$args=array(` `'category__in'=>array( $cat),` `'order' => ASC,` `'caller_get_posts' => 1,` `'paged'=>$paged,` `'orderby' => date,` `);` `query_posts($args);` How can I sort properly?
If something unexpected happens between `query_posts()` and `get_post()`, it is probably a plugin that hooks into the query and modifies it. Try disabling all plugins to see whether the problem disappears. Re-enable them one by one until you see the problem, that is the plugin that causes it.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "posts, sort" }
Create slugs programmatically I'm updating programmatically posts in a WP 3.01 install, using custom made tools. Sometimes I do change programmatically `post_status` from DRAFT to PUBLISHED using custom `SELECT` queries, however this seems spoiling posts permalinks. When in a DRAFT state, posts have the following link structure Could there be some "trick" to force a change in the link structure, generating the proper permalink?
You need to programmatically set the slug as you do so. An SQL trigger could do the trick. Don't forget to mind duplicate slugs as you write it. Else, instead of publishing using the database, write a php script that calls the WP API.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "permalinks, draft" }
How do I obtain the post content via a custom meta box inside the editor? I have a custom meta box which I would like to use to report on the markup of the current post or page (number of words, number of heading tags, etc). How can I obtain the post content into memory in order to parse and report on its content inside the meta box?
The callback for a meta box gets the current object (post, comment, link, ... depending on what you're editing) passed as the first parameter. So in your meta box handler you can read this first argument and access it's `post_content` to get the content.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "theme development, metabox" }
How to insert current date/time in the content of a post? I'm making a list of suggestion here. I need to insert current date/time for each of my suggestions - they are added accumulatively. If you have any idea on doing that, please share.
You're on WordPress.com, so there's no way to add functionality that will allow you to do this. You could always type the date/time manually whenever you update it.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "posts, date time" }
Last time a user logged in I'm building a site where users log in to view content specific to them. I would like to display the last date and time they logged in. How would I get this information from wordpress? If it doesn't exist, how could I add it? Example: Welcome Back! Your last visit was on 10/25/2010 at 3:14pm. Thanks!
I don't see anything like it in the database, so you probably have to do this yourself. To save the last _login time_ , you can hook into the `wp_login` action, and save a user meta value (like `[myprefix]_lastlogintime`). You first read this value, so you get the _previous_ login time, save this in the session, and then save the new login time. On the regular admin pages you check whether this session variable is set. If it is, you display the welcome text and clear the session variable so you don't display it on every page. If you want to save the _last page visit time_ you have to write to the database on every (admin) page view. This is possible, but I would not recommend it. You can also save something once on logout (action `wp_logout`), but probably not everyone will remember to log out.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "customization, users, login, date time" }
URL redirect problem I have 2 pages in my wordpress 3.0.1 site with 2 urls www.mysite.co.uk/sub-page/child-of-sub-page/accommodation/ and www.mysite.co.uk/accommodation/ however any link in my site to www.mysite.co.uk/accommodation/ goes to www.mysite.co.uk/sub-page/child-of-sub-page/accommodation/ instead is this a bug in wordpress 3.0.1? or is there a way round this?
I'm not seeing this behavior in my test install, using the page hierarchy you have described. < I can access both the top-level accommodation page and the child page. Do you happen to have the Redirection plugin installed?
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "redirect, urls" }
Enable/disable post revisions programmatically Is there a way to temporarily disable revisions.... I have noticed that `wp_update_post` is very slow and creates revisions I don't need. The fix could be to disable revisions before issuing `wp_update_post` and re-enable the feature once done....
To keep posts updated, I am working with WordPress 4.4 and to enable/disable post revisions programmatically use: remove_action( 'post_updated', 'wp_save_post_revision' ); $post_id = wp_update_post( $arg ); add_action( 'post_updated', 'wp_save_post_revision' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 4, "tags": "php" }
difference between esc_attr(), strip_slashes(), strip_tags()? So what's the difference between these, and when should we use each one? Is esc_attr() safe enough to escape any type of data you get from the user ?
esc_attr() is, for the most part, an alias for a) kses (strips evil chars to prevent xss) and b) htmlspecialchars(), for use in HTML attributes. It can be used to display sanitized user input that cannot contain HTML. If you need only to sanitize strings before storing in the db, there are multiple variants of kses available. Also, don't miss the other esc_*() functions. There are quite a few. The other two you mention are self-explanatory.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "customization, php" }
Create custom page templates with plugins? Is it possible to make custom page templates available from a plugin?
`get_page_template()` can be overridden via the `page_template` filter. If your plugin is a directory with the templates as files in them, it's just a matter of passing the names of these files. If you want to create them "on the fly" (edit them in the admin area and save them in the database?), you might want to write them to a cache directory and refer to them, or hook into `template_redirect` and do some crazy `eval()` stuff. A simple example for a plugin that "redirects" to a file in the same plugin directory if a certain criterium is true: add_filter( 'page_template', 'wpa3396_page_template' ); function wpa3396_page_template( $page_template ) { if ( is_page( 'my-custom-page-slug' ) ) { $page_template = dirname( __FILE__ ) . '/custom-page-template.php'; } return $page_template; }
stackexchange-wordpress
{ "answer_score": 91, "question_score": 82, "tags": "plugins, templates, page template" }
Strip tags from a the terms() function Trying to print my custom post type's taxonomy but without the link. Tried this, but doesn't seem to work, any suggestions? $text = the_terms($post->ID,'type','','',''); echo strip_tags($text); Any help would be greatly appreciated... I'm about to start punching babies.
You _could_ use a filter and `strip_tags()`, as you suggested. Example using post tags, since that's the taxonomy I had available: function my_remove_links( $term_links ) { return array_map('strip_tags', $term_links); } add_filter('term_links-post_tag', 'my_remove_links'); Really though, I would just `get_the_terms()` and and craft the output yourself: function the_simple_terms() { global $post; $terms = get_the_terms($post->ID,'post_tag','',', ',''); $terms = array_map('_simple_cb', $terms); return implode(', ', $terms); } function _simple_cb($t) { return $t->name; } echo the_simple_terms();
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom taxonomy, php" }