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 |
|---|---|---|---|---|---|---|
56,229 | <p>Are there any plugin or code that sends out a email to me (admin) when a author or writer publish a post?</p>
| [
{
"answer_id": 56230,
"author": "Bainternet",
"author_id": 2487,
"author_profile": "https://wordpress.stackexchange.com/users/2487",
"pm_score": 4,
"selected": true,
"text": "<p>No need for plugin here are a few lines of code you can modify and paste in your themes functions.php file and... | 2012/06/22 | [
"https://wordpress.stackexchange.com/questions/56229",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16936/"
] | Are there any plugin or code that sends out a email to me (admin) when a author or writer publish a post? | No need for plugin here are a few lines of code you can modify and paste in your themes functions.php file and you will get a new email whenever a post is published:
```
add_action('publish_post', 'send_admin_email');
function send_admin_email($post_id){
$to = 'admin@email.here';
$subject = 'mail subject here'... |
56,274 | <h1>Update:</h1>
<p>Found the reason for the issue. The theme had this</p>
<pre><code>add_action('init','ezgz_buffer');
function ezgz_buffer()
{
ob_start('ob_gzhandler');
}
</code></pre>
<p>The above code enables gzip-compression if the visitor's browser can handle it.</p>
<h1>Actual Question:</h1>
<p>This is... | [
{
"answer_id": 56294,
"author": "Pothi Kalimuthu",
"author_id": 9584,
"author_profile": "https://wordpress.stackexchange.com/users/9584",
"pm_score": 2,
"selected": false,
"text": "<pre>\nmod_deflate: Not detected (required for Page Cache (enhanced mode) and Browser Cache)\nmod_env: Not ... | 2012/06/23 | [
"https://wordpress.stackexchange.com/questions/56274",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10701/"
] | Update:
=======
Found the reason for the issue. The theme had this
```
add_action('init','ezgz_buffer');
function ezgz_buffer()
{
ob_start('ob_gzhandler');
}
```
The above code enables gzip-compression if the visitor's browser can handle it.
Actual Question:
================
This is really really strange for... | ```
mod_deflate: Not detected (required for Page Cache (enhanced mode) and Browser Cache)
mod_env: Not detected (required for Page Cache (enhanced mode) and Browser Cache)
mod_expires: Not detected (required for Page Cache (enhanced mode) and Browser Cache)
mod_headers: Not detected (required for Page Cache (enhanced ... |
56,308 | <p>I'd been having trouble with the full domain name being written into the path of links and assets. Basically localhost:XXXX works fine, until I try to reach my site from a Virtual Box install of XP or in my local network, where the domain changes to computername.local:XXXX</p>
<p>I managed to solve this problem wit... | [
{
"answer_id": 56320,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 0,
"selected": false,
"text": "<p><code>home_url</code> calls <code>get_home_url</code> which has the filter <code>home_url</code>:</p>\n\n<pre><code... | 2012/06/23 | [
"https://wordpress.stackexchange.com/questions/56308",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13551/"
] | I'd been having trouble with the full domain name being written into the path of links and assets. Basically localhost:XXXX works fine, until I try to reach my site from a Virtual Box install of XP or in my local network, where the domain changes to computername.local:XXXX
I managed to solve this problem with a tip fr... | You need to set the WP\_HOME and WP\_SITEURL in `wp-config.php` in a smarter way. Like this:
```
<?php
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
// add the next line if you have a subdirectory install
define('WP_SITEURL', WP_HOME . '/path/to/wordpress');
```
This will solve your your issues with site URL... |
56,312 | <p>I'm using this code: <code>
<?php wp_tag_cloud( array( 'taxonomy' => 'channels') );?></code>
To display custom taxonomy as a cloud tag.
How can display with all links being the same size? I can't seem to override the inline styles.</p>
| [
{
"answer_id": 56320,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 0,
"selected": false,
"text": "<p><code>home_url</code> calls <code>get_home_url</code> which has the filter <code>home_url</code>:</p>\n\n<pre><code... | 2012/06/23 | [
"https://wordpress.stackexchange.com/questions/56312",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17428/"
] | I'm using this code: `<?php wp_tag_cloud( array( 'taxonomy' => 'channels') );?>`
To display custom taxonomy as a cloud tag.
How can display with all links being the same size? I can't seem to override the inline styles. | You need to set the WP\_HOME and WP\_SITEURL in `wp-config.php` in a smarter way. Like this:
```
<?php
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
// add the next line if you have a subdirectory install
define('WP_SITEURL', WP_HOME . '/path/to/wordpress');
```
This will solve your your issues with site URL... |
56,316 | <p>I have made my first theme. :) But I have a problem: plugins such as getsocial or dynamicwp-contact-form can not display in my custom theme. I tried using them in the twentyeleven theme, and they don't have that problem there. </p>
<p>I think there is a problem with my theme but I don't know where..</p>
| [
{
"answer_id": 56320,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 0,
"selected": false,
"text": "<p><code>home_url</code> calls <code>get_home_url</code> which has the filter <code>home_url</code>:</p>\n\n<pre><code... | 2012/06/23 | [
"https://wordpress.stackexchange.com/questions/56316",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16683/"
] | I have made my first theme. :) But I have a problem: plugins such as getsocial or dynamicwp-contact-form can not display in my custom theme. I tried using them in the twentyeleven theme, and they don't have that problem there.
I think there is a problem with my theme but I don't know where.. | You need to set the WP\_HOME and WP\_SITEURL in `wp-config.php` in a smarter way. Like this:
```
<?php
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
// add the next line if you have a subdirectory install
define('WP_SITEURL', WP_HOME . '/path/to/wordpress');
```
This will solve your your issues with site URL... |
56,338 | <p>As you can see in the attached image (<a href="https://i.imgur.com/V7642.png" rel="nofollow noreferrer">http://i.imgur.com/V7642.png</a>) my JetPack comments are rendering above the Discuss box. How do I go about moving them down? When I look in Chrome Inspector there doesn't even seem to be any Class or ID for me t... | [
{
"answer_id": 56342,
"author": "Chris_O",
"author_id": 251,
"author_profile": "https://wordpress.stackexchange.com/users/251",
"pm_score": 1,
"selected": false,
"text": "<h3>You should really pick one or the other.</h3>\n<p>They are both designed to replace your existing commenting syst... | 2012/06/23 | [
"https://wordpress.stackexchange.com/questions/56338",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17193/"
] | As you can see in the attached image ([http://i.imgur.com/V7642.png](https://i.imgur.com/V7642.png)) my JetPack comments are rendering above the Discuss box. How do I go about moving them down? When I look in Chrome Inspector there doesn't even seem to be any Class or ID for me to latch onto to bring them down. In my t... | ### You should really pick one or the other.
They are both designed to replace your existing commenting system and both take over the commenting functionality. Discuss does it by inserting javascript and jetpack uses an iframe. |
56,351 | <p>I wanted to update custom blog option created thru Settings Api using the function <code>update_blog_option</code>. I created this code.</p>
<pre><code> $country_base = get_blog_option($blog_id, 'mytheme_options');//retrieve all options
$country_base['country_base'] = $the_country;
$currency_unit = get_b... | [
{
"answer_id": 56355,
"author": "Z. Zlatev",
"author_id": 4192,
"author_profile": "https://wordpress.stackexchange.com/users/4192",
"pm_score": 0,
"selected": false,
"text": "<p>I think it's best just to <code>switch_to_blog($id);</code> and use regular functions as add_option(), get_opt... | 2012/06/24 | [
"https://wordpress.stackexchange.com/questions/56351",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7749/"
] | I wanted to update custom blog option created thru Settings Api using the function `update_blog_option`. I created this code.
```
$country_base = get_blog_option($blog_id, 'mytheme_options');//retrieve all options
$country_base['country_base'] = $the_country;
$currency_unit = get_blog_option($blog_id, 'myt... | As per the [Codex on update\_blog\_option](http://codex.wordpress.org/WPMU_Functions/update_blog_option):
>
> Switches to the blog id specified, runs update\_option() and then
> restores to the current blog. If $refresh is true then it will refresh
> the blog details.
>
>
>
---
Not tested, but I think your pro... |
56,352 | <p>I have a client project that has posts assigned to their country of origin.</p>
<p>The client wants to be able to search the posts by continent and or region. </p>
<p>I have a separate table that assigns each country to its respective region, and I have the WP query that uses the resulting array:</p>
<pre><code>$... | [
{
"answer_id": 56355,
"author": "Z. Zlatev",
"author_id": 4192,
"author_profile": "https://wordpress.stackexchange.com/users/4192",
"pm_score": 0,
"selected": false,
"text": "<p>I think it's best just to <code>switch_to_blog($id);</code> and use regular functions as add_option(), get_opt... | 2012/06/24 | [
"https://wordpress.stackexchange.com/questions/56352",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16909/"
] | I have a client project that has posts assigned to their country of origin.
The client wants to be able to search the posts by continent and or region.
I have a separate table that assigns each country to its respective region, and I have the WP query that uses the resulting array:
```
$country_names = array('Engla... | As per the [Codex on update\_blog\_option](http://codex.wordpress.org/WPMU_Functions/update_blog_option):
>
> Switches to the blog id specified, runs update\_option() and then
> restores to the current blog. If $refresh is true then it will refresh
> the blog details.
>
>
>
---
Not tested, but I think your pro... |
56,363 | <p>I am trying to create a membership site on WP where each members will have access to only specific pages created for them. I mean just a member is allowed to view content on a page while that page is restricted to others. I just to grant on a member access to a page. I don't know if this is possible with the help an... | [
{
"answer_id": 56364,
"author": "Dominic",
"author_id": 9905,
"author_profile": "https://wordpress.stackexchange.com/users/9905",
"pm_score": 0,
"selected": false,
"text": "<p>You could add the IDs of allowed users to a custom field on certain pages. Then use <code>get_current_user_id()<... | 2012/06/24 | [
"https://wordpress.stackexchange.com/questions/56363",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17454/"
] | I am trying to create a membership site on WP where each members will have access to only specific pages created for them. I mean just a member is allowed to view content on a page while that page is restricted to others. I just to grant on a member access to a page. I don't know if this is possible with the help any p... | The same concept as Dominic's (no need of a members plugin) but expanded to use a Meta Box, visible only for Admins, with a dropdown list with all the users (with exceptions).
Code borrowed and adapted [from this answer](https://wordpress.stackexchange.com/a/33834/12615). Put in `functions.php`:
```
// List Users
add... |
56,367 | <p>How i can create a welcome message area for my frontpage with backend control {admin panel}</p>
<h2> Welcome </h2>
<p> message</p>
| [
{
"answer_id": 56371,
"author": "ahmedag",
"author_id": 17457,
"author_profile": "https://wordpress.stackexchange.com/users/17457",
"pm_score": -1,
"selected": true,
"text": "<p>Create a page theme, then call it in <code>index.php</code>:</p>\n\n<pre><code>$recent = new WP_Query( 'page_i... | 2012/06/24 | [
"https://wordpress.stackexchange.com/questions/56367",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16115/"
] | How i can create a welcome message area for my frontpage with backend control {admin panel}
Welcome
--------
message | Create a page theme, then call it in `index.php`:
```
$recent = new WP_Query( 'page_id=**ID**' );
while ( $recent->have_posts() ) : $recent->the_post();
?><h3><?php the_title(); ?></h3><?php
the_content();
endwhile;
``` |
56,370 | <p>I would like to remove fields from the profile in <a href="http://wordpress.org/extend/plugins/theme-my-login/" rel="nofollow">Theme My Login</a>. I want to remove everything except email and password field. I am able to hide fields using a little jQuery. But un fortunately I'm not good with it. Can someone help me ... | [
{
"answer_id": 56371,
"author": "ahmedag",
"author_id": 17457,
"author_profile": "https://wordpress.stackexchange.com/users/17457",
"pm_score": -1,
"selected": true,
"text": "<p>Create a page theme, then call it in <code>index.php</code>:</p>\n\n<pre><code>$recent = new WP_Query( 'page_i... | 2012/06/24 | [
"https://wordpress.stackexchange.com/questions/56370",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16936/"
] | I would like to remove fields from the profile in [Theme My Login](http://wordpress.org/extend/plugins/theme-my-login/). I want to remove everything except email and password field. I am able to hide fields using a little jQuery. But un fortunately I'm not good with it. Can someone help me how to make this? step by ste... | Create a page theme, then call it in `index.php`:
```
$recent = new WP_Query( 'page_id=**ID**' );
while ( $recent->have_posts() ) : $recent->the_post();
?><h3><?php the_title(); ?></h3><?php
the_content();
endwhile;
``` |
56,375 | <p>I have differnet Custom Post Types in my blog. <br />I also have custom templates for each of them like <strong>loop-{$cpt-name}.php</strong><br />
I would like to include different cpt templates dynamically in search results based on what custom post type is post at the moment in the loop. I am trying to do it like... | [
{
"answer_id": 56739,
"author": "danblaker",
"author_id": 750,
"author_profile": "https://wordpress.stackexchange.com/users/750",
"pm_score": 0,
"selected": false,
"text": "<p>You're definitely better off only doing one query, but it will require a little re-architecting of your custom p... | 2012/06/24 | [
"https://wordpress.stackexchange.com/questions/56375",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17254/"
] | I have differnet Custom Post Types in my blog.
I also have custom templates for each of them like **loop-{$cpt-name}.php**
I would like to include different cpt templates dynamically in search results based on what custom post type is post at the moment in the loop. I am trying to do it like this ( search.php ):
... | I would recommend using **content-{posttype}.php** method, where you only have HTML markup, template tags for posts or custom post types and leave loops outside of those files. See Twenty Eleven for more detailed example.
After this change you can easily modify search.php and include specific content markup based on p... |
56,376 | <p>i've been searching for a while now on how to show Cubepoints Points and Ranks in bbPress replies right below the user avatar and name... </p>
<p>Found the template file where to show the info, tho not sure this would be the correct one to grab the reply-author info, the "loop-single-reply.php" and just bellow bbp... | [
{
"answer_id": 56739,
"author": "danblaker",
"author_id": 750,
"author_profile": "https://wordpress.stackexchange.com/users/750",
"pm_score": 0,
"selected": false,
"text": "<p>You're definitely better off only doing one query, but it will require a little re-architecting of your custom p... | 2012/06/24 | [
"https://wordpress.stackexchange.com/questions/56376",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17463/"
] | i've been searching for a while now on how to show Cubepoints Points and Ranks in bbPress replies right below the user avatar and name...
Found the template file where to show the info, tho not sure this would be the correct one to grab the reply-author info, the "loop-single-reply.php" and just bellow bbp\_reply\_au... | I would recommend using **content-{posttype}.php** method, where you only have HTML markup, template tags for posts or custom post types and leave loops outside of those files. See Twenty Eleven for more detailed example.
After this change you can easily modify search.php and include specific content markup based on p... |
56,377 | <p>I noticed that if you make changes trough the new "customize" feature, when you navigate on a different page within the iframe preview document, your changes still apply, even if they are unsaved.</p>
<p>It looks like WP is storing the temporary changes somewhere, and it applies them on the site if the site is view... | [
{
"answer_id": 56729,
"author": "Andy Adams",
"author_id": 6816,
"author_profile": "https://wordpress.stackexchange.com/users/6816",
"pm_score": 1,
"selected": false,
"text": "<p>You'll notice that when you click a link in the customizer preview window, the request that is generated is a... | 2012/06/24 | [
"https://wordpress.stackexchange.com/questions/56377",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17464/"
] | I noticed that if you make changes trough the new "customize" feature, when you navigate on a different page within the iframe preview document, your changes still apply, even if they are unsaved.
It looks like WP is storing the temporary changes somewhere, and it applies them on the site if the site is viewed in "cus... | There's a few bits here that apply, but the short of it is this code in `customize-preview.js`:
```
this.body.on( 'click.preview', 'a', function( event ) {
event.preventDefault();
self.send( 'scroll', 0 );
self.send( 'url', $(this).prop('href') );
});
```
The event.preventDefault prevents the links from ... |
56,383 | <p>I've hit some sort of stumbling bock here, and I can't find my way over it.</p>
<p>I'm trying to craft a custom WP query that searches for posts by country of origin, selecting multiple countries at once. </p>
<p>I have a table that maps countries to regions, so the initial query will search for the selected regio... | [
{
"answer_id": 56729,
"author": "Andy Adams",
"author_id": 6816,
"author_profile": "https://wordpress.stackexchange.com/users/6816",
"pm_score": 1,
"selected": false,
"text": "<p>You'll notice that when you click a link in the customizer preview window, the request that is generated is a... | 2012/06/24 | [
"https://wordpress.stackexchange.com/questions/56383",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16909/"
] | I've hit some sort of stumbling bock here, and I can't find my way over it.
I'm trying to craft a custom WP query that searches for posts by country of origin, selecting multiple countries at once.
I have a table that maps countries to regions, so the initial query will search for the selected region, and return all... | There's a few bits here that apply, but the short of it is this code in `customize-preview.js`:
```
this.body.on( 'click.preview', 'a', function( event ) {
event.preventDefault();
self.send( 'scroll', 0 );
self.send( 'url', $(this).prop('href') );
});
```
The event.preventDefault prevents the links from ... |
56,385 | <p>I'm using a redirect plugin that adds rewrites to the permalink. I want to count views on the front-end since I can't hook into the single.php as a result. This seems to be close, but it isn't incrementing the views meta value. I'm not sure where to debug, or tr</p>
<p>Here's my code so far:</p>
<p>I'm copying ... | [
{
"answer_id": 56729,
"author": "Andy Adams",
"author_id": 6816,
"author_profile": "https://wordpress.stackexchange.com/users/6816",
"pm_score": 1,
"selected": false,
"text": "<p>You'll notice that when you click a link in the customizer preview window, the request that is generated is a... | 2012/06/24 | [
"https://wordpress.stackexchange.com/questions/56385",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17467/"
] | I'm using a redirect plugin that adds rewrites to the permalink. I want to count views on the front-end since I can't hook into the single.php as a result. This seems to be close, but it isn't incrementing the views meta value. I'm not sure where to debug, or tr
Here's my code so far:
I'm copying most of this from th... | There's a few bits here that apply, but the short of it is this code in `customize-preview.js`:
```
this.body.on( 'click.preview', 'a', function( event ) {
event.preventDefault();
self.send( 'scroll', 0 );
self.send( 'url', $(this).prop('href') );
});
```
The event.preventDefault prevents the links from ... |
56,392 | <p>When I insert images into a blog post, wp is automatically inserted markup around the img element: specifically a div and a p (for the caption).....where is that markup being generated in wp sourcecode?</p>
| [
{
"answer_id": 56425,
"author": "Robert Kopacz",
"author_id": 10066,
"author_profile": "https://wordpress.stackexchange.com/users/10066",
"pm_score": 0,
"selected": false,
"text": "<p>have a look inside the media.php file in the wp-includes folder. In WP 3.4, around line 198. This is the... | 2012/06/24 | [
"https://wordpress.stackexchange.com/questions/56392",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9039/"
] | When I insert images into a blog post, wp is automatically inserted markup around the img element: specifically a div and a p (for the caption).....where is that markup being generated in wp sourcecode? | ```
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
```
The p tags come from [wpautop](http://codex.wordpress.org/Function_Reference/wpautop) |
56,407 | <p>Ok, the quick explanation:</p>
<p>I'm using a custom post type, 'lakes'. And, using custom taxonomies to organize them. They are: state, watertype and county. </p>
<p>I've created a 'page' for each state that displays all the listings using that state's name in the tags. This part works fine. What we want to do is... | [
{
"answer_id": 56445,
"author": "Godforever",
"author_id": 17254,
"author_profile": "https://wordpress.stackexchange.com/users/17254",
"pm_score": 0,
"selected": false,
"text": "<p>First of all you didn't mention what taxonomies are your states? \nSecondly when you say \"tag\", again, wh... | 2012/06/24 | [
"https://wordpress.stackexchange.com/questions/56407",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17472/"
] | Ok, the quick explanation:
I'm using a custom post type, 'lakes'. And, using custom taxonomies to organize them. They are: state, watertype and county.
I've created a 'page' for each state that displays all the listings using that state's name in the tags. This part works fine. What we want to do is also have some o... | If you don't need a "tag", I have seen "Featured" items be featured by some a post meta key. I always need a way to feature items, so yesterday I wrote a plugin that will add a metabox to any post type you'd like, with a simple checkbox. Also has columns and quickedit capabilities.
<https://github.com/helgatheviking/F... |
56,411 | <p>I am using WP 3.4. My problem occurs when I attempt to copy and paste anything into the post or page editor of WordPress. The situation arises every time I save or attempt to preview the post. The post gets truncated and about 65% of the text gets chopped off the end of the post. This does not happen if I manually e... | [
{
"answer_id": 56416,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 2,
"selected": false,
"text": "<p>Your browser doesn’t send the copied text UTF-8 encoded to the server. On the first character that isn’t UTF-8 compati... | 2012/06/24 | [
"https://wordpress.stackexchange.com/questions/56411",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17474/"
] | I am using WP 3.4. My problem occurs when I attempt to copy and paste anything into the post or page editor of WordPress. The situation arises every time I save or attempt to preview the post. The post gets truncated and about 65% of the text gets chopped off the end of the post. This does not happen if I manually ente... | Your browser doesn’t send the copied text UTF-8 encoded to the server. On the first character that isn’t UTF-8 compatible, in your example the apostrophe – ’ –, the stream to the data base is broken and not recovered. That’s a browser issue.
If I had to guess – well, I *have* because you didn’t mention it – I would ... |
56,417 | <p>I'm trying to add a rewrite rule to make this:</p>
<pre><code>mysite/?attachment_id=106
</code></pre>
<p>look like this:</p>
<pre><code>mysite/series/106
</code></pre>
<p>I've looked everywhere in this site and others and it's very confusing because there are lots of different ways to do it.
I've tried editing t... | [
{
"answer_id": 56426,
"author": "vmassuchetto",
"author_id": 7385,
"author_profile": "https://wordpress.stackexchange.com/users/7385",
"pm_score": 2,
"selected": false,
"text": "<p>This seem to work for me:</p>\n\n<pre><code>// Add your query variable\n\nadd_filter( 'query_vars', 'my_que... | 2012/06/25 | [
"https://wordpress.stackexchange.com/questions/56417",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17249/"
] | I'm trying to add a rewrite rule to make this:
```
mysite/?attachment_id=106
```
look like this:
```
mysite/series/106
```
I've looked everywhere in this site and others and it's very confusing because there are lots of different ways to do it.
I've tried editing the `functions.php` file in my themes folder, addi... | Place the code suggested below in *functions.php* of your desired theme, it worked for me with WP 3.4: [http://matty.co.za/2009/11/custom-url-rewrites-in-wordpress/](http://matty.blog/custom-url-rewrites-in-wordpress/) |
56,429 | <p>Is it possible to dynamically get sidebar parameters from within a widget? That is, I am trying to access the <code>before_widget</code>/<code>after_widget</code>/<code>before_title</code>/<code>after_title</code>/<code>name</code> parameters of the containing sidebar.</p>
<p>Suppose we have a sidebar registered li... | [
{
"answer_id": 56440,
"author": "Samiul Amin Shanto",
"author_id": 17469,
"author_profile": "https://wordpress.stackexchange.com/users/17469",
"pm_score": -1,
"selected": false,
"text": "<p>Use variable name only, like:</p>\n\n<pre><code>$name\n$before_title\n$after_title\n$before_widget... | 2012/06/25 | [
"https://wordpress.stackexchange.com/questions/56429",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3564/"
] | Is it possible to dynamically get sidebar parameters from within a widget? That is, I am trying to access the `before_widget`/`after_widget`/`before_title`/`after_title`/`name` parameters of the containing sidebar.
Suppose we have a sidebar registered like so:
```
register_sidebar( array(
'name' => "Homepage Side... | The parameters are given (as an array) as the first argument provided to the `widget` method. The second argument, `$instance`, holds the options for that particular instance of the widget.
My usual set up is:
```
function widget($args, $instance){
//Extract the widget-sidebar parameters from array
extract($... |
56,433 | <p>I have a custom post type and I want to be able to control the order that the posts are displayed by defining the order in an array, and then checking the posts meta_value against the array to see where it should sit in the order of posts.</p>
<p>Using the code below I can get the dealers who's 'Postcode' is one of... | [
{
"answer_id": 56440,
"author": "Samiul Amin Shanto",
"author_id": 17469,
"author_profile": "https://wordpress.stackexchange.com/users/17469",
"pm_score": -1,
"selected": false,
"text": "<p>Use variable name only, like:</p>\n\n<pre><code>$name\n$before_title\n$after_title\n$before_widget... | 2012/06/25 | [
"https://wordpress.stackexchange.com/questions/56433",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13184/"
] | I have a custom post type and I want to be able to control the order that the posts are displayed by defining the order in an array, and then checking the posts meta\_value against the array to see where it should sit in the order of posts.
Using the code below I can get the dealers who's 'Postcode' is one of the valu... | The parameters are given (as an array) as the first argument provided to the `widget` method. The second argument, `$instance`, holds the options for that particular instance of the widget.
My usual set up is:
```
function widget($args, $instance){
//Extract the widget-sidebar parameters from array
extract($... |
56,438 | <p>My brain has fallen over. How do I save this post data?
Building some key-value pairs in the form.</p>
<pre><code> for ($i = 1; $i <= 3; $i++) {
$saved = $meta[$i];
//print_r($saved);
//echo $saved['key'];
echo '<p>';
echo '<label for="meta_k_'.$i.'">Key<... | [
{
"answer_id": 56443,
"author": "HungryCoder",
"author_id": 17129,
"author_profile": "https://wordpress.stackexchange.com/users/17129",
"pm_score": 1,
"selected": false,
"text": "<p>you are almost there. just hook your saving logic to 'save_post'.</p>\n\n<pre><code>add_action('save_post'... | 2012/06/25 | [
"https://wordpress.stackexchange.com/questions/56438",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/6068/"
] | My brain has fallen over. How do I save this post data?
Building some key-value pairs in the form.
```
for ($i = 1; $i <= 3; $i++) {
$saved = $meta[$i];
//print_r($saved);
//echo $saved['key'];
echo '<p>';
echo '<label for="meta_k_'.$i.'">Key</label> ', '<input id="meta_k_... | This should be work:
```
foreach ($_POST['_meta'] as $value) {
update_post_meta($post_id, $value['key'], $value['value']);
}
``` |
56,459 | <p>When I sign out from the <a href="http://wordpress.org/extend/plugins/mingle-forum/" rel="nofollow noreferrer">forum</a> I'm using and click 'register', it takes me to the register page but some of the fields are already filled out. The name is in the 'email' field and the email address is in the 'password' field. H... | [
{
"answer_id": 56443,
"author": "HungryCoder",
"author_id": 17129,
"author_profile": "https://wordpress.stackexchange.com/users/17129",
"pm_score": 1,
"selected": false,
"text": "<p>you are almost there. just hook your saving logic to 'save_post'.</p>\n\n<pre><code>add_action('save_post'... | 2012/06/25 | [
"https://wordpress.stackexchange.com/questions/56459",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17488/"
] | When I sign out from the [forum](http://wordpress.org/extend/plugins/mingle-forum/) I'm using and click 'register', it takes me to the register page but some of the fields are already filled out. The name is in the 'email' field and the email address is in the 'password' field. How can I make it so that none of the fie... | This should be work:
```
foreach ($_POST['_meta'] as $value) {
update_post_meta($post_id, $value['key'], $value['value']);
}
``` |
56,473 | <p>I have a custom WP query that is returning every post, instead of just the ones being specified by the query. I can't seem to find anything wrong with the code, so I must be missing something: </p>
<pre><code>//Process incoming variable
if(!empty($_REQUEST['region'])){
$region = $_REQUEST['region'];
} else {
... | [
{
"answer_id": 56443,
"author": "HungryCoder",
"author_id": 17129,
"author_profile": "https://wordpress.stackexchange.com/users/17129",
"pm_score": 1,
"selected": false,
"text": "<p>you are almost there. just hook your saving logic to 'save_post'.</p>\n\n<pre><code>add_action('save_post'... | 2012/06/25 | [
"https://wordpress.stackexchange.com/questions/56473",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16909/"
] | I have a custom WP query that is returning every post, instead of just the ones being specified by the query. I can't seem to find anything wrong with the code, so I must be missing something:
```
//Process incoming variable
if(!empty($_REQUEST['region'])){
$region = $_REQUEST['region'];
} else {
$region =... | This should be work:
```
foreach ($_POST['_meta'] as $value) {
update_post_meta($post_id, $value['key'], $value['value']);
}
``` |
56,485 | <p>How do you display or process HTML in a wrapped shortcode ?</p>
<p><code>[myshortcode]<div class="map"></div>[/myshortcode]</code></p>
<p>my shortcode code is </p>
<pre><code>function myshortcode_sc($atts, $content = null) {
extract( shortcode_atts( array(
'col' => 'left',
), $atts ) );
$o... | [
{
"answer_id": 64357,
"author": "Chris",
"author_id": 10713,
"author_profile": "https://wordpress.stackexchange.com/users/10713",
"pm_score": 3,
"selected": true,
"text": "<p>Maybe try replacing</p>\n\n<pre><code>. do_shortcode($content) .\n</code></pre>\n\n<p>with\n<code>.$content.</cod... | 2012/06/25 | [
"https://wordpress.stackexchange.com/questions/56485",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4249/"
] | How do you display or process HTML in a wrapped shortcode ?
`[myshortcode]<div class="map"></div>[/myshortcode]`
my shortcode code is
```
function myshortcode_sc($atts, $content = null) {
extract( shortcode_atts( array(
'col' => 'left',
), $atts ) );
$output = '<div class="span' . esc_attr($col) . '">' . ... | Maybe try replacing
```
. do_shortcode($content) .
```
with
`.$content.` ?
Source: <http://wp.smashingmagazine.com/2009/02/02/mastering-wordpress-shortcodes/> |
56,489 | <p>I've got some code that I want to turn into a function. It works great until I wrap it in said function:</p>
<pre><code> $args = array(
'posts_per_page' => -1,
'post_type' => 'asset',
'category_name' => $cat
);
$cat_query = new WP_Query( $args );
$ma... | [
{
"answer_id": 56494,
"author": "EAMann",
"author_id": 46,
"author_profile": "https://wordpress.stackexchange.com/users/46",
"pm_score": 4,
"selected": true,
"text": "<p>Simple, you're addressing <code>$post</code> out of context.</p>\n\n<p>When you're running a standard WordPress loop, ... | 2012/06/25 | [
"https://wordpress.stackexchange.com/questions/56489",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16973/"
] | I've got some code that I want to turn into a function. It works great until I wrap it in said function:
```
$args = array(
'posts_per_page' => -1,
'post_type' => 'asset',
'category_name' => $cat
);
$cat_query = new WP_Query( $args );
$matching_category_ids = a... | Simple, you're addressing `$post` out of context.
When you're running a standard WordPress loop, WP will load a global `$post` variable with the results of the current query. This includes the ID, title, content, post meta, etc. The loop functions will reference this global variable to actually give you data.
Take th... |
56,491 | <p>So I am working on a site for a client of mine. We have about 50+ posts filed in a category called "Articles". I created a custom page template that has a custom query to display all the posts in a bullet list on this page, and if you click on it you can go directly to the post to read more or open a PDF directly. W... | [
{
"answer_id": 56496,
"author": "fdsa",
"author_id": 8288,
"author_profile": "https://wordpress.stackexchange.com/users/8288",
"pm_score": -1,
"selected": false,
"text": "<p>You could just print out <code>the_excerpt</code> and <a href=\"http://codex.wordpress.org/Function_Reference/the_... | 2012/06/25 | [
"https://wordpress.stackexchange.com/questions/56491",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17502/"
] | So I am working on a site for a client of mine. We have about 50+ posts filed in a category called "Articles". I created a custom page template that has a custom query to display all the posts in a bullet list on this page, and if you click on it you can go directly to the post to read more or open a PDF directly. Wher... | replace the\_content(); with echo wpse\_limit\_content();
```
function wpse_limit_content() {
$content = $post->post_content;
$MAX_LENGTH = 100;
if ( strlen( $content ) <= $MAX_LENGTH )
return apply_filters('the_content', $content );
$s2 = substr( $content, 0, $MAX_LENGTH );
$s3 = p... |
56,502 | <p>I was wondering if it's possible to enqueue raw CSS as a string directly from within a template file?</p>
<p>I'm writing a custom template for a page and need to add some style rules for it. What I want to do is write the styles out as a string var in PHP then use the enqueue_style function to load these styles, ra... | [
{
"answer_id": 56503,
"author": "kevin conboy",
"author_id": 17506,
"author_profile": "https://wordpress.stackexchange.com/users/17506",
"pm_score": 0,
"selected": false,
"text": "<p>Yes as long as it's registered/enqueued before wp_head() in the header.</p>\n"
},
{
"answer_id": ... | 2012/06/25 | [
"https://wordpress.stackexchange.com/questions/56502",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10789/"
] | I was wondering if it's possible to enqueue raw CSS as a string directly from within a template file?
I'm writing a custom template for a page and need to add some style rules for it. What I want to do is write the styles out as a string var in PHP then use the enqueue\_style function to load these styles, rather than... | Yes and no.
You *can* load a raw CSS string into the header programatically, but you can't use `wp_enqueue_style()` to enqueue it. That function specifically loads *files* into the header in `<link>` tags.
But what you can do is something like this:
```
function print_inline_script() {
?>
<style type="text/css">
/* ... |
56,507 | <p>I'm trying to direct new site visitors to a custom registration page <strong>for the their first visit only</strong>. The registration collects detailed information relating to an upcoming event, it is <strong>not</strong> designed to register the visitor as a user of the WordPress installation.</p>
<p>The registra... | [
{
"answer_id": 56503,
"author": "kevin conboy",
"author_id": 17506,
"author_profile": "https://wordpress.stackexchange.com/users/17506",
"pm_score": 0,
"selected": false,
"text": "<p>Yes as long as it's registered/enqueued before wp_head() in the header.</p>\n"
},
{
"answer_id": ... | 2012/06/25 | [
"https://wordpress.stackexchange.com/questions/56507",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16868/"
] | I'm trying to direct new site visitors to a custom registration page **for the their first visit only**. The registration collects detailed information relating to an upcoming event, it is **not** designed to register the visitor as a user of the WordPress installation.
The registration page contains a Gravity form wh... | Yes and no.
You *can* load a raw CSS string into the header programatically, but you can't use `wp_enqueue_style()` to enqueue it. That function specifically loads *files* into the header in `<link>` tags.
But what you can do is something like this:
```
function print_inline_script() {
?>
<style type="text/css">
/* ... |
56,508 | <p>I'd like to add a custom form to the admin bar in Wordpress. is there a way to accomplish this? So far all of the documentation seems to only allow the addition of simple text links.</p>
| [
{
"answer_id": 56535,
"author": "tollmanz",
"author_id": 4850,
"author_profile": "https://wordpress.stackexchange.com/users/4850",
"pm_score": 3,
"selected": false,
"text": "<p>I just gave this a shot and it seemed to work fine:</p>\n\n<pre><code>function wpse_form_in_admin_bar() {\n ... | 2012/06/25 | [
"https://wordpress.stackexchange.com/questions/56508",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/293/"
] | I'd like to add a custom form to the admin bar in Wordpress. is there a way to accomplish this? So far all of the documentation seems to only allow the addition of simple text links. | I just gave this a shot and it seemed to work fine:
```
function wpse_form_in_admin_bar() {
global $wp_admin_bar;
$wp_admin_bar->add_menu( array(
'id' => 'wpse-form-in-admin-bar',
'parent' => 'top-secondary',
'title' => '<form><input type="text" /><input type="submit" /> </form>'
)... |
56,552 | <p>I have a child theme based on the twenty ten theme which I am happy with except for one thing. My gallery posts (I am a photographer so the goal of my blog is pictures) do not show any images from the post on the main page. I want to have my main page be a list of recent gallery posts each of which should show the... | [
{
"answer_id": 56556,
"author": "josh",
"author_id": 6353,
"author_profile": "https://wordpress.stackexchange.com/users/6353",
"pm_score": 2,
"selected": true,
"text": "<p>Instead of overriding the main loop, you can always just create a template, similar to the main loop and use that on... | 2012/06/26 | [
"https://wordpress.stackexchange.com/questions/56552",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17287/"
] | I have a child theme based on the twenty ten theme which I am happy with except for one thing. My gallery posts (I am a photographer so the goal of my blog is pictures) do not show any images from the post on the main page. I want to have my main page be a list of recent gallery posts each of which should show the shor... | Instead of overriding the main loop, you can always just create a template, similar to the main loop and use that on a separate page (which you then set to display as your home page).
You'd just need to set up a wp\_query in that template to call the posts you want and run a loop on that.
That way everything is left ... |
56,555 | <p>I'm trying to create a search page for a custom post type. This is the code I'm using:</p>
<pre><code>$s = $_GET['s'];
$args = array(
'post_type' => 'companies',
's' => $s
);
query_posts($args);
if ( have_posts() ) :
....results.....
endif
</code></pre>
<p>The problem is that adding ... | [
{
"answer_id": 56880,
"author": "SickHippie",
"author_id": 5434,
"author_profile": "https://wordpress.stackexchange.com/users/5434",
"pm_score": 0,
"selected": false,
"text": "<p>The best way I've found to search custom post types is add an input field like this to your search form:</p>\... | 2012/06/26 | [
"https://wordpress.stackexchange.com/questions/56555",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16847/"
] | I'm trying to create a search page for a custom post type. This is the code I'm using:
```
$s = $_GET['s'];
$args = array(
'post_type' => 'companies',
's' => $s
);
query_posts($args);
if ( have_posts() ) :
....results.....
endif
```
The problem is that adding the "s" parameter in query\_post... | You shouldn't use `$_GET['s']` directly like that, and you definitely shouldn't use `query_posts`, although I understand using it for testing.
If you're going to build your own search mechanism in this way, then you should run `$_GET['s']`through the `urldecode()` function first, to make sure it doesn't contain weird ... |
56,558 | <p>I have a CPT with slug <code>function</code> (singular) and archive slug <code>functions</code> (plural).</p>
<p>Permalink structure for:</p>
<ul>
<li>singular is <code>/function/[postname]/</code> </li>
<li>archive is <code>/functions/[page-x/]</code>.</li>
</ul>
<p>(can poke live at <a href="http://queryposts.c... | [
{
"answer_id": 56559,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 3,
"selected": true,
"text": "<ol>\n<li>Hook into <code>'404_template'</code>. (<a href=\"https://github.com/toscho/T5-404-Tools/blob/master/t5-404-tool... | 2012/06/26 | [
"https://wordpress.stackexchange.com/questions/56558",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/847/"
] | I have a CPT with slug `function` (singular) and archive slug `functions` (plural).
Permalink structure for:
* singular is `/function/[postname]/`
* archive is `/functions/[page-x/]`.
(can poke live at [QueryPosts](http://queryposts.com/) )
This works and looks fine, however I have logged some cases when people man... | 1. Hook into `'404_template'`. ([Example](https://github.com/toscho/T5-404-Tools/blob/master/t5-404-tools.php))
2. [Fetch all public custom post types](http://codex.wordpress.org/Function_Reference/get_post_types) where `has_archive` is not `FALSE`.
3. Find the post type’s `has_archive` string and see if it is part of ... |
56,561 | <p>I am following this tutorial — "<a href="http://nenuno.co.uk/creative/wordpress/popular-posts-wordpress-without-plugin/" rel="nofollow">Display Your Popular Posts In WordPress Without A Plugin</a>" and want to limit the max number of characters in the title that are displayed. Also, why is the thumbnail, at times, s... | [
{
"answer_id": 56568,
"author": "Bainternet",
"author_id": 2487,
"author_profile": "https://wordpress.stackexchange.com/users/2487",
"pm_score": 2,
"selected": false,
"text": "<p>first add this function to your functions.php file</p>\n\n<pre><code>function max_title_length($title){\n ... | 2012/06/26 | [
"https://wordpress.stackexchange.com/questions/56561",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17531/"
] | I am following this tutorial — "[Display Your Popular Posts In WordPress Without A Plugin](http://nenuno.co.uk/creative/wordpress/popular-posts-wordpress-without-plugin/)" and want to limit the max number of characters in the title that are displayed. Also, why is the thumbnail, at times, smaller than the number I defi... | first add this function to your functions.php file
```
function max_title_length($title){
$max = 20;
return substr( $title, 0, $max ). " …";
}
```
then before the loop of the code you linked add this line to hook the above function:
```
add_filter( 'the_title', 'max_title_length');
```
and after t... |
56,562 | <p>I have a WP blog with a few pages and posts and several categories. I want to write a loop to retrieve images attached to the posts (not the pages) and only those from a specific category and it's children. The category id is 60.</p>
<p>This is the WP_Query call:</p>
<pre><code>$my_query = new WP_Query( array(
'... | [
{
"answer_id": 56563,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 1,
"selected": false,
"text": "<p>Attachment posts don't have categories, their parents 'post' posts do, so you have a two step problem.</p>\n... | 2012/06/26 | [
"https://wordpress.stackexchange.com/questions/56562",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14411/"
] | I have a WP blog with a few pages and posts and several categories. I want to write a loop to retrieve images attached to the posts (not the pages) and only those from a specific category and it's children. The category id is 60.
This is the WP\_Query call:
```
$my_query = new WP_Query( array(
'post_type' => 'attac... | You'll need to first grab the posts, then grab the attachments that are children of said posts.
```
$my_query = new WP_Query( array(
'meta_key' => 'my_hash',
'nopaging' => true,
'orderby' => 'meta_value',
'fields' => 'ids',
'cat' => '60',
));
if ( $post_ids = $my_query->get_posts() ) {
$post_i... |
56,569 | <p>How can I remove the category/taxonomy description field? The one which shows up on the edit category/taxonomy page. </p>
| [
{
"answer_id": 56570,
"author": "Rutwick Gangurde",
"author_id": 4740,
"author_profile": "https://wordpress.stackexchange.com/users/4740",
"pm_score": 2,
"selected": false,
"text": "<p>AFAIK, you can add new fields but you cannot remove the old ones! They are directly printed, and not st... | 2012/06/26 | [
"https://wordpress.stackexchange.com/questions/56569",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5079/"
] | How can I remove the category/taxonomy description field? The one which shows up on the edit category/taxonomy page. | When no hook is available, you can always count on the old jQuery trickery...
```
add_action( 'admin_footer-edit-tags.php', 'wpse_56569_remove_cat_tag_description' );
function wpse_56569_remove_cat_tag_description(){
global $current_screen;
switch ( $current_screen->id )
{
case 'edit-category':
... |
56,571 | <p>How can I override a function in pluggable.php?</p>
<p>I have tried making my own plugin -- got the fatal error on function already defined.</p>
<p>I tried functions.php in my theme -- got the white screen.</p>
<p>Is it possible to override a pluggable.php function without touching the source code file itself?</p... | [
{
"answer_id": 56576,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 4,
"selected": true,
"text": "<p>Wrap it in a <code>function_exists</code> check:</p>\n\n<pre><code>if( ! function_exists('some_pluggable_function') ... | 2012/06/26 | [
"https://wordpress.stackexchange.com/questions/56571",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17532/"
] | How can I override a function in pluggable.php?
I have tried making my own plugin -- got the fatal error on function already defined.
I tried functions.php in my theme -- got the white screen.
Is it possible to override a pluggable.php function without touching the source code file itself?
Thanks.
**Here is the fu... | Wrap it in a `function_exists` check:
```
if( ! function_exists('some_pluggable_function') ) {
function some_pluggable_function()
}
}
``` |
56,580 | <p>How can I create a different side bar for single posts than for main page?</p>
<p>At the moment I have 2 working one for pages and one for the blog</p>
<p>thanks</p>
<p>this is how it looks in funtions.php</p>
<pre><code>// Register Sidebars
register_sidebar(array('name' => 'Sidebar Blog','id' => 'sidebar-... | [
{
"answer_id": 56585,
"author": "Stephen Harris",
"author_id": 9364,
"author_profile": "https://wordpress.stackexchange.com/users/9364",
"pm_score": 0,
"selected": false,
"text": "<p>Register the sidebars:</p>\n\n<pre><code>register_sidebar(array('name' => 'Sidebar Blog','id' => 's... | 2012/06/26 | [
"https://wordpress.stackexchange.com/questions/56580",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17531/"
] | How can I create a different side bar for single posts than for main page?
At the moment I have 2 working one for pages and one for the blog
thanks
this is how it looks in funtions.php
```
// Register Sidebars
register_sidebar(array('name' => 'Sidebar Blog','id' => 'sidebar-blog'));
register_sidebar(array('name' =>... | I would consider the following ...
Register a new sidebar:
```
function your_new_widget() {
register_sidebar( array(
'name' => __( 'Single View Sidebar', 'your_textdomain' ),
'id' => 'sidebar-single',
'description' => __( 'This widget area is found only on the single post view.', 'yo... |
56,593 | <p>I'm not sure why this script is not loading or producing any load errors via Firebug. Here is my plugin script:</p>
<pre><code>class AV_Slideshow{
function __construct(){
$this->hooks();
}
function hooks(){
add_action('wp_head', array( $this, 'load_av_slider' ));
}
function load_av_slider(){
wp_... | [
{
"answer_id": 56594,
"author": "Stephen Harris",
"author_id": 9364,
"author_profile": "https://wordpress.stackexchange.com/users/9364",
"pm_score": 2,
"selected": true,
"text": "<p>The class constructor method isn't called until your shortcode handler is (i.e. when WordPress is searchin... | 2012/06/26 | [
"https://wordpress.stackexchange.com/questions/56593",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10099/"
] | I'm not sure why this script is not loading or producing any load errors via Firebug. Here is my plugin script:
```
class AV_Slideshow{
function __construct(){
$this->hooks();
}
function hooks(){
add_action('wp_head', array( $this, 'load_av_slider' ));
}
function load_av_slider(){
wp_register_script('... | The class constructor method isn't called until your shortcode handler is (i.e. when WordPress is searching the post content for shortcodes). This is done after `wp_head` is called, so you're missing the boat.
However, you don't need to enqueue scripts on your `wp_head` - and doing so for shortcodes/widgets which may ... |
56,596 | <p>I would like to display two images in my header.</p>
<p>functions.php:</p>
<pre><code>define('BP_DTHEME_DISABLE_CUSTOM_HEADER', true);
//add support for featured images with post type of header image
add_theme_support( 'post-thumbnails', array('header_image') );
add_action( 'init', 'create_post_type' );
functio... | [
{
"answer_id": 56600,
"author": "Shane",
"author_id": 10555,
"author_profile": "https://wordpress.stackexchange.com/users/10555",
"pm_score": 2,
"selected": true,
"text": "<p>I think you should be using the WordPress <code>loop</code> instead of a foreach, since you're using WP_Query.</p... | 2012/06/26 | [
"https://wordpress.stackexchange.com/questions/56596",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/11033/"
] | I would like to display two images in my header.
functions.php:
```
define('BP_DTHEME_DISABLE_CUSTOM_HEADER', true);
//add support for featured images with post type of header image
add_theme_support( 'post-thumbnails', array('header_image') );
add_action( 'init', 'create_post_type' );
function create_post_type() ... | I think you should be using the WordPress `loop` instead of a foreach, since you're using WP\_Query.
```
<?php if( $header_images->have_posts() ) { while( $header_images->have_posts() ) { $header_images->the_post(); ?>
<div class="header-image">
<?php echo get_the_post_thumbnail( $post->ID, 'thumbnai... |
56,597 | <p>I need opposite of this:</p>
<pre><code><?php if ( get_post_meta($post->ID, 'price_list_category1', true) ) : ?>style="display:none;"<?php endif; ?>
</code></pre>
<p>In other words I want <code>style="display:none;"</code> only when meta data doesn't exist.</p>
<p>I thought it would be straightfor... | [
{
"answer_id": 56599,
"author": "Shane",
"author_id": 10555,
"author_profile": "https://wordpress.stackexchange.com/users/10555",
"pm_score": 4,
"selected": true,
"text": "<p><del>You could use the <code>empty</code> function inside your <code>if</code> as such :</del></p>\n\n<pre><code>... | 2012/06/26 | [
"https://wordpress.stackexchange.com/questions/56597",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | I need opposite of this:
```
<?php if ( get_post_meta($post->ID, 'price_list_category1', true) ) : ?>style="display:none;"<?php endif; ?>
```
In other words I want `style="display:none;"` only when meta data doesn't exist.
I thought it would be straightforward like `if ( get_post_meta($post->ID, 'price_list_catego... | ~~You could use the `empty` function inside your `if` as such :~~
```
<?php if( empty( get_post_meta( $post->ID, 'price_list_category1', true ) ) ) : ?>style="display:none;"<?php endif; ?>
```
The above returns an error, you should assign the return value to a variable. See my edit below.
**Warning**
`empty` might... |
56,606 | <p>Now, when you add or edit a particular post within your desired post type, there are more screen options as well. Although, these Screen Options are showing/hiding meta boxes. I would like to be able to programmatically obtain a list of all of these registered Screen Options of meta boxes, so that I can again check ... | [
{
"answer_id": 56628,
"author": "MikeSchinkel",
"author_id": 89,
"author_profile": "https://wordpress.stackexchange.com/users/89",
"pm_score": 5,
"selected": true,
"text": "<p>What you need is in global <code>$wp_meta_boxes</code> indexed by <code>get_current_screen()->id</code>. Remo... | 2012/06/26 | [
"https://wordpress.stackexchange.com/questions/56606",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9579/"
] | Now, when you add or edit a particular post within your desired post type, there are more screen options as well. Although, these Screen Options are showing/hiding meta boxes. I would like to be able to programmatically obtain a list of all of these registered Screen Options of meta boxes, so that I can again check if ... | What you need is in global `$wp_meta_boxes` indexed by `get_current_screen()->id`. Removing the screen options will also remove the metaboxes which you can do just before screen options are displayed using the `'in_admin_header'` hook.
So let's assume you want to get rid of the *"Send Trackbacks"* screen option which ... |
56,607 | <p>I have a installation of Multisite that has a history of serious signup spam problems.</p>
<p>When we ran WPMU 2.9.2 we tried <a href="http://www.darcynorman.net/2009/05/20/stopping-spamblog-registration-in-wordpress-multiuser/" rel="nofollow">this .htaccess method</a>, <a href="http://wpmu.org/block-spam-on-wordpr... | [
{
"answer_id": 56628,
"author": "MikeSchinkel",
"author_id": 89,
"author_profile": "https://wordpress.stackexchange.com/users/89",
"pm_score": 5,
"selected": true,
"text": "<p>What you need is in global <code>$wp_meta_boxes</code> indexed by <code>get_current_screen()->id</code>. Remo... | 2012/06/26 | [
"https://wordpress.stackexchange.com/questions/56607",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9383/"
] | I have a installation of Multisite that has a history of serious signup spam problems.
When we ran WPMU 2.9.2 we tried [this .htaccess method](http://www.darcynorman.net/2009/05/20/stopping-spamblog-registration-in-wordpress-multiuser/), [this math plugin](http://wpmu.org/block-spam-on-wordpress-multisite-and-buddypre... | What you need is in global `$wp_meta_boxes` indexed by `get_current_screen()->id`. Removing the screen options will also remove the metaboxes which you can do just before screen options are displayed using the `'in_admin_header'` hook.
So let's assume you want to get rid of the *"Send Trackbacks"* screen option which ... |
56,656 | <p>I would like to create a template file and put there a login code, register code and widget code. I can do it for a widget, but I do not know how to do such thing for login and register. Any advice how to accomplish that?</p>
| [
{
"answer_id": 56660,
"author": "Max Yudin",
"author_id": 11761,
"author_profile": "https://wordpress.stackexchange.com/users/11761",
"pm_score": 0,
"selected": false,
"text": "<p>You can use login and register forms as widgets also. Register more widget areas and use some plugins there.... | 2012/06/27 | [
"https://wordpress.stackexchange.com/questions/56656",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17368/"
] | I would like to create a template file and put there a login code, register code and widget code. I can do it for a widget, but I do not know how to do such thing for login and register. Any advice how to accomplish that? | There's [`wp_register()`](http://queryposts.com/function/wp_register/) which displays either a link to the registration or a login link.
Then you got [`wp_loginout()`](http://queryposts.com/function/wp_loginout/) that has either a login or logout link - depending on the login status of the user.
Another thing you cou... |
56,658 | <p>so close to figuring this out, or not I'm not to sure! Basically what I want to do is on the authors page (so outside the loop) if a user role is an editor I want to display a little badge (but just outputting their name and role at the mo) in their profile. I have:</p>
<p>functions.php:</p>
<pre><code>function ge... | [
{
"answer_id": 56659,
"author": "Rutwick Gangurde",
"author_id": 4740,
"author_profile": "https://wordpress.stackexchange.com/users/4740",
"pm_score": 0,
"selected": false,
"text": "<p>Edit: Get all the editors first and then loop over them.</p>\n\n<pre><code>$users = get_users(array('ro... | 2012/06/27 | [
"https://wordpress.stackexchange.com/questions/56658",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16473/"
] | so close to figuring this out, or not I'm not to sure! Basically what I want to do is on the authors page (so outside the loop) if a user role is an editor I want to display a little badge (but just outputting their name and role at the mo) in their profile. I have:
functions.php:
```
function get_user_role($id)
{
... | In your template:
```
// rolename could for e.g. be 'editor' or 'author' or 'administrator'
author_can( get_the_ID(), 'rolename' ) AND print "<img src='...' alt='A kool badge!' />";
``` |
56,667 | <p>I want to echo my hierarchical taxonomies parents which I used in my posts.<br>
I've see answers about that, but no one didn't help me.</p>
<p>To get all taxonomies, currently I use </p>
<pre><code><?php the_terms( $post->ID, 'mytaxname', '', ' / ', ' ' ); ?>`
</code></pre>
<p>How to get only parents of ... | [
{
"answer_id": 58315,
"author": "marikamitsos",
"author_id": 17797,
"author_profile": "https://wordpress.stackexchange.com/users/17797",
"pm_score": 0,
"selected": false,
"text": "<p>There is a plugin that claims to do <em>(we haven't tried it ourselves)</em> what you are looking for.</p... | 2012/06/27 | [
"https://wordpress.stackexchange.com/questions/56667",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17567/"
] | I want to echo my hierarchical taxonomies parents which I used in my posts.
I've see answers about that, but no one didn't help me.
To get all taxonomies, currently I use
```
<?php the_terms( $post->ID, 'mytaxname', '', ' / ', ' ' ); ?>`
```
How to get only parents of used tax's? | I think you should try to get it to work in some other way.
It's normal it doesn't work, since the url from the page can't be changed by the .htaccess, because the url is not your permalink but the new domain.
Why not set the name server of the new url, to the old one.
so they go to the same page.
Then change your... |
56,681 | <p>I'm using the following code in my functions.php file to redirect users who are not logged in to a particular landing page</p>
<pre><code> <?php
if(!is_user_logged_in()) {
wp_redirect( 'http://www.mysite.com/landingpage', 301 ); exit;
}
</code></pre>
<p>The problem is I cannot access my wp-login or wp-ad... | [
{
"answer_id": 56682,
"author": "1321941",
"author_id": 15923,
"author_profile": "https://wordpress.stackexchange.com/users/15923",
"pm_score": 0,
"selected": false,
"text": "<pre><code> <?php\nif($_SERVER['REQUEST_URI'] != '.../' || $_SERVER['REQUEST_URI'] != '.../'){\n\n if(!is_us... | 2012/06/27 | [
"https://wordpress.stackexchange.com/questions/56681",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | I'm using the following code in my functions.php file to redirect users who are not logged in to a particular landing page
```
<?php
if(!is_user_logged_in()) {
wp_redirect( 'http://www.mysite.com/landingpage', 301 ); exit;
}
```
The problem is I cannot access my wp-login or wp-admin anymore. Every url redire... | something like:
```
if (
!in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))
&& !is_admin()
&& !is_user_logged_in()
) {
wp_redirect('http://www.mysite.com/landingpage', 301);
exit;
}
```
should do it.
see <http://codex.wordpress.org/Function_Reference/is_admin> &
[Check if wp-login i... |
56,695 | <p>I am currently working on the completion of a custom template and my last hurdle is to be able to remove the comments feed link being added to the head of the page.</p>
<p>For example: in firefox when you open any of the pages on my site there is an rss icon, when clicked I am shown 3 options to add to my reader bu... | [
{
"answer_id": 56696,
"author": "Sergi",
"author_id": 17739,
"author_profile": "https://wordpress.stackexchange.com/users/17739",
"pm_score": 3,
"selected": true,
"text": "<p>Add this to <code>functions.php</code></p>\n\n<pre class=\"lang-php prettyprint-override\"><code>add_filter('post... | 2011/01/07 | [
"https://wordpress.stackexchange.com/questions/56695",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13161/"
] | I am currently working on the completion of a custom template and my last hurdle is to be able to remove the comments feed link being added to the head of the page.
For example: in firefox when you open any of the pages on my site there is an rss icon, when clicked I am shown 3 options to add to my reader but the last... | Add this to `functions.php`
```php
add_filter('post_comments_feed_link', '__return_null');
``` |
56,698 | <p>While a specific use-case, I believe this may benefit others.</p>
<p>I am using <a href="http://wphostreviews.com/product/turbocsv" rel="nofollow">TurboCSV</a> to mass-import a number of posts into WordPress (which it is doing wonderfully so far). Within that import, I am specifying custom fields to be used in conj... | [
{
"answer_id": 61175,
"author": "SickHippie",
"author_id": 5434,
"author_profile": "https://wordpress.stackexchange.com/users/5434",
"pm_score": 3,
"selected": true,
"text": "<p>Have you seen <a href=\"http://code.trac.wordpress.org/browser/wpshell\" rel=\"nofollow\">wpshell</a>? It's a... | 2012/06/27 | [
"https://wordpress.stackexchange.com/questions/56698",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9605/"
] | While a specific use-case, I believe this may benefit others.
I am using [TurboCSV](http://wphostreviews.com/product/turbocsv) to mass-import a number of posts into WordPress (which it is doing wonderfully so far). Within that import, I am specifying custom fields to be used in conjunction with [Advanced Custom Fields... | Have you seen [wpshell](http://code.trac.wordpress.org/browser/wpshell)? It's a command line tool for wordpress. Basically, it's a Wordpress environment that lets you run arbitrary php - so you could set up a `WP_Query` that pulls all posts, loop through them, and fire that command on each one.
Sort of what I had in m... |
56,703 | <p>Following snippet used(and works great) but generates a redirect chain :(.</p>
<pre><code>If (function_excists('basicgravatar')
function basicgravatar ($avatar_defaults) {
$myavatar = get_stylesheet_directory_uri() . '/images/gravatar.png'; //Child theme
//$myavatar = get_bloginfo('template_directory') . '... | [
{
"answer_id": 56714,
"author": "Bainternet",
"author_id": 2487,
"author_profile": "https://wordpress.stackexchange.com/users/2487",
"pm_score": 0,
"selected": false,
"text": "<p>I use <a href=\"http://wordpress.org/extend/plugins/fv-gravatar-cache/\" rel=\"nofollow\"><strong><code>FV G... | 2012/06/27 | [
"https://wordpress.stackexchange.com/questions/56703",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15605/"
] | Following snippet used(and works great) but generates a redirect chain :(.
```
If (function_excists('basicgravatar')
function basicgravatar ($avatar_defaults) {
$myavatar = get_stylesheet_directory_uri() . '/images/gravatar.png'; //Child theme
//$myavatar = get_bloginfo('template_directory') . '/images/gravat... | This is essentially how gravatar service works.
Your code has no knowledge if particular email has gravatar associated with it. The only way would be to query gravatar API and store if there is gravatar available (and re-query for updates) for each email and resulting functionality will quickly snowball past just havi... |
56,707 | <p>How to display the content for given page ID withot the <code><p></p></code> wrapper?</p>
<p>The method I'm currently using is: </p>
<pre><code><?php
$id=21;
$post = get_page($id);
$content = apply_filters('the_content', $post->post_content);
echo $content;
?>
</code></pre>
<p>For examp... | [
{
"answer_id": 56708,
"author": "Bainternet",
"author_id": 2487,
"author_profile": "https://wordpress.stackexchange.com/users/2487",
"pm_score": 2,
"selected": false,
"text": "<p>You need to remove the <code>wpautop</code> filter ex:</p>\n\n<pre><code><?php \n$id=21; \n$post = get_pag... | 2012/06/27 | [
"https://wordpress.stackexchange.com/questions/56707",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17269/"
] | How to display the content for given page ID withot the `<p></p>` wrapper?
The method I'm currently using is:
```
<?php
$id=21;
$post = get_page($id);
$content = apply_filters('the_content', $post->post_content);
echo $content;
?>
```
For example `page ID = 21` has the following content: `Some content`
What... | You can add this in your functions.php file for instance,
```
remove_filter ('the_content', 'wpautop');
```
Which will remove the paragraph formatting from `the_content` template tag in all cases.
Should you have a need for it in the future, you can write;
`<?php wpautop(the_content());?`> in your template to add... |
56,721 | <p>No matter what, I CANNOT figure out why WP_Query pulls in all posts, and completely ignores <code>posts_per_page</code> ...
I only want to show one post.</p>
<pre><code><?php
$args = array(
'post_type' => 'post',
'orderby' => 'date',
'order' => 'ASC',
'posts_per_page' => -1
);
... | [
{
"answer_id": 56724,
"author": "Pontus Abrahamsson",
"author_id": 16722,
"author_profile": "https://wordpress.stackexchange.com/users/16722",
"pm_score": 4,
"selected": true,
"text": "<p>Change <code>posts_per_page</code> to <code>1</code> only, not <code>-1</code>.</p>\n\n<p>Like this:... | 2012/06/27 | [
"https://wordpress.stackexchange.com/questions/56721",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9295/"
] | No matter what, I CANNOT figure out why WP\_Query pulls in all posts, and completely ignores `posts_per_page` ...
I only want to show one post.
```
<?php
$args = array(
'post_type' => 'post',
'orderby' => 'date',
'order' => 'ASC',
'posts_per_page' => -1
);
// The Query
$the_query = new WP_Query(... | Change `posts_per_page` to `1` only, not `-1`.
Like this: `'posts_per_page' => 1`
`-1` means all. |
56,730 | <p>I'm receiving this error: [27-Jun-2012 18:22:39 UTC] PHP Fatal error: Call to undefined function plugin_basename() in /XXXX/public_html/wp-content/plugins/price-update/price-update.php on line 68:</p>
<pre><code> //We set the plugin basename here, could manually set it, but this is for demonstration pur... | [
{
"answer_id": 56773,
"author": "Michael Ecklund",
"author_id": 9579,
"author_profile": "https://wordpress.stackexchange.com/users/9579",
"pm_score": 0,
"selected": false,
"text": "<p>Perhaps you'd be better off using <a href=\"http://codex.wordpress.org/Function_Reference/plugin_dir_pat... | 2012/06/27 | [
"https://wordpress.stackexchange.com/questions/56730",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5605/"
] | I'm receiving this error: [27-Jun-2012 18:22:39 UTC] PHP Fatal error: Call to undefined function plugin\_basename() in /XXXX/public\_html/wp-content/plugins/price-update/price-update.php on line 68:
```
//We set the plugin basename here, could manually set it, but this is for demonstration purposes
... | [plugin\_basename](http://codex.wordpress.org/Function_Reference/plugin_basename) is a WordPress function that gets your plugins file name by simply passing it the directory.
-------------------------------------------------------------------------------------------------------------------------------------------------... |
56,732 | <p>I am trying to create a custom field for a custom taxonomy. update_post_meta works great with posts. Taxonomies are not posts so this won't work. </p>
<pre><code><?php update_post_meta($post_id, $meta_key, $meta_value, $prev_value); ?>
</code></pre>
<p>How would I save a custom field within a custom taxo... | [
{
"answer_id": 56737,
"author": "Neil",
"author_id": 17591,
"author_profile": "https://wordpress.stackexchange.com/users/17591",
"pm_score": 1,
"selected": false,
"text": "<p>Correct me if I'm wrong, but isn't what you're looking for the <a href=\"http://codex.wordpress.org/Taxonomies#Us... | 2012/06/27 | [
"https://wordpress.stackexchange.com/questions/56732",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/2825/"
] | I am trying to create a custom field for a custom taxonomy. update\_post\_meta works great with posts. Taxonomies are not posts so this won't work.
```
<?php update_post_meta($post_id, $meta_key, $meta_value, $prev_value); ?>
```
How would I save a custom field within a custom taxonomy? Other solutions include the... | ```
update_metadata()
```
great post on [Adding Custom Fields to Taxonomy](http://shibashake.com/wordpress-theme/add-term-or-taxonomy-meta-data).
The solution outlined does require creating an additional database table but it does the job perfectly. |
56,736 | <p>I want to use local avatar system for my wp website , I want to filter the <code>get_avatar()</code> function so it will return the avatar from my server instead of the default gavatar .</p>
<p>I have the following code :</p>
<pre><code>class local_avatar{
function __construct(){
add_fil... | [
{
"answer_id": 56741,
"author": "Pontus Abrahamsson",
"author_id": 16722,
"author_profile": "https://wordpress.stackexchange.com/users/16722",
"pm_score": 2,
"selected": false,
"text": "<p>You can easy add new avatars with this function:</p>\n\n<pre><code> // Custom Default Avatar\n if (... | 2012/06/27 | [
"https://wordpress.stackexchange.com/questions/56736",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17188/"
] | I want to use local avatar system for my wp website , I want to filter the `get_avatar()` function so it will return the avatar from my server instead of the default gavatar .
I have the following code :
```
class local_avatar{
function __construct(){
add_filter('get_avatar',array($this,'get_avat... | You can easy add new avatars with this function:
```
// Custom Default Avatar
if ( !function_exists('addgravatar') ) {
function addgravatar( $avatar_defaults ) {
$myavatar = get_bloginfo('template_directory').'/images/custom-gravatar.jpg';
// Change path to your custom avatar
$avatar_defaults[$my... |
56,742 | <p>The WordPress Codex points to an extremely simple way to change the <strong>URL</strong> of the wp-content directory, which is, adding this in wp-config.php:</p>
<pre><code>define( 'WP_CONTENT_URL', 'http://example.com/wp-content');
</code></pre>
<p>And that does the job of serving most of the JavaScript and CSS f... | [
{
"answer_id": 56746,
"author": "fdsa",
"author_id": 8288,
"author_profile": "https://wordpress.stackexchange.com/users/8288",
"pm_score": -1,
"selected": false,
"text": "<p>The function <a href=\"http://codex.wordpress.org/Function_Reference/wp_enqueue_script\" rel=\"nofollow\">wp_enque... | 2012/06/27 | [
"https://wordpress.stackexchange.com/questions/56742",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10691/"
] | The WordPress Codex points to an extremely simple way to change the **URL** of the wp-content directory, which is, adding this in wp-config.php:
```
define( 'WP_CONTENT_URL', 'http://example.com/wp-content');
```
And that does the job of serving most of the JavaScript and CSS files on my website from the different d... | Okay, I've tried numerous (literally) codes and methods, and failed miserably. So, like I said in the question, the only safe way seems to be re-registering (unregistering and enqueuing) the scripts.
**The Scripts:**
```
http://mywebsite.com/wp-includes/js/comment-reply.js
http://mywebsite.com/wp-includes/js/quicktag... |
56,760 | <p>Saving extra fields that were added to a taxonomy. I want the most proper & efficient way of doing so. <strong>Where should I save the new fields?</strong> </p>
<p>2 possible solutions are to </p>
<p>1) Use the Wordpress options table as described here... <a href="http://sabramedia.com/blog/how-to-add-cust... | [
{
"answer_id": 56761,
"author": "James",
"author_id": 8383,
"author_profile": "https://wordpress.stackexchange.com/users/8383",
"pm_score": 3,
"selected": true,
"text": "<p>Option 2 is the cleanest method - which I've also used a number of times. Unfortunately, there is no default term_m... | 2012/06/27 | [
"https://wordpress.stackexchange.com/questions/56760",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/2825/"
] | Saving extra fields that were added to a taxonomy. I want the most proper & efficient way of doing so. **Where should I save the new fields?**
2 possible solutions are to
1) Use the Wordpress options table as described here... [Add Custom Fields to Custom Taxonomies](http://sabramedia.com/blog/how-to-add-custom-fie... | Option 2 is the cleanest method - which I've also used a number of times. Unfortunately, there is no default term\_metadata table in WordPress yet. This post also covers the same approach, <http://shibashake.com/wordpress-theme/add-term-or-taxonomy-meta-data>
And of course, there's a plugin for that too :) <http://wor... |
56,769 | <p>It is possible to use this as a permalink for a post:</p>
<pre><code>/%category%/%postname%/
</code></pre>
<p>But lets say I've created a taxonomy called "artist". I'd like to use this for my posts:</p>
<pre><code>/%artist%/%postname%/
</code></pre>
<p>I know that taxonomies allow you to list their terms with th... | [
{
"answer_id": 56778,
"author": "Aleks",
"author_id": 17614,
"author_profile": "https://wordpress.stackexchange.com/users/17614",
"pm_score": 1,
"selected": false,
"text": "<p>I think this is what your looking for:\n<a href=\"https://wordpress.org/extend/plugins/custom-post-type-permalin... | 2012/06/28 | [
"https://wordpress.stackexchange.com/questions/56769",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17427/"
] | It is possible to use this as a permalink for a post:
```
/%category%/%postname%/
```
But lets say I've created a taxonomy called "artist". I'd like to use this for my posts:
```
/%artist%/%postname%/
```
I know that taxonomies allow you to list their terms with this:
```
/%artist%/%someartist%/
```
but that i... | Assuming your custom taxonomy is called `artist` (and you don't override the slug in the `rewrite` parameter) you can use the *rewrite tag* `%artist%`. WordPress implements almost every functionality to use those rewrite tags in post permalinks. There are only a few small adaptations necessary.
Building the Permalink
... |
56,775 | <p>I searched a lot of thread regarding my problem, but unfortunately I found nothing works, and this my final option. I want to add some custom fields on my comment form. How can I do that?</p>
| [
{
"answer_id": 56776,
"author": "Rutwick Gangurde",
"author_id": 4740,
"author_profile": "https://wordpress.stackexchange.com/users/4740",
"pm_score": 4,
"selected": true,
"text": "<p>Here you go: <a href=\"https://wordpress.stackexchange.com/questions/1353/adding-custom-fields-to-wordpr... | 2012/06/28 | [
"https://wordpress.stackexchange.com/questions/56775",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9583/"
] | I searched a lot of thread regarding my problem, but unfortunately I found nothing works, and this my final option. I want to add some custom fields on my comment form. How can I do that? | Here you go: [Adding Custom Fields to WordPress Comment Forms?](https://wordpress.stackexchange.com/questions/1353/adding-custom-fields-to-wordpress-comment-forms)
And another awesome post on this: <http://wpengineer.com/2214/adding-input-fields-to-the-comment-form/>
Functions are available to add/update, delete comm... |
56,779 | <p>I am building an add-on to an events module that checks for availability, since there wasn't a function for that in that module. Now that I have built the logic, there are three emails I will need to send:</p>
<ul>
<li><p>One if the post is being submitted for the first time (ie 'New appointment')</p></li>
<li><p>O... | [
{
"answer_id": 56861,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 5,
"selected": true,
"text": "<p><a href=\"https://wordpress.stackexchange.com/questions/55365/what-hooks-filters-are-there-to-alter-selected-terms-on-p... | 2012/06/28 | [
"https://wordpress.stackexchange.com/questions/56779",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17484/"
] | I am building an add-on to an events module that checks for availability, since there wasn't a function for that in that module. Now that I have built the logic, there are three emails I will need to send:
* One if the post is being submitted for the first time (ie 'New appointment')
* One if the post has been publish... | [Hook into `edit_post`](https://wordpress.stackexchange.com/questions/55365/what-hooks-filters-are-there-to-alter-selected-terms-on-post-save/55368#55368) to catch changes. And take a look at `wp_transition_post_status()` which is called on inserts and updates:
```
function wp_transition_post_status($new_status, $old_... |
56,784 | <p>Can someone please help me, I'm looking for a way to find the main parent product category of a WooCommerce product? Say, the product is marked under Gadgets, but the main parent of them all is Electronics.</p>
<p>I want this per post, as I want to add a class to each post signifying its main parent <code>product_c... | [
{
"answer_id": 56786,
"author": "Pontus Abrahamsson",
"author_id": 16722,
"author_profile": "https://wordpress.stackexchange.com/users/16722",
"pm_score": -1,
"selected": false,
"text": "<p>You can try this:</p>\n\n<pre><code><?php\n $term = get_term_by( 'slug', get_query_var( 'term'... | 2012/06/28 | [
"https://wordpress.stackexchange.com/questions/56784",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9744/"
] | Can someone please help me, I'm looking for a way to find the main parent product category of a WooCommerce product? Say, the product is marked under Gadgets, but the main parent of them all is Electronics.
I want this per post, as I want to add a class to each post signifying its main parent `product_cat`.
Please re... | I wrote my own function to go all the way up the "chain". My recursive might not be the best implementation you've seen, but it works.
```
function get_parent_terms($term) {
if ($term->parent > 0) {
$term = get_term_by("id", $term->parent, "product_cat");
if ($term->parent > 0) {
get_pa... |
56,794 | <p>Reading this great article <strong><a href="http://devotepress.com/coding/data-validation-sanitization-wordpress-1/" rel="nofollow">Data Validation and Sanitization in Wordpress</a></strong> I've noticed that in my blog, in header.php, I used <code><?php echo $title ?></code> in a pair of codes.</p>
<p>Accord... | [
{
"answer_id": 56795,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 2,
"selected": false,
"text": "<p>In the articles case, <code>$title</code> is an arbitrary value, as such it should be escaped via html, but, ... | 2012/06/28 | [
"https://wordpress.stackexchange.com/questions/56794",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17477/"
] | Reading this great article **[Data Validation and Sanitization in Wordpress](http://devotepress.com/coding/data-validation-sanitization-wordpress-1/)** I've noticed that in my blog, in header.php, I used `<?php echo $title ?>` in a pair of codes.
According to the above [article](http://devotepress.com/coding/data-vali... | In the articles case, `$title` is an arbitrary value, as such it should be escaped via html, but, if it was gotten from a WordPress core function it is probably safe, but you should check anyway
For example, `get_the_title()` can contain html markup and is not escaped by default.
Eitherway post and page titles should... |
56,805 | <p>I have front-end user form like,</p>
<ul>
<li>Title</li>
<li>Image Upload</li>
<li>Drop Down Category</li>
<li>Description</li>
<li>Tag</li>
</ul>
<p>Now when a user fills the form and hits the publish button from the front-end..... at the back-end a post is created with title and all the details, im able to creat... | [
{
"answer_id": 56806,
"author": "Pontus Abrahamsson",
"author_id": 16722,
"author_profile": "https://wordpress.stackexchange.com/users/16722",
"pm_score": 1,
"selected": false,
"text": "<p>Add this after save new post:</p>\n\n<pre><code>//Set the object terms after when we have the ID\nw... | 2012/06/28 | [
"https://wordpress.stackexchange.com/questions/56805",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14583/"
] | I have front-end user form like,
* Title
* Image Upload
* Drop Down Category
* Description
* Tag
Now when a user fills the form and hits the publish button from the front-end..... at the back-end a post is created with title and all the details, im able to create a post with post title and the description, but im una... | Also, how are you processing your image upload? That function only sets the enctype.
By adding the following beneath your call to `wp_insert_post` you will be able to process your image upload,
```
if (!function_exists('wp_generate_attachment_metadata')){
require_once(ABSPATH . "wp-admin" . '/includes/image.php')... |
56,832 | <p>I'm serving a different header in Wordpress depending what section you are within the site, 'residential' , 'business' or other by using the following code. Although i need to extend it to work with grandchildren as well, so another level down.</p>
<pre><code><?php
/*
Template Name: Package
*/
if (is_page('busi... | [
{
"answer_id": 56834,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 2,
"selected": false,
"text": "<p><a href=\"http://codex.wordpress.org/Function_Reference/get_ancestors\" rel=\"nofollow\"><code>get_ancestors()</cod... | 2012/06/28 | [
"https://wordpress.stackexchange.com/questions/56832",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17628/"
] | I'm serving a different header in Wordpress depending what section you are within the site, 'residential' , 'business' or other by using the following code. Although i need to extend it to work with grandchildren as well, so another level down.
```
<?php
/*
Template Name: Package
*/
if (is_page('business') || $post->... | [`get_ancestors()`](http://codex.wordpress.org/Function_Reference/get_ancestors) will return the full parent page ID hierarchy for a given page ID which you could check against. |
56,847 | <p>I'd like to have the first paragraph/sentence of my posts in their single.php page styled differently - say... bold.</p>
<p>How do I go about doing that in the most efficient way?</p>
| [
{
"answer_id": 56849,
"author": "HungryCoder",
"author_id": 17129,
"author_profile": "https://wordpress.stackexchange.com/users/17129",
"pm_score": 1,
"selected": false,
"text": "<p>Here is the idea</p>\n\n<pre><code>add_filter('the_content', 'testfunc');\n\nfunction custom_formatter($ma... | 2012/06/28 | [
"https://wordpress.stackexchange.com/questions/56847",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15943/"
] | I'd like to have the first paragraph/sentence of my posts in their single.php page styled differently - say... bold.
How do I go about doing that in the most efficient way? | In the end, this is the function that worked for me:
```
add_filter('the_content', 'first_line_bold');
function first_line_bold($content)
{
if (!is_page()) {
$pattern = "/<p.*?>([^`]*?)<\/p>/";
$match = "<span style=\"font-weight:bold;font-size:16px;\">$1</span>";
$content = preg_replace($pattern... |
56,852 | <p>Bulding off of <a href="https://wordpress.stackexchange.com/a/28521/9605">this</a> response from @kaiser about being able to filter by post types on a search page, I wanted to be able to automatically add-in all of the public post types available. So, after some help with @kaiser, I came up with:</p>
<pre><code>fun... | [
{
"answer_id": 57757,
"author": "Christian",
"author_id": 5437,
"author_profile": "https://wordpress.stackexchange.com/users/5437",
"pm_score": 0,
"selected": false,
"text": "<p>you wrote</p>\n\n<pre><code>if ( !is_search() && !in_array( get_post_type(), $post_types ) )\n retu... | 2012/06/28 | [
"https://wordpress.stackexchange.com/questions/56852",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9605/"
] | Bulding off of [this](https://wordpress.stackexchange.com/a/28521/9605) response from @kaiser about being able to filter by post types on a search page, I wanted to be able to automatically add-in all of the public post types available. So, after some help with @kaiser, I came up with:
```
function sw_custom_post_type... | To clear up some confusion in previous answers, pre\_get\_posts isn't a filter so you don't need to return anything.
Your only problem that I see is the if:
```php
if ( !is_search() && !in_array( get_post_type(), $post_types ) )
return;
```
Basically get\_post\_type() is going to return false during pre\_get\_p... |
56,865 | <p>I am trying to preview a NextGen gallery on my main page (and category pages) to show a single image from the gallery on the main page next to the text from the post that normally shows up. I have found examples of PHP that get the images from a gallery given a gallery ID. In my loop I have a current post. What I... | [
{
"answer_id": 56975,
"author": "Ian Lelsie",
"author_id": 17287,
"author_profile": "https://wordpress.stackexchange.com/users/17287",
"pm_score": 3,
"selected": true,
"text": "<p>I have found a solution. After a bunch of searching around I <a href=\"http://pastebin.com/rBeTjZRL\" rel=\... | 2012/06/28 | [
"https://wordpress.stackexchange.com/questions/56865",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17287/"
] | I am trying to preview a NextGen gallery on my main page (and category pages) to show a single image from the gallery on the main page next to the text from the post that normally shows up. I have found examples of PHP that get the images from a gallery given a gallery ID. In my loop I have a current post. What I canno... | I have found a solution. After a bunch of searching around I [found some code](http://pastebin.com/rBeTjZRL) that determines if a post has a specific short code in it.
That code also has some attempt to parse the parameters to the short code. Which is good because I want the gallery ID. There were some issues with the... |
56,874 | <p>How can I get an url-friendly version of the post_title? I´m using anchor links for my posts on an archive page, and for the moment the posts get the post_ID as a hash tag but I would like to get the title instead as it would look nicer.</p>
| [
{
"answer_id": 56882,
"author": "mrwweb",
"author_id": 9844,
"author_profile": "https://wordpress.stackexchange.com/users/9844",
"pm_score": 1,
"selected": false,
"text": "<p>PHP has a function for url encoding that would probably work:</p>\n\n<pre><code>urlencode( get_the_title() );\n</... | 2012/06/28 | [
"https://wordpress.stackexchange.com/questions/56874",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5079/"
] | How can I get an url-friendly version of the post\_title? I´m using anchor links for my posts on an archive page, and for the moment the posts get the post\_ID as a hash tag but I would like to get the title instead as it would look nicer. | PHP has a function for url encoding that would probably work:
```
urlencode( get_the_title() );
``` |
56,879 | <p>I got a tricky question. I have created a custom post type whose posts I would like to display in a scrolling carousel. The carousel will only display the title, the excerpt and a "read more" button. The "read more" button displays the full post in a FancyBox.</p>
<p>Here is my code so far:</p>
<pre><code><ul i... | [
{
"answer_id": 56901,
"author": "Evan Mattson",
"author_id": 12055,
"author_profile": "https://wordpress.stackexchange.com/users/12055",
"pm_score": 0,
"selected": false,
"text": "<p>If your fancybox content isn't what you want then the issue is most likely with your jquery or plugin usa... | 2012/06/28 | [
"https://wordpress.stackexchange.com/questions/56879",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4986/"
] | I got a tricky question. I have created a custom post type whose posts I would like to display in a scrolling carousel. The carousel will only display the title, the excerpt and a "read more" button. The "read more" button displays the full post in a FancyBox.
Here is my code so far:
```
<ul id="slider2">
<?php
$... | The issue is that you are declaring a same ID for every DIV in the LOOP. What you need is to do something like this:
```
<ul id="slider2">
<?php
$args = array( 'post_type' => 'jobs', 'posts_per_page' => 15 , 'order' => 'ASC' );
$loop = new WP_Query( $args ); $i = 0; ?>
<?php while ( $loop->have_posts()... |
56,883 | <p>I am trying to create links like the ones in the post tab (see image below).</p>
<p><img src="https://i.stack.imgur.com/H9fge.png" alt="enter image description here"></p>
<p>I created my <code>WP_List_table</code> but I am not sure how to create those links or how to get them to show a different db query.</p>
<p>... | [
{
"answer_id": 56938,
"author": "Stephen Harris",
"author_id": 9364,
"author_profile": "https://wordpress.stackexchange.com/users/9364",
"pm_score": 4,
"selected": false,
"text": "<p>As mentioned in the comments, if this is an existing table you wish to add/remove links from, <a href=\"h... | 2012/06/28 | [
"https://wordpress.stackexchange.com/questions/56883",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16500/"
] | I am trying to create links like the ones in the post tab (see image below).

I created my `WP_List_table` but I am not sure how to create those links or how to get them to show a different db query.
I know about the `extra_tablenav` function in the... | As mentioned in the comments, if this is an existing table you wish to add/remove links from, [see this answer](https://wordpress.stackexchange.com/questions/19418/how-to-add-a-quicklink-to-the-posts-admin-publishedscheduledtrash-menu/52075#52075).
If this a custom subclass of `WP_List_Table`, e.g.:
```
class Wpse568... |
56,884 | <p>I am currently hooking on <code>the_content()</code> but that goes through the Wordpress loop too. How can I only hook on the Single.php page?</p>
<p>Also, is there a way to only look on the first X posts in the Wordpress loop? </p>
<p>By the way, I am creating a plugin</p>
| [
{
"answer_id": 56887,
"author": "Pippin",
"author_id": 2418,
"author_profile": "https://wordpress.stackexchange.com/users/2418",
"pm_score": 5,
"selected": true,
"text": "<p>This will handle appending the content to single posts:</p>\n\n<pre><code>function yourprefix_add_to_content( $con... | 2012/06/28 | [
"https://wordpress.stackexchange.com/questions/56884",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5652/"
] | I am currently hooking on `the_content()` but that goes through the Wordpress loop too. How can I only hook on the Single.php page?
Also, is there a way to only look on the first X posts in the Wordpress loop?
By the way, I am creating a plugin | This will handle appending the content to single posts:
```
function yourprefix_add_to_content( $content ) {
if( is_single() ) {
$content .= 'Your new content here';
}
return $content;
}
add_filter( 'the_content', 'yourprefix_add_to_content' );
``` |
56,894 | <p>I've been trying to figure this out for a while now. So I'm trying to add a custom field call "counter" to every single post. I try simply inserting the field "counter" to the post table. Every time a user clicks a button on the post, it increments the counter So far so good.</p>
<p>But now the tricky part is being... | [
{
"answer_id": 56899,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 2,
"selected": false,
"text": "<p>Adding a column to the posts table is a bad idea, this is indeed what <a href=\"http://codex.wordpress.org/Custom_F... | 2012/06/29 | [
"https://wordpress.stackexchange.com/questions/56894",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17288/"
] | I've been trying to figure this out for a while now. So I'm trying to add a custom field call "counter" to every single post. I try simply inserting the field "counter" to the post table. Every time a user clicks a button on the post, it increments the counter So far so good.
But now the tricky part is being able to g... | Adding a column to the posts table is a bad idea, this is indeed what [Custom Fields (Post Meta)](http://codex.wordpress.org/Custom_Fields) are for. Query and sort your posts based on the values of your custom field with [WP\_Query](http://codex.wordpress.org/Class_Reference/WP_Query) and a [post meta (custom field) qu... |
56,898 | <p>Right now I have several images attached to my page, but I only want four of them to display in a slideshow, and then the other ones are referenced within the page's visual/html box. The problem is currently all my images attached to the page have a post type of "attachment", and this code iterates through all of t... | [
{
"answer_id": 56899,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 2,
"selected": false,
"text": "<p>Adding a column to the posts table is a bad idea, this is indeed what <a href=\"http://codex.wordpress.org/Custom_F... | 2012/06/29 | [
"https://wordpress.stackexchange.com/questions/56898",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/11033/"
] | Right now I have several images attached to my page, but I only want four of them to display in a slideshow, and then the other ones are referenced within the page's visual/html box. The problem is currently all my images attached to the page have a post type of "attachment", and this code iterates through all of them:... | Adding a column to the posts table is a bad idea, this is indeed what [Custom Fields (Post Meta)](http://codex.wordpress.org/Custom_Fields) are for. Query and sort your posts based on the values of your custom field with [WP\_Query](http://codex.wordpress.org/Class_Reference/WP_Query) and a [post meta (custom field) qu... |
56,909 | <p>when I create a gallery I get this code generated yet I can;t find out how</p>
<pre><code><img width="150" height="150" src="http://localhost/wp2/wp-content/uploads/2012/06/28_0120-150x150.jpg" class="attachment-thumbnail" alt="_28_0120" title="_28_0120">
</code></pre>
<p>What function generates the thumbnai... | [
{
"answer_id": 56911,
"author": "Pontus Abrahamsson",
"author_id": 16722,
"author_profile": "https://wordpress.stackexchange.com/users/16722",
"pm_score": 0,
"selected": false,
"text": "<p>In Wp-admin you can sett the size in Settings -> Media.</p>\n\n<p>If you want the url on the page y... | 2012/06/29 | [
"https://wordpress.stackexchange.com/questions/56909",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14982/"
] | when I create a gallery I get this code generated yet I can;t find out how
```
<img width="150" height="150" src="http://localhost/wp2/wp-content/uploads/2012/06/28_0120-150x150.jpg" class="attachment-thumbnail" alt="_28_0120" title="_28_0120">
```
What function generates the thumbnail URL and how does the thumbnail... | The thumbnail size is based on the dimensions defined in **WordPress Dashboard > Settings > Media**, unless your theme overrides it.
>
> how can I make my theme override it?
>
>
>
To change default post-thumbnail size, you need to use [`set_post_thumbnail_size`](http://codex.wordpress.org/Function_Reference/set_p... |
56,923 | <p>I have a post type and I want to sort posts in its archive according to two values:</p>
<ol>
<li>by a <strong>meta</strong> value called "artwork_year" which contains a 4 digit number (year)</li>
<li>by post <strong>publish date</strong></li>
</ol>
<p><em>what the query should do is:</em> first get the artwork_yea... | [
{
"answer_id": 56911,
"author": "Pontus Abrahamsson",
"author_id": 16722,
"author_profile": "https://wordpress.stackexchange.com/users/16722",
"pm_score": 0,
"selected": false,
"text": "<p>In Wp-admin you can sett the size in Settings -> Media.</p>\n\n<p>If you want the url on the page y... | 2012/06/29 | [
"https://wordpress.stackexchange.com/questions/56923",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8421/"
] | I have a post type and I want to sort posts in its archive according to two values:
1. by a **meta** value called "artwork\_year" which contains a 4 digit number (year)
2. by post **publish date**
*what the query should do is:* first get the artwork\_year and sort the posts accordingly (show first higher number... ie... | The thumbnail size is based on the dimensions defined in **WordPress Dashboard > Settings > Media**, unless your theme overrides it.
>
> how can I make my theme override it?
>
>
>
To change default post-thumbnail size, you need to use [`set_post_thumbnail_size`](http://codex.wordpress.org/Function_Reference/set_p... |
56,926 | <p>After searching several hours, I've decided to crowd-source this one. I have a client who uses Wordpress very frequently, they often have to create a link to a certain page for collecting donations - the issue is they always get the link wrong (long story, but they always screw it up!). I've been searching for a p... | [
{
"answer_id": 56932,
"author": "Pontus Abrahamsson",
"author_id": 16722,
"author_profile": "https://wordpress.stackexchange.com/users/16722",
"pm_score": 3,
"selected": true,
"text": "<p>You can make a button to the Tinymce editor that adds a pre defined link like this youtube button:</... | 2012/06/29 | [
"https://wordpress.stackexchange.com/questions/56926",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17654/"
] | After searching several hours, I've decided to crowd-source this one. I have a client who uses Wordpress very frequently, they often have to create a link to a certain page for collecting donations - the issue is they always get the link wrong (long story, but they always screw it up!). I've been searching for a plugin... | You can make a button to the Tinymce editor that adds a pre defined link like this youtube button:

Put this in your functions.php theme file:
```
// Hook into WordPress
add_action('init', 'mylink_button');
// Create Our Initialization Function
fun... |
56,944 | <p>Lets say on my WordPress website I navigate to:</p>
<blockquote>
<p>www.example.com/media-centre/news/17/an-example-news-post</p>
</blockquote>
<p>In this case I am looking at a post in a CPT called <code>News</code>.</p>
<p>What I want to do is get the page ID thats closest to that URL. I know the closest page... | [
{
"answer_id": 56947,
"author": "Stephen Harris",
"author_id": 9364,
"author_profile": "https://wordpress.stackexchange.com/users/9364",
"pm_score": 2,
"selected": false,
"text": "<p>You should be able to get the current url from <code>$url = add_query_arg()</code>.</p>\n\n<p>Then assumi... | 2012/06/29 | [
"https://wordpress.stackexchange.com/questions/56944",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4610/"
] | Lets say on my WordPress website I navigate to:
>
> www.example.com/media-centre/news/17/an-example-news-post
>
>
>
In this case I am looking at a post in a CPT called `News`.
What I want to do is get the page ID thats closest to that URL. I know the closest page ID can be found at:
>
> www.example.com/media-c... | Got there myself with the aid from Stephen Harris and some PHP help over at SO.
```
$page = get_closest_page();
// echo $page->ID;
function get_closest_page( $url = false )
{
global $wp;
if( ! $url )
$url = $wp->request;
$page = get_page_by_path( $url );
if( $page )
return $page;
... |
56,965 | <p>I've got WP site on a self-hosted server. Any files I create are owned by me/me and any files created by WP are owned by apache/apache. I've created a group, wp, that both me and apache are members of and that works ok. But how can I set this up so when either me or apache creates or edits a file or directory that i... | [
{
"answer_id": 56967,
"author": "AlxVallejo",
"author_id": 10099,
"author_profile": "https://wordpress.stackexchange.com/users/10099",
"pm_score": 0,
"selected": false,
"text": "<p>By default, a new file will inherit the permissions of it's parent directory.</p>\n\n<p>You need to enter t... | 2012/06/29 | [
"https://wordpress.stackexchange.com/questions/56965",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15555/"
] | I've got WP site on a self-hosted server. Any files I create are owned by me/me and any files created by WP are owned by apache/apache. I've created a group, wp, that both me and apache are members of and that works ok. But how can I set this up so when either me or apache creates or edits a file or directory that it g... | You may as I have found need to change the group that apache runs under. In ubuntu you can do this by editing the `/etc/apache2/envvars` file.
The above answer by AlxVallejo is mostly correct but this (Tom's) is a better answer with regards to setting permissions
<https://serverfault.com/questions/6895/whats-the-best... |
56,966 | <p>I am using the following code to output a list of items in my 'documents' Custom Post type by Year and Month.</p>
<pre><code><ul>
<?php
$post_type = 'documents';
global $wpdb;
/**/
$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type =... | [
{
"answer_id": 56973,
"author": "SickHippie",
"author_id": 5434,
"author_profile": "https://wordpress.stackexchange.com/users/5434",
"pm_score": 0,
"selected": false,
"text": "<p>Don't use <code>$wpdb</code>, use <code>wp_query</code>. Not only will your code be leaner and quicker, you'... | 2012/06/29 | [
"https://wordpress.stackexchange.com/questions/56966",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16192/"
] | I am using the following code to output a list of items in my 'documents' Custom Post type by Year and Month.
```
<ul>
<?php
$post_type = 'documents';
global $wpdb;
/**/
$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = '".$post_type."' ORDER BY po... | Thanks SickHippie.
This is what I ended up with:
```
<?php $args = array(
'posts_per_page' => -1,
'post_type' => 'documents',
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'download-category',
'field' => 'slug',
... |
56,968 | <p>I've recently been forced to edit the core files of a plugin. I've updated the title of said plugin to indicate that its been edited.</p>
<p>My question is will the plugin still get update notifications? If so, I'll likely disable the updates for this plugin, to prevent someone forgetting about my updates and overw... | [
{
"answer_id": 56972,
"author": "SickHippie",
"author_id": 5434,
"author_profile": "https://wordpress.stackexchange.com/users/5434",
"pm_score": 2,
"selected": false,
"text": "<p>You can't disable updates but not update notifications - they're tied together.</p>\n\n<p>To disable notifica... | 2012/06/29 | [
"https://wordpress.stackexchange.com/questions/56968",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5846/"
] | I've recently been forced to edit the core files of a plugin. I've updated the title of said plugin to indicate that its been edited.
My question is will the plugin still get update notifications? If so, I'll likely disable the updates for this plugin, to prevent someone forgetting about my updates and overwriting.
I... | As SickHippie says and AFAIK, you can't have both. I'm adding an answer with the info I collected in this Stack.
---
### [Disable update notification for individual plugins](https://wordpress.stackexchange.com/q/20580/12615)
Bainternet in a Comment:
>
> Simply open up the plugin file and change the version number ... |
57,003 | <p>I had some problem with WP recognizing a is_single condition for loading scripts called in function.php.</p>
<p>I put a error_log(is_single()) to check what was going on.</p>
<p>When opening a post page the log showed me that log function has been called and the is_sigle() tag was positive the first time and negat... | [
{
"answer_id": 57031,
"author": "mrwweb",
"author_id": 9844,
"author_profile": "https://wordpress.stackexchange.com/users/9844",
"pm_score": -1,
"selected": false,
"text": "<p>I suspect that your function isn't being run at all, at least in the way you intend.</p>\n\n<p>As per the codex:... | 2012/06/30 | [
"https://wordpress.stackexchange.com/questions/57003",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10100/"
] | I had some problem with WP recognizing a is\_single condition for loading scripts called in function.php.
I put a error\_log(is\_single()) to check what was going on.
When opening a post page the log showed me that log function has been called and the is\_sigle() tag was positive the first time and negative the secon... | I had this same issue. I logged the request URI and discovered that the additional call was for a file that didn't exist (that's what I get for copying and pasting a bunch of code from one project to another). I created a file at the expected name and location, and the additional call to my wp\_enqueue\_scripts hook fu... |
57,011 | <p>I'm using the following code to generate tags</p>
<pre><code><?php if( has_tag() ): ?>
<?php echo '<div id="tagWrapper">'?><p>Tags</p><?php the_tags('<ul class="tags"><li class="tag-body olive">','</li><li>','</li></ul>'); ?><?php echo '<... | [
{
"answer_id": 57018,
"author": "its_me",
"author_id": 10691,
"author_profile": "https://wordpress.stackexchange.com/users/10691",
"pm_score": 3,
"selected": true,
"text": "<p>The function <a href=\"http://codex.wordpress.org/Function_Reference/get_the_tags\" rel=\"nofollow\"><code>get_t... | 2012/06/30 | [
"https://wordpress.stackexchange.com/questions/57011",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10413/"
] | I'm using the following code to generate tags
```
<?php if( has_tag() ): ?>
<?php echo '<div id="tagWrapper">'?><p>Tags</p><?php the_tags('<ul class="tags"><li class="tag-body olive">','</li><li>','</li></ul>'); ?><?php echo '</div>' ?>
<?php endif; ?>
```
It's output is an unordered list with simple `<a>` links. I ... | The function [`get_the_tags();`](http://codex.wordpress.org/Function_Reference/get_the_tags) is probably what you are looking for. The following code displays a list of tags with links to each one and a specific class for each tag:
```
<?php
$tags = get_the_tags();
$html = '<div class="post_tags">';
foreac... |
57,014 | <p>I've been using Wordpress for a while, and came to a point where I need to make css customizations, but only for a certain page. I know that one way to do this is to use conditional tags:</p>
<p><code>if ( is_page( 'mypage' )</code></p>
<p>And that's where I get stuck!</p>
<p>Are there any other ways of making cs... | [
{
"answer_id": 57017,
"author": "its_me",
"author_id": 10691,
"author_profile": "https://wordpress.stackexchange.com/users/10691",
"pm_score": 2,
"selected": false,
"text": "<p>You'd need something like this (to be added in functions.php):</p>\n\n<pre><code>add_action('wp_enqueue_scripts... | 2012/06/30 | [
"https://wordpress.stackexchange.com/questions/57014",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16262/"
] | I've been using Wordpress for a while, and came to a point where I need to make css customizations, but only for a certain page. I know that one way to do this is to use conditional tags:
`if ( is_page( 'mypage' )`
And that's where I get stuck!
Are there any other ways of making css customizations, only for a certai... | You'd need something like this (to be added in functions.php):
```
add_action('wp_enqueue_scripts','wpse57014_register_script');
function wpse57014_register_script(){
//Register and enqueue stylesheet only on this page
if ( is_page( 'mypage' ) ) {
wp_register_style( 'wpse57014_mypage_stylesheet', get_... |
57,038 | <p>I would like to be able to conditionally hide the author's name on the Single.php if the Category name is equal to "News" and otherwise if the category is something else hide it. How do I go about doing this? The code I have below does not seem to work:</p>
<pre><code> <!-- header.php -->
&... | [
{
"answer_id": 57017,
"author": "its_me",
"author_id": 10691,
"author_profile": "https://wordpress.stackexchange.com/users/10691",
"pm_score": 2,
"selected": false,
"text": "<p>You'd need something like this (to be added in functions.php):</p>\n\n<pre><code>add_action('wp_enqueue_scripts... | 2012/06/30 | [
"https://wordpress.stackexchange.com/questions/57038",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17193/"
] | I would like to be able to conditionally hide the author's name on the Single.php if the Category name is equal to "News" and otherwise if the category is something else hide it. How do I go about doing this? The code I have below does not seem to work:
```
<!-- header.php -->
<?php get_header(); ?... | You'd need something like this (to be added in functions.php):
```
add_action('wp_enqueue_scripts','wpse57014_register_script');
function wpse57014_register_script(){
//Register and enqueue stylesheet only on this page
if ( is_page( 'mypage' ) ) {
wp_register_style( 'wpse57014_mypage_stylesheet', get_... |
57,043 | <p>I have a basic plugin in the admin options panel for events.</p>
<p>I want to call a function that is from a different social media plugin (<a href="https://wordpress.org/plugins/mingle/" rel="noreferrer">Mingle</a>). I can call the plugin functions in the theme, but not within core files of other plugins, or other... | [
{
"answer_id": 236430,
"author": "Ethan O'Sullivan",
"author_id": 98212,
"author_profile": "https://wordpress.stackexchange.com/users/98212",
"pm_score": 2,
"selected": false,
"text": "<p>To call one function from one plugin in another plugin (inception?), you can try the following login... | 2012/06/30 | [
"https://wordpress.stackexchange.com/questions/57043",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17692/"
] | I have a basic plugin in the admin options panel for events.
I want to call a function that is from a different social media plugin ([Mingle](https://wordpress.org/plugins/mingle/)). I can call the plugin functions in the theme, but not within core files of other plugins, or other plugins' admin panels it seems.
I h... | Maybe you should try calling the functions of your plugin using the `plugins_loaded` action.
Plugin A
--------
```
class PluginA {
public function func_a() {
// do stuff
}
}
```
Plugin B
--------
```
class PluginB {
function functB() {
if (class_exists('PluginA')) {
//do stuff that depends of P... |
57,054 | <p>Seems logical for any other network, not for buddypress though :(</p>
<p>We all know the extended user profiles in buddypress - problem is, even though some fields are marked as required, that "required" seems to have no real significance for buddypress developers. So we have some "required" fields, which nobody EV... | [
{
"answer_id": 57056,
"author": "Tyler Carter",
"author_id": 16921,
"author_profile": "https://wordpress.stackexchange.com/users/16921",
"pm_score": 1,
"selected": false,
"text": "<p>Sounds like you should instead be putting these fields in the registration page, so that they don't even ... | 2012/06/30 | [
"https://wordpress.stackexchange.com/questions/57054",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17695/"
] | Seems logical for any other network, not for buddypress though :(
We all know the extended user profiles in buddypress - problem is, even though some fields are marked as required, that "required" seems to have no real significance for buddypress developers. So we have some "required" fields, which nobody EVER asks th... | Use `wp_redirect()` and `admin_url()` to redirect the user to his profile page if the custom buddypress user meta data isn't completely filled.
From another answer, I've seen that there's the following function: `bp_get_profile_field_data()`. So you can easily build a template tag, that gives you either the full buddy... |
57,060 | <p>I've read through a lot of code snippets now and it seems like wether I'm to stupid or there is no solution for this.</p>
<p>I have a setup where some information for a product is loaded via amazon API if I enter the ASIN code in a meta box when creating a post. When I save the post, the Amazon product image is aut... | [
{
"answer_id": 57063,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 0,
"selected": false,
"text": "<p>I'm not familiar with the Amazon API, but if you're handy with a bit of php you could make this happen.</p>\n\n<p>T... | 2012/07/01 | [
"https://wordpress.stackexchange.com/questions/57060",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17257/"
] | I've read through a lot of code snippets now and it seems like wether I'm to stupid or there is no solution for this.
I have a setup where some information for a product is loaded via amazon API if I enter the ASIN code in a meta box when creating a post. When I save the post, the Amazon product image is automatically... | I recently released a plugin that imports any external images found in a post and imports them into the media library, attaches them to the post and sets the first image found as the featured image.
<http://wordpress.org/extend/plugins/media-tools/>
I'm posting the basic function that gets the external image and sets... |
57,065 | <p>I'm trying to show the most popular (recent) posts on my blog. I have made a special formula for this. I am querying for these posts like so:</p>
<pre><code>$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'meta_key' => '_post_popularity',
'meta_query' => array(
array(
... | [
{
"answer_id": 57067,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 2,
"selected": true,
"text": "<p>As you've discovered, meta queries only work with the post meta table, it is indeed looking for a meta key of <code>... | 2012/07/01 | [
"https://wordpress.stackexchange.com/questions/57065",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17427/"
] | I'm trying to show the most popular (recent) posts on my blog. I have made a special formula for this. I am querying for these posts like so:
```
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'meta_key' => '_post_popularity',
'meta_query' => array(
array(
'key' => 'post_date... | As you've discovered, meta queries only work with the post meta table, it is indeed looking for a meta key of `post_date`.
You can't do timespan queries with a simple query, but we can accomplish this with a combination of a query for the meta key, and a `posts_where` filter directly on the SQL to get the time span.
... |
57,070 | <p>Simple question. When pagination is activated, the URL changes to <code>"site.com/page/2"</code>. For my site, this should be <code>"site.com/paggetto/2"</code>. </p>
<p>How can I change that rewrite rule? I also want to change <code>"author"</code> and other variables.</p>
| [
{
"answer_id": 57073,
"author": "DarkGhostHunter",
"author_id": 16135,
"author_profile": "https://wordpress.stackexchange.com/users/16135",
"pm_score": 5,
"selected": false,
"text": "<p>Figured out:</p>\n\n<pre><code>function re_rewrite_rules() {\n global $wp_rewrite;\n // $wp_rewr... | 2012/07/01 | [
"https://wordpress.stackexchange.com/questions/57070",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16135/"
] | Simple question. When pagination is activated, the URL changes to `"site.com/page/2"`. For my site, this should be `"site.com/paggetto/2"`.
How can I change that rewrite rule? I also want to change `"author"` and other variables. | For some sites in German I use the following plugin to translate `page` to `seite` (the German word for `page`):
```
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: T5 Page to Seite
* Description: Ersetzt <code>/page/</code> durch <code>/seite/</code>.
* Author: Fuxia Scholz
* License: MIT
* License URI... |
57,072 | <p>As of wordpress 3.4 we're supposed to use wp_get_theme to return theme data. </p>
<pre><code>$theme = wp_get_theme();
//var_dump($theme);
echo $theme->Author;
</code></pre>
<p>despite the var_dump indicating the correct string, $theme->Author always returns a hyperlink with the author's name, but linked to t... | [
{
"answer_id": 57078,
"author": "Ruturaj",
"author_id": 13540,
"author_profile": "https://wordpress.stackexchange.com/users/13540",
"pm_score": 0,
"selected": false,
"text": "<p>Yes, you're right. I could reproduce the issue on my Wordpress 3.4.1 installation. Not sure if this is a bug; ... | 2012/07/01 | [
"https://wordpress.stackexchange.com/questions/57072",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/6477/"
] | As of wordpress 3.4 we're supposed to use wp\_get\_theme to return theme data.
```
$theme = wp_get_theme();
//var_dump($theme);
echo $theme->Author;
```
despite the var\_dump indicating the correct string, $theme->Author always returns a hyperlink with the author's name, but linked to the author's site. how can i... | Do not use just the header string, call `display()` instead and set the second parameter to `FALSE` to suppress markup.
```
// FALSE for no markup
$theme->display( 'Author', FALSE );
```
What you see in your `var_dump()` are *private* properties. If you print `$theme->Author` the magic [`__get()`](http://php.net/__g... |
57,079 | <p>In my <code>functions.php</code> file I would like to remove the below filter, but I'm not sure how to do it since it's in a class. What should <code>remove_filter()</code> look like?</p>
<pre><code>add_filter('comments_array',array( $this, 'FbComments' ));
</code></pre>
<p>It's on line 88 <a href="http://plugins.tr... | [
{
"answer_id": 57086,
"author": "2hamed",
"author_id": 7410,
"author_profile": "https://wordpress.stackexchange.com/users/7410",
"pm_score": 0,
"selected": false,
"text": "<p>I'm not sure but you can try using a singleton.<br />\nYou must store the object reference in a static property o... | 2012/07/01 | [
"https://wordpress.stackexchange.com/questions/57079",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17701/"
] | In my `functions.php` file I would like to remove the below filter, but I'm not sure how to do it since it's in a class. What should `remove_filter()` look like?
```
add_filter('comments_array',array( $this, 'FbComments' ));
```
It's on line 88 [here](http://plugins.trac.wordpress.org/browser/seo-facebook-comments/t... | That’s a very good question. It goes down to the dark heart of the plugin API and best programming practices.
For the following answer I created a simple plugin to illustrate the problem with easy to read code.
```
<?php # -*- coding: utf-8 -*-
/* Plugin Name: Anonymous OOP Action */
if ( ! class_exists( 'Anonymous_... |
57,092 | <p>Right in my main plugin file, wp-email-capture.php I am calling this:-</p>
<pre><code>add_action( 'admin_init', 'wp_email_capture_add_custom_boxes');
</code></pre>
<p>This calls this function:-</p>
<pre><code>function wp_email_capture_add_custom_boxes()
{
add_meta_box("wp_email_capture_admin_supportbox", _... | [
{
"answer_id": 57086,
"author": "2hamed",
"author_id": 7410,
"author_profile": "https://wordpress.stackexchange.com/users/7410",
"pm_score": 0,
"selected": false,
"text": "<p>I'm not sure but you can try using a singleton.<br />\nYou must store the object reference in a static property o... | 2012/07/01 | [
"https://wordpress.stackexchange.com/questions/57092",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9918/"
] | Right in my main plugin file, wp-email-capture.php I am calling this:-
```
add_action( 'admin_init', 'wp_email_capture_add_custom_boxes');
```
This calls this function:-
```
function wp_email_capture_add_custom_boxes()
{
add_meta_box("wp_email_capture_admin_supportbox", __('Support', 'WPEC'), "wp_email_captu... | That’s a very good question. It goes down to the dark heart of the plugin API and best programming practices.
For the following answer I created a simple plugin to illustrate the problem with easy to read code.
```
<?php # -*- coding: utf-8 -*-
/* Plugin Name: Anonymous OOP Action */
if ( ! class_exists( 'Anonymous_... |
57,109 | <p>We have ten blogs running on a little EC2 instances, we want to see if all the blogs can share the same wordpress php code so</p>
<ol>
<li>When I update the Wordpress, all the blogs get updated</li>
<li>Save memory in Apache/mod_php as no duplicated scripts or bytecode in the cache (in case of APC).</li>
</ol>
<p>... | [
{
"answer_id": 57553,
"author": "SickHippie",
"author_id": 5434,
"author_profile": "https://wordpress.stackexchange.com/users/5434",
"pm_score": 0,
"selected": false,
"text": "<p>There's a couple things that don't make sense in your basic premise. First off, if you have ten blogs in sep... | 2012/07/01 | [
"https://wordpress.stackexchange.com/questions/57109",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16037/"
] | We have ten blogs running on a little EC2 instances, we want to see if all the blogs can share the same wordpress php code so
1. When I update the Wordpress, all the blogs get updated
2. Save memory in Apache/mod\_php as no duplicated scripts or bytecode in the cache (in case of APC).
We cant use MU as we need all th... | Assuming all the installs are on the same instance and thus can have the same files shared between them, then the main thing you need to do is to have all the custom content stuff live outside of the main WordPress folders.
So first, you're going to want a fresh copy of WordPress somewhere, untouched (and untouchable,... |
57,122 | <p>I'm trying to create a custom page 2 template that's different from the main index.php. For example, the main index page would display the latest news + a lot of features like a magazine. When readers click to read on to page 2, 3, 4 etc of the news posts, they are taken to a more regular news page. Kinda like somet... | [
{
"answer_id": 57553,
"author": "SickHippie",
"author_id": 5434,
"author_profile": "https://wordpress.stackexchange.com/users/5434",
"pm_score": 0,
"selected": false,
"text": "<p>There's a couple things that don't make sense in your basic premise. First off, if you have ten blogs in sep... | 2012/07/01 | [
"https://wordpress.stackexchange.com/questions/57122",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17710/"
] | I'm trying to create a custom page 2 template that's different from the main index.php. For example, the main index page would display the latest news + a lot of features like a magazine. When readers click to read on to page 2, 3, 4 etc of the news posts, they are taken to a more regular news page. Kinda like somethin... | Assuming all the installs are on the same instance and thus can have the same files shared between them, then the main thing you need to do is to have all the custom content stuff live outside of the main WordPress folders.
So first, you're going to want a fresh copy of WordPress somewhere, untouched (and untouchable,... |
57,141 | <p>I would like to create a condition that checks to see if a post has a thumbail and if it does display it, otherwise display the first image in a post.</p>
<p>I tried something like this in my loop.php but it didn't seem to work:</p>
<pre><code><?php if (has_post_thumbnail()) { ?>
<a href="<?php the_per... | [
{
"answer_id": 57143,
"author": "its_me",
"author_id": 10691,
"author_profile": "https://wordpress.stackexchange.com/users/10691",
"pm_score": 2,
"selected": false,
"text": "<p><a href=\"http://wordpress.org/extend/plugins/get-the-image/\" rel=\"nofollow\">Get the Image</a> does what you... | 2012/07/02 | [
"https://wordpress.stackexchange.com/questions/57141",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17193/"
] | I would like to create a condition that checks to see if a post has a thumbail and if it does display it, otherwise display the first image in a post.
I tried something like this in my loop.php but it didn't seem to work:
```
<?php if (has_post_thumbnail()) { ?>
<a href="<?php the_permalink(); ?>"><?php the_post_thum... | [Get the Image](http://wordpress.org/extend/plugins/get-the-image/) does what you need and better. It's NOT overwhelming with lots of unnecessary features, and does what it says. Try it to see if it does what you need.
>
> **How does Get the Image plugin pull images?**
>
>
> * Looks for an image by custom field (on... |
57,144 | <p>I have a page called 'home' which is set to be the front of my site, but I'd like it to show the most recent blog post or two at the bottom. I have some PHP that will do this from another site</p>
<pre><code><?php
query_posts('showposts=1');
while (have_posts()): the_post(); ?>
<h2><a href="<?ph... | [
{
"answer_id": 57143,
"author": "its_me",
"author_id": 10691,
"author_profile": "https://wordpress.stackexchange.com/users/10691",
"pm_score": 2,
"selected": false,
"text": "<p><a href=\"http://wordpress.org/extend/plugins/get-the-image/\" rel=\"nofollow\">Get the Image</a> does what you... | 2012/07/02 | [
"https://wordpress.stackexchange.com/questions/57144",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8325/"
] | I have a page called 'home' which is set to be the front of my site, but I'd like it to show the most recent blog post or two at the bottom. I have some PHP that will do this from another site
```
<?php
query_posts('showposts=1');
while (have_posts()): the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_... | [Get the Image](http://wordpress.org/extend/plugins/get-the-image/) does what you need and better. It's NOT overwhelming with lots of unnecessary features, and does what it says. Try it to see if it does what you need.
>
> **How does Get the Image plugin pull images?**
>
>
> * Looks for an image by custom field (on... |
57,155 | <p>How can I create a customizable widget with random posts from my blog that can be published on another site as js, iframe or div.
Is there any Wordpress plugin for that?</p>
| [
{
"answer_id": 57158,
"author": "Ruturaj",
"author_id": 13540,
"author_profile": "https://wordpress.stackexchange.com/users/13540",
"pm_score": 0,
"selected": false,
"text": "<p>I think in essence what you're talking about is a Custom Widget that will parse and display RSS Feed of your B... | 2012/07/02 | [
"https://wordpress.stackexchange.com/questions/57155",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17722/"
] | How can I create a customizable widget with random posts from my blog that can be published on another site as js, iframe or div.
Is there any Wordpress plugin for that? | To create a special output of random posts:
1. [Register an endpoint](http://codex.wordpress.org/Rewrite_API/add_rewrite_endpoint) to the root of your blog. See [A (Mostly) Complete Guide to the WordPress Rewrite API](http://pmg.co/a-mostly-complete-guide-to-the-wordpress-rewrite-api) for details.
2. Refresh the perma... |
57,160 | <p>I´m trying to set up a local development environment for me to work on a Wordpress multisite that I´m building. I use Mamp Pro with default ports (Apache: 80, MySQL: 3306), and I also added a new host with the same domain name as the page will have when going live. So, now when I go to <a href="http://mylivedomain.c... | [
{
"answer_id": 57162,
"author": "Pontus Abrahamsson",
"author_id": 16722,
"author_profile": "https://wordpress.stackexchange.com/users/16722",
"pm_score": 1,
"selected": false,
"text": "<p>Can you update your .htaccess file manually, Copy the settings from from Network Setup and then ope... | 2012/07/02 | [
"https://wordpress.stackexchange.com/questions/57160",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5079/"
] | I´m trying to set up a local development environment for me to work on a Wordpress multisite that I´m building. I use Mamp Pro with default ports (Apache: 80, MySQL: 3306), and I also added a new host with the same domain name as the page will have when going live. So, now when I go to <http://mylivedomain.com> I get t... | Appart of the default ports and correctly configuring WPMS...
In the Advanced Tab:

And manually add the subdomains in `/etc/hosts`1 file:
```
# BRASOFILO MULTISITE START
127.0.0.1 test1.brasofilo.dev
127.0.0.1 test2.brasofilo.dev
127.0.0.1 cloned.brasofilo.dev
# ... |
57,171 | <p>I want to create font size and background change buttons, which i know how to do it. The problem is with remember it, so if user will go to a different page, background and font will stay the same. How can i do it?</p>
<p>I was thinking about saving this in cookies. What do you think about that?</p>
<p>Is anyone c... | [
{
"answer_id": 57173,
"author": "Pontus Abrahamsson",
"author_id": 16722,
"author_profile": "https://wordpress.stackexchange.com/users/16722",
"pm_score": 0,
"selected": false,
"text": "<p>You can use this plugin for the font: <a href=\"http://wordpress.org/extend/plugins/font-resizer/\"... | 2012/07/02 | [
"https://wordpress.stackexchange.com/questions/57171",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17056/"
] | I want to create font size and background change buttons, which i know how to do it. The problem is with remember it, so if user will go to a different page, background and font will stay the same. How can i do it?
I was thinking about saving this in cookies. What do you think about that?
Is anyone can write an examp... | Here is how you can sett a cookie whit a variable:
Now it saves for one day.
```
$settings = $mybackground;
setcookie('background',$settings,time() + (86400)); // 86400 = 1 day
```
Print it in the body like an img whit this:
```
echo $_COOKIE['background'];
``` |