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 |
|---|---|---|---|---|---|---|
29,239 | <p>I'm curious if there is a known issue with WordPress or PHP where the environment may degrade to a point where WordPress simply ignores calls to register_activation_hook(). I was pulling my hair out for an hour on my local environment running MAMP when I had a coworker test the code on her machine; exact same code w... | [
{
"answer_id": 29263,
"author": "davidfrey",
"author_id": 7952,
"author_profile": "https://wordpress.stackexchange.com/users/7952",
"pm_score": 2,
"selected": false,
"text": "<p>I feel a bit dense for not noticing this sooner, but I finally realized that my plugins directory on my comput... | 2011/09/22 | [
"https://wordpress.stackexchange.com/questions/29239",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7952/"
] | I'm curious if there is a known issue with WordPress or PHP where the environment may degrade to a point where WordPress simply ignores calls to register\_activation\_hook(). I was pulling my hair out for an hour on my local environment running MAMP when I had a coworker test the code on her machine; exact same code wo... | After a little more thought, I think using a resolved path lookup might be safer:
```
function plugin_symlink_path( $file )
{
// If the file is already in the plugin directory we can save processing time.
if ( preg_match( '/'.preg_quote( WP_PLUGIN_DIR, '/' ).'/i', $file ) ) return $file;
// Examine each s... |
29,241 | <p>I've been trying to update my theme location programmtically and while the menu gets created with menu items, the theme location never gets set.</p>
<p>Here is what I have:</p>
<pre><code>function create_my_menu() {
if(!is_nav_menu('primary-menu')) {
$menu_id = wp_create_nav_menu('primary-menu');
//$menu = arr... | [
{
"answer_id": 29242,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 1,
"selected": false,
"text": "<p>Generally speaking, you shouldn't be (or need to be) \"updating\" the <code>theme_location</code> for a cus... | 2011/09/23 | [
"https://wordpress.stackexchange.com/questions/29241",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8882/"
] | I've been trying to update my theme location programmtically and while the menu gets created with menu items, the theme location never gets set.
Here is what I have:
```
function create_my_menu() {
if(!is_nav_menu('primary-menu')) {
$menu_id = wp_create_nav_menu('primary-menu');
//$menu = array( 'menu-item-type' ... | Generally speaking, you shouldn't be (or need to be) "updating" the `theme_location` for a custom nav menu. The `theme_location` is the **template location** for a given nav menu.
If you need to do dynamic manipulation of a custom nav menu, you might be better off targeting the `id` of the menu, rather than the `theme... |
29,258 | <p>I would like to show a different sidebar for 2 specific posts(same custom post type). I understand how to do this using separate templates for different pages, but I want to have it all happen in the single-posttype.php page. Or am I thinking about this wrong? My end goal is to show different text widgets in the sid... | [
{
"answer_id": 29260,
"author": "Brooke.",
"author_id": 2204,
"author_profile": "https://wordpress.stackexchange.com/users/2204",
"pm_score": 3,
"selected": true,
"text": "<p>I think <a href=\"http://wordpress.org/extend/plugins/widget-logic/\" rel=\"nofollow\">Widget Logic</a> is what y... | 2011/09/23 | [
"https://wordpress.stackexchange.com/questions/29258",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7318/"
] | I would like to show a different sidebar for 2 specific posts(same custom post type). I understand how to do this using separate templates for different pages, but I want to have it all happen in the single-posttype.php page. Or am I thinking about this wrong? My end goal is to show different text widgets in the sideba... | I think [Widget Logic](http://wordpress.org/extend/plugins/widget-logic/) is what you're looking for. It adds a field to each widget to allow you to specify which post get which widgets. It uses the standard [Conditional Tags](http://codex.wordpress.org/Conditional_Tags) making it easy to use. You'd just want to do som... |
29,266 | <p>this is the correct solution</p>
<pre><code><?php $meta_cat_name = get_post_meta( $post->ID, 'related blog articles', true ); if( !empty( $meta_cat_name ) ): $my_query = new WP_Query( array( 'category_name' => $meta_cat_name, 'posts_per_page' => 5, ) ); if ( $my_query->have_posts() ): while ( $my_que... | [
{
"answer_id": 29268,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 0,
"selected": false,
"text": "<p>move your <code>get_post_meta</code> call outside the query and check if it's not empty first:</p>\n\n<pre><code>&l... | 2011/09/23 | [
"https://wordpress.stackexchange.com/questions/29266",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8824/"
] | this is the correct solution
```
<?php $meta_cat_name = get_post_meta( $post->ID, 'related blog articles', true ); if( !empty( $meta_cat_name ) ): $my_query = new WP_Query( array( 'category_name' => $meta_cat_name, 'posts_per_page' => 5, ) ); if ( $my_query->have_posts() ): while ( $my_query->have_posts() ) : $my_quer... | ```
<?php
$metacatname = get_post_meta( $post->ID, 'related blog articles', true );
if(!(empty( $metacatname ))):
$my_query = new WP_Query( array(
'category_name' => $meta_cat_name,
'posts_per_page' => 5,
) );... |
29,283 | <p>Hello I've been struggling for ages trying to find a solution for this. Basically I just want to retrieve all images from a post and display a caption underneath. Here is the code i'm using:</p>
<pre><code> <?php
$argsThumb = array(
'order' => 'DESC',
'post_type' => 'attachment',
... | [
{
"answer_id": 29288,
"author": "Michael",
"author_id": 4884,
"author_profile": "https://wordpress.stackexchange.com/users/4884",
"pm_score": 1,
"selected": false,
"text": "<p>the following should just show the caption:</p>\n\n<pre><code>echo '<div class=\"slideshow-content\"><i... | 2011/09/23 | [
"https://wordpress.stackexchange.com/questions/29283",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8893/"
] | Hello I've been struggling for ages trying to find a solution for this. Basically I just want to retrieve all images from a post and display a caption underneath. Here is the code i'm using:
```
<?php
$argsThumb = array(
'order' => 'DESC',
'post_type' => 'attachment',
'post_parent' => ... | the following should just show the caption:
```
echo '<div class="slideshow-content"><img src="'.wp_get_attachment_url($attachment->ID, 'thumbnail', false, false).'" /><div class="captions">'.apply_filters('the_excerpt', $attachment->post_excerpt).'</div></div>';
```
(applying the excerpt filter adds the paragraph t... |
29,286 | <p>I am using a version of this (http://www.deluxeblogtips.com/meta-box-script-for-wordpress/) meta box script but I want to be able to limit which edit screen a meta box shows.</p>
<p>For example, if I only want a meta box to show in the "contact" page edit screen, is that possible?</p>
<pre><code>$meta_boxes[] = ar... | [
{
"answer_id": 29291,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 3,
"selected": true,
"text": "<p>Inside your <code>add_meta_boxex</code> hook callback function, you will have an <code>add_meta_box()</code>... | 2011/09/23 | [
"https://wordpress.stackexchange.com/questions/29286",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7999/"
] | I am using a version of this (http://www.deluxeblogtips.com/meta-box-script-for-wordpress/) meta box script but I want to be able to limit which edit screen a meta box shows.
For example, if I only want a meta box to show in the "contact" page edit screen, is that possible?
```
$meta_boxes[] = array(
'id' => 'project... | Inside your `add_meta_boxex` hook callback function, you will have an `add_meta_box()` call. Wrap that call in a conditional, using data from the `$post` global (I'm *fairly certain* it is available in `edit.php`). For example, you could use either the Page ID or slug.
Page ID:
```
global $post;
if ( '123' == $post->... |
29,322 | <h2>Edit: Important note for WordPress v4.4 onward</h2>
<p>This question used a great workaround for the lack of real term meta in older versions of WordPress, but since the release of WordPress v4.4, <a href="https://codex.wordpress.org/Function_Reference/add_term_meta" rel="nofollow noreferrer">real term meta has be... | [
{
"answer_id": 29326,
"author": "Dave Romsey",
"author_id": 2807,
"author_profile": "https://wordpress.stackexchange.com/users/2807",
"pm_score": 4,
"selected": true,
"text": "<p>Solved!</p>\n\n<pre><code>add_action( 'create_category', 'save_extra_taxonomy_fields', 10, 2 ); \n</code></... | 2011/09/23 | [
"https://wordpress.stackexchange.com/questions/29322",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/2807/"
] | Edit: Important note for WordPress v4.4 onward
----------------------------------------------
This question used a great workaround for the lack of real term meta in older versions of WordPress, but since the release of WordPress v4.4, [real term meta has been introduced](https://codex.wordpress.org/Function_Reference... | Solved!
```
add_action( 'create_category', 'save_extra_taxonomy_fields', 10, 2 );
```
Props to the [Category Meta plugin](http://wordpress.org/extend/plugins/wp-category-meta/screenshots/). I downloaded various category meta plugins from the WP repo, and this one has the ability to add the meta data on the Add Ne... |
29,339 | <p>I have created an archive page.. where i wanted to display which archive month is displaying.. how can I display the month name?</p>
| [
{
"answer_id": 29344,
"author": "Jeremy Jared",
"author_id": 5339,
"author_profile": "https://wordpress.stackexchange.com/users/5339",
"pm_score": 2,
"selected": false,
"text": "<p>To display the Month, place this in your template where you want the date to show:</p>\n\n<pre><code><?p... | 2011/09/24 | [
"https://wordpress.stackexchange.com/questions/29339",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8912/"
] | I have created an archive page.. where i wanted to display which archive month is displaying.. how can I display the month name? | If you want to get the month of the current archive page you'll have to use `single_month_title`. The following code will output " August 2014" (notice the space before the month)
```
<?php single_month_title(' ') ?>
```
Without a space before the month:
```
<?php echo trim(single_month_title(' ',false)) ?>
```
*... |
29,355 | <p>When I'm creating a new post, <strong>just after clicking "Add New"</strong>, when the post editor shows, instead of having to use the dropdown and choose a custom field to use, I'd like to have some default custom field inputs already openend.</p>
<p>Visually, instead of :</p>
<p><img src="https://i.stack.imgur.c... | [
{
"answer_id": 29358,
"author": "Roman",
"author_id": 3817,
"author_profile": "https://wordpress.stackexchange.com/users/3817",
"pm_score": 4,
"selected": true,
"text": "<p>The action hook <code>save_post</code> is called on save, but i don't know if you can add metadata at this time. Bu... | 2011/09/24 | [
"https://wordpress.stackexchange.com/questions/29355",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1381/"
] | When I'm creating a new post, **just after clicking "Add New"**, when the post editor shows, instead of having to use the dropdown and choose a custom field to use, I'd like to have some default custom field inputs already openend.
Visually, instead of :
 on the post creation screen, you h... |
29,357 | <p>My client is not a computer person. I created a website for him. There is some important pages. My client is always delete this page. Then i want to reconfigure the code (the page id). </p>
<p>How do i disable delete options for particular pages. </p>
<p>PS: He may able to EDIT these page. Not Delete. </p>
| [
{
"answer_id": 29360,
"author": "Roman",
"author_id": 3817,
"author_profile": "https://wordpress.stackexchange.com/users/3817",
"pm_score": 4,
"selected": false,
"text": "<p>You can remove the capabilites <code>delete_pages</code>, <code>delete_others_pages</code> and <code>delete_publis... | 2011/09/24 | [
"https://wordpress.stackexchange.com/questions/29357",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8917/"
] | My client is not a computer person. I created a website for him. There is some important pages. My client is always delete this page. Then i want to reconfigure the code (the page id).
How do i disable delete options for particular pages.
PS: He may able to EDIT these page. Not Delete. | You can remove the capabilites `delete_pages`, `delete_others_pages` and `delete_published_pages` from the role which the user is assigned to. This will prevent the complete user role from deleting pages.
To restrict this behavior only to one user, you have to create and assign a dedicated, new role to the user. Look ... |
29,359 | <p>Any way to disable post revision on specific post types only?</p>
| [
{
"answer_id": 29361,
"author": "Roman",
"author_id": 3817,
"author_profile": "https://wordpress.stackexchange.com/users/3817",
"pm_score": 4,
"selected": true,
"text": "<p>Remove the <code>revisions</code> property inside the <code>supports</code> parameter of <code>register_post_type()... | 2011/09/24 | [
"https://wordpress.stackexchange.com/questions/29359",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/421/"
] | Any way to disable post revision on specific post types only? | Remove the `revisions` property inside the `supports` parameter of `register_post_type()`.
**Example**
```
$args = array(
// ...
'supports' => array('title','editor','thumbnail','comments','revisions')
);
register_post_type('book',$args);
```
Change to:
```
$args = array(
// ...
'supports' => arra... |
29,370 | <p>Is there an easy way to apply a function on all action hooks? </p>
<blockquote>
<p>I want to apply <code>esc_attr()</code> to every action hook (in a way that would work from functions.php or a plugin). </p>
</blockquote>
<p>I figure I would need to filter <code>do_action</code> and <code>do_action_ref_array</co... | [
{
"answer_id": 29987,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 1,
"selected": false,
"text": "<p>While this might be possible technically (with messy output buffering) this makes little sense. It would likely brea... | 2011/09/24 | [
"https://wordpress.stackexchange.com/questions/29370",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7388/"
] | Is there an easy way to apply a function on all action hooks?
>
> I want to apply `esc_attr()` to every action hook (in a way that would work from functions.php or a plugin).
>
>
>
I figure I would need to filter `do_action` and `do_action_ref_array` except that those functions don't use `apply_filters`. Is the... | Just to answer the **title**
>
> Apply function on all action hooks?
>
>
>
isn't that hard, when you know where to look:
```
add_action( 'all', 'callback_function' );
``` |
29,375 | <h2>Let me first explain what I am wanting to do...</h2>
<p>I am wanting to add all my hundreds of website bookmarks that I have now in my browser, into wordpress for the following reasons.</p>
<ul>
<li>Can search my bookmarks by tags</li>
<li>Can search my bookmarks by description and/or name</li>
<li>Can access my bo... | [
{
"answer_id": 29379,
"author": "Brian Fegter",
"author_id": 4793,
"author_profile": "https://wordpress.stackexchange.com/users/4793",
"pm_score": 2,
"selected": false,
"text": "<p>Why don't you just use the built in bookmarks post functionality. If you click on the Links menu, it alread... | 2011/09/25 | [
"https://wordpress.stackexchange.com/questions/29375",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8668/"
] | Let me first explain what I am wanting to do...
-----------------------------------------------
I am wanting to add all my hundreds of website bookmarks that I have now in my browser, into wordpress for the following reasons.
* Can search my bookmarks by tags
* Can search my bookmarks by description and/or name
* Can... | This is how i would go about it:
* Website Title - **Post title.**
* Website URL - **custom field.**
* Website Description - **post content (editor).**
* Bookmark Tags - **custom taxonomy.**
* Screenshot image - **Post thumbnail.**
Seems simple enough. |
29,427 | <p>I'm going to be using a jQuery slider on my homepage only (not a WP plugin, but a third party). What I'd like to do is include jQuery, the plugin's jQuery script using a .js file, then include the script needed to fire the plugin right before the closing body tag. I'm a bit confused about how that works.</p>
<p>I ... | [
{
"answer_id": 29429,
"author": "Brian Fegter",
"author_id": 4793,
"author_profile": "https://wordpress.stackexchange.com/users/4793",
"pm_score": 3,
"selected": true,
"text": "<p>You typically should use the jQuery version that's built in. There are instances where you might want to use... | 2011/09/25 | [
"https://wordpress.stackexchange.com/questions/29427",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8678/"
] | I'm going to be using a jQuery slider on my homepage only (not a WP plugin, but a third party). What I'd like to do is include jQuery, the plugin's jQuery script using a .js file, then include the script needed to fire the plugin right before the closing body tag. I'm a bit confused about how that works.
I know WordPr... | You typically should use the jQuery version that's built in. There are instances where you might want to use wp\_dequeue\_script('jquery') and then add a different version of jQuery.
Here's the best way to add a script dependent on jQuery:
```
function theme_register_scripts(){
wp_enqueue_script('jquery');
wp_e... |
29,430 | <p>I'd like to get a menu object from its theme location argument.</p>
<p>My goal is to output separately the menu name and its items name, url and description.</p>
<p>Example of what I'm looking for :</p>
<pre><code>$menu = get_menu('nav-menu'); //get menu from its theme location
echo $menu->name; //displays the... | [
{
"answer_id": 29432,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 5,
"selected": true,
"text": "<p><a href=\"http://www.andrewgail.com/getting-a-menu-name-in-wordpress/\" rel=\"nofollow noreferrer\">This met... | 2011/09/25 | [
"https://wordpress.stackexchange.com/questions/29430",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8939/"
] | I'd like to get a menu object from its theme location argument.
My goal is to output separately the menu name and its items name, url and description.
Example of what I'm looking for :
```
$menu = get_menu('nav-menu'); //get menu from its theme location
echo $menu->name; //displays the menu name
foreach($menu->items... | [This method looks like what you're looking for](http://www.andrewgail.com/getting-a-menu-name-in-wordpress/), using get\_nav\_menu\_locations() and [get\_term()](https://developer.wordpress.org/reference/functions/get_term/):
```
$theme_locations = get_nav_menu_locations();
$menu_obj = get_term( $theme_locations[$th... |
29,433 | <p>I want to take the text widget and remove the preceding / trailing markup from the text output currently showing as </p>
<pre><code><div class="textwidget">Test</div>
</code></pre>
<p>The before_widget / after_widget that is assigned with each widget area is under my control but the widget content itse... | [
{
"answer_id": 49944,
"author": "Goran Jakovljevic",
"author_id": 15469,
"author_profile": "https://wordpress.stackexchange.com/users/15469",
"pm_score": -1,
"selected": false,
"text": "<p>Text widgets formating can be found in '/wp-includes/default-widgets.php' starting from line 368. I... | 2011/09/25 | [
"https://wordpress.stackexchange.com/questions/29433",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3899/"
] | I want to take the text widget and remove the preceding / trailing markup from the text output currently showing as
```
<div class="textwidget">Test</div>
```
The before\_widget / after\_widget that is assigned with each widget area is under my control but the widget content itself is beyond me.
```
// Area 4, loc... | You have a couple options as I see it:
There's a [the\_widget()](http://codex.wordpress.org/Function_Reference/the_widget) template tag that lets you control the before\_widget and after\_widget properties. However, it divorces the widget from the Widgets UI.
Alternately, you can try to accomplish whatever you're try... |
29,435 | <p>thanks to Roman for pointing me in the right direction my plugin is almost ready. The only problem i am now facing is that i cannot get the rewrite_rules applying on activation they only work after i goto the Wordpress admin menu, goto the Permalinks settings page and click Save Changes, then it all works.</p>
<p>I... | [
{
"answer_id": 29437,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 3,
"selected": true,
"text": "<p>If I had to guess?</p>\n\n<p>The plugin activation hook is firing <em>before</em> the <code>rewrite_rules_ar... | 2011/09/25 | [
"https://wordpress.stackexchange.com/questions/29435",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8921/"
] | thanks to Roman for pointing me in the right direction my plugin is almost ready. The only problem i am now facing is that i cannot get the rewrite\_rules applying on activation they only work after i goto the Wordpress admin menu, goto the Permalinks settings page and click Save Changes, then it all works.
I am using... | If I had to guess?
The plugin activation hook is firing *before* the `rewrite_rules_array` filter is applied, resulting in the rules being flushed *before* you make changes to them.
[See here for the Codex-recommended implementation](http://codex.wordpress.org/Class_Reference/WP_Rewrite#Examples), using the `wp_loade... |
29,447 | <p>I am trying to be able to search a particular custom post type on my blog. The custom post type is named: <strong>website_bookmarks</strong></p>
<p>I have modified my search form with a hidden field </p>
<pre><code><input type="hidden" name="post_type" value="website_bookmarks" />
</code></pre>
<p>So on m... | [
{
"answer_id": 29438,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 4,
"selected": true,
"text": "<p>It depends on the license under which the Theme is released.</p>\n\n<p>Assuming the Theme was released under... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29447",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8668/"
] | I am trying to be able to search a particular custom post type on my blog. The custom post type is named: **website\_bookmarks**
I have modified my search form with a hidden field
```
<input type="hidden" name="post_type" value="website_bookmarks" />
```
So on my search page in the URI I will see...
```
www.mydo... | It depends on the license under which the Theme is released.
Assuming the Theme was released under GPL: no; you are free to change the Theme in any way you want. If you redistribute the Theme, modified or unmodified, you are required to maintain the original copyright/license information *in the Theme file headers*, b... |
29,456 | <p>I've successfully redirected my blog page to my most recent post - i.e. so when you click the 'blog' link in the nav it goes to the most recent post page and you can click next/prev buttons to navigate between other posts.</p>
<p>Now I want to do the same thing but for a specific category so when you click a catego... | [
{
"answer_id": 29461,
"author": "Brian Fegter",
"author_id": 4793,
"author_profile": "https://wordpress.stackexchange.com/users/4793",
"pm_score": 3,
"selected": false,
"text": "<p>You can do this by creating a template in your theme called category.php using the following.</p>\n\n<pre><... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29456",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1063/"
] | I've successfully redirected my blog page to my most recent post - i.e. so when you click the 'blog' link in the nav it goes to the most recent post page and you can click next/prev buttons to navigate between other posts.
Now I want to do the same thing but for a specific category so when you click a category link, i... | You know, the other way to do what you're trying to do is simply to set the global `posts_per_page` variable to `1` in **Dashboard -> Settings -> Reading**. |
29,457 | <p>here is Hierarchy</p>
<p>Parent (id=34)
Child
Child of child-1
Child of child-2
Child of child-3
Child of child-4</p>
<p>I am at child of child, i Just want to show sibblings of child of child if parent is '34', like this</p>
<ul>
<li>Child of child-1</li>
<li>Child of child-2</li>
<li>Child of ... | [
{
"answer_id": 29458,
"author": "Mark",
"author_id": 8757,
"author_profile": "https://wordpress.stackexchange.com/users/8757",
"pm_score": 0,
"selected": false,
"text": "<p>I do not understand your question that good but check out <a href=\"http://codex.wordpress.org/Function_Reference/g... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29457",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8950/"
] | here is Hierarchy
Parent (id=34)
Child
Child of child-1
Child of child-2
Child of child-3
Child of child-4
I am at child of child, i Just want to show sibblings of child of child if parent is '34', like this
* Child of child-1
* Child of child-2
* Child of child-3
* Child of child-4
I used the below function i... | The page object has 2 properties: post\_parent which is the parent page, and ancestors, which is array of all of the page's ancestors in the tree.
```
$currentPageId = get_the_ID();
$page = get_page($currentPageId);
if (in_array(34, $page->ancestors)) {
$siblings = get_pages(array('child_of' => $page->post_pa... |
29,467 | <p>The following code works brilliantly for retrieving certain pages, but I can't get it to retrieve POSTS by name. I'd like exactly the same code, but to retrieve posts rather than pages. Any help appreciated.</p>
<pre><code><?php
function get_my_content($page) {
$my_id = $page;
$post_id = get_... | [
{
"answer_id": 29468,
"author": "Jasper Kennis",
"author_id": 5828,
"author_profile": "https://wordpress.stackexchange.com/users/5828",
"pm_score": 0,
"selected": false,
"text": "<p>Using that earlier question I was referring to, you could do something like this:</p>\n\n<pre><code><?p... | 2011/09/25 | [
"https://wordpress.stackexchange.com/questions/29467",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/6374/"
] | The following code works brilliantly for retrieving certain pages, but I can't get it to retrieve POSTS by name. I'd like exactly the same code, but to retrieve posts rather than pages. Any help appreciated.
```
<?php
function get_my_content($page) {
$my_id = $page;
$post_id = get_post($my_id, ARRA... | As per docs you only need to specify different post type to make it work:
```
$page = get_page_by_title('testpage', OBJECT, 'post');
``` |
29,476 | <p>I want to show first post wider than other posts on the index page of my wordpress theme like firstpost.com.</p>
<p>Please suggest me how to do this? </p>
| [
{
"answer_id": 29482,
"author": "Mohit Bumb",
"author_id": 8184,
"author_profile": "https://wordpress.stackexchange.com/users/8184",
"pm_score": 0,
"selected": false,
"text": "<p>when you start loop take one variable $i=1;\nand increament this variable with 1 everytime loop is running </... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29476",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8954/"
] | I want to show first post wider than other posts on the index page of my wordpress theme like firstpost.com.
Please suggest me how to do this? | you create a variable that holds the count of the loop. then with every iteration you increment this variable.
in your loop you can check for the first post to do something else then the rest of the posts, assign a different css class for example.
```php
// create var for count
$count = 0;
// do your loop & incremen... |
29,485 | <p>I'm running a multisite network with 100+ themes installed and activated. Is there a way to manipulate the list of available themes in wp-admin so that certain themes appear in the list first? (a kind of "Featured" or "recommended") After the first 9 or so alphabetical as default would be fine.</p>
<p>Obviously Goo... | [
{
"answer_id": 29541,
"author": "Roman",
"author_id": 3817,
"author_profile": "https://wordpress.stackexchange.com/users/3817",
"pm_score": 1,
"selected": false,
"text": "<p>Probably not without editing core files. I haven't found any hook you could use. </p>\n\n<p>If you look in the fil... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29485",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3669/"
] | I'm running a multisite network with 100+ themes installed and activated. Is there a way to manipulate the list of available themes in wp-admin so that certain themes appear in the list first? (a kind of "Featured" or "recommended") After the first 9 or so alphabetical as default would be fine.
Obviously Googling the ... | Came up with a silly but effective measure to get certain themes at the front of the list. Because themes are listed alphabetically, it was possible to manipulate the output by changing the theme name, specifically by adding a symbol to the front of the theme name it will appear at the start of the list.
I settled for... |
29,493 | <p>I have a big one page wordpress site and a menu created from wordpress admin pages panel. I added everywhere in my main page such links like <code><A NAME="gohere"></code> and similar. Now I need to add href's to the page menu name's like <code><a href="#gohere"></code> Actually I do not know is it possi... | [
{
"answer_id": 29496,
"author": "Mohit Bumb",
"author_id": 8184,
"author_profile": "https://wordpress.stackexchange.com/users/8184",
"pm_score": 1,
"selected": true,
"text": "<p>well you've to change code in loop\nfor example currently now loop is like</p>\n\n<pre><code><?php if(have_... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29493",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7552/"
] | I have a big one page wordpress site and a menu created from wordpress admin pages panel. I added everywhere in my main page such links like `<A NAME="gohere">` and similar. Now I need to add href's to the page menu name's like `<a href="#gohere">` Actually I do not know is it possible to do this from the wordpress adm... | well you've to change code in loop
for example currently now loop is like
```
<?php if(have_post) : while(yourquery): the_post : <div>the_title</div><div>the_content</div> endwhile; endif;
```
Then Just Add this line also
```
<?php if(have_post) : while(yourquery): the_post <a name="$i"><div>the_title</div><div>the... |
29,498 | <p>I have the site in WordPress where I used the custom fields, but now I want to use that custom field as post tag automatically.</p>
<p>Can anyone have any idea?</p>
<p>Thanks.</p>
| [
{
"answer_id": 29502,
"author": "chrismou",
"author_id": 8960,
"author_profile": "https://wordpress.stackexchange.com/users/8960",
"pm_score": 1,
"selected": false,
"text": "<p>As far as I am aware, this isn't possible to do automatically \"out of the box\". A quick Google and it looks ... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29498",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10751/"
] | I have the site in WordPress where I used the custom fields, but now I want to use that custom field as post tag automatically.
Can anyone have any idea?
Thanks. | To convert the old custom fields, you can write a plugin that, on activation, fetches all the posts with your custom field name and converts them to tags with the handy `wp_set_post_terms`.
First set up a few constants with your field names and post type.
```
<?php
/**
* CHANGE THIS! what is your custom field's name... |
29,501 | <p>I am trying to create a custom login page for my site, namely <code>http://localhost/site/login</code>, the problem I am running into now is that when the user tries to log in and enters the wrong username or password, they are redirected to the <code>wp-login.php</code> page, which is problematic, as you can imagin... | [
{
"answer_id": 29504,
"author": "Brian Fegter",
"author_id": 4793,
"author_profile": "https://wordpress.stackexchange.com/users/4793",
"pm_score": 0,
"selected": false,
"text": "<p>Try using an AJAX login plugin. <a href=\"http://wordpress.org/extend/plugins/login-with-ajax/\" rel=\"nofo... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29501",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/2632/"
] | I am trying to create a custom login page for my site, namely `http://localhost/site/login`, the problem I am running into now is that when the user tries to log in and enters the wrong username or password, they are redirected to the `wp-login.php` page, which is problematic, as you can imagine, so I would like to add... | [jquery Validation plugin](http://docs.jquery.com/Plugins/Validation) should do what you want. |
29,505 | <p>Anyone know of an easy way to alter the default WordPress search from searching ALL pages, to searching only child pages from a specific page parent?</p>
<p>I know of the filter you can use to alter whether pages or posts are searched:</p>
<pre><code>function SearchFilter($query) {
if ($query->is_search) {
... | [
{
"answer_id": 29506,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 2,
"selected": false,
"text": "<p>I have no idea if this will work, but couldn't you reference the <code>post_parent</code> in the query args... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29505",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8961/"
] | Anyone know of an easy way to alter the default WordPress search from searching ALL pages, to searching only child pages from a specific page parent?
I know of the filter you can use to alter whether pages or posts are searched:
```
function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type',... | I have no idea if this will work, but couldn't you reference the `post_parent` in the query args?
```
function SearchFilter($query) {
if ($query->is_search) {
//$query->set('post_type', 'page');
global $post;
$query->set( 'post_parent', $post->ID );
}
return $query;
}
add_filter('pre_get_posts','SearchFilt... |
29,507 | <p>Does anyone know how I can turn this:</p>
<pre><code><div id="mySlides">
<?php query_posts('showposts=4&cat=11'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div>
<h2><a href="<?php the_permalink()... | [
{
"answer_id": 29510,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 2,
"selected": true,
"text": "<p>I think this is probably a more-involved question, but I'll try to answer it as-is. The following code will ... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29507",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/6787/"
] | Does anyone know how I can turn this:
```
<div id="mySlides">
<?php query_posts('showposts=4&cat=11'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div>
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="< ?php the_title_attribute(); ?>"... | I think this is probably a more-involved question, but I'll try to answer it as-is. The following code will wrap each post's content in a `<div>`:
```
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div id="slide<?php the_ID(); ?>>
// Post content - i.e. your slider... |
29,508 | <p>Does anyone know of a simple plugin that allows an administrator to send messages to users that have accounts, and allow those same users to reply to the message. I found one <a href="http://wordpress.org/extend/plugins/private-messages-for-wordpress/" rel="nofollow">here</a>, but the problem is that it allows any u... | [
{
"answer_id": 29509,
"author": "petermolnar",
"author_id": 4209,
"author_profile": "https://wordpress.stackexchange.com/users/4209",
"pm_score": 1,
"selected": false,
"text": "<p>You can add a private messaging plugin, for example <a href=\"http://wordpress.org/extend/plugins/email-user... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29508",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8962/"
] | Does anyone know of a simple plugin that allows an administrator to send messages to users that have accounts, and allow those same users to reply to the message. I found one [here](http://wordpress.org/extend/plugins/private-messages-for-wordpress/), but the problem is that it allows any user to send any user messages... | Yes, you can do this with the plugin you linked, [Private Messages for WordPress](http://wordpress.org/plugins/private-messages-for-wordpress/).
Firstly, download version 2.1.09 - version 2.1.10 introduced mostly bugs, one of which excludes admins from the senders list.
Open the file `pm4wp.php` and edit line 450 t... |
29,512 | <p>Can you please help me?</p>
<p>For getting post url I use: <code><?php the_permalink() ?></code>
But for pages and for categories? If I use <code><?php the_permalink() ?></code> on categories it displays post url.</p>
| [
{
"answer_id": 29513,
"author": "Michael",
"author_id": 4884,
"author_profile": "https://wordpress.stackexchange.com/users/4884",
"pm_score": 2,
"selected": false,
"text": "<p>for pages, it should be the same as for posts;</p>\n\n<p>to link to category archives, try to use the category I... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29512",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | Can you please help me?
For getting post url I use: `<?php the_permalink() ?>`
But for pages and for categories? If I use `<?php the_permalink() ?>` on categories it displays post url. | There's currently no way in core to get the current archive / category / tag / custom taxonomy URL. I have a patch waiting for that to be added [right here](https://core.trac.wordpress.org/ticket/18660). For now though, you could just use the code in the last patch on that ticket:
```
<?php
/* Get the current archive ... |
29,516 | <p>The default search function if the search form is empty returns the home page, I want it to return a "sorry your search returned no results" page.</p>
<p><a href="https://wordpress.stackexchange.com/questions/24463/changing-the-default-wordpress-search-action">this post doesn't answer it</a></p>
<p>and <a href="ht... | [
{
"answer_id": 29589,
"author": "Rutwick Gangurde",
"author_id": 4740,
"author_profile": "https://wordpress.stackexchange.com/users/4740",
"pm_score": 0,
"selected": false,
"text": "<p>I handle it in my themes as follows. Try using this code:</p>\n\n<pre><code><?php if (!have_posts())... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29516",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7318/"
] | The default search function if the search form is empty returns the home page, I want it to return a "sorry your search returned no results" page.
[this post doesn't answer it](https://wordpress.stackexchange.com/questions/24463/changing-the-default-wordpress-search-action)
and [this ticket](http://core.trac.wordpres... | Here are 3 ways of fixing this, I advise you use solution 2, but pay attention to the jQuery in solution 1 as a way of avoiding the situation in the first place.
For those wanting more code posted from the question askers theme, this is not a theme issue, this is a general WordPress issue that affects all WordPress si... |
29,518 | <p>I'm working on a blog which migrated from wordpress.com, which now is self-hosted. I created a theme based off their CSS customizations, and everything is working. I'm looking to add the Facebook and Twitter buttons, to the end of posts and end of posts on front page. Essentially In the same manner as wordpress.... | [
{
"answer_id": 29521,
"author": "Rev. Voodoo",
"author_id": 3429,
"author_profile": "https://wordpress.stackexchange.com/users/3429",
"pm_score": 0,
"selected": false,
"text": "<p><a href=\"http://wordpress.org/extend/plugins/jetpack/\" rel=\"nofollow\">http://wordpress.org/extend/plugin... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29518",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8339/"
] | I'm working on a blog which migrated from wordpress.com, which now is self-hosted. I created a theme based off their CSS customizations, and everything is working. I'm looking to add the Facebook and Twitter buttons, to the end of posts and end of posts on front page. Essentially In the same manner as wordpress.com.
I... | Why go for a plugin at all?? all you want is twitter & facebook share / tweet right ?
You can do this:
**1. embed this shortcode in your functions.php (or shortcode page if you got one)**
```
function shreplz() {
return '
<div class="sharebox">
<div class="twittme"><a name="fb_share"></a> <script src="htt... |
29,519 | <p>I have a site with more than 300,000 posts (but really little posts) and cheking why is going so slow I've seen that in the hompage it makes something like this:</p>
<p>"Generated in 15.024 seconds. Made 9492 queries to database and 0 cached queries. Memory used - 81.12MB"</p>
<p>Home only displays the first 10 ps... | [
{
"answer_id": 29523,
"author": "markratledge",
"author_id": 268,
"author_profile": "https://wordpress.stackexchange.com/users/268",
"pm_score": 1,
"selected": false,
"text": "<p>Delete post/page revisions and that will reduce queries as well as the overall size of the DB. Run this in ph... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29519",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8963/"
] | I have a site with more than 300,000 posts (but really little posts) and cheking why is going so slow I've seen that in the hompage it makes something like this:
"Generated in 15.024 seconds. Made 9492 queries to database and 0 cached queries. Memory used - 81.12MB"
Home only displays the first 10 psts and runs a cou... | Delete post/page revisions and that will reduce queries as well as the overall size of the DB. Run this in phpmyadmin (backup the DB first):
```
DELETE a,b,c
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)
WHERE a.post_type = 'revision'
```
Chan... |
29,525 | <p>I'm trying to set the number of posts_per_page dynamically using my own variable. This code works fine:</p>
<pre><code>query_posts( $query_string . "&posts_per_page=" . $myvar )
// then display the loop using get_template_part( 'loop' );
</code></pre>
<p>That works fine, but I would like to know how to do it ... | [
{
"answer_id": 29527,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 2,
"selected": false,
"text": "<p>when you call <code>query_posts</code> with a modified query in your template, you're actually running another quer... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29525",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3564/"
] | I'm trying to set the number of posts\_per\_page dynamically using my own variable. This code works fine:
```
query_posts( $query_string . "&posts_per_page=" . $myvar )
// then display the loop using get_template_part( 'loop' );
```
That works fine, but I would like to know how to do it using $wp\_query instead of ... | `query_posts` will do the query again (destroy current wp\_query and create a new one and then doing the query with the parameters you pass to it)
To get the same behaviour after setting the new parameter with `set_var` you need to query the database again using something like this
```
$wp_query->set('posts_per_page... |
29,545 | <p>Im trying to do a redirect to a certain bp profile page but for some reason it keeps going to the home page on the login.</p>
<p>this is my code im not entirely sure what the problem is and why it keeps going to the home page.</p>
<pre><code>add_action('login_form', 'redirect_after_login');
function redirect_after... | [
{
"answer_id": 29745,
"author": "Jeremy Love",
"author_id": 2635,
"author_profile": "https://wordpress.stackexchange.com/users/2635",
"pm_score": 1,
"selected": true,
"text": "<p>I was able to find success with this function from <a href=\"http://wordpress.org/extend/plugins/bp-redirect-... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29545",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/2635/"
] | Im trying to do a redirect to a certain bp profile page but for some reason it keeps going to the home page on the login.
this is my code im not entirely sure what the problem is and why it keeps going to the home page.
```
add_action('login_form', 'redirect_after_login');
function redirect_after_login() {
global... | I was able to find success with this function from [BP Redirect to Profile](http://wordpress.org/extend/plugins/bp-redirect-to-profile/) (see [GitHub repository](https://github.com/sbrajesh/bp-redirect-to-profile)):
```
<?php
/*
Plugin Name: BP Redirect to Profile for Buddypress
Description:Redirect user to their prof... |
29,561 | <p>I realize improving WordPress's search function is a huge can of worms, but the ONLY additional thing I need it to do is to show results when I search for an author's name.</p>
<p>For example, if we have an author named Katie Johnson, and I search for Katie, I get results where her name is listed in the CONTENT, bu... | [
{
"answer_id": 29570,
"author": "hacksy",
"author_id": 8780,
"author_profile": "https://wordpress.stackexchange.com/users/8780",
"pm_score": 3,
"selected": false,
"text": "<p>Maybe you can try adding your condition directly in the query string, using something like this</p>\n\n<pre><code... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29561",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7855/"
] | I realize improving WordPress's search function is a huge can of worms, but the ONLY additional thing I need it to do is to show results when I search for an author's name.
For example, if we have an author named Katie Johnson, and I search for Katie, I get results where her name is listed in the CONTENT, but not resu... | Maybe you can try adding your condition directly in the query string, using something like this
```
function wpse_29570_where_filter($where){
global $wpdb;
if( is_search() ) {
$search= get_query_var('s');
$query=$wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE ( meta_k... |
29,563 | <p>I have a current job where my client has requested to have their "sponsors" rotate in the sidebar widget. Right now I have a random ad widget which rotates them randomly...</p>
<p>I was wanting to know if there is a plugin or a way to make a number of image ads slide, or rotate live when you are on the page not via... | [
{
"answer_id": 29570,
"author": "hacksy",
"author_id": 8780,
"author_profile": "https://wordpress.stackexchange.com/users/8780",
"pm_score": 3,
"selected": false,
"text": "<p>Maybe you can try adding your condition directly in the query string, using something like this</p>\n\n<pre><code... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29563",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7125/"
] | I have a current job where my client has requested to have their "sponsors" rotate in the sidebar widget. Right now I have a random ad widget which rotates them randomly...
I was wanting to know if there is a plugin or a way to make a number of image ads slide, or rotate live when you are on the page not via refresh a... | Maybe you can try adding your condition directly in the query string, using something like this
```
function wpse_29570_where_filter($where){
global $wpdb;
if( is_search() ) {
$search= get_query_var('s');
$query=$wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE ( meta_k... |
29,572 | <p>Hey all i am having some problems with finding out where wordpress saves my pages. I have a default theme selected and have added a few pages. However, the links to them seem to show up all the same (page.com/about, page.com/contact, etc etc). They all have the same content no matter what page i view (even though ea... | [
{
"answer_id": 29570,
"author": "hacksy",
"author_id": 8780,
"author_profile": "https://wordpress.stackexchange.com/users/8780",
"pm_score": 3,
"selected": false,
"text": "<p>Maybe you can try adding your condition directly in the query string, using something like this</p>\n\n<pre><code... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29572",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8469/"
] | Hey all i am having some problems with finding out where wordpress saves my pages. I have a default theme selected and have added a few pages. However, the links to them seem to show up all the same (page.com/about, page.com/contact, etc etc). They all have the same content no matter what page i view (even though each ... | Maybe you can try adding your condition directly in the query string, using something like this
```
function wpse_29570_where_filter($where){
global $wpdb;
if( is_search() ) {
$search= get_query_var('s');
$query=$wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE ( meta_k... |
29,618 | <p>I'm working on a conditional statement (in a loop) that looks for a featured image then grabs a default image if there is none, which I have figured out. But, I also wanted a way to pull the first image (or any image) attachment before going the route of the default image. Having trouble finding the right way to ch... | [
{
"answer_id": 29606,
"author": "Maxim Krizhanovsky",
"author_id": 8294,
"author_profile": "https://wordpress.stackexchange.com/users/8294",
"pm_score": 2,
"selected": false,
"text": "<p>Use uninstall hook to delete all settings. On deactivation you can move temporary some data that was ... | 2011/09/27 | [
"https://wordpress.stackexchange.com/questions/29618",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8678/"
] | I'm working on a conditional statement (in a loop) that looks for a featured image then grabs a default image if there is none, which I have figured out. But, I also wanted a way to pull the first image (or any image) attachment before going the route of the default image. Having trouble finding the right way to check ... | Use uninstall hook to delete all settings. On deactivation you can move temporary some data that was inserted in the plugin, like menu items, etc., but keep plugin settings active. |
29,628 | <p>I'm trying to add this social-network button:</p>
<pre><code><a href="http://svejo.net/submit/?url=[your url]"
data-url="[your url]"
data-type="compact"
id="svejo-button">Add in Svejo</a>
<script type="text/javascript" src="http://svejo.net/javascripts/svejo-button.js"></script&g... | [
{
"answer_id": 29629,
"author": "Ionut Staicu",
"author_id": 223,
"author_profile": "https://wordpress.stackexchange.com/users/223",
"pm_score": 2,
"selected": false,
"text": "<p>IIRC enqueue_script is triggered before <code>init</code> ( or very close to that ), while the short tags is ... | 2011/09/27 | [
"https://wordpress.stackexchange.com/questions/29628",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8801/"
] | I'm trying to add this social-network button:
```
<a href="http://svejo.net/submit/?url=[your url]"
data-url="[your url]"
data-type="compact"
id="svejo-button">Add in Svejo</a>
<script type="text/javascript" src="http://svejo.net/javascripts/svejo-button.js"></script>
```
to my blog posts.
But loading... | You need to be hooking the function that calls the enqueue, personally I actually like to register scripts and enqueue them separately, rather than just enqueueing them, as it allows the flexibilty to enqueue conditionally and can save keystrokes down the line at little to no performance penalty. The code you are going... |
29,645 | <p>I have several menus generated on a page using wp_list_pages. I want to add a class to the last menu item on only one instance of these.</p>
<p>For example, I have a menu here:</p>
<pre><code><ul id="headerlinks">
<?php wp_list_pages('title_li=&include=24,26,28,30'); ?>
</ul>
</code></pre>
... | [
{
"answer_id": 29650,
"author": "kaiser",
"author_id": 385,
"author_profile": "https://wordpress.stackexchange.com/users/385",
"pm_score": 0,
"selected": false,
"text": "<p>There isn't passed any ID to the filter, but you can inspect the output and get around it using <code>debug_backtra... | 2011/09/27 | [
"https://wordpress.stackexchange.com/questions/29645",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8997/"
] | I have several menus generated on a page using wp\_list\_pages. I want to add a class to the last menu item on only one instance of these.
For example, I have a menu here:
```
<ul id="headerlinks">
<?php wp_list_pages('title_li=&include=24,26,28,30'); ?>
</ul>
```
And another like so:
```
<ul id="sublinks">
<?php ... | Simply add the filter before the call and remove it afterward something like this
```
<ul id="headerlinks">
<?php
add_filter('wp_list_pages', 'add_markup_pages');
wp_list_pages('title_li=&include=24,26,28,30');
remove_filter('wp_list_pages', 'add_markup_pages');
?> </ul>
``` |
29,684 | <p>I m having trouble in resizing media images. I tried <a href="http://codex.wordpress.org/Function_Reference/add_image_size" rel="nofollow">add_image_size</a> function to resize my original image like below.</p>
<blockquote>
<p>add_image_size( 'my_thumb', 145, 100);</p>
</blockquote>
<p>it creates thumb images wi... | [
{
"answer_id": 29732,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 0,
"selected": false,
"text": "<p>First, if you added your <code>add_image_size()</code> call to <code>functions.php</code> <em>after</em> yo... | 2011/09/28 | [
"https://wordpress.stackexchange.com/questions/29684",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8540/"
] | I m having trouble in resizing media images. I tried [add\_image\_size](http://codex.wordpress.org/Function_Reference/add_image_size) function to resize my original image like below.
>
> add\_image\_size( 'my\_thumb', 145, 100);
>
>
>
it creates thumb images with height 100 but it changes width for every image.
l... | If you are trying to retroactively resize images, use the code you've supplied in your functions.php, then run the Regenerate Thumbnails plugin <http://wordpress.org/extend/plugins/regenerate-thumbnails/>
Once you've done that you should be able to display the image using the following:
```
the_post_thumbnail('my_thu... |
29,697 | <p>I'm in a dead end with a schedualed task in a wordpress plugin for a multisite. Somehow the action I added don't get triggered. The task is getting schedualed and returns a timestamp when I run wp_next_scheduled(), but the action itself doesn't go off and trigger the function. </p>
<p>Information that might give so... | [
{
"answer_id": 29698,
"author": "Andreas N",
"author_id": 6324,
"author_profile": "https://wordpress.stackexchange.com/users/6324",
"pm_score": -1,
"selected": false,
"text": "<p>I think you forgot <strong>register_activation_hook()</strong></p>\n\n<p>See <a href=\"http://codex.wordpress... | 2011/09/26 | [
"https://wordpress.stackexchange.com/questions/29697",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/47608/"
] | I'm in a dead end with a schedualed task in a wordpress plugin for a multisite. Somehow the action I added don't get triggered. The task is getting schedualed and returns a timestamp when I run wp\_next\_scheduled(), but the action itself doesn't go off and trigger the function.
Information that might give some clues... | You need to call add\_action from outside the class, with a reference to the object. Example:
```
$cj = new Cronjobs;
add_action('update_properties_daily', array(&$cj, 'do_updates'));
``` |
29,702 | <p>I'm not sure if is wordpress itself or Tiny MCE that's doing it. But when switching between HTML and Visual editor it's adding <code>&nbsp;</code>, and adding an extra one each time I switch back and forth. I don't even have a line break in the code, it seems to somehow be deciding where it wants to place them b... | [
{
"answer_id": 29713,
"author": "Matthew Xerri",
"author_id": 5804,
"author_profile": "https://wordpress.stackexchange.com/users/5804",
"pm_score": 3,
"selected": true,
"text": "<p>All I use is <code>remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' );</c... | 2011/09/27 | [
"https://wordpress.stackexchange.com/questions/29702",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/11059/"
] | I'm not sure if is wordpress itself or Tiny MCE that's doing it. But when switching between HTML and Visual editor it's adding ` `, and adding an extra one each time I switch back and forth. I don't even have a line break in the code, it seems to somehow be deciding where it wants to place them based on the tags i... | All I use is `remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' );` and that stops Wordpress from creating any extra markup. Are you copying and pasting your code from an external editor? |
29,712 | <p>I'm including a php file in single.php, in the loop. </p>
<p>Is it possible to use WP variables such as the_title(), the_date(), etc in the included php file? </p>
| [
{
"answer_id": 29714,
"author": "petermolnar",
"author_id": 4209,
"author_profile": "https://wordpress.stackexchange.com/users/4209",
"pm_score": 2,
"selected": true,
"text": "<p>Get the title into a variable, and use the variable in the included PHP instead:</p>\n\n<pre><code>$title = g... | 2011/09/28 | [
"https://wordpress.stackexchange.com/questions/29712",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4567/"
] | I'm including a php file in single.php, in the loop.
Is it possible to use WP variables such as the\_title(), the\_date(), etc in the included php file? | Get the title into a variable, and use the variable in the included PHP instead:
```
$title = get_the_title();
include "yourfile.php";
```
yourfile.php:
```
<?php
echo $title;
?>
``` |
29,716 | <p>I am working on a theme which contains a custom post type with custom fields.</p>
<p>Everything is working perfectly except the when a new custom post is added, the custom fields for the first custom post and first one only are wiped.</p>
<pre><code>function save_details(){
global $post;
update_post_me... | [
{
"answer_id": 29714,
"author": "petermolnar",
"author_id": 4209,
"author_profile": "https://wordpress.stackexchange.com/users/4209",
"pm_score": 2,
"selected": true,
"text": "<p>Get the title into a variable, and use the variable in the included PHP instead:</p>\n\n<pre><code>$title = g... | 2011/09/28 | [
"https://wordpress.stackexchange.com/questions/29716",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9017/"
] | I am working on a theme which contains a custom post type with custom fields.
Everything is working perfectly except the when a new custom post is added, the custom fields for the first custom post and first one only are wiped.
```
function save_details(){
global $post;
update_post_meta($post->ID, "testim... | Get the title into a variable, and use the variable in the included PHP instead:
```
$title = get_the_title();
include "yourfile.php";
```
yourfile.php:
```
<?php
echo $title;
?>
``` |
29,735 | <p>How do I link to the image editor's <em>Edit Image</em> function from the front end?</p>
<p>I know that I can open the lightbox with a simple link, such as <code><a href="wp-admin/media-upload.php?post_id=719&amp;type=image" id="content-add_image" class="thickbox add_image" title="Add an Image">Upload pho... | [
{
"answer_id": 29714,
"author": "petermolnar",
"author_id": 4209,
"author_profile": "https://wordpress.stackexchange.com/users/4209",
"pm_score": 2,
"selected": true,
"text": "<p>Get the title into a variable, and use the variable in the included PHP instead:</p>\n\n<pre><code>$title = g... | 2011/09/28 | [
"https://wordpress.stackexchange.com/questions/29735",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1057/"
] | How do I link to the image editor's *Edit Image* function from the front end?
I know that I can open the lightbox with a simple link, such as `<a href="wp-admin/media-upload.php?post_id=719&type=image" id="content-add_image" class="thickbox add_image" title="Add an Image">Upload photos</a>`
However unlike opening... | Get the title into a variable, and use the variable in the included PHP instead:
```
$title = get_the_title();
include "yourfile.php";
```
yourfile.php:
```
<?php
echo $title;
?>
``` |
29,742 | <p>I'm just trying to find a way to narrow my current search bar so that it only searches within my 'events' custom post-type.</p>
<p>I do not want the search to index any other post type, only 'events'.</p>
<p>Here's the search bar:</p>
<pre><code><form id="searchform" action="http://localhost:8888/ltc" method="... | [
{
"answer_id": 29744,
"author": "hacksy",
"author_id": 8780,
"author_profile": "https://wordpress.stackexchange.com/users/8780",
"pm_score": 5,
"selected": true,
"text": "<p>To search for a custom post type , you can add to the query <code>&post_type=events</code> , to achieve this j... | 2011/09/28 | [
"https://wordpress.stackexchange.com/questions/29742",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5883/"
] | I'm just trying to find a way to narrow my current search bar so that it only searches within my 'events' custom post-type.
I do not want the search to index any other post type, only 'events'.
Here's the search bar:
```
<form id="searchform" action="http://localhost:8888/ltc" method="get">
<input class="inl... | To search for a custom post type , you can add to the query `&post_type=events` , to achieve this just edit your form like this
```
<form id="searchform" action="http://localhost:8888/ltc" method="get">
<input class="inlineSearch" type="text" name="s" value="Enter a keyword" onblur="if (this.value == '') {thi... |
29,818 | <p>I'm trying to create a wrapper shortcut function to register and load stylesheets in the header. currently, the function loads this css file src:</p>
<pre><code>http://my.test/wp-content/theme/css/.css
</code></pre>
<p>I, obviously want it to pass the parameter given. The problem is, the new function definition wi... | [
{
"answer_id": 29811,
"author": "Brian Fegter",
"author_id": 4793,
"author_profile": "https://wordpress.stackexchange.com/users/4793",
"pm_score": 0,
"selected": false,
"text": "<p>It looks like the brands might be sub pages. If you go to Pages and look at the Brands page you will probab... | 2011/09/29 | [
"https://wordpress.stackexchange.com/questions/29818",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9047/"
] | I'm trying to create a wrapper shortcut function to register and load stylesheets in the header. currently, the function loads this css file src:
```
http://my.test/wp-content/theme/css/.css
```
I, obviously want it to pass the parameter given. The problem is, the new function definition within the new function defi... | Studying the code is an obvious approach.
You can also try plugins, such as [Debug Bar](http://wordpress.org/extend/plugins/debug-bar/) that can easily display you information, such as template being used and so what you are looking at. |
29,822 | <p>I would like to add a custom bulk action to a custom post type. I came across the filter <code>bulk_actions-screenid</code>, <strike>which according to its <a href="http://codex.wordpress.org/Plugin_API/Filter_Reference/bulk_actions">documentation</a>, would do exactly as I wish</strike>. However, after about two ho... | [
{
"answer_id": 29823,
"author": "scribu",
"author_id": 205,
"author_profile": "https://wordpress.stackexchange.com/users/205",
"pm_score": 3,
"selected": false,
"text": "<p>The <code>bulk_actions-*</code> filter doesn't allow you to add custom bulk actions precisely because it's tricky t... | 2011/09/29 | [
"https://wordpress.stackexchange.com/questions/29822",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/6228/"
] | I would like to add a custom bulk action to a custom post type. I came across the filter `bulk_actions-screenid`, which according to its [documentation](http://codex.wordpress.org/Plugin_API/Filter_Reference/bulk_actions), would do exactly as I wish. However, after about two hours of debugging I found the following com... | I think the latest major release warrants a new answer to this question, considering the popularity of this question.
**Since WordPress 4.7 (released December 2016) it is possible to add custom bulk actions without using JavaScript.**
The filter `bulk_actions-{$screen}` (e.g. `bulk_actions-edit-page` for the pages ov... |
29,829 | <p>Does WordPress have any built-in pagination functions to show the page numbers instead of previous and next page links?</p>
<p>If not, how can I add that?</p>
<p>Thanks</p>
| [
{
"answer_id": 29823,
"author": "scribu",
"author_id": 205,
"author_profile": "https://wordpress.stackexchange.com/users/205",
"pm_score": 3,
"selected": false,
"text": "<p>The <code>bulk_actions-*</code> filter doesn't allow you to add custom bulk actions precisely because it's tricky t... | 2011/09/29 | [
"https://wordpress.stackexchange.com/questions/29829",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9049/"
] | Does WordPress have any built-in pagination functions to show the page numbers instead of previous and next page links?
If not, how can I add that?
Thanks | I think the latest major release warrants a new answer to this question, considering the popularity of this question.
**Since WordPress 4.7 (released December 2016) it is possible to add custom bulk actions without using JavaScript.**
The filter `bulk_actions-{$screen}` (e.g. `bulk_actions-edit-page` for the pages ov... |
29,847 | <p>I keep seeing this pattern, and wonder what it's for, how WP uses it internally:</p>
<pre><code>if ( empty($post) ) {
if ( isset($GLOBALS['post']) )
$_post = & $GLOBALS['post'];
else
return $null;
} elseif ( is_object($post) && empty($post->filter) ) {
... | [
{
"answer_id": 29853,
"author": "Roman",
"author_id": 3817,
"author_profile": "https://wordpress.stackexchange.com/users/3817",
"pm_score": 1,
"selected": false,
"text": "<p>@Shaan: I don't think that Tom was looking for a description about the WP Plugin API. He is looking for a descript... | 2011/09/29 | [
"https://wordpress.stackexchange.com/questions/29847",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3687/"
] | I keep seeing this pattern, and wonder what it's for, how WP uses it internally:
```
if ( empty($post) ) {
if ( isset($GLOBALS['post']) )
$_post = & $GLOBALS['post'];
else
return $null;
} elseif ( is_object($post) && empty($post->filter) ) {
_get_post_ancestors($post... | The $post->filter contains the context under which the contents of the post have been filtered. Context could be something like "display" indicating the post is meant to be displayed on the page.
This is done by the sanitization functions, to indicate under what context the post data was sanitized. Different contexts... |
29,857 | <p>I have added a new custom post type named: <strong>website_bookmarks</strong></p>
<p>I plan on using it as my bookmarks manager (going to export all my bookmarks from Google Chrome into my custom post type) for the following reasons</p>
<ul>
<li>Can search bookmarks easily</li>
<li>Can add tags (php, web design, e... | [
{
"answer_id": 29860,
"author": "Brooke.",
"author_id": 2204,
"author_profile": "https://wordpress.stackexchange.com/users/2204",
"pm_score": 3,
"selected": true,
"text": "<p>did you try <code>if (!isset($post_type))</code> or <code>if(empty($post_type))</code>?? For example I would try ... | 2011/09/29 | [
"https://wordpress.stackexchange.com/questions/29857",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8668/"
] | I have added a new custom post type named: **website\_bookmarks**
I plan on using it as my bookmarks manager (going to export all my bookmarks from Google Chrome into my custom post type) for the following reasons
* Can search bookmarks easily
* Can add tags (php, web design, etc...)
* Can add descriptions to explain... | did you try `if (!isset($post_type))` or `if(empty($post_type))`?? For example I would try this:
```
function mySearchFilter($query) {
$post_type = $_GET['post_type'];
if ($query->is_search) {
if (!empty($post_type)) {
$query->set('post_type', $post_type);
}
}
return $query;
}... |
29,866 | <p>I've created a custom post type, and i want to display and allow comments.</p>
<p>I have this in function.php : </p>
<pre><code>// Add Custom Post Types
add_action( 'init', 'thm_post_types' );
// Add Custom Post Types Function
require_once ( THEME_INCLUDES . 'theme-post-types.php' );
require_once ( T... | [
{
"answer_id": 29868,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 3,
"selected": true,
"text": "<p>Have you tried adding comment support to your custom post type, via <a href=\"http://codex.wordpress.org/Fun... | 2011/09/29 | [
"https://wordpress.stackexchange.com/questions/29866",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9061/"
] | I've created a custom post type, and i want to display and allow comments.
I have this in function.php :
```
// Add Custom Post Types
add_action( 'init', 'thm_post_types' );
// Add Custom Post Types Function
require_once ( THEME_INCLUDES . 'theme-post-types.php' );
require_once ( THEME_INCLUDES . 'them... | Have you tried adding comment support to your custom post type, via [`add_post_type_support()`](http://codex.wordpress.org/Function_Reference/add_post_type_support)?
e.g.
```
<?php
add_post_type_support( 'product', array( 'comments' ) );
?>
``` |
29,876 | <p>I have two membership levels e.g MYE 1 and MYE II. I am using wishlish plugin.</p>
<p>When a person enrolls in MYE I and then later enrolls in MYE II - they are currently blocked from using the same email address - most people only hve 1 email address that they like doing business in - Can we PLEASE allow them to u... | [
{
"answer_id": 29896,
"author": "Rev. Voodoo",
"author_id": 3429,
"author_profile": "https://wordpress.stackexchange.com/users/3429",
"pm_score": 0,
"selected": false,
"text": "<p>Are we discussing a specific plugin? Does it use standard WP signup?</p>\n\n<p>I don't see how usernames/ema... | 2011/09/30 | [
"https://wordpress.stackexchange.com/questions/29876",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9067/"
] | I have two membership levels e.g MYE 1 and MYE II. I am using wishlish plugin.
When a person enrolls in MYE I and then later enrolls in MYE II - they are currently blocked from using the same email address - most people only hve 1 email address that they like doing business in - Can we PLEASE allow them to use the sam... | I'm not sure what the wishlist plugin is but I think the best way to accomplish this may be to use custom user metadata.
Such as adding "enrolled\_in" to the meta\_data then check for the value.
```
<?php if is_user_logged_in(){
global $user_ID;
$member_level = get_user_meta($user_ID, "member_level", true);
//... |
29,881 | <p>I'm wondering if there's a simple way top stop WordPress automatically hardcoding featured image height and width attributes, other than using regex...</p>
<p>As I'm using a flexible grid for my project (who isn't!) this is causing some funky image issues.</p>
| [
{
"answer_id": 29883,
"author": "Vilius Paulauskas",
"author_id": 9040,
"author_profile": "https://wordpress.stackexchange.com/users/9040",
"pm_score": 4,
"selected": true,
"text": "<p>You can get featured image URL and add it to your content manually, eg:</p>\n\n<pre><code><?php \n$i... | 2011/09/30 | [
"https://wordpress.stackexchange.com/questions/29881",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9069/"
] | I'm wondering if there's a simple way top stop WordPress automatically hardcoding featured image height and width attributes, other than using regex...
As I'm using a flexible grid for my project (who isn't!) this is causing some funky image issues. | You can get featured image URL and add it to your content manually, eg:
```
<?php
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' );
if ($image) : ?>
<img src="<?php echo $image[0]; ?>" alt="" />
<?php endif; ?>
``` |
29,897 | <p>How do I set my custom loop to only show top-level posts? I have a hierarchical custom post type and the archive page shows both the parent and child posts.</p>
| [
{
"answer_id": 29904,
"author": "Manny Fleurmond",
"author_id": 2234,
"author_profile": "https://wordpress.stackexchange.com/users/2234",
"pm_score": 5,
"selected": true,
"text": "<p>This solution is based on some code by <a href=\"http://justintadlock.com/archives/2010/02/02/showing-cus... | 2011/09/30 | [
"https://wordpress.stackexchange.com/questions/29897",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1057/"
] | How do I set my custom loop to only show top-level posts? I have a hierarchical custom post type and the archive page shows both the parent and child posts. | This solution is based on some code by [Justin Tadlock](http://justintadlock.com/archives/2010/02/02/showing-custom-post-types-on-your-home-blog-page). pre\_get\_posts is called before WordPress gets the posts of the main loop. Basically, you test to see if the page is the archive of the post type and make sure post\_p... |
29,918 | <p>I would like to query only pages with a certain page template with <code>WP_Query</code> or a function that would return the post object, but I can't find any information about that on the official codex.</p>
| [
{
"answer_id": 29943,
"author": "anmari",
"author_id": 3569,
"author_profile": "https://wordpress.stackexchange.com/users/3569",
"pm_score": 1,
"selected": false,
"text": "<p>The page template is stored as a meta value with key \"_wp_page_template\".</p>\n\n<p>So all you need is to use t... | 2011/09/30 | [
"https://wordpress.stackexchange.com/questions/29918",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9082/"
] | I would like to query only pages with a certain page template with `WP_Query` or a function that would return the post object, but I can't find any information about that on the official codex. | UPDATE:
This is now a decade old answer, meant for a very old version of WordPress. I can see the comments informing me that this might not work for newer WP versions, please do refer to the other answers below if mine is not working for your version of WP. For WP 2.\*, this will work.
Try this...
Assuming the templat... |
29,921 | <p>I'm working on a theme index.php and it seems that when I use the "template_directory" it is not actually pulling the url path of the file, but instead is just pulling the main domain name. So instead of </p>
<pre><code> http://example.com/wp-content/themes/theme_name/images/pic.jpg
</code></pre>
<p>its pulling th... | [
{
"answer_id": 29928,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 1,
"selected": false,
"text": "<p>I suspect one of two things:</p>\n<ol>\n<li><p>You're not using the correct template tag.</p>\n<p>Are you u... | 2011/09/30 | [
"https://wordpress.stackexchange.com/questions/29921",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8720/"
] | I'm working on a theme index.php and it seems that when I use the "template\_directory" it is not actually pulling the url path of the file, but instead is just pulling the main domain name. So instead of
```
http://example.com/wp-content/themes/theme_name/images/pic.jpg
```
its pulling the domain url and showing ... | To get the exact path of image which is placed in <http://example.com/wp-content/themes/theme_name/images/pic.jpg> in your theme.
All you have to use below code:
1. To show image
>
>
> ```
> <img src="<?php bloginfo('template_url'); ?>/images/pic.jpg" />
>
> ```
>
> |
29,932 | <p>Standard WordPress post types have "Post Tags" which can be used to "tag" posts with similar content, makes those similar posts easily accessible just by opening that particular tag page and receiving the list of all posts.</p>
<p>I need exactly the same thing with my custom post types:</p>
<ul>
<li>ability to tag... | [
{
"answer_id": 29933,
"author": "Fred Rocha",
"author_id": 1450,
"author_profile": "https://wordpress.stackexchange.com/users/1450",
"pm_score": 1,
"selected": false,
"text": "<p>Easy. Funny enough I was tackling that very same issue myself.</p>\n\n<p>Get yourself the \"Custom Post Type ... | 2011/09/30 | [
"https://wordpress.stackexchange.com/questions/29932",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1376/"
] | Standard WordPress post types have "Post Tags" which can be used to "tag" posts with similar content, makes those similar posts easily accessible just by opening that particular tag page and receiving the list of all posts.
I need exactly the same thing with my custom post types:
* ability to tag the post with multip... | I actually managed to figure it out and did it just beside the code of my custom post type. Like Fred suggested, I need to add a taxonomy to my custom post type called "tag".
And this is the way to do it:
```
register_taxonomy
(
'myposttype-tag',
array('myposttype'),
array
(
'hierarchical' =>... |
29,955 | <p>Hello I need to have the following code on a specific page:</p>
<pre><code><div class="searchbar" >
<div class="searchbar-inner" >
search <input type="text" id="search" />
<span class="result-count" ></span>
</div>
<... | [
{
"answer_id": 29948,
"author": "Community",
"author_id": -1,
"author_profile": "https://wordpress.stackexchange.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "<p>You should spend some time in the word press documentation </p>\n\n<p><a href=\"http://wordpress.org/extend/plugin... | 2011/10/01 | [
"https://wordpress.stackexchange.com/questions/29955",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9011/"
] | Hello I need to have the following code on a specific page:
```
<div class="searchbar" >
<div class="searchbar-inner" >
search <input type="text" id="search" />
<span class="result-count" ></span>
</div>
</div>
```
Is it possible that I use a shortcode to ... | You should spend some time in the word press documentation
[disable Rss](http://wordpress.org/extend/plugins/disable-rss/)
More [here](http://codex.wordpress.org/Main_Page) |
29,957 | <p>Full disclosure, PHP and Wordpress are not my specialties.</p>
<p>I've got this plugin here -> <a href="http://wordpress.org/extend/plugins/ustream-status/" rel="nofollow">http://wordpress.org/extend/plugins/ustream-status/</a> that adds a Widget that will show if my Ustream.tv channel is on the air or off the air.... | [
{
"answer_id": 29963,
"author": "anmari",
"author_id": 3569,
"author_profile": "https://wordpress.stackexchange.com/users/3569",
"pm_score": 0,
"selected": false,
"text": "<p>I had a similar need - wanting a widget with its settings, but not in a sidebar. If the widget developer has not... | 2011/10/01 | [
"https://wordpress.stackexchange.com/questions/29957",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7298/"
] | Full disclosure, PHP and Wordpress are not my specialties.
I've got this plugin here -> <http://wordpress.org/extend/plugins/ustream-status/> that adds a Widget that will show if my Ustream.tv channel is on the air or off the air. The widget itself has fields where I enter my channel name so that it can check it for m... | The correct "WordPress" way of doing it would be to use [**the\_widget**](http://codex.wordpress.org/Function_Reference/the_widget) template tag to display widgets anywhere you want.
so in you case you would something like this:
```
$instance['account'] = 'account name'; //Ustream channel name
$instance['online'] = '... |
29,960 | <p>What plugin will allow me to redirect 404 errors to a specific WP page...and track all 404 errors?</p>
<p>I'd like to just use a plugin that will redirect without having to edit templates and such.</p>
| [
{
"answer_id": 29979,
"author": "Jono Warren",
"author_id": 8872,
"author_profile": "https://wordpress.stackexchange.com/users/8872",
"pm_score": 0,
"selected": false,
"text": "<p>You can make a 404 page by creating a file in your theme called <code>404.php</code> and filling that with w... | 2011/10/01 | [
"https://wordpress.stackexchange.com/questions/29960",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4088/"
] | What plugin will allow me to redirect 404 errors to a specific WP page...and track all 404 errors?
I'd like to just use a plugin that will redirect without having to edit templates and such. | add these to your function.php
```
add_action( 'template_redirect', 'custom_redirect', 1 );
function custom_redirect() {
$direction = get_permalink( 12 ); // Or whatever the page_id is ...
if ( is_404() ) wp_redirect( $direction );
}
```
There. But it still not tracking the 404 errors. Unless you add more sp... |
29,974 | <p>I'm trying to push some variables to google analytics and would like to be able to detect if a shortcode has been included on a page at all.</p>
<p>Anybody know a smart way going about this?</p>
<p>Thank you!</p>
<p>Noel</p>
| [
{
"answer_id": 29975,
"author": "anmari",
"author_id": 3569,
"author_profile": "https://wordpress.stackexchange.com/users/3569",
"pm_score": 4,
"selected": true,
"text": "<p>I have sometimes wondered the same thing - whether wp maybe checked on save and kept a register etc</p>\n\n<p>I ha... | 2011/10/01 | [
"https://wordpress.stackexchange.com/questions/29974",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/2393/"
] | I'm trying to push some variables to google analytics and would like to be able to detect if a shortcode has been included on a page at all.
Anybody know a smart way going about this?
Thank you!
Noel | I have sometimes wondered the same thing - whether wp maybe checked on save and kept a register etc
I had a quick look at the code, and it seems not.
There is however a global `$shortcode_tags`, and wp has this function
```
function get_shortcode_regex() {
global $shortcode_tags;
$tagnames = array_keys($shor... |
30,004 | <p>If I wanted to show a slider on the home page only, is it better or does it make a difference if I:</p>
<ul>
<li>use a PHP if/then statement and echo a division and markup, or </li>
<li>use CSS along with a body class and display none the division? or</li>
<li>a combination of both</li>
</ul>
<p>What's the best pr... | [
{
"answer_id": 30005,
"author": "Ijaas",
"author_id": 9085,
"author_profile": "https://wordpress.stackexchange.com/users/9085",
"pm_score": 2,
"selected": true,
"text": "<p>target homepage only with if statement.</p>\n\n<pre><code>if ( is_front_page() or is_home() )\n\n}\n</code></pre>\n... | 2011/10/02 | [
"https://wordpress.stackexchange.com/questions/30004",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8678/"
] | If I wanted to show a slider on the home page only, is it better or does it make a difference if I:
* use a PHP if/then statement and echo a division and markup, or
* use CSS along with a body class and display none the division? or
* a combination of both
What's the best practice? | target homepage only with if statement.
```
if ( is_front_page() or is_home() )
}
```
if your home page has page/2 page/3 then use the following to display the slider on only page 1 of the homepage.
```
if ( is_front_page() or is_home() && ! is_paged() ) {
}
``` |
30,007 | <p>I'm in the process of building out a search page to perform a query on a custom post type and its associated meta and taxonomy. Eventually, I would it to query multiple taxonomies as well as compare values to those in the meta (ie - find posts with foo between X and Y).</p>
<p>I have a pretty good understanding of... | [
{
"answer_id": 30005,
"author": "Ijaas",
"author_id": 9085,
"author_profile": "https://wordpress.stackexchange.com/users/9085",
"pm_score": 2,
"selected": true,
"text": "<p>target homepage only with if statement.</p>\n\n<pre><code>if ( is_front_page() or is_home() )\n\n}\n</code></pre>\n... | 2011/10/02 | [
"https://wordpress.stackexchange.com/questions/30007",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8906/"
] | I'm in the process of building out a search page to perform a query on a custom post type and its associated meta and taxonomy. Eventually, I would it to query multiple taxonomies as well as compare values to those in the meta (ie - find posts with foo between X and Y).
I have a pretty good understanding of the query ... | target homepage only with if statement.
```
if ( is_front_page() or is_home() )
}
```
if your home page has page/2 page/3 then use the following to display the slider on only page 1 of the homepage.
```
if ( is_front_page() or is_home() && ! is_paged() ) {
}
``` |
30,021 | <p>in my theme I want to define a series of custom post types and custom taxonomies, each one having its own customized slug; the base language of my theme is english, therefore the slugs will be in English language</p>
<p>for example while defining the slug of custom post type "product" args:</p>
<pre><code>'rewrite... | [
{
"answer_id": 30705,
"author": "chifliiiii",
"author_id": 4130,
"author_profile": "https://wordpress.stackexchange.com/users/4130",
"pm_score": 1,
"selected": false,
"text": "<p>If that doest not work Why not you just simple do:</p>\n\n<pre><code>$post_slug= __('product', 'mytextdomain... | 2011/10/02 | [
"https://wordpress.stackexchange.com/questions/30021",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8421/"
] | in my theme I want to define a series of custom post types and custom taxonomies, each one having its own customized slug; the base language of my theme is english, therefore the slugs will be in English language
for example while defining the slug of custom post type "product" args:
```
'rewrite' => array( 'slug' =>... | I wouldn't try to localize your slugs. Instead, why not give your users the option to change them by adding another field to the permalink settings page?
Hook into `load-options-permalink.php` and set up some things to catch the `$_POST` data to save your slug. Also add a settings field to the page.
```
<?php
add_act... |
30,028 | <p>I've been searching for a code snippet that lets me limit the title length similar to what you can to with the_excerpt and then just display "(...)" if the title is too long.
I'd like to use that in loops outside of single.php, e.g. in my sidebar where an extremely long title would harm the layout.</p>
<p>All I cou... | [
{
"answer_id": 30044,
"author": "EAMann",
"author_id": 46,
"author_profile": "https://wordpress.stackexchange.com/users/46",
"pm_score": 3,
"selected": true,
"text": "<p>This depends 100% on how you're getting the title. If you're using a global object (i.e. <code>$post->post_title</... | 2011/10/02 | [
"https://wordpress.stackexchange.com/questions/30028",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/6903/"
] | I've been searching for a code snippet that lets me limit the title length similar to what you can to with the\_excerpt and then just display "(...)" if the title is too long.
I'd like to use that in loops outside of single.php, e.g. in my sidebar where an extremely long title would harm the layout.
All I could find w... | This depends 100% on how you're getting the title. If you're using a global object (i.e. `$post->post_title` then you're not passing it through any filters and you'll have to use some fancy post-processing to pare the title down.
However, if you're inside a post loop, use either `the_title()` to echo the current post'... |
30,029 | <p><br/>
I downloaded a free theme and I changed everything except the footer I can't change it.
I opened the file <strong>footer.php</strong> and there was only written as shown:</p>
<pre><code></div><!-- /content-wrapper -->
<div id="footer"><?php wp_footer(); ?>
<ul id="footer-nav">
... | [
{
"answer_id": 30042,
"author": "EAMann",
"author_id": 46,
"author_profile": "https://wordpress.stackexchange.com/users/46",
"pm_score": 3,
"selected": true,
"text": "<p>The <code>wp_footer()</code> function is a WordPress hook. It allows plugins to place additional content at the botto... | 2011/10/02 | [
"https://wordpress.stackexchange.com/questions/30029",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8984/"
] | I downloaded a free theme and I changed everything except the footer I can't change it.
I opened the file **footer.php** and there was only written as shown:
```
</div><!-- /content-wrapper -->
<div id="footer"><?php wp_footer(); ?>
<ul id="footer-nav">
<?php wp_list_pages('title_li=&depth=1' ); ?>
</div>
</div>
... | The `wp_footer()` function is a WordPress hook. It allows plugins to place additional content at the bottom of the page - this is very useful if you're installing tracking scripts like Google Analytics.
But that function is *not* what is adding copyright information or other junk usually bundled with free themes.
Ins... |
30,033 | <p>A friend's heavily customized blog has a category with a specific <code>categoryname-single.php</code> file to display posts.</p>
<p>Apparently for no special reason, since yesterday, <code>the_content()</code> is not returning any content any more for posts in that category, even though the WP back-end is clearly... | [
{
"answer_id": 30042,
"author": "EAMann",
"author_id": 46,
"author_profile": "https://wordpress.stackexchange.com/users/46",
"pm_score": 3,
"selected": true,
"text": "<p>The <code>wp_footer()</code> function is a WordPress hook. It allows plugins to place additional content at the botto... | 2011/10/02 | [
"https://wordpress.stackexchange.com/questions/30033",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/2161/"
] | A friend's heavily customized blog has a category with a specific `categoryname-single.php` file to display posts.
Apparently for no special reason, since yesterday, `the_content()` is not returning any content any more for posts in that category, even though the WP back-end is clearly showing content in the post.
Al... | The `wp_footer()` function is a WordPress hook. It allows plugins to place additional content at the bottom of the page - this is very useful if you're installing tracking scripts like Google Analytics.
But that function is *not* what is adding copyright information or other junk usually bundled with free themes.
Ins... |
30,036 | <p>I know it is possible to change the WordPress category list to radio buttons in the admin panel for posts, but I would like to make the just the Parents radio buttons and the sub categories or children checkboxs... something like this. </p>
<pre><code><ul>
<li><input type="radio"> Category 1
... | [
{
"answer_id": 35805,
"author": "uwiuw",
"author_id": 10921,
"author_profile": "https://wordpress.stackexchange.com/users/10921",
"pm_score": 0,
"selected": false,
"text": "<p>If the function use a walker type, then override by an extended child class of the walker. </p>\n\n<p>If you do ... | 2011/09/18 | [
"https://wordpress.stackexchange.com/questions/30036",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | I know it is possible to change the WordPress category list to radio buttons in the admin panel for posts, but I would like to make the just the Parents radio buttons and the sub categories or children checkboxs... something like this.
```
<ul>
<li><input type="radio"> Category 1
<ul class="children">
... | I'm pretty sure you could use JavaScript to do this for you very simply. I'd try this out:
```
function convert_root_cats_to_radio()
{
global $post_type;
if ( 'post' != $post_type )
return;
?>
<script type="text/javascript">
jQuery("#categorychecklist>li>label input").each(function(){
... |
30,037 | <p>In wordpress you have a few 'default' archive URL's. Like for example: <a href="http://www.mydomain.com/2011/">http://www.mydomain.com/2011/</a> generates an overview of the posts of (only) that year.</p>
<p>If you have an category blogs the url <a href="http://www.mydomain.com/blogs/">http://www.mydomain.com/blogs... | [
{
"answer_id": 32338,
"author": "Tom Auger",
"author_id": 3687,
"author_profile": "https://wordpress.stackexchange.com/users/3687",
"pm_score": 2,
"selected": false,
"text": "<p><code>http://myblog.com/?post_type=post</code> for a list of all posts, probably sorted in descending order by... | 2011/10/02 | [
"https://wordpress.stackexchange.com/questions/30037",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | In wordpress you have a few 'default' archive URL's. Like for example: <http://www.mydomain.com/2011/> generates an overview of the posts of (only) that year.
If you have an category blogs the url <http://www.mydomain.com/blogs/> generates an overview of all the posts within that category. (Spread over multiple pages)... | This may be an old question, but all the answers here are incorrect.
If the front page is set to a static page, and another page is set to the blog page, this will dynamically fetch and echo the URL for the *blog archive page* (i.e. blog index page)...
```
<?php echo get_permalink( get_option( 'page_for_posts' ) ) ?... |
30,039 | <p>Is it possible to display related posts from same category as the current post?</p>
| [
{
"answer_id": 30041,
"author": "Michael",
"author_id": 4884,
"author_profile": "https://wordpress.stackexchange.com/users/4884",
"pm_score": 6,
"selected": true,
"text": "<p>One possibility:</p>\n\n<pre><code>$related = get_posts( \n array( \n 'category__in' => wp_get_post_... | 2011/10/02 | [
"https://wordpress.stackexchange.com/questions/30039",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9061/"
] | Is it possible to display related posts from same category as the current post? | One possibility:
```
$related = get_posts(
array(
'category__in' => wp_get_post_categories( $post->ID ),
'numberposts' => 5,
'post__not_in' => array( $post->ID )
)
);
if( $related ) {
foreach( $related as $post ) {
setup_postdata($post);
/*whatever you want ... |
30,049 | <p>I would like to filter <code>wp_generate_tag_cloud</code> so each of the tag links include the slug as a class. More specifically, I would like to output "tag-" + the tag slug. </p>
<p>Currently what is assigned as the class is "tag-link-" + the tag ID.</p>
<p>The the end, I would happy with either a replacement o... | [
{
"answer_id": 30055,
"author": "Michael",
"author_id": 4884,
"author_profile": "https://wordpress.stackexchange.com/users/4884",
"pm_score": 3,
"selected": true,
"text": "<p>one possible way:\nadd a filter in functions.php of your theme:</p>\n\n<pre><code>add_filter ( 'wp_tag_cloud', 't... | 2011/10/02 | [
"https://wordpress.stackexchange.com/questions/30049",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4258/"
] | I would like to filter `wp_generate_tag_cloud` so each of the tag links include the slug as a class. More specifically, I would like to output "tag-" + the tag slug.
Currently what is assigned as the class is "tag-link-" + the tag ID.
The the end, I would happy with either a replacement or just adding this additiona... | one possible way:
add a filter in functions.php of your theme:
```
add_filter ( 'wp_tag_cloud', 'tag_cloud_slug_class' );
function tag_cloud_slug_class( $taglinks ) {
$tags = explode('</a>', $taglinks);
$regex = "#(.*tag-link[-])(.*)(' title.*)#e";
foreach( $tags as $tag ) {
$tagn[] = preg_rep... |
30,061 | <p>I'm new to wordpress and modifying the code that's already working on a website. I want to get user's ID but I haven't figured out yet how. The following sample code works on my local environment but it only returs 0 for a user ID on the production site. Any idea would be appreciated.</p>
<pre><code><?php
$docro... | [
{
"answer_id": 30072,
"author": "Rutwick Gangurde",
"author_id": 4740,
"author_profile": "https://wordpress.stackexchange.com/users/4740",
"pm_score": 1,
"selected": false,
"text": "<p>Use <code>global $current_user</code>, followed by <code>get_currentuserinfo()</code>. <code>$current_u... | 2011/10/02 | [
"https://wordpress.stackexchange.com/questions/30061",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8810/"
] | I'm new to wordpress and modifying the code that's already working on a website. I want to get user's ID but I haven't figured out yet how. The following sample code works on my local environment but it only returs 0 for a user ID on the production site. Any idea would be appreciated.
```
<?php
$docroot = "/home/produ... | `wp_get_current_user()` is actually just a wrapper for `$current_user` and `get_currentuserinfo()`, so you can use both. It's important, though, to only call it on or after the `init` hook. Calling it before will only return 0, as you've experienced. |
30,066 | <p>I have a widgetized area and I am trying to add a new widget that can be added to my widget area, </p>
<p>I need the code below to be the widget output</p>
<pre><code><ul>
<?php
$args = array( 'taxonomy' => 'post_tag' );
$terms = get_terms('post_tag', $args);
$count = count($terms); $i=0;
if ($count &g... | [
{
"answer_id": 30074,
"author": "Tara",
"author_id": 5021,
"author_profile": "https://wordpress.stackexchange.com/users/5021",
"pm_score": 0,
"selected": false,
"text": "<p>see this codex for more info:\n<a href=\"http://codex.wordpress.org/Function_Reference/register_widget\" rel=\"nofo... | 2011/10/03 | [
"https://wordpress.stackexchange.com/questions/30066",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8668/"
] | I have a widgetized area and I am trying to add a new widget that can be added to my widget area,
I need the code below to be the widget output
```
<ul>
<?php
$args = array( 'taxonomy' => 'post_tag' );
$terms = get_terms('post_tag', $args);
$count = count($terms); $i=0;
if ($count > 0) {
foreach ($terms as $term... | I got it working now with the code below, not sure if it is the best way but it works good
```
/**
* Tag LIST widget class
*/
class WP_Widget_Tag_List extends WP_Widget
{
function __construct()
{
$widget_ops = array('description' => __("Your most used tags in List format"));
parent::__constr... |
30,068 | <p>I have Question how can i add custom meta box (Media Uploader) at category description, i mean when i will create or edit category then i can add any media file like PDF, </p>
<pre><code> <?php add_meta_box( $id, $title, $callback, $page, $context, $priority, $callback_args ); ?>
</code></pre>
<p>That is wo... | [
{
"answer_id": 30069,
"author": "Rutwick Gangurde",
"author_id": 4740,
"author_profile": "https://wordpress.stackexchange.com/users/4740",
"pm_score": 0,
"selected": false,
"text": "<p>Yes you can... check my answer here - <a href=\"https://wordpress.stackexchange.com/questions/28467/cus... | 2011/10/03 | [
"https://wordpress.stackexchange.com/questions/30068",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7463/"
] | I have Question how can i add custom meta box (Media Uploader) at category description, i mean when i will create or edit category then i can add any media file like PDF,
```
<?php add_meta_box( $id, $title, $callback, $page, $context, $priority, $callback_args ); ?>
```
That is wordpress meta box function but i ... | This can be achieved using the plugin [Advanced Custom Fields](http://wordpress.org/extend/plugins/advanced-custom-fields).
### Config

### Result
 |
30,077 | <p>Morning all,</p>
<p>I'm having some issues with excluding my custom post-type 'events' from my index.php loop for my Blog page.</p>
<p>I simply want to display the posts from my actual Blog, which I assume come under the post-type 'post', but when I try to display the 'post' type it also shows my 'events' post-typ... | [
{
"answer_id": 30092,
"author": "w3uiguru",
"author_id": 8982,
"author_profile": "https://wordpress.stackexchange.com/users/8982",
"pm_score": 2,
"selected": false,
"text": "<p>No need to exclude the <code>'events'</code> you just fetch the 'post' type.</p>\n\n<p>See the example -</p>\n\... | 2011/10/03 | [
"https://wordpress.stackexchange.com/questions/30077",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5883/"
] | Morning all,
I'm having some issues with excluding my custom post-type 'events' from my index.php loop for my Blog page.
I simply want to display the posts from my actual Blog, which I assume come under the post-type 'post', but when I try to display the 'post' type it also shows my 'events' post-type.
Here's my loo... | Try using the following before "`if (have posts()..`"
```
$args = array(
'post_type' => 'post',
'orderby' => 'rand',
'showposts' => '1'
);
query_posts( $args );
``` |
30,087 | <p>I have installed a widget so that I may add testimonials. This widget cycles through the testimonials in the sidebar and everything is fine. What I now want to do is create a testimonials page that retrieves all the entries from this widget. The functionality already exists in the widget to retrieve all the testimon... | [
{
"answer_id": 30092,
"author": "w3uiguru",
"author_id": 8982,
"author_profile": "https://wordpress.stackexchange.com/users/8982",
"pm_score": 2,
"selected": false,
"text": "<p>No need to exclude the <code>'events'</code> you just fetch the 'post' type.</p>\n\n<p>See the example -</p>\n\... | 2011/10/03 | [
"https://wordpress.stackexchange.com/questions/30087",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9124/"
] | I have installed a widget so that I may add testimonials. This widget cycles through the testimonials in the sidebar and everything is fine. What I now want to do is create a testimonials page that retrieves all the entries from this widget. The functionality already exists in the widget to retrieve all the testimonial... | Try using the following before "`if (have posts()..`"
```
$args = array(
'post_type' => 'post',
'orderby' => 'rand',
'showposts' => '1'
);
query_posts( $args );
``` |
30,094 | <p>So let's say i register a custom taxonomy called:</p>
<pre><code>Clients
</code></pre>
<p>With a few terms such as: <code>Microsoft, IBM, Apple</code></p>
<p>Under a CPT (custom post type) called <code>projects</code>:</p>
<h1>Permalinks</h1>
<p><code>/%year%/%monthnum%/%taxonomy%/%postname%/</code> this is the stru... | [
{
"answer_id": 30097,
"author": "Jamal Jama",
"author_id": 2474,
"author_profile": "https://wordpress.stackexchange.com/users/2474",
"pm_score": 0,
"selected": false,
"text": "<p>You cannot access the <code>clients</code> location because its not a term, its your taxonomy base.</p>\n\n<p... | 2011/10/03 | [
"https://wordpress.stackexchange.com/questions/30094",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4369/"
] | So let's say i register a custom taxonomy called:
```
Clients
```
With a few terms such as: `Microsoft, IBM, Apple`
Under a CPT (custom post type) called `projects`:
Permalinks
==========
`/%year%/%monthnum%/%taxonomy%/%postname%/` this is the structure i am using;
<http://www.example.com/projects/> - Displays A... | You need to write a custom rule. I did similar stuff for a recent project. Create a template, and assign it to a page, with slug as 'clients' (or anything you like, but change the slug in the following rule as well). Try the following code, use **functions.php**:
```
add_action('init', 'custom_rule');
function custom_... |
30,102 | <p>Our team has run in to a problem working with WordPress 3 multisite. We usually work with a local copy of the site (localhost/testsite) but with the same database to keep all changes up to date.</p>
<p>This works fine in a single install because you can override the database configs from PHP with: </p>
<pre><code>... | [
{
"answer_id": 42129,
"author": "Matthew Boynes",
"author_id": 12324,
"author_profile": "https://wordpress.stackexchange.com/users/12324",
"pm_score": 0,
"selected": false,
"text": "<p>This problem has been rectified in recent versions of WordPress. However, the easiest solution to this ... | 2010/09/29 | [
"https://wordpress.stackexchange.com/questions/30102",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1082/"
] | Our team has run in to a problem working with WordPress 3 multisite. We usually work with a local copy of the site (localhost/testsite) but with the same database to keep all changes up to date.
This works fine in a single install because you can override the database configs from PHP with:
```
define( 'URL', $path ... | Just came up with a solution to this issue posted here <https://stackoverflow.com/questions/12958123/override-wp-siteurl-and-wp-home-for-wordpress-multisite/>
Basically you do not copy the `wp_site` and `wp_blogs` tables to your development installs when pulling in a production database, and have pre-configured them l... |
30,117 | <p>I'd like to keep the javascript and css styles used by my widget inside their own files (and not add them to the theme).</p>
<p>But i can't seem to get wordpress to add them when the widget is actually used on a sidebar.</p>
<p>I've tried this:</p>
<p>inside the Class declaration, i've added 2 functions</p>
<pre... | [
{
"answer_id": 30119,
"author": "Bainternet",
"author_id": 2487,
"author_profile": "https://wordpress.stackexchange.com/users/2487",
"pm_score": 4,
"selected": true,
"text": "<p><code>wp_print_scripts</code> and <code>wp_print_styles</code> hooks are fired way before your widget function... | 2011/10/03 | [
"https://wordpress.stackexchange.com/questions/30117",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/82/"
] | I'd like to keep the javascript and css styles used by my widget inside their own files (and not add them to the theme).
But i can't seem to get wordpress to add them when the widget is actually used on a sidebar.
I've tried this:
inside the Class declaration, i've added 2 functions
```
class EssentielleRubriquesPo... | `wp_print_scripts` and `wp_print_styles` hooks are fired way before your widget function so that is way it's not working.
A solution to that would be to include the scripts in the footer using `wp_print_footer_scripts` hook, take a look at [Jan's answer to a similar question](https://wordpress.stackexchange.com/questi... |
30,121 | <p>I'm trying to show all the posts associated with a Taxonomy (not a term) but it seems to not work.</p>
<pre><code><?php
$args = array(
'post_type' => 'projects',
'tax_query' => array(
array(
'taxonomy' => 'clients',
'terms' => 'Unilever'
)
)
);
$th... | [
{
"answer_id": 30125,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 2,
"selected": true,
"text": "<p>You haven't specified the 'field' value e.g. <code>'field' => 'slug',</code></p>\n\n<p><a href=\"http://cod... | 2011/10/03 | [
"https://wordpress.stackexchange.com/questions/30121",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4369/"
] | I'm trying to show all the posts associated with a Taxonomy (not a term) but it seems to not work.
```
<?php
$args = array(
'post_type' => 'projects',
'tax_query' => array(
array(
'taxonomy' => 'clients',
'terms' => 'Unilever'
)
)
);
$the_query = new WP_query();
$th... | You haven't specified the 'field' value e.g. `'field' => 'slug',`
<http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters> |
30,127 | <pre><code>(function($) {
$(document).ready(function(){
/*$('body').css('position','relative');
$('body').animate({'left':'-9999px'},3000);*/
alert('hello');
});
}(jQuery));
</code></pre>
<p>Tried also</p>
<pre><code>$(document).ready(function(){
/*$('body').css('position',... | [
{
"answer_id": 30129,
"author": "pixeline",
"author_id": 82,
"author_profile": "https://wordpress.stackexchange.com/users/82",
"pm_score": 0,
"selected": false,
"text": "<p>try this:</p>\n\n<pre><code>jQuery.noConflict();\njQuery(document).ready(function($) {\n alert(\"hello\");\n\n});... | 2011/10/03 | [
"https://wordpress.stackexchange.com/questions/30127",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3435/"
] | ```
(function($) {
$(document).ready(function(){
/*$('body').css('position','relative');
$('body').animate({'left':'-9999px'},3000);*/
alert('hello');
});
}(jQuery));
```
Tried also
```
$(document).ready(function(){
/*$('body').css('position','relative');
$('bo... | Are you sure the jQuery library is loaded on your page? The error you're getting implies it isn't. View the source and search for jQuery.
Then try adding this some where in your functions.php (or plugin) file and see if your script works.
```
<?php
add_action( 'wp_enqueue_scripts', 'wpse30127_enqueue' );
function wps... |
30,139 | <p>I'm wondering if it is possible to add different classes to second/third/fourth/etc-level items that have children in Appearance > Menus tree?</p>
<p>That's how I call the menu:</p>
<pre><code> <?php $menu_args = array(
'container' => '',
'menu_class' => '',
'menu_id' =>... | [
{
"answer_id": 30150,
"author": "SarahA",
"author_id": 8515,
"author_profile": "https://wordpress.stackexchange.com/users/8515",
"pm_score": 2,
"selected": false,
"text": "<p>One solution is to add a custom CSS class when you're creating/editing your menu in the admin. If you don't alrea... | 2011/10/03 | [
"https://wordpress.stackexchange.com/questions/30139",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1869/"
] | I'm wondering if it is possible to add different classes to second/third/fourth/etc-level items that have children in Appearance > Menus tree?
That's how I call the menu:
```
<?php $menu_args = array(
'container' => '',
'menu_class' => '',
'menu_id' => 'my-menu',
'walker' ... | There are two ways of doing this:
* Javascript. You could use JQuery to select the `<li>` that have `<ul>` children of class 'sub-menu', inserting content, or appending a CSS class which you then style. For example: `$('.sub-menu').parent().addClass('myclass')`
* PHP, a new walker function. Copy the code from wp-inclu... |
30,162 | <p>I'am developing a plugin that will push files to a remote server via http upload. Currently I got it to work with CURL doing something like this:</p>
<pre><code>$post = array("post_file"=>"@/path/FILE.EXT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
</code></pre>
<p>Now my question is how I can achieve the ... | [
{
"answer_id": 30182,
"author": "Otto",
"author_id": 2232,
"author_profile": "https://wordpress.stackexchange.com/users/2232",
"pm_score": 2,
"selected": false,
"text": "<p>Something like this, perhaps.</p>\n\n<pre><code>$args['body'] = array('post_file'=>'@/path/FILE.EXT');\nwp_remot... | 2011/10/03 | [
"https://wordpress.stackexchange.com/questions/30162",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5873/"
] | I'am developing a plugin that will push files to a remote server via http upload. Currently I got it to work with CURL doing something like this:
```
$post = array("post_file"=>"@/path/FILE.EXT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
```
Now my question is how I can achieve the same using wp\_remote\_host. ... | Something like this, perhaps.
```
$args['body'] = array('post_file'=>'@/path/FILE.EXT');
wp_remote_post($url, $args);
```
The $args array contains the parameters for the post. The body parameter controls what is posted. There's many other possible parameters as well. See <http://codex.wordpress.org/HTTP_API#Other_Ar... |
30,165 | <p>How to make that google wont follow these two pages:</p>
<p><a href="http://mysite.com/products-page/your-account/" rel="nofollow">http://mysite.com/products-page/your-account/</a>
http://mysite.com/products-page/checkout/</p>
<p>Thanks!</p>
<p>P.S. Im using worpdress with WP Ecommerce plugin.</p>
| [
{
"answer_id": 30182,
"author": "Otto",
"author_id": 2232,
"author_profile": "https://wordpress.stackexchange.com/users/2232",
"pm_score": 2,
"selected": false,
"text": "<p>Something like this, perhaps.</p>\n\n<pre><code>$args['body'] = array('post_file'=>'@/path/FILE.EXT');\nwp_remot... | 2011/10/03 | [
"https://wordpress.stackexchange.com/questions/30165",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7552/"
] | How to make that google wont follow these two pages:
<http://mysite.com/products-page/your-account/>
http://mysite.com/products-page/checkout/
Thanks!
P.S. Im using worpdress with WP Ecommerce plugin. | Something like this, perhaps.
```
$args['body'] = array('post_file'=>'@/path/FILE.EXT');
wp_remote_post($url, $args);
```
The $args array contains the parameters for the post. The body parameter controls what is posted. There's many other possible parameters as well. See <http://codex.wordpress.org/HTTP_API#Other_Ar... |
30,172 | <p>I have a simple custom shortcode plugin where you give it a tag and it'll display the titles of all the posts with that tag.</p>
<p>e.g. In my post if I type "[listposts tag=oct-2011]" it will output the titles of all posts tagged as "oct-2011".</p>
<p>This plugin has been working fine for me until the v3.2 upgrad... | [
{
"answer_id": 30192,
"author": "Rutwick Gangurde",
"author_id": 4740,
"author_profile": "https://wordpress.stackexchange.com/users/4740",
"pm_score": 0,
"selected": false,
"text": "<p>I checked your code locally, it works fine...</p>\n\n<pre><code>function listposts($atts) {\n $atts ... | 2011/10/03 | [
"https://wordpress.stackexchange.com/questions/30172",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9140/"
] | I have a simple custom shortcode plugin where you give it a tag and it'll display the titles of all the posts with that tag.
e.g. In my post if I type "[listposts tag=oct-2011]" it will output the titles of all posts tagged as "oct-2011".
This plugin has been working fine for me until the v3.2 upgrade.
Now, it still... | The [`get_posts()`](https://codex.wordpress.org/Template_Tags/get_posts) argument is supposed to be `numberposts` not `posts_per_page` and you were passing it as string. Try making it an integer.
```
function listposts( $atts ) {
$atts = shortcode_atts( array(
'tag' => 'jan-2011',
'... |
30,178 | <p>I know I can publicly show future posts in a loop using <code>'post_status' => 'future'</code> in WP_Query. But clicking on a future post's permalink will result in a 404 if you are not a logged-in user.</p>
<p>Suppose I have a post called Apocalypse in the post_type 'event', scheduled for 12-12-2099. The perma... | [
{
"answer_id": 30381,
"author": "supertrue",
"author_id": 3564,
"author_profile": "https://wordpress.stackexchange.com/users/3564",
"pm_score": 4,
"selected": true,
"text": "<p>In short, you can make future posts visible by telling Wordpress to mark them as <code>'published'</code> inste... | 2011/10/03 | [
"https://wordpress.stackexchange.com/questions/30178",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3564/"
] | I know I can publicly show future posts in a loop using `'post_status' => 'future'` in WP\_Query. But clicking on a future post's permalink will result in a 404 if you are not a logged-in user.
Suppose I have a post called Apocalypse in the post\_type 'event', scheduled for 12-12-2099. The permalink is *mysite.com/eve... | In short, you can make future posts visible by telling Wordpress to mark them as `'published'` instead of `'scheduled'`. You do this by using a `future_post` hook, which gets called when a post changes status. Each post type automatically gets its own future hook; since the custom post type I'm using is `event`, I can ... |
30,196 | <p>I'm attempting to create a Twitter style stream, so basically just index, a tag archive, and maybe a page or two while prohibiting access to everything else. For instance, they try to access a single post page and are tossed back to home. Is this appropriate use of redirects and wp_redirect, and if so, would it be b... | [
{
"answer_id": 30200,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 1,
"selected": false,
"text": "<p>It seems this would just be a function of your theme. If you don't provide links to single posts, categories, etc.,... | 2011/10/04 | [
"https://wordpress.stackexchange.com/questions/30196",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9152/"
] | I'm attempting to create a Twitter style stream, so basically just index, a tag archive, and maybe a page or two while prohibiting access to everything else. For instance, they try to access a single post page and are tossed back to home. Is this appropriate use of redirects and wp\_redirect, and if so, would it be bet... | It seems this would just be a function of your theme. If you don't provide links to single posts, categories, etc., then as far as your visitors are concerned, those things effectively don't exist.
If you really want to prevent access to things, you can't redirect in a template as headers have already been sent. You c... |
30,209 | <p>I develop my first wordpress plugin. I have not really found a tutorial "easy to use", so I started it.</p>
<p>Currently, the "add_menu" did not add my link to manage settings. Yet when I activate my plugin, wordpress does not display an error and tells me "extension enabled"</p>
<p>Can you help me? Here is my cod... | [
{
"answer_id": 30930,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 1,
"selected": false,
"text": "<p>WordPress is not written in these languages and have no assumed way to interact with them.</p>\n\n<p>You can access ... | 2011/10/04 | [
"https://wordpress.stackexchange.com/questions/30209",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9161/"
] | I develop my first wordpress plugin. I have not really found a tutorial "easy to use", so I started it.
Currently, the "add\_menu" did not add my link to manage settings. Yet when I activate my plugin, wordpress does not display an error and tells me "extension enabled"
Can you help me? Here is my code.
file "affili... | WordPress is not written in these languages and have no assumed way to interact with them.
You can access such info by connecting to WP database or by accessing WP-generated RSS feed, whatever is easier for tools you need to use. |
30,211 | <p>My Question is regarding User access control in wordpress</p>
<p>I have two user - admin (admin access) and user1(editor). My requirement is admin can do any modification in admin site. But user1 can only edit and update some pages and no access other access except assigned pages.</p>
<p>I have no idea how to impl... | [
{
"answer_id": 30221,
"author": "Community",
"author_id": -1,
"author_profile": "https://wordpress.stackexchange.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "<p>You can use a plugin like Justin Tadlock's <a href=\"http://wordpress.org/extend/plugins/members/\" rel=\"nofollow... | 2011/10/04 | [
"https://wordpress.stackexchange.com/questions/30211",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8982/"
] | My Question is regarding User access control in wordpress
I have two user - admin (admin access) and user1(editor). My requirement is admin can do any modification in admin site. But user1 can only edit and update some pages and no access other access except assigned pages.
I have no idea how to implement this functi... | Very interesting question. It's a bit outside the scope of the typical rolls/capabilities functionality as it's more fine grained (unless I'm wrong -- very possible).
The first step would be to put some sort of way in that you can assign which posts a user can edit.
It makes the most sense to stick that the user's p... |
30,228 | <p>i have a childtheme from twentyeleven,</p>
<p>i created a 'inicio' (name) custom menu,</p>
<p><img src="https://i.stack.imgur.com/GdWyS.jpg" alt="enter image description here"></p>
<p>how can I apply it?</p>
<p>tried:</p>
<pre><code><?php wp_nav_menu( array( 'theme_location' => 'inicio' ) ); ?>
</code>... | [
{
"answer_id": 30227,
"author": "Scott",
"author_id": 4610,
"author_profile": "https://wordpress.stackexchange.com/users/4610",
"pm_score": 0,
"selected": false,
"text": "<p>The only config to worry about with WordPress end is enabling/forcing SSL/HTTPS connections which can be done in t... | 2011/10/04 | [
"https://wordpress.stackexchange.com/questions/30228",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3435/"
] | i have a childtheme from twentyeleven,
i created a 'inicio' (name) custom menu,

how can I apply it?
tried:
```
<?php wp_nav_menu( array( 'theme_location' => 'inicio' ) ); ?>
```
but not working (not even change visible)
EDIT
Trying now:
head... | I did this recently for a client. A lot of it will depend on your host, though.
Most hosts are set up to only listen for traffic on port 80. SSL requires that Apache listen on port 443. You're seeing the default server page likely because Apache isn't set up to forward traffic for those subdomains.
You need to contac... |
30,231 | <p>I am creating 2 custom post types, and with the one displaying a list of the posts in #2.</p>
<p>I am 90% of the way there, have the select showing but can't get it populated with the custom post types posts from #2.</p>
<p>I am using get_posts to create the array, and then echoing into the select.</p>
<pre><code... | [
{
"answer_id": 30235,
"author": "sanchothefat",
"author_id": 1733,
"author_profile": "https://wordpress.stackexchange.com/users/1733",
"pm_score": 1,
"selected": false,
"text": "<p>You should look at the contents of <code>$option</code> before you try echoing it out. It contains all the ... | 2011/10/04 | [
"https://wordpress.stackexchange.com/questions/30231",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9166/"
] | I am creating 2 custom post types, and with the one displaying a list of the posts in #2.
I am 90% of the way there, have the select showing but can't get it populated with the custom post types posts from #2.
I am using get\_posts to create the array, and then echoing into the select.
```
$option_list = get_pages( ... | If 'Partners' is a custom post type, then why don't you use [get\_posts](http://codex.wordpress.org/Function_Reference/get_posts)? Try using it...
```
$pages = get_posts(array('post_type' => 'partners', 'posts_per_page'=> -1, 'post_status' => 'publish'));
echo '<select name="activitymeta_sel" id="activitymeta_sel">';
... |
30,241 | <p>I've checked around and haven't seen an answer which works as of yet. I have a WP_Query with the following arguments:</p>
<pre><code>$args = array(
'post_status' => 'publish',
'post_type' => 'listing',
'meta_key' => 'client_feedback_score',
'orderby' => 'client_feedback_score',
'orde... | [
{
"answer_id": 30243,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 8,
"selected": true,
"text": "<p><code>orderby</code> should be <code>meta_value_num</code>, or <code>meta_value</code>, not the name of the key. See... | 2011/10/04 | [
"https://wordpress.stackexchange.com/questions/30241",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5590/"
] | I've checked around and haven't seen an answer which works as of yet. I have a WP\_Query with the following arguments:
```
$args = array(
'post_status' => 'publish',
'post_type' => 'listing',
'meta_key' => 'client_feedback_score',
'orderby' => 'client_feedback_score',
'order' => 'DESC'
);
$query =... | `orderby` should be `meta_value_num`, or `meta_value`, not the name of the key. See [WP\_Query orderby parameters](https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters). |
30,252 | <p>I'm trying to create a custom menu that displays a <code><li></li></code> when a user is logged in, and not display it when they're not. I have this so far, but it's not working. Does anyone know how to do this properly? </p>
<pre><code>add_filter('wp_nav_menu_items','custom_nav_items',1,2);
function... | [
{
"answer_id": 30263,
"author": "Jamie",
"author_id": 3317,
"author_profile": "https://wordpress.stackexchange.com/users/3317",
"pm_score": 0,
"selected": false,
"text": "<p>There is a plugin available at <a href=\"http://wpsmith.net/my-plugins/wp-custom-menu-filter-plugin/\" rel=\"nofol... | 2011/10/04 | [
"https://wordpress.stackexchange.com/questions/30252",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9174/"
] | I'm trying to create a custom menu that displays a `<li></li>` when a user is logged in, and not display it when they're not. I have this so far, but it's not working. Does anyone know how to do this properly?
```
add_filter('wp_nav_menu_items','custom_nav_items',1,2);
function custom_nav_items($menu, $args) {
global... | I do not believe a plugin would be needed for this.
You could add a class to the menu item (enable the class field under Screen Options when you are editing the menu item). Also be sure that you have the `body_class()` function applied to your body tag. Then you can do:
```
.your-menu-item-class {
display: none;
... |
30,255 | <p>So I'm trying to query some posts from 1 category only and it does seem to be working. I tried get_post() also but no luck and after awhile I just caved and used query_posts (which is apparently bad practice). Here's my code:</p>
<pre><code><div id="primary">
<div id="content" role="main">
... | [
{
"answer_id": 30266,
"author": "wdalhaj",
"author_id": 9098,
"author_profile": "https://wordpress.stackexchange.com/users/9098",
"pm_score": 3,
"selected": true,
"text": "<p>Weird Problem!, try the following:</p>\n\n<ul>\n<li>Make sure that the targeted categories are not empty.</li>\n<... | 2011/10/04 | [
"https://wordpress.stackexchange.com/questions/30255",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7355/"
] | So I'm trying to query some posts from 1 category only and it does seem to be working. I tried get\_post() also but no luck and after awhile I just caved and used query\_posts (which is apparently bad practice). Here's my code:
```
<div id="primary">
<div id="content" role="main">
<?php que... | Weird Problem!, try the following:
* Make sure that the targeted categories are not empty.
* If you are using custom post type,include it in the query `'post_type'=>'advertisement'` for example.
* If the targeted categories are special taxonomies,make sure to include it in the query : `'term'=>'cars'` along with child... |
30,281 | <p>Is it possible to have a custom page template in a different folder?</p>
<p>I'm setting up a little framework for WordPress that I can use over and over for themes and just for the sake of being tidy I want to put custom page templates inside a different folder rather than the root of the theme directory.</p>
<p>H... | [
{
"answer_id": 30287,
"author": "Bainternet",
"author_id": 2487,
"author_profile": "https://wordpress.stackexchange.com/users/2487",
"pm_score": 3,
"selected": true,
"text": "<p>WordPress uses <code>get_page_template()</code> to determine the template file to use which can be altered by ... | 2011/10/04 | [
"https://wordpress.stackexchange.com/questions/30281",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9184/"
] | Is it possible to have a custom page template in a different folder?
I'm setting up a little framework for WordPress that I can use over and over for themes and just for the sake of being tidy I want to put custom page templates inside a different folder rather than the root of the theme directory.
How would one go a... | WordPress uses `get_page_template()` to determine the template file to use which can be altered by filters:
```
//for pages
add_filter( 'page_template', 'My_custom_page_template' );
function My_custom_page_template( $page_template )
{
if ( is_page( 'my-custom-page-slug' ) ) {
$page_template = 'pathto/custo... |
30,302 | <p>I'm showing a list of users like so:</p>
<pre><code><ul>
<?php $directors = get_users('role=director');
foreach ($directors as $director) {
$dir_id = $director->ID;
$dir_order = get_user_meta($dir_id, 'exit_director_order', TRUE);
$dir_link = get_blog... | [
{
"answer_id": 31045,
"author": "Niels",
"author_id": 6068,
"author_profile": "https://wordpress.stackexchange.com/users/6068",
"pm_score": 3,
"selected": true,
"text": "<p>Here's the solution. Comments included:</p>\n\n<pre><code><?php $results = get_users('role=director'); \n\n ... | 2011/10/05 | [
"https://wordpress.stackexchange.com/questions/30302",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/6068/"
] | I'm showing a list of users like so:
```
<ul>
<?php $directors = get_users('role=director');
foreach ($directors as $director) {
$dir_id = $director->ID;
$dir_order = get_user_meta($dir_id, 'exit_director_order', TRUE);
$dir_link = get_bloginfo('home').'/?author='.$... | Here's the solution. Comments included:
```
<?php $results = get_users('role=director');
foreach ($results as $result) {
// Get data about each user as an object
$user = get_userdata($result->ID);
// Create a flat array with only the fields we need
$direct... |
30,308 | <p>Simply put - how might I completely hide media files uploaded by any other users other then themselves? Id like to disable access to these links & files since they are a way for non-admin users to be able to access and edit a custom post type that is normally not visible to them otherwise in the backend of wordp... | [
{
"answer_id": 30449,
"author": "Wyck",
"author_id": 1509,
"author_profile": "https://wordpress.stackexchange.com/users/1509",
"pm_score": -1,
"selected": false,
"text": "<p>In all honestly with how WordPress works right now, you can't. You would have to write your own PHP to enable thi... | 2011/10/05 | [
"https://wordpress.stackexchange.com/questions/30308",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3567/"
] | Simply put - how might I completely hide media files uploaded by any other users other then themselves? Id like to disable access to these links & files since they are a way for non-admin users to be able to access and edit a custom post type that is normally not visible to them otherwise in the backend of wordpress.
... | Actually you can, and here's how to do it:
This code hides all posts and media that do not belong to the currently logged in author (you can change it to apply to other user roles). It also fixes the post and media count on the filter bars (e.g. All | Images | Videos | Unattached).
```
// Show only posts and media re... |