qid int64 4 8.14M | question stringlengths 20 48.3k | answers list | date stringlengths 10 10 | metadata list | input stringlengths 12 45k | output stringlengths 2 31.8k |
|---|---|---|---|---|---|---|
4,041 | <p>If possible, how can installed plugins (meaning the files have been placed in wp-content/plugins directory) be activated from other plugins?</p>
| [
{
"answer_id": 4043,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 4,
"selected": false,
"text": "<p>Plugin activation process is coded to work with WP admin interface. It performs some checks to prevent enabling plugi... | 2010/11/14 | [
"https://wordpress.stackexchange.com/questions/4041",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/353/"
] | If possible, how can installed plugins (meaning the files have been placed in wp-content/plugins directory) be activated from other plugins? | This is how I did it in some web apps:
```
function run_activate_plugin( $plugin ) {
$plugin = trim( $plugin );
$current = get_option( 'active_plugins' );
$plugin = plugin_basename( $plugin );
if ( !in_array( $plugin, $current ) ) {
$current[] = $plugin;
sort( $current );
do_ac... |
4,045 | <p>I'm adding an action witht he following line: </p>
<p><code>add_action( 'admin_init', 'fb_init_scripts');</code></p>
<p>And my function looks like this:</p>
<pre><code> function fb_init_scripts() {
//Only use these scripts in admin interface
if (is_admin() ) {
wp_enqueue_script('jquery-ui','http... | [
{
"answer_id": 4046,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 4,
"selected": true,
"text": "<p>Yep, pointless.</p>\n\n<p><code>admin_init</code> only fires in admin area (and couple more files related to AJAX func... | 2010/11/14 | [
"https://wordpress.stackexchange.com/questions/4045",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1447/"
] | I'm adding an action witht he following line:
`add_action( 'admin_init', 'fb_init_scripts');`
And my function looks like this:
```
function fb_init_scripts() {
//Only use these scripts in admin interface
if (is_admin() ) {
wp_enqueue_script('jquery-ui','http://ajax.googleapis.com/ajax/libs/jqueryu... | Yep, pointless.
`admin_init` only fires in admin area (and couple more files related to AJAX functionality) so additional `is_admin()` check is not necessary.
It often comes up in examples for hooks that fire both on front-end and admin area. |
4,074 | <p>I have a main page where i want to show up the latest post content of two or more blogs.. for now I have this code : </p>
<pre><code> <?php
// Include WordPress Blog 1
define('WP_USE_THEMES', false);
require('./blog1/wp-load.php');
?>
<?php query_posts('showposts=3');?>
<... | [
{
"answer_id": 4080,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 3,
"selected": true,
"text": "<p>I highly doubt you can get it to work that way reliably. WordPress relies a lot on global variables and so there is no... | 2010/11/15 | [
"https://wordpress.stackexchange.com/questions/4074",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/420/"
] | I have a main page where i want to show up the latest post content of two or more blogs.. for now I have this code :
```
<?php
// Include WordPress Blog 1
define('WP_USE_THEMES', false);
require('./blog1/wp-load.php');
?>
<?php query_posts('showposts=3');?>
<?php while (have_posts()): th... | I highly doubt you can get it to work that way reliably. WordPress relies a lot on global variables and so there is no way you can keep two WordPress instances active and sane at the same time.
My suggestion would be to use RSS feeds of posts from those two blogs (with RSS widget or [`fetch_feed()`](http://codex.wordp... |
4,089 | <p>I have been trying to get this worked out for over a year and have tried numerous ways and have not been able to get it to work. I'd really appreciate it if someone could help me with this. Here's what I'm trying to do...</p>
<p>I need to create 15 custom metaboxes for the Write screen on my custom post type for ... | [
{
"answer_id": 4097,
"author": "Wyck",
"author_id": 1509,
"author_profile": "https://wordpress.stackexchange.com/users/1509",
"pm_score": 2,
"selected": false,
"text": "<p>I know you said you don't want another plug-in but I would recommend checking out \"Verve meta boxes\" or \"Custom F... | 2010/11/15 | [
"https://wordpress.stackexchange.com/questions/4089",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/765/"
] | I have been trying to get this worked out for over a year and have tried numerous ways and have not been able to get it to work. I'd really appreciate it if someone could help me with this. Here's what I'm trying to do...
I need to create 15 custom metaboxes for the Write screen on my custom post type for Slideshows (... | Solve a complex Problem (rationally)
====================================
To solve complex problems, there is a kind of standardized/well known approach: Divide your complex problem into a set of smaller problems. Smaller problems are easier to solve. If you have solved each smaller problem you most often have solved ... |
4,092 | <p>How to remove comment section from page only , not from posts pages?</p>
| [
{
"answer_id": 4093,
"author": "Jan Fabry",
"author_id": 8,
"author_profile": "https://wordpress.stackexchange.com/users/8",
"pm_score": 3,
"selected": false,
"text": "<p>If you want to display comments and the comment form on posts but not on pages, you need to split up the logic in you... | 2010/11/15 | [
"https://wordpress.stackexchange.com/questions/4092",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/32/"
] | How to remove comment section from page only , not from posts pages? | If you want to display comments and the comment form on posts but not on pages, you need to split up the logic in your template file to call [`comments_template()`](http://codex.wordpress.org/Function_Reference/comments_template) depending on the type of the item displayed (post or page). There are two ways to do this:... |
4,095 | <p>Using <code>/%category%/%postname%/</code> for the permalink I get a URL string of all the categories that the specific post is included in.
I would like the categories in the url to be filtered down to only one branch of the categories structure, and starting not from the root parent category.</p>
<p>I have a trav... | [
{
"answer_id": 4096,
"author": "Jan Fabry",
"author_id": 8,
"author_profile": "https://wordpress.stackexchange.com/users/8",
"pm_score": 3,
"selected": true,
"text": "<p>This should be possible. First, you're lucky that <code>www.mytravelblog.com/jakarta/myPostName/</code> already works,... | 2010/11/15 | [
"https://wordpress.stackexchange.com/questions/4095",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/967/"
] | Using `/%category%/%postname%/` for the permalink I get a URL string of all the categories that the specific post is included in.
I would like the categories in the url to be filtered down to only one branch of the categories structure, and starting not from the root parent category.
I have a travel blog and I have th... | This should be possible. First, you're lucky that `www.mytravelblog.com/jakarta/myPostName/` already works, it shows you the post and doesn't redirect you to the longer version (at least it seems to work on my side). That means you only have to work on the generated link, and not mess with the way incoming URLs are han... |
4,134 | <p>As per documentation I satisfied all the requirements of the like button by using the meta-tags, however I still don't get the image I would like linked by Facebook: it always goes fishing for another image in the sidebar.</p>
<p>Now, of course I could solve this by being explicit about which image I really want bu... | [
{
"answer_id": 4139,
"author": "Lars Koudal",
"author_id": 667,
"author_profile": "https://wordpress.stackexchange.com/users/667",
"pm_score": 2,
"selected": false,
"text": "<p>Yoast.com actually covered this quite recently...</p>\n\n<pre><code>if ( is_singular() ) {\n global $post;\n ... | 2010/11/16 | [
"https://wordpress.stackexchange.com/questions/4134",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/890/"
] | As per documentation I satisfied all the requirements of the like button by using the meta-tags, however I still don't get the image I would like linked by Facebook: it always goes fishing for another image in the sidebar.
Now, of course I could solve this by being explicit about which image I really want but I do I g... | Yoast.com actually covered this quite recently...
```
if ( is_singular() ) {
global $post;
if ( current_theme_supports('post-thumbnails')
&& has_post_thumbnail( $post->ID ) ) {
$thumbnail = wp_get_attachment_image_src(
get_post_thumbnail_id( $post->ID ), 'thumbnail', false);
echo '<meta prop... |
4,136 | <p>I need to create a plugin that makes custom page templates available in wp-admin. I'm wondering if someone has tackled this already, as it seems like a pretty typical process?</p>
| [
{
"answer_id": 4138,
"author": "Lars Koudal",
"author_id": 667,
"author_profile": "https://wordpress.stackexchange.com/users/667",
"pm_score": 2,
"selected": false,
"text": "<p>I'm not entirely sure I understand what you are trying to achieve, at least why you would want a plugin to do t... | 2010/11/16 | [
"https://wordpress.stackexchange.com/questions/4136",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1341/"
] | I need to create a plugin that makes custom page templates available in wp-admin. I'm wondering if someone has tackled this already, as it seems like a pretty typical process? | Like Rarst answered you can really do that without editing core files or remove the page attributes metabox and create your on using the same code with a bit of modification.
the code below is the code for the /admin/include/meta-boxes.php
and i added the a comment to show where your extra page template options would g... |
4,140 | <p>Currently, it is up to any plugin's author as to where to put a link to the plugin's option page. I have seen at least the following "solutions":</p>
<ul>
<li>Plugin list</li>
<li>Dashboard menu</li>
<li>Plugins menu</li>
<li>Appearance menu </li>
<li>Tools menu </li>
<li>Settings menu</li>
<li>Tools menu</li>
<li... | [
{
"answer_id": 4138,
"author": "Lars Koudal",
"author_id": 667,
"author_profile": "https://wordpress.stackexchange.com/users/667",
"pm_score": 2,
"selected": false,
"text": "<p>I'm not entirely sure I understand what you are trying to achieve, at least why you would want a plugin to do t... | 2010/11/16 | [
"https://wordpress.stackexchange.com/questions/4140",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1524/"
] | Currently, it is up to any plugin's author as to where to put a link to the plugin's option page. I have seen at least the following "solutions":
* Plugin list
* Dashboard menu
* Plugins menu
* Appearance menu
* Tools menu
* Settings menu
* Tools menu
* Top level
In my opinion, this is very bad style (globally, not n... | Like Rarst answered you can really do that without editing core files or remove the page attributes metabox and create your on using the same code with a bit of modification.
the code below is the code for the /admin/include/meta-boxes.php
and i added the a comment to show where your extra page template options would g... |
4,142 | <p>I need to prevent uploading bmp image for user. How can it be possible?</p>
| [
{
"answer_id": 4143,
"author": "hakre",
"author_id": 178,
"author_profile": "https://wordpress.stackexchange.com/users/178",
"pm_score": 3,
"selected": false,
"text": "<p>The magic is in <code>get_allowed_mime_types()</code> which calls the <code>upload_mimes</code> filter. That is filte... | 2010/11/16 | [
"https://wordpress.stackexchange.com/questions/4142",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1581/"
] | I need to prevent uploading bmp image for user. How can it be possible? | I have found the solution [from here](http://netweblogic.com/other/adding-removing-allowed-filetypes-wordpress-media-library/). And its working!
WordPress has a set of restricted filetypes it will allow you to upload via the media library. Whilst this is a great security feature, there may be times where you’d like t... |
4,153 | <p>When a user tries to share a page with an embedded video on it only the title of the pages shows up on their facebook status and not the flash video player. This happens while sharing with the addthis button or if the url is posted directly to the facebook page. Any idea how I can make facebook pickup the embedded ... | [
{
"answer_id": 4157,
"author": "EAMann",
"author_id": 46,
"author_profile": "https://wordpress.stackexchange.com/users/46",
"pm_score": 4,
"selected": true,
"text": "<p>That really depends on how the video is embedded into the page. Facebook can only handle specific formats and if it se... | 2010/11/16 | [
"https://wordpress.stackexchange.com/questions/4153",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1596/"
] | When a user tries to share a page with an embedded video on it only the title of the pages shows up on their facebook status and not the flash video player. This happens while sharing with the addthis button or if the url is posted directly to the facebook page. Any idea how I can make facebook pickup the embedded flas... | That really depends on how the video is embedded into the page. Facebook can only handle specific formats and if it sees something it doesn't expect, it defaults to a failsafe "show nothing" standard.
If the embedded video is well-recognized standard (i.e. YouTube's default player) it should work just fine. If it's yo... |
4,177 | <p>How to query Post with current date month with custom field:</p>
<p>Here is my code</p>
<pre><code> <?php
global $wp_query;
$event_month = get_post_meta($wp_query->post->ID, 'eventdate', true); //format in db 11/17/2010
$event_month = date("n"); //A numeric representation of a month, withou... | [
{
"answer_id": 4184,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 2,
"selected": true,
"text": "<p><code>meta_key</code> value should be name of custom field. I doubt you have fields named after each month, so it's li... | 2010/11/17 | [
"https://wordpress.stackexchange.com/questions/4177",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/420/"
] | How to query Post with current date month with custom field:
Here is my code
```
<?php
global $wp_query;
$event_month = get_post_meta($wp_query->post->ID, 'eventdate', true); //format in db 11/17/2010
$event_month = date("n"); //A numeric representation of a month, without leading zeros (1 to 12)
... | `meta_key` value should be name of custom field. I doubt you have fields named after each month, so it's likely should be `eventdate`.
`meta_compare` should have value that specifies a comparison operator, or just be omitted and it will default to `=` in that case.
From this you can't really query full event date on ... |
4,178 | <p>I am building a custom menu section (a new item with subitems in the main menu section on the left side) in the WordPress Administration of my website. The section shall include a main post type, and for this you should be able to link category and country.</p>
<p>It would be possible to use taxonomies, but taxonom... | [
{
"answer_id": 8534,
"author": "hakre",
"author_id": 178,
"author_profile": "https://wordpress.stackexchange.com/users/178",
"pm_score": 0,
"selected": false,
"text": "<p>You need to modify the menu individually by code, most certainly by a plugin. <a href=\"http://codex.wordpress.org/Ad... | 2010/11/17 | [
"https://wordpress.stackexchange.com/questions/4178",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3216/"
] | I am building a custom menu section (a new item with subitems in the main menu section on the left side) in the WordPress Administration of my website. The section shall include a main post type, and for this you should be able to link category and country.
It would be possible to use taxonomies, but taxonomy only sup... | WordPress let's you define where a post type appears in the args where you register it. It's the `show_in_menu` argument. You can set it to true, false or a the slug (a string) of the page under which you'd like it to appear.
So, let's say you already have a post type "main". To display another post type under that yo... |
4,182 | <p>I'm intending to use the default "post tags" taxonomy to provide a common set of tags across posts and 2 custom post types (to allow for collection/aggregation by tag).</p>
<p>I'd like to rename the "post tags" taxonomy to something else - like "general tags' - to make it a bit clearer, especially when this taxonom... | [
{
"answer_id": 4188,
"author": "Jan Fabry",
"author_id": 8,
"author_profile": "https://wordpress.stackexchange.com/users/8",
"pm_score": 6,
"selected": true,
"text": "<p>The information about taxonomies is stored in the global <code>$wp_taxonomies</code> array. If you register a new taxo... | 2010/11/17 | [
"https://wordpress.stackexchange.com/questions/4182",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/490/"
] | I'm intending to use the default "post tags" taxonomy to provide a common set of tags across posts and 2 custom post types (to allow for collection/aggregation by tag).
I'd like to rename the "post tags" taxonomy to something else - like "general tags' - to make it a bit clearer, especially when this taxonomy is attac... | The information about taxonomies is stored in the global `$wp_taxonomies` array. If you register a new taxonomy, it is added as an object with different properties, including the labels to use in the UI. The standard tags and categories are also registered there on each page load, with [the `create_initial_taxonomies()... |
4,191 | <p>I would like to be able to grant my editors the power to change the menu, can this be done?</p>
<p>The appearance tab doesn't appear to be an option at all, can I make it so?</p>
| [
{
"answer_id": 4193,
"author": "Jan Fabry",
"author_id": 8,
"author_profile": "https://wordpress.stackexchange.com/users/8",
"pm_score": 2,
"selected": false,
"text": "<p>When I look at the admin menu structure, it seems <a href=\"http://core.trac.wordpress.org/browser/branches/3.0/wp-ad... | 2010/11/17 | [
"https://wordpress.stackexchange.com/questions/4191",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/784/"
] | I would like to be able to grant my editors the power to change the menu, can this be done?
The appearance tab doesn't appear to be an option at all, can I make it so? | add this to your theme's `functions.php`:
```
// add editor the privilege to edit theme
// get the the role object
$role_object = get_role( 'editor' );
// add $cap capability to this role object
$role_object->add_cap( 'edit_theme_options' );
```
---
Update (suggested in comments):
>
> You probably shouldn't do ... |
4,192 | <p>I'm sorry for this scholar question, but I'm totaly confused with search in Wordpress. What is the difference beetwen <code>searchpage.php</code>, <code>searchform.php</code> and <code>search.php</code>? Could anybody tell me how it all works? Thanks. </p>
| [
{
"answer_id": 4194,
"author": "hakre",
"author_id": 178,
"author_profile": "https://wordpress.stackexchange.com/users/178",
"pm_score": 4,
"selected": true,
"text": "<p>Your question is most likely referring to a specific theme, but I'll answer it for the current default Twenty Ten (Wor... | 2010/11/17 | [
"https://wordpress.stackexchange.com/questions/4192",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1301/"
] | I'm sorry for this scholar question, but I'm totaly confused with search in Wordpress. What is the difference beetwen `searchpage.php`, `searchform.php` and `search.php`? Could anybody tell me how it all works? Thanks. | Your question is most likely referring to a specific theme, but I'll answer it for the current default Twenty Ten (Wordpress Theme) as it's well documented. You find it in the `wp-content/themes/twentyten` directory.
The main search template in there is `search.php`. It is the template file to display the search page.... |
4,197 | <p>OK I need to query posts using the following criteria:</p>
<p>category_name=office,
meta_key=featured_post,
meta_value=Yes</p>
<p>and order these results using a second custom field which has a numerical value</p>
<p>meta_key=prop_order</p>
<p>I have the following query which pulls the correct posts, but doesn't... | [
{
"answer_id": 4194,
"author": "hakre",
"author_id": 178,
"author_profile": "https://wordpress.stackexchange.com/users/178",
"pm_score": 4,
"selected": true,
"text": "<p>Your question is most likely referring to a specific theme, but I'll answer it for the current default Twenty Ten (Wor... | 2010/11/17 | [
"https://wordpress.stackexchange.com/questions/4197",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/912/"
] | OK I need to query posts using the following criteria:
category\_name=office,
meta\_key=featured\_post,
meta\_value=Yes
and order these results using a second custom field which has a numerical value
meta\_key=prop\_order
I have the following query which pulls the correct posts, but doesn't order them by the second... | Your question is most likely referring to a specific theme, but I'll answer it for the current default Twenty Ten (Wordpress Theme) as it's well documented. You find it in the `wp-content/themes/twentyten` directory.
The main search template in there is `search.php`. It is the template file to display the search page.... |
4,201 | <p>I am trying to show a list of posts that are related to category X and tag Y.
I've tried the following code:</p>
<pre><code>$args = array(
'posts_per_page' => 4,
'tag_id' => $tag_id,
'cat' => $cat_id,
);
query_posts($args);
</code></pre>
<p>but it doesn't work correctly and returns all the pos... | [
{
"answer_id": 4858,
"author": "Chris_O",
"author_id": 251,
"author_profile": "https://wordpress.stackexchange.com/users/251",
"pm_score": 5,
"selected": true,
"text": "<h3>Edit: See below for proper way to query category and tag intersections.</h3>\n<pre><code>global $wp_query;\n ... | 2010/11/17 | [
"https://wordpress.stackexchange.com/questions/4201",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/395/"
] | I am trying to show a list of posts that are related to category X and tag Y.
I've tried the following code:
```
$args = array(
'posts_per_page' => 4,
'tag_id' => $tag_id,
'cat' => $cat_id,
);
query_posts($args);
```
but it doesn't work correctly and returns all the posts in the co\ategory.
Would love t... | ### Edit: See below for proper way to query category and tag intersections.
```
global $wp_query;
$args = array(
'category__and' => 'category', //must use category id for this field
'tag__in' => 'post_tag', //must use tag id for this field
'posts_per_page' => -1); //get all posts
$post... |
4,216 | <p>Ok, I'm using the TagCloudShortCode plugin. I have a problem with how my tag pages display.... I want them to display the way they show on my main page, with the image and more button... how do I change the way it displays?</p>
<p>I want it to display like this <code>http://www.top-iphone-apps.info/</code></p>
<p>... | [
{
"answer_id": 4218,
"author": "edelwater",
"author_id": 576,
"author_profile": "https://wordpress.stackexchange.com/users/576",
"pm_score": 0,
"selected": false,
"text": "<p>open the file \"tag.php\" in an an editor, replace</p>\n\n<pre><code>get_template_part( 'loop', 'tag' );\n</code>... | 2010/11/18 | [
"https://wordpress.stackexchange.com/questions/4216",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1618/"
] | Ok, I'm using the TagCloudShortCode plugin. I have a problem with how my tag pages display.... I want them to display the way they show on my main page, with the image and more button... how do I change the way it displays?
I want it to display like this `http://www.top-iphone-apps.info/`
but it displays like this `h... | First, the root of your issue is that WordPress has two very different template tags to output posts: [`the_content()`](http://codex.wordpress.org/Function_Reference/the_content) and [`the_excerpt()`](http://codex.wordpress.org/Function_Reference/the_excerpt). There are a lot of nuances with these and many get details ... |
4,225 | <p>I need to show some info only to admins visiting a page, so I need a conditional tag to identify them. So far I have found:</p>
<pre><code><?php if ( current_user_can('manage_options') ): ?>
</code></pre>
<p>is this the correct function?</p>
| [
{
"answer_id": 4224,
"author": "Adhip Gupta",
"author_id": 81,
"author_profile": "https://wordpress.stackexchange.com/users/81",
"pm_score": 1,
"selected": false,
"text": "<p>It's up to you whether you want to use jQuery in your site (on the public site) or not. It's a part of the theme.... | 2010/11/18 | [
"https://wordpress.stackexchange.com/questions/4225",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/745/"
] | I need to show some info only to admins visiting a page, so I need a conditional tag to identify them. So far I have found:
```
<?php if ( current_user_can('manage_options') ): ?>
```
is this the correct function? | jQuery is loaded by the theme that you use and not by WordPress. The theme must be modified to not load jQuery.
Useless? not sure. It is very useful. Many themes' UI elements and even design elements may depend on jQuery. |
4,257 | <p>The code below adds a custom input field to the attachments editor. How can I convert the text input to a checkbox and get/set the value of the checkbox on load and save?</p>
<p>Note: <code>"input" => "checkbox"</code> does <em>not</em> work :(</p>
<pre><code>function image_attachment_fields_to_edit($form_field... | [
{
"answer_id": 4258,
"author": "prettyboymp",
"author_id": 203,
"author_profile": "https://wordpress.stackexchange.com/users/203",
"pm_score": 4,
"selected": true,
"text": "<p>Set the 'input' to 'html' and write out the html for the input:</p>\n\n<pre><code>function filter_attachment_fie... | 2010/11/18 | [
"https://wordpress.stackexchange.com/questions/4257",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/366/"
] | The code below adds a custom input field to the attachments editor. How can I convert the text input to a checkbox and get/set the value of the checkbox on load and save?
Note: `"input" => "checkbox"` does *not* work :(
```
function image_attachment_fields_to_edit($form_fields, $post) {
$form_fields["imageL... | Set the 'input' to 'html' and write out the html for the input:
```
function filter_attachment_fields_to_edit( $form_fields, $post ) {
$foo = (bool) get_post_meta($post->ID, 'foo', true);
$form_fields['foo'] = array(
'label' => 'Is Foo',
'input' => 'html',
'html' => '<label for="attachments-'.$pos... |
4,264 | <p>Is there a built-in filter to add a custom icon and function to the WordPress "Uploads/Insert" toolbar? This is the toolbar that's located just above the content editor. The existing icon I want to replicate is shown in the blue circle of the image below.</p>
<p>I'd like to add a custom icon that loads the "Add an ... | [
{
"answer_id": 4265,
"author": "Travis Northcutt",
"author_id": 49,
"author_profile": "https://wordpress.stackexchange.com/users/49",
"pm_score": 2,
"selected": true,
"text": "<p>I'm inclined to say that this is possible. For instance, the Gravity Forms plugin adds an image here. Start w... | 2010/11/18 | [
"https://wordpress.stackexchange.com/questions/4264",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/366/"
] | Is there a built-in filter to add a custom icon and function to the WordPress "Uploads/Insert" toolbar? This is the toolbar that's located just above the content editor. The existing icon I want to replicate is shown in the blue circle of the image below.
I'd like to add a custom icon that loads the "Add an Image" wiz... | I'm inclined to say that this is possible. For instance, the Gravity Forms plugin adds an image here. Start with looking at the [media\_buttons\_context](http://adambrown.info/p/wp_hooks/hook/media_buttons_context?version=3.0&file=wp-admin/includes/media.php) hook. |
4,270 | <p>I am trying to change the "Set featured image", "Remove featured image", and "Use as featured image" text links of a custom post type for my plugin <a href="http://wordpress.org/extend/plugins/meteor-slides/" rel="nofollow noreferrer">Meteor Slides</a>.</p>
<p>I found the "admin_post_thumbnail_html" filter hook, an... | [
{
"answer_id": 4561,
"author": "Jan Fabry",
"author_id": 8,
"author_profile": "https://wordpress.stackexchange.com/users/8",
"pm_score": 3,
"selected": false,
"text": "<p>Regardless if you go the PHP or jQuery route, I suggest you set up your filters or enqueue your Javascript in the <co... | 2010/11/18 | [
"https://wordpress.stackexchange.com/questions/4270",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1059/"
] | I am trying to change the "Set featured image", "Remove featured image", and "Use as featured image" text links of a custom post type for my plugin [Meteor Slides](http://wordpress.org/extend/plugins/meteor-slides/).
I found the "admin\_post\_thumbnail\_html" filter hook, and came up with some code that will change "S... | Regardless if you go the PHP or jQuery route, I suggest you set up your filters or enqueue your Javascript in the `admin_head-post[-new].php` or `admin_print_scripts-post[-new].php` hook. There you can be sure that the global variable `$post_type` is set, and can check whether it is `slide`. Since the post thumbnail co... |
4,276 | <p>I'm working on a voting plugin for my site and I want to create 2 tables: one that stores votes and another that stores voter ips.</p>
<p>In Codex it suggests to use an if statement to see if the table has already been created when installing the plugin but how can I alter the code if I'm creating 2 tables?</p>
<p... | [
{
"answer_id": 4277,
"author": "EAMann",
"author_id": 46,
"author_profile": "https://wordpress.stackexchange.com/users/46",
"pm_score": 1,
"selected": false,
"text": "<p>If you're using unique table names, you can assume with a fair amount of confidence that table 2 exists if table 1 exi... | 2010/11/19 | [
"https://wordpress.stackexchange.com/questions/4276",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1613/"
] | I'm working on a voting plugin for my site and I want to create 2 tables: one that stores votes and another that stores voter ips.
In Codex it suggests to use an if statement to see if the table has already been created when installing the plugin but how can I alter the code if I'm creating 2 tables?
This is my if st... | Basic programming techniques you should have learned before building a plugin:
1. You can concatenate checks with && (and) and || (or).
2. You can (and should) guard each `CREATE` query with its own check
SQL syntax you should have looked into before writing queries on your own:
* [IF NOT EXISTS](http://dev.mysql.co... |
4,281 | <p>I'm using Wordpress 3.0.1 (most recent as of now) and working around the Whiteboard theme.</p>
<p>It seems that for attachments (images, specifically), Wordpress generates the HTML automatically and it looks something like this:</p>
<pre><code><div id="attachment_12" class="wp-caption alignleft" style="width: 3... | [
{
"answer_id": 4287,
"author": "t31os",
"author_id": 31073,
"author_profile": "https://wordpress.stackexchange.com/users/31073",
"pm_score": 3,
"selected": false,
"text": "<blockquote>\n <p>I want to change the default HTML code structure so that I can insert additional tags</p>\n</bloc... | 2010/11/19 | [
"https://wordpress.stackexchange.com/questions/4281",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1631/"
] | I'm using Wordpress 3.0.1 (most recent as of now) and working around the Whiteboard theme.
It seems that for attachments (images, specifically), Wordpress generates the HTML automatically and it looks something like this:
```
<div id="attachment_12" class="wp-caption alignleft" style="width: 310px">
<a rel="shadowbox... | >
> I want to change the default HTML code structure so that I can insert additional tags
>
>
>
Run a filter on `img_caption_shortcode`, you can find that hook in the source here.
<http://core.trac.wordpress.org/browser/tags/3.0.1/wp-includes/media.php#L720>
Example
=======
```
add_filter( 'img_caption_shortcode... |
4,283 | <p>I cannot figure out how to use the wp_list_categories function to do what I need it to:</p>
<pre><code><?php if(is_page('realisations')) { ?>
<ul id="subpage">
<li><strong>Les secteurs</strong></li>
<?php wp_list_categories('child_of=3&title_li='); ?>
</ul>... | [
{
"answer_id": 4316,
"author": "hakre",
"author_id": 178,
"author_profile": "https://wordpress.stackexchange.com/users/178",
"pm_score": 0,
"selected": false,
"text": "<p>Okay, here is how to do that and - for further reference - some infos how you can get the most of these wordpress fun... | 2010/11/19 | [
"https://wordpress.stackexchange.com/questions/4283",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | I cannot figure out how to use the wp\_list\_categories function to do what I need it to:
```
<?php if(is_page('realisations')) { ?>
<ul id="subpage">
<li><strong>Les secteurs</strong></li>
<?php wp_list_categories('child_of=3&title_li='); ?>
</ul>
<?php }; if(is_category() or is_single()) { ?>
<ul id="subpage... | I had a similar question, and the solution was to add a function in functions.php.
[How to get current\_cat in navbar, in single post](https://wordpress.stackexchange.com/questions/2009/how-to-get-current-cat-in-navbar-in-single-post/2010#2010) |
4,291 | <p>I have created a page that uses custom posts: <a href="http://www.africanhealthleadership.org/resources/toolkit/" rel="nofollow">http://www.africanhealthleadership.org/resources/toolkit/</a></p>
<p>Each tool (Preparation, Assessment, etc.) is a custom post. On the WP Admin, each tool is a category; each category h... | [
{
"answer_id": 4297,
"author": "MathSmath",
"author_id": 1537,
"author_profile": "https://wordpress.stackexchange.com/users/1537",
"pm_score": 2,
"selected": false,
"text": "<p>Make you're passing the <em>numeric category id</em> into the category_description function.</p>\n\n<p>The valu... | 2010/11/19 | [
"https://wordpress.stackexchange.com/questions/4291",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1097/"
] | I have created a page that uses custom posts: <http://www.africanhealthleadership.org/resources/toolkit/>
Each tool (Preparation, Assessment, etc.) is a custom post. On the WP Admin, each tool is a category; each category has a "description" field. I would like to output those descriptions on the Toolkit page. I tried... | To get the taxonomy term for this particular post, then what you need is `wp_get_post_terms($post->ID, 'yourtaxonomyname')`
This will return an array of terms in the specified taxonomy for the post specified. The codex page is: <http://codex.wordpress.org/Function_Reference/wp_get_post_terms>
If you're after a specif... |
4,302 | <p>I need to apply an add_filter from my functions.php but only if the user has opened media-upload.php from my custom function. Is it possible to send a variable when opening media-upload.php that I could then test for existence of before executing add_filter?</p>
<p>Example: Here is my code in which I'm opening the ... | [
{
"answer_id": 4315,
"author": "hakre",
"author_id": 178,
"author_profile": "https://wordpress.stackexchange.com/users/178",
"pm_score": 3,
"selected": true,
"text": "<p>For the part of opening a lightbox, browse for something and then performing something on an action within: Wordpress ... | 2010/11/19 | [
"https://wordpress.stackexchange.com/questions/4302",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/366/"
] | I need to apply an add\_filter from my functions.php but only if the user has opened media-upload.php from my custom function. Is it possible to send a variable when opening media-upload.php that I could then test for existence of before executing add\_filter?
Example: Here is my code in which I'm opening the media up... | For the part of opening a lightbox, browse for something and then performing something on an action within: Wordpress has this already build in. For what you ask is basically the thickbox that opens up like in the post editor when you browse for an image in the gallery.
You find all the code you need for that already ... |
4,304 | <p>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.</p>
<p>However, my code below is returning the main site id rather than the blog_id ... | [
{
"answer_id": 4306,
"author": "EAMann",
"author_id": 46,
"author_profile": "https://wordpress.stackexchange.com/users/46",
"pm_score": 3,
"selected": true,
"text": "<p>Compare <code>$current_site->id</code> with <code>$current_site->blog_id</code>. According to the in-line docume... | 2010/11/19 | [
"https://wordpress.stackexchange.com/questions/4304",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/366/"
] | 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 s... | 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 `... |
4,307 | <p>I've added a new page under "Pages" in the wordpress admin, and added several custom fields. I'd also like to be able to add an upload image field to the page editor - is there some way to do this via custom-fields? </p>
<p>Or is there a different direction I need to take if I need this ability?</p>
| [
{
"answer_id": 4413,
"author": "MathSmath",
"author_id": 1537,
"author_profile": "https://wordpress.stackexchange.com/users/1537",
"pm_score": 8,
"selected": true,
"text": "<p>For anyone who wants to know more about file uploading, here's a quick primer covering the major topics and pain... | 2010/11/19 | [
"https://wordpress.stackexchange.com/questions/4307",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1640/"
] | I've added a new page under "Pages" in the wordpress admin, and added several custom fields. I'd also like to be able to add an upload image field to the page editor - is there some way to do this via custom-fields?
Or is there a different direction I need to take if I need this ability? | For anyone who wants to know more about file uploading, here's a quick primer covering the major topics and pain points. This is written with WordPress 3.0 on a Linux box in mind, and the code is just a basic overview to teach the concepts. I'm sure some folks here could offer advice for improvement on the implementati... |
4,330 | <p>Is there a WP plugin that allows user to edit in-page footnotes in WYSIWYG manner?</p>
<p>No weird syntax.</p>
<p>No HTML pane.</p>
<p><strong>Update:</strong></p>
<p>Perhaps I'm missing something, as I'm new to WP.</p>
<p>All footnote plugins that I saw use custom syntax. Example:</p>
<pre><code>Blah blah bla... | [
{
"answer_id": 4328,
"author": "t31os",
"author_id": 31073,
"author_profile": "https://wordpress.stackexchange.com/users/31073",
"pm_score": 3,
"selected": true,
"text": "<p>The most ideal solution for walking over the data is to use the WordPress walker class.</p>\n\n<p><a href=\"http:/... | 2010/11/20 | [
"https://wordpress.stackexchange.com/questions/4330",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1642/"
] | 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]m... | The most ideal solution for walking over the data is to use the WordPress walker class.
<http://codex.wordpress.org/Function_Reference/Walker_Class>
You won't find many an example around the web for using it, but one was given by Scribu here.
<http://scribu.net/wordpress/extending-the-category-walker.html>
You can ... |
4,336 | <p>Is there any filter which can be used in a plugin to process the content of the text widget before it is rendered?</p>
| [
{
"answer_id": 4337,
"author": "edelwater",
"author_id": 576,
"author_profile": "https://wordpress.stackexchange.com/users/576",
"pm_score": 4,
"selected": true,
"text": "<h1>Filter</h1>\n<ol>\n<li>widget_text (for the text)</li>\n<li>widget_title (for the title)</li>\n</ol>\n<h1>Example... | 2010/11/20 | [
"https://wordpress.stackexchange.com/questions/4336",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/353/"
] | 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 ... |
4,343 | <p>We're building a plugin that displays posts, and we also want to display the image gallery when it is used in a post. However, we need to limit the number of photos displayed? Is that possible?</p>
| [
{
"answer_id": 4355,
"author": "hakre",
"author_id": 178,
"author_profile": "https://wordpress.stackexchange.com/users/178",
"pm_score": -1,
"selected": false,
"text": "<p>You can specify the number of images per gallery. This can be configured via the gallery tab in the media thickbox i... | 2010/11/20 | [
"https://wordpress.stackexchange.com/questions/4343",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1341/"
] | We're building a plugin that displays posts, and we also want to display the image gallery when it is used in a post. However, we need to limit the number of photos displayed? Is that possible? | There's two ways you can go about this, but both involve creating a function that does pretty much the same as the existing gallery shortcode function...
You can either..
1. Hook onto `post_gallery` and manipulate the incoming data(you can use the gallery shortcode function as a base for the filter if necessary)
2. U... |
4,346 | <p>As described, how can I show only the images with a certain tag on a Wordpress blog that use <code>NextGEN Gallery</code> as gallery plugin?</p>
<p>NextGEN Gallery version is 1.5.5 but I can upgrade to 1.6.2 (last) if necessary. I would like to display images with a specified tag on a new Wordpress Page.</p>
| [
{
"answer_id": 4355,
"author": "hakre",
"author_id": 178,
"author_profile": "https://wordpress.stackexchange.com/users/178",
"pm_score": -1,
"selected": false,
"text": "<p>You can specify the number of images per gallery. This can be configured via the gallery tab in the media thickbox i... | 2010/11/20 | [
"https://wordpress.stackexchange.com/questions/4346",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/36/"
] | As described, how can I show only the images with a certain tag on a Wordpress blog that use `NextGEN Gallery` as gallery plugin?
NextGEN Gallery version is 1.5.5 but I can upgrade to 1.6.2 (last) if necessary. I would like to display images with a specified tag on a new Wordpress Page. | There's two ways you can go about this, but both involve creating a function that does pretty much the same as the existing gallery shortcode function...
You can either..
1. Hook onto `post_gallery` and manipulate the incoming data(you can use the gallery shortcode function as a base for the filter if necessary)
2. U... |
4,349 | <p>After i add these codes to functions.php:</p>
<pre><code>add_editor_style();
function childtheme_mce_btns2($orig) {
return array('formatselect','styleselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', 'removeformat', '|', 'media', 'charmap', '|', 'outdent', 'indent', '|', 'undo', 'red... | [
{
"answer_id": 4350,
"author": "edelwater",
"author_id": 576,
"author_profile": "https://wordpress.stackexchange.com/users/576",
"pm_score": 0,
"selected": false,
"text": "<p>Is this your quesion:</p>\n\n<ol>\n<li><a href=\"http://www.orphicpixel.com/common-wordpress-annoyance/\" rel=\"n... | 2010/11/20 | [
"https://wordpress.stackexchange.com/questions/4349",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1372/"
] | After i add these codes to functions.php:
```
add_editor_style();
function childtheme_mce_btns2($orig) {
return array('formatselect','styleselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', 'removeformat', '|', 'media', 'charmap', '|', 'outdent', 'indent', '|', 'undo', 'redo', 'wp_help' ... | If you always want `<br/>` instead of `<p>` for newlines you can [change the TinyMCE configuration](http://wiki.moxiecode.com/index.php/TinyMCE%3aFAQ#TinyMCE_produce_P_elements_on_enter.2Freturn_instead_of_BR_elements.3F):
```
forced_root_block: false,
force_br_newlines: true,
force_p_newlines : false,
```
I think y... |
4,368 | <p>Using this solution :
<a href="https://wordpress.stackexchange.com/questions/3318/paginate-result-set-from-wpdb-get-results">Paginate result set from $wpdb->get_results()</a></p>
<p>I did make my code for Authors list page template as follow:</p>
<pre><code><div>
<table id="mytable"><tbody>
... | [
{
"answer_id": 4370,
"author": "edelwater",
"author_id": 576,
"author_profile": "https://wordpress.stackexchange.com/users/576",
"pm_score": 2,
"selected": false,
"text": "<p>Your Query is </p>\n\n<pre><code>\"SELECT ID, display_name from $wpdb->users ORDER BY display_name **LIMIT 10*... | 2010/11/21 | [
"https://wordpress.stackexchange.com/questions/4368",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1651/"
] | Using this solution :
[Paginate result set from $wpdb->get\_results()](https://wordpress.stackexchange.com/questions/3318/paginate-result-set-from-wpdb-get-results)
I did make my code for Authors list page template as follow:
```
<div>
<table id="mytable"><tbody>
<?php
// Get the authors from the database order... | Your Query is
```
"SELECT ID, display_name from $wpdb->users ORDER BY display_name **LIMIT 10**";
```
This Sql statement requests the first 10 authors |
4,381 | <p>I've created some custom metaboxes for my post write screen. Is there any way to make some of them display collapsed by default? </p>
<p>Just in case I'm not using the correct terms or not being clear in my question I will elaborate:</p>
<p>The metaboxes on the post write screen have a toggle switch in the upper ... | [
{
"answer_id": 4383,
"author": "hakre",
"author_id": 178,
"author_profile": "https://wordpress.stackexchange.com/users/178",
"pm_score": 4,
"selected": true,
"text": "<p>To display a metabox collapsed or closed by default, it is good to know that adding <code>closed</code> to it's class ... | 2010/11/21 | [
"https://wordpress.stackexchange.com/questions/4381",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/765/"
] | I've created some custom metaboxes for my post write screen. Is there any way to make some of them display collapsed by default?
Just in case I'm not using the correct terms or not being clear in my question I will elaborate:
The metaboxes on the post write screen have a toggle switch in the upper right hand corner ... | To display a metabox collapsed or closed by default, it is good to know that adding `closed` to it's class attribute will display it closed. All meta-boxes main divs that have `closed` in their classname, are displayed in the closed form.
When the arrow is clicked it will be removed or added (toggled). This is done in... |
4,388 | <h3>Edit</h3>
<p>I removed the original Question as this Q has far above 1.000 views now - which means it's important to a lot of people - to show you something that works a) without a custom Walker & b) is easy. <em>Note:</em> I only removed to original Q, because it was pretty unspectacular.</p>
<h3>The Task</h... | [
{
"answer_id": 4394,
"author": "Horttcore",
"author_id": 1379,
"author_profile": "https://wordpress.stackexchange.com/users/1379",
"pm_score": 1,
"selected": false,
"text": "<p>Maybe I got you wrong, but why don't you add the class in your theme?\nSpecify the class when you call the menu... | 2010/11/21 | [
"https://wordpress.stackexchange.com/questions/4388",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/385/"
] | ### Edit
I removed the original Question as this Q has far above 1.000 views now - which means it's important to a lot of people - to show you something that works a) without a custom Walker & b) is easy. *Note:* I only removed to original Q, because it was pretty unspectacular.
### The Task
Add css classes to all n... | I'm going to start by saying something similar to Horttcore..
Is there a reason you can't simply provide a differing container element for the given menu, it should provide enough specificity to style it uniquely.
Although, you could do something like this to conditionalise menu args based on the menu's location..
... |
4,402 | <p>I have a custom post type (gs_index) with commments enabled, and would like to display a list of recent comments only from that particular post type (outside of the loop)</p>
<p>I would also like to display the standard blog posts' comments without the comments from the custom post type.</p>
<p>Here is the code I ... | [
{
"answer_id": 4404,
"author": "Denis de Bernardy",
"author_id": 1208,
"author_profile": "https://wordpress.stackexchange.com/users/1208",
"pm_score": 2,
"selected": false,
"text": "<p>To be frank, my customers and I have only had miserable experiences with all of the various alternative... | 2010/11/22 | [
"https://wordpress.stackexchange.com/questions/4402",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/895/"
] | I have a custom post type (gs\_index) with commments enabled, and would like to display a list of recent comments only from that particular post type (outside of the loop)
I would also like to display the standard blog posts' comments without the comments from the custom post type.
Here is the code I am currently usi... | To be frank, my customers and I have only had miserable experiences with all of the various alternatives. Had I found a suitable one myself, I wouldn't be developing one in the background. :-P (And no, the one I'm working on by no means ready yet.) |
4,430 | <p>I am using <a href="http://wordpress.org/extend/plugins/breadcrumb-navxt/" rel="nofollow">Breadcrumb NavXT</a> plug-in in my pages but now I am facing a problem</p>
<p>I need to hide the "Home" link in some pages. I can do that either by hiding it in CSS or by not creating it at all. in PHP </p>
<p>If I want... | [
{
"answer_id": 4438,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 1,
"selected": false,
"text": "<p>Try <a href=\"http://wordpress.org/extend/plugins/breadcrumb-trail/\" rel=\"nofollow\">Breadcrumb Trail</a>, I took q... | 2010/11/23 | [
"https://wordpress.stackexchange.com/questions/4430",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1619/"
] | I am using [Breadcrumb NavXT](http://wordpress.org/extend/plugins/breadcrumb-navxt/) plug-in in my pages but now I am facing a problem
I need to hide the "Home" link in some pages. I can do that either by hiding it in CSS or by not creating it at all. in PHP
If I want to use CSS - I dont have any indication for firs... | Update
======
[Mtekk's answer](https://wordpress.stackexchange.com/questions/4430/recommended-breadcrumb-plugins-with-possibility-for-hiding-home-link/4454#4454) does basically what I was suggesting w/o the need to touch the plugin itself, so my answer is of quite theoretical nature. [He describes how to do that easil... |
4,462 | <p>While I've typically used <code>include</code> or <code>require</code> on their own to save long term code maintenance I've started to use <code>get_template_part</code> and <code>locate_template</code> as using built in WordPress stuff is always best.</p>
<p>My question is are you supposed to be able to pass varia... | [
{
"answer_id": 4466,
"author": "MathSmath",
"author_id": 1537,
"author_profile": "https://wordpress.stackexchange.com/users/1537",
"pm_score": 3,
"selected": false,
"text": "<p>I've had trouble with this too (while trying to get a custom query to work with a template part). The short ans... | 2010/11/23 | [
"https://wordpress.stackexchange.com/questions/4462",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/141/"
] | 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_pa... | Like [MathSmath wrote](https://wordpress.stackexchange.com/questions/4462/passing-variables-through-locate-template/4466#4466), [get\_template()](http://codex.wordpress.org/Function_Reference/get_template) does not support the re-use of your variables.
But [locate\_template()](http://codex.wordpress.org/Function_Refer... |
4,464 | <p>My theme options save routine is below. I'm finding that if the $value['id'] being passed from my options array has a period in it, the data does not get passed and the options appear to break at that point. Should I opt for another character or is there a workaround for using the period character in an option name?... | [
{
"answer_id": 4549,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 0,
"selected": false,
"text": "<p>I am not sure what the issue is here, this test code works fine for me:</p>\n\n<pre><code>$options = array( 'test_opt... | 2010/11/23 | [
"https://wordpress.stackexchange.com/questions/4464",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/366/"
] | My theme options save routine is below. I'm finding that if the $value['id'] being passed from my options array has a period in it, the data does not get passed and the options appear to break at that point. Should I opt for another character or is there a workaround for using the period character in an option name?
... | Dots and spaces are [replaced](http://www.php.net/manual/en/reserved.variables.php#72572) by PHP for array indexes via POST and GET. That may cause your problem. |
4,479 | <p>I have set up a WordPress site for a client. The client has the Editor role, however I have installed the <a href="http://wordpress.org/extend/plugins/members/">Members plugin</a> and given the client the capability to add new users to the WP admin. This is working just fine.</p>
<p>The question I have is that I ... | [
{
"answer_id": 4500,
"author": "John P Bloch",
"author_id": 11,
"author_profile": "https://wordpress.stackexchange.com/users/11",
"pm_score": 5,
"selected": false,
"text": "<p>It's actually pretty easy. You need to filter into <code>map_meta_caps</code> and stop editors from creating/edi... | 2010/11/24 | [
"https://wordpress.stackexchange.com/questions/4479",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1678/"
] | I have set up a WordPress site for a client. The client has the Editor role, however I have installed the [Members plugin](http://wordpress.org/extend/plugins/members/) and given the client the capability to add new users to the WP admin. This is working just fine.
The question I have is that I would like for the clie... | It's actually pretty easy. You need to filter into `map_meta_caps` and stop editors from creating/editing admins, and remove the administrator role from the 'editable roles' array. This class, as a plugin or in your theme's functions.php file would do it:
```
class JPB_User_Caps {
// Add our filters
function __co... |
4,481 | <p>I am creating a plugin and have a problem,</p>
<p>this code gives my all months that post were added:</p>
<pre><code> <select name="sdate" id="sdate">
<?php wp_get_archives('format=option'); ?>
</select>
</code></pre>
<p>the problem is that i dont get dates that only pages we... | [
{
"answer_id": 4495,
"author": "MathSmath",
"author_id": 1537,
"author_profile": "https://wordpress.stackexchange.com/users/1537",
"pm_score": 3,
"selected": false,
"text": "<p>The wp_get_archives() function runs a filter on its WHERE clause--it's called <strong>getarchives_where</strong... | 2010/11/24 | [
"https://wordpress.stackexchange.com/questions/4481",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1681/"
] | I am creating a plugin and have a problem,
this code gives my all months that post were added:
```
<select name="sdate" id="sdate">
<?php wp_get_archives('format=option'); ?>
</select>
```
the problem is that i dont get dates that only pages were added.
basicaly, i want dropdown thats gonna l... | The wp\_get\_archives() function runs a filter on its WHERE clause--it's called **getarchives\_where**. You could use this to modify the query to only include pages rather than posts (which is the hard-coded default).
I haven't tested this yet, but try it out:
```
add_filter('getarchives_where','my_archives_filter')... |
4,498 | <p>i set my wordpress permlink to <code>/%category%/%postname%</code> now i'm using Nextgen Gallery so when i have a gallery in a page it will be something like <code>/cat/page?gallery=10</code> i want to make it something like <code>cat/page/gallery id/</code> i tried alot with wp_rewrite ... but no luck ... any help ... | [
{
"answer_id": 4506,
"author": "Norcross",
"author_id": 403,
"author_profile": "https://wordpress.stackexchange.com/users/403",
"pm_score": 0,
"selected": false,
"text": "<p>Have you activated the permalinks in the NextGen settings? Under Gallery -> Options -> General select 'activate pe... | 2010/11/24 | [
"https://wordpress.stackexchange.com/questions/4498",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/889/"
] | i set my wordpress permlink to `/%category%/%postname%` now i'm using Nextgen Gallery so when i have a gallery in a page it will be something like `/cat/page?gallery=10` i want to make it something like `cat/page/gallery id/` i tried alot with wp\_rewrite ... but no luck ... any help ?
this is what i'm testing on .. i... | Have you had a look at the [rewrite API](http://codex.wordpress.org/Rewrite_API)? Maybe this can solve your problem?
If you use the rewrite API, then you probably should turn of NextGen rewrite function. |
4,522 | <p>For a plugin, I need to build my own very early post content and comment content filter. Post content/text changing works, i.e. the modifications end up in the client's browser. But my comment content/text modifications somehow are not persistent, i.e. the client receives the original comment text.</p>
<p>The point ... | [
{
"answer_id": 4537,
"author": "prettyboymp",
"author_id": 203,
"author_profile": "https://wordpress.stackexchange.com/users/203",
"pm_score": 1,
"selected": false,
"text": "<p>Without knowing much more about what you're tyring to accomplish, there are a few possible solutions.</p>\n\n<p... | 2010/11/25 | [
"https://wordpress.stackexchange.com/questions/4522",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1694/"
] | For a plugin, I need to build my own very early post content and comment content filter. Post content/text changing works, i.e. the modifications end up in the client's browser. But my comment content/text modifications somehow are not persistent, i.e. the client receives the original comment text.
The point in time I... | The function that includes the comments template [also (re)loads the comments](http://core.trac.wordpress.org/browser/branches/3.0/wp-includes/comment-template.php#L885). This means that whatever you do before that point, if you don't save it to the database it will not be used.
There is no way to prevent this SQL que... |
4,528 | <p>I have the following code: </p>
<pre><code> <div id="pc" class="smartbar-content">
<ul class="smartbar-items">
<?php
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
query_posts( array(
'cat' => '6'... | [
{
"answer_id": 4546,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 0,
"selected": false,
"text": "<p>Do I understand right that you store some kind of array in custom field?</p>\n\n<p>Arrays are serialized (turned into... | 2010/11/25 | [
"https://wordpress.stackexchange.com/questions/4528",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1463/"
] | I have the following code:
```
<div id="pc" class="smartbar-content">
<ul class="smartbar-items">
<?php
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
query_posts( array(
'cat' => '6',
'post... | The following code allows you to add the parameters `wpse4528_key` and `wpse4528_minimum` to your queries, and will then add an extra criterium to the where clause that counts the number of meta values with your key.
```
add_filter( 'posts_where', 'wpse4528_posts_where', 10, 2 );
function wpse4528_posts_where( $where,... |
4,535 | <p>I have a php file with some variables which I would like to use.</p>
<p>When I include it in the header.php the variables in that file are not recognized at footer.php and some other places.</p>
<p>Where is the best place to include this file so its content will be shared all over the wp files.</p>
| [
{
"answer_id": 4542,
"author": "curtismchale",
"author_id": 141,
"author_profile": "https://wordpress.stackexchange.com/users/141",
"pm_score": 0,
"selected": false,
"text": "<p>You need to make the variables constants and include them in header.php Using index.php will only include them... | 2010/11/26 | [
"https://wordpress.stackexchange.com/questions/4535",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1704/"
] | I have a php file with some variables which I would like to use.
When I include it in the header.php the variables in that file are not recognized at footer.php and some other places.
Where is the best place to include this file so its content will be shared all over the wp files. | Variables have a certain scope. The PHP Manual explains that [in detail](http://php.net/manual/en/language.variables.scope.php). So when you set a variable you should know in which scope those are set. This depends on where you set them and how that file gets included.
As Rarst already suggested, the function.php file... |
4,552 | <p>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?</p>
| [
{
"answer_id": 4556,
"author": "Wyck",
"author_id": 1509,
"author_profile": "https://wordpress.stackexchange.com/users/1509",
"pm_score": 0,
"selected": false,
"text": "<ul>\n<li><p>Use a theme that supports smaller\nwidths.</p>\n\n<p>Edit your CSS directly.</p>\n\n<p>Add a CSS media que... | 2010/11/26 | [
"https://wordpress.stackexchange.com/questions/4552",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1426/"
] | 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_... |
4,557 | <p>How can I make all subcategories use the template of its category parent?</p>
| [
{
"answer_id": 4570,
"author": "sorich87",
"author_id": 473,
"author_profile": "https://wordpress.stackexchange.com/users/473",
"pm_score": 4,
"selected": true,
"text": "<p>Here is a code I used to do it:</p>\n\n<pre><code>// make category use parent category template\nfunction load_cat_... | 2010/11/26 | [
"https://wordpress.stackexchange.com/questions/4557",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1697/"
] | How can I make all subcategories use the template of its category parent? | Here is a code I used to do it:
```
// make category use parent category template
function load_cat_parent_template($template) {
$cat_ID = absint( get_query_var('cat') );
$category = get_category( $cat_ID );
$templates = array();
if ( !is_wp_error($category) )
$templates[] = "category-{$cate... |
4,558 | <p>I am not sure which solution here would work best as a solution but what I am looking for is just a simple way to enter an optional domain through a metabox on the page edit screen and then just select a template from the default page templates wordpress uses.</p>
<p>I am assuming there must be a simple way to acco... | [
{
"answer_id": 4570,
"author": "sorich87",
"author_id": 473,
"author_profile": "https://wordpress.stackexchange.com/users/473",
"pm_score": 4,
"selected": true,
"text": "<p>Here is a code I used to do it:</p>\n\n<pre><code>// make category use parent category template\nfunction load_cat_... | 2010/11/26 | [
"https://wordpress.stackexchange.com/questions/4558",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/479/"
] | I am not sure which solution here would work best as a solution but what I am looking for is just a simple way to enter an optional domain through a metabox on the page edit screen and then just select a template from the default page templates wordpress uses.
I am assuming there must be a simple way to accomplish thi... | Here is a code I used to do it:
```
// make category use parent category template
function load_cat_parent_template($template) {
$cat_ID = absint( get_query_var('cat') );
$category = get_category( $cat_ID );
$templates = array();
if ( !is_wp_error($category) )
$templates[] = "category-{$cate... |
4,559 | <p>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?</p>
| [
{
"answer_id": 4570,
"author": "sorich87",
"author_id": 473,
"author_profile": "https://wordpress.stackexchange.com/users/473",
"pm_score": 4,
"selected": true,
"text": "<p>Here is a code I used to do it:</p>\n\n<pre><code>// make category use parent category template\nfunction load_cat_... | 2010/11/26 | [
"https://wordpress.stackexchange.com/questions/4559",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/479/"
] | 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? | Here is a code I used to do it:
```
// make category use parent category template
function load_cat_parent_template($template) {
$cat_ID = absint( get_query_var('cat') );
$category = get_category( $cat_ID );
$templates = array();
if ( !is_wp_error($category) )
$templates[] = "category-{$cate... |
4,563 | <pre><code>set_post_thumbnail_size( 80, 80, true ); // true for all post types
</code></pre>
<p>Suppose I have two post types in play on my blog: Post, Video and Product. I may want a 80x80 image size for my posts, but 100x100 for my videos and a 50x100 for my Products. To my knowledge, I am forced to create thumbnail... | [
{
"answer_id": 4565,
"author": "Jan Fabry",
"author_id": 8,
"author_profile": "https://wordpress.stackexchange.com/users/8",
"pm_score": 4,
"selected": false,
"text": "<p>There is no way to base the image sizes on the post type, as images are not yet attached to a post when you upload th... | 2010/11/26 | [
"https://wordpress.stackexchange.com/questions/4563",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/92/"
] | ```
set_post_thumbnail_size( 80, 80, true ); // true for all post types
```
Suppose I have two post types in play on my blog: Post, Video and Product. I may want a 80x80 image size for my posts, but 100x100 for my videos and a 50x100 for my Products. To my knowledge, I am forced to create thumbnails for my Post image... | There is no way to base the image sizes on the post type, as images are not yet attached to a post when you upload them and the intermediate image sizes are created (when you just add them via "New Media" they are not even attached to any post at all).
However, I recently [created two plugins](https://wordpress.stacke... |
4,567 | <p>I have a ajax request hooked on "template_redirect" (the ajax requests the post's url), and I want to display only the comment template:</p>
<pre><code>function get_comm(){
if(isset($_GET['get_my_comments'])):
$offset = intval($_GET['get_my_comments']);
echo $offset; // offset will be the same as "cpage"
... | [
{
"answer_id": 4565,
"author": "Jan Fabry",
"author_id": 8,
"author_profile": "https://wordpress.stackexchange.com/users/8",
"pm_score": 4,
"selected": false,
"text": "<p>There is no way to base the image sizes on the post type, as images are not yet attached to a post when you upload th... | 2010/11/27 | [
"https://wordpress.stackexchange.com/questions/4567",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/600/"
] | I have a ajax request hooked on "template\_redirect" (the ajax requests the post's url), and I want to display only the comment template:
```
function get_comm(){
if(isset($_GET['get_my_comments'])):
$offset = intval($_GET['get_my_comments']);
echo $offset; // offset will be the same as "cpage"
global $c... | There is no way to base the image sizes on the post type, as images are not yet attached to a post when you upload them and the intermediate image sizes are created (when you just add them via "New Media" they are not even attached to any post at all).
However, I recently [created two plugins](https://wordpress.stacke... |
4,568 | <p>I have a custom post type that accepts a YouTube embed HTML snippet, title, and a featured image. Currently, I'm going and finding an image for the featured image, but ideally I would be able to automatically download and resize the first frame of the video itself based on the video URL during the saving process of ... | [
{
"answer_id": 4615,
"author": "edelwater",
"author_id": 576,
"author_profile": "https://wordpress.stackexchange.com/users/576",
"pm_score": 2,
"selected": false,
"text": "<p>My video blog post generator (http://v.leau.co/) does this but not in wp context.</p>\n\n<p>You supply a query e.... | 2010/11/27 | [
"https://wordpress.stackexchange.com/questions/4568",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/92/"
] | I have a custom post type that accepts a YouTube embed HTML snippet, title, and a featured image. Currently, I'm going and finding an image for the featured image, but ideally I would be able to automatically download and resize the first frame of the video itself based on the video URL during the saving process of the... | Hi **@Jonathan Sampson:**
While this is not exactly what you asked for it might actually be a viable solution and it comes for free from WordPress.com thanks to [**@yoast**](http://twitter.com/yoast)'s tweet this morning when he referenced this blog post:
* [**An Automated Way to Take Screenshots of any Website – Fre... |
4,572 | <p>I am creating my first ever plugin for a membership site. I have a custom table named <code>subscription</code> with a <code>subscr_user_id</code> column whose values are taken from <code>$current_user->ID</code>. So when a current user subscribes, a new record is inserted into the table where <code>subscr_user_i... | [
{
"answer_id": 4575,
"author": "Chris",
"author_id": 1714,
"author_profile": "https://wordpress.stackexchange.com/users/1714",
"pm_score": 0,
"selected": false,
"text": "<p>\"$wpdb->subscription\" only applies if you use the same table prefix (usually wp_), otherwise just use \"subscript... | 2010/11/27 | [
"https://wordpress.stackexchange.com/questions/4572",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1649/"
] | I am creating my first ever plugin for a membership site. I have a custom table named `subscription` with a `subscr_user_id` column whose values are taken from `$current_user->ID`. So when a current user subscribes, a new record is inserted into the table where `subscr_user_id` gets the value of the current user's ID. ... | You need to tell $wpdb what subscriptions when initializing your plugin:
```
$wpdb->subscriptions = $wpdb->prefix . 'subscriptions';
``` |
4,584 | <p>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.</p>
<p>I have "voted up" and "voted down" links. For instance, when you click on "voted up" a new parameter <code>... | [
{
"answer_id": 4581,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 2,
"selected": false,
"text": "<p>What did you use for your front page, customized <code>index.php</code> or <code>home.php</code>? Is it static or sti... | 2010/11/27 | [
"https://wordpress.stackexchange.com/questions/4584",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1717/"
] | 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 pass... | 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**](http://codex.wordpress.org/Pages)"* and call it *"Home Page" (or whatever.)*
2. Create another Page and call it *"Blog" (or whatever.)*
3. In t... |
4,587 | <p>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:</p>
<pre><code>add_action('bp_adminbar_menus', 'new_adminbar_blogs_menu', 6);
remove_action('bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6);
</code></pre>... | [
{
"answer_id": 4588,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 2,
"selected": true,
"text": "<p>I am not sure about BuddyPress specifics.</p>\n\n<p>In general case remove doesn't work when it is firing before funct... | 2010/11/27 | [
"https://wordpress.stackexchange.com/questions/4587",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1718/"
] | 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... | 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 i... |
4,616 | <p>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".</p>
<p>To attempt to obtain this input stream into a code variable, I'm using wp_remote_get like so:</p>
<pre><code>$response =
wp_remote_retrieve_body(
wp_remote_ge... | [
{
"answer_id": 5501,
"author": "t31os",
"author_id": 31073,
"author_profile": "https://wordpress.stackexchange.com/users/31073",
"pm_score": 2,
"selected": true,
"text": "<p>Have you checked out the following plugin?<br>\n<a href=\"http://wordpress.org/extend/plugins/public-post-preview/... | 2010/11/28 | [
"https://wordpress.stackexchange.com/questions/4616",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/366/"
] | 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(
'http://localhos... | Have you checked out the following plugin?
<http://wordpress.org/extend/plugins/public-post-preview/> |
4,618 | <p>I created a custom URL parameter for sorting posts by their vote scores. I have a "most voted" link that sends a <code>?sort=most_voted</code> URL paramater and using a query posts filter I display posts with most votes.</p>
<p>If for instance I want to display most voted posts in category 5, I'll need a URL like t... | [
{
"answer_id": 4628,
"author": "hakre",
"author_id": 178,
"author_profile": "https://wordpress.stackexchange.com/users/178",
"pm_score": 2,
"selected": false,
"text": "<p>You can make use of the <a href=\"http://codex.wordpress.org/Function_Reference/add_query_arg\" rel=\"nofollow\">add_... | 2010/11/28 | [
"https://wordpress.stackexchange.com/questions/4618",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1717/"
] | I created a custom URL parameter for sorting posts by their vote scores. I have a "most voted" link that sends a `?sort=most_voted` URL paramater and using a query posts filter I display posts with most votes.
If for instance I want to display most voted posts in category 5, I'll need a URL like this `?cat=5&sort=most... | You will need to intercept the links generated by WordPress and append the query var onto the relevant URLs.
You can do this quite easily with a filter on category URLs with something like...
```
function add_my_query_var( $link ) {
$link = add_query_arg( 'sort', 'most_voted', $link );
return $link;
}
add_fil... |
4,636 | <p>I am currently building a plugin and it doesn't know when a user is logged in. </p>
<pre><code>global $current_user;
echo $current_user->ID;
</code></pre>
<p>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 alwa... | [
{
"answer_id": 4639,
"author": "prettyboymp",
"author_id": 203,
"author_profile": "https://wordpress.stackexchange.com/users/203",
"pm_score": 2,
"selected": true,
"text": "<p>The <code>$current_user</code> global isn't setup until right before the <code>'init'</code> action is called. ... | 2010/11/29 | [
"https://wordpress.stackexchange.com/questions/4636",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1649/"
] | 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 o... | 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. |
4,638 | <p>If you are familiar with this code</p>
<pre><code><?php
$pattern = get_shortcode_regex();
preg_match('/'.$pattern.'/s', $posts[0]->post_content, $matches);
if (is_array($matches) && $matches[2] == 'YOURSHORTCODE') {
//shortcode is being used
}
?>
</code></pre>
<p>from <a href="http://c... | [
{
"answer_id": 4686,
"author": "Jeff Stieler",
"author_id": 1579,
"author_profile": "https://wordpress.stackexchange.com/users/1579",
"pm_score": 3,
"selected": false,
"text": "<p>From: <a href=\"http://codex.wordpress.org/Shortcode_API#Limitations\" rel=\"nofollow\">http://codex.wordpre... | 2010/11/29 | [
"https://wordpress.stackexchange.com/questions/4638",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1737/"
] | If you are familiar with this code
```
<?php
$pattern = get_shortcode_regex();
preg_match('/'.$pattern.'/s', $posts[0]->post_content, $matches);
if (is_array($matches) && $matches[2] == 'YOURSHORTCODE') {
//shortcode is being used
}
?>
```
from [this](http://codex.wordpress.org/Function_Reference/get_sho... | From: <http://codex.wordpress.org/Shortcode_API#Limitations>
>
> The shortcode parser correctly deals with nested shortcode macros, provided their handler functions support it by recursively calling do\_shortcode()
>
>
>
It will not let you nest the same shortcode inside another though:
>
> However the parser w... |
4,642 | <p>I'm using the Multisite functionality of WordPress 3.0, and I have a network of sites built where I display one random post from one of the subsites on the main site's front page. I accomplish this, in part, by using the <code>switch_to_blog</code> function from the old WPMU function list.</p>
<p>Up until yesterday... | [
{
"answer_id": 4655,
"author": "andrea_r",
"author_id": 1391,
"author_profile": "https://wordpress.stackexchange.com/users/1391",
"pm_score": 0,
"selected": false,
"text": "<p>I'm tempted to aks what happened yesterday. :) New plugins installed? An upgrade?</p>\n\n<p>Yes, the function is... | 2010/11/29 | [
"https://wordpress.stackexchange.com/questions/4642",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/871/"
] | I'm using the Multisite functionality of WordPress 3.0, and I have a network of sites built where I display one random post from one of the subsites on the main site's front page. I accomplish this, in part, by using the `switch_to_blog` function from the old WPMU function list.
Up until yesterday I could call a funct... | It appears that switch\_to\_blog might be too unpredictable to rely on for major site design. Here's my first attempt at a SQL-based solution.
```
function get_intro_post($blogid, $thumb_size='') {
global $wpdb, $post;
// Get the system defined table prefix
$prefix = $wpdb->prefix;
// Create a full table pr... |
4,646 | <p>I created an author's page using:</p>
<pre><code> <?php
if(isset($_GET['author_name'])) :
$curauth = get_userdatabylogin($author_name);
else :
$curauth = get_userdata(intval($author));
endif;
?>
</code></pre>
<p>and then a standard loop, which displays all posts' titles published by that author. I... | [
{
"answer_id": 4657,
"author": "Sergio Majluf",
"author_id": 1576,
"author_profile": "https://wordpress.stackexchange.com/users/1576",
"pm_score": 1,
"selected": false,
"text": "<p>Solved in a much much much simpler way</p>\n\n<p>I have one loop per each category I need to display, and t... | 2010/11/29 | [
"https://wordpress.stackexchange.com/questions/4646",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1576/"
] | I created an author's page using:
```
<?php
if(isset($_GET['author_name'])) :
$curauth = get_userdatabylogin($author_name);
else :
$curauth = get_userdata(intval($author));
endif;
?>
```
and then a standard loop, which displays all posts' titles published by that author. I'm trying to separate the displa... | If you're using an author template there's absolutely no need to setup(set) the author query parameters, they'll be setup ready in the query object present on the author page..
You could additionally avoid the need to create numerous queries(one per category currently), by iterating over the query you have, extracting... |
4,663 | <p>I've created a custom taxonomy "foo" with rewrite slug "foo" and query_var "foo".</p>
<p>Say for example, I also have terms "bar" and "baz" in the "foo" taxonomy.</p>
<p>At the moment, permalinks like <code>/foo/bar</code> and <code>/foo/baz</code> work fine, using my <code>taxonomy-foo.php</code> template.</p>
<... | [
{
"answer_id": 4678,
"author": "Jan Fabry",
"author_id": 8,
"author_profile": "https://wordpress.stackexchange.com/users/8",
"pm_score": 4,
"selected": true,
"text": "<p>What you want is <strong>an index page for custom taxonomies</strong>. There is <a href=\"http://core.trac.wordpress.o... | 2010/11/29 | [
"https://wordpress.stackexchange.com/questions/4663",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1729/"
] | I've created a custom taxonomy "foo" with rewrite slug "foo" and query\_var "foo".
Say for example, I also have terms "bar" and "baz" in the "foo" taxonomy.
At the moment, permalinks like `/foo/bar` and `/foo/baz` work fine, using my `taxonomy-foo.php` template.
What I'd like to do is be able to hit `/foo` and retri... | What you want is **an index page for custom taxonomies**. There is [a ticket for that](http://core.trac.wordpress.org/ticket/13816), but it's not clear what is the most obvious thing to show on this page: 1) a list of all posts attached to any term of that taxonomy, or 2) a list of all terms of this taxonomy? Remember ... |
4,677 | <p>OK Full Code:</p>
<pre><code><?php
//check to see whether the user is an admin or not.
if (is_admin()) {
function wpsc_display_products_seo(){
global $wpdb;
$productList = $wpdb->get_results("SELECT * FROM " . WPSC_TABLE_PRODUCT_LIST . " ORDER BY name ASC");
echo get_admin_page_parent();
$path = 'admin.... | [
{
"answer_id": 4679,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 3,
"selected": false,
"text": "<p>I am not sure what you are trying to do.</p>\n\n<p>Admin links can be conveniently created with <code>admin_url()</co... | 2010/11/30 | [
"https://wordpress.stackexchange.com/questions/4677",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | OK Full Code:
```
<?php
//check to see whether the user is an admin or not.
if (is_admin()) {
function wpsc_display_products_seo(){
global $wpdb;
$productList = $wpdb->get_results("SELECT * FROM " . WPSC_TABLE_PRODUCT_LIST . " ORDER BY name ASC");
echo get_admin_page_parent();
$path = 'admin.php?page=wpsc_product... | I am not sure what you are trying to do.
Admin links can be conveniently created with `admin_url()` function, like this:
```
$path = 'admin.php?page=wpsc_product_seo_details';
$url = admin_url($path);
$link = "<a href='{$url}'>Edit</a>";
echo $link;
```
What exactly do you have problem with? |
4,689 | <p>Here is my index.php file, for some reason the footer.php isn't being loaded through </p>
<p>really weird, its in the directory of my theme, what could be causing this?</p>
<pre><code> <?php get_header(); ?>
<?php get_sidebar(); ?>
<div id="content">
<?php query_posts('cat=-15'); ?>
... | [
{
"answer_id": 4692,
"author": "anu",
"author_id": 490,
"author_profile": "https://wordpress.stackexchange.com/users/490",
"pm_score": 4,
"selected": true,
"text": "<p>From the Codex (http://codex.wordpress.org/Function_Reference/get_footer)</p>\n\n<blockquote>\n <p>If the theme contain... | 2010/11/30 | [
"https://wordpress.stackexchange.com/questions/4689",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1531/"
] | Here is my index.php file, for some reason the footer.php isn't being loaded through
really weird, its in the directory of my theme, what could be causing this?
```
<?php get_header(); ?>
<?php get_sidebar(); ?>
<div id="content">
<?php query_posts('cat=-15'); ?>
<?php if (have_posts()) : ?>
<?php while ... | From the Codex (http://codex.wordpress.org/Function\_Reference/get\_footer)
>
> If the theme contains no footer.php file then the footer from the default theme wp-includes/theme-compat/footer.php will be included.
>
>
>
Chances are that something is wrong with your footer.php, and there's nothing to render - ie i... |
4,690 | <p><strong>My Question:</strong><br>
Is it possible to add custom dashboard widgets in the right hand column instead of only on the left hands side?</p>
<p>I use <code>wp_add_dashboard_plugin( $widget_id, $widget_name, $callback, $control_callback = null )</code> to add the plugin code, but it doesn't have any options... | [
{
"answer_id": 4697,
"author": "somatic",
"author_id": 838,
"author_profile": "https://wordpress.stackexchange.com/users/838",
"pm_score": 4,
"selected": true,
"text": "<p>You're right - it doesn't. Neither does the <code>wp_add_dashboard_widget</code> function. So just use the generic <... | 2010/11/30 | [
"https://wordpress.stackexchange.com/questions/4690",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/798/"
] | **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.
... | 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 Widge... |
4,696 | <p>I've got a custom loop that I'm using to display some Real Estate listings that will be available within 60 days. I'm calling it with the following function: </p>
<pre><code><?php
$sixtydays = date('Y/m/d', strtotime('+60 days'));
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query = new Post... | [
{
"answer_id": 4699,
"author": "eileencodes",
"author_id": 1352,
"author_profile": "https://wordpress.stackexchange.com/users/1352",
"pm_score": 4,
"selected": false,
"text": "<p>I had a similar issue earlier today...</p>\n\n<p>Do you have a custom post type and a page or post with the s... | 2010/11/30 | [
"https://wordpress.stackexchange.com/questions/4696",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1753/"
] | I've got a custom loop that I'm using to display some Real Estate listings that will be available within 60 days. I'm calling it with the following function:
```
<?php
$sixtydays = date('Y/m/d', strtotime('+60 days'));
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query = new PostsOrderedByMetaQue... | I've run into this problem with PageNavi before. My solution is to hijack the $wp\_query variable temporarily and then reassign it after closing the loop. An exmaple:
```
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args=array(
'post_type'=>'post',
'cat' => 6,
'posts_per_page' => 5,
... |
4,707 | <p>I have a page where I only want to show posts from a specific category. At the same time, I want the posts to be sorted by a custom field value in my posts:</p>
<pre><code>query_posts('category_name=' . str_replace(" ", "", $store_name) . '&meta_key=wpfp_favorites&orderby=meta_value_num');
</code></pre>
<p... | [
{
"answer_id": 4716,
"author": "t31os",
"author_id": 31073,
"author_profile": "https://wordpress.stackexchange.com/users/31073",
"pm_score": 2,
"selected": false,
"text": "<p>Have you tried hard-coding the category parameter for testing, and additionally trying different methods to set t... | 2010/11/30 | [
"https://wordpress.stackexchange.com/questions/4707",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | I have a page where I only want to show posts from a specific category. At the same time, I want the posts to be sorted by a custom field value in my posts:
```
query_posts('category_name=' . str_replace(" ", "", $store_name) . '&meta_key=wpfp_favorites&orderby=meta_value_num');
```
The sorting is not working howeve... | Have you tried hard-coding the category parameter for testing, and additionally trying different methods to set the query parameters..
Eg.
```
query_posts( array( 'category_name' => 'myname', 'meta_ke' => 'wpfp_favorites', 'orderby' => 'meta_value_num' ) );
query_posts( array( 'cat' => N, 'meta_key' => 'wpfp_favorite... |
4,712 | <p>I have a template page in Wordpress that I want the Admin to be able to change the text on that page. I'd love to learn how to make a plugin (I know how to make a plugin so that it shows up in WP, installs when the user sets it to activate, and then create the admin panel) that shows just one text field, and the dat... | [
{
"answer_id": 4721,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 1,
"selected": false,
"text": "<p>Why do you want special admin panel for this? It seems like something that can simply be handled by page with custom ... | 2010/11/30 | [
"https://wordpress.stackexchange.com/questions/4712",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1354/"
] | I have a template page in Wordpress that I want the Admin to be able to change the text on that page. I'd love to learn how to make a plugin (I know how to make a plugin so that it shows up in WP, installs when the user sets it to activate, and then create the admin panel) that shows just one text field, and the data t... | An example code for an options-page for a theme. Copy this code in the functions.php of the theme.
```
if ( !function_exists('localizing_theme_setup') ) {
function localizing_theme_setup() {
localizing_constants();
// Make theme available for translation
// Translations can be filed in t... |
4,724 | <p>I want to show a category only if a (custom) post is in that category AND region = $name for that post.</p>
<p>So, e.g. I have a custom post (type "business") named "Mamma Mia" in child-category: "pizzerias" (and in parent-category "food"), and in region "Rotterdam" (custom taxonomy: "region", custom taxonomy term:... | [
{
"answer_id": 4915,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 0,
"selected": false,
"text": "<p>Forgive me if I've missed something, but would it not be as simple as;</p>\n\n<pre><code>if (is_object_in_te... | 2010/12/01 | [
"https://wordpress.stackexchange.com/questions/4724",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1866/"
] | I want to show a category only if a (custom) post is in that category AND region = $name for that post.
So, e.g. I have a custom post (type "business") named "Mamma Mia" in child-category: "pizzerias" (and in parent-category "food"), and in region "Rotterdam" (custom taxonomy: "region", custom taxonomy term: "rotterda... | >
> the intention is to show a list of
> categories, but only those categories
> that have posts where the custom
> taxonomy region is set to Rotterdam
>
>
>
This is done in the [Query Multiple Taxonomies](http://wordpress.org/extend/plugins/query-multiple-taxonomies/) plugin:
<http://plugins.trac.wordpress.or... |
4,725 | <p>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: </p>
<pre><code>add_role( $role_name , $role_display_name , array( 'read' => true,
... | [
{
"answer_id": 4727,
"author": "t31os",
"author_id": 31073,
"author_profile": "https://wordpress.stackexchange.com/users/31073",
"pm_score": 7,
"selected": true,
"text": "<p>See the <a href=\"https://developer.wordpress.org/reference/classes/wp_user/\" rel=\"nofollow noreferrer\">WP_User... | 2010/12/01 | [
"https://wordpress.stackexchange.com/questions/4725",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1649/"
] | 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,
... | See the [WP\_User class](https://developer.wordpress.org/reference/classes/wp_user/), 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 r... |
4,732 | <p>I'm trying to integrate ajax in wordpress using the wp codex guidelines.
In the PHP I added:</p>
<pre><code>wp_enqueue_script ( 'my_ajax', ADMIN_URL . 'js/ajax.js','jquery','1.0.0' );
wp_localize_script( 'my_ajax', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
</code></pre>
<p>The ajax code i... | [
{
"answer_id": 4733,
"author": "Horttcore",
"author_id": 1379,
"author_profile": "https://wordpress.stackexchange.com/users/1379",
"pm_score": 3,
"selected": false,
"text": "<p>In my projects I do it like that</p>\n\n<p>PHP</p>\n\n<pre><code>function foo() {\n echo 'bar';\n}\nadd_acti... | 2010/12/01 | [
"https://wordpress.stackexchange.com/questions/4732",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1567/"
] | I'm trying to integrate ajax in wordpress using the wp codex guidelines.
In the PHP I added:
```
wp_enqueue_script ( 'my_ajax', ADMIN_URL . 'js/ajax.js','jquery','1.0.0' );
wp_localize_script( 'my_ajax', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
```
The ajax code is:
```
jQuery.ajax({url: MyA... | In my projects I do it like that
PHP
```
function foo() {
echo 'bar';
}
add_action('wp_ajax_foo', 'foo' ); // executed when logged in
add_action('wp_ajax_nopriv_foo', 'foo' ); // executed when logged out
```
Javascript
```
data = { action: 'foo', avalue: 'some value', 'anothervalue': 'another value' };
jQuery.... |
4,736 | <p>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.</p>
<p>Basically I manage a couple hundred WordPress blogs, and I'm building a newsletter generator for my cl... | [
{
"answer_id": 4739,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 4,
"selected": true,
"text": "<p>Codex has example snippet on how to use <code>post_limits</code> filter to override amount set in admin for feed.</p>\... | 2010/12/01 | [
"https://wordpress.stackexchange.com/questions/4736",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1113/"
] | 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. The... | 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');
```
<http://codex.wordpress.org/Function_Reference/query_posts#Usage_Ti... |
4,744 | <p>I am trying to output a list of categories per an article. I am using the following code,</p>
<p><code><?php wp_list_categories('child_of=270&style=none'); ?></code></p>
<p>(string) Style to display the categories list in. A value of list displays the categories as list items while none generates no spec... | [
{
"answer_id": 4747,
"author": "PNMG",
"author_id": 1756,
"author_profile": "https://wordpress.stackexchange.com/users/1756",
"pm_score": 3,
"selected": true,
"text": "<p>I came to a solution for this by reviewing the <a href=\"http://codex.wordpress.org/Template_Tags/wp_list_categories\... | 2010/12/01 | [
"https://wordpress.stackexchange.com/questions/4744",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1354/"
] | 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... | I came to a solution for this by reviewing the [Wordpress Codex](http://codex.wordpress.org/Template_Tags/wp_list_categories). 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')... |
4,745 | <p>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 <code>the_post_thumbnail()</code> and <code>get_the_post_thumbnail()</code>.</p>
<p>What methods are available to me to ... | [
{
"answer_id": 4746,
"author": "Sampson",
"author_id": 92,
"author_profile": "https://wordpress.stackexchange.com/users/92",
"pm_score": 0,
"selected": false,
"text": "<p>One method would be to convert whatever is returned from <code>get_the_post_thumbnail()</code> to an object, and pull... | 2010/12/01 | [
"https://wordpress.stackexchange.com/questions/4745",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/92/"
] | 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 thumb... | Thumbnail is essentially attachment so you can approach from that side - lookup ID with [`get_post_thumbnail_id()`](http://codex.wordpress.org/Function_Reference/get_post_thumbnail_id) and fetch data with [`wp_get_attachment_image_src()`](http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src), like ... |
4,770 | <p>I'm using this piece of code to show related posts based on the tag of the post you are viewing. </p>
<p>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 </p>
<p>Reason for this is i already have a loop to show related posts in t... | [
{
"answer_id": 4771,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 3,
"selected": true,
"text": "<p>Very similar to what you do with tags. Retrieve IDs of categories for current post:</p>\n\n<pre><code>$categories = ge... | 2010/12/02 | [
"https://wordpress.stackexchange.com/questions/4770",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1778/"
] | 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,... | 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,
``` |
4,779 | <p>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 <code>sort</code> URL parameter is on. </p>
<p><code>add_filter( 'posts_where', 'votes', 10, 2 );</code></p>
<p>I used to get <code>Undefined index: sort</code> so I mod... | [
{
"answer_id": 4780,
"author": "hakre",
"author_id": 178,
"author_profile": "https://wordpress.stackexchange.com/users/178",
"pm_score": 2,
"selected": false,
"text": "<p>If you check for <code>$query->query_vars</code> first but then use <code>$_GET['sort']</code> later on, you have ... | 2010/12/02 | [
"https://wordpress.stackexchange.com/questions/4779",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1717/"
] | 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 ... | 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";
... |
4,782 | <p>Is there a way to overwrite a core function is the Wordpress core using a plugin? I don't need to inject code, I need to replace the function entirely with a re-written version.</p>
<p>The specific function is wp_nav_menu_item_post_type_meta_box() in /wp-admin/includes/nav-menu.php</p>
<p>Basically there's a lack ... | [
{
"answer_id": 4785,
"author": "EAMann",
"author_id": 46,
"author_profile": "https://wordpress.stackexchange.com/users/46",
"pm_score": 4,
"selected": true,
"text": "<p>Not really, no. You can override built-in PHP functions, but not user-defined functions.</p>\n\n<p>However, all this f... | 2010/12/02 | [
"https://wordpress.stackexchange.com/questions/4782",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1769/"
] | Is there a way to overwrite a core function is the Wordpress core using a plugin? I don't need to inject code, I need to replace the function entirely with a re-written version.
The specific function is wp\_nav\_menu\_item\_post\_type\_meta\_box() in /wp-admin/includes/nav-menu.php
Basically there's a lack of functio... | Not really, no. You can override built-in PHP functions, but not user-defined functions.
However, all this function does is define a meta box. Why not define your own?
Once you've got your own meta box defined and added, you can call `remove_meta_box` to remove the standard one:
```
remove_meta_box( 'add-POSTTYPENAM... |
4,794 | <p>Firstly, apologies for the terminology used here, I will try to be as descriptive as possible.</p>
<p>I am trying to create a menu system that will achieve the following:</p>
<ol>
<li>List top level pages as one menu (level 1)</li>
<li>When on a top level page, list the child pages in a separate menu (level 2)</li... | [
{
"answer_id": 4850,
"author": "goldenapples",
"author_id": 290,
"author_profile": "https://wordpress.stackexchange.com/users/290",
"pm_score": 0,
"selected": false,
"text": "<p>You're using <code>wp_list_pages</code> to check if your page has children. Try using <code>get_children</code... | 2010/12/02 | [
"https://wordpress.stackexchange.com/questions/4794",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | Firstly, apologies for the terminology used here, I will try to be as descriptive as possible.
I am trying to create a menu system that will achieve the following:
1. List top level pages as one menu (level 1)
2. When on a top level page, list the child pages in a separate menu (level 2)
3. When on a child page, list... | To list top level pages only:
```
wp_list_pages( 'depth=1' );
```
To list children of the current page, but **only** if it is a top level page:
```
if ( 0 == $post->post_parent) {
wp_list_pages( 'child_of=' . $post->ID . '&depth=1' );
}
```
To list children of the current page, but **only** if it is a child p... |
4,795 | <p>I'm curious what dependencies <code>add_image_size()</code> 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.</p>
<p><strong>functions.php</strong></p>
<p... | [
{
"answer_id": 4798,
"author": "PNMG",
"author_id": 1756,
"author_profile": "https://wordpress.stackexchange.com/users/1756",
"pm_score": 0,
"selected": false,
"text": "<p>Your question reminded me of a time when I was playing with the Wordpress 3.0 beta and ran into a similar issue. Not... | 2010/12/02 | [
"https://wordpress.stackexchange.com/questions/4795",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/92/"
] | 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,... | This particular issue was caused by an environment missing [GD](http://php.net/manual/en/book.image.php). 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. |
4,809 | <p>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.</p>
<p>Can anybody tell me that function?</p>
| [
{
"answer_id": 4813,
"author": "Denis de Bernardy",
"author_id": 1208,
"author_profile": "https://wordpress.stackexchange.com/users/1208",
"pm_score": 5,
"selected": false,
"text": "<p>See this answer: <a href=\"https://wordpress.stackexchange.com/questions/1567/best-collection-of-code-f... | 2010/12/03 | [
"https://wordpress.stackexchange.com/questions/4809",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/18051/"
] | 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 rig... |
4,842 | <p>I'm using the mysql <a href="http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_greatest" rel="nofollow">GREATEST()</a> 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.</p>
<pre><co... | [
{
"answer_id": 4847,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 3,
"selected": true,
"text": "<p>I think you want to use <code>get_var()</code>, not <code>get_row()</code> - <a href=\"http://dev.mysql.com/d... | 2010/12/03 | [
"https://wordpress.stackexchange.com/questions/4842",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1717/"
] | I'm using the mysql [GREATEST()](http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_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) {
... | I think you want to use `get_var()`, not `get_row()` - [looking at the documentation](http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_greatest), 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 grea... |
4,845 | <p>My shopping cart is being cached by w3 total cache. This is the expected default behaviour. The thing is I can't find an easy solution for this.</p>
<p>I am showing my shopping cart on almost every page, so using rejected cookies or something similar is not an option. Is it possible to tell w3 total cache not to ca... | [
{
"answer_id": 4851,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 0,
"selected": false,
"text": "<p>W3, like all other plugins of this kind, caches page output in static file. Basically you can't have part of static f... | 2010/12/03 | [
"https://wordpress.stackexchange.com/questions/4845",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1380/"
] | My shopping cart is being cached by w3 total cache. This is the expected default behaviour. The thing is I can't find an easy solution for this.
I am showing my shopping cart on almost every page, so using rejected cookies or something similar is not an option. Is it possible to tell w3 total cache not to cache a sing... | ### W3 Total Cache is a very advanced plugin that has built in ways to handle almost any situation.
To exclude a page from being cached use one of the following commands below:
```
define('DONOTCACHEPAGE', true);
Disables page caching for a given page.
define('DONOTCACHEDB', true);
Disables database caching for given... |
4,878 | <blockquote>
<p><em>(<strong>Moderator's note:</strong> The original title was "drop down taxonomy")</em></p>
<p>I want to add a drop-down box filled
with my custom taxonomies, so when
someone selects any value, it
redirects to corresponding page. I
tried out this code, which worked</p>
<p><code>&l... | [
{
"answer_id": 4879,
"author": "MikeSchinkel",
"author_id": 89,
"author_profile": "https://wordpress.stackexchange.com/users/89",
"pm_score": 2,
"selected": true,
"text": "<p>Hi <strong>@ntechi:</strong></p>\n\n<p>Here's a function I wrote which I named <code>the_taxonomy_dropdown()</cod... | 2010/12/04 | [
"https://wordpress.stackexchange.com/questions/4878",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1743/"
] | >
> *(**Moderator's note:** The original title was "drop down taxonomy")*
>
>
> I want to add a drop-down box filled
> with my custom taxonomies, so when
> someone selects any value, it
> redirects to corresponding page. I
> tried out this code, which worked
>
>
> `<?php wp_dropdown_categories( array(
> 'taxo... | Hi **@ntechi:**
Here's a function I wrote which I named `the_taxonomy_dropdown()` to give you what I think you are looking for.
```
function the_taxonomy_dropdown($taxonomy) {
$id = "{$taxonomy}-dropdown";
$js =<<<SCRIPT
<script type="text/javascript">
jQuery(document).ready(function($){
$("select#{$id}").cha... |
4,888 | <p>I'd like to modify the properties of a registered style(or script - same applies) before it's been loaded.</p>
<p>Right now i'm trying to modify a registered style just before it gets enqueued, so i can point it at another file(ie. change the <code>src</code> property, maybe others to). Looking for some ideas speci... | [
{
"answer_id": 4889,
"author": "sorich87",
"author_id": 473,
"author_profile": "https://wordpress.stackexchange.com/users/473",
"pm_score": 2,
"selected": false,
"text": "<p>You can use the filter <code>wp_admin_css_uri</code> in the function of the same name which returns the uri of the... | 2010/12/04 | [
"https://wordpress.stackexchange.com/questions/4888",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/31073/"
] | I'd like to modify the properties of a registered style(or script - same applies) before it's been loaded.
Right now i'm trying to modify a registered style just before it gets enqueued, so i can point it at another file(ie. change the `src` property, maybe others to). Looking for some ideas specifically about where t... | Modify a registered style's path
================================
I wanted to tweak the path to one of the WordPress admin stylesheets so i could keep requests down, and because it makes little sense to include two stylesheets, when the one i'm calling redefines all the styling in the stylesheet enqueued by WordPress.... |
4,896 | <p>I'm working on a site that has been running for few years and had different maintainers so it's kind of a mess. What I found weird is a lot of entries in <code>wp_postmeta</code> where all the keys are numeric and contain a string like this:</p>
<pre><code>wpAjaxe17fbeda4c811052694cd66e93bf1868f720040882f22c2bba843... | [
{
"answer_id": 4898,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 1,
"selected": false,
"text": "<blockquote>\n <p>the last post (as in the one with the greatest ID) referred to one of these meta keys is dat... | 2010/12/05 | [
"https://wordpress.stackexchange.com/questions/4896",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/745/"
] | I'm working on a site that has been running for few years and had different maintainers so it's kind of a mess. What I found weird is a lot of entries in `wp_postmeta` where all the keys are numeric and contain a string like this:
```
wpAjaxe17fbeda4c811052694cd66e93bf1868f720040882f22c2bba8432e030f010c8069596982baf4c... | The best way to know which plugin was adding them is to search/grep your installation for occurrences of `'wpAjax'` and `"wpAjax"`. If you find none (which is likely, since the oldest is 3 years old) safely `delete from wp_postmeta where meta_key like 'wpAjax%'`, or something along those lines, if the latter statement ... |
4,900 | <p>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?</p>
<p>Right now I'm using an action hook to immediately insert the id of new posts I publish.</p>
<pre><code>function transfer_post_id($post_ID) {
global $wpdb;
if (!($wpdb... | [
{
"answer_id": 4902,
"author": "hakre",
"author_id": 178,
"author_profile": "https://wordpress.stackexchange.com/users/178",
"pm_score": 3,
"selected": false,
"text": "<p>You can design your table in such a way that an ID can only exists once by using a key. You can then run a insert int... | 2010/12/05 | [
"https://wordpress.stackexchange.com/questions/4900",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1717/"
] | 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 pos... | 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;
``` |
4,906 | <p>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. </p>
<p>I'm able to create a field called Excerpt in my Meta Box, however I only know how to save... | [
{
"answer_id": 4911,
"author": "sorich87",
"author_id": 473,
"author_profile": "https://wordpress.stackexchange.com/users/473",
"pm_score": 3,
"selected": true,
"text": "<p>Just name the field 'excerpt'.</p>\n\n<p>E.g.:</p>\n\n<pre><code><textarea name=\"excerpt\" id=\"excerpt\">&l... | 2010/12/06 | [
"https://wordpress.stackexchange.com/questions/4906",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/765/"
] | 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 ... | 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 -->
``` |
4,907 | <p>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 - <a href="http://inversekarma.in/scraps/you-dont-mess-with-the-rajinikanth/">http://inversekarma.in/scraps/you-dont-mess-with-the-rajinikanth... | [
{
"answer_id": 4908,
"author": "ariefbayu",
"author_id": 127,
"author_profile": "https://wordpress.stackexchange.com/users/127",
"pm_score": 4,
"selected": true,
"text": "<p>Try this code:</p>\n\n<h2><strong>WARNING: THIS IS JUST PSEUDOCODE!</strong></h2>\n\n<pre><code>$entries = $wpdb-&... | 2010/12/06 | [
"https://wordpress.stackexchange.com/questions/4907",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1606/"
] | 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 - <http://inversekarma.in/scraps/you-dont-mess-with-the-rajinikanth/>.
In the above post, there's only 4 comments, but the comment count shoes 8... | 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... |
4,909 | <p>Title is little bit :S
sorry :)
For example,we have paginate links function that output html something like this</p>
<pre><code><span class='page-numbers current'>some number</span>
</code></pre>
<p>How can I filter that,to remove that span,class,to apply my own html tags,styles,tnx in advance.I just w... | [
{
"answer_id": 4910,
"author": "sorich87",
"author_id": 473,
"author_profile": "https://wordpress.stackexchange.com/users/473",
"pm_score": 1,
"selected": false,
"text": "<p>I think the best way to do it would be to copy that function (wp-includes/general-template.php, line 1943) and cre... | 2010/12/06 | [
"https://wordpress.stackexchange.com/questions/4909",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1147/"
] | Title is little bit :S
sorry :)
For example,we have paginate links function that output html something like this
```
<span class='page-numbers current'>some number</span>
```
How can I filter that,to remove that span,class,to apply my own html tags,styles,tnx in advance.I just want to apply my own styles and html ta... | Use a custom pagination function:
my source:
```
function fb_paging_bar( $args = array() ) {
$defaults = array(
'range' => 4,
'custom_query' => FALSE,
'previous_string' => __( '«««', FB_GREYFOTO_TEXTDOMAIN ),
'next_string' => __( '»»&... |
4,914 | <p>I see there are a lot of plugins to create tabbed widget in side-bar:</p>
<ol>
<li><a href="http://wordpress.org/extend/plugins/fun-with-sidebar-tabs/" rel="nofollow">Fun with tabs</a></li>
<li><a href="http://wordpress.org/extend/plugins/post-2-tabs-jquery-tabs/" rel="nofollow">Post 2 tabs</a></li>
<li><a href="ht... | [
{
"answer_id": 4910,
"author": "sorich87",
"author_id": 473,
"author_profile": "https://wordpress.stackexchange.com/users/473",
"pm_score": 1,
"selected": false,
"text": "<p>I think the best way to do it would be to copy that function (wp-includes/general-template.php, line 1943) and cre... | 2010/12/06 | [
"https://wordpress.stackexchange.com/questions/4914",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1302/"
] | I see there are a lot of plugins to create tabbed widget in side-bar:
1. [Fun with tabs](http://wordpress.org/extend/plugins/fun-with-sidebar-tabs/)
2. [Post 2 tabs](http://wordpress.org/extend/plugins/post-2-tabs-jquery-tabs/)
3. [Hybrid Tabs](http://wordpress.org/extend/plugins/hybrid-tabs/)
4. [Wordpress Tabs Slide... | Use a custom pagination function:
my source:
```
function fb_paging_bar( $args = array() ) {
$defaults = array(
'range' => 4,
'custom_query' => FALSE,
'previous_string' => __( '«««', FB_GREYFOTO_TEXTDOMAIN ),
'next_string' => __( '»»&... |
4,918 | <p>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</p>
<blockquote>
<p>[zdvideo]url-of-youtube-video[/zdvideo]</p>
</blockquote>
<p>Now I need to go back to plain YouTube embedding. How do I... | [
{
"answer_id": 4921,
"author": "Denis de Bernardy",
"author_id": 1208,
"author_profile": "https://wordpress.stackexchange.com/users/1208",
"pm_score": 3,
"selected": false,
"text": "<p>Best I'm aware, MySQL doesn't have much of a regexp replace functionality -- not to mention its very cl... | 2010/12/06 | [
"https://wordpress.stackexchange.com/questions/4918",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1606/"
] | 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 search... | 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]', '');
``` |
4,924 | <p>I'm sure there is a simple reason/answer for this: Why does </p>
<p><code>echo 'Archive for '. the_time('Y');</code></p>
<p>give me <code>2010Archive for</code>? I had expected it would give me
<code>Archive for 2010</code></p>
| [
{
"answer_id": 4925,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 4,
"selected": true,
"text": "<p>As most template tags that start with <code>the_</code> this one echoes time and not returns it (which template tags t... | 2010/12/06 | [
"https://wordpress.stackexchange.com/questions/4924",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1118/"
] | 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 'Archi... |
4,931 | <p>I have two custom meta fields that I've enabled for each post, scottb_customHeader and scottb_customTitle</p>
<p>These work fine as long as I'm using the full edit feature to edit posts. However, when I click "Quick Edit", then click "Update", my custom meta values for the post are cleared out. What do I need to do... | [
{
"answer_id": 4941,
"author": "MathSmath",
"author_id": 1537,
"author_profile": "https://wordpress.stackexchange.com/users/1537",
"pm_score": 3,
"selected": true,
"text": "<p>Add a hidden flag to the post edit form along with your custom fields. Something like </p>\n\n<pre><code><inp... | 2010/12/06 | [
"https://wordpress.stackexchange.com/questions/4931",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/366/"
] | I have two custom meta fields that I've enabled for each post, scottb\_customHeader and scottb\_customTitle
These work fine as long as I'm using the full edit feature to edit posts. However, when I click "Quick Edit", then click "Update", my custom meta values for the post are cleared out. What do I need to do to reso... | Add a hidden flag to the post edit form along with your custom fields. Something like
```
<input type="hidden" name="my_hidden_flag" value="true" />
```
Then, wrap all of your custom save\_post stuff in a check for this flag. Then you don't have to check for the autosave constant any more either--if the flag doesn'... |
4,936 | <p>How can I remove the Featured Image meta box? I've tried using the <code>remove_meta_box</code> function and specifying the boxes ID but it doesn't seem to work like it does for the other native meta boxes. </p>
<p>Here is the specific code I tried:</p>
<pre><code>add_action( 'admin_menu', 'remove_thumbnail_box'... | [
{
"answer_id": 4937,
"author": "PNMG",
"author_id": 1756,
"author_profile": "https://wordpress.stackexchange.com/users/1756",
"pm_score": 5,
"selected": true,
"text": "<p>I haven't had time to test this but this looks like it should work for you.</p>\n\n<pre><code>add_action('do_meta_box... | 2010/12/06 | [
"https://wordpress.stackexchange.com/questions/4936",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/765/"
] | 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... | 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](http://wordpress.org/support/topic/how-to-move-featured-image-b... |
4,945 | <p>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...)</p>
<p>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?</p>
| [
{
"answer_id": 4949,
"author": "MathSmath",
"author_id": 1537,
"author_profile": "https://wordpress.stackexchange.com/users/1537",
"pm_score": 3,
"selected": true,
"text": "<p>Haven't tested this yet, but it should do the trick in 3x:</p>\n\n<pre><code>// Get all the existing links\n$arr... | 2010/12/06 | [
"https://wordpress.stackexchange.com/questions/4945",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/366/"
] | 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 o... |
4,952 | <p>Does anyone know of a way to add code to the functions.php file which will automatically force all posts belonging to a custom post type to be "private" and/or "password protected" with a default password set?</p>
<p>I am specifically referring to creating a new post or editing an existing post thus ensuring a post... | [
{
"answer_id": 4953,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 2,
"selected": false,
"text": "<pre><code>function force_type_private($post)\n{\n if ($post['post_type'] != 'my_post_type' || $post['post_s... | 2010/12/06 | [
"https://wordpress.stackexchange.com/questions/4952",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/479/"
] | Does anyone know of a way to add code to the functions.php file which will automatically force all posts belonging to a custom post type to be "private" and/or "password protected" with a default password set?
I am specifically referring to creating a new post or editing an existing post thus ensuring a post belonging... | You can hook onto `save_post`, `wp_insert_post` or `wp_insert_post_data` to modify the post object prior to it being inserted or saved.
Using `save_post` or `wp_insert_post` the callback would need to declare two args and would receive the post object as the second incoming variable.. (and i'm showing you to cover the... |
4,961 | <p>The codex doesn't seem to say how one would go about adding a description to a custom widget registered with <code>wp_register_sidebar_widget()</code>. The default description seems to be the name of teh widget itself.</p>
<pre><code>function myFunc(){
/* widget code */
}
wp_register_sidebar_widget( 'wdgt1', 'Sit... | [
{
"answer_id": 4962,
"author": "sorich87",
"author_id": 473,
"author_profile": "https://wordpress.stackexchange.com/users/473",
"pm_score": 2,
"selected": false,
"text": "<p>This is the old (and difficult) way to create WordPress widgets. Use the Widget API instead: <a href=\"http://code... | 2010/12/07 | [
"https://wordpress.stackexchange.com/questions/4961",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/92/"
] | 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()... | 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 widg... |