INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Set template for custom post type? Is there a way to add the template selection dropdown to the custom post type? Perhaps under Page Attributes?
So far it seems there is no native way to do it in WordPress, correct me if I am wrong. If you are okay with using plugins there is Custom Post Template that you could try.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, page attributes" }
How to add a 2nd "featured image" to a post? My theme has a slider widget that allows the end user to select a category and it assigns the posts in that category to the slider. If a post has a featured image, its used as the background of the slide for that post. However, there are cases where the featured image on the post itself needs to be different that the one used in the slider. What are some options for a workaround? Ideally, I'd like to just create a clone of the "Featured Image" panel, calling it "Slider Image". How difficult would that be? What files do I need to clone? Any plugins that already do this?
This plugin has worked for me in the past: < Or you could create a custom field - Advanced Custom Fields makes this very easy (and for the end user too): < This could be integrated by using the traditional 'featured image' as the slider image - ie leaving `<?php the_post_thumbnail(); ?>` or equivalent in the loop that makes your slider. Then when displaying the post, you could check if the post has a secondary image attached, and fall back to the featured image if not. Something like this with the Advanced Custom Fields Plugin (untested code): <?php if (!( $secondary = get_field('secondary-image'))) { the_post_thumbnail(); // or however you like to do it } else { echo wp_get_attachment_image($secondary); } ?>
stackexchange-wordpress
{ "answer_score": 2, "question_score": 5, "tags": "theme development, post thumbnails" }
Can I use $query->set() (in a pre_get_posts() hook) with a custom taxonomy in WP 3? I can do something like the following with a standard category: $query->set('category__not_in', $term_id); But how do I do the same with a custom taxonomy term? I'm using Wordpress 3.3.1 if it is relevant. Thank you. :)
For what it's worth, I just gave up on the '__not_in' approach and went with the following somewhat sneaky solution: //Create the exclusion rule $new_tax_query = array( array( 'taxonomy' => 'x_category', 'field' => 'slug', 'terms' => array('y-slug'), 'operator' => 'NOT IN', ) ); //If there is already a tax_query, 'AND' our new rule with the entire existing rule. $tax_query = $query->get('tax_query'); if(!empty($tax_query)) { $new_tax_query = array( 'relation' => 'AND', $tax_query, $new_tax_query ); } // var_dump($new_tax_query); $query->set('tax_query', $new_tax_query);
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom taxonomy, query, pre get posts" }
Difference between 'LIKE' and 'IN' in meta queries You can use a variety of different comparison operators in meta queries, among which are `'LIKE'`, `'NOT LIKE'`, `'IN'`, and `'NOT IN'`. What is the difference in use between `LIKE` and `IN`? Here's the relevant section of the WP Query Codex page: > ### meta_query ( _array_ ) - Custom field parameters (3.1) > > * **key** ( _string_ ) - Custom field key. > * **value** ( _string_ | _array_ ) - Custom field value ( _Note_ : Array support is limited to a compare value of 'IN', 'NOT IN', 'BETWEEN', or 'NOT BETWEEN') > * **compare** ( _string_ ) - Operator to test. Possible values are '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'. Default value is '='. > * **type** ( _string_ ) - Custom field type. Possible values are 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'. Default value is 'CHAR'. >
Meta queries are essentially wrapper for ease of setup, but end results is part of SQL query to run on MySQL database. These operators are those of MySQL, see in documentation: * `LIKE` operator (performs pattern matching) * `IN()` function (checks if value is in set)
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "custom field, wp query, mysql, meta query" }
How can I get posts from 9/13/11 to today with SQL? I have been working with a client to redesign his site and we are at the stage where we are going live, except I'm running into a little problem. Time is of the essence, as the deadline is mid-day tomorrow. Since I began working on the site, he sent me a database of posts from the beginning of time up until September 13, 2011. Now that we're going live with the new design, I need to update the posts in the new database from that day up until today so they don't get lost in the process. I tried using WordPress' export feature, unfortunately there are far too many posts for it to allow me to even download the file. So what I want to do is use an SQL query to get these posts, and export a `.sql` file in phpMyAdmin. Can anybody give me an example of how I would do this? Any help is appreciated, thanks.
![](
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, sql, phpmyadmin" }
What is the correct way for a theme to support plugin UIs? For instance if my plugin is creating a form on a page, what can I do to make it as easy as possible for theme developers to skin the form too?
First of all, provide a **well-formed default HTML form**. Use `<label>`, `<fieldset>` and `<legend>` where appropriate. This markup provides a good structure for CSS styling. Adding in some CSS classes may help too. Provide a **filter** that allows developers to tweak the default form. To go even further, you can allow developers to completely rewrite the form output to their likings by allowing them to provide a **custom form template file** within a theme. if ($custom_form = locate_template('plugin_form.php')) { // Load custom form include $custom_form; } else { // Default form with filter $form = '<form><!-- Default HTML --></form>'; $form = apply_filters('pluginprefix_form_output', $form); echo $form; } Have a look at the `get_search_form()` function in `wp-includes/general-template.php` for a good example of a similar implementation.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "plugins, plugin development, theme development" }
Is Wordpress secure enough for a multi-user article directory? One of my friends is going to launch a small article directory (ex: < using WP. The site will be hosted on a shared hosting in the beginning and will be moved to a dedicated server in the future. The site will be open for public registration like any other article directory and each registered user can manage their posts using the WP admin. The user role will be set to **Author** for all the registered users. The question is that whether **WP is secure enough** for an article directory setup like this and whether the registered users can hack/de-stabilize the site even if all the WP security hardening is done. In a nutshell, **the main concern is with the open registration.** Please advice.
Wordpress is only as secure as you make it. Open registrations should not be a problem if you: 1. Use CAPTCHA for registrations. 2. Use double opt-in: have users verify their email after they register. By default, registered users must be subscribers and after they are verified, you can set them as authors. Wordpress users cannot by default hack/destabilize the installation. Your main concern would be external hackers. Use all the hardening that you can and be wary of upgrading WP. There are many websites that trust WP for such a setup. I think < also uses WP - very effectively too. :)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp admin, security, user roles, user access, user registration" }
Parse error: syntax error, unexpected I get this error when I enter data in my form Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in \functions.php on line 77 return '<span class="vwbx">Views</span>''<span class="vwbx">$count.</span>'; ==== Whole function=== function getPostViews($postID){ $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); return "0 View"; } return $count. '<span class="vwbx">Views</span>''<span class="vwbx">views</span>'; }
The problem is that you have two strings that aren't actually being appended together. Try replacing return $count. '<span class="vwbx">Views</span>''<span class="vwbx">views</span>'; With return $count. '<span class="vwbx">Views</span>'.'<span class="vwbx">views</span>'; (note the added period in the centre). Or instead, remove the two quotation marks from the centre: return $count. '<span class="vwbx">Views</span><span class="vwbx">views</span>'; That should work :D **EDIT** In response to your comment... I think you'll be wanting to replace it with: return '<span class="vwbx">Views</span><span class="bxarw"></span><span class="CntBx">'.$count.'</span>';
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "errors" }
Image crop, resize and compression plugin? I've been looking through the plugins to find one that will allow the user to resize & crop images within WP. This has been the one area that clients struggle with - mainly those who don't have any photo editing software on their computers. Also, if there's one that deals with some kind of image compression options then that would be great as some clients have put some huge images on pages. Has anyone got any pointers or experience with any of the plugins out there to do this? **Update:** Image rotation would be nice too!
WordPress has cropping and resizing and rotation built in. Tutorial: <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, images" }
Edit Comments Form in TwentyEleven Is there a way I can edit / change the layout of the comments form (leave a reply form) in the TwentyEleven theme? I want to put the textarea on top and I can change the styles via css but physically moving the forms is where I'm having trouble. I'm not sure where to find the code for it. tl;dr Where's the comments form code?
The comments template is added to template files via the `comments_template()` template tag. The `comments_template()` template tag includes the `comments.php` template-part file. The `comments.php` template-part file includes the comment-reply form via the `comment_form()` template tag. Refer to the Codex (linked) for detailed instructions for modifying the content and output of `comment_form()`.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "comments, theme twenty eleven" }
Showing option when page is frontpage Currently I'm having some difficulties with below snippet. As it currently works it shows `the_excerpt_rss` on a single post and single page. AND it shows the option on `is_home()`. But what if a page (instead of the 'blog') is the frontpage? If possible I'd like to include the option as well. I've tried several versions of including `is_front_page()` but without any luck thus far. The snippet I'm currently using: <?php if (is_single() OR is_page()): if (have_posts()): while (have_posts()): the_post(); ?> <meta name="description" content="<?php the_excerpt_rss(); ?>"> <?php endwhile; endif; elseif (is_home()): ?> <meta name="description" content="<?php $options = get_option('schema_theme_options'); echo $options['metadescription']; ?>"> <?php endif; ?>
Try `if ( 'page' == get_option( 'show_on_front' ) ) {}`. ### Edit > but I've tried adding and replacing `<?php endwhile; endif; elseif (is_home()): ?>` with both of your code. Could you perhaps include your snippet with mine? I'm not sure why you would do that. I was specifically answering this question: > But what if a page (instead of the 'blog') is the frontpage? If possible I'd like to include the option as well. The answer to that question is what I posted: `if ( 'page' == get_option( 'show_on_front' ) **However** , that won't actually solve your problem, if I'm reading your code properly. Reading what you're asking, this _should_ work: if ( is_single() || is_page() || is_front_page() ) (Note: I used `||` instead of `OR` as the Boolean operator.) To be honest, I'm somewhat surprised that this works on static pages. I didn't know that they generated RSS output.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "frontpage, options" }
What is a good way to implement photo galleries on Wordpress? I want to publish about 1GB of photos on my Wordpress-powered website. I want viewers to load the photos quickly, but also tobe able to download high-resolution versions. Here is what I have tried. 1) Using NextGen: This seems great, but when huge photos are uploaded, NextGen does not automatically shrink them, making galleries very slow. 2) Using Flickr: Unfortunately, many of my clients view the photos from China, and Flickr is slow there sometimes. Besides, free Flickr has an upload limit of 300MB/month. 3) Picasa: Same, Google applications are slow in China. I am open to a budget of < $25/year, but would really appreciate free services. Thank you.
I don't understand the problem with NextGen. For a "gallery page" it creates thumbernails which are small (in fact as you can set the size up as you want it). The same goes for opening images themselves - you can set up the resize option for the full size size of images. Example - it means that if you upload a 5000x5000px image, you can tell NextGen to automatically create thumbernails that are 150x150px, and to shrink images to 1000x1000px. I mean, if you have really huge photos and you do not resize them, it will take some time for the browser to load them up, there is no going around that.. Or maybe what you want is to have auto thumbnail and image resizing (150x150px thumbs, and 1000x1000px) for viewing in the browser, but to also keep the option of downloading the original full size image? Perhaps plogger or zenphotopress might better suit your needs.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "gallery" }
Blog pagination WITHOUT using max_num_pages WP 3.2.1 I'm in a bit of a bind. I have to create some pagination for the blog, but I believe I'm running into the bug described here, and I don't have authorization to fiddle with the server's `php.ini` file. So, I need to find a way to create pagination for the blog without having max_num_pages. Is that possible? I don't want to re-engineer the blog loop if I don't have to. EDIT: max_num_pages isn't even in the list of query_vars when I print them with `print_r($wp_query->query_vars);` EDIT 2: Similarly, found_posts isn't in $wp_query, either. If it helps, I'm using a modified version of Avia as the theme.
Try: ini_set( 'mysql.trace_mode', 0 ); … in your `functions.php`. Maybe an .htaccess entry … php_value mysql.trace_mode 0 … works too. I haven’t tested it.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "pagination, loop, blog" }
Changing max number of blog posts per page doesn't work WP 3.2.1 Changing the max number of posts to show on each page via Settings->Reading isn't working. Could this reported bug be the culprit?
If it doesn't work then there must be some problem or overwrite in your custom theme, add this code in your index.php or where ever you want to show the custom number of posts, query_posts( $query_string . '&posts_per_page=1' ); change '1' to any number you want
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "options, blog" }
how to show content of latest blog post with read more link? I want to show the latest blog post content in my side bar with a read more link. So how will I do this?
Use `get_posts()` and set `'numberposts'` to `1`. The first and only entry will contain your latest blog post as a post object.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "blog, read more" }
SetCookie simply not working I cannot get a cookie to set properly through WordPress theme. I am putting the following code on the bottom of my `functions.php` page for my theme. function set_cookie() { if (isset($_GET['id'])) { $referrerID = $_GET['id']; setcookie('referrerid', $referrerID,time()+ 3600 * 24, COOKIEPATH, COOKIE_DOMAIN, false); } } add_action( 'init', 'set_cookie'); I even went as far as using JavaScript to alert if the script reached the function (which it did). Why are my cookies not being set?? (The code works locally - outside of WordPress that is).
Make sure the HTTP headers are not sent already at the point you want to set the cookie. Here's how you can test that: function set_cookie() { var_dump(headers_sent()); // should be bool(false) ... Turning `WP_DEBUG` on in your config.php file may help also while debugging. * * * By the way, you really should be doing some filtering on `$_GET['id']`. This variable could contain anything. Casting it to a (positive) integer should go a long way: $referrerID = absint($_GET['id']); // Note: absint() is a WP function
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "php" }
How to add attachment without uploading? When save post, I made dir in wp_uploads_dir, and copied 2 files and one folder in this dir. Now I want to do the WP_insert_attatchment process to make the 2 files as attachements. How can I do it? Edit: I inset_attatchement by directly using their URL. Now they show up in Media Libray, but I can't see whether the attachment_id is recorded or not. Which table in database can I go to find it?
You need the local path to add an attachment: // add the file to the media library $attachment = array( 'post_mime_type' => 'image/png' // the MIME type , 'post_title' => 'Attachment title' ); // Adds the file to the media library and generates the thumbnails. $attach_id = wp_insert_attachment( $attachment, $path ); // PATH!
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "attachments" }
BuddyPress admin bar links are broken I have activated BuddyPress on a blog but the link `My Account` on the admin bar is broken. I have configured BuddyPress to auto create pages but still the problem persists. I have been searching Google for two days now. Please help. Thanks
Buddypress requires pretty permalinks to function properly. If you have set them up already try to go to the permalinks admin page and resave them and see if that helps. If your host won't let wordpress write to an .htaccess file, that page will also show you what should be in it. < <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, buddypress, admin bar" }
Add title & subtitle to shortcodes Is there a way I can add a custom title & subtitle to this shortcode function? function spoiler( $atts, $content = null ) { return '<div class="moreinfo"> <h3 class="click drop subtitle"> <!-- title & subtitle go here --> </h3> <div class="morecontent"><p>' . $content . '</p></div><!--/.morecontent--> </div><!--/.moreinfo-->'; } add_shortcode('spoiler', 'spoiler'); Obviously the title & subtitle would go there the comment is in the h3 tag.
function spoiler( $atts, $content = NULL ) { extract( shortcode_atts( array( 'title' => 'default title', 'subtitle' => 'default subtitle', ), $atts ) ); return '<div class="moreinfo"><h3 class="click drop subtitle">' .'Title:'.$title.'Subtitle:'.$subtitle. '</h3><div class="morecontent"><p>' .$content. '</p></div><!--/.morecontent--></div><!--/.moreinfo-->'; } add_shortcode( 'spoiler', 'spoiler' ); //[spoiler title='title' subtitle='subtitle']content[/spoiler] Docs: `add_shortcode`, `extract` That should allow you to display the title and subtitle by applying them as attributes. You could, if you liked, do processing on content and use some sort of divider (say || or something that would never be used in the text) and do an `explode()` on the content based on that divider...your call.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "functions, shortcode" }
What code removes the admin bar for all users in WordPress 3.3? How can I remove the admin bar in both the front and backend for all users in WordPress 3.3?
/* Front end */ show_admin_bar( false ); /* back end */ function disableAdminBar(){ remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 ); function remove_admin_bar_style_backend() { echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>'; } add_filter('admin_head','remove_admin_bar_style_backend'); } add_action('init', 'disableAdminBar'); Modified version of <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "admin bar" }
Sub-directory blog on a sub-domain WordPress network site I have a WordPress Network install with the individual sites installed on subdomains. * example.com * a.example.com * b.example.com I would now like to launch a blog on each of the sites. It'd like the blog to be situated in a `/blog` sub-directory of each of the subdomains, but as the blogs would be completely separate from the website and use it a different theme, I think it makes sense to have them as separate sites in the network. In other words, what I'd like to have is: * example.com * example.com/blog * a.example.com * a.example.com/blog * b.example.com * b.example.com/blog Each of the above being a separate WordPress Network site, with different themes, admin panels, etc. Is there any way to accomplish something like this? Thanks! P.S.: The site runs on nginx.
I've finally solved it by installing a separate WordPress instance in the /blog folder. Both the root and the /blog are Network subdomain installs. Surprisingly enough this works without any conflicts and I didn't even need the Multi Network plugin.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 3, "tags": "multisite, cms" }
How can I add a menu item to the admin area? I've used almost all of the Wordpress example code but it still doesn't work. I've put the php file under wp-content/plugins/menuitem/ .The code is simple <?php add_action('admin_menu', 'donations_overview_menu'); function donations_overview_menu() { add_options_page('Donations overview', 'Donations overview', 'manage_options', 'donations-overview', 'donations_overview');} function donations_overview() { if (!current_user_can('manage_options')) { wp_die( __('You do not have sufficient permissions to access this page.') ); } echo '<div class="wrap">'; echo '<p>Here is where the form would go if I actually had options.</p>'; echo '</div>'; } ?>
The code itself is fine. But you would need to activate the plug-in: you can't simply place the file in the plug-ins directory. You will need to give the plug-in a 'header' too. See the Codex. Alternatively, place the code in your theme's functions.php, but really it should be in a plug-in.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "admin, menus, admin menu" }
Daily notices of failed login attempts for non-existent admin user I run a multi-user site and for the past week or two I have been getting daily notices that someone is getting locked out due to failed login attempts for user "admin" via the Limit Login Attempts plugin. There is no user account for "admin" and I assume this is an attack in an attempt to gain access to the wp-admin section of the site. I'm assuming if there is no "admin" user, then these attempts will never be successful. Am I safe to disregard these notices since there is no user named "admin" or are there other measures I can take to safeguard my site from being accessed maliciously? The attempts have been from a few different IP addresses so blocking the IP would only temporarily deter the behavior. Limiting the wp-admin to only specific IP addresses is not realistic due to the number of users that log in from different places.
Yes, you can safely ignore it, especially if your site has no "admin" user. The brute-force attack will never accomplish anything. I also use Limit Login Attempts - mainly for this very purpose. It lets me know when manual brute-force attempts are being made on my back-end login. (Last time I bothered to WHOIS the IP, the attack was coming from Russia, FWIW.) Short of blocking the IP address, there is little you can do to prevent brute-force attempts. If they get to be bothersome, just increase the lockout duration.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "admin, login" }
How can I customize the upload error message in Wordpress? After following the guide for How can I prevent uploading bmp image? to remove bmp (and in my case tiff images) from being uploaded, I tested and it is working, but noticed users are now getting the error message: Sorry, this file type is not permitted for security reasons. screenshot-with-shadow.png That looks to be in the `wp-admin/includes/file.php` folder: if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) ) return $upload_error_handler( $file, __( 'Sorry, this file type is not permitted for security reasons.' )); and also further down: if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) ) return call_user_func($upload_error_handler, $file, __( 'Sorry, this file type is not permitted for security reasons.' )); How can I hook into this so that I can change the message to something a little more friendly?
This is untested, but I _think_ you can just define wp_handle_upload_error in your functions.php file and return custom error messages. If you look at where that function is defined in that file, if ( ! function_exists( 'wp_handle_upload_error' ) ) { function wp_handle_upload_error( &$file, $message ) { return array( 'error'=>$message ); } } You can see it first does a test to see if the function is defined, so it would be safe to create another one (of course, in your own code, also check to see if its defined just to be safe). You'll have some experimenting to do, but hopefully this puts you on the right path! Cheers~
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "hooks, uploads, multi language, language" }
Limit the amount of words displayed by the Latest News plugin, or recommend an alternative I am using the Latest News plugin (made by James Piggot, plugin website is here) and I have inserted code that displays 5 of the latest news items in the sidebar area. It's working fine, and displays all I need it to display. However, I want to be able to display the first few lines of the news article with a "Read More" link after it. There doesn't seem to be a way to do that with this plugin, and instead it displays the entire contents of the latest news item in the side bar. Does anyone have any experience using this plugin who could help guide me to restricting the amount of the post it displays? If it can't be achieved using this plugin, is there a plugin out there that I could use that would allow me to do what I need to do? Many thanks!
If you go into your /wp-content/plugins directory, and edit the `latest-news.php` file, on line 85 change: <?php the_content('read more...');?> ... to: <?php the_excerpt('read more...');?> Note that modifying plugins is risky, because if you do an automatic update of the plugin after this, your changes will be modified. Because of this, it is advisable to branch your plugin before making changes.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "plugins, plugin recommendation" }
Don't display a sidebar widget when on a specific page I am trying to stop latest blog items from displaying in the blog section of my site. I have used the following code: <?php if ( is_page('blog') ) { ?> <h2>Don't display anything</h2> <?php } /* for all other pages */ else { ?> <h2>Display blog</h2> <?php } ?> However, whenever I am on the blog page it displays "Display Blog", completely ignoring the if statement. Is there something I'm missing from getting this working?
Assuming that the `'blog'` slug is correct, your code would work. I would suggest making a separate template for the page, namely page-blog.php (see < and < where you set up the structure and appearance of the page exactly as you want it to be. WordPress will automatically look for the file when opening a page with the name of `'blog'` (that is, the slug must be `'blog'`). Also, the code you posted above would normally go in loop.php, granted that you are using the default template-setup.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "php, widgets, sidebar" }
why doesn't my rewrite rule work? (is there something weird with wordpress htaccess?) My ht access includes: Options +FollowSymLinks RewriteEngine on RewriteCond %{REQUEST_URI} ^/preview/(.*)\-[0-9]+$ RewriteRule ^/preview/(.*)\-[0-9]+$ /$1 [R=301,L] but still when I try to access something such as: < it doesn't redirect (where < will work...) im using a plugin: Wp htaccess Control to add the rule, so it's definitely being added to the wordpress rewrite rule system, but it's not having any effect? are there any more wordpress quirks I need to avoid? Is there a basic error I'm missing?
Sooo the problem was my brackets around the content in the condition I think. I'm still not so hot on these things, but I use these rules and they work: RewriteCond %{REQUEST_URI} ^/(review|preview|feature).*\-[0-9]+$ RewriteRule ^review/(.*)\-[0-9]+$ /$1 [R=301,L] RewriteRule ^preview/(.*)\-[0-9]+$ /$1 [R=301,L] RewriteRule ^feature/(.*)\-[0-9]+$ /$1 [R=301,L] note: the (review|preview|feature) but is an x OR y OR z, as I have the rule working for any of those folders specifically.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "mod rewrite, redirect" }
Foliopress WYSIWYG editor does not display images I use the Foliopress WYSIWYG editor. I inserted overview-1.png via the 'Quick Insert Image' option. This added the following mark-up: <img width="166" height="263" alt="overview 1" src="images/2012/01/overview-1.png" /> The width and height attributes are correct yet the editor can't find the src. But on the FE the img gets displayed. How do I display the img in the WYSIWYG as well?
A base-Element in the front-end's header was the reason, why it worked in the fe but not in the editor.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "editor, wysiwyg, images" }
Last class on last headline? I have the following code which should add a last class to the fourth post but doesn't appear to be, what is wrong with this coding? It show's 4 posts fine but the fourth one doesn't have the class last attached to it. <div class="headline-strip"> <ul> <?php if (have_posts()) : while (have_posts()) : the_post(); $count = 1; if( $post->ID == $do_not_duplicate ) continue; ?> <li <?php if ($count == 4) : ?>class="last"<?php endif; ?>><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><span> <?php the_post_thumbnail( array (176,176) );?> </span> <?php the_title(); ?> </a></li> <?php endwhile; $count++; endif; ?> </ul> </div>
`$count = 1;` is set in the while loop, so every time the loop runs it sets to 1 again. Place it before your loop and it will work. $count = 1; if (have_posts()) : while (have_posts()) : the_post(); Ow and the $count++ is outside the loop so it will only run after all the posts. Change that to: <?php $count++; endwhile; endif; ?>
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "php, css, loop" }
query usermeta from custom field I am using a plugin to create custom fields in the user registration. I have created a check box field called g300 which is the name of the meta_key stored in wp_usermeta. It looks like the value in the database is a comma when the checked it off. How could I return a list of users that checked off this box?
I haven't touched user functions so far, but according to the codex, should look something like this. $args = array( 'meta_key' => 'g300', 'meta_value' => ',' ); $users = get_users( $args ); **EDIT** This assumes that all the users with the field unchecked have a comma value ( for example, it won't work if the value in the DB is empty ). **Example 2** $args = array( 'meta_key' => 'g300', 'meta_value' => 'I will attend the G300 class,' //Was the comma intentional? If not, remove ); $users = get_users( $args ); if( !empty( $users ) ) { foreach( $users as $user ) { echo $user->display_name; //name echo $user->user_email; //email $meta = get_user_meta( $user->ID, 'is_700_a', TRUE ); echo $meta; //the meta field value } }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom field, customization, query, user meta" }
Ordering custom posts I have a page on my site that has customer testimonials. Each testimonial is a custom post. I want to order the testimonials arbitrarily. What's the best way to do this?
The way I previously did this, was by adding a custom field to my CPTs, and ordering by that value when I fetched my posts with WP_Query. $myquery = new WP_Query( array( 'post_type' => 'your_post_type', 'meta_key' => 'my_custom_field_name', 'orderby' => 'meta_value' ) ); However, I believe if you add 'page-attributes' to your 'supports' parameter when you register your CPT, you have the 'Order' field available, which you can order by. $myquery = new WP_Query( array( 'post_type' => 'your_post_type', 'orderby' => 'menu_order' ) );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types" }
Text and image in taxonomy page I want my taxonomy pages have some custom text and an image before the list of posts and excerpts. I need it for a personal travel blog. I have a "travel" taxonomy that keeps all travels I've made ("egypt", "china", "italy"...) and now I want to show some introductory text before te list of post related to this _travel_. For example, if you go to _www.domain.com/travel/italy_ you will find: > Italy is an European country [photo] > > Post 1 - excerpt > > Post 2 - excerpt .... If you click on _www.domain.com/travel/china_ : > China is the most populated country in the world [photo] > > Post 1 - excerpt > > Post 2 - excerpt I know I can get it easily by creating a page for each travel, but then the list of post for the given travel taxonomy won't be automatically generated (I need this feature).
Use the description field and the plugin Taxonomy Images from @mfields.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "custom taxonomy" }
$post->ID and the_id() always return the wrong value I have a site where I display the same exact footer on every page. There is one exception, though. On one certain page I need to change one small part of the footer. I figure the simplest way to do this is to check, within the footer, whether I'm on that page or not. It wouldn't make sense to change the whole entire footer for that page since I'm only changing a tiny part of the footer, deep within the footer. The problem is that whenever I call `$post->ID` or `the_id()` from within the footer, it gives me an ID that clearly doesn't match the post I'm on. It always gives me `89`, no matter what page I'm on in the site. I figure I must be doing something wrong. Can anyone tell me what it is?
It sounds like you are altering the global `$post` data somewhere (usually another loop). Be sure to call `wp_reset_postdata()` after you are finished with something that sets up post data in an alternate loop.
stackexchange-wordpress
{ "answer_score": 16, "question_score": 5, "tags": "posts" }
Custom /Page/2/ Template Only Is there a method of doing this? Can I use PHP to say `if(URL=page/2/) { }` or something like that within my template? Essentially, I want an ad to appear in my sidebar when a user clicks 'Older Entries' and Wordpress directs them to "myblog.com/page/2/". I'm pretty sure I know how to accomplish this with JQuery, but I was wondering if there was a way through PHP, and without a plugin. Thanks WPA
PHP has the [`$_SERVER[]`]( variable, you can use this to get just about anything contained in the URL, you'll probably want to look at `PATH_INFO` as a launching point. You can use `strpos()` (or, if you want to have better results, `preg_match()`) to check whether or not the string you get from `$_SERVER[]` contains the desired string.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "templates, sidebar" }
query if page has not child I'm trying to create a page which display a few of sub pages (child pages), however if the page has not child I would like to display a message. I cannot get a query that allow me to do something like this: if (Page has childs) { do this } else { display this } Any help? Thanks in advanced
$args = array( 'post_status' => 'publish', 'post_parent' => $post_id ); $children = get_posts( $args ); if( count( $children ) > 0 ) { //has children } else { //does not have children } Docs: `get_posts()` This should also allow you to have access to the data of the children, should you need it. If you need any additional parameters in `$args` (a post type, for example), make sure to include those.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "query, child pages" }
Custom Text Under Navigation Links My navigation bar of my wordpress theme is set up to wp_list_pages. I'd like to display text underneath those page links. Like: * * * Home "Home Sweet Home" * * * Do I need a widget to accomplish this or is it relatively simple to implement?
Yes, but you need to use a custom walker. You must modify the function that traverse the page and output the HTML. Extend the basic wordpress class and implement your function. See this stackechange post for a code example. Note: I suggest you to use wp_nav_menu (custom menus) instead of wp_list_page and use the item description as your sub_menu item description.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "plugins, pages" }
Insert the current theme header into an external HTML/XHTML file My Emacs org-mode projects get exported to XHTML files. I would like to loosely integrate them into my blog. In particular, I'd like to use the header (and possibly footer) from my theme in the XHTML file. Would it be possible to put something like `<?php include("../blog-wp-content/themes/my-theme/header.php");?>` (this obviously doesn't work) in my XHTML file to import the header from Wordpress? Are there other approaches to splicing the header with my file?
The key to answer was found on SO; here is the solution for my case: create a PHP file with the following: <?php define('WP_USE_THEMES', false); require('path/to/your-wordpress-dir/wp-blog-header.php'); get_header(); ?> //Contents of the body of your XHTML page go here <?php get_footer(); ?> Now you have an external page in the format of your Wordpress theme.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "themes, html, headers" }
Set Wordpress TinyMCE Editor To Readonly I am trying to disable the tinyMCEeditor in wordpress so it is `readonly` if the post has already been published. I already have the logic for determining if the post is published (by using `$post` object's `post_status` variable)but I have not found a solution for setting the `readonly` parameter in tinyMCE to `true`. Cross-Post from StackOverflow
You can hook into `tiny_mce_before_init` to modify the TinyMCE arguments to set the `readonly` attribute. For example (using PHP 5.3): add_filter( 'tiny_mce_before_init', function( $args ) { // do you existing check for published here if ( 1 == 1 ) $args['readonly'] = 1; return $args; } ); This will make the TinyMCE readonly, however it won't make the HTML editor readonly (that's not TinyMCE) and it also won't stop people using the Media Upload to insert images. However, that might not be an issue - because I would recommend you implement some server-side checking to prevent edits, as it's always possible for someone to send whatever content they want from the browser by manipulating the DOM etc.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "plugins, tinymce" }
"Master" Wordpress Multisite - Database Sync I've had an idea in my head about creating a Wordpress Multisite environment that would have Plugins along with them that would not only have "default" settings, but be able to update each blog's plugin options based on a "master" site. That way, instead of having to change settings through every site - you'd be able to just change it in one spot. Now I've seen < which can handle activating and setting specific plugin settings - but this wouldn't take care of any ongoing sync between the websites. There'd be times when certain settings shouldn't be brought over/synced, for things like an API key for Akismet for example. Any suggestions would be greatly appreciated. Thanks!
< or <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugins, multisite, database, get plugin data" }
Correct way of getting the current page uri Can someone please tell me how to get the correct url of the page the user is on? I need to grab the url and construct a new link. Here is the issue that I am having. For example, let's say I am on home_url() is $_SERVER['REQUEST_URI] is /myplugin/samplepage/?some_var=1&some_var=2 As you can see, if I do this $url = home_url() . $_SERVER['REQUEST_URI]; The outcome will be Notice the 'myplugin' in the url twice, which doesn't work.
The built-in `redirect_canonical()` uses the following: $requested_url = is_ssl() ? ' : ' $requested_url .= $_SERVER['HTTP_HOST']; $requested_url .= $_SERVER['REQUEST_URI'];
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "home url" }
How can I enable a TINYMCE rich text editor in the admin interface? I'd like to add some text above my category archives, and I'd like to use the built-in Wordpress TinyMCE editor to do it. I've seen some plugins like `black-studio-tinymce-widget` which does a nice job of adding rich text to a widget, but I'd like to set up TinyMce to be used in the description area of the Edit Category page. Is there a plugin to do this or how would I set up Wordpress to allow this? screenshot-with-shadow.png
Something like this looks ot be what you are after <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "categories, wp admin, tinymce, editor, plugin tinymce" }
Posts 2 Posts Plugin : error message everywhere Just upgraded to the last version of Posts 2 Posts plugin (I have the last WP version too) and I have the following error message on every dashboard page : « Warning: Connection types without a 'name' parameter are deprecated. in /home/.../wp-content/plugins/posts-to-posts/core/api.php on line 59 » Plus my website layout is destroyed. How can I fix this ?
You can fix it by adding a 'name' parameter to your `p2p_register_connection_type()` call, as shown in the wiki: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin posts to posts" }
Network: retrieve a list of latest posts I need to list all the latest x posts from the whole Network in my WordPress Network. I am already using the Sitewide Tags plugin to collect all posts in a separate blog, but I also need to list the latest posts elsewhere. Most scripts and plugins I have been looking at only list one post from each blog, but I need to list the latest X posts, sorted by date, and allow several posts from each blog site.
Have you considered using Sitewide Tags to populate one blog, then using the RSS feed from that blog to display the lastest posts wherever you need them?
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugins, theme development, multisite" }
Submitting POST data to a custom page template triggers a 404, why? I've got a simple custom page template with a form on it. This page can process the form itself, so the entered data gets submitted there as well, using POST. Submitting the form, however, results in a 404 in my blog's regular theme (default template). If I leave out all of the data entry elements in the form, so I'll be submitting an entry form, it somehow works. You can use this code to reproduce the error if you want to see for yourself. Any suggestions as to what could be wrong are much appreciated, thanks!
You need to change: <form action="index.php" method="post"> to: <form action="" method="post"> I'm guessing that this is just a test case, but be sure that your final template has calls to `wp_head` and `wp_footer` in there.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "posts, page template, forms" }
search results to a variable in search.php Is there any way I can get the search results to a variable in search.php file? Now I have the following code in my search.php file. <?php if (have_posts()) : ?> <h3 class="pagetitle"><?php _e( 'Search Results', 'buddypress' ) ?></h3> <?php while (have_posts()) : the_post(); ?> ...... I know the while loop uses some variable that contains the search results. Now I want to use this variable before the loop. I need this variable to do some processing before displaying the results.
<?php $search_query = get_search_query(); ?> I think you're searching for this function: `get_search_query()`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "search" }
Plugin for Marathon Running Event Management Is there a plugin that works to be a marathon running event management tool? I need things like ways to accept registrations, payments, and displaying the results when the event is over.
I find it difficult for you to find a plugin **SPECIFIC** for marathon, but you can check out some "normal" event managers like : < or < <
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "plugin recommendation, events" }
Delete all scheduled events with a particular hook I have several cron jobs all hooked to the same hook, but each with a different argument (a post ID). It appears `wp_clear_scheduled_hook` only clears job which match the argument passed with it (or jobs without any arguments, if no argument is provided). Is there a way to delete all the cron jobs associated with a hook, regardless of the argument that job has? (Without doing so 'manually' by looping through the IDs). * * * Seems an answer was deleted! To clarify what I would like to achieve: each post has an expiration date - and I would like to delete the post after this date. (An alternative option is to have one cron job - repeating every 24 hours that deletes any expired posts). However, I decided to create a one-off job for each post - but it seems you can't delete all the jobs at once without cycling through them.
4.9.0 introduced `wp_unschedule_hook()` <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 9, "tags": "cron" }
Is it recommended to pass some data to scripts in `wp_enqueue_scripts`? I have on many occasions used `wp_enqueue_script` to pass some 'query variables' to scripts like this: function my_enqueue_scripts(){ $tempurl = urlencode( get_bloginfo( 'template_url' ) ); wp_register_script( 'somescript', get_bloginfo( 'template_url' ) . '/js/somescript.php?url=' . $tempurl ); wp_enqueue_script( 'somescript' ); } add_action( 'wp_enqueue_scripts', 'my_enqueue_scripts' ); And I am just wondering if this is a 'best practice' or 'safe' to do, I don't see why it wouldn't be but I guess you never know until you ask. I'm just wondering what are the downsides of doing this, or even if there is an alternative/better way to do this. I also notice if I pass more than 1 variable, only the first one will actually be retrievable in the script. Is there something I need to do to make that work? Some advice would be great, thanks.
`wp_localize_script` is the “WordPress way” to pass data from php to javascript. See this post by Otto for more info.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "php, wp enqueue script, customization" }
Change order of comment fields Is there a way to display the comment field first and then the Name / Email / Website fields? I am using <?php comment_form( ); ?> in my theme. I am not looking for a CSS solution.
Some loose implementation of where I would start. The hooks `'comment_form_default_fields'`, `'comment_form_defaults'`, and the `'comment_form_{location}'` hooks look promising. Line 1569 of comment-template.php is doing the fields, and line 1575 is doing the main field, you might be able to "trick" wordpress into putting the comment field up top...but all that seems like it would take a lot of tinkering and time to get perfect, CSS is probably the best way to go about this unfortunately.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "comments, comment form, customization" }
In what files I can change country names of wp-ecommerce plugin? I am using the newest wp-ecommerce plugin and as I am selling to a non-english speaking country I would like all country names listed in my language in the cart. I search and all the files and changed in several files, but it did not help. Maybe, somebody know where I should change country name what it would be in my language in the cart?
The various currencies and their associated countries are stored in the database, `{$prefix}wpsc_currency_list`.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin wp e commerce" }
Comment moderation on custom post types I know that I can require all of the comments on my site to be moderated, but is there a way of forcing moderation for a specific custom post type (i.e. my CPT "species") whilst allowing instantaneous comments across the rest of the site? Thanks in advance,
Yes, this is possible. Comment moderation is an option, and is retrieved like any other option: get_option('comment_moderation'); the get_option function applies a filter before returning the value... return apply_filters( 'option_' . $option, maybe_unserialize( $value ) ); So what you'll want to do is `add_filter('option_comment_moderation', 'check_moderable_post_types')` and in your `check_moderable_post_types` function, check to see if the current post's post type is species. If so, return 1, and if not return the $value that is passed to the function! Edit: This _should_ do the trick: add_filter('option_comment_moderation', 'check_moderable_post_types'); function check_moderable_post_types($value) { if (get_post_type() == 'species') return 1; return $value; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "custom post types, comments" }
Custom taxonomy term as class? I'm trying to add a class to a container within a query, ideally I'd like to use the terms from a custom taxonomy I have setup (guide-categories). As an example: <div class="myclass *taxonomy term*"> -content- </div> Any help would be much appreciated, been looking around trying to find out how to do this for a while, but haven't had any luck yet!
You could do something like this <?php $terms = get_the_terms( $post->ID, 'taxonomy_name' ); ?> <div class="myclass<?php foreach( $terms as $term ) echo ' ' . $term->slug; ?>"> <!-- content --> </div> <
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "custom taxonomy, terms" }
Unbind postbox click handler I'm trying to unbind the click handler on post metaboxes so they no longer hide when the handle is clicked. I need to do this because I use the handle to contain `<select>` elements & when changing these the `click` event is fired. The code that binds the click handler is here: < Unfortunately the only way to unbind it seems to be editing this file & inserting the unbind inside `add_postbox_toggles` Hope anyone can help
You can just put the necessary javascript in a file and enqueue it on the necessary page: add_action( 'admin_enqueue_scripts', 'add_admin_scripts', 10, 1 ); function add_admin_scripts( $hook ) { //You can globalise $post here and enqueue the script for only certain post-types. if ( $hook == 'post-new.php' || $hook == 'post.php') { wp_register_script( 'my_js_handle','/path/to/js/my-js-file.js',array('jquery'),1,true); wp_enqueue_script('my_js_handle'); } } With the javascript file containing: jQuery(document).ready(function() { jQuery('.postbox h3, .postbox .handlediv').unbind('click.postboxes'); }); (In, fact you could probably just 'print' it in the admin-footer).
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "jquery, metabox" }
display loop only if a post meta data exist I'm looking to display the following loop, only if a custom field data exists, if not, I don't want to display anything. <?php while (have_posts()) : the_post(); $data = get_post_meta( $post->ID, 'key', true );?> <!-- info --> <?php endwhile; ?> Any guessing? Thanks in advanced.
If you want to avoid preprocessing the data, this will work (though it's definitely the quick and dirty method): <?php while (have_posts()) : the_post(); ?> <?php $data = get_post_meta( $post->ID, 'key', true ); ?> <?php if( $data != '' ) : ?> <!-- info --> <?php endif; ?> <?php endwhile; ?> Otherwise (and this is definitely the better way to go if you need the best functionality), you can do a preliminary loop through the data (or even get different data using the meta), determine if any of the posts have meta, then conditionally execute the loop.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom field" }
Get permalink of post that an attachment is linked to How do I get the permalink of a post that an attachment image is attached to?
Try this: <a href="<?php echo get_permalink($post->post_parent); ?>">Attachment parent</a>
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "posts" }
How to integrate blog status? I want to add a "status" to my wordpress blog. My definition of status is a piece of text that say something about the blog that could be changed every day or not changed in month and completely independent of blog posts and pages. For example, in my case I need to add a brief description of the city I am while travelling. Any plugin or similar to do this? Note: Text widget is not an option because I have to control where to put this information, ideally through a PHP call
You can use the option API to set the blog_status and then display it. If you want to use blog description for the purpose you already have the UI available to set it from Setting->General and set the tag line to update your blog status. Then you can display the tag line anywhere in your theme template using the following: echo get_option( 'blogdescription', 'Default status message' ); But if you are using blog description somewhere else and want a dedicated option for the blog status purpose then you can use the `update_option` like in the examples below to set and display the blog status. To set the blog status: update_option( 'blog_status_message', 'This is pretty cool blog status message' ); To display the blog status: echo get_option( 'blog_status_message', 'The default status message' ); For more information on Options API.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "plugins, post status" }
Creating a multi-file upload form on the front end for attachments I am trying to create a public form where users can upload multiple images to be attached to a particular post. I am able to get it to work with single images thanks to this post at Golden Apples Design. The problem is that I'm struggling with multiple file uploads. I've changed <form method="post" action="#" enctype="multipart/form-data" > <input type="file" name="upload_attachment"> <input type="submit"> <form> to <form method="post" action="#" enctype="multipart/form-data" > <input type="file" multiple=multiple name="upload_attachment[]"> <input type="submit"> <form> Now the $_FILES array is in a different format and the file handler doesn't handle it properly. Can anyone help me figure out how to loop through the array in the correct way and feed the file hander the format it wants?
This may not be the most elegant way to do it (I'm not sure if overwriting the $_FILES global is even allowed) but this seems to work: global $post; if ($_FILES) { $files = $_FILES['upload_attachment']; foreach ($files['name'] as $key => $value) { if ($files['name'][$key]) { $file = array( 'name' => $files['name'][$key], 'type' => $files['type'][$key], 'tmp_name' => $files['tmp_name'][$key], 'error' => $files['error'][$key], 'size' => $files['size'][$key] ); $_FILES = array("upload_attachment" => $file); foreach ($_FILES as $file => $array) { $newupload = wp_insert_attachment($file,$post->ID); } } } }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "attachments, uploads, front end" }
How to get userid at wp_logout action hook? I need to perform some cleanup after a user logged out, so I added a wp_logout action hook. Problem is, wp_get_current_user() already returns null if called from within the wp_logout action hook. How do I get the logging out users userid inside a wp_logout action hook?
How about hooking `'clear_auth_cookie'` with the cleaning you need to do? If you need even more depth, you can outright replace `wp_clear_auth_cookie()`, but that can get into issues where it will conflict with other plugins, so avoid that if possible.
stackexchange-wordpress
{ "answer_score": 16, "question_score": 9, "tags": "users" }
How to install a plugin for a free WordPress site? > **Possible Duplicate:** > How can I install a plugin on a Wordpress.com hosted blog? I've a free WordPress (xxx.wordpress.com) blog and now I want to install a plugin like the way I install them with my WordPress site at my own domain. Can't find it in the menu. Isn't this possible with a free WordPress site?
No, you can't add plugin's to WordPress.com the Free websites. They can't allow free sites to add possible vulnerable plug-ins to the server. This would drive up the costs and make it impossible to offer them for free.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 2, "tags": "plugins" }
Search engine for WP as CMS I am running WP as a CMS at the moment and I've been looking for a decent search engine plugin to index the site. The requirements are: * Facet posts based on custom taxonomies (aka, be able to drill down based on taxonomies assigned to posts) * Fast * Does not display the actual post but rather an excerpt Nice to haves: \- Display most recent comment date, author I have come across the Apache SOLR plugin and it does a decent job except for faceting by custom taxonomy. It facets by Categories, Tags, and Author but the Categories is so convoluted that I might as well rethink how I apply categories to the posts. Does anyone have any experience with this? Thanks!
1st You're looking for a search result display, not for a search engine. 2nd It's as easy as modifying the Search Results Template. **Excerpt** can be used like normal in your templates loop. **Fast** , depends highly on your themes code and the plugins you use, as well as your server, so I skip this point. **Facet** Without a link to the plugin, it's hard to tell. A live example would be good as well.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "search" }
content filter (add_filter) for category description? I'm running an add_filter function on the_content and I need to run the same function on the category description. Does something like that exist or do I need to create a custom function for it?
Sure, hook it right onto `category_description`. Here's an example: function category_desc_filter( $desc, $cat_id ) { $desc = 'Description: ' . $desc; return $desc; } add_filter( 'category_description', 'category_desc_filter' ); Didn't test it but based on the Codex it should work. See the Codex for more info: <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "theme development, filters" }
home.php or frontpage (via settings) for theme? OK. I'm getting conflicting instructions from my training resources (again). This time the issue for me is **"how to set a default homepage"**. One tutorial _(Coyers "WordPress 3: Creating and Editing Custom Themes")_ **uses home.php** , while another _("Professional WordPress")_ recommends setting "Front page displays..." via WordPress (Settings > Reading). ...aargh! In checking the forums and blogs, I see the same issue: **conflicting advice**. With one user advising to **NEVER** use the home.php template page in a theme as _"It can cause problems on some servers"_. **Is this true?** And another user swearing by it. ...What is a noob to do? So, given the confusion (and given that I'm a noob looking to do things the right way)... 1. What is the difference between the two approaches? 2. Which approach to a standard homepage should one use **when creating a theme**? thanks, sleeper
1. Simply put, the WordPress template hierarchy reserves `home.php` for the homepage, but if you set a Front Page post, it will display that instead. If WordPress core developers reserved it for the homepage, I do not believe it would cause issues with any servers, because they would be putting everyone at risk. Hope that explains it for you. :) 2. It is completely personal preference. **From the WP Codex:** 1. WordPress first determines whether it has a static front page. If a static front page has been set, then WordPress loads that page according to the page template hierarchy. 2. If a static front page has not been set, then WordPress looks for a template file called home.php and uses it to generate the requested page. 3. If home.php is missing, WordPress looks for a file called index.php in the active theme's directory, and uses that template to generate the page. See the relevant WordPress Codex page for more information: <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "homepage, frontpage" }
register_activation_hook and updating I have used: register_activation_hook(__FILE__, 'CrayonWP::install'); In `install()` I would like to check the plugin version being installed, and if it is below a certain version, I would like to alter the existing database model to the new format. How would I determine the version being installed?
`register_activation_hook()` is only called when the user activates the plugin. It is not called after a plugin upgrade. The preferred method of handling upgrades is using register_activation_hook() to store the current version in the wp_options table and then checking it on each admin page load.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 4, "tags": "updates, installation" }
Sort results by name & asc order on Archive.php I currently use the following code to list posts in Archive.php but I want the results to be ordered by name in ascending order, I have checked the codex but the answer isn't clear to me, how can I get this working? <?php $post = $posts[0]; // ?> Thanks in advance.
The easiest way to do this is to use a hook (the `pre_get_posts` hook) to change the order. But you should check that the query is one for which you do want to alter the order! (`is_archive()` or `is_post_type_archive()` should be sufficient.) For instance, put the following in your theme's functions.php... add_action( 'pre_get_posts', 'my_change_sort_order'); function my_change_sort_order($query){ if(is_archive()): //If you wanted it for the archive of a custom post type use: is_post_type_archive( $post_type ) //Set the order ASC or DESC $query->set( 'order', 'ASC' ); //Set the orderby $query->set( 'orderby', 'title' ); endif; };
stackexchange-wordpress
{ "answer_score": 53, "question_score": 21, "tags": "archives, sort" }
Is there an easy way to flag posts in the admin area? I'm looking for a plugin, or maybe a bit of code (even another example I can look at that does something similar)... I'd like to be able to have certain users 'flag' posts, such that when something has been edited once, there could be a checkbox to say 'flag this for subediting', and then that post can be highlighted in the 'posts' section and easily picked out for subbing and then queued for publishing. Does anyone know of a plugin or something that might accomplish this? I don't really know where to start and my googlings have turned up nothing so far.
If a user has a role of contributer/author then cannot publish content. What they do is publish content for review. Then when an editor/administrator logs in there are numbers shown in the left hand side navigation notifying that there is content waiting to be reviewed. To me what you are asking for is already part of WordPress. If this isn't functional enough for you can look at Edit Flow Plugin
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, posts, wp admin" }
How to hook a function only when I need to delete permanently a post? I need to hook a function only when I delete permanently a post from the database, I've tried the 'before_delete_post' hook, however, it's called both when it's trashed and permanently deleted. The wp_delete_post() function calls wp_trash_post() and should stop processing, but it looks like the wp_delete_post() is called again after the post is trashed. I've seen this question: Wordpress Delete hook with wp_delete_post function?. My need is exactly the oposite of it.
The issue was the "Sitewide tags" plugin which was misbehaving the natural WP flow. A function called `sitewide_tags_post_delete()` is hooked on 'trash_post' and it's calling `wp_delete_post()` to delete the post on the main blog. Following the @Stephen's approach, I did this: add_action('before_delete_post', 'my_deleted_post'); function my_deleted_post($post_id){ global $blog_id; if($blog_id == <main_blog_id>){ // usually is 1 return false; } //do whatever you need :) };
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "posts, multisite, customization" }
How to change settings so I can upload images in Wordpress posts? When I try to upload an image in a post on this WordPress site: < ...I get the message "Unable to create directory **__**. Is its parent directory writable by the server?" How do I change settings so I can upload images?
Go to the admin panel and navigate to Settings>Media and see what it says in the Store uploads in this folder dialog box. You can try deleting whatever is in it and click save. WordPress will then try to use the default wp-content/uploads/images/2012... folders. If that doesn't work I'd FTP to my server and check the file permissions.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "server" }
Force use of RSS 0.92 feed Just wondering if there was an elegant way to force WordPress to use the RSS 0.92 feed at all? The reason I ask is that we have added some custom XML tags to a site's feed so that an accompanying iOS app can pull certain data from the feed - WordPress has recently deprecated RSS 0.92 in favour of RSS 2.0 and this is breaking the app, so reverting to RSS 0.92 as a short term fix would be ideal. I will very much look forward to any thoughts you might have! Alex
Do you mean RDF/RSS 1.0 feed? It is not deprecated and should be available just fine at `/feed/rdf` To force RSS 2.0 links to use RSS 0.92 template try this: remove_action( 'do_feed_rss2', 'do_feed_rss2' ); add_action( 'do_feed_rss2', 'do_feed_rss' );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "rss" }
How do I Create Forums with bbpress Plugin that can only be Viewed by Logged in Users I'm trying to configure forums using the bbpress plugin that can only be viewed by logged in users. I attempted creating them as private but found that sub-forums don't show up on my root /forums page. Another forum suggested using is_user_logged_in() to determine whether or not forums are displayed. What is the best place to put a check for is_user_logged_in() that will hide all forum related pages and posts from non-logged in users. I am up for other suggestions as well if there is a better way to do it, but I am not finding much documentation.
The solution I went with was to create a file in my theme's folder named bbpress.php. I then copied the contents of my theme's page.php file into the new file and modified it to only show it's contents when a user is logged in. In my case it looked like the following: if( is_user_logged_in() ) { get_template_part( 'loop', 'page' ); } else{ _e('You must be logged in to view this page.', 'twentyten-child'); } Apparently the bbpress plugin looks in a a particular order for the template it will use (see < I chose to name the file bbpress.php since it makes it clear when I look back at my code what the file is connected to.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "login, bbpress" }
Looking for a home page carousel I'm looking for a plug in for a carousel similar to this one < Essentially it's a carousel with a navigation to the side. When you scroll over the navigation the carousel changes. It's important that the content of the carousel (nav, images and text over the images) is editable within WordPress by editors, and not only editable by a programmer. I haven't been able to find anything similar to this. Has anyone got any pointers?
From my personal experience, the best WP Carousel/Slider I have seen and used was Nivo Slider. It's in the WordPress Extend Directory: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "plugins, plugin recommendation" }
Post date vs. event date in Wordpress If I'm creating a WordPress site, what should I do when I have a blog that manages events to keep date events? For instance, in my own case, I'm making a travel blog where some histories have a real date (when I visit some place), but are published in a later date (when I'm at home). I'd like to show the _real_ date but if I set this real date as the post date, the post order is a chaos (I have events that are directly hidden and never showed in the home page, because the date is not among the latest 10 posts). What should I do? Is there any plugin to help with that? Or maybe I can change my theme listing the posts in a different manner, but how?
I'm not sure about a plugin, but you can definitely add custom meta that allows you to set the event date, or even an event daterange (my preferred way of handling this is an event date and a duration, cuts down on calculations in the backend and is generally easier to understand, but ymmv). This allows you to keep your post dates in order while maintaining event dates, and also allows you to query by either of them using WP_Query, should you have that need.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 3, "tags": "events, date, order" }
Where are the images for the theme Twenty Eleven 1.2? In Twenty Eleven 1.2, where would I find the images that appear at the top of the blog -- in what folder? I know one of the images is called 'lanterns.jpg', but I can't find it or the other ones. Here's the site: < Thanks,
They are in the `/images/headers/` directory. Here they are in SVN. ### Edit Full path: `/wp-content/themes/twentyeleven/images/headers/`
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "theme twenty eleven" }
Cant we use a PHP file directly like myhome.com/some.php? i just want to add a php file into my site say www.mysite.com/some.php. I dont want to create any page using that php file as page template. All i want is to add a php file which as some php codes in it and redirects to my another page after successful access. I know it is possible and seen in many sites that they use it. How should I to do this???? any solution or at least an hint will help me.
I think you're just looking for a basic php include: include '/some.php'; Just make sure the path is correct. I've used this before no problem, php will interpret your included file as if it were part of the file including it. ... after reading your question again you may be asking for something even simpler, just link to your file from another page to access any resource, including php files, on your site.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, php, settings api" }
Where is the WP auto-save draft JavaScript? If you write a title, then move away from (blur) that input field, WordPress will auto-save a draft for you, likely in order to create a post slug placeholder for you. I'm looking to possibly extend this functionality to also save on blurring of the content body TinyMCE pane. The logic is not entirely straightforward -- for example, it appears to saves a draft only when the post is yet unpublished -- so I need to look further into the logic. In order to scope this change, I need to find where in the JavaScript (?) codebase WordPress does this auto-saving. Having trouble so far. Does anyone know?
I believe the file responsible is `wp-includes/js/autosave.js`. There is a dev version for easy reading.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "javascript, tinymce, draft, customization" }
Upload media error: unable to create directory (windows hosting) Trying to upload any kind of media on a new WP install is failing due to a messed up media folder path: > Unable to create directory D:\webs\bucmio\wp/wp-content/uploads. Is its parent directory writable by the server? The reason why it's not working is obvious, but how can I correct it? I'm guessing I need to get the full path in the `Settings > Media` but how to find it? The host is Cbeyond.
you need to ensure chmod permissions on wp-content are set to 0755. (i know sometimes i have to go 0777 even though i am fairly sure that isn't advisable) i usually do this w/ folder properties in my FTP client, but i'm sure there are other ways.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "uploads, windows" }
What is the best way to customise admin files so they survive future upgrades? I have a site with some custom post types, one of which doesn't have a title. When viewed in the admin section, the posts are listed like so ![]( Which is less than ideal, for obvious reasons. I have edited one of the admin files `wp-admin/includes/class-wp-posts-list-table.php` to display the list as below ![]( The problem is the customisation is overwritten by upgrades. What is the correct way to make customisations to the admin files so they survive upgrades?
**Don't edit core WP files.** Use the provided filters instead. For instance, have a look at the `manage_$posttype_posts_columns` filter.
stackexchange-wordpress
{ "answer_score": 14, "question_score": 5, "tags": "customization, admin" }
why are the term_id and term_taxonomy_id doesn't match on custom taxonomies, but are duplicates on categories In the wp_term_taxonomy table if I look at the category taxonomy, and then look at all its term_id and term_taxonomy_id, they are all identical. But when I look at the last 4, which are from my custom taxonomy, they don't match. What is a good explanation for this. I am not allowed to add images yet since I am new, so, I am adding a link to the screen-shot. Thanks. Screen Shot
1. `term_id` is a unique ID for the term. 2. `term_taxonomy_id` is a unique ID for the `term`+`taxonomy` pair. A taxonomy consists of sometimes many terms, so basically the `term_taxonomy_id` links the `term_id` to the `taxonomy`. All info on these can be found here: <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom taxonomy" }
WP Category Meta plugin fix? Does anyone know of a fix for WP Category Meta < or a similar solution to add images and meta data to categories? With the latest version of WP it doesn't work anymore and I really need it to work since one of my themes depends heavily on it. If there's any coder that can make it work, I might even drop some $
take a look at **`wordpress taxonomies extra fields the easy way`** **UPDATE:** to get the data on the front end you can use the functions that come with the class ex: if (!function_exists('get_tax_meta')) require_once("path/to/Tax-meta-class/Tax-meta-class.php"); $saved_data = get_tax_meta($term_id,'field_id'); echo $saved_data;
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "categories, metabox" }
Using Microsift Word/Outlook for content publishing to Wordpress I am tasked with building an tool to allow users to publish to Wordpress from their PC using MS Word and Outlook. I know, completely defeat the purpose of having Wordpress, but the basic requirement are: 1. Format must be preserved, including images 2. Providing an interface for categorizing and tagging the document 3. Does not involve the WP web UI. (Users insist on using Word as the publishing tool) 4. Workflow should be simple as possible, ie invoke in Word, select categories/tags, publish. After doing some research, I think this could be achieved by creating an VBA macro that saves Word to html format, and sending it via http to wordpress XMLRPC However, I haven't quite work out how to include the images, and how to keep the category from Wordpress and the macro in sync. I would like to hear from anyone who have experience in this and suggestion on how to implement this.
I wouldn't recommend it but... If you are not going to use multisite, then Wordpress has a _Post via e-mail_ feature setup under Settings > Writing. See < An alternative might be to get them to use **Windows Live Writer** , which would give the users a familiar mircrosoft interface. See: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, formatting, xml rpc" }
Does Wordpress generate an automatic page for post formats? I want a page to view only a specific post format (e.g. aside). Do I have to create my own page and run a custom query, or does Wordpress have an automatic page generated for me (like the categories)?
Take a look at get_post_format_link() Here's a little example that uses `get_post_format_link()` to show a link to the format's archive page. You can see something similar to this in action on Justin Tadlock's site. function get_post_format_archive_link() { return sprintf( '<a class="post-format-archive-link %1$s" href="%2$s">%1$s</a>', get_post_format(), get_post_format_link( get_post_format() ) ); } usage: echo get_post_format_archive_link(); The URL Structure is: > > /type/{post format}/ > So for an aside we'd have: > > >
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "wp query, pages, post formats" }
Building a form with WordPress, and also pulling that data for a user page I am going to give the most basic example of what I want to achieve. I have a page for booking a pickup service, and a form needs to be created to take information of the following. (Date, # of Bottles, Name, Address, phone #) Once the data is entered I want the info to be stored in a database, where I can later export it back on a page. Where I will have a list of each entry containing that data. How do I go about doing this in wordpress, I have done something similar in php a while ago, my memory is a little bit bad though. Is there some sort of process. I don't really know where to start. (not needed just yet, but for the date, I want to delete a certain date, once it has been chosen before once, and I want to have a drop down menu to choose dates, specifically time increments of 30mins e.g. monday 19th 8:30, 9:00 instead of the user choosing their own time) Thanks for any help.
I would created custom post type for this and store all information (Date, # of Bottles, Name, Address, phone #) in post meta. It would be a lot easier, if you use Gravity Forms or Ninja Forms, personally I've not used last one, but it has free lite version so it's worth to try.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "loop, database, forms" }
Merge page with custom post type This may be a weird scenario, but...I have a custom post type called Resources. When visiting /resources/ I get the archive as expected. What I want is a text describing this post type. Therefore I've made a page with the exact name and path. If I now go to /resources/ I still get the archive page, which is good. So, I created a custom template (archive-resources.php) and from there I searched pages with the same path and then I find my page and is able to write out the text before listing the archive. What I want to know is that, is this a good way to solve my problem? if not, how can I make it better?
I don't see anything wrong with using `archive-$cpt_name.php` as your default archive page for the custom post type. That would be the correct way to go about doing it. Although there are many different methods to do it, I think you are on the right track to the best way.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom post types, pages" }
What defines a post as portfolio page content? I have three types of content, Posts which I have defined as Blog and categorise accordingly, Slider Images defined by a specfic category, and Pages. I want to have content as portfolio on a profolio page similar to a blog. My theme allows it, under the new page editor I have options to have a portfollio template. !enter image description here I have chosen that template but I cannot point a post or other piece of content to appear here. How do I choose a post to sit under this page? For information I am using this theme
This theme probably uses the custom post type feature. Therefore you have to create a post inside this custom post type menu. The picture below shows you the label "Cars" as a custom post type. You probably have a label "Portfolio" or something similiar here. !custom post type Another option would be, that you can set the type of a post inside the post editor screen. Create a new post and look for a metabox where you can specify the type of this post. If this doesn't help, you should contact the developer of your theme.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "categories, page template" }
Post Meta not saving when have empty post Hi I created a meta box on the post, page and project post types. The meta boxes save their data well on every post type. However I have a slight problem, when I create a new post and just enter a value in the meta box, then click 'save draft', the value in the meta box is not saved. On the pages and project post types the value would save. The behaviour is that if I don't enter anything in the title or the content of a new post, no metadata will be saved, and I also noticed that no permalink is generated, while for the other post types it is generated and the meta data is saved. Is this standard WordPress behaviour or do I have some bug in my code? Functionally wise I don't think it's a big problem, because we will of course always be entering a title and content within the posts, but I'm curious about this behaviour and would like to know if it's coming from my end or not. Thanks.
It's default WordPress behavior. You cannot create, save or even trash "empty" posts (considering, for that last case, that you created one manually). Luckily, there's a filter that allows you to override it and insert / save posts without need for title or content; insert this into your `functions.php`: add_filter('wp_insert_post_empty_content', '__return_false'); I've successfully created a post with only meta fields with the code above.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "metabox" }
Removing translation textdomain I am working on a plugin for myself, so, it's totally useless to load textdomain. But most of codes I copied from others are using the `__(' ','')` I copied the codes from several plugins. So, even if I load textdomain, it's going to be useless as well,posibly slow down the performence. My question is-- What's going to happen when WP read those `__(' ','')` without a textdomain loaded ? Will it become a problem?
I've actually been in the exact situation you're in before, all you need to do is drop the `__()`s and the `_e()`s and replace them with their first parameter, you can pretty easily do this by regex if there are a lot, and it's quick to do by hand if there aren't...I'm not sure what the performance penalty on them is, especially if they're empty, but I'm a bit of a performance hound, so it wasn't something I was going to risk.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "performance, translation" }
My login form does not work I have the following code that generates a login form for every page in my blog. <form action="<?php echo wp_login_url(); ?>" method="post"> username: <br /> <input name="log" id="login_username" type="text" /> <br /> password: <br /> <input name="pwd" id="login_password" type="password" /> <br /> <br /> <input name="rememberme" id="rememberme" type="checkbox" value="forever" /> remember me <br /> <br /> <input type="submit" value="login" /> <input type="hidden" name="redirect_to" value="/" /> <input type="hidden" name="testcookie" value="1" /> </form> But it doesn't work. It just lands the user in login page. I'm wondering if I have left out a part of the form! **SOLVED** : I should've just put a hidden input in the form with name of `login` and some value like `true`.
I should've just put a hidden input in the form with name of `login` and some value like `true`.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "login, forms" }
How to display sorted posts in the 'All Posts' page I've been following this tutorial to build a sorting page for my posts: < The sorting works fine, but the new sorting is not reflected back in the 'All Posts' section under 'Posts', it only displays sorted under the 'Sort Posts' submenu created by this code in the tutorial. How would I extend this further to also sort the posts correctly under 'All Posts', as it is a bit confusing for the user as it is? Also, does anybody know why there is no functionality for sorting, especially for pages and custom post types (I can imagine posts being more date-oriented), built into the WP Core?
I **think** this is what you want... This isn't tested so you may have to fiddle with it. in your `functions.php` file, add something like this : * * * **EDIT (2)** After rereading, I saw you're not using custom post types, so i'll change my code accordingly. ~~I don't know how to detect when you're on the 'manage all posts' page, so maybe someone can complete my`'if'` statement.~~ This should work. function set_post_order_in_admin( $wp_query ) { if ( is_admin() ) { if( 'edit.php' === $GLOBALS['pagenow'] ) { $wp_query->set( 'orderby', 'menu_order' ); $wp_query->set( 'order', 'ASC' ); } } } add_filter( 'pre_get_posts', 'set_post_order_in_admin' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "posts, sort" }
Translation for plugin I modified a .po file, basically I opened as txt file and made the changes, however I uploaded it and is changes are not working. I wonder if I need an special software for doing and generate a new .mo each time I make a change, or what am I missing? Thank in advanced
You need to do "msgfmt" using the command line tool to convert the .po to a .mo, that is what Wordpress (and all gettext compliant software) uses.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "translation" }
Export all content from wordpress Evening all. I've decided instead of upgrading the install of wordpress that I have, to just take the content (my writeups, comments, pages) and move them to the new site install. Is there an easy way to do this at all, or would it just be simpler to just move the old DB to the new install? For reference, I'm upgrading from v2.9 to the latest release.
WordPress already has this available under **Tools > Export**. You can export all of your posts, comments, authors, etc. into an XML file which you can them Import into a new (or not new) installation. I believe this has been part of the core since WordPress 2.1. !Where to Find Export in WordPress
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "database, migration, installation" }
Shortcode Attribute I want to assign a title to my column shortcode. Essentially, [column title="nameofcolumn"]content[/columntitle]. But I'm not quite sure what to do after the "=>" or after my div class of title. I've looked for tutorials but I can't find anything specific enough for me to understand. function column_shortcode( $atts, $content = null ) { extract(shortcode_atts(array( 'title' => 'WHAT DO I ENTER HERE', ), $atts)); return '<div class="third"><div class="title">DO I NEED SOME TEXT HERE?</div><hr/>' . $content . '</div>'; } add_shortcode('one_third', 'column_shortcode'); EDIT: Also I'd like to set my 1/3 columns under a row div so I can clear: both. How can I accommodate that?
yeah, you are kind in the right path, just need to know that the 'title' is a variable that will get and past the value, so you have to call it exactly where you wrote "DO I NEED SOME TEXT HERE", so it goes like this: function column_shortcode( $atts, $content = null ) { extract(shortcode_atts(array( 'title' => 'WHAT DO I ENTER HERE', ), $atts)); return '<div class="third"><div class="title">'. $title .'</div><hr/></div>'; } add_shortcode('one_third', 'column_shortcode'); Notice where you have 'WHAT DO I ENTER HERE', is the default value it will take so probably you might want to leave it blank :) UPDATE*** I didn't notice that call to the content you had in there, you don't need it, let me know if it goes well
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "shortcode" }
Custom Fields Not in Search Results I noticed that the content of my custom fields is not in my search results. Is there a good remedy for this? I could just hardcode my content into page templates but I would like the content to be searchable. Thanks.
You can use an custom plugin for your custom fields function fb_custom_search_where($where) { // put the custom fields into an array $customs = array('custom_field1', 'custom_field2', 'custom_field3'); foreach( $customs as $custom ) { $query .= " OR ("; $query .= "( m.meta_key = '$custom' )"; $query .= " AND ( m.meta_value LIKE '{$n}{$term}{$n}' )"; $query .= ")"; } $where = " AND ({$query}) AND ($wpdb->posts.post_status = 'publish') "; return($where); } add_filter( 'posts_where', 'fb_custom_search_where' ); Also you can check the plugin WP Custom Fields Search and you have adhoc an solution.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom field, search" }
Remove edit post link from static front page Checking for front page with either is_home() or is_front_page() still removes the edit link from all pages/posts. What's wrong with this? add_filter( 'edit_post_link', 'foo_edit_post_link' ); function foo_edit_post_link() { if (is_home()) { return FALSE; } }
Try function foo_edit_post_link($link) { if (is_home()) { return FALSE; } return $link; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "frontpage" }
Allow Users Only Edit Their Profile? We want to create profiles for individuals/companies which would allow them to login to the backend and adjust their profile. So essentially the admin of Wordpress would have access to all pages and profiles but the individual/company would only have access to their profile page - which they can then update. Where do I start with something like this?
By default, the `author` user role allows users to _add, edit, and delete their own pages and posts_ , but disallows users to _edit or delete others' pages and posts_ ; however, it does not, out of the box, limit users to the creation of a single page or post. If your intent is merely to allow users to create a public profile page, I would recommend creating a custom template that displays user meta data, that each user can manage from his/her own back-end profile page. If you need additional user meta data, simply add custom user meta data to the user profile page. That way, you can use custom templates to output the public profile pages using the user custom meta data, while being able to leave users in the `subscriber` user role, which prevents them from creating pages or posts.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "login, user roles, permissions, community" }
Getting admin notices working for plugin errors I'm beginning with creating plugins and I don't quite understand the process of displaying error messages. e.g. I use the php readfile function to download a file from a hidden location. If something goes wrong e.g. the file isn't found, how do you display a message **at that moment**. I know you need to use add_action for 'admin_notices' but I can't quite figure out where you are supposed to put the add_action calls. As far as I can tell, you have to create a function my_download_file which tries the download and echo's a `<div class="error">`. Then 'somewhere' you need to call `add_action('admin_notices', 'my_download file');`. This, from reading the Action Reference, then gets called when admin_notices are being printed out. But does it always get called, or does it only get called when do_action gets called?
What you need to do (as we discussed in comments) is run your conditional logic inside the function that that `add_action` calls. For example, you're adding an action to the `admin notices` hook. The action will run, but the stuff inside that action's callback will only run if you let it. add_action( 'admin_notices', 'your_custom_function' ); function your_custom_function() { // You need some way to set (or retrieve) the value of your $error here (if not already set) if( $error ) { // Put everything here } } In a theme, this is typically found in your `functions.php` file or a file included in it. In a plugin, it could be in any file also as long as it is included in your main plugin file.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "plugin development, actions, notifications" }
Importing posts in custom post type into new website I have two wordpress installs. One in root directory and other in subdirectory of the same domain. I want to transfer posts of subdirectory **into a custom post type of main site**. Post of subdirectory (to be transferred) have several taxonomies so should I import and transfer taxonomies first? If yes then how to? and do all this transfer?
I think all you should need to do is export from WP as you normally would if you were just transferring the content. Download the resulting XML file, change all `<wp:post_type>post</wp:post_type>` entries to `<wp:post_type>YOUR_CUSTOM_POST_TYPE</wp:post_type>`. This should work, assuming your Custom Post Type is already registered in the theme.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "custom post types, bulk import" }
Filter Posts By Tag I'm trying to filter my posts by category, then further by city. The only way I can think of filter by city is if the admin adds the city to the listed tags and then filtering from there via switch statement. How can I filter posts by a certain tag? Is there a better way to do what I'm doing? My PHP knowledge is intermediate and my Wordpress knowledge is pretty basic. Thanks in advance!
here you go, The following returns all posts that belong to category 1 and are tagged "apples" query_posts( 'cat=1&tag=apples' ); Add this inside the page before the loop change '1' and 'apples' to whatever category and tag you want. If you must use `query_posts()`, make sure you call `wp_reset_query()` after you're done. look here for more info, <
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "posts, customization, query posts, filters, tags" }
display menu with out list tags Is there a way I can display a menu in my theme that isn't formatted in a list? i just want to display the `<a>` tags without the `<li>` tags. is this possible? theme file: <?php wp_nav_menu( array( 'theme_location' => 'navigation' ) ); ?> functions.php: function register_my_menus() { register_nav_menus(array('navigation' => __( 'Main Nav' ))); } add_action( 'init', 'register_my_menus' ); **Edit:** see my answer below, found on Stack Overflow
It looks like what i'll need to do is look at a customized menu walker, as suggested at this thread over on Stack Overflow: < From there, looking at suggestions I found: < That's solved this perfectly!
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme development" }
How do you add a category to a post in code We do a lot of post maintenance outside of the WordPress interface and as a result we need ways of categorising posts. Obviously Wordpress has categories (aka taxonomies) on posts and I plan on using them, but haven't found a way that I can do that in code. We also use custom post types extensively so the accepted answer may need to state how to incorporate categories into them.
There's the `wp_update_post()`, also. According to categories, please refer to the documentation. > Categories need to be passed as an array of integers that match the category IDs in the database. This is the case even where only one category is assigned to the post. So, it would be something like: $post = get_post($i = $post_id); $post->post_category = array ($cat1, $cat2, $cat3); wp_update_post($post);
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "categories" }
How should I use register_setting, add_settings_section, & add_settings_field in my plugin's options page? I'm working on a settings section for my plugin, and after reading over Wordpress's documentation which is in ROGUH DRAFT status, and also the Creating Options Pages \- which is also in "transition", I've been left with questions about how to correctly use the new Settings API to add an options page for my plugin. I have around 30 plugins installed and did a search for the keywords `register_setting`, `add_settings_section`, & `add_settings_field` and only found one match as part of Coffee2Code's plugin framework - for which I can't find any documentation anywhere. Can someone give me a working example, or provide a link to a simple working example, of how I should use the new "Settings API" to create a simple options page for my plugin?
I wrote a tutorial for Incorporating the Settings API in WordPress Themes. The only real difference for Plugins is that you'll use `add_settings_page()` instead of `add_theme_page()`. The rest should pretty much be the same.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "plugins, options, api, settings api" }
how to add class to the ul returned by wp_list_bookmarks wp_list_bookmarks returns HTML that has a `ul` with classes `xoxo blogroll`. I'd like to add another class to that ul, but can't seem to find an elegant way to do so. wp_list_bookmarks does accept an argument "class", but that is applied to the li, not the ul. Is there some argument I'm missing? Or is there a hook I can hook onto and add a class?
There is a filter `'wp_list_bookmarks'` for the complete markup. You can use it: add_filter( 'wp_list_bookmarks', 'wpse40213_new_classes', 10, 1 ); function wpse40213_new_classes( $html ) { return str_replace( "class='xoxo blogroll'", "class='my_bookmarks blogroll'", $html ); }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "get bookmarks" }