INSTRUCTION
stringlengths 11
999
| RESPONSE
stringlengths 0
999
| SOURCE
stringlengths 16
38
| METADATA
dict |
---|---|---|---|
Override default url for author pages?
So the default url to display a list of posts by a particular author looks like this:
`
I am wondering how to change the 'author' in that url to something else?
I am working on a website for a charter school and they would like to allow each teacher to have a list of posts by "classroom". So the desired url would be
`
|
You might wish to try.. <
Hope that helps.. ;)
|
stackexchange-wordpress
|
{
"answer_score": 6,
"question_score": 14,
"tags": "url rewriting, urls, author"
}
|
Where do files uploaded via Media Manager get stored in MU?
Standard WordPress sites, at least of the versions of WP I've tested, store files uploaded via the Media Manager under wp-content/uploads/
Where do these same files get stored in MU sites and how can you obtain a reference to this folder via script from functions.php?
Is the location different depending on which version of WP or WPMU is installed?
|
Have a look at the following page and see if that answers the question for you... ;) <
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "theme development, multisite"
}
|
How to set up sub-categories for author pages?
I am setting up Wordpress for a school. They want to enable teachers to have their own section of the site where they can create posts in different categories (assignments, events, etc).
I know that Wordpress supports multiple authors and that I can show posts by those authors out of the box by going to `
However, instead of just showing all of the posts from different categories in one loop, I would like to allow the user to view posts by category and they can choose from a link menu.
!alt text
Can anyone point me in the right direction on how to do this? Is there a way to create a url that would filter posts by author AND category?
|
You should consider to make use of an author template. It will allow you to control how the author page is displayed, so you can add what you pictured into there.
You can then register a rewrite endpoint to create the multiple areas of the author page. In the template just check on which "subpage" you are and display the tabs and listing accordingly.
That's basically doing WP_Query then which is pretty well documented, so should be an easy start.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 3,
"tags": "categories, customization, author"
}
|
Creating a job board using WordPress (for free)?
I found several plugins/themes for creating a job board with WordPress, but only one solution which is free (see here)
Are there any other **free** solutions for doing that?
|
## Plug-ins
* Job Listing
* Job Manager
* WP Careers
* WP Job Board \- _Premium_ (This has a similar name to the one you linked to, but they seem to be completely different systems)
## Themes
* JobRoller \- _Premium_
* Job Board \- _Premium_
* JobPress \- _Premium_
* Tapp Jobs \- _Premium_
As you can see, a lot of available solutions are premium plug-ins or themes. The pricing seems fairly reasonable ($25-$40 for a good solution), but if you're really strapped with your project budget the free plug-ins might serve as a good base for building your own replacement.
_Once again, though, I have no criteria with which to judge any of these alternatives since you never explained exactly what you were looking for. All of these options will help you build a job site, but without a better understanding of what you're trying to accomplish, I have no idea which, if any, would be the best route for you._
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "themes, plugin recommendation, theme recommendation"
}
|
How to test for MU via functions.php?
What is the call to determine, from a theme's functions.php whether the site is an MU site or not?
Updated with answer:
$dir =
is_multisite() ? 'wp-content/blogs.dir/'.$current_site->blog_id.'/files/'
: 'wp-content/uploads/';
|
Try the `is_multisite()` conditional, more documentation here: <
You may find the `is_main_site()` conditional useful as well. Just note that `is_main_site()` will always be true if `is_multisite()` is false.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "theme development, multisite"
}
|
How to get blog-id of an MU site from functions.php
How can one determine, from functions.php, the blog-id of the site (or alternately, the path to the media directory)?
|
For the current site, you can use the `$current_site` global variable and look at the blog_id member variable, e.g. `$current_site->blog_id`
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "theme development, multisite"
}
|
Limiting sessions to one IP at a time
On a site with premium user account subscriptions, I'd like to be able to limit logins to one computer at a time. The most straightforward way to accomplish this would be to limit by IP, but I haven't had any luck finding a plugin to accomplish this. Does anybody know of one I can use to get this functionality?
Related: Login security question - Does WP show me if I'm logged in from multiple locations?
|
As already suggested in a comment above of mine, technically a (cookie based) session is limited to one IP at a time by using the Safer Cookies (WordPress Plugin).
This does not prevent another login with the same username and password because it is a feature of WordPress to allow you to login multiple times with your credentials and therefore with multiple IPs.
What you would like to achieve is to prevent multiple logins at all then. According to Otto, this is not trivial. Stacy writes, that the Wishlist Member (Wordpress Plugin) has such a functionality built in: IP-Login Protection. So probably that plugin or part thereof is a solution to your issue. IANAL, but that plugin is violating the GPL license as it restricts you to make use of your wordpress derivate. I would not use it.
But probably there is another plugin out there available, or it's quite easy to extend Login LockDown (Wordpress Plugin) to bind the whole session to the last valid IP recorded.
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 5,
"tags": "plugin recommendation, security, login, ip"
}
|
Remove problem PHP code entered into footer via Theme
A friend of mine has a WordPress site using the Theisis theme. Recently he added a bit of problematic PHP code to the footer via the Theme (not into a PHP file). The PHP code is erroring out causing the site to WSOD (White Screen of Death). Because the footer is on every page, he can't get back in to remove the PHP code to fix the site. I'm not super familiar with WordPress (use mostly Drupal myself) so I'm not 100% sure how to help him. I'd guess the PHP snippet got stored in the database and needs to be manually removed from there. But I don't know the WordPress schema all that well. Can someone point me in the right direction? Where in the database would this code be store so I can remove it?
|
Use FTP to rename the Thesis theme folder and then WP will use the default theme and you will be able to get back into admin.
If he edited the theme file via the theme editor in WP admin, then replace the file he edited in the Thesis folder from a fresh copy and try and reactivate the theme.
If that doesn't work and the added code was saved to the Thesis theme options, use a plugin called Clean Options to clear out the old Thesis theme options and start over: <
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "themes, php, errors"
}
|
Duplicate content with incremental titles. How is this happening?
I was looking through the crawl results of my SEO Moz app and saw that there are somehow many copies of certain pages that have titles that are the exact same except for a number added to them. An example is in the image. How could this be happening?!alt text
|
These are attachment URLs. They are created for all images in your post. You have a gallery with 17 images, so for each image an URL with the structure `[post_url]/[attachment_name]` is created. `/2010/07/2011-honda-odyssey-official-details-photos-and-specs/` is the post URL, `2011_hondy_odyssey-2` is the name of one of the images in it (created based on the file name when you upload it). You can style these pages by modifying the `attachment.php` template file.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "content"
}
|
How To Provide Sub-Blogs Their Own Domain Names?
I ran a search that did not yield that many results.
Is it possible, and how can each sub-blog of a multi-site installation be given its own domain name?
|
Shortly after, I was able to find Otto's tutorial on the topic.
WordPress 3.0: Multisite Domain Mapping Tutorial
|
stackexchange-wordpress
|
{
"answer_score": 7,
"question_score": 4,
"tags": "multisite, options, domain, customization"
}
|
how do I filter single_cat_title to remove all instances of a particlular word
I have certain names in my category title (that need to stay there for other reasons). I am displaying all category titles with the blog name prefixed, but on categories that already have this name I would like to automatically remove the blog name from the single_cat_title. i.e. "My Blog My Blog Category" is what is showing using but where single_cat_title allready has the blogname as part of the title, I would like to only show "My Blog Category". Can one do this with single_cat_title as I have used it everywhere and manually replacing these would be problemattic?
|
There is a filter with the same name (`single_cat_title`) you can make use of to replace a particular word all the time:
add_filter('single_cat_title', function($title) {
return str_replace('word to replace', '', $title);
})
;
This should basically do the job.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 2,
"tags": "categories"
}
|
Can I add custom meta for each image uploaded via media-upload.php?
I'm calling media-upload.php via a custom icon click inside the content editor and I would like to add a custom meta value for all images that are uploaded when the media-upload.php is called from my custom function.
For example, for each of the images that are uploaded, I want to insert a value into wp_postmeta of _customAttachment = 1 like so:
update_post_meta($post['ID'], '_customAttachment', true);
I know how I can pass the current post-id to the media-upload.php (via querystring parameters), but I have no idea how to attach my update_post_meta filter to the save/upload trigger in media-upload.php
Is there a filter for this?
|
Yes, you can add fields, an example
function rt_image_attachment_fields_to_save($post, $attachment) {
// $attachment part of the form $_POST ($_POST[attachments][postID])
// $post['post_type'] == 'attachment'
if( isset($attachment['rt-image-link']) ){
// update_post_meta(postID, meta_key, meta_value);
update_post_meta($post['ID'], '_rt-image-link', $attachment['rt-image-link']);
}
return $post;
}
// now attach our function to the hook.
add_filter("attachment_fields_to_save", "rt_image_attachment_fields_to_save", null , 2);
see more on this post
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 3,
"tags": "filters, uploads"
}
|
Styling Shortcodes in Visual Editor
Does anyone know how to style the visual editor so that when specific shortcodes are used they are replaced with an image within the visual editor?
I have found that many users screw up the shortcode text or delete it by mistake when using the visual editor so I would like for shortcodes to be replaced with paceholder images within the visual editor. HTML editor would still show the codes though.
|
I have not a working solution at hand, but what I would do is to analyze how this is done for the more seperator. In the HTML editor, there is `<!-- more -->`, in the visual editor, an image is displayed instead.
This is done by extending the tinyMCE editor - which is the base of the visual editor in wordpress - with a plugin. To learn more about tinymce plugins, you find more examples and documentation in the moxiecode wiki: Creating a plugin for TinyMCE (3.x).
You find example code within the following file:
wp-includes/js/tinymce/plugins/wordpress/editor_plugin.dev.js
It works basically by replacing content (e.g. the shortcode `[mycode]`) with some predefined HTML that contains the image. Before the content get's posted, it is replaced again with the original HTML. You can make use of regular expressions in the process. The more link is showing this quite well.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 5,
"tags": "admin, shortcode, customization, visual editor"
}
|
Error getting correct blog_id on MU from functions.php
I have script in my functions.php that seeks to locate the media directory of the site in which the theme is installed. This is pretty simple unless the site is an MU site. In that case, the media directory is based on the blog_id.
However, my code below is returning the main site id rather than the blog_id of the site in which its being run...
function get_image_list()
{
global $current_site;
$dir=is_multisite() ? 'wp-content/blogs.dir/'.$current_site->blog_id.'/files/' : 'wp-content/uploads/';
$url=is_multisite() ? get_bloginfo('url').'/wp-content/blogs.dir/'.$current_site->blog_id.'/files/' : get_bloginfo('url').'/wp-content/uploads/';
In this case, the actual blog_id is 3, however, its returning a value of 1 for $current_site->blog_id
The error is...
cannot open wp-content/blogs.dir/1/files/
|
Compare `$current_site->id` with `$current_site->blog_id`. According to the in-line documentation, `blog_id` should be working ... but check to see if there's a major difference there (your system might have a plug-in or something else causing a problem).
* * *
## Update - Ignore last
It seems like `$current_site` is a global variable defined by your _site_ or _network_ and will always return the same `blog_id` as your network dashboard - in this case, "1."
What you need to use instead is `$current_blog`:
function get_image_list() {
global $current_blog;
$dir=is_multisite() ? 'wp-content/blogs.dir/'.$current_blog->blog_id.'/files/' : 'wp-content/uploads/';
$url=is_multisite() ? get_bloginfo('url').'/wp-content/blogs.dir/'.$current_blog->blog_id.'/files/' : get_bloginfo('url').'/wp-content/uploads/';
That should get you the right information.
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 3,
"tags": "plugin development, multisite"
}
|
Querystring data gets truncated
When I check "view source > frame info" on the window produced by the jQuery code below, it cuts off the querystring at the &type=image. I'm url encoding the ampersands properly, right?
Address: ...wp-admin/media-upload.php?post_id=28&type=image&
function wpe_customImages($initcontext)
{
global $post;
?>
<script type="text/javascript">
jQuery(document).ready(function() {
var fileInput = '';
jQuery('#wpe-uploadAttachments').click(function() {
fileInput = jQuery(this).prev('input');
formfield = jQuery('#upload_image').attr('name');
post_id = jQuery('#post_ID').val();
tb_show('', 'media-upload.php?post_id='+post_id+'&type=image&TB_iframe=true&wpe_idCustomAttachment=true');
return false;
});
|
As you have asked wether or not you have done the url encoding for the ampersands right, then my answer is: No.
You are calling a javascript function, you're not outputting something as x(ht)ml. You therefore do not need to encode `&` as `&`. The function is expecting a URL not a string that contains an xml encoded url.
But that's probably nit-picking.
The reason why this does not work is, that tb_show() cut's away anything after the first `TB_` it finds in that URL, and only the part of the URL before that string is preserved for the iframe src. So you need to move the `TB_iframe=true` to the end of the parameter. This should do the trick:
tb_show('', 'media-upload.php?post_id='+post_id+'&type=image&wpe_idCustomAttachment=true&TB_iframe=true');
BTW, wordpress is open source. You can just look to find the tb_show() function in source and look why something is happening or not. This can help to find out specific stuff. I didn't do anything else :)
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 2,
"tags": "jquery"
}
|
Search result permalink
how to make permalink available for search result page
/?s=one+two+ok to /search/one-two-ok/
thank
|
That kind of search request should already work(query it directly in your address bar), the component you're missing is redirecting the non-pretty search requests..
For doing the redirect, you should find the following plugin still works.. <
Hope that helps..
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 2,
"tags": "permalinks, search"
}
|
Adding HTML to the Header, Screws up in IE7
Working on a site for a client:
<
I added an HTML table to header.php to include the "Call us at..." and the social media icons. It renders fine in most browsers but IE7 screws up that table. I ran it through the W3C validator and that part of the code is fine.
You can see what I mean by putting the above URL into: <
Any ideas for how to solve the problem? Thanks!
Jim
|
Write a stylesheet just for ie7 and link it in wordpress like so:
<!--[if IE 7]><link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/css/ie7.css" /><![endif]-->
in the file add this
#header table {float:right;}
#header table tr td p {margin-top:45px;}
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "css, html"
}
|
Reproducing hierarchical list output from wp_list_categories(), using get_categories()
I need more control over the category listing output, so I'm using `get_categories()`, instead of `wp_list_categories()`.
This function returns a flat array of objects ordered by a certain attribute. How can I build a hierarchical list from it like `wp_list_categories()` does?
|
The most ideal solution for walking over the data is to use the WordPress walker class.
<
You won't find many an example around the web for using it, but one was given by Scribu here.
<
You can also look to the classes WordPress uses to extend the walker as further examples.
<
Hope that helps..
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 2,
"tags": "customization, taxonomy"
}
|
WYSIWYG-able Footnote Plugin
Is there a WP plugin that allows user to edit in-page footnotes in WYSIWYG manner?
No weird syntax.
No HTML pane.
**Update:**
Perhaps I'm missing something, as I'm new to WP.
All footnote plugins that I saw use custom syntax. Example:
Blah blah blah ((my footnote)) blah
Other:
Blah blah blah [ref]my footnote[/ref]
I need plugin that will allow user to edit footnotes visually, like Word does.
|
From all the footnote plugins that I'm aware of, they don't provide the functionality you're looking for. It's normally expected that a user edits the footnotes content in the place where the footnote is edited in the current plugins.
But the list is pretty impressive. So probably you might want to look on your own: Footnote Wordpress Plugins.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 1,
"tags": "plugin recommendation"
}
|
Is There A Hook To Process The Content Of The Text Widget?
Is there any filter which can be used in a plugin to process the content of the text widget before it is rendered?
|
# Filter
1. widget_text (for the text)
2. widget_title (for the title)
# Example
function add_smiley($content) {
$new_content = '';
$new_content.= $content . ':)';
return $new_content;
}
add_filter('widget_text', 'add_smiley');
Note that this works only for the content so not if you have a widget with only a title.
# Reference
1. <
2. <
3. <
|
stackexchange-wordpress
|
{
"answer_score": 7,
"question_score": 5,
"tags": "plugin development, customization, widgets, widget text"
}
|
How to use Canonical URL meta tag to avoid duplicate content issues with WP home pages
By default, Wordrpess sites have at least 2 URLs that can be used to reach the home page:
www.site.com/
www.site.com/hello-world
Both these URLs point to the same page, the default "hello world" post that WordPress creates.
How can theme developer's specify a canoninical url meta tag to suggest to search agents which URL it should index in the above example?
In your answer, please include an example for each choice: one in which site.com is preferred and one in which site.com/hello-world is preferred.
|
You might probably want to install Canonical URL’s for WordPress (Wordpress Plugin). It allows you to specify a canonical URL for each post and page. So you can configure the way you want.
The plugin is not big, you probably can integrate the functionality easily into your theme then.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "theme development, wp head"
}
|
Custom post type - get_day_link()
How can I get the archive links for a custom post type? get_day_link() doesn't seem to work
|
From the top of my head, `get_day_link()` does not work for custom post types. This might work in 3.1 as you can add archives to your custom post types.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "custom post types, php, archives"
}
|
How to run scripts when a new blog is created in Buddypress?
I'd like to insert some mysql data into every new blog that's created on my buddypress system. How can I hook up to the newly created blog data? ID, for example, would allow me to insert it right from the PHP. Is there a better way to do it?
Thanks!
|
see: How To Modify New Sub Blog Immediately When Super Administrator Creates It?
The code I wanted to post I unfortunately could not post beacause "body is limited to 30000 characters; you entered 62367" so ... the following filters are handy (from WordPressMU plugin for site admin to set defaults for new blogs, Deanna Schneider) :
function set_blog_defaults($blog_id, $user_id)
{
global $wp_rewrite, $wpdb, $current_site;
switch_to_blog($blog_id);
// do stuff
}
// When a new blog is created, set the options
add_action('wpmu_new_blog', array(&$cets_wpmubd, 'set_blog_defaults'), 100, 2);
?>
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "buddypress, mysql, actions"
}
|
Why does my Posts page only show a single post when using Thematic?
This seems to be a Thematic theme bug becuase if I switch to other themes, everything is working as expected. This is not the first time I created a frontpage using a static page. I made sure I followed this: < Any idea pls?
|
You should definitely check this page : <
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "customization, homepage"
}
|
WordPress kills an iframe's apostrophes
I'm using an iframe to let multiple sites embed one interactive element. On the iframe's actual page it works fine, and it looks fine on another website I embedded it. But when I embed it in a WordPress blog, all my apostrophes show up as squares.
I tried removing all smart quotes and apostrophes with "dumb" quotes, no luck.
I tried replacing all the apostrophes with ' and, again, no luck
Any clues what my cause this?
The iframe code:
<iframe src=" name="interactive" scrolling="no" frameborder="0" marginheight="5" align="center" vspace="5" widtha"590px" height="720px"></iframe>
And you can see the interactive code by just viewing the first link
|
The apostrophs get translated in
'
For the apostrophs, I guess it is an xss security feature. Check
settings > reading > encoding (UTF8)
But im not sure (maybe the theme sets another encoding fixed in the header instead of reading the global variable). In any case your embed show correct in my WP test post (so with an apostrophe).
Maybe you can set in the code of the iframe also
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 1,
"tags": "oembed, iframe"
}
|
Fancy-box Esay wordpress plugin fails to work on Multilingual site
I have a multi lingual site. On the site I want to display youtube movies using fancybox (or any other equivalent solution)
The plugin is installed and set. When checked on the He version - all works well. On En on the other side, it redirects to youtube.
EN: < HE: <
Any idea why this happens ?
I am using qtranslate for the multilingual support
*Changed site default to HE for now
|
Got a different solution. Just replaced wp-fancybox-easy with wp-lightpop. Wp-lightpop works wonderfully out of the box. 2 changed I needed to do were: 1\. go to the setting page and change the links to be displayed as popup (otherwise it's open the language navigation links as overlay) 2\. change box style (look&feel)
Problem solved :-)
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "theme development, jquery"
}
|
Placing a widget with $wpdb query
I'm getting the feeling that adding Widgets via MySQL query is not as simple as I thought. I was under the impression all data is stored in the `options` table, but it seems like I was wrong.
Any idea how to place a widget via $wpdb? What data should be written down? And where?
Thanks!
|
Placing widgets via a MySQL or something MySQL abstracted via the global variable `$wpdb` that is an instance of the WPDB class is _not_ trivial.
That's not because MySQL is something complicated or because `$wpdb` is useless at all but this has do something with the way the widget configuration is stored inside the mysql database options tables.
But there is always a work around. The nature of the widget configuration is stored inside the mysql database options tables. Just read the widgets configuration out of the option (get_option), edit it as you wish (use var_dump to inspect how that array is used) and then store it back into mysql via update_option.
That done you should be able to edit this "via mysql" (e.g. in the database) while making the settings of your wish.
This is quite a quick answer but it probably solves your issue.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "widgets, mysql, query, wpdb"
}
|
Configure paragraph style without editing CSS
Is there a way to change the default text paragraph style in WP without changing CSS by hand?
I.e. I need GUI for that.
In particular, I want to configure padding height between paragraphs.
|
It depends on your theme. With most themes you'll have to manually edit the CSS to do this.
But some themes have control panels that allow you to make changes to the design without editing the code. If you'd rather not write code but would like to make changes to your site, I'd suggest using a theme with design options.
Some are very simple, just a few color choices or layouts to choose from, but others have hundreds of options. There are some free ones in the theme directory like Constructor and Platform, check out the theme-options tag to see all the themes which should have control panels.
Of course there are also commercial themes which have these features as well, like Builder and Prose.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "plugin recommendation, css"
}
|
Where's did this div element come from?
This div element is causing a big gap on my wordpress page, specifically on the single post page. It's nowhere in the themes, I can't seem to find where this div element is coming from. Have you encountered this before (the highlighted element)? !alt text
**PS** : Happens on chrome only. **UPDATE:** Still having this problem even with the stable chrome. Help anybody?
**UPDATE2** : I think its the syntax highlighter plugin. And I also found out all other wordpress blogs (that I've checked) have this div. And the code's height in the post adds to the height of the div.
|
It looks to me like JavaScript for your lightbox.
* edit
If this only happens in Chrome, there is a rendering bug that has gone unfixed for quite some time.
Add height:100%; to the body or html element in your css.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "customization"
}
|
Can anyone recommend a wordpress based CRM/Project Management system or plugin?
Hello I am wondering if anyone can recommend, from first hand experience, a reasonably simple CRM or project management plugin for WordPress.
I have read this question on the topic. But I am looking for slightly more detail and if possible someone who has actually used one of these.
The functionality I am looking for is to be able to store contacts, share files, have a forum/message board or even chat type area and some simple task/project management functions such as assigning cases to team members. One more thing, if possible users should be able to select their preferred language, preferably at least with English and Simplified Chinese, although I accept this may not be possible or may require manual translation.
I have used both sugarcrm and vtiger, but have found that them to be a bit bloated and was wondering if any of the WordPress option available would be suitable for our needs.
|
The only project I know that is viable is rolopress, download it and see what you can adjust.
FYI I have a related question open here: < but for a PRM.
But the thing you are looking for is I think not a CRM system but a PM/software project system, all your requirements are met with RTC ( < ), free for 10 users. It has chat, users, projects, projectmanagement, tickets, version control, reports, your (agile/RUP/UP/whatever) planning and project approach etc... and all integrated. You can have rss feeds on everything and it has a REST, etc.. possibilites and an API. I have not tried version 3 yet: <
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "plugin recommendation"
}
|
Should the page cache be refreshed often?
In the w3 total cache there is the option to set the time until the cache is flushed (and thus, recreated on the next time a visitor comes by).
My question is, assuming I've got a lot of content on my site that doesn't change almost ever, why would I not just set the caching to stay for days (instead of getting flushed every hour or so)?
Is there a problem with that strategy?
|
The one possibility is caching broken page. For example some database query fails (which is not uncommon in shared environment and/or under load) and some page gets displayed broken / with errors.
Since caching doesn't assume integrity checking it can cache such page... And your cache interval is days - page is broken as long.
It would work better if mechanism was manual - you explicitly make something static and it remains that way (plenty CMS enginges work completely like that - generate complete static page and serve it). But I am not aware of any WP plugins that implement that.
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 2,
"tags": "cache, plugin w3 total cache"
}
|
can I prevent WP users (even admin) from deleting custom categories?
I am writing a plugin where I have custom taxonomy (category). I want to prevent
* **any user** from
* **deleting some** of
* **custom categories**.
Is there any way how to do so.
Let's say that category with id1-id10 nobody (admin included) can delete.
|
If you want to prevent deleting a single or a list of category IDs within the admin, you can prevent so by blocking all requests that delete the category.
There is no hook in wordpress you can make use of to use easily, but there's always a work-around. In my example I use the `check_admin_referer` and `check_ajax_referer` hooks (note the typo in the hook name) combined with a check if the request is actually one to delete a category (delete something within the `category` taxnonomy).
Example Must-Use Plugin: Wordpress Block Category Deletion Example
On deletion of a blocked category, you will get either a _You do not have permission to do that._ message (Ajax) or a _This category is blocked for deletion._ message and you need to go back with your browser.
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 2,
"tags": "plugin development, custom taxonomy"
}
|
Page with posts from category doesn't work
I'm working on my wordpress site, and I want to have a page that shows all posts from the category 'portfolio' on a separate site. I'm using the following technique:
<
However, on my testblog this works fine ( < ) but on my live blog it doesn't seem to load the custom pagetemplate portfolio.php ( < ). Instead, it uses the regular page.php template.
Both are pages (not posts), use the exact same theme (not even a copy, the same physical theme in a multisite installation), the same custom field 'category' with a value of 'portfolio' and both blogs have at least one entry with the 'portfolio' category.
The only difference between the two is that the dev blog does _not_ have the option to choose the page's template (yet it does use the custom Portfolio template). The live site does have this option and it's set to Portfolio of course but when I view the page it uses Page. I can't find out why this is either.
Anyone who can help?
|
So, apparently I accidently copied the comment `Template Name: Portfolio` to my page.php as well, so when I selected the 'portfolio' template wordpress just picked page.php out of the two possible templates. May be a warning for other people that have this problem :)
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "page template"
}
|
Passing variables through locate_template
While I've typically used `include` or `require` on their own to save long term code maintenance I've started to use `get_template_part` and `locate_template` as using built in WordPress stuff is always best.
My question is are you supposed to be able to pass variables through to the results of either `get_template_part` or `locate_template`?
<?php
$var = get_option( 'my-custom-option' );
get_template_part( 'custom-template-part' );
?>
In the code above the `$var` would be printed inside the custom template but the variable doesn't seem to work. Am I missing something or is this expected behaviour?
I've found that they don't pass in the instance above or when using locate_template
<?php
locate_template( 'custom-template-part.php', true );
?>
|
Like MathSmath wrote, get_template() does not support the re-use of your variables.
But locate_template() infact does no inclusion at all. It just locates a file for inclusion.
So you can make use of include to have this working just like you expect it:
include(locate_template('custom-template-part.php'));
`$var` from your example can be used in the template part then.
A related question with a more technical explanation of the variable scope and get_template(): Form Submitting Error with get_template_part()
|
stackexchange-wordpress
|
{
"answer_score": 65,
"question_score": 56,
"tags": "get template part, include"
}
|
What type of Google tracking should I use?
I have WP Multisite and now I want to track the different sites.
I'm using Multisite Domain Mapping to map `www.mysite.com` to `
My questions is:
**a)** Do I need to add the same google analytics script to all themes?
**b)** when creating the script at GA, I have the following choices:
* A single domain (default)
* One domain with multiple subdomains
* Multiple top-level domains
Do I use nr 2 or 3?
I know there are plugins I can use. But I still have to create the scripts at GA, right?
|
Hook the script into the footer, which is easy enough.
<
As stated in the post, toss that into mu-plugins, it will track all your site, regardless of domain. GA can sort it out on their end.
totally do-able.
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 2,
"tags": "multisite, google analytics"
}
|
What URL do you pass to wp_remote_get to load the body of the current post's preview?
In the code below, I'm attempting to get a reference to the body content of the current post's fully rendered preview...
$response = wp_remote_retrieve_body(wp_remote_get('
$post->post_content = $response;
I'm just sending it to $post->post_content so that I can easily see it.
Here's part of what it returns...
<body id="error-page">
<p>You do not have permission to preview drafts.</p></body>
</html>
I'm logged in as the administrator, so obviously I'm calling the preview wrong. How can I pass the URL in wp_remote_get to obtain the body section of the preview stream?
When I use...
$post->post_content = "<pre>".$response['body']."</pre>";
I get
<pre><</pre>
|
The URL is okay, what you need to add are cookies that authenticate you as the user who is allowed to see the preview. That is basically sending headers. I would start with the HTTP API (Wordpress Codex) looking for a method to add additional HTTP headers and set your cookies.
Otherwise - because probably this is somewhat complicated - you could take a look inside the preview code so to see if you can provide a hook to control access to previews. If possible, you can add some secret parameter to the URL which would allow you to preview any page w/o the need of being logged in (and the need of a nonce as it needs to be provided for preview as well).
The result of either the first or the second approach is quite the same, the only difference would be how to trigger it.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "plugin development"
}
|
How do I customise the new user welcome email
How can I customise the the new user welcome email ?
I tried ' however it conflicts with some of the other plugins I need to use, Cimy Extra Fields.
There is one other plugin that is to old for wordpress 3.0.1.
Will
|
SB Welcome Email Editor works by replacing `wp_new_user_notification()` with an own version. The original version can be found in `wp-includes/pluggable.php`, the plugin uses an elaborate replacement with all kinds of options. You can do this to: create a new plugin (just a PHP file in `wp-content/plugins/`), and define `wp_new_user_notification($user_id, $plaintext_pass = '')` there. This will then be used instead of the regular WordPress version.
|
stackexchange-wordpress
|
{
"answer_score": 8,
"question_score": 10,
"tags": "email, user registration"
}
|
What do these phpMyAdmin errors mean on my WordPress databaes?
I'm getting 3 very similar phpMyAdmin errors on one of my WordPress databases.
More than one INDEX key was created for column `comment_approved`
More than one FULLTEXT key was created for column `post_title`
More than one INDEX key was created for column `lead_id`
Anyone know how to resolve these?
!alt text
|
As it writes, a problem with the indexes definitions of those tables. Please try a repair on the reported table and see if that helps.
Have you activated a specific add-on lately or did you alter tables?
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 0,
"tags": "posts, comments, database, errors, mysql"
}
|
How do you remove a broken theme from WordPress Admin (without FTP or Cpanel)
Is it possible to remove a broken theme from WordPress using only the WordPress dashboard? i.e, without using cpanel or FTP?
Background: When you are doing customer support, its rare that you have access to the user's FTP or cpanel, but its pretty simple for them to set you up as a temporary user to troubleshoot their site.
|
You can use `Appearance > Editor` to kill theme's header in `style.css`. Won't really remove it, but will prevent it from showing up as available in WP.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "themes"
}
|
Incompatible Archive. PCLZIP_ERR_BAD_FORMAT (-10)
What causes this error (generated while uploading any theme to this WP site)
Unpacking the package…
Incompatible Archive. PCLZIP_ERR_BAD_FORMAT (-10) :
Unable to find End of Central Dir Record signature
I've tried to upload several different popular themes to the site.
|
This error comes from the library that manages ZIP formatted archives: <
After a quick web search, two solutions came up:
1) Which version of WordPress are you using? For version 2.8 this seems to be a known and fixed issue. Hence, an update of WordPress could help.
2) You perhaps have to increase your available hosting space.
If it's nothing of this, searching for your error message + WordPress yields many many results!
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "themes"
}
|
Steps for Moving Multiple WordPress Installs to a Multisite Install?
_( **Moderator's Note:** Original title was: "Steps to move multiple wordpress installations to a WP MU installation")_
Any tips on moving multiple WordPress installations to a single Multisite[1] installation?
[1] _Multisite is the new name for WPMU._
|
For the record MU functionality was merged into core and is now referred to as `multisite`.
Codex has guide at Migrating Multiple Blogs into WordPress 3.0 Multisite
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 5,
"tags": "multisite, domain mapping"
}
|
Conditional Display of Links in Widgets
I want the links widget in my sidebar to display links based on the page the user is on. For example, if the user is on the home page I want it to display link1, link2 and link3. But if the user goes to the 'About' page I want the links widget to display link4 and link5.
Is there a way to specify conditional display of links depending on the page id?
Thanks
|
Widget Logic <
Also Query Posts Widget is very useful <
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "plugins, plugin recommendation, widgets, customization, links"
}
|
WP_Query with the "offset" argument
I'm making a custom query for posts using something like:
$p = new WP_Query();
$p->query(array('offset' => 30, 'posts_per_page' => 10));
If I have 36 posts on the entire blog, `$p->post_count` will return the number of posts that were retrieved, 6 in this case.
I need to get the post count just like I would if I omitted this 2 arguments (so I can calculate the remaining post count). How can I do that, without making another query?
|
The found_posts property `$p->found_posts` will return it.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 2,
"tags": "customization, posts, php, wp query"
}
|
Notify multiple email addresses on comments
Can you recommend a plugin that enables notification on multiple email addresses on posted comments? Looking for a plugin that both notifies a global list of email addresses and the author of the post.
|
Post authors are notified of new comments by default; there are several plugins that modify this behavior. See `wp_notify_postauthor`.
You can hook into `comment_notification_recipients` and add an aribtrary list of recipients as described here. Then you could create a metabox or dashboard widget to manage the recipient list.
Keep in mind that this functionality might be abused as a spam engine or turned into one unintentionally if your comment spam filtering is inadequate.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 2,
"tags": "plugin recommendation, comments, email"
}
|
how do I force a single column layout in screen layout
I am using multipress, but users with small screens cannot access the HTML tab as the Publish meta box has a div that slides above it, disabling the ability to click it. One idea is to force a single column layout, but there are no options for this in screen options. Is there another way to do it?
|
You can use the filter `screen_layout_columns` to set only one column for the post screen `get_user_option_screen_layout_post` to force the user option to 1.
If you want to use that for custom post type then use `get_user_option_screen_layout_{post_type}`
The following code will do it:
function so_screen_layout_columns( $columns ) {
$columns['post'] = 1;
return $columns;
}
add_filter( 'screen_layout_columns', 'so_screen_layout_columns' );
function so_screen_layout_post() {
return 1;
}
add_filter( 'get_user_option_screen_layout_post', 'so_screen_layout_post' );
|
stackexchange-wordpress
|
{
"answer_score": 17,
"question_score": 6,
"tags": "wp admin, user interface"
}
|
Default menu editor with automatic page list
How can I add a page to the menu and define for the menu item that all subpages should be included by means of a simple checkbox?
|
you might be interested in one of my threads. Here: How to Hard Code Custom menu items
Thanks!
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 1,
"tags": "menus, functions, php"
}
|
How can I create an alternative home page?
I'm working on a site which has a fully customized front page. Now I'm asked to add a more classic looking blog type page which will be reacheable at `
I tried creating a custom (empty) page called `blog` and put some code into `page-blog.php`, but the problem is that I can't get The Loop to work in there: the page render aborts right where the display of The Loop should start.
Is a custom page the wrong way to do it?
|
Assuming you are using WordPress v3.x _(as I don't remember how this works in earlier versions)_ this is what you need to do if starting from scratch:
1. Create a _" **Page**"_ and call it _"Home Page" (or whatever.)_
2. Create another Page and call it _"Blog" (or whatever.)_
3. In the admin console select the _"Settings" > "Reading"_ option.
4. Select _"A static page"_ for the _"Front Page Displays"_ radio button.
5. Assign _"Front Page"_ to be _"Home Page" (or whatever from #1)_
6. Assign _"Posts Page"_ to be _"Blog" (or whatever from #2)_
7. Click _"Save Changes"_
8. You're done.
Here's a screenshot showing the admin console options:

|
stackexchange-wordpress
|
{
"answer_score": 6,
"question_score": 3,
"tags": "customization, page template, loop"
}
|
Prevent WordPress from loading comments
I'm displaying the comments for a post my way, using `$comm = get_comments()` and then passing `$comm` to `wp_list_comments()` (this is the reason why).
How to disable WordPress from loading comments from the database into `$wp_query`, when the comment template is being displayed ? I'm asking this because I want to avoid this extra database call, since I'm getting the comments myself using the above method.
PS: I also noticed the `$comments` global variable is a array containing ALL the comments for a post, not just the ones from the current comment page. If I have a post with 10K comments, WP will load all these at once? Seems ridiculous...
|
You can't prevent `comments_template()` from making an SQL query. Well, you could maybe hook into the DB layer to prevent just that specific query, but that would be very cumbersome to do. If this is for a theme, you could just remove the call to `comments_template()` and replace it with your own function. `comments_template()` doesn't do that much: just load all the comments, maybe also the just-submitted comment if it isn't approved yet, separate them into pings, trackbacks and regular comments if needed, and load the comments template file. Comments paging is relatively young in WordPress, so it's probably not as efficient as it could be yet.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 1,
"tags": "customization, comments, php, database, wp query"
}
|
Custom query_posts() parameter
I'm adding voting features to a theme. Visitors can vote posts Up or Down. I created a table for storing number of votes for each post and that works fine. Now I'm trying to sort posts by their votes.
I have "voted up" and "voted down" links. For instance, when you click on "voted up" a new parameter `sort=up` is passed in the URL.
In the loop if the parameter exists and is = "up" I want to loop posts with votes up.
wpdb->get_results("SELECT post_id, FROM $wpdb->votes WHERE up > 5");
This is where I want to use something like `query_posts('sort=up')` before the loop. My question is, how to I create the custom "sort" parameter?
|
If you have your data in separate table adding support for it in query is somewhat messy. Basically you will need to filter `posts_where` and `posts_join` to modify raw SQL query so that your custom table is joined and checked against your custom values.
As per [faster :)] anu's suggestion it would make sense to store values in Custom Fields and use Custom Field Parameters (related to Orderby, but not same thing) in query.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "php, query posts, database, wp query, mysql"
}
|
Why doesn't remove_action work in my plugin?
Using a WordPress multisite network with Buddypress. In order to modify the top nav bar, I've written a function to replace part of the menu. Calling it thus:
add_action('bp_adminbar_menus', 'new_adminbar_blogs_menu', 6);
remove_action('bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6);
Works perfectly in my functions.php, but when I try to move the above code to the plugin file, the remove_action fails to fire, but the add_action works as expected.
**As a temporary solution, renaming the function folder to something appearing after Buddypress alphabetically solved the issue.**
|
I am not sure about BuddyPress specifics.
In general case remove doesn't work when it is firing before function is actually added to the hook. Between core, plugins, parent and child themes there are a lot of relative combinations of add/remove possible.
In such case to make remove fire properly you need to wrap it into function and hook that wrapper function to some point later, after add.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "filters"
}
|
Host a blog engine in my wordpress site
Hi I have a website like www.shankpress.com, it is wordpress v3, and i want my users to have blogs hosted in my site and have url like: blogs.shaknpress.com...and I can show who got the most popular blog entry etc...
users can openly register, create a blog, start blogging and so on ...
I am willing to buy solutions if no free stuff is available...
|
To run multiple blogs on single installation of WordPress you need to enable and configure `multisite` functionality, see Create a Network.
While that will take care of basics, managing network of blogs controlled by users (rather than single admin/team) reliably and securely will likely require much more research and work.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "blog page"
}
|
Featured Image Size
I am in the process of developing a new theme for my blog and am making a featured content slider. The issue that I am having is getting wordpress to force the image to the dimensions that I want it to be. The exact dimensions are 494px x 168px. I've tried simple using `the_post_thumbnail( array(494, 168) );`, but that didn't work. I also tried adding a custom image size to my functions file. This would sometimes get the height right (but not always), but didn't get the width right a single time. Could somebody please give me a way to force the dang image to be 494px X 168px?
|
For post thumbnails you can either crop and image to the thumbnail size or scale the image. To enable crop you can call the thumbnail 1 of 2 ways.
1. Name a size in the functions.php file like so:
<?php add_image_size( 'my-post-thumbnail', 494, 168, true ); ?>
and then call it in the theme file
<?php the_post_thumbnail('my-post-thumbnail'); ?>
The true tells wordpress to crop the image rather than scale, to scale leave true out.
1. Call the size just in the theme file
<?php the_post_thumbnail(494, 168, true); ?>
Also, the_post_thumbnail doesn't work on images already uploaded. To test if the sizes truly aren't working upload a new file after adding the new thumbnail size/calling it in your theme file.
Mark on Wordpress has a good tutorial on Post Thumbnails <
|
stackexchange-wordpress
|
{
"answer_score": 9,
"question_score": 2,
"tags": "theme development, images"
}
|
What does ?cat=2-5-results mean at the end of URLs?
I'm seeing a lot of visits in my Analytics to my home page with the query string "?cat=2-5-results". These pages are getting a lot of traffic. To the best of my knowledge, I'm not using this parameter on my site anywhere. If I google "wordpress ?cat=2-5-results" I find a lot of other sites with the same phantom pages.
Anyone know what this means?
My site: <
Here are how the pages appear in GA: !alt text
|
It's used (together with the search query) to measure number of results for a search query, it's not supposed to show up in Analytics like this, this could only happen due to people scraping your site and clicking through to the actual URL...
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 0,
"tags": "taxonomy"
}
|
How can I call "preview post" from wp_remote_get with authentication?
I've got a plugin that needs to interogate the post preview (the contents of the rendered page that's presented when the user clicks "Preview Post".
To attempt to obtain this input stream into a code variable, I'm using wp_remote_get like so:
$response =
wp_remote_retrieve_body(
wp_remote_get(
'
$post->post_content = $response;
(I'm just replacing the post content with the results of the get for easy previewing during code testing).
My problem is that since I'm not passing any authentication parameters in the wp_remote_get, the preview action fails.
Is it possible to pass a parameter that authenticates the current user and returns the preview to the script?
|
Have you checked out the following plugin?
<
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "plugin development"
}
|
How to intergrate wordpress.com with twitter like the way it is with facebook?
(Please note this is not a wordpress.org question)
Hi everyone,
I want every new post on my blog automatically broadcasted on twitter - the same thing is beautifully supproted with facebook. But I cannot find how to activate it on my blog at namgivu.wordpress.com.
Please help if you know how to. Thank you!
|
Hi **@Nam Gi VU:**
In general, this is not really a WordPress question. I'll answer it because I tend to be lenient about how related questions need to be but there's a good change another moderator will close the question and if they do I'll agree.
Basically since WordPress.com does not provide this feature you need to use a 3rd party service that will read your RSS feed and send tweets to your Twitter account:
* **TwitterFeed**
* **Auto Tweet**
* **Feedburner Socialize** ( **Also**)
-Mike
P.S. One more thing. I do not recommend auto-tweeting blog posts. Most Twitter users _(myself included)_ will unfollow people who auto-tweet if they recognize them doing it. I want to hear from the person, not something they've set up to run automatically. FWIW.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "wordpress.com hosting, twitter"
}
|
Is there any plugin to show number of clicks on the link?
I have a post having different links. I have to show number of clicks on each link. Is there any link to show number of clicks on the link?
|
WP-Click-Track
<
> The click tracker works in 2 modes:
>
> 1. Scans posts and rewrites them to include a tracking element
> 2. Enables users to create stand alone trackable links that can be embedded in posts or offsite.
>
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "plugins, plugin recommendation, widgets"
}
|
is it possible to replace the use of gd_lib with imagick or ImageMagick?
i'm looking around for a solution since weeks and can't make anything work yet. the problem is that my server is running debian/lenny and it's not supporting the bundled gd_lib which i need for thumbnailing/cropping stuff.
but i could make use of imagick or imagemagick (package vs plugin). my question is: is there any way to replace the gd functions in media.php with the ones from imagick? AND is there a smarter way then modiyfing the media.php to do so?
thanks
|
Yes!
Orangelab has built a plugin which can replace WP's use of GD with Imagemagick (provided it's already installed on your server - it's not included) for creation of all image sizes and thumbs, and even regenerate existing images too!
For anyone who cares about image fidelity, this is huge deal, as GD does not handle color profile preservation or conversion (resulting in horrible desaturation), and also ends up softening any image it converts...
<
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 7,
"tags": "images, post thumbnails, core"
}
|
Should I use SVN or Git?
I've never used version control before, but I'm starting to work more collaboratively on WordPress plugins and themes and I think it would be a good idea to have a record of versions and updates.
WordPress seems to favour SVN, but Git seems to be the new, cooler alternative.
Which version control do you use currently? And which system would you choose today if you were starting out in WP theme and plugin dev?
|
I use Git for all my projects since it lets me work offline and that happens fairly often for me. Git can interface with SVN if you'd still like to use Git then push your plugins to WordPress.org.
* <
* <
|
stackexchange-wordpress
|
{
"answer_score": 10,
"question_score": 4,
"tags": "svn, git, version control"
}
|
Will a plugin able to know is_user_logged_in?
I am currently building a plugin and it doesn't know when a user is logged in.
global $current_user;
echo $current_user->ID;
It works when embedded on a template but not on a plugin? I have a custom database that depends on user_id, whenever I insert a record, user_id field always has a zero value while others have the correct one.
|
The `$current_user` global isn't setup until right before the `'init'` action is called. So any code using it shouldn't be fired until that action or later.
I would also suggest using the `get_current_user_id()` method instead of getting the global directly.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "plugin development"
}
|
custom taxonomies on pages
i need some help how can i display custom taxonomies on selected pages? i mean i have 3 custom taxonomies location,duration & courses i have created three pages where i want to display the terms of these custom taxonomies, i have displayed it on my posts by using function
<?php echo do_shortcode("[terms]"); ?>
but same thing i want to make display on my pages also, how can i do that??????
|
If you want to display a list of all terms in a taxonomy, you can call `wp_list_categories()` and pass the `taxonomy` argument to get anything other than the categories:
wp_list_categories( array(
'taxonomy' => 'your-taxonomy'
) );
If you want to use a shortcode for this, so you can use it in your post content, use `add_shortcode()`. This untested example code allows you to use `[taxonomy_terms]` or `[taxonomy_terms taxonomy=my-taxonomy]` in your content:
add_shortcode( 'taxonomy_terms', 'wpse4668_taxonomies' );
function wpse4668_taxonomies( $atts )
{
// Sanitize our input
$atts = shortcode_atts( array(
'taxonomy' => 'your-default-taxonomy',
), $atts );
// Don't echo the output, just return it
$atts['echo'] = 0;
return wp_list_categories( $atts );
}
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "custom taxonomy"
}
|
Creating a modal dialog without jQuery
I am writing a plugin that depends on modal dialogs for screen space.
Right now I am using jQuery to create the dialogs, but I want a way that integrates better into the admin theme.
Obviously WP has to have some sort of native dialog system (it's used for uploads). How do I access it?
|
The WordPress admin area uses Thickbox, which is still a jQuery plugin (jQuery is used all over the admin area). You need to enqueue the script and style (`add_thickbox()` does this for you), and then all links that have class `thickbox` will be converted. You need to add some URL parameters too, for example the image upload link looks like this: `media-upload.php?post_id=735&type=image&TB_iframe=1&width=640&height=285`. `post_id` and `type` are WordPress-specific, but `TB_iframe`, `width` and `height` are needed for Thickbox, and you should use them in your own links too.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 2,
"tags": "plugins, plugin development"
}
|
How to position custom dashboard widgets on side column
**My Question:**
Is it possible to add custom dashboard widgets in the right hand column instead of only on the left hands side?
I use `wp_add_dashboard_plugin( $widget_id, $widget_name, $callback, $control_callback = null )` to add the plugin code, but it doesn't have any options to allow you to set the position.
Any suggestions?
**My Comments:**
The Version 2.8 of WordPress suggests that it's possible, but I can't see anything in the code (/wp-admin/includes/dashboard.php) that is related to this.
It seems only to add the dashboard plugin if its name is in the `$side_widgets` array, the contents of which are: `array('dashboard_quick_press', 'dashboard_recent_drafts', 'dashboard_primary', 'dashboard_secondary');`
My thoughts are that I'd have to directly modify `$wp_meta_boxes['dashboard']` \- but I'm not sure of the consequences of this.
|
You're right - it doesn't. Neither does the `wp_add_dashboard_widget` function. So just use the generic `add_meta_box` and indicate dashboard and placement:
add_action( 'wp_dashboard_setup', 'my_dashboard_setup_function' );
function my_dashboard_setup_function() {
add_meta_box( 'my_dashboard_widget', 'My Widget Name', 'my_dashboard_widget_function', 'dashboard', 'side', 'high' );
}
function my_dashboard_widget_function() {
// widget content goes here
}
|
stackexchange-wordpress
|
{
"answer_score": 9,
"question_score": 0,
"tags": "widgets, dashboard"
}
|
Installing One Plugin on a Few Blogs on a MultiSite
I would like to install a plugin on 3 out of the 20 blogs I have going on my MutliSite WP 3.0. Is this possible?
|
The plugins folder is shared. You can install one copy of the plugin and _activate_ it on three blogs and not the others.
If you don;t want the others to be aware of the plugin's existence... you'll have to use another plugin to exclude it.
< or
<
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 3,
"tags": "multisite"
}
|
Safe way to find last inserted id in a table?
Is it safe to use `$wpdb->insert_id;` to find the `id` of a last updated `row id` just after an update? ex:
$sql = $wpdb->insert($table_name, $arrayWithDataToInsert, array('%s','%s'));
$results['new_created_id'] = $wpdb->insert_id;
or am I running into the possibility that I will catch the id of another row that was inserted immediatly after mine?
Thanks!
|
At a higher level, there truly isn't any means to know if the php/db connector will return the correct id by relying on $wpdb->insert_id. The only way to be 100% sure is to have add a key you know will be unique (and indexed as such); you can then retrieve the id by querying the table against that unique key.
The reason I write this is, if a trigger function adds rows from within the DB, or more importantly if a plugin hooks in wpdb in a such a way that it messes around with inserts alongside the one you're doing (e.g. for logging), you're not safe.
With that in mind, hardly anyone in the WP community (and most other communities, for that matter) has the slightest idea of what a DB can do, and treats the thing as if it's a bunch of huge arrays. So you're very safe to rely on it in practice.
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 2,
"tags": "database, wpdb"
}
|
Best practices for A/B testing?
What do you guys use for A/B testing with WordPress?
Knowing that WordPress has plugins for everything, I went looking for A/B testing plugin and didn't find any.
It also looks like < or similar solution may work together with WorpdPress. But I would much rather prefer managing everything in a single app.
Any ideas/suggestions?
|
This is not a straight WordPress solution but I would recommend a/b testing feature found in the Google website optimizer. <
It works with your analytics account. You just need to create two (or more) pages in WordPress.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 3,
"tags": "customization"
}
|
wp-login.php redirecting to HTTPS
I recently restored a WP multi-site 3.0.1 database from production to a staging environment, and when I try to login, I am being redirected to an HTTPS URL. The browser complains that the certificate is bad, and then when I click "proceed", it says page not found. I have cleared my browser cookies and all that good stuff, but it still won't let me login.
Also, I am experiencing intermittent "No site defined on this host" errors when I try to login.
I've never seen this issue before, and I have definitely done this backup db restore process before.
Thanks for your help, Dave
|
I figured this one out finally. It turns out that the data in the wp_usermeta table for user_id=1 (admin) was corrupted. This was apparently causing the SSL redirect issue when trying to login to any domains.
Once I restored the proper data for user_id=1 into wp_usermeta, everything worked fine. I would much rather have WordPress give an error like "hey, your usermeta data is messed up", rather than have some strange random behavior like that.
Thanks for the help, Dave
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 3,
"tags": "login"
}
|
How to change a user's role?
I have custom roles in my setup and I want to be able to automatically change a user's role thru a function. Say user A has a SUBSCRIBER role, how do I change it to EDITOR? When adding a role we just:
add_role( $role_name , $role_display_name , array( 'read' => true,
'edit_posts' => false,
'delete_posts' => false, ));
How about changing a role? Is there something like:
change_role($old_role, $new_role);
**UPDATE:** I think this one will do:
$wp_user_object = new WP_User($current_user->ID);
$wp_user_object->set_role('editor');
|
See the WP_User class, you can use this to add and remove roles for a user.
Specifically, a user's role can be modified by creating an instance of the `WP_User` class, and calling the `add_role`, `remove_role` or `set_role` methods depending on what your requirements are.
# Example
Removing the subscriber role, then adding the editor role.
// Making sure to adjust `3` to an appropriate user ID
$u = new WP_User( 3 );
// Remove role
$u->remove_role( 'subscriber' );
// Add role
$u->add_role( 'editor' );
The add and remove methods are probably most suited to use cases where users are given multiple roles.
If your aim is to simply switch a role, this is more easily done using the `set_role` method, like so.
// Making sure to adjust `10` to an appropriate user ID
$u = new WP_User( 10 );
// Switch role
$u->set_role( 'author' );
Hope that helps.
|
stackexchange-wordpress
|
{
"answer_score": 71,
"question_score": 52,
"tags": "user roles"
}
|
Get all posts in RSS
I'm wondering how/if I can access more than the most recent X posts defined in the wordpress settings. I've seen plugins that migrate all blog content through RSS, haven't poked around to see their methods.
Basically I manage a couple hundred WordPress blogs, and I'm building a newsletter generator for my clients. They want to be able to select a few posts and have the excerpts appear in the newsletter body. The sites are spread across multiple servers and the newsletter generator is being built on top of our CRM, so direct database queries would be difficult. RSS would be the cleanest, but I can't seem to figure out how to access more than 10 at a time (when 10 is set in the admin).
Any ideas?
|
Codex has example snippet on how to use `post_limits` filter to override amount set in admin for feed.
if (isset ($query->query_vars['feed']) and ($query->query_vars['feed'] == 'ics'))
add_filter('post_limits','__return_empty_string');
<
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 12,
"tags": "rss, feed"
}
|
Remove line breaks in wp_list_categories()?
I am trying to output a list of categories per an article. I am using the following code,
`<?php wp_list_categories('child_of=270&style=none'); ?>`
(string) Style to display the categories list in. A value of list displays the categories as list items while none generates no special display method (the list items are separated by `<br>` tags).
How do I remove the stupid `<br />` after each output?
Frustrating how this code
`<?php the_category(', '); ?>`
Will output the links without a line break...
Any help would be greatly appreciated.
|
I came to a solution for this by reviewing the Wordpress Codex. The trick is to turn off the automatic echo of wp_list_categories, and then use str_replace(). My example follows:
<?php $variable = wp_list_categories('child_of=270&style=none&echo=0'); ?>
<?php $variable = str_replace('<br />', '', $variable); ?>
<?php echo $variable; ?>
The only real change in your query is the inclusion of "echo=0" which will return the information in a variable rather than just displaying it.
The real work is done by str_replace() which looks for any `<br />` tags and removes them from the string. Then just echo out the updated string and no more breaks!
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 3,
"tags": "template tags"
}
|
Getting Thumbnail Path rather than Image Tag
I see many methods of showing thumbnails in WordPress, but I'm not immediately sure how I could get only the path to a post's thumbnail rather than the html-ready code generated by functions like `the_post_thumbnail()` and `get_the_post_thumbnail()`.
What methods are available to me to get _only_ the path of the thumbnail (to set it as a bgimage) rather than the `<img />` tag? Do I only have the option of parsing the results of the `get_` method or is there an easier way?
|
Thumbnail is essentially attachment so you can approach from that side - lookup ID with `get_post_thumbnail_id()` and fetch data with `wp_get_attachment_image_src()`, like this:
if (has_post_thumbnail()) {
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail_name');
echo $thumb[0]; // thumbnail url
}
(source)
|
stackexchange-wordpress
|
{
"answer_score": 10,
"question_score": 6,
"tags": "post thumbnails"
}
|
Missing argument 3 for wp_register_sidebar_widget()
I installed the Deprecated Calls plugin and it's telling me to change `register_sidebar_widget()` and `register_widget_control()`, essentially add `wp_` first.
I did but I'm getting `Missing argument 3 for wp_register_sidebar_widget()` and `wp_register_widget_control()`
Is it ok if I put the default `none` for the 3rd arg?
|
The signature of newer function is different:
* `register_sidebar_widget``( $name,` **`$output_callback`**`, $classname );`
* `wp_register_sidebar_widget``( $id, $name,` **`$output_callback`**`, $options );`
Can't simply replace one function with another here, need to re-order arguments accordingly.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "plugins, widgets, php, sidebar, functions"
}
|
Related Tags not in category
I'm using this piece of code to show related posts based on the tag of the post you are viewing.
I'd like to modify is a little to exclude the related posts from the loop if they are in the same category of the post you are viewing
Reason for this is i already have a loop to show related posts in the same category, so trying to cut out the duplicates.
<?php
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),
'showposts'=>5,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<!-- loop here -->
<?php
endwhile;
}wp_reset_query();
}
?>
Thanks
|
Very similar to what you do with tags. Retrieve IDs of categories for current post:
$categories = get_the_category();
$cat_ids = array();
foreach($categories as $category)
$cat_ids[] = $category->term_id;
Then exclude them in query:
'category__not_in' => $cat_ids,
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "categories, tags"
}
|
Use WordPress file upload in my plugin - on frontend and on backend?
Is there a way to use wp multifile upload system in my plugin?
|
You could always include the stuff related to swfupload, yes. But there will be a better way in WP 3.1: you'll be able to use the whole upload UI.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "customization, plugin development"
}
|
Check if variable is set in filter
Thanks to your suggestions, I enabled wp_debug and discovered flaws with my plugin. I have a filter for sorting posts by votes. I use it when the `sort` URL parameter is on.
`add_filter( 'posts_where', 'votes', 10, 2 );`
I used to get `Undefined index: sort` so I modified my function to first check if the variable is set.
function votes( $where, $query )
{
$sort = array_key_exists('sort', $query->query_vars) ? $_GET['sort'] : null;
if ( isset($sort) ) {
$where .= " AND $sort >= votes";
}
return $where;
}
This works fine but I'm not confident if it's correct. I'm wondering if there's a better method to do this.
|
The variable you have named `$query` is actually the WP_Query instance having filters applied to it.
You can simply call its function `get` to retrieve query vars.
For example:
function votes( $where, $query )
{
$sort = $query->get('sort');
if (!empty($sort)
$where .= " AND $sort >= votes";
return $where;
}
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "plugins, plugin development, php, functions, filters"
}
|
Server B handling add_image_size() differently than Server A
I'm curious what dependencies `add_image_size()` has because I just copied a theme over to a new server and began adding thumbnails to custom post types only to find out that my request for hard-cropping is being ignored, and the images are kept proportional.
**functions.php**
...
set_post_thumbnail_size( 80, 80, true );
add_image_size( 'micro', 32, 32, true);
add_image_size( 'featured', 340, 225, true );
add_image_size( 'videowide', 460, 225, true );
...
On my local server (WAMP Server on Windows Vista) the `true` is respected, and the images are cropped in such a way that extra pixels are lost - edges aren't respected. On my live server (CloudLinux Server 5.5 x64), the images are kept proportional.
Is there some gdlibrary dependencies or something I am needing to change on the live server to get the expected results?
|
This particular issue was caused by an environment missing GD. After installing GD on the server, the issue was resolved. Of course you will need to go back and re-submit your thumbnails to have correct cropping, or use a plugin to retroactively recreate your thumbnails.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "post thumbnails, images, cropping"
}
|
How can I detect hierarchal relationships beyond children (grandchild, great-grandchild, etc)?
Often times, a custom theme for Wordpress will require a dynamic content that reflects a relationship to a top level page of a site.
Is there a Conditional Tag that will check if the current page is a grand-child (or separated by further generations) by ID?
|
Turns out there is an excellent function that has been passed around the Wordpress forums `is_tree()`
function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath
global $post; // load details about this page
$anc = get_post_ancestors( $post->ID );
foreach($anc as $ancestor) {
if(is_page() && $ancestor == $pid) {
return true;
}
}
if(is_page()&&(is_page($pid)))
return true; // we're at the page or at a sub page
else
return false; // we're elsewhere
};
To use it in template, just give it the ID you want to check the current page against, and it will return true if the current page is a descendant.
`<?php if(is_tree(12)){echo 'foobar';} ?>`
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "theme development, templates, conditional content"
}
|
How to solve this problem with my subdomain?
I have my site hosted at < I have set a subdomain in it for my blog. But after landing on my blog whatever other links I click i get the link as <
I want it to be <
What should I do...?
|
Have you changed the site address to try and remove the wordpress from the URL? This is under Settings then General. You then have two URLs one of which is the actual physical directory and the other is the one you want to appear to the visitors to your website. This should allow you to remove the 'wordpress' element from your public URL, unless I am not understanding your question correctly and there is more to this than meets my eye?
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "customization"
}
|
How to display SQL query that ran in query?
I have come across a function before that displayed the exact SQL code that was used. In a loop for example, but can't remember.
Can anybody tell me that function?
|
Hi **@Keith Donegan:**
If I understand your question correctly I think this is what you are looking for?
<?php echo $GLOBALS['wp_query']->request; ?>
`$wp_query` is a global variable that contains the current query run by the loop. If you run the above code anytime while the loop is still active or even right after the loop it should give you the SQL from the loop. Just make sure you inspect it before letting something else run that uses `query_posts()` again.
|
stackexchange-wordpress
|
{
"answer_score": 163,
"question_score": 128,
"tags": "query, code, sql"
}
|
What are the differences in capabilities between the super-administrator and administrator?
What are the capabilities that a super-administrator has that an administrator does not have?
The codex page on user capabilities does not have a list of capabilities of the super-admin. It lists only the capabilities of the administrator.
|
The super_admin has access to all admininstrator APIs and also the multi-site functions. If you go to the codex page, it will say so: <
You can find the multisite functions here: <
If you want to do a more fine-grain investigation of what it can call, I suggest you get familiar with the WP code. The funtion you should grep for is_super_admin
Hope this helps.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 2,
"tags": "multisite, customization, capabilities"
}
|
Making the category & tag Description textarea bigger
Which files do i edit to make the textarea for tag & cat description bigger?
Or maybe there's an easier way through functions.php to save having to do it every-time i update wp?
Thanks
|
Hook onto the edit-tags page and insert some additional styling to adjust the textarea, the ID remains the same for post tags, categories and i think other taxonomies to..
# Adjust CSS for taxonomy management page
Example only, tailor to suit you needs.
add_action( 'admin_print_styles-edit-tags.php', 'resize_description_field' );
function resize_description_field() {
?>
<style type="text/css">
textarea#tag-description { height:300px!important; }
</style>
<?php
}
Hope that helps..
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "categories, admin"
}
|
Host wordpress on a subdirectory of a Rails application
I would like to know if it is possible to host a wordpress blog on the subdirectory of a rails application:
For instance: I would like to have domain.com/blog instead of having my blog on a subdomain: blog.domain.com .
I'm currently using lighttpd, but I can switch to something else if there is a solution.
Thanks
|
You can also set an apache Alias to say /blog is /path/to/wordpress
so it's technically not inside your RoR app, you can deploy/make changes to the RoR app all day long then, without the need to worry about overwriting wordpress files.
|
stackexchange-wordpress
|
{
"answer_score": 6,
"question_score": 2,
"tags": "hosting"
}
|
How can I add Google ads to my home page?
Guys I know this is the stupid question but need a little help, I need to put ads on my homepage as I have on my post page:
!alt text
These are the ads I get on my post page (i.e `single.php`).
I also want the same thing on my home page over here:
!alt text
I tried using a `<div>` tag like I did on `single.php`, but it is not working.
|
How do you have your home page set up and what template are you trying to modify? Usually it is `index.php` or `home.php`, but it can also be `front-page.php` or even something completely different from defaults.
See Template Hierarchy in Codex.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 2,
"tags": "adsense"
}
|
greatest() function returns undefined property
I'm using the mysql GREATEST() function to compare two table fields and display in a loop either one with the highest integer value. The 2 fields consist of vote scores for posts: UP or DOWN.
function vote_results($post_id) {
global $wpdb;
$table = $wpdb->prefix . "post_votes";
$results = $wpdb->get_row( "SELECT GREATEST (up, down) FROM $table WHERE voted_post_id = $post_id" );
echo $results->up; //echo if highest value
echo $results->down; //echo if highest value
}
Then in my loop I call the function but get `Notice: Undefined property: stdClass::$up` for
echo $results->up;
and the same notice for `down`. I'm not sure what I'm doing wrong here.
|
I think you want to use `get_var()`, not `get_row()` \- looking at the documentation, MySQL's `GREATEST` just returns a single value.
`$results` will then just be the value of the greatest (be it `up` or `down`).
If you want the greatest `up` **and** the greatest `down`, use;
$wpdb->get_row("SELECT GREATEST(up) AS 'up', GREATEST(down) AS 'down' ...")
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 1,
"tags": "plugins, database, query posts, functions, mysql"
}
|
Limit author image size
Is there a way to limit the size (dimensions) of the image a user can upload to their profile? It looks like Wordpress does do some kind of limiting as uploading a 1024x768 image the result gets scaled down to 360x270, but where is that configured, either in the UI (which I haven't found) or through code?
This is the section of the user profile I'm referring to: !alt text
|
It looks like the author image section of the User Profile editor was from the "Author Image" plugin. I didn't suspect that at first because I didn't know that plugins were allowed to modify that screen, so I thought it was just a build-in Wordpress function and that the plugin just allowed for easy display.
As it doesn't look like the plugin has a settings page I ended up just modifying the plugin itself. For those curious, the file to modify is `sem-author-image-admin.php` and the variable is about 3/4 of the way down, just search for the comment `// Set a maximum height and width` and you'll find it. (There's no guarantee that this will remain the same in future versions and upgrading the plugin will most likely break this, just an FYI)
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "images, author, customization"
}
|
Setting up custom post type archives in WP3.1? Any luck?
I've just moved a site I'm developing to WP3.1 so that I can take advantage of and start testing some of the new features. I'm especially liking the `has_archive` parameter in registering custom post types. I had a post type called 'recipes', and added this line to the args on registering it:
'has_archive' => 'recipe-listings',
From what I understand, that should generate the rewrite rules necessary to make **/recipe-listings/** be equivalent to **/?post_type=recipe**. However, I can't seem to get it working.
The generic form < works fine, but < just goes to 404. What else do I need to do to get custom post type archives working properly? Has anyone else worked it out yet?
|
I asked the question too soon. And thanks to @Jan Fabry for pointing me in the right direction.
In case anyone else has this problem, here's the answer.
Any time the rewrite rules are changed (adding a new post type, changing the slug or the has_archive slug, etc.) you have to call `flush_rewrite_rules` once. It has to be called after the post types are registered. I put it at the very end of my function which registered the post types on 'init', visited the site once, then deleted it out. Now the site works fine.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 5,
"tags": "custom post types, archives, customization"
}
|
Insert all post IDs in new database table
I have a plugin which creates a new database table. Upon activating the plugin is there a way to insert all my posts ids into that table?
Right now I'm using an action hook to immediately insert the id of new posts I publish.
function transfer_post_id($post_ID) {
global $wpdb;
if (!($wpdb->get_row("SELECT post_id FROM $my_table WHERE post_id = $post_ID" ) ) ) { //if post id not already added
$wpdb->insert( $my_table, array( 'post_id' => $post_ID ) );
}
return $post_ID;
}
add_action ( 'publish_post', 'transfer_post_id' );
However there are posts before activating the plugin that I need a way to insert without manually updating each one.
|
Like so:
INSERT INTO $mytable (post_id)
SELECT ID
FROM $wpdb->posts as posts
LEFT JOIN $mytable as dup_check
ON dup_check.post_id = posts.ID
WHERE dup_check.post_id IS NULL;
|
stackexchange-wordpress
|
{
"answer_score": 6,
"question_score": 1,
"tags": "php, query posts, hooks, functions, mysql"
}
|
Replace the Post Excerpt Meta Box with a Field in My Custom Meta Box
I've got a custom meta box for a custom post type which will be the only metabox I plan to show in the main column (except the native title box). I want to move the native Expert box/field inside my Custom Meta Box.
I'm able to create a field called Excerpt in my Meta Box, however I only know how to save this to the Custom Fields, not the original location that the native Except saves to.
|
Just name the field 'excerpt'.
E.g.:
<textarea name="excerpt" id="excerpt"><?php echo esc_html( '$post->post_excerpt' ); ?></textarea> <!-- if it is a textarea field -->
or
<input name="excerpt" id="excerpt" value="<?php echo esc_attr( '$post->post_excerpt' ); ?>" /> <!-- if it is a text field -->
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "metabox, excerpt"
}
|
Resetting comment count
Recently, I had to move to another domain and had to recreate all my MySQL tables on the enw server. I noticed that for some posts, the number of comments is doubled. Example - <
In the above post, there's only 4 comments, but the comment count shoes 8 comments. I am not sure it is not a theme-related issue, as this happens only for a few posts.
Can someone show me how to write a MySQL query to recount the comments for all posts? Or maybe a plugin?
|
Try this code:
## **WARNING: THIS IS JUST PSEUDOCODE!**
$entries = $wpdb->get_results("SELECT * FROM wp_posts WHERE post_type IN ('post', 'page')");
foreach($entries as $entry)
{
$post_id = $entry->ID;
$comment_count = $wpdb->get_var("SELECT COUNT(*) AS comment_cnt FROM wp_comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1'");
$wpdb->query("UPDATE wp_posts SET comment_count = '$comment_count' WHERE ID = '$post_id'");
}
Or you might want to try solution from this page (although it's not the proper way as you will add another query for every post)
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 6,
"tags": "comments, database, errors, mysql"
}
|
Search and replace text across all posts
I had used the ZD Video Plugin for WP a long time, and now, since my move to WP 3.0.2, it doesn't work anymore. To embed a YouTube video using the plugin, I would just write
> [zdvideo]url-of-youtube-video[/zdvideo]
Now I need to go back to plain YouTube embedding. How do I write a MySQL query that searches for `[zdvideo]*[zdvideo]` and replaces it with `*`?
|
What about these two queries?
UPDATE wp_posts SET post_content = REPLACE(post_content, '[zdvideo]', '');
UPDATE wp_posts SET post_content = REPLACE(post_content, '[/zdvideo]', '');
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 3,
"tags": "plugins, search, mysql, query"
}
|
Why does this echo values in the wrong order?
I'm sure there is a simple reason/answer for this: Why does
`echo 'Archive for '. the_time('Y');`
give me `2010Archive for`? I had expected it would give me `Archive for 2010`
|
As most template tags that start with `the_` this one echoes time and not returns it (which template tags that start with `get_the_` do).
First `the_time()` fires and echoes year, then its return (`null`) gets concatenated and echoed with string.
So:
echo 'Archive for ';
the_time('Y');
Or:
echo 'Archive for ' . get_the_time('Y');
|
stackexchange-wordpress
|
{
"answer_score": 8,
"question_score": 2,
"tags": "php, date time"
}
|
Automatic updates not working/plugins not installing
I am trying to run an automatic update from Wordpress 3.0 to 3.02. However, I get the following error message:
"Unable to locate WordPress Root directory.
Installation Failed"
I also cannot install plugins on the same server. The error message for the plugins is quite similar: "Plugin could not be deleted due to an error: Unable to locate WordPress Plugin directory."
I have contacted the host but they have not been much help.
Any ideas would be greatly appreciated.
Thank you! Jeff
|
Jeff, unfortunately this looks like a problem with your hosting setup, so your host will be the only one who can help. If they can't, and the problem doesn't correct itself, I'd recommend exporting your site and moving to a more supportive host.
In the meantime, though, who is your current host? If you have FTP access, try manually updating a plug-in by transferring the new files to your server. If that works, then you can manually update WordPress using the standard upgrade instructions.
If you don't have FTP access and still can't auto-update, there's not much more we can do without going through your host directly.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "plugins, updates"
}
|
Remove the Featured Image Meta Box
How can I remove the Featured Image meta box? I've tried using the `remove_meta_box` function and specifying the boxes ID but it doesn't seem to work like it does for the other native meta boxes.
Here is the specific code I tried:
add_action( 'admin_menu', 'remove_thumbnail_box' );
function remove_thumbnail_box() {
remove_meta_box( 'postimagediv', 'post', 'side' );
}
|
I haven't had time to test this but this looks like it should work for you.
add_action('do_meta_boxes', 'remove_thumbnail_box');
function remove_thumbnail_box() {
remove_meta_box( 'postimagediv','post','side' );
}
Check this for more info.
**Edit:** The main change here is that you need to attach the function to do_meta_boxes instead of admin_menu
|
stackexchange-wordpress
|
{
"answer_score": 21,
"question_score": 9,
"tags": "metabox, post thumbnails"
}
|
Remove Default Blogroll Links via Plugin script
I have a plugin that I use on all my new sites to set up site defaults (deletes the "hello world" post, the "about" page, the "Mr WordPress" comment, etc...)
I'd like to add a routine that removes all the default links under "Blogroll". I'm not sure what function to call. Any ideas?
|
Haven't tested this yet, but it should do the trick in 3x:
// Get all the existing links
$arr_args = array( 'hide_invisible' => 0 );
$arr_links = get_bookmarks( $arr_args );
// Run through the list and delete 'em
foreach($arr_links as $obj_link) {
wp_delete_link($obj_link->link_id);
}
Of course, you'd only want to do this once, and only on a fresh install as it deletes all links. Alternately, you could hardcode an array of default link slugs/ids and loop through that instead. Depends where and when you're running this thing.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "plugin development"
}
|
Importing users to Buddypress with custom fields
Here's the setup:
* The client uses a proprietary custom-coded PHP CMS and is wanting to move to WordPress with BuddyPress.
* The old, custom CMS has a roster functionality, which I'm using BuddyPress custom fields to replace.
* The custom fields are basic contact info (Phone, Fax) and company info (Text field).
What is the best way to import these? It seems my two options are:
1. Create a pretty large SQL query that reformats this data between databases (I'm about 3 hours into doing it this way so far)
2. Export it into some sort of JSON format and use the Ning importer.
If the best option is using the Ning importer, know where I can get an example Ning user list CSV so I may format the user data accordingly? If the best option is using a big MySQL query, what are some things I should look at in terms of row values WordPress expects?
Many thanks!
|
I ended up writing a bunch of MySQL statements. My process went:
1. Add users into wp_users.
2. Add first name into wp_usermeta.
3. Add last name into wp_usermeta.
4. Add nickname into wp_usermeta.
5. Add last activity into wp_usermeta. (This is important for BuddyPress; otherwise, users won't show up in the members-loop)
6. Add name to BuddyPress.
7. Add custom "phone" field to BP.
8. Add custom "fax" field to BP.
9. Add custom "company" field to BP.
~~If anybody doing something similar comes across this question and would like the SQL I used, feel free to message me.~~ After half a dozen people requested the SQL code I have, I've written a blog post that includes the full SQL I used, plus a basic importer script. See: <
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 2,
"tags": "custom field, mysql, buddypress, import, bulk import"
}
|
What are the advantages of WordPress over other systems?
I've tried to explain the benefits of WordPress to others; comparing it to static sites is easy, as (most) everything can be done online with WP. I have more difficulty comparing and contrasting with other content management systems such as Drupal.
I realize that there is no perfect system for every use, but what features - if any - of WordPress would you point out as being easier or more useful, compared to other tools?
I am particularly interested in features regarding use of WP as a CMS, not just a blog.
|
Hi **@Grant Palin** :
My use of WordPress is almost exclusively CMS, and the other software I have experience with is **Drupal** _(2 years ago, but have continued to follow it)_ and **DotNetNuke** _(5 years ago, and I haven't looked back.)_ I also reviewed **Joomla** about 3+ years ago and found is to be both too complex and too inflexible, so I never seriously considered it.
Anyway, I can only speak with any real authority about how WordPress compares with Drupal as a CMS, and as luck would have it I wrote a blog post about exactly topic last week:
* **17 Reasons WordPress is a Better CMS than Drupal**
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 1,
"tags": "cms, comparison"
}
|
How to add a description to Widgets?
The codex doesn't seem to say how one would go about adding a description to a custom widget registered with `wp_register_sidebar_widget()`. The default description seems to be the name of teh widget itself.
function myFunc(){
/* widget code */
}
wp_register_sidebar_widget( 'wdgt1', 'Site Map', 'myFunc', array() );
!alt text
|
Here's what you looking for:
class WP_Widget_Sitemap extends WP_Widget {
function WP_Widget_Sitemap() {
$widget_ops = array( 'classname' => 'widget_sitemap', 'description' => __( "This is the description" ) );
$this->WP_Widget( 'sitemap', __('Site Map'), $widget_ops);
}
function widget() { ... }
function form() { ... }
function update() { ... }
...
See: <
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 2,
"tags": "widgets"
}
|
User bar above logotipo?
I am looking for a simple example on how to create a user bar or a simple theme with it that can serve me as example.
What I meant is something like we have here on Wordpress Answers if u get above the logo you have a userbar with information when user is logged in and options to login/register when user is not logged in.
I did a small search around here with the terms navigation bar and user bar but didnt find anything for the header.
|
If you're looking for an example how this can be done, grab the current development version of wordpress. It's already everything in there you might need / can imagine.
If you don't want to make use of 3.1 but 3.0, use the 3.1 code as the example you're asking for. The user bar is located in admin-bar.php and class-wp-admin-bar.php.
Your theme needs to support `admin-bar` and the code takes care on it's own by point-cutting the `wp_head` hook - which you should have in your theme in any case. Script and CSS styles are named 'admin-bar' as well.
So it's basically copying over the files to your site, enabling theme support for it and if there are some 3.1 only functions used therein, work around those. You can additionally move those files to your theme, rename functions and classes to reflect your namespace to have this a bit more separated.
A benefit to make use of that is that your site will be compatible when updating to 3.1.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "customization, theme development"
}
|
You do not have permission to edit this user
I am using wordpress mu. My blog administrators are unable to edit users - getting the message: You do not have permission to edit this user. I have checked my plugins etc and cannot find the cause. Is there a solution to this problem?
|
this is set in wp-config.php: define( "EDIT_ANY_USER", true );
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "multisite"
}
|
Update users custom profile fields
Ok guys, i have problem when using some trics from here or other sites. I`m trying to use this method of adding custom user fields. But, when i add this, everytime i save it`s all ok, but when i come back to edit something different in user profile, those new fields just goes blank, and if i did not input again my data in those fields and save my profile, those fields goes blank in DB. So, something is not ok that need to show me what i did just saved.
As I told, it`s all ok until i open again my profile for editing.
Ok, here is code, <
|
You have specified the value of the `<textarea>` in a `value` attribute, but for a `<textarea>` you must put it between the two tags:
<textarea rows="10" cols="60" name="adsense_336" id="adsense_336" class="regular-text" ><?php echo esc_attr( get_the_author_meta( 'adsense_336', $user->ID ) ); ?></textarea>
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "functions"
}
|
Server-side sorting of posts
I have seen on some websites that you can sort posts server-side by passing in some queries like so: `domain.com/?sort=date` or `domain.com/?sort=name`
How would I do this with WordPress posts on a page?
|
The display of posts is controlled by WordPress Loop. It has a lot of possible arguments, but they are rarely exposed in URL (especially if using pretty permalinks).
But it is possible to make use of arguments by manually adding them to URL.
For sorting see Orderby Parameters. Your example would be something like:
domain.com/?orderby=date
domain.com/?orderby=title
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "posts, sort"
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.