INSTRUCTION
stringlengths 11
999
| RESPONSE
stringlengths 0
999
| SOURCE
stringlengths 16
38
| METADATA
dict |
---|---|---|---|
Plugin generated taxonomies' permalinks with custom placeholders
I have a problem with permalinks for custom taxonomies generated with Types < a plugin for creating taxonomies, custom posts and custom fields.
The problem is that once i set up my taxonomy i'm not able to configure the permalinks.
The options for my taxonomies are:
Plural name: Volumes
Singular name: Volume
Slug: volume
Rewrite: yes
In the permalinks i choose custom and set: `/%volume%/%postname%/`
But then the posts url, instead of showing the actual taxonomy slug, it shows the permalink code, link eg this: `
The post name is replaced, but the taxonomy not. Of course the link doesn't work...
I really cannot understand what is going wrong here. | Looks like it's not something can be done without digging into the code.
However i found a plugin the fits my needs pretty well: <
with this you can just set /%your-taxonomy%/%postname%/ in the permalinks settings page and your done! | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "plugins, custom taxonomy, permalinks, url rewriting"
} |
esc_html__ security : what for in this example?
how does `esc_html__` (the 2nd one) protect the `$message` variable from being hacked ? what's the point to use this protection here (the second one with a plain text)?
<?php
function unknown(){
/* If the user input any text, escape it. */
if ( !empty ( $_POST['unknown'] ) )
$message = esc_html ( $_POST['unknown'] );
/* If no text was input, use a default, translated message. */
else
$message = esc_html__( 'No message input by the user.', 'unknown' );
return $message;
}
?>
Thanks | It really doesn't do much in that scenario. If you're going to leave that message as a string constant instead of something that is system or user generated, you're fine using one of the other translation functions: `__()` or `_x()`. `esc_html__()` is a little overkill for that particular line of code.
**Edit:**
The main reason for the `esc_` functions is to protect your site against bad input, either intentional or accidental. You're going to want to use the appropriate function whenever you're working with any data that can be manipulated by a user or is not explicitly set by you.
If you have any questions about WP functions in the future my recommendation would be to check the source. Either do a search in a WP install to find the function, or click the link at the bottom of the codex page that links to the source file. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "security, wp localize script"
} |
What is the correct MIME type for PSD (Photoshop)
I am trying to create an upload area (frontend) for word press users on a site. I've got a lot of types opened up through some function calls, but unable to correctly get PSD support. I'm seeing a lot of different types, and to my knowledge have tried all. I'm not sure if my hosting environment makes any difference. Am on Hostgator VPS.
Anyone successfully gotten WP to upload PSDs? | This is what I use to allow PSD upload:
add_filter('upload_mimes', 'custom_upload_mimes');
function custom_upload_mimes ( $existing_mimes = array() ) {
$existing_mimes['psd'] = 'image/vnd.adobe.photoshop';
return $existing_mimes;
} | stackexchange-wordpress | {
"answer_score": 9,
"question_score": 7,
"tags": "functions"
} |
Export SQL query based on custom field?
I'm operating on two WordPress sites and I need to export posts only with a specific custom field from one site and import into the other. I can't do a generic dump of the database because some data would be overridden.
My SQL query:
> SELECT * FROM wp_posts INNER JOIN wp_postmeta ON wp_postmeta.post_ID = wp_posts.ID WHERE ( wp_postmeta.meta_key = 'Color' AND wp_postmeta.meta_value IS NOT NULL );
Now I can export that into a .xml or .csv but I can't import that into the other site.
This is because the meta columns are appended to the row of the wp_posts. (Screenshot: <
Is there a work-around? | Change your query to:
SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON wp_postmeta.post_ID = wp_posts.ID WHERE ( wp_postmeta.meta_key = 'Color' AND wp_postmeta.meta_value IS NOT NULL );
That way it only gets the data in wp_posts, but still filters based on your criteria. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "mysql, import, export, phpmyadmin"
} |
Is there any way to add images to the Media Library through a path on the server?
I have 3 folders with images that I want to add to my media library. I do not want to have them uploaded under the default path (i.e. uploads/year/month). I can upload them anywhere in the theme folder.
Is there any plugin/method to do that? | You can use the Add From Server plugin. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "media library"
} |
printf and _n in this example?
what is the last `$count` in this example?
printf( _n(
'You have published %s post.', 'You have published %s posts.',
$count,
'myplugin' ),
$count );
i guess the first one is to fill each %s, so what is the second $count?
Thanks | The `_n` (see Codex) function accepts four arguments. The first two are texts to be translated (the first is singular, the second plural), the third argument is a number (in this case `$count`). When `$count` is 1 the first string is used, otherwise the second string is used.
So in fact the first instance of `$count` is only used to determine whether the single / plural text should be used. `_n` then translates that string, using the plug-in/theme domain - i.e. the fourth argument) and the language set in the wp-config. This then returns a translated string such as:
> Se han publicado %s artículos
The `printf` then echos this string with the `%s` replaced by the second argument, `$count` (which is the second instance of $count`) . | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "text, customization"
} |
White screen on front page only
I've got the famous white screen, but only on my home page. Deeper pages load just fine. I moved my `themes` directory to `themes-old` and made a new `themes` directory that only has twentyten in it. I changed my theme to twenty ten. I don't have any plugins enabled, but I moved my plugins directory and created a new, empty plugins directory.
I turned debugging on.
I'm at a total loss here. I did make some theme tweaks today, but I already restored the back up of my theme which didn't help, and anyway I've now set twentyten as my theme. | To make sure that the `index.php` will be loaded first add the following line to your `.htaccess`:
DirectoryIndex index.php index.html
This tells Apache to ignore an `index.html` if an `index.php` exists. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "server, debug, frontpage, wp debug"
} |
Extract the last published post
How do I extract the last published post?
I would be grateful if someone can just point out the relevant action hooks that I should check out. I have seen publish_post, edit_post, save_post, get_the_tags, sanitize_** functions in `post.php` but so far no success.
I want to export the entire array of the last published post from the database. How do I do that? | Thank You! I sorted this out myself thanks...
For any one who stumbles upon this, here's the resolution...
// Get the last n number of posts.
$args = array( 'numberposts' => 'n' ); // replace n with the number of posts
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.$recent["post_title"].'" >' . $recent["post_title"].'</a> </li> ';
echo '<li>Tags '.print_r($recent).'</li> ';
} | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "posts, export"
} |
How to get a variable number of posts per post type on the main loop?
I'm looking for a way to balance the content at the homepage of my blog:
the blog has a few post types like Poscasts, Videos and Blog and I'd like to have let's say 10 Posts on the homepage, but I'd like to make 5 of them always the lastest Blog.
Making 3 separated boxes don't solve my problem because the posts are mixed and there won't always be as many posts of the other types.
I could think of the solution for it on pure PHP , but I'd like to get a idea on how to do this using the wordpress API, any help , reference will be welcome! | So, after a few months. I found the answer to your exact question:
add_action('pre_get_posts', 'custom_main_query', 1);
function custom_main_query( $query ) {
if ( $query->is_main_query() && is_home() ) {
//be super careful with this and to be safe, keep the is_home()
//bit there, I've had some funny results without it.
$query->query_vars['posts_per_page'] = 3; //displays 3 posts ;)
$query->query_vars['post_type'] = array('post'); //and if you wanted multiple cpts <3
return $query;
}
}
Cheers | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 8,
"tags": "plugins, custom post types, code"
} |
Using GD Star Rating outside of the loop?
I need to insert a rating straight away after having programmatically created a post in WordPress and added a comment.
What is the (GDSR) function to call to fire the rating once I've got the post id/comment id? | Here it is:
gdsrBlgDB::save_vote($post_id, $user_ID, $ip, $ua, $vote, $comment_id);
then insert in the theme:
wp_gdsr_comment_integrate_standard_result(get_comment_ID()); | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugin gd star rating"
} |
show all in query_posts on category.php?
I want to be able to switch back and forth by clicking an anchor tag preferably, between showing a subset of posts and showing all posts, the code I am using is:
query_posts($query_string . '&posts_per_page=-1');
or
query_posts( array(
'posts_per_page' => 45,
//'paged' => ( get_query_var('page') ? get_query_var('page') : 1 ),
));
(paged isn't working)
Any way to do this? The problem is I need the 45 limit to show by default, and then a show all anchor tag or button that the user can click.
Any help would be much appreciated!
Thanks! Donna | You could add a url parameter for posts per page. Something like this:
$pppage = ( get_query_var( 'posts_per_page' ) == 'all' ) ? -1 : 45;
query_posts( array(
'posts_per_page' => $pppage
) );
then you can set your URL with the parameter `posts_per_page=all` if you want to show all the posts, if it doesn't find that parameter it will default to 45 posts. You can rewrite this parameter to something like `/all/` to show all. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "query posts"
} |
Name of JQuery technique used on this site
What is the effect or jquery plugin used to create the on hover video effect used on this site? < | 1. Hi
2. It's not Jquery, it's Flash
3. Your question is not Wordpress related | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "jquery"
} |
Change the actual (or viewable) Wordpress directory structure
I like the simplicity of wordpress and all it has to offer, but for security purposes I would like to change the actual (or viewable) directory structure of my site.
The install has a set of files that everybody who's familiar with wordpress will know about. I have read about some security measures some where that suggests changing the file/directory structure of a wordpress site to increase the level of security. This would prevent someone from knowing right away if a site wordpress based or not.
I have no idea how to do this, but I think using the htaccess might be a solution. Im also concerned about future updates and is there a way to change the actual (or viewable) file structure without effecting updates.
I would appreciate some advice on this. Thanks for any help on the matter! | This has been answered many times. Search this site, as toscho points out above.
And see Ben Word - Hide WordPress, who shows how to:
> 1 - Clean up the output of wp_head and removing the generator from RSS feeds
>
> 2 - Hide /wp-content/ by rewriting static theme assets (CSS, JS, and images), rewriting the plugins directory, and also changing the location of WordPress uploads
>
> 3 - Clean up the output of navigation menus with a custom walker
>
> 4 - Show root relative URLs | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "php, htaccess, directory"
} |
Why does WP load so many files in the head of source code? How do I optimize it?
I have noticed that wordpress loads a bunch of files into the head of a site. This looks really sloppy and discloses vital information about the file structure of a website.
Depending how many plugins are installed a site can easily have 10+ `<link>` and `<script>` tags. I understand how these files may work together, but it _does_ look excessive and unorganized.
That said, is there a way to optimize this and somehow combine certain files to reduce the number of files loaded?
There are benefits that can be gained from this, such as improved performance and security.
If anyone has any suggestions please let me know. | First of all, search this site. This questions has been answered many times in the past: < and <
Secondly, there is a difference in what WP loads and what a theme and a plugin will load. Look in the theme functions file to see what the theme loads, i.e. javascripts and CSS. Look in the browser source to see what plugins load; they often load a lot of code via wp_head or wp_footer.
Use Firebug with Firefox, or use the developer tools in Chrome or Safari or IE.aspx) to see what's loading on your site. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "headers, filesystem, wp head, wp load.php"
} |
Disable new user notification to admin email
I get an email notifying me of every new user registration on my site and now that it gets hundreds or thousands of new users a day, it's getting a little out of hand.
It seems like it'd be a Wordpress setting to disable it, but I can't seem to find anything. Do I really need a plugin to do this? | One plugin, among several: <
You can grab the function out of it and use it directy in functions.php | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 5,
"tags": "email, notifications"
} |
Show menu based on parent & ancestor
Trying to show a wp menu based on parent. Works great on parent / child pages, but on grandchildren pages its failing. How should i restructure the menu selector to include the sub nav menu based on the main parent?
<?php
if ( wp_get_nav_menu_object( $post->post_title ) ) {
wp_nav_menu( array(
'menu' => $post->post_title,
'menu_class' => 'subnav',
'container' => ''
) );
} else {
if ( wp_get_nav_menu_object( get_the_title( $post->post_parent ) ) ) {
wp_nav_menu( array(
'menu' => get_the_title( $post->post_parent ),
'menu_class' => 'subnav',
'container' => ''
) );
}
}
?> | Work around.
if (is_page( 'pagename' ) || in_array("5", $post->ancestors)) {
wp_nav_menu( array( 'container_class' => 'subnav', 'menu' => 'visit' ));
}
5 being the ID of the page in question.
So while this is a bit more work, needing and if / if:else statement for each page, it will scale to allow as many child / grandchild pages as needed | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "menus, sub menu"
} |
Multiple Authors on a Single Blog
I'm currently researching into using WordPress and so, apologies in advance if this seems like a very basic question.
Our main requirement is to have a single blog, but allow multiple users / authors (essentially the entire organization which could be up to 100 people) to post.
Is this possible in WordPress?
We would be hosting WordPress within our organization (e.g. in an intranet environment).
Thank you! | There is no limitation on the amount of users... There are some great plugins
that would help you manage permissions and limitation you might want to empose
to avoid problems..
Tip: Aritcle writers should a writer user level
1. Email Users Plugin \- This would help you send email to all users in one click.
2. WyPiekacz \- A very good plugin! would help you set a minimun post length, maximum amount of categories and tags and more..
Hope This helps,
Sagive | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "author, blog"
} |
Limit number of emails per second
Our users have been complaining about activation emails taking a while to be received. After digging around, we discovered that about 50% of users get the emails instantly and the other 50% take between 5 mins and 2 hours, which is unacceptable.
We determined that Wordpress was sending emails at a rate of ~20+ emails/sec and Godaddy's threshold is 4 emails/sec, which I think is causing this problem.
Is there a way for me to limit stagger the emails out a bit more? Are there plugins or settings I can adjust to resolve this? | A possible workaround depending on your level of coding knowledge:
You could use the Transients API. Simplified: It adds an Option with an expiration time.
Then you could hook into the `phpmailer_init`-action and update the transient value with your new email. If the time expired, you could send the previously added mails out and then add the ones that are above 4.
Sorry, no code in detail as it's more a server/hosting question than a wordpress one. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "email"
} |
Editing Wordpress Permissions in LAMP - Ubuntu 11.10
I'm hosting a local version of my wordpress theme on Ubuntu 11.10. However, LAMP is installed in a directory that requires sudo privileges. When I try to add images or any outside content to my theme, it fails because it cannot create a folder/write to a folder.
How do I edit the permissions to allow Wordpress the access it needs? | I think that setting all to 777 is not the most secure option.
Basically, my favourite is to change the wordpress to the webserver's owner. Being:
sudo chown -R www-data:www-data /var/www/
So that the webserver is responsible for handling changes.
Also, you can change the rights to 755 for the whole /var/www branch
sudo chmod -R -c 755 /var/www/
Finally, allow your wp-content/ folder in 775 ( so that you can edit files from the WordPress backend without having to upload files via FTP. ( Not necessarily a best practice but useful from time to time ) via
sudo chmod -R -c 775 /var/www/WORDPRESS/wp-contents/
And you will have a reasonable setup with uploads, editing from backend and a minimum level of security. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 3,
"tags": "permissions, linux"
} |
wp_mail and BCC headers
I'm using WP 3.3.1
I am trying to add BCC onto the headers of an email I'm sending out, but the BCC is not being added.
public $from = "[email protected]";
public $replyTo = "[email protected]";
public $bcc = "[email protected]";
$headers['From'] = "From: ".$this->from;
$headers['Reply-To'] = "Reply-To: ".$this->replyTo;
$headers['Bcc'] = "Bcc: ".$this->bcc;
wp_mail("[email protected]", "My Subject Line" , $html, $headers);
I've looked at this article, which says the problem was suppose to be fixed in WP 3.2...but for me, it's still not working.
I am using a local SMTP server application called Papercut to monitor the emails that are being sent.
**Related:** wp_mail not recognizing cc and bcc headers | You could try to debug the output like this:
function test_phpmailer_init( $phpmailer )
{
echo '<pre>';
var_dump( $phpmailer );
echo '</pre>';
return $phpmailer;
}
add_action( 'phpmailer_init', 'test_phpmailer_init' );
The code in your question is correct, the problem is with your local SMTP application. If you are using a local SMTP server (e.x. Papercut), it only displays the headers that a receiver would see. Since BCC addresses are hidden, you will not see them. So to check to see if BCC addresses are being attached, you can use the function I've listed above which will spit out the mail output. | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 6,
"tags": "plugins, email, wp mail"
} |
Export posts with postmeta without ID?
I have some select posts on one database that I need to export and import into a different database.
Because both databases are operating independently, there is overlap with post IDs so I can't export the ID from wp_posts.
I can successfully export and import the posts, but the post meta is dropped. And, since I'm not exporting the ID, I can't export the wp_postmeta without referencing the appropriate (NEW) ID.
Any ideas on how I can transfer only some posts to a different site and keep the post_meta while ditching the ID? | Instead of exporting raw SQL, instead us eth eWordPress exporter and import them that way. This way any media attachments, taxonomy terms, and post meta are all included, and all URLs are adjusted too | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "post meta, mysql, export, phpmyadmin"
} |
wordpress prevent multiple shortcodes
I created a wordpress plugin and I added shortcode feature to it. but i want to execute only one shortcode and prevent applying of multiple shortcodes if the administrator did so. | Just remove the shortcode during the first call.
add_shortcode( 'foo', 'foo_shortcode_handler' );
function foo_shortcode_handler()
{
remove_shortcode( 'foo' );
return 'bar';
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugins, shortcode"
} |
Is there any fundamental difference in developing a wordpress multi-network site?
I would really like to know: Is there any fundamental difference in developing a multi-network site as opposed to a normal wordpress site?
More Specifically:
1. Is the wordpress plugin development process the same?
2. Is theming the same? Can I use common AND separate stylesheets?
3. Will my old WP queries continue to work the same across the site network?
4. Can I expect popular wordpress plugins for taxonomies, custom fields and custom posts to work seamlessly across the network?
5. Can I create custom post types that are unique to each network?
I am completely new to multisite but am totally game with the single wordpress install. Would really appreciate guidance from this community. | Essentially, a WordPress network is number of almost totally unique sites which answers most of your questions: you can proceed as you normally would.
The network allows you to share the database and file system, but each site is unique and the only main feature shared between each network site is the user system.
To answer each question though:
1. Yes -- however, you can create network-specific plugins that do some things at the network level, rather than simply network activating a plugin (a new instance for each site)
2. Yes
3. Yes
4. Yes
5. Yes -- each post type is necessarily unique to its site | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 3,
"tags": "multisite"
} |
Google Map Integration
I want to create a Interactive google map as per < .. I just wanna ask if I can do that using wordpress plugin, or can I have that kind of fucntionality even without using wordpress plugin? but how?.. here are the details..
any tip please.. do I have to do to manually or there is an easy way for me to be able to do that.. please help me :) | I'm not sure to understand what you want here...
You want something like yelp on the right? ( here )
That will update the website when you change your map boundaries?
Edit: I think you should look at this plugin . Is it this? | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "google maps"
} |
How to Add Author Editing Capability to Existing Post by Admin
I apologize if this is mentioned on here but I can't find any information!
Anyway, I am building a WordPress site where I created the content with my administrator account. However, once the site is launched there are going to be 10-15+ Author accounts in order to manage a single custom post each.
Is there any way that I can create a new account, and add author capability to a post which already exists but is not created by them?
Or is there a way I can change the author on an existing post from the admin account to the newly created one? | There's a capability that's named `edit_others_posts`, that you can assign to users or roles. But there's also an easier way to do this: The (by default) hidden "Author" meta box.
### How-to change the author of a post
 | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 7,
