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 |
|---|---|---|---|---|---|---|
154,960 | <p>I've currently got this:</p>
<pre><code>$num = 1;
while($num < 6) {
register_setting( 'front_page_options', 'slide_title_'.$num );
register_setting( 'front_page_options', 'slide_description_'.$num );
register_setting( 'front_page_options', 'slide_button_1_text_'.$num );
register_setting( 'front_page_op... | [
{
"answer_id": 154952,
"author": "sabarnix",
"author_id": 56542,
"author_profile": "https://wordpress.stackexchange.com/users/56542",
"pm_score": 2,
"selected": true,
"text": "<p>Do this on template_redirect hook. You can use wp_safe_redirect to redirect to different page in the blog. I ... | 2014/07/17 | [
"https://wordpress.stackexchange.com/questions/154960",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/52645/"
] | I've currently got this:
```
$num = 1;
while($num < 6) {
register_setting( 'front_page_options', 'slide_title_'.$num );
register_setting( 'front_page_options', 'slide_description_'.$num );
register_setting( 'front_page_options', 'slide_button_1_text_'.$num );
register_setting( 'front_page_options', 'slide_bu... | Do this on template\_redirect hook. You can use wp\_safe\_redirect to redirect to different page in the blog. I can't give you the code because I don't from where you are getting the $user |
154,963 | <p>I'm trying to get the post title of a post_type (post/page/portfolio) in the admin panel outside of the loop.</p>
<p>I nearly tried all possible solutions, but without success:</p>
<pre><code>//method 1
$content_post = get_post(3208);
$_menu_item_title = $content_post->post_title; //(Trying to get property of n... | [
{
"answer_id": 154977,
"author": "stoopkid1",
"author_id": 55193,
"author_profile": "https://wordpress.stackexchange.com/users/55193",
"pm_score": 1,
"selected": false,
"text": "<p>As already been pointed out, the \"non-object error\" means get_post() returned nothing, and that the post ... | 2014/07/17 | [
"https://wordpress.stackexchange.com/questions/154963",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/44401/"
] | I'm trying to get the post title of a post\_type (post/page/portfolio) in the admin panel outside of the loop.
I nearly tried all possible solutions, but without success:
```
//method 1
$content_post = get_post(3208);
$_menu_item_title = $content_post->post_title; //(Trying to get property of non-object error)
//met... | If you have only ID of a post and you want only the title of that post, then using [`get_post_field`](https://codex.wordpress.org/Function_Reference/get_post_field) will be best way to do this, I guess.
The syntax of this function:
```
get_post_field( $field, $post_id, $context );
```
So code, that will solve your ... |
154,984 | <p>With enqueue you would change <code>$deps</code> to your script or array of scripts that are needed to run first for your script to work. </p>
<pre><code><?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?>
</code></pre>
<p>For example:</p>
<pre><code>function script_that_requires_jquery() ... | [
{
"answer_id": 154995,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 3,
"selected": false,
"text": "<pre><code>function script_that_requires_jquery() {\n wp_register_script( 'script-with-dependency', 'ht... | 2014/07/18 | [
"https://wordpress.stackexchange.com/questions/154984",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/38123/"
] | With enqueue you would change `$deps` to your script or array of scripts that are needed to run first for your script to work.
```
<?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?>
```
For example:
```
function script_that_requires_jquery() {
wp_register_script( 'script-with-dependency', 'h... | ```
function script_that_requires_jquery() {
wp_register_script( 'script-with-dependency', 'http://www.example.com/script-with-dependency.js', array( 'jquery' ), '1.0.0', true );
wp_enqueue_script( 'script-with-dependency' );
}
add_action( 'wp_enqueue_scripts', 'script_that_requires_jquery' );
```
This is the... |
155,008 | <p>I'm using the Option-Tree framework for the options of my theme. Now I want to add the option to create and edit the robots.txt file. First, I have the function to get the content of the file or create it with a default content; is this:</p>
<pre><code>function get_robots($path)
{
$robots_file = $path . DIRECTORY_S... | [
{
"answer_id": 155013,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 0,
"selected": false,
"text": "<p>Question has too much detail. It doesn't matter what you want to do, if you want to run code only \"once\... | 2014/07/18 | [
"https://wordpress.stackexchange.com/questions/155008",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/37313/"
] | I'm using the Option-Tree framework for the options of my theme. Now I want to add the option to create and edit the robots.txt file. First, I have the function to get the content of the file or create it with a default content; is this:
```
function get_robots($path)
{
$robots_file = $path . DIRECTORY_SEPARATOR . 'ro... | You are underestimating the complexity of robots file handling in WordPress. The presence of physical file is one of two cases.
If physical file is not present during template load [`is_robots()`](http://queryposts.com/function/is_robots/) checks is performed and in positive case [`do_robots()`](http://queryposts.com... |
155,014 | <p>I need to so some stuff only when specific templates (homepages) are used, I couldn't think of any better solution than this since is_page_template() do not handle arrays:</p>
<pre><code> $home_1 = is_page_template('home-1.php');
$home_2 = is_page_template('home-2.php');
$home_3 = is_page_tem... | [
{
"answer_id": 155017,
"author": "Rajeev Vyas",
"author_id": 6961,
"author_profile": "https://wordpress.stackexchange.com/users/6961",
"pm_score": 2,
"selected": false,
"text": "<p>Check out this <a href=\"http://codex.wordpress.org/Function_Reference/is_page_template#Alternative\" rel=\... | 2014/07/18 | [
"https://wordpress.stackexchange.com/questions/155014",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/26310/"
] | I need to so some stuff only when specific templates (homepages) are used, I couldn't think of any better solution than this since is\_page\_template() do not handle arrays:
```
$home_1 = is_page_template('home-1.php');
$home_2 = is_page_template('home-2.php');
$home_3 = is_page_template('home-... | Check out this [Alternative](http://codex.wordpress.org/Function_Reference/is_page_template#Alternative)
```
<?php
// in the loop:
$template = get_page_template_slug( get_the_ID() );
if (in_array($template,array('home1','home2')) ) ){
// Yep, Do your stuff
}
// anywhere:
$template = get_page_templat... |
155,072 | <p>I've been using <code>get_theme_mod()</code> for some time in various projects of mine. I decided to take advantage of the Theme Customization API in WordPress v3.4 once it was available as I felt it was an indispensable tool for my clients to use.</p>
<p>After some time, I began to notice that my sites were feelin... | [
{
"answer_id": 155168,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 2,
"selected": false,
"text": "<p><code>get_theme_mod</code> is just a wrapper around <code>get_option</code>. In theory because it is anot... | 2014/07/18 | [
"https://wordpress.stackexchange.com/questions/155072",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56794/"
] | I've been using `get_theme_mod()` for some time in various projects of mine. I decided to take advantage of the Theme Customization API in WordPress v3.4 once it was available as I felt it was an indispensable tool for my clients to use.
After some time, I began to notice that my sites were feeling a little more slugg... | The answer that yes, the theme\_mod functions will be slower, but not significantly, and the benefits outweigh the differences.
Theme mods are stored as options. So, in essence, the theme\_mod functions are wrappers around the options functions.
First, understand that theme\_mod settings are stored as an array in a s... |
155,075 | <p>I have a query that displays the names of donors as well as a dedication. It displays using a date meta query.</p>
<pre><code>$args = array(
'post_type' => 'donors',
'order_by' => 'id',
'order' => 'DESC',
'posts_per_page' => -1,
'date_query' => array(
array(
'after' => $... | [
{
"answer_id": 155098,
"author": "nishant",
"author_id": 56807,
"author_profile": "https://wordpress.stackexchange.com/users/56807",
"pm_score": -1,
"selected": false,
"text": "<p>Please try with <code>wp_reset_query();</code> after your query.<br>\nlike: </p>\n\n<pre><code> $query = ne... | 2014/07/18 | [
"https://wordpress.stackexchange.com/questions/155075",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56798/"
] | I have a query that displays the names of donors as well as a dedication. It displays using a date meta query.
```
$args = array(
'post_type' => 'donors',
'order_by' => 'id',
'order' => 'DESC',
'posts_per_page' => -1,
'date_query' => array(
array(
'after' => $from,
'before' => $to
... | Try to add
```
'post_type' => 'any',
'post_stauts' => 'any',
```
to your arguments and see what happens. This should retrieve posts in all post types with any post status. If it only retrieves 252 posts, then the other posts doesn't not meet your criteria in your query.
The other important thing is that with suc... |
155,080 | <p>I need some help. I would like to make a custom taxonomy archive that shows a grid of the terms(categories) in the taxonomy. I know how to accomplish the grid portion, but I'm having trouble with the main function of displaying the terms. I feel like I've seen this done so many times, but not that I'm trying to acco... | [
{
"answer_id": 155098,
"author": "nishant",
"author_id": 56807,
"author_profile": "https://wordpress.stackexchange.com/users/56807",
"pm_score": -1,
"selected": false,
"text": "<p>Please try with <code>wp_reset_query();</code> after your query.<br>\nlike: </p>\n\n<pre><code> $query = ne... | 2014/07/18 | [
"https://wordpress.stackexchange.com/questions/155080",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/37657/"
] | I need some help. I would like to make a custom taxonomy archive that shows a grid of the terms(categories) in the taxonomy. I know how to accomplish the grid portion, but I'm having trouble with the main function of displaying the terms. I feel like I've seen this done so many times, but not that I'm trying to accompl... | Try to add
```
'post_type' => 'any',
'post_stauts' => 'any',
```
to your arguments and see what happens. This should retrieve posts in all post types with any post status. If it only retrieves 252 posts, then the other posts doesn't not meet your criteria in your query.
The other important thing is that with suc... |
155,090 | <p>I am very new to ajax with wordpress . Here i am getting a selected option value in <code>var test</code> using bellow function when i alert it its showing a right value. </p>
<p>This <code>var test</code> value i have to send using ajax and i want GET this value in PHP variable.</p>
<p>So what i required to call ... | [
{
"answer_id": 155091,
"author": "TBI Infotech",
"author_id": 52417,
"author_profile": "https://wordpress.stackexchange.com/users/52417",
"pm_score": 1,
"selected": false,
"text": "<p>Use the built-in wordpress Ajax actions:</p>\n\n<p>Your jquery will look like this:</p>\n\n<pre><code>$(... | 2014/07/19 | [
"https://wordpress.stackexchange.com/questions/155090",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/39122/"
] | I am very new to ajax with wordpress . Here i am getting a selected option value in `var test` using bellow function when i alert it its showing a right value.
This `var test` value i have to send using ajax and i want GET this value in PHP variable.
So what i required to call ajax and get script variable value of `... | I have call ajax using bellow code its working good.
Here i am sending the `variable time` to this page using post `$.post("'. plugins_url().'/woocommerce-booking/gettime.php",`
```
var time=0;
jQuery("#time_slot").change(function()
{
time=time_slot.va... |
155,162 | <p>I have the following</p>
<pre><code>GrandParent
-Parent01
--Child
-Parent02
--Child
--Child
-Parent03
--Child
</code></pre>
<p>I wish to find a solution that when Im on the Grandparent page, that it will only return the parents and not the children IE.</p>
<pre><code>GrandParent
-Parent01
-Parent02
-Parent03
</co... | [
{
"answer_id": 155165,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 1,
"selected": false,
"text": "<p>You're using <code>get_children</code> and it's doing exactly what you told it to do. You told it to get all... | 2014/07/19 | [
"https://wordpress.stackexchange.com/questions/155162",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/50822/"
] | I have the following
```
GrandParent
-Parent01
--Child
-Parent02
--Child
--Child
-Parent03
--Child
```
I wish to find a solution that when Im on the Grandparent page, that it will only return the parents and not the children IE.
```
GrandParent
-Parent01
-Parent02
-Parent03
```
This is the code I have at present,... | [This answer](https://stackoverflow.com/a/24847487/1908141) on Stack overflow fixed it for me ... by adding in these lines ..
```
<?php foreach ( $pages as $page ): ?>
<?php if ( $postid != $page->post_parent ) continue; ?>
``` |
155,177 | <p>I dont want to have dropdown (select - options) in my wordpress menu, even in mobile or lower width devices. I know I can use css to hide it, but I want to remove it at all. I googled for an hour and I found that I should use a custom walker on Roots!!!! but I dont know whats that and how. please help me, I am a new... | [
{
"answer_id": 155277,
"author": "bravokeyl",
"author_id": 43098,
"author_profile": "https://wordpress.stackexchange.com/users/43098",
"pm_score": 2,
"selected": false,
"text": "<p>We can use depth parameter of <a href=\"https://developer.wordpress.org/reference/functions/wp_nav_menu/\" ... | 2014/07/20 | [
"https://wordpress.stackexchange.com/questions/155177",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/52225/"
] | I dont want to have dropdown (select - options) in my wordpress menu, even in mobile or lower width devices. I know I can use css to hide it, but I want to remove it at all. I googled for an hour and I found that I should use a custom walker on Roots!!!! but I dont know whats that and how. please help me, I am a newby. | We can use depth parameter of [`wp_nav_menu`](https://developer.wordpress.org/reference/functions/wp_nav_menu/) to set how many levels menu walker traverses.
```
wp_nav_menu( array( 'menu_id'=>'nav', 'theme_location'=>'header-menu' , 'depth' => 1) );
```
You can create a child theme so that updates won't override du... |
155,188 | <p>I want to insert a TIMESTAMP into my column's TIMESTAMP column, but I always get all zeros.</p>
<p>Here is my insert:</p>
<pre><code>$now = 'NOW()';
// insert the date into the db
$wpdb->insert(
'wp_date',
array(
'name' => $name,
'date' => $now
),
array(
'... | [
{
"answer_id": 155189,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 3,
"selected": true,
"text": "<p>I hadn't tried to reproduce it, but the likely reason is that what you <em>want</em> to use in query is SQL function... | 2014/07/20 | [
"https://wordpress.stackexchange.com/questions/155188",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/37281/"
] | I want to insert a TIMESTAMP into my column's TIMESTAMP column, but I always get all zeros.
Here is my insert:
```
$now = 'NOW()';
// insert the date into the db
$wpdb->insert(
'wp_date',
array(
'name' => $name,
'date' => $now
),
array(
'%s',
'%s'
)
); //... | I hadn't tried to reproduce it, but the likely reason is that what you *want* to use in query is SQL function (`NOW()`) but what you *"tell"* WordPress to use is a string.
Declaring its format to be `%s` means it is sanitized and put in quotes, making it something like `'NOW()'` which MySQL probably sees as very inval... |
155,202 | <p>I have a custom Wordpress theme that includes a members only section. In order to implement this, I have the following code at the top of my restricted pages.</p>
<pre><code><?php if ( ! current_user_can ('view_players_area') ) { header('Location: ' . wp_login_url( "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI... | [
{
"answer_id": 155204,
"author": "MaximOrlovsky",
"author_id": 15294,
"author_profile": "https://wordpress.stackexchange.com/users/15294",
"pm_score": 1,
"selected": false,
"text": "<p>Put this on the top of the file with your code:</p>\n\n<pre><code>global $current_user;\nif ( !$current... | 2014/07/20 | [
"https://wordpress.stackexchange.com/questions/155202",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/44235/"
] | I have a custom Wordpress theme that includes a members only section. In order to implement this, I have the following code at the top of my restricted pages.
```
<?php if ( ! current_user_can ('view_players_area') ) { header('Location: ' . wp_login_url( "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ) ); } ?>
```... | Do not set `header` in a template file. Those are part of the HTTP request itself.
About your problem:
Add a template (whatever file you need - see "Template Hierarchy"). On top of it you include the default stuff like `get_header();` and so on. For the restricted part, you use the following:
```
if ( current_user_c... |
155,205 | <p>I try to remove a nav menu programmatically but I didn't find the way to do it. I knwo how to create it but I don't know how to delete it...
I've got the menu name and I wan't to delete it like in wp admin panel but programmatically.</p>
<p>Or I want to delete all the menu item inside it.</p>
| [
{
"answer_id": 155441,
"author": "lolo",
"author_id": 44401,
"author_profile": "https://wordpress.stackexchange.com/users/44401",
"pm_score": 3,
"selected": false,
"text": "<p>Finally the answer is simple:</p>\n\n<pre><code>$menu_name = 'your menu';//name,id,slug\nwp_delete_nav_menu($m... | 2014/07/20 | [
"https://wordpress.stackexchange.com/questions/155205",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/44401/"
] | I try to remove a nav menu programmatically but I didn't find the way to do it. I knwo how to create it but I don't know how to delete it...
I've got the menu name and I wan't to delete it like in wp admin panel but programmatically.
Or I want to delete all the menu item inside it. | Finally the answer is simple:
```
$menu_name = 'your menu';//name,id,slug
wp_delete_nav_menu($menu_name);
``` |
155,206 | <p>By default, the <em>WordPress</em> tag cloud widget has a set amount of 45 tags to display. This can be seen in the <code>wp-includes/category-template.php</code> file.</p>
<p>By default, the <em>WooCommerce</em> plugin which I have installed, and it's products tag cloud widget also resembles this.</p>
<p>How do ... | [
{
"answer_id": 155207,
"author": "Gabriel",
"author_id": 54569,
"author_profile": "https://wordpress.stackexchange.com/users/54569",
"pm_score": 4,
"selected": true,
"text": "<p>Add the following to your theme's function.php. Default values are shown below, except changing 'number' from ... | 2014/07/20 | [
"https://wordpress.stackexchange.com/questions/155206",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/28275/"
] | By default, the *WordPress* tag cloud widget has a set amount of 45 tags to display. This can be seen in the `wp-includes/category-template.php` file.
By default, the *WooCommerce* plugin which I have installed, and it's products tag cloud widget also resembles this.
How do I modify this amount from within my `wp-con... | Add the following to your theme's function.php. Default values are shown below, except changing 'number' from 45 to 15. Only the changed values need to be included, so you can either leave the default values or remove/comment out those lines.
For Wordpress Tag Cloud widget:
```
function custom_tag_cloud_widget() {
... |
155,208 | <p>I have the following loop working as I want it but I need the 'activists' list item to include <code><?php the_post_thumbnail(); ?></code>.</p>
<p>What would be the best way to write this?</p>
<pre><code><?php
$terms = array('news', 'activists', 'resources', 'posts' );
if ( !empty( $term... | [
{
"answer_id": 155209,
"author": "OmAk",
"author_id": 70700,
"author_profile": "https://wordpress.stackexchange.com/users/70700",
"pm_score": 0,
"selected": false,
"text": "<p>You can use this: </p>\n\n<pre><code><a href=\"<?php the_permalink(); ?>\" title=\"<?php echo the_ti... | 2014/07/20 | [
"https://wordpress.stackexchange.com/questions/155208",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56850/"
] | I have the following loop working as I want it but I need the 'activists' list item to include `<?php the_post_thumbnail(); ?>`.
What would be the best way to write this?
```
<?php
$terms = array('news', 'activists', 'resources', 'posts' );
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
... | You can make use of [`get_post_type( $post )`](http://codex.wordpress.org/Function_Reference/get_post_type) to check whether a post belongs to a certain post type
Inside your loop, you can do the following check
```
while ($my_query->have_posts()) : $my_query->the_post();
if ( 'activists' == get_post_type() ) {
... |
155,220 | <p>I today install on wordpress new responsive theme ''Twenty Fourteen'',
I try to edit css, try to change bg color of header menu,
I can't found in css where i change bg color,
I before do this a million times on old not responsive css, how i edit responsive css ?</p>
<p>Thanks.</p>
| [
{
"answer_id": 155209,
"author": "OmAk",
"author_id": 70700,
"author_profile": "https://wordpress.stackexchange.com/users/70700",
"pm_score": 0,
"selected": false,
"text": "<p>You can use this: </p>\n\n<pre><code><a href=\"<?php the_permalink(); ?>\" title=\"<?php echo the_ti... | 2014/07/20 | [
"https://wordpress.stackexchange.com/questions/155220",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/38090/"
] | I today install on wordpress new responsive theme ''Twenty Fourteen'',
I try to edit css, try to change bg color of header menu,
I can't found in css where i change bg color,
I before do this a million times on old not responsive css, how i edit responsive css ?
Thanks. | You can make use of [`get_post_type( $post )`](http://codex.wordpress.org/Function_Reference/get_post_type) to check whether a post belongs to a certain post type
Inside your loop, you can do the following check
```
while ($my_query->have_posts()) : $my_query->the_post();
if ( 'activists' == get_post_type() ) {
... |
155,226 | <p>I have a form on my site.</p>
<p>This the user register one missing person.
I created a custom post type missing person, custom taxonomies, and custom fields.
All this input's save as well in wp.</p>
<p>But I don't know submit an image and save this image as featured image.</p>
<pre><code>$my_post = array(
... | [
{
"answer_id": 155238,
"author": "Bindiya Patoliya",
"author_id": 34932,
"author_profile": "https://wordpress.stackexchange.com/users/34932",
"pm_score": 0,
"selected": false,
"text": "<p>You can try this way :</p>\n\n<pre><code>set_post_thumbnail( $my_post_id, $thumbnail_id );\n</code><... | 2014/07/21 | [
"https://wordpress.stackexchange.com/questions/155226",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56861/"
] | I have a form on my site.
This the user register one missing person.
I created a custom post type missing person, custom taxonomies, and custom fields.
All this input's save as well in wp.
But I don't know submit an image and save this image as featured image.
```
$my_post = array(
'post_title' => $... | sorry this isn't an answer but you need to sanitize that user input. Your allowing tags to be written directly into your post content which allows anyone to run javascript in both wp admin and on the front end of your site (assuming you'll eventually print these posts). highly recommend (at minimum) strip\_tags() or ht... |
155,252 | <p>I want to create a tag archive page (or template) specific for some custom post type(CPT).</p>
<p>I am little new to PHP and Wordpress, by the way.</p>
<p>In my environment, I have CPT <code>portfolio</code> and custom taxonomy <code>portfolio_category</code>.</p>
<p>I could make default tag archive page using th... | [
{
"answer_id": 155259,
"author": "cybmeta",
"author_id": 37428,
"author_profile": "https://wordpress.stackexchange.com/users/37428",
"pm_score": 3,
"selected": true,
"text": "<p>If I understood correctly, you want a archive template for terms of core tag taxonomy that includes only your ... | 2014/07/21 | [
"https://wordpress.stackexchange.com/questions/155252",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/37130/"
] | I want to create a tag archive page (or template) specific for some custom post type(CPT).
I am little new to PHP and Wordpress, by the way.
In my environment, I have CPT `portfolio` and custom taxonomy `portfolio_category`.
I could make default tag archive page using the template `tag.php` that shows posts with spe... | If I understood correctly, you want a archive template for terms of core tag taxonomy that includes only your `portfolio` custom post type. The best way is to use the `pre_get_posts` action hook to set `post_type` argument of the query to `'portfolio'`:
```
add_action('pre_get_posts', 'query_post_type');
function quer... |
155,257 | <p>On my news website I have posts and another custom type called "aggregato". This type has 10 custom fields, "link01", "link02"... "link10".</p>
<p>Both posts and aggregato has a meta key, called "home", that is used to say WP to put the post on front page.</p>
<p>I want to make a query for the front page that load... | [
{
"answer_id": 155268,
"author": "bravokeyl",
"author_id": 43098,
"author_profile": "https://wordpress.stackexchange.com/users/43098",
"pm_score": 0,
"selected": false,
"text": "<pre><code>$exclude_posts = array();//array of id's that are in aggregato custom fields\n$query = new WP_Query... | 2014/07/21 | [
"https://wordpress.stackexchange.com/questions/155257",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/55133/"
] | On my news website I have posts and another custom type called "aggregato". This type has 10 custom fields, "link01", "link02"... "link10".
Both posts and aggregato has a meta key, called "home", that is used to say WP to put the post on front page.
I want to make a query for the front page that loads the 12 latest p... | First off: You *theoretically can* query the WordPress database with raw MySQL, of course.
See `wpdb`'s [`get_results`](https://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results) method.
That might save you a second query, but obviously will not return proper `WP_Post` objects.
That being said, nope, ... |
155,267 | <p>I'm looking to do a redirect based on browser, but only for a specific page (or 2). I'd like to send the user to an alternative page if the browser is IE7 or less. The alt page will have completely different setup and everything to work for their old crap.</p>
<p>I can't find a plugin. I'm looking at doing a php in... | [
{
"answer_id": 155270,
"author": "Domain",
"author_id": 26523,
"author_profile": "https://wordpress.stackexchange.com/users/26523",
"pm_score": 1,
"selected": false,
"text": "<p>If you want to detect only IE specific browsers, then following code help you. You need to replace the comment... | 2014/07/21 | [
"https://wordpress.stackexchange.com/questions/155267",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56883/"
] | I'm looking to do a redirect based on browser, but only for a specific page (or 2). I'd like to send the user to an alternative page if the browser is IE7 or less. The alt page will have completely different setup and everything to work for their old crap.
I can't find a plugin. I'm looking at doing a php inject plugi... | If you want to detect only IE specific browsers, then following code help you. You need to replace the comments with the redirection code
```
function browser_detection_redirect(){
preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
if (count($matches)>1){
//Then we're using IE
$version = $matches... |
155,272 | <p>The title might be a bit vague while I'm not quite sure how to describe it. </p>
<p><strong>What I want:</strong></p>
<p>At every single post (in this case of post type 'event') a logged in user must be able to click a 'Join' button (and when clicked a 'Unjoin' button).
The admin must be able to see which users h... | [
{
"answer_id": 155270,
"author": "Domain",
"author_id": 26523,
"author_profile": "https://wordpress.stackexchange.com/users/26523",
"pm_score": 1,
"selected": false,
"text": "<p>If you want to detect only IE specific browsers, then following code help you. You need to replace the comment... | 2014/07/21 | [
"https://wordpress.stackexchange.com/questions/155272",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/37104/"
] | The title might be a bit vague while I'm not quite sure how to describe it.
**What I want:**
At every single post (in this case of post type 'event') a logged in user must be able to click a 'Join' button (and when clicked a 'Unjoin' button).
The admin must be able to see which users have joined an event and which ... | If you want to detect only IE specific browsers, then following code help you. You need to replace the comments with the redirection code
```
function browser_detection_redirect(){
preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
if (count($matches)>1){
//Then we're using IE
$version = $matches... |
155,282 | <p>I have a blog which runs on Wordpress and inside the Wordpress environment I'm fine and know how to display specific blogposts etc.</p>
<p>But beside I want to insert specific Blog-posts in a static HTML Website which doesn't have a CMS and is standalone.
Imagine the simplest case of </p>
<pre><code><body>
... | [
{
"answer_id": 155287,
"author": "Laxmana",
"author_id": 40948,
"author_profile": "https://wordpress.stackexchange.com/users/40948",
"pm_score": 1,
"selected": false,
"text": "<p>You can use <strong>XML-RPC</strong> which is supported by Wordpress.</p>\n\n<p>You can use RSS if you just w... | 2014/07/21 | [
"https://wordpress.stackexchange.com/questions/155282",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/49869/"
] | I have a blog which runs on Wordpress and inside the Wordpress environment I'm fine and know how to display specific blogposts etc.
But beside I want to insert specific Blog-posts in a static HTML Website which doesn't have a CMS and is standalone.
Imagine the simplest case of
```
<body>
<p class="blogpost"> <!-- i... | You can try using the [JSON API](https://wordpress.org/plugins/json-api/) plugin.
It has endpoints for latest posts etc that can be accessed via jQuery, I use it to power mobile apps that use WordPress for content management. You also have the ability to create your own endpoints if the defaults don't give you what yo... |
155,290 | <p>I'm working with a handy responsive theme framework (Reverie) and I'm developing my own theme the right way using a Child theme. The Parent theme calls a sidebar called with an ID of 'Footer' and applies some basic styles to it. I want to adjust this in my child theme, so I was looking at perhaps filtering it but in... | [
{
"answer_id": 155296,
"author": "HU is Sebastian",
"author_id": 56587,
"author_profile": "https://wordpress.stackexchange.com/users/56587",
"pm_score": 2,
"selected": false,
"text": "<p>It should be possible to use the after_setup_theme hook to unregister the sidebar you don't want like... | 2014/07/21 | [
"https://wordpress.stackexchange.com/questions/155290",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/30653/"
] | I'm working with a handy responsive theme framework (Reverie) and I'm developing my own theme the right way using a Child theme. The Parent theme calls a sidebar called with an ID of 'Footer' and applies some basic styles to it. I want to adjust this in my child theme, so I was looking at perhaps filtering it but in th... | Thanks for your help fellas! The after\_setup\_theme() function was a new one for me which is probably going to be very helpful down the line. Unfortunately my error was something simpler. When I called the unregister\_sidebar function..
```
add_action ('widgets_init, remove_footer', 11);
```
I was missing the prope... |
155,291 | <p>I have a theme that is being used for a multisite installation that will be used by 6 sub-brands of an organization. Each sub-brand will only require some of the custom post types set up by the theme – thus I would like to hide the ones not needed.</p>
<p>The theme has an options page where I can set a variable to ... | [
{
"answer_id": 155296,
"author": "HU is Sebastian",
"author_id": 56587,
"author_profile": "https://wordpress.stackexchange.com/users/56587",
"pm_score": 2,
"selected": false,
"text": "<p>It should be possible to use the after_setup_theme hook to unregister the sidebar you don't want like... | 2014/07/21 | [
"https://wordpress.stackexchange.com/questions/155291",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56891/"
] | I have a theme that is being used for a multisite installation that will be used by 6 sub-brands of an organization. Each sub-brand will only require some of the custom post types set up by the theme – thus I would like to hide the ones not needed.
The theme has an options page where I can set a variable to state whic... | Thanks for your help fellas! The after\_setup\_theme() function was a new one for me which is probably going to be very helpful down the line. Unfortunately my error was something simpler. When I called the unregister\_sidebar function..
```
add_action ('widgets_init, remove_footer', 11);
```
I was missing the prope... |
155,303 | <p>I'm writing a plugin but have a problem.</p>
<p>I wanted to make an upload form for my existing plugin, so I don't need to upload every picture with the Media Uploader and Copy&Paste the URL in the form.</p>
<p>I used this tutorial: <a href="http://www.webmaster-source.com/2013/02/06/using-the-wordpress-3-5-me... | [
{
"answer_id": 155307,
"author": "Welcher",
"author_id": 27210,
"author_profile": "https://wordpress.stackexchange.com/users/27210",
"pm_score": 1,
"selected": false,
"text": "<p>It's probably due to an unclosed curly brace somewhere. Can include more code? The line numbers in the error ... | 2014/07/21 | [
"https://wordpress.stackexchange.com/questions/155303",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56898/"
] | I'm writing a plugin but have a problem.
I wanted to make an upload form for my existing plugin, so I don't need to upload every picture with the Media Uploader and Copy&Paste the URL in the form.
I used this tutorial: [Tutorial](http://www.webmaster-source.com/2013/02/06/using-the-wordpress-3-5-media-uploader-in-you... | It's probably due to an unclosed curly brace somewhere. Can include more code? The line numbers in the error message are not always where the actual issue is. |
155,331 | <p>Is there a way to filter single.php so that if someone came from search.php it would display one thing, but if they came from anywhere else it would display another?</p>
<p>Thanks,
Josh</p>
| [
{
"answer_id": 155337,
"author": "karpstrucking",
"author_id": 55214,
"author_profile": "https://wordpress.stackexchange.com/users/55214",
"pm_score": 1,
"selected": false,
"text": "<p>You could hook into the <code>the_permalink</code> filter and check for <code>is_search()</code> to con... | 2014/07/21 | [
"https://wordpress.stackexchange.com/questions/155331",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9820/"
] | Is there a way to filter single.php so that if someone came from search.php it would display one thing, but if they came from anywhere else it would display another?
Thanks,
Josh | I created an `if` statement to solve my problem:
```
<?
if (stripos(wp_get_referer(), "cat=")!==false) {
echo "Came from Search";
} else {
echo "Didn't come from Search";
}
?>
```
I am doing a category search, so I check to see if cat= is in the referrer url (or search url), if it is I ex... |
155,332 | <p>In a site I'm developing, I have the following category structure:</p>
<pre><code>* movies (parent)
* thriller (child)
* comedy (child)
* drama (child)
</code></pre>
<p>The current post is in the <strong>comedy</strong> category. The <strong>has_term</strong> function with the following parameters retu... | [
{
"answer_id": 155335,
"author": "Gabriel",
"author_id": 54569,
"author_profile": "https://wordpress.stackexchange.com/users/54569",
"pm_score": 5,
"selected": true,
"text": "<p>Add the following to your theme's functions.php:</p>\n\n<pre><code>/**\n * Tests if any of a post's assigned c... | 2014/07/21 | [
"https://wordpress.stackexchange.com/questions/155332",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/33049/"
] | In a site I'm developing, I have the following category structure:
```
* movies (parent)
* thriller (child)
* comedy (child)
* drama (child)
```
The current post is in the **comedy** category. The **has\_term** function with the following parameters returns true:
```
has_term( 'comedy', 'category' )
``... | Add the following to your theme's functions.php:
```
/**
* Tests if any of a post's assigned categories are descendants of target categories
*
* @param int|array $cats The target categories. Integer ID or array of integer IDs
* @param int|object $_post The post. Omit to test the current post in the Loop or main qu... |
155,367 | <p>I would like to query most of my pages and categories on the homepage. So far I am able to get the pages and category (posts), but I cannot order the list the way I want to. I want to be able to get a custom order like page, posts from a category, another page, and posts from another category.</p>
<p>I am using the... | [
{
"answer_id": 156929,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 1,
"selected": false,
"text": "<p>wordpress sucks in keeping media<=>content relationships. Part of the problem is that by default all m... | 2014/07/22 | [
"https://wordpress.stackexchange.com/questions/155367",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3327/"
] | I would like to query most of my pages and categories on the homepage. So far I am able to get the pages and category (posts), but I cannot order the list the way I want to. I want to be able to get a custom order like page, posts from a category, another page, and posts from another category.
I am using the following... | wordpress sucks in keeping media<=>content relationships. Part of the problem is that by default all media are public once they are uploaded and you have no way to know where are they are being used. Just because an image is not referenced anymore in its original post doesn't mean that it is not referenced at any other... |
155,409 | <p>Currently my website archive page is showing 5 post per page. I need to set it to 100 post per page.</p>
<p>(My home page showing 5 post per page and I don't want change it)</p>
<p>Here is my archive.php </p>
<pre><code> <?php get_header(); ?>
<?php do_atomic( 'before_content' ); // my-life_before... | [
{
"answer_id": 155421,
"author": "Brad Dalton",
"author_id": 9884,
"author_profile": "https://wordpress.stackexchange.com/users/9884",
"pm_score": 5,
"selected": false,
"text": "<p>You can use <a href=\"http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts\" rel=\"noreferr... | 2014/07/22 | [
"https://wordpress.stackexchange.com/questions/155409",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56946/"
] | Currently my website archive page is showing 5 post per page. I need to set it to 100 post per page.
(My home page showing 5 post per page and I don't want change it)
Here is my archive.php
```
<?php get_header(); ?>
<?php do_atomic( 'before_content' ); // my-life_before_content ?>
<div id="content">
... | You can use [`pre_get_posts`](http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts) in your functions file to alter the query
```
function wpsites_query( $query ) {
if ( $query->is_archive() && $query->is_main_query() && !is_admin() ) {
$query->set( 'posts_per_page', 100 );
}
}
add_action( ... |
155,426 | <p>I need to grab a clients themes and plugins to migrate their website to our servers. I tried using All In One Migration but it didnt work and caused some errors. Now I am going to do a fresh install of Wordpress. I can get the database with the Migrate DB tool but have no idea how to get the themes or plugins. I... | [
{
"answer_id": 155421,
"author": "Brad Dalton",
"author_id": 9884,
"author_profile": "https://wordpress.stackexchange.com/users/9884",
"pm_score": 5,
"selected": false,
"text": "<p>You can use <a href=\"http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts\" rel=\"noreferr... | 2014/07/22 | [
"https://wordpress.stackexchange.com/questions/155426",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/20663/"
] | I need to grab a clients themes and plugins to migrate their website to our servers. I tried using All In One Migration but it didnt work and caused some errors. Now I am going to do a fresh install of Wordpress. I can get the database with the Migrate DB tool but have no idea how to get the themes or plugins. I obviou... | You can use [`pre_get_posts`](http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts) in your functions file to alter the query
```
function wpsites_query( $query ) {
if ( $query->is_archive() && $query->is_main_query() && !is_admin() ) {
$query->set( 'posts_per_page', 100 );
}
}
add_action( ... |
155,448 | <p>I'm trying to figure out a way to remove the shortcodes from my JSON output which I'm using the <a href="https://wordpress.org/plugins/json-api/" rel="nofollow">Wordpress JSON API</a> for.</p>
<p>I need to remove the shortcodes from the content before <code>do_shortcode</code> is applied which will cause the shortc... | [
{
"answer_id": 155421,
"author": "Brad Dalton",
"author_id": 9884,
"author_profile": "https://wordpress.stackexchange.com/users/9884",
"pm_score": 5,
"selected": false,
"text": "<p>You can use <a href=\"http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts\" rel=\"noreferr... | 2014/07/22 | [
"https://wordpress.stackexchange.com/questions/155448",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/49662/"
] | I'm trying to figure out a way to remove the shortcodes from my JSON output which I'm using the [Wordpress JSON API](https://wordpress.org/plugins/json-api/) for.
I need to remove the shortcodes from the content before `do_shortcode` is applied which will cause the shortcodes to render. The reason being that they will... | You can use [`pre_get_posts`](http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts) in your functions file to alter the query
```
function wpsites_query( $query ) {
if ( $query->is_archive() && $query->is_main_query() && !is_admin() ) {
$query->set( 'posts_per_page', 100 );
}
}
add_action( ... |
155,471 | <p>I am in the process of moving a WP site from one host to another. I copied the database and all the files, created a new database and imported the old one. I then changed the wp-config file. The home page shows fine, but when I try to access /wp-admin it takes me back to the old site.</p>
<p>The new site is a dev s... | [
{
"answer_id": 155473,
"author": "NightHawk",
"author_id": 14656,
"author_profile": "https://wordpress.stackexchange.com/users/14656",
"pm_score": 6,
"selected": true,
"text": "<p>If this is a single WordPress install, there are a couple database entries with your old domain. Specificall... | 2014/07/22 | [
"https://wordpress.stackexchange.com/questions/155471",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/48611/"
] | I am in the process of moving a WP site from one host to another. I copied the database and all the files, created a new database and imported the old one. I then changed the wp-config file. The home page shows fine, but when I try to access /wp-admin it takes me back to the old site.
The new site is a dev server wher... | If this is a single WordPress install, there are a couple database entries with your old domain. Specifically, `siteurl` and `home` within `wp_options`.
That said, if the dev URL is temporary, you can also set the following two constants in `wp-config.php`:
```
define('WP_HOME', 'http://' . $_SERVER['SERVER_NAME']);
... |
155,484 | <p>I have worked with Ruby on Rails and I was looking for some code that did something close to the wonderfull RoR's ActiveRecord.</p>
<p>I stepped by <a href="http://www.phpactiverecord.org/" rel="nofollow">this site</a>. Its PHP-ActiveRecord!</p>
<p>I found it amazing, and it was exactly what I was looking for, but... | [
{
"answer_id": 155530,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 3,
"selected": true,
"text": "<p>If you plan to use it just for your own code, and have it running alongside WordPress' default database dri... | 2014/07/23 | [
"https://wordpress.stackexchange.com/questions/155484",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56420/"
] | I have worked with Ruby on Rails and I was looking for some code that did something close to the wonderfull RoR's ActiveRecord.
I stepped by [this site](http://www.phpactiverecord.org/). Its PHP-ActiveRecord!
I found it amazing, and it was exactly what I was looking for, but I didn't find anyone trying to use it on W... | If you plan to use it just for your own code, and have it running alongside WordPress' default database driver (`wpdb`), I see no real problems.
It's only if you plan on fully integrating/overriding WP's driver that I see it being near-impossible; hard-coded SQL is prolific throughout core, and translating them to Act... |
155,486 | <p>I'm working on some conditional elements here and I thought I had it but it's still not working right. <a href="http://averylawoffice.ca/category/legal-libation-columns" rel="nofollow">You can see my site here</a>.</p>
<p>What I've done is displayed only category Legal Libation Columns (98) on this page and exclude... | [
{
"answer_id": 155530,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 3,
"selected": true,
"text": "<p>If you plan to use it just for your own code, and have it running alongside WordPress' default database dri... | 2014/07/23 | [
"https://wordpress.stackexchange.com/questions/155486",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25108/"
] | I'm working on some conditional elements here and I thought I had it but it's still not working right. [You can see my site here](http://averylawoffice.ca/category/legal-libation-columns).
What I've done is displayed only category Legal Libation Columns (98) on this page and excluded it form the blog itself. Perfect.
... | If you plan to use it just for your own code, and have it running alongside WordPress' default database driver (`wpdb`), I see no real problems.
It's only if you plan on fully integrating/overriding WP's driver that I see it being near-impossible; hard-coded SQL is prolific throughout core, and translating them to Act... |
155,488 | <p>Most of the wordpress plugins I found is <code>functions based</code>, for example, the offical <code>akismet</code> plugin</p>
<pre><code>function akismet_init() {
global $wpcom_api_key, $akismet_api_host, $akismet_api_port;
// ...
}
add_action('init', 'akismet_init');
</code></pre>
<p><strong>There are... | [
{
"answer_id": 155530,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 3,
"selected": true,
"text": "<p>If you plan to use it just for your own code, and have it running alongside WordPress' default database dri... | 2014/07/23 | [
"https://wordpress.stackexchange.com/questions/155488",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16037/"
] | Most of the wordpress plugins I found is `functions based`, for example, the offical `akismet` plugin
```
function akismet_init() {
global $wpcom_api_key, $akismet_api_host, $akismet_api_port;
// ...
}
add_action('init', 'akismet_init');
```
**There are a few issues with this approach:**
* you cannot share... | If you plan to use it just for your own code, and have it running alongside WordPress' default database driver (`wpdb`), I see no real problems.
It's only if you plan on fully integrating/overriding WP's driver that I see it being near-impossible; hard-coded SQL is prolific throughout core, and translating them to Act... |
155,489 | <p>I connected to the db and successfully pulled products data. Now I want to to display products from specific category. The store is using woocommerce. The landing page is in different location so I can't import wp functions.</p>
<p>Here's what I come up with so far:</p>
<pre><code>SELECT ID, `post_date` , `post_t... | [
{
"answer_id": 155533,
"author": "ksr89",
"author_id": 31368,
"author_profile": "https://wordpress.stackexchange.com/users/31368",
"pm_score": 2,
"selected": false,
"text": "<p>I check your query and it's working fine without any errors or empty results. But in addition if you remove <co... | 2014/07/23 | [
"https://wordpress.stackexchange.com/questions/155489",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/54533/"
] | I connected to the db and successfully pulled products data. Now I want to to display products from specific category. The store is using woocommerce. The landing page is in different location so I can't import wp functions.
Here's what I come up with so far:
```
SELECT ID, `post_date` , `post_title` , `post_conten... | I check your query and it's working fine without any errors or empty results. But in addition if you remove `INNER JOIN` from `wp_terms` table its also working because you are not getting anything from that table and it is not used in `WHERE` clause also.
```
SELECT ID, `post_date` , `post_title` , `post_content` , ... |
155,507 | <p>I have created a page called "videos", this is set as the post page where all post should show up.
That´s fine, but I want to exclude all posts from two of the sites categories.</p>
<p>I tried this code, but it´s not working
it´s the right page id and the right category id´s.</p>
<pre><code> function exclude_ca... | [
{
"answer_id": 155508,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 0,
"selected": false,
"text": "<h2>EDIT:</h2>\n\n<p>I have misread the question and did not realise that the page is set as blogpage. I'm... | 2014/07/23 | [
"https://wordpress.stackexchange.com/questions/155507",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/43092/"
] | I have created a page called "videos", this is set as the post page where all post should show up.
That´s fine, but I want to exclude all posts from two of the sites categories.
I tried this code, but it´s not working
it´s the right page id and the right category id´s.
```
function exclude_category($query) {
... | Yes your code will fail, but not because the above answer, but because this isn't the page you ask for.
As you wrote, you set the page "videos" to be the page where all the posts are shown.
When a page is set as a blogpage, Wordpress will use home.php or index.php according to the template hierarchy to display the b... |
155,562 | <p>I am interested in having a blog on my site which will be in a subdirectory of the main wordpress homepage</p>
<p>e.g. website.com/blog</p>
<p>however, I am interested to know if there is a way to host the blog on a separate server - primarily because I don't want to overload the server for the rest of the site if... | [
{
"answer_id": 155583,
"author": "lartan",
"author_id": 49586,
"author_profile": "https://wordpress.stackexchange.com/users/49586",
"pm_score": -1,
"selected": false,
"text": "<p>Does it have to be website.com/blog?</p>\n\n<p>A faster solution and less complex would be to just host the b... | 2014/07/23 | [
"https://wordpress.stackexchange.com/questions/155562",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/52794/"
] | I am interested in having a blog on my site which will be in a subdirectory of the main wordpress homepage
e.g. website.com/blog
however, I am interested to know if there is a way to host the blog on a separate server - primarily because I don't want to overload the server for the rest of the site if there is a lot o... | A reverse proxy could work, such as varnish or nginx. Using varnish as an example:
```
backend blog {
.host = "blog-server-ip";
}
backend default {
.host = "current-domain-ip";
}
sub vcl_recv {
if (req.rul ~ "^/blog/") {
req.backend = blog;
}
}
``` |
155,572 | <p>Hi i am working on custom post types in wordpress presently we are using below code to display the custom posts, but the thing is the custom post types are keep on increasing, </p>
<pre><code>add_action( 'pre_get_posts', 'add_my_post_types_to_query' );
function add_my_post_types_to_query( $query ) {
if ( is_h... | [
{
"answer_id": 155573,
"author": "sabarnix",
"author_id": 56542,
"author_profile": "https://wordpress.stackexchange.com/users/56542",
"pm_score": 3,
"selected": true,
"text": "<pre><code>add_action( 'pre_get_posts', 'add_my_post_types_to_query' );\n\nfunction add_my_post_types_to_query( ... | 2014/07/23 | [
"https://wordpress.stackexchange.com/questions/155572",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56910/"
] | Hi i am working on custom post types in wordpress presently we are using below code to display the custom posts, but the thing is the custom post types are keep on increasing,
```
add_action( 'pre_get_posts', 'add_my_post_types_to_query' );
function add_my_post_types_to_query( $query ) {
if ( is_home() && $query... | ```
add_action( 'pre_get_posts', 'add_my_post_types_to_query' );
function add_my_post_types_to_query( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', 'any' );
return $query;
}
```
refer to <http://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters> |
155,586 | <p>I have a WP install that's been getting hammered the last couple days by brute force login attempts.</p>
<p>The site has the Limit Login Attempts plug-in installed. And when I started getting frequent notifications about lockouts, I decided since I only access the <code>wp-login.php</code> file and the <code>wp-adm... | [
{
"answer_id": 155607,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 3,
"selected": true,
"text": "<p>The answer is most likely XML-RPC which is used to communicate with the mobile wordpress apps and is alway... | 2014/07/23 | [
"https://wordpress.stackexchange.com/questions/155586",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/27191/"
] | I have a WP install that's been getting hammered the last couple days by brute force login attempts.
The site has the Limit Login Attempts plug-in installed. And when I started getting frequent notifications about lockouts, I decided since I only access the `wp-login.php` file and the `wp-admin` from one place, to blo... | The answer is most likely XML-RPC which is used to communicate with the mobile wordpress apps and is always on in newer versions. If you don't use mobile apps to admin your WP you can use my plugin - <http://wordpress.org/plugins/control-xml-rpc-publishing/> to disable it. |
155,588 | <p>I can't find solution for this ...</p>
<p>URL: <em>www.foo.com/some_page/?name=John</em></p>
<p>Page content:</p>
<blockquote>
<p>Hi [Name]!</p>
</blockquote>
<p>Worpress still redirects back to <em>www.foo.com/some_page/</em></p>
<p>I tried everything ...</p>
<p>I need something like the following in <em>fu... | [
{
"answer_id": 155590,
"author": "gdaniel",
"author_id": 30984,
"author_profile": "https://wordpress.stackexchange.com/users/30984",
"pm_score": 4,
"selected": true,
"text": "<p>If I understand your question correctly, you want to be able to get the parameter from the url, add it to the ... | 2014/07/23 | [
"https://wordpress.stackexchange.com/questions/155588",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57026/"
] | I can't find solution for this ...
URL: *www.foo.com/some\_page/?name=John*
Page content:
>
> Hi [Name]!
>
>
>
Worpress still redirects back to *www.foo.com/some\_page/*
I tried everything ...
I need something like the following in *functions.php*
```
function name_shortcode() {
return $_GET['name'];
}
a... | If I understand your question correctly, you want to be able to get the parameter from the url, add it to the shortcode so you can add the parameter to the content.
See if this works:
```
add_shortcode('name', 'get_name');
function get_name() {
return $_GET['name'];
}
```
In the wordpress backend editor you w... |
155,611 | <p>For the <code>Page</code> post type: I can create a <code>logout</code> page in the CMS and create a <code>page-logout.php</code> for its template.</p>
<p>I created an <code>Account</code> post type but I can't use <code>account-user-registration.php</code> for a <code>User Registration</code> post under <code>Acco... | [
{
"answer_id": 155622,
"author": "hamed",
"author_id": 57052,
"author_profile": "https://wordpress.stackexchange.com/users/57052",
"pm_score": -1,
"selected": false,
"text": "<p>I use this: <code>archive-{$post-type}.php</code></p>\n"
},
{
"answer_id": 155636,
"author": "HU i... | 2014/07/24 | [
"https://wordpress.stackexchange.com/questions/155611",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40834/"
] | For the `Page` post type: I can create a `logout` page in the CMS and create a `page-logout.php` for its template.
I created an `Account` post type but I can't use `account-user-registration.php` for a `User Registration` post under `Account` post type. | As Pages are a special built in Posttype, they get an own template hierarchy. Other "normal" post types and custom post types can only be templated by "single-$posttype.php". You can however hook into the single\_template filter and make wordpress redirect to your template file:
```
function get_custom_post_type_templ... |
155,625 | <p>Here is how I've implemented it:</p>
<pre><code>add_action( 'delete_post', array( 'MyClassName', 'delete' ) );
</code></pre>
<p>In the delete function I was using a $wpdb->insert command to see whether the function gets called. But I see that the $wpdb->insert command is called twice (inserts two rows in my table)... | [
{
"answer_id": 155632,
"author": "HU is Sebastian",
"author_id": 56587,
"author_profile": "https://wordpress.stackexchange.com/users/56587",
"pm_score": 0,
"selected": false,
"text": "<p>If you use Classes for your plugin, then you have to add the action like this:</p>\n\n<pre><code>add_... | 2014/07/24 | [
"https://wordpress.stackexchange.com/questions/155625",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/55042/"
] | Here is how I've implemented it:
```
add_action( 'delete_post', array( 'MyClassName', 'delete' ) );
```
In the delete function I was using a $wpdb->insert command to see whether the function gets called. But I see that the $wpdb->insert command is called twice (inserts two rows in my table). Any ideas as to why some... | I found my solution.
The function you hook into delete\_post (or probably any other similar hook) executes as many times as needed. Considering delete\_post needs to delete the post and all of its revisions, it will always run more than once. In order to avoid having your function execute each time WordPress deletes a... |
155,629 | <p>I have registered several custom taxonomies for a custom post type. Code for one of them is the following:</p>
<pre><code>$labels = array(
'name' => __( 'Genre', 'textdomain' ),
'singular_name' => __( 'Genre', 'textdomain' ),
'search_items' => __( 'Search Genres', 'textdom... | [
{
"answer_id": 155631,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 4,
"selected": true,
"text": "<p>Just like CPT capabilities those of taxonomy are also customizable, in <a href=\"http://codex.wordpress.org/Function... | 2014/07/24 | [
"https://wordpress.stackexchange.com/questions/155629",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56470/"
] | I have registered several custom taxonomies for a custom post type. Code for one of them is the following:
```
$labels = array(
'name' => __( 'Genre', 'textdomain' ),
'singular_name' => __( 'Genre', 'textdomain' ),
'search_items' => __( 'Search Genres', 'textdomain' ),
'all_items'... | Just like CPT capabilities those of taxonomy are also customizable, in [`register_taxonomy()`](http://codex.wordpress.org/Function_Reference/register_taxonomy):
>
> capabilities
>
>
> * 'manage\_terms' - 'manage\_categories'
> * 'edit\_terms' - 'manage\_categories'
> * 'delete\_terms' - 'manage\_categories'
> * 'a... |
155,637 | <p>I have a custom post type and a taxonomy which allows the user to select which category the post is in.</p>
<p>Here is my custom taxonomy:</p>
<pre><code>add_action( 'init', 'create_talcat_taxonomy', 0);
function create_Talcat_taxonomy()
{
register_taxonomy ( 'Talcat', 'artist', array( 'hierarchical' =>
... | [
{
"answer_id": 155641,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 3,
"selected": true,
"text": "<p>I think you are talking about terms, not categories. You can use <a href=\"http://codex.wordpress.org/Te... | 2014/07/24 | [
"https://wordpress.stackexchange.com/questions/155637",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/51147/"
] | I have a custom post type and a taxonomy which allows the user to select which category the post is in.
Here is my custom taxonomy:
```
add_action( 'init', 'create_talcat_taxonomy', 0);
function create_Talcat_taxonomy()
{
register_taxonomy ( 'Talcat', 'artist', array( 'hierarchical' =>
true, 'label' => 'Categ... | I think you are talking about terms, not categories. You can use [`wp_list_categories`](http://codex.wordpress.org/Template_Tags/wp_list_categories) to retrieve and display the terms that a post belongs to.
Here is a working example from the codex. Remember the `$taxonomy` variable can be changed to `category` or any ... |
155,664 | <p>I have a blog that publish articles of any philosophers.Each philosopher has a special page that includes information about him.</p>
<p>I've created a post type called <em>philosopher</em>. I want to display the title of each philosopher's articles under his page, but because every philosopher has many articles, I ... | [
{
"answer_id": 155668,
"author": "sunil",
"author_id": 56910,
"author_profile": "https://wordpress.stackexchange.com/users/56910",
"pm_score": -1,
"selected": false,
"text": "<p>paste this code in a template</p>\n\n<pre><code> <?php\n//if a certain page, then display posts authored... | 2014/07/24 | [
"https://wordpress.stackexchange.com/questions/155664",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/54976/"
] | I have a blog that publish articles of any philosophers.Each philosopher has a special page that includes information about him.
I've created a post type called *philosopher*. I want to display the title of each philosopher's articles under his page, but because every philosopher has many articles, I only want to disp... | You can simply use the default author.php page to do this. If you don't have one, make a copy of index.php and rename it author.php
Now, use [`pre_get_posts`](http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts) to include your custom post type in the author pages. This code goes in functions.php
```... |
155,665 | <p>I am working on custom post types. Presently we are using below code to display all custom posts in home page </p>
<pre><code> <?php
$args = array(
'public' => true,
'_builtin' => false
);
$output = 'names'; // names or objects, note names is the default
$operator = 'and'; // 'and' or 'or'
$p... | [
{
"answer_id": 155671,
"author": "Khan",
"author_id": 43593,
"author_profile": "https://wordpress.stackexchange.com/users/43593",
"pm_score": 1,
"selected": false,
"text": "<p>your <code>query_posts</code> line uses <code>$post_type</code> which will only be the last post type in the <co... | 2014/07/24 | [
"https://wordpress.stackexchange.com/questions/155665",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56910/"
] | I am working on custom post types. Presently we are using below code to display all custom posts in home page
```
<?php
$args = array(
'public' => true,
'_builtin' => false
);
$output = 'names'; // names or objects, note names is the default
$operator = 'and'; // 'and' or 'or'
$post_types = get_post_ty... | Not to be rude, but you've missed everything here
Firstly, you should never use [`query_posts`](http://codex.wordpress.org/Function_Reference/query_posts) to construct custom queries. This is not just my emphasis, but the codex as well. The one big problem with `query_posts` is, it many circumstances, pagination fails... |
155,675 | <p>I am using the Wordpress get_users() function to search for users with a specific meta_key value.</p>
<pre><code>$wordpress_user = get_users( array('meta_key' => 'unique_id',
'meta_value' => 'unique_id_value') );
</code></pre>
<p>According to the result of the preceding, I... | [
{
"answer_id": 155671,
"author": "Khan",
"author_id": 43593,
"author_profile": "https://wordpress.stackexchange.com/users/43593",
"pm_score": 1,
"selected": false,
"text": "<p>your <code>query_posts</code> line uses <code>$post_type</code> which will only be the last post type in the <co... | 2014/07/24 | [
"https://wordpress.stackexchange.com/questions/155675",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/54952/"
] | I am using the Wordpress get\_users() function to search for users with a specific meta\_key value.
```
$wordpress_user = get_users( array('meta_key' => 'unique_id',
'meta_value' => 'unique_id_value') );
```
According to the result of the preceding, I am performing the creation of... | Not to be rude, but you've missed everything here
Firstly, you should never use [`query_posts`](http://codex.wordpress.org/Function_Reference/query_posts) to construct custom queries. This is not just my emphasis, but the codex as well. The one big problem with `query_posts` is, it many circumstances, pagination fails... |
155,696 | <p>I have a wordpress page that has this code in the text editor part of a web page:</p>
<pre><code>This page creates a cookie and houses a etst link that is only accessible to the holder of the cookie.
&nbsp;
Test Link (authentication required).
&nbsp;
Syntax:
<span style="color: #444444;">setcookie(na... | [
{
"answer_id": 155671,
"author": "Khan",
"author_id": 43593,
"author_profile": "https://wordpress.stackexchange.com/users/43593",
"pm_score": 1,
"selected": false,
"text": "<p>your <code>query_posts</code> line uses <code>$post_type</code> which will only be the last post type in the <co... | 2014/07/24 | [
"https://wordpress.stackexchange.com/questions/155696",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/43988/"
] | I have a wordpress page that has this code in the text editor part of a web page:
```
This page creates a cookie and houses a etst link that is only accessible to the holder of the cookie.
Test Link (authentication required).
Syntax:
<span style="color: #444444;">setcookie(name, value, expire, path, dom... | Not to be rude, but you've missed everything here
Firstly, you should never use [`query_posts`](http://codex.wordpress.org/Function_Reference/query_posts) to construct custom queries. This is not just my emphasis, but the codex as well. The one big problem with `query_posts` is, it many circumstances, pagination fails... |
155,713 | <p>This should be simple, but it escapes me.</p>
<p>I have a custom post type and a custom taxonomy. The taxonomy is named "asset_type" and the slug is "type"</p>
<p>I am using <code>wp_list_categories</code> to provide a sidebar menu where users can click to view posts in the clicked taxonomy.</p>
<p>For example:<... | [
{
"answer_id": 155736,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 3,
"selected": true,
"text": "<p>Steve, you've asked a couple of questions which I had a look at, and I came to the conclusion that your ... | 2014/07/24 | [
"https://wordpress.stackexchange.com/questions/155713",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23610/"
] | This should be simple, but it escapes me.
I have a custom post type and a custom taxonomy. The taxonomy is named "asset\_type" and the slug is "type"
I am using `wp_list_categories` to provide a sidebar menu where users can click to view posts in the clicked taxonomy.
For example:
```
<div class="category-sidebar">... | Steve, you've asked a couple of questions which I had a look at, and I came to the conclusion that your loop is causing all of your headaches.
>
> My loop to display ALL the posts is:
>
>
>
> ```
> $args = array( 'post_type' => 'design_asset', 'posts_per_page' => 100, 'orderby' => 'title', 'order' => 'ASC' );
> ... |
155,758 | <p>I need to have a different amount of posts per page on the first page that on the other pages. </p>
<p>For example, this is what I need</p>
<ul>
<li>Total posts: 6</li>
<li>First page: showing 3 posts</li>
<li>Following page: showing 2 posts per page</li>
</ul>
<p>Here's my code:</p>
<pre><code>$paged = (get_que... | [
{
"answer_id": 155782,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 6,
"selected": true,
"text": "<p><strong>EDIT - ANSWER REVISITED</strong></p>\n\n<p>I've being working on another solution which is actua... | 2014/07/25 | [
"https://wordpress.stackexchange.com/questions/155758",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/37130/"
] | I need to have a different amount of posts per page on the first page that on the other pages.
For example, this is what I need
* Total posts: 6
* First page: showing 3 posts
* Following page: showing 2 posts per page
Here's my code:
```
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$fp_limit = ... | **EDIT - ANSWER REVISITED**
I've being working on another solution which is actually better the original answer. This does not involve any custom query and I think for all purposes my original answer can be dropped but kept for informational purposes
I still believe you are on the homepage and will also treat this as... |
155,771 | <p>I am trying to add some HTML to the title label in the backend of WordPress.</p>
<p><strong>Attempt 1:</strong></p>
<p>I am using the following (simplified) function:</p>
<pre><code>function change_post_titles() {
global $post, $title, $action, $current_screen;
$title = 'foo<br>bar';
}
add_action('... | [
{
"answer_id": 158267,
"author": "Sri",
"author_id": 57473,
"author_profile": "https://wordpress.stackexchange.com/users/57473",
"pm_score": -1,
"selected": false,
"text": "<pre><code>function change_post_titles() {\n global $post, $title, $action, $current_screen;\n $title = \"foo... | 2014/07/25 | [
"https://wordpress.stackexchange.com/questions/155771",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/55197/"
] | I am trying to add some HTML to the title label in the backend of WordPress.
**Attempt 1:**
I am using the following (simplified) function:
```
function change_post_titles() {
global $post, $title, $action, $current_screen;
$title = 'foo<br>bar';
}
add_action('admin_head', 'change_post_titles');
```
This ... | It is not possible to add HTML to it.
For example, `wp-admin/edit.php` uses the following code:
```
<h1 class="wp-heading-inline">
<?php
echo esc_html( $post_type_object->labels->name );
?>
</h1>
```
As you can see, this uses the [esc\_html()](https://developer.wordpress.org/reference/functions/esc_html/) function.... |
155,800 | <p>I am working on a <a href="http://wonderland.opteradev.com" rel="nofollow">site</a> that uses jQuery for a number of functions but I am having a repeating error:</p>
<blockquote>
<p>hoverIntent is not a function</p>
</blockquote>
<p>I have referenced similar questions on this forum and they almost universally sa... | [
{
"answer_id": 158267,
"author": "Sri",
"author_id": 57473,
"author_profile": "https://wordpress.stackexchange.com/users/57473",
"pm_score": -1,
"selected": false,
"text": "<pre><code>function change_post_titles() {\n global $post, $title, $action, $current_screen;\n $title = \"foo... | 2014/07/25 | [
"https://wordpress.stackexchange.com/questions/155800",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/48611/"
] | I am working on a [site](http://wonderland.opteradev.com) that uses jQuery for a number of functions but I am having a repeating error:
>
> hoverIntent is not a function
>
>
>
I have referenced similar questions on this forum and they almost universally say that it is due to multiple references to jQuery, however... | It is not possible to add HTML to it.
For example, `wp-admin/edit.php` uses the following code:
```
<h1 class="wp-heading-inline">
<?php
echo esc_html( $post_type_object->labels->name );
?>
</h1>
```
As you can see, this uses the [esc\_html()](https://developer.wordpress.org/reference/functions/esc_html/) function.... |
155,827 | <p>The custom fields all have prices including $ signs, and a dot as separator.</p>
<pre><code>$theQuery = new WP_Query(array(
'orderby' => 'meta_value_num',
'meta_key' => 'price',
'order' => ASC
));
</code></pre>
<p>All formatted like this: </p>
<p>$24.95
$190.00
$1.40</p>
<p>They won't sort correctly d... | [
{
"answer_id": 155836,
"author": "Manny Fleurmond",
"author_id": 2234,
"author_profile": "https://wordpress.stackexchange.com/users/2234",
"pm_score": 0,
"selected": false,
"text": "<p>You'll have to use the <code>post_clauses</code> filter to create some custom SQL:</p>\n\n<pre><code>ad... | 2014/07/26 | [
"https://wordpress.stackexchange.com/questions/155827",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56573/"
] | The custom fields all have prices including $ signs, and a dot as separator.
```
$theQuery = new WP_Query(array(
'orderby' => 'meta_value_num',
'meta_key' => 'price',
'order' => ASC
));
```
All formatted like this:
$24.95
$190.00
$1.40
They won't sort correctly due to the dollar sign, is it possible to ignore o... | You could also use the `posts_orderby` filter:
```
function wpse155827_posts_orderby_price( $orderby ) {
return str_replace( 'wp_postmeta.meta_value', 'substr(wp_postmeta.meta_value, 1)', $orderby );
}
add_filter( 'posts_orderby', 'wpse155827_posts_orderby_price' );
$theQuery = new WP_Query( array(
'orderby' =... |
155,837 | <p>I'm currently building a website for a friend and have assigned him the user role of editor. I don't want to give him an administrator role in case he breaks the layout. Anyway, I am using 'add_menu_page()' to add the Appearance > Menus page as an option for the Editor and it is showing up when I log in as an editor... | [
{
"answer_id": 155838,
"author": "Bindiya Patoliya",
"author_id": 34932,
"author_profile": "https://wordpress.stackexchange.com/users/34932",
"pm_score": -1,
"selected": false,
"text": "<p>Try this way :</p>\n\n<pre><code> add_menu_page( 'custom menu title', 'custom menu', 'manage_option... | 2014/07/26 | [
"https://wordpress.stackexchange.com/questions/155837",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/48204/"
] | I'm currently building a website for a friend and have assigned him the user role of editor. I don't want to give him an administrator role in case he breaks the layout. Anyway, I am using 'add\_menu\_page()' to add the Appearance > Menus page as an option for the Editor and it is showing up when I log in as an editor ... | Run this once, it will be saved in database. You can run it once by adding it to functions.php and reloading the site once.
```
$user = new WP_User( $user_id ); // the user id you want to have that capability
$user->add_cap( 'edit_others_posts' ); // or any other capability that you want
``` |
155,888 | <p>Does <strong>apply_filters</strong>/<strong>do_action</strong> <code>$tag</code> name have a characters limit? Can be any problems if the tag name is way too long? I ask this because I know that WP transients have a limit of <a href="http://codex.wordpress.org/Function_Reference/set_transient#Parameters" rel="nofoll... | [
{
"answer_id": 155838,
"author": "Bindiya Patoliya",
"author_id": 34932,
"author_profile": "https://wordpress.stackexchange.com/users/34932",
"pm_score": -1,
"selected": false,
"text": "<p>Try this way :</p>\n\n<pre><code> add_menu_page( 'custom menu title', 'custom menu', 'manage_option... | 2014/07/26 | [
"https://wordpress.stackexchange.com/questions/155888",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/31111/"
] | Does **apply\_filters**/**do\_action** `$tag` name have a characters limit? Can be any problems if the tag name is way too long? I ask this because I know that WP transients have a limit of [45 characters](http://codex.wordpress.org/Function_Reference/set_transient#Parameters).
FYI, this is the tag I'm referring to:
... | Run this once, it will be saved in database. You can run it once by adding it to functions.php and reloading the site once.
```
$user = new WP_User( $user_id ); // the user id you want to have that capability
$user->add_cap( 'edit_others_posts' ); // or any other capability that you want
``` |
155,903 | <p>I know how to show the total number of posts in a site, but is there a way to show the number of posts the page you're on is displaying?</p>
<p>For example, I want to show this at the bottom of each of my blog pages (8 posts per page);</p>
<pre><code>Index - "Showing posts 1 through 8 of 294 total"
Page2 - "Showin... | [
{
"answer_id": 155914,
"author": "karpstrucking",
"author_id": 55214,
"author_profile": "https://wordpress.stackexchange.com/users/55214",
"pm_score": 2,
"selected": true,
"text": "<p>This should work, but I haven't tested it:</p>\n\n<pre><code>global $wp_query;\n$page = ( get_query_var(... | 2014/07/26 | [
"https://wordpress.stackexchange.com/questions/155903",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/19319/"
] | I know how to show the total number of posts in a site, but is there a way to show the number of posts the page you're on is displaying?
For example, I want to show this at the bottom of each of my blog pages (8 posts per page);
```
Index - "Showing posts 1 through 8 of 294 total"
Page2 - "Showing posts 9 through 17 ... | This should work, but I haven't tested it:
```
global $wp_query;
$page = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$ppp = get_query_var('posts_per_page');
$end = $ppp * $page;
$start = $end - $ppp + 1;
$total = $wp_query->found_posts;
echo "Showing posts $start through $end of $total total.";
``` |
155,912 | <p>I have registered a new widget area, code as below and want to add a button after the <code>.textwidget</code>, however cannot seem to do it properly. Adding it after the <code></li></code> results in the button not being contained within a container and thus messes up the page - which is to be expected.</p>
... | [
{
"answer_id": 155914,
"author": "karpstrucking",
"author_id": 55214,
"author_profile": "https://wordpress.stackexchange.com/users/55214",
"pm_score": 2,
"selected": true,
"text": "<p>This should work, but I haven't tested it:</p>\n\n<pre><code>global $wp_query;\n$page = ( get_query_var(... | 2014/07/27 | [
"https://wordpress.stackexchange.com/questions/155912",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/26686/"
] | I have registered a new widget area, code as below and want to add a button after the `.textwidget`, however cannot seem to do it properly. Adding it after the `</li>` results in the button not being contained within a container and thus messes up the page - which is to be expected.
It's not possible to add a containe... | This should work, but I haven't tested it:
```
global $wp_query;
$page = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$ppp = get_query_var('posts_per_page');
$end = $ppp * $page;
$start = $end - $ppp + 1;
$total = $wp_query->found_posts;
echo "Showing posts $start through $end of $total total.";
``` |
155,917 | <p>I am trying to add a link, in the Admin Sidebar, that links to one of the pages I've created in the PAGES section. For example, I've created an ABOUT page. So in the sidebar I would like a link to "About" that loads this link: <code>post.php?post=7&action=edit</code></p>
<p>Why? I am trying to do this because I... | [
{
"answer_id": 156052,
"author": "Bryan Willis",
"author_id": 38123,
"author_profile": "https://wordpress.stackexchange.com/users/38123",
"pm_score": 4,
"selected": true,
"text": "<p>To dynamically add menu items you can use WP_Query, specifically get_posts or get_pages. Get pages is mor... | 2014/07/27 | [
"https://wordpress.stackexchange.com/questions/155917",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40679/"
] | I am trying to add a link, in the Admin Sidebar, that links to one of the pages I've created in the PAGES section. For example, I've created an ABOUT page. So in the sidebar I would like a link to "About" that loads this link: `post.php?post=7&action=edit`
Why? I am trying to do this because I am working on a website ... | To dynamically add menu items you can use WP\_Query, specifically get\_posts or get\_pages. Get pages is more consistent. Here's an example to add all pages to the Pages admin menu. You can change paramaters to exclude, include, orderby, etc in the $args below. To change to a custom post type just change $custom variab... |
155,926 | <p>Is there a way to <strong>automatically set page order</strong> to the last order number <strong>upon creating new pages</strong> instead of having it set to 0?</p>
| [
{
"answer_id": 155974,
"author": "karpstrucking",
"author_id": 55214,
"author_profile": "https://wordpress.stackexchange.com/users/55214",
"pm_score": 2,
"selected": false,
"text": "<p>You could hook into the <code>publish_page</code> transitional status action and use a simple SQL query... | 2014/07/27 | [
"https://wordpress.stackexchange.com/questions/155926",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1044/"
] | Is there a way to **automatically set page order** to the last order number **upon creating new pages** instead of having it set to 0? | You could use ajax and the `admin_footer-post-new.php` hook. The sql would vary depending on whether you want the highest or most recently published order number. The following returns the highest published order number + 1:
```
function wpse155926_set_menu_order() {
$ret = array();
if ( check_ajax_referer( '... |
155,935 | <p>I am pretty new in WordPress theme development and I have the following doubt about how show posts into a page.</p>
<p>I have this page belonging to an old custom legacy blog that I am build again using WordPress: <a href="http://www.asper-eritrea.com/comunicati.asp" rel="nofollow">http://www.asper-eritrea.com/comu... | [
{
"answer_id": 155947,
"author": "Domain",
"author_id": 26523,
"author_profile": "https://wordpress.stackexchange.com/users/26523",
"pm_score": -1,
"selected": false,
"text": "<p>The issue is occurring because of the get_template_part function. It is including the template file which pri... | 2014/07/27 | [
"https://wordpress.stackexchange.com/questions/155935",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/29275/"
] | I am pretty new in WordPress theme development and I have the following doubt about how show posts into a page.
I have this page belonging to an old custom legacy blog that I am build again using WordPress: <http://www.asper-eritrea.com/comunicati.asp>
As you can see in this page are presented some posts using the fo... | The `get_template_part('content', get_post_format());` line includes content from one of the other files in your theme based on the post type, the file name will be something like `content-page.php` (or `content.php` if the format is not found).
If you print out what `get_post_format()` returns, you will be able to te... |
155,937 | <p>I'm creating a "Related posts" section for my theme, based on a tutorial from <a href="http://www.wpbeginner.com/wp-themes/how-to-add-related-posts-with-a-thumbnail-without-using-plugins/" rel="nofollow">wpbeginner.com</a>. It offered two options in selecting posts: those in the same category(ies), using <code>categ... | [
{
"answer_id": 155970,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 2,
"selected": true,
"text": "<p>Yes, that is possible. All <a href=\"http://codex.wordpress.org/Taxonomies\" rel=\"nofollow\"><strong>Ta... | 2014/07/27 | [
"https://wordpress.stackexchange.com/questions/155937",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/36204/"
] | I'm creating a "Related posts" section for my theme, based on a tutorial from [wpbeginner.com](http://www.wpbeginner.com/wp-themes/how-to-add-related-posts-with-a-thumbnail-without-using-plugins/). It offered two options in selecting posts: those in the same category(ies), using `category__in`, or those with the same t... | Yes, that is possible. All [**Taxonomies**](http://codex.wordpress.org/Taxonomies) are stored in the db in the `wp_term_taxonomy` table. The following are all listed as taxonomies
* category
* post\_tag
* link\_category
* post\_format and
* Custom taxonomies
All terms belonging to these taxonomies are stored in the `... |
156,001 | <p>I'm trying to retrieve the current URL of the page, which works everywhere except for archive pages, for example, a category page. On a category page, it shows as the most recent post in that category.</p>
<pre><code>$this_id = $wp_the_query->get_queried_object_id();
$this_url = get_permalink($this_id);
echo $th... | [
{
"answer_id": 156005,
"author": "Domain",
"author_id": 26523,
"author_profile": "https://wordpress.stackexchange.com/users/26523",
"pm_score": 0,
"selected": false,
"text": "<p>Category URLs can be retrieved using function <code>get_category_link</code>. So instead of using <code>get_pe... | 2014/07/27 | [
"https://wordpress.stackexchange.com/questions/156001",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25735/"
] | I'm trying to retrieve the current URL of the page, which works everywhere except for archive pages, for example, a category page. On a category page, it shows as the most recent post in that category.
```
$this_id = $wp_the_query->get_queried_object_id();
$this_url = get_permalink($this_id);
echo $this_url; // Should... | Untested, but here is a solution from [Konstantin Kovshenin](http://kovshenin.com/2012/current-url-in-wordpress/)
```
global $wp;
$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
```
You can then just simply `echo $current_url` |
156,004 | <p>I've been searching for this a lot...but all I get is not what I need.
I simply want to show next and previous links on single.php (from all the categories, based on publish date, not just in the same category), but skipping a category.
So if the next (or previous) post would be in category id 402, skip the post ... | [
{
"answer_id": 156006,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 0,
"selected": false,
"text": "<p>This is what the Custom Post Types are for - separate unrelated types of content. For your description it... | 2014/07/28 | [
"https://wordpress.stackexchange.com/questions/156004",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/6927/"
] | I've been searching for this a lot...but all I get is not what I need.
I simply want to show next and previous links on single.php (from all the categories, based on publish date, not just in the same category), but skipping a category.
So if the next (or previous) post would be in category id 402, skip the post and... | Use the 4th parameter $excluded\_terms
<http://codex.wordpress.org/Function_Reference/next_post_link>
```
<?php next_post_link( $format, $next, $in_same_term = true, $excluded_terms = '402', $taxonomy = 'category' ); ?>
```
Same for the previous\_post\_link
<http://codex.wordpress.org/Template_Tags/previous_post_li... |
156,009 | <p>My custom query works, except when debugging it throws off an error: </p>
<blockquote>
<p>Undefined Offset: 0 in /wp-includes/query.php</p>
</blockquote>
<p>This is what my query looks like : </p>
<pre><code><?php $loop = new wp_query('post_type=car&category_name='.get_the_title());?>
<?php if( $l... | [
{
"answer_id": 156006,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 0,
"selected": false,
"text": "<p>This is what the Custom Post Types are for - separate unrelated types of content. For your description it... | 2014/07/28 | [
"https://wordpress.stackexchange.com/questions/156009",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57187/"
] | My custom query works, except when debugging it throws off an error:
>
> Undefined Offset: 0 in /wp-includes/query.php
>
>
>
This is what my query looks like :
```
<?php $loop = new wp_query('post_type=car&category_name='.get_the_title());?>
<?php if( $loop->have_posts() ) : ?>
<table style="width: 100%">... | Use the 4th parameter $excluded\_terms
<http://codex.wordpress.org/Function_Reference/next_post_link>
```
<?php next_post_link( $format, $next, $in_same_term = true, $excluded_terms = '402', $taxonomy = 'category' ); ?>
```
Same for the previous\_post\_link
<http://codex.wordpress.org/Template_Tags/previous_post_li... |
156,040 | <p>I'm a bit stuck with my actual project. Actually I wanted to link a search icon to the search page (where there's a form & the results).</p>
<p>Actually I tried to link like this: <code>/project/?s=</code> but it redirects to the index page when <code>s=</code> empty - when I assign a parameter like <code>s=ips... | [
{
"answer_id": 156110,
"author": "amieiro",
"author_id": 19888,
"author_profile": "https://wordpress.stackexchange.com/users/19888",
"pm_score": 0,
"selected": false,
"text": "<p>When WordPress makes a search it uses the search.php template and if it has not it then it uses the index.php... | 2014/07/28 | [
"https://wordpress.stackexchange.com/questions/156040",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57240/"
] | I'm a bit stuck with my actual project. Actually I wanted to link a search icon to the search page (where there's a form & the results).
Actually I tried to link like this: `/project/?s=` but it redirects to the index page when `s=` empty - when I assign a parameter like `s=ipsum` it directs to the search page with it... | Create a file `search.php` inside your theme-folder. In this file you can design the search page and its functionality.
Typically search page looks like this,
```
<?php
/**
* The template for displaying search results pages
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
... |
156,045 | <p>I have the following <strong>3 different Roles</strong>: <code>Admin</code>, <code>Editor</code>, and <code>SEO</code>. I have installed WordPress SEO by Yoast, and I want to get this:</p>
<ul>
<li><strong>I don't want the editors to see the SEO options</strong>, because they only write posts and don't know about S... | [
{
"answer_id": 156073,
"author": "Howdy_McGee",
"author_id": 7355,
"author_profile": "https://wordpress.stackexchange.com/users/7355",
"pm_score": 4,
"selected": true,
"text": "<p>Maybe this isn't the best method because it does give an editor access to Settings and Options, but what thi... | 2014/07/28 | [
"https://wordpress.stackexchange.com/questions/156045",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40743/"
] | I have the following **3 different Roles**: `Admin`, `Editor`, and `SEO`. I have installed WordPress SEO by Yoast, and I want to get this:
* **I don't want the editors to see the SEO options**, because they only write posts and don't know about SEO. There is a person with the `SEO` role, who will do the optimization.
... | Maybe this isn't the best method because it does give an editor access to Settings and Options, but what this does is gives the a specific editor (based on user ID) the permissions to edit options. We then test if we're loading one of the options template, if we are AND the user id is the same id we've given permission... |
156,080 | <p>Is there a way to add classes to the <code>body_class</code> function based on the current page?</p>
<p>For example if you're on the homepage, as well as the usual generated classes, the <code><body></code> element would also have <code>front</code> and <code>main-page</code> classes. Then if you were on the ... | [
{
"answer_id": 156169,
"author": "pyverret",
"author_id": 57252,
"author_profile": "https://wordpress.stackexchange.com/users/57252",
"pm_score": 2,
"selected": true,
"text": "<p>Found a fix.</p>\n\n<p>Seems pagination is breaking the display of the the Pages hierarchy in the metabox.</p... | 2014/07/28 | [
"https://wordpress.stackexchange.com/questions/156080",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/19319/"
] | Is there a way to add classes to the `body_class` function based on the current page?
For example if you're on the homepage, as well as the usual generated classes, the `<body>` element would also have `front` and `main-page` classes. Then if you were on the "About" page it would have `inner-page` and `sixcol` classes... | Found a fix.
Seems pagination is breaking the display of the the Pages hierarchy in the metabox.
Here is the fix to disable page pagination in the nav menu metabox
<https://core.trac.wordpress.org/attachment/ticket/18282/18282-disable-nav-menu-pagination.patch>
Thanks |
156,103 | <p>I modified this code to use for a basic useful link library, I found the code at <a href="https://stackoverflow.com/questions/8643508/how-to-group-articles-by-tags/8645453#8645453">https://stackoverflow.com/questions/8643508/how-to-group-articles-by-tags/8645453#8645453</a>. </p>
<pre><code><?php
$args = array(
... | [
{
"answer_id": 156169,
"author": "pyverret",
"author_id": 57252,
"author_profile": "https://wordpress.stackexchange.com/users/57252",
"pm_score": 2,
"selected": true,
"text": "<p>Found a fix.</p>\n\n<p>Seems pagination is breaking the display of the the Pages hierarchy in the metabox.</p... | 2014/07/28 | [
"https://wordpress.stackexchange.com/questions/156103",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57272/"
] | I modified this code to use for a basic useful link library, I found the code at <https://stackoverflow.com/questions/8643508/how-to-group-articles-by-tags/8645453#8645453>.
```
<?php
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'taxonomy' => 'useful_l... | Found a fix.
Seems pagination is breaking the display of the the Pages hierarchy in the metabox.
Here is the fix to disable page pagination in the nav menu metabox
<https://core.trac.wordpress.org/attachment/ticket/18282/18282-disable-nav-menu-pagination.patch>
Thanks |
156,130 | <p>ok, i have at site a blog.mysite.com, and recently migrated all content to a new wp install at mysite.com.</p>
<p>i want to redirect all of the posts from blog.mysite.com to mysite.com and also account for permalink structure.</p>
<p>blog.mysite.com is /%year%/%monthnum%/%day%/%postname%/</p>
<p>mysite.com is /%c... | [
{
"answer_id": 156131,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 0,
"selected": false,
"text": "<p>yes, use the redirection plugin. redirect all traffic from blog.mysite.com to mysite.com and use the plug... | 2014/07/29 | [
"https://wordpress.stackexchange.com/questions/156130",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8513/"
] | ok, i have at site a blog.mysite.com, and recently migrated all content to a new wp install at mysite.com.
i want to redirect all of the posts from blog.mysite.com to mysite.com and also account for permalink structure.
blog.mysite.com is /%year%/%monthnum%/%day%/%postname%/
mysite.com is /%category%/%postname%/
th... | this was the answer via htaccess (to be placed in htaccess within the blog.mysite.com directory).
```
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:blog\.)site\.com$ [NC]
RewriteRule ^ http://site.com%{REQUEST_URI} [L,R=301]
``` |
156,157 | <p>I have a perplexing problem with Wordpress. When pages under /admin/ loads "load-scripts.php" with "plupload" as one of the arguments, it hangs for ever. The "Add New Post" page is one such page. For example, this URL hangs for ever:</p>
<p><a href="http://example.com/wp-admin/load-scripts.php?c=0&load%5B%5D=jq... | [
{
"answer_id": 161676,
"author": "user3851351",
"author_id": 59831,
"author_profile": "https://wordpress.stackexchange.com/users/59831",
"pm_score": 0,
"selected": false,
"text": "<p>I know you said you had this problem with Apache too, but I can only speak for Nginx. I found this while ... | 2014/07/29 | [
"https://wordpress.stackexchange.com/questions/156157",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57293/"
] | I have a perplexing problem with Wordpress. When pages under /admin/ loads "load-scripts.php" with "plupload" as one of the arguments, it hangs for ever. The "Add New Post" page is one such page. For example, this URL hangs for ever:
<http://example.com/wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migra... | Short and anticlimactic answer: the big fancy corporate firewall protecting the server was set to HTTP "application" mode. We switched it over to simply allowing all traffic on port "80" and the issue was solved. [Rarst♦ was right!](https://wordpress.stackexchange.com/questions/156157/load-scripts-php-hangs-and-times-o... |
156,165 | <p>I want to add a custom class to anchors in <code>wp_nav_menu</code> outputs.</p>
<p>Default for example is: </p>
<pre><code><li id="menu-item" class="menu-item menu-item-type-custom">
<a href="http://example.com">example</a>
</li>
</code></pre>
<p>I want this : </p>
<pre><code><li ... | [
{
"answer_id": 156180,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 2,
"selected": false,
"text": "<p>You can add classes natively via interface in admin. Open <code>Screen Options</code> (top right of the screen) and... | 2014/07/29 | [
"https://wordpress.stackexchange.com/questions/156165",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/48376/"
] | I want to add a custom class to anchors in `wp_nav_menu` outputs.
Default for example is:
```
<li id="menu-item" class="menu-item menu-item-type-custom">
<a href="http://example.com">example</a>
</li>
```
I want this :
```
<li id="menu-item" class="menu-item menu-item-type-custom ">
<a href="http://examp... | You can do this with the [`nav_menu_link_attributes`](https://codex.wordpress.org/Plugin_API/Filter_Reference/nav_menu_link_attributes) filter.
```
add_filter( 'nav_menu_link_attributes', 'wpse156165_menu_add_class', 10, 3 );
function wpse156165_menu_add_class( $atts, $item, $args ) {
$class = 'class'; // or some... |
156,186 | <p>i want to add a class to all links inside of the_content, that point to other interal content, f.ex. other posts and pages. i want to do this automatically. dunno if the best practise would be, to look for content or try to hook into the tinymce editor.. and eather way around, i don't know how..</p>
<p>this is what... | [
{
"answer_id": 156189,
"author": "jbyrne2007",
"author_id": 54265,
"author_profile": "https://wordpress.stackexchange.com/users/54265",
"pm_score": -1,
"selected": false,
"text": "<p>You can do this in jquery on document load. Using addClass</p>\n\n<pre><code>$(\"#DivName\").find(\"a\").... | 2014/07/29 | [
"https://wordpress.stackexchange.com/questions/156186",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10994/"
] | i want to add a class to all links inside of the\_content, that point to other interal content, f.ex. other posts and pages. i want to do this automatically. dunno if the best practise would be, to look for content or try to hook into the tinymce editor.. and eather way around, i don't know how..
this is what i have:
... | i didn't want to use js, i wanted a php solution, plus i also manipulate all internal links into anchor links. in the end, you have to decide for yourself, what would be the best way for you, php or js.
this goes into functions.php inside the current theme folder.
```
add_filter('the_content', 'crawl_content');
funct... |
156,217 | <p>How can I add a link to the primary navigation menu with the <code>class="right"</code> attribute?</p>
<p>I tried to add a static link to <code>example.com/wp-logout.php?action=logout</code> but that leads to a logout confirmation page. Is there any way to make it a log out link?</p>
| [
{
"answer_id": 156261,
"author": "Chittaranjan",
"author_id": 43031,
"author_profile": "https://wordpress.stackexchange.com/users/43031",
"pm_score": 7,
"selected": true,
"text": "<p>You can achieve this using the <code>wp_nav_menu_items</code> hook. Let's have a look at the following pi... | 2014/07/29 | [
"https://wordpress.stackexchange.com/questions/156217",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/30778/"
] | How can I add a link to the primary navigation menu with the `class="right"` attribute?
I tried to add a static link to `example.com/wp-logout.php?action=logout` but that leads to a logout confirmation page. Is there any way to make it a log out link? | You can achieve this using the `wp_nav_menu_items` hook. Let's have a look at the following piece of code which shows the login/logout link on the `primary` menu location.
```
add_filter( 'wp_nav_menu_items', 'wti_loginout_menu_link', 10, 2 );
function wti_loginout_menu_link( $items, $args ) {
if ($args->theme_loc... |
156,226 | <p>I have an array of ids that correspond to terms. How do I get the full term objects for each id?</p>
<pre><code>$ids = array(1,2,3);
</code></pre>
<p>Ideally, I would love to be able to do something similar to the way <a href="https://wordpress.stackexchange.com/a/22584/27667">taxonomy queries</a> with <code>WP_Qu... | [
{
"answer_id": 156227,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 3,
"selected": true,
"text": "<p>I wonder if you mean something like <a href=\"http://codex.wordpress.org/Function_Reference/get_terms#Examples... | 2014/07/29 | [
"https://wordpress.stackexchange.com/questions/156226",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/27667/"
] | I have an array of ids that correspond to terms. How do I get the full term objects for each id?
```
$ids = array(1,2,3);
```
Ideally, I would love to be able to do something similar to the way [taxonomy queries](https://wordpress.stackexchange.com/a/22584/27667) with `WP_Query` work, but obviously with terms instea... | I wonder if you mean something like [this](http://codex.wordpress.org/Function_Reference/get_terms#Examples) modified Codex example:
```
// Fetch:
$terms = get_terms( 'category', array(
'include' => array( 1, 2, 3 ),
) );
// Output:
if ( ! empty( $terms ) && ! is_wp_error( $terms ) )
{
$li = '';
foreach... |
156,231 | <p>UPDATE************
Well I have a working solution, although not ideal. </p>
<p>Using the Genesis sandbox child theme which has a mobile nav button built-in, I was able to set that to use the primary nav menu, so that takes care of minimised desktops.</p>
<p>I then added the responsive menu plugin which allowed me ... | [
{
"answer_id": 156476,
"author": "The Maniac",
"author_id": 10966,
"author_profile": "https://wordpress.stackexchange.com/users/10966",
"pm_score": 1,
"selected": false,
"text": "<p>Its quite odd to have two themes running like you describe, but I think we can figure this out.</p>\n\n<p>... | 2014/07/29 | [
"https://wordpress.stackexchange.com/questions/156231",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/22537/"
] | UPDATE\*\*\*\*\*\*\*\*\*\*\*\*
Well I have a working solution, although not ideal.
Using the Genesis sandbox child theme which has a mobile nav button built-in, I was able to set that to use the primary nav menu, so that takes care of minimised desktops.
I then added the responsive menu plugin which allowed me to ch... | After 5 days of googling, trial and error and umpteen plugins, I finally have a solution that works for me.
I've gone back to using a common theme for both desktop and mobile visitors, but each with their own custom menu. This was made easier for me because I'm experimenting with the Genesis framework and their "Sandb... |
156,250 | <p>I am trying to add a hook to post saving using WP Frontend User</p>
<p>When the form saves and the post is created within the "save_post" function I am trying to find the value of a custom field "cf_end_date" and assign it to something else</p>
<p>I am not able to grab the custom field "cf_end_date" value fast eno... | [
{
"answer_id": 156256,
"author": "helgatheviking",
"author_id": 6477,
"author_profile": "https://wordpress.stackexchange.com/users/6477",
"pm_score": 1,
"selected": false,
"text": "<p>“Call to member function format() on a non-object” means that <code>$formatted_date</code> is not an obj... | 2014/07/30 | [
"https://wordpress.stackexchange.com/questions/156250",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57275/"
] | I am trying to add a hook to post saving using WP Frontend User
When the form saves and the post is created within the "save\_post" function I am trying to find the value of a custom field "cf\_end\_date" and assign it to something else
I am not able to grab the custom field "cf\_end\_date" value fast enough. If I go... | “Call to member function format() on a non-object” means that `$formatted_date` is not an object.
Why do you need 2 functions for this? Can't you just check the post meta for your custom field in the save routine? Especially with such a late priority the custom field should already be saved.
```
function acf_set_ex... |
156,252 | <p>I want to exclude one of the categories from my posts, which will always be the same, named "documentaires" and with the ID 20.</p>
<p>Here is the code :</p>
<pre><code><?php echo get_the_term_list( get_the_ID(), 'project_category', '', ', ' ); ?>
</code></pre>
| [
{
"answer_id": 156257,
"author": "Bindiya Patoliya",
"author_id": 34932,
"author_profile": "https://wordpress.stackexchange.com/users/34932",
"pm_score": 1,
"selected": false,
"text": "<p>Try this </p>\n\n<pre><code><?php\n $terms = get_the_terms( the_ID(), 'project_category' );\n ... | 2014/07/30 | [
"https://wordpress.stackexchange.com/questions/156252",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57351/"
] | I want to exclude one of the categories from my posts, which will always be the same, named "documentaires" and with the ID 20.
Here is the code :
```
<?php echo get_the_term_list( get_the_ID(), 'project_category', '', ', ' ); ?>
``` | By default you can't exclude terms from [`get_the_term_list`](http://codex.wordpress.org/Function_Reference/get_the_term_list). However, you can tweak the original function and make it exclude terms. The original function can be found in *wp-includes/category-template.php* lines 1277 to 1306.
Add this to your functio... |
156,274 | <p>I'm facing a problem where my title is being displayed multiple times.</p>
<p>Using the following code the page title 'News' is displayed 10 times, the same number as the number of posts I've elected to display.</p>
<pre><code><?php while ( have_posts() ) : the_post();
if( is_singular() ) { ?>
&l... | [
{
"answer_id": 156276,
"author": "user57366",
"author_id": 57366,
"author_profile": "https://wordpress.stackexchange.com/users/57366",
"pm_score": -1,
"selected": false,
"text": "<p>You can use this code.</p>\n\n<pre><code><?php\n\n// The Query\n$the_query = new WP_Query( $args );\n\n... | 2014/07/30 | [
"https://wordpress.stackexchange.com/questions/156274",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57365/"
] | I'm facing a problem where my title is being displayed multiple times.
Using the following code the page title 'News' is displayed 10 times, the same number as the number of posts I've elected to display.
```
<?php while ( have_posts() ) : the_post();
if( is_singular() ) { ?>
<h1 class="row-title"><a href... | The function [`wp_title()`](http://codex.wordpress.org/Function_Reference/wp_title) is supposed to be used to generate the text for the title tag:
```
<head>
<title><?php wp_title();?></title>
...
</head>
```
but to display the current post title within the loop, you should instead use the [`the_title()`](ht... |
156,309 | <p>I'm creating a custom options page and I have a textarea that I've turned into a TinyMCE editor using wp_editor.</p>
<p>TinyMCE displays correctly, however it breaks when I include square brackets in the $id. Here's the code I'm using for the add_settings_field function callback:</p>
<pre><code>function px_wp_edit... | [
{
"answer_id": 156317,
"author": "Jack Lenox",
"author_id": 7437,
"author_profile": "https://wordpress.stackexchange.com/users/7437",
"pm_score": 0,
"selected": false,
"text": "<p>I'm not able to test this right now, but try this:</p>\n\n<pre><code>$id = htmlentities('theme_options[px_wp... | 2014/07/30 | [
"https://wordpress.stackexchange.com/questions/156309",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14396/"
] | I'm creating a custom options page and I have a textarea that I've turned into a TinyMCE editor using wp\_editor.
TinyMCE displays correctly, however it breaks when I include square brackets in the $id. Here's the code I'm using for the add\_settings\_field function callback:
```
function px_wp_editor($args){
... | You cannot put square brackets as editor id. but you can change textarea name by.
```
wp_editor('','px_wp_editor',array('textarea_name' => 'theme_options[px_wp_editor]'));
```
the important part is, "id" and "textarea\_name" are different. |
156,322 | <p>I'm trying to populate the postmeta table with a custom value when a custom type ('my-solutions') is published. I've read a few threads, the Codex and <a href="http://www.wphub.com/run-a-function-when-post-published" rel="nofollow">Pippin's blog</a> on this matter and tried many variations, but can't get this to wo... | [
{
"answer_id": 156324,
"author": "Jack Lenox",
"author_id": 7437,
"author_profile": "https://wordpress.stackexchange.com/users/7437",
"pm_score": 0,
"selected": false,
"text": "<p>As @Howdy_McGee has said, I'd actually use the <code>publish_post</code> <a href=\"http://codex.wordpress.or... | 2014/07/30 | [
"https://wordpress.stackexchange.com/questions/156322",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/45255/"
] | I'm trying to populate the postmeta table with a custom value when a custom type ('my-solutions') is published. I've read a few threads, the Codex and [Pippin's blog](http://www.wphub.com/run-a-function-when-post-published) on this matter and tried many variations, but can't get this to work. If anyone can add or corre... | Newer New solution:
-------------------
```
function wpse153622_transition_solution( $new_status, $old_status, $post ) {
if ( $new_status != $old_status && 'publish' === $new_status && 'my-solution' === $post->post_type ) {
update_post_meta( $post_id, 'my_json', 'json' );
}
}
add_action( 'transition_p... |
156,328 | <p>After some answers I have edited my code. This is my plugin structure</p>
<pre><code>stpl1
stpl1.php
getuser.php
</code></pre>
<p>In stpl1.php I have the following code:</p>
<pre><code><?php
/*
Plugin Name: Wordpress Plugin Stijn 1
Description: Een Wordpress plugin die data uit een database haalt en invu... | [
{
"answer_id": 156324,
"author": "Jack Lenox",
"author_id": 7437,
"author_profile": "https://wordpress.stackexchange.com/users/7437",
"pm_score": 0,
"selected": false,
"text": "<p>As @Howdy_McGee has said, I'd actually use the <code>publish_post</code> <a href=\"http://codex.wordpress.or... | 2014/07/30 | [
"https://wordpress.stackexchange.com/questions/156328",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57077/"
] | After some answers I have edited my code. This is my plugin structure
```
stpl1
stpl1.php
getuser.php
```
In stpl1.php I have the following code:
```
<?php
/*
Plugin Name: Wordpress Plugin Stijn 1
Description: Een Wordpress plugin die data uit een database haalt en invult via Ajax
in een form.
Version: 1.1
... | Newer New solution:
-------------------
```
function wpse153622_transition_solution( $new_status, $old_status, $post ) {
if ( $new_status != $old_status && 'publish' === $new_status && 'my-solution' === $post->post_type ) {
update_post_meta( $post_id, 'my_json', 'json' );
}
}
add_action( 'transition_p... |
156,352 | <p>I am trying to remove the option to edit the <strong>Permalink</strong>.</p>
<p>I know how to hide it with CSS and I have. But a hacker could simply just go to Inspect Element and change <code>display: none;</code> to <code>display: block;</code> and then be able to modify the Permalink.</p>
<p>So is there a way t... | [
{
"answer_id": 156324,
"author": "Jack Lenox",
"author_id": 7437,
"author_profile": "https://wordpress.stackexchange.com/users/7437",
"pm_score": 0,
"selected": false,
"text": "<p>As @Howdy_McGee has said, I'd actually use the <code>publish_post</code> <a href=\"http://codex.wordpress.or... | 2014/07/30 | [
"https://wordpress.stackexchange.com/questions/156352",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/36110/"
] | I am trying to remove the option to edit the **Permalink**.
I know how to hide it with CSS and I have. But a hacker could simply just go to Inspect Element and change `display: none;` to `display: block;` and then be able to modify the Permalink.
So is there a way to block that option? Or can I check if the user subm... | Newer New solution:
-------------------
```
function wpse153622_transition_solution( $new_status, $old_status, $post ) {
if ( $new_status != $old_status && 'publish' === $new_status && 'my-solution' === $post->post_type ) {
update_post_meta( $post_id, 'my_json', 'json' );
}
}
add_action( 'transition_p... |
156,374 | <p>I am using this to load css styles in the admin area (for any user who is not an administrator):</p>
<pre><code>function wpse_admin_styles() {
if ( !current_user_can( 'manage_options' ) ) {
echo '<style>
.fun-stuff-here {color:aqua;}
</style>
';
}
}
ad... | [
{
"answer_id": 156324,
"author": "Jack Lenox",
"author_id": 7437,
"author_profile": "https://wordpress.stackexchange.com/users/7437",
"pm_score": 0,
"selected": false,
"text": "<p>As @Howdy_McGee has said, I'd actually use the <code>publish_post</code> <a href=\"http://codex.wordpress.or... | 2014/07/31 | [
"https://wordpress.stackexchange.com/questions/156374",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40679/"
] | I am using this to load css styles in the admin area (for any user who is not an administrator):
```
function wpse_admin_styles() {
if ( !current_user_can( 'manage_options' ) ) {
echo '<style>
.fun-stuff-here {color:aqua;}
</style>
';
}
}
add_action('admin_head', 'wp... | Newer New solution:
-------------------
```
function wpse153622_transition_solution( $new_status, $old_status, $post ) {
if ( $new_status != $old_status && 'publish' === $new_status && 'my-solution' === $post->post_type ) {
update_post_meta( $post_id, 'my_json', 'json' );
}
}
add_action( 'transition_p... |
156,386 | <p>I'm using this filter and function to display a custom, stripped-down version of the TinyMCE editor. Everything works as it should...except the 'Anchor' button will not show ('anchor')? According to the TinyMCE website (<a href="http://www.tinymce.com/wiki.php/Controls" rel="nofollow noreferrer">http://www.tinymce.c... | [
{
"answer_id": 156396,
"author": "Romain",
"author_id": 56396,
"author_profile": "https://wordpress.stackexchange.com/users/56396",
"pm_score": 0,
"selected": false,
"text": "<p>Your first filter isn't correct. 'styleselect' give you and generate a dropdown on the tinyMCE. You can't add ... | 2014/07/31 | [
"https://wordpress.stackexchange.com/questions/156386",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40679/"
] | I'm using this filter and function to display a custom, stripped-down version of the TinyMCE editor. Everything works as it should...except the 'Anchor' button will not show ('anchor')? According to the TinyMCE website (<http://www.tinymce.com/wiki.php/Controls>), that is the control to use.
**Does anyone know why the... | I had the exact same problem and found the solution to this.
The problem is that the anchor plugin for TinyMCE is not being included as part of the default Wordpress install. So while Wordpress says to include:
```
$buttons[] = 'anchor';
```
…that's not going to work because the TinyMCE plugin for anchors isn't the... |
156,398 | <p>I am creating a simple "global settings" plugin, which simply saves a few text fields. Saving works as intended, and I can retrieve my data in frontend as follows:</p>
<pre><code><?php $options = get_option('wpglobalsettings'); ?>
<?php echo $options['wpglobalsettings_image1']; ?>
</code></pre>
<p>What... | [
{
"answer_id": 156416,
"author": "Christopher Lamm",
"author_id": 31769,
"author_profile": "https://wordpress.stackexchange.com/users/31769",
"pm_score": 0,
"selected": false,
"text": "<p>Because your $options variable is limited to just the scope of the wp_global_settings_frontend() fun... | 2014/07/31 | [
"https://wordpress.stackexchange.com/questions/156398",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14378/"
] | I am creating a simple "global settings" plugin, which simply saves a few text fields. Saving works as intended, and I can retrieve my data in frontend as follows:
```
<?php $options = get_option('wpglobalsettings'); ?>
<?php echo $options['wpglobalsettings_image1']; ?>
```
What I would like though, would be to avoi... | First of all, [the\_content](http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content)
is a filter hook and not action. Secondly, it will only work when post content will be access on your site front end. You can probably make use of [global](http://codex.wordpress.org/Global_Variables) variables instead.
e... |
156,430 | <p>I want to display the tags of the posts in my main page.</p>
<p>I used:</p>
<pre><code>global $post;
the_tags();
</code></pre>
<p>But it's only showing up for my FIRST page.</p>
| [
{
"answer_id": 156432,
"author": "Chinmoy Kumar Paul",
"author_id": 57436,
"author_profile": "https://wordpress.stackexchange.com/users/57436",
"pm_score": -1,
"selected": false,
"text": "<p>try this once</p>\n\n<pre><code>$tags = get_tags();\n$html = '<div class=\"post_tags\">';\n... | 2014/07/31 | [
"https://wordpress.stackexchange.com/questions/156430",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57405/"
] | I want to display the tags of the posts in my main page.
I used:
```
global $post;
the_tags();
```
But it's only showing up for my FIRST page. | Use:
```
get_the_tags();
```
With the Post `$id`parameter so it works outside the loop
Source: [`get_the_tags`](http://codex.wordpress.org/Function_Reference/get_the_tags) |
156,514 | <p>In the user profile I provide some <code>wp_editor()</code> for user can insert some extra information the the problem happen </p>
<pre><code> foreach ($condition as $b) {
$check = $b.$lang;
?>
<div id="tabs-<?php echo $i ?>">
<?php wp_editor... | [
{
"answer_id": 156465,
"author": "gdaniel",
"author_id": 30984,
"author_profile": "https://wordpress.stackexchange.com/users/30984",
"pm_score": 0,
"selected": false,
"text": "<p>I found this filter online a while ago when I had similar issue. I wanted to display all children pages that ... | 2014/08/01 | [
"https://wordpress.stackexchange.com/questions/156514",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57481/"
] | In the user profile I provide some `wp_editor()` for user can insert some extra information the the problem happen
```
foreach ($condition as $b) {
$check = $b.$lang;
?>
<div id="tabs-<?php echo $i ?>">
<?php wp_editor(get_the_author_meta($b . $lang, $profile_i... | It's an issue with WP core that hierarchies don't display in Appearance > Menu > Product Categories tab. In that ticket you can find workarounds:
<https://core.trac.wordpress.org/ticket/18282>
For me worked partially (displayed the hierarchy to the left) this plugin, discussed in the above ticket:
<https://core.trac.w... |
156,522 | <p>I am fairly new to Wordpress and I recently noted a huge amount of traffic hitting the following:</p>
<pre><code>162.242.170.222 - - [01/Aug/2014:08:18:54 -0500] "POST /xmlrpc.php HTTP/1.0" 503 4859
162.242.170.222 - - [01/Aug/2014:08:19:01 -0500] "POST /xmlrpc.php HTTP/1.0" 503 4859
162.242.170.222 - - [01/Aug/201... | [
{
"answer_id": 156523,
"author": "YaFred",
"author_id": 36853,
"author_profile": "https://wordpress.stackexchange.com/users/36853",
"pm_score": 3,
"selected": true,
"text": "<p>There are plugins for that: e.g. <a href=\"http://wordpress.org/plugins/disable-xml-rpc/\" rel=\"nofollow\">htt... | 2014/08/01 | [
"https://wordpress.stackexchange.com/questions/156522",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57487/"
] | I am fairly new to Wordpress and I recently noted a huge amount of traffic hitting the following:
```
162.242.170.222 - - [01/Aug/2014:08:18:54 -0500] "POST /xmlrpc.php HTTP/1.0" 503 4859
162.242.170.222 - - [01/Aug/2014:08:19:01 -0500] "POST /xmlrpc.php HTTP/1.0" 503 4859
162.242.170.222 - - [01/Aug/2014:08:19:01 -05... | There are plugins for that: e.g. <http://wordpress.org/plugins/disable-xml-rpc/>
You can also write a filter yourself
```
add_filter('xmlrpc_enabled', '__return_false');
```
You can simply add this code your theme functions.php (located in wp-content/themes/your\_theme).
However, you are advised to create a child... |
156,539 | <p>Why doesent this work?!
I want to update my postmeta "doors" from frontend</p>
<pre><code><?php
if ( isset( $_POST['submit'] ) )
{ //if nonce check succeeds.
global $post;
$postid = $post->ID;
$data = $_POST['doors'];
update_post_meta($postid, 'doors', '2' );
echo s... | [
{
"answer_id": 156523,
"author": "YaFred",
"author_id": 36853,
"author_profile": "https://wordpress.stackexchange.com/users/36853",
"pm_score": 3,
"selected": true,
"text": "<p>There are plugins for that: e.g. <a href=\"http://wordpress.org/plugins/disable-xml-rpc/\" rel=\"nofollow\">htt... | 2014/08/01 | [
"https://wordpress.stackexchange.com/questions/156539",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57498/"
] | Why doesent this work?!
I want to update my postmeta "doors" from frontend
```
<?php
if ( isset( $_POST['submit'] ) )
{ //if nonce check succeeds.
global $post;
$postid = $post->ID;
$data = $_POST['doors'];
update_post_meta($postid, 'doors', '2' );
echo self::$auto_id. 'door... | There are plugins for that: e.g. <http://wordpress.org/plugins/disable-xml-rpc/>
You can also write a filter yourself
```
add_filter('xmlrpc_enabled', '__return_false');
```
You can simply add this code your theme functions.php (located in wp-content/themes/your\_theme).
However, you are advised to create a child... |
156,543 | <p>I currently have the following function in my <code>functions.php</code> which checks if a username exists in the DB.</p>
<pre><code>function check_username() {
$username = $_POST['user'];
if ( username_exists( $username ) ) {
$return['user_exists'] = true;
}
else {
... | [
{
"answer_id": 156544,
"author": "Chinmoy Kumar Paul",
"author_id": 57436,
"author_profile": "https://wordpress.stackexchange.com/users/57436",
"pm_score": 3,
"selected": true,
"text": "<p>Please change the type </p>\n\n<p><code>type : \"GET\",</code></p>\n\n<p>to</p>\n\n<p><code>type : ... | 2014/08/01 | [
"https://wordpress.stackexchange.com/questions/156543",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/54163/"
] | I currently have the following function in my `functions.php` which checks if a username exists in the DB.
```
function check_username() {
$username = $_POST['user'];
if ( username_exists( $username ) ) {
$return['user_exists'] = true;
}
else {
$return['user_exists'] ... | Please change the type
`type : "GET",`
to
`type : "POST",` |
156,569 | <p>I'm using the following function in functions.php to check if a username exists in the DB</p>
<pre><code>function check_username() {
$username = $_POST['user'];
if ( username_exists( $username ) ) {
$return['user_exists'] = true;
}
else {
$return['user_exists'] = false;
}
echo json_... | [
{
"answer_id": 156573,
"author": "Rajeev Vyas",
"author_id": 6961,
"author_profile": "https://wordpress.stackexchange.com/users/6961",
"pm_score": 0,
"selected": false,
"text": "<p>You need to include wp-includes/user.php file when you are using ajax for user related functions.</p>\n\n<p... | 2014/08/02 | [
"https://wordpress.stackexchange.com/questions/156569",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/54163/"
] | I'm using the following function in functions.php to check if a username exists in the DB
```
function check_username() {
$username = $_POST['user'];
if ( username_exists( $username ) ) {
$return['user_exists'] = true;
}
else {
$return['user_exists'] = false;
}
echo json_encode($return... | When using Ajax API, and you want to make the ajax callback available for non-logged users, you need to add 2 actions, `"wp_ajax_{$action}"` and `"wp_ajax_nopriv_{$action}"`.
Using only the first action, the callback will be called only for logged users, using only the second it will be called only for non-logged visi... |
156,577 | <p>I need that the main page of my site have 3 columns:
- The first having the 5 most viewed posts;
- The second with the next 5 most viewed posts;
- The third with the most recent posts.</p>
<p>I don't want the posts to be never repeated in the same column or another column, so I'm using wp_query to get the posts I w... | [
{
"answer_id": 156630,
"author": "bonger",
"author_id": 57034,
"author_profile": "https://wordpress.stackexchange.com/users/57034",
"pm_score": 0,
"selected": false,
"text": "<p>You could recreate the <code>$loaded</code> array from the database:</p>\n\n<pre><code>$hot_ppp = 3;\n$next_pp... | 2014/08/02 | [
"https://wordpress.stackexchange.com/questions/156577",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57523/"
] | I need that the main page of my site have 3 columns:
- The first having the 5 most viewed posts;
- The second with the next 5 most viewed posts;
- The third with the most recent posts.
I don't want the posts to be never repeated in the same column or another column, so I'm using wp\_query to get the posts I want, in t... | This might not solve your problem, but it will help you in future to create custom queries. Paginating more than one query can get extremely tricky. By default the build in pagination in Wordpress don't have this logic to paginate multiple queries. You will have to run multiple queries and merge them in some way.
OK,... |
156,608 | <p>The following code (old post is <a href="https://wordpress.stackexchange.com/questions/80087/enable-recent-comments-widget-to-display-comments-on-attachment-posts">here</a> and author is <a href="https://wordpress.stackexchange.com/users/25765/diggy">diggy</a>) is useful, but i'd like display post and page on recent... | [
{
"answer_id": 156609,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 1,
"selected": false,
"text": "<p>There are several sides to this. What it should be <em>ideally</em>, what is <em>is</em> practically, and what it u... | 2014/08/02 | [
"https://wordpress.stackexchange.com/questions/156608",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/55102/"
] | The following code (old post is [here](https://wordpress.stackexchange.com/questions/80087/enable-recent-comments-widget-to-display-comments-on-attachment-posts) and author is [diggy](https://wordpress.stackexchange.com/users/25765/diggy)) is useful, but i'd like display post and page on recent comments widget, not onl... | There are several sides to this. What it should be *ideally*, what is *is* practically, and what it usually *has* to be practically.
There are two contexts to the writing files in WordPress.
Just do it with PHP
-------------------
The locked down hardest scenario here is that only `uploads` is writable. Otherwise co... |
156,620 | <p>I'm a bit of a wordpress noob and I'm diving head first into a course creation plugin. The structure will go <strong>program > course > level > lesson</strong>. Right now I have lessons set up as a custom post type and levels, courses and programs are taxonomies. Basically I could use help creating a navigation p... | [
{
"answer_id": 156622,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 2,
"selected": false,
"text": "<p>You are using taxonomies to model a hierarchy. I think this is not a good solution. Terms in a taxonomy are not mutua... | 2014/08/03 | [
"https://wordpress.stackexchange.com/questions/156620",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57391/"
] | I'm a bit of a wordpress noob and I'm diving head first into a course creation plugin. The structure will go **program > course > level > lesson**. Right now I have lessons set up as a custom post type and levels, courses and programs are taxonomies. Basically I could use help creating a navigation path where you first... | Your data model is interesting. You can answer this question better than me, but I don't know if we really can say, as @toscho does, that a lesson will never be shared between courses, or that no two levels will have the same lesson in.
I believe that a lesson and a course are both post-like things, but a level is som... |
156,626 | <p>Not sure why <a href="https://wordpress.stackexchange.com/questions/38207/special-characters-in-wordpress-utf-8">this thread was closed</a>, but this is the same issue inflicting many people. </p>
<p>All my WP config settings are in order: </p>
<pre><code>//define('DB_CHARSET', 'utf8');
//define('DB_CHARSET', 'utf... | [
{
"answer_id": 156670,
"author": "josh",
"author_id": 24323,
"author_profile": "https://wordpress.stackexchange.com/users/24323",
"pm_score": 3,
"selected": false,
"text": "<p>This is typically caused when you are copying/pasting MS Word information into the WordPress content editor. Wo... | 2014/08/03 | [
"https://wordpress.stackexchange.com/questions/156626",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16142/"
] | Not sure why [this thread was closed](https://wordpress.stackexchange.com/questions/38207/special-characters-in-wordpress-utf-8), but this is the same issue inflicting many people.
All my WP config settings are in order:
```
//define('DB_CHARSET', 'utf8');
//define('DB_CHARSET', 'utf8_unicode_ci');
//define('DB_COL... | This is typically caused when you are copying/pasting MS Word information into the WordPress content editor. WordPress uses something called "Smart Quotes", via a function named [wptexturize()](http://codex.wordpress.org/Function_Reference/wptexturize).
**Ideal Solution**
The ideal solution would be to go back throug... |
156,642 | <p>I have a multi-wordpress installation (3.x) with 5 sites and only one of them is using SSL.</p>
<p>All of these are running on their own domain, and the <a href="http://ssldomain.com" rel="nofollow noreferrer">http://ssldomain.com</a> forwards to <a href="https://ssldomain.com" rel="nofollow noreferrer">https://ssl... | [
{
"answer_id": 172746,
"author": "Bikram Pahi",
"author_id": 64976,
"author_profile": "https://wordpress.stackexchange.com/users/64976",
"pm_score": -1,
"selected": false,
"text": "<p>We can add https in very simple way.... No need to had code all these in any hook....</p>\n\n<ol>\n<li>L... | 2014/08/03 | [
"https://wordpress.stackexchange.com/questions/156642",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/944/"
] | I have a multi-wordpress installation (3.x) with 5 sites and only one of them is using SSL.
All of these are running on their own domain, and the <http://ssldomain.com> forwards to <https://ssldomain.com>.
Still, this seems to break wordpress upgrades.
Now I get a message:
Upgrade Network
<https://nonsecureddomai... | This is an old question, but I figured I'd post my answer as I just had to deal with this problem and figured out a temporary workaround that got it to work for me.
WARNING: This requires modifying core which is NOT recommended. If you use this workaround, you should probably remove the workaround when you've finished... |
156,644 | <p>I am very new in WordPress development and I have the folglowing problem.</p>
<p>I use this function (declared into the <strong>functions.php</strong> file of my theme) to modify the <strong>main query</strong> in such a way that the post having a specific tag are not displayed in my homepage:</p>
<pre><code>funct... | [
{
"answer_id": 156653,
"author": "adrian7",
"author_id": 7171,
"author_profile": "https://wordpress.stackexchange.com/users/7171",
"pm_score": 0,
"selected": false,
"text": "<p>Please check the <a href=\"http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters\" rel=\"nofo... | 2014/08/03 | [
"https://wordpress.stackexchange.com/questions/156644",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/29275/"
] | I am very new in WordPress development and I have the folglowing problem.
I use this function (declared into the **functions.php** file of my theme) to modify the **main query** in such a way that the post having a specific tag are not displayed in my homepage:
```
function exclude_featured_tag_and_legacy_posts( $que... | [`pre_get_posts`](http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts) and [`WP_Query`](http://codex.wordpress.org/Class_Reference/WP_Query) uses the exact same parameters, so if you need to know which parameters you can use with `pre_get_posts`, simply visit the `WP_Query` page in the codex.
There is... |
156,645 | <pre><code>if ( ! is_admin() ) {
add_filter( 'wp_get_nav_menu_items', 'display_last_posts_for_menu_item_ts', 10, 3 );
}
function display_last_posts_for_menu_item_ts( $items, $menu, $args ) {
$menu_order = count($items); /* Offset menu order */
$post_ids = array(250,973);
$args = array ( 'include' => $p... | [
{
"answer_id": 156652,
"author": "adrian7",
"author_id": 7171,
"author_profile": "https://wordpress.stackexchange.com/users/7171",
"pm_score": 3,
"selected": true,
"text": "<p>That's because object properties are case sensitive, thus <code>$post->ID</code> is not the same as <code>$po... | 2014/08/03 | [
"https://wordpress.stackexchange.com/questions/156645",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/44326/"
] | ```
if ( ! is_admin() ) {
add_filter( 'wp_get_nav_menu_items', 'display_last_posts_for_menu_item_ts', 10, 3 );
}
function display_last_posts_for_menu_item_ts( $items, $menu, $args ) {
$menu_order = count($items); /* Offset menu order */
$post_ids = array(250,973);
$args = array ( 'include' => $post_ids );... | That's because object properties are case sensitive, thus `$post->ID` is not the same as `$post->id` .
Just by printing out these two you'll notice the difference, or do a print\_r of the `$post` object to see all of the available properties and methods. |