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 |
|---|---|---|---|---|---|---|
73,202 | <p>Im currently trying to integrate a superfish menu into my wordpress theme, however it seems to be disappearing. I believe i have coded the js and the css correctly... can someone give me a pointer as to whats up? Or how to integrate into the functions.php</p>
<p><em><strong>FURTHER UPDATE</em>*</strong></p>
<p>Ok.... | [
{
"answer_id": 73194,
"author": "kaiser",
"author_id": 385,
"author_profile": "https://wordpress.stackexchange.com/users/385",
"pm_score": 6,
"selected": true,
"text": "<h1>Understanding the internals</h1>\n\n<p>The \"sort\" order of adjacent (next/prev) posts is not really a sort \"orde... | 2012/11/19 | [
"https://wordpress.stackexchange.com/questions/73202",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23834/"
] | Im currently trying to integrate a superfish menu into my wordpress theme, however it seems to be disappearing. I believe i have coded the js and the css correctly... can someone give me a pointer as to whats up? Or how to integrate into the functions.php
***FURTHER UPDATE***\*
Ok.... so i put the functions back into... | Understanding the internals
===========================
The "sort" order of adjacent (next/prev) posts is not really a sort "order". It's a separate query on each request/page, **but** it sorts the query by the `post_date` - or the post parent if you have a hierarchical post as currently displayed object.
When you ta... |
73,210 | <p>For organisation, I'm trying to split up the functions.php file into separate files. In particular the functions for shortcodes in a separate file, with the shortcodes being defined in functions.php. Here's the code in the functions.php:-</p>
<pre><code>locate_template( array( 'inc/shortcode-functions.php' ), true,... | [
{
"answer_id": 73211,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 1,
"selected": false,
"text": "<p>The <code>locate_template()</code> function is intended to be used to locate/include <em>template</em> file... | 2012/11/19 | [
"https://wordpress.stackexchange.com/questions/73210",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9918/"
] | For organisation, I'm trying to split up the functions.php file into separate files. In particular the functions for shortcodes in a separate file, with the shortcodes being defined in functions.php. Here's the code in the functions.php:-
```
locate_template( array( 'inc/shortcode-functions.php' ), true, true );
add_... | The `locate_template()` function is intended to be used to locate/include *template* files, not *functional* files.
Just use `include()` and/or `require()` to include functional files in `functions.php`. |
73,238 | <p><strong>The Problem:</strong></p>
<p>I am currently in the finishing stages of a premium theme I've been developing and all is mostly well. For pages I have a few custom meta boxes for adding in slideshows and other additional pieces of page content and have found that the editing screen is now pretty long.</p>
<p... | [
{
"answer_id": 73242,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 1,
"selected": false,
"text": "<p>You can probably do this with some CSS. Here's a quick hack job via the webkit inspector:</p>\n\n<pre><code>#side-s... | 2012/11/20 | [
"https://wordpress.stackexchange.com/questions/73238",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1687/"
] | **The Problem:**
I am currently in the finishing stages of a premium theme I've been developing and all is mostly well. For pages I have a few custom meta boxes for adding in slideshows and other additional pieces of page content and have found that the editing screen is now pretty long.
Due to the large vertical hei... | Solution based in [this StackOverflow Q&A](https://stackoverflow.com/q/6691558/1287812).
Well, more a proof of concept than anything... Style and scripts being printed the lazy way.
Add a fixed `Scroll to top` div linked to an anchor near the `Publish` button.
```
add_action( 'admin_head-post.php', 'scroll_to_top'... |
73,257 | <p>I'm updating my wordpress plugin to use a custom TinyMCE button. From inside the TinyMCE button javascript, I'd like to interact with wordpress data--ie set custom post options inside the plugin setting page, then access those values inside the TinyMCE js script.</p>
<p>Can I invoke my php plugin functions from ins... | [
{
"answer_id": 73242,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 1,
"selected": false,
"text": "<p>You can probably do this with some CSS. Here's a quick hack job via the webkit inspector:</p>\n\n<pre><code>#side-s... | 2012/11/20 | [
"https://wordpress.stackexchange.com/questions/73257",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23861/"
] | I'm updating my wordpress plugin to use a custom TinyMCE button. From inside the TinyMCE button javascript, I'd like to interact with wordpress data--ie set custom post options inside the plugin setting page, then access those values inside the TinyMCE js script.
Can I invoke my php plugin functions from inside the Ti... | Solution based in [this StackOverflow Q&A](https://stackoverflow.com/q/6691558/1287812).
Well, more a proof of concept than anything... Style and scripts being printed the lazy way.
Add a fixed `Scroll to top` div linked to an anchor near the `Publish` button.
```
add_action( 'admin_head-post.php', 'scroll_to_top'... |
73,305 | <p>I am using the WordPress API to get the user login. My code:</p>
<pre><code><?php
define('WP_USE_THEMES', false);
require('wp-blog-header.php');
$creds = array();
$creds['user_login'] = 'user';
$creds['user_password'] = 'password';
$creds['remember'] = true;
$user = wp_signon( $creds, false);
if ( is_wp_error($... | [
{
"answer_id": 73954,
"author": "Murat",
"author_id": 23879,
"author_profile": "https://wordpress.stackexchange.com/users/23879",
"pm_score": 2,
"selected": false,
"text": "<p>I solved the problem. Here's the solution.</p>\n\n<p>Add this line to your wp-config.php :</p>\n\n<pre><code>def... | 2012/11/20 | [
"https://wordpress.stackexchange.com/questions/73305",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23879/"
] | I am using the WordPress API to get the user login. My code:
```
<?php
define('WP_USE_THEMES', false);
require('wp-blog-header.php');
$creds = array();
$creds['user_login'] = 'user';
$creds['user_password'] = 'password';
$creds['remember'] = true;
$user = wp_signon( $creds, false);
if ( is_wp_error($user) )
echo $... | I solved the problem. Here's the solution.
Add this line to your wp-config.php :
```
define('COOKIE_DOMAIN', '.yourdomain.com');
```
save the file and upload. That's all. |
73,306 | <p>Im integrating Superfish into WP. I have called the CSS and the JS. However when I place a class style in the <code>wp_menu</code> as below, the menu is disappearing (<a href="http://rusticblonde.hostizzo.com/" rel="nofollow">see here for rendered output</a>). Could anyone assist (this has been followed <a href="htt... | [
{
"answer_id": 73954,
"author": "Murat",
"author_id": 23879,
"author_profile": "https://wordpress.stackexchange.com/users/23879",
"pm_score": 2,
"selected": false,
"text": "<p>I solved the problem. Here's the solution.</p>\n\n<p>Add this line to your wp-config.php :</p>\n\n<pre><code>def... | 2012/11/20 | [
"https://wordpress.stackexchange.com/questions/73306",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23874/"
] | Im integrating Superfish into WP. I have called the CSS and the JS. However when I place a class style in the `wp_menu` as below, the menu is disappearing ([see here for rendered output](http://rusticblonde.hostizzo.com/)). Could anyone assist (this has been followed [from a not so helpful tutorial](http://wp.tutsplus.... | I solved the problem. Here's the solution.
Add this line to your wp-config.php :
```
define('COOKIE_DOMAIN', '.yourdomain.com');
```
save the file and upload. That's all. |
73,316 | <p>I have a navigation menu in Wordpress. I would like it to check if the page has a custom field of "menu_icon" and if it does, add that custom field into the menu item it corresponds to. I'm sure this would require some sort of walker function extension but I am a bit new to PHP and Wordpress. I've search around and... | [
{
"answer_id": 73319,
"author": "Nicole",
"author_id": 8337,
"author_profile": "https://wordpress.stackexchange.com/users/8337",
"pm_score": 2,
"selected": false,
"text": "<p>This is what i have used for checking to see if the custom field is there or not. I am sure you can use it as wel... | 2012/11/20 | [
"https://wordpress.stackexchange.com/questions/73316",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23884/"
] | I have a navigation menu in Wordpress. I would like it to check if the page has a custom field of "menu\_icon" and if it does, add that custom field into the menu item it corresponds to. I'm sure this would require some sort of walker function extension but I am a bit new to PHP and Wordpress. I've search around and ha... | This is what i have used for checking to see if the custom field is there or not. I am sure you can use it as well.
```
<?php
$custom_field = get_post_meta($post->ID, 'Your Custom Field Name', true);
// Checks to see if there is a value in the custom field
if($custom_field != '') { echo $custom_field; }
... |
73,330 | <p>Basically, I want to query PARENT for a bunch of custom field data and echo it out. Then, I want to query all of the CHILD pages of that parent and echo out more data. </p>
<p>What's the best way to do it?</p>
<ol>
<li>Top level query for parent then within that query a sublevel a query for the children.</li>
<li>... | [
{
"answer_id": 73338,
"author": "Zach",
"author_id": 9605,
"author_profile": "https://wordpress.stackexchange.com/users/9605",
"pm_score": 0,
"selected": false,
"text": "<p>Here is an example using categories instead of pages, but you can query the information using the parent's informat... | 2012/11/20 | [
"https://wordpress.stackexchange.com/questions/73330",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5089/"
] | Basically, I want to query PARENT for a bunch of custom field data and echo it out. Then, I want to query all of the CHILD pages of that parent and echo out more data.
What's the best way to do it?
1. Top level query for parent then within that query a sublevel a query for the children.
2. 2 seperate top level queri... | I don't understand the distinction you are making between 'sublevel' query and 'toplevel' query, but this is how I pull children for a page.
```
$children = get_children(
array(
'post_parent' => $servid,
'post_type' => 'page',
'post_status' => 'publish',
'orderby' => '... |
73,344 | <p>I'm developing a plugin with an options page using the Settings API. </p>
<p>I'd like to have one options array stored for my plugin, but on the settings page, I'd only like some of the settings to be visible to admin users, but the full list of settings to be available to the super admin.</p>
<p>Is this possible?... | [
{
"answer_id": 73345,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 3,
"selected": true,
"text": "<p>Test the current user’s role with <code>current_user_can( 'administrator' )</code>: </p>\n\n<pre><code>if ( current_use... | 2012/11/20 | [
"https://wordpress.stackexchange.com/questions/73344",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/2659/"
] | I'm developing a plugin with an options page using the Settings API.
I'd like to have one options array stored for my plugin, but on the settings page, I'd only like some of the settings to be visible to admin users, but the full list of settings to be available to the super admin.
Is this possible? | Test the current user’s role with `current_user_can( 'administrator' )`:
```
if ( current_user_can( 'administrator' ) )
{
add_settings_field( /* arguments */ );
// or
add_settings_section( /* arguments */ );
}
```
Make sure to use the same check when you save the options. Otherwise your regular users mi... |
73,348 | <p>I have the following code in my functions.php</p>
<pre><code>$code = 'EUR';
global $wpdb;
$query = 'SELECT * FROM ';
$query .= $wpdb->get_blog_prefix() . 'fxbase ';
$query .= 'WHERE code= '.$code;
$data = $wpdb->get_row( $wpdb->prepare( $query ), ARRAY_A );
</code></pre>
<p>The problem is the above query ... | [
{
"answer_id": 73352,
"author": "kaiser",
"author_id": 385,
"author_profile": "https://wordpress.stackexchange.com/users/385",
"pm_score": 0,
"selected": false,
"text": "<h2><code>prepare()</code> the right way</h2>\n\n<p>Things that don't need prepare: Default objects from <code>$wpdb</... | 2012/11/20 | [
"https://wordpress.stackexchange.com/questions/73348",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23772/"
] | I have the following code in my functions.php
```
$code = 'EUR';
global $wpdb;
$query = 'SELECT * FROM ';
$query .= $wpdb->get_blog_prefix() . 'fxbase ';
$query .= 'WHERE code= '.$code;
$data = $wpdb->get_row( $wpdb->prepare( $query ), ARRAY_A );
```
The problem is the above query does not give any result. Just to t... | Your specific issue in that code is that you're missing the quote marks around the $code.
`$query .= 'WHERE code= '.$code;`
Should be:
`$query .= 'WHERE code= "'.$code.'"';`
In the long run, you should indeed use prepare() properly, but this is the specific problem with the code you posted. |
73,354 | <p>I'm setting up a real estate website. I make listings using a custom post type named <code>listings</code> in which I have multiples meta boxes for <strong>beds</strong>, <strong>baths</strong>, and various other information.</p>
<p>I use a plugin to import these posts because listings are generated from third-part... | [
{
"answer_id": 73357,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 1,
"selected": false,
"text": "<p>I would recommend just modifying the <code>single-listings.php</code> template file to output the gallery d... | 2012/11/20 | [
"https://wordpress.stackexchange.com/questions/73354",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23897/"
] | I'm setting up a real estate website. I make listings using a custom post type named `listings` in which I have multiples meta boxes for **beds**, **baths**, and various other information.
I use a plugin to import these posts because listings are generated from third-party software (XML file with Xpaths). Everything w... | I would recommend just modifying the `single-listings.php` template file to output the gallery directly:
```
<?php echo do_shortcode( '[gallery] ); ?>
```
That way, for all the images that have been imported and attached to a given CPT, they weill be output just as if you had placed a `[gallery]` shortcode in the po... |
73,356 | <p>I want to display a dynamic sidebar on all pages, and a different sidebar on the homepage. There are also particular pages where I don't want to display either of them. </p>
<p>This code is not hiding the unwanted sidebar off of the Homepage; both sidebars show. How can I hide 'multipackage' from the homepage and o... | [
{
"answer_id": 73359,
"author": "developdaly",
"author_id": 3293,
"author_profile": "https://wordpress.stackexchange.com/users/3293",
"pm_score": 0,
"selected": false,
"text": "<p>What your code says in English is this:</p>\n\n<p>If there is no dynamic_sidebar function OR there is no sid... | 2012/11/20 | [
"https://wordpress.stackexchange.com/questions/73356",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23479/"
] | I want to display a dynamic sidebar on all pages, and a different sidebar on the homepage. There are also particular pages where I don't want to display either of them.
This code is not hiding the unwanted sidebar off of the Homepage; both sidebars show. How can I hide 'multipackage' from the homepage and only displa... | >
> I want to display a dynamic sidebar on all pages, and a different sidebar on the homepage. There are also particular pages where I don't want to display either of them.
>
>
> This code is not hiding the unwanted sidebar off of the Homepage; both sidebars show. How can I hide 'multipackage' from the homepage and ... |
73,358 | <p>I have a custom walker that extends the Walker class. My code uses the Walker_Page class as it's base as it does pretty much everything else I want but I need to modify it a bit so that it behaves a little differently.</p>
<p>Essentially, I want to prevent the walker from creating new levels of navigation for menu... | [
{
"answer_id": 73376,
"author": "Stephen Harris",
"author_id": 9364,
"author_profile": "https://wordpress.stackexchange.com/users/9364",
"pm_score": 1,
"selected": false,
"text": "<p>You may find this <a href=\"http://wp.tutsplus.com/tutorials/creative-coding/understanding-the-walker-cla... | 2012/11/20 | [
"https://wordpress.stackexchange.com/questions/73358",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12055/"
] | I have a custom walker that extends the Walker class. My code uses the Walker\_Page class as it's base as it does pretty much everything else I want but I need to modify it a bit so that it behaves a little differently.
Essentially, I want to prevent the walker from creating new levels of navigation for menu items tha... | I accidentally left out an important detail in my question that made it a little more complex to solve. I also wanted to show sub navigation of the current page if it had children.
I did this by comparing the element's ancestors to the current page's ancestors (as well as the current page itself), if there wasn't any ... |
73,365 | <p>I'm creating a script that automates build a wordpress site from another CMS.
I've been able to change every setting: themes, options, subdomain, site title, etc.</p>
<p>But what is eluding me is being able to create custom menus.
The code below SHOULD be able to do it for me. However it is not, and I am completely... | [
{
"answer_id": 73376,
"author": "Stephen Harris",
"author_id": 9364,
"author_profile": "https://wordpress.stackexchange.com/users/9364",
"pm_score": 1,
"selected": false,
"text": "<p>You may find this <a href=\"http://wp.tutsplus.com/tutorials/creative-coding/understanding-the-walker-cla... | 2012/11/20 | [
"https://wordpress.stackexchange.com/questions/73365",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23842/"
] | I'm creating a script that automates build a wordpress site from another CMS.
I've been able to change every setting: themes, options, subdomain, site title, etc.
But what is eluding me is being able to create custom menus.
The code below SHOULD be able to do it for me. However it is not, and I am completely stumped o... | I accidentally left out an important detail in my question that made it a little more complex to solve. I also wanted to show sub navigation of the current page if it had children.
I did this by comparing the element's ancestors to the current page's ancestors (as well as the current page itself), if there wasn't any ... |
73,370 | <p>I would like to inject some elements directly after the <code><body></code> tag. </p>
<p>Is that possible using only WordPress hooks?</p>
| [
{
"answer_id": 73372,
"author": "Mario Peshev",
"author_id": 11506,
"author_profile": "https://wordpress.stackexchange.com/users/11506",
"pm_score": 0,
"selected": false,
"text": "<p>You can create a plugin that is based on JavaScript and uses <code>prependTo</code> in order to place a t... | 2012/11/20 | [
"https://wordpress.stackexchange.com/questions/73370",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23901/"
] | I would like to inject some elements directly after the `<body>` tag.
Is that possible using only WordPress hooks? | Just add a custom hook to your template:
```
<body>
<?php do_action( 'wpse73370_custom_hook' ); ?>
``` |
73,388 | <p>I'm running 3.4.2 on Ubuntu. I'm unable to make any changes to menus at all. Also I'm unable to upload anything (flash or browser uploader) to the media library. However plugins have no problem adding things to the library. When I try to make a change I get page not found. </p>
<p>I have my memory limit set at 128M... | [
{
"answer_id": 73392,
"author": "user1576978",
"author_id": 23576,
"author_profile": "https://wordpress.stackexchange.com/users/23576",
"pm_score": 0,
"selected": false,
"text": "<p>backup your wp-config.php, delete the original and run your yoursite/wp-admin again, filling all the field... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73388",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15175/"
] | I'm running 3.4.2 on Ubuntu. I'm unable to make any changes to menus at all. Also I'm unable to upload anything (flash or browser uploader) to the media library. However plugins have no problem adding things to the library. When I try to make a change I get page not found.
I have my memory limit set at 128MB in php.i... | >
> I have my memory limit set at 128MB in php.ini and wp-config.php. There is [an implicit minimum requirement](http://hakre.wordpress.com/2010/06/28/wordpress-3-0-memory-requirements-256-mb/) for the WP Admin to be able to use 256M.
>
>
>
Try setting your PHP memory limit to **256M** instead of 128M.
Also, be s... |
73,396 | <p>I want to add 200 videos from YouTube playlist to my WordPress blog. Each video iframe add as each post to particular category. I searched many plugins but that's not meet my requirement.</p>
| [
{
"answer_id": 73392,
"author": "user1576978",
"author_id": 23576,
"author_profile": "https://wordpress.stackexchange.com/users/23576",
"pm_score": 0,
"selected": false,
"text": "<p>backup your wp-config.php, delete the original and run your yoursite/wp-admin again, filling all the field... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73396",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23906/"
] | I want to add 200 videos from YouTube playlist to my WordPress blog. Each video iframe add as each post to particular category. I searched many plugins but that's not meet my requirement. | >
> I have my memory limit set at 128MB in php.ini and wp-config.php. There is [an implicit minimum requirement](http://hakre.wordpress.com/2010/06/28/wordpress-3-0-memory-requirements-256-mb/) for the WP Admin to be able to use 256M.
>
>
>
Try setting your PHP memory limit to **256M** instead of 128M.
Also, be s... |
73,420 | <p>I have this structure</p>
<p>Category > Subcategory > Post</p>
<p>I´m trying to display some content if the user it´s on a specific category, or in it´s subcategory or post.</p>
<p>I´m using this code but it only works if the user is in the category.php, not if the user it´s on a single.php that belongs to the th... | [
{
"answer_id": 73426,
"author": "Johannes Pille",
"author_id": 9745,
"author_profile": "https://wordpress.stackexchange.com/users/9745",
"pm_score": 2,
"selected": false,
"text": "<p>The <a href=\"http://codex.wordpress.org/Function_Reference/is_category\" rel=\"nofollow\"><code>is_categ... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73420",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/22933/"
] | I have this structure
Category > Subcategory > Post
I´m trying to display some content if the user it´s on a specific category, or in it´s subcategory or post.
I´m using this code but it only works if the user is in the category.php, not if the user it´s on a single.php that belongs to the that parent category:
```... | The [`is_category`](http://codex.wordpress.org/Function_Reference/is_category) [Conditional Tag](http://codex.wordpress.org/Conditional_Tags) *checks if a Category archive page is being displayed* - hence it is expected to return `false` on single post pages, whether the post in question is in said category or not.
To... |
73,425 | <p>I have the Download Monitor Plugin installed and it works beautifully, I just have a question regarding the categories.</p>
<p>I have a parent category, Issue 0, which will have anywhere from 3-6 sub categories in it. Instead of the section on the front page looking like below, where it just lists every download in... | [
{
"answer_id": 73454,
"author": "Steve",
"author_id": 23132,
"author_profile": "https://wordpress.stackexchange.com/users/23132",
"pm_score": 1,
"selected": false,
"text": "<p>There is very good documentation on the WP Download Monitor available at the <a href=\"http://mikejolley.com/pro... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73425",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23226/"
] | I have the Download Monitor Plugin installed and it works beautifully, I just have a question regarding the categories.
I have a parent category, Issue 0, which will have anywhere from 3-6 sub categories in it. Instead of the section on the front page looking like below, where it just lists every download in the paren... | From the [documentation and its sample code](http://mikejolley.com/projects/download-monitor/usage/), I cannot see an option to get the downloads categories tree.
The function `get_downloads` returns a [one-dimensional array](http://webcheatsheet.com/php/arrays.php). Maybe a [routine](https://stackoverflow.com/questio... |
73,427 | <p>I've the below php to display the content of the post id#9 on my 'home page' of my site, so that whenever the client updates the page, it's reflected on the homepage as well - rather than having to make the change twice.</p>
<p><strong>At the moment all the post content is being shown, I need to strip it down to ab... | [
{
"answer_id": 73430,
"author": "Mridul Aggarwal",
"author_id": 22495,
"author_profile": "https://wordpress.stackexchange.com/users/22495",
"pm_score": 0,
"selected": false,
"text": "<p>For the excerpt, you can use this function but for the content, it will create problems with the html,... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73427",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13998/"
] | I've the below php to display the content of the post id#9 on my 'home page' of my site, so that whenever the client updates the page, it's reflected on the homepage as well - rather than having to make the change twice.
**At the moment all the post content is being shown, I need to strip it down to about 100 words...... | WordPress has inbuilt function [force\_balance\_tags](https://codex.wordpress.org/Function_Reference/force_balance_tags)
which I belive is not explored much but it can be useful in such scenario.
get the content and truncate it to any arbitrary length
```
$content = get_the_content();
$length = 1000;
if(strlen($co... |
73,431 | <p>I`m trying to retrieve the names of taxonomy items and include them into a theme admin panel.</p>
<pre>
function retrieve_my_terms() {
global $terms;
$terms = get_terms('taxonomy');
foreach ($terms as $term) {
$option = $term->name;
return $option;
}
}
</pre>
<p>The function is a... | [
{
"answer_id": 73434,
"author": "Mridul Aggarwal",
"author_id": 22495,
"author_profile": "https://wordpress.stackexchange.com/users/22495",
"pm_score": 2,
"selected": true,
"text": "<p>You can add the action on the init itself, just increase the priority of the <code>add_action</code> ca... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73431",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23912/"
] | I`m trying to retrieve the names of taxonomy items and include them into a theme admin panel.
```
function retrieve_my_terms() {
global $terms;
$terms = get_terms('taxonomy');
foreach ($terms as $term) {
$option = $term->name;
return $option;
}
}
```
The function is added after th... | You can add the action on the init itself, just increase the priority of the `add_action` call. The higher the priority the later the function is called.
`add_action('init', 'retrieve_my_terms', 9999);`
But my suggestion is that you should do these kind of things as late as possible, preferably just before the first ... |
73,440 | <p>I want to create a custom page for my Wordpress blog that will execute my php code in it, whilst remaining a part of the overall site css/theme/design.</p>
<p>The php code will make use of 3rd party APIs (so I need to include other php files)</p>
<p>How do I accomplish this?</p>
<p>N.B. I do not have a specific n... | [
{
"answer_id": 73441,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 0,
"selected": false,
"text": "<p>Create a <a href=\"http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates\" rel=\"nofollow\">custom page te... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73440",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23705/"
] | I want to create a custom page for my Wordpress blog that will execute my php code in it, whilst remaining a part of the overall site css/theme/design.
The php code will make use of 3rd party APIs (so I need to include other php files)
How do I accomplish this?
N.B. I do not have a specific need to interact with the... | Please refer to [the **Page Templates** section of the **Static Pages** Codex entry](http://codex.wordpress.org/Pages#Page_Templates).
Essentially, you create a custom page template, named something like `template-foobar.php`, which will live in your Theme's root directory, or in a one-deep sub-directory.
Inside this... |
73,446 | <p>I have this shortcode </p>
<pre><code> [learn_more caption="something here:"]
[/learn_more]
</code></pre>
<p>I want to extract the caption value and remove other stuff. "something here:"</p>
<p>This is the code that I have, but it print the shortcode as it is.</p>
<pre><code> $exclude_codes = 'learn_more';
$... | [
{
"answer_id": 73461,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 2,
"selected": false,
"text": "<p>I read your question differently than @eric-holmes. It sounds to me like your shortcode needs to function nor... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73446",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/11917/"
] | I have this shortcode
```
[learn_more caption="something here:"]
[/learn_more]
```
I want to extract the caption value and remove other stuff. "something here:"
This is the code that I have, but it print the shortcode as it is.
```
$exclude_codes = 'learn_more';
$wp_content = preg_replace("~(?:\[/?)(?!(?:$e... | Thanks every one for help, actually I solved the problem without using regex at all. I use wp-mpdf plugin with wp-event-manager, when I try to output the event page to PDF some content didn't show like title, and some content, .. and that's what cause the problem, but after some customization I was able to get the cont... |
73,455 | <p>I have a custom post type called campsites, events and activities </p>
<p>I want to display this in a list.</p>
<p>So when the user click on the link, it will then display all the posts under that custom post type.</p>
<p>Any help would be greatly appreciated.</p>
<h3>Edit</h3>
<pre><code>add_action('init', 'ac... | [
{
"answer_id": 73460,
"author": "Rachel Baker",
"author_id": 8054,
"author_profile": "https://wordpress.stackexchange.com/users/8054",
"pm_score": 0,
"selected": false,
"text": "<p>Mandy,</p>\n\n<p>You can create a new page template (name it what you want, I would name it 'page-activity... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73455",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23833/"
] | I have a custom post type called campsites, events and activities
I want to display this in a list.
So when the user click on the link, it will then display all the posts under that custom post type.
Any help would be greatly appreciated.
### Edit
```
add_action('init', 'activity_resources_register_post_type');
... | ### Create custom page template
The first step is to [create a custom page template](http://codex.wordpress.org/Pages#Page_Templates) to hold the code. For example, name the file `template-cpt-list.php`:
```
<?php
/**
* Template Name: Custom Post Types List
*/
get_header();
// Custom code will go here
get_footer... |
73,459 | <p>Is there a built-in function that would allow me to restrict access to registered users until the official launch date in Wordpress 3.4.2? The blog is self-hosted. </p>
| [
{
"answer_id": 73462,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 3,
"selected": true,
"text": "<p>This should do it. Place it in your theme's <code>functions.php</code> or a plugin.</p>\n\n<pre><code>function... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73459",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9856/"
] | Is there a built-in function that would allow me to restrict access to registered users until the official launch date in Wordpress 3.4.2? The blog is self-hosted. | This should do it. Place it in your theme's `functions.php` or a plugin.
```
function tst($a) {
if (!current_user_can('edit_posts')) {
wp_die('You are not allowed to view this page');
}
}
add_filter('template_redirect','tst');
```
You can still get to the login page like normal by going to "/wp-login.php" or... |
73,470 | <p>I am writing a counter plugin for WordPress, which will keep track of daily and total views.</p>
<p>Normally you would use post meta fields for storing such information. But I cannot:</p>
<p>I cannot use meta fields, because meta fields cannot be updated without the risk of loosing previous values (no locking). Fo... | [
{
"answer_id": 73484,
"author": "IgniteWoo Team",
"author_id": 23925,
"author_profile": "https://wordpress.stackexchange.com/users/23925",
"pm_score": 1,
"selected": false,
"text": "<p>MySQL will prevent collisions for you on records that are being written/edited. So you actually CAN use... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73470",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23924/"
] | I am writing a counter plugin for WordPress, which will keep track of daily and total views.
Normally you would use post meta fields for storing such information. But I cannot:
I cannot use meta fields, because meta fields cannot be updated without the risk of loosing previous values (no locking). For example:
The m... | Alternatively, instead of updating your metafield, add a new one!
Then the problem becomes, which meta has the highest value, and how do I cleanup the other meta fields.
How I Would Do It
=================
Instead of reinventing the wheel, I can see that Google has already done a brilliant job of counting how many p... |
73,477 | <p>I have a big site for a client, and as it is a really customized wordpress installation with lots of extensions on functionality, I can't use the caching plugins.</p>
<p>To improve the performance, I built a lot of the Site using transients (for example the navigation, the google maps with all the markers etc.), an... | [
{
"answer_id": 73479,
"author": "Stephen Harris",
"author_id": 9364,
"author_profile": "https://wordpress.stackexchange.com/users/9364",
"pm_score": 4,
"selected": true,
"text": "<p>For development I would advise to always work with <code>WP_DEBUG</code> set to <code>true</code> and do t... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73477",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15680/"
] | I have a big site for a client, and as it is a really customized wordpress installation with lots of extensions on functionality, I can't use the caching plugins.
To improve the performance, I built a lot of the Site using transients (for example the navigation, the google maps with all the markers etc.), and leave th... | For development I would advise to always work with `WP_DEBUG` set to `true` and do the following:
```
$key = 'transient_key';
if( !WP_DEBUG && ( false !== ($transient = get_transient($key)) ){
/* Generate transient manually */
$expiration = 24*60*60;//How long to keep for
set_transient($key,$transient, $expi... |
73,478 | <p>The code I'm using, is outside of WordPress i.e.</p>
<pre><code>define('WP_USE_THEMES', false);
require('blog/wp-blog-header.php');
global $wpdb;
</code></pre>
<p>The code that I'm trying to display the post thumbnail (the set featured image) is:</p>
<pre><code>if(has_post_thumbnail($post->ID)){
echo "... | [
{
"answer_id": 73479,
"author": "Stephen Harris",
"author_id": 9364,
"author_profile": "https://wordpress.stackexchange.com/users/9364",
"pm_score": 4,
"selected": true,
"text": "<p>For development I would advise to always work with <code>WP_DEBUG</code> set to <code>true</code> and do t... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73478",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/21131/"
] | The code I'm using, is outside of WordPress i.e.
```
define('WP_USE_THEMES', false);
require('blog/wp-blog-header.php');
global $wpdb;
```
The code that I'm trying to display the post thumbnail (the set featured image) is:
```
if(has_post_thumbnail($post->ID)){
echo "has a thumb";
get_the_post_thumbnail... | For development I would advise to always work with `WP_DEBUG` set to `true` and do the following:
```
$key = 'transient_key';
if( !WP_DEBUG && ( false !== ($transient = get_transient($key)) ){
/* Generate transient manually */
$expiration = 24*60*60;//How long to keep for
set_transient($key,$transient, $expi... |
73,492 | <p>I have a meta_query that gets all the items with a price range between 2 variables. My problem is that 10 000 is not the same as 10000. How can I fix this? </p>
<p>I have been googling but I'n not sure what to google so I'm not really getting anywhere. </p>
<p>Help would be appreciated</p>
<p>Thanks
Hanè </p>
<p... | [
{
"answer_id": 73495,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 2,
"selected": true,
"text": "<p>The problem is that you're comparing <code>10000</code> and <code>10 000</code> as <strong>strings</strong>,... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73492",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23928/"
] | I have a meta\_query that gets all the items with a price range between 2 variables. My problem is that 10 000 is not the same as 10000. How can I fix this?
I have been googling but I'n not sure what to google so I'm not really getting anywhere.
Help would be appreciated
Thanks
Hanè
Edit - Code Added
```
$k... | The problem is that you're comparing `10000` and `10 000` as **strings**, and as such they are *not the same value*.
So, you either need to sanitize the strings to ensure that both return an equivalent value, or you'll need to force them to be integers, so that they'll be evaluated as the same value.
### Edit
Your b... |
73,497 | <p>Hey all i have been trying to find the content that loads up for a page for a few days now and can not seem to find where its located.</p>
<p>This is the WP code that seems to populate the content:</p>
<pre><code>if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'id' => 'home-top-sideba... | [
{
"answer_id": 73502,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 3,
"selected": true,
"text": "<p><a href=\"http://codex.wordpress.org/Customizing_Your_Sidebar\" rel=\"nofollow\">The content for a dynamic sid... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73497",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8469/"
] | Hey all i have been trying to find the content that loads up for a page for a few days now and can not seem to find where its located.
This is the WP code that seems to populate the content:
```
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'id' => 'home-top-sidebar',
'name' => 'Home ... | [The content for a dynamic sidebar is whatever widgets are added to that sidebar from the backend.](http://codex.wordpress.org/Customizing_Your_Sidebar) Look at wp-admin->Appearance->Widgets. The actual code for those widgets could come from WordPress itself, a plugin, or your theme.
But...
>
> The content that i am... |
73,509 | <p>This seems like an easy thing to do but I am missing something here. I have a custom post type called "recipient" and a meta check box called "<code>yes_current</code>" - (we help children with cancer and run events for them so we need to know who is a current recipient and who is a past recipient.) We want to disp... | [
{
"answer_id": 73516,
"author": "jepser",
"author_id": 6519,
"author_profile": "https://wordpress.stackexchange.com/users/6519",
"pm_score": 0,
"selected": false,
"text": "<p>If I understand what you want, when you register a CP on your theme, there is an option \"exclude_from_search\" s... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73509",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23932/"
] | This seems like an easy thing to do but I am missing something here. I have a custom post type called "recipient" and a meta check box called "`yes_current`" - (we help children with cancer and run events for them so we need to know who is a current recipient and who is a past recipient.) We want to display two section... | Thanks guys. I think I may have found a solution.
What I did:
* On `taxonomy-types.php`, get all Items for that type using WP\_QUERY.
* Loop through them, use `get_the_terms()` to get taxonomy Model for each Item
* Still in the loop: use PHP's `in_array()` function and a `$model_ids` array for unique Model checking
*... |
73,511 | <p>I am using custom posts, and in these, I don't a need for the title.</p>
<p>This causes Wordpress to set the titles of my posts to "Auto Draft".</p>
<p>I'd like to change the title's value to something else, computed from other fields in my post.</p>
<p>How do I go about doing that using save_post or some other m... | [
{
"answer_id": 73529,
"author": "Ralf912",
"author_id": 16589,
"author_profile": "https://wordpress.stackexchange.com/users/16589",
"pm_score": 2,
"selected": false,
"text": "<p>Try the filter <a href=\"https://developer.wordpress.org/reference/hooks/default_title/\" rel=\"nofollow noref... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73511",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15943/"
] | I am using custom posts, and in these, I don't a need for the title.
This causes Wordpress to set the titles of my posts to "Auto Draft".
I'd like to change the title's value to something else, computed from other fields in my post.
How do I go about doing that using save\_post or some other means? | This simplest method would be to edit the data at the point it's inserted, rather than updating it afterwards, using [`wp_insert_post_data`](https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data) instead of `save_post`. This works on creating a new post or updating an existing post without change.... |
73,518 | <p>I have a custom template with a drop-down that filters posts by category. I do it by making the form post to the page itself and then catching the argument and using it in a query (see code below). </p>
<p>Here's the bummer: if you navigate to page 2 (for example) and <strong>then</strong> use the filter, the URL s... | [
{
"answer_id": 73529,
"author": "Ralf912",
"author_id": 16589,
"author_profile": "https://wordpress.stackexchange.com/users/16589",
"pm_score": 2,
"selected": false,
"text": "<p>Try the filter <a href=\"https://developer.wordpress.org/reference/hooks/default_title/\" rel=\"nofollow noref... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73518",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8105/"
] | I have a custom template with a drop-down that filters posts by category. I do it by making the form post to the page itself and then catching the argument and using it in a query (see code below).
Here's the bummer: if you navigate to page 2 (for example) and **then** use the filter, the URL still contains the `/pag... | This simplest method would be to edit the data at the point it's inserted, rather than updating it afterwards, using [`wp_insert_post_data`](https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data) instead of `save_post`. This works on creating a new post or updating an existing post without change.... |
73,543 | <p>When you use a standard custom field in WP you have to write the name of the cusotm fields the first time. </p>
<p>The second time you use a custom field it sticks to the custom fields dropdown list. But, sometimes when you install plugins they ise ALOT of custom fields. </p>
<p>This list becomes a bit long an it... | [
{
"answer_id": 73547,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 0,
"selected": false,
"text": "<p>There isn't a way to filter what appears there, you can see where it queries for keys and renders that field in the... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73543",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12727/"
] | When you use a standard custom field in WP you have to write the name of the cusotm fields the first time.
The second time you use a custom field it sticks to the custom fields dropdown list. But, sometimes when you install plugins they ise ALOT of custom fields.
This list becomes a bit long an it may "push" som of... | You can filter the query for these keys on`'query'`. I would start that filter as late as possible to avoid side effect.
Sample code, **tested**:
```
add_filter( 'postmeta_form_limit', 'wpse_73543_hide_meta_start' );
function wpse_73543_hide_meta_start( $num )
{
add_filter( 'query', 'wpse_73543_hide_meta_filter'... |
73,544 | <p>Having some trouble with my first attempt at a direct DB query using $wpdb. I'm using the WordTwit plugin, and trying to retrieve the short url extension for the current post that is created by the plugin. This is the code I have:</p>
<pre><code>global $wpdb;
$short = $wpdb->get_var("SELECT url FROM $wpdb->pr... | [
{
"answer_id": 73547,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 0,
"selected": false,
"text": "<p>There isn't a way to filter what appears there, you can see where it queries for keys and renders that field in the... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73544",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/2041/"
] | Having some trouble with my first attempt at a direct DB query using $wpdb. I'm using the WordTwit plugin, and trying to retrieve the short url extension for the current post that is created by the plugin. This is the code I have:
```
global $wpdb;
$short = $wpdb->get_var("SELECT url FROM $wpdb->prefix.'tweet_url' WHE... | You can filter the query for these keys on`'query'`. I would start that filter as late as possible to avoid side effect.
Sample code, **tested**:
```
add_filter( 'postmeta_form_limit', 'wpse_73543_hide_meta_start' );
function wpse_73543_hide_meta_start( $num )
{
add_filter( 'query', 'wpse_73543_hide_meta_filter'... |
73,545 | <p>I am using the following code to generate a JSON feed. I need to extract the excerpt from posts, but when I run get_the_excerpt() it takes 28 seconds (yes SECONDS!) to run on my local server versus 599 milliseconds when I change get_the_excerpt() to 'hi'.</p>
<p>Does anybody have any idea why this is taking so long... | [
{
"answer_id": 73548,
"author": "Tyler Carter",
"author_id": 16921,
"author_profile": "https://wordpress.stackexchange.com/users/16921",
"pm_score": 2,
"selected": false,
"text": "<p>If you want to access the POST object directly, you can global <code>$post</code> and directly access the... | 2012/11/21 | [
"https://wordpress.stackexchange.com/questions/73545",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1462/"
] | I am using the following code to generate a JSON feed. I need to extract the excerpt from posts, but when I run get\_the\_excerpt() it takes 28 seconds (yes SECONDS!) to run on my local server versus 599 milliseconds when I change get\_the\_excerpt() to 'hi'.
Does anybody have any idea why this is taking so long and w... | The problem will likely be a (very slow) callback that is attached to your `get_the_excerpt()` function.
To inspect the attached callbacks, just inspect the global:
```
// Best hooked to `shutdown`
echo '<pre>'.var_export( $GLOBALS['wp_filters']['get_the_excerpt'], true ).'</pre>';
```
Then get rid of all those cal... |
73,561 | <p>I'm looking for a complete blank Dashboard. No widgets at all and preferably one column. </p>
<p>There are snippets to remove the default WordPress widgets but haven't found anything about the ones added by plugins. Searched all over and seems that this hasn't been asked.</p>
<p><img src="https://i.stack.imgur.co... | [
{
"answer_id": 73562,
"author": "brasofilo",
"author_id": 12615,
"author_profile": "https://wordpress.stackexchange.com/users/12615",
"pm_score": 5,
"selected": true,
"text": "<p>From <a href=\"https://wordpress.stackexchange.com/q/56104/12615\">this Q&A</a>, I've learned about the g... | 2012/11/22 | [
"https://wordpress.stackexchange.com/questions/73561",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12615/"
] | I'm looking for a complete blank Dashboard. No widgets at all and preferably one column.
There are snippets to remove the default WordPress widgets but haven't found anything about the ones added by plugins. Searched all over and seems that this hasn't been asked.
, I've learned about the global variable **`$wp_meta_boxes`**. And over there is also the code to *remove the default meta boxes*.
After examining the variable, this is the code I wrote to remove all Dashboard Widgets, **including the ones added by plug... |
73,590 | <p>Given a wordpress (3.4.x) install that only has 1 admin, how would I grab, from within a plugin, the IP of the currently logged in admin, if there is an admin logged in?</p>
<p>In other words: I need to obtain the IP of the admin, IF there is admin is logged in, and use this IP for other purposes. The request will... | [
{
"answer_id": 73592,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 1,
"selected": false,
"text": "<p>Like any other IP, they are not different for admins …</p>\n\n<pre><code>function get_ip() \n{\n $ip = '';\n ... | 2012/11/22 | [
"https://wordpress.stackexchange.com/questions/73590",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5090/"
] | Given a wordpress (3.4.x) install that only has 1 admin, how would I grab, from within a plugin, the IP of the currently logged in admin, if there is an admin logged in?
In other words: I need to obtain the IP of the admin, IF there is admin is logged in, and use this IP for other purposes. The request will not necess... | This functionality is not directly available, you'll have to track the logins inside the database(probably as a transient) & check if that transient is available.
```
function check_for_admin() {
$user = wp_get_current_user();
if(in_array('administrator', $user->roles))
set_transient('admin_ip', get_ip... |
73,609 | <p>Using this piece of code you can show content depending if it's a child-page or not:</p>
<pre><code><?php
global $post;
if ( is_page() && $post->post_parent ) : ?>
This is a child-page.
<?php else : ?>
This is a parent-page.
<?php endif; ?>
</code></pre>
<p>But I would like to add o... | [
{
"answer_id": 73611,
"author": "fischi",
"author_id": 15680,
"author_profile": "https://wordpress.stackexchange.com/users/15680",
"pm_score": 0,
"selected": false,
"text": "<p>you can achive that with using</p>\n\n<pre><code>global $post;\n\n$args = array (\n 'parent' => $post->... | 2012/11/22 | [
"https://wordpress.stackexchange.com/questions/73609",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/21153/"
] | Using this piece of code you can show content depending if it's a child-page or not:
```
<?php
global $post;
if ( is_page() && $post->post_parent ) : ?>
This is a child-page.
<?php else : ?>
This is a parent-page.
<?php endif; ?>
```
But I would like to add one more statement, so that I could have different conte... | I ended up using this code:
```
<?php
global $post;
$children = get_pages( array( 'child_of' => $post->ID ) );
if ( is_page() && $post->post_parent ) : ?>
This is a child-page.
<?php elseif ( is_page() && count( $children ) > 0 ) : ?>
This is a parent-page (with one or more children)
<?php else : ?>
This is a paren... |
73,614 | <p>I was wondering how to create a list of categories name and ids for Wordpress Bookmarks such as <a href="http://codex.wordpress.org/Function_Reference/get_all_category_ids" rel="nofollow"><code>get_all_category_ids</code></a> for post.</p>
<p>I tried using the <a href="http://codex.wordpress.org/Function_Reference/... | [
{
"answer_id": 73611,
"author": "fischi",
"author_id": 15680,
"author_profile": "https://wordpress.stackexchange.com/users/15680",
"pm_score": 0,
"selected": false,
"text": "<p>you can achive that with using</p>\n\n<pre><code>global $post;\n\n$args = array (\n 'parent' => $post->... | 2012/11/22 | [
"https://wordpress.stackexchange.com/questions/73614",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23957/"
] | I was wondering how to create a list of categories name and ids for Wordpress Bookmarks such as [`get_all_category_ids`](http://codex.wordpress.org/Function_Reference/get_all_category_ids) for post.
I tried using the [`get_bookmarks`](http://codex.wordpress.org/Function_Reference/get_bookmarks), but the category does ... | I ended up using this code:
```
<?php
global $post;
$children = get_pages( array( 'child_of' => $post->ID ) );
if ( is_page() && $post->post_parent ) : ?>
This is a child-page.
<?php elseif ( is_page() && count( $children ) > 0 ) : ?>
This is a parent-page (with one or more children)
<?php else : ?>
This is a paren... |
73,619 | <p>How do I load the contents of a text file - or any other file, like .php - and use the test for the <code>login_message</code> hook that prints a message above the <code>#login</code> box in wp-login.php?</p>
<p><em>(BTW, this is in a child theme, if it makes a difference.)</em></p>
<pre><code>function custom_logi... | [
{
"answer_id": 73611,
"author": "fischi",
"author_id": 15680,
"author_profile": "https://wordpress.stackexchange.com/users/15680",
"pm_score": 0,
"selected": false,
"text": "<p>you can achive that with using</p>\n\n<pre><code>global $post;\n\n$args = array (\n 'parent' => $post->... | 2012/11/22 | [
"https://wordpress.stackexchange.com/questions/73619",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/268/"
] | How do I load the contents of a text file - or any other file, like .php - and use the test for the `login_message` hook that prints a message above the `#login` box in wp-login.php?
*(BTW, this is in a child theme, if it makes a difference.)*
```
function custom_login_message() {
$message = get_bloginfo('stylesheet... | I ended up using this code:
```
<?php
global $post;
$children = get_pages( array( 'child_of' => $post->ID ) );
if ( is_page() && $post->post_parent ) : ?>
This is a child-page.
<?php elseif ( is_page() && count( $children ) > 0 ) : ?>
This is a parent-page (with one or more children)
<?php else : ?>
This is a paren... |
73,622 | <p>I have a custom plugin 'Charts' that has it's own menu. In that menu are links to the 3 pages for the plugin - 'Charts', 'Add Chart' and 'Edit Chart'. However, I don't want to display the link to 'Edit Chart'.</p>
<p>Here is how I add the page in question -</p>
<pre><code>$this->pagehook = add_submenu_page('cha... | [
{
"answer_id": 73628,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 5,
"selected": true,
"text": "<p>Use a submenu page as parent slug. The admin menu has just two levels, so the imaginary third level will be hidden.</p>... | 2012/11/22 | [
"https://wordpress.stackexchange.com/questions/73622",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10097/"
] | I have a custom plugin 'Charts' that has it's own menu. In that menu are links to the 3 pages for the plugin - 'Charts', 'Add Chart' and 'Edit Chart'. However, I don't want to display the link to 'Edit Chart'.
Here is how I add the page in question -
```
$this->pagehook = add_submenu_page('charts', __('Edit Chart'), ... | Use a submenu page as parent slug. The admin menu has just two levels, so the imaginary third level will be hidden.
Sample code, tested:
```
add_action( 'admin_menu', 'wpse_73622_register_hidden_page' );
function wpse_73622_register_hidden_page()
{
add_submenu_page(
'options-writing.php',
'Hidden... |
73,630 | <p>I'm using wp_query to create a custom query that retrieves search results but it is returning 0 results. Here is the code:</p>
<pre><code>$query = 's=the&posts_per_page=5&paged=1';
$custom_query = new WP_Query();
$custom_query->query($query);
if( $custom_query->have_posts() ) {
while ( $cust... | [
{
"answer_id": 73632,
"author": "Toby",
"author_id": 23962,
"author_profile": "https://wordpress.stackexchange.com/users/23962",
"pm_score": 0,
"selected": false,
"text": "<p>Try adding <strong>&post_type=any</strong> to your query</p>\n\n<pre><code>$query = 's=the&posts_per_page... | 2012/11/22 | [
"https://wordpress.stackexchange.com/questions/73630",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23961/"
] | I'm using wp\_query to create a custom query that retrieves search results but it is returning 0 results. Here is the code:
```
$query = 's=the&posts_per_page=5&paged=1';
$custom_query = new WP_Query();
$custom_query->query($query);
if( $custom_query->have_posts() ) {
while ( $custom_query->have_posts() ) : $... | Lets take the nicer form of what you have as posted in another answer
```
$args = array(
's' => 'the',
'posts_per_page' => 5,
'paged' => 1
);
$custom_query = new WP_Query($args);
```
I strongly recommend you use WP\_Query with an argument array and pass in via the constructor like this.
Lets look at you... |
73,636 | <p>e.g.</p>
<pre><code>curl -I http://ma.tt/blog/wp-config.php
200 OK
</code></pre>
<p>The wp-config.php is not public facing file, since it currently just return blank page, so why not return 404 instead. (so will not be cached by Google)</p>
<p>Also, for file such as <code>readme.html</code>, it should be hidden a... | [
{
"answer_id": 73638,
"author": "Mridul Aggarwal",
"author_id": 22495,
"author_profile": "https://wordpress.stackexchange.com/users/22495",
"pm_score": 0,
"selected": false,
"text": "<p>First a correction, if you block the files under wp-admin, you won't be able to use the wordpress admi... | 2012/11/22 | [
"https://wordpress.stackexchange.com/questions/73636",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16037/"
] | e.g.
```
curl -I http://ma.tt/blog/wp-config.php
200 OK
```
The wp-config.php is not public facing file, since it currently just return blank page, so why not return 404 instead. (so will not be cached by Google)
Also, for file such as `readme.html`, it should be hidden as it disclose your wordpress version, e.g. <... | I wouldn't bother with the readme file as probably no hacker bothers to check your WP version before trying to hack into the site.
Will not bother with anything in /wp-includes and /wp-admin because I trust the core team to make that code secure in the default installation, and those file don't contain any information ... |
73,646 | <p>I am building a user generated content sharing theme
so how can i allow visitors to upload an image from a url
i mean to say that they enter the url and the image gets automatically attached</p>
<p>this is the code i am currently using for</p>
<pre><code><?php
/*
Template Name: Submit Content Template
*/
// i... | [
{
"answer_id": 73648,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 0,
"selected": false,
"text": "<p>See Codex for the example in <a href=\"http://codex.wordpress.org/Function_Reference/media_handle_sideload\" rel=\"... | 2012/11/22 | [
"https://wordpress.stackexchange.com/questions/73646",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/22975/"
] | I am building a user generated content sharing theme
so how can i allow visitors to upload an image from a url
i mean to say that they enter the url and the image gets automatically attached
this is the code i am currently using for
```
<?php
/*
Template Name: Submit Content Template
*/
// if you are not using this... | You have not created the attachment as link to the post, you will need to do that first. Then you can use in the content.
Alternative it is possibel to upload to other path, but better is a link in the post, post-ID to attachment-ID.
Easiest way to do that is with `wp_insert_attachment()`. This function takes an arra... |
73,649 | <p>I have a function which should return the future event date:</p>
<pre><code>function get_upcoming_exercises( $limit = -1 ) {
$args = array(
'post_type' => 'px_event',
'posts_per_page' => $limit,
'post_status' => 'publish',
'meta_query' => array(
array(
... | [
{
"answer_id": 73655,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 1,
"selected": false,
"text": "<p>Your date format is in the wrong order. Think of it from a strictly numerical perspective- 11222012 > 1032013</p>\n... | 2012/11/22 | [
"https://wordpress.stackexchange.com/questions/73649",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1484/"
] | I have a function which should return the future event date:
```
function get_upcoming_exercises( $limit = -1 ) {
$args = array(
'post_type' => 'px_event',
'posts_per_page' => $limit,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => ... | Your date format is in the wrong order. Think of it from a strictly numerical perspective- 11222012 > 1032013
Dates should follow the [MySQL date format](http://dev.mysql.com/doc/refman/5.5/en/datetime.html) in descending units- yyyy-mm-dd |
73,654 | <p>I am trying to use <code>get_transient()</code> method in my Wordpress, I have read the document and seems like I am doing what has been described in the docs.</p>
<p>I need to show weather in my website and I am using a third party weather API which is updated every 6 hours.</p>
<p>We are creating a local cache ... | [
{
"answer_id": 73658,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 2,
"selected": false,
"text": "<p>The problem is not with the 'transients' function. That looks like an error message returned from your third ... | 2012/11/22 | [
"https://wordpress.stackexchange.com/questions/73654",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9415/"
] | I am trying to use `get_transient()` method in my Wordpress, I have read the document and seems like I am doing what has been described in the docs.
I need to show weather in my website and I am using a third party weather API which is updated every 6 hours.
We are creating a local cache of weather so that the API sh... | Catching the weather API remote data
------------------------------------
The `msg`, you're showing in your question is basically the result from the weather API. And it says, that there's no data available for your location.
The first thing you want to do is some research in [the Codex and the "WP HTTP API"](http://... |
73,676 | <p>I am using the multi post thumbnails plugin. I have a custom post type "artist" who has a logo. In the loop I want to echo out the following:</p>
<pre><code>$logo = MultiPostThumbnails::get_post_thumbnail_id('artist', 'Logo', $post->ID);
echo $logo;
</code></pre>
<p>Nothing gets returned - I used a <code>var_du... | [
{
"answer_id": 73677,
"author": "Ralf912",
"author_id": 16589,
"author_profile": "https://wordpress.stackexchange.com/users/16589",
"pm_score": 1,
"selected": false,
"text": "<p>First check if the post has a thumbnail:</p>\n\n<pre><code>$has_thumbnail = MultiPostThumbnails::has_post_thum... | 2012/11/22 | [
"https://wordpress.stackexchange.com/questions/73676",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23972/"
] | I am using the multi post thumbnails plugin. I have a custom post type "artist" who has a logo. In the loop I want to echo out the following:
```
$logo = MultiPostThumbnails::get_post_thumbnail_id('artist', 'Logo', $post->ID);
echo $logo;
```
Nothing gets returned - I used a `var_dump` on $logo to check, it is just ... | First check if the post has a thumbnail:
```
$has_thumbnail = MultiPostThumbnails::has_post_thumbnail( 'artist', 'Logo', $post->ID );
```
If the post has no thumbnail, maybe you don't have attached a thumbnail to the post. |
73,690 | <p>Note: This is not the popular question about how to create multiple instances of a widget. I have a text widget that I am using to display "business hours". This text needs to go in multiple sidebars and is likely to change often enough to be a nuisance to change it in multiple places. Is there a way to use the s... | [
{
"answer_id": 73718,
"author": "brasofilo",
"author_id": 12615,
"author_profile": "https://wordpress.stackexchange.com/users/12615",
"pm_score": 2,
"selected": true,
"text": "<p>A possible solution would be to enable shortcodes in the Text Widget.</p>\n\n<pre><code>add_filter( 'widget_t... | 2012/11/23 | [
"https://wordpress.stackexchange.com/questions/73690",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23976/"
] | Note: This is not the popular question about how to create multiple instances of a widget. I have a text widget that I am using to display "business hours". This text needs to go in multiple sidebars and is likely to change often enough to be a nuisance to change it in multiple places. Is there a way to use the same in... | A possible solution would be to enable shortcodes in the Text Widget.
```
add_filter( 'widget_text', 'do_shortcode', 11 );
```
Then put the same [shortcode](http://codex.wordpress.org/Shortcode_API) (i.e.: "`[business_hours]`") in all text widgets, and all of them will display the same content.
It's even possible ... |
73,702 | <p>I have a search widget with a drop down populated with my custom taxonomies. I need one of the other input fields to only show when a certain taxonomy or its children are selected. </p>
<p>Before you say this is only a jquary question, please bare with me. I think I need to edit wp_dropdown_categories() with Walker... | [
{
"answer_id": 73712,
"author": "HaneD",
"author_id": 23928,
"author_profile": "https://wordpress.stackexchange.com/users/23928",
"pm_score": 1,
"selected": false,
"text": "<p>To add the data-select to the select tag use </p>\n\n<pre><code> <?php \n $select = wp_dropdown_categories(... | 2012/11/23 | [
"https://wordpress.stackexchange.com/questions/73702",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23928/"
] | I have a search widget with a drop down populated with my custom taxonomies. I need one of the other input fields to only show when a certain taxonomy or its children are selected.
Before you say this is only a jquary question, please bare with me. I think I need to edit wp\_dropdown\_categories() with Walker\_Catego... | My full working code for those interested
```
<?php
// Equipment Category Dropdown, thanks https://gist.github.com/2902509
class Walker_SlugValueCategoryDropdown extends Walker_CategoryDropdown {
function start_el(&$output, $category, $depth, $args) {
$pad = str_repeat(' ', ... |
73,719 | <p>Is there an easy way of getting the charset and collation of the DB tables in WordPress without resorting to SQL queries?</p>
| [
{
"answer_id": 73720,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 4,
"selected": true,
"text": "<p>There are <code>$wpdb->charset</code> and <code>$wpdb->collate</code>. I am not sure if or when one of these valu... | 2012/11/23 | [
"https://wordpress.stackexchange.com/questions/73719",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/736/"
] | Is there an easy way of getting the charset and collation of the DB tables in WordPress without resorting to SQL queries? | There are `$wpdb->charset` and `$wpdb->collate`. I am not sure if or when one of these values might be empty, so it is better to prepare for empty values …
From my DB class:
```
/**
* Get table charset and collation.
*
* @since 2012.10.22
* @return string
*/
protected static function get_wp_charset_collate() {
... |
73,738 | <p>How can I get something like this to work?</p>
<pre><code>// in a plugin / theme:
// This imaginary function will make WordPress think that the
// current request is a 404.
// Ideally this function could be ran anywhere, but realistically it
// will probably have to be before the template_redirect hook runs.
gene... | [
{
"answer_id": 73742,
"author": "dave1010",
"author_id": 8305,
"author_profile": "https://wordpress.stackexchange.com/users/8305",
"pm_score": 0,
"selected": false,
"text": "<p>What seems to work:</p>\n\n<pre><code>global $wp_query;\n$wp_query->set_404();\n$wp_query->max_num_pages ... | 2012/11/23 | [
"https://wordpress.stackexchange.com/questions/73738",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8305/"
] | How can I get something like this to work?
```
// in a plugin / theme:
// This imaginary function will make WordPress think that the
// current request is a 404.
// Ideally this function could be ran anywhere, but realistically it
// will probably have to be before the template_redirect hook runs.
generate_404_someh... | ```
function generate_404_somehow() {
global $wp_query;
$wp_query->is_404 = true;
}
add_action('wp','generate_404_somehow');
```
Of course, that will send all of you page to the 404 template. I don't know what the conditions are that this should fire or not fire.
Or to be more cautious (see comments) ...
```
... |
73,744 | <p>I'm trying to retrieve the thumbnails for only certain products of my woocommerce, using <code>products_tag</code>,</p>
<p>this code is showing all products :</p>
<pre><code><ul class="products">
<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => 5 );
$loop = new WP_Query( $args );
w... | [
{
"answer_id": 73814,
"author": "Rodrigo Sanz",
"author_id": 23942,
"author_profile": "https://wordpress.stackexchange.com/users/23942",
"pm_score": 4,
"selected": true,
"text": "<p>I found the answer, it was a typing mistake, you have to put </p>\n\n<pre><code>'product_tag' => 'where... | 2012/11/23 | [
"https://wordpress.stackexchange.com/questions/73744",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23942/"
] | I'm trying to retrieve the thumbnails for only certain products of my woocommerce, using `products_tag`,
this code is showing all products :
```
<ul class="products">
<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => 5 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(... | I found the answer, it was a typing mistake, you have to put
```
'product_tag' => 'wherever_tag_you_use'
```
and it's works like charm |
73,748 | <p>I have the <code>ID</code> from a product (<code>1345</code>) how can i get the category name of that specific product?</p>
<p>I try </p>
<pre><code>$post_categories = wp_get_post_categories( $post->ID );
print_r( $post_categories );
</code></pre>
<p>but it outputs:</p>
<pre><code>Array ( ) Array ( ) Array ( ... | [
{
"answer_id": 73761,
"author": "Mridul Aggarwal",
"author_id": 22495,
"author_profile": "https://wordpress.stackexchange.com/users/22495",
"pm_score": 5,
"selected": true,
"text": "<p>Since the question is tagged woocommerce, i'm assuming that it's a product CPT created by woocommerce w... | 2012/11/23 | [
"https://wordpress.stackexchange.com/questions/73748",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23942/"
] | I have the `ID` from a product (`1345`) how can i get the category name of that specific product?
I try
```
$post_categories = wp_get_post_categories( $post->ID );
print_r( $post_categories );
```
but it outputs:
```
Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( )
```
What those ... | Since the question is tagged woocommerce, i'm assuming that it's a product CPT created by woocommerce wordpress plugin. This answer doesn't apply if that's not the case.
The products categories is not normal categories, they are a custom taxonomy created specifically for products which is just labeled as "Categories".... |
73,749 | <p>I have devved a small plugin based on a shortcode. Here's a stripped down version of the code for the shortcode itself:</p>
<pre><code>function lishortcode($liatts) {
extract(shortcode_atts(array(
"li" => get_option('li'),
), $liatts));
foreach ($liatts as $key => $option) {
... | [
{
"answer_id": 73750,
"author": "Steve",
"author_id": 23132,
"author_profile": "https://wordpress.stackexchange.com/users/23132",
"pm_score": 0,
"selected": false,
"text": "<pre><code>function lishortcode($liatts) {\n// $liatts here is an array( 'URL' => \"http://www.differenturl.com/... | 2012/11/23 | [
"https://wordpress.stackexchange.com/questions/73749",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15507/"
] | I have devved a small plugin based on a shortcode. Here's a stripped down version of the code for the shortcode itself:
```
function lishortcode($liatts) {
extract(shortcode_atts(array(
"li" => get_option('li'),
), $liatts));
foreach ($liatts as $key => $option) {
$li[$key] = $optio... | First of all, you're using `extract` / `shortcode_atts` in correctly:
The line:
```
extract(shortcode_atts(array(
"li" => get_option('li'),
), $liatts));
```
uses `shortcode_atts` and then extracts turns each key in the returnarray into its own variable: e.g. `$li` in this example. But you then go on... |
73,796 | <p>I have this code</p>
<pre><code>function add_custom_meta_box() {
add_meta_box(
'custom_meta_box', // $id
'Custom Meta Box', // $title
'show_custom_meta_box', // $callback
'page', // $page
'normal', // $context
'high'); // $priority
}
add_action('add_meta_boxes', 'add_custom_meta_box');... | [
{
"answer_id": 73797,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 3,
"selected": false,
"text": "<p>Define an array of post types, and register the metabox for each one separately:</p>\n\n<pre><code>function add_custom... | 2012/11/24 | [
"https://wordpress.stackexchange.com/questions/73796",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24012/"
] | I have this code
```
function add_custom_meta_box() {
add_meta_box(
'custom_meta_box', // $id
'Custom Meta Box', // $title
'show_custom_meta_box', // $callback
'page', // $page
'normal', // $context
'high'); // $priority
}
add_action('add_meta_boxes', 'add_custom_meta_box');
```
I want ... | Define an array of post types, and register the metabox for each one separately:
```
function add_custom_meta_box() {
$post_types = array ( 'post', 'page', 'event' );
foreach( $post_types as $post_type )
{
add_meta_box(
'custom_meta_box', // $id
'Custom Meta Box', // $titl... |
73,802 | <p>I have two questions in a row:</p>
<ul>
<li>How to check the array values, what <code>WP_Query</code> has brought to me?</li>
<li>If I get 10 posts in cat=3, then I want to get only 5 from them, and then want to echo them individually wherever I want them to print.</li>
</ul>
<p>It may be like:</p>
<pre>
--------... | [
{
"answer_id": 73816,
"author": "Mridul Aggarwal",
"author_id": 22495,
"author_profile": "https://wordpress.stackexchange.com/users/22495",
"pm_score": 0,
"selected": false,
"text": "<p>The posts retrieved from a query are stored in the variable named <code>posts</code>. You can read or ... | 2012/11/24 | [
"https://wordpress.stackexchange.com/questions/73802",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/22728/"
] | I have two questions in a row:
* How to check the array values, what `WP_Query` has brought to me?
* If I get 10 posts in cat=3, then I want to get only 5 from them, and then want to echo them individually wherever I want them to print.
It may be like:
```
-------------------
| 1 | 2 |
-------------------... | Assuming you start with:
```
$custom_query_args = array(
'cat' => 10,
'post_per_page' => 5
);
$custom_query = new WP_Query($custom_query_args);
```
Then to answer your first question, you can see what is returned (for development/debugging) via:
```
var_dump( $custom_query );
```
To output your query as... |
73,803 | <p>I've created a custom Taxonomy for a Custom Post Type, and created five or so terms within the taxonomy.</p>
<p>I've created a single image upload and assigned it to the custom taxonomy, and uploaded images for each term.</p>
<p>I can't for the life of me figure out how to get the image to display. I've var_dumped... | [
{
"answer_id": 73819,
"author": "brasofilo",
"author_id": 12615,
"author_profile": "https://wordpress.stackexchange.com/users/12615",
"pm_score": 3,
"selected": true,
"text": "<p>As per the plugin <a href=\"http://www.advancedcustomfields.com/docs/tutorials/retrieving-values-from-other-p... | 2012/11/24 | [
"https://wordpress.stackexchange.com/questions/73803",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24016/"
] | I've created a custom Taxonomy for a Custom Post Type, and created five or so terms within the taxonomy.
I've created a single image upload and assigned it to the custom taxonomy, and uploaded images for each term.
I can't for the life of me figure out how to get the image to display. I've var\_dumped the term but th... | As per the plugin [documentation](http://www.advancedcustomfields.com/docs/tutorials/retrieving-values-from-other-pages-taxonomy-user-media/):
>
> The second parameter needed is a string in the format “$type\_$id”.
>
>
>
```
// get value from a taxonomy (taxonomy = "category", id = 3)
$value = get_field('field_na... |
73,827 | <p>is there any way to style the profile page on wordpress ? I will like to add something like:</p>
<p><strong>Start of the page just below the <code><h2></code> tag</strong></p>
<pre><code><div id="normal-sortables" class="meta-box-sortables ui-sortable">
<div id="poststuff" class="metabox-holder ... | [
{
"answer_id": 73828,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 0,
"selected": false,
"text": "<p>You've been poking around in the right pages. I think you know the answer already. :) If you see a hook in th... | 2012/11/24 | [
"https://wordpress.stackexchange.com/questions/73827",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15704/"
] | is there any way to style the profile page on wordpress ? I will like to add something like:
**Start of the page just below the `<h2>` tag**
```
<div id="normal-sortables" class="meta-box-sortables ui-sortable">
<div id="poststuff" class="metabox-holder has-right-sidebar">
<div id="post-body">
... | It works on a standard profile page (your profile / Profile) without other plugins installed.
Other plugins may affect the overall result. I think code can be improved, if some one knows how please give it a go.
```
function better_profile_page($buff... |
73,834 | <p>I know this has been discussed before but I can't seem to make it work with any of the solution posted in other topics.</p>
<p>How can I make pagination to work on a loop like this:</p>
<pre><code> <div id="first-loop-container">
<?php $my_query = new WP_Query('showposts=5'); ?>
... | [
{
"answer_id": 73885,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 1,
"selected": false,
"text": "<p>You have to pass pagination parameters to your queries as well. As it is, you are just pulling 5 posts. By de... | 2012/11/24 | [
"https://wordpress.stackexchange.com/questions/73834",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24027/"
] | I know this has been discussed before but I can't seem to make it work with any of the solution posted in other topics.
How can I make pagination to work on a loop like this:
```
<div id="first-loop-container">
<?php $my_query = new WP_Query('showposts=5'); ?>
<?php while ($my_query->have_post... | You have to pass pagination parameters to your queries as well. As it is, you are just pulling 5 posts. By default that is going to be the most recent five. Then another query pulls the next five. The fact that you are trying to paginate two loops makes this trickier than normal. However...
At first at first I thought... |
73,840 | <p>I'm trying to understand where to use filters and where to use actions. </p>
<p>Suppose I have a query in a plugin, which later add on modules might modify to change the results of the query, thus modifying the arguments. </p>
<p>Would this be an ideal implementation of this concept, or should I be using actions h... | [
{
"answer_id": 73841,
"author": "Oleg Butuzov",
"author_id": 14536,
"author_profile": "https://wordpress.stackexchange.com/users/14536",
"pm_score": 2,
"selected": false,
"text": "<p>My Congratulations. You understand topic perfectly. Filters if you want to change incoming content (that'... | 2012/11/24 | [
"https://wordpress.stackexchange.com/questions/73840",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5844/"
] | I'm trying to understand where to use filters and where to use actions.
Suppose I have a query in a plugin, which later add on modules might modify to change the results of the query, thus modifying the arguments.
Would this be an ideal implementation of this concept, or should I be using actions here?
// Function... | +1 to both of the other answers, for explaining the primary differences between *actions* and *filters*.
However, to answer your *specific* question, about which to use for modifying a query:
1. Injecting your custom query into the template *does*, as you guessed, require hooking into an existing **action**. (Whether... |
73,852 | <p>I'm creating a one page wordpress website, and I need my 'home', 'about', 'portfolio', 'services' and 'contact' pages to all be on my front page. I created the following page template for my front page:</p>
<p><strong>page-home.php:</strong></p>
<pre><code><?php get_header(); ?>
<div id="primary"... | [
{
"answer_id": 73853,
"author": "Taurayi",
"author_id": 23273,
"author_profile": "https://wordpress.stackexchange.com/users/23273",
"pm_score": 0,
"selected": false,
"text": "<p>Worked something out that works:</p>\n\n<pre><code><?php \n\n $titles = array('home', 'about', 'portfoli... | 2012/11/25 | [
"https://wordpress.stackexchange.com/questions/73852",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23273/"
] | I'm creating a one page wordpress website, and I need my 'home', 'about', 'portfolio', 'services' and 'contact' pages to all be on my front page. I created the following page template for my front page:
**page-home.php:**
```
<?php get_header(); ?>
<div id="primary">
<div id="content">
... | There is no need to use such custom code when wordpress provides a better way of ordering the pages using `menu_order`. You can see this option under `Page Attributes` box on the right side of page edit screen. You can assign the ordering as per your criteria, then use the following code
```
<?php
global $wp_query;
$w... |
73,859 | <p>Sorry if this question is a bit to trivial, but I'm writing a theme that depends on a plugin to be installed. It's a multilingual theme, so I absolutely need the user to have <a href="http://wordpress.org/extend/plugins/polylang/" rel="nofollow">Polylang</a> installed. I thought about just copying the plugin files i... | [
{
"answer_id": 73862,
"author": "Oleg Butuzov",
"author_id": 14536,
"author_profile": "https://wordpress.stackexchange.com/users/14536",
"pm_score": 2,
"selected": false,
"text": "<p>sample code that you can addopt and chage... to check is plugin installed. \n// addition check on init ho... | 2012/11/25 | [
"https://wordpress.stackexchange.com/questions/73859",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5986/"
] | Sorry if this question is a bit to trivial, but I'm writing a theme that depends on a plugin to be installed. It's a multilingual theme, so I absolutely need the user to have [Polylang](http://wordpress.org/extend/plugins/polylang/) installed. I thought about just copying the plugin files into my theme, but that would ... | sample code that you can addopt and chage... to check is plugin installed.
// addition check on init hook.
```
add_action('admin_init', 'wpse_73859_init');
function wpse_73859_init(){
// if - we in wp-admin
// if - we class of polylang not found
// and if we can manage_options (there a lot of different
... |
73,868 | <p>I'm building a plugin and I'm quite new to wordpress I have a class what has couple of methods what should execute database queries. The class look as it follows </p>
<pre><code>class MyClass{
private $wpdb;
function __construct(){
global $wpdb;
}
function query(){
... | [
{
"answer_id": 73870,
"author": "Oleg Butuzov",
"author_id": 14536,
"author_profile": "https://wordpress.stackexchange.com/users/14536",
"pm_score": 3,
"selected": true,
"text": "<pre><code>class MyClass{\n function __construct(){\n global $wpdb;\n $this->db = $wpdb;\... | 2012/11/25 | [
"https://wordpress.stackexchange.com/questions/73868",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23759/"
] | I'm building a plugin and I'm quite new to wordpress I have a class what has couple of methods what should execute database queries. The class look as it follows
```
class MyClass{
private $wpdb;
function __construct(){
global $wpdb;
}
function query(){
$wpdb->q... | ```
class MyClass{
function __construct(){
global $wpdb;
$this->db = $wpdb;
}
function query(){
return $this->db->query(
$this->db->prepare("INSERT INTO {$this->db->wp_competitors} (id, ield_key, field_value) VALUES ( %d, %s, %s )",
1, $field_key, $field_valu... |
73,874 | <p>I am creating a plugin in WordPress Version 3.4.2. When the administrator submits a form, a new folder is created inside my plugin directory and a file saved in this new folder.</p>
<p>But it gives me the following error:</p>
<pre><code>error : The file has not been created
$dir = plugins_url()."/folder-name/;
... | [
{
"answer_id": 73876,
"author": "Oleg Butuzov",
"author_id": 14536,
"author_profile": "https://wordpress.stackexchange.com/users/14536",
"pm_score": 2,
"selected": false,
"text": "<p>You can use <a href=\"http://codex.wordpress.org/Function_Reference/plugin_dir_path\" rel=\"nofollow\">pl... | 2012/11/25 | [
"https://wordpress.stackexchange.com/questions/73874",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14547/"
] | I am creating a plugin in WordPress Version 3.4.2. When the administrator submits a form, a new folder is created inside my plugin directory and a file saved in this new folder.
But it gives me the following error:
```
error : The file has not been created
$dir = plugins_url()."/folder-name/;
```
The above code ... | Do not use the plugin directory to store new files.
* During an update the plugin directory will be erased by WordPress. And all files in it too.
* The plugin directory might be read-only in some setups (I do that always).
Use the [regular uploads directory](http://codex.wordpress.org/Function_Reference/wp_upload_dir... |
73,881 | <p>I am trying to run the wp-cron.php manually by calling it that way: </p>
<pre><code>http://mysite.com/wp-cron.php?doing_wp_cron
</code></pre>
<p>Disabling the auto cron function with :</p>
<pre><code>define('DISABLE_WP_CRON', TRUE);
</code></pre>
<p>produces the same error.</p>
<p>What could be the issue?</p>
| [
{
"answer_id": 78551,
"author": "Simes",
"author_id": 25678,
"author_profile": "https://wordpress.stackexchange.com/users/25678",
"pm_score": 2,
"selected": false,
"text": "<p>If you're launching wp-cron manually you don't need the \"doing_wp_cron\" parameter. The fact that you have it a... | 2012/11/25 | [
"https://wordpress.stackexchange.com/questions/73881",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24045/"
] | I am trying to run the wp-cron.php manually by calling it that way:
```
http://mysite.com/wp-cron.php?doing_wp_cron
```
Disabling the auto cron function with :
```
define('DISABLE_WP_CRON', TRUE);
```
produces the same error.
What could be the issue? | If you're launching wp-cron manually you don't need the "doing\_wp\_cron" parameter. The fact that you have it and haven't given it a value is very likely to be what's causing your error. |
73,883 | <p>Using Wordpress 3.4.2, the wp_enqueue_script documentation seems to indicate that jQuery UI libraries can be loaded simply by referencing their handles. I have the following code with no prior wp_register_script():</p>
<pre><code>wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
</code></pre>
<p>T... | [
{
"answer_id": 73886,
"author": "kaiser",
"author_id": 385,
"author_profile": "https://wordpress.stackexchange.com/users/385",
"pm_score": 3,
"selected": false,
"text": "<p>I guess you have to <a href=\"http://codex.wordpress.org/Function_Reference/wp_enqueue_script\" rel=\"noreferrer\">... | 2012/11/25 | [
"https://wordpress.stackexchange.com/questions/73883",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24046/"
] | Using Wordpress 3.4.2, the wp\_enqueue\_script documentation seems to indicate that jQuery UI libraries can be loaded simply by referencing their handles. I have the following code with no prior wp\_register\_script():
```
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
```
The enqueue for 'jquery'... | I guess you have to [really read the Codex about `wp_enqueue_script()`](http://codex.wordpress.org/Function_Reference/wp_enqueue_script) again and then dig into jQuery a little bit more. jQuery UI is a *dependency* of jQuery (which means it *depends* on having jQuery loaded). So you need to load jQuery first, before l... |
73,890 | <p>I currently have the following trying to avoid showing tags (the icon in this case) when there aren't any, but the icon continues to show up. Any thoughts?</p>
<pre><code><?php if ( is_singular() && function_exists('the_tags') ) : ?>
<p><i class="icon-tags"></i><?php the_tags... | [
{
"answer_id": 73891,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 4,
"selected": true,
"text": "<p>Get a <strong>string</strong> value for the tags and print it only if there <em>are</em> tags:</p>\n\n<pre><code>$tags ... | 2012/11/25 | [
"https://wordpress.stackexchange.com/questions/73890",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1340/"
] | I currently have the following trying to avoid showing tags (the icon in this case) when there aren't any, but the icon continues to show up. Any thoughts?
```
<?php if ( is_singular() && function_exists('the_tags') ) : ?>
<p><i class="icon-tags"></i><?php the_tags('', ', ', ' '); ?></p>
<?php endif; ?>
``` | Get a **string** value for the tags and print it only if there *are* tags:
```
$tags = get_the_tag_list('', ', ', ' ');
if ( "" !== trim( $tags ) )
{
echo "<p><i class='icon-tags'></i>$tags</p>";
}
``` |
73,900 | <p>I need to add some html into the header.php but instead of directly changing the header.php of my theme or creating a child theme, how can I do it with just actions and/or hooks?</p>
| [
{
"answer_id": 73902,
"author": "Steve",
"author_id": 23132,
"author_profile": "https://wordpress.stackexchange.com/users/23132",
"pm_score": 0,
"selected": false,
"text": "<p>It all depends upon the theme, what you want to change, and if WordPress and/or the theme provide filters and ho... | 2012/11/25 | [
"https://wordpress.stackexchange.com/questions/73900",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15816/"
] | I need to add some html into the header.php but instead of directly changing the header.php of my theme or creating a child theme, how can I do it with just actions and/or hooks? | If you are looking to insert code into the `<head></head>` block, then this hook does it:
```
add_action( 'wp_head', 'wpse_73900_wp_head' );
function wpse_73900_wp_head()
{
?>
<!-- Custom Html --->
<?php
}
```
If that's not the case, then it's more difficult. I think it would depend on the theme providi... |
73,956 | <p>I have a product search widget when you select certain products a hidden field is shown. I would like to set a custom category in my widget options that is then used for displaying my hidden field. </p>
<p>I have the front end working 100% when I add the parent category_id manually to my code. Now I just need to se... | [
{
"answer_id": 73962,
"author": "HaneD",
"author_id": 23928,
"author_profile": "https://wordpress.stackexchange.com/users/23928",
"pm_score": 2,
"selected": true,
"text": "<p>I got it :-) thanks to <a href=\"https://wordpress.stackexchange.com/a/20034/23928\">this</a></p>\n\n<pre><code>f... | 2012/11/26 | [
"https://wordpress.stackexchange.com/questions/73956",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23928/"
] | I have a product search widget when you select certain products a hidden field is shown. I would like to set a custom category in my widget options that is then used for displaying my hidden field.
I have the front end working 100% when I add the parent category\_id manually to my code. Now I just need to set the cat... | I got it :-) thanks to [this](https://wordpress.stackexchange.com/a/20034/23928)
```
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
//Strip tags from title and name to remove HTML
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['kwtax... |
73,983 | <p>I have tried to create a function that generates a random slug when a post is created. I am a bit worried that the function generates non unique strings as slugs. How can I solve this?</p>
<p>The function looks like:</p>
<pre><code>add_filter('name_save_pre','unique_slug', 0);
function random_string() {
$leng... | [
{
"answer_id": 73985,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 3,
"selected": false,
"text": "<p>Use the function <a href=\"http://queryposts.com/function/wp_unique_post_slug/\" rel=\"nofollow\"><code>wp_unique_post... | 2012/11/26 | [
"https://wordpress.stackexchange.com/questions/73983",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24083/"
] | I have tried to create a function that generates a random slug when a post is created. I am a bit worried that the function generates non unique strings as slugs. How can I solve this?
The function looks like:
```
add_filter('name_save_pre','unique_slug', 0);
function random_string() {
$length = 6;
$characte... | I've found this plugin that should do the trick: <http://wordpress.org/extend/plugins/wp-hashed-ids/> |
73,996 | <p>I use a lot of embedded videos (via <code>oembed</code>) on my blog, and that can slow down page loads. </p>
<p>Is there a way to automatically replace YouTube (and other) videos with a thumbnail (preferably the post's featured image). And then replace the thumbnail with the video iframe when clicked?</p>
| [
{
"answer_id": 74026,
"author": "brasofilo",
"author_id": 12615,
"author_profile": "https://wordpress.stackexchange.com/users/12615",
"pm_score": 4,
"selected": true,
"text": "<h2>Notes</h2>\n\n<ul>\n<li>Solution for YouTube and Vimeo. </li>\n<li>Uses Featured Image or default thumbnail... | 2012/11/26 | [
"https://wordpress.stackexchange.com/questions/73996",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13504/"
] | I use a lot of embedded videos (via `oembed`) on my blog, and that can slow down page loads.
Is there a way to automatically replace YouTube (and other) videos with a thumbnail (preferably the post's featured image). And then replace the thumbnail with the video iframe when clicked? | Notes
-----
* Solution for YouTube and Vimeo.
* Uses Featured Image or default thumbnail from video provider.
* If more than one oEmbed exists in the same page, using the Featured Image provoques duplicate "thumbs".
* Post has to be updated before changes are seen.
* To do: `<iframe>` and `<img>` sizes, other oEmbeds.... |
73,997 | <p>Hey all i am wondering what i need to add in order to have a different sidebar for a set page?</p>
<p>I created a category for the page (<strong>called PatientEdu</strong>):</p>
<p><img src="https://i.stack.imgur.com/dsVaj.jpg" alt="patcat"></p>
<p>And made sure the page was linked to the category:</p>
<p><img s... | [
{
"answer_id": 74026,
"author": "brasofilo",
"author_id": 12615,
"author_profile": "https://wordpress.stackexchange.com/users/12615",
"pm_score": 4,
"selected": true,
"text": "<h2>Notes</h2>\n\n<ul>\n<li>Solution for YouTube and Vimeo. </li>\n<li>Uses Featured Image or default thumbnail... | 2012/11/26 | [
"https://wordpress.stackexchange.com/questions/73997",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8469/"
] | Hey all i am wondering what i need to add in order to have a different sidebar for a set page?
I created a category for the page (**called PatientEdu**):

And made sure the page was linked to the category:

But it still se... | Notes
-----
* Solution for YouTube and Vimeo.
* Uses Featured Image or default thumbnail from video provider.
* If more than one oEmbed exists in the same page, using the Featured Image provoques duplicate "thumbs".
* Post has to be updated before changes are seen.
* To do: `<iframe>` and `<img>` sizes, other oEmbeds.... |
73,999 | <h2>Problem</h2>
<p>I have a user based site, so when user <strong>deletes</strong> his profile somehow his/her comments stay visible.</p>
<p>There is no name and blank avatar with the comment. Is there any way to delete the comments of a user if the user deletes his/her profile and how? Is there a function of somehow?... | [
{
"answer_id": 74010,
"author": "Ralf912",
"author_id": 16589,
"author_profile": "https://wordpress.stackexchange.com/users/16589",
"pm_score": 1,
"selected": false,
"text": "<pre><code>add_action( 'deleted_user', 5, 1 );\n\nfunction delete_user_comments( $user_id = 0 ){\n\n if( 0 === $... | 2012/11/26 | [
"https://wordpress.stackexchange.com/questions/73999",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5499/"
] | Problem
-------
I have a user based site, so when user **deletes** his profile somehow his/her comments stay visible.
There is no name and blank avatar with the comment. Is there any way to delete the comments of a user if the user deletes his/her profile and how? Is there a function of somehow? This really is a stra... | +1 @toscho 's comment. This will break nested comment / conversation in comment. You should disable nested comments in the Settings.
Try this code. Note that this is not tested
```
add_action( 'delete_user', 'my_delete_user');
function my_delete_user($user_id) {
$user = get_user_by('id', $user_id);
// delet... |
74,001 | <p>This problem only occurs with the articles/blog posts on the homepage of the site, <a href="http://readbuzz.com" rel="nofollow">readbuzz.com</a>.</p>
<p>On the homepage of the site, the author's name is supposed to link to that particular author's post page, where all the blog posts the author posted on the website... | [
{
"answer_id": 74005,
"author": "Ralf912",
"author_id": 16589,
"author_profile": "https://wordpress.stackexchange.com/users/16589",
"pm_score": 0,
"selected": false,
"text": "<p>Look in the source code of your homepage. You will see that all links are empty:</p>\n\n<pre><code><a href=... | 2012/11/26 | [
"https://wordpress.stackexchange.com/questions/74001",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/20870/"
] | This problem only occurs with the articles/blog posts on the homepage of the site, [readbuzz.com](http://readbuzz.com).
On the homepage of the site, the author's name is supposed to link to that particular author's post page, where all the blog posts the author posted on the website will show up. Instead, each name th... | >
> The code below is the correct code, in several different PHP files.
> Currently need to know how to write it using the
> the\_author\_posts\_link();
>
>
>
> ```
> <p class="postAuthor">By <a href="<?php the_author_meta('user_url'); ?>"><?php the_author(); ?></a></p>
>
> ```
>
>
Just replace this:
```
<a ... |
74,009 | <p>I'm writing a plugin to do some specific business logic - edit records for authenticated users, etc.</p>
<p>Rather than having the overhead of a form processing plugin that uses stuff in template tags. I've created a rewrite do redirect like:</p>
<pre><code>/mylisting/909 ->/wp-content/themes/myplugin/edit.php... | [
{
"answer_id": 74020,
"author": "Steve",
"author_id": 23132,
"author_profile": "https://wordpress.stackexchange.com/users/23132",
"pm_score": 2,
"selected": false,
"text": "<blockquote>\n <p>The problem is, I want to use my theme within my plugins files as\n they'll be output in the si... | 2012/11/26 | [
"https://wordpress.stackexchange.com/questions/74009",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/18936/"
] | I'm writing a plugin to do some specific business logic - edit records for authenticated users, etc.
Rather than having the overhead of a form processing plugin that uses stuff in template tags. I've created a rewrite do redirect like:
```
/mylisting/909 ->/wp-content/themes/myplugin/edit.php?id=909
```
Which seem... | >
> I've created a rewrite do redirect like:
>
>
>
> ```
> /mylisting/909 ->/wp-content/themes/myplugin/edit.php?id=909
>
> ```
>
> Which seems to make sense as I'm keeping the very specific logic to an individual plugin.
>
>
>
There is a better way: [Create an endpoint](https://wordpress.stackexchange.com/a... |
74,013 | <p>I am building a theme, and in the options I have created a place for link color. I cant seem to get this into the theme in any reasonable way. The best I can do is to put it after <code>wp_head</code> ... but that doesn't seem right. The color will be a hex color so I cant just set up style sheets for a fixed number... | [
{
"answer_id": 74023,
"author": "Wyck",
"author_id": 1509,
"author_profile": "https://wordpress.stackexchange.com/users/1509",
"pm_score": 1,
"selected": false,
"text": "<p><code>wp_head</code> is typically how it is done, at least for small cosmetic changes. What you should check out is... | 2012/11/26 | [
"https://wordpress.stackexchange.com/questions/74013",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/6169/"
] | I am building a theme, and in the options I have created a place for link color. I cant seem to get this into the theme in any reasonable way. The best I can do is to put it after `wp_head` ... but that doesn't seem right. The color will be a hex color so I cant just set up style sheets for a fixed number of colors and... | You would simply call that option inside of a callback, and hook it into `wp_print_styles` or `wp_head` (either one is semantically correct in this case).
First, set up your callback, which will print an *inline style sheet*:
```
function wpse74013_print_custom_styles() {
?>
<style type="text/css">
</style>
... |
74,017 | <p>Usually, if I want to check for some attribute of the post I'm about to publish, I will check like this:</p>
<pre><code>$post_title = $_POST['post_title'];
</code></pre>
<p>post_title is the name of the title field in the edit window.</p>
<p>I thought I'd apply the same logic to the taxonomy meta box.</p>
<pre><... | [
{
"answer_id": 74024,
"author": "chrisguitarguy",
"author_id": 6035,
"author_profile": "https://wordpress.stackexchange.com/users/6035",
"pm_score": 1,
"selected": true,
"text": "<p>You're on the right track.</p>\n\n<p>When you do something like this in a form..</p>\n\n<pre><code><inp... | 2012/11/26 | [
"https://wordpress.stackexchange.com/questions/74017",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10099/"
] | Usually, if I want to check for some attribute of the post I'm about to publish, I will check like this:
```
$post_title = $_POST['post_title'];
```
post\_title is the name of the title field in the edit window.
I thought I'd apply the same logic to the taxonomy meta box.
```
$formats = $_POST['tax_input[formats][... | You're on the right track.
When you do something like this in a form..
```
<input name="tax_input[formats][]" />
```
You create levels in the `$_POST` array.
So you'd get the formats array like this...
```
<?php
$formats = $_POST['tax_input']['formats'];
```
Full example...
```
<?php
add_action('save_post', '... |
74,034 | <p>The below code is for listing the custom post types itself and its children in the sidebar.
The code works great but does not highlight the sub pages.</p>
<p>In <code>functions.php</code>:</p>
<pre><code>if(!function_exists('get_post_top_ancestor_id')){
/**
* Gets the id of the topmost ancestor of the current page... | [
{
"answer_id": 74024,
"author": "chrisguitarguy",
"author_id": 6035,
"author_profile": "https://wordpress.stackexchange.com/users/6035",
"pm_score": 1,
"selected": true,
"text": "<p>You're on the right track.</p>\n\n<p>When you do something like this in a form..</p>\n\n<pre><code><inp... | 2012/11/27 | [
"https://wordpress.stackexchange.com/questions/74034",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24100/"
] | The below code is for listing the custom post types itself and its children in the sidebar.
The code works great but does not highlight the sub pages.
In `functions.php`:
```
if(!function_exists('get_post_top_ancestor_id')){
/**
* Gets the id of the topmost ancestor of the current page. Returns the current
* page's i... | You're on the right track.
When you do something like this in a form..
```
<input name="tax_input[formats][]" />
```
You create levels in the `$_POST` array.
So you'd get the formats array like this...
```
<?php
$formats = $_POST['tax_input']['formats'];
```
Full example...
```
<?php
add_action('save_post', '... |
74,052 | <p>I cant get the comments template to show up in my single-events.php </p>
<p>This is my code</p>
<pre><code><?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'events' ); ?>
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
</cod... | [
{
"answer_id": 74166,
"author": "manish",
"author_id": 24162,
"author_profile": "https://wordpress.stackexchange.com/users/24162",
"pm_score": 0,
"selected": false,
"text": "<p>I am using </p>\n\n<pre><code>comments_template('/single-comment.php');\n</code></pre>\n\n<p><code>single-comme... | 2012/11/27 | [
"https://wordpress.stackexchange.com/questions/74052",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23833/"
] | I cant get the comments template to show up in my single-events.php
This is my code
```
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'events' ); ?>
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
```
If I put the comments template in my events ... | Here's 2 solutions i tested:
Try adding support for comments in your custom post type code
```
'supports' => array( 'comments' ),
```
You could also use `add_post_type_support`
```
add_action('init', 'wpsites_comments');
function wpsites_comments() {
add_post_type_support( 'events', 'comments' );
}
```
[Cod... |
74,063 | <p>I am trying to fetch all direct children of a page. But I am getting all children and grand children as well. Any ideas?</p>
<p><strong>PHP Source:</strong></p>
<pre><code>$args = array(
'child_of' => $post->ID,
'parent ' => $post->ID,
'hierarchical' => 0,
'sort_col... | [
{
"answer_id": 74068,
"author": "realloc",
"author_id": 6972,
"author_profile": "https://wordpress.stackexchange.com/users/6972",
"pm_score": 5,
"selected": true,
"text": "<p>Please check the parameter 'parent'. It seems there is a space after the name.</p>\n"
},
{
"answer_id": 1... | 2012/11/27 | [
"https://wordpress.stackexchange.com/questions/74063",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24112/"
] | I am trying to fetch all direct children of a page. But I am getting all children and grand children as well. Any ideas?
**PHP Source:**
```
$args = array(
'child_of' => $post->ID,
'parent ' => $post->ID,
'hierarchical' => 0,
'sort_column' => 'menu_order',
'sort_order' => 'a... | Please check the parameter 'parent'. It seems there is a space after the name. |
74,064 | <p>I have a query for a custom post type:</p>
<pre><code><?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$books = new WP_Query(array(
'post_type' => 'wiki',
'posts_per_page' => '50',
'paged' => $paged
));
?>
</code></pre>
<p>And i want to loop through these posts using... | [
{
"answer_id": 74066,
"author": "Johannes Pille",
"author_id": 9745,
"author_profile": "https://wordpress.stackexchange.com/users/9745",
"pm_score": 4,
"selected": true,
"text": "<p>You will either need to globalize <code>$books</code> (if you want to stick to <code>get_template_part()</... | 2012/11/27 | [
"https://wordpress.stackexchange.com/questions/74064",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8038/"
] | I have a query for a custom post type:
```
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$books = new WP_Query(array(
'post_type' => 'wiki',
'posts_per_page' => '50',
'paged' => $paged
));
?>
```
And i want to loop through these posts using the loop-books.php:
```
<?php get_templ... | You will either need to globalize `$books` (if you want to stick to `get_template_part()` ) or use
```
require( locate_template( 'loop-books.php' ) );
```
instead of `get_template_part( 'loop', 'books' );`. This issue is caused by `$books` in `loop-books.php` being defined only in the [scope](http://php.net/manual/e... |
74,070 | <p>I've learned just a slight bit with WordPress Rewrite API -- just enough to add another rewrite rule for a plugin. The plugin works if installed in the root, but I'm finding that if one installs WordPress in a subdir, then I need to do the following changes to the .htaccess file. I'd like to know how to automate the... | [
{
"answer_id": 74073,
"author": "Sawant",
"author_id": 24118,
"author_profile": "https://wordpress.stackexchange.com/users/24118",
"pm_score": 1,
"selected": false,
"text": "<p>If you don't want Wordpress to overwrite your changes in .htaccess file, then make sure that you write your cha... | 2012/11/27 | [
"https://wordpress.stackexchange.com/questions/74070",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13/"
] | I've learned just a slight bit with WordPress Rewrite API -- just enough to add another rewrite rule for a plugin. The plugin works if installed in the root, but I'm finding that if one installs WordPress in a subdir, then I need to do the following changes to the .htaccess file. I'd like to know how to automate these ... | If you don't want Wordpress to overwrite your changes in .htaccess file, then make sure that you write your changes outside of the Wordpress comment block, that is, either before or after this:
```
# BEGIN WordPress
...
# END WordPress
```
Think of this area as Wordpress' territory. Anything within this block, will ... |
74,072 | <p>while writing new code and testing it, I incorporate it into my site by testing for the remote IP address as follows; i.e., I'm the only one who will see the new code:</p>
<p>in <code>/functions.php</code>:</p>
<pre><code>// to hide certain sections/features from people other than myself
$myIP = '219.88.88.88'; // t... | [
{
"answer_id": 74073,
"author": "Sawant",
"author_id": 24118,
"author_profile": "https://wordpress.stackexchange.com/users/24118",
"pm_score": 1,
"selected": false,
"text": "<p>If you don't want Wordpress to overwrite your changes in .htaccess file, then make sure that you write your cha... | 2012/11/27 | [
"https://wordpress.stackexchange.com/questions/74072",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15311/"
] | while writing new code and testing it, I incorporate it into my site by testing for the remote IP address as follows; i.e., I'm the only one who will see the new code:
in `/functions.php`:
```
// to hide certain sections/features from people other than myself
$myIP = '219.88.88.88'; // the value as currently indicate... | If you don't want Wordpress to overwrite your changes in .htaccess file, then make sure that you write your changes outside of the Wordpress comment block, that is, either before or after this:
```
# BEGIN WordPress
...
# END WordPress
```
Think of this area as Wordpress' territory. Anything within this block, will ... |
74,076 | <p>I have a page.php and single.php template that are 100% identical. Yet, when I render page.php the div don't get nested in the same way as single.php and the layout gets broken.</p>
<p>I've even diff'd the output of the two pages and, with the exception of the meta and non visible elements, they are also 100% ident... | [
{
"answer_id": 74078,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 4,
"selected": true,
"text": "<h2>Edit</h2>\n\n<p>Based on this comment:</p>\n\n<blockquote>\n <p>commenting out comments_template works.</p... | 2012/11/27 | [
"https://wordpress.stackexchange.com/questions/74076",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/890/"
] | I have a page.php and single.php template that are 100% identical. Yet, when I render page.php the div don't get nested in the same way as single.php and the layout gets broken.
I've even diff'd the output of the two pages and, with the exception of the meta and non visible elements, they are also 100% identical.
Fol... | Edit
----
Based on this comment:
>
> commenting out comments\_template works.
>
>
>
The problem lies in the template markup in `comments.php`. The likely reason that you see it in some output and not others is likely because you've got comments enabled in one context, and not in the other. Try comparing single p... |
74,082 | <p>I have the following code inside my single.php page:</p>
<p><strong>UPDATED CODE</strong></p>
<pre><code> <?php if (have_posts()) : the_post();
$post_id = get_the_ID();
if ( is_single() ) {
$cats = get_the_category();
$cat = $cats[0];
} else {
// category archives
$c... | [
{
"answer_id": 74085,
"author": "totels",
"author_id": 23446,
"author_profile": "https://wordpress.stackexchange.com/users/23446",
"pm_score": -1,
"selected": false,
"text": "<p>WP codex is your best friend:</p>\n\n<p>From <code>query_posts</code> <a href=\"http://codex.wordpress.org/Fun... | 2012/11/27 | [
"https://wordpress.stackexchange.com/questions/74082",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8469/"
] | I have the following code inside my single.php page:
**UPDATED CODE**
```
<?php if (have_posts()) : the_post();
$post_id = get_the_ID();
if ( is_single() ) {
$cats = get_the_category();
$cat = $cats[0];
} else {
// category archives
$cat = get_category( get_query_var( 'ca... | Your problem is that you're using **`query_posts()`**, when you need to be using [**`WP_Query()`**](http://codex.wordpress.org/Class_Reference/WP_Query). To display all posts (by ignoring pagination, use the [`posts_per_page` parameter](http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters):
```
$c... |
74,089 | <p>I've done some searches here and on Google but everything I'm finding isn't working correctly. I was hoping to post my code here and get help with where I'm going wrong. </p>
<p>On the index page of my site, I have one "featured" post that has a different layout than the rest of the posts. When you click to the nex... | [
{
"answer_id": 74085,
"author": "totels",
"author_id": 23446,
"author_profile": "https://wordpress.stackexchange.com/users/23446",
"pm_score": -1,
"selected": false,
"text": "<p>WP codex is your best friend:</p>\n\n<p>From <code>query_posts</code> <a href=\"http://codex.wordpress.org/Fun... | 2012/11/27 | [
"https://wordpress.stackexchange.com/questions/74089",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7662/"
] | I've done some searches here and on Google but everything I'm finding isn't working correctly. I was hoping to post my code here and get help with where I'm going wrong.
On the index page of my site, I have one "featured" post that has a different layout than the rest of the posts. When you click to the next page, th... | Your problem is that you're using **`query_posts()`**, when you need to be using [**`WP_Query()`**](http://codex.wordpress.org/Class_Reference/WP_Query). To display all posts (by ignoring pagination, use the [`posts_per_page` parameter](http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters):
```
$c... |
74,097 | <p>What I'm trying to do is display the most recent post (a la my theme's "single.php") on my "home" page. </p>
<p>This is complicated by the fact that I have certain plugins (specifically, Scripts n Styles) that are hooking wp_head and wp_enqueue_scripts. In these hooks, they are checking is_singular() to see if my... | [
{
"answer_id": 74106,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 1,
"selected": false,
"text": "<p>I'm not sure how plugin hooks would impact in any way the solution to your problem. The <code>home.php</cod... | 2012/11/27 | [
"https://wordpress.stackexchange.com/questions/74097",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24125/"
] | What I'm trying to do is display the most recent post (a la my theme's "single.php") on my "home" page.
This is complicated by the fact that I have certain plugins (specifically, Scripts n Styles) that are hooking wp\_head and wp\_enqueue\_scripts. In these hooks, they are checking is\_singular() to see if my per-pos... | [Chip's answer](https://wordpress.stackexchange.com/a/74106/24125) helped me fix the error, but it took a bit more tweaking to get it fully solved.
With a static front page, the `front-page.php` template will be called (as per the [hierarchy](http://codex.wordpress.org/Template_Hierarchy)) with `$wp_query` populated ... |
74,099 | <p>Hi I'm try to get an if statement to work.</p>
<p>I want to display some HTML code if the post is created by a specific author.</p>
<p>This is what I'm come up with but it doesn't work.</p>
<pre><code><?php if ( get_posts ($post->ID, 'post_author', true) == '20')
{ ?> HTML <?php } ?>
</code></p... | [
{
"answer_id": 74101,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 0,
"selected": false,
"text": "<p>Assuming you're inside the loop, you can use <a href=\"http://codex.wordpress.org/Function_Reference/get_th... | 2012/11/27 | [
"https://wordpress.stackexchange.com/questions/74099",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24126/"
] | Hi I'm try to get an if statement to work.
I want to display some HTML code if the post is created by a specific author.
This is what I'm come up with but it doesn't work.
```
<?php if ( get_posts ($post->ID, 'post_author', true) == '20')
{ ?> HTML <?php } ?>
```
Thank You | The `get_posts()` function retrieves posts from the database. If I understand you correctly, that's not what you want though, you simply mean to check the author of the post currently displayed.
You can simply use `$post->post_author`. If outside [the Loop](http://codex.wordpress.org/The_Loop), you have to call upon t... |
74,141 | <p>whewn ever i try to login <a href="http://affiliatesurge.com.au/wp-admin/" rel="nofollow">http://affiliatesurge.com.au/wp-admin/</a></p>
<p>i got ""
Warning: Cannot modify header information - headers already sent by (output started at /home/affiliat/public_html/wp-config.php:1) in /home/affiliat/public_html/wp-inc... | [
{
"answer_id": 74154,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 2,
"selected": false,
"text": "<p>You saved your <code>wp-config.php</code> with a <a href=\"http://en.wikipedia.org/wiki/Byte_order_mark#UTF-8\" rel=\"... | 2012/11/28 | [
"https://wordpress.stackexchange.com/questions/74141",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24145/"
] | whewn ever i try to login <http://affiliatesurge.com.au/wp-admin/>
i got ""
Warning: Cannot modify header information - headers already sent by (output started at /home/affiliat/public\_html/wp-config.php:1) in /home/affiliat/public\_html/wp-includes/pluggable.php on line 881 ""
Error ... i already try removing spaci... | You saved your `wp-config.php` with a [Byte order mark (BOM)](http://en.wikipedia.org/wiki/Byte_order_mark#UTF-8). Save the file again without the BOM.
In Linux or Mac OS X open the file with [Vim](http://www.vim.org/), enter …
```
:set nobomb
```
… and save it.
In Windows open it in [Notepad++](http://notepad-plu... |
74,145 | <p>I am setting up a "built in" contact form that I need to pull the administrators email address from an external php page. </p>
<p>For instance, my form <code>action="path/to/process_form.php"</code></p>
<p>Within that <code>proces_form.php</code> I have a few options set up. </p>
<pre><code>$msg = "Form Contents:... | [
{
"answer_id": 74147,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 0,
"selected": false,
"text": "<p>You won't be able to <code>include</code> it without executing it, and it looks like that would be a problem.... | 2012/11/28 | [
"https://wordpress.stackexchange.com/questions/74145",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14000/"
] | I am setting up a "built in" contact form that I need to pull the administrators email address from an external php page.
For instance, my form `action="path/to/process_form.php"`
Within that `proces_form.php` I have a few options set up.
```
$msg = "Form Contents: \n\n";
foreach ($this->fields as $key => $field)
... | How about this:
```
<?php
// Connect to WP
require('/path/to/wp-blog-header.php');
global $wpdb;
$admin_email = get_option( 'admin_email' ); ?>
$msg = "Form Contents: \n\n";
foreach ($this->fields as $key => $field)
$msg .= "$key : $field \n";
$to = $admin_email;
$subject = 'New Form Submission';
$from = $t... |
74,169 | <p>When you're editing a post and select a child category or term, and update, the selected terms appear at the top ( leading to potentially confusing situations where 'foo' 'foo' and 'foo' are selected each with different parents and no way to tell them apart ).</p>
<p>How do I prevent this behaviour? Either by showi... | [
{
"answer_id": 74211,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 3,
"selected": true,
"text": "<p>This bugs me too. It is very confusing, so I thought I'd look into it. </p>\n\n<p>That meta box is created in ... | 2012/11/28 | [
"https://wordpress.stackexchange.com/questions/74169",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/736/"
] | When you're editing a post and select a child category or term, and update, the selected terms appear at the top ( leading to potentially confusing situations where 'foo' 'foo' and 'foo' are selected each with different parents and no way to tell them apart ).
How do I prevent this behaviour? Either by showing the par... | This bugs me too. It is very confusing, so I thought I'd look into it.
That meta box is created in ["wp-admin/includes/meta-boxes.php" on line ~399](http://core.trac.wordpress.org/browser/trunk/wp-admin/includes/meta-boxes.php#L399). It uses [`wp_terms_checklist`](http://codex.wordpress.org/Function_Reference/wp_term... |
74,175 | <p>I've successfully added a custom post type.</p>
<pre><code>register_post_type('case',
array(
'labels' => array(
'name' => __('Cases'),
'singular_name' => __('Case')
),
'public' => true,
'has_archive' => true,
... | [
{
"answer_id": 74177,
"author": "Philip",
"author_id": 19188,
"author_profile": "https://wordpress.stackexchange.com/users/19188",
"pm_score": 1,
"selected": false,
"text": "<p>I got it by searching some more on google.</p>\n\n<pre><code>'has_archive' => true,\n</code></pre>\n\n<p>Thi... | 2012/11/28 | [
"https://wordpress.stackexchange.com/questions/74175",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/19188/"
] | I've successfully added a custom post type.
```
register_post_type('case',
array(
'labels' => array(
'name' => __('Cases'),
'singular_name' => __('Case')
),
'public' => true,
'has_archive' => true,
'supports' => array('... | I got it by searching some more on google.
```
'has_archive' => true,
```
This line is vital.
Found out I had to rename my custom template pages to **archive-"the custom type name"** which in this case was.
```
archive-case.php
```
Because of this I could remove my "static" page called case and let the system pi... |
74,180 | <p>I am using Wordpress media uploader to upload images and I was wondering if there is a way to make it upload to my remote server instead of my local server? Example: My wordpress blog is hosted on Server A and I want to want to use the media uploader to upload images to Server B instead of Server A.</p>
<p>Both ser... | [
{
"answer_id": 78075,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": -1,
"selected": false,
"text": "<p>You can use <a href=\"http://en.wikipedia.org/wiki/SSHFS\" rel=\"nofollow\">SSHFS</a> or <a href=\"http:/... | 2012/11/28 | [
"https://wordpress.stackexchange.com/questions/74180",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17971/"
] | I am using Wordpress media uploader to upload images and I was wondering if there is a way to make it upload to my remote server instead of my local server? Example: My wordpress blog is hosted on Server A and I want to want to use the media uploader to upload images to Server B instead of Server A.
Both servers run U... | I have just built a plugin that does this. It is not perfect but it do its job.
You can find it in my Github: <https://github.com/pontusab/wp-ftp-media-library>
So you need to change some things within the file on the row 28:
```
/**
* Change this to match your server
* You only need to change the those w... |
74,220 | <p>I need to get logged in user id inside my plugin.</p>
<p>Is this the proper way?</p>
<pre><code>$root = dirname(dirname(dirname(dirname(__FILE__))));
if (file_exists($root.'/wp-load.php')) {
require_once($root.'/wp-load.php');
}
$user_id = get_current_user_id();
</code></pre>
<p><a href="http://ottopress.com/201... | [
{
"answer_id": 74221,
"author": "EAMann",
"author_id": 46,
"author_profile": "https://wordpress.stackexchange.com/users/46",
"pm_score": 2,
"selected": true,
"text": "<p>If you're inside a plugin, WordPress is already loaded. You don't need to load it yourself.</p>\n\n<p>Inside whatever... | 2012/11/28 | [
"https://wordpress.stackexchange.com/questions/74220",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5074/"
] | I need to get logged in user id inside my plugin.
Is this the proper way?
```
$root = dirname(dirname(dirname(dirname(__FILE__))));
if (file_exists($root.'/wp-load.php')) {
require_once($root.'/wp-load.php');
}
$user_id = get_current_user_id();
```
[Otto saying](http://ottopress.com/2010/dont-include-wp-load-pleas... | If you're inside a plugin, WordPress is already loaded. You don't need to load it yourself.
Inside whatever function needs the user ID, you need to do two things:
1. Globalize the user data variable
2. Populate the user data variable
Here's some pseudocode:
```
function some_function_that_needs_user_info() {
gl... |
74,230 | <p>Can someone tell me how to wrap the Read More anchor (that displays after an excerpt) with DIV tags using <code>get_the_content('Read More')</code>?</p>
| [
{
"answer_id": 74233,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 3,
"selected": true,
"text": "<p>Put a filter on <a href=\"http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/post-template.php#L217... | 2012/11/28 | [
"https://wordpress.stackexchange.com/questions/74230",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1462/"
] | Can someone tell me how to wrap the Read More anchor (that displays after an excerpt) with DIV tags using `get_the_content('Read More')`? | Put a filter on [`the_content_more_link`](http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/post-template.php#L217).
Untested but...
```
function wrap_more_link($more) {
return '<div>'.$more.'</div>';
}
add_filter('the_content_more_link','wrap_more_link');
``` |
74,235 | <p>The function below is used to show certain content after the first paragraph. I would like to show 'content X' after the 1st paragraph and 'content Y' after 2nd paragraph.</p>
<pre><code><?php
$paragraphAfter= 1; //display after the first paragraph
$content = apply_filters('the_content', get_the_content());
$con... | [
{
"answer_id": 74242,
"author": "Max Yudin",
"author_id": 11761,
"author_profile": "https://wordpress.stackexchange.com/users/11761",
"pm_score": 4,
"selected": true,
"text": "<p>My way to do this (<strong>see update below</strong>):</p>\n\n<pre><code>function addParagraphs($content) {\n... | 2012/11/28 | [
"https://wordpress.stackexchange.com/questions/74235",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12990/"
] | The function below is used to show certain content after the first paragraph. I would like to show 'content X' after the 1st paragraph and 'content Y' after 2nd paragraph.
```
<?php
$paragraphAfter= 1; //display after the first paragraph
$content = apply_filters('the_content', get_the_content());
$content = explode("<... | My way to do this (**see update below**):
```
function addParagraphs($content) {
// you can add as many as you want:
$additions = array(
'<p>After 1st paragraph</p>',
'<p>After 2nd paragraph</p>'
);
$content = get_the_content();
$output = ''; // define variable to avoid PHP warnin... |
74,311 | <p>I'm struggling to figure out how to use wp_handle_upload() with ajax when processing a form. What I'm doing here is using a form to allow users to edit posts from the front end so they can do some things like change the image for a post so we'll start there.</p>
<p>I'm gonna leave out chunks of this function to kee... | [
{
"answer_id": 74320,
"author": "Bainternet",
"author_id": 2487,
"author_profile": "https://wordpress.stackexchange.com/users/2487",
"pm_score": 3,
"selected": true,
"text": "<p>Uploading files in ajax is a bit tricky because it is not possible to upload files using the browser's XMLHttp... | 2012/11/29 | [
"https://wordpress.stackexchange.com/questions/74311",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12700/"
] | I'm struggling to figure out how to use wp\_handle\_upload() with ajax when processing a form. What I'm doing here is using a form to allow users to edit posts from the front end so they can do some things like change the image for a post so we'll start there.
I'm gonna leave out chunks of this function to keep it sim... | Uploading files in ajax is a bit tricky because it is not possible to upload files using the browser's XMLHttpRequest object so you need to use some kind of Ajax upload plugin.
Also `wp_handle_upload()` is not what your using in your code its `media_handle_sideload()`
* `wp_handle_upload()` - should be used for file ... |
74,325 | <p>Hi I have page displaying 20 featured images and info of a specific category, I wish to able to have pagination so I can have multiple pages for the category.</p>
<p>How do I do this? I cant seem to get it work.</p>
<p>Any help would be appreciated </p>
<p>Thanks</p>
<pre><code><?php get_header(); ?>
<d... | [
{
"answer_id": 74341,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 0,
"selected": false,
"text": "<p>You are not passing any pagination parameters. Like this, <a href=\"http://codex.wordpress.org/Class_Referenc... | 2012/11/29 | [
"https://wordpress.stackexchange.com/questions/74325",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17112/"
] | Hi I have page displaying 20 featured images and info of a specific category, I wish to able to have pagination so I can have multiple pages for the category.
How do I do this? I cant seem to get it work.
Any help would be appreciated
Thanks
```
<?php get_header(); ?>
<div class="modus-grid">
<?php query_post... | The problem exists because you are using `query_posts()`, instead of properly filtering the main query via `pre_get_posts`.
Remove your `query_posts()` call from the template file, then add the following to functions.php:
```
function wpse74325_pre_get_posts( $query ) {
if ( $query->is_main_query() && is_category... |
74,340 | <p>I just installed Wordpress. I have a non Wordpress splash page at [root folder]/index.html. I'd like to keep the splash page up while I work on skinning Wordpress. When I try to access index.php (also in the root folder), it rewrites the url to index.html. I don't see index.html in the url but the splash page is... | [
{
"answer_id": 74343,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 1,
"selected": false,
"text": "<p>Try this.</p>\n\n<pre><code>function temp_page_redirect() {\n if (!current_user_can('administrator')) {\n ... | 2012/11/29 | [
"https://wordpress.stackexchange.com/questions/74340",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/22989/"
] | I just installed Wordpress. I have a non Wordpress splash page at [root folder]/index.html. I'd like to keep the splash page up while I work on skinning Wordpress. When I try to access index.php (also in the root folder), it rewrites the url to index.html. I don't see index.html in the url but the splash page is there ... | Either use a plugin (like [wp-maintenance-mode](http://wordpress.org/extend/plugins/wp-maintenance-mode/)) or hardcode your .htaccess file to redirect to the splash page, and allow your own (or your team) IP address to ignore the redirect. Like this:
```
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_... |