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 |
|---|---|---|---|---|---|---|
185,318 | <p>From what I understand <code>esc_attr_e</code> is ideally used for escaping values in attributes - Is it right that the usage of <code>esc_attr_e</code> can also be worked in with non attribute values, such as the h3 and label elements in the example below?</p>
<pre><code><h3><?php esc_attr_e( 'Some Text',... | [
{
"answer_id": 185320,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 2,
"selected": false,
"text": "<p>I would suggest using <code>esc_html</code> instead of <code>esc_attr</code> for that, e.g.</p>\n\n<pre><cod... | 2015/04/25 | [
"https://wordpress.stackexchange.com/questions/185318",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/70831/"
] | From what I understand `esc_attr_e` is ideally used for escaping values in attributes - Is it right that the usage of `esc_attr_e` can also be worked in with non attribute values, such as the h3 and label elements in the example below?
```
<h3><?php esc_attr_e( 'Some Text', 'my-plugin' ); ?></h3>
<form name="myplugin... | I would suggest using `esc_html` instead of `esc_attr` for that, e.g.
```
<a href="<?php echo esc_url( $url );?>" class="<?php echo esc_attr( $classes ); ?>">
<?php echo esc_html( $title ); ?>
</a>
<div>
<?php echo wp_kses_post( $html_with_safe_tags );?>
</div>
<script>
<?php echo wp_json_encode( $data_for... |
185,326 | <p>I'm creating a custom registration form which works using username and email inputs, but when I include First and Last name fields it won't let me register. </p>
<p>Here is the form: </p>
<pre><code><form id="_wb_register" action="<?php echo home_url(); ?>" method="post">
<p>
<la... | [
{
"answer_id": 185320,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 2,
"selected": false,
"text": "<p>I would suggest using <code>esc_html</code> instead of <code>esc_attr</code> for that, e.g.</p>\n\n<pre><cod... | 2015/04/25 | [
"https://wordpress.stackexchange.com/questions/185326",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/70006/"
] | I'm creating a custom registration form which works using username and email inputs, but when I include First and Last name fields it won't let me register.
Here is the form:
```
<form id="_wb_register" action="<?php echo home_url(); ?>" method="post">
<p>
<label for="_wb_register_username"><?php _e('... | I would suggest using `esc_html` instead of `esc_attr` for that, e.g.
```
<a href="<?php echo esc_url( $url );?>" class="<?php echo esc_attr( $classes ); ?>">
<?php echo esc_html( $title ); ?>
</a>
<div>
<?php echo wp_kses_post( $html_with_safe_tags );?>
</div>
<script>
<?php echo wp_json_encode( $data_for... |
185,340 | <p>I have a custom PHP application and a Wordpress instance running as 2 completely separate codebases on the same server. I would like my custom PHP application to be able to consume content from the Wordpress instance as and when it is published or updated.</p>
<p>I am using the excellent <a href="http://wp-api.org/... | [
{
"answer_id": 185348,
"author": "gpnalin",
"author_id": 68734,
"author_profile": "https://wordpress.stackexchange.com/users/68734",
"pm_score": -1,
"selected": false,
"text": "<p>You can use WP's <a href=\"https://codex.wordpress.org/Plugin_API/Action_Reference/save_post\" rel=\"nofollo... | 2015/04/25 | [
"https://wordpress.stackexchange.com/questions/185340",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71163/"
] | I have a custom PHP application and a Wordpress instance running as 2 completely separate codebases on the same server. I would like my custom PHP application to be able to consume content from the Wordpress instance as and when it is published or updated.
I am using the excellent [WP API](http://wp-api.org/) to retri... | Use the [HTTP API](https://codex.wordpress.org/HTTP_API) to send a "ping" on the `wp_insert_post` action, which is fired whenever a post is created/updated:
```
/**
* @param int $post_id The ID of the post.
* @param WP_Post $post The post object.
* @param bool $update True if the post alre... |
185,359 | <p>My category structure is as follows:</p>
<pre><code>- Top Category
---- Sub Category 1
------- Sub Sub Category 1.1
------- Sub Sub Category 1.2
------- Sub Sub Category 1.3
---- Sub Category 2
------- Sub Sub Category 2.1
------- Sub Sub Category 2.2
------- Sub Sub Category 2.3
</code></pre>
<p>I'm on a post und... | [
{
"answer_id": 212570,
"author": "thebigtine",
"author_id": 76059,
"author_profile": "https://wordpress.stackexchange.com/users/76059",
"pm_score": 2,
"selected": false,
"text": "<p><a href=\"http://codex.wordpress.org/Function_Reference/get_ancestors\" rel=\"nofollow\"><code>get_ancesto... | 2015/04/25 | [
"https://wordpress.stackexchange.com/questions/185359",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56525/"
] | My category structure is as follows:
```
- Top Category
---- Sub Category 1
------- Sub Sub Category 1.1
------- Sub Sub Category 1.2
------- Sub Sub Category 1.3
---- Sub Category 2
------- Sub Sub Category 2.1
------- Sub Sub Category 2.2
------- Sub Sub Category 2.3
```
I'm on a post under 1.2 so it would be:
``... | [`get_ancestors()`](http://codex.wordpress.org/Function_Reference/get_ancestors) returns an array containing the parents of any given object.
This example has two categories. The parent with the id of 447 and the child with a id of 448 and returns the a category hierarchy (with IDs):
```
get_ancestors( 448, 'categor... |
185,366 | <p>I'm currently transitioning a website from their existing CMS to WordPress.</p>
<p>I have a custom post type of 'Episodes', with a URL of myurl.com/episodes/</p>
<p>There is also an existing directory at myurl.com/episodes/ which needs to remain in place for historical reasons - it contains a large number of image... | [
{
"answer_id": 185369,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 1,
"selected": false,
"text": "<p>Not using WordPress. With that directory in place, your web server doesn't even touch WordPress when it hand... | 2015/04/25 | [
"https://wordpress.stackexchange.com/questions/185366",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71175/"
] | I'm currently transitioning a website from their existing CMS to WordPress.
I have a custom post type of 'Episodes', with a URL of myurl.com/episodes/
There is also an existing directory at myurl.com/episodes/ which needs to remain in place for historical reasons - it contains a large number of images and static HTML... | Not using WordPress. With that directory in place, your web server doesn't even touch WordPress when it handles the request.
I would:
* Move as much of your stuff as possible away from using that folder
* Rename the rewrite rule so that it's not just `/episodes/` so that it doesn't clash
You could try moving the fol... |
185,444 | <p>I would like to use a different menu for my mobile website than my desktop website. With different I mean the content not the layout. I just want to use the mobile menu of the twentytwelve theme.</p>
<p>What I've done so far:</p>
<p>In my child functions.php i've added the following code:</p>
<pre><code> regi... | [
{
"answer_id": 190832,
"author": "Nikolai",
"author_id": 74343,
"author_profile": "https://wordpress.stackexchange.com/users/74343",
"pm_score": 3,
"selected": false,
"text": "<p>As recommended in a similar post: <a href=\"https://wordpress.stackexchange.com/a/156494/74343\">https://word... | 2015/04/26 | [
"https://wordpress.stackexchange.com/questions/185444",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71216/"
] | I would like to use a different menu for my mobile website than my desktop website. With different I mean the content not the layout. I just want to use the mobile menu of the twentytwelve theme.
What I've done so far:
In my child functions.php i've added the following code:
```
register_nav_menus( array(
... | As recommended in a similar post: <https://wordpress.stackexchange.com/a/156494/74343>
1.) Create the [menus](https://codex.wordpress.org/Appearance_Menus_Screen) as you want them, and name them as you like, as an example "**mobile-menu**" and "**desktop-menu**".
2.) In your [child theme](https://codex.wordpress.org... |
185,456 | <p>Is it possible to display the author on all pages (not blog-entries) who created it? Every plugin I find is for blog-posts. </p>
| [
{
"answer_id": 185459,
"author": "Ben H",
"author_id": 64567,
"author_profile": "https://wordpress.stackexchange.com/users/64567",
"pm_score": 1,
"selected": false,
"text": "<p>If I have understood correctly you should be able to edit your page template to include the below. I'm not sure... | 2015/04/26 | [
"https://wordpress.stackexchange.com/questions/185456",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71223/"
] | Is it possible to display the author on all pages (not blog-entries) who created it? Every plugin I find is for blog-posts. | You need to add the following code to content-page.php in your theme folder.
```
<?php the_author(); ?>
``` |
185,462 | <p>We have one custom requirement that when we add an image (suppose a car image) in the homepage, after that when I'm creating a new page, I always want that car image to appear on the right hand side by default. So whenever I'm changing the homepage car image to some other image, it should reflect on other pages also... | [
{
"answer_id": 185459,
"author": "Ben H",
"author_id": 64567,
"author_profile": "https://wordpress.stackexchange.com/users/64567",
"pm_score": 1,
"selected": false,
"text": "<p>If I have understood correctly you should be able to edit your page template to include the below. I'm not sure... | 2015/04/26 | [
"https://wordpress.stackexchange.com/questions/185462",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71224/"
] | We have one custom requirement that when we add an image (suppose a car image) in the homepage, after that when I'm creating a new page, I always want that car image to appear on the right hand side by default. So whenever I'm changing the homepage car image to some other image, it should reflect on other pages also.
... | You need to add the following code to content-page.php in your theme folder.
```
<?php the_author(); ?>
``` |
185,473 | <p>I am trying to do a query to grab all the pages that have the tickbox checked <code>"feature_on_front_page"</code> which has the value <code>"featured"</code> with label <code>"Featured"</code>.</p>
<p>I added this checkbox with ACF.</p>
<p>My query is:</p>
<pre><code> <?php wp_reset_query(); // Restor... | [
{
"answer_id": 185477,
"author": "Rituparna sonowal",
"author_id": 71232,
"author_profile": "https://wordpress.stackexchange.com/users/71232",
"pm_score": -1,
"selected": false,
"text": "<p>Try \"posts_per_page\" in place of \"numberposts\". numberposts is not a valid parameter of WP_Que... | 2015/04/26 | [
"https://wordpress.stackexchange.com/questions/185473",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/70230/"
] | I am trying to do a query to grab all the pages that have the tickbox checked `"feature_on_front_page"` which has the value `"featured"` with label `"Featured"`.
I added this checkbox with ACF.
My query is:
```
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
<?php
... | UPDATE: Ok this should work, according to ACF's documentation:
```
$args = array(
'posts_per_page' => -1,
'post_type' => 'page',
'meta_query' => array(
array(
'key' => 'feature_on_front_page',
'value' => 'featured',
'compare' => 'LIKE'
... |
185,511 | <p>I am using the below in my wordpress for developing a oauth based application.</p>
<p><strong>WP-API</strong> (api generating plugin)</p>
<p><strong>WP API OAuth1</strong> (oauth server)and </p>
<p><strong>WP API client-cli</strong> (oauth client library)</p>
<p>at the below url is for the wp client-cli
<a href=... | [
{
"answer_id": 201885,
"author": "bilalshahid10",
"author_id": 79978,
"author_profile": "https://wordpress.stackexchange.com/users/79978",
"pm_score": 1,
"selected": true,
"text": "<p>I was facing a similar issue when trying to use Client-CLI with OAuth 1.0a plugin, however I found a sol... | 2015/04/27 | [
"https://wordpress.stackexchange.com/questions/185511",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71251/"
] | I am using the below in my wordpress for developing a oauth based application.
**WP-API** (api generating plugin)
**WP API OAuth1** (oauth server)and
**WP API client-cli** (oauth client library)
at the below url is for the wp client-cli
<https://man-sudarshann-1.c9.io/api/>
I am getting this error **OAuth signatu... | I was facing a similar issue when trying to use Client-CLI with OAuth 1.0a plugin, however I found a solution [here](https://github.com/WP-API/OAuth1/pull/32) on the official repository.
In the file `lib/class-wp-json-authentication-oauth1.php` on line `524`, change the following code:
```
$base_request_uri = rawurle... |
185,512 | <p>Currently I'm working on a plugin that will display a grid based on post type with many settings to customize it. One of the settings will be to choose between different skins available to display inside the grid.</p>
<p>I would like to offer the possibility to developers to include their own skins with a custom HO... | [
{
"answer_id": 201885,
"author": "bilalshahid10",
"author_id": 79978,
"author_profile": "https://wordpress.stackexchange.com/users/79978",
"pm_score": 1,
"selected": true,
"text": "<p>I was facing a similar issue when trying to use Client-CLI with OAuth 1.0a plugin, however I found a sol... | 2015/04/27 | [
"https://wordpress.stackexchange.com/questions/185512",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/35097/"
] | Currently I'm working on a plugin that will display a grid based on post type with many settings to customize it. One of the settings will be to choose between different skins available to display inside the grid.
I would like to offer the possibility to developers to include their own skins with a custom HOOK/Filter.... | I was facing a similar issue when trying to use Client-CLI with OAuth 1.0a plugin, however I found a solution [here](https://github.com/WP-API/OAuth1/pull/32) on the official repository.
In the file `lib/class-wp-json-authentication-oauth1.php` on line `524`, change the following code:
```
$base_request_uri = rawurle... |
185,519 | <p>I need to get the current plugin name using a define like this</p>
<pre><code>define(PLUGIN_NAME, plugin_basename(dirname(__FILE__)));
</code></pre>
<p>Regrettably, that code doesn't work because the php file is nested inside a subdirectory (includes) of my plugin directory and it returns</p>
<pre><code>my-plugin... | [
{
"answer_id": 239497,
"author": "Mark Howells-Mead",
"author_id": 83412,
"author_profile": "https://wordpress.stackexchange.com/users/83412",
"pm_score": 3,
"selected": false,
"text": "<p>Within the plugin's main PHP file:</p>\n\n<pre><code>$plugin_data = get_plugin_data( __FILE__ );\n$... | 2015/04/27 | [
"https://wordpress.stackexchange.com/questions/185519",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/70174/"
] | I need to get the current plugin name using a define like this
```
define(PLUGIN_NAME, plugin_basename(dirname(__FILE__)));
```
Regrettably, that code doesn't work because the php file is nested inside a subdirectory (includes) of my plugin directory and it returns
```
my-plugin/includes
```
Is there any functio... | Within the plugin's main PHP file:
```
$plugin_data = get_plugin_data( __FILE__ );
$plugin_name = $plugin_data['Name'];
``` |
185,524 | <p>I have a regular business website that I built on Wordpress - www.example.com</p>
<p>I have a blog page in my website under - www.example.com/blog </p>
<p>When viewing a blog post it looks like this: www.exmaple.com/[category]/[posts-name] </p>
<p>How can I add "/blog" to this URL before the category?
like this:... | [
{
"answer_id": 185525,
"author": "cybmeta",
"author_id": 37428,
"author_profile": "https://wordpress.stackexchange.com/users/37428",
"pm_score": 2,
"selected": true,
"text": "<p>You can not do that viw .htaccess because .htacces rules can not control how the permalinks are generated by W... | 2015/04/27 | [
"https://wordpress.stackexchange.com/questions/185524",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/75062/"
] | I have a regular business website that I built on Wordpress - www.example.com
I have a blog page in my website under - www.example.com/blog
When viewing a blog post it looks like this: www.exmaple.com/[category]/[posts-name]
How can I add "/blog" to this URL before the category?
like this: www.exmaple.com/blog/[c... | You can not do that viw .htaccess because .htacces rules can not control how the permalinks are generated by WordPress. Instead, go to WordPress settings->permalink. Select custom structure and enter:
```
blog/%category%/%postname%
``` |
185,527 | <p>I have such a wp query args:</p>
<pre><code>$args = array(
'post_type'=> 'myposttype',
'posts_per_page' => 10,
'meta_query' => array(
'relation' => 'AND',
array('key' => 'routeFrom','value' => 'rome','compare' => 'LIKE'),
array('key' => 'routeTo','value' => 'paris','compare'... | [
{
"answer_id": 185528,
"author": "fischi",
"author_id": 15680,
"author_profile": "https://wordpress.stackexchange.com/users/15680",
"pm_score": 2,
"selected": false,
"text": "<p>You can ignore sticky posts by adding</p>\n\n<pre><code>'ignore_sticky_posts' => true,\n</code></pre>\n\n<p... | 2015/04/27 | [
"https://wordpress.stackexchange.com/questions/185527",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56604/"
] | I have such a wp query args:
```
$args = array(
'post_type'=> 'myposttype',
'posts_per_page' => 10,
'meta_query' => array(
'relation' => 'AND',
array('key' => 'routeFrom','value' => 'rome','compare' => 'LIKE'),
array('key' => 'routeTo','value' => 'paris','compare' => 'LIKE'),
)
);
```
Each my po... | Custom queries and sticky posts are quite a curve ball to work with. I don't know how your setup looks and what exactly is your user case, but your best solution here would be to run two queries here, the first one to get your sticky posts and the other one to display normal posts
Your first query's arguments will loo... |
185,530 | <p>I want to remove WordPress logo from login and register page. I think I have to make some changes in .css file for this. So I want to know in which css file do I have to make the changes?</p>
| [
{
"answer_id": 185531,
"author": "fischi",
"author_id": 15680,
"author_profile": "https://wordpress.stackexchange.com/users/15680",
"pm_score": 2,
"selected": false,
"text": "<p>You can add a filter to <code>login_head</code>. As explained in the <a href=\"http://codex.wordpress.org/Plug... | 2015/04/27 | [
"https://wordpress.stackexchange.com/questions/185530",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71258/"
] | I want to remove WordPress logo from login and register page. I think I have to make some changes in .css file for this. So I want to know in which css file do I have to make the changes? | You can add a filter to `login_head`. As explained in the [Codex](http://codex.wordpress.org/Plugin_API/Filter_Reference/login_head), add this to your code:
```
function my_custom_login_logo() {
echo '<style type="text/css">
h1 a {background-image:url(http://example.com/your-logo.png) !important; margin:0 auto... |
185,545 | <p>I am using this to localize strings in my theme </p>
<pre><code>__('Background image', 'themename');
</code></pre>
<p>there are plenty of strings that are localized but to make sure that the theme lang files and localization strings can be quickly changed, I would like to use something like this </p>
<pre><code>$... | [
{
"answer_id": 185547,
"author": "kraftner",
"author_id": 47733,
"author_profile": "https://wordpress.stackexchange.com/users/47733",
"pm_score": 3,
"selected": true,
"text": "<p>Yes this is problematic as <a href=\"https://developer.wordpress.org/themes/functionality/localization/#wordp... | 2015/04/27 | [
"https://wordpress.stackexchange.com/questions/185545",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/67176/"
] | I am using this to localize strings in my theme
```
__('Background image', 'themename');
```
there are plenty of strings that are localized but to make sure that the theme lang files and localization strings can be quickly changed, I would like to use something like this
```
$theme_name = 'themename';// this woul... | Yes this is problematic as [i18n tools](https://developer.wordpress.org/themes/functionality/localization/#wordpress-i18n-tools) that parse your theme to generate a \*.pot file for translation can't understand this as they do not run PHP code but just search your code as text.
Here is [a blogpost detailing on why this... |
185,558 | <p>I was wondering if someone could help me out. I would like to create a dropdown search filter for my wordpress site. I would like the drop downs to be populated by meta_boxes values which i have for a custom post type. I know that <code><?php echo get_post_meta($post->ID, 'meta_field', true); ?></code> is t... | [
{
"answer_id": 185565,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 1,
"selected": false,
"text": "<p>First, you have a very basic PHP mistake: <a href=\"https://php.net/manual/en/language.types.string.php#lang... | 2015/04/27 | [
"https://wordpress.stackexchange.com/questions/185558",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/67512/"
] | I was wondering if someone could help me out. I would like to create a dropdown search filter for my wordpress site. I would like the drop downs to be populated by meta\_boxes values which i have for a custom post type. I know that `<?php echo get_post_meta($post->ID, 'meta_field', true); ?>` is the way to get them but... | First, you have a very basic PHP mistake: [single quotes mean "string literal"](https://php.net/manual/en/language.types.string.php#language.types.string.syntax.single). Variables won't be processed. You are literally putting "$variable" into the generated code.
Second, look at the third parameter of `get_post_meta()... |
185,577 | <p>So WP 4.2 introduced emojis (smileys) that basically adds JS and other junk all over your pages. Something some people may find shocking. How does one completely erase all instances of this?</p>
| [
{
"answer_id": 185578,
"author": "Christine Cooper",
"author_id": 24875,
"author_profile": "https://wordpress.stackexchange.com/users/24875",
"pm_score": 9,
"selected": true,
"text": "<p>We will hook into <code>init</code> and remove actions as followed:</p>\n\n<pre><code>function disabl... | 2015/04/27 | [
"https://wordpress.stackexchange.com/questions/185577",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24875/"
] | So WP 4.2 introduced emojis (smileys) that basically adds JS and other junk all over your pages. Something some people may find shocking. How does one completely erase all instances of this? | We will hook into `init` and remove actions as followed:
```
function disable_wp_emojicons() {
// all actions related to emojis
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detecti... |
185,579 | <p>I have a file in my theme's JS folder named cycle2.js.</p>
<ol>
<li><p>How do I include the Jquery from 'wordpress→includes' into my theme?</p></li>
<li><p>How do I load this custom JavaScript file 'cycle2.js' into my theme?</p>
<p>I have:</p>
<pre><code>function watercolor_js_scripts(){
if (!is_admin()) {
w... | [
{
"answer_id": 185582,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 1,
"selected": false,
"text": "<p>Your snippet seems mostly ok, except that dependency is a list and should be <code>array('jquery')</code>. Also <co... | 2015/04/27 | [
"https://wordpress.stackexchange.com/questions/185579",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/70369/"
] | I have a file in my theme's JS folder named cycle2.js.
1. How do I include the Jquery from 'wordpress→includes' into my theme?
2. How do I load this custom JavaScript file 'cycle2.js' into my theme?
I have:
```
function watercolor_js_scripts(){
if (!is_admin()) {
wp_register_script('cycle2', get_template_direct... | Your snippet seems mostly ok, except that dependency is a list and should be `array('jquery')`. Also `wp_enqueue_scripts` should be use as more appropriate.
You can check out Codex documentation for a complete example, see [Example of Automatic Dependency Loading](https://codex.wordpress.org/Function_Reference/wp_regi... |
185,587 | <p>I've found that <code>wp_update_post()</code> escapes all ampersands provided in the post's <code>post_content</code>. I'm trying to update a post without converting ampersands to <code>&amp;</code>. (I need to add plaintext URLs (<em>not</em> links) to the <code>post_content</code> field of posts). So, I'm t... | [
{
"answer_id": 185593,
"author": "rinogo",
"author_id": 10388,
"author_profile": "https://wordpress.stackexchange.com/users/10388",
"pm_score": 1,
"selected": false,
"text": "<p>I'm not sure how WP's admin interface handles this (e.g. the scenario I referenced in the question), but I fou... | 2015/04/27 | [
"https://wordpress.stackexchange.com/questions/185587",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10388/"
] | I've found that `wp_update_post()` escapes all ampersands provided in the post's `post_content`. I'm trying to update a post without converting ampersands to `&`. (I need to add plaintext URLs (*not* links) to the `post_content` field of posts). So, I'm trying to find a way to use `wp_update_post()` with escaping d... | That is correct, the updating in the Admin section does not change the `&` to `&` while the wp\_update\_post() function (which can be found under [/wp-includes/post.php](https://github.com/WordPress/WordPress/blob/master/wp-includes/post.php) on line 3772) does but only when the user does not have the capability **... |
185,600 | <p>I have been using the same pagination query for the majority of the websites i have created. This time it is not working for some reason I have used the pagination trouble shooting links <a href="https://codex.wordpress.org/Pagination" rel="nofollow">Here</a> but nothing seems to be working. I have attached my code ... | [
{
"answer_id": 185706,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 3,
"selected": true,
"text": "<p>As I already stated in comments, you should never use <code>query_posts</code>, only use <code>query_pos... | 2015/04/27 | [
"https://wordpress.stackexchange.com/questions/185600",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/67512/"
] | I have been using the same pagination query for the majority of the websites i have created. This time it is not working for some reason I have used the pagination trouble shooting links [Here](https://codex.wordpress.org/Pagination) but nothing seems to be working. I have attached my code below.
This time i am query... | As I already stated in comments, you should never use `query_posts`, only use `query_posts` if you are intended to break your page functionalities. Add `query_posts` to the very top of your **EVIL LIST**.
`query_posts` breaks the main query object, the very object that your pagination function relies on. Your paginati... |
185,609 | <p>I'm trying to change the header menu, such that it looks different when it is logged in and logged out, without changing the main menu.</p>
<pre><code>function my_wp_nav_menu_args( $args = '' ) {
if( is_user_logged_in() ) {
$args['widget_nav_menu'] = 'menu 4';
} else {
$args['widget_nav_me... | [
{
"answer_id": 185706,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 3,
"selected": true,
"text": "<p>As I already stated in comments, you should never use <code>query_posts</code>, only use <code>query_pos... | 2015/04/28 | [
"https://wordpress.stackexchange.com/questions/185609",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71292/"
] | I'm trying to change the header menu, such that it looks different when it is logged in and logged out, without changing the main menu.
```
function my_wp_nav_menu_args( $args = '' ) {
if( is_user_logged_in() ) {
$args['widget_nav_menu'] = 'menu 4';
} else {
$args['widget_nav_menu'] = 'menu 3... | As I already stated in comments, you should never use `query_posts`, only use `query_posts` if you are intended to break your page functionalities. Add `query_posts` to the very top of your **EVIL LIST**.
`query_posts` breaks the main query object, the very object that your pagination function relies on. Your paginati... |
185,617 | <p>I am managing the WordPress website i don't have the document of the website my problem is the website has the registration page please see [this link]</p>
<p>but when i check the registration page in WordPress admin the page is blank i don't have any idea how the previous developer linked the page can anyone help ... | [
{
"answer_id": 185618,
"author": "jimihenrik",
"author_id": 64625,
"author_profile": "https://wordpress.stackexchange.com/users/64625",
"pm_score": 0,
"selected": false,
"text": "<p>Probably under your theme folder. Maybe a custom page-template, something like <code>page-register.php</co... | 2015/04/28 | [
"https://wordpress.stackexchange.com/questions/185617",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/31332/"
] | I am managing the WordPress website i don't have the document of the website my problem is the website has the registration page please see [this link]
but when i check the registration page in WordPress admin the page is blank i don't have any idea how the previous developer linked the page can anyone help where to f... | This is a `buddypress` page, linked with the page ID 4275. The body class of your delivered HTML is:
```
<body class="registration register buddypress page page-id-4275 page-template-default admin-bar no-customize-support no-js">
```
To edit this page itself, go to <http://hoteliersnetworkme.com/wp-admin/post.php?p... |
185,631 | <p>How to get the same post content for in (the default) <code>domain.com/year/month/post-slug</code> and <code>domain.com/custom/post-slug</code> (without redirect).</p>
<p>Can I do this with some kind of rewrite or do I need a custom post type with it's own permalink structure?</p>
<p>So the gist is that I want to ... | [
{
"answer_id": 185658,
"author": "user2914563",
"author_id": 68720,
"author_profile": "https://wordpress.stackexchange.com/users/68720",
"pm_score": -1,
"selected": false,
"text": "<p>I think you need to change your permalink structure for all your past posts and future posts?</p>\n\n<p>... | 2015/04/28 | [
"https://wordpress.stackexchange.com/questions/185631",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/64625/"
] | How to get the same post content for in (the default) `domain.com/year/month/post-slug` and `domain.com/custom/post-slug` (without redirect).
Can I do this with some kind of rewrite or do I need a custom post type with it's own permalink structure?
So the gist is that I want to show the same content a little differen... | I ended going the CPT route, as I couldn't figure out other way. Just added a bunch of logic to duplicate/modify/delete the normal posts when needed.
```
<?php // function for the CPT
function SU_kuuma_kysymys_type() {
// creating (registering) the custom type
register_post_type( 'kuuma_kysymys', /* (http://... |
185,639 | <p>I've downloaded <a href="http://contactform7.com/" rel="nofollow">Contact Form 7</a> to add contact forms adding a simple snippet after every post, and I've added it in functions.php like this : </p>
<pre><code>//if post type I add a form
function is_post_type($type)
{
global $wp_query;
if($type == get_pos... | [
{
"answer_id": 185642,
"author": "Sladix",
"author_id": 27423,
"author_profile": "https://wordpress.stackexchange.com/users/27423",
"pm_score": 1,
"selected": false,
"text": "<p>You can try to add a get parameter to your url in the link to your contact form.</p>\n\n<p>If it's a lightbox ... | 2015/04/28 | [
"https://wordpress.stackexchange.com/questions/185639",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/69187/"
] | I've downloaded [Contact Form 7](http://contactform7.com/) to add contact forms adding a simple snippet after every post, and I've added it in functions.php like this :
```
//if post type I add a form
function is_post_type($type)
{
global $wp_query;
if($type == get_post_type($wp_query->post->ID)) return true... | This is pretty easy out of the box:
Just use the `[_url]` special mail tag.
As long as you are on a post or page you can even add some more things like the title with `[_post_title]`.
Just have a look at [the documentation](http://contactform7.com/special-mail-tags/) for more options. |
185,650 | <p>I found similar questions to it but none was an exact match to my question.</p>
<p>I am using featured image in all my posts. I want to remove featured image on single post view from a single category (Say Video Interview) and not from multiple post view i.e. homepage.</p>
<p>In other words, From Video category I ... | [
{
"answer_id": 185666,
"author": "Guerrilla",
"author_id": 70230,
"author_profile": "https://wordpress.stackexchange.com/users/70230",
"pm_score": 1,
"selected": false,
"text": "<p>You can update the way image is displayed in template. in the page loop it will have something like this:<... | 2015/04/28 | [
"https://wordpress.stackexchange.com/questions/185650",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/68720/"
] | I found similar questions to it but none was an exact match to my question.
I am using featured image in all my posts. I want to remove featured image on single post view from a single category (Say Video Interview) and not from multiple post view i.e. homepage.
In other words, From Video category I want to show feat... | You can update the way image is displayed in template. in the page loop it will have something like this:
```
<?php the_post_thumbnail(); ?>
```
This grabs the featured image. You can wrap that in a [conditional statement](https://codex.wordpress.org/Conditional_Tags#A_Category_Page) to check for whatever you like.
... |
185,659 | <p>I am trying to investigate the correlation between the total number of posts published on a blog and the traffic it receive. I think it's not a huge task but my experience with coding with Wordpress is almost null. </p>
<p>I guess it should be something like a foreach which loops all the posts and list the publishi... | [
{
"answer_id": 185660,
"author": "jjarolim",
"author_id": 56506,
"author_profile": "https://wordpress.stackexchange.com/users/56506",
"pm_score": 2,
"selected": false,
"text": "<p>the fastest way imho would be to create a custom sql statement:</p>\n\n<pre><code>global $wpdb;\n$rows = $wp... | 2015/04/28 | [
"https://wordpress.stackexchange.com/questions/185659",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/64590/"
] | I am trying to investigate the correlation between the total number of posts published on a blog and the traffic it receive. I think it's not a huge task but my experience with coding with Wordpress is almost null.
I guess it should be something like a foreach which loops all the posts and list the publishing date fo... | the fastest way imho would be to create a custom sql statement:
```
global $wpdb;
$rows = $wpdb->query('SELECT DATE(post_date) AS date, COUNT(*) AS count FROM ' . $wpdb->posts . ' GROUP BY DATE(post_date) ORDER BY DATE(post_date)');
foreach ($rows as $row) {
echo $row->date . ': ' . $row->count . '<br>';
}
``` |
185,685 | <p>i have this custom search-result page</p>
<pre><code>global $query_string;
$query_args = explode("&", $query_string);
$search_query = array(
'nopaging' => true,
'post_type' => 'page'
);
foreach($query_args as $key => $string) {
$query_split = explode("=", $string);
... | [
{
"answer_id": 185803,
"author": "efoula",
"author_id": 42810,
"author_profile": "https://wordpress.stackexchange.com/users/42810",
"pm_score": -1,
"selected": false,
"text": "<p>Put this in your custom search page instead of your code, and don't forget to define your post types in the q... | 2015/04/28 | [
"https://wordpress.stackexchange.com/questions/185685",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/62794/"
] | i have this custom search-result page
```
global $query_string;
$query_args = explode("&", $query_string);
$search_query = array(
'nopaging' => true,
'post_type' => 'page'
);
foreach($query_args as $key => $string) {
$query_split = explode("=", $string);
$search_query[$query_spli... | You just need to get the data using `get_post_meta()`.
```
<h1><a href="<?php echo get_permalink()?>"><?php the_title(); ?></a></h1>
<span class="description">
<?php echo get_post_meta( get_the_ID(), 'mobile_adv_service_desc', true ); ?>
</span>
```
This Plugin stores your values as WordPress metadata. So to ret... |
185,693 | <p>I am aware of the option to set <code>exclude_from_search => 'true'</code> when registering a custom post type. But what are the other options?</p>
| [
{
"answer_id": 185696,
"author": "Howdy_McGee",
"author_id": 7355,
"author_profile": "https://wordpress.stackexchange.com/users/7355",
"pm_score": 3,
"selected": true,
"text": "<p>You can use the <a href=\"https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts\" rel=\"nofo... | 2015/04/28 | [
"https://wordpress.stackexchange.com/questions/185693",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/500/"
] | I am aware of the option to set `exclude_from_search => 'true'` when registering a custom post type. But what are the other options? | You can use the [`pre_get_posts`](https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts) hook. Do note though, this hook filters the query on both the front-end and admin. For example, we could do something like this:
```
function search_post_types( $query ) {
if( is_admin() ) {
return $que... |
185,699 | <p>i have a field called bookname and based on the entry in that i am trying to check the <code>posttype = books</code> and pull out the logoid when the bookname matchs but for some reason <code>get_post_thumbnail_id</code> doesn't pull out the id of the image even when its present hence doesn't set the image.</p>
<pr... | [
{
"answer_id": 185700,
"author": "fischi",
"author_id": 15680,
"author_profile": "https://wordpress.stackexchange.com/users/15680",
"pm_score": 3,
"selected": true,
"text": "<p>You need to call <code>get_post_thumbnail_id()</code> with the <code>ID</code> of the post, not the post object... | 2015/04/28 | [
"https://wordpress.stackexchange.com/questions/185699",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/50113/"
] | i have a field called bookname and based on the entry in that i am trying to check the `posttype = books` and pull out the logoid when the bookname matchs but for some reason `get_post_thumbnail_id` doesn't pull out the id of the image even when its present hence doesn't set the image.
```
$importbookname = get_field(... | You need to call `get_post_thumbnail_id()` with the `ID` of the post, not the post object.
```
$importbookcoverid = get_post_thumbnail_id( $importbookpost->ID );
```
and you should be fine. |
185,729 | <p>So I have a page (ex. site.com/start) where I want to show a login page (ex. site.com/start/login) if not logged in, in order to view the page.</p>
<p>Without using any plugin, what would be the condition logic which if user visits <code>/start</code> page, while they are not not logged in, then the user is redirec... | [
{
"answer_id": 185730,
"author": "jrothafer",
"author_id": 71024,
"author_profile": "https://wordpress.stackexchange.com/users/71024",
"pm_score": 2,
"selected": true,
"text": "<p>In a template file, this should do it:</p>\n\n<pre><code><php\nIf (!is_user_logged_in())\n{\n wp_redire... | 2015/04/28 | [
"https://wordpress.stackexchange.com/questions/185729",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/67604/"
] | So I have a page (ex. site.com/start) where I want to show a login page (ex. site.com/start/login) if not logged in, in order to view the page.
Without using any plugin, what would be the condition logic which if user visits `/start` page, while they are not not logged in, then the user is redirected to `/start/login`... | In a template file, this should do it:
```
<php
If (!is_user_logged_in())
{
wp_redirect( "start/login" );
exit();
}
?>
``` |
185,731 | <p>What I am trying to achieve is the following: for every user on our website, I want to do an API request to a service (local REST API interacting with another database) once and then cache the result in the WP_User (sub)class until the user will logout and login again (as this value is used on every page in the appl... | [
{
"answer_id": 240033,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 0,
"selected": false,
"text": "<p>Your question is a bit broad, but the main issue seems to be that for every new student you want to approach an ... | 2015/04/28 | [
"https://wordpress.stackexchange.com/questions/185731",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71349/"
] | What I am trying to achieve is the following: for every user on our website, I want to do an API request to a service (local REST API interacting with another database) once and then cache the result in the WP\_User (sub)class until the user will logout and login again (as this value is used on every page in the applic... | If I did understand well, we need to cache a value retrieved from another REST service, from the login to logout of the user on the wordpress installation, so we will hook into this `wp_login` to get the value and cache it using [Transient API](https://codex.wordpress.org/Transients_API), [Options API](https://codex.wo... |
185,747 | <p>I'm getting this error at the top of my wordpress site:</p>
<blockquote>
<p>Notice: Use of undefined constant SCRIPT_DEBUG - assumed 'SCRIPT_DEBUG' in /[wordpress path]/wp-includes/formatting.php on line 4144</p>
</blockquote>
<p>No idea where it came from, any ideas what started causing this?</p>
<p>Using vers... | [
{
"answer_id": 185945,
"author": "Frederik Spang",
"author_id": 25242,
"author_profile": "https://wordpress.stackexchange.com/users/25242",
"pm_score": 4,
"selected": true,
"text": "<p>This is a <a href=\"https://core.trac.wordpress.org/ticket/32118?cversion=0&cnum_hist=10\" rel=\"no... | 2015/04/29 | [
"https://wordpress.stackexchange.com/questions/185747",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71358/"
] | I'm getting this error at the top of my wordpress site:
>
> Notice: Use of undefined constant SCRIPT\_DEBUG - assumed 'SCRIPT\_DEBUG' in /[wordpress path]/wp-includes/formatting.php on line 4144
>
>
>
No idea where it came from, any ideas what started causing this?
Using version 4.2.1 | This is a [known bug](https://core.trac.wordpress.org/ticket/32118?cversion=0&cnum_hist=10)
As far as I'm concerned, you can easily fix it by replacing
```
if ( SCRIPT_DEBUG ) {
```
with
```
if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) {
```
That should suppress the error for now.
When Wordpress is updated ... |
185,753 | <p>I have a curly problem I've been working on for some time. At first it appears as if the get_body_class() function was broken but after I removed it from the template the issue persists.</p>
<pre><code><html class="js firefox">
<head>
<body>
<body>
<div class="top_div&quo... | [
{
"answer_id": 185945,
"author": "Frederik Spang",
"author_id": 25242,
"author_profile": "https://wordpress.stackexchange.com/users/25242",
"pm_score": 4,
"selected": true,
"text": "<p>This is a <a href=\"https://core.trac.wordpress.org/ticket/32118?cversion=0&cnum_hist=10\" rel=\"no... | 2015/04/29 | [
"https://wordpress.stackexchange.com/questions/185753",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/20547/"
] | I have a curly problem I've been working on for some time. At first it appears as if the get\_body\_class() function was broken but after I removed it from the template the issue persists.
```
<html class="js firefox">
<head>
<body>
<body>
<div class="top_div">
<div id="page" class="hfeed site logo">
<div id="p... | This is a [known bug](https://core.trac.wordpress.org/ticket/32118?cversion=0&cnum_hist=10)
As far as I'm concerned, you can easily fix it by replacing
```
if ( SCRIPT_DEBUG ) {
```
with
```
if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) {
```
That should suppress the error for now.
When Wordpress is updated ... |
185,755 | <p>I'm trying to display a texts with functions on my page. Please find the code below. I'm not getting the output I want. </p>
<pre><code><?php $content = the_content(); ?>
<?php printf(__('Output : %1$s', 'theme'), $content); ?>
</code></pre>
<p>Which Outputs : </p>
<pre><code>Foo
Output :
</code></pr... | [
{
"answer_id": 185761,
"author": "Kim Christensen",
"author_id": 71367,
"author_profile": "https://wordpress.stackexchange.com/users/71367",
"pm_score": 2,
"selected": false,
"text": "<p>You want to use <code>get_the_content()</code>, \n<code>the_content()</code> prints the content.</p>\... | 2015/04/29 | [
"https://wordpress.stackexchange.com/questions/185755",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/26988/"
] | I'm trying to display a texts with functions on my page. Please find the code below. I'm not getting the output I want.
```
<?php $content = the_content(); ?>
<?php printf(__('Output : %1$s', 'theme'), $content); ?>
```
Which Outputs :
```
Foo
Output :
```
I need my output to be like this :
```
Output : Foo
... | `the_content()` prints it output to screen. What you want is to return that output and assign a variable to it.
You should note, although `get_the_content()` do exactly what you want, it only returns unfiltered content, and not filtered content like `the_content()`. You should manually add those filters, which is real... |
185,781 | <p>I want to show related posts, with the same taxonomy (artists) as the current post. In the related post I don't want the current post to appear.</p>
<p>I am also using a custom post type. (sculptures)</p>
<p>This is the code I am using below, but it is showing the current post in the related post and all post not ... | [
{
"answer_id": 185764,
"author": "m4n0",
"author_id": 70936,
"author_profile": "https://wordpress.stackexchange.com/users/70936",
"pm_score": 2,
"selected": true,
"text": "<p>Yes, the categories are stored in <code>wp_terms</code> table which contains the term_id, name and slug. Deleting... | 2015/04/29 | [
"https://wordpress.stackexchange.com/questions/185781",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/66373/"
] | I want to show related posts, with the same taxonomy (artists) as the current post. In the related post I don't want the current post to appear.
I am also using a custom post type. (sculptures)
This is the code I am using below, but it is showing the current post in the related post and all post not only those with t... | Yes, the categories are stored in `wp_terms` table which contains the term\_id, name and slug. Deleting the category in admin panel removes the three values along with it. |
185,800 | <p>I'm trying to make WordPress theme with the materialize framework but I'm really confused by the navbar part. I've searched on the internet but found nothing, it seems nobody works with materialize.</p>
<p>The only thing that I have found is to make it with nav_walker, like it is done in bootstrap but I don't know ... | [
{
"answer_id": 185764,
"author": "m4n0",
"author_id": 70936,
"author_profile": "https://wordpress.stackexchange.com/users/70936",
"pm_score": 2,
"selected": true,
"text": "<p>Yes, the categories are stored in <code>wp_terms</code> table which contains the term_id, name and slug. Deleting... | 2015/04/29 | [
"https://wordpress.stackexchange.com/questions/185800",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71384/"
] | I'm trying to make WordPress theme with the materialize framework but I'm really confused by the navbar part. I've searched on the internet but found nothing, it seems nobody works with materialize.
The only thing that I have found is to make it with nav\_walker, like it is done in bootstrap but I don't know how to do... | Yes, the categories are stored in `wp_terms` table which contains the term\_id, name and slug. Deleting the category in admin panel removes the three values along with it. |
185,839 | <p>I've tried this on a fresh install on the twentyfifteen theme. I'm adding a metabox to pages which allows uploads - Whenever I upload a file on a new Page it uploads the file but also adds another file to the media library with the <code>post_id</code> as the name. It then saves the phantom ID as post meta. If I pub... | [
{
"answer_id": 185852,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": -1,
"selected": false,
"text": "<p>Part of your problem might be that while you create a nonce you don't really use it.</p>\n\n<p>You don't... | 2015/04/29 | [
"https://wordpress.stackexchange.com/questions/185839",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/7355/"
] | I've tried this on a fresh install on the twentyfifteen theme. I'm adding a metabox to pages which allows uploads - Whenever I upload a file on a new Page it uploads the file but also adds another file to the media library with the `post_id` as the name. It then saves the phantom ID as post meta. If I publish the post ... | I've modified your code a little to check that the post type is a page, that the current user can edit that page, verify the nonce and verify the inserting attachment functions. The resulting code is working. It seems that don't checking the post type could be the reason of the issue. Also, you don't need to manually i... |
185,864 | <p>I have event listings that look like this</p>
<pre><code>PAPA ROACH AT THE PARAMOUNT IN HUNTINGTON ON APR 28, 2015
</code></pre>
<p>Im trying to remove everything after the last "ON"</p>
<pre><code>$s = the_title();
echo substr($s, 0, strrpos($s, 'ON') - 1);
</code></pre>
<p>The code above works if '$s' is a reg... | [
{
"answer_id": 185866,
"author": "m4n0",
"author_id": 70936,
"author_profile": "https://wordpress.stackexchange.com/users/70936",
"pm_score": 2,
"selected": true,
"text": "<p>Try using the <code>post</code> variable to access the <code>post_title</code></p>\n\n<pre><code>global $post;\n$... | 2015/04/29 | [
"https://wordpress.stackexchange.com/questions/185864",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/63922/"
] | I have event listings that look like this
```
PAPA ROACH AT THE PARAMOUNT IN HUNTINGTON ON APR 28, 2015
```
Im trying to remove everything after the last "ON"
```
$s = the_title();
echo substr($s, 0, strrpos($s, 'ON') - 1);
```
The code above works if '$s' is a regular string but if it is 'the\_title()' it does n... | Try using the `post` variable to access the `post_title`
```
global $post;
$s = $post->post_title;
echo substr($s, 0, strrpos($s, 'on') - 1);
``` |
185,872 | <p>I am trying to do a pretty basic AJAX request at the moment, just to test functionality, routing my calls through admin-ajax.php. However, every time I try to fire the AJAX request, I get a 404 error that says "Uncaught syntaxerror: Unexpected token <". Wtf? It appears to be doing this because of the carot in my ... | [
{
"answer_id": 227346,
"author": "prosti",
"author_id": 88606,
"author_profile": "https://wordpress.stackexchange.com/users/88606",
"pm_score": 0,
"selected": false,
"text": "<p>Make sure you set your</p>\n\n<pre><code>define( 'WP_DEBUG', false );\n</code></pre>\n\n<p>Else the notices an... | 2015/04/29 | [
"https://wordpress.stackexchange.com/questions/185872",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/55073/"
] | I am trying to do a pretty basic AJAX request at the moment, just to test functionality, routing my calls through admin-ajax.php. However, every time I try to fire the AJAX request, I get a 404 error that says "Uncaught syntaxerror: Unexpected token <". Wtf? It appears to be doing this because of the carot in my DTD...... | `success` and `error` are **functions**, not **properties** of AJAX function. Working code:
```
$(".tabs .btn").click(function(e) {
e.preventDefault();
$.ajax({
url:"/wp-admin/admin-ajax.php",
type: "GET",
dataType: "html",
cache: false,
data: {
action: "show... |
185,916 | <p>im using the <strong>wp_list_table</strong> class on my backend theme, to show some informations that i have saved on database, but there is a lot of informations and i want to make it responsive, show/hide some elements according to screen size.</p>
<p>I thought it would happen automatically as in the table that d... | [
{
"answer_id": 186020,
"author": "Latz",
"author_id": 13811,
"author_profile": "https://wordpress.stackexchange.com/users/13811",
"pm_score": 0,
"selected": false,
"text": "<p>Responsive list tables are a development goal of WordPress v4.3: <a href=\"https://make.wordpress.org/core/2015/... | 2015/04/30 | [
"https://wordpress.stackexchange.com/questions/185916",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71441/"
] | im using the **wp\_list\_table** class on my backend theme, to show some informations that i have saved on database, but there is a lot of informations and i want to make it responsive, show/hide some elements according to screen size.
I thought it would happen automatically as in the table that displays posts but tha... | i'm using wp-list-table without the (php) class but html only and wanna share my research. There is some stuff to watch if you need a responsive table when building a wp-list-table yourself:
* add class `column-primary` to header `th` and body `td`. If this class is missing the table gets messy in mobile view
* add bu... |
185,931 | <p>Recently I updated my wordpress to 4.2.1 and now I have a problem with editing people's comments. After editing them, the avatar picture of who edited the comment is shown instead of the avatar of the real man who wrote the comment. What should I do?</p>
| [
{
"answer_id": 186020,
"author": "Latz",
"author_id": 13811,
"author_profile": "https://wordpress.stackexchange.com/users/13811",
"pm_score": 0,
"selected": false,
"text": "<p>Responsive list tables are a development goal of WordPress v4.3: <a href=\"https://make.wordpress.org/core/2015/... | 2015/04/30 | [
"https://wordpress.stackexchange.com/questions/185931",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/36838/"
] | Recently I updated my wordpress to 4.2.1 and now I have a problem with editing people's comments. After editing them, the avatar picture of who edited the comment is shown instead of the avatar of the real man who wrote the comment. What should I do? | i'm using wp-list-table without the (php) class but html only and wanna share my research. There is some stuff to watch if you need a responsive table when building a wp-list-table yourself:
* add class `column-primary` to header `th` and body `td`. If this class is missing the table gets messy in mobile view
* add bu... |
185,960 | <p>I'm trying to build a function to display the current chapter (page) within the single.php file ONLY if there's more than one chapter (page break).</p>
<p>This function will output the chapter # within the page header under the title. Then I will customize and use the wp_link_pages at the bottom for the chapter pag... | [
{
"answer_id": 185967,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 2,
"selected": false,
"text": "<p><code>$multipage</code> is an <a href=\"https://codex.wordpress.org/Global_Variables#Inside_the_Loop_variabl... | 2015/04/30 | [
"https://wordpress.stackexchange.com/questions/185960",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71466/"
] | I'm trying to build a function to display the current chapter (page) within the single.php file ONLY if there's more than one chapter (page break).
This function will output the chapter # within the page header under the title. Then I will customize and use the wp\_link\_pages at the bottom for the chapter pagination.... | The `$multipage` is constructed inside the `setup_postdata()` method of `WP_Query`.
It's called when you run `the_post()`. So just as @s\_ha\_dum explained, you have to make a loop around it:
You can try this:
```
if( have_posts() )
{
the_post(); // Make a call to setup_postdata().
echo ... |
185,971 | <p>I have a custom function written in PHP for a Wordspress theme. When I initially wrote it, it worked exactly as expected (it returns the parents and grandparents etc of a term from its ID).</p>
<p>However, after a couple of hours, it started throwing up 503 errors. Why would this only happen after a while? Is there... | [
{
"answer_id": 185972,
"author": "Howdy_McGee",
"author_id": 7355,
"author_profile": "https://wordpress.stackexchange.com/users/7355",
"pm_score": 2,
"selected": false,
"text": "<p>If I had to guess, I'd say you're running into a memory leak like you suggested, infinite recursive loop. Y... | 2015/04/30 | [
"https://wordpress.stackexchange.com/questions/185971",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/63673/"
] | I have a custom function written in PHP for a Wordspress theme. When I initially wrote it, it worked exactly as expected (it returns the parents and grandparents etc of a term from its ID).
However, after a couple of hours, it started throwing up 503 errors. Why would this only happen after a while? Is there some sort... | What about using the WordPress function [`get_ancestors()`](https://codex.wordpress.org/Function_Reference/get_ancestors), which
>
> Returns an array containing the parents of the given object.
>
>
>
To be exact an
>
> Array of ancestors from lowest to highest in the hierarchy
>
>
>
We can easily create a... |
185,997 | <p>I'm searching the web on the last 3 hours without success.</p>
<p>I have a website where authors can publish posts, and posts views are tracking using postmeta "post_views_count".</p>
<p>I'm using this code and works, but show me the count only for the first 5 posts and not for all author posts. This is the code?<... | [
{
"answer_id": 185998,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 2,
"selected": false,
"text": "<p>It's showing you the first 5 posts because that's how many posts are on page 1, and you never told it how ma... | 2015/04/30 | [
"https://wordpress.stackexchange.com/questions/185997",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71488/"
] | I'm searching the web on the last 3 hours without success.
I have a website where authors can publish posts, and posts views are tracking using postmeta "post\_views\_count".
I'm using this code and works, but show me the count only for the first 5 posts and not for all author posts. This is the code?
```
global $wp... | It's showing you the first 5 posts because that's how many posts are on page 1, and you never told it how many posts per page to load, so it used the default posts per page you set under settings.
You'll want to modify the `get_posts` call to have the `posts_per_page` parameter.
However, I will note the following pro... |
185,999 | <p>I have a parent theme that uses correctly <code>load_theme_textdomain()</code> to load all the translated strings in many languages.</p>
<p>Then I created a child theme that uses <code>load_child_theme_textdomain()</code> to achieve the same thing for its strings.</p>
<p>There are certain translated strings for a ... | [
{
"answer_id": 188424,
"author": "redelschaap",
"author_id": 69725,
"author_profile": "https://wordpress.stackexchange.com/users/69725",
"pm_score": 2,
"selected": false,
"text": "<p>You can use language files that are in your child theme folder. First you have to know which text domain ... | 2015/05/01 | [
"https://wordpress.stackexchange.com/questions/185999",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/69071/"
] | I have a parent theme that uses correctly `load_theme_textdomain()` to load all the translated strings in many languages.
Then I created a child theme that uses `load_child_theme_textdomain()` to achieve the same thing for its strings.
There are certain translated strings for a particular language on the parent theme... | I think I found a solution, but before a little
Premise
-------
`load_theme_textdomain()` and `load_child_theme_textdomain()` are basically equal, the only difference is the default path they use:
* they get the current language (using `get_locale()`) and add the relative **.mo** file to the path passed as argument;... |
186,034 | <p>The essence of the question is, I'm looking for a solution like this: </p>
<pre><code>$blog_upload_dir_info = wp_upload_dir( $date, $blog_ID );
$blog_upload_url = $blog_upload_dir_info[ 'baseurl' ];
</code></pre>
<p>Where <code>$blog_ID</code> is different of the current blog ID. The most »WP-obvious« solution fai... | [
{
"answer_id": 218845,
"author": "Megan Rose",
"author_id": 84643,
"author_profile": "https://wordpress.stackexchange.com/users/84643",
"pm_score": 1,
"selected": false,
"text": "<p>Why not just use <code>get_option('upload_path')</code> after your <code>switch_to_blog( $blog_ID );</code... | 2015/05/01 | [
"https://wordpress.stackexchange.com/questions/186034",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/31323/"
] | The essence of the question is, I'm looking for a solution like this:
```
$blog_upload_dir_info = wp_upload_dir( $date, $blog_ID );
$blog_upload_url = $blog_upload_dir_info[ 'baseurl' ];
```
Where `$blog_ID` is different of the current blog ID. The most »WP-obvious« solution fails:
```
switch_to_blog( $blog_ID );
... | Why not just use `get_option('upload_path')` after your `switch_to_blog( $blog_ID );`?
Does that do it? |
186,048 | <p>Can you please help me on how can I display a list <code><li></code> of newly published child pages.
I've been looking on google how to use display it using the <code>wp_list_pages();</code> but can't find out there. I want to display it like in the "Latest Trainings" or something like that.</p>
| [
{
"answer_id": 186053,
"author": "Nicolai Grossherr",
"author_id": 22534,
"author_profile": "https://wordpress.stackexchange.com/users/22534",
"pm_score": 0,
"selected": false,
"text": "<p>If you're really just looking to get a list of children with <a href=\"https://codex.wordpress.org/... | 2015/05/01 | [
"https://wordpress.stackexchange.com/questions/186048",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/50871/"
] | Can you please help me on how can I display a list `<li>` of newly published child pages.
I've been looking on google how to use display it using the `wp_list_pages();` but can't find out there. I want to display it like in the "Latest Trainings" or something like that. | This will get you the post data for all child pages:
```
$args = array(
'post_type' => 'page',
'post_parent__not_in' => array(0),
'no_found_rows' => true,
);
$child = new WP_Query($args);
var_dump(wp_list_pluck($child->posts,'post_title')); // debugging only... |
186,062 | <p>Original post:
<a href="https://wordpress.stackexchange.com/questions/149076/query-between-dates-using-date-picker-fields">Query between dates using Date Picker fields</a></p>
<p>I originally made a post last year on this same subject, but seems the update to WP v4.2.1 has broken my filter. In summary, I am using ... | [
{
"answer_id": 186130,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 2,
"selected": false,
"text": "<p>There's no need for the custom meta SQL filter - the beauty of storing dates in the format <code>Ymd</code... | 2015/05/01 | [
"https://wordpress.stackexchange.com/questions/186062",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/18119/"
] | Original post:
[Query between dates using Date Picker fields](https://wordpress.stackexchange.com/questions/149076/query-between-dates-using-date-picker-fields)
I originally made a post last year on this same subject, but seems the update to WP v4.2.1 has broken my filter. In summary, I am using ACF and date picker pl... | There's no need for the custom meta SQL filter - the beauty of storing dates in the format `Ymd` is that you can treat them numerically, and MySQL will still be able to find events in a given "range" and sort them ascending/descending.
I've done this recently on another site using ACF for start/end date:
```
if ( ! e... |
186,069 | <p>I can get <code>wp_logout</code> to work, but not without generating lots of warnings ('PHP warning: Cannot modify header information - headers already sent'). </p>
<p><code>wp_logout</code> calls <code>wp_clear_auth_cookie</code>, which calls <code>setcookie</code>, and the cookies have to go with the HTTP headers... | [
{
"answer_id": 186345,
"author": "EML",
"author_id": 69329,
"author_profile": "https://wordpress.stackexchange.com/users/69329",
"pm_score": 0,
"selected": false,
"text": "<p>This isn't great, but seems to work. It's not as simple as calling <code>wp_logout</code> before any content is s... | 2015/05/01 | [
"https://wordpress.stackexchange.com/questions/186069",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/69329/"
] | I can get `wp_logout` to work, but not without generating lots of warnings ('PHP warning: Cannot modify header information - headers already sent').
`wp_logout` calls `wp_clear_auth_cookie`, which calls `setcookie`, and the cookies have to go with the HTTP headers. I'm calling `wp_logout` inside the page (in the head... | If you're using `wp_logout` in your own code, its probably best to `exit` or `wp_redirect` immediately afterwards.
You can call `wp_set_current_user(0)` after `wp_logout()` to manually log the user out instantly, if you need to continue executing PHP but don't want the user to be logged in. |
186,071 | <p>In the WP Admin panel, I have a plugin that does certain calculations based on input from a form. I need it to print pretty, so I am attempting to render the plugin page without the admin menu etc.</p>
<p>I thought that <code>remove_action( 'wp_footer', 'wp_admin_bar_render', 10000 );</code> would accomplish this, ... | [
{
"answer_id": 186080,
"author": "bueltge",
"author_id": 170,
"author_profile": "https://wordpress.stackexchange.com/users/170",
"pm_score": 0,
"selected": false,
"text": "<p>If you will disable the admin bar for all users on this page, use this </p>\n\n<pre><code>wp_deregister_script( '... | 2015/05/01 | [
"https://wordpress.stackexchange.com/questions/186071",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/50860/"
] | In the WP Admin panel, I have a plugin that does certain calculations based on input from a form. I need it to print pretty, so I am attempting to render the plugin page without the admin menu etc.
I thought that `remove_action( 'wp_footer', 'wp_admin_bar_render', 10000 );` would accomplish this, but it seems to not b... | In modern WordPress toolbar is considered *mandatory* part of admin. That is WordPress is explicitly opinionated about not letting you to disable it. While you still can kind of hack it out, it's unnecessary struggle.
If you need a blank page there is no reason to struggle with blanking admin interface for it. You cou... |
186,119 | <p>I have a custom table in database named <code>wp_tasks</code> which has 5 fields. </p>
<p>But I am unable to insert the current time to <code>assign_date</code> field.</p>
<p><strong>wp_tasks table</strong></p>
<pre><code>id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
worker_id INT(6) ,
project_id INT(6),
work_i... | [
{
"answer_id": 186105,
"author": "Ibrahim",
"author_id": 30773,
"author_profile": "https://wordpress.stackexchange.com/users/30773",
"pm_score": 0,
"selected": false,
"text": "<p>You can not get \"list of all\" wordpress plugin from api.wordpress , this api is set to display information ... | 2015/05/02 | [
"https://wordpress.stackexchange.com/questions/186119",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71448/"
] | I have a custom table in database named `wp_tasks` which has 5 fields.
But I am unable to insert the current time to `assign_date` field.
**wp\_tasks table**
```
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
worker_id INT(6) ,
project_id INT(6),
work_id INT(6),
assign_date DATETIME
```
**Inserting records**
``... | Guys I found the answer.
Well, after a lot of changes in codes, I finally did it through API.
Through that PHP page, you can search in any plugin which exist in Wordpress Repository.
Sorry, I cannot include the code because it's too long.
Basically, I am just listing down in short what exactly I did.
First of all I... |
186,126 | <p>I understand there are 2 different types when it comes to a custom post type:
-page
-post. </p>
<p>Where <strong>page</strong> supports child pages, and <strong>post</strong> does not. </p>
<p>However, when i try to make a child page with only numbers in it's slug, wordpress puts -2 behind it. Example:</p>
<p>/po... | [
{
"answer_id": 186145,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 2,
"selected": false,
"text": "<p>It would be more correct to say that CPTs can be hierarchical and non–hierarchical. Page and post are just respecti... | 2015/05/02 | [
"https://wordpress.stackexchange.com/questions/186126",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/64516/"
] | I understand there are 2 different types when it comes to a custom post type:
-page
-post.
Where **page** supports child pages, and **post** does not.
However, when i try to make a child page with only numbers in it's slug, wordpress puts -2 behind it. Example:
/posttype/parent/10-2/
instead of what i would have ... | As you guessed and @Rarst suspected, there's a pagination check in `wp_unique_post_slug()` for hierarchical post types:
```
preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug )
```
which will match any numeric only slug, optionally preceded by "page". To get around this you could use the `'wp_unique_post_sl... |
186,128 | <p>My question title might be little confuse. Here is the scenario, For example: I am giving an API service from my wordpress site.</p>
<p>Using it others can know few information. Like if they send a User ID in query URL then i'll send them user phone number.</p>
<p>For Example: If they access the site with <code>ww... | [
{
"answer_id": 186131,
"author": "Emetrop",
"author_id": 64623,
"author_profile": "https://wordpress.stackexchange.com/users/64623",
"pm_score": 0,
"selected": false,
"text": "<p>Yes, <code>init</code> is good for this purpose. In <a href=\"https://codex.wordpress.org/Plugin_API/Action_R... | 2015/05/02 | [
"https://wordpress.stackexchange.com/questions/186128",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/37102/"
] | My question title might be little confuse. Here is the scenario, For example: I am giving an API service from my wordpress site.
Using it others can know few information. Like if they send a User ID in query URL then i'll send them user phone number.
For Example: If they access the site with `www.example.com/?cuid=23... | If you want a more user-friendly URL structure, you could [add a rewrite endpoint](https://codex.wordpress.org/Rewrite_API/add_rewrite_endpoint).
This will add the rules for and intercept requests to `/my-api/`:
```
function wpd_add_api_endpoint() {
add_rewrite_endpoint( 'my-api', EP_ROOT );
}
add_action( 'init',... |
186,150 | <p>I've searched many places and tried many ways for this but no success.</p>
<p>I have a shortcode in my WP Theme like;</p>
<pre><code>[recent_posts layout="thumbnails-on-side" columns="4" number_posts="4" offset="" cat_slug="" exclude_cats="" thumbnail="yes" title="no" meta="no" excerpt="no" excerpt_length="35" str... | [
{
"answer_id": 186131,
"author": "Emetrop",
"author_id": 64623,
"author_profile": "https://wordpress.stackexchange.com/users/64623",
"pm_score": 0,
"selected": false,
"text": "<p>Yes, <code>init</code> is good for this purpose. In <a href=\"https://codex.wordpress.org/Plugin_API/Action_R... | 2015/05/02 | [
"https://wordpress.stackexchange.com/questions/186150",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3405/"
] | I've searched many places and tried many ways for this but no success.
I have a shortcode in my WP Theme like;
```
[recent_posts layout="thumbnails-on-side" columns="4" number_posts="4" offset="" cat_slug="" exclude_cats="" thumbnail="yes" title="no" meta="no" excerpt="no" excerpt_length="35" strip_html="yes" animati... | If you want a more user-friendly URL structure, you could [add a rewrite endpoint](https://codex.wordpress.org/Rewrite_API/add_rewrite_endpoint).
This will add the rules for and intercept requests to `/my-api/`:
```
function wpd_add_api_endpoint() {
add_rewrite_endpoint( 'my-api', EP_ROOT );
}
add_action( 'init',... |
186,195 | <p>I want to get all info of top level menu from childrens</p>
<pre><code><li class="l-nav-item dropdown"><button class="open-icon visible-xs fa fa-angle-down"></button><a href=" ">Home</a>
<ul class="dropdown-menu l-nav-sublist">
<li class="l-nav-subite... | [
{
"answer_id": 186131,
"author": "Emetrop",
"author_id": 64623,
"author_profile": "https://wordpress.stackexchange.com/users/64623",
"pm_score": 0,
"selected": false,
"text": "<p>Yes, <code>init</code> is good for this purpose. In <a href=\"https://codex.wordpress.org/Plugin_API/Action_R... | 2015/05/03 | [
"https://wordpress.stackexchange.com/questions/186195",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/59052/"
] | I want to get all info of top level menu from childrens
```
<li class="l-nav-item dropdown"><button class="open-icon visible-xs fa fa-angle-down"></button><a href=" ">Home</a>
<ul class="dropdown-menu l-nav-sublist">
<li class="l-nav-subitem"><a href="">Home Style I</a></li>
<li... | If you want a more user-friendly URL structure, you could [add a rewrite endpoint](https://codex.wordpress.org/Rewrite_API/add_rewrite_endpoint).
This will add the rules for and intercept requests to `/my-api/`:
```
function wpd_add_api_endpoint() {
add_rewrite_endpoint( 'my-api', EP_ROOT );
}
add_action( 'init',... |
186,198 | <p>I want to display Y number of authors' info randomly. These authors have to have at least X numbers of posts published.</p>
<p>Please keep in mind that this would be for a blog with thousands of users where most of them have published 0 posts.</p>
<p>I have looked at functions like <code>wp_list_authors()</code> a... | [
{
"answer_id": 186220,
"author": "Gixty",
"author_id": 14128,
"author_profile": "https://wordpress.stackexchange.com/users/14128",
"pm_score": 1,
"selected": false,
"text": "<p>This is a rough draft of what I have so far. Please feel free to update it and improve it.</p>\n\n<p>First of a... | 2015/05/03 | [
"https://wordpress.stackexchange.com/questions/186198",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14128/"
] | I want to display Y number of authors' info randomly. These authors have to have at least X numbers of posts published.
Please keep in mind that this would be for a blog with thousands of users where most of them have published 0 posts.
I have looked at functions like `wp_list_authors()` and `WP_User_Query()` but I c... | You can get rid of most of your code above. [`WP_User_Query`](https://codex.wordpress.org/Class_Reference/WP_User_Query) has an `include` parameter (*introduced in Wordpress 3.9*)
>
> **include** (array) - List of users to be included.
>
>
>
So we need to get a random array of author ID's. I have modified your `c... |
186,201 | <p>how can I change the 1st child name of the admin menu in wp? I have upload a picture, I want to have a different name of the 1st child of the menu and the parent will be the same.</p>
<p><img src="https://i.stack.imgur.com/Di3m8.png" alt="enter image description here"></p>
<p>this is mycode</p>
<pre><code>add_act... | [
{
"answer_id": 186220,
"author": "Gixty",
"author_id": 14128,
"author_profile": "https://wordpress.stackexchange.com/users/14128",
"pm_score": 1,
"selected": false,
"text": "<p>This is a rough draft of what I have so far. Please feel free to update it and improve it.</p>\n\n<p>First of a... | 2015/05/04 | [
"https://wordpress.stackexchange.com/questions/186201",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/68933/"
] | how can I change the 1st child name of the admin menu in wp? I have upload a picture, I want to have a different name of the 1st child of the menu and the parent will be the same.

this is mycode
```
add_action('admin_menu', 'mymenu_admin_actions');... | You can get rid of most of your code above. [`WP_User_Query`](https://codex.wordpress.org/Class_Reference/WP_User_Query) has an `include` parameter (*introduced in Wordpress 3.9*)
>
> **include** (array) - List of users to be included.
>
>
>
So we need to get a random array of author ID's. I have modified your `c... |
186,253 | <p>Given a user id, $user_id, and post id, $post_id, how can I programatically update a wordpress post author?</p>
<p>Note: these posts are already created and the author cannot be set upon creation. Another process is creating the post and defaulting to the admin as the author. I don't have access to creating the pos... | [
{
"answer_id": 186275,
"author": "Emetrop",
"author_id": 64623,
"author_profile": "https://wordpress.stackexchange.com/users/64623",
"pm_score": 6,
"selected": true,
"text": "<p>It shouldn't be any problem. Try this:</p>\n\n<pre><code>$arg = array(\n 'ID' => $post_id,\n 'post_au... | 2015/05/04 | [
"https://wordpress.stackexchange.com/questions/186253",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71608/"
] | Given a user id, $user\_id, and post id, $post\_id, how can I programatically update a wordpress post author?
Note: these posts are already created and the author cannot be set upon creation. Another process is creating the post and defaulting to the admin as the author. I don't have access to creating the post but ha... | It shouldn't be any problem. Try this:
```
$arg = array(
'ID' => $post_id,
'post_author' => $user_id,
);
wp_update_post( $arg );
``` |
186,267 | <p>I'm using Nginx and a custom add_rewrite_rule that looks like this:</p>
<pre><code>function add_pony() {
//this should allow me to POST to domain.com/pony
add_rewrite_rule('^pony$', 'index.php?pony=true', 'top');
}
add_action( 'init', 'add_pony');
function parse_pony( $params ) {
if(isset($params->query_... | [
{
"answer_id": 186275,
"author": "Emetrop",
"author_id": 64623,
"author_profile": "https://wordpress.stackexchange.com/users/64623",
"pm_score": 6,
"selected": true,
"text": "<p>It shouldn't be any problem. Try this:</p>\n\n<pre><code>$arg = array(\n 'ID' => $post_id,\n 'post_au... | 2015/05/04 | [
"https://wordpress.stackexchange.com/questions/186267",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/34359/"
] | I'm using Nginx and a custom add\_rewrite\_rule that looks like this:
```
function add_pony() {
//this should allow me to POST to domain.com/pony
add_rewrite_rule('^pony$', 'index.php?pony=true', 'top');
}
add_action( 'init', 'add_pony');
function parse_pony( $params ) {
if(isset($params->query_vars['pony'])){... | It shouldn't be any problem. Try this:
```
$arg = array(
'ID' => $post_id,
'post_author' => $user_id,
);
wp_update_post( $arg );
``` |
186,272 | <p>I'm running a WP site on my laptop using localhost, and I often need my coworkers to see it. If they enter my home's IP, they were able to access the site, but all the URL's in WP that used site_url() or similar were echoing out "localhost" which of course didn't work for outsiders.</p>
<p>So I changed WP to use my... | [
{
"answer_id": 186283,
"author": "adelval",
"author_id": 40965,
"author_profile": "https://wordpress.stackexchange.com/users/40965",
"pm_score": 4,
"selected": true,
"text": "<p>You can use <code>wp-config.php</code> to change the site url depending on where the site is accesed from, usi... | 2015/05/04 | [
"https://wordpress.stackexchange.com/questions/186272",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/70599/"
] | I'm running a WP site on my laptop using localhost, and I often need my coworkers to see it. If they enter my home's IP, they were able to access the site, but all the URL's in WP that used site\_url() or similar were echoing out "localhost" which of course didn't work for outsiders.
So I changed WP to use my IP for t... | You can use `wp-config.php` to change the site url depending on where the site is accesed from, using `$_SERVER['REMOTE_ADDR']`. Mine has something like this:
```
if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1' || $_SERVER['REMOTE_ADDR'] == '::1') {
// accesing site from my local server
define('WP_SITEURL', 'http:... |
186,282 | <p>I am currently using a wordpress installation in which all the website is intended to be shown in http while the https part is protected by a self signed certificate, distributed manually to the admins. The problem I have is that the images uploaded are all uploaded with the "https" prefix, I imagine because the lin... | [
{
"answer_id": 186283,
"author": "adelval",
"author_id": 40965,
"author_profile": "https://wordpress.stackexchange.com/users/40965",
"pm_score": 4,
"selected": true,
"text": "<p>You can use <code>wp-config.php</code> to change the site url depending on where the site is accesed from, usi... | 2015/05/04 | [
"https://wordpress.stackexchange.com/questions/186282",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71623/"
] | I am currently using a wordpress installation in which all the website is intended to be shown in http while the https part is protected by a self signed certificate, distributed manually to the admins. The problem I have is that the images uploaded are all uploaded with the "https" prefix, I imagine because the link i... | You can use `wp-config.php` to change the site url depending on where the site is accesed from, using `$_SERVER['REMOTE_ADDR']`. Mine has something like this:
```
if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1' || $_SERVER['REMOTE_ADDR'] == '::1') {
// accesing site from my local server
define('WP_SITEURL', 'http:... |
186,313 | <p>I am trying to create custom template for custom taxonomy. For example i have a custom taxonomy registered in WP with name brands and slug brand
i used following code to register custom taxonomy.</p>
<pre><code>function brand() {
$labels = array(
'name' => _x( 'brands', 'Taxonomy Gener... | [
{
"answer_id": 186283,
"author": "adelval",
"author_id": 40965,
"author_profile": "https://wordpress.stackexchange.com/users/40965",
"pm_score": 4,
"selected": true,
"text": "<p>You can use <code>wp-config.php</code> to change the site url depending on where the site is accesed from, usi... | 2015/05/05 | [
"https://wordpress.stackexchange.com/questions/186313",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71641/"
] | I am trying to create custom template for custom taxonomy. For example i have a custom taxonomy registered in WP with name brands and slug brand
i used following code to register custom taxonomy.
```
function brand() {
$labels = array(
'name' => _x( 'brands', 'Taxonomy General Name', 'text_... | You can use `wp-config.php` to change the site url depending on where the site is accesed from, using `$_SERVER['REMOTE_ADDR']`. Mine has something like this:
```
if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1' || $_SERVER['REMOTE_ADDR'] == '::1') {
// accesing site from my local server
define('WP_SITEURL', 'http:... |
186,315 | <p>First i write manually update, delete, insert and select query and execute data with <code>mysql_query</code> function</p>
<p>Like this:</p>
<p>Select query</p>
<pre><code>$prefix = $wpdb->prefix;
$postSql = "SELECT DISTINCT post_id
FROM " . $prefix . "postmeta As meta
Inner Join " . $p... | [
{
"answer_id": 237866,
"author": "T.Todua",
"author_id": 33667,
"author_profile": "https://wordpress.stackexchange.com/users/33667",
"pm_score": 2,
"selected": false,
"text": "<h1>About UPDATE+INSERT:</h1>\n\n<p>I have made a function for myself, and might help you too, i.e. :</p>\n\n<pr... | 2015/05/05 | [
"https://wordpress.stackexchange.com/questions/186315",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/64316/"
] | First i write manually update, delete, insert and select query and execute data with `mysql_query` function
Like this:
Select query
```
$prefix = $wpdb->prefix;
$postSql = "SELECT DISTINCT post_id
FROM " . $prefix . "postmeta As meta
Inner Join " . $prefix . "posts As post
On post... | About UPDATE+INSERT:
====================
I have made a function for myself, and might help you too, i.e. :
```
UPDATE_OR_INSERT('wp_users', array('gender'=>'female'), array('name'=>'Monika') );
```
that will UPDATE A VALUE in column (where `name=monika`), but in case that value doesnt exists, then it creates a ne... |
186,316 | <p>well, I'm using woo-commerce plugin to manage a shop. I need to add a user who can manage products(add new, edit). so I added a user and gave him a shop manager role, but the permissions granted for this role is much more than what I wanted (e.g. listing other users, accessing orders, being able to change shop's set... | [
{
"answer_id": 187398,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 2,
"selected": false,
"text": "<p>This is treading very close to being off-topic as it asks specifically about a particular plugin, but the an... | 2015/05/05 | [
"https://wordpress.stackexchange.com/questions/186316",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71621/"
] | well, I'm using woo-commerce plugin to manage a shop. I need to add a user who can manage products(add new, edit). so I added a user and gave him a shop manager role, but the permissions granted for this role is much more than what I wanted (e.g. listing other users, accessing orders, being able to change shop's settin... | This is treading very close to being off-topic as it asks specifically about a particular plugin, but the answer is quite generic:
[You can remove the capabilities you don't need.](http://codex.wordpress.org/Function_Reference/remove_cap)
```
function remove_cap_wpse_186316(){
remove_cap( 'yourwoorole', 'yourwoo... |
186,319 | <p>I am getting started with Docker and I'm still new to professional WordPress development practices. I would like to set up a Docker development environment (on my Mac) so that I can do custom WordPress theme development.</p>
<p>Assuming you have done this before and are already using Docker, how did you set this up... | [
{
"answer_id": 187430,
"author": "Andrew",
"author_id": 60152,
"author_profile": "https://wordpress.stackexchange.com/users/60152",
"pm_score": 3,
"selected": false,
"text": "<p>I'm going to post a partial answer to start the discussion in the hope of getting some helpful comments to fil... | 2015/05/05 | [
"https://wordpress.stackexchange.com/questions/186319",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/60152/"
] | I am getting started with Docker and I'm still new to professional WordPress development practices. I would like to set up a Docker development environment (on my Mac) so that I can do custom WordPress theme development.
Assuming you have done this before and are already using Docker, how did you set this up? What doe... | I'm going to post a partial answer to start the discussion in the hope of getting some helpful comments to fill in the blanks or alternative answers...
Step 1: Install and Set Up boot2docker
======================================
Docker only runs on Linux. So in order to use Docker on our Mac, we need to install `boo... |
186,326 | <p>I need change WP password without logout profile.
When I use wp_set_password( $password, $user_ID ) i have problem with logout.</p>
| [
{
"answer_id": 186331,
"author": "bueltge",
"author_id": 170,
"author_profile": "https://wordpress.stackexchange.com/users/170",
"pm_score": 1,
"selected": false,
"text": "<p>I have no working example, only hints for thinking about this topic.\nThe function to set a new password via the ... | 2015/05/05 | [
"https://wordpress.stackexchange.com/questions/186326",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71646/"
] | I need change WP password without logout profile.
When I use wp\_set\_password( $password, $user\_ID ) i have problem with logout. | Try below code, it won't log you out after the password change and it works with Ajax functions too. No need to reset cookies/sessions afterwards.
```
$userdata['ID'] = 1; //user ID
$userdata['user_pass'] = 'new_password';
wp_update_user( $userdata ); // this will handle encryption and everything
```
Cheers |
186,327 | <p>This function will show the last 3 posts from any category on front page:</p>
<pre><code> // Only top 3 posts from CHR category
add_action('pre_get_posts', 'ad_filter_categories');
function ad_filter_categories($query) {
if ($query->is_main_query() && is_home()) {
$query->set('category_name',... | [
{
"answer_id": 186331,
"author": "bueltge",
"author_id": 170,
"author_profile": "https://wordpress.stackexchange.com/users/170",
"pm_score": 1,
"selected": false,
"text": "<p>I have no working example, only hints for thinking about this topic.\nThe function to set a new password via the ... | 2015/05/05 | [
"https://wordpress.stackexchange.com/questions/186327",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71647/"
] | This function will show the last 3 posts from any category on front page:
```
// Only top 3 posts from CHR category
add_action('pre_get_posts', 'ad_filter_categories');
function ad_filter_categories($query) {
if ($query->is_main_query() && is_home()) {
$query->set('category_name','chatham-house-rules');
$q... | Try below code, it won't log you out after the password change and it works with Ajax functions too. No need to reset cookies/sessions afterwards.
```
$userdata['ID'] = 1; //user ID
$userdata['user_pass'] = 'new_password';
wp_update_user( $userdata ); // this will handle encryption and everything
```
Cheers |
186,337 | <p>So I'm having some issues with this and I can't see why. I just need a custom role that can access the blog in the back end.</p>
<p>I've added a new post type with a Capability type of <code>blog</code> and a new user role with all the caps fr it that would allow admin access users to add/edit the custom post type... | [
{
"answer_id": 235193,
"author": "Akshay Shah",
"author_id": 54263,
"author_profile": "https://wordpress.stackexchange.com/users/54263",
"pm_score": 0,
"selected": false,
"text": "<p>If you are ok with plugin than you can use velow plugin.</p>\n\n<p><a href=\"https://wordpress.org/plugin... | 2015/05/05 | [
"https://wordpress.stackexchange.com/questions/186337",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/39242/"
] | So I'm having some issues with this and I can't see why. I just need a custom role that can access the blog in the back end.
I've added a new post type with a Capability type of `blog` and a new user role with all the caps fr it that would allow admin access users to add/edit the custom post type. This works for admin... | It's hard to troubleshoot the above code because it's only a part of the actual code, but here's the minimum plugin needed to register a custom post type (called Example) and a custom role (Blog Manager) that has access to the Example custom post type.
This can be used as part of a theme's functions.php file as well. ... |
186,357 | <p>I have made some changes (colours, etc...) in the appearance customize from my child theme, is actually working as is just applying to my child, but when I open the style.css from my child I don't see any change, where these changes are?</p>
| [
{
"answer_id": 186358,
"author": "websupporter",
"author_id": 48693,
"author_profile": "https://wordpress.stackexchange.com/users/48693",
"pm_score": 3,
"selected": true,
"text": "<p>If you mean the WordPress Customizer: These changes are not saved to the style.css, but they come most li... | 2015/05/05 | [
"https://wordpress.stackexchange.com/questions/186357",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71663/"
] | I have made some changes (colours, etc...) in the appearance customize from my child theme, is actually working as is just applying to my child, but when I open the style.css from my child I don't see any change, where these changes are? | If you mean the WordPress Customizer: These changes are not saved to the style.css, but they come most likely to be found shortly before `</head>`. Probably you will find there something like
```
<style>
//definitions via Customizer
</style>
``` |
186,366 | <p>Woocommerce has three built in image sizes. But since there are more than three different container sizes, some images always get stretched or squeezed. Hence image quality and page speed suffer. Woocommerce uses for example the catalogue size for catalogue images and related product images. Wordpress offers an easy... | [
{
"answer_id": 186367,
"author": "m4n0",
"author_id": 70936,
"author_profile": "https://wordpress.stackexchange.com/users/70936",
"pm_score": 1,
"selected": false,
"text": "<p>You can overwrite the CSS of WooCommerce through this snippet, <a href=\"http://www.remicorson.com/woocommerce-c... | 2015/05/05 | [
"https://wordpress.stackexchange.com/questions/186366",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71669/"
] | Woocommerce has three built in image sizes. But since there are more than three different container sizes, some images always get stretched or squeezed. Hence image quality and page speed suffer. Woocommerce uses for example the catalogue size for catalogue images and related product images. Wordpress offers an easy me... | There's a few options you can choose from whenever changing image sizes. Switching out the actual default WooCommerce images is more difficult than a normal WordPress install as they are ingrained with the plugin.
---
**Modify Related Product Image Sizes:**
I've tested this and it seems to work only on related produ... |
186,371 | <p>I use cloudflare via the cloudflare plugin, have SSL enabled.</p>
<p>Enabled ssl within the wp-config.php file:</p>
<p><code>define('WP_HOME','https://example.org');</code></p>
<p><code>define('WP_SITEURL','https://example.org');</code></p>
<p><code>$_SERVER['HTTPS'] = 'on';</code></p>
<p>Everything seems to wo... | [
{
"answer_id": 186372,
"author": "m4n0",
"author_id": 70936,
"author_profile": "https://wordpress.stackexchange.com/users/70936",
"pm_score": 2,
"selected": true,
"text": "<p>You need to forward the http:// to https:// to avoid infinite loop.</p>\n\n<pre><code>if ($_SERVER['HTTP_X_FORWAR... | 2015/05/05 | [
"https://wordpress.stackexchange.com/questions/186371",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71668/"
] | I use cloudflare via the cloudflare plugin, have SSL enabled.
Enabled ssl within the wp-config.php file:
`define('WP_HOME','https://example.org');`
`define('WP_SITEURL','https://example.org');`
`$_SERVER['HTTPS'] = 'on';`
Everything seems to work fine on the main site, but when trying to login to admin I see:
You... | You need to forward the http:// to https:// to avoid infinite loop.
```
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS']='on';
``` |
186,379 | <p>I created a custom key and wanted to store multiple values in the key with an array in my plugin using a drop down box, however, I printed out the array and came back out with this value...</p>
<pre><code>Array ( [0] => a:2:{i:0;s:2:"75";i:1;s:2:"68";} )
</code></pre>
<p>My thinking was that it would just add a... | [
{
"answer_id": 186381,
"author": "lampyridae",
"author_id": 29163,
"author_profile": "https://wordpress.stackexchange.com/users/29163",
"pm_score": 0,
"selected": false,
"text": "<p>It seems like the your multiple values were simply serialized by PHP's <a href=\"http://php.net/manual/en/... | 2015/05/05 | [
"https://wordpress.stackexchange.com/questions/186379",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71631/"
] | I created a custom key and wanted to store multiple values in the key with an array in my plugin using a drop down box, however, I printed out the array and came back out with this value...
```
Array ( [0] => a:2:{i:0;s:2:"75";i:1;s:2:"68";} )
```
My thinking was that it would just add another value `[1] => 'content... | You're looking at a [serialized representation](https://stackoverflow.com/questions/8641889/how-to-use-php-serialize-and-unserialize) of the array `Array( '75', '68' )`. Serialization is the process by which PHP stores a data object as a string, much like the manner in which JSON is a string representation of a Javascr... |
187,413 | <p>I have written a small plugin where i have loaded following scripts</p>
<pre><code>wp_enqueue_script('jquery', plugins_url('/js/jquery.min.js', __FILE__),'','1.7',true);
wp_enqueue_script('new-cycle', plugins_url('/js/cycle.js', __FILE__),array( 'jquery' ),'1.0',true);
wp_enqueue_script('new-jcarousellite', plugins... | [
{
"answer_id": 187416,
"author": "Abhishek Deshpande",
"author_id": 45590,
"author_profile": "https://wordpress.stackexchange.com/users/45590",
"pm_score": 0,
"selected": false,
"text": "<p>Instead of putting the code in function and hooking it to <code>wp_footer</code>.</p>\n\n<p>You ca... | 2015/05/06 | [
"https://wordpress.stackexchange.com/questions/187413",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/35612/"
] | I have written a small plugin where i have loaded following scripts
```
wp_enqueue_script('jquery', plugins_url('/js/jquery.min.js', __FILE__),'','1.7',true);
wp_enqueue_script('new-cycle', plugins_url('/js/cycle.js', __FILE__),array( 'jquery' ),'1.0',true);
wp_enqueue_script('new-jcarousellite', plugins_url('/js/jcar... | Try to add the code to the footer using `add_action('wp_footer', 'front_js', 99);` where 99 specifies the order in which the functions are executed. Now it should be executed after your scripts are loaded. |
187,422 | <p>I need to sort and paginate custom taxonomy post types. i have a page where i have next and previous link. on clicking next and previous link next or previous brand(custom taxonomy) should load. I have achieved this so far</p>
<pre><code> $terms = get_the_terms( get_the_ID(), 'brand' );
if($terms) {
$BrandId=$ter... | [
{
"answer_id": 187432,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 1,
"selected": false,
"text": "<p>As I stated in comments, you can either use <a href=\"http://php.net/manual/en/function.usort.php\" rel... | 2015/05/06 | [
"https://wordpress.stackexchange.com/questions/187422",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71641/"
] | I need to sort and paginate custom taxonomy post types. i have a page where i have next and previous link. on clicking next and previous link next or previous brand(custom taxonomy) should load. I have achieved this so far
```
$terms = get_the_terms( get_the_ID(), 'brand' );
if($terms) {
$BrandId=$terms[0]->term_id... | As I stated in comments, you can either use [`usort()`](http://php.net/manual/en/function.usort.php) to sort the returned array of terms, or you can just use [`wp_get_post_terms()`](https://codex.wordpress.org/Function_Reference/wp_get_post_terms) which is already sorted by default by name in ascending order
```
$term... |
187,425 | <p>I am working on a plugin. The plugin make custom post type "product". First i use <code>template_redirect</code> action for redirection to single and category pages.</p>
<p>Here is my template_redirect code:</p>
<pre><code>add_action("template_redirect", 'my_theme_redirect');
function my_theme_redirect() {
gl... | [
{
"answer_id": 187442,
"author": "deemi-D-nadeem",
"author_id": 64316,
"author_profile": "https://wordpress.stackexchange.com/users/64316",
"pm_score": 3,
"selected": true,
"text": "<p>Ok i done by my own.</p>\n\n<p>I delete all above code and write this code. It works perfectly for me</... | 2015/05/06 | [
"https://wordpress.stackexchange.com/questions/187425",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/64316/"
] | I am working on a plugin. The plugin make custom post type "product". First i use `template_redirect` action for redirection to single and category pages.
Here is my template\_redirect code:
```
add_action("template_redirect", 'my_theme_redirect');
function my_theme_redirect() {
global $wp;
$plugindir = dirn... | Ok i done by my own.
I delete all above code and write this code. It works perfectly for me
Code:
```
function template_chooser($template){
global $wp_query;
$plugindir = dirname(__FILE__);
$post_type = get_query_var('post_type');
if( $post_type == 'product' ){
return $plugindir . '/themefi... |
187,443 | <p>I have two categories</p>
<ul>
<li>Category1 (ID = 1)</li>
<li>Category2 (ID = 2)</li>
</ul>
<p>I want to display posts Which are in Category2 and in (Category1 + Category2).</p>
<p>If a post is only in Category1 then it should not display.</p>
<p>I have used the following code.</p>
<pre><code>'category__in' ... | [
{
"answer_id": 187449,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 4,
"selected": true,
"text": "<p>This is very unusual case, and the only solution I can think of here is to get an array of category ids ... | 2015/05/06 | [
"https://wordpress.stackexchange.com/questions/187443",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/11985/"
] | I have two categories
* Category1 (ID = 1)
* Category2 (ID = 2)
I want to display posts Which are in Category2 and in (Category1 + Category2).
If a post is only in Category1 then it should not display.
I have used the following code.
```
'category__in' => array(2)
```
It works but I think it is not the corre... | This is very unusual case, and the only solution I can think of here is to get an array of category ids to include into `category__in` in order to skip posts that are **only** assigned to category `1`
In order to achieve this, we must
* use [`get_terms()`](https://codex.wordpress.org/Function_Reference/get_terms) to ... |
187,446 | <p>My theme calls the update_meta_cache() function 58 times per page! This function appears to run the following query based on the post in question:</p>
<pre><code>SELECT post_id, meta_key, meta_value
-> FROM wp_postmeta
-> WHERE post_id IN (81649)
-> ORDER BY meta_id ASC
-> ;
</code></pre>
<p>The vast m... | [
{
"answer_id": 190047,
"author": "Anh Tran",
"author_id": 2051,
"author_profile": "https://wordpress.stackexchange.com/users/2051",
"pm_score": 2,
"selected": false,
"text": "<p>Whenever you use the function <code>get_post_meta()</code>, the above query will be performed to get <em>all</... | 2015/05/06 | [
"https://wordpress.stackexchange.com/questions/187446",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17938/"
] | My theme calls the update\_meta\_cache() function 58 times per page! This function appears to run the following query based on the post in question:
```
SELECT post_id, meta_key, meta_value
-> FROM wp_postmeta
-> WHERE post_id IN (81649)
-> ORDER BY meta_id ASC
-> ;
```
The vast majority of the meta\_keys (and corre... | Whenever you use the function `get_post_meta()`, the above query will be performed to get *all* post meta and store in the cache. The more posts you query, the more queries are made.
To reduce the number of queries, we should **pre-cache all meta values of all posts** in the query before calling `get_post_meta`.
This... |
187,475 | <p>My individual WP site is installed in a sub-directory (e.g., example.com/wordpress) and I would like visitors to be able to view it from BOTH the root directory (example.com) AND the sub-directory (example.com/wordpress). I followed the instructions on <a href="https://codex.wordpress.org/Giving_WordPress_Its_Own_Di... | [
{
"answer_id": 190047,
"author": "Anh Tran",
"author_id": 2051,
"author_profile": "https://wordpress.stackexchange.com/users/2051",
"pm_score": 2,
"selected": false,
"text": "<p>Whenever you use the function <code>get_post_meta()</code>, the above query will be performed to get <em>all</... | 2015/05/06 | [
"https://wordpress.stackexchange.com/questions/187475",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/44332/"
] | My individual WP site is installed in a sub-directory (e.g., example.com/wordpress) and I would like visitors to be able to view it from BOTH the root directory (example.com) AND the sub-directory (example.com/wordpress). I followed the instructions on [Codex](https://codex.wordpress.org/Giving_WordPress_Its_Own_Direct... | Whenever you use the function `get_post_meta()`, the above query will be performed to get *all* post meta and store in the cache. The more posts you query, the more queries are made.
To reduce the number of queries, we should **pre-cache all meta values of all posts** in the query before calling `get_post_meta`.
This... |
187,477 | <p>I read <a href="http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action" rel="nofollow">this article</a> about how to set an offset for one specific category in the loop. I was wondering about if this was possible for more than just one category.</p>
<p>My problem with the code suggested in the article linked ... | [
{
"answer_id": 190047,
"author": "Anh Tran",
"author_id": 2051,
"author_profile": "https://wordpress.stackexchange.com/users/2051",
"pm_score": 2,
"selected": false,
"text": "<p>Whenever you use the function <code>get_post_meta()</code>, the above query will be performed to get <em>all</... | 2015/05/06 | [
"https://wordpress.stackexchange.com/questions/187477",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/52621/"
] | I read [this article](http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action) about how to set an offset for one specific category in the loop. I was wondering about if this was possible for more than just one category.
My problem with the code suggested in the article linked above is that I am using a single wi... | Whenever you use the function `get_post_meta()`, the above query will be performed to get *all* post meta and store in the cache. The more posts you query, the more queries are made.
To reduce the number of queries, we should **pre-cache all meta values of all posts** in the query before calling `get_post_meta`.
This... |
187,480 | <p>I'm attempting to use a .htaccess file to block access to the wp-admin folder. I've read through the Brute Force Attacks doc (<a href="https://wordpress.org/support/article/brute-force-attacks/" rel="nofollow noreferrer">https://wordpress.org/support/article/brute-force-attacks/</a>) and I've added the block below, ... | [
{
"answer_id": 187491,
"author": "brandozz",
"author_id": 64789,
"author_profile": "https://wordpress.stackexchange.com/users/64789",
"pm_score": 3,
"selected": true,
"text": "<p>Placing the htaccess file in the wp-admin directory did not work for me so I went a different route and it se... | 2015/05/06 | [
"https://wordpress.stackexchange.com/questions/187480",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/64789/"
] | I'm attempting to use a .htaccess file to block access to the wp-admin folder. I've read through the Brute Force Attacks doc (<https://wordpress.org/support/article/brute-force-attacks/>) and I've added the block below, using my ip addresses, to the .htaccess file and placed it in the wp-admin folder:
```
# Block acce... | Placing the htaccess file in the wp-admin directory did not work for me so I went a different route and it seems to be working very well. Below is what I have in my **main** htaccess file:
```
<files wp-login.php>
# set up rule order
order deny,allow
# default deny
deny from all
allow from x.x.x.x
allow from y.y.y.y
a... |
187,487 | <p>I would like to know how to do add a logo to my <a href="http://abraham-accountants.co.uk/" rel="nofollow">website</a>, before the site title.</p>
<pre><code><html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" conte... | [
{
"answer_id": 187488,
"author": "Interactive",
"author_id": 52240,
"author_profile": "https://wordpress.stackexchange.com/users/52240",
"pm_score": 1,
"selected": false,
"text": "<p>The title is probably placed within the header.php file. </p>\n\n<p>So openup and find something like:</p... | 2015/05/06 | [
"https://wordpress.stackexchange.com/questions/187487",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/72715/"
] | I would like to know how to do add a logo to my [website](http://abraham-accountants.co.uk/), before the site title.
```
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="http:... | The title is probably placed within the header.php file.
So openup and find something like:
```
<h1><a href="<?php bloginfo('url');?>"><?php bloginfo('name');?></a></h1>
```
This is what displays `Abraham & Co` on your website.
Now first of you need your image uploaded to you images folder in the theme folder.
... |
187,494 | <p>I am using Visual Composer to add an accordion to my page. Now I need to be able to deep link to arbitrary elements in the accordion. In other words, I need to be able to provide people with links that will open an arbitrary element in the accordion. So, a url like <code>/mypage#tab4</code> might used open the 4th a... | [
{
"answer_id": 196705,
"author": "gbuckingham89",
"author_id": 13207,
"author_profile": "https://wordpress.stackexchange.com/users/13207",
"pm_score": 3,
"selected": true,
"text": "<p>After having the same issue, I've come up with a basic solution - hopefully it's not too late for you.</... | 2015/05/06 | [
"https://wordpress.stackexchange.com/questions/187494",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/27667/"
] | I am using Visual Composer to add an accordion to my page. Now I need to be able to deep link to arbitrary elements in the accordion. In other words, I need to be able to provide people with links that will open an arbitrary element in the accordion. So, a url like `/mypage#tab4` might used open the 4th accordion tab. ... | After having the same issue, I've come up with a basic solution - hopefully it's not too late for you.
The Visual Composer "accordion plugin" seems to be a wrapper around the jQuery UI accordion; so the same methods are available. I've written some basic (room for improvement no doubt) code that checks if there is a h... |
187,499 | <p>I'm getting started with a project that is making use of Backbone and the WP REST API, but I"m having a little trouble.</p>
<p>Using the built in API JS for models and collections allows me to pretty easily update a post title or content. All I have to do is call:</p>
<pre><code>this.model.set({title: 'New Title'}... | [
{
"answer_id": 196705,
"author": "gbuckingham89",
"author_id": 13207,
"author_profile": "https://wordpress.stackexchange.com/users/13207",
"pm_score": 3,
"selected": true,
"text": "<p>After having the same issue, I've come up with a basic solution - hopefully it's not too late for you.</... | 2015/05/06 | [
"https://wordpress.stackexchange.com/questions/187499",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/30668/"
] | I'm getting started with a project that is making use of Backbone and the WP REST API, but I"m having a little trouble.
Using the built in API JS for models and collections allows me to pretty easily update a post title or content. All I have to do is call:
```
this.model.set({title: 'New Title'});
this.model.save();... | After having the same issue, I've come up with a basic solution - hopefully it's not too late for you.
The Visual Composer "accordion plugin" seems to be a wrapper around the jQuery UI accordion; so the same methods are available. I've written some basic (room for improvement no doubt) code that checks if there is a h... |
187,500 | <p>We have a lot of rogue custom fields. I feel that we can clear significant space in the DB if we remove the blank values. If I query my database with the following:</p>
<pre><code>select * from wp_postmeta where meta_value = ''
</code></pre>
<p>I get 871038 (!)</p>
<p>My question is, is it safe to delete these? A... | [
{
"answer_id": 187501,
"author": "fischi",
"author_id": 15680,
"author_profile": "https://wordpress.stackexchange.com/users/15680",
"pm_score": 4,
"selected": true,
"text": "<p>You should be fine deleting empty custom fields.</p>\n\n<p>The main reason is, that <code>get_post_meta( $id, '... | 2015/05/06 | [
"https://wordpress.stackexchange.com/questions/187500",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/38536/"
] | We have a lot of rogue custom fields. I feel that we can clear significant space in the DB if we remove the blank values. If I query my database with the following:
```
select * from wp_postmeta where meta_value = ''
```
I get 871038 (!)
My question is, is it safe to delete these? Are there any potential issues tha... | You should be fine deleting empty custom fields.
The main reason is, that `get_post_meta( $id, 'metakey', true )` returns an empty string if the field is not set, so it is the same as having an empty record set.
`get_post_meta( $id, 'metakey', false )`, returns an empty array if no value is set, so you should be fine... |
187,527 | <p>Let me explain what Im trying to do. Im creating a plugin that will have a main page like a dashboard that will be used to manage the public facing side of the plugin. Just think like a separate app inside a normal WordPress site.</p>
<p>That page needs to be completely separate from user theme as will be totally c... | [
{
"answer_id": 187532,
"author": "JoshuaDoshua",
"author_id": 45769,
"author_profile": "https://wordpress.stackexchange.com/users/45769",
"pm_score": 1,
"selected": false,
"text": "<p>It seems a little odd to only offer the admin bar for a page, but the easiest solution I can think of wo... | 2015/05/06 | [
"https://wordpress.stackexchange.com/questions/187527",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4130/"
] | Let me explain what Im trying to do. Im creating a plugin that will have a main page like a dashboard that will be used to manage the public facing side of the plugin. Just think like a separate app inside a normal WordPress site.
That page needs to be completely separate from user theme as will be totally custom. Adm... | This is what I´ve done so far, I won't mark as correct answer yet in case there is a better approach that Im not aware.
```
add_action('wp_enqueue_scripts',array( $this, 'remove_all_actions'), 99);
public function remove_all_actions(){
if( 'custom-template.php' != get_page_template_slug( get_queried_object_id(... |
187,529 | <p>In Advanced Custom Fields, I would like limit the Relationship field (<a href="http://www.advancedcustomfields.com/resources/relationship/" rel="nofollow">http://www.advancedcustomfields.com/resources/relationship/</a>) to specific pages.</p>
<p>For various resons, involing Custom Post Types is not a solution for m... | [
{
"answer_id": 187531,
"author": "JoshuaDoshua",
"author_id": 45769,
"author_profile": "https://wordpress.stackexchange.com/users/45769",
"pm_score": 0,
"selected": false,
"text": "<p>In <code>register_taxonomy</code> you can pass <code>page</code> as the associated post type and it will... | 2015/05/06 | [
"https://wordpress.stackexchange.com/questions/187529",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71639/"
] | In Advanced Custom Fields, I would like limit the Relationship field (<http://www.advancedcustomfields.com/resources/relationship/>) to specific pages.
For various resons, involing Custom Post Types is not a solution for me right now.
This is my sitemap:
```
website.com
website.com/contact/
website.com/help/
websi... | Found a solution that works:
```
add_filter('acf/fields/relationship/query/name=products', 'exclude_id', 10, 3);
function exclude_id ( $args, $field, $post ) {
$args['post__not_in'] = array( $post, 9, 10, 11 );
return $args;
}
```
Added in functions. This will exclude the pages with id 9, 10 and 11. |
187,543 | <p>I made a custom endpoint with <code>wp rest api</code> for</p>
<p><code>/wp-json/dn/locations</code></p>
<p>which in turn runs the following <code>wpdb</code> query</p>
<pre><code>$sql = "SELECT *
FROM wp_posts p
WHERE p.post_type = 'location'
AND p.ID = 133;";
$results = $wpdb->get_results($sql);
</code></pr... | [
{
"answer_id": 187671,
"author": "Jacksonkr",
"author_id": 13170,
"author_profile": "https://wordpress.stackexchange.com/users/13170",
"pm_score": 1,
"selected": false,
"text": "<p>I ended up using $wpdb for my custom tables and went with wp_query for my custom posts with ACF fields</p>\... | 2015/05/07 | [
"https://wordpress.stackexchange.com/questions/187543",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13170/"
] | I made a custom endpoint with `wp rest api` for
`/wp-json/dn/locations`
which in turn runs the following `wpdb` query
```
$sql = "SELECT *
FROM wp_posts p
WHERE p.post_type = 'location'
AND p.ID = 133;";
$results = $wpdb->get_results($sql);
```
Which returns fine but unfortunately my ACF fields aren't showing up ... | I ended up using $wpdb for my custom tables and went with wp\_query for my custom posts with ACF fields
```
$q = new WP_Query(array(
'post_type' => 'coupon',
'post__in' => $cids
));
$coupons = array();
while($q->have_posts()) : $q->the_post();
$p = get_post();
$f = get... |
187,597 | <p>I have a custom post type named <code>store</code> and I have a custom taxonomy <code>city</code>, I also have a meta box with a field that is stored with <code>update_post_meta( $post_id, 'store_postal_code', $postal_code );</code> it also has a post meta for <code>store_parking</code>.</p>
<p>How would I query th... | [
{
"answer_id": 187600,
"author": "jdm2112",
"author_id": 45202,
"author_profile": "https://wordpress.stackexchange.com/users/45202",
"pm_score": 1,
"selected": false,
"text": "<p>You need a custom query and loop here, at least that's how I do it.</p>\n\n<pre><code>$args = array(\n 'post... | 2015/05/07 | [
"https://wordpress.stackexchange.com/questions/187597",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8757/"
] | I have a custom post type named `store` and I have a custom taxonomy `city`, I also have a meta box with a field that is stored with `update_post_meta( $post_id, 'store_postal_code', $postal_code );` it also has a post meta for `store_parking`.
How would I query the database in such a way it returns me rows in such a ... | I would use a custom query like this:
```
$amsterdamstore_args = array(
'post_type' => 'store', // This is your custom post type
'tax_query' => array(
array(
'taxonomy' => 'city', // This is your custom taxonomy
'terms' => 'Amsterdam', // The term you search for
'field' => 'name', ... |
187,606 | <p>I'd like to execute some small piece of code like the following one:</p>
<pre><code>global $wpdb;
$rows = $wpdb->query('SELECT DATE(post_date) AS date, COUNT(*) AS count FROM ' . $wpdb->posts . ' GROUP BY DATE(post_date) ORDER BY DATE(post_date)');
foreach ($rows as $row) {
echo $row->date . ': ' . $ro... | [
{
"answer_id": 187608,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 2,
"selected": false,
"text": "<p>Context is everything with a question like this. However, since you are talking about a \"sandbox\" I am goi... | 2015/05/07 | [
"https://wordpress.stackexchange.com/questions/187606",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/64590/"
] | I'd like to execute some small piece of code like the following one:
```
global $wpdb;
$rows = $wpdb->query('SELECT DATE(post_date) AS date, COUNT(*) AS count FROM ' . $wpdb->posts . ' GROUP BY DATE(post_date) ORDER BY DATE(post_date)');
foreach ($rows as $row) {
echo $row->date . ': ' . $row->count . '<br>';
}
`... | Best way for execute any PHP code during development its Console from [Developer plugin](https://wordpress.org/plugins/developer/). You can install [Developer plugin](https://wordpress.org/plugins/developer/), and activate console module. "Debug" link will appear in top right corner in your admin bar. You can go there,... |
187,612 | <p>We've been noticing really long load times when going to edit a post or page. Using Query Monitor, we found that this WP core query is taking upwards to 15-20s.</p>
<pre><code>SELECT meta_key
FROM wp_postmeta
GROUP BY meta_key
HAVING meta_key NOT LIKE '\\_%'
ORDER BY meta_key
LIMIT 30
caller:
meta_form()
pos... | [
{
"answer_id": 187712,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 3,
"selected": false,
"text": "<p>If you want to test your custom SQL to see how it affects the loading time, you can try this query swapping: ... | 2015/05/07 | [
"https://wordpress.stackexchange.com/questions/187612",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/38536/"
] | We've been noticing really long load times when going to edit a post or page. Using Query Monitor, we found that this WP core query is taking upwards to 15-20s.
```
SELECT meta_key
FROM wp_postmeta
GROUP BY meta_key
HAVING meta_key NOT LIKE '\\_%'
ORDER BY meta_key
LIMIT 30
caller:
meta_form()
post_custom_meta_... | If you want to test your custom SQL to see how it affects the loading time, you can try this query swapping:
```
/**
* Restrict the potential slow query in the meta_form() to the current post ID.
*
* @see http://wordpress.stackexchange.com/a/187712/26350
*/
add_action( 'add_meta_boxes_post', function( $post )
{
... |
187,629 | <p>Per this question (<a href="https://wordpress.stackexchange.com/questions/29635/how-to-create-an-attachments-archive-with-working-pagination">How to create an attachments archive with working pagination?</a>), I've been using the following function to have archive pages display attachments as well as pages and posts... | [
{
"answer_id": 187631,
"author": "ambroseya",
"author_id": 72778,
"author_profile": "https://wordpress.stackexchange.com/users/72778",
"pm_score": 1,
"selected": false,
"text": "<p>The WP_Query documentation on the codex specifically says:</p>\n\n<blockquote>\n <p>'attachment' - an atta... | 2015/05/07 | [
"https://wordpress.stackexchange.com/questions/187629",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/65906/"
] | Per this question ([How to create an attachments archive with working pagination?](https://wordpress.stackexchange.com/questions/29635/how-to-create-an-attachments-archive-with-working-pagination)), I've been using the following function to have archive pages display attachments as well as pages and posts. It was worki... | Figured it out! The culprit was the plugin "Add Categories to Pages" which one of my editors had added to the site. In addition to registering `post_tag` and `category` for the `page` post type, it *also* modified the archive.php and tag.php queries to only look in the `post` and `page` types---yet another solution for... |
187,644 | <p>Many people embed my website's pages in their websites as iframes. I want them to not take my footer, header and a specific division in those iframes. Since, footer, header and mentioned specific division is present in all of my pages.</p>
<p>What should I do? Should I add some code in my header or in my <code>func... | [
{
"answer_id": 187663,
"author": "Tuan Anh Hoang-Vu",
"author_id": 2222,
"author_profile": "https://wordpress.stackexchange.com/users/2222",
"pm_score": 0,
"selected": false,
"text": "<p>Why don't you create a <a href=\"http://codex.wordpress.org/Page_Templates#Custom_Page_Template\" rel... | 2015/05/07 | [
"https://wordpress.stackexchange.com/questions/187644",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/72782/"
] | Many people embed my website's pages in their websites as iframes. I want them to not take my footer, header and a specific division in those iframes. Since, footer, header and mentioned specific division is present in all of my pages.
What should I do? Should I add some code in my header or in my `functions.php` file... | You could detect the `$_SERVER['HTTP_REFERER']` variable to detect whether the page is requested from an external server. If so, then you should load an alternative header and footer using `get_header()` and `get_footer()`. You'll need those calls to make sure all scripts and stylesheets are loaded, but you can remove ... |
187,651 | <p>Okay so I have been trying to educate myself to create new panels sections and controls dynamically using customizer's JS API.</p>
<p>It has been frustrating few days and I was unable to get the exact way to achieve this via JS API. </p>
<p>So far, this is some thing I am doing to make it happen but with no succe... | [
{
"answer_id": 189897,
"author": "Mohit Aneja",
"author_id": 54029,
"author_profile": "https://wordpress.stackexchange.com/users/54029",
"pm_score": -1,
"selected": false,
"text": "<p>I'd suggest instead of reinventing the wheel, maybe you will consider this framework as a base for your ... | 2015/05/07 | [
"https://wordpress.stackexchange.com/questions/187651",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/48410/"
] | Okay so I have been trying to educate myself to create new panels sections and controls dynamically using customizer's JS API.
It has been frustrating few days and I was unable to get the exact way to achieve this via JS API.
So far, this is some thing I am doing to make it happen but with no success:
```
// fo... | 1) Maybe bind to the api.ready state which may fix having to call your section twice
```
(function($, api){
api.bind( 'ready', function() {...
}
})(jQuery);
```
I saw a note in trac that said "Note that the APIs for dynamically-added controls, and APIs for JS-templated custom Sections and Panels are not yet ava... |
187,665 | <p>I am working on listing some working portfolio. I want to list a certain amount and I was reading the post_per_page can do that. </p>
<p>I have the following query, just trying to figure out where I can add the post par page code. I'm pretty new at php and wordpress. Any help would be appreciated.</p>
<pre><code>&... | [
{
"answer_id": 189897,
"author": "Mohit Aneja",
"author_id": 54029,
"author_profile": "https://wordpress.stackexchange.com/users/54029",
"pm_score": -1,
"selected": false,
"text": "<p>I'd suggest instead of reinventing the wheel, maybe you will consider this framework as a base for your ... | 2015/05/07 | [
"https://wordpress.stackexchange.com/questions/187665",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/68271/"
] | I am working on listing some working portfolio. I want to list a certain amount and I was reading the post\_per\_page can do that.
I have the following query, just trying to figure out where I can add the post par page code. I'm pretty new at php and wordpress. Any help would be appreciated.
```
<?php
$args = arra... | 1) Maybe bind to the api.ready state which may fix having to call your section twice
```
(function($, api){
api.bind( 'ready', function() {...
}
})(jQuery);
```
I saw a note in trac that said "Note that the APIs for dynamically-added controls, and APIs for JS-templated custom Sections and Panels are not yet ava... |
187,705 | <p>I've been asked to add a sort of safety mechanism to a site where a user can only access their profile if they have a cookie set after logging in, and they can only have a maximum of 3 cookies. I've made a table in the database to store the cookies, so I can keep count of them.</p>
<p>I don't really know how WordPr... | [
{
"answer_id": 187710,
"author": "Jayson",
"author_id": 72813,
"author_profile": "https://wordpress.stackexchange.com/users/72813",
"pm_score": 4,
"selected": true,
"text": "<p><code>wp_login</code> hook provides access to two parameters: <code>$user->user_login</code> (string) and <c... | 2015/05/08 | [
"https://wordpress.stackexchange.com/questions/187705",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/72812/"
] | I've been asked to add a sort of safety mechanism to a site where a user can only access their profile if they have a cookie set after logging in, and they can only have a maximum of 3 cookies. I've made a table in the database to store the cookies, so I can keep count of them.
I don't really know how WordPress works,... | `wp_login` hook provides access to two parameters: `$user->user_login` (string) and `$user` ( WP\_User ). To pass them into your function you will need to add a priority (default is 10) and request 2 arguments from the add\_action() call:
```
function login_cookie($user_login, $user) {
global $wpdb;
var_dump... |
187,731 | <p>For example, i include 'wp-load.php' from external file. but if WP is not installed, then while i access that file, it redirects to '/wp-admin/install.php'. How to disable redirection, even if WP not installed, it doesnt matter to me.</p>
| [
{
"answer_id": 187710,
"author": "Jayson",
"author_id": 72813,
"author_profile": "https://wordpress.stackexchange.com/users/72813",
"pm_score": 4,
"selected": true,
"text": "<p><code>wp_login</code> hook provides access to two parameters: <code>$user->user_login</code> (string) and <c... | 2015/05/08 | [
"https://wordpress.stackexchange.com/questions/187731",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/33667/"
] | For example, i include 'wp-load.php' from external file. but if WP is not installed, then while i access that file, it redirects to '/wp-admin/install.php'. How to disable redirection, even if WP not installed, it doesnt matter to me. | `wp_login` hook provides access to two parameters: `$user->user_login` (string) and `$user` ( WP\_User ). To pass them into your function you will need to add a priority (default is 10) and request 2 arguments from the add\_action() call:
```
function login_cookie($user_login, $user) {
global $wpdb;
var_dump... |
187,744 | <p>I have 2 post types: lets say <code>products</code> and <code>product_variations</code>. I'd like to be able to modify the query via <code>pre_get_posts</code> to get all product with meta_keys <code>"_visible" = "true"</code> and <code>"_available" = "true"</code> AND all product_variations with meta_key <code>"_fe... | [
{
"answer_id": 187710,
"author": "Jayson",
"author_id": 72813,
"author_profile": "https://wordpress.stackexchange.com/users/72813",
"pm_score": 4,
"selected": true,
"text": "<p><code>wp_login</code> hook provides access to two parameters: <code>$user->user_login</code> (string) and <c... | 2015/05/08 | [
"https://wordpress.stackexchange.com/questions/187744",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/6477/"
] | I have 2 post types: lets say `products` and `product_variations`. I'd like to be able to modify the query via `pre_get_posts` to get all product with meta\_keys `"_visible" = "true"` and `"_available" = "true"` AND all product\_variations with meta\_key `"_featured" = "true"`.
The product\_variations don't have the ... | `wp_login` hook provides access to two parameters: `$user->user_login` (string) and `$user` ( WP\_User ). To pass them into your function you will need to add a priority (default is 10) and request 2 arguments from the add\_action() call:
```
function login_cookie($user_login, $user) {
global $wpdb;
var_dump... |
187,769 | <p>I have this query:</p>
<pre><code>$cat_array = array();
$args=array(
'post_type' => 'post',
'post_status' => 'publish',
'exclude' => '187',
'posts_per_page' => 19,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_... | [
{
"answer_id": 187836,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 1,
"selected": false,
"text": "<p>Just skip the excluded category in your <code>foreach</code>:</p>\n\n<pre><code>foreach ( $cat_array as $c... | 2015/05/08 | [
"https://wordpress.stackexchange.com/questions/187769",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/6927/"
] | I have this query:
```
$cat_array = array();
$args=array(
'post_type' => 'post',
'post_status' => 'publish',
'exclude' => '187',
'posts_per_page' => 19,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
... | solved this with
```
if ($cat_array) {
foreach($cat_array as $cat) {
$category = get_term_by('ID',$cat, 'category');
if($category->name != 'Excluded category'){
echo '<div class="catspace"><a href="' . esc_attr(get_term_link($category, 'category')) . '" title="' . sprintf( __( "latest posts... |
187,773 | <p>I have a client's site where they want to add image title attributes dynamically to images that don't have one already. So if the title attribute is empty, add a title of whatever the post title is. How would I accomplish this?</p>
<p>Effectively:
<code><img src=img.jpg title=[wp-post-title-here] /></code></p... | [
{
"answer_id": 188273,
"author": "ambroseya",
"author_id": 72778,
"author_profile": "https://wordpress.stackexchange.com/users/72778",
"pm_score": 1,
"selected": false,
"text": "<p>If we can assume that this is done properly for images that are in templates, and you're only concerned abo... | 2015/05/08 | [
"https://wordpress.stackexchange.com/questions/187773",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/30778/"
] | I have a client's site where they want to add image title attributes dynamically to images that don't have one already. So if the title attribute is empty, add a title of whatever the post title is. How would I accomplish this?
Effectively:
`<img src=img.jpg title=[wp-post-title-here] />` | You can try the following test plugin, that uses the [`domDocument`](http://php.net/manual/en/class.domdocument.php) class, to see how it works on your HTML.
It assumes PHP 5.4+ with LibXML 2.7.8+.
```
<?php
/**
* Plugin Name: Add Missing Image Title Attributes
* Description: For posts in the main loop (Assumes PHP... |