INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Single Post Breadcrumb not linking back to Custom Post Type Index? I am using a breadcrumb code that will not place a link on two custom single post pages linking back to two custom post type index pages. The full Breadcrumb code can be seen here: < if(get_post_type() == 'Portfolio'){ echo '<a href="' . ' . '">' . 'Portfolio'. '</a>' . $markup; } else if(get_post_type() == 'Artwork'){ echo '<a href="' . ' . '">' . 'Artwork' . '</a>' . $markup; } EDIT: This has been resolved with the code above, thanks all who helped.
If you read the codex you will see that `is_single` accepts post id's / titles / slugs and **EDIT** If you are using two custom post types then WP will select the right `single-POSTNAME.php` And in your check you best check the posttype like: if ( get_post_type() == 'postfolio' ) { /*do stuff*/ }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "templates" }
Problem using the word "RSS" as a tag I'm using RSS as a tag for some of my blog posts, and I was using them without any problem. myblog.com/tag/rss/ But I've just realised that Google Webmaster Tools gives me some related errors. The issue is this: when trying to retrieve the feed of this tag, from myblog.com/tag/rss/feed/ it gets redirected to myblog.com/tag/feed/ And this gives an error. Anyone knows how to solve it? Thanks!
It's not possible to do yet due to a bug in Wordpress core. A workaround was provided in Wordpress ticket function disable_canonical_redirection_for_tag_feeds() { if ( is_feed() && is_tag() ) remove_action( 'template_redirect', 'redirect_canonical' ); } add_action( 'wp', 'disable_canonical_redirection_for_tag_feeds' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "tags, redirect, rss, feed" }
How to install Google Analytics onto site without internet access I just created an intranet site for the company that I work for. The IT department will not allow my site to access the internet for security reasons, but my boss still wants Google Analytics installed. I usually just use Joost De Valk's GA plugin, but I don't think it will work since I don't have internet access. Any ideas about installing GA without an internet connection?
Remember that GA runs client side in the browser and if your intranet visitors do not have access to GA servers via the internet then GA is not going to work for you. With that said, Joost De Valk's GA plugin has a way to manually enter the UA code rather than using a connection to Google to pull available UA codes. !GA manual enter UA code The method shown in the image above will work if the server has no internet access. If your intranet users don't have internet access and because of this GA is not an option then you can look at using something like Piwik instead. You can install Piwik on the intranet server and use WP-Piwik to bridge Piwik with WordPress
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, plugin recommendation, google analytics" }
display random posts on index.php instead of latest I have the settings so only one post (which is by default the most recent) displays with index.php my current working code <?php if (have_posts()) : while (have_posts()) : the_post(); ?> How could I change to code to display a random post from any category/date? It just needs to be one post if that makes a difference. many thanks
Place the following code in your theme functions.php file. function one_random_post_on_home_page( $query ) { if ( ! ( $query->is_home() && $query->is_main_query() ) ) return; $query->set( 'orderby ', 'rand' ); $query->set( 'posts_per_page', 1 ); } add_action( 'pre_get_posts', 'one_random_post_on_home_page' ); I'm assuming when you say index.php you mean your blogs home page. The index.php file in your theme can be used for many other areas of your website so making any alterations in that file might have undesired effects else where.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "posts" }
How to change order of posts in admin Hi I have set a custom post type with some custom fields, one of the custom fields is a date field which is different from the publish date of the post itself, which is by default used by WordPress to sort the posts. I would like posts on this screen to be by default sorted using the custom field. How can I do that, is there some filter? Secondly, I would also like to have a dropdown at the top of the page, so a user can filter posts by custom field.
## Adding Columns to Admin To answer your first question, I recommend a plugin called Codepress Admin Columns. This is by far one of the easier and non-coding ways to implement columns. But it will set you back 15EUR to purchase the add-on that allows sorting. If you wish to get your hands dirty with code then this post by tzeldin88 will help you get started. ## Filter Posts from Dropdown I do not know of any plugins that do this and have not found any in my search. But you could code your own with a little help. First, there are two approaches to this, a form or using javascript. _(actually they are both the same, but using javascript makes everything flow together)_ I dont have time right now to find the best tutorial for you but if you search "wordpress drop down to filter post" then you should have no problem coming up with some reading. I will update when I get back with some articles that I do find pertinent.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom field, filters" }
WordPress linking On my homepage, I have several links that should link to different parts of my website. The first link should be redirected to a custom post type that has the slug portfolio. The other links should be redirected to different custom template pages like contact page , about us page, etc. Are there any functions in WordPress that allow me to link to this pages?
There _are_ functions in WordPress that deal with adding menu items. Is this the kind of "function" you're looking for? <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "theme development" }
How do I link to the posts page? How can I link to the posts page that has been set in Settings > Reading? This is for a premium theme so it can't just be the page's permalink.
WordPress Does it like this this. echo get_permalink( get_option( 'page_for_posts' ) );
stackexchange-wordpress
{ "answer_score": 5, "question_score": -1, "tags": "posts" }
How to Sort Custom columns in admin I have set a custom column for date in admin, but the sorting is not working, when I click to sort the dates are jumbled up and not sorted correctly. This is the sorting function Im using function sortable_columns() { return array( // meta column id => sortby value used in query 'publishdate' => 'date', // e.g. 1344964575 ); } add_filter( "manage_edit-post_sortable_columns", "sortable_columns" );
This tutorial from WPTuts+ will do the trick ... Quick Tip: Make Your Custom Column Sortable > In a recent article by Claudio Simeone, he demonstrated how you could add extra columns to your post, or custom post type, admin screens (or remove existing ones). In this quick tip I build on that by showing you how to make your newly created columns sortable.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "posts" }
how to show last 5 images from the one post gallery i want to get the 5 images of a one post gallery and show this random, > example : [gallery id="123" orderby="rand" {numberpost=1 } or offset ? ] _[[gallery] codex]( tanks for help me.
Try installing the following plugin: < You'll be able to set how many images to show via this code: [gallery link=file start=1 end=5] Hope this helps!
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "shortcode, gallery" }
Custom setup of wordpress comments that are displayed I have setup in admin to have 5 comments per post display, which is what I want, and newest at the top. But the problem is when a 6th comment is made it is the only one displayed and you can read the previous comments which will display 5. What I would like it to do is always display 5 comments, when 6th is made the oldest pushed to the next page. Thanks, Matt
Ended up solving this with the following code: <ol class="commentlist"> <?php $comments = array_reverse($comments, true); ?> <?php /* Loop through and list the comments. Tell wp_list_comments() * to use twentyten_comment() to format the comments. * If you want to overload this in a child theme then you can * define twentyten_comment() and that will be used instead. * See twentyten_comment() in twentyten/functions.php for more. */ wp_list_comments( array( 'callback' => 'twentyten_comment','status' => 'approve&number=5','order' => 'asc' ) ); ?> </ol>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, custom post types, posts, comments, comments template" }
Customize field names in backend profile edit page through function.php > **Possible Duplicate:** > How To Add Custom Form Fields To The User Profile Page? I want to change a the names of some of the fields in the edit profile page in the backend. For instance, instead of it saying "Twitter", I want it to display "Enter Twitter ID". I am aware that I can do this by editing the core WP files, but to avoid redoing the same process, how can I do this through the function.php file? What code can I enter that would make this possible?
What you need to look at is hooking into the `user_contactmethods` filter. Perhaps something along these lines: function test_new_contact(){ $user_contactmethods = array( 'aim' => __('AIM'), 'yim' => __('Yahoo IM'), 'jabber' => __('Jabber / Google Talk'), 'twitter' => __( 'Enter Twitter ID' ), ); return $user_contactmethods; } add_filter( 'user_contactmethods', 'test_new_contact' ); Note the "core" user contact methods should be included in your filter function, unless of course you want to remove them ... then simply do not include them at all.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "php, functions, profiles, customization" }
Worthwhile to restrict direct access of theme files? I've run across the following snippet in themes from time to time: if ( ! defined('ABSPATH')) exit('restricted access'); It's at the beginning of some (all?) PHP files in a theme and it's supposed to prevent direct access of the file by nefarious sources. I see that this isn't included in Twenty Ten or Eleven and I've never seen it recommended in official WordPress documentation. It seems like a good idea to me, but I also don't know enough about security to judge it and can't find much with Google. Is this something I should have in my custom themes? If so, should it be in all PHP files or just some?
Usually, you don’t need it. But … there is at least one edge case: * If a theme file is a template _part_ , * _and_ it is using global variables from the calling context (parent file), * _and_ register_globals is `on`, * _and_ it is just using these variables without any security check … … an attacker can call this file, set the missing variables with `GET` or `POST` and make the theme file print those out. And then there _is_ a security problem. So … the best option is not a context check like the one from your example, but good code: avoid global variables, check their content before you print it out.
stackexchange-wordpress
{ "answer_score": 30, "question_score": 36, "tags": "theme development, security" }
How to sanitize uploaded file filename from a plugin? There is a problem with WordPress Form Manager plugin that doesn't sanitize the uploaded file filename. So, when a user upload a photo with special characters in the filename, you will not be able to show it up on the front-end, for example. My question is, how can I sanitize that? Ps: I already shot the question to the plugin's author.
I found a way. Change the lines on wordpress-form-manager plugin direcoty -> types -> file.php (around line 109) From: if($fileNameFormat == "%filename%"){ $newFileName = $pathInfo['filename']; } To: if($fileNameFormat == "%filename%"){ //Sanitize the filename (See note below) $remove_these = array(' ','`','"','\'','\\','/','%'); $newFileName = str_replace($remove_these, '', $pathInfo['filename']); //Make the filename unique $newFileName = time().'-'.$newFileName; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, php, sanitization" }
Linking beetween pages in wordpress Hi I am trying to link to some custom templates I have created and I don't seem to know how to do it the right way.For example: I have created a custom contact page and named it contact.php.From the front-page I want to link to it.Now this is what I did but I don't think this is the best way: <a href="<?php bloginfo('url') ?>/contact"> Now this works but only if the permalinks are set in the settings page to postname.If for example the page is set to default the links shows the 404.php. How can I set the links the right way? I noticed that when creating custom post types there is a way to rewrite the permalinks and define a slug for the new page.Is there a similar way to rewrite permalinks for custom templates?
You'll want to use the `get_permalink` function like so: <a href="<?php echo get_permalink(get_page_by_path('contact')); ?>">Contact</a> Which will return the correct URL no matter what your permalink settings are.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "theme development" }
Get page->parent's name? How can i get the name of a page's parent? I can only get it's id. $page = get_queried_object(); $pageparent = $page->post_parent;
Once you've got the id of a post or page, use `get_the_title($id)` to get the page title (which is what I assume you mean by name) Codex Reference
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "post meta" }
Moving Wordpress with Super Skeleton theme I have a Wordpress with the Super Skeleton theme ( installed on my server. Now I want to move it to another server. I have gone through the usual steps of moving a Wordpress and the Wordpress itself works great, but for some reason the settings for the Super Skeleton theme didn't seem to follow along in the move. I have tried hitting the "Realod XML" button in the Theme Options without any success.
The theme is using Option Tree to save the theme options and this is the steps I went through to export the options from the old Wordpress installation and import them into the new one. 1. Go to `Users > Your profile` and check the checkbox in the bottom saying `Show Settings & Docs` under the `Options Tree` headline and hit `Update`. 2. This will enable a new item in the sidebar called `OptionTree` then go to `Settings > Export` 3. Follow the instructions on this page I then did the exact same thing on the new Wordpress installation to import the settings.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "themes" }
How to add only a (sub) capacity to an user role? I know I can add capabilities to the any role using the role object and add_cap via functions.php <?php // get the the role object $editor = get_role('editor'); // add $cap capability to this role object $editor->add_cap('edit_theme_options'); ?> The **list of capabilities** shows that "edit_theme_options" allows access to almost all items under _Appearance_ (all but _edit theme_ ). **What I wold like to do is add capacity to access only _Appearance>Menu_ to a role. Is this possible without modifying the core?** The two most popular ACL editing plugins (Members and User Role Editor) don't allow for this as they only use the default _list of capabilities_
It's stupid, but you can't. (Not without editing core, anyway.) Right at the top of the nav-menus.php source code is an `edit_theme_options` check that's not filterable. < If you're not concerned about your editors trying anything too shady, you could simply hide the menu items using a plugin like Adminimize or Admin Menu Editor. Of course, you could also open a ticket at < to try to get the core devs to change this.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "permissions, user roles" }
Very Quick Custom Pluggable Function Question Lets say I have a function set up like such: add_action( 'init', 'jigoshop_add_to_cart_action' ); function jigoshop_add_to_cart_action($url = false){ //code } To make it pluggable by others plugins, I just need to change this to add_action( 'init', 'jigoshop_add_to_cart_action' ); if (!function_exists('jigoshop_add_to_cart_action')) { //ADD THIS function jigoshop_add_to_cart_action($url = false){ //code } } //AND THIS right?
No, because you're hooking it to an init action, then somebody can replace the function simply by unhooking it themselves. You don't really need to wrap it or make it pluggable.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin development" }
How to get the result of comments_number() as a string instead of printing it out? `comments_number()` is quite useful: It takes the result of `get_comments_number()` and prepares the output with some localization magic. Unfortunately, it prints the result out when it is done, it doesn’t offer an option to just _return_ the string. How can I get the string without printing it? I want to use it as a variable value.
Easiest way: ob_start(); comments_number(); $data = ob_get_clean(); $data will contain the text.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "comments" }
Proper method to restrict non logged users into certain pages I was wondering which is the correct method to do this and which action hook should i use. I have custom login/register pages so if the user try to go to a forbidden page and its not logged in i will redirect him to a login page. Currently on my functions.php i got the following: /* * Restrict non logged users to certain pages */ add_action('template_redirect','my_non_logged_redirect'); function my_non_logged_redirect() { if ((is_page('mi-perfil') || is_page('agregar-empresa')) && !is_user_logged_in() ) { wp_redirect( home_url() ); die(); } } Im using the right method/hook or should i use another one or a easier one?
I couldnt find a better method other than: /* * Restrict non logged users to certain pages */ add_action('template_redirect','my_non_logged_redirect'); function my_non_logged_redirect() { if ((is_page('mi-perfil') || is_page('agregar-empresa')) && !is_user_logged_in() ) { wp_redirect( home_url() ); die(); } }
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "pages, actions, template redirect" }
Database Tables in Wordpress Theme I am creating some sliders type functionality for my wordpress theme and I thought that creating two seperate db tables like 'sliders' and 'slider_images' is a good idea. My problem is that i don't know what is the best way to handle the creation of those tables. If it was a plugin, I would just do it on activation, but it is just some functionality as part of my theme and i haven't really found a hook that is executed once when the theme is activated. If possible, i would like to not have to check the database for the existence of tables in every page refresh and create if not. Is there a way to do that ?
Don't use separate database tables in a Theme, _especially_ for creating custom content types. Use WordPress-core Custom Post Types.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "theme development, database" }
Does WordPress use the InnoDB engine for MySQL by default? I just created a new WordPress site in my server. Normally, WordPress uses MyISAM as the database type. But this time, it created all InnoDB tables! Is this normal? Has WordPress switched to InnoDB in the latest versions?
> WordPress actually specifies no table type in the create statements, so it uses MySQL's default table engine which is InnoDB from version 5.5 onwards.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 6, "tags": "database, mysql, innodb" }
Please Check this '.htaccess' File I just found my '.htaccess' file has the same lines of code repeated twice as below, maybe some plugins changed it, is it incorrect? Should I remove the repeated one? Thanks!! <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
This often happens when using a plugin like WP Super Cache or W3 Total Cache that need to add things to the .htaccess file. You can safely delete the top version (the one without the `BEGIN/END WordPress` lines), but having duplicate entries won't hurt anything. It will add a tiny bit of overhead as the rules are processed, but it's negligible on a site that isn't getting very large amounts of traffic.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "plugins, url rewriting, htaccess" }
prevent wordpress from creating thumbnails of an image I have a theme installed which automatically generates differnet sizes of images (thumbnails) when I add a "featured" image in a post. supermuc-106x80.jpg supermuc-116x80.jpg supermuc-150x100.jpg supermuc-150x150.jpg supermuc-290x180.jpg supermuc-300x174.jpg supermuc-600x250.jpg supermuc-600x400.jpg supermuc-905x500.jpg supermuc.jpg Thats OK so far. My problem is when I want to add some more pictures/photos inside the post it also creates differnet sizes of the picture but actually this is not "featured" image so all those sizes are just wasting my disk space. Is there any way or plugin to allow me select which thumbnails will be generated when I upload an image? So I can "disable" all sizes I dont want to be created and save disk space?
Check out @Otto's plugin Dynamic Image Resizer. I think it does exactly what you're asking for. I haven't used it before, so I can't vouch for it, but the plugin author's identity goes a long way toward me trusting it.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "thumbnails" }
How can I create an alternate full-HTML editor for posts? I have created a custom post type; the content of this custom post type should be a full html page - not just a snippet of html. The standard editor appears to interfere with the html and it does not appear to be ready to handle a full html page source as its content. Ideally, I would love to be able to disable the 'editor' capability for this custom post type and replace the editor with a custom plugin - only, I'm not sure about the best course of action to implement this functionality. I am open to writing the plugin myself, but it would be nice to learn that such a plugin exists already.
## The Problem It seems that you're using the normal theme template files for posts and pages to display your custom post type. This means, that you also got the `wp_head()` hook and other template, that output default (post/page specific) things. ## The solution Add a template file to your theme, that's named `single-{$post_type}.php` and nothing than the loop with only `echo get_the_content()` in it. This way you can build your HTML without any interference. `get_the_content()` has no filters applied, that normally get attached to `the_content()`.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "html editor" }
Themes with variable width or single columns? I want to display source code I've just set up a new WordPress blog, and as a developer I want to post some source code as well. Now I found the suitable plug-ins I need, and also a sleek theme, or so I thought. The problem is the width, it's just way too small. Even if I pick the option this theme has to only use a single column, it's still not wide enough. I guess my choices as a programmer wanting a theme to display my code correctly will be rather shallow, but there must be something I can do? Here's the first post I made on this blog: <
It will be good if you can pick up a theme that is wide enough for your requirements. Probably a theme based on 1140 grid system will work good for you. That said, if you still want to use your existing theme then you can edit theme's `style.css` , on line 76 you can delete `max-width:1000px` After this the page will occupy the entire available space .
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, themes, code" }
<?PHP getting changed into <!--?PHP When I post a PHP code snippet into a wordpress post it will convert `<?PHP` into `<!--?PHP` To avoid this I must replace `<?PHP` with `&lt;?PHP` I am asking if there is a setting or easy method to avoid this? If not I am thinking of maybe writing a PHP function that will search the content filed and replace `<?PHP` with `&lt;?PHP` Any ideas
Here is my only idea so far function strip_php($content) { return str_ireplace("<?PHP", "&lt;?PHP", $content ); } add_filter('content_save_pre','strip_php');
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php" }
Wordpress visual editor broke due to non standard port? I recently installed WordPress on my own server, which uses non-port 80 Apache service. I could view posts but the tinymce editor constantly broke. More specifically, all menu items in visual editor did not appear and if there were any text, they were all invisible until I highlighted them. After numerous research, someone mentioned this problem could due to there is ":" (colon) in the siteurl address. I could not verify this theory because my ISP blocked port 80. I was wondering if anyone experience the same problem and how do they solve it?
I had exactly same issue with Visual Editor but my site was working on port 80. This is what I did : Edited wp-config.php and added the following : define( 'CONCATENATE_SCRIPTS', false ); and everything worked fine. Additionally you can check if `wp-includes/js/tinymce/wp-tinymce.js.gz` file exists or not. If not, then upload it via FTP
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "tinymce, visual editor, debug" }
Different Server for Images I am on a shared hosting on HostGator and now I want to take one other shared hosting on some server and want to put only the images used on my site to it. So that those http requests of images could go to another server, is that possible? and how? thanks.
What you are looking for is called "CDN" or "Content Delivery Network". Here is a WIKI! definition if you are not familiar. There are plenty of good tutorials out there that will show you how to carry this out using Wordpress. Here is one you can have a look at. <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "hosting" }
Setting Variable Path to Template Directory inside Script I have **HTML5 Template** with 5 pages. I am converting it to a **WordPress Theme**. I have a contact page. This page includes 'forms.js' script to send contact form data to 'MailHandler.php' file. Inside the 'forms.js' script there is a variable I want to change, mailHandlerURL:'bat/MailHandler.php' How do I change this to something like the following? mailHandlerURL:<?php echo get_template_directory_uri(); ?>'/bat/MailHandler.php' The PHP is not working inside this script. Please help.
If you want to send the url of the website, or other server side calculated values, to JavaScript you can use `wp_localize_script` (Codex Page). This function creates an object, with the values you've passed. As the documentation states, you've got to include your script with `wp_enqueue_script`, else it doesn't call localize_script. Also make sure to call `wp_head()` before your closing head tags, to make it work.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "javascript, wp enqueue script, scripts" }
Submenu in sidebar custom page template i would like to show the submenu of my page in a custom page template on the left side in a Sidebar-area. Does any know the code for showing the submenu. Wordpress 3.4.1 Thanks a lot!!!
If you are trying to code this yourself, all the info you need is in the Wordpress Codex - < Alternatively you could use a widget like the BE Subpages Widget
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "menus, sidebar" }
Using jQuery .after inside loop I have a bit of javascript that will dynamically add a static post to a loop. The script uses the jQuery 'after' method and on a static page it works beautifully but when inside the loop I don't get any results. Can anyone see what i'm doing wrong here? Does WP not allow DOM insertion within a loop? function newTile(){ var adTile = "<div class='new-box' id='article-tile'><h1> this is a test</h1> </div>"; var adLoc = 5; var tiles = $('#article-tile:nth-child('+adLoc+')'); $(tiles).after(adTile); }
WordPress requires **no-conflict** for jQuery. Change this: var tiles = $('#article-tile:nth-child('+adLoc+')'); $(tiles).after(adTile); ...to this: var tiles = jQuery('#article-tile:nth-child('+adLoc+')'); jQuery(tiles).after(adTile); Or else wrap your entire script accordingly: jQuery(document).ready(function($) { // $() will work as an alias for jQuery() inside of this function });
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "loop, jquery, ajax, javascript, content" }
How to Create Export/Import Functionality for Plugin I am following the tutorial here < The script shows how to export all options into JSON. Since my plugin creates a custom post type, I would also like to export and import all posts of this custom post type. How can I do that?
There are two basic approaches you can take. 1. Use the standard wordpress inport / export plugin manually through the admin. Your custom post type must have the property can_export = true (default = true) If you go this route, there are interesting options for adding extra functionality for users, Check out this tutorial on adding export filters specific to a custom post type 2. Use a custom export / import method you script yourself. For an example of how this might be done, see the Export to Text plugin. Just download it and read the code. For the import side, you would then examine their suggested import plugin, CSV Importer
stackexchange-wordpress
{ "answer_score": 5, "question_score": 4, "tags": "export" }
TinyMCE Plugin Parameter Can anyone tell me if there is anywhere I can find out what each of these TinyMCE plugins are for? $in['plugins']='inlinepopups,tabfocus,paste,media,fullscreen,wordpress,wpeditimage,wpgallery,wplink,wpdialogs,wpfullscreen'; I'm wondering because if I remove the `wordpress` one that the editor will stop stripping out my `<p>` tags, but I also lose all my spacing in the `html` view of the editor as well.
The first few you listed are not WordPress specific, and information about them can be found as follows: 1. **inlinepopups** 2. **tabfocus** 3. **paste** 4. **media** 5. **fullscreen** As for the WordPress specific plugins, their source code is here (trac). There are no comments, but here's my take based on a very cursory read through: 1. **wordpress:** seems to setup the editor with default buttons, classes, size, etc 2. **wpeditimage:** seems to add the insert media dialog 3. **wpgallery:** launches tb_show("",tinymce.documentBaseURL+" **/media-upload.php**?post_id="+f+"&tab=gallery&TB_iframe=true&width="+d+"&height="+g) which adds the gallery dialog 4. **wplink:** seems to add the insert link dialog 5. **wpdialogs:** adds tinyMCEPopup js function, probably used by the other dialogs 6. **wpfullscreen:** puts the editor in wordpress 'distraction free' full screen mode. Not sure why this one and the standard fullscreen plugin both exist.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "tinymce, editor, wp editor, plugin tinymce" }
How to benchmark a WordPress installation? I'm trying to gather some benchmarking data to determine how well my optimizations to WordPress are fairing. I've found this page on High Traffic Tips but it doesn't contain any data. Are there any tools that benchmark WordPress? Not just how well it holds up against traffic, but things like how caching fairs when you're performing X Posts an hour and X comments a minute as well as other normal use cases for WordPress. For the record, I've run Siege and Blitz.io against installations, but that's merely how well your site can cache and serve/spread the requests around. If that's the only the only measurement that can be consistently produced (maybe req/s is the only way to go) then that's fine. If there are other tools that can show how many req/s can be sustained over varying usage (have to regenerate the cache ever 10 mins will have a big impact if it's serve while refreshing, or clear out cache then refresh cache).
Siege. Test against both an actual post/page (which would theoretically hit page cache, APC, varnish, etc. for every request after the first request), and against a 404 (e.g., randomly generated strings), which would require database queries on each hit. A few helpful flags: * `-b` benchmark (don't wait between requests) * `-c N` where N is the number of concurrent requests to make * `-t N` where N is the time (e.g., `30S`) to run the test If it's helpful this script will generate random strings (404s) which can be used to generate requests to posts/pages which will generate 404s.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 14, "tags": "customization, optimization" }
Move Index to a page From a default WordPress install, I have set a static page as the front page and now I want to have the last posts (what is normally seen when visiting the root of the website) in a "Blog" page. Do I have to create a special template for this page where I must create a new query, save the paged variable for the navigation and so forth, or is it possible somehow to reuse the simple index.php template in this "Blog" page ?
When changing the setting to make the front page a static page, you will have assigned the blog posts to another page. If you name that page 'blog' you can access your latest posts at yourwebsite.com/blog No extra tinkering required :)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "templates" }
How do I insert a custom field in a user submitted post? Please help! I have a form for users to submit posts, and I want them to be able to choose photos already in the media gallery based on category selected. I want to include radio buttons to choose between a few images that will attach to the post, become the featured image, or just echo out in a template file in this manner <?php $custommeta = get_post_meta($post->ID, "CategoryImage", true); ?> The value of the selected image will be the image url to echo out into the custom field. I can not figure out the code to get the custom field in the form and get the value into the custom field. I think I should use add_post_meta but I am not completely sure how to incorporate it. Any help would be greatly appreciated. I am using the plugin User Submitted Posts but I would take a general answer as well.
I got custom fields working in the front end form linked in this post: How to use nonce with front end submission form? Here is the code used for the form page (custom page template): < Hopefully that will be of help to you with a bit of tweaking to use image URL's instead of text as the custom field input. I had considered using the User Submitted Post plugin too but couldn't figure out how to include custom fields with that, so ended up making the form by hand.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, custom field, images, forms" }
warnings & errors after MAMP to live (hosteurope) I get these warnings after getting live with my wordpress site from local to server. Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'bones_register_sidebars' not found or invalid function name in /is/htdocs/wp1108989_5IDG6XP7VR/www/cgi-bin/website/wp-includes/plugin.php on line 403 Warning: Cannot modify header information - headers already sent by (output started at /is/htdocs/wp1108989_5IDG6XP7VR/www/cgi-bin/website/wp-includes/plugin.php:403) in /is/htdocs/wp1108989_5IDG6XP7VR/www/cgi-bin/website/wp-includes/pluggable.php on line 881 hoster is hosteurope. any one any ideas how to fix it?
These are warnings, not errors ( edited original question to reflect this ). You have two options: * **The easy way** \- Turn off displaying errors and warnings, log them to a file instead * **The proper way** \- Fix the warnings, and log them to a file instead of outputting If you need help fixing the warnings, post your code I'll update my answer with an explanation of what happened and how to fix them. Specifically, the code in your theme/plugins that adds `bones_register_sidebars` which is being complained about by PHP
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "errors, warnings" }
how to make custom posts sticky? > **Possible Duplicate:** > Wordpress 3.1 - How does one add sticky post capabilities to post types What I had was normal posts...until I realized that custom posts are what I should use for my purpose. But then I noticed that I don't have the option to make a custom post sticky from the admin panel. Is there a way to get that feature working?
there was a big talk about that : < They ended deciding that a custom field will have to be used...
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, sticky post" }
Avoid updating post when sending POST or GET request to post.php I've created a Plugin which adds a new meta-box on the post.php dashboard page, containing a form. Whenever a POST request is submitted from that form, I would like to save some post meta-data. I have been able to implement this, but I noticed that each time this POST request is sent, the entire blog post gets updated, including changes that were made outside my meta-box. It's as if I was pressing the default "Update" button instead of my own form submit button. Is there a way to send a POST (or GET) request to post.php without having it interpreted as a request to save all changes to the blog post? There must be such a possibility, since refreshing that page from a browser does not cause the blog post to automatically be updated. I know I could probably do this using AJAX, but I'd like to avoid that if possible. Also, I'm using WordPress 3.4.1.
The metabox itself sits inside a form which encompasses (almost) the entire page. You're metabox callback shouldn't print a form itself (since you'll end up with nested forms). Instead the meta data should be updated when the post itself is updated, using the `save_post` hook. The only way of updating part of the post's metadata without updating the entire post is to use Ajax.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugin development, forms, dashboard" }
How to Remove a Title from All Category and Tags Page? I am trying to remove the title from all my category and tags page. So far, I have been using this code < It works but not perfectly. The title of my category and tag page is removed. However, on my sidebar, the content in my recent posts widget also lose their titles. What other qualifier should I add other than is_archive() so that it strictly targets only the title on the category and tag pages? Thanks.
I agree that editing the loop would be the best way to do this as it keep the changes local to that php template. Simply go into category.php (or archive.php) and tag.php, look for `<?php the_title(); ?>` and delete it or change it to `<?php //the_title(); ?>` to comment it out.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "categories, tags, archives, title" }
multiple external urls in wordpress website I am working over a wordpress website which is basically a union of wordpress + their official website which is in php. In wordpress I am simply showing wordpress data. but when user need to create something , then user is directed to that official website. Example 1. Create new flower from the flower page (I have content page for flower) 2. Create new fruit from Fruit page I just want to know the standard way to manage all these number of external urls rather than giving a static links for all of them. Thanks
I'm not completely sure what you mean but if you're wanting to keep all the links represented in the Wordpress system you could use the 'page links to' plugin and create a Wordpress page for each of the external links - < Then link to the Wordpress page version from within your Wordpress pages.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins" }
Mass crop images: Landscape images -> Portrait images I have several images that are wider than they are tall (landscape). The problem is that the theme I'm using crops images to 150x214px (taller than they are wide). This set up works for the majority of the images but there are still several left with the sides cut off. Is there anyway I can mass-crop the images that are wider than they are tall? Here's what I mean: The image on the left is wider so the sides get cut off. I want to add height to these images so the whole product fits like the image on the right.
In media settings change: > Crop thumbnail to exact dimensions (normally thumbnails are proportional) to unchecked. This will fix the problem on new images. For old already imported images, you'll need to regenerate them. There are many plugins that can do this. This plugin is well known: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "images, cropping" }
Access Tables with number prefix I have multiple sites setup within my site. I need to access all the various options tables which are named 'wp_#_options'. How can I select these tables that have a number prefix? Using `$wpdb->get_results($wpdb->prepare("SELECT * FROM ".$wpdb->7_options." WHERE ....."));` gives me a parse error.
When in multisite, the wpdb prefix is always the prefix required to access the tables for the current site. This includes the site ID so this should work: $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."options WHERE .....")); There should be no difference at all when using multisite, just make your queries as if it were single site.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "query, mysql" }
Multisite multidomain I have a wordpress multisite. I'm using a single domain, but **I want to use multiples domains. I want to allow the user choose a domain for his subdomain.** I was searching, but i don't found nothing about this... only a domain mapping plugin and is for singles sites.
One way to do it is to use the **Networks for WordPress** plugin: < It will create a sub-network for each of your domains. So basically you'd have a network of networks of sites. Each sub-network will be using the same install of WordPress, but will be managed separately with it's own sites under it. Like so: mainsite.com * site2.com * blog1.site2.com * blog2.site2.com * site3.com * blog1.site3.com * blog2.site3.com (mainsite.com could also have it's own blogs under it)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "multisite, customization" }
How to output only the post content How can I output ONLY the post content (ie the text entered into the wysiwyg) and nothing else? i just need this for the posts in a specific category, so if i could call like say, <?php get_template_part( 'venue_content', 'single' ); ?> it would be ideal.
Assuming you are in the loop, or otherwise know (or know how to get) the `$post` object: function wpse63358_get_post_content() { global $post; return $post->post_content; } If you want the _formatted_ post content, replace this: return $post->post_content; ...with this: return apply_filters( 'the_content', $post->post_content ); To echo the function output: echo wpse63358_get_post_content(); ### Edit Note: if you just want to output post content in the template, you don't actually even have to bother with wrapping it in a function. Simply use: global $post; echo apply_filters( 'the_content', $post->post_content );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "the content" }
Plugin activated but plugin files nowhere to be found I installed ThreeWP Broadcast through the WP backend and it works fine. But where can I find the associated PHP files? I've tried looking in the plugins and mu plugins folder of wp-content.
Go on your plugin list and hover the edit button for the selected plugin. Have a look at the url. It should be something like: `
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins" }
Loops running into each other I have 3 loops on one page, each pulling a different CPT into a portfolio like layout. Live: < Gist: < However the tags for the second and third sections are inheriting the ones from the loop before it. Also when I click on one of the tags to filter it, it filters all 3 loops. JS issue? In fact, could it all be JS related? I know there are probably better ways to do this instead of multiple Custom Post Types & Loops. But it's kinda in there now. I'm hesitant to start all over.
Pretty simple fix, from what I can tell.. after each "loop" you need to reset your term list.. $term_list = '';
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, loop, jquery, javascript" }
How to make wp dropdown category load with selected option on top? I have the selected option saved correctly, but when load the page, wp_dropdown_categories still load the list by its order. I prefer to load the selected item on top. How to do this?
if the currently selected item has some type of identifier on it (maybe class="current") you may be able to use some jquery to grab it's value, hide it, then move it to the top. <div class="topdiv"> this is top div </div> <ul> <li>1</li> <li class="current">2</li> </ul> (function() { var top = $('.current').html(); $('.current').hide(); $('.topdiv').text(top); })(); this worked in testing
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories" }
Plugin that resets database and deletes all content, plugins Is there any plugin that can immediately return a site to how it looked when just installed, including removing all extra db entries, themes and plugins installed etc?
The WordPress Reset plugin will reset your database to its default settings. This plugin doesn’t delete files, so you’ll have to manually delete themes and plugins before using this plugin.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "plugins" }
Removing user fields > **Possible Duplicate:** > How To Add Custom Form Fields To The User Profile Page? I'm current removing some user fields with the following code in the functions.php file: function adjust_contact_methods( $contactmethods ) { unset($contactmethods['aim']); unset($contactmethods['jabber']); unset($contactmethods['yim']); unset($contactmethods['twitter']); return $contactmethods; } add_filter('user_contactmethods','adjust_contact_methods',10,1); I'd like to additionally remove the website and Google+ fields, but I can't find the correct keyword. Any advice?
unset($contactmethods['googleplus']); Is what I needed to add to my above code.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "wp admin, users" }
Is it safe to update from 2.6.2 to the newest version? I'm using Wordpress version 2.6.2 and now it shows in the page that Deprecated: Assigning the return value of new by reference is deprecated in /home/np14388/domains/<sitename>/public_html/wp-settings.php on line 472 etc. Is it safe to update from this version to the newest one, or should I update in certain phases (2.6.2 -> 2.6.3 etc.)? Please help.
Probably. Just do the following before updating: 1. Do a direct SQL backup of the database 2. Export your site content 3. Disable all Plugins 4. Switch to the default Theme Then update to the latest version. If anything goes wrong, just restore from your backups, and try an iterative update.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "updates, wordpress version, deprecation" }
Hide widget if user is logged in without plugin I would like to be able to hide a widget in the front-end if the user is logged in and only display the widget when the user is not logged in. I have found a plugin that does this called Widget Logic however i don't want to install too many plugins especially for something as small as this. Your help will be much appreciated.
If you're comfortable changing the code where the widget is outputted you could use the is_user_logged_in() function. Something like this: <div id="widget_area"> <?php if ( is_user_logged_in() ) { // show nothing } else { dynamic_sidebar('widget_name'); } ?> </div> The downside being that this is now hard coded and you might have to add this function in a few different files. Steve
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "widgets" }
Is there a save_post hook for custom post types? Is there a `save_post` hook for custom post types? Example: `save_my_post_type` I know there is `publish_my_post_type` but I'm looking for a save hook.
the hook is the same `save_post` just make sure its your post type ex: add_action('save_post','save_post_callback'); function save_post_callback($post_id){ global $post; if ($post->post_type != 'MY_CUSTOM_POST_TYPE_NAME'){ return; } //if you get here then it's your post type so do your thing.... }
stackexchange-wordpress
{ "answer_score": 42, "question_score": 52, "tags": "hooks" }
How to stop wordpress from showing the selected category on top of others in the category selection? By default in the category chooser at the edit post screen wordpress displays the selected categories on top of the others, i find that extremely annoying and i would like to disable the feature even if i need a hack for this.
If I got this right, you need this plugin: Category Checklist Tree. > On the post editing screen, after saving a post, you will notice that the checked categories are displayed on top, breaking the category hierarchy. This plugin removes that "feature". > > Additionally, it automatically scrolls to the first checked category. > > Works with custom taxonomies too.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "categories, wp admin" }
Noob Question - Buddypress Dynamic content on static page Sorry for posting such a noob question but I am totally stuck and don't know what I am looking for. So basically I have a buddypress website with a static homepage. On the homepage I need to add a dynamic area where the admins can add a news story, this story will change maybe once a month. I just need to know what I am looking for, is it widgets or sidebars or something else? Once again sorry for the noob question, I am new to all the WP/BP stuff. Its the latest version of WP/BP. Kyle
You need to open up your custom child theme and add a loop to the index.php. Or if you want it in the sidebar then you add it to sidebar.php with a conditional check if you only want it to appear on the homepage. If you only want to show one post you add something like this. <?php global $wp_query; $args = array( 'cat' => #, //add the category id of the posts 'posts_per_page' => 1, // set how many posts to show in the loop ); $wp_query = new WP_Query( $args ); while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?> //setup the contents of the loop <h2><?php the_title(); ?></h2> <p><?php the_excerpt(); ?></p> <?php endwhile; ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "buddypress, customization" }
Force resize for all video content I'm looking for a way to force all video content on my site to scale to 100% width and I'm hoping to avoid using any additional javascript. Is there a filter or function that I can use to accomplish this? If so how is it used? And I do not want a plugin!
Without knowing more information - you can use CSS to set a max width to any element. iframe, object, embed { max-width:100%; } Rachel Baker mentioned Fitvids.JS in her WordCamp Chicago presentation last weekend. It is a Javascript plugin that writes specific code for the various video providers online. Try the CSS solution and fall back to JS if you can't figure it out.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "functions, filters, hooks, videos" }
Can You Build Page Templates Without Extra Files I'm very familiar creating page templates in WP and for this project I really just have one page template with an option to switch the sidebar from the right side to the left side. The problem is that I would hate to have all of that duplicate code in both templates especially since I'll just be swapping css classes on the two elements. Options: * 2 separate Page templates * Custom fields * Custom taxonomies I'm thinking that having a custom taxonomy might be the best solution. The client would see a small box on the right side of the page titled `Visual Options` and there would be a checkbox for `Sidebar on right`. It is intuitive and it is DRY. Is there something else I didn't consider?
Don't use custom page templates for structural layout changes. Use custom post metadata instead, and then output conditional CSS rules (or even custom HTML markup, though that's probably not necessary here) based on the value of the custom post metadata.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom taxonomy, custom field, pages, page template, page attributes" }
Wordpress Menu - creating a fake link I like to create Web site mockups for clients using Wordpress. Typically I will only create the landing page and a believable navigation menu. To keep from creating extraneous pages I will create a Custom Link using "#" and then enter whatever menu name. The problem I run into is when I mouse-over the menu link I get a straight cursor symbol instead of the typical mouse-over hand symbol. Basically I am looking for a simple solution, if it exists, so that when a client mouses-over one of these menu links the cursor changes to the hand so it 'feels' like a real link.
CSS. .menu li { cursor:pointer; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "menus" }
Mass check a certain box in an option panel for 3000+ WooCommerce products? I am using WooCommerce and have 3000+ products. With WooCommerce, there is an option to enable/disable reviews for each product. The box looks like this on my edit product page: !snapshot Unfortunately, the checkbox (highlighted in red) doesn't come checked by default. I have contacted WooCommerce about this and they told me that this box being checked depends on whether or not I have comments enabled in _Settings > Discussion_. However, comments are, and have always been enabled, yet none of my products have the reviews option checked by default. This is a huge burden because this would potentially mean that I would have to browse through each of the 3000+ products and check off the box manually. Is another way I can "mass check" these boxes for each of my products?
If you have database access, and are familiar/comfortable with MySQL, you could write a simple update script on the product table, replacing all 'review_status' to be 'yes'. I am not familiar with WooCommerce back end, but you will just need to find the proper table, column, and value, and it would be a 5-10 second long ordeal. `UPDATE [wp_woo_products_table] SET [product_status]='[enabled/yes]'` Ignore the square brackers [] in the line above, they simply mean placeholders for the proper values.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins" }
trouble with featured image I don't understand why this happens I created a new image size in functions.php called blog. Code looks like this add_theme_support( 'post-thumbnails' ); add_image_size('blog', 134, 134, false); Yet for some reason when the featured image comes out as 134 by 58 when called like this <?php the_post_thumbnail('blog'); ?> Can anyone tell me why that is? The actual image uploaded to the library is much larger than that
When you set that final argument of `add_image_size()` to `false`, it scales the image down until the height or width matches one of the set values, then it maintains the proportions. For example: * A 600px by 400px image using your settings is 134px wide (the long dimension) and then 89px tall (proportional to 134px wide). * If the image were 400px by 600px it would be 134px tall by 89px wide.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images" }
wp_list_pages() refuses to output posts Someone help me understand why the following do not output anything: wp_list_pages( 'post_type=post' ) wp_list_pages( 'post_type=event' ) Yet the following work as expected: wp_list_pages( 'post_type=page' ) WP_Query( 'post_type=post' ) WP_Query( 'post_type=event' ) I'm stumped.
`wp_list_pages` will only output hierarchical post types. If we look at the function in source, we'll see that it calls `get_pages` to load pages for output. If we look at `get_pages` function in source, we'll see: // Make sure the post type is hierarchical $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) ); if ( !in_array( $post_type, $hierarchical_post_types ) ) return false; The default `post` post type is not hierarchical, so the function outputs nothing. If your `event` post type is also not hierarchical then that would explain why it also outputs nothing.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "query, wp list pages, post type" }
How to make sure a wp-cron job runs I am using a plugin to send emails to a relatively large email list. Because we have a low per-hour email threshold from our host we have to use a setting in the plugin to throttle the emails down to only a certain number every hour. I am assuming that the plugin uses wp-cron to accomplish this. I have tried finding documentation on wp-cron but the only substantial information I have been able to find is that it requires a page view to run. Questions: 1. Is an RSS feed being pinged enough to trigger a "page view" and therefore wp-cron? 2. How long after a page view will wp-cron run? (e.g. if last page view is at 6:59p.m. will cron scheduled for 7pm run?) 3. What happens if a cron job is missed?(No one visits website all day until 7:03 p.m. Is 7p.m. cron job run?)
1. Yes. 2. No, because the scheduled job hasn't reached the time yet. 3. Yes, but not until 7:03pm. Basically, any hit to the site after the scheduled time will cause the queued job to run. The WP_Cron is a "best effort" system, not an exact timer. This is generally good enough though, since if nobody's visiting the site, then it doesn't need to run and do anything for the most part.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "plugins, wp cron" }
Setting a default placeholder image WITHOUT link Can anyone help? I'm trying to show a default placeholder image on my posts when the user hasn't uploaded an image. I have the below code BUT i need to rewrite it so that the link isn't applied to the placeholder image - only the uploaded image. Unfortunately my PHP isn't great at all so would appreciate some help.. <div class="imageContainer"><a href="<?php the_permalink(); ?>"> <?php // Must be inside a loop. if ( has_post_thumbnail() ) { the_post_thumbnail('size-2'); } else { echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/shared/placeholder.jpg" />'; } ?> </a></div>
<div class="imageContainer"> <?php if ( has_post_thumbnail() ) : ?> <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('size-2'); ?></a> <?php else : ?> <img src="<?php echo get_bloginfo( 'stylesheet_directory' ); ?>/images/shared/placeholder.jpg" /> <?php endif; ?> </div>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "post thumbnails" }
How to place HTML tags in content from the_content()? Firstly, I am new to Wordpress so thank you for your patience. I have a list of posts (with excerpts) being displayed in the page using Short Tags. The output is fine , However, I wish to add and change some tags which is coming as a content from the_content as I see under page.php file of my theme files. Any direction / guidance is greatly appreciated. Many thanks.
_sorry to mark this as an answer for some reason I can't comment on this question._ Can you explain more what you mean by "I have a list of posts (with excerpts) being displayed in the page using Short Tags."? Do you have a list of posts excerpts displayed on the front and some number of short tags in the backend that utilize some plugin? Without more information I can only point you to the content filter on the WP Codex. You should be able to use that to filter the output before it is sent to the browser.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "theme development, themes, pages, the content" }
How to get user ID during registration and add it to a custom table I am trying to get the user ID during registration and automatically add that ID to my custom table. I am using the WP-Members plugin for registration. Is it possible to get user ID on the fly while registering and add that ID to another custom table with WP-Members plugin. Or I could use a custom registration page if required; but I need some guidance how to get user ID on the fly during registration. **Anyone please help me...**
Please take a look at user_register hook This is fired when a new user is registered and conveniently passes you the user ID of the new user. function function_name( $user_id ) { /* do what you want to do with ID here */ } add_action( 'user_register', 'function_name');
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "users, user registration, table" }
Is it possible to import a wordpress backup from a single site in to a multi-site configuration? I have a local development server with WordPress installed (my desktop Linux Mint 12 box). I'd like to use multi-site WordPress to manage my different client projects through one install, but I have a couple of important questions before I commit to this set-up. 1) Is it possible to import a database backup (created from the Admin Panel's backup tool) from a single WP site into a multi-site child site? 2) Vice versa -- Is it possible to export a multi-site child site's database and import it in to a single site? (for migrating from my dev box to the live server!) 3) Are there any other 'obvious' problems that I should worry about when using this kind of set-up for localhost development? Community question: What method(s) do any other developers out there use for managing multiple WordPress projects? All advice / help / guidance greatly appreciated!
I imported/exported between a single wordpress blog and a multisite wordpress without problems, many times. Personally on a multi-site wordpress I have a parent generic theme and each website has it's own child theme with as few files as possible, mostly only html/css for custom post types. Security issues or big complicated options are most of the time in the parent theme anyway, which means I keep improving all my websites at the same time. It's how I like doing, doesn't mean I would advice to do the same because a working website has something wonderful: it's working... Anyway if you make a mistake with an update (plugins, themes or other) all the websites using the same help noticing earlier.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "multisite, database, import, export, development strategy" }
Changing the template hierarchy Is there an easy way to change the WP default template hierarchy? For instance; Say I want to change my theme directory structure so that it completely changes from the Template Hierarchy suggested here based upon conditionals: < If I wanted to make sure that for all page types (`is_single()` `is_home()` etc) it always opens one template file which then instigates my own pattern to provide the output? Thanks very much!
Try this filter function wpse_63614_restructure_template_hierarchy( $template ){ return get_template_directory().'/filename.php'; } add_filter( 'template_include', 'wpse_63614_restructure_template_hierarchy' ); The filename would be the file you would want to call in your theme folder. For child themes you would use `get_stylesheet_directory` instead. **EDIT:** Or as suggested by Chip Bennett and what I too feel would be better; you can use the `template_redirect` hook in the following manner. The priority can be set accordingly if required. function wpse_63614_restructure_template_hierarchy(){ include( get_template_directory().'/filename.php' ); exit; } add_action( 'template_redirect', 'wpse_63614_restructure_template_hierarchy' );
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "php, theme development, themes, page template" }
Add a term to an attachment submitted from front end I have a front end post form where users can upload a file with their post that I save as an attachment using `media_handle_sideload()`. I need a way to add a term to that attachment so I can show a loop of all specific attachments by a user with that term.
`media handle sideload` returns an attachment ID, and attachments are normal posts with the post type 'attachment'. All the same things apply, featured images parents taxonomies post meta etc albeit with a few attachment oriented functions like `wp_get_attachment_image` So use `wp_set_object_terms` as you normally would, e.g.: $id = media_handle_sideload(.... if(!is_wp_error($id)){ wp_set_object_terms( $id, array(terms...), $taxonomy, $append ); }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "taxonomy, attachments, terms" }
Post-thumbnail only for specific post-types? I have this in my `functions.php` add_theme_support( 'post-thumbnails' ); This means all my post-types (normal posts and custom-post-types) have post-thumbnails enabled. Is it possible to just enable them inside a custom-post-type and not on normal posts?
Use `remove_post_type_support` to disable features for specific post types. add_action( 'init', 'wpa63635_init' ); function wpa63635_init() { remove_post_type_support( 'post', 'thumbnail' ); }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "custom post types, functions, post thumbnails, add theme support" }
Semantic URL Custom Post Type and Taxonomies permalinks I have created a custom post type with custom taxonomies. Now I need help with the permalinks. Now is like that: * custom post type archive: `example.com/custom-post-type/` * taxonomy archive: `example.com/taxonomy/` * single custom post type: `example.com/custom-post-type/single/` It should be like that: * custom post type archive: `example.com/custom-post-type/` * taxonomy archive `example.com/custom-post-type/taxonomy/` * single custom post type: `example.com/custom-post-type/taxonomy/single/` How can I achieve that?
## Plugin Recommendation I've had some great experience with the plugin Custom Post Type Permalinks. Here's the settings panel that it provides which allows you to define your structure per custom post type. !Custom Post Type Permalinks Admin ## Adding More Permalink Tags If you want to further extend the permalink structure tags for your needs you can take a look at the add_rewrite_tag API function. ## CTP Tax Archive The CPT Permalinks plugin won't take care of your CPT Tax archive, so you need to add the following rewrite rule to your functions.php file: add_rewrite_rule('^(your-cpt)/(taxonomy_1|taxonomy_1|taxonomy_3)/?','index.php?post_type=$matches[1]&taxonomy=$matches[2]','top'); You will obviously need to replace your-cpt and the taxonomy names in the regex. ## Testing I highly recommend you to use the Monkeyman Rewrite Analyzer to help understand what rewrites are registered and how they match your URLs. Hope this helps you out.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, custom taxonomy, permalinks" }
Pull comments from one page/post into another page/post? I am creating a facebook app via wordpress but some how need to pull the comments off my homepage and insert them onto another page, essentially what I am trying to do is duplicate the homepage with a different url/page name. I have mananged to do so easily but I need the comments as well. Thanks a tonne to anyone who can help in advance!
If that's the case you are going about it the wrong way. You should use WP_Ajax_Response to send the comment, or just redirect the the same page. Duplicate content is not what WP is intended for.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, comments, templates, page template" }
Rewriting search permalink when typing "a" into my search field (/?s=a) I my `search.php` template is loaded and all results that match that letter are shown. If I add this to my .htacess … RewriteCond %{REQUEST_URI} ^/$ RewriteCond %{QUERY_STRING} ^s=(.+)$ RewriteRule .* /searchmyblog/%1/? [R,L] and then type "a" into my search the first result of my search is shown. So there is no `search.php` template shown with all the results but rather the page is redirected to "mypage.com/somecategory/amore-mio" Why is that happening? I simply want to rewrite the normal `/?s=` to `/search/` or any other custom url. Any ideas on that? I found heaps of posts online, but none of them seem to be state of the art or use some weird JS-hacks that I find unnecessary. Ideas on that?
WordPress doesn’t know that you want the path `/searchmyblog/` as search result base. So when it sees the `a` it tries to find the best match – in your case a post starting with this letter. To fix that you could modify my code for the pagination base to change the search base: if ( ! function_exists( 't5_search_base' ) ) { register_activation_hook( __FILE__ , 't5_flush_rewrite_on_init' ); register_deactivation_hook( __FILE__ , 't5_flush_rewrite_on_init' ); add_action( 'init', 't5_search_base' ); function t5_search_base() { $GLOBALS['wp_rewrite']->search_base = 'searchmyblog'; } function t5_flush_rewrite_on_init() { add_action( 'init', 'flush_rewrite_rules', 11 ); } } Now your `.htaccess` should work.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "permalinks, search, htaccess" }
Where does WordPress default SimplePie save cache data? Where does WordPress default SimplePie save cache data? I could only find relevant info about cache durations but not the location. SimplePie has a method called `set_cache_location()` but I cannot find it being used in WordPress. I'm writing a plugin and if a cache folder is available already by default, I'd like to use it rather than creating for my plugin. Does anybody know it?
In WordPress, the `WP_Feed_Cache` class uses the `WP_Feed_Cache_Transient` class to store the results into a transient. So, short answer, either in the database or in the Object Cache if you have a persistent object cache stored. If you need to cache something for a period of time, use a transient. <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "rss, feed, cache, simplepie" }
store/cache ajax sent data to avoid repeated request I developed a widget that offer a full blown archive search tool, where the user can select various options that are joined into an objects to be passed to WP_Query in an ajax action that returns the results data via JSON. 10 results are sent back to the page so pagination is needed. A new request is sent every time the page is turned. More here. My question is: to decrease the request payload, I want that if the action is called after a page turn the information about the query is not sent but just the change page order is sent. To achieve this i suppose the solution is to store the already sent query. How is possible to do this? thanks!
Attempting to answer this question directly: if the data you are returning is exactly the same each time, you can send cache control / expires headers with your AJAX response so that the browser knows not to request again for a while. // ask the browser to cache this response, to reduce requests $expires = 60 * 15; // 15 minutes header('Pragma: public'); header('Cache-Control: maxage=' . $expires); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT'); But if you want different data each time, which it sounds like you do (via paging), then caching does nothing for you here. This answer on your other question explains why you would be better off grabbing small chunks at a time.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "ajax, performance" }
Redirect old query string urls to new SEO urls I had urls like `example.com/?area=new-york`. `area` is a custom taxonomy. I had to change the urls to `example.com/new-york`. I want to do a 301 to new urls if previous urls are accessed. and I want Google to update its index. I have been trying to define a rewrite rule that can accomplish this but I failed. Help needed!
You can use the Redirection plugin. This plugin supports full regular expressions and another interesting redirection functions.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "url rewriting, rewrite rules" }
Function to check if custom page is used by page? I have template-clientlist.php now I search on wordpress doc but can find a function on how to check if page used template-clientlist.php template-clientlist.php <?php /* Template Name: Page Of Posts */ ?> Is there function that exist or custom function to check if page used the custom template?
You can give this a try. $template_name = get_post_meta( get_the_ID(), '_wp_page_template', true );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "functions, customization, page template" }
why is there an author.php Why is there an author.php file when the same information is in the single.php? I looked at the template hierarchy and one would think that if author.php wasn't present, the single.php would come into play but it doesn't. I would also think that if you styled the author.php then that would affect the author bio on the pages, but it doesn't. So I was thinking about just removing the author bio all together. Maybe make it a function and call it in my page. What do you think?
From the Codex: > ...when a viewer clicks on a link to a post author, by default he or she is taken to a page listing the posts from that particular author in chronological order, from newest posts at the top to oldest at the bottom. In other words, the author template is used to show posts made by one person as well as their bio (if so configured). Whether or not to use it is up you, so go ahead and remove it if you want or if you are the only author.
stackexchange-wordpress
{ "answer_score": 2, "question_score": -3, "tags": "author" }
Filter an array with a callback - for single & multidimensional arrays I've a filter attached, that allows modifying an array: $data = apply_filters( 'wpse_example_filter', $data ); The problem is, that the data can be a single or multidimensional array: // single: 'SINGLE' => array( // some data ) // multidimensional: 'MULTI' => array( 0 => array( // some data ) 1 => array( // some data ) ) **Question:** What's the easiest way to loop through the data of one of those arrays (inside my callback), without knowing if I got a single or multidimensional array and without creating another callback function? **In other words:** How would I write a recursive filter callback?
While your answer is very interesting and I like it, I still want to post another proposal, just let you have another choice :) IMHO, if the data contains only simple fields, like: array( 'name' => 'my name', 'address' => 'my address', 'phone' => '01234', ); then you can use the code below: add_filter( 'wpse63692_example_filter', 'wpse63692_example_cb' ); function wpse63692_example_cb( $data ) { foreach ( $data as $key => $value ) { // Recursively apply filters to sub array if ( is_array( $value ) ) $data[$key] = apply_filters( current_filter(), $value ); } // Do something with $data return $data; }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "filters, callbacks" }
iis6 multisite and permissions For testing mobile themes and other reasons, I am trying to use an existing server with wordpress setup as multisite. The root site is not in inetpub/wwwroot but rather on another partition and that seems to work. I want to the site to be conventionally < and < I can see that the tables are created in the db when I add the other site, but not corresponding directories of /wpadmin, /wp-content, or /wp-includes get created anywhere. I guess I am not sure where they should get created, and what permissions I would need on that directory. I have tried using IIRF to get around the .htaccess rewrite issue, (I think) but since the correct sub-directories never get created, there is nothing to redirect to. What have I done wrong? Is it not possible to have the base site in /? but not in /inetpub/wwwroot/? I hope this is clear
The solution was not that there was a permissions issue. Since iis6 doesn't use .htaccess it required installing Ionics Isapi Rewriter Enabled on the webserver you then insert essentially the same content as a the .htaccess file into an iirf.ini file in the root of the site you want and the content becomes available. Much simpler than I was trying originally.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "multisite, permissions, iis" }
Modify admin panel tab position I was just wondering if it's possible at all to move the position of a tab inside the admin panel. Here's what I mean: As you can see I have plenty of custom post types, and each one except for the Slider type has position = 5 ( above media ). Unfortunately some of them are sliding below, and I am looking for a way to have media after all of them again. Not a big deal, just wondering if it's possible. Looked around but couldn't find anything. Thanks.
Just in case anyone might stumble upon this and have the same problem, it can be done by manipulating the admin menu itself, and there's a great tutorial for this <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp admin" }
Adding a wp_head hook from an included PHP file I am using a WordPress plugin for including PHP code within posts and pages, and it's working great - however, I need to insert some styles and scripts, and in order to do that, I need to add a hook to wp_head. I tried it, creating a function and using `add_action('wp_head','my_func');` but it didn't work - my stuff is not being included. I think its because wp_head is being called before my script it being included. I would like to do this without changing any of my themes files. Is there any way to do this? I am using the latest WordPress version.
To enqueue styles and scripts properly, use the `wp_enqueue_scripts` action like so: function wpa_63708_enqueue_scripts() { wp_register_script( 'my-script','/path/to/script' ); wp_enqueue_script( 'my-script' ); } add_action( 'wp_enqueue_scripts', 'wpa_63708_enqueue_scripts' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "themes, hooks, include, wp head" }
custom naming of search permalink /search/ I found this snippet online … function search_url_rewrite_rule() { if ( is_search() && !empty($_GET['s'])) { wp_redirect(home_url("/search/") . urlencode(get_query_var('s'))); exit(); } } add_action('template_redirect', 'search_url_rewrite_rule'); This transforms my `?/s=term` into `/search/term` which is almost what I want. I'd like to use the german word "suche" instead of "search" inside my permalinks. I thought of changing `home_url("/search/")` to simply `home_url("/suche/")` but that doesn't work. How can I make that happen?
The reason it isn't working is because you haven't told WordPress how to handle that page. You can do so by applying a rewrite rule in the following manner. add_action( 'init', 'wpse_63716_search_rule' ); function wpse_63716_search_rule(){ add_rewrite_rule('^suche/([^/]*)?', 'index.php?s=$matches[1]', 'top'); } Don't forget to flush the permalinks after adding the above code.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "permalinks, url rewriting, search, htaccess" }
nested conditional to check for feature image and custom field? I have this working for the most part, but some of the syntax is wrong someplace because when the post DOESNT have a thumbnail, it still prints that last echo and closes a div outside of the conditional. Can someone help me get this syntax on this code right? Basically I want: Check for venue image, if it's there, display it. If there IS a thumbnail image, then check for a custom field, if it's there, display it. If not, do nothing, if no venue image, do nothing. Here is my code: <?php if ( has_post_thumbnail() ) echo '<div id="venue-single-img">'; { // check if the post has a Post Thumbnail assigned to it. the_post_thumbnail(); if ( get_post_meta($post->ID, 'Venue Image Notation', true) ) { echo '<span>' . get_post_meta($post->ID, 'Venue Image Notation', true) . '</span>'; } else {} echo '</div>'; } ?>
I believe this should do what you want: <?php if ( has_post_thumbnail() ) { echo '<div id="venue-single-img">'; the_post_thumbnail(); if ( get_post_meta($post->ID, 'Venue Image Notation', true) ) { echo '<span>' . get_post_meta($post->ID, 'Venue Image Notation', true) . '</span>'; } echo '</div>'; } ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "conditional tags" }
Conditional tag to show content in custom rss feed? The wonderful answer here helped me create a custom RSS feed, and that's one major part done. I know that there's the **`is_feed`** conditional tag to show content only if it's a feed. But is there a conditional tag to show content only in my custom feed? If not, is there any other way to do it? ( **PS:** I want to change the output of Wordpress' built-in gallery in my custom feed.)
Okay, that was quite easy. So, if your custom feed URL (non-pretty) is ` then the conditional tag would be used as such: if ( is_feed( $feeds = 'wpse63760_custom_feed' ) ) { // So what's the conditional content? } else { // This is shown everywhere else }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "feed, conditional tags" }
Switched hosts to one with cPanel. To transfer my blog should I do the WP install or just be uploading my old WP directory & database? I've never transferred a website before let alone a database. I believe I backed up the database to an .sql file and I haven't deactivated the old host yet in case I need to do it again. My main question is now that I'm on a host with cPanel should I use the automatic "WP Install" and then upload the database somehow or should I just follow Moving WordPress and just upload all of my folders and files from the backup?
After fumbling a bit with the database I came across < Switched the nameserver back, got into the old wordpress, did an export from in there so it would be in the xml format it wanted instead of sql. Switched the nameserver again to the new host, did a fresh WP install and imported the xml file from within wordpress. No database, phpmyadmin or mysql required!
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "hosting, uploads, migration" }
Custom menu: Link names I would like to build a wordpress theme with a custom menu (no dropdowns, nothing fancy). I am trying to get `wp_nav_menu` do what I want, but I can't quite see how to achieve the following. I would like to give the menu items different names, i.e. if I have a page called `Classes`, I would like the link in the menu to be called `clAssEs` (which I will style to be rendered in a different font). Should I use custom fields for this? P.S.: Looking at the html output, the classes of my menu list items are `page_item` and `page-item-21`. Does this mean I am doing something wrong? This looks more like it is generated by `wp_page_menu`. I am calling `wp_nav_menu` with <?php wp_nav_menu(array( 'theme_location' => 'main-menu', 'menu_class' => 'menu', 'container_id' => 'none', 'fallback_cb' => 'wp_page_menu' )); ?>
You can add other classes to individual menu items manually. Within the Appearance->Menus page, click Screen Options in the top right corner. You will see a menu that looks like this: !Custom Menu Classes Check off `CSS Classes` and it will give you an extra form field per page item. Adding a custom class will allow you to target each specific list element with CSS of JavaScript on the front-end. You can change the names of your menu items manually as well. They do not have to mirror the actual page names.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme development, menus" }
How to wrap this Link with an Image? im working on default wordpress theme twenty eleven, i just wanted to know how can i wrap this previous and next anchor with an image or next/previous button? <span class="nav-previous"><?php previous_image_link( false, __( '&larr; Previous' , 'twentyeleven' ) ); ?></span> <span class="nav-next"><?php next_image_link( false, __( 'Next &rarr;' , 'twentyeleven' ) ); ?></span>
Try passing in the image into the functions themselves: <?php $previous_image = "<img src=' alt='Previous Posts'>"; $next_image = "<img src=' alt='Newer Posts'>"; ?> <span class="nav-previous"><?php previous_image_link( false, $previous_image ); ?></span> <span class="nav-next"><?php next_image_link( false, $next_image ); ?></span>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "attachments" }
Add Field To All Pages I'm trying to add a custom field to the built in Page content type. I've found lots of tutorials on how to do this for a single page, but I want to do this for all pages in my theme. Please point me in the right direction.
If you want to do that yourself, take a look at function `add_meta_box` (don't forget the examples). That page has almost everything you need to create a custom meta box for a certain post type. If you want to simplify your work, you might want to use an utility like Meta Box plugin. This plugin can help you register your custom meta box with many built-in fields.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "theme development, custom field" }
Google Docs Viewer have problem in MultiSite sub-blogs An example file: < and here is same file but direct url without ms-files.php: < Its same file. Just first one is getting call with ms-files.php. Problem is first file is not working in google docs viewer: < giving this error: > Sorry, we are unable to generate a view of the document at this time. Please try again later. You can also try to download the original document by clicking here. But if i call same file with directly without ms-files.php: < Its working! So for some reason wordpress multisite is corrupting files in sub-blogs. There is no problem in main blog because main blog's files getting direct call and not using ms-files.php So how can i fix this? If you think i cant fix it, how can i get real path url from WordPress generated /files/ url?
Only fix for 3.4.2 involves hacking a core file. The issue is already corrected in the upcoming version 3.5. Edit wp-includes/functions.php. Around line 1810, you'll find this: 'doc|docx' => 'application/msword', Change that to this: 'doc' => 'application/msword', The docx file extension is actually already handled properly later down in the file, line 1819: 'docx|dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml', So it will work properly once you remove the spurious extension. Again, hacking core files is a bad thing, but seeing as the refactorization in WordPress 3.5 corrects the issue already, and there's no way to do this in a plugin or theme or even with a proper drop-in, I think that this specific case might justify it.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "multisite" }
Index in root, wordpress in subdirectory Okay I've googled this for hours...I installed wordpress to a subdirectory as a content management system, but I want my main index.php along with other files to remain in the root. What .htaccess code do I need to so that the main url < doesn't look for the wordpress/index.php (which of course causes the error "Warning: require(./wp-blog-header.php) [function.require]: failed to open stream: No such file or directory in /home/..."
## WordPress core in a subdirectory, but accessed via the root folder If you're trying to move WP to a subdirectory, but access it from the root, use the following approach. Keep your index file in the root, but point it to the proper path: `./SUBDIRECTORY/wp-blog-header.php` instead of `./wp-blog-header.php` Make sure you change you change the `home` and `siteurl` settings to match your directory structure either in Settings->General or by adding the following to your wp-config.php file: define('WP_HOME',' define('WP_SITEURL',' ## WordPress completely isolated to a subdirectory If you would like to keep WP completely in the subdirectory, just move your .htaccess index.php files to the sub instead of the root. As long as it doesn't conflict with the root .htaccess, it should work just fine. You can have nested .htaccess files within subdirectories and permalinks should work just fine.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "redirect, htaccess" }
Plugin init hook Is there a plugin init hook that runs whenever the plugin is being loaded? I'd like to link the functions for requiring files and defining constants to such a hook if it exists.
There's the `plugins_loaded` hook for normal Plugins and `muplugins_loaded`, which runs earlier. My best advice for hooks is making cross file searches for `do_action` or dump the content of the `all` hook with `$GLOBALS['wp_filter'][ current_filter() ];`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "hooks" }
Do New_to_publish hooks work for custom post types Do these hooks listed on the following site work for custom post types? < // function to be executed when a custom post type is published function run_when_post_published() { // your function code here } // replace {custom_post_type_name} with the name of your post type add_action('new_to_publish_{custom_post_type_name}', 'run_when_post_published'); add_action('draft_to_publish_{custom_post_type_name}', 'run_when_post_published'); add_action('pending_to_publish_{custom_post_type_name}', 'run_when_post_published'); I cannot get them to work...
I think you're using wrong hooks. Please take a look at wp_transition_post_status function, you'll see the correct hooks: function wp_transition_post_status($new_status, $old_status, $post) { do_action('transition_post_status', $new_status, $old_status, $post); do_action("{$old_status}_to_{$new_status}", $post); do_action("{$new_status}_{$post->post_type}", $post->ID, $post); } So, in your code, you should use hooks: 'new_to_publish' 'draft_to_publish' 'pending_to_publish' and in your function, you have to **check your post type**.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "hooks" }
Make a wordpress site similar to Hot Or Not - Image rating system I'm wondering how I would go about implementing some kind of image voting system to wordpress. I've had a brief look at plugins but none are particularly great. I would also like users to be able to upload photos? I'm not great with wordpress so any advice would be great. I'm literally open to anything here. I was also thinking of adding in buddypress to give some kind of community behind it all. Any advice welcome at all. More the merrier in fact!
Perhaps WordPress database schema is not so good for an implementation like this one, there's a couple of ways of how to do it. You could set a `rating` post type that is actually a reference with attachmed images and some information for people to rate. So, every time a `is_user_logged_in` user rates any post of this post type, you'll probably want to set the post as rated by this user (so he won't rate it again) on a reference for him in `wp_usermeta`, and also increase a `rating_count` on `wp_postmeta`. Well, this is just to start.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, images, rating" }
Tag description doesn't show hyperlink I have added HTML code into my TAG description box, but for some reason the output doesn't display the required results. I have even tried to add HREF tag manually into this box, but no hyperlinks are visible. The code contains tag_description();
You can't put HTML in taxonomy descriptions, but you can use a plugin such as < to enable that functionality.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "customization" }
Meta query stopped working The following query stopped working all of a sudden and I can't figure out why. <?php $today = date("Y/m/j"); query_posts(array( 'post_type' => array('events'), 'meta_key' => 'event_date', 'post_status' => 'publish', 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'event_date', 'meta-value' => $value, 'value' => $today, 'compare' => '>=', 'type' => 'CHAR' ) ) )); ?> No plugins have been installed and no one thouched the code, and I have no php/javacript error on the page. If I disable `value` in the meta_query, the posts show up fine, only there is no point of the query without it...
should `'type' => 'CHAR'` actually be `'type' => 'DATE'` the Codex might help on the possible parameters you need here
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "query posts, meta query, date" }
Is the W3 Total Cache plugin a good choice for WordPress MultiSite? I heard that many people had issues with W3 Total Cache on a WordPress MultiSite install. And then I see this on the plugin page: > Compatible up to: 3.2.1 > > Last Updated: 2011-8-26 Seeing that I'm running on WordPress MultiSite Version 3.4.1 and that it's been over a year since the last plugin update, I'm really wondering if this plugin is a good choice for me. Or should I use WP Super Cache with WP Minify instead?
W3 Total Cache is a GREAT option! One thing to keep in mind is that you need to individually work with each site for the settings - there is not a global settings area (yet). The next version is said to have this built-in. If you need this "right now", then WP Super cache does this and is a great option, if you can hold out for a little bit, then W3 Total Cache would be my personal recommendation. Thanks!
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "multisite, plugin w3 total cache, cache" }
How to access the actual input html of the login form I'm designing a custom login template and I need a way to access the `<input>` html so I can add a label inside the input. I understand the use of `wp_login_form()` but that only lets me set the default lables outside the input to blank. I need to add the `onfocus` and `onblur` attributes to the html. Any ideas?
There's this basic _trick:_ Close brackets, open again, insert what you need, close again. Real life example: $args = array( // some args for the login form 'value_username' => 'User Name" onBlur="whatever" onFocus="anotherfoo'; ); wp_login_form( $args ); So we closed the brackets after the Username, then added our additional attributes and left the quotes open at the end, so the `wp_login_form()` function can then close it by itself.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp login form" }
mysql query from wordpress page using custom table I want to a mysql query that matches a page title. Not sure of a better way to accomplish this task, but I am stuck. This is my basic test code. <?php $page_title = wp_title(''); echo $page_title; $test = $wpdb->get_results("SELECT * FROM $wpdb->park_data WHERE park_name = '"$page_title"' ") or die(mysql_error()); $row = mysql_fetch_array($test); echo $row['park_name']; ?> I keep getting a error on the query. If I just echo wp_title('');, no problem, prints. Can anyone see what I am doing wrong?
I think if you add a couple of periods before and after the php variable in your query, remove the use of mysql_fetch_array, and use get_row(), it should work better. Here's how I would get a park from your custom table: <?php $page_title = wp_title(''); $park = $wpdb->get_row("SELECT * FROM $wpdb->park_data WHERE park_name='".$page_title."'"); if($park) { print_r($park); // because other than it being an object, I'm not exactly sure what's returned. } ?> Also, keep in mind that the mysql query assumes the wp_title() returns the page title formatted exactly the same as the park_name stored in the DB. You may need to format wp_title() to get it to match up with your table data. It looks like you just want one park returned so I used get_row() instead: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "php, query, mysql" }
When is the {$new_status}_{$post->post_type} transition hook fired? Is it fired after a post has been published? Say I have a CPT and want to perform some automated actions based on the post that gets saved, can I do: add_action('publish_myt_cpt', 'myfunction');
It is fired in `wp-includes/post.php` on line 3026 in the following function: wp-includes/post.php: line 3014-3027 function wp_transition_post_status($new_status, $old_status, $post) { do_action('transition_post_status', $new_status, $old_status, $post); do_action("{$old_status}_to_{$new_status}", $post); do_action("{$new_status}_{$post->post_type}", $post->ID, $post); }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "hooks" }