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 |
|---|---|---|---|---|---|---|
49,251 | <p>I have an unusual situation where I need to make the built-in post type 'page' non-hierarchical.</p>
<p>I printed the post type object with <code>var_dump(get_post_type_object('page')); die;</code> and I got this: </p>
<pre><code>object(stdClass)#164 (26) {
["labels"]=>
...
}
["description"]=>
stri... | [
{
"answer_id": 49252,
"author": "miahelf",
"author_id": 15252,
"author_profile": "https://wordpress.stackexchange.com/users/15252",
"pm_score": 0,
"selected": false,
"text": "<p>As far as I can tell, there is no (good) way to change the core post types. The alternative of course is to ma... | 2012/04/17 | [
"https://wordpress.stackexchange.com/questions/49251",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/6068/"
] | I have an unusual situation where I need to make the built-in post type 'page' non-hierarchical.
I printed the post type object with `var_dump(get_post_type_object('page')); die;` and I got this:
```
object(stdClass)#164 (26) {
["labels"]=>
...
}
["description"]=>
string(0) ""
["publicly_queryable"]=>
... | This is a pretty late answer, but I was looking to do something similar and figured it out. I wanted to get nav\_menu\_items into an RSS feed, which required changing the built in nav\_menu\_item post type property publicly\_queryable.
Anyway, it was actually pretty simple, here's a generic function to do it:
```
fun... |
49,264 | <p>I need to display author image along with posts. I used the following code to display posts with author image.</p>
<pre><code>$the_query = new WP_Query("post_type=post&paged=".get_query_var('paged'));
while ( $the_query->have_posts() ) : $the_query->the_post();
<?php the_excerpt(); ?>
<p><... | [
{
"answer_id": 49266,
"author": "miahelf",
"author_id": 15252,
"author_profile": "https://wordpress.stackexchange.com/users/15252",
"pm_score": 2,
"selected": false,
"text": "<p>If you are not using it inside a normal loop, get the author ID a different way and use the function like this... | 2012/04/17 | [
"https://wordpress.stackexchange.com/questions/49264",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15100/"
] | I need to display author image along with posts. I used the following code to display posts with author image.
```
$the_query = new WP_Query("post_type=post&paged=".get_query_var('paged'));
while ( $the_query->have_posts() ) : $the_query->the_post();
<?php the_excerpt(); ?>
<p><?php the_author_image(); ?></p>
<?php ... | I know this is old, but I just came across it shortly before I came across the solution.
To display the author image inside the loop, just use this code:
```
<?php echo get_avatar( get_the_author_meta( 'ID' ) , 32 ); ?>
```
Where '32' is the size of the image. If it's outside the loop, then just specify the author'... |
49,279 | <p>So I have a plugin with two user-customisable settings. (It's not complete but I'm getting the framework in place.) When the two settings are on the "general" settings page they work just fine...</p>
<pre><code>add_action('admin_init', 'mj_admin_init');
function mj_admin_init(){
register_setting('general', 'mj... | [
{
"answer_id": 53674,
"author": "Matthew Muro",
"author_id": 1511,
"author_profile": "https://wordpress.stackexchange.com/users/1511",
"pm_score": 1,
"selected": false,
"text": "<p>If you check the arguments for <a href=\"http://codex.wordpress.org/Function_Reference/add_menu_page\" rel=... | 2012/04/17 | [
"https://wordpress.stackexchange.com/questions/49279",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7640/"
] | So I have a plugin with two user-customisable settings. (It's not complete but I'm getting the framework in place.) When the two settings are on the "general" settings page they work just fine...
```
add_action('admin_init', 'mj_admin_init');
function mj_admin_init(){
register_setting('general', 'mj_options', 'mj_... | If you check the arguments for [add\_menu\_page](http://codex.wordpress.org/Function_Reference/add_menu_page), you'll see that the fifth argument is your callback function. And, right now, there's nothing in the mj\_admin function.
What you need to do is output your form in that function.
```
<?php
function mj_admin(... |
49,285 | <p>Maybe I simply do not understand what <code>get_template_part()</code> is doing …</p>
<p>I have a file called <code>event-list.php</code> that should work as template for other pages and files so all my events (a custom post type) get listed!</p>
<p>Inside this <code>event-list.php</code> I have this …</p>
<pre><... | [
{
"answer_id": 49282,
"author": "mor7ifer",
"author_id": 11740,
"author_profile": "https://wordpress.stackexchange.com/users/11740",
"pm_score": 0,
"selected": false,
"text": "<pre><code>add_filter( 'the_excerpt', 'wpse49280_strip_header_tags', 1 );\nfunction wpse49280_strip_header_tags(... | 2012/04/17 | [
"https://wordpress.stackexchange.com/questions/49285",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3529/"
] | Maybe I simply do not understand what `get_template_part()` is doing …
I have a file called `event-list.php` that should work as template for other pages and files so all my events (a custom post type) get listed!
Inside this `event-list.php` I have this …
```
<?php
$loop = new WP_Query( $args );
while ( $loop->have... | Rather than messing with regex, you might consider using a **user-defined excerpt** (i.e. a **manual excerpt**, which *retains* HTML tags, rather than relying solely on the automatic excerpt, which strips HTML tags.
Depending on your specific use case, using the manual excerpt for displaying HTML-formatted excerpts is... |
49,291 | <p>I have an URL (such as the URL <code>/sample-page/</code>), I need the corresponding object ID. How?</p>
| [
{
"answer_id": 49293,
"author": "shabushabu",
"author_id": 14944,
"author_profile": "https://wordpress.stackexchange.com/users/14944",
"pm_score": 3,
"selected": false,
"text": "<p>Try this function:</p>\n\n<pre><code>url_to_postid( $url );\n</code></pre>\n\n<p>The <a href=\"http://codex... | 2012/04/17 | [
"https://wordpress.stackexchange.com/questions/49291",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13880/"
] | I have an URL (such as the URL `/sample-page/`), I need the corresponding object ID. How? | Try this function:
```
url_to_postid( $url );
```
The [WordPress codex](http://codex.wordpress.org/Function_Reference/url_to_postid) is your friend. A quick Google search could have provided the answer. |
49,294 | <p>want to know who is login in my wordpress website if admin login then go to dashboard and if user login then go to homepage </p>
<p>Approach:
I used this code </p>
<pre><code><?php if ( is_user_logged_in() ) {
echo ‘ user is loin ‘ ;
} else {
echo ‘ Not Login ‘ ;
} ?>
</code></pre>
<p>and </p>
<pre... | [
{
"answer_id": 49296,
"author": "Sola",
"author_id": 14925,
"author_profile": "https://wordpress.stackexchange.com/users/14925",
"pm_score": 1,
"selected": false,
"text": "<p>is_admin() only checkes if the dashboard page is displayed or not, if you want to tell the role of a user, try <a... | 2012/04/17 | [
"https://wordpress.stackexchange.com/questions/49294",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14547/"
] | want to know who is login in my wordpress website if admin login then go to dashboard and if user login then go to homepage
Approach:
I used this code
```
<?php if ( is_user_logged_in() ) {
echo ‘ user is loin ‘ ;
} else {
echo ‘ Not Login ‘ ;
} ?>
```
and
```
if(is_admin()) { ...output my admin stuff..... | is\_admin() only checkes if the dashboard page is displayed or not, if you want to tell the role of a user, try [current\_user\_can( $capability )](http://codex.wordpress.org/Function_Reference/current_user_can) |
49,306 | <p>I don't consider myself to be a newb, I've had a loop of all the pages work before, but right now one of my custom loops on my page template (which is used as the index page of the site), will not show a list of 'pages'. </p>
<pre><code><?php get_header(); ?>
<?php if ( have_posts() ) while ( have_posts()... | [
{
"answer_id": 49307,
"author": "Boone Gorges",
"author_id": 14052,
"author_profile": "https://wordpress.stackexchange.com/users/14052",
"pm_score": 0,
"selected": false,
"text": "<p>Nothing is jumping out at me as being outright <em>wrong</em> (though you have some spotty use of bracket... | 2012/04/17 | [
"https://wordpress.stackexchange.com/questions/49306",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/6353/"
] | I don't consider myself to be a newb, I've had a loop of all the pages work before, but right now one of my custom loops on my page template (which is used as the index page of the site), will not show a list of 'pages'.
```
<?php get_header(); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> // ... | This is not the place to use query\_posts. query\_posts should only be used if you need to change the main loop. There is also no need to reset the query and your missing endif on both loops.
### I would use [get\_pages](http://codex.wordpress.org/Function_Reference/get_pages) instead of running a new WP\_Query.
```
... |
49,330 | <p>Here is how I am getting the views for one post:</p>
<pre><code>function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key... | [
{
"answer_id": 49350,
"author": "5t3ph",
"author_id": 6161,
"author_profile": "https://wordpress.stackexchange.com/users/6161",
"pm_score": 5,
"selected": true,
"text": "<p>View this section of the Codex to learn how to create a custom query:\n<a href=\"http://codex.wordpress.org/Class_R... | 2012/04/17 | [
"https://wordpress.stackexchange.com/questions/49330",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13169/"
] | Here is how I am getting the views for one post:
```
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
... | View this section of the Codex to learn how to create a custom query:
<http://codex.wordpress.org/Class_Reference/WP_Query>
Your query will be something like:
```
$query = new WP_Query( array(
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
'posts_per_page' => 5
) );
```
By default, the... |
49,331 | <p>Whilst writing some code that backs-up a plugin, I hit a problem with 'the wrong kind of directory slash' on my windows dev environment.</p>
<p>Tracking it through I find in default-constants.php:91</p>
<pre><code>define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
</code></pre>
<p>which is based on the follo... | [
{
"answer_id": 49337,
"author": "bueltge",
"author_id": 170,
"author_profile": "https://wordpress.stackexchange.com/users/170",
"pm_score": 1,
"selected": false,
"text": "<p>It is an constant, only a string. For the separator / have PHP an constant. \nAlso, this is WordPress, differently... | 2012/04/17 | [
"https://wordpress.stackexchange.com/questions/49331",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13623/"
] | Whilst writing some code that backs-up a plugin, I hit a problem with 'the wrong kind of directory slash' on my windows dev environment.
Tracking it through I find in default-constants.php:91
```
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
```
which is based on the following in default-constants.php:46
... | The forward slash works on every operating system supported by PHP. Yes, on Windows too. It is also more readable and easier to type, so there is no need to use the constant.
See the tickets [#20849](http://core.trac.wordpress.org/ticket/20849 "'ABSPATH' Invalid with Windows Servers") and [#15598](http://core.trac.wor... |
49,332 | <p>on my theme, i found this script</p>
<pre><code>add_image_size( 'slider', 464, 249, true );
add_image_size( 'fmenu', 306, 280, true );
add_image_size( 'teamthumb', 138, 207, true );
add_image_size( 'imlink', 286, 140, true );
add_image_size( 'albmlink', 274, 274, true );
add_image_size( 'fppost', 90, 90, true );
a... | [
{
"answer_id": 49338,
"author": "Michelle",
"author_id": 16,
"author_profile": "https://wordpress.stackexchange.com/users/16",
"pm_score": 4,
"selected": true,
"text": "<p>I believe those are probably generated by the default WordPress sizes - thumbnail, medium and large. (See Appearanc... | 2012/04/17 | [
"https://wordpress.stackexchange.com/questions/49332",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13723/"
] | on my theme, i found this script
```
add_image_size( 'slider', 464, 249, true );
add_image_size( 'fmenu', 306, 280, true );
add_image_size( 'teamthumb', 138, 207, true );
add_image_size( 'imlink', 286, 140, true );
add_image_size( 'albmlink', 274, 274, true );
add_image_size( 'fppost', 90, 90, true );
add_image_size(... | I believe those are probably generated by the default WordPress sizes - thumbnail, medium and large. (See Appearance > Media for where those sizes are set).
If you want to eliminate the extra image sizes the simplest way might be to eliminate some of your theme's custom image sizes and use the defaults instead. OR, y... |
49,339 | <p>I get this error due to one of the plugins which I rely on. </p>
<p>Notice: wp_enqueue_style was called incorrectly. Scripts and styles
should not be registered or enqueued until the wp_enqueue_scripts,
admin_enqueue_scripts, or init hooks. </p>
<p>What does this error mean and how do you fix it?
Mind due that t... | [
{
"answer_id": 49344,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 4,
"selected": true,
"text": "<p>The problem is that the <a href=\"http://codex.wordpress.org/Function_Reference/wp_enqueue_style\"><code>wp_... | 2012/04/17 | [
"https://wordpress.stackexchange.com/questions/49339",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14967/"
] | I get this error due to one of the plugins which I rely on.
Notice: wp\_enqueue\_style was called incorrectly. Scripts and styles
should not be registered or enqueued until the wp\_enqueue\_scripts,
admin\_enqueue\_scripts, or init hooks.
What does this error mean and how do you fix it?
Mind due that this is not a... | The problem is that the [`wp_enqueue_style()`](http://codex.wordpress.org/Function_Reference/wp_enqueue_style) call is inside of the `category_collapse()` member function of the `CategoryCollapse()` class, and the `CategoryCollapse()` class is being instantiated by a callback hooked into the `plugins_loaded` action hoo... |
49,346 | <p>I have a custom post type where I have a taxonomy <code>cities</code> and a term <code>berlin</code>. Archive can be seen at <code>example.com/cities/berlin</code> and it's rendered normally from the <code>archive.php</code> template.</p>
<p>Now, I want to order them according to a custom field, <code>start_date</c... | [
{
"answer_id": 49351,
"author": "mrwweb",
"author_id": 9844,
"author_profile": "https://wordpress.stackexchange.com/users/9844",
"pm_score": 3,
"selected": true,
"text": "<p>You can't concatenate an array onto query_string like that. See <a href=\"http://digwp.com/2011/05/loops/#query-po... | 2012/04/17 | [
"https://wordpress.stackexchange.com/questions/49346",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8698/"
] | I have a custom post type where I have a taxonomy `cities` and a term `berlin`. Archive can be seen at `example.com/cities/berlin` and it's rendered normally from the `archive.php` template.
Now, I want to order them according to a custom field, `start_date` in this case, but still keep the original query around. So t... | You can't concatenate an array onto query\_string like that. See [Digging Into WordPress's post about looping](http://digwp.com/2011/05/loops/#query-posts) for the right format. Alternately, you can use `array_merge()` like on the [query\_posts Codex page](http://codex.wordpress.org/Function_Reference/query_posts#Prese... |
49,354 | <p>On the posts that we label "sticky" the word "featured" appears. How can I change that to "new"?</p>
<p>David</p>
| [
{
"answer_id": 49381,
"author": "Travis Pflanz",
"author_id": 14558,
"author_profile": "https://wordpress.stackexchange.com/users/14558",
"pm_score": 0,
"selected": false,
"text": "<p>Wherever you want \"new\" to be displayed, enter:</p>\n\n<pre><code><?php if ( is_sticky ) { \n ec... | 2012/04/17 | [
"https://wordpress.stackexchange.com/questions/49354",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15303/"
] | On the posts that we label "sticky" the word "featured" appears. How can I change that to "new"?
David | This looks like a theme issue.
And, if you are using TwentyEleven, the "Featured" word is printed in the file **/wp-content/themes/twentyeleven/content.php**
At the very beginning you'll see
```
<h3 class="entry-format"><?php _e( 'Featured', 'twentyeleven' ); ?></h3>
```
change it for what you need |
49,379 | <p>I have created a custom post type and registered it using this code</p>
<pre><code>$labels = array(
'name' => __( 'Portfolio' ),
'singular_name' => __( 'Portfolio' )
);
$args = array(
'labels' => $labels,
'public' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,... | [
{
"answer_id": 49397,
"author": "soju",
"author_id": 3646,
"author_profile": "https://wordpress.stackexchange.com/users/3646",
"pm_score": 1,
"selected": false,
"text": "<p>Add a <code>s</code> to <code>show_in_nav_menu</code> : <code>show_in_nav_menus</code></p>\n"
},
{
"answer_... | 2012/04/18 | [
"https://wordpress.stackexchange.com/questions/49379",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14445/"
] | I have created a custom post type and registered it using this code
```
$labels = array(
'name' => __( 'Portfolio' ),
'singular_name' => __( 'Portfolio' )
);
$args = array(
'labels' => $labels,
'public' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'show_ui' => true,
'query_... | Add a `s` to `show_in_nav_menu` : `show_in_nav_menus` |
49,393 | <p>I've been looking for the answer to this everywhere but with no success and that's why I'm asking here.</p>
<p>I don't even know if the question is the right one.</p>
<p>In any case, I'll try to explain.</p>
<p>I have a WordPress page with variables in the URL, like this: <a href="http://planeta-beisbol.com/tal-d... | [
{
"answer_id": 49394,
"author": "Alex Thomas",
"author_id": 6243,
"author_profile": "https://wordpress.stackexchange.com/users/6243",
"pm_score": -1,
"selected": false,
"text": "<p>You can do you're own custom permalink structures, have you looked here - <a href=\"http://codex.wordpress.... | 2012/04/18 | [
"https://wordpress.stackexchange.com/questions/49393",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15315/"
] | I've been looking for the answer to this everywhere but with no success and that's why I'm asking here.
I don't even know if the question is the right one.
In any case, I'll try to explain.
I have a WordPress page with variables in the URL, like this: <http://planeta-beisbol.com/tal-dia-como-hoy/?dia=18&mes=04>
The... | The following two functions should point you in the right direction:
```
function wpse49393_query_vars($query_vars)
{
$query_vars[] = 'myvar';
return $query_vars;
}
add_filter('query_vars', 'wpse49393_query_vars');
function wpse49393_rewrite_rules_array($rewrite_rules)
{
$rewrite_rules['path/to/page/([^/]... |
49,414 | <p>In the admin bar an admin can create a new post by using the add new drop down. In there I want to change the label <code>Post</code> to something else.</p>
<p>How can I do this? I just need the code to make the change in the admin bar as I have the code already to change the Post label everywhere else in the admin... | [
{
"answer_id": 49415,
"author": "Scott",
"author_id": 4610,
"author_profile": "https://wordpress.stackexchange.com/users/4610",
"pm_score": 3,
"selected": true,
"text": "<p>Found my answer including my full solution:</p>\n\n<pre><code><?php\n/*\nPlugin Name: Rename Posts to News\nDesc... | 2012/04/18 | [
"https://wordpress.stackexchange.com/questions/49414",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4610/"
] | In the admin bar an admin can create a new post by using the add new drop down. In there I want to change the label `Post` to something else.
How can I do this? I just need the code to make the change in the admin bar as I have the code already to change the Post label everywhere else in the admin section.
Bonus poin... | Found my answer including my full solution:
```
<?php
/*
Plugin Name: Rename Posts to News
Description: Rename built in posts to be called News
Version: 1.0
Author: Scott Cariss @ Philosophy Design
Author URI: http://www.philosophydesign.com
*/
// Not a WordPress context? Stop.
! defined( 'ABSPATH' ) and exit;
add_a... |
49,418 | <p>I would like to change the text in the wp media uploader.
I managed to find the function at the <a href="http://adambrown.info/p/wp_hooks/hook/post-html-upload-ui?version=3.3&file=wp-admin/includes/media.php" rel="nofollow">media.php</a> and i tried to using the filter to change the text like this:</p>
<pre><c... | [
{
"answer_id": 49419,
"author": "Hiranthi",
"author_id": 7067,
"author_profile": "https://wordpress.stackexchange.com/users/7067",
"pm_score": 2,
"selected": false,
"text": "<p>The 'post-html-upload-ui' is an action, not a filter. So it should be: add_action instead of add_filter.</p>\n"... | 2012/04/18 | [
"https://wordpress.stackexchange.com/questions/49418",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14728/"
] | I would like to change the text in the wp media uploader.
I managed to find the function at the [media.php](http://adambrown.info/p/wp_hooks/hook/post-html-upload-ui?version=3.3&file=wp-admin/includes/media.php) and i tried to using the filter to change the text like this:
```
function uploader_text() {
remove_action... | This worked for me:
```
function uploader_text() {
?>
<p class="upload-html-bypass hide-if-no-js">
<?php _e('mytext here'); ?>
</p>
<?php
}
remove_action('post-html-upload-ui', 'media_upload_html_bypass');
add_action('post-html-upload-ui', 'uploader_text');
```
You tried to do "remove\_action" after the... |
49,425 | <p>im kind of a wordpress noob so please excuse my inexperience. </p>
<p>so long story short, ive been tasked with creating a WP theme (kinda simple) but, one of the areas, around footer area, has a few things they want, like a 2ndary menu/ bread crumbs etc...maybe even custom html box etc that i can do other things w... | [
{
"answer_id": 49427,
"author": "Johannes Pille",
"author_id": 9745,
"author_profile": "https://wordpress.stackexchange.com/users/9745",
"pm_score": 2,
"selected": false,
"text": "<p>Menus:</p>\n\n<ul>\n<li><a href=\"http://codex.wordpress.org/Function_Reference/wp_nav_menu\" rel=\"nofol... | 2012/04/18 | [
"https://wordpress.stackexchange.com/questions/49425",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12944/"
] | im kind of a wordpress noob so please excuse my inexperience.
so long story short, ive been tasked with creating a WP theme (kinda simple) but, one of the areas, around footer area, has a few things they want, like a 2ndary menu/ bread crumbs etc...maybe even custom html box etc that i can do other things with later ... | You can add additional widgetized sidebars to your theme by adding to your theme's functions.php.
If you have not already added widget support in the theme, include:
```
if (function_exists('register_sidebar'))
```
Then add:
```
// Footer Widgets
register_sidebar(array(
'id' => 'footerwidgets',
'name' => 'Foot... |
49,449 | <p>I use Markdown in my posts, and the plugin I use for that purpose requires the Visual editor be disabled.</p>
<p>The HTML editor is pretty much just a text box. To make writing easier, I would like to enable some custom keyboard shortcuts that allow me to format text in markdown when a key combination is pressed (l... | [
{
"answer_id": 49469,
"author": "Lee",
"author_id": 15184,
"author_profile": "https://wordpress.stackexchange.com/users/15184",
"pm_score": -1,
"selected": false,
"text": "<p>I'm not sure how to get ctrl + b and other button combinations to work but here is a list of the shortcuts for th... | 2012/04/18 | [
"https://wordpress.stackexchange.com/questions/49449",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10691/"
] | I use Markdown in my posts, and the plugin I use for that purpose requires the Visual editor be disabled.
The HTML editor is pretty much just a text box. To make writing easier, I would like to enable some custom keyboard shortcuts that allow me to format text in markdown when a key combination is pressed (like `Ctrl`... | The toolbar / editor used on Stack Exchange websites (and in my plug-in [WP-MarkDown](http://wordpress.org/extend/plugins/wp-markdown/)) is [PageDown](http://code.google.com/p/pagedown/).
This comes with three JavaScript files:
* One that handles MarkDown to HTML conversion
* One that handles sanitization
* One that ... |
49,451 | <p>I wonder, is there a way to change the locale at runtime using WordPress ?</p>
<p>What I mean, is, I have create a custom URL in order to create an XML file with data for integration with another web application. The URL has also a language portion. Lets say this is my URL</p>
<p><a href="http://example.com/custom... | [
{
"answer_id": 49455,
"author": "onetrickpony",
"author_id": 1986,
"author_profile": "https://wordpress.stackexchange.com/users/1986",
"pm_score": 2,
"selected": false,
"text": "<p>I don't know if it's possible to do this within a plugin, because of the constants WP requires defined befo... | 2012/04/18 | [
"https://wordpress.stackexchange.com/questions/49451",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7850/"
] | I wonder, is there a way to change the locale at runtime using WordPress ?
What I mean, is, I have create a custom URL in order to create an XML file with data for integration with another web application. The URL has also a language portion. Lets say this is my URL
<http://example.com/custom/url/en>
where last port... | I'm trying to do a similiar thing, and the experts on the wp-hackers mailing list (Otto, Nacin) told me this:
>
> Don't try to change WPLANG, you can't change a define'd constant.
> Instead, change the global $locale, or put a filter on 'locale'.
>
>
>
So the best solution is to apply a filter on the 'locale' gl... |
49,452 | <p>I'm thinking about creating single page portfolio theme, but I'm a little confused on how this would be done based on the different sections on the single page.</p>
<p>I'll explain what I would like to do and hopefully someone can help me figure this out. I'm just looking for guidance on what I should do to handle ... | [
{
"answer_id": 49455,
"author": "onetrickpony",
"author_id": 1986,
"author_profile": "https://wordpress.stackexchange.com/users/1986",
"pm_score": 2,
"selected": false,
"text": "<p>I don't know if it's possible to do this within a plugin, because of the constants WP requires defined befo... | 2012/04/18 | [
"https://wordpress.stackexchange.com/questions/49452",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15330/"
] | I'm thinking about creating single page portfolio theme, but I'm a little confused on how this would be done based on the different sections on the single page.
I'll explain what I would like to do and hopefully someone can help me figure this out. I'm just looking for guidance on what I should do to handle the differ... | I'm trying to do a similiar thing, and the experts on the wp-hackers mailing list (Otto, Nacin) told me this:
>
> Don't try to change WPLANG, you can't change a define'd constant.
> Instead, change the global $locale, or put a filter on 'locale'.
>
>
>
So the best solution is to apply a filter on the 'locale' gl... |
49,453 | <p>I'm currently working on the admin page of my custom post type, and I got stuck on deciding whether to add a nonce field again for the second metabox or not. I'm very new to custom post types, and searching online about this doesn't really yield that many results.</p>
<p>Any thoughts? Thanks.</p>
| [
{
"answer_id": 49459,
"author": "Tribalpixel",
"author_id": 11987,
"author_profile": "https://wordpress.stackexchange.com/users/11987",
"pm_score": 0,
"selected": false,
"text": "<p>The nonce field is used to validate that the contents of the form came from the location on the current si... | 2012/04/18 | [
"https://wordpress.stackexchange.com/questions/49453",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14804/"
] | I'm currently working on the admin page of my custom post type, and I got stuck on deciding whether to add a nonce field again for the second metabox or not. I'm very new to custom post types, and searching online about this doesn't really yield that many results.
Any thoughts? Thanks. | I would recommend so.
You do (and should) have your own nonce with which to check the origin of the data and the intent of the user. If you have just one nonce for a metabox - then you run into problems if that metabox is removed (not the same as hidden). If removed the second metabox will (or at least should) never ... |
49,474 | <p>I'm having to design an e-commerce site where users should be able to create a product from front-end.</p>
<p>In WordPress, the product will simply be a post with custom fields like Price, Condition,.......</p>
<p>Also, from front-end, the user should be able to upload pictures.</p>
<p>I just need some advice fro... | [
{
"answer_id": 49478,
"author": "mrwweb",
"author_id": 9844,
"author_profile": "https://wordpress.stackexchange.com/users/9844",
"pm_score": 2,
"selected": false,
"text": "<p>Gravity Forms (premium plugin) allows for easy creation of front-end forms, supports custom fields, and other var... | 2012/04/18 | [
"https://wordpress.stackexchange.com/questions/49474",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12000/"
] | I'm having to design an e-commerce site where users should be able to create a product from front-end.
In WordPress, the product will simply be a post with custom fields like Price, Condition,.......
Also, from front-end, the user should be able to upload pictures.
I just need some advice from you guys. What would b... | I like mrwweb's suggestion, but if you are trying to do it yourself / for free, you will have to do a few things:
1) Make a new template PHP file with the forms you will need to create a new product, create a new page and assign it the template you created
2) Create your custom post type or decide to use post meta in... |
49,492 | <p>For the purpose of good HTML structure, accessibility and SEO I'd like to change the site's title and description from H1 and H2 to P when appearing on any page other than the homepage. A conditional statement logic would be something like; when not homepage change site title and description to Site Title and Descri... | [
{
"answer_id": 49494,
"author": "Stephen Harris",
"author_id": 9364,
"author_profile": "https://wordpress.stackexchange.com/users/9364",
"pm_score": 2,
"selected": false,
"text": "<p>There are two conditionals, depending on your setup:</p>\n\n<ul>\n<li><a href=\"http://codex.wordpress.or... | 2012/04/18 | [
"https://wordpress.stackexchange.com/questions/49492",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5605/"
] | For the purpose of good HTML structure, accessibility and SEO I'd like to change the site's title and description from H1 and H2 to P when appearing on any page other than the homepage. A conditional statement logic would be something like; when not homepage change site title and description to Site Title and Descripti... | ```
<?php if (is_home() || is_front_page()) { $header_tag = 'h1'; }
else { $header_tag = 'h2'; } ?>
<<?php echo $header_tag;?>><?php the_title();?></<?php echo $header_tag; ?>>
```
Expanding on what Stephen Harris said, here is a useable example. Lots of different ways to use same code function. |
49,514 | <p>I have this function below that is called with the <code>admin_init</code> Action </p>
<pre><code>function my_flush_rewrites() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
</code></pre>
<p>Like this </p>
<pre><code>add_action('admin_init', 'my_flush_rewrites');
</code></pre>
<p>I am curious,... | [
{
"answer_id": 49515,
"author": "mrwweb",
"author_id": 9844,
"author_profile": "https://wordpress.stackexchange.com/users/9844",
"pm_score": 4,
"selected": true,
"text": "<p><a href=\"http://codex.wordpress.org/Plugin_API/Action_Reference/admin_init\" rel=\"noreferrer\">From the Codex</a... | 2012/04/19 | [
"https://wordpress.stackexchange.com/questions/49514",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8668/"
] | I have this function below that is called with the `admin_init` Action
```
function my_flush_rewrites() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
```
Like this
```
add_action('admin_init', 'my_flush_rewrites');
```
I am curious, when is this called? Is this called on every page load? Hopefully... | [From the Codex](http://codex.wordpress.org/Plugin_API/Action_Reference/admin_init):
>
> admin\_init is triggered before any other hook when a user access the
> admin area. This hook doesn't provide any parameters, so it can only
> be used to callback a specified function.
>
>
>
So yes, it's run on every *admin... |
49,549 | <p>I found the following codes to get post details.
However, it is not possible to <strong>get the posts by content</strong>.
Does any one has any ideas?</p>
<p><strong>get_posts()</strong></p>
<pre><code>//// get post ////
$args = array(
'numberposts' => -1, // number of posts to display; display all: -1.... | [
{
"answer_id": 49550,
"author": "mor7ifer",
"author_id": 11740,
"author_profile": "https://wordpress.stackexchange.com/users/11740",
"pm_score": 1,
"selected": false,
"text": "<p>I can't think of an elegant way off the top of my head, I'm not sure if it's even possible using core functio... | 2012/04/19 | [
"https://wordpress.stackexchange.com/questions/49549",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15356/"
] | I found the following codes to get post details.
However, it is not possible to **get the posts by content**.
Does any one has any ideas?
**get\_posts()**
```
//// get post ////
$args = array(
'numberposts' => -1, // number of posts to display; display all: -1.
'offset' => 0,
// 'category' ... | You have to extend the db query to search in the `post_content` column. There is a filter: `'posts_where'` you can use.
I would write a simple wrapper for `get_posts()` to extends its arguments an run the filter once. Example:
```
class T5_Posts_By_Content
{
protected static $content = '';
protected static ... |
49,568 | <p>when using wp_editor, I paste my text in the visual editor. If I switch to HTML editor, all of my tags are there. So far, no problem. When I update the thing, all of my tags appear in my visual editor and in HTML, they become something like :</p>
<pre><code>&lt;p&gt;&lt;strong&gt;
</code></pre>
<p>... | [
{
"answer_id": 49572,
"author": "Dave Romsey",
"author_id": 2807,
"author_profile": "https://wordpress.stackexchange.com/users/2807",
"pm_score": 1,
"selected": false,
"text": "<p>Try changing</p>\n\n<p><code><?php wp_editor($metabox->get_the_value(), $metabox->get_the_name(), $... | 2012/04/19 | [
"https://wordpress.stackexchange.com/questions/49568",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15012/"
] | when using wp\_editor, I paste my text in the visual editor. If I switch to HTML editor, all of my tags are there. So far, no problem. When I update the thing, all of my tags appear in my visual editor and in HTML, they become something like :
```
<p><strong>
```
If I update again, the tags appear on my ... | I ran into the same issue when making use of the new wp\_editor function on an alchemy powered metabox. I did some searching and turned up a solution that makes use of "html\_entity\_decode". Take a look at the reference here: <https://gist.github.com/1838037> |
49,583 | <p>I am trying to make a post which will contain several custom fileds. the custom fields should show within jqery tabs. I have already made it in here: <a href="http://algodonesdentistreview.com/ahmad/dentists/a-test-dentist-post" rel="nofollow">http://algodonesdentistreview.com/ahmad/dentists/a-test-dentist-post</a> ... | [
{
"answer_id": 49582,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 4,
"selected": false,
"text": "<p>The details of custom post types aren't stored anywhere, they're loaded at runtime with each request via <a href=\"... | 2012/04/19 | [
"https://wordpress.stackexchange.com/questions/49583",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5776/"
] | I am trying to make a post which will contain several custom fileds. the custom fields should show within jqery tabs. I have already made it in here: <http://algodonesdentistreview.com/ahmad/dentists/a-test-dentist-post> but the problem is, the tabs aren't dynamic, that is, if I'm adding a field from dashboard, it won'... | The details of custom post types aren't stored anywhere, they're loaded at runtime with each request via [`register_post_type`](http://codex.wordpress.org/Function_Reference/register_post_type) calls. |
49,585 | <p>I've mimicked <a href="https://wordpress.stackexchange.com/users/2232/otto">Otto's</a> setup here: <a href="http://ottopress.com/2011/creating-a-wordpress-site-using-svn/" rel="nofollow noreferrer">http://ottopress.com/2011/creating-a-wordpress-site-using-svn/</a> and my brief example is below.</p>
<p>That tutorial... | [
{
"answer_id": 52971,
"author": "sam",
"author_id": 9384,
"author_profile": "https://wordpress.stackexchange.com/users/9384",
"pm_score": 1,
"selected": false,
"text": "<p>Not sure if this is exactly relevant, but <a href=\"http://codex.wordpress.org/Before_You_Create_A_Network#WordPress... | 2012/04/19 | [
"https://wordpress.stackexchange.com/questions/49585",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3293/"
] | I've mimicked [Otto's](https://wordpress.stackexchange.com/users/2232/otto) setup here: <http://ottopress.com/2011/creating-a-wordpress-site-using-svn/> and my brief example is below.
That tutorial is specific to a single site install, and specifies a single domain. **How can I customize the `htaccess` below to be sui... | For now, this is unsolvable according to Mark Jaquith, [as noted here](https://github.com/markjaquith/WordPress-Skeleton).
>
> **Q**: Does this support WordPress in multisite mode?
>
>
> **A**: No. Not until
> WordPress supports WordPress-in-a-subdirectory installation for
> multisite. If you're a WordPress hacker ... |
49,598 | <p>Is there a built in wordpress function that let's me look up the
"parent" field of the <code>wp_term_taxonomy</code> table if I pass the <code>TT_ID</code> to
it?</p>
<p>Something like</p>
<pre><code>get_value ( $wp_table_name, $id_fieldname, $id_value,
$the_field_info_to_retrieve )
</code></pre>
<p>Example</p>
... | [
{
"answer_id": 49609,
"author": "jerclarke",
"author_id": 175,
"author_profile": "https://wordpress.stackexchange.com/users/175",
"pm_score": 1,
"selected": false,
"text": "<p>My experience with this was that it is an issue area of the taxonomy system in core. In several cases the core c... | 2012/04/19 | [
"https://wordpress.stackexchange.com/questions/49598",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14967/"
] | Is there a built in wordpress function that let's me look up the
"parent" field of the `wp_term_taxonomy` table if I pass the `TT_ID` to
it?
Something like
```
get_value ( $wp_table_name, $id_fieldname, $id_value,
$the_field_info_to_retrieve )
```
Example
```
get_value ( "wp_term_taxonomy", "term_taxonomy_id", "pa... | My experience with this was that it is an issue area of the taxonomy system in core. In several cases the core code does fetch info based on a tt\_id or an array of them, but in each of these cases it is painfully done with a custom SQL query inside that particular function rather than an API function.
To solve my ow... |
49,608 | <p>I'm creating a plugin with an admin page that needs to:</p>
<ul>
<li>stream a file for download (set content-type & other headers)</li>
<li>display HTML without the admin menu etc</li>
</ul>
<p>In both of these cases the 'pages' <strong>must</strong> be accessible only to logged in administrators. So far I've ... | [
{
"answer_id": 52877,
"author": "Michael Ecklund",
"author_id": 9579,
"author_profile": "https://wordpress.stackexchange.com/users/9579",
"pm_score": -1,
"selected": false,
"text": "<p>Take a look at the WordPress HTTP API.\n<a href=\"http://core.trac.wordpress.org/browser/tags/3.3.2/wp-... | 2012/04/19 | [
"https://wordpress.stackexchange.com/questions/49608",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15372/"
] | I'm creating a plugin with an admin page that needs to:
* stream a file for download (set content-type & other headers)
* display HTML without the admin menu etc
In both of these cases the 'pages' **must** be accessible only to logged in administrators. So far I've found one way to accomplish both of these, by includ... | I've done this two ways:
1) - a csv export function - detect that special content type handling is required BEFORE wp outputs anything.
```
add_action ('plugins_loaded', 'amr_meta_handle_csv');
function amr_meta_handle_csv ($csv, $suffix='csv') {
// chcek if there is a csv request on this page BEFORE we do... |
49,641 | <p>I'm using the plugin custom post type ui to create a post type says movie. Everything is ok. I create a movie and its viewable at </p>
<pre><code>http://localhost/wordpress/movies/test/
</code></pre>
<p>however, when i go on</p>
<p><a href="http://localhost/wordpress/movies/" rel="nofollow">http://localhost/wordp... | [
{
"answer_id": 49659,
"author": "Jay",
"author_id": 9092,
"author_profile": "https://wordpress.stackexchange.com/users/9092",
"pm_score": 0,
"selected": false,
"text": "<p>Go to the admin panel and under settings tab go to the permalinks tab and once you are in the permalinks page save c... | 2012/04/20 | [
"https://wordpress.stackexchange.com/questions/49641",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12000/"
] | I'm using the plugin custom post type ui to create a post type says movie. Everything is ok. I create a movie and its viewable at
```
http://localhost/wordpress/movies/test/
```
however, when i go on
<http://localhost/wordpress/movies/>
I was expecting to see test as a movie in all the list of movies but nothing ... | Simply add `has_archive` => 'movies' to the arguments array you pass to `register_post_type` and you should be fine, since by default it is set to false. |
49,643 | <p>I want to hide/remove the Personal Options in the <strong>Your Profile</strong> (<code>wp-admin/profile.php</code>) admin page.</p>
<p>I am aware that solutions for this exist, but I they use jQuery to do hide this section. This works, but when a user has JavaScript disabled in their browser, it will show up again.... | [
{
"answer_id": 49683,
"author": "Community",
"author_id": -1,
"author_profile": "https://wordpress.stackexchange.com/users/-1",
"pm_score": 6,
"selected": true,
"text": "<p>This should do the trick</p>\n\n<pre><code>// removes the `profile.php` admin color scheme options\nremove_action( ... | 2012/04/20 | [
"https://wordpress.stackexchange.com/questions/49643",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14728/"
] | I want to hide/remove the Personal Options in the **Your Profile** (`wp-admin/profile.php`) admin page.
I am aware that solutions for this exist, but I they use jQuery to do hide this section. This works, but when a user has JavaScript disabled in their browser, it will show up again. Therefore it is not a proper way ... | This should do the trick
```
// removes the `profile.php` admin color scheme options
remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
if ( ! function_exists( 'cor_remove_personal_options' ) ) {
/**
* Removes the leftover 'Visual Editor', 'Keyboard Shortcuts' and 'Toolbar' options.
*/... |
49,655 | <p>I'm generating an XML file using PHP for a website where they review tech products. In the XML file, I have to display the rating of products. For rating purposes, I'm using GD Star Rating plugin.</p>
<p>I've been experimenting with wpdb class to fetch the rating of each product. However I've not had any luck so fa... | [
{
"answer_id": 49657,
"author": "developdaly",
"author_id": 3293,
"author_profile": "https://wordpress.stackexchange.com/users/3293",
"pm_score": 0,
"selected": false,
"text": "<p>Oh, you'll kick yourself for this one.</p>\n\n<p>You have:</p>\n\n<p><code>$wpbd->prepare</code></p>\n\n<... | 2012/04/20 | [
"https://wordpress.stackexchange.com/questions/49655",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14974/"
] | I'm generating an XML file using PHP for a website where they review tech products. In the XML file, I have to display the rating of products. For rating purposes, I'm using GD Star Rating plugin.
I've been experimenting with wpdb class to fetch the rating of each product. However I've not had any luck so far. I'm usi... | You need to add the global $wpdb reference and also add the second parameter required for prepare():
```
global $wpdb;
$post_id = $post->ID;
$reviewScore = $wpdb->query(
$wpdb->prepare(
"SELECT review FROM {$wpdb->prefix}gdsr_data_article WHERE post_id = %d",
$post_id
)
);
``` |
49,665 | <p>guys what I'm trying to do is run a series of if checks in the code before executing a series of functions and custom code. One of these if checks will check to see if a post already exists and if so it will then check how old the post is and if the post is say over 48 hours in age it will delete that post and recre... | [
{
"answer_id": 49668,
"author": "Julien Le Thuaut",
"author_id": 15387,
"author_profile": "https://wordpress.stackexchange.com/users/15387",
"pm_score": 0,
"selected": false,
"text": "<p>I'm not sure of what you're trying to do but why don't you select the post_date in your request direc... | 2012/04/20 | [
"https://wordpress.stackexchange.com/questions/49665",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/176798/"
] | guys what I'm trying to do is run a series of if checks in the code before executing a series of functions and custom code. One of these if checks will check to see if a post already exists and if so it will then check how old the post is and if the post is say over 48 hours in age it will delete that post and recreate... | You can use [`wp_delete_post()`](http://codex.wordpress.org/Function_Reference/wp_delete_post) and [`get_the_date()`](http://codex.wordpress.org/Function_Reference/get_the_date).
```
global $wpdb;
if ( !is_user_logged_in())
echo 'You must be logged in.';
// check if title $my_post_name already exists in wpdb
else... |
49,666 | <p>How to display child page from specific parent page in homepage ?</p>
<p>This is my page structure</p>
<pre><code>Home
About Us
Hotel Category
Hotel A
Room 1
Room 2
Hotel B
Room 1
Room 2
Hotel C
Room 1
Room 2
Contact Us
</code></pre>
<p>And i try to achieve this at homepage(parent pa... | [
{
"answer_id": 49783,
"author": "Fazle Elahee",
"author_id": 15231,
"author_profile": "https://wordpress.stackexchange.com/users/15231",
"pm_score": 0,
"selected": false,
"text": "<p>Below code (Template for show child pages with title and excerpt) might useful to you. if you are using w... | 2012/04/20 | [
"https://wordpress.stackexchange.com/questions/49666",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8911/"
] | How to display child page from specific parent page in homepage ?
This is my page structure
```
Home
About Us
Hotel Category
Hotel A
Room 1
Room 2
Hotel B
Room 1
Room 2
Hotel C
Room 1
Room 2
Contact Us
```
And i try to achieve this at homepage(parent page is Hotel Category : id=8)
```... | This should do it.
```
<?php
$pages = get_pages('child_of=199');
foreach($pages as $child) {
?>
<h3><?php echo get_the_title($child->ID); ?></h3>
<?php
// This next line gets the full page of content
// echo get_post_field('post_content', $child->ID);
// This next line will cut the content off at 450 let... |
49,675 | <p>Here is what I have </p>
<p>I am not having any lucking finding how to simply include a file in the content editor using a shortcode.</p>
<p>For Example if I wanted to include form.php inside my Contact Page how would I make this happen using a shortcode?</p>
<p>Below is was attempting to work with to no avail.</... | [
{
"answer_id": 49715,
"author": "Eric Allen",
"author_id": 5831,
"author_profile": "https://wordpress.stackexchange.com/users/5831",
"pm_score": 3,
"selected": true,
"text": "<p>I modified some code from an old blog post to do this, and allow for query-strings to be attached to the file ... | 2012/04/20 | [
"https://wordpress.stackexchange.com/questions/49675",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15395/"
] | Here is what I have
I am not having any lucking finding how to simply include a file in the content editor using a shortcode.
For Example if I wanted to include form.php inside my Contact Page how would I make this happen using a shortcode?
Below is was attempting to work with to no avail.
Any help would be apprec... | I modified some code from an old blog post to do this, and allow for query-strings to be attached to the file as well.
Original credit goes to [amberpanther.com](http://www.amberpanther.com/knowledge-base/using-the-wordpress-shortcode-api-to-include-an-external-file-in-the-post-content/), and it turns out they made a ... |
49,679 | <p>I just exported a largish WP blog from MediaTemple to PHPFog.</p>
<p>I used the standard WordPress export and import plugins.</p>
<p>For some unknown reason all of my media assets have been duplicated. I now have twice as many images per post.</p>
<p>If an original file was called "Lot-44-Warrens.jpg" it now has ... | [
{
"answer_id": 49987,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 3,
"selected": false,
"text": "<p>Use a run-once script to clean it up. Just an outline, no code:</p>\n\n<ol>\n<li>Get all posts. See <a href=\"http://c... | 2012/04/20 | [
"https://wordpress.stackexchange.com/questions/49679",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1341/"
] | I just exported a largish WP blog from MediaTemple to PHPFog.
I used the standard WordPress export and import plugins.
For some unknown reason all of my media assets have been duplicated. I now have twice as many images per post.
If an original file was called "Lot-44-Warrens.jpg" it now has a duplicate called "Lot-... | combining the two answer on this page, I found this worked.
```
$args = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => -1
));
$loop = new WP_Query($args);
while($loop->have_posts()) {
the_post();
$args2 = array(
'order' => 'ASC',
'post_type' => 'attachment',
'post_parent' => $post... |
49,687 | <p>I'd like somer code that I can place in my <code>functions.php</code> file that will only modify the specified custom post type. </p>
<p>I have already tried several plugins, but all of them have more features than I need. It's overkill to mess with things I don't want them to mess with. </p>
<p>Ideally, the code... | [
{
"answer_id": 56066,
"author": "Foxinni",
"author_id": 17011,
"author_profile": "https://wordpress.stackexchange.com/users/17011",
"pm_score": 1,
"selected": false,
"text": "<p>Well there is two ways of doing it in that i can think of...</p>\n\n<p>The simplest seems to be the wp_cron co... | 2012/04/20 | [
"https://wordpress.stackexchange.com/questions/49687",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3603/"
] | I'd like somer code that I can place in my `functions.php` file that will only modify the specified custom post type.
I have already tried several plugins, but all of them have more features than I need. It's overkill to mess with things I don't want them to mess with.
Ideally, the code will:
* Set up a daily cron... | ```
add_action( 'wp', 'delete_expired_coupons_daily' );
function delete_expired_coupons_daily() {
if ( ! wp_next_scheduled( 'delete_expired_coupons' ) ) {
wp_schedule_event( time(), 'daily', 'delete_expired_coupons');
}
}
add_action( 'delete_expired_coupons', 'delete_expired_coupons_callback' );
function delete_ex... |
49,711 | <p>I've never actually written a Wordpress plugin before, so this is my first crack at it.</p>
<p>Basically, the plugin is for multi-author blogs where post authors must submit their post for review. The Editor/Administrator must come in and approve and publish/schedule the post. All of this is good, and built into Wor... | [
{
"answer_id": 49713,
"author": "Eric Allen",
"author_id": 5831,
"author_profile": "https://wordpress.stackexchange.com/users/5831",
"pm_score": 2,
"selected": false,
"text": "<p>You could check the user role when loading your metabox.</p>\n\n<pre><code>//get user\n$user_id = get_current... | 2012/04/20 | [
"https://wordpress.stackexchange.com/questions/49711",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14558/"
] | I've never actually written a Wordpress plugin before, so this is my first crack at it.
Basically, the plugin is for multi-author blogs where post authors must submit their post for review. The Editor/Administrator must come in and approve and publish/schedule the post. All of this is good, and built into Wordpress.
... | Thanks to ericissocial for sending me in the right direction.
I decided to go with:
```
if(current_user_can( 'edit_others_posts' )) {
//add meta box
}
```
This way any custom user role with `edit_others_posts` can use the function. |
49,717 | <p>I have everything ready for publishing a new version of my plugin but one last issue stands...</p>
<p>The old version had no naming convention for its key option names.</p>
<p>The options grew and I renamed all of them, using prefixes for the sake of good coding practice and my own sanity.</p>
<p>I thought of put... | [
{
"answer_id": 49736,
"author": "mor7ifer",
"author_id": 11740,
"author_profile": "https://wordpress.stackexchange.com/users/11740",
"pm_score": 3,
"selected": true,
"text": "<p>You should store a version number for your plugin in the database (if you don't already, add this pronto), usi... | 2012/04/20 | [
"https://wordpress.stackexchange.com/questions/49717",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12615/"
] | I have everything ready for publishing a new version of my plugin but one last issue stands...
The old version had no naming convention for its key option names.
The options grew and I renamed all of them, using prefixes for the sake of good coding practice and my own sanity.
I thought of putting a warning in the De... | You should store a version number for your plugin in the database (if you don't already, add this pronto), using that you can do this (note that this is pseudocode):
```
if( $db_version < {your desired version} ) {
// previous updates and such
$db_version = $new_version; //put that in the database
}
if( $db_ve... |
49,753 | <p>I've been reading about Custom Post Types, Custom Taxonomy and Category but I'm still getting some confusion. I want to build somewhat like an ecommerce site just to understand it better.</p>
<p>Say I've a problem like this</p>
<pre><code>Products
--Computer
--Operating System
--Linux... | [
{
"answer_id": 49754,
"author": "Johannes Pille",
"author_id": 9745,
"author_profile": "https://wordpress.stackexchange.com/users/9745",
"pm_score": 2,
"selected": true,
"text": "<p>I'd say your on exactly the right track.</p>\n\n<p>Since you're in the process of reading up on CPTs and s... | 2012/04/21 | [
"https://wordpress.stackexchange.com/questions/49753",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12000/"
] | I've been reading about Custom Post Types, Custom Taxonomy and Category but I'm still getting some confusion. I want to build somewhat like an ecommerce site just to understand it better.
Say I've a problem like this
```
Products
--Computer
--Operating System
--Linux
--Wi... | I'd say your on exactly the right track.
Since you're in the process of reading up on CPTs and such, I'd highly recommend giving this 4-part tutorial series a read:
[Reusable Custom Meta Boxes, wp|tuts+](http://wp.tutsplus.com/tutorials/reusable-custom-meta-boxes-part-1-intro-and-basic-fields/) |
49,772 | <p>I have a wordpress plugin that is interfering with the function of another plugin. But, I believe the interference only occurs on the admin side.</p>
<p>I've found the lines within the code that are interfering, and they appear to be loading html code on the header and footer of ALL admin pages.</p>
<p>I would li... | [
{
"answer_id": 49793,
"author": "random_user_name",
"author_id": 11704,
"author_profile": "https://wordpress.stackexchange.com/users/11704",
"pm_score": 1,
"selected": false,
"text": "<p>Using @One Trick Pony's method, this should do what you want:</p>\n\n<pre><code>global $current_scree... | 2012/04/21 | [
"https://wordpress.stackexchange.com/questions/49772",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/11602/"
] | I have a wordpress plugin that is interfering with the function of another plugin. But, I believe the interference only occurs on the admin side.
I've found the lines within the code that are interfering, and they appear to be loading html code on the header and footer of ALL admin pages.
I would like to restrict the... | Using @One Trick Pony's method, this should do what you want:
```
global $current_screen; // Makes the $current_screen object available
if ($current_screen && $current_screen->base == "edit") {
// Edit-page/post-only code here
}
```
If you want it on the add OR edit screens, then:
```
global $current_scree... |
49,773 | <p>When adding a metabox, i.e.:</p>
<pre><code>add_meta_box(
'metabox_id',
'Metabox Title',
'my_metabox_callback',
'page',
'normal',
'low',
array( 'foo' => $var1, 'bar' => $var2)
);
</code></pre>
<p>how do I add a <code>class</code> to it for css styling? I'd like to avoid having t... | [
{
"answer_id": 49780,
"author": "Dakshinamurthy Karra",
"author_id": 13215,
"author_profile": "https://wordpress.stackexchange.com/users/13215",
"pm_score": 2,
"selected": true,
"text": "<p>Just add the class to the markup you are generating in the callback.</p>\n"
},
{
"answer_i... | 2012/04/21 | [
"https://wordpress.stackexchange.com/questions/49773",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14804/"
] | When adding a metabox, i.e.:
```
add_meta_box(
'metabox_id',
'Metabox Title',
'my_metabox_callback',
'page',
'normal',
'low',
array( 'foo' => $var1, 'bar' => $var2)
);
```
how do I add a `class` to it for css styling? I'd like to avoid having to call each `id` in the style rule for meta... | Just add the class to the markup you are generating in the callback. |
49,803 | <p>I am using Wordpress 3.3.2 with the following plugin:
- <a href="http://wordpress.org/extend/plugins/advanced-access-manager/" rel="nofollow">http://wordpress.org/extend/plugins/advanced-access-manager/</a></p>
<p>The plugin works perfectly but the author said there is currently no way to achieve this from the plug... | [
{
"answer_id": 49806,
"author": "Adam",
"author_id": 13418,
"author_profile": "https://wordpress.stackexchange.com/users/13418",
"pm_score": 3,
"selected": true,
"text": "<p>You could do something like (in your functions.php file);</p>\n<pre><code>if(current_user_can('member')){ \n\nadd... | 2012/04/22 | [
"https://wordpress.stackexchange.com/questions/49803",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15412/"
] | I am using Wordpress 3.3.2 with the following plugin:
- <http://wordpress.org/extend/plugins/advanced-access-manager/>
The plugin works perfectly but the author said there is currently no way to achieve this from the plugin, So I am wondering if there is either another plugin or any code modifications I can make to ac... | You could do something like (in your functions.php file);
```
if(current_user_can('member')){
add_filter('get_sample_permalink_html', 'perm', '',4);
function perm($return, $id, $new_title, $new_slug){
$post = get_post( $id );
if( ! $post || ( $post->post_type !== 'testimonials' ) )
{
return $... |
49,810 | <p>I am currently using WP 3.3.1.</p>
<p>Basically I just want a page for users who login via wp-login.php and see the backend admin panel to be able to see a page that shows a list of files they can download. </p>
<ol>
<li>The files will either be .zip, .pdf, or .txt. </li>
<li>Would be awesome if the list of downlo... | [
{
"answer_id": 49819,
"author": "Eric Allen",
"author_id": 5831,
"author_profile": "https://wordpress.stackexchange.com/users/5831",
"pm_score": 2,
"selected": false,
"text": "<p>There will be several steps involved in this process, I'll outline a few here to get you started.</p>\n\n<p><... | 2012/04/22 | [
"https://wordpress.stackexchange.com/questions/49810",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15412/"
] | I am currently using WP 3.3.1.
Basically I just want a page for users who login via wp-login.php and see the backend admin panel to be able to see a page that shows a list of files they can download.
1. The files will either be .zip, .pdf, or .txt.
2. Would be awesome if the list of downloads had the same exact form... | There will be several steps involved in this process, I'll outline a few here to get you started.
**Step 1: Set up a Plug-in**
You can view some more info about them [here](http://codex.wordpress.org/Writing_a_Plugin). I won't go over the header information in this answer because it's pretty self-explanatory in that ... |
49,848 | <p>I am trying to write a little plugin which allows me to add a different theme to each page. well.. still trying.. ;)</p>
<p>code: <a href="http://pastebin.com/dP1GH43E" rel="nofollow">http://pastebin.com/dP1GH43E</a></p>
<p>When I put <code>return 'mytesttheme';</code> at the end it works just perfect!
when I add ... | [
{
"answer_id": 49866,
"author": "IFightCode",
"author_id": 8096,
"author_profile": "https://wordpress.stackexchange.com/users/8096",
"pm_score": 1,
"selected": false,
"text": "<p>As far I know, to use <strong>post->ID</strong> outside of loop, <strong>wp_query</strong> should be called f... | 2012/04/22 | [
"https://wordpress.stackexchange.com/questions/49848",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15436/"
] | I am trying to write a little plugin which allows me to add a different theme to each page. well.. still trying.. ;)
code: <http://pastebin.com/dP1GH43E>
When I put `return 'mytesttheme';` at the end it works just perfect!
when I add an ID (`$page_theme = get_post_meta('66', [...]`) it also works..
when I write `ech... | There are several issues with your code. Let's start at the beginning...
**Adding hooks**
**All** your hooks will be added at the backend. Even those which are outside the `if((is_admin))` branch. Add your hooks explicitly where they should work:
```
if (is_admin()){
// do this on backend (admin side)
/* load ... |
49,853 | <p>I plan to implement some specific content for specific categories only, about 15. I wonder will wordpress conditionals (15 if) slow down my website visibly? Sorry if this sounds silly.</p>
| [
{
"answer_id": 49872,
"author": "offroff",
"author_id": 13073,
"author_profile": "https://wordpress.stackexchange.com/users/13073",
"pm_score": 1,
"selected": false,
"text": "<p>The answer is no but just to put your question into perspective I tried the following code. 1.5 million ifs.</... | 2012/04/22 | [
"https://wordpress.stackexchange.com/questions/49853",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15438/"
] | I plan to implement some specific content for specific categories only, about 15. I wonder will wordpress conditionals (15 if) slow down my website visibly? Sorry if this sounds silly. | The answer is no but just to put your question into perspective I tried the following code. 1.5 million ifs.
```
$start = microtime();
$count = 0;
while(true) {
$count++;
if($count > 1500000) {
break;
}
}
$stop = microtime();
$total = $stop-$start;
print "Total time:$total";
```
0.16 seconds |
49,861 | <p>I like to use the <a href="http://nathanstaines.com/articles/starkers-html5/">Starkers Theme</a> and build child-theme.</p>
<p>So, I`d like to remove the this primary menu</p>
<p>Starkers (functions.php)</p>
<pre><code>function starkers_setup() {
// This theme uses wp_nav_menu() in one location.
register_nav_menu... | [
{
"answer_id": 49865,
"author": "IFightCode",
"author_id": 8096,
"author_profile": "https://wordpress.stackexchange.com/users/8096",
"pm_score": 2,
"selected": false,
"text": "<p>This should definitely work for you, I just checked out</p>\n\n<pre><code>add_action( 'after_setup_theme', 'r... | 2012/04/22 | [
"https://wordpress.stackexchange.com/questions/49861",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12521/"
] | I like to use the [Starkers Theme](http://nathanstaines.com/articles/starkers-html5/) and build child-theme.
So, I`d like to remove the this primary menu
Starkers (functions.php)
```
function starkers_setup() {
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => __( 'Primary Nav... | The Starkers theme setup is hooked to `after_setup_theme`, at a priority of `10`. So you basically have to wrap the unregister function inside another function (child themes functions.php file) and add it *later* than the parent themes setup function, so it gets first added by the parent and later on removed by the chi... |
49,864 | <p>I like to use a child-theme.</p>
<p>The parent functions.php</p>
<pre><code>function starkers_widgets_init() {
// Area 1, located at the top of the sidebar.
register_sidebar( array(
'name' => __( 'Primary Widget Area', 'starkers' ),
'id' => 'primary-widget-area',
'description' => __( 'The prim... | [
{
"answer_id": 49868,
"author": "IFightCode",
"author_id": 8096,
"author_profile": "https://wordpress.stackexchange.com/users/8096",
"pm_score": 3,
"selected": true,
"text": "<p>Check the code bellow, I think that should work.</p>\n\n<pre><code>add_action( 'after_setup_theme', 'remove_de... | 2012/04/22 | [
"https://wordpress.stackexchange.com/questions/49864",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12521/"
] | I like to use a child-theme.
The parent functions.php
```
function starkers_widgets_init() {
// Area 1, located at the top of the sidebar.
register_sidebar( array(
'name' => __( 'Primary Widget Area', 'starkers' ),
'id' => 'primary-widget-area',
'description' => __( 'The primary widget area', 'starkers' )... | Check the code bellow, I think that should work.
```
add_action( 'after_setup_theme', 'remove_default_sidebars', 11 );
function remove_default_sidebars(){
remove_action( 'widgets_init', 'starkers_widgets_init' );
}
``` |
49,879 | <p>So I'm trying to figure out how to properly use the get_current_screen. For learning sake, I'm just popping an alert for a specific page. I've looked at <a href="http://www.deluxeblogtips.com/2012/01/get-admin-screen-information.html" rel="nofollow">http://www.deluxeblogtips.com/2012/01/get-admin-screen-information... | [
{
"answer_id": 49883,
"author": "Stephen Harris",
"author_id": 9364,
"author_profile": "https://wordpress.stackexchange.com/users/9364",
"pm_score": 3,
"selected": true,
"text": "<p><code>wp_enqueue_scripts</code> is only fired on the front end, and not on admin screens. For loading scri... | 2012/04/22 | [
"https://wordpress.stackexchange.com/questions/49879",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15403/"
] | So I'm trying to figure out how to properly use the get\_current\_screen. For learning sake, I'm just popping an alert for a specific page. I've looked at <http://www.deluxeblogtips.com/2012/01/get-admin-screen-information.html> and the codex on WP\_Screen and get\_current\_screen (hit my max links cause my rep isn't 1... | `wp_enqueue_scripts` is only fired on the front end, and not on admin screens. For loading scripts admin side, you'll want the hook [`admin_enqueue_scripts`](http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts).
Passed as an optional argument is the page hook. (Examples include `edit.php`, fo... |
49,901 | <p>I'm a novice and looking to add the wp_editor to a custom metabox textarea field. I've looked seemingly everywhere for an complete example for writing a metabox with a textarea that uses the wp_editor. I am looking for a complete beginning to end example.</p>
<p>I do not want to use a plugin.</p>
<p>Anyone have a ... | [
{
"answer_id": 49905,
"author": "JohnG",
"author_id": 14194,
"author_profile": "https://wordpress.stackexchange.com/users/14194",
"pm_score": 0,
"selected": false,
"text": "<p>Are you looking for a code example from scratch, or would you consider integrating a custom metabox plugin which... | 2012/04/23 | [
"https://wordpress.stackexchange.com/questions/49901",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14558/"
] | I'm a novice and looking to add the wp\_editor to a custom metabox textarea field. I've looked seemingly everywhere for an complete example for writing a metabox with a textarea that uses the wp\_editor. I am looking for a complete beginning to end example.
I do not want to use a plugin.
Anyone have a link to a compl... | There is at least 1 issue with using wp\_editor in a meta box, as discussed in [ticket #19173](http://core.trac.wordpress.org/ticket/19173)(Good read on the subject of wp\_editor and meta boxes). TinyMCE gets all messed up if you move the meta box that contains it (specifically, if TinyMCE's location in the DOM is chan... |
49,904 | <p>I got this code <em>(<a href="http://www.sitepoint.com/split-wordpress-content-into-multiple-sections/" rel="nofollow">source</a>)</em></p>
<pre><code>// split content at the more tag and return an array
function split_content() {
global $more;
$more = true;
$content = preg_split('/<span id="more-\d+... | [
{
"answer_id": 49905,
"author": "JohnG",
"author_id": 14194,
"author_profile": "https://wordpress.stackexchange.com/users/14194",
"pm_score": 0,
"selected": false,
"text": "<p>Are you looking for a code example from scratch, or would you consider integrating a custom metabox plugin which... | 2012/04/23 | [
"https://wordpress.stackexchange.com/questions/49904",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15419/"
] | I got this code *([source](http://www.sitepoint.com/split-wordpress-content-into-multiple-sections/))*
```
// split content at the more tag and return an array
function split_content() {
global $more;
$more = true;
$content = preg_split('/<span id="more-\d+"><\/span>/i', get_the_content('more'));
for($... | There is at least 1 issue with using wp\_editor in a meta box, as discussed in [ticket #19173](http://core.trac.wordpress.org/ticket/19173)(Good read on the subject of wp\_editor and meta boxes). TinyMCE gets all messed up if you move the meta box that contains it (specifically, if TinyMCE's location in the DOM is chan... |
49,927 | <p>I'd like to execute some code everytime my wordpress cron runs, regardless of the timeframe. Is it possible to create an add_action for this? I looked in the filter list but I couldn't find anything relevant.</p>
<p>Thanks!</p>
| [
{
"answer_id": 49928,
"author": "Scott",
"author_id": 4610,
"author_profile": "https://wordpress.stackexchange.com/users/4610",
"pm_score": 4,
"selected": true,
"text": "<p>Basically every page load looks to see if there is anything scheduled to run, so by that logic the cron is checked ... | 2012/04/23 | [
"https://wordpress.stackexchange.com/questions/49927",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4284/"
] | I'd like to execute some code everytime my wordpress cron runs, regardless of the timeframe. Is it possible to create an add\_action for this? I looked in the filter list but I couldn't find anything relevant.
Thanks! | Basically every page load looks to see if there is anything scheduled to run, so by that logic the cron is checked and can possibly run on every page load.
I can only presume you want to schedule something to run every so often. If that's the case you need to look at [wp\_schedule\_event()](http://codex.wordpress.org/... |
49,939 | <p>I am writing a plugin for WordPress, one of the tasks I need to-do is send the HTML content of a new post to an e-mail address at the time of posting, I know I can use certain hooks to fire after the post has been saved, but is there a way to get the full HTML content of the new page/post with the theme applied?</p>... | [
{
"answer_id": 49949,
"author": "fcrossen",
"author_id": 15471,
"author_profile": "https://wordpress.stackexchange.com/users/15471",
"pm_score": 0,
"selected": false,
"text": "<p>See the save_post action hook - <a href=\"http://codex.wordpress.org/Plugin_API/Action_Reference/save_post\" ... | 2012/04/23 | [
"https://wordpress.stackexchange.com/questions/49939",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15462/"
] | I am writing a plugin for WordPress, one of the tasks I need to-do is send the HTML content of a new post to an e-mail address at the time of posting, I know I can use certain hooks to fire after the post has been saved, but is there a way to get the full HTML content of the new page/post with the theme applied?
I hav... | ```
add_action('publish_post', 'email_post');
function email_post($postID)
{
$post = get_post($postID);
$content = $post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$mailto = 'youremail';
$subject = 'New Post';
if(mail($ma... |
49,942 | <p>I want the email to be sent to different email addresses based on a drop-down Subject value. Can I do this with Contact Form 7?</p>
| [
{
"answer_id": 49946,
"author": "JohnG",
"author_id": 14194,
"author_profile": "https://wordpress.stackexchange.com/users/14194",
"pm_score": 0,
"selected": false,
"text": "<p>Yes. You can create the drop down menu and populate it with the various e-mail addresses you want the user to ch... | 2012/04/23 | [
"https://wordpress.stackexchange.com/questions/49942",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15468/"
] | I want the email to be sent to different email addresses based on a drop-down Subject value. Can I do this with Contact Form 7? | Use Pipes. See the FAQ: <http://contactform7.com/selectable-recipient-with-pipes/>
I.e.:
```
[select your-recipient "CEO|ceo@example.com"
"Sales|sales@example.com"
"Support|support@example.com"]
``` |
49,956 | <p>I have a category called "javascript" and it's limiting my list to only 4 entries?</p>
<pre><code><?php get_header(); ?>
<div class="container">
<div class="row">
<div class="decorate">
<h1>Javascript</h1>
<?php if (have_posts()) : ?>
<... | [
{
"answer_id": 49957,
"author": "markratledge",
"author_id": 268,
"author_profile": "https://wordpress.stackexchange.com/users/268",
"pm_score": 3,
"selected": true,
"text": "<p>This has nothing to do with the loop in the template file.</p>\n\n<p>Check Settings>>Reading>>\"Blog pages sho... | 2012/04/23 | [
"https://wordpress.stackexchange.com/questions/49956",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/2417/"
] | I have a category called "javascript" and it's limiting my list to only 4 entries?
```
<?php get_header(); ?>
<div class="container">
<div class="row">
<div class="decorate">
<h1>Javascript</h1>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<p><a... | This has nothing to do with the loop in the template file.
Check Settings>>Reading>>"Blog pages show at most..."
That setting is the default setting for Archives, too, as well as Search results, etc.
Use [WordPress › Custom Post Limits « WordPress Plugins](http://wordpress.org/extend/plugins/custom-post-limits/) to ... |
49,965 | <p>Running WordPress 3.3.2 and PHP Version 5.2.17</p>
<p>I'm trying to get the access_token from Facebook using wp_remote_request() and Facebook OAuth API (btw, working example at the end of this entry).</p>
<p>Is there any reason why this doesn't work (should according to doc and source code)?:</p>
<pre><code>$resp... | [
{
"answer_id": 49967,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 2,
"selected": false,
"text": "<p><code>body</code> argument is used for POST requests and set in headers. For GET request encode request arguments in... | 2012/04/23 | [
"https://wordpress.stackexchange.com/questions/49965",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14546/"
] | Running WordPress 3.3.2 and PHP Version 5.2.17
I'm trying to get the access\_token from Facebook using wp\_remote\_request() and Facebook OAuth API (btw, working example at the end of this entry).
Is there any reason why this doesn't work (should according to doc and source code)?:
```
$response = wp_remote_request(... | `body` argument is used for POST requests and set in headers. For GET request encode request arguments into URL (as in your second snippet). |
49,977 | <p>I would like to know is there any way/Plugin to limit the user published post (in a given time span) by his role?</p>
<p>Like this:</p>
<blockquote>
<ul>
<li>Role A -> 1 post per day and 30 post total.</li>
<li>Role B -> 10 post per day and 100 post total.</li>
<li>Role C -> unlimited.</li>
</ul>
</block... | [
{
"answer_id": 50012,
"author": "Bainternet",
"author_id": 2487,
"author_profile": "https://wordpress.stackexchange.com/users/2487",
"pm_score": 3,
"selected": true,
"text": "<p>You can use my plugin <a href=\"http://wordpress.org/extend/plugins/bainternet-posts-creation-limits/\" rel=\"... | 2012/04/23 | [
"https://wordpress.stackexchange.com/questions/49977",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14728/"
] | I would like to know is there any way/Plugin to limit the user published post (in a given time span) by his role?
Like this:
>
> * Role A -> 1 post per day and 30 post total.
> * Role B -> 10 post per day and 100 post total.
> * Role C -> unlimited.
>
>
>
I know there are some plugin out there that have these fe... | You can use my plugin [Posts Creation Limits](http://wordpress.org/extend/plugins/bainternet-posts-creation-limits/) which has a per user, per role, per post type, per post status limiting system and combined with its `post_creation_limits_custom_checks` action hook and check if the user has created a post that day alr... |
49,979 | <p>I am currently building a webpage for a local sports club with 800 members. The features I need in a potential membership plugin is:</p>
<ol>
<li>Member database with name, address, email, phone etc</li>
<li>Able to sort the members in different sport categories (football, athletics etc) and subcategories (youth, s... | [
{
"answer_id": 50012,
"author": "Bainternet",
"author_id": 2487,
"author_profile": "https://wordpress.stackexchange.com/users/2487",
"pm_score": 3,
"selected": true,
"text": "<p>You can use my plugin <a href=\"http://wordpress.org/extend/plugins/bainternet-posts-creation-limits/\" rel=\"... | 2012/04/23 | [
"https://wordpress.stackexchange.com/questions/49979",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15461/"
] | I am currently building a webpage for a local sports club with 800 members. The features I need in a potential membership plugin is:
1. Member database with name, address, email, phone etc
2. Able to sort the members in different sport categories (football, athletics etc) and subcategories (youth, senior etc).
3. Onli... | You can use my plugin [Posts Creation Limits](http://wordpress.org/extend/plugins/bainternet-posts-creation-limits/) which has a per user, per role, per post type, per post status limiting system and combined with its `post_creation_limits_custom_checks` action hook and check if the user has created a post that day alr... |
49,996 | <p>Here's are wp_query args:</p>
<pre><code>$args = array(
'post_type' => 'sportpages'
,'post_status' => 'publish'
,'posts_per_page' => 1000
,'post_parent' => 4738
,'meta_query' => array(
'relation' => 'OR'
,array(
'key' => 'ecpt_sportgender_2'
... | [
{
"answer_id": 50001,
"author": "kaiser",
"author_id": 385,
"author_profile": "https://wordpress.stackexchange.com/users/385",
"pm_score": 1,
"selected": false,
"text": "<p>You'll probably need to do one of the following</p>\n\n<ul>\n<li><code>'compare' => '='</code> (or leave it out,... | 2012/04/23 | [
"https://wordpress.stackexchange.com/questions/49996",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15484/"
] | Here's are wp\_query args:
```
$args = array(
'post_type' => 'sportpages'
,'post_status' => 'publish'
,'posts_per_page' => 1000
,'post_parent' => 4738
,'meta_query' => array(
'relation' => 'OR'
,array(
'key' => 'ecpt_sportgender_2'
,'value' => 'Boys'
... | You'll probably need to do one of the following
* `'compare' => '='` (or leave it out, as it's the default)
* or... `'value' => $wpdb->esc_like( '%Boys%' )` (needs `global $wpdb;`)
* or... `'value' => $wpdb->esc_like( 'Boys' )` (needs `global $wpdb;`) |
50,006 | <h1>Problem</h1>
<p>I have a page on my site where I need to do additional searching within that page. I am using the default way of WordPress searching with <code><?php get_search_form(); ?></code> for my main header search, which works great.</p>
<p>I created another HTML form on my page, not using the defau... | [
{
"answer_id": 50022,
"author": "onetrickpony",
"author_id": 1986,
"author_profile": "https://wordpress.stackexchange.com/users/1986",
"pm_score": 2,
"selected": false,
"text": "<p>You can modify the query before it gets processed:</p>\n\n<pre><code>add_action('parse_query', function($qu... | 2012/04/23 | [
"https://wordpress.stackexchange.com/questions/50006",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13169/"
] | Problem
=======
I have a page on my site where I need to do additional searching within that page. I am using the default way of WordPress searching with `<?php get_search_form(); ?>` for my main header search, which works great.
I created another HTML form on my page, not using the default PHP method, for the additi... | The simplest option if you want to show search results within a page context you'll need to do a custom loop, otherwise you won't be able to access the page information.
Change the input with the name `s` to something else like `search` or `q` to stop wordpress from doing it's usual built in search.
Next change the f... |
50,009 | <p>I have two custom post types (Authors and Partners). I display their archive page's in the main navigation and use archive-authors.php and archive-partners.php to make a couple small tweaks to the display of posts in each.</p>
<p>Now, my client would like to display some text before the archive's post listing. So f... | [
{
"answer_id": 50025,
"author": "Adam",
"author_id": 13418,
"author_profile": "https://wordpress.stackexchange.com/users/13418",
"pm_score": 3,
"selected": true,
"text": "<p>One of the easiest (although not the only) of ways to achieve this is by creating a custom options panel in the WP... | 2012/04/23 | [
"https://wordpress.stackexchange.com/questions/50009",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9844/"
] | I have two custom post types (Authors and Partners). I display their archive page's in the main navigation and use archive-authors.php and archive-partners.php to make a couple small tweaks to the display of posts in each.
Now, my client would like to display some text before the archive's post listing. So far I can t... | One of the easiest (although not the only) of ways to achieve this is by creating a custom options panel in the WP dashboard that will allow your client to create and update information that can be used through out your template files with no technical knowledge being necessary.
You can either paste the following dir... |
50,019 | <p>I want to do some (sometimes really complex) stuff on my pages based on pages/posts IDs', Settings API, etc. </p>
<p>Now I've all my functions written directly within page.php file, but I don't want it to leave it this way - it's really messy and it's hard to control everything. I'd love to have separate files for ... | [
{
"answer_id": 50020,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 3,
"selected": true,
"text": "<p>Globals aren't passed into functions. You have to declare them.</p>\n\n<p>Change this:</p>\n\n<pre><code>fun... | 2012/04/23 | [
"https://wordpress.stackexchange.com/questions/50019",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1869/"
] | I want to do some (sometimes really complex) stuff on my pages based on pages/posts IDs', Settings API, etc.
Now I've all my functions written directly within page.php file, but I don't want it to leave it this way - it's really messy and it's hard to control everything. I'd love to have separate files for each funct... | Globals aren't passed into functions. You have to declare them.
Change this:
```
function test() {
return $post->ID; //or echo $post->ID;
}
```
...to this:
```
function test() {
global $post;
return $post->ID; //or echo $post->ID;
}
``` |
50,032 | <p>To clarify my question...
My plugin is/was using AJAX to call the file <code>pluginname/submit/pick.php</code> My <code>pluginname/pluginname.php</code> contains the usual plugin header and wordpress automatically finds it.</p>
<p>Original Question...
I'm trying to use the global <code>$wpdb</code> in a plugin to ... | [
{
"answer_id": 50055,
"author": "kaiser",
"author_id": 385,
"author_profile": "https://wordpress.stackexchange.com/users/385",
"pm_score": 2,
"selected": false,
"text": "<p>You're making something completely wrong.</p>\n\n<h2>Header comment</h2>\n\n<p>In your main file, you need the foll... | 2012/04/24 | [
"https://wordpress.stackexchange.com/questions/50032",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15493/"
] | To clarify my question...
My plugin is/was using AJAX to call the file `pluginname/submit/pick.php` My `pluginname/pluginname.php` contains the usual plugin header and wordpress automatically finds it.
Original Question...
I'm trying to use the global `$wpdb` in a plugin to insert data into one of my tables.
From the ... | **The short answer**
The error is because I put a URL in instead of a filepath. and the one line fix is to set `$p = '../../../../wp-blog-header.php';`
**The long answer**
Following kaiser's link led me down a long road that eventually lead to what I believe is the correct way to do this.
in `pluginname/plugin.php`... |
50,035 | <p>I am developing a site that has two different custom post types; one of them is called Articles and one is called Sketchpad. Sketchpad is user submitted content that is assigned a custom taxonomy term value of either; public or private. Public posts are shown on the site and private posts aren't. </p>
<p>The articl... | [
{
"answer_id": 50057,
"author": "FourStacks",
"author_id": 7297,
"author_profile": "https://wordpress.stackexchange.com/users/7297",
"pm_score": 3,
"selected": true,
"text": "<p>not sure if you'll have tried this yet but you could consider grabbing the two sets of posts separately then m... | 2012/04/24 | [
"https://wordpress.stackexchange.com/questions/50035",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1687/"
] | I am developing a site that has two different custom post types; one of them is called Articles and one is called Sketchpad. Sketchpad is user submitted content that is assigned a custom taxonomy term value of either; public or private. Public posts are shown on the site and private posts aren't.
The article post typ... | not sure if you'll have tried this yet but you could consider grabbing the two sets of posts separately then merging them. Finally use `get_posts` to create a combined list sorted the way you want. Something like this might work for you (you may want to add in a posts per page argument to the $args variables):
```
<?p... |
50,043 | <p>This seems like simple thing but I need way to determine whether the current screen is for <strong>Add New</strong> or <strong>Edit</strong> ( a sort of wordpress admin conditional tag). Is there a built in function for this already, or ... any idea how to accomplish?</p>
| [
{
"answer_id": 50045,
"author": "Bainternet",
"author_id": 2487,
"author_profile": "https://wordpress.stackexchange.com/users/2487",
"pm_score": 6,
"selected": true,
"text": "<p>here is a function that i have:</p>\n<pre><code>/**\n * is_edit_page \n * function to check if the current pag... | 2012/04/24 | [
"https://wordpress.stackexchange.com/questions/50043",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7247/"
] | This seems like simple thing but I need way to determine whether the current screen is for **Add New** or **Edit** ( a sort of wordpress admin conditional tag). Is there a built in function for this already, or ... any idea how to accomplish? | here is a function that i have:
```
/**
* is_edit_page
* function to check if the current page is a post edit page
*
* @author Ohad Raz <admin@bainternet.info>
*
* @param string $new_edit what page to check for accepts new - new post page ,edit - edit post page, null for either
* @return boolean
*/
functi... |
50,047 | <p>I have a plugin that I'm using to switch themes for a specific user for development. When logged in as that user they see the different style sheet but the themes files, function.php, header.php, etc are the active theme for everyone else.</p>
<p>What I am doing wrong?</p>
<pre><code>function change_user_theme($te... | [
{
"answer_id": 50054,
"author": "sanchothefat",
"author_id": 1733,
"author_profile": "https://wordpress.stackexchange.com/users/1733",
"pm_score": 3,
"selected": true,
"text": "<p>Take a look at my answer here:</p>\n\n<p><a href=\"https://wordpress.stackexchange.com/questions/33335/switc... | 2012/04/24 | [
"https://wordpress.stackexchange.com/questions/50047",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/2832/"
] | I have a plugin that I'm using to switch themes for a specific user for development. When logged in as that user they see the different style sheet but the themes files, function.php, header.php, etc are the active theme for everyone else.
What I am doing wrong?
```
function change_user_theme($template) {
global ... | Take a look at my answer here:
[Switch Theme Through Options Panel](https://wordpress.stackexchange.com/questions/33335/switch-theme-through-options-panel/33409#33409)
The code is as follows:
```
add_action( 'setup_theme', 'switch_user_theme' );
function switch_user_theme() {
if ( in_array( wp_get_current_user()... |
50,052 | <p>a plugin i'm working on has a conflict with w3 total cache. To be more specific, in my code i have</p>
<pre><code>static function get_instance()
{
if( self::$_instance === NULL ) {
// get the settings from the database
self::$_instance = get_option( 'ai1ec_settings' );
// if there are n... | [
{
"answer_id": 51107,
"author": "fischi",
"author_id": 15680,
"author_profile": "https://wordpress.stackexchange.com/users/15680",
"pm_score": 3,
"selected": true,
"text": "<p>okay, here we go. try this: in your functions.php modify the behaviour of ai1ec_options: </p>\n\n<pre><code>$ai1... | 2012/04/24 | [
"https://wordpress.stackexchange.com/questions/50052",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13205/"
] | a plugin i'm working on has a conflict with w3 total cache. To be more specific, in my code i have
```
static function get_instance()
{
if( self::$_instance === NULL ) {
// get the settings from the database
self::$_instance = get_option( 'ai1ec_settings' );
// if there are no settings in ... | okay, here we go. try this: in your functions.php modify the behaviour of ai1ec\_options:
```
$ai1ec_options = get_option('ai1ec_options');
delete_option('ai1ec_options');
add_option('ai1ec_options', $ai1ec_options, '', 'no'); // thanks for your suggestion :)
```
be careful though, as you might lose your set option... |
50,056 | <p>I'm trying to use <code>$wpdb->get_results</code> to retrieve an array of all posts including custom fields. I can retrieve the meta_key and meta_value columns like this:</p>
<pre><code>[meta_key] => state [meta_value] => california
</code></pre>
<p>but I'm trying to list them in the object like this:</p>... | [
{
"answer_id": 50062,
"author": "kaiser",
"author_id": 385,
"author_profile": "https://wordpress.stackexchange.com/users/385",
"pm_score": 2,
"selected": false,
"text": "<p>Note, before going further: Take care about portability and security:</p>\n\n<pre><code>function wpse50056_get_post... | 2012/04/24 | [
"https://wordpress.stackexchange.com/questions/50056",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14297/"
] | I'm trying to use `$wpdb->get_results` to retrieve an array of all posts including custom fields. I can retrieve the meta\_key and meta\_value columns like this:
```
[meta_key] => state [meta_value] => california
```
but I'm trying to list them in the object like this:
```
[meta_key] => meta_value [state] => califo... | Note, before going further: Take care about portability and security:
```
function wpse50056_get_post_meta()
{
global $wpdb;
$results = $wpdb->get_results( "
SELECT
ID,
post_date,
post_title,
post_content,
meta_key,
meta_val... |
50,064 | <p>Cannot figured it out... I need to count how many posts there are for each taxonomy term form each month.</p>
| [
{
"answer_id": 50087,
"author": "GhostToast",
"author_id": 13676,
"author_profile": "https://wordpress.stackexchange.com/users/13676",
"pm_score": 0,
"selected": false,
"text": "<p>One method you might want to research is <code>wp_get_archives</code>\n<a href=\"http://codex.wordpress.org... | 2012/04/24 | [
"https://wordpress.stackexchange.com/questions/50064",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12710/"
] | Cannot figured it out... I need to count how many posts there are for each taxonomy term form each month. | This is a long answer and there is a lot of code, please note that it is all **not** tested.
My solution use a function that create a multidimensional array where key are year, month, term id and the value are the term count.
The function also accept as argument an array of args to pass to WP\_Query, limiting the ter... |
50,094 | <p>From what I can see wp_remote_get() saves remote file contents to memory.</p>
<p>The files that I need to download are compressed in either ZIP or GZIP and within which will either be a CVS or XMl file</p>
<p>What I need to do first is download the remote file to the harddrive as ZIP either GZIP and then unzip the... | [
{
"answer_id": 50210,
"author": "AndyW",
"author_id": 15510,
"author_profile": "https://wordpress.stackexchange.com/users/15510",
"pm_score": 4,
"selected": false,
"text": "<p>Well here's the solution that I came up with:</p>\n\n<pre><code>// Use wp_remote_get to fetch the data\n$respons... | 2012/04/24 | [
"https://wordpress.stackexchange.com/questions/50094",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15510/"
] | From what I can see wp\_remote\_get() saves remote file contents to memory.
The files that I need to download are compressed in either ZIP or GZIP and within which will either be a CVS or XMl file
What I need to do first is download the remote file to the harddrive as ZIP either GZIP and then unzip them
Is it possib... | Well here's the solution that I came up with:
```
// Use wp_remote_get to fetch the data
$response = wp_remote_get($url);
// Save the body part to a variable
$zip = $data['body'];
// In the header info is the name of the XML or CVS file. I used preg_match to find it
preg_match("/.datafeed_([0-9]*)\../", $response['h... |
50,096 | <p>I have a custom post type and a metabox with a file input.</p>
<p>I can insert the attachment, but I can't update the attachment metadata and I don't know how to fix it because I don't receive any error.</p>
<p>Here is my code:</p>
<pre><code>$attach_id = wp_insert_attachment( $attachment, $filename, $post_id );
... | [
{
"answer_id": 51300,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 2,
"selected": false,
"text": "<p><em>From comment:</em></p>\n\n<p>Let WordPress generate a file path and use that for the next steps:</p>\n\n<pre><code... | 2012/04/24 | [
"https://wordpress.stackexchange.com/questions/50096",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4984/"
] | I have a custom post type and a metabox with a file input.
I can insert the attachment, but I can't update the attachment metadata and I don't know how to fix it because I don't receive any error.
Here is my code:
```
$attach_id = wp_insert_attachment( $attachment, $filename, $post_id );
$attach_data = wp_generate_a... | *From comment:*
Let WordPress generate a file path and use that for the next steps:
```
$upload = wp_handle_upload($filename, array('test_form' => false));
$attach_id = wp_insert_attachment( $attachment, $upload['file'], $post_id );
wp_update_attachment_metadata( $attach_id, $attach_data );
``` |
50,111 | <p>For some reason I can't get the jquery document ready to fire for my plugin</p>
<p>my javascript</p>
<pre><code>jquery(document).ready(function($) {
alert("hello world");
$("#testdiv").text("hi");
});
</code></pre>
<p>the source from my website</p>
<pre><code><link rel='stylesheet' id='admin-bar-css' ... | [
{
"answer_id": 50113,
"author": "Joseph Leedy",
"author_id": 8554,
"author_profile": "https://wordpress.stackexchange.com/users/8554",
"pm_score": 3,
"selected": true,
"text": "<p>Try using <code>jQuery</code> instead of <code>jquery</code>. (Note the capital \"Q\".)</p>\n\n<p>Edit:</p>\... | 2012/04/24 | [
"https://wordpress.stackexchange.com/questions/50111",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15493/"
] | For some reason I can't get the jquery document ready to fire for my plugin
my javascript
```
jquery(document).ready(function($) {
alert("hello world");
$("#testdiv").text("hi");
});
```
the source from my website
```
<link rel='stylesheet' id='admin-bar-css' href='http://example.com/wp-includes/css/admin... | Try using `jQuery` instead of `jquery`. (Note the capital "Q".)
Edit:
Upon viewing your source, you have an extra `});`.
[Working example](http://jsfiddle.net/Greug/) |
50,125 | <p>I am having problems finding an answer to this. I need to have a custom user meta field. </p>
<p>I can create them which is fine but I need to create a drop down one. </p>
<p>For example I want the user meta to be Unit type and the drop down values to be Residential and Commercial</p>
<p>Any help on this would be... | [
{
"answer_id": 50127,
"author": "Bainternet",
"author_id": 2487,
"author_profile": "https://wordpress.stackexchange.com/users/2487",
"pm_score": 1,
"selected": false,
"text": "<p>Once again if you know how to add a text field you know how to add any other form field, ex:</p>\n\n<h2>showi... | 2012/04/24 | [
"https://wordpress.stackexchange.com/questions/50125",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15517/"
] | I am having problems finding an answer to this. I need to have a custom user meta field.
I can create them which is fine but I need to create a drop down one.
For example I want the user meta to be Unit type and the drop down values to be Residential and Commercial
Any help on this would be great. Thanks. | thanks for that. Just one minor tweak, as the first bit of code threw up an error. Below is the working code for the first block of code.
```
//hooks
add_action( 'show_user_profile', 'Add_user_fields' );
add_action( 'edit_user_profile', 'Add_user_fields' );
function Add_user_fields( $user ) { ?>
<h3>Extra fields</h... |
50,136 | <p>I've many categories in my database but when i'm calling <code>wp_list_categories()</code> it is not listing any categories, its only outputting </p>
<pre><code>Categories
No categories
</code></pre>
<p>Also, I'm trying to populate it using <code>get_categories()</code> but still same problem, it outputting as i... | [
{
"answer_id": 50144,
"author": "Rutwick Gangurde",
"author_id": 4740,
"author_profile": "https://wordpress.stackexchange.com/users/4740",
"pm_score": 1,
"selected": false,
"text": "<p>You can use <code>wp_list_categories</code> or <code>get_categories</code>, just pass <code>hide_empty ... | 2012/04/25 | [
"https://wordpress.stackexchange.com/questions/50136",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12000/"
] | I've many categories in my database but when i'm calling `wp_list_categories()` it is not listing any categories, its only outputting
```
Categories
No categories
```
Also, I'm trying to populate it using `get_categories()` but still same problem, it outputting as if there were no category | You can use `wp_list_categories` or `get_categories`, just pass `hide_empty = 0` to it. This will get you even those categories which do not have any posts associated with them.
Ex: `$cats = get_categories(array('hide_empty' => 0));` |
50,146 | <p>If I know the current post id that i have in the variable $pid</p>
<p>I use <code>$terms = get_the_terms($pid, 'custom_category');</code></p>
<p>How do I get just the <code>term id/term_taxonomy_id</code></p>
<p>if I <code>var_dump</code> <code>$terms</code> I see what I want...but I have no idea how the heck to ... | [
{
"answer_id": 50149,
"author": "Rajeev Vyas",
"author_id": 6961,
"author_profile": "https://wordpress.stackexchange.com/users/6961",
"pm_score": 3,
"selected": true,
"text": "<p>(Probably better to use <code>get_the_terms</code>).</p>\n\n<pre><code>$terms = wp_get_object_terms( $pid, '... | 2012/04/25 | [
"https://wordpress.stackexchange.com/questions/50146",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15403/"
] | If I know the current post id that i have in the variable $pid
I use `$terms = get_the_terms($pid, 'custom_category');`
How do I get just the `term id/term_taxonomy_id`
if I `var_dump` `$terms` I see what I want...but I have no idea how the heck to return just the id, not an array, just the id.
Bare in mind...I les... | (Probably better to use `get_the_terms`).
```
$terms = wp_get_object_terms( $pid, 'custom_category', array('fields'=>'ids'));
```
Get an array of term ids (will always been array, even if it is an array of one):
```
$ids = wp_list_pluck( $terms, 'term_id' );
```
If you just want one id... then 'pop' out the last... |
50,148 | <p><img src="https://i.stack.imgur.com/laOV6.jpg" alt="enter image description here"></p>
<p>I am a PHP novice and wrote this function. It is an alphabetical navigation which shows only the letter that have posts in both that letter and the currently filtered "genero" taxonomy term.</p>
<p>I use multiple taxonomy que... | [
{
"answer_id": 50150,
"author": "offroff",
"author_id": 13073,
"author_profile": "https://wordpress.stackexchange.com/users/13073",
"pm_score": 1,
"selected": false,
"text": "<p>I didn't use the transients API yet but in this case I think it's a good choice. You use it but only for a sma... | 2012/04/25 | [
"https://wordpress.stackexchange.com/questions/50148",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/325/"
] | 
I am a PHP novice and wrote this function. It is an alphabetical navigation which shows only the letter that have posts in both that letter and the currently filtered "genero" taxonomy term.
I use multiple taxonomy queries to find "artistas" posts t... | I would just retrieve an array of alphabet/taxonomy terms that have posts. You do this, but doesn't actually use it. This function will return an array of non-empty (alphabet) terms:
(**Transient?** - unless you have multiple post types using this taxonomy, (*see below*) I'm not sure if much is gained from using trans... |
50,156 | <p>If I use Lighttpd as webserver, how can I use caching plugin like w3 total cache or wp super cache?
Need your help for configuring lighttpd.</p>
<p>Thanks.</p>
| [
{
"answer_id": 54941,
"author": "Pontus Abrahamsson",
"author_id": 16722,
"author_profile": "https://wordpress.stackexchange.com/users/16722",
"pm_score": 2,
"selected": true,
"text": "<p>The following script takes the url that was asked from the client. It checks whether there is a fres... | 2012/04/25 | [
"https://wordpress.stackexchange.com/questions/50156",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8096/"
] | If I use Lighttpd as webserver, how can I use caching plugin like w3 total cache or wp super cache?
Need your help for configuring lighttpd.
Thanks. | The following script takes the url that was asked from the client. It checks whether there is a fresh version of a static HTML page on the cache and if yes, it servers that. If the file does not exist at all or the it is expired(I check its modification date) then the request is forwarded to the PHP fcgi so that it can... |
50,165 | <p>I use FaceBook JS SDK to check whether the user has permission to log in to my site or not. If user has permission I log him into the WP site. </p>
<p><strong>It is possible to check with JS whether the user already logged in or not?</strong> Possible to check existance of <code>wordpress_logged_in_</code> cookie, ... | [
{
"answer_id": 55489,
"author": "kaiser",
"author_id": 385,
"author_profile": "https://wordpress.stackexchange.com/users/385",
"pm_score": 2,
"selected": false,
"text": "<p>Just use <a href=\"http://codex.wordpress.org/Function_Reference/wp_localize_script\" rel=\"nofollow\"><code>wp_loc... | 2012/04/25 | [
"https://wordpress.stackexchange.com/questions/50165",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9909/"
] | I use FaceBook JS SDK to check whether the user has permission to log in to my site or not. If user has permission I log him into the WP site.
**It is possible to check with JS whether the user already logged in or not?** Possible to check existance of `wordpress_logged_in_` cookie, and how?
I am trying with this co... | Just use [`wp_localize_script()`](http://codex.wordpress.org/Function_Reference/wp_localize_script) and [`is_user_logged_in()`](http://codex.wordpress.org/Function_Reference/is_user_logged_in).
```
wp_localize_script(
'my-ajax-request',
'MyAjax',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ... |
50,168 | <p>This is my code thus far:</p>
<pre><code>function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' ),
'extra-menu' => __( 'Extra Menu' )
)
);
}
add_action( 'init', 'register_my_menus' );
</code></pre>
<p>But this seems to on... | [
{
"answer_id": 50267,
"author": "Adam",
"author_id": 13418,
"author_profile": "https://wordpress.stackexchange.com/users/13418",
"pm_score": 3,
"selected": true,
"text": "<p>Example code taken from <strong>new2wp.com</strong> located <a href=\"http://new2wp.com/snippet/register-and-creat... | 2012/04/25 | [
"https://wordpress.stackexchange.com/questions/50168",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10990/"
] | This is my code thus far:
```
function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' ),
'extra-menu' => __( 'Extra Menu' )
)
);
}
add_action( 'init', 'register_my_menus' );
```
But this seems to only register 'locations' in which... | Example code taken from **new2wp.com** located [**HERE**](http://new2wp.com/snippet/register-and-create-new-nav-menus-with-default-menu-items/)
```
// Function for registering wp_nav_menu() in 3 locations
add_action( 'init', 'register_navmenus' );
function register_navmenus() {
register_nav_menus( ... |
50,201 | <p>I have a plugin that I am developing that is using custom post types and taxonomies. My question is this. How can I load the content/theme data from my plugin on to the page when the go to the custom url of the taxonomy?</p>
<p>EDIT</p>
<p>I am trying to use the plugin's template files and not the themes for my cu... | [
{
"answer_id": 50206,
"author": "Stephen Harris",
"author_id": 9364,
"author_profile": "https://wordpress.stackexchange.com/users/9364",
"pm_score": 4,
"selected": true,
"text": "<p>First of all - <strong>plugins are for generating content, themes are for displaying it</strong>. So reall... | 2012/04/25 | [
"https://wordpress.stackexchange.com/questions/50201",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5880/"
] | I have a plugin that I am developing that is using custom post types and taxonomies. My question is this. How can I load the content/theme data from my plugin on to the page when the go to the custom url of the taxonomy?
EDIT
I am trying to use the plugin's template files and not the themes for my custom taxomony. | First of all - **plugins are for generating content, themes are for displaying it**. So really, a plugin shouldn't do this. But there are grey areas - for example in an 'events' related plugin, it would be desirable to display dates, venue etc - things that a WordPress theme wouldn't normally display.
I would suggest... |
50,216 | <p>jQuery cycle thumbnails ?</p>
<p>Hi all</p>
<p>I have a demo here (not in Wordpress) where I'm using the jQuery cycle plugin
to create the slideshow and the thumbnails.</p>
<p><a href="http://www.ttmt.org.uk/forum/wordpress/" rel="nofollow">http://www.ttmt.org.uk/forum/wordpress/</a></p>
<p>I want to create the ... | [
{
"answer_id": 50206,
"author": "Stephen Harris",
"author_id": 9364,
"author_profile": "https://wordpress.stackexchange.com/users/9364",
"pm_score": 4,
"selected": true,
"text": "<p>First of all - <strong>plugins are for generating content, themes are for displaying it</strong>. So reall... | 2012/04/25 | [
"https://wordpress.stackexchange.com/questions/50216",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17373/"
] | jQuery cycle thumbnails ?
Hi all
I have a demo here (not in Wordpress) where I'm using the jQuery cycle plugin
to create the slideshow and the thumbnails.
<http://www.ttmt.org.uk/forum/wordpress/>
I want to create the same thing in Wordpress
<http://www.ttmt.org.uk/wordpress/>
Here I have one page with the images... | First of all - **plugins are for generating content, themes are for displaying it**. So really, a plugin shouldn't do this. But there are grey areas - for example in an 'events' related plugin, it would be desirable to display dates, venue etc - things that a WordPress theme wouldn't normally display.
I would suggest... |
50,219 | <p>I am building my first responsive WP site with my own custom WP Theme. The primary templates are part fluid, part fixed. This enabled me to create only 3 "versions", a desktop, tablet and mobile version. All changes happen due to media queries. (Sizes are 768 to 1200 px for desktop, 530 to 767 for tablet, 300 to 529... | [
{
"answer_id": 50223,
"author": "kaiser",
"author_id": 385,
"author_profile": "https://wordpress.stackexchange.com/users/385",
"pm_score": 1,
"selected": false,
"text": "<blockquote>\n <p>This answer is only here for historical reasons (and because it's mentioned in @toschos answer). <s... | 2012/04/25 | [
"https://wordpress.stackexchange.com/questions/50219",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5686/"
] | I am building my first responsive WP site with my own custom WP Theme. The primary templates are part fluid, part fixed. This enabled me to create only 3 "versions", a desktop, tablet and mobile version. All changes happen due to media queries. (Sizes are 768 to 1200 px for desktop, 530 to 767 for tablet, 300 to 529 fo... | Do not use server side browser sniffing. [It **will** fail:](http://www.smashingmagazine.com/2012/04/19/why-we-shouldnt-make-separate-mobile-websites/)
>
> The question here is how can you reliably detect mobile browsers in order to redirect them? The fact is: you can’t. Most people attempt to do this with browser sn... |
50,242 | <p>I am using wp_tag_cloud but my problem is the inline CSS (for the font-size). I am doing RWD so I need full control of my markup/css.</p>
<p>As I saw there is no property that will make it go away, so I guess I need to use another function, or the format=array. I tried using the array format but I couldn't make the... | [
{
"answer_id": 50261,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 2,
"selected": false,
"text": "<p>Add a filter for the tag cloud in your <code>functions.php</code>:</p>\n\n<pre><code>add_filter( 'wp_tag_cloud', 'wpse... | 2012/04/25 | [
"https://wordpress.stackexchange.com/questions/50242",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15550/"
] | I am using wp\_tag\_cloud but my problem is the inline CSS (for the font-size). I am doing RWD so I need full control of my markup/css.
As I saw there is no property that will make it go away, so I guess I need to use another function, or the format=array. I tried using the array format but I couldn't make the tags ap... | Add a filter for the tag cloud in your `functions.php`:
```
add_filter( 'wp_tag_cloud', 'wpse_50242_unstyled_tag_cloud' );
/**
* Change tag cloud inline style to CSS classes.
*
* @param string $tags
* @return string
*/
function wpse_50242_unstyled_tag_cloud( $tags )
{
return preg_replace(
"~ style='... |
50,247 | <p>So I have been doing some digging and narrowed down the file that I believe is calling for the front page excerpts on all posts. No matter what I change it to, it doesn't seem to adjust.</p>
<pre><code>//get excerpt for feed panels
function con_feed_excerpt() {
$excerpt = get_the_excerpt();
if (strlen($excer... | [
{
"answer_id": 50252,
"author": "Isaac Boda",
"author_id": 15553,
"author_profile": "https://wordpress.stackexchange.com/users/15553",
"pm_score": 0,
"selected": false,
"text": "<p>I did seem to get it working with a custom plugin. There doesn't seem to be an option for adjusting the fro... | 2012/04/26 | [
"https://wordpress.stackexchange.com/questions/50247",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | So I have been doing some digging and narrowed down the file that I believe is calling for the front page excerpts on all posts. No matter what I change it to, it doesn't seem to adjust.
```
//get excerpt for feed panels
function con_feed_excerpt() {
$excerpt = get_the_excerpt();
if (strlen($excerpt)>230) {
... | Here is a custom function I've written to modify your excerpt however you want. You should NOT be changing any core files to make modifications, as these will be overwritten by any updates made to the Wordpress framework:
```
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'preserve_... |
50,249 | <p>How can I use wp_get_object_terms() to get a list of all the terms attached to all posts in the current query?</p>
<p>For example, for the current query I want to get an array of the terms from the "Alfa" taxonomy that are contained in all the queried posts.</p>
<pre><code>wp_get_object_terms($wp_query, 'alfa');
<... | [
{
"answer_id": 51089,
"author": "mrwweb",
"author_id": 9844,
"author_profile": "https://wordpress.stackexchange.com/users/9844",
"pm_score": 4,
"selected": true,
"text": "<p>I think you're on the right track because <code>wp_get_object_terms()</code> can take an array of IDs for its firs... | 2012/04/26 | [
"https://wordpress.stackexchange.com/questions/50249",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/325/"
] | How can I use wp\_get\_object\_terms() to get a list of all the terms attached to all posts in the current query?
For example, for the current query I want to get an array of the terms from the "Alfa" taxonomy that are contained in all the queried posts.
```
wp_get_object_terms($wp_query, 'alfa');
```
But that only... | I think you're on the right track because `wp_get_object_terms()` can take an array of IDs for its first argument, it's just that $wp\_query is not the array you want.
I can't guarantee that this is more efficient (not my area of expertise), but I believe this [partially-tested] snippet would do what you want with at ... |
50,275 | <p>I have tried dbDelta and $wpdb->query, they does not work. Does anyone has any ideas?</p>
| [
{
"answer_id": 50311,
"author": "Aaron Wagner",
"author_id": 15568,
"author_profile": "https://wordpress.stackexchange.com/users/15568",
"pm_score": 0,
"selected": false,
"text": "<p>According to <a href=\"http://www.sitepoint.com/forums/showthread.php?636176-Wordpress-Plugins-Does-TRUNC... | 2012/04/26 | [
"https://wordpress.stackexchange.com/questions/50275",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15356/"
] | I have tried dbDelta and $wpdb->query, they does not work. Does anyone has any ideas? | As try today, truncate is WAY BETTER that DELETE, because DELETE broke the site, and trucate just empty the table, here is the working code :
```
global $wpdb;
$wpdb->query('TRUNCATE TABLE wp_posts');
``` |
50,290 | <p>I'm sorting out a long-neglected wordpress.org blog. It has over 100,000 pieces of trackback spam. How can I remove them all?</p>
| [
{
"answer_id": 50291,
"author": "fredley",
"author_id": 7091,
"author_profile": "https://wordpress.stackexchange.com/users/7091",
"pm_score": 1,
"selected": false,
"text": "<p>I gave up on finding an elegant solution and just used a MySQL sledgehammer to banish the spam:</p>\n\n<pre><cod... | 2012/04/26 | [
"https://wordpress.stackexchange.com/questions/50290",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7091/"
] | I'm sorting out a long-neglected wordpress.org blog. It has over 100,000 pieces of trackback spam. How can I remove them all? | To make this more WP-ish:
```
function wpse_delete_trackbacks()
{
global $wpdb;
$wpdb->query( $wpdb->prepare(
"
DELETE FROM %s WHERE `comment_type` = 'trackback'
",
"{$wpdb->prefix}comments"
) );
}
``` |
50,298 | <p>I am setting up a child theme for some of my faculty members, and as a part of the theme, I would like a handful of plugins to be activated at the time that the theme is activated. So, naturally, I used the after_setup_theme action and called my setup function. It works great, except it runs on EVERY request (admi... | [
{
"answer_id": 50301,
"author": "Chip Bennett",
"author_id": 3966,
"author_profile": "https://wordpress.stackexchange.com/users/3966",
"pm_score": 3,
"selected": false,
"text": "<p>The <code>after_setup_theme</code> action is <strong>intended</strong> to fire on every WordPress load. It ... | 2012/04/26 | [
"https://wordpress.stackexchange.com/questions/50298",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15568/"
] | I am setting up a child theme for some of my faculty members, and as a part of the theme, I would like a handful of plugins to be activated at the time that the theme is activated. So, naturally, I used the after\_setup\_theme action and called my setup function. It works great, except it runs on EVERY request (admin a... | The `after_setup_theme` action is **intended** to fire on every WordPress load. It is simply part of the process during which WordPress invokes the template system, determines the various setup parameters for the Theme, and then proceeds on with subsequent processing, such as determining the correct template to display... |
50,303 | <p>So I thought I could do it like this (also I want to only get 3) -</p>
<pre><code>$menu_items = wp_get_nav_menu_items(26);
$menu_items = array_rand($menu_items, 3);
foreach ( (array) $menu_items as $key => $menu_item ) {
$title = $menu_item->title;
echo $title;
}
</code></pre>
| [
{
"answer_id": 50313,
"author": "kaiser",
"author_id": 385,
"author_profile": "https://wordpress.stackexchange.com/users/385",
"pm_score": 1,
"selected": false,
"text": "<p>Ehm, <em>afaik</em> the <code>return</code> value of the menu fn is an <code>object</code>: You need to <code>type ... | 2012/04/26 | [
"https://wordpress.stackexchange.com/questions/50303",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15570/"
] | So I thought I could do it like this (also I want to only get 3) -
```
$menu_items = wp_get_nav_menu_items(26);
$menu_items = array_rand($menu_items, 3);
foreach ( (array) $menu_items as $key => $menu_item ) {
$title = $menu_item->title;
echo $title;
}
``` | Ehm, *afaik* the `return` value of the menu fn is an `object`: You need to `type cast` earlier
```
$menu_items = (array) wp_get_nav_menu_items( 26 ); // Typecast here
$menu_items = array_rand( $menu_items, 3 );
foreach ( $menu_items as $key => $menu_item )
{
echo $menu_item['title'];
}
``` |
50,305 | <p>I have been days over this issue now. Initially it was, how to store a user's follower data in database, for which I got couple of nice recommendations here at WordPress Answers. After, following the recommendations I have added a new table like this:</p>
<pre><code>id leader_id follower_id
1 2 4
2 ... | [
{
"answer_id": 50310,
"author": "kaiser",
"author_id": 385,
"author_profile": "https://wordpress.stackexchange.com/users/385",
"pm_score": 3,
"selected": false,
"text": "<h2>Template Tag</h2>\n\n<p>Just place both functions in your <code>functions.php</code> file. Then adjust the 1st fun... | 2012/04/26 | [
"https://wordpress.stackexchange.com/questions/50305",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9094/"
] | I have been days over this issue now. Initially it was, how to store a user's follower data in database, for which I got couple of nice recommendations here at WordPress Answers. After, following the recommendations I have added a new table like this:
```
id leader_id follower_id
1 2 4
2 3 1... | I am answering this question extremely late and my apologies for the same. I had been way too busy with deadlines to attend to this.
A big thanks to @m0r7if3r and @kaiser in providing the base solutions that I could extend and implement in my application. This answer provides details on my adaptation of the solutions ... |
50,306 | <p>I'm trying to use image upload in my theme's options page and haven't found yet a simple ajax upload script with many tutorials or a good documentation, I just want a simple straightforward script so I just edit the file path and couple other stuff, and of course that works with many uploaders on the page.</p>
<p>I... | [
{
"answer_id": 50308,
"author": "Aaron Wagner",
"author_id": 15568,
"author_profile": "https://wordpress.stackexchange.com/users/15568",
"pm_score": 3,
"selected": true,
"text": "<p>I have used the native uploader with great results. Try adding this snippet of JS:</p>\n\n<pre><code>jQue... | 2012/04/26 | [
"https://wordpress.stackexchange.com/questions/50306",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14490/"
] | I'm trying to use image upload in my theme's options page and haven't found yet a simple ajax upload script with many tutorials or a good documentation, I just want a simple straightforward script so I just edit the file path and couple other stuff, and of course that works with many uploaders on the page.
I tried plu... | I have used the native uploader with great results. Try adding this snippet of JS:
```
jQuery('#upload_image_button').click(function() {
formfield = jQuery('#fwpPhoto').attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
window.send_to_editor = function(html) {
imgur... |
50,331 | <p>Before describing the problem, let me first tell that I have already searched on google, also read the ACF documentation, support, even asked on their support forum but it's hard to get any kind of answer there.</p>
<p>So the thing is I have this wysiwyg on a custom post type I made where I have an item description... | [
{
"answer_id": 50334,
"author": "kaiser",
"author_id": 385,
"author_profile": "https://wordpress.stackexchange.com/users/385",
"pm_score": 2,
"selected": false,
"text": "<p>Simply go and apply the default filter:</p>\n\n<pre><code>// You´ll likely need a function that doesn´t echo/print ... | 2012/04/26 | [
"https://wordpress.stackexchange.com/questions/50331",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15574/"
] | Before describing the problem, let me first tell that I have already searched on google, also read the ACF documentation, support, even asked on their support forum but it's hard to get any kind of answer there.
So the thing is I have this wysiwyg on a custom post type I made where I have an item description, I really... | Simply go and apply the default filter:
```
// You´ll likely need a function that doesn´t echo/print the output to get this working
// without an error
echo apply_filters( 'the_excerpt', get_field( 'YOUR_FIELD_NAME', get_the_ID() ) );
``` |
50,333 | <p>Is it possible to hide the active themes in a network so that the subdomain users won't see them as being available?</p>
<p>The problem is that i have 10 themes installed on the network and the subdomain users see the ones not assigned to them under Appearance -> Themes, and activate other themes. I am trying to re... | [
{
"answer_id": 50335,
"author": "kaiser",
"author_id": 385,
"author_profile": "https://wordpress.stackexchange.com/users/385",
"pm_score": 0,
"selected": false,
"text": "<p>If you don't mind an jQuery solution:</p>\n\n<pre><code>function wpse50333_hide_current_theme()\n{\n echo '<s... | 2012/04/26 | [
"https://wordpress.stackexchange.com/questions/50333",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15394/"
] | Is it possible to hide the active themes in a network so that the subdomain users won't see them as being available?
The problem is that i have 10 themes installed on the network and the subdomain users see the ones not assigned to them under Appearance -> Themes, and activate other themes. I am trying to remove this ... | You could remove the `'switch_themes'` capability from the `'administrator'` role, which should prevent regular admins (as opposed to the network superadmin) from being able to switch their theme. Try this:
```
add_action('admin_init', 'custom_remove_switch_themes_role_from_admins');
function custom_remove_switch_them... |
50,342 | <p>I'm trying to create a condition in Wordpress that only calls the <code>wp_head()</code> on all pages except for the "About Us" page and "News Articles" pages. Here's the code:</p>
<pre><code><?php if (!is_page('about-us') || !is_page('news-articles')) {wp_head();}?>
</code></pre>
<p>It seems to work great ... | [
{
"answer_id": 50343,
"author": "Michael",
"author_id": 15579,
"author_profile": "https://wordpress.stackexchange.com/users/15579",
"pm_score": 2,
"selected": false,
"text": "<p>Rather than an or <code>||</code> you need an and <code>&&</code>.</p>\n\n<pre><code><?php if (!is_... | 2012/04/26 | [
"https://wordpress.stackexchange.com/questions/50342",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15578/"
] | I'm trying to create a condition in Wordpress that only calls the `wp_head()` on all pages except for the "About Us" page and "News Articles" pages. Here's the code:
```
<?php if (!is_page('about-us') || !is_page('news-articles')) {wp_head();}?>
```
It seems to work great when I only use the command for one of the p... | You should be using the "AND" operator, not "OR"
```
<?php if (!is_page('about-us') && !is_page('news-articles')) {wp_head();}?>
```
Because you want to display the WP head only if both conditions are true. |
50,360 | <p>I need some help regarding Custom Query by keyword.</p>
<p>I send a keyword to my page where I would like to list those posts which post_title contains the keyword I sent.</p>
<p>Here comes my query as follows:</p>
<pre><code>$q = 'SELECT guid, post_content, post_title, post_parent, post_type FROM wp_posts WHERE ... | [
{
"answer_id": 50354,
"author": "cpilko",
"author_id": 7937,
"author_profile": "https://wordpress.stackexchange.com/users/7937",
"pm_score": 2,
"selected": false,
"text": "<p>Take a look at /plugins/wpbook/includes/publish_to_facebook.php.</p>\n\n<p>They only have one function that posts... | 2012/04/26 | [
"https://wordpress.stackexchange.com/questions/50360",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15581/"
] | I need some help regarding Custom Query by keyword.
I send a keyword to my page where I would like to list those posts which post\_title contains the keyword I sent.
Here comes my query as follows:
```
$q = 'SELECT guid, post_content, post_title, post_parent, post_type FROM wp_posts WHERE (post_title REGEXP '".$keyw... | Take a look at /plugins/wpbook/includes/publish\_to\_facebook.php.
They only have one function that posts to FB. You should be able to cobble something together from their code.
Just make sure if you write your own files to them in a separate folder in your plugins directory. Otherwise any updates to WPBook will over... |
50,372 | <p>Ok, I installed the Custom Post Type UI plugin and create one. I then added a new post to it. In my theme, i have a piece of code like this:</p>
<pre><code><?php
$loop = new WP_Query( array(
'post_type' => 'case studies', /* edit this line */
'posts_per_page' => 15 ) );
?>
<?... | [
{
"answer_id": 50375,
"author": "Starfs",
"author_id": 15259,
"author_profile": "https://wordpress.stackexchange.com/users/15259",
"pm_score": 0,
"selected": false,
"text": "<p>You could just write this into your single.php file (within the loop) and echo out whatever fields you need wit... | 2012/04/26 | [
"https://wordpress.stackexchange.com/questions/50372",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/2496/"
] | Ok, I installed the Custom Post Type UI plugin and create one. I then added a new post to it. In my theme, i have a piece of code like this:
```
<?php
$loop = new WP_Query( array(
'post_type' => 'case studies', /* edit this line */
'posts_per_page' => 15 ) );
?>
<?php while ( $loop->have_posts... | Use `single-{posttype}.php` for the single template. Also, if you register your post type with the `has_archive` argument set to `true`, then you can use `archive-{posttype}.php` for your archive template, which will allow you to skip that query that you have there, since the global `$wp_query` object will already be p... |
50,404 | <p>Is it possible to only show posts that have todays date or in the future? I don't want to show any posts that are in the past. </p>
<p>Also, I want the list to show posts that have a date in the future as in the CMS it shows as scheduled.</p>
<p>Here's my loop:</p>
<pre><code><div class="news-content" style="b... | [
{
"answer_id": 50411,
"author": "Thomas ",
"author_id": 15561,
"author_profile": "https://wordpress.stackexchange.com/users/15561",
"pm_score": 0,
"selected": false,
"text": "<p>As described <a href=\"http://codex.wordpress.org/Class_Reference/WP_Query#Time_Parameters\" rel=\"nofollow\">... | 2012/04/27 | [
"https://wordpress.stackexchange.com/questions/50404",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4588/"
] | Is it possible to only show posts that have todays date or in the future? I don't want to show any posts that are in the past.
Also, I want the list to show posts that have a date in the future as in the CMS it shows as scheduled.
Here's my loop:
```
<div class="news-content" style="background-color:#feefe7!IMPORTA... | Can't believe I didn't see this sooner, simply solved it with this in the query:
`'post_status' => 'future'`
So once published it just disappears from the list. |
50,413 | <p>I know it's probably not encouraged, but is there a way to replace the standard dashboard widgets (Recent Drafts, Quickpress, etc.) with a standard image banner ad?</p>
<p>I know how to add new dashboard widgets, but I want this to be a plain image with no surrounding widget.</p>
| [
{
"answer_id": 50417,
"author": "Mohit Bumb",
"author_id": 8184,
"author_profile": "https://wordpress.stackexchange.com/users/8184",
"pm_score": 3,
"selected": true,
"text": "<p>Check this reference </p>\n\n<p><a href=\"http://www.wpbeginner.com/wp-themes/how-to-add-custom-dashboard-widg... | 2012/04/27 | [
"https://wordpress.stackexchange.com/questions/50413",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15535/"
] | I know it's probably not encouraged, but is there a way to replace the standard dashboard widgets (Recent Drafts, Quickpress, etc.) with a standard image banner ad?
I know how to add new dashboard widgets, but I want this to be a plain image with no surrounding widget. | Check this reference
<http://www.wpbeginner.com/wp-themes/how-to-add-custom-dashboard-widgets-in-wordpress/>
for adding dashboard widget
[Remove Widgets in Dashboard](https://wordpress.stackexchange.com/questions/47707/remove-widgets-in-dashboard)
for removing dashboard widget
```
add_action('wp_dashboard_setup',... |