INSTRUCTION
stringlengths 11
999
| RESPONSE
stringlengths 0
999
| SOURCE
stringlengths 16
38
| METADATA
dict |
---|---|---|---|
Converting HTML5 to XHTML
What do I need to ponder if I want to convert Twenty Eleven theme to XHTML? Is it just the matter of replacing the HTML5 for divs? | Probably the easiest way to do it is to set the doctype, etc and then use the w3c xhtml validator and just go through one by one and pick off the errors...but that will take A LOT of time, I strongly recommend you leave it as is. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "themes, theme twenty eleven, html5"
} |
Convert attachment ID into url?
I'm using the plugin advanced custom fields to create custom fields to create a relationship between two pages.
The code below is looking at the relationship field and grabbing the page title and company logo of the linked page.
The only problem is that instead of outputting the image url (so it displays the image), it's outputting the attachment ID. How can I convert the attachment ID into a url so the image displays?
<?php foreach(get_field('connections') as $relationship): ?>
<img src="<?php echo get_post_meta($relationship->ID, 'company_logo', true ); ?>" height="57" width="250" />
<a href="<?php echo get_permalink($relationship->ID); ?>"><?php echo get_the_title($relationship->ID) ?></a>
<br />
<?php endforeach; ?> | You need the function wp_get_attachment_image_src() see <
In your code it would be something like:
<?php foreach(get_field('connections') as $relationship): ?>
<?php $img = wp_get_attachment_image_src( get_post_meta($relationship->ID, 'company_logo', true ), 'thumbnail' ); ?>
<img src="<?php echo $img[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>" />
<a href="<?php echo get_permalink($relationship->ID); ?>"><?php echo get_the_title($relationship->ID) ?></a>
<br />
<?php endforeach; ?>
You can change 'thumbnail' to your desired size. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "custom field, images"
} |
Stop Images Linking to Themselves?
I have images on my website which I do not really want stolen, I have a no right click plugin which will help, and I would like to stop people clicking on the image to display it on it's own in a browser window.
I understand that anyone can access the source code and find the URL, I just want to make it a little more difficult.
How can I remove links from images, and just have the embedded image? | To change the default for images (so you don't have to choose "none" on the image links to checkboxes every time you insert an image into a post), you can go to **yoursite.com/wp-admin/options.php** ; find the `image_default_link_type` option, and change the value from "file" to "none". | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 0,
"tags": "permalinks, images, options, copyright"
} |
Within the database, where is the flag which says that a user has Super Admin rights?
I have an user in a Wordpress Multisite installation and have access to the Mysql database, I would like to give myself super-admin rights to access the wp-admin/network page. Where can I do it on Mysql?
I looked the database and I think the wp_usersmeta table is the one, but I have no idea how Wordpress manages the roles within the database.
Any help? | This is actually stored in the {prefix}sitemeta table. The meta key is site_admins, and it's a serialized PHP array of usernames. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "multisite, database, mysql, user roles"
} |
How to add super admin to all sites
Is there a way to add super admins to ALL sites without having to add them to each site individually? My group of super admins needs access to all sites. | Super admins do have access to all sites, but they don't show up in "My Sites" by default, which I imagine is where you're looking. They'll want to go to the network admin (/wp-admin/network/, then go to all sites from there, then find the site they want to edit and click "Dashboard" (which appears on hover).
I like to think of "My Sites" almost as favorites, and only add myself to a site when I'll be accessing it frequently, as it reduces the list I have to pick through.
Does that make sense and clear up your question? | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 5,
"tags": "multisite, admin, network admin"
} |
Facebook like button not showing up in iframe
I have tried what seems like every plugin to add the facebook like button to my site, but none of them are displaying on the page.
I am trying to use the iframe method to avoid having to create an app id to use the XFBML method. The iframe gets created in the right spot, but nothing is showing on the page.
Can anyone recommend a plugin that is currently working? I'm only interested in adding a Like button, I don't need other social sharing, but at this point, I'm willing to use whatever works! | For the most reliable results, you need to create and App at FB. Try < | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -2,
"tags": "plugin recommendation, facebook"
} |
wp_list_categories() Exclude All Categories Except One
Is there a way to exclude all categories except one? I want to show a category and it's sub-categories as a dropdown menu, but the admin might add more subcategories to it so I don't want to limit what they can put in there by just including unique ID's.
So I want to exclude all categories except 1 and it's subcategories. Is this possible with wp_list_categories()? | Try the `exclude` parameter in the `wp_list_categories`. That should remove the selected categories and their descendants.
**EDIT:** Must be getting late; this almost the opposite of what you wanted. To only include one category term in a drop-down menu (and all of its descendants), you can use `child_of`. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "posts, menus, filters, categories"
} |
How to prevent a page from being linked in the menu/crossbar
I apologize if the question is confusing. Let me explain:
I'm running a modified version of Twentyten and I've been doing the parent/child thing with my pages, which show up on the horizontal menu that I like to call the crossbar. However, I want to add pages that are not linked to from there, only from a sidebar widget.
Unfortunately, I am not at all fluent when it comes to PHP...I've been trying to learn. Does anyone understand what I'm trying to do/have a solution?
EDIT: I ended up just making a seperate html document that uses the stylesheet and linked to it. Is there an outstanding reason NOT to do this? | No php or extra page template necessary. See < and add/remove pages from the main menu and make a new sidebar menu. Or keep the page out of the main menu and add a simple href link to it in the sidebar. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "links"
} |
How to redirect a link to a new link?
I am about to change the slug for my page's permalink. Since I dont want to loose the traffic, i would like to redirect the visitors to the new more SEo friendly link.
Can I achieve this with the mod_rewrite? (I use Apache on Ubuntu)
Or any other easier alternative? (I prefer not using any plugin if possible)
Many Thanks, | Go with the easiest alternative of all: _do nothing_.
No, really: WordPress itself handles redirects for renamed Post Titles.
### Edit
Apparently, the retention of `_wp_old_slug` only happens for _non-hierarchical_ objects.
So, since Pages are hierarchical, they don't get to enjoy the auto-magic slug redirection.
Therefore, for static Pages or other hierarchical post objects, I would recommend using a 301 Redirect Plugin. There are several to choose from. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "url rewriting, redirect, apache"
} |
How to make tags show up in search results?
Im looking for a way to make tags a searchable object. To clarify, Im NOT trying to make the search engine search posts by looking at its tags, but I want tags to show up in the results just like a post. any help would be much apreciated | You'd have to do some modification to the generated SQL query via filters: `posts_search`, `posts_join`, `posts_where`.
Or you can just use the plugin Search Everything. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "taxonomy, search, tags"
} |
iPad WordPress theme?
I want to convert one HTML5/CSS3 theme in WP
This theme is build for iPads, now my question is is that possible to convert it? If yes then how? I mean should i create each different page template (ex. dashboard, calender etc..)
I just want to conform it before start that how should i need to understand before start it? | It definitely is possible, and you should really read the WordPress Codex before diving in, and read it in-depth. It's very well documented and usually a simple Google search will bring up answers for many of your questions.
The WordPress Codex will explain everything for you, especially this page for your situation, regarding creating a theme. Pay attention to the template hierarchy as well to be able to customize certain pages without much work.
The Codex also has a Where to Start page that can be of tremendous use.
You can also check out other questions tagged with `<theme-development>` for many common questions that WP developers have.
All I can suggest is read, read, read!
**Edit:** This page is also a good read to begin. :)
Hope this helps! | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "theme development, themes"
} |
How to prevent URL-modification when page title contains digits only?
When I create a page whose title contains only digits - wordpress adds '-2' to the url, like it does in cases, where there is a page with the same name already existing. However this is not the case here.
Example: If I create a page titled `909303`, the url will be: `../909303-2/`
I want it to be `../909303/`. How do I do that conveniently? | well.. it is not exactly the case, but in a way, it is . every page has actually "2" names , one is the name you give and one is the ID, which is the number. If you will give a "name" which is a "number" - it might override another entity (Can be a post, page , attachment, or even a draft) with the same ID. that would result in multiple errors and 404 , depending on your permalink structure.
SO , it is not such a good idea to do that, but if you really want to go with it first try to change your permalink structure and if that does not work, you will need to hook the sanitize_title() - but I will still advise to avoid such a practice.
( read here for more: < \- it is an old post from previous wordpress releases - , but maybe will let you understand WHY it is doing what it does.) | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "url rewriting, urls, title, paths"
} |
Is it possible to have one page with multiple items, or 2 blogs on a site?
I have a Page on my site that I use as a Blog.
And then there's another page that I'd like to add a few different posts to. It's not really a blog, it's a list of projects, and each one will have about 300 words of description.
I'd like users to be able to pick which project they want to view. So this could work as either a blog, or as a drop-down menu from the menu item 'other projects', or maybe in another way.
\-- Since I already have a blog on the site, is it possible to add another blog under another menu item?
\-- Or is there another way to accomplish the objective, such as making 'other projects' a drop-down menu?
The current blog is here: <
And the page I'd like to list projects on is here: < | It's absolutely possible on the same WordPress install.
How I do it, is I generally reserve the 'posts' sections for the site's news, and make a Custom Post Type for other things, such as your projects list.
Have a look at the codex for custom post types, and the template hierarchy
To separate the blog posts from your projects custom post type, simple add something like this is the appropriate template file:
query_posts( 'post_type=projects' ); // For projects
Or
query_posts( 'post_type=post' ); // For posts
query_posts works if you're using the main query.
* * *
Another solution, if you have no extra data to keep about projects, is to simply store your projects in 'posts' as well, and associate a category to them.
query_posts( 'post_type=post&cat=5' ); //EX if category id 5 = projects category | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "customization"
} |
How do I install more than one WordPress blog on EC2?
I created an EC2 instance and installed WordPress inside `/var/www/html/blog/`. I'm running Amazon Linux with Apache.
Assuming I want to create another blog. Do I create another directory and install WP as per the first attempt? Or can I run two blogs from the same installation? | Unless EC2 is much different than other servers, you should be able to install another WordPress installation under another directory.
For instance, you could have `/var/www/html/blog/` with WordPress installed and `/var/www/html/blog/wordpress` with another WordPress install.
You can either use a separate database or use the same one as the other install, but you would need a unique table prefix set in the wp-config.php.
You can read more about multiple installs here:
<
I've never used EC2, but I would assume it would work very similar to any other server. If not, you may want to reach out to their support to see what the differences are. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "installation"
} |
Change div background acording to the selected category
I'm coding a graphic menu that consist in five divs with a background each. On mouseover the background changes and the child div disappears. On click, each one works like a link to the correspondent category. I want to apply some changes to the clicked div, so I was wonder if there is some function in wordpress to get the selected category. So I can check for It and in function of wich category is selected apply the changes to the correspondent div.
Thanks in advance. | If you use `wp_list_categories` (see Codex), it automatically adds the classes `cat-item`,`cat-item-{ID}` and (to the current category being viewed) `current-cat`. (It also adds `current-cat-parent` to the parent of the current category).
This should be enough to style any particular category a certain way, and style the current category a particlar way.
However, you can obtain the current category being viewed by, in your category template file, using:
$term = get_queried_object();
The current category's slug is given by `$term->slug`. This would allow you to add a certain styling to the current category (the exact details of how to do that would depend on how you were displaying the category links). | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "categories, functions, menus"
} |
What is the "icon" parameter in wp_get_attachment_image_src used for?
On the reference page for `wp_get_attachment_image_src`, there is a parameter called `icon` and it only says:
$icon - (bool) (optional) Use a media icon to represent the attachment.
Default: false
What is this used for and how does it affect the returned value? | It's a icon with which to display the attachment. If it isn't set, it uses the default icon. The exception here is for **images** : the returned values always refer to the thumbnail (of size set in the arguments of `wp_get_attachment_image_src`). Icons are always shown at their original size.
If the attachment was an audio file, it would use the audio icon, unless otherwise specified using the `icon` argument. See the 'Change Icon Directory' section of the link you gave in the question. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 2,
"tags": "functions, attachments"
} |
Divert traffic when site down
Any bright ideas on how to fallback to an HTML page "Website Offline" when the main box holding the Wordpress multi-site is down?
Real scenario; fully operational SAAS built on cloud vps. Cloud VPS has issues, emergency rebuild of SAN, our box goes offline. Is there a way to direct traffic to a specific page in the event of melt-down? | If you are running Nginx, it is easier to implement a similar scenario with an isolated server running Nginx alone.
In Nginx, the HttpUpstreamModule can be configured to divert the traffic to a completely different domain running on a different server. For example, if your site is yoursite.com, it is easy to divert the visitors to status.yoursite.com when the main site (running on a different server) is down for some reason. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "offline"
} |
Page not appearing under its Parent
If I add a page with the name 'Bottle Project' and give it the parent 'Other Projects', the page appears at < \-- so that looks right.
...but if I mouse over the menu item 'Other projects' at < , the item 'Bottle Project' doesn't appear. And if I click on 'Other projects', then it doesn't appear either.
How can I make it so users can navigate to 'Bottle Project' from the menus on my site -- specifically that 'Bottle Project' appears under the menu item 'Other projects'...? | If you go to appearance->Menus, you should be able to fully customize your menu, assuming your theme is even decent. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "pages"
} |
Removing posts by sql
Often i build a site and we have test posts. I was wondering if there's a way via sql to drop all the blog posts with a simple sql query.
Obviously, I would have backed up my previous database before truncating these tables.
I would like to leave the pages alone if possible. | You're probably better off doing this with wordpress functions and adding a button which would delete all posts (or even having a shortcode that, when loaded, would do it). The reason I recommend doing this instead of SQL directly is that `wp_delete_post()` will take all the associated meta with it, which saves you having to do complicated SQL. You can combine this with `WP_Query` to get posts given a complex set of desired parameters and then loop through them to remove them. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "sql"
} |
How to make blog posts have their own urls?
When I post a blog post, the blog post doesn't appear with a separate url -- it just appears under < and there's no button to edit the url when I'm on the Edit Post page.
How do i make blog posts have their own urls? | Set Permalinks (in settings) to /%postname%/, you set the blog location in settings->general, not in your permalinks. Permalinks builds on the Settings->General URL | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "posts"
} |
W3 total cach and theme changes
i have read that i have to weight with w3 total cache until my blog design is complete. But to be honest, it will never be finished. I'm constantly developing new stuff.
How will this affect my site if i chose to use w3 total cache? Can i reset the cache every time i make changes to the theme? and how does this plug in deal with comments?
Hope some one have a simple answer for me :) | You can turn it on and clear the cache whenever you like, it even adds a button to the admin bar specifically to purge all caches. I say implement it as early as possible so that you don't have to rewrite any code in case there's an odd conflict with it or anything. You can turn off comment caching if memory serves right, activate the plugin and just read through the options, it does a good job of explaining everything. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "theme development, plugin w3 total cache"
} |
How to have Wordpress send a user confirmation/validation email on signup
I have a WP 3.3 installed and running great. My client would like to confirm a valid email address by sending the user a confirmation email containing a link to "confirm". I have played around with Pie Register a little bit but cannot get it to send emails like it says it can.
Are there other plugins or tools out there capable of the same thing? I don't think its a huge deal but the client won't budge on it.
Also the site sends other emails just fine.
ideas? | This plugin does exactly what you need - Pie Register
From Wordpress.org Plugin Directory:
> Email Validation Hate fake emails? Make sure your users are not registering with invalid email accounts by forcing them to click a validation link that's sent out with their registration email. This sets there username to a random generated string (something like: 'unverified__h439herld3') so they can't login until they hit that validation link which will put their real username back in place allowing them to login as per usual. Unverified registrations have a defined grace period that will automatically delete an unverified account after a specified period of time, so you don't get clogged up with those fakies. (Manage under Users > Unverified Users) | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 5,
"tags": "plugins, user registration"
} |
Ordering system through Wordpress
I don't use Wordpress much, but I was wondering if anyone knew whether this would be possible in WP. Basically I want an online ordering system, so just like a normal cart where you can put things in your basket etc, except, instead of paying for it you just place an order and it generates an order email to me?
Jonny? | That is very much possible. If you want some inspiration on that, look at plugins like WooCommerce, 66Cart, and WP-Ecommerce (to name just a few). You'll want to implement it through custom post types and it will probably take a decent bit of coding to build from the ground up, but you can definitely do it. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "order"
} |
Can I decide what categories show on my posts page?
Forgive me if this is too basic of a question...
I am using Twenty Eleven and am wanting to only allow my "news" category show on the front page, excluding all other categories.
How can I do this? | $args = array(
//post basics
'post_status' => 'publish',
'post_type' => 'post',
'posts_per_page' => 10
//order
'orderby' => 'date',
'order' => 'desc',
//category query
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'news' //make this the slug of the category you want to use
)
)
);
$posts = new WP_Query( $args );
`$posts` will now contain 10 posts from news. You can tweak this as you see fit, it's pretty simple to do, and `WP_Query` is INCREDIBLY powerful.
Docs: `WP_Query` | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "custom post types, theme twenty eleven"
} |
Buddypress User Settings template location?
I am trying to customize my BuddyPress layout and I can't find where to edit the user profile page layout.
EG: /members/username-nice/settings/
This is just the page where you can change your password. The header and footer appear as they should, and there's a form to change your password, but I can't find the template file where this is coming from.
I've copied all the files from from /wp-content/plugins/buddypress/bp-themes/bp-default/members/single over to my theme. There is ** NO ** settings folder within this folder.
I was able to edit all the other profile templates (activity, profile, etc) because these templates were there in the theme.
1) where/do these files exist?
2) is this content being generated by WP and not BP? If so, which default template is is falling back on? And how do I edit around it? | SOLVED ....
The settings tab is rendered through the template
members/single/plugins.php | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "themes, buddypress"
} |
How can I move (or create another) publish button?
How do I create a "publish" button to put in a custom metabox?
Or if you can point me to the code that creates the current publish box, that'd help me out.
-attempting to simplify my custom post type- | ### Dig in Core
All admin UI pages use a core function for a reason:
submit_button( $text = NULL, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = NULL );
There's also `get_submit_button()` in case you want to return instead of print the button. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "custom post types, php, metabox, publish"
} |
Which plugin will let me relate one post to another?
Here is what I am trying to do: I am trying to allow users to create a post under 'category-A'. Then Create a post under 'category-B' which is linked to the post under 'category-A'
For example:
category-A Post Title
Post content...
link to additional post under category-B | If you want to generate those connections automatically, based on a certain algorithm, then YARPP would probably do the job nicely.
If you want control over each connection, then you might want to take a look at Posts 2 Posts. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "posts, plugin recommendation"
} |
Which plugin will let me decide what users have access to on their side bar in wp-admin?
I want to customize the editor role so that they only have access to 'pages, posts, comments, profiles'. | I've tried quite a few different ones, I always come back to the one that works best: Justin Tadlock's Members Plugin.
It's very easy to use right out of the box. It has predefined roles, or you can create your own user roles with about every option available in WordPress. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugins, admin"
} |
How to override existing plugin action with new action
I'm using a plugin. It has an action like this.
add_action('publish_post', 'old_action');
function old_action($pid) {
"code goes here"
}
}
I'm writing a module for this plugin. So i need to override that old action function with my new action function.
This is my new function.
function new_action($pid) {
"code goes here"
}
}
I want to replace that old_action function with my new_action function using hooks. Can anyone help me?
Thanks | You can use the `remove_action()` function, like this:
remove_action('publish_post', 'old_action');
add_action('publish_post', 'new_action');
It's important to note that if the old_action was added with a priority parameter, you must add that to the `remove_action` call, otherwise it will fail to remove it. There are other implications if the old_action was added within a class. See here for more info. | stackexchange-wordpress | {
"answer_score": 42,
"question_score": 23,
"tags": "plugin development, actions"
} |
Finding the index page using the admin panel of wordpress
I am helping out a non profit and they wanted some help in modifying the home page of their site .I looked around the admin area but I couldnt not find the index page anywhere so that I could make the changes.
Where should I be looking and if I cant find it from the admin page ,what other ways can I go about finding it. | Take a look at WordPress' Template Hierachy. You will need to find which theme is active, and investigate the theme files.
Also check Settings -> Reading to see if a static page is being set as the homepage. If it is not it should be one of the following template files:
* index.php
* home.php
* front-page.php
Hope that helps! | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "homepage"
} |
Managing database tables in WordPress multisite
I'm working on plugin that creates and stores some data in database table (using global $wpdb->base_prefix). In WordPress multisite I want sub-website owners to have access only to data that they've created. What is the best way to handle this? Should I create new table for each sub-website, or add "blog_id" column to table and check it every time?
Thanks for help. | use the API, the functions of WordPress for save data and check before, it is an Multisite install; thats all. The first example is only for check, is the activated as network wide.
// if is active in network of multisite
if ( is_multisite() && isset($_GET['networkwide']) && 1 == $_GET['networkwide'] ) {
add_site_option( 'my_settings_id', $data );
} else {
add_option( 'my_settings_id', $data );
}
The follow example check for mutlisite and if the plugin active in complete network.
if ( is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) )
$values = get_site_option( 'my_settings_id' );
else
$values = get_option( 'my_settings_id' );
Also you can check this in each blog and save the data in the tables of each blog.
*the examples was from this post | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugins, multisite, database"
} |
How to convert hits from Top 10 plugin to WordPress Popular Posts?
How can I import/convert hits from the plugin top 10 to wordpress popular posts plugin? | # Short Answer
You don't.
# Long Answer
These two plugins are fundamentally different. Popular Posts stores views in a custom field with each post. Top 10 creates a new table in the database and stores views there.
So you'll need to look for the `wp_top-ten` table in your database. It should have these fields:
* `postnumber`
* `cntaccess`
`postnumber` is the ID of your post and `cntaccess` is the number of views it has. You can move this into the `pvc_views` custom field for the post to migrate the data.
You'll likely need to script this in SQL; that's an exercise I leave to you. In reality, you'd be better served just switching to the new plugin and starting your counter from scratch. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": -2,
"tags": "plugins"
} |
How to hook into wordpress admin upload iframe?
I have written a plugin which lets the user upload file attachments for using WordPress as a download site.
So I have added a meta box which shows the user the files he has uploaded for every post. Everything is working fine until I wanted to make it so that if a user uploads file using the built-in upload manager and then closes the ThickBox a function of mine is invoked to update that meta box for new files.
In simple words, I want to be able to listen on the ThickBox close event. That's it. | When the thickbox gets closed it triggers 'tb_unload' (in earlier WordPress version it was just 'unload' (not sure though) )
So you can do something like:
$(window).bind('tb_unload', function() {
//do stuff
}); | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 2,
"tags": "uploads, thickbox, iframe"
} |
Listing parent section in search results
I'm building a search results template and want to display the parent section of the website for each result returned. so at the bottom of each search result excerpt it'd say "Found in [section] | Reacd More"
Something like: | For your custom post types and your blog, you can use get_post_type(). For your About parent page, if the pages only go one level deep, you can check `$post->post_parent` to see if it's the about page. Otherwise, you can use get_post_ancestors() and check that array to see if your About page is in it! | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "search, template tags"
} |
possible to combine sites that have lots of content, into multisite?
i run 3 wordpress sites.
they are each on different installations.
i don't really want to combine them right now because i'm not very proficient technically, with wordpress, but i might want to combine them at a later date, to make it easier to administer.
but i want to check in case it's better to set it up now, because i'm just setting one wordpress site up -- maybe it's better to do this now.
so my question is: at a later date, when i have 3 sites running, each with lots of content on, can i combine them at that time?
or does setting up multisite involve starting things from scratch? | > at a later date, when i have 3 sites running, each with lots of content on, can i combine them at that time?
Yes, you can. I've found the easiest way to do so is to use the Export/Import feature, but it really depends on the site, and sometimes you have to get creative. Assuming these will be easy, what you would do is setup a multisite install, create new sites within this for each of your 3 solo sites, export XML files from your solo sites, then import those XML files respectively into the new sites in your Multisite network.
Does that make sense? | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "multisite"
} |
Recent posts script mess up blog posts
I use this script to display recent posts:
<ul>
<?php query_posts('showposts=5'); ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<li><?php the_content_limit(250); ?></li>
<?php endwhile;?>
</ul>
I put this in the header.php. It does the job, but also all other posts and pages gets messed up. When I try to load any ordinary page (page.php) I get only content from two blog posts and similar problems. It is not the issue with the_content_limit. I also tried excerpt - and its the same.
Any ideas how to avoid the problem but still have recent posts? | Add this after your endwhile
<?php wp_reset_query() ?>
Regards | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "posts"
} |
Is it possible to make the heading on a page different text to the text of the menu item?
Is it possible to make the heading on a page different text to the text of the menu item?
I have a page with a very long title and I'd like to make the clickable menu text shorter.
Site is here: < | Go into Apparences -> Menu -> (find the header menu) -> Click the page you want to change, when the options open, just change the heading label to whatever you want.
Regards | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "menus"
} |
How to disable image thumbnails from media manager but not post media uploader?
I'm trying to use the script below in order to disable automatic thumbnail generation when images are uploaded via the media manager.
I'd like to leave the thumbnail option intact when an image is uploaded directly to a post, because that uploader gives the user the ability to specify the image size.
The problem is that it disables thumbnail options in both places. I want to allow thumbs everywhere except the media manager upload.
if ($pagenow == 'media-new.php' || $pagenow == 'async-upload.php'){
add_filter('intermediate_image_sizes_advanced','disable_thumbnails');
}
function disable_thumbnails($arr_sizes){
if(!stristr($_POST['type'], 'image')){
return array();
}
return $arr_sizes;
} | Not sure if I've understand this correctly but you should be able to check which tab is currently open by looking at `$_GET['tab']`
* upload new tab = `type`
* from url = `type_url`
* gallery = `gallery`
* media library = `library`
So you could wrap your code inside
if ( $_GET['tab'] != 'type' ) // do stuff | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "uploads"
} |
What's the best action to use when you want to do something only once per theme setup?
I'm writing a theme which has it's own set of database tables.
I'm wondering what is the best action for me to use when I want my install function to be invoked only once when the theme is activated for the first time?
I know there is a `setup_theme` action, but not sure if that's the one I should use. | You should read this: Activation/Deactivation hook for wordpress theme | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 2,
"tags": "theme development, actions, customization"
} |
Where in functions.php to add this code so thumbnail images display?
Thumbnail images are not displaying by blog excerpts on my blog at < \-- I found some code that I think I might need to add to functions.php to make this happen, and if I do need to do this, I'd like to know where in functions.php I should add the code...
In my twentyeleven files, in functions.php, it says:
// This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images add_theme_support( 'post-thumbnails' );
But the following code isn't in functions.php:
if ( function_exists( 'add_theme_support' ) ) { add_theme_support( 'post-thumbnails' ); }
If my understanding of this: < is correct, then maybe I have to add that code into functions.php to make thumbnails appear on my blog ...?
Where in the file functions.php would I add the code?
And I presume curly brackets } signify the end of lines of code -- so I guess I'd paste the code after a curly bracket somewhere? | Post thumbnails are enabled in the twenty-eleven theme by default. If it's not working either you have a plugin conflict, or someone has edited the functions.php file. Here is the section of the twenty-eleven functions.php file that should enable the post thumbnails:
add_theme_support( 'post-thumbnails' );
The code needs to be inside the `function twentyeleven_setup()` function to work. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "post thumbnails"
} |
Using Ajax call in jQuery doesn't work in widget
So I'm in the midst of creating a new conversion widget and I'm having some trouble getting the Ajax call to work in my widget. (works perfectly outside of WordPress).
The problem at the moment is that it outputs the whole homepage in the #results div rather than just the results figure: | If your AJAX Url is conversion.php it will most likely point to yourdomain.com/conversion.php. Is your file in that location?
Looks like not, and I guess you don't have a 404.php, and in that case your request gets directed to your index.php, that's why you get the contents of your homepage.
If your file is in your theme folder, you would have to change the URL to wp-content/themes/yourtheme/conversion.php
But the much **easier and recommended** way is to use WP built in AJAX functionality: See this codex page for more informations:
EDIT: Most posts on this topic are for AJAX on the WordPress backend but it's possible to use it on the frontend as well. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 2,
"tags": "plugin development, widgets, jquery, ajax"
} |
Wordpress comment reply link image
I'm currently setting up comments for a Wordpress theme I'm created, I have just successfully created **nested comments** but I'm having issues removing the word ' **reply** ' from the reply button in order to use an image via the css.
The code I'm using at the moment for the reply link is as follows:
<?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
I need the word 'reply' to completely disappear and just rely on my css button which is as follows:
ol.commentlist li div.reply { width:104px;height:35px;background-image:url(images/comment_reply.png); }
ol.commentlist li div.reply:hover { background-image:url(images/comment_reply_rl.png);}
ol.commentlist li div.reply a { float:left;width:104px;height:35px;background-image:url(images/comment_reply.png); }
All help will be massively appreciated.
Thanks in advance! | try:
<?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth'], 'reply_text' => ''))) ?> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "comments"
} |
Solution for Wordpress URL structure changes and 301 redirects?
After a major site review, we've created a new link and category structure to better accommodate URLs and content for the long-term. While we roll out the change, we need to avoid broken links and SEO issues because our category structure is changing.
While best practice is to implement a 301 redirect, is there a solution to automatically redirect all previous categories? Or at least handle it in an efficient way within Wordpress Admin?
**Why this isn't a duplicate:** This is focused on category changes, not just a few changed URLs.
Thanks. | For a large number of redirects, using your .htaccess file is the way to go (assuming you're using apache). If you aren't doing an unreasonable number of redirects and want control within WordPress' Admin, the aptly named Simple 301 Redirects is a great option. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "redirect"
} |
Auto Populate Excerpt Field
How do auto populate the excerpt field with the first 15 words of the post content? I found this snippet:
function wps_excerpt_content( $content ) {
$content = "YOUR EXCERPT HERE";
return $content;
}
add_filter( 'default_excerpt', 'wps_excerpt_content' );
But I don't know how to modify it with what I need. Any help? | How about using the `excerpt_length` filter?
function my_excerpt_lenght( $length ) {
return 15;
}
add_filter( 'excerpt_length', 'my_excerpt_lenght', 999 ); | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 1,
"tags": "excerpt"
} |
Widget Screen Locked
Within the Wordpress dashboard, the widget screen is locked and it won't allow me to drag new widgets within the sidebars - or remove any that's there. I've seen suggestions to toggle the 'screen options' from that page, but there that button is locked as well within that page in the dashboard. I've tried deactivated plugins and installing a 'cache clear' and still nothing.
**Anyone have any suggestions as to why this is happening?** | sounds like something is breaking your javascript. Install/Open Firebug (if using firefox) and check the console for JavaScript errors then debug from there. It's probably a plugin loading some conflicting JS. The other thing I've seen do this is loading jQuery from Google CDN in the backend. So if your theme is using the fairly common snippet to de-register jQuery then re-register it from google CDN it should only do so on the frontend. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugins, dashboard"
} |
Moving to another server database connection error
I have some issues when I try to move it on other server. This are the steps:
1. I go into my actual database through phpmyadmin, export the database.
2. I copy the entire folder of my wordpress website from FTP, and paste it through FTP on my new host.
3. I modify the wp-config.php with my new database details.
4. Now I enter on my new host phpmyadmin I import the database that was created from my old host.
And now when I enter on my website, I receive: **Error establishing a database connection** I really need some help with this. Thanks! | **Error establishing a database connection** means a bad password, DB user, DB name or server location (usually localhost) in wp-config.php. Simple as that. Check and check again.
Editing wp-config.php « WordPress Codex | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "database, errors, installation"
} |
Beta Versioning of Plugins
When I'm writing a fix to some bugs, I often increment the version and send it to the bug finder to see if my fix works. If I have `1.2.5` and I want to create a beta that will become redundant once I commit my code, should I use `1.2.5-beta` or `1.2.6-beta`? My concern is that `1.2.6` < `1.2.6-beta` so that the string comparison may favour the beta and the bug finder would not get a notification of the stable version being released.
EDIT:
If the string is compared absolutely without taking into account the release type, you could use `1.2.5-fix` and then `1.2.6`. The problem is also outlined at < | If your current plugin version is `1.2.5`, and you have a beta version for the next version, it should be called `1.2.6-beta`. Your user can install it, and when the real `1.2.6` version is released on the repository, WordPress will notify the user on the Plugins page and let him update.
WordPress uses a PHP function called `version_compare` to compare version numbers for this purpose. When comparing version numbers, WordPress will recognize them like this:
`1.2.5` < `1.2.6-beta` < `1.2.6`
I've tested this out with a plugin of my own in the repository, currently at version `0.45.11`. I changed the version number of the plugin on my own site to `0.45.11-beta`, and WordPress let me update to `0.45.11` from the Plugins admin page. | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 6,
"tags": "plugins, wordpress version"
} |
Get the bare URL for an attachment
I'm trying to get the link to the thumbnail size of an attachment image.
I tried this:
wp_get_attachment_link( $img_id, 'thumbnail' );
but it returns the actual HTML for the image wrapped in a link. I want just the bare URL directly to that size image.
Does Wordpress have a different function I should be using, or do I have to extract it from the HTML returned by `wp_get_attachment_link`? | What about using `wp_get_attachment_image_src`?
Using `wp_get_attachment_image_src`:
$src = wp_get_attachment_image_src( $img_id, 'thumbnail' );
$src = $src[0]; // Grabs only the URL ($src[1] = width of image, $src[2] = height of image) | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "attachments, urls, images"
} |
How can I add a featured image to a page?
I need the ability to add an image to a page, like a featured image. How can I do that, and how do I get the featured image to display in page.php? It can be a plugin if what I am asking can't be done within Wordpress itself out of the box. | Eek! A 33% acceptance rate isn't really going to do you any favours but lucky for you Wordpress' in-built post-thumbnail featured image functionality works for posts, custom post types and pages too.
Add the following line into your theme functions.php file:
add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
Then in your page.php file and I stress that **this must be used within the page loop** (not outside of it) the following function will show your featured image on a page if it has one assigned to it.
the_post_thumbnail()
Adding a featured image to a page is the same process as adding one to a post. On the page editing screen you will see a metabox with a link that says, ' _Set a featured image_ ' click that and you're good to go. No plugins required. | stackexchange-wordpress | {
"answer_score": 12,
"question_score": 8,
"tags": "plugins"
} |
What is the easiest and cheapest way to sell a download on my website?
I know that there are several e-commerce plugins, like JigoShop, WP E Commerce, and Woo Commerce.
I also know there area lot of payment gateways like authorize.net and Paypal.
However, if I have a really simple piece of software that I want to sell on my website, a single file download, what is the easiest and cheapest way to accomplish this? Can I use one of the WP plugins without having to pay for PayFlow Pro to allow the download? | Go for Woocommerce! In my opinion the best and most powerful free ecommerce plugin. They offer also features for download products | stackexchange-wordpress | {
"answer_score": 1,
"question_score": -2,
"tags": "plugin recommendation, e commerce, paypal"
} |
Creating a sub folder inside a root installation?
Currently I have a root wordpress installation at www.mysite.com.
I've added a new folder /store in the root and added in a blank html. However, I can't seem to access the folder by going to www.mysite.com/store.
Any idea how I can do this?
* ** _Update_ ***
I realised when I'd encountered this issue there was no .htaccess file.
It seems like after I've added the .htaccess with a rewriterule to index.php, it all works.
How does wordpress exactly do it's rewrites without a .htaccess in the first place? | I don't know why you couldn't access the folder. Maybe you wanna check your `.htaccess` file first. The default rewrite conditions for apache created by WordPress should include the following two lines, which prevents the redirecting to `index.php` if a physical file or directory is found.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
You could force a redirect with another rewrite condition for your directory, but this should not be necessary.
E.g.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/store/(.*)$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]
</IfModule> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "installation"
} |
How can I set the first link in my nav menu to simply be a drop-down to some other pages
I want to have a set of ~3 pages in a subdirectory called "about"
example.com/about/history
example.com/about/program
example.com/about/coaches
I don't want any `about/index.html` page, I just want "about" to be the label of the drop-down menu. The pages will be just regular WordPress pages.
I don't need help writing the HTML/CSS, I just need to know what files to edit and how to set it up in the WP admin area.
Hope my first post makes sense. This is my first WordPress project. Thanks in advance. | Use the wordpress Menus under Appereance -> Menu and wp_nav_menu instead of wp_list_pages in your theme. If your theme is recent, changes are that you are using it now.
Under Appereance -> Menu
* Create a menu, label il "Site menu"
* Create a **custom link** About, and assign it # as destination link
* Drag and drop your about pages after About
See this page of the codex on the menus | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "navigation, hierarchical, menus"
} |
Fully-featured forum plugin
I'm looking for a plugin recommendation.
I'm currently using bbPress to add a forums area to our website.
However, it has been deemed "disappointing" in terms of functionality.
Are there any forum plugins which have the following features?
* Easy image attachment (i.e. not like the bbPress GD add-on which uses the Media Library)
* Unread threads / mark as unread button
* Private messaging
* Quoting
* Rich text editor for new topics/replies
Thanks in advance, | SimplePress currently is the best-featured forum plugin for WordPress. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 4,
"tags": "plugin recommendation"
} |
How can I make a wp site in a mobile application?
Which are the ways and how is possible a wp site become an iphone, ipad, android and a blackberry application(not a wp mobile theme)? | WordPress is a set of PHP scripts running on a web server. So your application needs a web server, a data base and PHP. I don’t think this is possible on all of those platforms. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 2,
"tags": "mobile, iphone, third party applications, android"
} |
How to execute a plugin on a single page only?
A few basic questions to accelerate my wordpress plugin development start. I'd like to develop a wordpress plugin that adds some javascript and css to a specific page. What filters or actions should be used? How to restrict execution of a plugin to a single (known) page? How can a plugin add some content to a page? | WordPress has a built-in function called wp_enqueue_script() which will allow a certain piece of JavaScript to be included in a page. If you'd just like to see that script on a particular page, you can conditionally call it from the theme file. For example:
<?php if (is_page('home')) {
wp_register_script('custom_script', get_template_directory_uri() .
'/js/custom_script.js');
wp_enqueue_script('custom_script');
} ?>
You can do something similar with wp_register_style() and wp_enqueue_style() to include the CSS as well. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "plugins, css, javascript"
} |
How set template for "custom post type" individual post
For example, I have post named "My book number 1", that is in "Book" custom post type group. And is another post named "My book number 2", that is too in "Book" custom post type.
Question: How I can set specific design template for "My book number 1" post? | You can just create a template...call it something like book-one-template.php, the first line after `<?php` will need to be `/* Template Name: Book One Template */`. Then, using that and the custom-post-template plugin you can set that as the template for any post you like. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom post types, posts, customization"
} |
Simple plugins to post info about new blog entries?
I am looking for some plugins that would automatically post information about new blog entries (posts) to my facebook/google+ pages.
But - simple search through plugins listing shows that such plugins don't exists, or are rare. Most of the plugins offer content sharing the other way (i.e. display entries from facebook/google+ in your wordpress blog), or simply provide a way to have "Like"/"+1" buttons.
Can anyone of you suggest a simple plugin to send notifications about new blog posts? | For Facebook: <
For Twitter: <
For Google+ <
The twitter and facebook plugins will autopost from your site to each service. The G+ plugin is new, and still under development. I don't know that there is any plugin yet that pushes notifications to G+.... | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "facebook, notifications, google plus"
} |
Force category-slug.php to show page, even if it doesn't exist
I have a custom query in category-slug.php, which works fine unless the category doesn't have that number of pages itself.
If the category only has 5 pages of posts, but the query I put in has 7, it'll show 404 for pages 6 and 7.
Pretty sure the reason for this is that category-slug.php checks to see if there is a page for that category before it gets to the query I have in the file.
Is there a way for me to force it to run the page instead of showing a 404? | I've not tested this, but adding an action after `parse_query` or `wp` which checks if the current request `is_category()`, and then setting the is_404 property of the global `$wp_query` to false might set you off in the right direction. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "categories, pagination"
} |
Post formats "audio" and "video" only showing in index.php
I have files in my theme called `single-audio.php` and `single video.php`, but when I click on an audio post-format or video post-format wordpress uses the `index.php` instead of my `single-audio.php` or `single-video.php` files. Any ideas? | There is a huge difference between Post Formats and Post Types. I am assuming you are using post formats, which do not have a default template file for you to use.
What you can do though is use `has_post_format()` to see if the post has the format you are using, and if it does, use `get_template_part()` to get a specific template file that you created to display there.
For example:
// If this post has a post format of 'video'
if( has_post_format( 'video', $post->ID ) ) {
// Then get and display 'single-video.php'
get_template_part( 'single', 'video' );
} | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 4,
"tags": "custom post types, page template"
} |
ecommerce plugin with "buy for a friend" feature
Does anyone know about any ecommerce plugin with a feature to send the purchase to a friend?
I need that feature but I cannot find any around. I would appreciate any information on this. | I found one plugin called Certificate gift, basically does the job | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugin recommendation, e commerce"
} |
Change the post date from a meta box
I'm having a problem with updating the post_date in a custom function I've written.
I'm trying to change the "post_date" to my custom "meta_date" value.
Here is the function:
function cfc_reset_postdate( $data, $postarr ) {
// If it is our form has not been submitted, so we dont want to do anything
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if($data['post_type'] == 'scripture-memory') {
$date = get_post_meta( get_the_ID(), 'cfc_date', true );
$date = DateTime::createFromFormat('D - M j, Y', $date);
$date = $date->format('Y-m-d');
$data['post_date'] = $date;
return $data;
}
add_filter( 'wp_insert_post_data', 'cfc_reset_postdate', '10', 2);
I've tried linking it to all these filters but none seem to work...
It works, except I have to press the "Update" button twice to change the post_date to match my new meta date.
What am I doing wrong? | A Note: Actions and Filters are not really interchangeable: Filters typically must return the passed data or it's going to break something.
Building off of what m0r7if3r said, `wp_insert_post_data` is a filter, so you should be modifying the post's $data and returning it at the end of the function.
(Alternatively, you could global the variables you need to alter during an appropriate action, then change it.)
for a tutorial, first read: <
Then consider the following (I haven't tested this but it's based on your code):
function cfc_reset_postdate( $data ) {
$date = get_post_meta( get_the_ID(), 'cfc_date', true );
$date = DateTime::createFromFormat('D - M j, Y', $date);
$date = $date->format('Y-m-d');
$data['post_date'] = $date;
return $data;
}
add_filter( 'wp_insert_post_data', 'cfc_reset_postdate'); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "metabox, post meta, wp update post"
} |
Post editor is 89953px tall. How to fix?
Using a self-hosted install updated to 3.3.1, when I go to the edit post screen, the editor is set to a height of 89953px. When I view source, I see the following lines in the markup for the post editor:
<iframe id="content_ifr" src='javascript:""' frameborder="0" allowtransparency="true" title="Rich Text Area Press ALT F10 for toolbar. Press ALT 0 for help." style="width: 100%; height: 89953px; display: block; "></iframe>
I cannot figure out what is causing the editor's height to be set at 89953px. I have tried disabling all plugins and reverting to the default theme, using the 'Use Google Libraries' plugin and clearing all caches, to no avail. | Well, as it turns out, the "size of the post box" setting under Writing Settings had been changed to 5000 lines. Putting it back at a sane number has fixed the issue. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "admin, tinymce, editor"
} |
Is there a wordpress plugin enabling an autocomplete search box, then jump to page?
I have very little experience with WordPress. I am exploring it as a potential solution for our needs.
I would like to implement an autocomplete search box (a bit like jQuery's) where users could type, say, the name of an ingredient and jump automatically to that ingredient's page. We would fill the possible values of the search box ourselves.
Is there such a plugin for WordPress or should implement this myself via Javascript? If I need to implement this myself, are there any tips/code examples available? | You could use the autocompleter plugin. It does exactly what you describe: it autocompletes half-typed tags and categories.
You'd just need to tag your recipes with their ingredients. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "search, navigation, pages"
} |
Change permalink in wp-property
I have set default property page so in the property url it shows /lima-investments/property-name. But I want to remove /lima-investments from the url.
I want to change following url
<
to
<
Please help. | Used Custom permalink plugin and it worked. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "permalinks, urls"
} |
PNG with transparent background turns black when uploaded and resized
Steps to reproduce:
1. Create a PNG-8 with a transparent background.
2. Upload to WordPress 3.3.1.
3. View original PNG in any browser, Chrome, Firefox, IE, etc. Notice that it retains transparency as it should.
4. View a resized version of that PNG in any browser. Observe that the transparent portions of the PNG are now black.
Examples:
* Original uploaded image: <
* Resized version of the uploaded image: <
This occurs even with a clean install of WordPress 3.3.1 with no plugins activated. Any ideas on what might be causing this bug? I've been searching all over this forum, the WordPress support forums, and anywhere else Google can find. All I see out there are mentions of a NextGEN Gallery plugin bug and the infamous IE6 PNG transparency bug, neither of which appear to pertain to this problem.
Thanks in advance. | I'd try saving it as a PNG 24 first.
If that doesn't work have a look at these:
<
< | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 5,
"tags": "uploads, images"
} |
Show add_meta_box by selecting a specific category
In my plugin I want to display an add_meta_box under the WYSISWYG in the new post page, which is no problem and works fine. But the box should only appear when a specific category (example: category with id = 5) is selected, otherwise it is not visible.
How can this be achieved?
Edit as requested in the comments here is my jquery:
$script = "
<script type='text/javascript'>
jQuery(document).ready(function($) {
$('#metabox_sectionid').hide();
$('#in-category-".CATEGORY."').is(':checked') ? $('#metabox_sectionid').show() : $('#emetabox_sectionid').hide();
$('#in-category-".CATEGORY."').click(function() {
$('#metabox_sectionid').toggle(this.checked);
});
});
</script>";
echo $script;
BR & Thanks, mybecks | You could try this: get the ID's of the attached categories and wrap your add_meta_box function inside a simple test against your defined cat ID.
add_action('add_meta_boxes', 'is_in_cat_example');
function is_in_cat_example() {
global $post;
$category = '5'; // can be an array of ID's as well
if ( in_category( $category, $post ) ) {
add_meta_box(...);
}
} | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "plugin development, categories, metabox"
} |
WordPress Login redirection according to user role
In my application a user needs to 1stlogin and is then able to access the website.
There are 3 different user roles in use on my site
> 1. administrator
> 2. editor
> 3. contributor
>
User can login from
_No login from any theme template._
I have found this code, but it doesn't work
function my_login_redirect_contributors() {
if ( current_user_can('contributor') ){
return 'url-to-redirect-to';
}
}
add_filter('login_redirect', 'my_login_redirect_contributors');
* * *
_Note: I do not want to use plugin like Peter's Login Redirect. I want to achieve it by customizing wp core code with a filter._ | You're using the filter **wrong**. If you got more than one `@param`, then you have to state them when adding the filter.
function wpse40745_redirect_on_login( $redirect_to, isset( $_REQUEST['redirect_to'] ), $user )
{
# uncomment the following line if it's not working and replace $user->roles[0] with something that works
// echo '<pre>'; print_r( $user ); echo '</pre>'; exit;
if ( in_array( $user->roles[0], array( 'contributer', 'whatever_other_role ) ) )
return home_url();
return $redirect_to;
}
add_filter( 'login_redirect', 'wpse40745_redirect_on_login', 20, 3 ); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "login, user roles, user access"
} |
How do I embed youtube videos with https instead of http in the URL?
I'm running a site that only communicates over SSL/https so if I embed a youtube video using http I will get an error message saying the site is'nt fully secure. Is it possible to rewrite something so that WordPress accepts https and still auto embeds youtube links added to the content area? Cause now, when I try to embed a https youtube link, all that is shown is the URL, no movie.
**Update**
I've tried to add providers using this code in functions.php but it does nothing:
wp_oembed_add_provider(' ' );
wp_oembed_add_provider('# ' true);
wp_oembed_add_provider(' ' );
wp_oembed_add_provider('# ' true); | < has a working patch now.
Edit: Plugin code to do similar until patch gets in:
wp_oembed_add_provider('# ' true);
wp_oembed_add_provider(' ' false ); | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 8,
"tags": "embed, youtube"
} |
registration process with contact from 7?
It is possible to create registration process with contact from 7.
i want all the features of contact from 7 in my registration from.
my registration from is in popup on my site.
if possible with contact from 7 then tell me how or give me some other idea for registration process.
Thanks | Try using the plugin contact form 7 to Database Extension and then follow the directions at this post:
< | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "user registration, plugin contact form 7"
} |
Add "parent" class to parent menu items
Is there a good way to add a class of "parent" to list items that have children using wp_nav_menu?
I've found a couple of solutions online but non seem to have the desired effect. | This may not be the ideal solution, depending on what you need the class for, but you could add a "parent" class via JavaScript. The line below uses the jQuery `:has()` selector:
$('#nav-id').find('li:has(ul)').addClass('parent'); | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 2,
"tags": "menus"
} |
Is there a way to backdate posts?
Is there a way to backdate posts on WordPress?
The reason is that I am migrating content over from another site and want to keep their original publishing dates.
* * *
## Edit
The content is being migrated manually from a non-wordpress website | To manually edit publish date, click the Edit link in the Publish box when editing a post and set the date to whatever you'd like.
!enter image description here | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "posts"
} |
How to secure WordPress XMLRPC?
XMLRPC is great for remote publishing to WordPress, but there has been many security issues attributed to it. How do it make it more secure? More specifically, only user from the intranet will be publishing through XMLRPC. WP is currently running on Lighttpd and php5.3. | XMLRPC is as secure as the rest of WordPress. All of the requests need to be authenticated with username and password credentials that exist on your site already. That means, if someone has a login for your site, they can use the XMLRPC interface (if it's turned on). But anonymous users can't get in.
The only potential security vulnerability you might face with XMLRPC is that of a man in the middle attack. But you face this same risk with the regular WordPress admin, so it's not unique to XMLRPC.
The _best_ way to prevent this kind of an issue is to enable SSL security on your site. You'll need an SSL certificate, and then you need to access you XMLRPC endpoint via ` rather than ` This will encrypt your requests and prevent anyone from intercepting them and stealing your credentials.
You should also enable SSL security on login for your regular site because it, too, faces the same risks. | stackexchange-wordpress | {
"answer_score": 7,
"question_score": 2,
"tags": "security, xml rpc"
} |
Adding a <code> button to the WYSIWYG editor?
I've been looking for a way to add a button to wrap text in ` for the WYSIWYG editor in Wordpress 3.3.1.
I tried this:
function enable_more_buttons($buttons) {
$buttons[] = 'code';
return $buttons;
}
add_filter("mce_buttons_3", "enable_more_buttons");
But that did not work as expected. It did display a button, but it brings up a popup window to edit the HTML.
In addition to it would be nice to have and . | I finally found a plugin that did just what I wanted - a button for in the WYSIWYG editor: WYSIWYG Inline Code Command | stackexchange-wordpress | {
"answer_score": 7,
"question_score": 3,
"tags": "wysiwyg"
} |
Does anyone have any frameworks to setup custom post types and related actions/filters?
So I know that setting up custom post types ranges from just registering them to adding custom permalinks, custom sorting, customizing columns in the admin, etc. I was wondering if anyone had a template or framework that they use regularly to set up custom post types in projects? Do you start from scratch every time or do you have a base line you start from that you customize? | The Custom Post Type Demos by toscho hold some nice basic classes, that you can use. I'd recommend taking a look at this source (as he's a _trusted author_ and a pretty good coder). | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 4,
"tags": "custom post types, framework"
} |
Database interaction (private-public)
I like to have a nice website for my client.
I will do it with WordPress. But that client will manage a database, much like Excel or Lotus or Access or FileMaker.
I like to offer the same style of database interaction (add, modify, query) with ans private access to wordpress... can i do that and how ?
Thanks in advance | Forget that kind of interaction... drupal ? IDK | stackexchange-wordpress | {
"answer_score": -1,
"question_score": 0,
"tags": "database, editor, private"
} |
Count custom post type based on two meta data
I am trying to count my custom post type called 'appointments' that match two meta data values .
The meta data keys are 'location' and 'timestamp'
So in english my query is: How many appointments are scheduled at Location at Time
How can this be done? | $args = array(
'post_type' => 'appointments',
'meta_query' => array(
'relationship' => 'AND',
array(
'key' => 'location',
'value' => $place //set this somewhere
),
array(
'key' => 'timestamp',
'value' => $time //set this somewhere
)
)
);
$posts = new WP_Query( $args );
Docs: `WP_Query`
You have the flexibility to add just about anything else you need to that, for example, `post_status`. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "custom post types, query posts"
} |
Blog shows up without Theme/CSS styles
I installed Wordpress to my own domain and it was working just fine. I then, downloaded a new Wordpress theme and uploaded it into the wp-content/themes/ folder directory. The name of the folder is theme43 with an images folder and various php files within it (just like the automatically installed twentyten and twentyeleven themes). But now, when I navigate to the blog in my browser (Latest Firefox) the text shows up without the pictures, colors, etc. If I 'View the Source' on the page, the stylesheet link maps to /wp-content/themes/twentyeleven.
However, the path indicates that the wp-content is in the root directory. I have moved everything from the root to a folder within the root called blog (www.blahblah.com/blog/wp-content/themes/...). This is clearly the problem. How do I get Wordpress to look at the 'blog' folder within the root instead of the root itself? | You can add the WP_HOME and WP_SITEURL constants in your wp-config.php file to manually override the database options.
**Scenario one:** You want to surface WordPress from your blog folder.
define('WP_HOME','
define('WP_SITEURL','
**Scenario Two:** You've moved WordPress to another folder, but want it to surface at your root.
define('WP_HOME','
define('WP_SITEURL','
You will need to make sure your index.php file is still in the root, and point the include to the new blog folder.
require('./blog/wp-blog-header.php');
**Scenario Three:** If you aren't comfortable going the wp-config route, move your site back to its original location, login to wp-admin, go to the Settings menu, and adjust the home and site urls in the admin interface. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "themes, css, troubleshooting"
} |
How to get all posts related to particular category name?
I am developing one project and in this project i have to display all the posts related to particular category name.
I have searched a lot but i haven't got any idea to implement this.
How can i do this so that i can display all the posts from particular category/term | Just use `WP_Query()` to generate your custom query, using the category parameters.
Assuming you know (or know how to _get_ ) the ID of the specific category, as `$catid`:
<?php
$category_query_args = array(
'cat' => $catid
);
$category_query = new WP_Query( $category_query_args );
?>
Note: you could also pass the category **slug** to the query, via `category_name`, instead of `cat`.
Now, just output your loop:
<?php
if ( $category_query->have_posts() ) : while $category_query->have_posts() : $category_query->the_post();
// Loop output goes here
endwhile; endif;
?> | stackexchange-wordpress | {
"answer_score": 14,
"question_score": 6,
"tags": "posts, get posts"
} |
Display custom post type
I am using this code to display custom post type.
$gabquery = new WP_Query();
$gabquery->query('showposts='.$showpostbotleft.'&post_type=courses' );
How to edit it to limit number of posts and specific taxonomy name of this custom post type. | I prefer using using the array form...
$gabquery = new WP_Query(array(
'post_type'=>'courses',//The name of the post type
'posts_per_page'=>5, //Use this rather than showposts
'tax_query'=>array(
array(
'taxonomy'=>'my-custom-tax', //Your custom taxonomy name
'operator' => 'IN',//NOT IN & AND also available
'field'=>'slug',//or you could select by ID
'terms'=>array('my-term-slug')//Get posts with this term (or ID if above is ID)
)
)
));
The above queries posts of type 'courses', limits the number of posts to be displayed to 5 per page, and selects only posts which belong to the 'my-term-slug' term of the 'my-custom-tax' taxonomy.
See the WP_Query Codex. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "custom post types"
} |
How to change the length of excerpt() method?
I am using the_excerpt() method to display some wordings from the blog posts.
I have read the post from this link. <
But my situation is different.
I am displaying some wordings from the posts in two places. In the first place I want to display 20 words and in the 2nd place I want to display 50 words.
So what will I do for this? | The top answer to this question handles dynamically altering the length of your excerpt using a custom excerpt function. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "excerpt"
} |
grab or load text on demand
## What i want to do
I want some content (could be stored any where in a post or custom field) to load only when the user clicks for it to load. This content could be any thing (text,images,html etc) and this may be accomplished through any way (eg ajax, shortcode) i don't mind.
## Specification
what i don't what to do is let the content be loaded before hand, be hidden and be displayed when demanded. It has to only load when its wanted or demanded. | You should really take a look at the AJAX in Plugins article. It gives examples of how to setup AJAX the proper way in WordPress.
Here's the basic workflow of using AJAX in WordPress:
1. Create an enqueue your custom JavaScript file that uses jQuery.post or jQuery.get or jQuery.ajax
2. Create a callback for the wp_ajax action hook (learn the difference between normal and nopriv hooks)
3. Within your callback function, you would create some logic that would echo whatever type of content you choose (make sure to exit or die() at the end of the callback)
It's best if you learn to fish on this one rather than someone doing the fishing for you. :) | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugins, custom field, functions, shortcode, ajax"
} |
How to make WP admin recognize a newly created child theme?
I am having a problem that's very similar to the one described here, except that the solution that worked for him (text encoding) didn't work for me.
I even tried applying `unix2dos -o style.css` from the command line (which definitely changed the file from LF to CRLF, as I could see that the file increased slightly in size), but that didn't help.
I also tried clicking the button `Search Installed Themes` but that didn't help either.
What are the requirements for making a child theme appear in the admin's list of Available Themes? | Found the cause of the problem - and fixed it!
It turns out that LF vs. CRLF is not an issue at all on a LAMP based webhost.
The problem in my particular case was that I copied the original theme's `style.css` **verbatim** , and it was missing a very critical line in the comment section:
Template: twentyeleven
Once I fixed that everything started working as expected.
Note: Template should point at the parent's directory, not the child's one. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "theme development"
} |
Need post_type_archive_title function but in 'single'
I'm trying to pull a custom post type name/title out for use in the breadcrumb of a single-[cpt].php template file.
In the archive-[cpt].php I can use post_type_archive_title() and it echo the name. How would I get this same title in a single view?
Thanks!
I've trawled though the codex and haven't seen a function, but might have missed it! | There doesn't appear to be one, but the following should work:
//Get post type
$post_type_obj = get_post_type_object( get_post_type() );
//Get post type's label
$title = apply_filters('post_type_archive_title', $post_type_obj->labels->name );
$archive_title = apply_filters('post_type_archive_title', $post_type_obj->labels->all_items);
This can, for instance, be put in one generic `header` template that is applied to all `single-cpt` files. With `is_single()` it can be put in an even more generic `header` template.
For a complete list of labels, see < | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 1,
"tags": "custom post types, archives, single"
} |
Why would get_posts be ignoring posts with 2-digit ids?
I'm using this code to list child pages of the current page and similar code to get child pages of all ancestors to use in a sidebar contextual hierarchical nav menu:
$pageset = get_posts('numberposts=0&post_type=page&post_parent='.$wp_query->post->ID);
For some reason, both iterations are ignoring posts with a two-digit post id. Everything else shows up fine.
Am I missing something? Do I have a setting that's incorrect? I'm banging my head here... | It might be because you are using `numberposts=0` If you want to return all posts then you need to use `-1` not `0` | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "get posts, id"
} |
Check if post is in draft or pending review?
Each of our posts are reviews for individual games and we occasionally have to 'pause' the game by changing it from published to pending review. The problem is if the page is indexed by search engines, anyone trying to visit the link will get a 404, which is obviously not desired. I'd like to instead redirect to a listing of all our games.
I can think of a few options but I'm not sure which would be preferred.
I could just do a temporary 302 redirect from that post to the game listing page. I'm not entirely sure how this will work for SEO however.
I could also do a check to see if the post is pending review (in the 404 page?), and if it is, then display the game listing page. I'm not entirely sure how to go about this. I tried finding a function to check if it's in pending review but didn't have any luck. | `post_status` is part of the `$post` object which you can use to determine if it is published, a draft, pending, etc.
if( $post->post_status == 'pending' )
// do stuff | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 3,
"tags": "redirect, 404 error, draft"
} |
Shortcode to display the latest news article within a page
Could someone help me write a custom shortcode to simply display the latest post anywhere in Wordpress? I've seen a lot of ways how to do this in pure PHP in a custom page template, but if I try to convert it, I always get problems (double display) or completely nothing. It should be just one post (not page) of any kind at all, as long as it's the most recent one.
I just need it like this:
<h2>Title</h2>
<p>Excerpt...</p>
<a href="permalink" class="button">Read more</a>
I've also looked for some plugins, but that's also problematic. They break all shortcode functionality or they just display a list...
Can anyone help me out and score some points? I would surely appreciate it. | In functions.php file :
function my_recent_post()
{
global $post;
$html = "";
$my_query = new WP_Query( array(
'post_type' => 'post',
'posts_per_page' => 1
));
if( $my_query->have_posts() ) : while( $my_query->have_posts() ) : $my_query->the_post();
$html .= "<h2>" . get_the_title() . "</h2>";
$html .= "<p>" . get_the_excerpt() . "</p>";
$html .= "<a href=\"" . get_permalink() . "\" class=\"button\">Read more</a>";
endwhile; endif;
return $html;
}
add_shortcode( 'recent', 'my_recent_post' );
And the shortcode would be [recent].
Code is untested, but should look something like that. | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 0,
"tags": "posts, shortcode"
} |
Can a page contain php code?
I am trying to use the following line of PHP code in one of my pages:
<input name="from" id="from" value="<?php echo $_GET['from'];?>" type="text" />
But instead of displaying an empty "from" input field (before typing anything into it), it displays `<?php echo $_GET['from'];`.
Am I missing something?
Clarification: I am entering this line of PHP code (in addition to some HTML) from the Admin's `Edit Page` (the HTML tab of course, not the Visual one). | You can't use PHP in the WordPress back-end editor. Maybe with a plugin you can, but not out of the box.
The easiest solution for this is creating a shortcode. Then you can use something like `[input type="text" name"from"]` in your editor.
function input_func( $atts ) {
extract( shortcode_atts( array(
'type' => 'text',
'name' => '',
), $atts ) );
return '<input name="' . $name . '" id="' . $name . '" value="' . (isset($_GET['from']) && $_GET['from'] ? $_GET['from'] : '') . '" type="' . $type . '" />';
}
add_shortcode( 'input', 'input_func' );
See < | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "php, pages, forms"
} |
Why Won't my jQuery Play Nice with Wordpress?
Code in question here: <
It worked on the HTML page I tested it on. Its supposed to add "display: none" to the content divs and then add "display: block" when the appropriate tab is clicked. But it just changes to "display: none" and never changes. | WordPress automatically loads jQuery in "no conflict" mode so that it will be compatible with other libraries. This means the `$` variable **_isn't used for jQuery_** within WordPress.
Rewrite your code to use the full jQuery keyword when you begin your closure like this:
jQuery(document).ready(function($) {
// ... other code in here
});
This is functionally the same as `$(document).ready(function() {` but uses the full name of the jQuery object to avoid noConflict issues. By passing jQuery in to the closure as the `$` variable you can then use `$` like normal _inside_ the closure. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "jquery, shortcode"
} |
$paged always 0 on plugin's custom page
I'm making a plugin that loads a specific template depending on a certain query var being passed, in effect creating a page for the plugin on the front end, as outlined in this post:
Create a page without adding a page in the Database \- the first answer by Brian Fegter
So if I head to mysite.com/foobar I can use my custom template. However, if I hook a function up to wp_head and print out the paged query_var, it always returns 0, regardless of the value in the url (mysite.com/foobar/page/2, or example).
Any thoughts as to why this is happening? Is there a better way for my plugin to create a new page on the front end?
Thanks in advance. | I resolved this myself. The problem being:
add_rewrite_rule('^foobar?','index.php?is_foobar_page=1','top');
Which prevents any other query_vars from being created. To resolve this, a slightly more complicated rewrite rule combo is set up:
add_rewrite_rule('^foobar?$','index.php?is_foobar_page=1','top');
add_rewrite_rule('foobar/page/([0-9]+)?$','index.php?is_foobar_page=1&paged=$matches[1]','top');
This takes into consideration the creation of the plugin's subpage 'foobar' and also allows for pagination within this page.
Hope this helps someone. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugin development, query, paged"
} |
WordPress admin section appears broken
My WordPress admin area looks like the image linked below. I have tried reinstalling WordPress using the option in the `Updates` panel. But I cannot get it to revert. Has anybody had a similar problem and knows the solution?
My guess is that it's CSS but shouldn't have to reinstall WP sorted that out?
Need more rep to include this image in the post | In your screenshot I can see at least 3 menu items that were added by a plugin.
Standard practice when WP breaks after an update is to:
1. Disable all plugins (You can rename the `/wp-content/plugins` directory to turn them all off at once).
2. Revert to the default (TwentyEleven) theme
Then you can re-enable your plugins one at a time to figure out which one it is that's breaking things. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "wp admin"
} |
Trouble Removing Plugin
I'm editing this site < currently and I am trying to get rid of the login in the upper-right corner. I go to plugins and deactivate a plugin called "Login with AJAX", then I refresh the page and only the page's header displays.
Anyone know what I'm doing wrong? | My best guess is that the function for showing the Ajax login is still in the theme header.php
You can look for the function login_with_ajax() in your themes header.php and remove it, if it's there.
If an undefined function is called you get a fatal error and the script will stop. So it only displays until the function, in your case the end of your header. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugins, ajax, login"
} |
Compatibility with RTL installations
I want develop a plugin that add boxes and menus in WordPress backed.
What I have to keep in mind to make it **compatible with WordPress RTL** installations?
Any idea or suggestion will be appreciated.
Thanks | You can use `is_rtl()` to check if the user is setup for RTL or not, then you would just need to register and enqueue the RTL styles instead of the LTR styles. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "plugins, dashboard"
} |
add_filter() doesn't work in loop
I'm trying to order the posts in the home page by modified date, and I put this code in the functions.php of my active child theme:
function orderby_last_modified() {
return 'post_modified DESC';
}
If I add the filter in the same functions.php file it works:
add_filter('posts_orderby', 'orderby_last_modified');
But I only want the filter in the home page loop, when I change that line to the home page it just dont work.
<?php
add_filter('posts_orderby', 'orderby_last_modified');
if(have_posts()):
while(have_posts()) atom()->template('teaser');
remove_filter('posts_orderby', 'orderby_last_modified');
?> | It doesn't work in your template because the query has already happened before the template is loaded. If you want to add your filter only under certain conditions, you need to hook an earlier action, like pre_get_posts, and check if the query is for the home page:
function add_my_orderby_filter( $query ) {
if ( $query->is_home ) {
add_filter('posts_orderby', 'orderby_last_modified');
}
}
add_action( 'pre_get_posts', 'add_my_orderby_filter' );
This would go in your `functions.php` along with your `orderby_last_modified` function.
See the WordPress Action Reference for the order actions are executed in a request. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 2,
"tags": "loop"
} |
Nice way to print_r arrays
So you know how Drupal has functions in modules like Devel that allow you to output arrays in a nice format like `dsm($array)` or `krumo($array)`... Does WordPress have an equivalent or a nice way of displaying `print_r($array)`? | I created a Kint plugin that works really well. I also integrates with the Debug Bar plugin. You can download it at: <
There are a few functions to help you out with WordPress specific globals:
* `dump_wp_query()`
* `dump_wp()`
* `dump_post()`
For printing arrays in a styled, collapsible format you would do the following.
$foo_bar = array(
'foo' => 'bar',
'bar' => 'oof',
'rab' => 'foo'
);
d($foo_bar); //Styled
s($foo_bar); //Un-styled | stackexchange-wordpress | {
"answer_score": 12,
"question_score": 7,
"tags": "array, formatting"
} |
Post data returning null
I'm writing code from within a plugin and I'm attempting to create a two-part registration form. I'm using POST to determine if the first part of the form was submitted or not. Unfortunately, though, the POST data is not coming through. Here is what my form looks like:
<form action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post">
<input type="submit" name="user_info_form" id="user_info_form" />
</form>
This should POST back to the same page, in theory. I then use the below code to read the POST data.
if(isset($_POST['user_info_form']))
{
echo "found data";
}
else
{
echo "nothing found";
}
Unfortunately, "nothing found" is being outputted following a form submission.
Is there any reason for this that has to do with WordPress? I've been at this for hours now so any help is _very_ much appreciated! | I found my own answer on this one (just now). The stupid plugin had javascript at the bottom of the page disabling all submit buttons from working - what a joke, sorry everyone. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -1,
"tags": "posts, pages"
} |
How can I show the subcategories content on the parent category page?
I have a WordPress website that has a category with two subcategories.
Now, how is it possible to show the content (the subcategories items/content) on the parent category? | One possibility:
<?php
$sub_cats = get_categories('parent=' . get_query_var('cat'));
if( $sub_cats ) :
foreach( $sub_cats as $sub_cat ) :
$sub_query = new WP_Query( array(
'category__in' => array( $sub_cat->term_id ),
'posts_per_page' => -1)
);
if ( $sub_query->have_posts() ) :
while( $sub_query->have_posts() ) : $sub_query->the_post();
//your output//
endwhile;
endif;
endforeach;
endif;
?>
< < | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "categories"
} |
Split Testing with W3 Cache Enabled?
I'm trying to do some simple split testing on a category page, but W3 Cache is causing some issues.
To do the split testing, I randomly select a layout (either grid or horizontal), then I store it in a $_SESSION variable so that the page is the same for that user while they're on the site.
Then on the category-slug.php page, I just do an if statement to determine what layout to display based on the value in the $_SESSION variable.
It is all working fine, except W3 Cache is caching the page. So the $_SESSION will have a grid layout value, but a horizontal layout will actually be displayed. Obviously this skews my data.
I'd rather not disable W3 Cache since it helps reduce our page load time. Anyone have any ideas? | I ended up just putting variables to denote the layout in the conversion link.
For example, if the layout is a grid, the url is <
It doesn't consistently let me switch layouts between users, but at least the data isn't being skewed by a $_SESSION variable reporting something differently than what is being seen by the user. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugin w3 total cache"
} |
implementing a centralized content "show-do-not-show" toggle?
I have many custom templates for different post types, and I am manually inserting a social share bar inside the 'entry-meta' footer in each of those templates. I need a simple centralized way to disable the social share bar without hacking into the plugin.
Basically I have this setup so far:
In **functions.php** :
`update_option( 'show_social_bar', 'true' );`
In my templates I have this check:
if( get_option( 'show_social_bar' ) === 'true' ) {
// show my social share links
}
If I need to turn the bar off, I just set the option to 'false' in **functions.php**. This somehow seems inefficient. Is there a more sensible way? | It's a bad practice to update an option on every page load. You should use a constant instead.
define('SHOW_SOCIAL_BAR', true); //functions.php
if(SHOW_SOCIAL_BAR){
//Do Something
} | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "functions, customization"
} |
Minimal WordPress Functionality on Existing Website
I have a client that wants the ability to remove or add a special offer from the front page of her website.
I thought of creating a custom loop using a featured image etc, which would display the latest special offer.
Her site is a PHP site right now without any WP functionality.
What is the minimum installation that would allow me to display this loop. Instead of creating a theme and template I just want to use the existing page.
Thanks. | You can require the wp-load.php file in the existing page...
<?php require('wp-load.php') ?>
This will basically load the WordPress installation and allow you to access each of the functions (and the loop) as you normally would. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "theme development"
} |
Main Sidebar Dispappeared - What could possibly cause this?
I used to have the drag & drop Widgets on Main Sidebar working but for some reason it no longer works. That is, whatever I place there (on the back-end) is no longer visible on the front-end.
In my attempts to troubleshoot this, I uninstalled completely the only 2 plugins I had:
1. "Contact Form With Captcha"
2. "WP fade in text news"
But that didn't help.
I also switched back to the `twentyeleven` theme (from a child theme containing `style.css` only) but that didn't help either.
I also compared the content of the entire directory tree with pristine copy of the WordPress 3.3.1 ZIP package and found no differences. Does this point to some problem in some settings stored in the database?
Lastly, I tried the 3 different `Default Layout` settings in `Appearance > Theme Options`, just in case. That didn't help either.
What could possibly make the sidebar disappear? | After much search I found an explanation to the mystery: With the new `Twenty Eleven` theme (from WordPress 3.2 and up), the sidebar is gone in the **single post page**. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "sidebar"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.