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 |
|---|---|---|---|---|---|---|
245,405 | <p>I have a post meta for image uploads which allows a maximum of 5 files.</p>
<p>The data is stored in like this:</p>
<pre><code>a:5:{i:0;s:3:"694";i:1;s:3:"694";i:2;s:3:"697";i:3;s:3:"695";i:4;s:3:"696";}
</code></pre>
<p>The problem is, I can't get the image URLs. My code:</p>
<pre><code> <?php... | [
{
"answer_id": 245408,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 1,
"selected": false,
"text": "<p>You need to move </p>\n\n<pre><code> $ppurl = wp_get_attachment_url($value); // $value of the foreach\n</co... | 2016/11/07 | [
"https://wordpress.stackexchange.com/questions/245405",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/77768/"
] | I have a post meta for image uploads which allows a maximum of 5 files.
The data is stored in like this:
```
a:5:{i:0;s:3:"694";i:1;s:3:"694";i:2;s:3:"697";i:3;s:3:"695";i:4;s:3:"696";}
```
The problem is, I can't get the image URLs. My code:
```
<?php $ppics = get_post_meta( get_the_ID(), 'shop_de... | Your `var_dump` looks like it's returning an array because you're passing `false` to [`get_post_meta()`](https://developer.wordpress.org/reference/functions/get_post_meta/). Also you don't want to `print_r()` on an `echo` line.
>
> Retrieve post meta field for a post.
>
>
> * **$post\_id** *(int) (Required)* Post I... |
245,415 | <p>Does anyone know what is considered the best way to install Wordpress. Manually or perhaps is using something like Softaculous or QuickInstall the better approach?</p>
| [
{
"answer_id": 245416,
"author": "montrealist",
"author_id": 8105,
"author_profile": "https://wordpress.stackexchange.com/users/8105",
"pm_score": 0,
"selected": false,
"text": "<p>If you have access to the server and enough permissions to install/run things on it, I'd recommend installi... | 2016/11/08 | [
"https://wordpress.stackexchange.com/questions/245415",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/91629/"
] | Does anyone know what is considered the best way to install Wordpress. Manually or perhaps is using something like Softaculous or QuickInstall the better approach? | Use [WP-CLI's](https://wp-cli.org/) - `wp core install` - Runs the standard WordPress installation process.
>
> Creates the WordPress tables in the database using the URL, title, and default admin user details provided. Performs the famous 5 minute install in seconds or less.
>
>
>
```
$ wp core install --url=exa... |
245,445 | <p>I'm trying to create add-ones of WC-Vendors where I have to create custom post type for Vendor user Only.</p>
<p>Here is code snippet I used</p>
<pre><code> register_post_type( 'acme_product',
array(
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product' ... | [
{
"answer_id": 245453,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 0,
"selected": false,
"text": "<p>You need to add the <strong>capability</strong> and/or <strong>map_meta_cap</strong> to the argument array of ... | 2016/11/08 | [
"https://wordpress.stackexchange.com/questions/245445",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/96426/"
] | I'm trying to create add-ones of WC-Vendors where I have to create custom post type for Vendor user Only.
Here is code snippet I used
```
register_post_type( 'acme_product',
array(
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product' )
),
'public' => t... | First you have to passed two additional arguments into the register\_post\_type() function.
1. capability\_type
2. map\_meta\_cap
Then, You can add capability using [add\_cap();](https://codex.wordpress.org/Function_Reference/add_cap) function.
```
register_post_type( 'acme_product',
array(
'labels' => ar... |
245,455 | <p>My plugin has several php files that are included on the main plugin file. I am using some functions on the other files but they don't work there. They work when I use them on the main plugin file.</p>
<p>For example,</p>
<p><strong>On the main plugin file <em>"test-plugin.php"</em></strong></p>
<pre><code><?p... | [
{
"answer_id": 245453,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 0,
"selected": false,
"text": "<p>You need to add the <strong>capability</strong> and/or <strong>map_meta_cap</strong> to the argument array of ... | 2016/11/08 | [
"https://wordpress.stackexchange.com/questions/245455",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/42650/"
] | My plugin has several php files that are included on the main plugin file. I am using some functions on the other files but they don't work there. They work when I use them on the main plugin file.
For example,
**On the main plugin file *"test-plugin.php"***
```
<?php
/*
Plugin Name: Test Plugin
Description: test
Ve... | First you have to passed two additional arguments into the register\_post\_type() function.
1. capability\_type
2. map\_meta\_cap
Then, You can add capability using [add\_cap();](https://codex.wordpress.org/Function_Reference/add_cap) function.
```
register_post_type( 'acme_product',
array(
'labels' => ar... |
245,462 | <p>My code was checked and seems OK so maybe the problem lies in the <code>htaccess</code> file whose content on my online server is:</p>
<pre><code>SetEnv PHP_VER 5_4
Options -Indexes
ErrorDocument 404 /index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.fr$
RewriteRule ^(.*) http://www.example.fr/$1... | [
{
"answer_id": 245736,
"author": "Michelle",
"author_id": 16,
"author_profile": "https://wordpress.stackexchange.com/users/16",
"pm_score": 1,
"selected": false,
"text": "<p>You may need to use <code>bloginfo('url')</code> aka <a href=\"https://developer.wordpress.org/reference/functions... | 2016/11/08 | [
"https://wordpress.stackexchange.com/questions/245462",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/11634/"
] | My code was checked and seems OK so maybe the problem lies in the `htaccess` file whose content on my online server is:
```
SetEnv PHP_VER 5_4
Options -Indexes
ErrorDocument 404 /index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.fr$
RewriteRule ^(.*) http://www.example.fr/$1 [QSA,L,R=301]
```
An... | The best way to deal with Form Posts in Wordpress is to use a special endpoint, **/wp-admin/admin-post.php**.
POST data can be messed up, both by the WP Query call, and by any redirects that happen.
So you set up your form with this action:
```
<form action="<?= admin_url('admin-post.php') ?>" method="post">
<input... |
245,465 | <p>I wanted to filter the blog title displayed in the header to apply different CSS styles to different title parts/words, so I added the below function to my (WP 4.7) Twenty Seventeen child theme's <em>functions.php</em> and this worked very well. The problem is that this function added the CSS code also to the meta t... | [
{
"answer_id": 245736,
"author": "Michelle",
"author_id": 16,
"author_profile": "https://wordpress.stackexchange.com/users/16",
"pm_score": 1,
"selected": false,
"text": "<p>You may need to use <code>bloginfo('url')</code> aka <a href=\"https://developer.wordpress.org/reference/functions... | 2016/11/08 | [
"https://wordpress.stackexchange.com/questions/245465",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25187/"
] | I wanted to filter the blog title displayed in the header to apply different CSS styles to different title parts/words, so I added the below function to my (WP 4.7) Twenty Seventeen child theme's *functions.php* and this worked very well. The problem is that this function added the CSS code also to the meta title displ... | The best way to deal with Form Posts in Wordpress is to use a special endpoint, **/wp-admin/admin-post.php**.
POST data can be messed up, both by the WP Query call, and by any redirects that happen.
So you set up your form with this action:
```
<form action="<?= admin_url('admin-post.php') ?>" method="post">
<input... |
245,478 | <p>Looking at <a href="https://developer.wordpress.org/reference/functions/get_post_meta/" rel="noreferrer"><code>get_post_meta()</code></a> I always have to remember to set the <code>$single</code> param to <code>true</code>. I generally assume I'm setting a value and I expect to get that value back.</p>
<blockquote>... | [
{
"answer_id": 245480,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": -1,
"selected": false,
"text": "<p>If you have a serialize value in the meta, you can set it to true and get the unserialize array. </p>\n\n<p>S... | 2016/11/08 | [
"https://wordpress.stackexchange.com/questions/245478",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84219/"
] | Looking at [`get_post_meta()`](https://developer.wordpress.org/reference/functions/get_post_meta/) I always have to remember to set the `$single` param to `true`. I generally assume I'm setting a value and I expect to get that value back.
>
> Retrieve post meta field for a post.
>
>
> * **$post\_id** *(int) (Requir... | In general, **storing PHP serialized data in database in a bad idea**. It can be easily understood if you use multple key-value pairs of data in one field row, that is, you use an array or a object with one meta key.
Imaging a car as the object. You can set multiple meta values to describe the car, for example `color`... |
245,479 | <p>I'm using <a href="https://wordpress.org/plugins/ajax-load-more/" rel="nofollow noreferrer">Ajax Load more</a> plugin. <br>
I have made it to load X posts on button click, but on the page load there are no posts loaded initially (obviously). <br>
What should I do to have (let's say) 10 posts loaded automatically and... | [
{
"answer_id": 245483,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 3,
"selected": true,
"text": "<p>You need to set the <code>offset</code> in the query.</p>\n\n<p>To get the right offset value, you will need to... | 2016/11/08 | [
"https://wordpress.stackexchange.com/questions/245479",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106555/"
] | I'm using [Ajax Load more](https://wordpress.org/plugins/ajax-load-more/) plugin.
I have made it to load X posts on button click, but on the page load there are no posts loaded initially (obviously).
What should I do to have (let's say) 10 posts loaded automatically and then next ones loading only on button cli... | You need to set the `offset` in the query.
To get the right offset value, you will need to store and send back the offset value to your ajax script (`data-offset` in the input or an hidden field).
```
$args = array(
'posts_per_page'=> 10,
'post_status'=> 'publish',
'offset'=> $_POST['off... |
245,482 | <p>My visual editor isn't working on a site after just launching it to a new server. I assumed a permissions issue, but the file itself is set to 644. I tried 755 on it as well and still no go. The directories all the way up are 755. </p>
<p>I can access other files in the directory, but not this one file. Any ideas? ... | [
{
"answer_id": 245483,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 3,
"selected": true,
"text": "<p>You need to set the <code>offset</code> in the query.</p>\n\n<p>To get the right offset value, you will need to... | 2016/11/08 | [
"https://wordpress.stackexchange.com/questions/245482",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24054/"
] | My visual editor isn't working on a site after just launching it to a new server. I assumed a permissions issue, but the file itself is set to 644. I tried 755 on it as well and still no go. The directories all the way up are 755.
I can access other files in the directory, but not this one file. Any ideas? | You need to set the `offset` in the query.
To get the right offset value, you will need to store and send back the offset value to your ajax script (`data-offset` in the input or an hidden field).
```
$args = array(
'posts_per_page'=> 10,
'post_status'=> 'publish',
'offset'=> $_POST['off... |
245,512 | <p>I was developing a new WordPress website so i added this function at the end of the "functions.php" file to redirect all users to a /maintenance-mode page in my website except me(My IP-Address):</p>
<pre><code>function wp_maintenance_mode() {
if ( !is_page( 2075 ) && $_SERVER['REMOTE_ADDR'] != "111.222.... | [
{
"answer_id": 245521,
"author": "mpickett",
"author_id": 106046,
"author_profile": "https://wordpress.stackexchange.com/users/106046",
"pm_score": 0,
"selected": false,
"text": "<p>Have you tried to take the function out of functions.php file altogether? I had a similar issue, not with ... | 2016/11/08 | [
"https://wordpress.stackexchange.com/questions/245512",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97480/"
] | I was developing a new WordPress website so i added this function at the end of the "functions.php" file to redirect all users to a /maintenance-mode page in my website except me(My IP-Address):
```
function wp_maintenance_mode() {
if ( !is_page( 2075 ) && $_SERVER['REMOTE_ADDR'] != "111.222.33.44" ) {
wp_... | I was able to fix it finally! .. All i did is deactivating all WordPress plugins then reactivating them again, and all worked fine .. Just that!!! |
245,513 | <p>I want to know, how to get i.e. $post ID, TITLE and etc.. in metabox?</p>
<p>is other solution available, instead of <code>$GLOBALS['post']</code> ?</p>
| [
{
"answer_id": 245514,
"author": "kaiser",
"author_id": 385,
"author_profile": "https://wordpress.stackexchange.com/users/385",
"pm_score": 1,
"selected": false,
"text": "<p>Just go with what the API provides (the global <code>$post</code> object refers to the post that is set up via the... | 2016/11/08 | [
"https://wordpress.stackexchange.com/questions/245513",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/33667/"
] | I want to know, how to get i.e. $post ID, TITLE and etc.. in metabox?
is other solution available, instead of `$GLOBALS['post']` ? | Do not rely on globals like `get_the_ID()` or `get_post()` do. Use the parameters for your callbacks.
You get the current post object **twice**:
1. When you register the metabox, you get the post object as a second parameter.
2. When your output callback is called, you get it as the first parameter.
Here is an examp... |
245,520 | <p>If someone opens any post at the front-end, does it matter how many times I call <code>get_post_meta</code> function? I thought it could increase performance if I won't call that function 2-3 times instead of 20 calls on single post page.</p>
| [
{
"answer_id": 245524,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 3,
"selected": true,
"text": "<p>One call to <code>get_post_meta()</code> fetches all met keys and values for that post. All these values are then stor... | 2016/11/08 | [
"https://wordpress.stackexchange.com/questions/245520",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/33667/"
] | If someone opens any post at the front-end, does it matter how many times I call `get_post_meta` function? I thought it could increase performance if I won't call that function 2-3 times instead of 20 calls on single post page. | One call to `get_post_meta()` fetches all met keys and values for that post. All these values are then stored in the cache. The next call will just fetch the data from the cache. So you can safely call that function multiple times.
In details:
1. `get_post_meta()` calls `get_metadata('post', $post_id, $key, $single);... |
245,523 | <p>I am using child theme of rehub theme to create a website. Just like many other themes it has option of "static homepage" and "recent posts" homepage. As my theme is a deal based theme I have to use "recent posts" options.</p>
<p>But, due to this the home page is missing H1 tag because there is no tag by default in... | [
{
"answer_id": 245524,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 3,
"selected": true,
"text": "<p>One call to <code>get_post_meta()</code> fetches all met keys and values for that post. All these values are then stor... | 2016/11/08 | [
"https://wordpress.stackexchange.com/questions/245523",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106576/"
] | I am using child theme of rehub theme to create a website. Just like many other themes it has option of "static homepage" and "recent posts" homepage. As my theme is a deal based theme I have to use "recent posts" options.
But, due to this the home page is missing H1 tag because there is no tag by default in the theme... | One call to `get_post_meta()` fetches all met keys and values for that post. All these values are then stored in the cache. The next call will just fetch the data from the cache. So you can safely call that function multiple times.
In details:
1. `get_post_meta()` calls `get_metadata('post', $post_id, $key, $single);... |
245,535 | <p>Usually, you would use <code>esc_url()</code> to escape a URL before displaying it. If that 'URL' is a data URI (eg. <code>'data:image/svg+xml;base64,...'</code>), it will be trimmed blank by <code>esc_url()</code>.</p>
<p>The Codex page on Data Validation <a href="https://codex.wordpress.org/Data_Validation#URLs" ... | [
{
"answer_id": 245539,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 1,
"selected": false,
"text": "<p>A data UR<strong>I</strong> isn't quite a ur<strong>l</strong>, but it <strong>is</strong> an attribute. Use... | 2016/11/08 | [
"https://wordpress.stackexchange.com/questions/245535",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/46066/"
] | Usually, you would use `esc_url()` to escape a URL before displaying it. If that 'URL' is a data URI (eg. `'data:image/svg+xml;base64,...'`), it will be trimmed blank by `esc_url()`.
The Codex page on Data Validation [has this to say](https://codex.wordpress.org/Data_Validation#URLs) about escaping URLs:
>
> Always ... | It is possible to pass an array with allowed protocols to the [esc\_url()](https://developer.wordpress.org/reference/functions/esc_url/) function. For data-URLs this has to contain the `data` scheme, as this is not whitelisted by [wp\_allowed\_protocols()](https://developer.wordpress.org/reference/functions/wp_allowed_... |
245,544 | <p>Forgive me if this is discussed elsewhere on the forums but I can't seem to find it anywhere. How can we display the current time from the blog (or from New York, for instance) within a block of text? It would be even better if it continues changing each second after loading but not necessary.</p>
<p>This would be ... | [
{
"answer_id": 245545,
"author": "jgraup",
"author_id": 84219,
"author_profile": "https://wordpress.stackexchange.com/users/84219",
"pm_score": 2,
"selected": false,
"text": "<p>Take a look at <a href=\"https://codex.wordpress.org/Function_Reference/current_time\" rel=\"nofollow noreferr... | 2016/11/08 | [
"https://wordpress.stackexchange.com/questions/245544",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/96983/"
] | Forgive me if this is discussed elsewhere on the forums but I can't seem to find it anywhere. How can we display the current time from the blog (or from New York, for instance) within a block of text? It would be even better if it continues changing each second after loading but not necessary.
This would be difference... | Take a look at [`current_time()`](https://codex.wordpress.org/Function_Reference/current_time).
>
> Returns the blog's current local time in the specified format. There are two named formats: 'mysql' for MySQL/MariaDB's timestamp data type format (i.e. YYYY-MM-DD HH:MM:SS), and 'timestamp' for the Unix timestamp form... |
245,589 | <p>The solution <code><?php query_posts('posts_per_page=9'); ?></code> to limit author related posts show the entire website post :( </p>
<pre><code> <?php
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
?>
<h2>About: <?php ech... | [
{
"answer_id": 245590,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 2,
"selected": true,
"text": "<p>Never, <strong>never</strong> re-query a native archive - use the <a href=\"https://codex.wordpress.org/Plu... | 2016/11/09 | [
"https://wordpress.stackexchange.com/questions/245589",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24058/"
] | The solution `<?php query_posts('posts_per_page=9'); ?>` to limit author related posts show the entire website post :(
```
<?php
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
?>
<h2>About: <?php echo $curauth->nickname; ?></h2>
<dl>
<dt>W... | Never, **never** re-query a native archive - use the [`pre_get_posts` hook](https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts) to *alter* the main query:
```
add_action( 'pre_get_posts', function ( $wp_query ) {
if ( $wp_query->is_main_query() && $wp_query->is_author() ) {
$paged = max(... |
245,622 | <p>When I enqueue Bootstrap with <code>wp_enqueue_style()</code>, Bootstrap is loaded after the child theme's <code>style.css</code> and will override <code>style.css</code>.
One way to load <code>style.css</code> after Bootstrap is to enqueue <code>style.css</code> as well, but this will cause it to be loaded twice.
A... | [
{
"answer_id": 245623,
"author": "jdm2112",
"author_id": 45202,
"author_profile": "https://wordpress.stackexchange.com/users/45202",
"pm_score": 2,
"selected": false,
"text": "<p>Good news. This is an easy fix. WordPress allows you to declare dependencies when registering scripts and ... | 2016/11/09 | [
"https://wordpress.stackexchange.com/questions/245622",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/105416/"
] | When I enqueue Bootstrap with `wp_enqueue_style()`, Bootstrap is loaded after the child theme's `style.css` and will override `style.css`.
One way to load `style.css` after Bootstrap is to enqueue `style.css` as well, but this will cause it to be loaded twice.
Any idea how to enqueue `style.css` once AND after Bootstra... | Mostly the parent theme might be enqueing the child theme's `style.css`, if so you can dequeue it by using handle and then enqueue with proper dependency.
If the child theme's handle is `child-theme-style`, then dequeue it using
`wp_dequeue_style('child-theme-style')`
then enqueue it as needed like so.
```
wp_enque... |
245,636 | <p>I have a custom field with the key <code>colour</code> and the value can either be <code>red</code> or <code>blue</code> for individual posts.</p>
<p>I know the code to return posts that are either red or blue i.e. <code>?colour=red</code>, but I don't know the code to return posts that are either red or blue i.e. ... | [
{
"answer_id": 245623,
"author": "jdm2112",
"author_id": 45202,
"author_profile": "https://wordpress.stackexchange.com/users/45202",
"pm_score": 2,
"selected": false,
"text": "<p>Good news. This is an easy fix. WordPress allows you to declare dependencies when registering scripts and ... | 2016/11/09 | [
"https://wordpress.stackexchange.com/questions/245636",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106177/"
] | I have a custom field with the key `colour` and the value can either be `red` or `blue` for individual posts.
I know the code to return posts that are either red or blue i.e. `?colour=red`, but I don't know the code to return posts that are either red or blue i.e. `?colour=red&colour=blue`.
I have received help with ... | Mostly the parent theme might be enqueing the child theme's `style.css`, if so you can dequeue it by using handle and then enqueue with proper dependency.
If the child theme's handle is `child-theme-style`, then dequeue it using
`wp_dequeue_style('child-theme-style')`
then enqueue it as needed like so.
```
wp_enque... |
245,653 | <p>I am using this code:</p>
<pre><code>function the_alt_title($title= '') {
$page = get_page_by_title($title);
if ($p = get_post_meta($page->ID, "_x_entry_alternate_index_title", true)) {
$title = $p;
}
return $title;
}
add_filter('the_title', 'the_alt_title', 10, 1);
</code></pre>
<p>In ... | [
{
"answer_id": 245654,
"author": "ngearing",
"author_id": 50184,
"author_profile": "https://wordpress.stackexchange.com/users/50184",
"pm_score": 3,
"selected": true,
"text": "<p><code>$page = get_page_by_title($title)</code> - this line is failing somewhere, so you should do a check on ... | 2016/11/09 | [
"https://wordpress.stackexchange.com/questions/245653",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40727/"
] | I am using this code:
```
function the_alt_title($title= '') {
$page = get_page_by_title($title);
if ($p = get_post_meta($page->ID, "_x_entry_alternate_index_title", true)) {
$title = $p;
}
return $title;
}
add_filter('the_title', 'the_alt_title', 10, 1);
```
In debug.log i get
```
PHP Noti... | `$page = get_page_by_title($title)` - this line is failing somewhere, so you should do a check on this to make sure it exists.
Like so:
```
function the_alt_title($title= '') {
$page = get_page_by_title($title);
if (!$page) {
return $title;
}
if ($p = get_post_meta($page->ID, "_x_entry_altern... |
245,682 | <p>I have a simple WP_Query to get a list of posts of co-author (taxonomy <em>author</em>) order by date, this is the query :</p>
<pre class="lang-php prettyprint-override"><code>$username = get_the_author_meta( 'login', $author_id );
$args = array(
'post_type' => 'any',
'orderby' => 'date',
//'orderby' =&g... | [
{
"answer_id": 273835,
"author": "Pravin Work",
"author_id": 120969,
"author_profile": "https://wordpress.stackexchange.com/users/120969",
"pm_score": 5,
"selected": true,
"text": "<p>This will definitely work....It worked for me...</p>\n<pre class=\"lang-php prettyprint-override\"><code... | 2016/11/10 | [
"https://wordpress.stackexchange.com/questions/245682",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/100533/"
] | I have a simple WP\_Query to get a list of posts of co-author (taxonomy *author*) order by date, this is the query :
```php
$username = get_the_author_meta( 'login', $author_id );
$args = array(
'post_type' => 'any',
'orderby' => 'date',
//'orderby' => 'post_date',
'order' => 'DESC',
'tax_query' => array(
... | This will definitely work....It worked for me...
```php
$username = get_the_author_meta( 'login', $author_id );
$args = array(
'post_type' => 'any',
'orderby' => 'date',
'order' => 'DESC',
'suppress_filters' => true,
'tax_query' => array(
array(
'taxonomy' => 'author',
... |
245,688 | <p>I have a strange issue that i don't really understand, I explain :
In my <code>tag.php</code>, i have an infinite scroll with custom post types thanks to the active tag and ajax.</p>
<pre><code>$posts = get_posts( array(
'post_type' => 'video',
'posts_per_page' => 6,
'paged' => 1,
'post_sta... | [
{
"answer_id": 273835,
"author": "Pravin Work",
"author_id": 120969,
"author_profile": "https://wordpress.stackexchange.com/users/120969",
"pm_score": 5,
"selected": true,
"text": "<p>This will definitely work....It worked for me...</p>\n<pre class=\"lang-php prettyprint-override\"><code... | 2016/11/10 | [
"https://wordpress.stackexchange.com/questions/245688",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106689/"
] | I have a strange issue that i don't really understand, I explain :
In my `tag.php`, i have an infinite scroll with custom post types thanks to the active tag and ajax.
```
$posts = get_posts( array(
'post_type' => 'video',
'posts_per_page' => 6,
'paged' => 1,
'post_status' => 'publish',
'post__not_... | This will definitely work....It worked for me...
```php
$username = get_the_author_meta( 'login', $author_id );
$args = array(
'post_type' => 'any',
'orderby' => 'date',
'order' => 'DESC',
'suppress_filters' => true,
'tax_query' => array(
array(
'taxonomy' => 'author',
... |
245,702 | <p>I have <code>current_time</code> in theme and it displays date like: <code>THURSDAY, NOVEMBER 10, 2016</code>. But I need to translate it to Persian. How can I do this?</p>
| [
{
"answer_id": 245705,
"author": "Demyd Ganenko",
"author_id": 88455,
"author_profile": "https://wordpress.stackexchange.com/users/88455",
"pm_score": 3,
"selected": true,
"text": "<p>Used <code>date_i18n</code> instead of <code>current_time</code>. For example:</p>\n\n<pre><code>echo da... | 2016/11/10 | [
"https://wordpress.stackexchange.com/questions/245702",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/88455/"
] | I have `current_time` in theme and it displays date like: `THURSDAY, NOVEMBER 10, 2016`. But I need to translate it to Persian. How can I do this? | Used `date_i18n` instead of `current_time`. For example:
```
echo date_i18n( 'Y. F j.', strtotime( get_the_time( "Y-m-d" ) ) );
``` |
245,724 | <p>Im using the following code on my WordPress custom theme home page to display the latest three portfolio posts:</p>
<pre><code><?php query_posts('post_type=portfolio&showposts=3'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="col-lg-4 col-md-... | [
{
"answer_id": 245705,
"author": "Demyd Ganenko",
"author_id": 88455,
"author_profile": "https://wordpress.stackexchange.com/users/88455",
"pm_score": 3,
"selected": true,
"text": "<p>Used <code>date_i18n</code> instead of <code>current_time</code>. For example:</p>\n\n<pre><code>echo da... | 2016/11/10 | [
"https://wordpress.stackexchange.com/questions/245724",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106714/"
] | Im using the following code on my WordPress custom theme home page to display the latest three portfolio posts:
```
<?php query_posts('post_type=portfolio&showposts=3'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12" <?php post... | Used `date_i18n` instead of `current_time`. For example:
```
echo date_i18n( 'Y. F j.', strtotime( get_the_time( "Y-m-d" ) ) );
``` |
245,728 | <p>I have installed a compressing plugin (<a href="https://wordpress.org/plugins/tiny-compress-images/" rel="nofollow noreferrer">https://wordpress.org/plugins/tiny-compress-images/</a>) in Wordpress to minimize the file size of all the images that I upload. Works really well, the only problem is the following:</p>
<p... | [
{
"answer_id": 245705,
"author": "Demyd Ganenko",
"author_id": 88455,
"author_profile": "https://wordpress.stackexchange.com/users/88455",
"pm_score": 3,
"selected": true,
"text": "<p>Used <code>date_i18n</code> instead of <code>current_time</code>. For example:</p>\n\n<pre><code>echo da... | 2016/11/10 | [
"https://wordpress.stackexchange.com/questions/245728",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106713/"
] | I have installed a compressing plugin (<https://wordpress.org/plugins/tiny-compress-images/>) in Wordpress to minimize the file size of all the images that I upload. Works really well, the only problem is the following:
If I create a new page, insert a picture and resize it manually in the editor Wordpress seems to cr... | Used `date_i18n` instead of `current_time`. For example:
```
echo date_i18n( 'Y. F j.', strtotime( get_the_time( "Y-m-d" ) ) );
``` |
245,730 | <p>I'm getting this error when I imported the dummy data through WP importer.can any tell me what is the problem. </p>
<p><a href="https://i.stack.imgur.com/D9V1v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D9V1v.png" alt="enter image description here"></a></p>
| [
{
"answer_id": 245732,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 1,
"selected": false,
"text": "<p>The screenshot states the problem clearly:</p>\n\n<pre><code>Maximum execution time of 60 seconds exceeded\n... | 2016/11/10 | [
"https://wordpress.stackexchange.com/questions/245730",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/105528/"
] | I'm getting this error when I imported the dummy data through WP importer.can any tell me what is the problem.
[](https://i.stack.imgur.com/D9V1v.png) | The screenshot states the problem clearly:
```
Maximum execution time of 60 seconds exceeded
```
Pages have a time limit inside which they need to do their work, otherwise a badly written PHP script could run forever.
This is why importing huge data sets runs into this problem. The bigger the import, the longer it ... |
245,751 | <p>I have an existing for loop, which is necessary for the design and layout. Inside this for loop I need show post by post.</p>
<p>This is my code.</p>
<pre><code><?php for($i=$val;$i<=$cdn;$i++) { ?>
<div class="desc dsc<?php echo $dsc++; ?>" style="display: none">
<div class="team-detai... | [
{
"answer_id": 245754,
"author": "elicohenator",
"author_id": 98507,
"author_profile": "https://wordpress.stackexchange.com/users/98507",
"pm_score": 0,
"selected": false,
"text": "<p>You should seperate the number you're 'echoing' from the loop. here's an example from a recent site I've... | 2016/11/10 | [
"https://wordpress.stackexchange.com/questions/245751",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/77627/"
] | I have an existing for loop, which is necessary for the design and layout. Inside this for loop I need show post by post.
This is my code.
```
<?php for($i=$val;$i<=$cdn;$i++) { ?>
<div class="desc dsc<?php echo $dsc++; ?>" style="display: none">
<div class="team-details">
<div class="name">
<... | If you're looking to get the post id to say add it to a div use the\_ID()
```
<div id="post-<?php the_ID(); ?>">
``` |
245,769 | <p>I want to ger several recent posts. So I use wp_get_recent_posts. But I get only first image.</p>
<pre><code><?php $args = array( 'numberposts' => '3' );
$recent_posts = wp_get_recent_posts($args);
foreach( $recent_posts as $recent ){
echo '<li><a href="' . get_permalink($recent["ID"]) . '">'... | [
{
"answer_id": 245772,
"author": "Syed Fakhar Abbas",
"author_id": 90591,
"author_profile": "https://wordpress.stackexchange.com/users/90591",
"pm_score": 4,
"selected": true,
"text": "<p>Actually, the condition is always returning false because you are not passing the post id to the fun... | 2016/11/10 | [
"https://wordpress.stackexchange.com/questions/245769",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/103556/"
] | I want to ger several recent posts. So I use wp\_get\_recent\_posts. But I get only first image.
```
<?php $args = array( 'numberposts' => '3' );
$recent_posts = wp_get_recent_posts($args);
foreach( $recent_posts as $recent ){
echo '<li><a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"].'</a... | Actually, the condition is always returning false because you are not passing the post id to the function [`has_post_thumbnail()`](https://developer.wordpress.org/reference/functions/has_post_thumbnail/) and the function always getting the default value which is `null`.
`has_post_thumbnail( $recent["ID"] )`.
Same wi... |
245,817 | <p>I'd like to remove the "Powered by Wordpress" custom link in the footer. </p>
<p>I want to do this using action hooks/filters in the child theme's <code>function.php</code> file.</p>
<p>I don't want to use CSS (which just hides it), edit the original theme file (which will get overriden when the theme updates), or... | [
{
"answer_id": 245867,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 0,
"selected": false,
"text": "<p>The function <code>sparkling_footer_info()</code> is directly called from the footer code, without any action or... | 2016/11/11 | [
"https://wordpress.stackexchange.com/questions/245817",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106748/"
] | I'd like to remove the "Powered by Wordpress" custom link in the footer.
I want to do this using action hooks/filters in the child theme's `function.php` file.
I don't want to use CSS (which just hides it), edit the original theme file (which will get overriden when the theme updates), or copy the `footer.php` file ... | As the function `sparkling_footer_info()` uses [`esc_html__()`](https://developer.wordpress.org/reference/functions/esc_html__/) and this function runs the [`esc_html`](https://developer.wordpress.org/reference/hooks/esc_html/) filter before outputting, you can intercept the output there.
```
add_filter ('esc_html', '... |
245,819 | <p>I want to display a custom button in my "Edit post" screen which saves the current post (everything including custom fields) and then runs a function (in my case redirecting to another page).</p>
<p>I know how to redirect after saving the post using the <code>save_posts</code> action and <code>wp_redirect</code> bu... | [
{
"answer_id": 245867,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 0,
"selected": false,
"text": "<p>The function <code>sparkling_footer_info()</code> is directly called from the footer code, without any action or... | 2016/11/11 | [
"https://wordpress.stackexchange.com/questions/245819",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/70492/"
] | I want to display a custom button in my "Edit post" screen which saves the current post (everything including custom fields) and then runs a function (in my case redirecting to another page).
I know how to redirect after saving the post using the `save_posts` action and `wp_redirect` but I can't figure out how to save... | As the function `sparkling_footer_info()` uses [`esc_html__()`](https://developer.wordpress.org/reference/functions/esc_html__/) and this function runs the [`esc_html`](https://developer.wordpress.org/reference/hooks/esc_html/) filter before outputting, you can intercept the output there.
```
add_filter ('esc_html', '... |
245,822 | <p>I am developing my WordPress theme using Material Bootstrap Design (MDB), a Material variant that uses Bootstrap 4 plus its own code.</p>
<p>It <a href="http://mdbootstrap.com/mdb-quick-start/" rel="nofollow noreferrer">calls for</a> using the following scripts...</p>
<pre><code><!-- JQuery -->
<script ty... | [
{
"answer_id": 245847,
"author": "Jesper Nilsson",
"author_id": 102950,
"author_profile": "https://wordpress.stackexchange.com/users/102950",
"pm_score": 0,
"selected": false,
"text": "<p>Maybe this is not that much of a WordPress question after all. But as far as I have seen the Bootstr... | 2016/11/11 | [
"https://wordpress.stackexchange.com/questions/245822",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/39300/"
] | I am developing my WordPress theme using Material Bootstrap Design (MDB), a Material variant that uses Bootstrap 4 plus its own code.
It [calls for](http://mdbootstrap.com/mdb-quick-start/) using the following scripts...
```
<!-- JQuery -->
<script type="text/javascript" src="/wp-content/themes/blankslate/mdb/js/jque... | WordPress loads jQuery because plugins and themes suppose it does. If you want another version of jQuery for your theme, there is a risk that plugins you may be using will not work, since (if they are maintained well) they are designed to work [with default jquery](https://wordpress.stackexchange.com/questions/244537/w... |
245,838 | <p>First, i'd like to point I do this probably wrong, but this is a bit of a desperate thing and it popped in my head.</p>
<p>We are developing a site for a client, and he wants breadcrumbs. Now we downloaded a plugin that allows you to place breadcrumbs by calling the breadcrumbs_trial function. Since the theme doesn... | [
{
"answer_id": 245841,
"author": "Community",
"author_id": -1,
"author_profile": "https://wordpress.stackexchange.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "<p>That is very tricky. I would manually place it in the template directly where I want it (or where the client want... | 2016/11/11 | [
"https://wordpress.stackexchange.com/questions/245838",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/87085/"
] | First, i'd like to point I do this probably wrong, but this is a bit of a desperate thing and it popped in my head.
We are developing a site for a client, and he wants breadcrumbs. Now we downloaded a plugin that allows you to place breadcrumbs by calling the breadcrumbs\_trial function. Since the theme doesn't suppor... | This will probably not work, or work in unexpected way. Shortcodes should **probably** be displayed only on a "post" single page. Using a shortcode in the way you want will either make the breadcrumbs not to be displayed on archive pages or have them displayed there multiple times or wrong places.
What you should do i... |
245,853 | <p>I am building a custom loop where I want to display post content only if its title matches a specific string. But I am out of luck on getting this done right. </p>
<p>Here is my code so far. </p>
<pre><code>$args = array(
'post_type' => 'property',
'posts_per_page' => -1
);
$query = new WP_Query( $args );
... | [
{
"answer_id": 245841,
"author": "Community",
"author_id": -1,
"author_profile": "https://wordpress.stackexchange.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "<p>That is very tricky. I would manually place it in the template directly where I want it (or where the client want... | 2016/11/11 | [
"https://wordpress.stackexchange.com/questions/245853",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/58787/"
] | I am building a custom loop where I want to display post content only if its title matches a specific string. But I am out of luck on getting this done right.
Here is my code so far.
```
$args = array(
'post_type' => 'property',
'posts_per_page' => -1
);
$query = new WP_Query( $args );
if ( $query->have_posts() )... | This will probably not work, or work in unexpected way. Shortcodes should **probably** be displayed only on a "post" single page. Using a shortcode in the way you want will either make the breadcrumbs not to be displayed on archive pages or have them displayed there multiple times or wrong places.
What you should do i... |
245,877 | <h1>Question</h1>
<p>What are all the files that I have to modify to get this to work?</p>
<h2>Background</h2>
<p>I have been searching stackoverflow for similar answers. Most talk about modifying something called a <code>php.ini</code> file. Which i have not been able to locate. But is that actually the case for WordP... | [
{
"answer_id": 245944,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 1,
"selected": false,
"text": "<p>The issue is exactly what @shanebp says - it's a PHP configuration issue. <em>However</em>, I can't see an... | 2016/11/11 | [
"https://wordpress.stackexchange.com/questions/245877",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/104295/"
] | Question
========
What are all the files that I have to modify to get this to work?
Background
----------
I have been searching stackoverflow for similar answers. Most talk about modifying something called a `php.ini` file. Which i have not been able to locate. But is that actually the case for WordPress themes?
I ... | I fixed the problem of not being able to see the thumbnails. Not sure this is the best overall long term solution, but it works now
[](https://i.stack.imgur.com/cwGad.png)
I added this line to the `php.ini` file.
```
allow_url_fopen = On
```
I fou... |
245,894 | <p>i'm using wordpress 4.6
i'd like to remove just the title tag automatically outputted by wordpress because need to hardcode the html title tag in the template.</p>
<p>i guess is something like this:</p>
<pre><code>add_action('wp_head', '//remove title tag command');
</code></pre>
<p>but i didn't find any valid so... | [
{
"answer_id": 245901,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 4,
"selected": true,
"text": "<p>You can see everything added to <code>wp_head</code> in the file <a href=\"https://github.com/WordPress/WordPress/b... | 2016/11/12 | [
"https://wordpress.stackexchange.com/questions/245894",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/104218/"
] | i'm using wordpress 4.6
i'd like to remove just the title tag automatically outputted by wordpress because need to hardcode the html title tag in the template.
i guess is something like this:
```
add_action('wp_head', '//remove title tag command');
```
but i didn't find any valid solution so far. | You can see everything added to `wp_head` in the file [`/wp-includes/default-filters.php`](https://github.com/WordPress/WordPress/blob/master/wp-includes/default-filters.php#L237).
If your theme supports the title tag, you can remove it entirely with `remove_action`:
```
remove_action( 'wp_head', '_wp_render_title_ta... |
245,906 | <p>I'm working on a custom project for a client and having an issue adding in <code>data-scroll</code> before the links in WordPress. I want the output to be <code><a data-scroll href='#'></code>. </p>
<p>Data-scroll is what I am looking to add in just after the a, <em>here</em> <code>href ="#"</code></p>
<p>Ho... | [
{
"answer_id": 245910,
"author": "Adam",
"author_id": 13418,
"author_profile": "https://wordpress.stackexchange.com/users/13418",
"pm_score": 2,
"selected": false,
"text": "<p>You'll want to use the following filter:</p>\n\n<p><a href=\"https://codex.wordpress.org/Plugin_API/Filter_Refer... | 2016/11/12 | [
"https://wordpress.stackexchange.com/questions/245906",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106819/"
] | I'm working on a custom project for a client and having an issue adding in `data-scroll` before the links in WordPress. I want the output to be `<a data-scroll href='#'>`.
Data-scroll is what I am looking to add in just after the a, *here* `href ="#"`
Hope someone can help me out. | A Custom Walker would be the best way to add anything anywhere to your wp\_nav\_menu
You hav to keep the following in your function.php
```
<?php
class MV_Cleaner_Walker_Nav_Menu extends Walker {
var $tree_type = array( 'post_type', 'taxonomy', 'custom' );
var $db_fields = ... |
245,915 | <p>I'm developing a plugin and I'd like to use colorbox in my plugin . So I use <code>wp_enqueue_script('jquery');</code> but it doesn't work . Then I search for it and add the following code and it is working now . But why should I deregister jquery ?</p>
<pre><code>wp_deregister_script('jquery');
wp_register_script... | [
{
"answer_id": 245921,
"author": "Third Essential Designer",
"author_id": 103698,
"author_profile": "https://wordpress.stackexchange.com/users/103698",
"pm_score": 2,
"selected": false,
"text": "<p>Linking jquery code twice conflicts the functions as they are present twice. So deregister... | 2016/11/12 | [
"https://wordpress.stackexchange.com/questions/245915",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14448/"
] | I'm developing a plugin and I'd like to use colorbox in my plugin . So I use `wp_enqueue_script('jquery');` but it doesn't work . Then I search for it and add the following code and it is working now . But why should I deregister jquery ?
```
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.go... | Linking jquery code twice conflicts the functions as they are present twice. So deregistering helps you but it is not good choice. You should go through jQuery no conflict thing. And you should register your jquery version with different name, so that it does not break wordpress.
Ref- jQuery [Forum](https://forum.jque... |
245,947 | <p>Actually it is more general question but now i am trying to use it on wordpress site so I preferred to post it here.</p>
<p>I am trying to understand the difference between remote post and form post. </p>
<p>When I query a string and post it to remote server, I get the result as string and with "print $response" s... | [
{
"answer_id": 245937,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 0,
"selected": false,
"text": "<p>You don't need to edit any file. Most of WordPress function can be hook with actions and filters.</p>\n\n<p>De... | 2016/11/12 | [
"https://wordpress.stackexchange.com/questions/245947",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106036/"
] | Actually it is more general question but now i am trying to use it on wordpress site so I preferred to post it here.
I am trying to understand the difference between remote post and form post.
When I query a string and post it to remote server, I get the result as string and with "print $response" see it on browser ... | WordPress uses a [hierarchy of templates](https://developer.wordpress.org/themes/basics/template-hierarchy/) (see the [visual overview](https://developer.wordpress.org/files/2014/10/template-hierarchy.png)) which it checks for presence. In your case when showing a category archive it will check for presence the followi... |
246,004 | <p>I just want to start out by saying, that I have tried multiple things before I resorted to writing this entry. You guys are my only hope.</p>
<p>My site works in Chrome, but disappears in Firefox or Safari. </p>
<p><strong>Things I have tried:</strong> </p>
<ul>
<li>Added register script then enqueue; In hopes th... | [
{
"answer_id": 245937,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 0,
"selected": false,
"text": "<p>You don't need to edit any file. Most of WordPress function can be hook with actions and filters.</p>\n\n<p>De... | 2016/11/13 | [
"https://wordpress.stackexchange.com/questions/246004",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94933/"
] | I just want to start out by saying, that I have tried multiple things before I resorted to writing this entry. You guys are my only hope.
My site works in Chrome, but disappears in Firefox or Safari.
**Things I have tried:**
* Added register script then enqueue; In hopes that my grid-12.css is loaded before fronts... | WordPress uses a [hierarchy of templates](https://developer.wordpress.org/themes/basics/template-hierarchy/) (see the [visual overview](https://developer.wordpress.org/files/2014/10/template-hierarchy.png)) which it checks for presence. In your case when showing a category archive it will check for presence the followi... |
246,026 | <p>I use Multi-Site at <code>example.com</code>.
Is there any simple method to redirect users to specific blog dashboard? for example, when I login at:</p>
<p><code>example.com/wp-login.php</code>
instead of default redirection to </p>
<p><code>example.com/wp-admin</code> I want to be redirected to</p>
<p><code>ex... | [
{
"answer_id": 251374,
"author": "malik irfan",
"author_id": 110267,
"author_profile": "https://wordpress.stackexchange.com/users/110267",
"pm_score": 1,
"selected": false,
"text": "<p>please see this it working fine for me :)</p>\n\n<pre><code>function uop_login_redirect( $redirect_to, ... | 2016/11/13 | [
"https://wordpress.stackexchange.com/questions/246026",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/33667/"
] | I use Multi-Site at `example.com`.
Is there any simple method to redirect users to specific blog dashboard? for example, when I login at:
`example.com/wp-login.php`
instead of default redirection to
`example.com/wp-admin` I want to be redirected to
`example.com/sub-site/wp-admin` | please see this it working fine for me :)
```
function uop_login_redirect( $redirect_to, $request, $user ) {
return ( is_array( $user->roles ) && in_array( 'administrator', $user->roles ) ) ? admin_url() : site_url();
}
add_filter( 'login_redirect', 'uop_login_redirect', 10, 3 );
``` |
246,028 | <p>I would like to create an Angular 2 SPA that uses the WordPress REST API as a back-end. How can I use the API to fetch the page the user has set as their front page?</p>
| [
{
"answer_id": 246035,
"author": "Connel",
"author_id": 42843,
"author_profile": "https://wordpress.stackexchange.com/users/42843",
"pm_score": 1,
"selected": false,
"text": "<p>I have just got this working using the plugin 'WP API Options' plugin. You can find the plugin here:\n<a href=... | 2016/11/13 | [
"https://wordpress.stackexchange.com/questions/246028",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/42843/"
] | I would like to create an Angular 2 SPA that uses the WordPress REST API as a back-end. How can I use the API to fetch the page the user has set as their front page? | We could implement our own endpoint:
```
https://example.tld/wpse/v1/frontpage
```
Here's a simple demo (*PHP 5.4+*):
```
<?php
/**
* Plugin Name: WPSE - Static Frontpage Rest Endpoint
*/
namespace WPSE\RestAPI\Frontpage;
\add_action( 'rest_api_init', function()
{
\register_rest_route( 'wpse/v1', '/frontpag... |
246,037 | <p>I want to add an option in pages' backend.<br>
Searching on the internet I find guides on how to create a backend page dedicated to options esclusively. I'd like to add an option to a page instead, under the page content editor (or on the right sidebar).<br><br>
Can anyone help me?</p>
| [
{
"answer_id": 246039,
"author": "vol4ikman",
"author_id": 31075,
"author_profile": "https://wordpress.stackexchange.com/users/31075",
"pm_score": 0,
"selected": false,
"text": "<p>I think, the easiest way for you is:\n<a href=\"https://wordpress.org/plugins/advanced-custom-fields/\" rel... | 2016/11/13 | [
"https://wordpress.stackexchange.com/questions/246037",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106889/"
] | I want to add an option in pages' backend.
Searching on the internet I find guides on how to create a backend page dedicated to options esclusively. I'd like to add an option to a page instead, under the page content editor (or on the right sidebar).
Can anyone help me? | To add a option box for a page or post, you need to use `add_meta_boxes` action.
```
//Register Meta Box
function register_meta_box() {
add_meta_box(
'meta-box-id',
__( 'MetaBox Title', 'text-domain' ),
'meta_box_callback',
'post',
'advanced',
'hi... |
246,055 | <p>I'm looking for a function that will count and show .jpg URLs or images in my post and then echo the results (eg. 12 images).</p>
<p>I've only found a way to count the attached images in the post. I also found an xpath function but I'm not sure if it is working, because I can't get it to echo the results.</p>
<p>H... | [
{
"answer_id": 246057,
"author": "Shamsur Rahman",
"author_id": 92258,
"author_profile": "https://wordpress.stackexchange.com/users/92258",
"pm_score": 0,
"selected": false,
"text": "<p>for more information visit <a href=\"https://blog.josemcastaneda.com/2014/03/18/get-image-count-in-wor... | 2016/11/14 | [
"https://wordpress.stackexchange.com/questions/246055",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106901/"
] | I'm looking for a function that will count and show .jpg URLs or images in my post and then echo the results (eg. 12 images).
I've only found a way to count the attached images in the post. I also found an xpath function but I'm not sure if it is working, because I can't get it to echo the results.
Here's what I have... | Use regex to find all the urls and filter by type.
```
$post = get_post( 504 );
$content = $post->post_content;
// match all urls
preg_match_all( '/(http:|https:)?\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/', $content, $matches );
$count = 0;
if ( ! empty( $matches ) && ! empty( $match... |
246,067 | <p>I have a stuck that make me headache so much, as you see picture, this is my result when i add option to event.</p>
<p><a href="https://i.stack.imgur.com/aofam.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aofam.png" alt="enter image description here"></a></p>
<p>I'm updated code in: <code>wp-... | [
{
"answer_id": 246057,
"author": "Shamsur Rahman",
"author_id": 92258,
"author_profile": "https://wordpress.stackexchange.com/users/92258",
"pm_score": 0,
"selected": false,
"text": "<p>for more information visit <a href=\"https://blog.josemcastaneda.com/2014/03/18/get-image-count-in-wor... | 2016/11/14 | [
"https://wordpress.stackexchange.com/questions/246067",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106904/"
] | I have a stuck that make me headache so much, as you see picture, this is my result when i add option to event.
[](https://i.stack.imgur.com/aofam.png)
I'm updated code in: `wp-content/theme/mytheme/lib/metabox/function.php`
```
$meta_boxes[] = arra... | Use regex to find all the urls and filter by type.
```
$post = get_post( 504 );
$content = $post->post_content;
// match all urls
preg_match_all( '/(http:|https:)?\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/', $content, $matches );
$count = 0;
if ( ! empty( $matches ) && ! empty( $match... |
246,090 | <p>I have a "cmb2" custom field with <code>type->file</code>. and i use it to upload images.</p>
<p><strong>If i use:</strong></p>
<p><code>echo get_post_meta( $post->ID, '_pf_photo1', 'medium' );</code></p>
<p>i get the url of the full image (not the medium one).</p>
<p>How can i get the url of the 'medium' ... | [
{
"answer_id": 246095,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 2,
"selected": false,
"text": "<p>You can get the <em>ID</em> of the file with <code>_pf_photo1_id</code>, then it's easy to get any size UR... | 2016/11/14 | [
"https://wordpress.stackexchange.com/questions/246090",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/43619/"
] | I have a "cmb2" custom field with `type->file`. and i use it to upload images.
**If i use:**
`echo get_post_meta( $post->ID, '_pf_photo1', 'medium' );`
i get the url of the full image (not the medium one).
How can i get the url of the 'medium' / 'thumbnail' and so on... | The `get_post_meta()` function can help to get the meta field but will not retrieve different size.
Assuming `_pf_photo1` embed the attachment id, you can do something like that:
```
// Note the "_id" suffix
$attachment_id = get_post_meta($post->ID, '_pf_photo1_id', true);
```
Last parameter for this function can n... |
246,124 | <p>When I try to login via domain.com/wp-admin/ it will not allow me to do so. However, when I log in via domain.com/admin/ it will allow me to login with no problems.</p>
<p>Does anyone have any ideas as to why this is? And possibly how to fix this?</p>
<p>Thanks in advance.</p>
| [
{
"answer_id": 246127,
"author": "Community",
"author_id": -1,
"author_profile": "https://wordpress.stackexchange.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<p>It could be a plugin installed on the site for security purposes, to restrict bots from accessing to the wp-admin... | 2016/11/14 | [
"https://wordpress.stackexchange.com/questions/246124",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98494/"
] | When I try to login via domain.com/wp-admin/ it will not allow me to do so. However, when I log in via domain.com/admin/ it will allow me to login with no problems.
Does anyone have any ideas as to why this is? And possibly how to fix this?
Thanks in advance. | In general you can change where items link with [WP Constants](https://codex.wordpress.org/Determining_Plugin_and_Content_Directories#Constants). But according to [`get_admin_url()`](https://core.trac.wordpress.org/browser/tags/4.5.3/src/wp-includes/link-template.php#L3106) it's possible the URL was filtered with `admi... |
246,137 | <p>I have a wordpress installation at a location in the form: www.mydomain.com/mysite.</p>
<p>I would like to redirect the DNS such that the address will (always!) appear as mysite.com.</p>
<p>I own both domain names. How can I do the redirection without breaking everything?</p>
| [
{
"answer_id": 246194,
"author": "user42826",
"author_id": 42826,
"author_profile": "https://wordpress.stackexchange.com/users/42826",
"pm_score": 1,
"selected": false,
"text": "<p>1) You have to change all references of www.mydomain.com to mysite.com in WP. WP will only respond to the h... | 2016/11/14 | [
"https://wordpress.stackexchange.com/questions/246137",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/78708/"
] | I have a wordpress installation at a location in the form: www.mydomain.com/mysite.
I would like to redirect the DNS such that the address will (always!) appear as mysite.com.
I own both domain names. How can I do the redirection without breaking everything? | 1) You have to change all references of www.mydomain.com to mysite.com in WP. WP will only respond to the hostname/url that it was configured for. If you make a request with a different url, WP will respond with an error message. WP stores the url in two places wp-config.php and the database. In wp-config.php just do a... |
246,140 | <p>I recently took over web admin for a nonprofit organization and one of the things they would like changed with their site is to have multiple forms such as contact, volunteer, donations, more info, etc. They would like this data sent in an email so that it can be sent to focus group members but need it sent in a dai... | [
{
"answer_id": 246194,
"author": "user42826",
"author_id": 42826,
"author_profile": "https://wordpress.stackexchange.com/users/42826",
"pm_score": 1,
"selected": false,
"text": "<p>1) You have to change all references of www.mydomain.com to mysite.com in WP. WP will only respond to the h... | 2016/11/14 | [
"https://wordpress.stackexchange.com/questions/246140",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106947/"
] | I recently took over web admin for a nonprofit organization and one of the things they would like changed with their site is to have multiple forms such as contact, volunteer, donations, more info, etc. They would like this data sent in an email so that it can be sent to focus group members but need it sent in a daily/... | 1) You have to change all references of www.mydomain.com to mysite.com in WP. WP will only respond to the hostname/url that it was configured for. If you make a request with a different url, WP will respond with an error message. WP stores the url in two places wp-config.php and the database. In wp-config.php just do a... |
246,146 | <p>I wonder how can I trigger filter hook only when post is saved with new revision directly after user clicked save button or publish new post.</p>
<p>My idea is to replace specific parts of the post, but I don't need to trigger my filter each time ajax request for autosaving is sent or new post draft is created. </p... | [
{
"answer_id": 246149,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 1,
"selected": false,
"text": "<p>you can use different statement in your function to determine this:</p>\n\n<pre><code> function filter_post_da... | 2016/11/14 | [
"https://wordpress.stackexchange.com/questions/246146",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106950/"
] | I wonder how can I trigger filter hook only when post is saved with new revision directly after user clicked save button or publish new post.
My idea is to replace specific parts of the post, but I don't need to trigger my filter each time ajax request for autosaving is sent or new post draft is created.
I am using ... | Look at [`'save_post'`](https://codex.wordpress.org/Plugin_API/Action_Reference/save_post) and
[Post Status Transitions](https://codex.wordpress.org/Post_Status_Transitions).
>
> `save_post` is an action triggered whenever a post or page is created or updated, which could be from an import, post/page edit form, xmlr... |
246,154 | <p>I am creating this role 'grocery' for a client but it basically only needs to be able to edit pages and upload media. For some reason the code I have is still allowing the 'grocery' role to delete posts and create pages and do a bunch of things I DO NOT want this role to be able to do. This is my code, cant't figure... | [
{
"answer_id": 246149,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 1,
"selected": false,
"text": "<p>you can use different statement in your function to determine this:</p>\n\n<pre><code> function filter_post_da... | 2016/11/14 | [
"https://wordpress.stackexchange.com/questions/246154",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93770/"
] | I am creating this role 'grocery' for a client but it basically only needs to be able to edit pages and upload media. For some reason the code I have is still allowing the 'grocery' role to delete posts and create pages and do a bunch of things I DO NOT want this role to be able to do. This is my code, cant't figure ou... | Look at [`'save_post'`](https://codex.wordpress.org/Plugin_API/Action_Reference/save_post) and
[Post Status Transitions](https://codex.wordpress.org/Post_Status_Transitions).
>
> `save_post` is an action triggered whenever a post or page is created or updated, which could be from an import, post/page edit form, xmlr... |
246,157 | <p>I have a short code in wordpress, below is a part of the shortcode →</p>
<p>[tm_single_image animation="fadeInLeft" classname="sub-banner1" image="http://trafficspinners.com/wp-content/uploads/2016/11/wedding-seating-chart-downloadable2.jpg"]</p>
<p>I want to put a clickable anchor text in this image, Please guide... | [
{
"answer_id": 246165,
"author": "Michelle",
"author_id": 16,
"author_profile": "https://wordpress.stackexchange.com/users/16",
"pm_score": 2,
"selected": true,
"text": "<p>I think you just need to add link_url to the shortcode, like so?</p>\n\n<p>[tm_single_image animation=\"fadeInLeft\... | 2016/11/14 | [
"https://wordpress.stackexchange.com/questions/246157",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/105791/"
] | I have a short code in wordpress, below is a part of the shortcode →
[tm\_single\_image animation="fadeInLeft" classname="sub-banner1" image="http://trafficspinners.com/wp-content/uploads/2016/11/wedding-seating-chart-downloadable2.jpg"]
I want to put a clickable anchor text in this image, Please guide me.
Widget De... | I think you just need to add link\_url to the shortcode, like so?
[tm\_single\_image animation="fadeInLeft" classname="sub-banner1" image="http://trafficspinners.com/wp-content/uploads/2016/11/wedding-seating-chart-downloadable2.jpg" link\_url="YOUR-LINK-HERE"]
Unless I am not understanding what you mean by 'clickabl... |
246,218 | <p>I want to have different 404 template for each custom post type.</p>
<p>eg. I have post type name <strong>event</strong> and the link will be<br>
<em>domain.com/event/my-event-name</em></p>
<p>but if it link to page that not have post<br>
<em>domain.com/event/xxxxxxx</em> <br></p>
<p>then it will show 404 page, b... | [
{
"answer_id": 246222,
"author": "elicohenator",
"author_id": 98507,
"author_profile": "https://wordpress.stackexchange.com/users/98507",
"pm_score": 1,
"selected": false,
"text": "<p>According to WP's template hierarchy , you cannot use different template to a 404 page. as @Ranuka sugge... | 2016/11/15 | [
"https://wordpress.stackexchange.com/questions/246218",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12397/"
] | I want to have different 404 template for each custom post type.
eg. I have post type name **event** and the link will be
*domain.com/event/my-event-name*
but if it link to page that not have post
*domain.com/event/xxxxxxx*
then it will show 404 page, but I want it different from `404.php` template, I try g... | WordPress 4.7 introduces a new filter that allows us to easily modify the *template hierarchy*:
```
/**
* Filters the list of template filenames that are searched for when retrieving
* a template to use.
*
* The last element in the array should always be the fallback
* template for this query type.
*
* Possib... |
246,225 | <p>I have to get all the terms from four taxonomies:</p>
<ul>
<li>vehicle_safely_features</li>
<li>vehicle_exterior_features</li>
<li>vehicle_interior_features</li>
<li>vehicle_extras</li>
</ul>
<p>I tried this:</p>
<pre><code>$terms = get_terms( array(
'taxonomy' => 'vehicle_safely_features',
'vehicle_e... | [
{
"answer_id": 246226,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 4,
"selected": true,
"text": "<p>If you want to retrieve multiple taxonomies you need to put the four taxonomies in an array, you are doing this... | 2016/11/15 | [
"https://wordpress.stackexchange.com/questions/246225",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/104741/"
] | I have to get all the terms from four taxonomies:
* vehicle\_safely\_features
* vehicle\_exterior\_features
* vehicle\_interior\_features
* vehicle\_extras
I tried this:
```
$terms = get_terms( array(
'taxonomy' => 'vehicle_safely_features',
'vehicle_exterior_features',
'vehicle_interior_features',
... | If you want to retrieve multiple taxonomies you need to put the four taxonomies in an array, you are doing this, but you have put `taxonomy=>` in the array.
```
$terms = get_terms(
'taxonomy' => array(
'vehicle_safely_features',
'vehicle_exterior_features',
... |
246,228 | <p>I am using WP-PageNavi plugin, which I incorporated into my custom tpl page. There is woocommerce shortcode which holds all the products that I want to display, but I only ever see the same ones and only one page results. I do not see what am I doing wrong. The code is:</p>
<pre><code> <?php
/* Template Na... | [
{
"answer_id": 246230,
"author": "Rishabh",
"author_id": 81621,
"author_profile": "https://wordpress.stackexchange.com/users/81621",
"pm_score": 1,
"selected": false,
"text": "<p>In case of <code>wp_query</code>, you can't use shortcode this way</p>\n\n<pre><code><?php wp_pagenavi(); ... | 2016/11/15 | [
"https://wordpress.stackexchange.com/questions/246228",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/101279/"
] | I am using WP-PageNavi plugin, which I incorporated into my custom tpl page. There is woocommerce shortcode which holds all the products that I want to display, but I only ever see the same ones and only one page results. I do not see what am I doing wrong. The code is:
```
<?php
/* Template Name: shine*/
... | In case of `wp_query`, you can't use shortcode this way
```
<?php wp_pagenavi(); ?>
```
You need to use variable (in which you are storing wp\_query) in array inside shortcode. Use shortcode like this instead. Replace above shortcode with below one.
```
<?php wp_pagenavi( array( 'query' => $query_slider ) ); ?>
``... |
246,270 | <p>I have a custom role, <code>grocery</code>, that I would like to remove the "new content" (the + New dropdown) node from the top admin bar while this role is logged in. I have the following function but it is removing it currently for all roles including admin. Would like to find a way to limit this to just 'grocery... | [
{
"answer_id": 246253,
"author": "kovshenin",
"author_id": 1316,
"author_profile": "https://wordpress.stackexchange.com/users/1316",
"pm_score": 2,
"selected": false,
"text": "<p>Searching the core codebase for <code>eval(</code> yielded no PHP results. Even the one in <code>class-pclzip... | 2016/11/15 | [
"https://wordpress.stackexchange.com/questions/246270",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93770/"
] | I have a custom role, `grocery`, that I would like to remove the "new content" (the + New dropdown) node from the top admin bar while this role is logged in. I have the following function but it is removing it currently for all roles including admin. Would like to find a way to limit this to just 'grocery' custom role.... | Searching the core codebase for `eval(` yielded no PHP results. Even the one in `class-pclzip.php` has been removed. |
246,273 | <p>I understand this is probably a pretty noob situation, but I can't for the life of me figure out <a href="https://i.imgur.com/EPe5jGw.gifv" rel="nofollow noreferrer">why it's doing this</a>.</p>
<p>Any ideas on how to overcome this so I can get WP installed on my server? I've tried searching around for an answer, b... | [
{
"answer_id": 246278,
"author": "Jen",
"author_id": 13810,
"author_profile": "https://wordpress.stackexchange.com/users/13810",
"pm_score": 2,
"selected": true,
"text": "<p>Curl is outputting the response to the screen. You need to send the output to a file, like this:</p>\n\n<pre><code... | 2016/11/15 | [
"https://wordpress.stackexchange.com/questions/246273",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107029/"
] | I understand this is probably a pretty noob situation, but I can't for the life of me figure out [why it's doing this](https://i.imgur.com/EPe5jGw.gifv).
Any ideas on how to overcome this so I can get WP installed on my server? I've tried searching around for an answer, but apparently nobody else has ran into this iss... | Curl is outputting the response to the screen. You need to send the output to a file, like this:
```
curl https://wordpress.org/latest.tar.gz -o wordpress.tar.gz
```
Note the lowercase 'o', and the presence of a filename after that argument. You can name the file whatever you want. With this exact command, it will b... |
246,301 | <p>I'm running a standard WP_Query on a property website, and I want to find all properties that have a postcode beginning with 'SC1'. In the meta query, doing a normal LIKE on the postcode works, but it also returns properties with postcode SC13, which isn't what I want.</p>
<p>As a result, I've changed my meta query... | [
{
"answer_id": 246304,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 3,
"selected": true,
"text": "<p>Note sure how your structure is, but here's one way, using <code>RLIKE</code> comparison and a <em>space</em> ... | 2016/11/15 | [
"https://wordpress.stackexchange.com/questions/246301",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106541/"
] | I'm running a standard WP\_Query on a property website, and I want to find all properties that have a postcode beginning with 'SC1'. In the meta query, doing a normal LIKE on the postcode works, but it also returns properties with postcode SC13, which isn't what I want.
As a result, I've changed my meta query to be as... | Note sure how your structure is, but here's one way, using `RLIKE` comparison and a *space* [character class](https://mariadb.com/kb/en/mariadb/pcre/#character-classes):
```
array(
'key' => '_address_postcode',
'value' => '^SC1[[:space:]]', // Starts with 'SC1 '
'compare' => 'RLIKE'
)
```
Mayb... |
246,319 | <p>Using the category.php template file and I can get all other information about a post except the excerpt or the content. Here's the code I'm using:</p>
<pre><code>$cat = get_queried_object();
$posts = get_posts(array('posts_per_page' => 15, 'offset' => 0, 'category' => $cat->term_id));
... | [
{
"answer_id": 246304,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 3,
"selected": true,
"text": "<p>Note sure how your structure is, but here's one way, using <code>RLIKE</code> comparison and a <em>space</em> ... | 2016/11/16 | [
"https://wordpress.stackexchange.com/questions/246319",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/101999/"
] | Using the category.php template file and I can get all other information about a post except the excerpt or the content. Here's the code I'm using:
```
$cat = get_queried_object();
$posts = get_posts(array('posts_per_page' => 15, 'offset' => 0, 'category' => $cat->term_id));
foreach($posts as $post)
... | Note sure how your structure is, but here's one way, using `RLIKE` comparison and a *space* [character class](https://mariadb.com/kb/en/mariadb/pcre/#character-classes):
```
array(
'key' => '_address_postcode',
'value' => '^SC1[[:space:]]', // Starts with 'SC1 '
'compare' => 'RLIKE'
)
```
Mayb... |
246,372 | <p>I'd like to create a subclass of <code>WP_Post</code> and add some "model functionality" to it. How can i force WP to create objects of that child class instead of WP_Post itself, when i query for my custom post type?</p>
<p><strong>Example:</strong></p>
<p>Let's assume i have two custom post types: <code>Book</co... | [
{
"answer_id": 246404,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 3,
"selected": false,
"text": "<p><code>WP_Post</code> class in WP is <code>final</code>, so it explicitly forbids subclassing. It is also quite vagu... | 2016/11/16 | [
"https://wordpress.stackexchange.com/questions/246372",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/82253/"
] | I'd like to create a subclass of `WP_Post` and add some "model functionality" to it. How can i force WP to create objects of that child class instead of WP\_Post itself, when i query for my custom post type?
**Example:**
Let's assume i have two custom post types: `Book` and `Review`. Each Book can have many Reviews. ... | `WP_Post` class in WP is `final`, so it explicitly forbids subclassing. It is also quite vague in practice, a lot of code around will happily take/produce post–*like* objects as long as they have established data structure.
It is challenging to recommend an alternative without knowing more about your specific needs. I... |
246,377 | <p>From the wp admin login page I click to reset my password (not on the theme, on wp). I get the email but it contains no url to click. Plugins are disabled. What shoud I do? </p>
| [
{
"answer_id": 246395,
"author": "jgraup",
"author_id": 84219,
"author_profile": "https://wordpress.stackexchange.com/users/84219",
"pm_score": 1,
"selected": false,
"text": "<p>Check out the <a href=\"https://github.com/WordPress/WordPress/blob/master/wp-login.php#L281\" rel=\"nofollow ... | 2016/11/16 | [
"https://wordpress.stackexchange.com/questions/246377",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107112/"
] | From the wp admin login page I click to reset my password (not on the theme, on wp). I get the email but it contains no url to click. Plugins are disabled. What shoud I do? | The problem is the `<` and `>` which surround the reset URL in `wp-login.php`. You can remove them using [retrieve\_password\_message](https://developer.wordpress.org/reference/hooks/retrieve_password_message/) in your theme `functions.php` file like below:
```
add_filter("retrieve_password_message", "mapp_custom_pass... |
246,385 | <p>I am currently having an issue with memory when my site tries to generate a tree of child pages. to my understanding query is too large (WP has 60000 pages)</p>
<p>following is code i am using</p>
<pre><code> ?php global $post;
wp_list_pages( array(
'child_of' => $post->ID, // Only pages that are... | [
{
"answer_id": 246394,
"author": "jgraup",
"author_id": 84219,
"author_profile": "https://wordpress.stackexchange.com/users/84219",
"pm_score": 1,
"selected": false,
"text": "<p><a href=\"https://codex.wordpress.org/Class_Reference/WP_Query\" rel=\"nofollow noreferrer\">WP_Query</a> has ... | 2016/11/16 | [
"https://wordpress.stackexchange.com/questions/246385",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/92228/"
] | I am currently having an issue with memory when my site tries to generate a tree of child pages. to my understanding query is too large (WP has 60000 pages)
following is code i am using
```
?php global $post;
wp_list_pages( array(
'child_of' => $post->ID, // Only pages that are children of the current pa... | [WP\_Query](https://codex.wordpress.org/Class_Reference/WP_Query) has [Pagination\_Parameters](https://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters) like `posts_per_page` and `offset` to help you out. Just page the results to limit the query to a more reasonable number per page. |
246,401 | <p>I'm developing a new theme for WP and I want to add different sorts of widgets and different classes, because I want these widgets to look different (for example footer widgets should have another styling, and now I can only target them with the "widget class", one class for all).</p>
<pre><code>function create_wid... | [
{
"answer_id": 246405,
"author": "prosti",
"author_id": 88606,
"author_profile": "https://wordpress.stackexchange.com/users/88606",
"pm_score": 0,
"selected": false,
"text": "<p>How about</p>\n\n<pre><code>function create_widget($name, $id, $description) {\n\n register_sidebar(array(\n\... | 2016/11/16 | [
"https://wordpress.stackexchange.com/questions/246401",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107133/"
] | I'm developing a new theme for WP and I want to add different sorts of widgets and different classes, because I want these widgets to look different (for example footer widgets should have another styling, and now I can only target them with the "widget class", one class for all).
```
function create_widget($name, $id... | When registering a sidebar, you can use certain placeholders for the widget classes. Here's an example taken from the codex:
```
'before_widget' => '<li id="%1$s" class="widget %2$s">',
```
It's the lack of `%1$s` and `%2$s` that is causing your issues. When in doubt always read the documentation on the codex and th... |
246,444 | <p>I am working on WordPress plugin and I have added support for wp cron there. See the code below:</p>
<pre><code>function __construct(){
//Cron Job
add_action('init', array($this,'g_order_sync'));
add_action('ga_order_syn', array($this,'sync_order'));
add_filter('cro... | [
{
"answer_id": 246422,
"author": "Jen",
"author_id": 13810,
"author_profile": "https://wordpress.stackexchange.com/users/13810",
"pm_score": 1,
"selected": false,
"text": "<p>This is a fantastic question - I've personally never run into this before, but here's what I'd try, assuming:</p>... | 2016/11/16 | [
"https://wordpress.stackexchange.com/questions/246444",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98100/"
] | I am working on WordPress plugin and I have added support for wp cron there. See the code below:
```
function __construct(){
//Cron Job
add_action('init', array($this,'g_order_sync'));
add_action('ga_order_syn', array($this,'sync_order'));
add_filter('cron_schedules',a... | This is a fantastic question - I've personally never run into this before, but here's what I'd try, assuming:
* you have an image of a server that you've been using to spin up new instances
* you're using a CDN and cloud storage for images and uploads (rather than having a local uploads folder)
With those two assumpt... |
246,466 | <p>In WordPress the default permalink URL like this</p>
<p>http://***.com/?p=123</p>
<p>when I change it to this: </p>
<p>http://***.com/new/sample-post/</p>
<p>Is that possible I still can get the default permalink link text, because the second URL is too long, it looks not so good when someone share it.</p>
| [
{
"answer_id": 246467,
"author": "Gonçalo Ribeiro",
"author_id": 107156,
"author_profile": "https://wordpress.stackexchange.com/users/107156",
"pm_score": 2,
"selected": false,
"text": "<p>When you are editing a post you can notice the URL in your browser looks like</p>\n\n<pre><code>htt... | 2016/11/17 | [
"https://wordpress.stackexchange.com/questions/246466",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/18787/"
] | In WordPress the default permalink URL like this
http://\*\*\*.com/?p=123
when I change it to this:
http://\*\*\*.com/new/sample-post/
Is that possible I still can get the default permalink link text, because the second URL is too long, it looks not so good when someone share it. | When you are editing a post you can notice the URL in your browser looks like
```
http://***.com/wp-admin/post.php?post=1351&action=edit
```
The number in the URL corresponds to the ID of your post. So you can access your post with that ID. In this example the short link for the post would be
```
http://***.com/?p=... |
246,484 | <p>I am writing a plugin. When an item (painting) is clicked for deleting while a list of them is shown at the dashboard, I want to delete it and then redirect the user to the previous page shown. So the action "delete" is catched and then goto action "show"</p>
<pre><code>public function display_paintings_page() {
... | [
{
"answer_id": 246488,
"author": "Jen",
"author_id": 13810,
"author_profile": "https://wordpress.stackexchange.com/users/13810",
"pm_score": 2,
"selected": false,
"text": "<p>opinion: I like ajax interactions for things like this. DELETEs are cheap, fast things to accomplish server side,... | 2016/11/17 | [
"https://wordpress.stackexchange.com/questions/246484",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107179/"
] | I am writing a plugin. When an item (painting) is clicked for deleting while a list of them is shown at the dashboard, I want to delete it and then redirect the user to the previous page shown. So the action "delete" is catched and then goto action "show"
```
public function display_paintings_page() {
$request = $th... | opinion: I like ajax interactions for things like this. DELETEs are cheap, fast things to accomplish server side, loading the whole page all over again takes too long. /opinion
If you're going to use redirects and want to display error messages, you have a couple of options.
1. Use the redirect url itself to pass inf... |
246,497 | <p>In my plugin, in <code>init</code> action I use <code>get_sites()</code> function... however it throws:</p>
<p><code>Call to undefined function get_sites() in XYZ on line 154</code>
whats solution? </p>
<p>p.s.<br/> 1) The same happens with <code>wp_get_sites()</code>...<br/> 2) no help when I use <code>require_on... | [
{
"answer_id": 246499,
"author": "T.Todua",
"author_id": 33667,
"author_profile": "https://wordpress.stackexchange.com/users/33667",
"pm_score": 1,
"selected": false,
"text": "<p>Solution seems to be:</p>\n\n<pre><code>if(function_exists('get_sites')) {$sites= get_sites();} \nels... | 2016/11/17 | [
"https://wordpress.stackexchange.com/questions/246497",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/33667/"
] | In my plugin, in `init` action I use `get_sites()` function... however it throws:
`Call to undefined function get_sites() in XYZ on line 154`
whats solution?
p.s.
1) The same happens with `wp_get_sites()`...
2) no help when I use `require_once(ABSPATH . 'wp-includes/ms-blogs.php');`
3) I use wordpress versi... | Solution seems to be:
```
if(function_exists('get_sites')) {$sites= get_sites();}
elseif(function_exists('wp_get_sites')) {$sites= wp_get_sites();}
``` |
246,502 | <p>I'm building a WordPress site for a local newspaper. This newspaper currently has a "service directory" online which is a bunch of yellow-page style ads for different local businesses. Each of these ads is just a single image with a click-through, although there are two different sized ads (priced at different rates... | [
{
"answer_id": 246504,
"author": "heller_benjamin",
"author_id": 96964,
"author_profile": "https://wordpress.stackexchange.com/users/96964",
"pm_score": 0,
"selected": false,
"text": "<p>If I understand what you are looking for, the plug in,advance custom fields, should be useful. It all... | 2016/11/17 | [
"https://wordpress.stackexchange.com/questions/246502",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107187/"
] | I'm building a WordPress site for a local newspaper. This newspaper currently has a "service directory" online which is a bunch of yellow-page style ads for different local businesses. Each of these ads is just a single image with a click-through, although there are two different sized ads (priced at different rates) t... | From what you describe these ads are separate pieces of information which you want to order and display based on their properties. That would mean storing them as custom posts is still the way to go. After all, posts are the way WordPress stores chunks of related information. That doesn't mean they have to be displayed... |
246,503 | <p>I'm having a problem with WPDB->insert inserting special characters.</p>
<p>I'm trying to insert a name (Jiří), the ř is being saved as ?.</p>
<p>The character is being able to inserted correctly into the database using <code>add_option</code>, which is strange.</p>
<p>Here is a version of the code which I'm tryi... | [
{
"answer_id": 246507,
"author": "cybmeta",
"author_id": 37428,
"author_profile": "https://wordpress.stackexchange.com/users/37428",
"pm_score": 2,
"selected": false,
"text": "<p>If the same code works with <code>add_option()</code> and not with <code>$wpdb->insert()</code> in a custo... | 2016/11/17 | [
"https://wordpress.stackexchange.com/questions/246503",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9918/"
] | I'm having a problem with WPDB->insert inserting special characters.
I'm trying to insert a name (Jiří), the ř is being saved as ?.
The character is being able to inserted correctly into the database using `add_option`, which is strange.
Here is a version of the code which I'm trying:-
```
$memberdata = array( 'nam... | If the same code works with `add_option()` and not with `$wpdb->insert()` in a custom table, it is probably because the collation of the custom table does not support the characters of the inserted data.
It shoulud work if you set the collation of your table to UTF-8, `utf8_general_ci` at minimum (to allow support for... |
246,510 | <p>I am using a php plugin to insert php in my code.</p>
<p>I have a form and I want to make it disappears once it is submitted, but even the most simple condition I am trying to make is not working (he always prints the header):</p>
<pre><code>[insert_php]
echo $_REQUEST['code'];
if ($_REQUEST['code'] == 'aba'... | [
{
"answer_id": 246512,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 2,
"selected": false,
"text": "<p>I wouldn't recommend writing PHP code in the content this way, e.g. for security reasons.</p>\n\n<p>Most like... | 2016/11/17 | [
"https://wordpress.stackexchange.com/questions/246510",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106943/"
] | I am using a php plugin to insert php in my code.
I have a form and I want to make it disappears once it is submitted, but even the most simple condition I am trying to make is not working (he always prints the header):
```
[insert_php]
echo $_REQUEST['code'];
if ($_REQUEST['code'] == 'aba'){
[/insert_php]
... | I wouldn't recommend writing PHP code in the content this way, e.g. for security reasons.
Most likely the shortcode is using `eval()` and you need a valid PHP code snippet in each such call.
The PHP documentation has this [warning](http://php.net/manual/en/function.eval.php):
>
> **Caution** The `eval()` language c... |
246,547 | <p>I have a page template, which is working nicely. But when I include , it loads the themes CSS and js files, which breaks my page template.</p>
<p>However, I still need the wp_head for some plugins to work.</p>
<p>Is there a way to stop wp_head from loading any of my theme's CSS & js files? </p>
<p>I want the ... | [
{
"answer_id": 246557,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 0,
"selected": false,
"text": "<p>There is no clear way to reliably do that (sans hacky approaches like buffering page output).</p>\n\n<p><em>Assumin... | 2016/11/17 | [
"https://wordpress.stackexchange.com/questions/246547",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107225/"
] | I have a page template, which is working nicely. But when I include , it loads the themes CSS and js files, which breaks my page template.
However, I still need the wp\_head for some plugins to work.
Is there a way to stop wp\_head from loading any of my theme's CSS & js files?
I want the page template to only use ... | Thank you for your help! This solution works with my theme:
```
function remove_all_theme_styles() {
if ( is_page_template('template-landing.php') ) {
global $wp_styles;
$wp_styles->queue = array();
}
}
add_action('wp_print_styles', 'remove_all_theme_styles', 100);
``` |
246,551 | <p>I don't think this is the most elegant way of achieving my objective but it's 95% there.</p>
<p>I have created a page template and added a post loop to list custom posts based on the a custom field set on the page.</p>
<p>I am trying to show a list of associated posts. I have a custom taxonomy 'servicestax' contai... | [
{
"answer_id": 246557,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 0,
"selected": false,
"text": "<p>There is no clear way to reliably do that (sans hacky approaches like buffering page output).</p>\n\n<p><em>Assumin... | 2016/11/17 | [
"https://wordpress.stackexchange.com/questions/246551",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107221/"
] | I don't think this is the most elegant way of achieving my objective but it's 95% there.
I have created a page template and added a post loop to list custom posts based on the a custom field set on the page.
I am trying to show a list of associated posts. I have a custom taxonomy 'servicestax' containing values such ... | Thank you for your help! This solution works with my theme:
```
function remove_all_theme_styles() {
if ( is_page_template('template-landing.php') ) {
global $wp_styles;
$wp_styles->queue = array();
}
}
add_action('wp_print_styles', 'remove_all_theme_styles', 100);
``` |
246,563 | <p>I've read the documentation on <a href="https://developer.wordpress.org/reference/functions/get_post_permalink/" rel="noreferrer"><code>get_post_permalink()</code></a> and <a href="https://developer.wordpress.org/reference/functions/get_permalink/" rel="noreferrer"><code>get_permalink()</code></a> and don't understa... | [
{
"answer_id": 246583,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 2,
"selected": false,
"text": "<p>Someone else will certainly explain better than me. As I only use <code>get_permalink()</code></p>\n\n<p>They ... | 2016/11/17 | [
"https://wordpress.stackexchange.com/questions/246563",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16/"
] | I've read the documentation on [`get_post_permalink()`](https://developer.wordpress.org/reference/functions/get_post_permalink/) and [`get_permalink()`](https://developer.wordpress.org/reference/functions/get_permalink/) and don't understand the difference between the two. It might be because I don't understand the pur... | The [`get_post_permalink()`](https://developer.wordpress.org/reference/functions/get_post_permalink/) funciton fetches the link to a post depending on its "permanent" link plus your custom rewrite rules that changes `?p=123` into for e.g. `my-beautiful-sunday-diary`. The [`get_permalink()`](https://developer.wordpress.... |
246,613 | <p>I have a Wordpress site that accepts posts by email and feeds them into specific categories. I just adopted a new theme (Astrid) and while I've been able to customize it with css and child theme, I'm frustrated by the fact that the sidebar is ever present in the category/archive view. Is there a way (perhaps using ... | [
{
"answer_id": 246615,
"author": "Ranuka",
"author_id": 106350,
"author_profile": "https://wordpress.stackexchange.com/users/106350",
"pm_score": 0,
"selected": false,
"text": "<p>This solution depend on the theme. Sometimes this solution does not work for your theme.</p>\n\n<ol>\n<li><p... | 2016/11/18 | [
"https://wordpress.stackexchange.com/questions/246613",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107235/"
] | I have a Wordpress site that accepts posts by email and feeds them into specific categories. I just adopted a new theme (Astrid) and while I've been able to customize it with css and child theme, I'm frustrated by the fact that the sidebar is ever present in the category/archive view. Is there a way (perhaps using cate... | category page flow (bottom to top) is like this:
```
category-slug.php
category-ID.php
category.php
archive.php
index.php
```
so you can not create compulsory **category.php**. open your current theme **archive.php**. and edit this code.
```
<?php
if( !is_category() ){
get_sidebar();
}
?>
``` |
246,632 | <p>I'm making a plugin to register participations on a contest.
I am using Magic Fields.
On my development server, when I put an entry as a normal user all the data is saved on db and it shows in backend. everytime I try to edti fields as admin, it don't save and send me to "wp-admin/edit.php"</p>
<p>Here's my saving ... | [
{
"answer_id": 246615,
"author": "Ranuka",
"author_id": 106350,
"author_profile": "https://wordpress.stackexchange.com/users/106350",
"pm_score": 0,
"selected": false,
"text": "<p>This solution depend on the theme. Sometimes this solution does not work for your theme.</p>\n\n<ol>\n<li><p... | 2016/11/18 | [
"https://wordpress.stackexchange.com/questions/246632",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/102510/"
] | I'm making a plugin to register participations on a contest.
I am using Magic Fields.
On my development server, when I put an entry as a normal user all the data is saved on db and it shows in backend. everytime I try to edti fields as admin, it don't save and send me to "wp-admin/edit.php"
Here's my saving function
... | category page flow (bottom to top) is like this:
```
category-slug.php
category-ID.php
category.php
archive.php
index.php
```
so you can not create compulsory **category.php**. open your current theme **archive.php**. and edit this code.
```
<?php
if( !is_category() ){
get_sidebar();
}
?>
``` |
246,662 | <p>I use conditional code to apply a css highlight to the menu item of a page currently being viewed.</p>
<p><code><li<?php if ( is_page('channels') || '2704' == $post->post_parent ) { echo " class=\"current\""; } // the page is 'channels', or the parent of the page is 'channels'?>><a href="/program... | [
{
"answer_id": 246615,
"author": "Ranuka",
"author_id": 106350,
"author_profile": "https://wordpress.stackexchange.com/users/106350",
"pm_score": 0,
"selected": false,
"text": "<p>This solution depend on the theme. Sometimes this solution does not work for your theme.</p>\n\n<ol>\n<li><p... | 2016/11/18 | [
"https://wordpress.stackexchange.com/questions/246662",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/103213/"
] | I use conditional code to apply a css highlight to the menu item of a page currently being viewed.
`<li<?php if ( is_page('channels') || '2704' == $post->post_parent ) { echo " class=\"current\""; } // the page is 'channels', or the parent of the page is 'channels'?>><a href="/programs/channels/">Channels</a></li>`
I... | category page flow (bottom to top) is like this:
```
category-slug.php
category-ID.php
category.php
archive.php
index.php
```
so you can not create compulsory **category.php**. open your current theme **archive.php**. and edit this code.
```
<?php
if( !is_category() ){
get_sidebar();
}
?>
``` |
246,684 | <p>I've got a lot of post meta keys that I no longer use, and I'm trying to work out how to delete them so they no longer show in the custom fields list in the admin panel.</p>
<p><a href="https://i.stack.imgur.com/F85hi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F85hi.png" alt="enter image des... | [
{
"answer_id": 246706,
"author": "Ranuka",
"author_id": 106350,
"author_profile": "https://wordpress.stackexchange.com/users/106350",
"pm_score": 3,
"selected": true,
"text": "<p>I found this from just a Google search (<a href=\"https://www.iftekhar.net/how-to-delete-unnecessary-post-met... | 2016/11/18 | [
"https://wordpress.stackexchange.com/questions/246684",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/88767/"
] | I've got a lot of post meta keys that I no longer use, and I'm trying to work out how to delete them so they no longer show in the custom fields list in the admin panel.
[](https://i.stack.imgur.com/F85hi.png)
This code will delete the post meta valu... | I found this from just a Google search ([Source](https://www.iftekhar.net/how-to-delete-unnecessary-post-metadata-from-wordpress/))
You have to change met value keys as you want. However, it is highly recommend to take a **DB backup** before running this code.
```
<?php
function delete_useless_post_meta() {
global... |
246,716 | <p>I started a <a href="http://meta-game.org/" rel="nofollow noreferrer">wordpress</a> site about games, and I'd like to setup a workflow to allow php devs to work on the backend without fear of breaking something on the main site. How can I modify plugins so they don't affect the main site?</p>
<p>I can run a server ... | [
{
"answer_id": 246706,
"author": "Ranuka",
"author_id": 106350,
"author_profile": "https://wordpress.stackexchange.com/users/106350",
"pm_score": 3,
"selected": true,
"text": "<p>I found this from just a Google search (<a href=\"https://www.iftekhar.net/how-to-delete-unnecessary-post-met... | 2016/11/19 | [
"https://wordpress.stackexchange.com/questions/246716",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107325/"
] | I started a [wordpress](http://meta-game.org/) site about games, and I'd like to setup a workflow to allow php devs to work on the backend without fear of breaking something on the main site. How can I modify plugins so they don't affect the main site?
I can run a server locally, and make my modifications with that, b... | I found this from just a Google search ([Source](https://www.iftekhar.net/how-to-delete-unnecessary-post-metadata-from-wordpress/))
You have to change met value keys as you want. However, it is highly recommend to take a **DB backup** before running this code.
```
<?php
function delete_useless_post_meta() {
global... |
246,730 | <p>I have a website which the post's contents are dynamically generated AFTER a post is published. </p>
<p>I'm using this code to generate the content i want:</p>
<p><code>add_action( 'publish_post', 'generate_content');
function generate_content($post){
//some code here
}</code></p>
<p>This proc... | [
{
"answer_id": 246743,
"author": "jgraup",
"author_id": 84219,
"author_profile": "https://wordpress.stackexchange.com/users/84219",
"pm_score": 0,
"selected": false,
"text": "<p>Use <a href=\"https://codex.wordpress.org/Function_Reference/wp_publish_post\" rel=\"nofollow noreferrer\"><co... | 2016/11/19 | [
"https://wordpress.stackexchange.com/questions/246730",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94498/"
] | I have a website which the post's contents are dynamically generated AFTER a post is published.
I'm using this code to generate the content i want:
`add_action( 'publish_post', 'generate_content');
function generate_content($post){
//some code here
}`
This process can sometimes take up to 5 minutes, while the po... | There might be two ways:
```
add_action( 'draft_post', 'wpse_246730_my_function' );
function wpse_246730_my_function( $post_id, $post )
{
// Do your things
// Just to stay safe
remove_action( 'draft_post', 'wpse_246730_my_function' );
wp_publish_post( $post_id );
add_action( 'draft_post', 'wpse_24... |
246,742 | <p>I am using <a href="https://github.com/sbrajesh/multisite-global-terms/blob/master/mu-global-terms.php" rel="nofollow noreferrer">this function</a> to make categories and tags global on my multisite installation.</p>
<p>An unfortunate side effect of global categories/tags is that it displays categories for posts ac... | [
{
"answer_id": 246743,
"author": "jgraup",
"author_id": 84219,
"author_profile": "https://wordpress.stackexchange.com/users/84219",
"pm_score": 0,
"selected": false,
"text": "<p>Use <a href=\"https://codex.wordpress.org/Function_Reference/wp_publish_post\" rel=\"nofollow noreferrer\"><co... | 2016/11/19 | [
"https://wordpress.stackexchange.com/questions/246742",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107070/"
] | I am using [this function](https://github.com/sbrajesh/multisite-global-terms/blob/master/mu-global-terms.php) to make categories and tags global on my multisite installation.
An unfortunate side effect of global categories/tags is that it displays categories for posts across all sites. This creates two undesirable pr... | There might be two ways:
```
add_action( 'draft_post', 'wpse_246730_my_function' );
function wpse_246730_my_function( $post_id, $post )
{
// Do your things
// Just to stay safe
remove_action( 'draft_post', 'wpse_246730_my_function' );
wp_publish_post( $post_id );
add_action( 'draft_post', 'wpse_24... |
246,746 | <p>I have a WordPress site using the following criteria from a plugin called MyCRED to determine whether to display content to the user, however that include consists of shortcodes and other non-PHP content. Is there a way to tell PHP 'treat this as if it is not PHP'? Shortcodes are key.</p>
<pre><code>$minimum = 100;... | [
{
"answer_id": 246743,
"author": "jgraup",
"author_id": 84219,
"author_profile": "https://wordpress.stackexchange.com/users/84219",
"pm_score": 0,
"selected": false,
"text": "<p>Use <a href=\"https://codex.wordpress.org/Function_Reference/wp_publish_post\" rel=\"nofollow noreferrer\"><co... | 2016/11/19 | [
"https://wordpress.stackexchange.com/questions/246746",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/96983/"
] | I have a WordPress site using the following criteria from a plugin called MyCRED to determine whether to display content to the user, however that include consists of shortcodes and other non-PHP content. Is there a way to tell PHP 'treat this as if it is not PHP'? Shortcodes are key.
```
$minimum = 100;
if ( is_user_... | There might be two ways:
```
add_action( 'draft_post', 'wpse_246730_my_function' );
function wpse_246730_my_function( $post_id, $post )
{
// Do your things
// Just to stay safe
remove_action( 'draft_post', 'wpse_246730_my_function' );
wp_publish_post( $post_id );
add_action( 'draft_post', 'wpse_24... |
246,750 | <p>I have a code which shows categories list with images. Im using plugin to attach image to category.</p>
<p>Working code is:</p>
<pre><code><?php
$args=array(
'orderby' => 'name',
'order' => 'ASC',
)
?>
<?php foreach (get_categories( $args ) as $cat) : ?>
<h3><a href="<?php echo g... | [
{
"answer_id": 246769,
"author": "Ranuka",
"author_id": 106350,
"author_profile": "https://wordpress.stackexchange.com/users/106350",
"pm_score": 1,
"selected": false,
"text": "<p>I don't know what is the purpose of having each each categories for every month because WordPress has monthl... | 2016/11/19 | [
"https://wordpress.stackexchange.com/questions/246750",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40822/"
] | I have a code which shows categories list with images. Im using plugin to attach image to category.
Working code is:
```
<?php
$args=array(
'orderby' => 'name',
'order' => 'ASC',
)
?>
<?php foreach (get_categories( $args ) as $cat) : ?>
<h3><a href="<?php echo get_category_link($cat->term_id); ?>"><?php echo $ca... | Here is full working code. Im not php developer, so there are probably some things that could and should be corrected but it works.
```
<?php
$args=array('orderby' => 'ID', 'order' => 'DESC');
$year="2005";
foreach (get_categories( $args ) as $cat) :
$post_ids ... |
246,768 | <p>I have a following code for the custom post type, and I want to display the content of it inside the loop.</p>
<pre><code> $args = array(
'post_type' => 'gallery',
'posts_per_page' => -1,
'paged' => $paged,
'supress_filters' => false,
... | [
{
"answer_id": 246770,
"author": "elicohenator",
"author_id": 98507,
"author_profile": "https://wordpress.stackexchange.com/users/98507",
"pm_score": 0,
"selected": false,
"text": "<p>have you tried using this?</p>\n\n<pre><code><?php the_content() ?>\n</code></pre>\n\n<p>also, you... | 2016/11/20 | [
"https://wordpress.stackexchange.com/questions/246768",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93692/"
] | I have a following code for the custom post type, and I want to display the content of it inside the loop.
```
$args = array(
'post_type' => 'gallery',
'posts_per_page' => -1,
'paged' => $paged,
'supress_filters' => false,
);
// Tax qu... | What do you have in loop-gallery.php? That's the file which will show the content of the gallery post.
If you haven't created a loop-gallery.php, you should create a file with that name and put it in the root theme folder. In that file you could put something like the following to show the content:
```
<div>
<h2><?... |
246,785 | <p>I want to show font awesome icon (installed) on the left side of the WordPress widget title. I found this shortcode that should do the work.</p>
<pre><code>add_filter( 'widget_title', 'do_shortcode' );
add_shortcode( 'icon', 'shortcode_fa' );
function shortcode_fa($attr, $content ) {
return '<i class="fa fa-'. ... | [
{
"answer_id": 246796,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 3,
"selected": true,
"text": "<p>I checked your code in my install. It works, except that you made a typo (missing backslash):</p>\n\n<pre><code>[... | 2016/11/20 | [
"https://wordpress.stackexchange.com/questions/246785",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/69365/"
] | I want to show font awesome icon (installed) on the left side of the WordPress widget title. I found this shortcode that should do the work.
```
add_filter( 'widget_title', 'do_shortcode' );
add_shortcode( 'icon', 'shortcode_fa' );
function shortcode_fa($attr, $content ) {
return '<i class="fa fa-'. $content . '"></i... | I checked your code in my install. It works, except that you made a typo (missing backslash):
```
[icon]cog[/icon]
```
Few notes:
* You must make sure to **enqueue** the *Font Awsesome* stylesheet.
* You must **close the shortcode**, like: `[icon]cog[/icon]`
* Remember to **escape** the class name with `esc_attr()`... |
246,809 | <p>Given an array of Post objects, how might one initialize <a href="https://codex.wordpress.org/The_Loop" rel="nofollow noreferrer">The Loop</a> so that the common Loop functions could be used:</p>
<pre><code>$posts = array( /* WP_Post, WP_Post, ... */);
while ( have_posts() ) {
the_post();
the_title();
}
</... | [
{
"answer_id": 246811,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 0,
"selected": false,
"text": "<p>You need to change the whole clause. </p>\n\n<pre><code> while ( $posts->have_posts() ) {\n the_post();... | 2016/11/20 | [
"https://wordpress.stackexchange.com/questions/246809",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/34330/"
] | Given an array of Post objects, how might one initialize [The Loop](https://codex.wordpress.org/The_Loop) so that the common Loop functions could be used:
```
$posts = array( /* WP_Post, WP_Post, ... */);
while ( have_posts() ) {
the_post();
the_title();
}
```
I am aware that I could simply loop over the ar... | I'm using this in one of my custom widgets:
```
global $post;
$posts = array( /* WP_Post, WP_Post, ... */);
while (list($i, $post) = each($posts)) :
setup_postdata($post);
// use the template tags below here
if(has_post_thumbnail()):
?><div class="featured_image_wrap"><?php
the_post_thu... |
246,834 | <p>I am trying to list the name of the moderators (users with editor role) that publish pending posts. I created a dashboard widget that shows the latest 10 published posts and the author, but I have problems getting the user that published it. I thought <code>the_modified_author</code> might be it, but I'm not sure if... | [
{
"answer_id": 246844,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 2,
"selected": false,
"text": "<p>We could save the id of the user that last published a post, as the value of the <code>_wpse_user_last_publi... | 2016/11/20 | [
"https://wordpress.stackexchange.com/questions/246834",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/77283/"
] | I am trying to list the name of the moderators (users with editor role) that publish pending posts. I created a dashboard widget that shows the latest 10 published posts and the author, but I have problems getting the user that published it. I thought `the_modified_author` might be it, but I'm not sure if there's **a b... | The reason that `get_the_modified_author()` is not working is that it relies on being used within the WordPress loop. `wp_get_recent_posts()` does not set up a global post object. Here is a complete example based on your original code that replaces `get_the_modified_author()` with some simple code to get the name of th... |
246,859 | <p>So I have a main domain site called: site.com and I recently bought wildcard SSL to try and get the main domain and all its sub-domains to be encrypted and be force all files to use https. After signing up for the service the certificate covers all domains like: *.site.com but all my subdomains have their own name l... | [
{
"answer_id": 246844,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 2,
"selected": false,
"text": "<p>We could save the id of the user that last published a post, as the value of the <code>_wpse_user_last_publi... | 2016/11/21 | [
"https://wordpress.stackexchange.com/questions/246859",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93537/"
] | So I have a main domain site called: site.com and I recently bought wildcard SSL to try and get the main domain and all its sub-domains to be encrypted and be force all files to use https. After signing up for the service the certificate covers all domains like: \*.site.com but all my subdomains have their own name lik... | The reason that `get_the_modified_author()` is not working is that it relies on being used within the WordPress loop. `wp_get_recent_posts()` does not set up a global post object. Here is a complete example based on your original code that replaces `get_the_modified_author()` with some simple code to get the name of th... |
246,866 | <p>I'm using <code>get_posts()</code> to fetch posts from a particular category to display at the top of my homepage, separate from the main homepage Loop. Everything seems to work fine, but for the title (returned through <code>the_title()</code>) which is always the same; the title of the first post fetched by <code>... | [
{
"answer_id": 246874,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 2,
"selected": false,
"text": "<p>Making Milos's comment into an answer....</p>\n\n<p>The problem you are facing is the result of many word... | 2016/11/21 | [
"https://wordpress.stackexchange.com/questions/246866",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107412/"
] | I'm using `get_posts()` to fetch posts from a particular category to display at the top of my homepage, separate from the main homepage Loop. Everything seems to work fine, but for the title (returned through `the_title()`) which is always the same; the title of the first post fetched by `get_posts()`. `the_permalink()... | Making Milos's comment into an answer....
The problem you are facing is the result of many wordpress template oriented functions expect some global variables. In `WP_Query` based loops setting those variable is done by calling the `the_post()` method of the `WP_Query` object, but with `get_posts` you need to call `set... |
246,872 | <p>I am setting up a transient with one hour expiry time.
Now i want to know how much time left for the transient to expire.</p>
<p>I am getting the transient timeout value with get_option function.</p>
<p>Can anyone help me out.</p>
<p>Thank You.</p>
| [
{
"answer_id": 246873,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 0,
"selected": false,
"text": "<p>Transients by definition can expire at any moment, no matter what interval you have requested, therefor t... | 2016/11/21 | [
"https://wordpress.stackexchange.com/questions/246872",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107417/"
] | I am setting up a transient with one hour expiry time.
Now i want to know how much time left for the transient to expire.
I am getting the transient timeout value with get\_option function.
Can anyone help me out.
Thank You. | The problem here is that if the site is actually using something like Redis, or any other supported "external cache" then nothing is going to actually be set in the options table (which can be checked with `wp_using_ext_object_cache`)
Storage in the options table is just how WordPress handles transients outside of any... |
246,885 | <p>I've got three page templates called "Simple", "Front", and "Form" and I would like to add a shortcut in the admin side bar to directly create a page that would be associated with any of these templates. So below "Add new" there would be:</p>
<p><a href="https://i.stack.imgur.com/6Hm8C.png" rel="nofollow noreferrer... | [
{
"answer_id": 246890,
"author": "GKS",
"author_id": 90674,
"author_profile": "https://wordpress.stackexchange.com/users/90674",
"pm_score": 2,
"selected": false,
"text": "<p>I found this question very interesting ,So here is what i have done to make this possible. </p>\n\n<p>Fetch page ... | 2016/11/02 | [
"https://wordpress.stackexchange.com/questions/246885",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8029/"
] | I've got three page templates called "Simple", "Front", and "Form" and I would like to add a shortcut in the admin side bar to directly create a page that would be associated with any of these templates. So below "Add new" there would be:
[](https://i... | I found this question very interesting ,So here is what i have done to make this possible.
Fetch page template and add them as sub menu of Post type page.
```
function addTemplateAddNewSubMenu() {
global $submenu;
// here we are fetching all page template from current activated theme.
$templates = wp_g... |
246,899 | <p>Here is a section of code that I have in a template file — to display sub-navigation if the page has child-pages:</p>
<pre><code><?php // display sub-nav if page has children ?>
<?php $children = get_pages(array('child_of' => $post->ID)); ?>
<?php if (count($children)) : ?>
<ul class... | [
{
"answer_id": 246905,
"author": "GKS",
"author_id": 90674,
"author_profile": "https://wordpress.stackexchange.com/users/90674",
"pm_score": 1,
"selected": true,
"text": "<p>is your file name is 'include-nav.php' or it is placed inside 'include' folder ? </p>\n\n<p>if not then simply cal... | 2016/11/21 | [
"https://wordpress.stackexchange.com/questions/246899",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | Here is a section of code that I have in a template file — to display sub-navigation if the page has child-pages:
```
<?php // display sub-nav if page has children ?>
<?php $children = get_pages(array('child_of' => $post->ID)); ?>
<?php if (count($children)) : ?>
<ul class="nav nav-tabs">
<?php foreach (... | is your file name is 'include-nav.php' or it is placed inside 'include' folder ?
if not then simply call it by passing name of **nav.php**
```
<?php get_template_part( 'nav' ); ?>
```
you don't have to pass include keyword to call template.
Hope this help :) |
246,914 | <p>Am I using <code>add_action('init'</code> correctly?<br>
I want to display some data if a user visits <code>example.com/?my_plugin</code></p>
<p>At the moment I'm using...</p>
<pre><code><?php
add_action( 'init', 'my_plugin' );
function my_plugin()
{
if( isset( $_GET['my_plugin'] ) ) {
...
... | [
{
"answer_id": 246918,
"author": "MD Sultan Nasir Uddin",
"author_id": 86834,
"author_profile": "https://wordpress.stackexchange.com/users/86834",
"pm_score": 0,
"selected": false,
"text": "<p>init hook runs after WordPress has finished loading but before any headers are sent. </p>\n\n<p... | 2016/11/21 | [
"https://wordpress.stackexchange.com/questions/246914",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/81576/"
] | Am I using `add_action('init'` correctly?
I want to display some data if a user visits `example.com/?my_plugin`
At the moment I'm using...
```
<?php
add_action( 'init', 'my_plugin' );
function my_plugin()
{
if( isset( $_GET['my_plugin'] ) ) {
...
echo $data;
}
}
```
This will run e... | Performance impact of hooked functionality is determined by how often hook fires and how intensive the operation is.
`init` only ever fires one per load, so multiple runs are not a factor for it.
Mostly the thing you need to pay attention to is context. If your logic fires on every load and result is conditional the ... |
246,946 | <p>I have created a custom login page that uses wp_login_form() to create the login form:</p>
<pre><code><div class="login-form">
<?php
wp_login_form( array(
'remember' => false,
'label_username' => '',
'label_password' => ''
)
);
?>
</div>
</code></... | [
{
"answer_id": 246918,
"author": "MD Sultan Nasir Uddin",
"author_id": 86834,
"author_profile": "https://wordpress.stackexchange.com/users/86834",
"pm_score": 0,
"selected": false,
"text": "<p>init hook runs after WordPress has finished loading but before any headers are sent. </p>\n\n<p... | 2016/11/21 | [
"https://wordpress.stackexchange.com/questions/246946",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107448/"
] | I have created a custom login page that uses wp\_login\_form() to create the login form:
```
<div class="login-form">
<?php
wp_login_form( array(
'remember' => false,
'label_username' => '',
'label_password' => ''
)
);
?>
</div>
```
I tried to add a simple message to the log... | Performance impact of hooked functionality is determined by how often hook fires and how intensive the operation is.
`init` only ever fires one per load, so multiple runs are not a factor for it.
Mostly the thing you need to pay attention to is context. If your logic fires on every load and result is conditional the ... |
246,957 | <p>I am trying to work out how to change details of a post after its status has changed.</p>
<p>I would like to change the title of the post by appending the post id number to it. Here is the code that I'm working with now, but it doesn't change the post's title:</p>
<pre><code>function update_post_info( $post_id, $p... | [
{
"answer_id": 246965,
"author": "Syed Fakhar Abbas",
"author_id": 90591,
"author_profile": "https://wordpress.stackexchange.com/users/90591",
"pm_score": 0,
"selected": false,
"text": "<p><code>post_title</code> saved in the <code>posts</code> the table as <code>post_title</code> not in... | 2016/11/21 | [
"https://wordpress.stackexchange.com/questions/246957",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84968/"
] | I am trying to work out how to change details of a post after its status has changed.
I would like to change the title of the post by appending the post id number to it. Here is the code that I'm working with now, but it doesn't change the post's title:
```
function update_post_info( $post_id, $post, $update ) {
// ... | A post's title (`post_title`) is not saved in meta data; it's a field within the post table.
Here's an updated version of your original code.
* [Infinite loop is
prevented](https://codex.wordpress.org/Function_Reference/wp_update_post)
by removing and then readding the `wpse246957_update_post_info`
callback.
* Post ... |
246,963 | <p>I'm looking around and see some hints at what I'm wanting to do may be possible, but it's just not clicking for me.</p>
<p>I have a custom post type rt_doctors. I'm trying to make it so there will be a dynamic list of the doctors in my main menu. </p>
<p>I'd like to have in the Nav Menu a menu item doctors that ... | [
{
"answer_id": 247650,
"author": "Dan.",
"author_id": 97196,
"author_profile": "https://wordpress.stackexchange.com/users/97196",
"pm_score": 3,
"selected": true,
"text": "<p><code>Walker_Nav_Menu</code> isn't what you would use for this.</p>\n\n<p>Instead, use the <code>wp_get_nav_menu_... | 2016/11/21 | [
"https://wordpress.stackexchange.com/questions/246963",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/77767/"
] | I'm looking around and see some hints at what I'm wanting to do may be possible, but it's just not clicking for me.
I have a custom post type rt\_doctors. I'm trying to make it so there will be a dynamic list of the doctors in my main menu.
I'd like to have in the Nav Menu a menu item doctors that links to the index... | `Walker_Nav_Menu` isn't what you would use for this.
Instead, use the `wp_get_nav_menu_items` filter. Before we start, you need some way of allowing the code to identify which is the menu item/page that you wish to be the parent of the list of posts. You can do this with a CSS class - give the parent menu item a CSS c... |
246,967 | <p>I have 3 separate sites/installs on the same server and they all use the same database:</p>
<ul>
<li>xxxx.com/en</li>
<li>xxxx.com/de</li>
<li>xxxx.com/es</li>
</ul>
<p>I want a <code><div></code> from a specific site in <code>xxxx.com/en</code> to appear on the other sites. Let's say I have <code><div id... | [
{
"answer_id": 247650,
"author": "Dan.",
"author_id": 97196,
"author_profile": "https://wordpress.stackexchange.com/users/97196",
"pm_score": 3,
"selected": true,
"text": "<p><code>Walker_Nav_Menu</code> isn't what you would use for this.</p>\n\n<p>Instead, use the <code>wp_get_nav_menu_... | 2016/11/21 | [
"https://wordpress.stackexchange.com/questions/246967",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107478/"
] | I have 3 separate sites/installs on the same server and they all use the same database:
* xxxx.com/en
* xxxx.com/de
* xxxx.com/es
I want a `<div>` from a specific site in `xxxx.com/en` to appear on the other sites. Let's say I have `<div id="table1">xxxx<div>` on `xxxx.com/en/page1`; I want this to show on `xxxx.com/... | `Walker_Nav_Menu` isn't what you would use for this.
Instead, use the `wp_get_nav_menu_items` filter. Before we start, you need some way of allowing the code to identify which is the menu item/page that you wish to be the parent of the list of posts. You can do this with a CSS class - give the parent menu item a CSS c... |
246,975 | <p>I have a custom taxonomy called prod-cat</p>
<p>I want to order the output in the template by number, so I added a term_meta to the taxonomy like this:</p>
<pre><code>add_action( 'prod-cat_add_form_fields', 'add_feature_group_field', 10, 2 );
function add_feature_group_field($taxonomy) {
?>
<div clas... | [
{
"answer_id": 246994,
"author": "Fabian Marz",
"author_id": 77421,
"author_profile": "https://wordpress.stackexchange.com/users/77421",
"pm_score": 5,
"selected": true,
"text": "<p><code>get_terms</code> supports a <code>meta_query</code> which calls a new <a href=\"https://codex.wordpr... | 2016/11/22 | [
"https://wordpress.stackexchange.com/questions/246975",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/63523/"
] | I have a custom taxonomy called prod-cat
I want to order the output in the template by number, so I added a term\_meta to the taxonomy like this:
```
add_action( 'prod-cat_add_form_fields', 'add_feature_group_field', 10, 2 );
function add_feature_group_field($taxonomy) {
?>
<div class="form-field term-order-w... | `get_terms` supports a `meta_query` which calls a new [WP\_Meta\_Query](https://codex.wordpress.org/Class_Reference/WP_Meta_Query) parameter as you can see [here](https://developer.wordpress.org/reference/functions/get_terms/). To query your terms with your desired meta, you could change your function call to something... |
246,987 | <p>Been looking around on this website and the internet but can't seem to find a solution. My client wants every order which has the order status cancelled to be completely removed out of WooCommerce after an amount of time.</p>
<pre><code><?php
function update_order_status( $order_id ) {
$order = new WC_Order( $or... | [
{
"answer_id": 246990,
"author": "Community",
"author_id": -1,
"author_profile": "https://wordpress.stackexchange.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<p>Hmm... If we use your script, I think if you save the time like: </p>\n\n<pre><code><?php\nfunction update_o... | 2016/11/22 | [
"https://wordpress.stackexchange.com/questions/246987",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/102035/"
] | Been looking around on this website and the internet but can't seem to find a solution. My client wants every order which has the order status cancelled to be completely removed out of WooCommerce after an amount of time.
```
<?php
function update_order_status( $order_id ) {
$order = new WC_Order( $order_id );
$order_... | do the following code in your child theme function.php file as given below.
```
function wc_remove_cancelled_status( $statuses ){
if( isset( $statuses['wc-cancelled'] ) ){
unset( $statuses['wc-cancelled'] );
}
return $statuses;
}
add_filter( 'wc_order_statuses', 'wc_remove_cancelled_status' );
``` |
247,002 | <p>I want to edit the content before save to database for the first time only when add a new post, so i check the path if it's at the post-new.php i want to apply the filter, but it's not working. anyone know how to solve this ? </p>
<pre><code>$pagePath = parse_url( $_SERVER['REQUEST_URI'] );
$pagePath = $pagePath['p... | [
{
"answer_id": 246990,
"author": "Community",
"author_id": -1,
"author_profile": "https://wordpress.stackexchange.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<p>Hmm... If we use your script, I think if you save the time like: </p>\n\n<pre><code><?php\nfunction update_o... | 2016/11/22 | [
"https://wordpress.stackexchange.com/questions/247002",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107171/"
] | I want to edit the content before save to database for the first time only when add a new post, so i check the path if it's at the post-new.php i want to apply the filter, but it's not working. anyone know how to solve this ?
```
$pagePath = parse_url( $_SERVER['REQUEST_URI'] );
$pagePath = $pagePath['path'];
$pagePa... | do the following code in your child theme function.php file as given below.
```
function wc_remove_cancelled_status( $statuses ){
if( isset( $statuses['wc-cancelled'] ) ){
unset( $statuses['wc-cancelled'] );
}
return $statuses;
}
add_filter( 'wc_order_statuses', 'wc_remove_cancelled_status' );
``` |
247,011 | <p>I need to show in the each post his parent category and sub category, at the moment I use this code:</p>
<pre><code><?php
$categories = get_the_category();
echo 'Parent Category: <a href="' . esc_url( get_category_link( $categories[0]->term_id ) ) . '">' . esc_html( $categories[0]->name ) . '</a&... | [
{
"answer_id": 246990,
"author": "Community",
"author_id": -1,
"author_profile": "https://wordpress.stackexchange.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<p>Hmm... If we use your script, I think if you save the time like: </p>\n\n<pre><code><?php\nfunction update_o... | 2016/11/22 | [
"https://wordpress.stackexchange.com/questions/247011",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107505/"
] | I need to show in the each post his parent category and sub category, at the moment I use this code:
```
<?php
$categories = get_the_category();
echo 'Parent Category: <a href="' . esc_url( get_category_link( $categories[0]->term_id ) ) . '">' . esc_html( $categories[0]->name ) . '</a> \n';
echo 'Sub Category: <a hr... | do the following code in your child theme function.php file as given below.
```
function wc_remove_cancelled_status( $statuses ){
if( isset( $statuses['wc-cancelled'] ) ){
unset( $statuses['wc-cancelled'] );
}
return $statuses;
}
add_filter( 'wc_order_statuses', 'wc_remove_cancelled_status' );
``` |
247,013 | <p>I've generated three different custom post types (e.g. books, movies, games). I've also created a custom taxonomy for all of them (e.g. genre).</p>
<p>What I need are archives for the taxonomy based on the post types. For example: "books-genre", "movies-genre"...</p>
<p>Is there any solution to do that? Now I've ... | [
{
"answer_id": 247020,
"author": "GKS",
"author_id": 90674,
"author_profile": "https://wordpress.stackexchange.com/users/90674",
"pm_score": 0,
"selected": false,
"text": "<p>You can register taxonomy dynamically like this, </p>\n\n<pre><code>add_action('init',function(){\n\n $postTyp... | 2016/11/22 | [
"https://wordpress.stackexchange.com/questions/247013",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/96806/"
] | I've generated three different custom post types (e.g. books, movies, games). I've also created a custom taxonomy for all of them (e.g. genre).
What I need are archives for the taxonomy based on the post types. For example: "books-genre", "movies-genre"...
Is there any solution to do that? Now I've only the taxonomy ... | Here is a complete example made possible using [`add_rewrite_rule()`](https://codex.wordpress.org/Rewrite_API/add_rewrite_rule). The basic setup for this example is documented first, then we'll get to the real part of the solution using `add_rewrite_rule()`.
Taxonomy and Post Type registration
------------------------... |
247,016 | <p>I am trying to run string locator plugin to find some strings in my theme directory. but whenever i try to run this plugin, following error ocures
"Warning
The maximum time your server allows a script to run is too low for the plugin to run as intended, at startup 2 seconds have passed"</p>
<p>I have tried to incre... | [
{
"answer_id": 247020,
"author": "GKS",
"author_id": 90674,
"author_profile": "https://wordpress.stackexchange.com/users/90674",
"pm_score": 0,
"selected": false,
"text": "<p>You can register taxonomy dynamically like this, </p>\n\n<pre><code>add_action('init',function(){\n\n $postTyp... | 2016/11/22 | [
"https://wordpress.stackexchange.com/questions/247016",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107270/"
] | I am trying to run string locator plugin to find some strings in my theme directory. but whenever i try to run this plugin, following error ocures
"Warning
The maximum time your server allows a script to run is too low for the plugin to run as intended, at startup 2 seconds have passed"
I have tried to increase max ex... | Here is a complete example made possible using [`add_rewrite_rule()`](https://codex.wordpress.org/Rewrite_API/add_rewrite_rule). The basic setup for this example is documented first, then we'll get to the real part of the solution using `add_rewrite_rule()`.
Taxonomy and Post Type registration
------------------------... |