INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Performance of my permalink structure? I have read the discussion on the performance of different permalinks on the wp hackers mailinglist, THIS forum and around Google. I could however not really deduce if the permalink structure I have been using for the past years is good or not: /%postname%-%year%%monthnum%%day%.html This combination put the postname directly after the / and the year,month,day combination makes it more unique since many postnames carry the same name. The html addition is something I have been using for the past 10 years on my blog (even pre wordpress) so that is legacy. I dont know if this is good for permance or bad for performance, how can i check this? (I have been running the blog for +10 years and there are about 10.000 posts with many links in) links: 1. < 2. < 3. < 4. <
You can check by looking at the size of the rewrite_rules option in the database. If it's small (which I believe it should with this structure), you're not using verbose rules. By contrast, if you see several lines per static page, you're using verbose rules and it's not good.
stackexchange-wordpress
{ "answer_score": 8, "question_score": 14, "tags": "permalinks, database, performance" }
Commit changes to WordPress Plugin SVN with TortoiseSVN I'm trying to upload my plugin for the first time to the WordPress SVN. I've been granted access from the WordPress team. I am able to download the directory. Then I try to place my plugin files into the `trunk` folder, and then commit the changes. When I do this. I am prompted for my login credentials. I use the same ones that I use on the Wordpress.org website. However, it keeps re-prompting me to enter my credentials. I am not sure what I am doing wrong. I made a screencast of the process. <
Try changing your password @ wordpress.org then retry. If still fails check your firewall log If it still fails ... ask Andrew Nacin :) < :)
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "plugin development, svn, repository" }
Do widget options need to be escaped widget()? I was wondering if you really need to escape user submitted data (widget option fields) within the widget() and form() functions (from the widget class) ? I don't see a reason to do this, if the data is already escaped in the update() function. Or am I missing something?
Mm, they're not slashed, if that's what your meaning. However, they're definitely not xss-sanitized. Use kses before saving, or esc_attr() on display, if you're dealing with untrusted data.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, customization, widgets" }
Embed iFrame in WordPress 3.0.1 I need to embed an iFrame into a post and it appears that tinyMCE or something is stripping it out when I go from HTML to Visual view while editing a post. I've found instructions for adding valid elements to tinyMCE but it only seems to apply to WordPress 2.8. No such file seems to exist under WordPress 3.0.1 (see Make WordPress WYSIWYG not strip out iframe's) None of the iFrame embedding plugins seem to support WP 3.0.1 either. Thanks for any tips.
Did you try this solution: Make WordPress WYSIWYG not strip out iframe's?
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "tinymce" }
How to configure Wordpress to be able to use <script> tag inside posts? I'm looking for a solution that would allow me to write tags inside posts and be sure that the visual editor or wordpress will not alter them. The same problem can apply for other specific HTML code that I may want to use. Disabling the visual editor is not an option, because in will render most edit operation too hard to use.
Add the following to your theme functions.php: function fb_change_mce_options($initArray) { $ext = 'script[charset|defer|language|src|type]'; if ( isset( $initArray['extended_valid_elements'] ) ) { $initArray['extended_valid_elements'] .= ',' . $ext; } else { $initArray['extended_valid_elements'] = $ext; } return $initArray; } add_filter('tiny_mce_before_init', 'fb_change_mce_options');
stackexchange-wordpress
{ "answer_score": 6, "question_score": 8, "tags": "javascript, tags" }
Multiple install for multilanguage. How to? I (will) have a multilingual (3 lang actually) site. I used WMPL some time, but this plugine made me sad... Finally, I decided to install each language a part. How should it be done? I have my `/` So, should I install `/en` `/fr` `/it` or `/` \+ `/fr` `/it` is there some plugin that will help me to synchronize content?
I would go for /en/ in order to prevent future issues and keep isolated the content that is not localizable. From my knowledge WPML does not support this yet.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "multisite, multi language" }
Custom Metabox with Ajax in Edit Post - Stuck I'm trying to create a custom meta box with multiple text fields. The idea is that there is initially one text box, then you can click the button 'Add New' and a another text box is added (using Ajax; no need to publish or update the post for the text box to be created). I'm using the following code (below), but it just doesn't work. I'm completely stuck; really need some help. I'm even willing to donate some cash if anyone can help me figure this out. <
If you end goal is to add text boxes dynamically, but still require the user to save/update the post, you don't need to use AJAX at all. Just name the text fields appropriately so an array of values is POSTed, then handle it in your save action. It may be helpful to save this array in a single post meta key, so you can just loop through it to output the meta box. Give an ID to the enclosing <div>, something like 'slideshow_metabox' Set your initial text boxes as so: <input type="text" style="position: relative; right: 0; width: 85%;" name="slideshow[]" value="<?php echo $value; ?>" /> And change your 'add button' onclick to be: function() { jQuery('#slideshow_metabox').append('<input type="text" style="position: relative; right: 0; width: 85%;" name="slideshow[]" value="" />'); } Hope this helps.
stackexchange-wordpress
{ "answer_score": 9, "question_score": 2, "tags": "metabox, editor, ajax" }
Line breaks not showing up properly I'm trying to have spacing show up between a paragraph and heading in the following excerpt: In my article series on handling extracurriculars, I coined the term Sovereign Zen philosophies. It builds off of Cal Newport’s Zen Valedictorian philosophy. Before you criticize this article as being a copycat, there are some subtle differences between both philosophies, namely the self-protective critical thinking components, and their applicability beyond schooling career. # Definition **Zen Valedictorian:** A way of living to become less overloaded and less stressed without becoming less impressive However, the line break between career and definition isn't showing up properly even with two `<br`>`<br`>. How would you suggest dealing with this?Blockquote
Presentation layer is best handled by CSS. In this case that would probably be `margin-bottom` rule for your heading. Markup with `<br />` is usually unreliable. WP mostly relies on `<p></p>` tags for paragraphs and not line breaks.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "formatting" }
Geo Blocking in Wordpress - how can it be implemented? I've tried to search for a geo-blocking plugin for wordpress - didn't find anything. So thought to ask here if anyone knows of a geo-blocking solution for wordpress sites? Thanks.
If memory serves, Bad Behavior allows to configure a few aspects of geo-blocking. There might be a few wp.org plugins tagged as security that allow to implement geo-blocking too. That said, I don't think it's the right approach. The best is to hop over to askapache.com. There's tons of security-related, htaccess-based stuff over there. Geo-blocking is among them.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "geo data" }
Mimicking admin panel menu from wordpress 3.0.1 I have chosen from a variety of menus for my application only one and it was a wordpress 3.0.1 admin panel menu, but I can't get pass the functionality of it. If to be more distinct I can't understand how the sliding in this menu work. Is there a jQuery function for every element of the menu or they made it with no link to the specific menu item and how does it remember the state (is menu item open or closed)? I hope I asked this question in the correct place. Thank you all for help.
It's a rather open ended question... Basically, the core menu functionality are in: * wp-amin/menu.php (initialize/display) * wp-admin/js/common.dev.js (fold/unfold and store state scripts) * wp-admin/includes/plugin.php (functions that allow plugins to add extra items) But these then make use of a wide variety of other WP functionality. If your goal is to create menu code for a separate app, as I'm suspecting, you're in for copying entire chunks of the WP code base so you might as well use WP altogether.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "customization, admin menu" }
"Connect" my personal website to wordpress.com I used to have a blog on wordpress.com, now I've created my own site (using wordpress of course), on a privately hosted domain. I used to have a lot more traffic hitting my blog on wordpress.com than on my new site. I can see some other sites (not subdomains on wordpress.com) listed in "freshly pressed" rss feed. How can I do that on my site?
I just figured that this can be done with an Offsite Redirect upgrade. It's a paid service (12$ per year), so I won't try it for now, however, for the sake of stackexchange Q/A, I would like to get a comment from someone who actually used this.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "wordpress.com hosting" }
How to change the language of a wordpress.com blog? I'm using my wordpress.com blog (not wordpress.org) and want to change the language of the blog. How can I do this?
I found it here <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "wordpress.com hosting, multi language" }
Prevent notice and warnings in error_reporting? When turning opn WP_DEBUG and WP_DEBUG_DISPLAY, I get tons of warnings and notices. I have tried to remove the warnings by doing a @ini_set('error_reporting', 1) to only show E_ERROR, but I still get tons of E_NOTICE. Is there someway to prevent all the warnings and notices and only show errors in HTML output?
Turn off WP_DEBUG because it overwrite your `ini_set`.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 5, "tags": "plugin development, errors, wp debug" }
Get custom field value from not-current page What is the best way of getting a custom field value from a page which is not the one currently displayed? I know the title of the page i want to get custom field value from, but not the pageID. Thanks!
Use: $meta = get_post_meta($id, $key, $single); With $single set to true if you don't want WP to return an array for unique meta keys.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "customization" }
Custom field values in permalink Is there a way to add a custom field value (if it exists) to the permalink?
Here's how I'd do it. I'm just going to say, I haven't tested this code at all, so I don't know if it even works. It's more of a starting point for you. function jpb_custom_meta_permalink( $link, $post ){ $post_meta = get_post_meta( $post->ID, '<insert your meta key here>', true ); if( empty( $post_meta ) || !is_string( $post_meta ) ) $post_meta = '<insert your default value (could be an empty string) here>'; $link = str_replace( '!!custom_field_placeholder!!', $post_meta, $link ); return $link; } add_filter( 'post_link', 'jpb_custom_meta_permalink', 10, 2 ); You would also have to go to your permalinks and change them to include `'!!custom_field_placeholder!!'`, like so: '/%year%/%monthnum%/!!custom_field_placeholder!!/%postname%/' This will not add any significance to your permalinks, merely text. If you need to add meaning to the text that goes there, that's a lot more work.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "customization" }
Adding pub_Date to an RSS feed hosted on Wordpress I am trying to use the FaceBook application RSS Grafitti to link my RSS feed from my Wordpress installation to a FaceBook Fanpage. It finds the feed OK, but cannot post to the Fan page because there is apparently no pubDate field in the RSS feed. I am not even sure where to find the file to edit in my WordPress installation. I have WordPress 3.0.1 installed on a shared Linux host.
Try feeding the app an atom feed instead. (i.e. /feed/atom/ instead of /feed/.) The needed field(s) might be in there. Else, there are a few hooks to add them via plugins (see the wp-includes/feed-*.php files).
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "customization, rss, facebook" }
Set user loggin status? I create user with wp_create_user,after succesfully creating a user I need to set his status to be logged in?How to set his status to be logged in ?
Use `wp_signon()`. Ex: $creds = array(); $creds['user_login'] = 'example'; $creds['user_password'] = 'plaintextpw'; $creds['remember'] = true; $user = wp_signon( $creds, false ); if ( is_wp_error($user) ) echo $user->get_error_message(); See Codex for more details about `wp_signon()`.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "customization, users, functions" }
How can I pass $post object to 'save_post' add_action? I have several functions that are called from inside a `save_post` function. However, all of the functions that use the `$post` object are returning incorrect values because it appears that the default value being passed to `save_post` is the post ID rather than the post object. How can I pass the post object to the `save_post` function in addition to the post ID? add_action('save_post', 'my_save_function');
Do: add_action('save_post', 'my_save_function', 10, 2); And the `$post object` will be passed as second argument to your function: function my_save_function($post_ID, $post) {
stackexchange-wordpress
{ "answer_score": 6, "question_score": 2, "tags": "posts, editor, save post" }
Link to large image version instead of original? How can I best make WP link to the large version of the image in all posts (instead of the original one) without modifying all the data in the database? I'm probably looking for the best filter to attach to.
You can modify the content that is displayed on the site by hooking in to the `the_content` filter. However, this is where the hard work starts. You need to identify all the images, figure out the links to the large sizes, and replace them. This could be a costly operation, so you might want to save the post back to the database and set a (hidden) meta key to indicate you don't have to do it again next time. Now, some hints on how to do this: to get info on the attached images, you use `get_children()` and specify you only want attachments: `get_children($post->ID, array('post_type' => 'attachment'))`. Attachments are stored like posts, and you can request different sizes with `wp_get_attachment_image_src()` by passing the requested size (`"large"`).
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "images" }
cannot find cforms action handler page I'm not able to find the action handler page for the cforms plugin anywhere. I want to write some function in the action handler page of the cforms plugin using the post values.
In the main cforms plugin folder, find the file called `my-functions.php`. You can add functions to that file as needed. Its pretty well-commented. What you want to do is add a function called `my_cforms_logic` or `my_cforms_action`, which get triggered at several different hooks during form submission and processing. According to the docs, you can move the `my-functions.php` file (annd any css tweaks you make) into a separate folder called “cforms-custom” to protect your customizations from future upgrades...
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, plugin cforms" }
Schedule cron event from widget Can I use wp_schedule_event() to set up a cron job from within a widget? I tried, but I can't make it work, The problem seems to be the $hook parameter. The function I'm trying to hook is located within the widget class so my guess is that WP can't find it. neither of these work: wp_schedule_event(time(), 'daily', 'my_widget_cron'); wp_schedule_event(time(), 'daily', array(&$this, 'my_widget_cron')); any ideas?
`wp_schedule_event` takes a hook as parameter, not a function. Try: wp_schedule_event(time(), 'daily', 'my_daily_event'); add_action('my_daily_event', array(&$this, 'my_widget_cron')); if ( !wp_next_scheduled( 'my_daily_event' ) ) { wp_schedule_event(time(), 'hourly', 'my_daily_event') } If you remove the widget from the sidebar, the cron will still continue to run. You can run the following code (outside of the widget class) to clear it: if ( !is_active_widget('your_widget_callback_function') && wp_next_scheduled( 'my_daily_event' ) ) { wp_clear_scheduled_hook('my_daily_event'); }
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "customization, widgets, hooks, cron" }
Can I make user role that can only access a certian content type? I would like make a custom role that can only access a custom content type that I'm going to be creating in the admin. Is that possible and does any know of any examples or tutorias that I should check out to get started? Thanks, Paul
The `register_post_type` has a `capabilities` (or simple version: `capability_type`) that you can use to specify a separate capability to create and edit posts of this type. If you set this, you can create a new role that has the capability to edit these custom posts, but not regular posts.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 4, "tags": "custom post types, capabilities, user roles" }
How do I add a new string to a .po or .pot file? I have a .pot file that came with my Wordpress theme. Now I want to add strings to it, that weren't there in the original theme. How do I do that? Do I have to update the .pot file? but 1) How do I do that, and 2) How do I make sure that the strings that were translated won't get erased? (I'm currently using Poedit and I can't see a feature to add a string.)
I am using < Give it a chance i suggest :)
stackexchange-wordpress
{ "answer_score": 6, "question_score": 5, "tags": "themes, buddypress" }
How can I tell what category I'm in? When displaying a category how can I tell what category it is? Say I'm on ` how can I get `quotes` aside from parsing the URL? I tried `get_the_category()` but it returns an array of all the categories of the first post shown in the page.
This should get you category object with ID, slug and rest of info: $wp_query->get_queried_object();
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "theme development" }
XML Sitemap Generator can't notify google and bing I am using wordpress Version 2.9.2 and XML Sitemap Generator 3.2.3 I have registered with Google Webmaster Tools. But I get an error while notifying to Google and I really don't know what it means. Heres a screenshot : !alt text And when I click on view result it show me the following message: Ping Test Trying to ping: The sections below should give you an idea whats going on. Errors, Warnings, Notices: WP_DEBUG was set to false somewhere before. You might not see all debug information until you remove this declaration! Result (text only): Result (HTML): If I want to debug the error where can I find WP_DEBUG ? Can someone tell me what's wrong here. Note : I have completed Google Webmaster verification process. Thanks.
`WP_DEBUG` is a constant which you can define in `wp-config.php` to disable hiding of PHP errors and notices. Add `define('WP_DEBUG', true);` to your config file to enable it. Just remember to never leave it on for long on a live blog. Since all pings fail this is likely not an issue with specific sitemap service, but with ping process itself. I think it might be HTTP requests failing for some reason, but there is no way to tell definitively from information you provided so far.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, errors, seo, google search" }
How to specify or extend the CSS-class of a menu item? is there a way to allow admin users to add classes to individual menu items in the back end? we have done some individual javascripting and CSS using the title tag, but that is not flexible as it is visible to the end user, so the method is not suited effects needed to be applied to multiple items.
This is natively supported by WordPress. In the menus page, click "Screen Options" (in the upper right corner): !Screen Options Then check "CSS Classes": !Check CSS Classes You will now have a "CSS Classes" Option for each menu item: !Enter CSS Classes
stackexchange-wordpress
{ "answer_score": 6, "question_score": 1, "tags": "menus" }
How to apply content filter permanently? I have the following temporary filter to fix a content error. We have data in our posts that have 4 digit zip codes, because the leading zero was cut when the original file was created. (For instance, a Massachusetts zip code is 0XXXX, but now in our content it is XXXX) function fix_zip_code($content){ if (preg_match('/<span class="postal-code">(\d{4})<\/span>/i',$content, $match)){ $content = str_replace($match[0],'0'.$match[0],$content); } return $content; } add_filter('the_content', 'fix_zip_code'); How can I apply that filter to all the content at once and re-save the posts so I can remove the regex filter completely?
//run once $allposts = get_posts('post_status=publish&numberposts=-1'); foreach ($allposts as $thispost) { wp_update_post( array( 'ID' => $thispost->ID, 'post_content' => fix_zip_code($thispost->post_content) ) ); } But as Rarst mentioned, backup your database before doing anything...
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "filters, the content, regex" }
Comment Link from get_comments()? I've got to update a bit of sloppy code that shows the 5 most recent comments across the entire blog. The code is using WordPress' `get_comments()` method, which doesn't appear to return comment id's, or comment links (direct links to comments within posts via the hash-tag). How can I collect more information about the particular comments, and make them links to the actual comments within their parent pages? <h3>Recent Comments</h3> <ul> <?php $comments = get_comments(array('status'=>'approve','number'=>'5')); ?> <?php foreach ($comments as $comment): ?> <?php $post = get_post($comment->comment_post_ID, 'OBJECT'); ?> <li><?php print $comment->comment_author; ?> on <a href="<?php print get_permalink($post->post_ID); ?>"> <?php print $post->post_title; ?> </a> </li> <?php endforeach; ?> </ul> This is located on the front page of the site, outside of the loop.
You're really close! Add #comment-`<?php comment_id(); ?>`to the href to append the anchor link <a href="<?php echo get_permalink($comment->comment_post_ID);?>#comment-<?php comment_ID() ?>"> <?php echo $post->post_title; ?> </a>
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "comments" }
How to wp_enqueue_script jQuery inside a Plugin I would like to use jQuery in my Wordpress plugin. I'm trying to load the jquery library using the enqueue script but its throwing an error. _Error: $ is not a function_ Here's the code snippet that's inside my main plugin.php file... function ($post) { wp_enqueue_script('jquery'); ?> <script type="text/javascript"> function doTestParse(searchString){ var rx = new RegExp('(?![^<]+>)'+searchString, "gi"); $(this).html($(this).html().replace(rx, '<b>$&</b>')); } </script> <?php ?>
jQuery is included in `noConflict` mode in WordPress, so you can't use the shorthand `$`, but must write `jQuery(this).html(jQuery(this).html().replace(rx, '<b>$&</b>'));`
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "jquery" }
A tool to analyze rewrite rules? Is there a good tool to analyze my rewrite rules? I always get confused with the regexes and the parameter replacements. _I have created something myself and will post it here so others can use it, but please feel free to add other tools!_
Well what a coincidence that you ask this, Jan! Just today I had time on a long train journey and decided to write a Rewrite Analyzer plugin, one that parses your rewrite rules and highlights the query variables. You can test URLs right there and see what query variables will be set. ![Display all rewrite rules and highlight captured URL parts and ignored query variables]( ![Test URLs and see matching rules with the resulting query variables]( You can find it in the plugin repository, or just as _Monkeyman Rewrite Analyzer_ when search for new plugins in your administration screen.
stackexchange-wordpress
{ "answer_score": 104, "question_score": 59, "tags": "plugin development, url rewriting, wpse plugin" }
Add array of post id's to a category? Is there a function to add array of post id's to a category,something like this array(2,3,5,6) to put in some category,not looking for update post. Tnx in advance.
Not exactly _add array_ , but you can loop through that array and run `wp_set_object_terms()` on each post id. Just study function's arguments carefully, because it defaults to overwriting terms, rather that adding.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "customization, functions" }
Highlight a Featured Post? I would like to "highlight" a featured post above all other posts with a special indicator. Is there a feature in WordPress that will do this or do I need to install a third party plug-in? I am using a custom WordPress install (not WP hosted).
Use the "sticky" feature. In the "Page Attributes" metabox (labelled as **Publish** ), if you click the "edit" link next to the **Visibility** option, there is a checkbox which allows you to _"Stick this post to the front page"_. Unless a theme overrides the default query, that post will show up above all the others. In addition, it adds the class name "sticky" to the attributes returned by `post_class()`, so you can style it however you want. !alt text To add some text to your featured posts and highlight them, add a function like this inside the loop in your index.php (or loop.php, etc., depending on your theme): if (is_sticky($post->ID)) echo '<span class="featured">Featured!</span>'; You can do the same thing with the css :before property, like this: div.sticky h2:before { content: "Featured! "; } (assuming you're using h2's to display the titles of your posts, and you want to add the text before the title)
stackexchange-wordpress
{ "answer_score": 8, "question_score": 5, "tags": "posts, sticky post" }
Most Flexible Photo Gallery Plugin? What is the most flexible photo gallery plugin available on WordPress? By flexible, I mean a plugin that can: * create galleries per folder / event * display / generate thumbnails per size I want (it would be good to have an API/function for this) * display the most recent gallery from either certain event or all photos uploaded. Is there any? Or something close to this?
The most full featured one I've found is NextGEN gallery. It even has add-ons for specific functionality beyond what's built in.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugin recommendation, images, gallery" }
Can I attach image to post without adding it to post? Can I "attach" images to a post without adding it to the post? The reason behind this is so that I can manipulate it however I want using an API.
There is a Plugin called Attachments < Maybe this is something you looking for.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 12, "tags": "images, attachments" }
w3 Total Cache expire headers not set I have been using w3 Total Cache with the setting to enable Expires Headers and eTags but they are not being set. I'm serving images and other media from a sub-domain such as static.example.org served by nginx but it didn't work even when I was serving these files with Apache from the main domain. I've tried disabling and re-enabling the browser caching settings in the admin without success. What do you suggest?
do you have mod_expires installed and enabled in your apache module?
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "plugin w3 total cache" }
How to filter $post->post_content prior to save I have a function inside my plugin that attaches to save_post, and inside that function, I'm seeking to filter the post_content prior to it being saved. However, the content never actually gets changed once its saved. See below where I'm setting $post->post_content = "test"; add_action('save_post', 'save_post_filter',10,2); function save_post_filter($postID, $post){ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $postID; } else { if($parent_id = wp_is_post_revision($postID)) { $postID = $parent_id; $post = get_post($postID); } $post->post_content = "test"; } }
The `content_save_pre` filter is applied to the content before it gets saved in the database. Some default filters hook into it too, for example `balanceTags()` and `wp_filter_post_kses()`.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "plugin development" }
Why does preg_replace_callback never fire in this function? In the function below, the save_content function runs, but the doReplace does not (echo "This is the doReplace" never shows. Any ideas why? add_action('content_save_pre', 'save_content'); function save_content($content){ global $post; $mykeyword = rseo_getKeyword($post); $mykeyword = preg_quote($mykeyword, '/'); $content = preg_replace_callback("/\b($mykeyword)\b/i","doReplace", $content); return $content; } function doReplace($matches) { echo "This is the doReplace"; die; }
Your function needs to return the data, not echo it.. function doReplace($matches) { return "This is the doReplace"; } Hope that helps..
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin development" }
What theme is good for posting code? I have my blog hosted at www.alphaot.com and I guess it's good enough. But problems arise when the lines of code get longer than 30 characters. The lines just wrap and get icky or something they even don't wrap! In your experience what's a great WordPress theme for a developers blog to post code to? Also, I'm using Windows Live Writer, any extensions for code publishing you would recommend? **Edit:** More than plugins, I'm interested on a clean, free wordpress theme that is WIDE so the code doesn't have to be wrapped.
In the end I used the theme called Elegant Grunge from Michael Tyson. I'm using Windows Live Writer 2011 with the Insert Code plugins for it, and it works very well. Check out my blog Alphaot.com to see how it ended up.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 6, "tags": "themes, theme recommendation, syntax highlighting, code" }
update_option method with support of utf8 I am using a plugin the updates the option table using update_option command. When I update content with hebrew characters it turns into gibrish. My database does support hebrew (or any other utf8 chars). Is there any workaround? Thank you!
Chances is are that the content-type/charset header is not being sent, and that you end up reading the utf8 chars as if they were latin-1. Also, note that serialize()/unserialize() are not multibyte character-safe. For a subset of characters, the string's length as returned by serialize() will occasionally differ from the expected length as it would be returned by mb_strlen(). This leads to all sorts of hard to debug unserialize problems which, since around WP 2.8, WP tries to discard in order to avoid crashing sites.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "options" }
Custom Taxonomy WP_Query for All Terms in a Taxonomy? Is there an easy way to query for any posts that is tagged with any term from a particular taxonomy? I know this technique: $custom_taxonomy_query = new WP_Query( array( 'taxonomy_name' => 'term_slug', ) ); But I would like to either pass a wildcard in place of term_slug, or perhaps just an empty string. Then that would give me all posts that are tagged by any term in that taxonomy, not just one specific term. Thanks for your help, Dave
In retrospect, I've did a mashup of MikeSchinkel and t31os suggestion. It's possible to inject that to existing queries on the fly, but it needs WordPress 3.1: **Plugin to get an RSS Feed for posts containing any term from a taxonomy.**
stackexchange-wordpress
{ "answer_score": 1, "question_score": 12, "tags": "taxonomy, wp query" }
How can I add a CSS rule to edit.php? I'm using `add_filter('manage_posts_columns')` in my `plugin.php` to add a column to the Edit Posts listing which is driven by `edit.php`. How can I attach a CSS style to the `edit.php`? I want to be able to color the background of my column `td`.
Creating Admin Themes article in Codex shows you how to add css styles to admin pages
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "plugin development, functions, css" }
How can I install a plugin on a Wordpress.com hosted blog? I used to have a self hosted wordpress blog but I switch to a wordpress.com one. I can't seem to find the plugins area. Any help?
You can't upload plugins on WordPress.com. For security and performance reasons, you can only run what wordpress.com staff has approved.
stackexchange-wordpress
{ "answer_score": 8, "question_score": 3, "tags": "plugins, wordpress.com hosting" }
Why is WordPress WYSIWYMG and how do I make it WYSIWYG? WordPress may have a text editor that appears to be WYSIWYG, but upon using it I discovered that it is actually WYSIWYMG- What You See Is What You _Might_ Get (once it's done screwing with the HTML). Isn't there a way to tell it to **do nothing** with the text you put into it? Just leave it as it is. No optimizations, no trying to guess what I meant, no correcting my HTML, no converting whitespace into nbsp's that for some reason cause line breaks, no changing the formatting or the spacing between embedded objects after you edit it to fix one typo... I did try searching the settings area but found only one HTML related option (regarding matching closing tags).
After you post your content, WordPress will pass **the_content()** function through a number of filtering function's. There are four of them, wptexturize(), convert_smilies(), convert_chars(), and wpautop(). All of these are defined in wp-includes/formatting.php and are referenced in wp-includes/default-filters.php. To remove these filtering functions you can disable them by putting this in your functions.php theme file: remove_filter('the_content', 'wpautop'); remove_filter('the_content', 'wptexturize'); remove_filter('the_content', 'convert_smilies'); remove_filter('the_content', 'convert_chars'); That should remove all formatting between what you save in TinyMCE (the WYSIWYG editor) and the front end view of your website. For more reference on what each of these does refer to the codex. I hope this helps, best of luck!
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "editor, html, formatting" }
WordPress bug reporting? If you find a WordPress bug, how do you verify that it has been reported and/ or is being worked on for the next release?
The process of evaluating and reporting bugs is documented in Codex under Reporting Bugs.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "bug tracking" }
How should I use posts_where to change meta_value from a string to integer? How should I use posts_where to change meta_value from a string to integer?
Try this: add_filter('posts_where', 'unquote_numeric_meta_value', 10, 2); function unquote_numeric_meta_value($where, $args) { $value = isset($args->query_vars['meta_value']) ? $args->query_vars['meta_value'] : false; if(is_numeric($value)) $where = str_replace("'{$value}'", $value, $where); return $where; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp query, post meta" }
Get cat parameter from admin-ajax I have a plugin that restricts the categories users can view/edit in the admin. All works fine in WordPress 3.0.1, but as I started testing 3.1 I noticed that the category filter, which is AJAX, allows you to bypass the restrictions. I'm able to filter this out in 3.0.1 because it's submitted via URL parameters. My trouble is being able to $_GET the 'cat' parameter from the new AJAX request. I have tried testing for $_SERVER['HTTP_X_REQUESTED_WITH'], but it doesn't register. I've asked this question on the wp-hackers mailing list, but no one can give me actual code that helps with my predicament.
For excluding terms of a taxonomy the better way to do that would be to use the hook that was created for doing term exclusions.. `list_terms_exclusions` Get the available categories using `get_terms` (get_categories calls get_terms anyway IIRC), and do your exclusions using a hook on `list_terms_exclusions` and your code should work as expected.. You can see the hook i'm referring to on line 1040. < **NOTE:** Your plugin does not have a sanitization callback function when it calls register_setting, your options won't get sanitized properly without one, i'd strongly advise you declare a callback function and sanitize the data as appropriate (especially if you're passing that saved data into queries).
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin development, wp admin, jquery, ajax" }
Basic gallery plugin suggestion I'm developing a custom wp theme which needs a gallery function. I looked over a few popular gallery plugins, but all of them seem "bloated" with a lot of unnecessary stuff. Do you have any recommendations of a light gallery plugin that allows the admin to upload photos and group them into galleries?
What's wrong with the built-in gallery functionality? Seems to match your description pretty well. ;-)
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "plugins, customization, themes, gallery" }
How to determine, from plugin script, if active theme has <h1>The Post Title</h1> My plugin needs to know if the currently active theme places the post title in H1 heading tags? I'm looking for suggestions on approaches to create script that could discern this. UPDATE: The plugin evaluates the SEO profile of the post content to help the user make improvements for search rankings. Second only to the post title, the h1 tag is one of the most important tags for SEO. However, I don't want to ask the user to include their primary keyword in an h1 heading tag in the post content if the theme already does that (as many do).
Send an HTTP request to the page and search the response body for `</h1>`. See this Gist for an example. Store the result in an option and delete this option when the user switches the theme (hook into the action `switch_theme`).
stackexchange-wordpress
{ "answer_score": 6, "question_score": 1, "tags": "plugin development" }
Advice needed for importing custom field data and database structure Looking for advice for the best method to accomplish the following. I have a custom page template with several custom fields/taxonomy. The data needed for these custom fields actually resides in .txt files that are updated once a week. They are easily converted into .csv files. What would be the best and most secure method in getting this data into a custom page template, I figure I have 3 options. Read the raw .txt or .csv files using custom php? Import the .csv into a separate database and grab the data from it? Import the data into the WordPress database? Option 3 seems to be the best one, but I am completely unfamiliar with the wordpress database structure and the best way to go about this.
Unlikely that you will need intermediary database, from your description this is likely to be easy enough with bit of PHP and WP APIs. 1. Create WP-Cron task (if you need automated recurrent import). 2. Read data from flat files, for example with `fgetcsv()`. 3. Use `wp_insert_post()` for creating posts and custom field functions to add your data. This was recently covered in detail in WP insert post PHP function and Custom Fields question.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "custom field, database, page template" }
Notify admin on new submit With WordPress 3.0 its easy to for users to submit custom content from the front end. They don't even need to be logged in anymore. Is there a functions code (not a plugin) to notify a predefined email, such as the site admin, of new posts in just a certain post type? For example the site admin get notified whenever a new "usernews" post type is posted? Thanks!
I don't know the name of a function that would do just that - but i can give you what i think is a good algorithm to do so However, I suggest you do the following trick : Once the user publishes new content - let it have a category called "user submission" for example or any other stuff Once an admin views the post, he can remove that category and label the content accordingly. So all you have to do is use feedburner or any email notification system to let the people you want know about the "new posts" or RSS subscription by category to do by programming : 1 - you have to fetch the user details for which users are admins from the tables users/usermeta 2 - in some separate table, you must have lastPostId, AdminId 3 - write a script get the posts that have an ID > lastPostId and send the email 4 - this script can be run using a cron job
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, admin, email, notifications" }
Add Custom Fields to Custom Post Type RSS I'd like to add custom fields in my custom post type to the RSS feed for that post type located at < I've seen info on doing this for the regular feed but nothing for how to rewrite the custom post type feed. I'll need to add 10 - 15 items to the feed (1st act, 2nd act, 3rd act, price, purchase link...)
function add_custom_fields_to_rss() { if(get_post_type() == 'my_custom_post_type' && $my_meta_value = get_post_meta(get_the_ID(), 'my_meta_key', true)) { ?> <my_meta_value><?php echo $my_meta_value ?></my_meta_value> <?php } } add_action('rss2_item', 'add_custom_fields_to_rss'); You should be able to substitute and any other meta values you need to add to the feed.
stackexchange-wordpress
{ "answer_score": 21, "question_score": 18, "tags": "custom post types, rss, feed" }
How do I create shortcodes for my wordpress themes? I have seen many professional wordpress themes for sale that have shortcodes built in with which you could easily make posts like this: [alert_box]This is an alert box which based on this short-code automatically switches the CSS so it is easier than messing with classes every time[/alert_box] How can I do this? I know that it requires you to add something to the functions.php, though I haven't been able to figure out how. Thank you, any help is appreciated.
See the Shortcode API article on the Codex for a tutorial and my Shortcode Plugin for some examples. A very basic example for the `functions.php`: /** * Shortcode for bloginfo() * * Usage: [bloginfo key="template_url"] * * @see * @source * @param array $atts * @return string */ function bloginfo_shortcode($atts) { extract( shortcode_atts( array( 'key' => 'name' ), $atts ) ); return get_bloginfo( $key ); } add_shortcode( 'bloginfo', 'bloginfo_shortcode' );
stackexchange-wordpress
{ "answer_score": 6, "question_score": 0, "tags": "shortcode" }
Deregister custom post types Anyone know of a way to deregister custom post types? Is there an equivalent to `register_post_type()`?
As of WordPress 4.5 there is function to do that, `unregister_post_type`. Example:- function delete_post_type(){ unregister_post_type( 'blocks' ); } add_action('init','delete_post_type');
stackexchange-wordpress
{ "answer_score": 43, "question_score": 50, "tags": "custom post types" }
can registration be enabled programatically? I need to allow registration as part of a build for a client, and I am aware this can be turned on in the admin panel, but can I turn it on in the function?
Yes sure you can, just update the appropriate option inside your given function.. update_option( 'users_can_register', 1 ); It's a checkbox option, so the value is 1 = on, 0 = off.. Hope that helps..
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "user registration" }
why is unregister_setting() undefined? trying to call unregister_setting('general','users_can_register'); so as to removed the option for allowing or dissallowing user registration (it is required in the theme, so it is set programatically) but it is returning `Call to undefined function unregister_setting()...`
That function is only available from the wp-admin section of the site. The file that contains it is only loaded as part of the wp-admin. You need to wrap it in a hook function: function unregister_users_can_register_setting() { unregister_setting('general', 'users_can_register'); } add_action('init', 'unregister_users_can_register_setting');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "options" }
How to show wp.me shortlink underneath each post? What is the variable that holds the wp.me url? / What is the webservice / call that provides me the wp.me url? / What is the workaround to read that rel tag from the dynamic generator header (on a self hosted domain). ... to show it beneath each post.
WP 3.0 includes: wp_get_shortlink() which returns the ?p=1 style url for any post within your domain. This can be filtered, however for other shortening services, which is what the Wordpress.com Stats plugin does for self-hosted blogs. With that plugin installed and activated, wp.me shortlinks will be output instead of the default mydomain.com/?p=1, and can be retrieved with the function which can be used within the loop as: echo wp_get_shortlink() or to retrieve any post outside the loop: $link = wp_get_shortlink($post->ID);
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "customization" }
In creating a theme, how can i allow a user to change an image outside post/page content? I'm creating a theme for a particular WordPress site. There's one spot in the sidebar that displays a photo. The user might want to change the photo once a week. He doesn't want to use FTP to upload the new photo, or edit any theme files. How can I set up the theme so he can upload a photo from within WordPress, e.g. to the media library, and have it replace the photo in the sidebar? The only thing I can think of is to have him upload the photo to the Media Library, click the hidden 'Edit' link under the photo in the media library, select and copy the file URL, then go to Appearance > Widgets and paste the URL into a widget that displays the photo. But this seems like a lot to ask of a non-technical user, and there's a lot that can go wrong. Is there a better way?
I ran into a similar problem recently. I found plug-in called "image widget" < that enabled upload right in the widget. The client though had no idea how to barely log in and find the widgets so I ended up using a flickr widget since it was more user friendly ( aka they could upload the image from their iphone to flickr).
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "theme development, images, media" }
How to list all images in uploads directory except those that are attached to any post I've got code in my functions.php which parses the WP uploads folder and lists all images it finds there. Is it possible to place a filter here that would exclude any image that is already "attached" to a post? eg: "List all images in folder "uploads" where image is not found in (attached images)"
Under Media / Edit, there's a means to list them, so I suggest you reuse the existing API. Else, a general method, which works anywhere, is to run a db query with a left join: select ID from foo left join bar on whatever where condition and bar.ID is null;
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "theme development, php, functions" }
NextGen Gallery Slideshow Positioning Issue I have been having an issue with the non-flash version of the NextGen Slideshow on my website. The slideshow seems to initially load the first slide about 5px below the desired position. The slide then moves up about a second or 2 later into the correct position. I have tried putting the slideshow in other widget areas and all result in the same positioning error. The page in question in here: www.ukjiayuan.com So far have been unable to get any support, but would really appreciate it if anyone can reccomend a solution. Many Thanks
Someone has just answered the question for me on the wordpress forum. It turns out that there was 5px of padding in the gallerys css file (line 301) that I hadn't found: .ngg-widget, .ngg-widget-slideshow { margin:0; overflow:hidden; padding:5px 0 0 0; <\--- change this to 0 0 0 0 or just 0 text-align:left I didn't add this, so it seems like the css have been like this in the first place. So if anyone else has this problem in the future just change that 5 to a 0.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "gallery, plugin nextgen gallery" }
domain mapping confused about sunrise When i try to access my domain mapping page it asks me to move the line define('sunrise', 'on') above the last require_once line in the wp-config file. It is already above this line. I tried moving it higher and even to the top of the file(below the opening I recognizes if i remove the line alltogether (asks me to uncomment the line or add it if it is missing) so I know It is not looking at some other file. What could cause this behavior? <
Apparantly this happens with the newer version of domain mapping because sunrise.php itself needs to be updated. To solve it I: Copy the new sunrise.php file from wp-content/plugins/wordpress-mu-domain-mapping/sunrise.php to wp-content/sunrise.php and you'll be fine. And it works now.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 4, "tags": "multisite, domain, wp config" }
Fatal error: Call to a member function query() on a non-object In the code below (from my functions.php), I'm attempting to create an array of items from the wp_postmeta table where the meta_key is "_wp_attached_file". I'm getting an error: Fatal error: Call to a member function query() on a non-object What's wrong with the query? $excludeImages = array(); $excludeImages = $wpdb->query("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file'"); array_push($excludeImages);
Hi **@Scott B:** Did you remember to include a `global $wpdb;` in your code, like so? global $wpdb; $excludeImages = array(); $excludeImages = $wpdb->query("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file'"); array_push($excludeImages);
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "php, wp query, wpdb" }
Send email on new comment when no admin approval needed? I see that if I turn off "An administrator must always approve the comment" and "Comment author must have a previously approved comment" I get no notifications of new comments on my site. Can I somehow make it send the notification even though approvals are unchecked in dashboard under "discussion settings"? And what would be a good way to send this notification to all users registered on this website, and not only to admin? I tried WP Comment Notifier For All (Wordpress Plugin). but it didn't work... thank you
mmm, well Comments Notifier (Wordpress Plugin) did the trick
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin recommendation, comments, notifications" }
Script to get a list of all images that are detached? In my functions.php, I have a need to list all images in the uploads folder which are not currently attached to a post in the WP database. It appears that every time an image is uploaded to the WP uploads folder (via FTP or via Media Manager), a records gets inserted in the WP database, right? How can I obtain a list of all images that are not currently attached to any post?
This should work: $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => 0 ); $attachments = get_posts($args); if ($attachments) { foreach ($attachments as $post) { setup_postdata($post); the_attachment_link($post->ID); } }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "plugin development" }
WordPress book for graphic designers? Is there a good WordPress book intended for graphic designers? I've started working with a friend in an arrangement where he designs a site and I build it in WordPress. This works great since I have the design sense of a blind monkey. He would like to learn more about WordPress and how best to design for it. I'm familiar with several good WordPress books, but most of them are intended for designer/developers. I'm looking for something that will serve as a guideline, offering suggestions for design conventions that are well suited to WordPress. Are there any such books? If there's not a book specifically aimed at designers, which other book would you suggest?
Some said this rockable book is awesome, though I don't buy it myself. I'm backend wordpress developer not front end, so I guess this book is not for me.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "design, books" }
Wordpress change author email notify message? just want to change a little bit author email notify message(wp_notify_postauthor - pluggable.php),and I'm applying filters on comment_notification_text function myfunction(){ return "<div class='left_side'>"..$comment..$post.."</div>" } add_filter('comment_notification_text', 'myfunction'); How to access data $comment,$post,... in myfunction ?
$comment_id can be passed as second parameter to your function. Modify you add_filter: add_filter('comment_notification_text', 'myfunction', 10, 2); Then get $comment and $post from $comment_id: function myfunction( $notify_message, $comment_id ) { $comment = get_comment( $comment_id ); $post = get_post($comment->comment_post_ID);
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "customization, functions" }
Modifying admin sidebar contents to show pending posts indicator I've been trying to get a pending count to appear on the admin sidebar, for pending posts, like the little bubble that appears for pending comments: !Comments pending bubble _Offtopic_ : Am I the only one that thinks this should be core behaviour? Where should I suggest this feature? Anyhow, I found this plugin, but I noticed it didn't always worked. Sometimes the notifier appears on Pages or other item. The code it uses to add the pending count goes something like this: $menu[5][0] .= " <span class='update-plugins count-$pending_count'><span class='plugin-count'>" . number_format_i18n($pending_count) . '</span></span>'; So, clearly the problem is the hard-coded 5 there, but how can I update it so it always points to Posts? I'll be glad to commit this change to the plugin if we know the answer. Thanks!
**@ign** Replace the line of code you posted with the following.. foreach( $menu as $menu_key => $menu_data ) : if( 'edit.php' != $menu_data[2] ) continue; $menu[$menu_key][0] .= " <span class='update-plugins count-$pending_count'><span class='plugin-count'>" . number_format_i18n($pending_count) . '</span></span>'; endforeach; ..that **should** avoid the need to know the specific key.. (let me know if any problems).. Hope that helps.. :)
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "posts, admin" }
How to add a post from a custom post type as the static page? I have created a custom post type and added some custom metaboxes to the page edit screen. My objective was to provide specific metaboxes which a user can edit which in turn would allow a user to modify specific content areas of a websites homepage. Everything described above works perfectly except that I seem to be unable to set the page created from this custom post type as the "static page" within the wordpress admin "settings" area. It seems the dropdown which lets your select a static page only shows pages located within the default wordpress "page" post_type. How would I be able to change these settings to achieve my goal?
Unless a solution can be provided on this topic I will assume for the time being that the best way to get this to work is to just create a "home.php" file within ones template and query the post ID directly. I have accepted this as the answer for the time being but if anyone finds a solution after this answer is accepted please post it and I will accept that as the correct answer.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 4, "tags": "custom post types, pages" }
Can I load posts via Ajax? I would like to make a portfolio page where each entry (a post) would be fetched using Ajax. This way I would have an image gallery, but in which I not only would have images but also the description of the work, if it's for sale, the url to the shop, and whatever other random fields. A gallery is not good enough because there is no clean way of displaying text belonging to each image's post.
Absolutely! There are a number of themes on the market that do load posts via AJAX. Take a look at any of them to get an idea of how they work. A particularly good example is K2 \- K2 loads entire pages of posts via AJAX if you click on the previous posts link. To really get your hands dirty, check out this awesome tutorial on loading posts via AJAX. Just keep in mind, AJAX is all about using JavaScript to request data from a server - your server in this case is running WordPress and is built to produce posts based on specific requests. All you need to do is add the JavaScript layer to request them on demand.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "posts, gallery, ajax, images" }
How to call a custom post with get_posts() instead of query_posts()? I currently use `query_posts` to show these custom posts but I'm pretty sure that I should uses `get_posts()` to write it correctly. <?php query_posts( array( 'type-mario' => 'games', 'showposts' => 10 ) ); ?> <p>Mario games</p> <?php while ( have_posts() ) : the_post(); ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <h2><?php the_title(); ?></h2> </div> <?php endwhile; ?> <?php wp_reset_query(); ?> Thanks for your advice.
Hi **Elium2009** : Using your code, I think this is what you were looking for? (note that `WP_Query()` is just the more direct version of `get_posts()`): <?php $posts = WP_Query(array( 'taxonomy' => 'type-mario' 'term' => 'games', 'posts_per_page' => 10 )); ?> <p>Mario games</p> <?php while ( $posts->have_posts() ) : $posts->the_post(); ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <h2><?php the_title(); ?></h2> </div> <?php endwhile; ?> <?php wp_reset_query(); ?> Hope this helps?
stackexchange-wordpress
{ "answer_score": 12, "question_score": 6, "tags": "custom post types, query posts" }
wordpress query_posts featured page always on top I'm using the query_posts for "Page" item rather than "Post". I want to have the ability to make the "featured" page always on the top, we could add a custom field called "featured_product", if it's eq "1" then display the post as the very first one. Here is the basic code for the query. Someone help please!? <?php query_posts(array('showposts' => 1000, 'post_parent' => $post->ID, 'post_type' => 'page', 'orderby' => 'title', 'order' => 'ASC')); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> ... <?php endwhile; else: ?> ... <?php endif; ?>
In your query posts array add this: 'meta_key' => (meta key name in database), 'meta_value' => 1 To make it at the top use two queries. One for the top first post and one for the rest of the posts/pages. so your whole query will look like this: <?php query_posts(array('showposts' => 1, 'post_parent' => $post->ID, 'post_type' => 'page', 'orderby' => 'title', 'order' => 'ASC', 'meta_key' => featured, 'meta_value' => 1); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> ... <?php endwhile; else: ?> ... <?php endif; ?> <?php wp_reset_query(); ?> <second query goes here as you have it in your post> Replace "featured" with your key name.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "query posts, sticky post" }
Can I integrate Google Analytics with my blog, hosted at wordpress.com? I have a blog hosted at wordpress.com. How do I integrate it with Google Analytics?
You can't. GA requires javascript, and wordpress.com doesn't allow it.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 3, "tags": "wordpress.com hosting, google analytics" }
Image archive without date I don't care about having images catalogued by date, I actually hate the subdirectories it creates by year and by month when you upload an image. Is there a way to store them all in the same folder?
Uncheck this box: **Setting/Media** [ ] Organize my uploads into month- and year-based folders
stackexchange-wordpress
{ "answer_score": 7, "question_score": 2, "tags": "media" }
Subscribe2 widget with choosing categories? Is it possible to specify the category people can choose to subscribe to in the Subscribe2 (Wordpress Plugin) widget?
there is an addon for subscribe2 that allows that called TT Subscribe2 Front End Plugin
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "widgets" }
wordpress 3.0 json issue im using the media finder plugin which works fine in 2.9 wordpress, but since the 3.0 wordpress, the json sans eval library which the plugin uses works no more. not sure what was involved in the upgrade from 2.9 to 3.0 core wise with json. here is a screenshot what firebug in firefox spits out, the actual json is parsed, but its not displayed. (media finder lets you search vid the media manager in your post) so since json eval sans is non validating, not sure if wp 3.0 doesnt like that. here is the url to the plugin < here is the screen shot of the error in the plugin anyone can assist would be a life saver, or even what is involved in converting the code from json sans eval to json2.js which wp is packed with now the code that would need to be converted to json2 would be the line xhr = $.post(ajaxurl, params, function(data) { data = jsonParse(data);
When I comment out the line: @header('Content-type: application/json; charset=UTF-8'); it works for me p.s. 1. there is also a ~~closing php~~ opening tag in it without the word php 2. there is a closing php tag at the bottom which can be gone 3. there is a notice on an undefined index. 4. better would be to use $charset = get_option('blog_charset'); I have no idea if this: < has something do with it, or this: < or this: < , did not dive in it.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "plugin development" }
Any plugin out there that uses WP's internal image uploader? I'm trying to use the media uploader thing from WP (the form from the pop-up with crunching and all that), and can't figure out how. Is there any plugin out there that uses it? It would be easier to understand...
The plugin Image Widget uses it. <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 5, "tags": "plugins, media, uploads" }
Does changing 'WPLANG' in wp-config.php just effect the admin language or does it have other consequences? I am curious to know if setting 'WPLANG' in wp-config.php just effects the admin language or does it have other consequences? I run a blog in a foreign language but use English in my admin. I initially set the WPLANG to the foreign language a while ago and used a plugin (admin in English) to keep the English admin interface whilst using an .mo file to translate the theme. I now use 'WPML' to manage the translations. I was wondering whether my WPLANG setting is still relevant and what it really means to the site? Thanks
WPLANG effects the whole site not just the admin section, you can use it in conjunction with WPML. It basically sets what language you have translations for but you must include a languages folder inside wp-include with the appropriate .mo and .po files. You can also set WPML to use the default languages directory ( which is set up by defining the language(s) in wp-config as I said above).
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "multi language, wp config" }
How To Modify New Sub Blog Immediately When Super Administrator Creates It? I want to trigger a function in a plugin when a new sub-blog is created in a multisite set up of WordPress. Is it possible? If so, to which action/filter should I hook? The motivation here is to modify the new sub-blog blog it has a preset arrangment of settings, theme, plugin options, plugin activations, content set up, etc. If there aren't action/hooks for this purpose are there any other ways to accomplish this?
U guess you can use the **activate_blog** hook
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "multisite, customization" }
How To Activate Plugins via Code? If possible, how can installed plugins (meaning the files have been placed in wp-content/plugins directory) be activated from other plugins?
This is how I did it in some web apps: function run_activate_plugin( $plugin ) { $plugin = trim( $plugin ); $current = get_option( 'active_plugins' ); $plugin = plugin_basename( $plugin ); if ( !in_array( $plugin, $current ) ) { $current[] = $plugin; sort( $current ); do_action( 'activate_plugin', $plugin ); update_option( 'active_plugins', $current ); do_action( 'activate_' . $plugin ); do_action( 'activated_plugin', $plugin ); } return null; } run_activate_plugin( 'akismet/akismet.php' );
stackexchange-wordpress
{ "answer_score": 34, "question_score": 25, "tags": "plugins, activation" }
Should I use is_admin() inside 'admin_init' hook callback I'm adding an action witht he following line: `add_action( 'admin_init', 'fb_init_scripts');` And my function looks like this: function fb_init_scripts() { //Only use these scripts in admin interface if (is_admin() ) { wp_enqueue_script('jquery-ui',' } } In this instance, is it pointless to use `is_admin()` to controll if I'm in admin panel, since I'm running this function in `admin_init` ?
Yep, pointless. `admin_init` only fires in admin area (and couple more files related to AJAX functionality) so additional `is_admin()` check is not necessary. It often comes up in examples for hooks that fire both on front-end and admin area.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 5, "tags": "admin" }
Best way to programmatically remove a category/term from a post I am working on a script to convert all posts in a given category to use a postmeta flag instead (testing of MySQL has shown me that on a site as large as mine this will lead to a meaningful decrease in query time). When converting posts I want to just fetch all posts in the category, add the postmeta then remove the category, which will let me just reload that function until there are no more posts in the category. I can't find a good function for removing a term from a post though. I want to give it the post id and the term taxonomy+ID and have it handled for me. I am also interested in plugins that can do the conversion for me if anyone knows of one. I couldn't find any that did cat->postmeta, unlike the opposite which can be handled by Scribu's plugin.
Hmmm, can't remember or find fitting function either. There is `wp_set_object_terms()` that is used in multiple wrappers like `wp_set_post_categories()`. It can overwrite categories for a post. So you can get post categories, check for unwanted one and write it back excluding unwanted in that case.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 8, "tags": "custom field, taxonomy, post meta, api" }
Using shortcode in template file this is shortcode in template: function shortcode_frame_left( $atts, $content = null) { return '<span class="frame alignleft">'. do_shortcode($content) . '</span>'; } add_shortcode('frame_left', 'shortcode_frame_left'); this is how using in post content: [frame_left] <a href="YOUR-URL"><img src="YOUR-URL" /></a> [/frame_left] I am trying to use this shortcode in template file for displaying post thumbnails. What i try: if (has_post_thumbnail()) { apply_filters( 'the_content', "[frame_left]".the_post_thumbnail()."[/frame_left]"); } and if (has_post_thumbnail()) { $thumbnail = '[frame_left]'. the_post_thumbnail() . '[/frame_left]'; echo do_shortcode("$thumbnail"); } What am i doing wrong?
`the_post_thumbnail()` echos the thumbnail and returns nothing. You probably want to use `get_the_post_thumbnail()` which returns it as a string. Your code currently is equivalent to this: if (has_post_thumbnail()) { // Echo the thumbnail the_post_thumbnail(); // Apply the filter but do nothing with the result. apply_filters( 'the_content', "[frame_left]"."[/frame_left]"); } if (has_post_thumbnail()) { // Echo the thumbnail the_post_thumbnail(); $thumbnail = '[frame_left]' . '[/frame_left]'; // Echo the <span> with an empty content echo do_shortcode("$thumbnail"); }
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "templates, shortcode" }
Get the latest taxonomy/category? I'm designing a custom magazine theme, where categories are used for different sections, and I created a custom "edition" taxonomy. The editor will create a new term in that taxonomy for each new edition published, i.e. the number of the issue. How can I query the latest "edition", so I can combine it with each category and then publish only the posts that belong to the newest edition? Something along the lines on: ?edition=34&cat=studies
The latest edition should always be the term in that taxonomy with the highest term_id, right? Query get_terms and find the latest edition, then use that term to build the rest of your query... $edition = get_terms('edition','orderby=none&order=DESC&number=1'); $latest_edition = $edition[0]->slug; Then you can either modify the current query, if that's what you want to do: global $wp_query; $wp_query->set('edition',$latest_edition); Or use it to build new queries: $studiesposts = get_posts('category_name=Studies&edition='.$latest_edition); If you have your permalink structure set up, it should also work to build urls for new links, like this:
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "custom taxonomy" }
Query 2 meta key values and a category I have a wp query that works great - it returns a list of featured posts. WP_Query("category_name=office&meta_key=featured_post&meta_value=Yes&posts_per_page=3"); However I want to add a 2nd custom key to the query (a custom order field) then order by the numerical value of the meta value of this key.. is it possible to use 2 meta_key values in a WP_Query? If not is it possible using an SQL query statement?
The query value parameters can be set to true ( returns single result) or false ( an array). < For instance <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "post meta" }
Getting Post details when post is published I would like to collect main info about post like Title etc. **in moment when post was written and it's going to be published** and perform some actions on this data. What's the hook for that? Thanks!
The function is `wp_insert_post()`, and as you can see there are some hooks you can use to modify data. `wp_insert_post_data` is a filter that gets all data right before it will be inserted into the database, so you modify it there and don't need to do anything to get it saved. At the end of the function you can see the `save_post` action and its equivalent `wp_insert_post`, which are more appropriate if you want to _do_ something (instead of _change_ something). These functions are fired when a post is saved, not only when it is published. For the publish action, look at `wp_transition_post_status()`, which has three hooks: * `transition_post_status`, called with the new and old statuses, and the post data * `{$old_status}_to_{$new_status}`, like `draft_to_publish`, called with the post data * `{$new_status}_{$post->post_type}`, like `publish_page`, called with the post ID and post data
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "plugins, customization" }
Showing Thumbnail from Previous and Next Posts Is there a simple way to use the post thumbnail when calling `previous_post_link()` and `next_post_link()`?
This could be acheived by using the `get_previous_post()` and `get_the_post_thumbnail()` functions. Then just pass the thumbnail value into the second parameter of `previous_post_link()`. $prevPost = get_previous_post(); $prevThumbnail = get_the_post_thumbnail( $prevPost->ID ); previous_post_link( '%link', $prevThumbnail );
stackexchange-wordpress
{ "answer_score": 10, "question_score": 2, "tags": "posts, post thumbnails, previous post link, next post link" }
How to replace "Password Protected" text with icon in Admin In Wordpress, whenever a post is password protected the backend admin area appends the text in bold "- Password protected" after the post title. What I am looking for is a way to remove this text and instead have it utilize an icon (link below) which should be appended before the title text. How can this be done? I want to use an Icon from the Aesthetica Icon Set by < !alt text
Try this (don't forget to replace icon URL): add_filter( 'display_post_states', 'password_protected_icon' ); function password_protected_icon( $post_states ) { $text = __('Password protected'); $pos = array_search( $text, $post_states); if( false !== $pos ) $post_states[$pos] = '<img src=" title="'.htmlspecialchars($text).'"/>'; return $post_states; }
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "wp admin, admin, posts, list, password" }
Trick to get custom post types to show up on a custom taxonomy page? I've setup a custom post type and a custom taxonomy for that post type, but I'm having one problem - on the custom taxonomy permalink pages, the content of the custom post that should be there is not being displayed. However, looking at the page source, I can see that there is a div that should contain the post content. Any suggestions on how to get the entire content to be displayed? Edit: The Custom Post Types UI plugin was used for the creation of the custom post types and the custom taxonomies. Edit 2: Turns out it was a Thesis problem. Design Options > Display Options > Archives was set to "titles only", which kept the content of the posts from being displayed.
By default, a custom post type isn't included in the standard query. You'll need to manually create a query in your taxonomy page for that post type.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, custom taxonomy" }
Link a custom post type child to a parent using dropdown I've got a custom post type called wine, this will be the main type, I also have a custom post type called review, I want to be able to associate multiple reviews with a wine and have this controlled in the review edit screen. On the Wine template I need to be able to link to the page listing all the reviews for that wine so the review needs to know the wine's $post->id Thanks, Mark
I would add a custom taxonomy called "wine" as well. You can use this taxonomy to associate reviews about the same wine and also to associate the "wine" custom post with the taxonomy. Then you can run a query to get all "review" posts that share the "pinot" term in the "wine" taxonomy, for example. This makes it easier to group posts, custom posts, and pages without needing to know `$post->ID` for anything. Justin Tadlock has written a fantastic explanation of custom taxonomies if you need a place to start ...
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types" }
How Is Network Activate Different From Activate (by Implementation)? How is plugin network activate different from normal activation by implementation? What is done/not done in network activation that is done/not done in activation?
Network activation will activate a plugin for every site in a network whereas regular activation will only activate a plugin for the site you're currently on. As far as implementation goes, there is one other important difference: If your plugin is built to do something when it's activated (via `register_activation_hook()`), this will fire automatically when you activate a plug-in normally, but it will _not_ fire for a network-activated plugin until you visit the admin screen for each blog. So if major database updates are tied in to `register_activation_hook()` they won't occur until you log in to the other sites.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 6, "tags": "plugins, multisite, customization" }
Formating the display of a post's date, outside the Loop I'm using this function to be able to retrieve several data, from outside the Loop: function get_post_data($postId) { global $wpdb; return $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE ID=$postId"); } ... and then, this to display the date a post was published: <?php global $wp_query; global $thePostID; $thePostID = $wp_query->post->ID; $data = get_post_data($thePostID); echo $data[0]->post_date; ?> wich displays something like "2010-06-14 22:36:03" in my sidebar, but I'd like to format it like just "June, 2010" Can it be done?
I'm using something like this: date('F, Y', strtotime($data[0]->post_date));
stackexchange-wordpress
{ "answer_score": 7, "question_score": 1, "tags": "formatting, date time, loop" }
How to Show Different Sidebars on Specific Pages? I'm making a blog where only on specific pages I want to show different sidebar, I will add some widgets to those sidebar, which I don't want to show in default sidebar. I've found a coding method to do this, but I would like to use a plugin, and not edit code myself. I need to give the control of adding/removing sidebar/widgets in client hands. So is there any plug-in to do this easily?
A client of mine recently used a plug-in similar to Widget Context to accomplish this. Rather than create different _sidebars_ you just define what _contexts_ you want your widgets to show up in. So if you have a set of widgets you want to show up on a specific page, you mark them to only show up on that page. But it allows you to continue using widgets that show up on every page/post if you want. The convenience of this plug-in is that you don't have to code anything, and it's got a fairly intuitive UI you can put in the hands of your own clients.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "plugin recommendation, sidebar" }
Weird problems after recovery from security breach The shared server that I used for hosting my WordPress website was hacked recently, and many of the `index.php` files, plugin files and uploads were deleted, with my MySQL databases untouched. But after having restored all of it from my local backups, I'm having some weird problems. 1. My homepage < does not fully load - the sidebar and footer are missing. If I view the page source, it ends at the point where the code for my sidebar starts. 2. I am not able to login to the dashboard. It throws a 500 error. Please help me fix this issue! P.S.: I have another WordPress blog on the same domain, at ` which is working perfectly without any of the above issues, after I restored the files from my backup.
Had you just overwrote site from backup? Not a good way since it may easily leave broken files or even backdoors. It is best to erase site completely, then copy clean WordPress archive and copy of your files from backup there. If possible it's best to restore database from pre-hack backup as well. If these are not possible I suggest you find someone who handles such cases professionally. There is now way to comprehensively advice on hacking case "in theory".
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugins, wp admin, errors, security" }
allow editors to edit menus? I would like to be able to grant my editors the power to change the menu, can this be done? The appearance tab doesn't appear to be an option at all, can I make it so?
add this to your theme's `functions.php`: // add editor the privilege to edit theme // get the the role object $role_object = get_role( 'editor' ); // add $cap capability to this role object $role_object->add_cap( 'edit_theme_options' ); * * * Update (suggested in comments): > You probably shouldn't do this on every request, AFAIK this causes a db write. Better on `admin_init` and only if `!$role_object->has_cap('edit_theme_options')`
stackexchange-wordpress
{ "answer_score": 70, "question_score": 54, "tags": "user roles" }
how to query posts by category and tag? I am trying to show a list of posts that are related to category X and tag Y. I've tried the following code: $args = array( 'posts_per_page' => 4, 'tag_id' => $tag_id, 'cat' => $cat_id, ); query_posts($args); but it doesn't work correctly and returns all the posts in the co\ategory. Would love to hear any insight you might have
### Edit: See below for proper way to query category and tag intersections. global $wp_query; $args = array( 'category__and' => 'category', //must use category id for this field 'tag__in' => 'post_tag', //must use tag id for this field 'posts_per_page' => -1); //get all posts $posts = get_posts($args); foreach ($posts as $post) : //do stuff endforeach;
stackexchange-wordpress
{ "answer_score": 21, "question_score": 13, "tags": "query posts, tags" }
INSERT in table row fatal error I just discovered this wonderful message board :-) Hopefully someone can help me with a Wordpress issue I can't figure out.. I added a hook to my plugin file to insert the post id of the immediate posts I publish, in a table named "post_votes" - used to keep track of up & down votes for posts. function post_votes($post_ID) { $wpdb->insert( $wpdb->prefix . 'post_votes', array( 'post_id' => $post_ID ) ); return $post_ID; } add_action ( 'publish_post', 'post_votes' ); so the code above should add a post id in the post_id row (in post_votes table).. however I get, > Fatal error: Call to a member function insert() on a non-object for $wpdb->insert( $wpdb->prefix . 'post_votes', array( 'post_id' => $post_ID ) );
This is more or less a programming question. $wpdb is not available everywhere. It's a global variable. If you want to use it inside your own functions, just add `global $wpdb;` at the first line of the function. For general programming questions, this might be another discovery for you: stackoverflow.com,it is about programming in specific. Regardless being PHP (as with wordpress plugins) or javascript stuff. But for your wordpress problem, here is the code in full: function post_votes($post_ID) { global $wpdb; $wpdb->insert( $wpdb->prefix . 'post_votes', array( 'post_id' => $post_ID ) ); return $post_ID; } add_action ( 'publish_post', 'post_votes' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "query posts, hooks, database" }
Adding new row to wp_post table I want to add 2 more rows (for voting up or down) to my default wordpress posts table. Would those rows be deleted when I update my WP version, or cause any other problem? An alternative would be to create a separate table but it's much faster and easier to query from 1 in my case.
First, I assume you're referring to columns, not rows. To answer your question, no, the upgrade process will not remove the extra columns from the posts table. That said, WordPress has the wp_postmeta table that should be used to store extra data about posts rather than adding columns to the posts table. I would suggest using the postmeta table instead of modifying the core database.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "database, mysql" }
What do I need jQuery for? What do you think of killing jQuery in the public facing WP site? Isn't it useless and making for slower page loading? What's the best way to get rid of it?
jQuery is loaded by the theme that you use and not by WordPress. The theme must be modified to not load jQuery. Useless? not sure. It is very useful. Many themes' UI elements and even design elements may depend on jQuery.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "jquery" }
How to tell if the user is an admin? I need to show some info only to admins visiting a page, so I need a conditional tag to identify them. So far I have found: <?php if ( current_user_can('manage_options') ): ?> is this the correct function?
Yes, that's good. You can be a little safer using `<?php if(current_user_can('manage_plugins') ); ?>`
stackexchange-wordpress
{ "answer_score": 6, "question_score": 2, "tags": "theme development, conditional content" }
Use a wordpress page to display a certain category I'm trying to set up a portfolio page on my wordpress website, and I would like the following construct: * /blog/ where I blog all kinds of things, including portfolio entries * /portfolio/ where I show just posts from my portfolio category * some regular /pagename/ pages (about, contact, etc) I want the portfolio section to have a separate style (and even html probably) than a regular category overview. So if someone clicks one of the categories in my blog they still see the normal /category/randomcategory/ overview page. This means I can't just change the category php page and/or the css, because the portfolio page is different from the regular view. Is there a way to set up my page so that it shows the posts in the category portfolio the way I want?
The page of posts example pulls posts from one category, it uses a custom field to designate the category, which in turn makes the page template re-usable on other pages with other categories to, if you so choose.. You can style that template however you like.. Hope that helps..
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "categories, customization" }
Encoding Method for URLs? Is there a method or API that WordPress uses to encode the URLs similar to how it generates part of the URL when using the title in the URL? I am writing a plugin that generates URLs and would like to use the same method as everything else is. For instance, I type "This is my blog post" in the title and "this-is-my-blog-post" gets generated.
On a lower level, the function `sanitize_title_with_dashes()` converts to lowercase, replaces spaces and non-alphanumeric characters with dashes, and urlencodes whatever you pass to it. <?php echo sanitize_title_with_dashes( 'This is my blog post' ); // this-is-my-blog-post
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin development, api" }