"tags": "admin, updates, activation"
} |
Stop auto formatting in shortcodes
Is there a way I can stop Wordpress auto formatting everything I enter inside a shortcode tag?
A the moment I want to include a h2, a paragraph and another shortcode, but everytime I do Wordpress wraps each different elemnt in p tags.
Is there a way to remove this so I can format each part individually? | You can postpone the `wp_autop` filter which is responsible for wrapping elements in P tags till after shortcodes are rendered:
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 12); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "shortcode, formatting"
} |
query_posts call sets is_home() to true
I have a custom home page (`home.php`). I want to show the original home page's posts on `/blog/`.
I created a new blog.php file, with Template Name: Blog, added
query_posts('numberposts=5&paged=' . get_query_var('paged'));
require dirname(__FILE__) . '/index.php';
to the file.
The problem is that this `query_posts` call sets `is_home()` to true. I have some code in `header.php` that needs to be run only on the home page, but it runs on this template's pages too.
What's the best way to do this? | Don't do it this way. `query_posts()` should not be used most of the time and you are really hacking things up here with direct template inclusion and such.
1. Create new page _Blog_ (no template).
2. Go to `Settings` > `Reading`.
3. Assign this page as `Posts page`. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "query posts"
} |
If taxonomy exists then to show some code
I want to insert following custom code in single.php can I set condition that if specific taxonomy exist then show and work this code otherwise not;
<div id="archivebox"> All courses in<?php echo get_the_term_list($post->ID,'country', ' ', ' ', '' ) ; ?><br>All courses in<?php echo get_the_term_list($post->ID,'institute', ' ', ' ', '' ) ; ?><br>All <?php echo get_the_term_list($post->ID,'subject', ' ', ' ', '', '' ) ; ?> courses worldwide<br>All<?php echo get_the_term_list($post->ID,'qualification', ' ', ' ', '' ) ; ?> courses worldwide<br>Alphabetical List: <?php echo get_the_term_list($post->ID,'alphabetical', ' ', ' ', '' ) ; ?> worldwide</div> | If you want to check for the _existence_ of a taxonomy, use `taxonomy_exists( $taxonomy )`:
<?php
if(taxonomy_exists('country')){
echo 'All courses in' . get_the_term_list($post->ID,'country', ' ', ' ', '' );
}
?>
etc...
### Edit
If, instead of checking for the _existence_ of a taxonomy, you want to check if the _current post belongs_ to a taxonomy, use `get_the_term_list( $post->ID, $taxonomy )`:
<?php
if( false != get_the_term_list( $post->ID, 'country' ) ) {
echo 'All courses in' . get_the_term_list($post->ID,'country', ' ', ' ', '' );
}
?> | stackexchange-wordpress | {
"answer_score": 8,
"question_score": 2,
"tags": "custom taxonomy"
} |
Custom page html headings plugin?
Does anyone know of a plugin that lets you customize the heading area of each page or post with HTML? The heading area I refer to is directly above the main post content. An example is on <
If you look in chrome developer tool or firebug, this div tag is their page-heading, below this is the main content area. For each page on their site it's unique. | You could use a simple custom field and have it displayed on the page template. Assuming you name the custom field "page-heading" this could help you:
<?php query_posts(); ?>
<?php if(get_post_meta($post->ID, 'page-heading', true)): ?>
<?php echo get_post_meta($post->ID, 'page-heading', true); ?>
<?php else : ?>
Normal content
<?php endif; ?>
You should be easily able to add this to the page template or to a new template according to your need. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "custom header"
} |
Setting up menus before making a template live
I'm currently creating a new template for a client. Their current template does not implement menus at all. They are all hard coded links in the template. The new template I making them will implement the menu functionality. Their menus are fairly extensive (around 50 links). Since the menu option does not currently show up on the existing theme, how can I go about adding all the menus before I make the new template live for all visitors? I really want to minimize downtime. I know I could just take the site offline, but that's not really an option for me. | All you need to do is enable custom menu's by creating a functions.php in your current theme, and or if it already has a functions.php file, you just need to add this:
add_theme_support( 'menus' );
And you will be able to add menus before making them live. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "menus, templates"
} |
Is it possible to allow BP Group Admins to Set which Menu Tab they would like to have as their Default landing page?
Is it possible to allow BP Group Admins to Set which Menu Tab they would like to have as their Default landing page when people enter their Group like Activity Stream or Documents etc? | You can do it programmatically like this: What's the easiest way to change the default landing page for BuddyPress groups?
The answer there could be expanded into a plugin that would provide a UI for group admins (and a means of storing preferences on a group-by-group basis), though this would take a bit of engineering using the BP Group Extension API: < | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "buddypress, tabs"
} |
I have a widget area in my header. How can I have that display a different widget depending on what group is shown?
I have a widget area in my header. How can I have that display a different widget depending on what group is shown? So if uses are in a group about say Baseball in the site Header in my theme the Widget on Baseball shows up but if the user is in a group on Golf then the header shows a widget I have for Golf? Can this be done? | You could install widget logic and add something like `bp_is_groups_component() && 'your-group' == bp_current_item()` in a widget's widget logic area.
The widget logic content filter feature looks like it could create something a bit more sophisticated than the above | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "widgets, buddypress"
} |
Does a reply to a wordpress comment notify the author of the comment?
Currently I have my comments set so that when you hit "reply" to a comment, it will insert `@USERNAME` of the person you are replying to. I am trying to find out if wordpress emails that user to let them know that I have replied to a comment they left or if this is something I will have to manually code in? | It doesn't automatically send out emails. You can install a plugin to do that, however. There are quite a few listed in the WordPress plugin repository:
<
Hope this helps, best of luck! | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 4,
"tags": "comments"
} |
How to use ajax to get multiple outputs?
jQuery.ajax({
type: "POST",
url:"wp-admin/admin-ajax.php",
data:'action=nafham_list_cats_selection&selection_id=' + $selection_id,
success:function(results){
jQuery(".semester_selection").empty();
jQuery(".semester_selection").prop('disabled', false);
jQuery(".semester_selection").append(results);
}
})
This is the ajax call I'ms ending, the following is the function that sends the data:
function nafham_list_cats_selection() {
if(isset($_POST['selection_id'])){
nafham_get_listed_cats($_POST['selection_id']);
}
}
How can I let the function outputs two values so that I can use
success:function(results1, results2){ | Instead of passing two parameters to function you can pass the array of two values like this :
$results['args1'] = "value1";
$results['args2'] = "value2";
echo json_encode($results);
and then get it in success function like this :
success:function(results){
jQuery(".semester_selection1").append(results.args1); // This appends value1
jQuery(".semester_selection2").append(results.args2); // This appends value2
} | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "ajax"
} |
Wordpress plugin for mail subscriptions
I'm working on a news site built with Wordpress, and I now want to add a page for subscriptions. This will be paid subscriptions for the **printed paper that people can get delivered to their home**.
My question is: is there a Wordpress plugin already created for this (free or paid)? I wouldn't really want to re-invent the wheel. Maybe I could somehow use one of the many Wordpress shopping cart solutions?
If not (which I suspect to be the case) how would I go about doing it on my own? I have no problem coding this up as a standalone application. I'm just not sure of how exactly to integrate it into the Wordpress admin area. | You can use this plugin < | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 2,
"tags": "plugins, plugin development, plugin recommendation, subscription, email"
} |
settings api and the data passed in the parameter
in an example of the Settings API, there's an input and the callback function to sanitize/validate the result from this input :
this is the input :
echo "<input id='text_string' name='boj_myplugin_options[text_string]' type='text' value='$text_string' />";
and this is the callback function :
function boj_myplugin_validate_options( $input ) {
$valid['text_string'] = preg_replace( '/[^a-zA-Z]/', '', $input['text_string'] );
i read that this function is passed the $_POST data as a parameter, but what does `text_string` stand for here : `$input['text_string']` ?
i'm a bit confused, it should be the `name` parameter, but the name parameter seems to be a plain text : `name='boj_myplugin_options[text_string]'`
Thanks for your answer | You sanitization callback function get passed all the values that correspond with the setting name. When a POST request is made to the `options.php` file from the page on which your settings resides, WordPress calls your sanitization callback in a way that would resemble this:
<?php
boj_myplugin_validate_options( $_POST['boj_myplugin_options'] );
Notice that the name attribute looks mysteriously like indexing an associative array: `boj_myplugin_options[text_string]`.
This sets up `$_POST['boj_myplugin_options']` as an array. But, as you can see above, WordPress doesn't pass the entire `$_POST` array into your sanitization callback: it just passes the values related to your plugin. Doing it this way allows you to store multiple values in the same option. You don't always do that, but it's fairly common. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "settings api, sanitization"
} |
When I try and use contact form 7 it breaks my page
I am using the following code to add a contact form to my template, but this code as is breaks the page. It just shows a white page when I add this code. Am I doing it wrong.
<?php
[contact-form-7 id="181" title="Contact form 1"]
?> | Well without more code it's hard to tell but one thing is you are wrapping a shortcode with php tags. My guess is you have error logs turned off or you'd see `Santax error unexpected '[' on line XXX`
If you are using the post/page editor you want to use`[contact-form-7 id="181" title="Contact form 1"]` (see no php tags)
If you really want to use php tags (or embed the form into a template) you could do something like
`<?php echo do_shortcode( '[contact-form-7 id="181" title="Contact form 1"]' ); ?>`
If that doesn't help please post more code. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "plugin contact form 7"
} |
Is the '/category/post-name-date/' permalink structure okay?
> **Wordpress Codex says:** Make sure to end your structure with either `%post_id%` or `%postname%` (e.g. `/%year%/%monthnum%/%day%/%postname%/`) so that each permalink points to an individual post.
But I would like to set my website's permalink structure (to suite the Google News URL guidelines) like this: `/%category%/%postname%-%year%%monthnum%%day%/`
So, an example URL would look like this:
_<
But this permalink structure appears to be against the quote from WP codex. Do you see any problems with my custom permalink structure? Please advise. | In a word, No. As long as you have `%postname` somewhere in there you should be fine. Having it at the end, beginning, or middle shouldn't matter. Although the Codex is a great resource it's also edited and written by other WordPress users. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "permalinks, codex"
} |
Rewrite-Rules not working on a vhost, everything goes to index.php
after setting up the wordpress htaccess rules in my vhost, i was unable to enter the wp-admin area. I was always redirected to the frontpage of my wordpress instance.
The rewriting itself worked on the mainpage. All links worked so far, but the admin area remains without any access.
Rewrite rules used:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Personally i dont know where to start looking, im even unable to find that problem over google, which is kinda rare - maybe someone over here knows where the problem is to be located. | OK, so the initial Problem was: `How to get the Rewrite Rule working at a VHOST Environment` and the answer - if unknown - was a little tricky. RewriteBase doesn't work on a VHOST. The Solution is to put all those Rewrite-Stuff at a Directory-Section like this:
<VirtualHost *:80>
ServerName www.mydomain.tld
...more config stuff...
<Directory "/var/www/mydomain">
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</Directory>
</VirtualHost>
Then it works. I'll be updating the questions title for better google results in the future. Hope this may help anyone running into the same troubles. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "permalinks, redirect, rewrite rules, virtual hosts"
} |
Best structure / rewrite rules to achieve the following url
I have been trying to achieve the following url structure in Wordpress and maintain a level of reusability in the admin area.
It is for a client preview area and needs to reflect multiple versions of different file types.
So the desired URL structure would be:
<
/client-name/ is a dashboard view showing links to /wireframes/ as well as /mockups/ or anything else that is a design phase.
/v1/ relates to the version number of /homepage/
The easiest way is to use pages and sub pages but there must be a better way. More of a CMS way. Maybe there isn't. Perhaps Wordpress is the wrong choice for this. | My gut feeling is that you want to use custom taxonomies for part of this. So client-name would be one taxonomy (flat), version would be another taxonomy (also flat). Wireframes might a post type or a taxonomy, not sure what makes sense for you. A little googling led me to the following links, that you might be able to shake and bake into something useful.
I agree that pages and sub-pages would be a cumbersome way to achieve this, since you'd need to recreate the tree structure for every client. With custom taxonomies, you'd create the structures once and re-use them.
* How can I rewrite URLs to pass taxonomy and post type values to the query?
* <
* <
* < | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "custom post types, urls, rewrite rules, customization"
} |
Edit "thank you for creating with Wordpress" in version 3.3.1
Is there a way to edit the text "thank you for creating with Wordpress" in version 3.3.1 at the bottom of the CMS? If so what file do I need to edit? | Credit definitely goes to @kaiser, but here is a full working solution. You can add this code to your functions.php file (in your theme):
function wpse_edit_footer() {
add_filter( 'admin_footer_text', 'wpse_edit_text', 11 );
}
function wpse_edit_text($content) {
return "New Footer Text";
}
add_action( 'admin_init', 'wpse_edit_footer' ); | stackexchange-wordpress | {
"answer_score": 13,
"question_score": 10,
"tags": "admin, cms"
} |
Permissions for installing themes and files in general?
www.net2ftp.com shows my permissions to be
rwxr-xr-x
for the top level directory which I aptly named wordpress ( test site ).
This would be for ( user | group | other ) and ( read | write | execute ) so that I have write permissions if I am " user ".
I am of course logged into wordpress with the only account that was setup at the beginning of the installation process.
Because wordpress would not install unless I copy pasted the config file over manually...it seems it differentiates between manual editing of files and software copying/editing of files.
Not to sure why?
When I do an install I get the error:
Unable to create directory /home/domain/public_html/wordpress/wp-content/uploads/2012/03. Is its parent directory writable by the server? | This is more of a system configuration question, but still ...
On the server, everything is locked down based on users and user permissions. You are a user. Your FTP account is a user. Your root account is a user. WordPress itself is a user.
So while _you_ as a user might have write permissions for the WordPress directories (which is why you can manually upload files), WordPress might not have write permissions and won't be able to add/edit its own files.
There is more information about file permissions located in the Codex, but I highly recommend you ask a system administrator (someone with plenty of Linux experience) to check to see which users have write permission and which user WordPress is running as. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "themes, installation"
} |
Allowing users to add HTML to BP Groups Description how can I error check html of users?
I am trying to modify the Group Description field on Buddypress Groups so that they can take HTML but Buddypress has filters to prevent this.
I used this;
remove_filter( 'bp_get_group_description', 'bp_groups_filter_kses', 1 ); remove_filter( 'groups_group_description_before_save', 'wp_filter_kses', 1 );
These are the filters applied: < I experimented with removing them and was able to get the form to accept HTML.
BUT, the problem is if someone enteres broken html and leaves a closing tag out for example it breaks the page. I put it in protective Tags so the page wont break but the form itself can be broken with bad html being used in the form.
So my question is, is there a way to do error checking on the html and prevent open tags and bad code from being submitted?
Thanks! | The key filter is `force_balance_tags`. Don't remove that one, as it's responsible for making sure that HTML tags are closed. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "buddypress, html, description"
} |
How to show multiple images in a slideshow for a portfolio page
I am planning to build a portfolio using custom post types, so the main portfolio page will show a "featured" image for each portfolio post. Once you click on one of these images you will go to the actual post page for that portfolio item.
Once on this page I would like to show multiple images for this particular portfolio post. So I am thinking of doing some sort of slideshow or possibly a big image with little thumbnail images that when clicked will load the larger version of the image into the big image slot.
So I am curious, when making a post for a portfolio item, how would I go about uploading and integrating multiple images for each item?
See the bottom of my mockup below, when you click on a thumbnail for a particular portfolio item, it will load a larger image
!enter image description here | A simple solution would be to use the featured image (post thumbnail) as image for the portfolio listing and for the item itself you can use the native gallery with its shortcode: `[gallery]`.
Also if you'd like to use some kind of lightbox with it you can look/use the plugin **`jQuery Lightbox For Native Galleries`** | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "custom post types"
} |
show list of latest comments for each post in a loop
I want to show the last 5 comments for each post on my index page loop of posts. What Im using now is only showing the same comments for every post. How should I set this up and how can I add an avatar to each comment.
What have this obviously isn't working..
<?php
$args = array(
'status' => 'approved',
'number' => '5',
);
$comments = get_comments($args);
foreach($comments as $comment) :
echo( $comment->get_avatar . $comment->comment_author . '<br />' . $comment->comment_content);
endforeach;
?> | You should place your code inside the loop and add to the `args` array `'post_id' => get_the_ID()` so it should look like this:
while(have_posts()){
the_post();
//your post loop output
$args = array(
'status' => 'approved',
'number' => '5',
'post_id' => get_the_ID()
);
$comments = get_comments($args);
foreach($comments as $comment) :
echo( $comment->get_avatar . $comment->comment_author . '<br />' . $comment->comment_content);
endforeach;
} | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "avatar, comments"
} |
dynamic page not indexed
Im writting a plugin who makes dynamic pages with simple page template:
<
the url is rewriting so internally call to <
and works, but the problem is, how I can index it to make searches?
Any ideas? | Do you have at least have a link to the query url somewhere on your public pages ?
Google does follow query parameters, so that will at least bring it to the crawlers attention.
See <
(I almost have the opposite with my event/calendar plugin. google is paying almost too much attention to the pages and their date query parameters (moving forward in time etc). See notes on that here < )
Other good seo stuff will then help. Sitemaps etc
Also see if you can improve the markup on the page - if about people, then maybe some people microdata will help google index the page .(my plugin's html does event rich snippets) see Rich snippets - People:
| stackexchange-wordpress | {
"answer_score": 1,
"question_score": 3,
"tags": "plugins, search"
} |
What to hook into to check a value before a post is published?
My website is set up with pages as categories, meaning that if a user publishes without choosing a category, no one can see the post unless they know the specific address.
What do I need to hook into in order to check if a category is chosen after the "publish" button is pressed but before the post is published publicly? | Try
function wpse46583_save($post_id,$post) {
// verify this is not an auto save routine.
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
//You should check nonces and permissions here
if ( !current_user_can( 'edit_page', $post_id )
return;
//Get category slugs associated with post
$cats =get_the_category($post_id);
if(empty($cats)){
//No category assigned - do something here.
}
return;
}
add_action('save_post','wpse46583_save',10,2); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugin development, api"
} |
Different style for most recent article
I'd like to make my most recent article display a large with a larger thumbnail and with more content, while the rest of the posts in the loop show a small thumbnail and only the title with no content.
Is there a way I can do this in one `while(have_posts())` loop? | check the built in counter `$wp_query->current_post` within the loop:
<?php
while( have_posts() ) :
the_post();
if( 0 == $wp_query->current_post ):
// this is the first post in the loop, output larger size, full content, etc.
else:
// output regular size, the_excerpt, etc.
endif;
endwhile;
?> | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "posts, loop"
} |
Overwrite default XMLRPC function from plugin
I want to overwrite the "metaWeblog.newMediaObject" xmlrpc call so the file is saved remotely. From mw_newMediaObject in class-wp-xmlrpc-server.php, i see that there is a hook:
do_action('xmlrpc_call', 'metaWeblog.newMediaObject');
So I should be able to do something in my plugin like:
add_action ('xmlrpc_call', 'myWewMediaObject');
function myWewMediaObject ($method) {
if ($method=='metaWeblog.newMediaObject') {
//perform some custom action
}
}
However, since the do_action call is at the beginning of the mw_newMediaObject function, I am unsure how to stop the execution after my plugin function exists.
Please let me know if I am on the right track and if there is another way to do this. | Actually, that hook just lets you tie in to the beginning of executing that function, it doesn't let you override anything.
If you want to replace this function entirely, I recommend two different options:
# 1\. Don't use it
Just define your own XMLRPC method (`myNamespace.newMediaObject`) and call that instead.
# 2\. Replace it
You can tie in to the `xmlrpc_methods` filter the same way you would to add a new method and can replace the callback for `metaWeblog.newMediaObject`:
add_filter( 'xmlrpc_methods', 'myMediaHandler' );
function myMediaHandler( $methods ) {
$methods[ 'metaWeblog.newMediaObject' ] = 'myMediaObject';
return $methods;
}
function myMediaObject( $args ) {
// ... custom functionality
}
Just be sure to maintain the same format with the $args array and to call/apply the same actions/filters in your custom method so that you don't run into any surprises. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 2,
"tags": "plugin development, xml rpc"
} |
Use one Wordpress database with multiple instances of one site
Is there a way to use the same database, tables and all, with two different domains? For example, two employees each have thier own subdomain to develop / test with, so there may be two instances of a site:
jack.example.com/test_blog/
jill.example.com/test_blog/
however, since the base url is stored in the database, it seems that it would require two distinct databases for this set up to work properly. Is there any way around this? | Turns out that instead of relying on the Database for a URL, you can set it in the config file, which solves the problem I was having, like so:
define('WP_SITEURL','
and then I set use a different config file for the other instance.
soruce: < | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 1,
"tags": "database"
} |
I keep getting logged out in Firefox
For some reason, tonight when I have gone to work on my Wordpress installation I firstly found myself logged out, even though there was a few cookies left in Firefox relating to the website and when I looked on the Simple:Press forum it had remembered my user name but knew I wasn't logged in. Nevertheless, I logged in again and it worked perfectly... until I navigate to a different page when it seems as though I never logged in; furthermore if I try to go directly to the Admin Dashboard from the page when it says I am logged in, it asks me to login again and the URL says `reauth=1` at the end.
Strangely, this only occurs in Mozila Firefox and it works perfectly on the same computer using Internet Explorer! Also, I can recall me doing anything to the installation yesterday for it to invoke this kind of behaviour today!
Any ideas would be much appreciated. Thanks In Advance. | This will happen occasionally on both Firefox and Safari when cookies don't match. Sometimes, WordPress will store an auth cookie and, for some reason, won't read data back out of it. This leaves you in a weird place of being semi-logged-in.
If you flush your cookies for the site, it should rectify the problem. Either delete the cookies manually via Firebug or tell FireFox to delete all cookies (either globally or just for the site), then log back in. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "admin, wp admin, login, logout"
} |
Child Theme: how to override variables?
I'm going to build my first Child Theme. I understood how to override functions (hope!), but how to override variables? For example, in a Premium Template I want to change the values of feed variables shown in functions.php:
$app_rss_feed = '
$app_twitter_rss_feed = '
$app_forum_rss_feed = '
But if I create my functions.php file inside my child theme and assign a different RSS feed value to these variables... nothing happens. So, which is the right way to change variables? | I'm mobile, so this will be short.
Use the after_setup_theme hook to add a function to set those variables. Declare them as global inside that function before setting them.
Hope that helps.
If anybody wants to add an example to this answer before I get home, feel free. ;) | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 4,
"tags": "templates, feed, child theme"
} |
Naming conventions when using (PHP5) namespaces?
Provided you are working on a php 5.3+ only package what are the namespace conventions when it comes to plugins
Funky_Monki\Banana_Blogger_Plugin\Admin::Banana_Tosser
Plugins\Funky_Monkey_Banana_Blogger\Admin::Banana_Tosser? | There are no such conventions for WP. But I would recommend to use such style:
Plugins\Your_Company\Your_Plugin\Your_Component\Your_Class | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "plugin development"
} |
How to create a language selection homepage?
I have a projects that needs a homepage similar to this one. I know there are many multi-language plugins out there. Here's exactly what I need:
if isHomepage and noLanguageSeleted
show selection page
else
show the actual page content in the sleeted language.
show all the links and menus in the selected language.
How and with the help of what plugin would you achieve this?
Thanks! | The absolute best plug in for this is WordPress Multi Lingual (WPML). I have used this on multiple sites, it works like a charm!.. and it provides excellent documentation for custom theme builders :)
Are you using a free theme? a paid premium theme? or are you building you own theme? If you are building your own you need to make sure the theme uses the GetText wrapper on all strings.
This plugin is not free, but it is absolutely worth the price! this plugin saves you allot of hassle. Plus you get unlimited updates. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugin recommendation, homepage, multi language"
} |
Why set a second parameter in the translate function?
The second parameter in the translate function is optional, but I always see people use it and some don't.
So I want to know if I should use it or not and if yes, how I will use it later.
I asking this because I'm new to this, and I'm using _e() and __ () right now in my theme, and I'll learn how to translate it when I finish.
Thanks in advance | Welcome to WPSE Peter,
The second argument is a _translation domain_. This is essentially where the translation for the first argument can be found. By default it checks the WordPress language folder - but if you are creating a custom theme or plug-in, you cannot rely on the translation for that string to be there (after all the WordPress language folders only contain translations for WordPress, not your plug-in/theme).
The setup is different for plug-ins, but to register a text domain for themes you use `load_theme_textdomain`:
add_action('after_setup_theme', 'my_theme_setup');
function my_theme_setup(){
load_theme_textdomain('my-unique-theme-domain', get_template_directory() . '/languages');
}
The first argument is the domain name, which is passed as the second argument in `_e()` and `__()`. The second is where the translation files can be found.
See Codex for `_e()` and `__()`. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "theme development, translation"
} |
a plugin to share a post to social networks via admin?
I'm not looking for a share this post button for the front end.
I've seen a couple of similar topics here but not exactly what I'm after.
What I would like is a plugin which offers the options in the admin panel to post a link my post to a facebook page, tweets it, perhaps takes the images and sends to flickr and so on. Something which would offer me some controls and configuration to make the oauth connections and then gives me extended sharing features when I make a new post.
Has anyone seen anything like this? I'm a bit overwhelmed when I look through the plugin directory searching for social plugins...
Thanks for any help whatsoever.. | What about Network Publisher?
Supports 25 networks, probably all you need.
Worth noticing: It uses a third-party service LinksAlpha. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugin recommendation, admin, wp admin, facebook"
} |
How can I create a smarter .htaccess file that will add a directory?
This is my current .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) /directory/ [R=301,L]
And "directory" is where my wordpress install is. So this simply redirects people from the root domain to the directory.
What I would like to do is create it so any information added to the url is passed through when the directory is added. SO ` becomes `
I know this is probably a snap for someone with more experience with regular expressions. Unfortunately I haven't been able to track down the info with standard web searches. Appreciate the help... | Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) /directory/$1 [R=301,L]
< look at "backreferencing" | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "htaccess, mod rewrite"
} |
Change page title from plugin
Is possible to change page title on the fly from plugin?
I've try global $post, but seem like plugin runs after.
Any Ideas?
Edit: Im writting some pages on the fly, based on same page / post, so every page show the same title. Looking a way to do via shortcode or writting my own plugin/function | There's a filter for that:
function wpse_alter_title( $title, $id )
{
// $id = $post->ID;
// alter the title here
return $title;
}
If you want to alter the "Protected" and "Private" titles, then you need other filters:
// Preserve the "%s" - else the title will be removed.
function wpse_alter_protected_title_format( $title )
{
return __( 'Protected: %s' );
}
function wpse_alter_private_title_format( $title )
{
return __( 'Private: %s' );
}
Last but not least, you must add your filter callbacks early enough.
function wpse_load_alter_title()
{
add_filter( 'the_title', 'wpse_alter_title', 20, 2 );
add_filter( 'protected_title_format', 'wpse_alter_protected_title_format' );
add_filter( 'private_title_format', 'wpse_alter_private_title_format' );
}
add_action( 'init', 'wpse_load_alter_title' ); | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 3,
"tags": "plugins, title, init"
} |
Recovering WP Login Credintials in Code?
Is there anyway to recover login credentials to Wordpress admin through the code somewhere?
I just tried wp-config. I'm asking because my email is not primary on the account so using 'Forgot Password' wouldn't help much as I need to get in now?
(I have FTP / Host access.) | You can do that via the database but you should
**be carful and backup the database befoure any changes are done**
first here is a link to md5 encoder (youll need it): MD5 Encoder
!change password in the mysql
Hope this help...
Sagive | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "php, login"
} |
Wordpress stripping out custom field tags
I am using wordpress get post meta to store the value of a custom field into a variable. In this particular instance, It is actually grabbing the post's parent's custom field due to the `$post->post_parent` Here is the code:
<?php $cast_members = get_post_meta($post->post_parent, 'cast_members', true); ?>
<p><?php echo $cast_members; ?></p>
<?php endif; ?>
The custom field cast_members is a series of cast members, each in its own paragraph. For some reason wordpress is stripping out the paragraph tags and displaying all of the cast members in a continuous string. I need to retain those paragraph tags so each cast member is on its own line. Any idea why `get_post_meta` strips out tags and how to fix it? | Change above code to like this:
<?php $cast_members = get_post_meta($post->post_parent, 'cast_members', true); ?>
<p><?php echo wpautop($cast_members); ?></p>
<?php endif; ?>
in this code wpautop() function automatically adds p tag for cast members. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "php, custom field, post meta"
} |
Is there a way to give users the option to log in to their favorite group on login?
Is there a way to give users the option to log in to their favorite group on login? So if a user belongs to say half a dozen groups I can show those groups on the login with some sort of drop down menu and have a checkbox they can tick off to select the Buddypress group they want to log directly into. | +1 to what @Bainternet said.
The only way I can imagine is if you used some ajax on the username field, so that when a username was entered (on `blur` maybe), a request would be sent to get that user's groups. I would never do this, however, as it would allow anyone to look at a list of a user's groups merely by typing their name into the login field, which seems to me a pretty serious privacy concern.
You could, without too much trouble, have a user setting that would allow a user to specify the group that he/she would like to be redirected to upon _every_ login. You'd use the `login_redirect` filter hook to do the magic. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "login, buddypress"
} |
Get only the path from a function like previous_post_link
I want to use something like `previous_post_link('%link','',TRUE )` and put the path into a javascript variable.
So using something like
`var previous = "<?php previous_post_link( '%link','',TRUE ); ?>";`
outputs :
`<a href=" rel="prev"></a>`
but instead I only want the path output in that variable.
`
I like this function because it allows you to remain in category so I am hoping for a solution where I still can easily have that as an option. | Add following function in your functions.php file.
function custom_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
if ( $previous && is_attachment() )
$post = & get_post($GLOBALS['post']->post_parent);
else
$post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
if ( !$post )
return;
$link = get_permalink($post);
$format = str_replace('%link', $link, $format);
$adjacent = $previous ? 'previous' : 'next';
echo apply_filters( "{$adjacent}_post_link", $format, $link );
}
and instead of calling previous_post_link('%link','',TRUE ) function call it as custom_post_link('%link','',TRUE ) and it will output the path as following
| stackexchange-wordpress | {
"answer_score": 4,
"question_score": 1,
"tags": "navigation"
} |
One time username change from frontend?
I'm using facebook connect plugin.
Usernames generated by that plugin look like firstname_lastname. I mean it looks ugly.
I would like to give the privilege to my users to change the username **BUT ONCE**.
I hope its like changing the password.
Here is my change password function.
Can anyone help me to modify it?
Thanks | Just add a meta record that tracks the state of the username-changing actions:
$user = wp_get_current_user();
$did_one_change = get_user_meta($user->ID, 'changed_username', true);
if($did_one_change !== false)
wp_die('You already changed your user name once!');
wp_update_user(array(
'ID' => $user->ID,
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
));
// here add a meta entry that suggests the user has changed their name once
update_user_meta($user->ID, 'changed_username', 1); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugin development, privileges, username"
} |
Remove tabs from media uploader for a CPT
I use the media uploader in a own meta-box for a custom post type called "premium". The Thickbox opens after a click of the button in the meta-box and files can be uploaded.
Now I want to remove the tabs "From URL" and "Library" only when used the uploader in the edit/new-page for the CPT or if possible with the call of the click-event.
I have no idea how to resolve.
P.S.: I use this js for calling the thickbox and tried to remove a tab via jQuery:
jQuery(document).ready(function() {
jQuery('#pc_extContent_button').click(function() {
formfield = jQuery('#pc_extContent').attr('name');
tbframe_interval = setInterval(function() {
jQuery('#tab-type_url').hide();
}, 2000);
tb_show('', 'media-upload.php?type=file&TB_iframe=true')
return false;
}); | You can use the `media_upload_tabs filter` check for your post type and unset any tab you don't want ex:
function remove_media_library_tab($tabs) {
if (isset($_REQUEST['post_id'])) {
$post_type = get_post_type($_REQUEST['post_id']);
if ('premium' == $post_type)
unset($tabs['library']);
unset($tabs['type_url']);
}
return $tabs;
}
add_filter('media_upload_tabs', 'remove_media_library_tab'); | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 3,
"tags": "custom post types, metabox, uploads, tabs"
} |
Localiztion in javascript
Wordpress currently uses the `gettext` feature which is available in `php` but unfortunately not in `Javascript`.
I have searched this matter on the web and have come up with this trick. But there is a problem as the php file needs to be called through `Wordpress` system for the `gettext` feature to kick in.
I'm wondering if there is any way to call a php file inside Wordpress so we can use the built-in functions and variables?
Or if anyone can come up with a better solution, that'd be super. | WordPress has a nice function mainly for that **wp_localize_script**
To use it first queue your script:
wp_enqueue_script( 'My_Script_handle', 'path/to/script.js' );
then create an array of strings you want to localize:
$data = array(
'exit' => __( 'Exit','my-plugin-domain' ),
'open' => __( 'Open','my-plugin-domain' ),
'close' => __( 'Close','my-plugin-domain' ),
'next' => __( 'Next','my-plugin-domain' ),
'previous' => __( 'Previous','my-plugin-domain' )
);
and call it using wp_localize_script
wp_localize_script( 'My_Script_handle', 'mystrings', $data );
then you can access it in the page using JavaScript like this:
alert(mystrings.exit);
alert(mystrings.open);
...
you get the Idea. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 1,
"tags": "plugins, javascript, localization"
} |
Exclude specific taxonomy term when using wp_get_post_terms
i have a single-post_type.php file where i constructud a breadcrumb (or similer to)
**i am currently using this to get the terms of this taxonomy:**
$terms = wp_get_post_terms( $post->ID, 'wedding_cat');
.
**Later on i am showing that term like this:**
<div class="breadcrumbs"><?php $term = array_pop($terms); echo '<a href="'. get_bloginfo('url') .'">'. __('Home', 'sagive') . '</a> » <a href="index.php?page_id=74">'.__('Wedding Rings', 'sagive').'</a> » <a href="'.get_term_link($term->slug, 'wedding_cat').'">'.$term->name.'</a>,'?></div>
That way i am only getting one term which is gr8 but..
i need to exclude a specific term comepletly from apearing.
How can i do that? | I'd use `wp_list_filter()` with the operator 'NOT' to compare either the term's name, slug or ID (depending how you want to test for term to be exluded).
Untested but something like this should work (assuming that you want to exclude the term with slug 'myslug'):
$terms = wp_get_post_terms( $post->ID, 'wedding_cat');
$terms = wp_list_filter($terms, array('slug'=>'myslug'),'NOT');
(Of course this may mean `$terms` because empty). | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 1,
"tags": "custom post types, taxonomy, exclude, advanced taxonomy queries"
} |
Why would post_type be ignored in this query?
In the following query, post_type seems to get ignored resulting in display of all posts from my installation. What have I done wrong?
<?php
function filter_where( $where = '' ) {
$where .= " AND post_date > '2009-03-01'";
return $where;
}
add_filter( 'posts_where', 'filter_where' );
$posts = query_posts( '&showposts=-1&post_type=listings' );
remove_filter( 'posts_where', 'filter_where' );
echo '<ol>';
foreach ($posts as $post) {
echo '<li>' . get_the_title() . '</li>';
}
echo '</ol>';
?> | Check if your post_type is exactly `listings` and not `listing`. Also check this approach:
<?php
function filter_where( $where = '' ) {
$where .= " AND post_date > '2009-03-01'";
return $where;
}
add_filter( 'posts_where', 'filter_where' );
function parse_wp_query( $query ) {
$query->set( 'post_type', array( 'listings' ) );
return $query;
}
add_filter( 'parse_query', 'parse_wp_query' );
$posts = query_posts( 'posts_per_page=-1&post_type=listings' );
remove_filter( 'posts_where', 'filter_where' );
remove_filter( 'parse_query', 'parse_wp_query' );
echo '<ol>';
foreach ($posts as $post) {
echo '<li>' . get_the_title() . '</li>';
}
echo '</ol>';
?> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "query posts, post type"
} |
How do i get the attached images with custom value checked?
I have added a custom field to the image attachement. When this custom field is checked the image will be part of a carousel on the home page. Now i am able to get the custom field to work and save the selected value, but how do i query the database so only the post with the custom field checked will be selected and their parent post.
In the end i want a shortcode with output like:
<a href="link-to-permalink-post"><img alt="attachment-title" src="img-src-link"/></a>
<div class="caption"><p>attachment-title</p></div>
I think in need to use get_post_meta but how?? | <?php
$args = array( 'post_type' => 'attachment',***'meta_key'=>'your meta key','meta_value'=>'your meta value',*** 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID );
$attachments = get_posts($args);
if ($attachments) {
foreach ( $attachments as $attachment ) {
echo apply_filters( 'the_title' , $attachment->post_title );
the_attachment_link( $attachment->ID , false );
}
}
?> | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "custom field, post meta"
} |
Registration Page
I've recently installed a wordpress network to my website and i'm stuck with a huge problem! my default blog now redirects to the signup form automatically and not the blogs home page.
I have set the static page in the reading settings, and disabled registrations.
it still redirects to
domain.com/wp-signup.php?new=domain.com
and it should go just to domain.com
is there an easy way of stopping this from happening?
**Solved this** , all it is is a missing `define( 'NOBLOGREDIRECT', ' );` from wp-config.php | Solved this, all it is is a missing
define( 'NOBLOGREDIRECT', ' );
from wp-config.php | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "multisite, user registration, homepage"
} |
Wordpress br in content problem
I have this irritating problem with a post in Wordpress (see the url below).
<
You'll notice the second lower case bold heading (Why Bytewire for website design essex?) is pushed down from the adjacent picture by a br which Wordpress seems to be silently inserting.
I can't seem to work out how to get rid of it or where the hell it's coming from.
Anyone solved this problem before? | Switch to the HTML editor and you'll be able to see all of your page markup. You likely have an unclosed tag or extra line return somewhere in the content, so the visual editor adds additional markup to clean that up. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "wp admin, content"
} |
Can't retrieve product (post) ID using Shopp e-commerce plugin
I'm using the shopp e-commerce plugin. In my template file I need to get the id of the product (post). The online docs for shopp list `shopp('product', 'id')` but irritatingly this prints the id and there appears to be no alternative that simply returns it. Also confusing, when I do `$post->ID` it returns -42... which is weird.
Can anyone help me return the post id of individual products inside the shopp loop?
Thanks. | It's turns out that you can add `return=true` to any of the theme template tags:
shopp('product', 'id', 'return=true');
As of writing this, that is not mentioned in the documentation at all. Shopp support was also able to confirm that the $post->ID variable does get over-written in a number of situations, so the strange value I was seeing is not surprising. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugin shopp"
} |
Allowing users to edit only their page and nobody else's
We currently have about 50 pages, each of which I want a user (eg, bob, rob, smith) to be able to edit only 1 page. For example, bob & smith each have their own page. I do not want bob to be able to edit smith's page. I want bob to ONLY be able to edit bob's page. I don't care if he can see other pages. Looking through the user roles, I don't see a way to currently to do this- I only see how to allow restrict access on a global scale.
Are their any plugins to help restrict edit access per user, or roles restricted to editing specific pages and I can just add 1 user per role? Or was there a way to do this with default settings I missed. | The Role Scoper plugin can enable this. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 7,
"tags": "users, user roles, user access"
} |
Media is not attached after import
I am new there and I need some help for importing a wordpress blog.
I have a old wordpress 3.1 blog (no multisites) and need to move to new hosting (a sites under multisites). I don't have the access of database so I do a wordpress export.
Then I do the wordpress import as usual, with `Download and import file attachments` checked. My hosting a restrictive hosting so I need to do break down the process by keep on reloading the import page (step 2). After all done I found only the last imported images are attached to the posts, all other linkages are gone.
Question:
* does it matter that the attachment linkage is gone?
* If I want to re-attach the attachment to the origin post, any plugin should I use? | Well, I found the answer by myself.
I finally get into update the attachment by myself. I found the default attachment UI is totally a pain, so I use bulk change attachment parent to change the media id when I know the post id. (It is OK for about 50 images)
The only problem with that plugin is the bulk change part doesn't works under common sense. Will fire ticket later. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "plugins, multisite, attachments, media, import"
} |
How to get gravatar url alone
I would like to use gravatar image as background image for a button. When i use `get_avatar` function it returns with height width src parameters.
But i need only gravatar url. I mean like `
Can anyone tell me how? Thanks | Just generate the URL yourself. It's just a hash of the user's email address.
function get_gravatar_url( $email ) {
$hash = md5( strtolower( trim ( $email ) ) );
return ' . $hash;
}
This function requires that you pass the user's email address in ... but you could do anything you need to programatically grab the user's address. | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 2,
"tags": "avatar, gravatar"
} |
filter title from shortcode
Just wondering how to filter to change the current page title from a shortcode,
Since shortocodes are rendering after $post.
any idea to archieve something like : `do_shortcode(['mytitle="newtitle"']);` | why not to use **the_title** filter?
add_filter('the_title', 'the_title_filter');
function the_title_filter($title){
$post = get_post(get_the_id());
//enter code here
return $title;
}
as for shortcode - its imposible. in logical way - imposible. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "filters, shortcode"
} |
How to use the full page
I'm trying to figure out how to get rid of the whitespace on this page: <
I need the calendar to be full page. On the edit page screen, there's an option to set the template as "full page, no sidebar" but it doesn't expand my content area.
Is there a setting I'm missing? | In the theme you have choosen (twenty ten) - the main Container
where you page / post is posted is the div:
<div id="content" role="main">
<!-- YOUR CONTENT IS PUBLISHED HERE -->
</div>
.
This div has a maximum width of 640 pixels...
if you want to change that you can do one of three things.
1. Change it in your css file (would affect the whole site)
2. Create a custom page template and change that by adding
Some css onPage..
3. use custom fields to embed the css in to your header
(my favorite way but need some coding <\-- a little bit)
.
Hope this helps... its just a css issue.. not really a wordpress one.
Cheers, Sagive. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "pages, page attributes"
} |
Add function to custom menu
I am am trying to add a function to my custom menu. The menu works, but I have no idea on how to get the `custom_execute_shortcode()` function to work inside the `add_profile_link_to_nav()` function.
Any help appreciated.
//--Nav Menu
function add_profile_link_to_nav(){
if ( is_user_logged_in() ) { ?>
<ul>
<li class="menu-item"id="one"> <a href=" Members</a>
<ul class="sub-menu">
function custom_execute_shortcode() {
$myfunction= '[Shortcode]';
$myfunction_parsed = do_shortcode($myfunction);
echo $myfunction_parsed;
}
<li class="menu-item"> </li>
</ul>
</li>
<!--end menu--->
<?php
}
}
add_action( "wp_nav_items","add_profile_link_to_nav" );
Thanks, Tim . | Simple, don't bundle the function inside. Instead, break it out like this:
//--Nav Menu
function add_profile_link_to_nav(){
if ( is_user_logged_in() ) { ?>
<ul>
<li class="menu-item"id="one"> <a href=" Members</a>
<ul class="sub-menu">
<?php echo custom_execute_shortcode(); ?>
<li class="menu-item"> </li>
</ul>
</li>
</ul> <!--end menu--->
<?php }
}
add_action( "wp_nav_items","add_profile_link_to_nav" );
function custom_execute_shortcode() {
$myfunction= '[Shortcode]';
$myfunction_parsed = do_shortcode($myfunction);
return $myfunction_parsed;
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "menus"
} |
Morris.js for Wordpress?
I found Morris.js to be a delightfully implemented charting script, and wanted to include it in my Wordpress installation. But I have never included a js file with my blog before, and would appreciate if someone can guide me on this:
1. How do I include the javascript file?
2. Where do I upload it on the server?
3. Anything else I need to know to use it?
Thanks. | Create js folder in your theme directory then save Morris.js into it. it is not mandatory to store it in js folder you can store it anywhere else but i recommend to do it to seprate javascipt files from other files.
Add follwing action into functions.php file
function custom_scripts() {
/* Include Scripts */
wp_enqueue_script( 'morris-script', get_template_directory_uri() . '/js/Morris.js', array( 'jquery' ), '', true );
}
add_action( 'wp_enqueue_scripts', 'custom_scripts' );
You can find more information about wp_enqueue_script() function from this link < of wordpress codex. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "javascript"
} |
how to display page title only for child category pages
I apologize if this is a dumb question, but I am just learning PHP and Wordpress. It's probably very simple.
I have a site where the top-level nav is all parent categories, with the child categories as dropdowns. The pages are all pulling from category.php.
On the child category pages, I would like to display the current child category page title (single_cat_title, I think) for styling, but I want to exclude this feature on the parent category pages.
I've been trying to write this very simply using get_the_category() as per this example in the codex:
`$category = get_the_category(); echo $category[0]->cat_name;`
Any help is greatly appreciated. | Add a check wherever you're displaying the title:
//Anything greater than 0 means the category has parents, 0 means no parent, child category
if($category->category_parent > 0){
echo $category[0]->cat_name;
}
This should help. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "categories, title, children"
} |
search page not found? (search.php or searchpage.php)
Am i wrong in thinking i can access the search page by using /search/ ? I've created the files search.php & searchpage.php but /search/ still returns 404?
I want to customise the page a bit...
best, Dan. | You should be able to access search pages via `search/foo` as well as `?s=foo`. This search rewrite rule is built in into WP since version 1.5. I tested it and it works.
As for the template files, you will need `search.php`, `searchpage.php` is not used.
Also see:
* <
* < | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "search, templates"
} |
How to concatenate inside the _e() function the right way?
I'm trying to create a function for the title inside my functions.php, I'm having a problem with the search title part where I have to concatenate here's the part with issues:
elseif (is_search()) {
_e('Search for ', 'textdomain') . '"' . esc_html(the_search_quey()) . '$quot; - '; }
this one gives a title like this: Search for searchtermsitename
no quotes and the search term is attached to the site name.
I tried this one:
elseif (is_search()) {
_e('Search for ' . '"' . esc_html(the_search_quey()) . '$quot; - ', 'textdomain'); }
it doesn't work either, this one outputs: searchtermSearch for "" sitename
it's better than the first one but he search query is before, and can't figure out why.
so any help, and thanks in advance. | `the_search_query()` echoes itself, so by putting it into another echo function (what `_e()` is) you'll get result as in second example.
It isn't recommended to use variables or function inside l18n functions, because they can't be translated, for more information see Otto's: Internationalization: You’re probably doing it wrong.
So you should use code like this:
printf( __( 'Seach for "%s", 'textdomain' ), get_search_query() );
Note that I'm using `get_search_query()`, because it simply returns value instead echoing it, also it passes query sting through `esc_attr()` and no need for `esc_html()`. | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 4,
"tags": "theme development, translation"
} |
How to add template to theme in WP
I've _very_ new to WP and I'm trying to setup a new page which displays only a specific category through the WP admin section.
I've downloaded the ACE plugin and I've managed to filter out posts with a specific category from the main page.
Now I want to create a separate page which displays only this category, but I can't work out how to add a new template to the theme through the online editor, in order to show these posts. I'm using the Clean Home theme.
Can someone help me work out how to do this? do I need to ssh in to the server to create a file, or is there some way of doing this through the admin console? | WordPress does not allow adding files though the admin side of things, therefore you will need FTP or SSH access to the server to add a file to your theme directory at least to initially add the template then you can edit it though your hearts content in the admin. (there may be a plugin that allows the admin to add theme files but I've never looked)
Nevertheless, here's how to add a new template...
1. Create a new php file and include the following to create a custom template and upload it to `wp-content/themes/clean-home`
<?php
/*
Template Name: My Template
*/
?>
2. Then just add Your Loop
3. Set a page to use your new custom template.
**Protip:** You may also be able to copy another template and change the name which will save you time of adding the header, footer, sidebar, and other styles with still allowing you to create a custom template. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "themes, templates"
} |
Ascending sort order for monthly & category view, i.e. ?m=201204, ?cat=4
I have my posts ordered ascending (from oldest to newest) because I use Wordpress as a website to accompany a book published based on the original blog. To do this I put the following code just before The Loop in index.php of my custom version of the Connections theme:
<?php
$wp_query->set('orderby', 'post_date');
$wp_query->set('order', 'ASC');
$wp_query->get_posts();
?>
This works fine for the main index and for when the posts are displayed by page, i.e.:
`index.php?paged=1`
However, when the posts are retrieved by month or by category, the sort order defaults to DESC, i.e.: <
<
I just want everything to always be ASC. Are there monthly and category templates I need to edit? Thanks. | You can hook into the `posts_clauses` filter and change `ASC` to `DESC` there with a simply `str_replace`. The filter has one argument `$pieces`, which is an array of the MySQL statement parts. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "sort, order"
} |
Exclude category from query
## PROBLEM
Hey everyone I have the wp loop to display posts, but I need to exclude category 81. I tried: **query_posts('cat=-81'); ? >** before the loop but the pagenavi is broken and it doesn't work properly.
## CODE
<?php if(have_posts()): ?>
<ol class="list posts">
<?php
$end = array(3,6,9,12,15,18,21,24,27,30,33,36,39,42,45);
$i = 0;
while (have_posts()) : the_post();
$i++;
global $post;
?>
## HEADER
I have this in the begining of the page - maybe it has something to do with it?:
<?php get_header();
global $wp_query;
$curauth = $wp_query->get_queried_object();
?> | try:
global $query_string;
query_posts( $query_string . '&cat=-81' );
< | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "categories, query, exclude"
} |
How to change post thumbnail title and alt attributes to post title?
Can we change the title and alt attributes of the_post_thumbnails and set them to post title instead ? like creating a function for it and adding a filter ? I tried searching but I can't seem to find what I want.
and thanks in advance. | Look at this <
second argument in this function you can set a few set fields, such as alt, title, source and class:
$default_attr = array(
'src' => $src,
'class' => "attachment-$size",
'alt' => trim(strip_tags( wp_postmeta->_wp_attachment_image_alt )),
'title' => trim(strip_tags( $attachment->post_title )),
); | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 3,
"tags": "theme development, functions, post thumbnails"
} |
Trip Advisor and WordPress
I would like to have TripAdvisor reviews of a client's restaurant shown on the site, what's the best way to do that? If possible he would like the possibility to check the review first before it is posted to the site. | The best way to do this would be to request access to the Trip Advisor API, available on request here: <
They only allow a certain amount per year and under fairly strict rules, but I've put in a request with them last year for something fairly similar as what you are requesting and got it approved fairly fast.
Their API is fairly straightforward (WSDL), but for any follow up questions it's probably best to open a new question. Good luck. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "rss"
} |
How to migrate a database from a server to another
I try the export method of phpmyadmin, but the user is exported with the data... so there is no way to re import it into another database without error message.
The old user is name : oldserver_username, and the new server user is called : some_text_server_name_new_user
So there is NO WAY i can have the same username to export-import... how can i export and re import without having to have username check or bypass that ?
i am completely lost in MySQL ! | The database user name/password is not stored in the database; it is only used to access the database. Change the username (and password, too) to the new values in wp-config.php.
And the problem might be access to the database via phpmyadmin; check your username/password in Cpanel or some other hosting control panel. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "database, sql, phpmyadmin"
} |
Removing buttons from the html editor
I've been searching the codex, and I'm probably overlooking something somewhere, but could someone tell if it would be possible to remove a button/quicktag from the WordPress html editor? | With the `quicktag_settings` filter:
function wpa_47010( $qtInit ) {
$qtInit['buttons'] = 'strong,em,link,block,del,img,ul,ol,li,code,more,spell,close,fullscreen';
return $qtInit;
}
add_filter('quicktags_settings', 'wpa_47010');
The default is:
$qtInit['buttons'] = 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,spell,close';
Though `'fullscreen'` usually gets added too at the end. So I just deleted the `'ins'` button.
**Edit to add:**
If you wish to create a custom button the following tutorial might help. | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 3,
"tags": "html editor"
} |
WPMU Domain not pinging
I have set up a WPMU setup and used my primary domain as the www. version of topmmorpg100.com
This has however caused me a few issues, as a simple command to ping topmmorpg100.com without the www. seems to fail. This is causing some problems when signing up for services of which the domain is pinged and checked for status.
I would assume the ping is not working because it is not following the redirect, how would someone suggest that I can fix this? | It's not a redirect issue. I am also unable to ping the `www`-version of your site as well. Just to test, I _also_ tried to ping your site's IP address directly ... and it also times out.
This could be because your server doesn't allow pings.
Some servers are set up to block ICMP traffic by default. A ping doesn't come over as normal HTTP traffic to port 80. It comes in as an ICMP message and is echoed by the server back to the requester.
From the looks of things ... this is disabled on your server. You need to work with a sysadmin to enable pings.
Further reading:
* <
* < | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "multisite"
} |
Will it make any difference if I have CDN on the same server but different directory?
I've done some research about `CDN` or `Content Delivery Network` for self-hosted Wordpress site like mine it's recommended to have this implemented because it can help if you get load of traffic to your site.
To my question, should CDN be hosted in the same domain, but in a different directory? Or is it recommended to be hosted entirely in a different server? | CDNs work best when the objects - images, scripts - are hosted on a completely different server. Hosting a CDN on the same box that holds your web site defeats the purpose, as the processor, RAM and bandwidth are already being used for the site, and even if the CDN is on a subdomain, your server is still being used.
Try WP Super Cache < with a Amazon Cloudfront CDN < (You don't have to set up an S3 bucket; just use Cloudfront.)
Super Cache is less .htaccess intensive and more foolproof than W3TC. Follow WP Super Cache's instructions to add an .htaccess file to the cache folder for full browser caching.
Use < to test site speed and caching. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "hosting, cdn"
} |
Mass .htaccess URL Forwarding
I'm doing the migration of a site, from MovableType to WordPress. The website contains around 3500 posts and when I uploaded the information to the new version of the site, the links have been altered.
Old site link (note that the category-name and the nodenumber are not fixed values. The nodenumber is a number that changes in each post):
<
New site link: <
My question is the following:
What would be the easiest and effective way to configure my Htaccess file to do a redirection from the old links to the new ones? There might be a simple way than to write them all by hand. | Have you looked at the Redirection plugin? You could make a rewrite rule for something like this: `/([^\/]+/([1-9]+)/([^/]+)/?` and then have it redirect to ` or something along those lines at least. I think you could do this with `.htaccess` as well, but I'm not familiar enough with the format for it to give you code in good conscious. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "redirect, htaccess"
} |
How to create thumbnails in wordpress with jwplayer
I can't seem to get a good answer on their site. What's the best way to create thumbnails for videos uploaded to my wordpress site? Users upload videos from the front end and I started doing this with only youtube videos which was great because I could just pull the thumbs from youtube. So how can I can auto create them now and store them in a way that's not complicated. I tries using a the "video thumbnails" plugin but that doesn't work. | I did worked with the plugin YAPB (also possible with standard WordPress thumbnail but needs bit of code moding) and used this setting in the arrays of JW player. It might be not fully automated but you can control your introduction image.
<?php if ($post->image): ?>
'image': '<?php echo $post->image->getThumbnailHref(array('w=400','h=276','q=95','zc=1','fltr[]=usm|30|0.5|3')) ?>',
<?php else: ?>
'image': '<?php echo get_stylesheet_directory(); ?>/img/no-image-video.jpg',
<?php endif; ?> | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "videos, thumbnails, jwplayer"
} |
Adding Categories across posts, and custom post types
I currently have a list of categories that go with my 'posts' I want the same categories to go with my custom post types 'services' and 'work'
The following code, adds the tags and categories to the work and services custom posts.
add_action('init', 'demo_add_default_boxes');
function demo_add_default_boxes() {
register_taxonomy_for_object_type('category', 'work');
register_taxonomy_for_object_type('post_tag', 'work');
register_taxonomy_for_object_type('category', 'services');
register_taxonomy_for_object_type('post_tag', 'services');
}
But when I categorise a work/service post, it does not appear on the /category/ page, only the 'posts' from that category appear. | By default, only post_type post is shown on category pages. To enable your custom post types, you could hook `pre_get_posts`, check if it's a category page, and if so add your post types:
function wpse_category_set_post_types( $query ){
if( $query->is_category() && $query->is_main_query() ){
$query->set( 'post_type', array( 'post', 'work', 'services' ) );
}
}
add_action( 'pre_get_posts', 'wpse_category_set_post_types' ); | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 2,
"tags": "custom post types"
} |
Last article Widget with text preview and more button
I tried to use the last article widget from Wordpress and from my theme (deCanto last article).
The first one only shows me a link with the heading, the last one shows me the complete article!
But both cannot provide me the function I would like. The five last articles should be displayed on the start page. There should be a heading, date and an excerpt (e.g. first 200 words) from the article. Below there should be a "More" button with which the user comes to the full article.
> **Heading**
>
> 28th March 2012
>
> Lorem Ipsum Dolor Sit Amet ....
>
> More
Which widget can provide me such functionality? In the plugin directory there are too much results .. | Seems that the article "How do I display read more buttons?" from < does the trick.
You have to place the more button in the article and define yourself when the break should be. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugins, widgets"
} |
Is there any record of installed plugins in the database?
I have my live install on one server and a development install on another. I've added a plugin to both but it only appears in the plugin list in `wp-admin` on one.
For a plugin to appear in `wp-admin` does it need to appear in the database at all? Or is it that just by having the plugin file(s) in the `plugins` directory that it'll be detected?
Cheers! | The plugin file had Mac line endings so the meta-data comment at the top of the file wasn't being parsed properly. e.g.
<?php
/*
Plugin Name: WP JSON-RPC
Plugin URI:
Description: This plugin provides a JSON version of the XML-RPC WordPress API...
Author: Jeff Stieler
Version: 0.9.1
*/ | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 4,
"tags": "plugins, plugin development, wp admin"
} |
What is the precendence of item types within WordPress
I recently stumbled across an issue on a site that uses the following URL structure;
/%postname%/%post_id%/
An old blog entry had the URL www.mysite.com/my-blog-post/1918/
Since that entry was made there was some media added to the site with the name My Blog Post, meaning the slug for it was also my-blog-post.
Since the addition of the media anyone going to www.thesite.com/my-blog-post/1918/ would be shown the media page instead of the blog page.
I can't see this happening too often, I have corrected the error and informed the guys in charge of content to be mindful of it but it got me thinking about the precedence of different item types.
I would have thought off the bat that Media types would be lower down the list, but apparently not.
**What I would like to know is how I go about finding what the precendence of WordPress items is and if there is any way of changing it.** | The precedence is determined by the order of the rewrite rules:
<
These map the structure to a query, which is then fed to `WP_Query`, which has its own defaults. I don't see why you would be landing onto the media post, the `post_id` does not match, there should not be any collision in the first place. This does not appear to be undefined behavior, rather a bug in the rewrite rules, caused by some plugins or the theme etc. I assume that there's a rewrite rule at the top which makes `/pagename/.*/` fetch media post types.
Dump the rules (`var_dump( get_rewrite_rules() )`) and see if anything makes sense.
Further reading:
* <
* <
* <
* < | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "content"
} |
wp remove query
i want to remove a certain query in wp 3.1
add_filter( 'query', 'remove_delete_7_day_draft_queries' );
function remove_delete_7_day_draft_queries( $query ) {
global $wpdb;
$q = "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date";
if ( $q == $query) {
return false;
}
return $query;
}
but in the error log i see something like this: WordPress database error Query was empty for query made by get_default_post_to_edit
any ideea how to remove the execution of the query without any error ? tx | I'm assuming you're talking about this piece of maintenance code right here:
<
Indeed, the code calls on lower level functionality of `$wpdb`, which doesn't contain too many hooks, only one in fact, `query`.
<
So, in order to return an empty result set you'll have to come up with a no-operation type of query, here are some examples:
* `SELECT NULL;` (returns 1 NULL result)
* `DO 0;`
* `SET @ignore_me = 0;`
* `SELECT * FROM `$wpdb->posts` WHERE 1=0;` | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "query"
} |
How to define WP_DEBUG as true outside of wp-config.php?
I am trying to create a debugging mode in one of my plugins so users can easily enable WP_DEBUG on their own, and hopefully report back to us with helpful error messages. Right now we ask them to modify their wp-config.php, but that's beyond some users' capabilities. I was hoping to just add `define( 'WP_DEBUG', true );`in our plugin if the user has checked that option, but it appears you can only enable WP_DEBUG from the wp-config.php file.
Does anyone know of any way to enable WP_DEBUG from anywhere else but wp-config? Or is there another useful WP function that I could be using instead?
Thanks, Dalton | WordPress logic forces `WP_DEBUG` to be defined to _something_ , even if it's omitted it will be set to `false` in `wp_initial_constants()` during load.
However "background" (that is not when it is checked explicitly) function of `WP_DEBUG` is to be a flag for how PHP error reporting should be configured on runtime. That configuration is performed by `wp_debug_mode()` and at any point after that can be changed by your plugin's code if necessary. | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 9,
"tags": "wp debug"
} |
How to batch update post content with custom post meta value
I have a custom meta box, using WPAlchemy, in which I am looking to get rid of. However, I would like to get all posts that have a specific custom meta value set, and insert it into the begininning of the post content, then delete the meta value.
I have a feeling this post gets me close, as I have been able to successfully add content to the beginning of posts, but have been unsuccessful accessing and adding the custom meta value I'm after. I'm also a little unsure of when to hook into WordPress and perform my actions.
Anyone have any suggestions on the best way to go about this? I figured I would build a simple plugin, activate it, let it do it's job, then remove it. | what about something like this on activation?
function wpa47153_run_once(){
$posts = get_posts(array('numberposts' => -1) );
foreach($posts as $p) :
$meta = get_post_meta($p->ID, 'meta_key',true);
if($meta) :
$my_post = array();
$my_post['ID'] = $p->ID;
$my_post['post_content'] = $meta . "<br/>" . $p->post_content ;
// Update the post into the database
wp_update_post( $my_post );
unset($my_post);
//remove the meta key
delete_post_meta($p->ID, 'meta_key');
endif;
endforeach;
}
where get_posts and get_post_meta are tweaked to your circumstance. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 3,
"tags": "posts, metabox, post meta, updates, wp update post"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.