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 |
|---|---|---|---|---|---|---|
387,887 | <p>Is there any hook or filter I can use programmatically to restrict posts displayed in the frontend archives and in the dashboard to posts only from specified author ID's? We've been getting a lot of spam authors lately and I'll like to also try this this approach while trying other means to get rid of spam.</p>
| [
{
"answer_id": 387850,
"author": "anton",
"author_id": 97934,
"author_profile": "https://wordpress.stackexchange.com/users/97934",
"pm_score": 0,
"selected": false,
"text": "<p><code>{$new_status}_{$post->post_type}</code> hook or <code>publish_post</code> fires when a post is transit... | 2021/05/08 | [
"https://wordpress.stackexchange.com/questions/387887",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/172353/"
] | Is there any hook or filter I can use programmatically to restrict posts displayed in the frontend archives and in the dashboard to posts only from specified author ID's? We've been getting a lot of spam authors lately and I'll like to also try this this approach while trying other means to get rid of spam. | >
> I don't know if it's the Gutenberg editor or if it's the hook
> `publish_post`
>
>
>
The hook itself works, and if you used the old WordPress post editor, then the issue in question would **not** happen.
So you can say that it's the Gutenberg/block editor.
>
> why it's not returning the meta and featured im... |
387,889 | <p>I want to override function in child theme to remove specific scripts, which is defined inside a class in parent theme.</p>
<p><strong>Parent</strong> theme <code>functions.php</code></p>
<pre><code>class Theme_Assets extends Theme_Base {
/**
* Hold data for wa_theme for frontend
* @var array
*/
... | [
{
"answer_id": 387850,
"author": "anton",
"author_id": 97934,
"author_profile": "https://wordpress.stackexchange.com/users/97934",
"pm_score": 0,
"selected": false,
"text": "<p><code>{$new_status}_{$post->post_type}</code> hook or <code>publish_post</code> fires when a post is transit... | 2021/05/08 | [
"https://wordpress.stackexchange.com/questions/387889",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/38796/"
] | I want to override function in child theme to remove specific scripts, which is defined inside a class in parent theme.
**Parent** theme `functions.php`
```
class Theme_Assets extends Theme_Base {
/**
* Hold data for wa_theme for frontend
* @var array
*/
private static $theme_json = array();
... | >
> I don't know if it's the Gutenberg editor or if it's the hook
> `publish_post`
>
>
>
The hook itself works, and if you used the old WordPress post editor, then the issue in question would **not** happen.
So you can say that it's the Gutenberg/block editor.
>
> why it's not returning the meta and featured im... |
387,944 | <p>My home is a static page, but Wordpress create enumeration "home/page/2/.../3/" and the only solution found that disable pages generation, also redirecting, is the instruction below, but I would like it to have effect only the home page and not the whole site.</p>
<p>Thank you in advance for any suggestion... | [
{
"answer_id": 387938,
"author": "Cas Dekkers",
"author_id": 153884,
"author_profile": "https://wordpress.stackexchange.com/users/153884",
"pm_score": 1,
"selected": true,
"text": "<p>WordPress sends emails via the <a href=\"https://developer.wordpress.org/reference/functions/wp_mail/\" ... | 2021/05/09 | [
"https://wordpress.stackexchange.com/questions/387944",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/206190/"
] | My home is a static page, but Wordpress create enumeration "home/page/2/.../3/" and the only solution found that disable pages generation, also redirecting, is the instruction below, but I would like it to have effect only the home page and not the whole site.
Thank you in advance for any suggestions.
```
global $pos... | WordPress sends emails via the [`wp_mail()`](https://developer.wordpress.org/reference/functions/wp_mail/) method, which, by default, [needs port 25 to be enabled](https://developer.wordpress.org/reference/functions/wp_mail/#notes) in your `php.ini` settings:
>
> For this function to work, the settings `SMTP` and `sm... |
387,969 | <p>I have a database column called "upvotes". I have another column called "userid".</p>
<p>I would like to increment the value in the "updates" column where the userid matches the dynamic variable I'm providing.</p>
<p>Here's my attempt:</p>
<pre><code> $results = $wpdb->query("... | [
{
"answer_id": 387975,
"author": "user44109",
"author_id": 206222,
"author_profile": "https://wordpress.stackexchange.com/users/206222",
"pm_score": 0,
"selected": false,
"text": "<p>EDIT: Seems like this is a bad idea:</p>\n<p>I seem to have solved this by constructing the query first l... | 2021/05/10 | [
"https://wordpress.stackexchange.com/questions/387969",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/206222/"
] | I have a database column called "upvotes". I have another column called "userid".
I would like to increment the value in the "updates" column where the userid matches the dynamic variable I'm providing.
Here's my attempt:
```
$results = $wpdb->query("UPDATE points SET upvotes = upvotes + 1 WHERE userid= %d", $th... | Just noticed that you are missing a prepare.
Your code should look like this
```
$results = $wpdb->query($wpdb->prepare('UPDATE points SET upvotes = upvotes + 1 WHERE userid= %d', $theDynamicUserID));
``` |
388,038 | <p>I'm achieving <a href="https://i.gyazo.com/4a78da9e378922e3640fd1cb3e142e49.png" rel="nofollow noreferrer">this list</a> in a really roundabout way at the moment and I feel like I should be able to do it with a foreach instead of separate queries for each "House" (House is a CPT and is assigned as usermeta... | [
{
"answer_id": 388041,
"author": "Lorn Waterfield",
"author_id": 194510,
"author_profile": "https://wordpress.stackexchange.com/users/194510",
"pm_score": 0,
"selected": false,
"text": "<p>Ah I did it. I'd just cocked up the names of some identifiers in the example above. This works for ... | 2021/05/11 | [
"https://wordpress.stackexchange.com/questions/388038",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/194510/"
] | I'm achieving [this list](https://i.gyazo.com/4a78da9e378922e3640fd1cb3e142e49.png) in a really roundabout way at the moment and I feel like I should be able to do it with a foreach instead of separate queries for each "House" (House is a CPT and is assigned as usermeta too), but I can't get it to work.
Currently doin... | Good for you that you've corrected the `$posts` that was undefined, but then:
1. There's no need to call `$the_query->get_posts()` because when `WP_Query` is instantiated with *a non-empty query*, e.g. `new WP_Query( 'post_type=house' )` (contains one query arg — `post_type`) as opposed to `new WP_Query()` (no query a... |
388,050 | <p>I just would like to show my "footer menu" only with the two pages I manually added in appearance section:</p>
<p><code>register_nav_menu('footer', 'Footer menu');</code></p>
<p><a href="https://i.stack.imgur.com/6ryUr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6ryUr.png" alt="enter... | [
{
"answer_id": 388045,
"author": "anton",
"author_id": 97934,
"author_profile": "https://wordpress.stackexchange.com/users/97934",
"pm_score": 1,
"selected": false,
"text": "<p><strong>1) Run php code in html files</strong></p>\n<p>You can't run PHP in .html files because the server does... | 2021/05/11 | [
"https://wordpress.stackexchange.com/questions/388050",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/197632/"
] | I just would like to show my "footer menu" only with the two pages I manually added in appearance section:
`register_nav_menu('footer', 'Footer menu');`
[](https://i.stack.imgur.com/6ryUr.png)
but when loading in the footer:
```
{!! wp_nav_menu([
... | Perhaps you could consider using [WP REST API](https://developer.wordpress.org/rest-api/) to get the [posts](https://developer.wordpress.org/rest-api/reference/posts/) with a [XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) in javascript instead of trying to get php work on .html file(s... |
388,097 | <p>I'm using the Post SMTP Plugin, but I manually send email via the <code>wp_mail()</code> function.
The gmail client shows the correct From:, but when I switch to outlook or another email client, shows the different Sender: (the one that has been set up in the Post SMTP From: setting)</p>
<p>I have tried these filter... | [
{
"answer_id": 388099,
"author": "dExIT",
"author_id": 92983,
"author_profile": "https://wordpress.stackexchange.com/users/92983",
"pm_score": 3,
"selected": true,
"text": "<p>First Disable PostSMTP plugin and delete if not used anymore it should cleanup.<br>\nThen in functions.php add t... | 2021/05/12 | [
"https://wordpress.stackexchange.com/questions/388097",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/131930/"
] | I'm using the Post SMTP Plugin, but I manually send email via the `wp_mail()` function.
The gmail client shows the correct From:, but when I switch to outlook or another email client, shows the different Sender: (the one that has been set up in the Post SMTP From: setting)
I have tried these filters, but only the `wp_... | First Disable PostSMTP plugin and delete if not used anymore it should cleanup.
Then in functions.php add the following lines
```
// Function to change email address
function sender_email( $original_email_address ) {
return 'tim.smith@example.com';
}
// Function to change sender name
function sender_name( $ori... |
388,220 | <p>Several times over time I changed sizes of thumbnails WP generate when images are uploaded, always setting bigger size.</p>
<p>Recently I set Thumbnail Width 600px width and Medium size Max Width 1800px.
After several hundred images uploaded I realized that I need to set smaller image sizes, I reduced Medium size fr... | [
{
"answer_id": 388221,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 1,
"selected": false,
"text": "<p>The width and height attributes on the <code>img</code> tag are not there to tell the browser how big the im... | 2021/05/15 | [
"https://wordpress.stackexchange.com/questions/388220",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25053/"
] | Several times over time I changed sizes of thumbnails WP generate when images are uploaded, always setting bigger size.
Recently I set Thumbnail Width 600px width and Medium size Max Width 1800px.
After several hundred images uploaded I realized that I need to set smaller image sizes, I reduced Medium size from 1800px... | >
> How to get real image dimension of already uploaded images *which
> dimensions are bigger than one now set in **media settings***?
>
>
>
(Note: The *italic and **bold*** formatting above was added by me.)
[`wp_get_attachment_image_src()`](https://developer.wordpress.org/reference/functions/wp_get_attachment_i... |
388,236 | <p>I am following the "<a href="https://developer.wordpress.org/block-editor/how-to-guides/metabox/meta-block-1-intro/" rel="nofollow noreferrer">Store Post Meta with a Block</a>" guide from the official Block Editor Handbook to add a custom post meta block using the supplied sample code (below). However, the... | [
{
"answer_id": 388238,
"author": "0Seven",
"author_id": 160222,
"author_profile": "https://wordpress.stackexchange.com/users/160222",
"pm_score": 0,
"selected": false,
"text": "<p>I discovered this was occurring because I was using the supplied ESNext JavaScript <a href=\"https://develop... | 2021/05/16 | [
"https://wordpress.stackexchange.com/questions/388236",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/160222/"
] | I am following the "[Store Post Meta with a Block](https://developer.wordpress.org/block-editor/how-to-guides/metabox/meta-block-1-intro/)" guide from the official Block Editor Handbook to add a custom post meta block using the supplied sample code (below). However, the block does not load and a `Uncaught SyntaxError: ... | You should use [@wordpress/scripts](https://github.com/WordPress/gutenberg/blob/trunk/packages/scripts/README.md) so you can profit from modern JavaScript language features and JSX and transpile it to browser-compatible code. It's really not complicated to use.
Just install it via `npm install @wordpress/scripts --sav... |
388,255 | <p>I have split up all my functions into separate files and load these from the functions.php using the below:</p>
<pre><code>require get_template_directory() . '/inc/bhh-functions/scripts-styles.php';
require get_template_directory() . '/inc/bhh-functions/user-functions.php';
</code></pre>
<p>However, I now have a fun... | [
{
"answer_id": 388257,
"author": "Antti Koskinen",
"author_id": 144392,
"author_profile": "https://wordpress.stackexchange.com/users/144392",
"pm_score": 1,
"selected": false,
"text": "<p>I think there's three things going on with your code.</p>\n<p>The first is that you're passing a num... | 2021/05/16 | [
"https://wordpress.stackexchange.com/questions/388255",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/68090/"
] | I have split up all my functions into separate files and load these from the functions.php using the below:
```
require get_template_directory() . '/inc/bhh-functions/scripts-styles.php';
require get_template_directory() . '/inc/bhh-functions/user-functions.php';
```
However, I now have a functions file that I only ... | I think there's three things going on with your code.
The first is that you're passing a numeric string as the first parameter to `has_term()`. If you're trying to pass the term ID to the function, you should remove the quotes from '16' and just pass 16, i.e. as integer.
<https://developer.wordpress.org/reference/func... |
388,312 | <p>I created a custom post type ( Customers ) and i want to show posts of this post type just to the users with Customer role.</p>
<p>there is any way without or with plugin?</p>
| [
{
"answer_id": 388314,
"author": "MMK",
"author_id": 148207,
"author_profile": "https://wordpress.stackexchange.com/users/148207",
"pm_score": 0,
"selected": false,
"text": "<p>if you want to use the plugin.\nAdvance Access manager.\n<a href=\"https://wordpress.org/plugins/advanced-acces... | 2021/05/17 | [
"https://wordpress.stackexchange.com/questions/388312",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/127972/"
] | I created a custom post type ( Customers ) and i want to show posts of this post type just to the users with Customer role.
there is any way without or with plugin? | as @Tonydjukic mentioned, the best way is get user role first and then showing content to him.
also with this code we can do it :
```
$user = wp_get_current_user();
$allowed_roles = array( 'administrator', 'customer' );
if ( array_intersect( $allowed_roles, $user->roles ) ) {
}
``` |
388,366 | <p>I'm echoing the post thumbnail here:</p>
<pre><code>echo '<div class="post-image right">' . the_post_thumbnail('featured-portrait-large') . '</div>';
</code></pre>
<p>And it works, but it's outputting the image outside the div like this:</p>
<pre><code><div class="post-header-text"... | [
{
"answer_id": 388367,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 3,
"selected": true,
"text": "<p><a href=\"https://developer.wordpress.org/reference/functions/the_post_thumbnail/\" rel=\"nofollow noreferr... | 2021/05/18 | [
"https://wordpress.stackexchange.com/questions/388366",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/186347/"
] | I'm echoing the post thumbnail here:
```
echo '<div class="post-image right">' . the_post_thumbnail('featured-portrait-large') . '</div>';
```
And it works, but it's outputting the image outside the div like this:
```
<div class="post-header-text">
<img width="500" height="700" src="[IMAGE URL DELETED]" class="at... | [`the_post_thumbnail()`](https://developer.wordpress.org/reference/functions/the_post_thumbnail/) echo the output, hence that's why the thumbnail is misplaced.
To manually echo the output, you should use [`get_the_post_thumbnail()`](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/) instead:
... |
388,384 | <p>I want to write some JavaScript and want to assign that to a custom capability, I explored a lot but unfortunately none of them worked, any help will be appriciated.</p>
<p>My codes are as below:</p>
<pre><code>add_action('init', function() {
if (current_user_can('disable_image'))
{
//add javascript ... | [
{
"answer_id": 388367,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 3,
"selected": true,
"text": "<p><a href=\"https://developer.wordpress.org/reference/functions/the_post_thumbnail/\" rel=\"nofollow noreferr... | 2021/05/19 | [
"https://wordpress.stackexchange.com/questions/388384",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/183839/"
] | I want to write some JavaScript and want to assign that to a custom capability, I explored a lot but unfortunately none of them worked, any help will be appriciated.
My codes are as below:
```
add_action('init', function() {
if (current_user_can('disable_image'))
{
//add javascript here
}
});
``` | [`the_post_thumbnail()`](https://developer.wordpress.org/reference/functions/the_post_thumbnail/) echo the output, hence that's why the thumbnail is misplaced.
To manually echo the output, you should use [`get_the_post_thumbnail()`](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/) instead:
... |
388,410 | <p>There are 2000 Custom Taxonomies, called <strong>tax_city</strong> in my website<br>
<a href="https://www.example.com/tax_city/london" rel="nofollow noreferrer">https://www.example.com/tax_city/london</a></p>
<p>and I want to change URL to something like this:</p>
<p><a href="https://www.example.com/services/home-ca... | [
{
"answer_id": 388413,
"author": "Pat J",
"author_id": 16121,
"author_profile": "https://wordpress.stackexchange.com/users/16121",
"pm_score": 2,
"selected": false,
"text": "<p>You'd be better off adding or modifying the <code>rewrite</code> variable that's being passed to your <a href=\... | 2021/05/19 | [
"https://wordpress.stackexchange.com/questions/388410",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8124/"
] | There are 2000 Custom Taxonomies, called **tax\_city** in my website
<https://www.example.com/tax_city/london>
and I want to change URL to something like this:
<https://www.example.com/services/home-care/london>
so, when someone visiting this URL, actually see taxonomy archive page. but with nicer URL.
I know th... | You'd be better off adding or modifying the `rewrite` variable that's being passed to your [`register_taxonomy()`](https://developer.wordpress.org/reference/functions/register_taxonomy/) call for the custom taxonomy. You can modify the rewrites to suit your purpose.
For example:
```
$taxonomy_args = array(
// All... |
388,491 | <p>I have my AJAX post category filter working fine on my site, thanks to the generous posts of folks like yourselves. What I can't seem to find is how to do something in the AJAX/jQuery script if the selected value is empty.</p>
<p>Here's my script:</p>
<pre><code>$(function(){
var event_change = $('#event-change');... | [
{
"answer_id": 388498,
"author": "phatskat",
"author_id": 20143,
"author_profile": "https://wordpress.stackexchange.com/users/20143",
"pm_score": 0,
"selected": false,
"text": "<p>I think you just need to call <code>removeClass</code> first and only call <code>addClass</code> when you ha... | 2021/05/20 | [
"https://wordpress.stackexchange.com/questions/388491",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/206670/"
] | I have my AJAX post category filter working fine on my site, thanks to the generous posts of folks like yourselves. What I can't seem to find is how to do something in the AJAX/jQuery script if the selected value is empty.
Here's my script:
```
$(function(){
var event_change = $('#event-change');
$( ".select" ).s... | Unfortunately, the answers given did not work. I was only looking at the jQuery portion, but the issue was in the functions filter, which I did not include in my original post. However, you did push me in the direction I needed, so thank you for that!
The problem was, I was always getting a response from the AJAX func... |
388,493 | <pre class="lang-php prettyprint-override"><code><?php
namespace wpplugin\basic;
class Basic extends \hg\wordpress\AbstractPlugin
{
public function register()
{
add_action('wp_ajax_simple_ajax2', array($this, 'onBasicFunc'));
add_action('wp_ajax_nopriv_simple_ajax2', array($this, 'onBasic... | [
{
"answer_id": 388498,
"author": "phatskat",
"author_id": 20143,
"author_profile": "https://wordpress.stackexchange.com/users/20143",
"pm_score": 0,
"selected": false,
"text": "<p>I think you just need to call <code>removeClass</code> first and only call <code>addClass</code> when you ha... | 2021/05/20 | [
"https://wordpress.stackexchange.com/questions/388493",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/206671/"
] | ```php
<?php
namespace wpplugin\basic;
class Basic extends \hg\wordpress\AbstractPlugin
{
public function register()
{
add_action('wp_ajax_simple_ajax2', array($this, 'onBasicFunc'));
add_action('wp_ajax_nopriv_simple_ajax2', array($this, 'onBasicFunc'));
}
public function onBasicF... | Unfortunately, the answers given did not work. I was only looking at the jQuery portion, but the issue was in the functions filter, which I did not include in my original post. However, you did push me in the direction I needed, so thank you for that!
The problem was, I was always getting a response from the AJAX func... |
388,596 | <p>I have a bothering PHP warning for ages, and I am wondering if someone has solution to this.
The following two-line warning is constantly recording in my error_log file:</p>
<pre><code>PHP Warning: Use of undefined constant ‘FORCE_SSL_LOGIN’ - assumed '‘FORCE_SSL_LOGIN’' (this will throw an Error in a future versio... | [
{
"answer_id": 390762,
"author": "Ali Salamati",
"author_id": 207977,
"author_profile": "https://wordpress.stackexchange.com/users/207977",
"pm_score": 1,
"selected": false,
"text": "<p>Edit wp-config file :</p>\n<pre class=\"lang-php prettyprint-override\"><code>define('FORCE_SSL_LOGIN'... | 2021/05/23 | [
"https://wordpress.stackexchange.com/questions/388596",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/206775/"
] | I have a bothering PHP warning for ages, and I am wondering if someone has solution to this.
The following two-line warning is constantly recording in my error\_log file:
```
PHP Warning: Use of undefined constant ‘FORCE_SSL_LOGIN’ - assumed '‘FORCE_SSL_LOGIN’' (this will throw an Error in a future version of PHP) in... | Edit wp-config file :
```php
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);
```
just copy this and paste in wp-config file.
best wishes for you |
388,651 | <p>Is there any way to add an attribute to the <code>body</code> tag?</p>
<p>For example:</p>
<pre><code><body test-attribute>
</code></pre>
<p>Obviously this can be easily edited in the theme, but I'm trying to figure out how to add it with a plugin.</p>
| [
{
"answer_id": 388652,
"author": "Pat J",
"author_id": 16121,
"author_profile": "https://wordpress.stackexchange.com/users/16121",
"pm_score": 1,
"selected": false,
"text": "<p>It doesn't appear that you can (easily) add arbitrary attributes to the <code><body></code> tag.</p>\n<p>... | 2021/05/25 | [
"https://wordpress.stackexchange.com/questions/388651",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/206832/"
] | Is there any way to add an attribute to the `body` tag?
For example:
```
<body test-attribute>
```
Obviously this can be easily edited in the theme, but I'm trying to figure out how to add it with a plugin. | It doesn't appear that you can (easily) add arbitrary attributes to the `<body>` tag.
However, WordPress provides the function [`body_class()`](https://developer.wordpress.org/reference/functions/body_class/) so you can add classes to the `<body>` tag.
If your theme uses it, you'll find something along these lines in... |
388,796 | <p>In Gutenberg there's the <code>getEntityRecord</code> selector that allows you to get the data of a post of a specific post type:</p>
<pre><code>// get the post object of a page with post id = 42
const post = useSelect( ( select ) =>
select('core').getEntityRecord( 'postType', 'page', 42 )
);
</code></pre>
<p... | [
{
"answer_id": 388886,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 3,
"selected": true,
"text": "<blockquote>\n<p>My question is, is there a similar selector for when you don't know the post type of a post bef... | 2021/05/27 | [
"https://wordpress.stackexchange.com/questions/388796",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/33049/"
] | In Gutenberg there's the `getEntityRecord` selector that allows you to get the data of a post of a specific post type:
```
// get the post object of a page with post id = 42
const post = useSelect( ( select ) =>
select('core').getEntityRecord( 'postType', 'page', 42 )
);
```
My question is, is there a similar se... | >
> My question is, is there a similar selector for when you don't know the post type of a post beforehand?
>
>
>
No, at the current time of writing there is not.
The fundamental problem is that the REST API doesn't provide a generic mechanism for getting a post type given a post ID. You can retrieve a post and i... |
388,990 | <p>In a Gutenberg component I'm developing, I have a function that searches for a keyword across multiple post types specified in a constant:</p>
<pre><code>const postTypes = [ 'posts', 'pages', 'portfolio' ];
const onSearchStringChange = ( keyword ) => {
Promise.all( postTypes.map( postType => apiFetch( {
... | [
{
"answer_id": 389022,
"author": "leemon",
"author_id": 33049,
"author_profile": "https://wordpress.stackexchange.com/users/33049",
"pm_score": 2,
"selected": false,
"text": "<p>I'm answering myself for the benefit of others. I was passing an array of post type slugs to <code>apiFetch</c... | 2021/06/01 | [
"https://wordpress.stackexchange.com/questions/388990",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/33049/"
] | In a Gutenberg component I'm developing, I have a function that searches for a keyword across multiple post types specified in a constant:
```
const postTypes = [ 'posts', 'pages', 'portfolio' ];
const onSearchStringChange = ( keyword ) => {
Promise.all( postTypes.map( postType => apiFetch( {
path: `/wp/v... | Instead of doing multiple `apiFetch` calls for each post type, a more optimal solution to make a search across multiple post types is to use the WP REST API `search` endpoint, which I didn't know it existed until now. The downside is that you don't get the full post objects using this endpoint, but if you only need the... |
389,050 | <p>I'm trying to add a .current-menu-item class to a li when on a specific url "/portfolio/". I can achieve this with jQuery:</p>
<pre><code>jQuery(document).ready(function( $ ) {
var loc = window.location.href; // returns the full URL
if(/portfolio/.test(loc)) {
$('#menu-item-33').addClass('current-m... | [
{
"answer_id": 390431,
"author": "Ejaz UL Haq",
"author_id": 178714,
"author_profile": "https://wordpress.stackexchange.com/users/178714",
"pm_score": 0,
"selected": false,
"text": "<p>Try the following tested solutions they are working <strong>100%</strong> on the frontend screen becaus... | 2021/06/02 | [
"https://wordpress.stackexchange.com/questions/389050",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80308/"
] | I'm trying to add a .current-menu-item class to a li when on a specific url "/portfolio/". I can achieve this with jQuery:
```
jQuery(document).ready(function( $ ) {
var loc = window.location.href; // returns the full URL
if(/portfolio/.test(loc)) {
$('#menu-item-33').addClass('current-menu-item');
}
});
``... | Here is the solution.
=====================
To set it up:
-------------
Paste the following at the bottom of the file `functions.php` in the folder of your current theme.
### Edit by the in the code`
`$when_on_one_of_these_page_slugs` should be an array of strings. The strings are the **slugs** of the pages on wher... |
389,055 | <p>I'm writing a post approval utility for the front end, because we don't want our editor to be able to access the admin dashboard. There are questions on Stack nearly identical to what I'm trying to accomplish, but that guy's problem has to do with the infinite loop issue. Otherwise, he claims his code works:</p>
<p>... | [
{
"answer_id": 390431,
"author": "Ejaz UL Haq",
"author_id": 178714,
"author_profile": "https://wordpress.stackexchange.com/users/178714",
"pm_score": 0,
"selected": false,
"text": "<p>Try the following tested solutions they are working <strong>100%</strong> on the frontend screen becaus... | 2021/06/02 | [
"https://wordpress.stackexchange.com/questions/389055",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/90364/"
] | I'm writing a post approval utility for the front end, because we don't want our editor to be able to access the admin dashboard. There are questions on Stack nearly identical to what I'm trying to accomplish, but that guy's problem has to do with the infinite loop issue. Otherwise, he claims his code works:
[How to c... | Here is the solution.
=====================
To set it up:
-------------
Paste the following at the bottom of the file `functions.php` in the folder of your current theme.
### Edit by the in the code`
`$when_on_one_of_these_page_slugs` should be an array of strings. The strings are the **slugs** of the pages on wher... |
389,079 | <p>I'm trying to make a photo gallery page for all my photos in my post-gallery post and have a modal open when you click on the photos. In the page there will probably be almost 100 photos and i'm not sure how to do this in a good way without duplicating the code for the modal 100x. I have considered using plugins but... | [
{
"answer_id": 390431,
"author": "Ejaz UL Haq",
"author_id": 178714,
"author_profile": "https://wordpress.stackexchange.com/users/178714",
"pm_score": 0,
"selected": false,
"text": "<p>Try the following tested solutions they are working <strong>100%</strong> on the frontend screen becaus... | 2021/06/03 | [
"https://wordpress.stackexchange.com/questions/389079",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/207249/"
] | I'm trying to make a photo gallery page for all my photos in my post-gallery post and have a modal open when you click on the photos. In the page there will probably be almost 100 photos and i'm not sure how to do this in a good way without duplicating the code for the modal 100x. I have considered using plugins but i'... | Here is the solution.
=====================
To set it up:
-------------
Paste the following at the bottom of the file `functions.php` in the folder of your current theme.
### Edit by the in the code`
`$when_on_one_of_these_page_slugs` should be an array of strings. The strings are the **slugs** of the pages on wher... |
389,081 | <p>I'm using a customised version of a commercial theme, with a lot of stuff in it.</p>
<p>I've changed style.css to only have:</p>
<pre><code>/*!
Theme Name: A quite unique theme name
Theme URI: http://www.mywebsite.org/
Version: 1.0.0
Description: Unique description
*/
</code></pre>
<p>Wordpress still finds an 'updat... | [
{
"answer_id": 389082,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 2,
"selected": true,
"text": "<p>It's the directory name.</p>\n<p>If your theme is in <code>wp-content/themes/my-theme</code>, then the t... | 2021/06/03 | [
"https://wordpress.stackexchange.com/questions/389081",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/176814/"
] | I'm using a customised version of a commercial theme, with a lot of stuff in it.
I've changed style.css to only have:
```
/*!
Theme Name: A quite unique theme name
Theme URI: http://www.mywebsite.org/
Version: 1.0.0
Description: Unique description
*/
```
Wordpress still finds an 'update' for the theme using the ori... | It's the directory name.
If your theme is in `wp-content/themes/my-theme`, then the theme name is `my-theme`. |
390,120 | <p>I am currently making a plugin that takes the posts and sends their data to a rest API. Everything else is going smoothly. But I am very confused about how I can achieve this for the featured images. I have to upload a file, not a url. Basically, the API takes multipart/form-data and has an HTTP request method PUT.<... | [
{
"answer_id": 390150,
"author": "CoderSantosh",
"author_id": 78627,
"author_profile": "https://wordpress.stackexchange.com/users/78627",
"pm_score": 1,
"selected": false,
"text": "<p>Here is an idea for sending a featured image (file data) on API and setting the image as a featured imag... | 2021/06/04 | [
"https://wordpress.stackexchange.com/questions/390120",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/110412/"
] | I am currently making a plugin that takes the posts and sends their data to a rest API. Everything else is going smoothly. But I am very confused about how I can achieve this for the featured images. I have to upload a file, not a url. Basically, the API takes multipart/form-data and has an HTTP request method PUT.
Th... | Here is an idea for sending a featured image (file data) on API and setting the image as a featured image on the server.
Get File data from URL using following function:
```
/*fetch the file from URL*/
function prefix_get_file_data_from_url( $url ) {
$response = wp_remote_get( $url );
if ( is_array( $response... |
390,149 | <p>I need to find whether any element of the so many Gutenberg- or Elementor-elements have been used in posts or pages.</p>
<p>Example:
I want to deactivate an Elementor Addon Plugin, which creates accordeons
I need to know where this Addon Plugin was used in posts or pages, if not I can deactivate / delete it, if yes... | [
{
"answer_id": 390157,
"author": "user3135691",
"author_id": 59755,
"author_profile": "https://wordpress.stackexchange.com/users/59755",
"pm_score": 1,
"selected": false,
"text": "<p>You are looking for:</p>\n<p>is_plugin_active( string $plugin )</p>\n<p>This function takes a string para... | 2021/06/05 | [
"https://wordpress.stackexchange.com/questions/390149",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/207369/"
] | I need to find whether any element of the so many Gutenberg- or Elementor-elements have been used in posts or pages.
Example:
I want to deactivate an Elementor Addon Plugin, which creates accordeons
I need to know where this Addon Plugin was used in posts or pages, if not I can deactivate / delete it, if yes I have to... | You are looking for:
is\_plugin\_active( string $plugin )
This function takes a string parameter that is the representation of the path to the plugin relative path in the plugins directory.
So your practical implementation would look something like this:
```
<?php
if(is_plugin_active('elementor/elementor.php') || ... |
390,175 | <p><a href="https://wordpress.stackexchange.com/a/254791/87127">This answer</a> describes a hack in which it is possible to upload new media to an "old" folder like 2012/12. That hack no longer seems to work in recent WP versions. Meanwhile, all the plugins I can find for media/folder management seem to want ... | [
{
"answer_id": 390178,
"author": "JosF",
"author_id": 50460,
"author_profile": "https://wordpress.stackexchange.com/users/50460",
"pm_score": 0,
"selected": false,
"text": "<p>You're talking about 'lost' media. Do you mean that the posts that contain that media are still present and just... | 2021/06/06 | [
"https://wordpress.stackexchange.com/questions/390175",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/87127/"
] | [This answer](https://wordpress.stackexchange.com/a/254791/87127) describes a hack in which it is possible to upload new media to an "old" folder like 2012/12. That hack no longer seems to work in recent WP versions. Meanwhile, all the plugins I can find for media/folder management seem to want to create an entirely ne... | Okay, so here's a hack to get what you want. There are a few caveats though, so please be sure to take account of this:
* this is untested with WPMS. I haven't a clue how this will affect it.
* it uses a so-called "private" WordPress function, which means that the functionality of this function may change with any WP ... |
390,191 | <p>I have a custom post type (foobar), with two meta_fields:</p>
<ul>
<li><code>updated_at</code></li>
<li><code>build_ran_at</code></li>
</ul>
<p>I would like to make a single WP_query, that returns on the foobar-posts, where <code>updated_at</code> is after <code>build_ran_at</code>.
Both the fields are DateTime-fiel... | [
{
"answer_id": 390203,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 1,
"selected": false,
"text": "<p>As of writing, there is no meta query <code>compare</code> value that can do what you're trying to do, whi... | 2021/06/06 | [
"https://wordpress.stackexchange.com/questions/390191",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128304/"
] | I have a custom post type (foobar), with two meta\_fields:
* `updated_at`
* `build_ran_at`
I would like to make a single WP\_query, that returns on the foobar-posts, where `updated_at` is after `build_ran_at`.
Both the fields are DateTime-fields.
---
Solution attempt
----------------
```
$foobar_query = new WP_Que... | As of writing, there is no meta query `compare` value that can do what you're trying to do, which is basically "*where <updated\_at meta> > <build\_ran\_at meta>*". But there are two options that you can choose from as an alternative to using the `meta_query` arg:
1. Use a raw SQL to retrieve just the IDs of the posts... |
390,215 | <p>I have different styles applied to pages (I hide the title for them) and posts (I don't want to hide the title here, but style the date of the post). I want to style them differently, which ist possible on the site itself. But in the editor I don't seem to have the possibility to distinguish between pages and posts.... | [
{
"answer_id": 390241,
"author": "tiago calado",
"author_id": 198152,
"author_profile": "https://wordpress.stackexchange.com/users/198152",
"pm_score": 0,
"selected": false,
"text": "<p>The html code must be prepared for it.<br>\nFor example different classes for the use of css.</p>\n<p>... | 2021/06/07 | [
"https://wordpress.stackexchange.com/questions/390215",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/198618/"
] | I have different styles applied to pages (I hide the title for them) and posts (I don't want to hide the title here, but style the date of the post). I want to style them differently, which ist possible on the site itself. But in the editor I don't seem to have the possibility to distinguish between pages and posts.
T... | You can use the [`admin_body_class`](https://developer.wordpress.org/reference/hooks/admin_body_class/) hook to add your own CSS classes. For example (if you're using Gutenberg):
```php
function pb_admin_body_class($classes) {
$screen = get_current_screen();
if (!$screen->is_block_editor()) {
return $... |
390,255 | <p>I'm creating a website in which I need that, when I click on one of the tabs of the specific menu, and it opens, this page contains a search box in its body.
My question is how can I add this search box to the page, where can it be edited.</p>
<p>I've now started using WordPress, I've been doing a search but I haven... | [
{
"answer_id": 390271,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 0,
"selected": false,
"text": "<p>If you're using the block editor, as of WordPress 5.3 there is a Search block that you can use: <a href... | 2021/06/08 | [
"https://wordpress.stackexchange.com/questions/390255",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/207483/"
] | I'm creating a website in which I need that, when I click on one of the tabs of the specific menu, and it opens, this page contains a search box in its body.
My question is how can I add this search box to the page, where can it be edited.
I've now started using WordPress, I've been doing a search but I haven't found ... | It's just a form that takes a GET parameter named `s`.
Example:
```
<form method="get" action="/">
<input type="text" name="s" placeholder="type here to search">
</form>
```
But I recommend using the function called `get_search_form()` that does basically the same thing. |
390,280 | <p>I have over 20 thousand pages and need to delete all of them except very few.
Deleting them from the wp-admin page would take too long and a huge effort.
Is there a command I can run in PhpMyAdmin to do the job?</p>
<p>let's assume that I want to keep pages with ID (1,2,3) and delete the rest.</p>
<p>Thanks a lot.</... | [
{
"answer_id": 390296,
"author": "Buttered_Toast",
"author_id": 192133,
"author_profile": "https://wordpress.stackexchange.com/users/192133",
"pm_score": 1,
"selected": false,
"text": "<p>You could do something like this</p>\n<pre><code>if (current_user_can('administrator')) {\n $page... | 2021/06/08 | [
"https://wordpress.stackexchange.com/questions/390280",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/123802/"
] | I have over 20 thousand pages and need to delete all of them except very few.
Deleting them from the wp-admin page would take too long and a huge effort.
Is there a command I can run in PhpMyAdmin to do the job?
let's assume that I want to keep pages with ID (1,2,3) and delete the rest.
Thanks a lot. | You could do something like this
```
if (current_user_can('administrator')) {
$pages = get_posts([
'post_type' => 'page', // get only pages
'posts_per_page' => -1, // get all
'post_status' => array_keys(get_post_statuses()), // all post statuses (publish, draft, private etc...)
'pos... |
390,282 | <p>Is it possible to change the file set-up of @wordpress/create-block to work with multiple blocks?</p>
<p>I've been trying to tweak the files, but maybe it's not even possible. I can't find anything saying it is.</p>
| [
{
"answer_id": 390722,
"author": "bosco",
"author_id": 25324,
"author_profile": "https://wordpress.stackexchange.com/users/25324",
"pm_score": 3,
"selected": false,
"text": "<p>It is! I've toyed with this off and on for the last year or so, and have come up with a few different ways to a... | 2021/06/08 | [
"https://wordpress.stackexchange.com/questions/390282",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/120585/"
] | Is it possible to change the file set-up of @wordpress/create-block to work with multiple blocks?
I've been trying to tweak the files, but maybe it's not even possible. I can't find anything saying it is. | It is! I've toyed with this off and on for the last year or so, and have come up with a few different ways to accomplish it. These are just the products of my own fiddling, however - there may well be more compelling solutions out there. Given the direction of `@wordpress/scripts` development, I would expect this use-c... |
390,290 | <p>I want to create a custom cookie with custom name only for customers who have once logged in. It should be created after they successfully logged in. It should be deleted after they logged out completely. I am using this code below. For some reason it is not working. Can someone throw some light?</p>
<pre><code> ... | [
{
"answer_id": 390722,
"author": "bosco",
"author_id": 25324,
"author_profile": "https://wordpress.stackexchange.com/users/25324",
"pm_score": 3,
"selected": false,
"text": "<p>It is! I've toyed with this off and on for the last year or so, and have come up with a few different ways to a... | 2021/06/09 | [
"https://wordpress.stackexchange.com/questions/390290",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/207516/"
] | I want to create a custom cookie with custom name only for customers who have once logged in. It should be created after they successfully logged in. It should be deleted after they logged out completely. I am using this code below. For some reason it is not working. Can someone throw some light?
```
// To Add Coo... | It is! I've toyed with this off and on for the last year or so, and have come up with a few different ways to accomplish it. These are just the products of my own fiddling, however - there may well be more compelling solutions out there. Given the direction of `@wordpress/scripts` development, I would expect this use-c... |
390,322 | <p>How do you pass the aria_label parameter to get_search_form()?</p>
<p>I can't seem to pass the 'aria_label' parameter to get_search_form() in the correct way and can't find any examples. Lots with the first parameter 'echo' which works as in the documentation, but nothing I've tried for aria_label has made the searc... | [
{
"answer_id": 390324,
"author": "anton",
"author_id": 97934,
"author_profile": "https://wordpress.stackexchange.com/users/97934",
"pm_score": 3,
"selected": true,
"text": "<p>You can pass an array of attributes with <code>aria_label</code> attribute in it. <br>\nTry this:</p>\n<pre><cod... | 2021/06/09 | [
"https://wordpress.stackexchange.com/questions/390322",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/173627/"
] | How do you pass the aria\_label parameter to get\_search\_form()?
I can't seem to pass the 'aria\_label' parameter to get\_search\_form() in the correct way and can't find any examples. Lots with the first parameter 'echo' which works as in the documentation, but nothing I've tried for aria\_label has made the search ... | You can pass an array of attributes with `aria_label` attribute in it.
Try this:
```
get_search_form(array('aria_label' => 'search-form'));
```
This function gets a form from `searchform.php` by default and if you have this file in your theme and aria-label still missing, you need to check the code in this file.... |
390,382 | <p>How can I add a custom rewrite rule so I can catch paths like these:</p>
<pre><code>/products/imports/filters
/products/imports/elements
/products/imports/parts
</code></pre>
<p>And point them to a template file, for examples:</p>
<pre><code>sector.php
</code></pre>
<p>My code:</p>
<pre><code>function sector_rewrite... | [
{
"answer_id": 390324,
"author": "anton",
"author_id": 97934,
"author_profile": "https://wordpress.stackexchange.com/users/97934",
"pm_score": 3,
"selected": true,
"text": "<p>You can pass an array of attributes with <code>aria_label</code> attribute in it. <br>\nTry this:</p>\n<pre><cod... | 2021/06/10 | [
"https://wordpress.stackexchange.com/questions/390382",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/89898/"
] | How can I add a custom rewrite rule so I can catch paths like these:
```
/products/imports/filters
/products/imports/elements
/products/imports/parts
```
And point them to a template file, for examples:
```
sector.php
```
My code:
```
function sector_rewrite_rule() {
add_rewrite_rule(
'(.?.+?)/([^/]*... | You can pass an array of attributes with `aria_label` attribute in it.
Try this:
```
get_search_form(array('aria_label' => 'search-form'));
```
This function gets a form from `searchform.php` by default and if you have this file in your theme and aria-label still missing, you need to check the code in this file.... |
390,452 | <p>I have a webpage on localhost that do not have wordpress environment, I had use woocommerce api to create the product, however woocommerce api doesnt seem to upload the image.
I want to create the product and upload the image.
this the code I am using and the woocommerce api default.</p>
<pre class="lang-php prettyp... | [
{
"answer_id": 390454,
"author": "Fabian Mossberg",
"author_id": 207387,
"author_profile": "https://wordpress.stackexchange.com/users/207387",
"pm_score": 3,
"selected": true,
"text": "<p>Just to make sure: You have a local environment, without WooCommerce, from which you want to create ... | 2021/06/12 | [
"https://wordpress.stackexchange.com/questions/390452",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/198152/"
] | I have a webpage on localhost that do not have wordpress environment, I had use woocommerce api to create the product, however woocommerce api doesnt seem to upload the image.
I want to create the product and upload the image.
this the code I am using and the woocommerce api default.
```php
<?php
$data = [
'name' ... | Just to make sure: You have a local environment, without WooCommerce, from which you want to create a product in your WooCommerce Wordpress site, and make sure that the images you provide are uploaded to your WordPress site.
1. Install library
==================
Make sure that you in your local environment have insta... |
390,489 | <p>I want to load 3 posts that have the same custom field value as the current post.<br>
for example:<br>
The current post has 3 custom fields:<br>
color: black<br>
background: red<br>
lastname: doe <br>
Now I want to load three posts with these custom fields:<br>
first post: color:black<br>
second post: background:red... | [
{
"answer_id": 390490,
"author": "Paul G.",
"author_id": 41288,
"author_profile": "https://wordpress.stackexchange.com/users/41288",
"pm_score": 2,
"selected": true,
"text": "<p>I've taken your code and refactored it. Your nested-for-loops arent the ideal way to go about this.</p>\n<p>Al... | 2021/06/13 | [
"https://wordpress.stackexchange.com/questions/390489",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/96600/"
] | I want to load 3 posts that have the same custom field value as the current post.
for example:
The current post has 3 custom fields:
color: black
background: red
lastname: doe
Now I want to load three posts with these custom fields:
first post: color:black
second post: background:red
third p... | I've taken your code and refactored it. Your nested-for-loops arent the ideal way to go about this.
Also, I've used your code and the meta key names exactly as you supplied them, so please double-check they're correct. Some of them are prefixed with `the_` and then sometimes not. It's strange, but that's what you supp... |
390,628 | <p>I'm trying to completely disable access to my parents page menu.
For example, I have a menu made like this :
parent page -> child page 1
-> child page 2</p>
<p>I made a real page for 'parent page' because my backend is better organized.
But I don't want that my customers go to www.mysite/parent-page</p>
<p>I t... | [
{
"answer_id": 390490,
"author": "Paul G.",
"author_id": 41288,
"author_profile": "https://wordpress.stackexchange.com/users/41288",
"pm_score": 2,
"selected": true,
"text": "<p>I've taken your code and refactored it. Your nested-for-loops arent the ideal way to go about this.</p>\n<p>Al... | 2021/06/16 | [
"https://wordpress.stackexchange.com/questions/390628",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/197738/"
] | I'm trying to completely disable access to my parents page menu.
For example, I have a menu made like this :
parent page -> child page 1
-> child page 2
I made a real page for 'parent page' because my backend is better organized.
But I don't want that my customers go to www.mysite/parent-page
I tried to put that page... | I've taken your code and refactored it. Your nested-for-loops arent the ideal way to go about this.
Also, I've used your code and the meta key names exactly as you supplied them, so please double-check they're correct. Some of them are prefixed with `the_` and then sometimes not. It's strange, but that's what you supp... |
390,648 | <p>How to list out all the terms of a custom taxonomy that are relative in another custom taxonomy?</p>
<p>I am creating a filter page for a CPT with multiple custom taxonomies.<br />
Please see the screenshot below:</p>
<p><a href="https://i.stack.imgur.com/cbHJ5.png" rel="nofollow noreferrer"><img src="https://i.stac... | [
{
"answer_id": 390490,
"author": "Paul G.",
"author_id": 41288,
"author_profile": "https://wordpress.stackexchange.com/users/41288",
"pm_score": 2,
"selected": true,
"text": "<p>I've taken your code and refactored it. Your nested-for-loops arent the ideal way to go about this.</p>\n<p>Al... | 2021/06/16 | [
"https://wordpress.stackexchange.com/questions/390648",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/137035/"
] | How to list out all the terms of a custom taxonomy that are relative in another custom taxonomy?
I am creating a filter page for a CPT with multiple custom taxonomies.
Please see the screenshot below:
[](https://i.stack.imgur.com/cbHJ5.png)
* **C... | I've taken your code and refactored it. Your nested-for-loops arent the ideal way to go about this.
Also, I've used your code and the meta key names exactly as you supplied them, so please double-check they're correct. Some of them are prefixed with `the_` and then sometimes not. It's strange, but that's what you supp... |
390,654 | <p>I have a custom block that has block variations. If I make the scope of the variations "inserter", they work as expected. But if I make the scope "block" and use BlockVariationPicker so the user chooses a variation upon adding a block (like they do when adding the core columns block), nothing hap... | [
{
"answer_id": 390490,
"author": "Paul G.",
"author_id": 41288,
"author_profile": "https://wordpress.stackexchange.com/users/41288",
"pm_score": 2,
"selected": true,
"text": "<p>I've taken your code and refactored it. Your nested-for-loops arent the ideal way to go about this.</p>\n<p>Al... | 2021/06/16 | [
"https://wordpress.stackexchange.com/questions/390654",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/120585/"
] | I have a custom block that has block variations. If I make the scope of the variations "inserter", they work as expected. But if I make the scope "block" and use BlockVariationPicker so the user chooses a variation upon adding a block (like they do when adding the core columns block), nothing happens when I click on a ... | I've taken your code and refactored it. Your nested-for-loops arent the ideal way to go about this.
Also, I've used your code and the meta key names exactly as you supplied them, so please double-check they're correct. Some of them are prefixed with `the_` and then sometimes not. It's strange, but that's what you supp... |
390,696 | <p>When using InnerBlocks so you can nest parent/child blocks you end up with additional HTML (in the editor) wrapping the child elements like so:</p>
<pre><code><div class="PARENT">
<div class="block-editor-inner-blocks">
<div class="block-editor-block-list__layout"... | [
{
"answer_id": 390699,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 3,
"selected": true,
"text": "<p>You can eliminate the wrapping containers abandoning <code>InnerBlocks</code> and instead using the <code>use... | 2021/06/17 | [
"https://wordpress.stackexchange.com/questions/390696",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/881/"
] | When using InnerBlocks so you can nest parent/child blocks you end up with additional HTML (in the editor) wrapping the child elements like so:
```
<div class="PARENT">
<div class="block-editor-inner-blocks">
<div class="block-editor-block-list__layout">
<div class="block-editor-block-list__block wp-... | You can eliminate the wrapping containers abandoning `InnerBlocks` and instead using the `useInnerBlocksProps` hook which is how the blocks that come with core do it. This will allow your block markup to match the frontend without the editor wrapping things in additional tags.
If we look at the official buttons block:... |
390,711 | <p>My site was running well last summer. But today when I tried to make updates in the wp-admin section, I got lots of 403 errors on all PHP files: <code>load-styles, load-scripts, edit.php, media-new.php</code>, etc... The interesting thing is that the front-end of my site has no problems.</p>
<h3>Screenshot:</h3>
<p>... | [
{
"answer_id": 390712,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 3,
"selected": true,
"text": "<p>You appear to be denying access to PHP files, which would explain why you are denied access to PHP files... | 2021/06/17 | [
"https://wordpress.stackexchange.com/questions/390711",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/188876/"
] | My site was running well last summer. But today when I tried to make updates in the wp-admin section, I got lots of 403 errors on all PHP files: `load-styles, load-scripts, edit.php, media-new.php`, etc... The interesting thing is that the front-end of my site has no problems.
### Screenshot:
[![403 errors in network... | You appear to be denying access to PHP files, which would explain why you are denied access to PHP files:
```
<FilesMatch ".(py|exe|php)$">
Order allow,deny
Deny from all
</FilesMatch>
```
What is the purpose of this? |
390,768 | <p>This is about the functions.php file.</p>
<p>I have a homepage with two links to enter data into either this form (refinance) or that form (purchase). Both forms have identical fields, just one question is different.</p>
<p>This site is for home purchase and refinance loans, so the difference between the two forms ... | [
{
"answer_id": 390712,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 3,
"selected": true,
"text": "<p>You appear to be denying access to PHP files, which would explain why you are denied access to PHP files... | 2021/06/19 | [
"https://wordpress.stackexchange.com/questions/390768",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/207981/"
] | This is about the functions.php file.
I have a homepage with two links to enter data into either this form (refinance) or that form (purchase). Both forms have identical fields, just one question is different.
This site is for home purchase and refinance loans, so the difference between the two forms is "What is the ... | You appear to be denying access to PHP files, which would explain why you are denied access to PHP files:
```
<FilesMatch ".(py|exe|php)$">
Order allow,deny
Deny from all
</FilesMatch>
```
What is the purpose of this? |
390,795 | <p>I am looking at ways to restrict direct access to the Wordpress Uploads folder. I've read a handful of Stackoverflow and blog posts about using "wordpress_logged_in" in .htaccess to check if a person is logged in and if they are not to restrict them. See example of a snippet below.</p>
<p>However, I also r... | [
{
"answer_id": 390712,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 3,
"selected": true,
"text": "<p>You appear to be denying access to PHP files, which would explain why you are denied access to PHP files... | 2021/06/20 | [
"https://wordpress.stackexchange.com/questions/390795",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/60781/"
] | I am looking at ways to restrict direct access to the Wordpress Uploads folder. I've read a handful of Stackoverflow and blog posts about using "wordpress\_logged\_in" in .htaccess to check if a person is logged in and if they are not to restrict them. See example of a snippet below.
However, I also read a post that w... | You appear to be denying access to PHP files, which would explain why you are denied access to PHP files:
```
<FilesMatch ".(py|exe|php)$">
Order allow,deny
Deny from all
</FilesMatch>
```
What is the purpose of this? |
390,837 | <p>i am working on custom page templates. so i want to remove all body classes by one function only.
i searched it for on net but not found any solution.</p>
<p>is there anyone who can answer it. @Php</p>
<p>Edit..</p>
<p>how to remove all page template classes except all other..</p>
<p>example - page-template, page-te... | [
{
"answer_id": 390839,
"author": "Rup",
"author_id": 3276,
"author_profile": "https://wordpress.stackexchange.com/users/3276",
"pm_score": 3,
"selected": false,
"text": "<p>I'm going to assume you mean the classes generated by <a href=\"https://developer.wordpress.org/reference/functions... | 2021/06/21 | [
"https://wordpress.stackexchange.com/questions/390837",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | i am working on custom page templates. so i want to remove all body classes by one function only.
i searched it for on net but not found any solution.
is there anyone who can answer it. @Php
Edit..
how to remove all page template classes except all other..
example - page-template, page-template-zx, page-template-zx... | I'm going to assume you mean the classes generated by [body\_class()](https://developer.wordpress.org/reference/functions/body_class/), e.g. from the twentytwentyone header.php:
```php
<body <?php body_class(); ?>>
<?php wp_body_open(); ?>
```
The simplest thing to do is to just remove the `<?php body_class(); ?>` c... |
390,867 | <p>I am using Wordpress/Woocommerce for my website along with jekyll (static html generator). I want to change a button based upon user logged in or logged out.</p>
<pre><code>\\ if user is logged in
<button>Log Out</button>
\\ else
<button>Log in</button>
</code></pre>
| [
{
"answer_id": 390839,
"author": "Rup",
"author_id": 3276,
"author_profile": "https://wordpress.stackexchange.com/users/3276",
"pm_score": 3,
"selected": false,
"text": "<p>I'm going to assume you mean the classes generated by <a href=\"https://developer.wordpress.org/reference/functions... | 2021/06/22 | [
"https://wordpress.stackexchange.com/questions/390867",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/194326/"
] | I am using Wordpress/Woocommerce for my website along with jekyll (static html generator). I want to change a button based upon user logged in or logged out.
```
\\ if user is logged in
<button>Log Out</button>
\\ else
<button>Log in</button>
``` | I'm going to assume you mean the classes generated by [body\_class()](https://developer.wordpress.org/reference/functions/body_class/), e.g. from the twentytwentyone header.php:
```php
<body <?php body_class(); ?>>
<?php wp_body_open(); ?>
```
The simplest thing to do is to just remove the `<?php body_class(); ?>` c... |
390,913 | <p>I'm developing a site using Understrap's starter theme. I wanted to use a split design on home.php where the latest post is displayed on top of the others "full width" while the rest are positioned below within a three column layout.</p>
<p>Thanks to <a href="https://wordpress.stackexchange.com/a/191448/20... | [
{
"answer_id": 390839,
"author": "Rup",
"author_id": 3276,
"author_profile": "https://wordpress.stackexchange.com/users/3276",
"pm_score": 3,
"selected": false,
"text": "<p>I'm going to assume you mean the classes generated by <a href=\"https://developer.wordpress.org/reference/functions... | 2021/06/23 | [
"https://wordpress.stackexchange.com/questions/390913",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/204194/"
] | I'm developing a site using Understrap's starter theme. I wanted to use a split design on home.php where the latest post is displayed on top of the others "full width" while the rest are positioned below within a three column layout.
Thanks to [this very helpful post](https://wordpress.stackexchange.com/a/191448/20419... | I'm going to assume you mean the classes generated by [body\_class()](https://developer.wordpress.org/reference/functions/body_class/), e.g. from the twentytwentyone header.php:
```php
<body <?php body_class(); ?>>
<?php wp_body_open(); ?>
```
The simplest thing to do is to just remove the `<?php body_class(); ?>` c... |
390,956 | <p>I would like to use REST API to update custom fields on various pages - an example would be tracking outside temperature, humidity, etc from a sensor. However, if the website has cache, the pages won't update with the new information in the custom fields.</p>
<p>How can I "punch holes" in the cache so only... | [
{
"answer_id": 390839,
"author": "Rup",
"author_id": 3276,
"author_profile": "https://wordpress.stackexchange.com/users/3276",
"pm_score": 3,
"selected": false,
"text": "<p>I'm going to assume you mean the classes generated by <a href=\"https://developer.wordpress.org/reference/functions... | 2021/06/24 | [
"https://wordpress.stackexchange.com/questions/390956",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/208193/"
] | I would like to use REST API to update custom fields on various pages - an example would be tracking outside temperature, humidity, etc from a sensor. However, if the website has cache, the pages won't update with the new information in the custom fields.
How can I "punch holes" in the cache so only these fields are u... | I'm going to assume you mean the classes generated by [body\_class()](https://developer.wordpress.org/reference/functions/body_class/), e.g. from the twentytwentyone header.php:
```php
<body <?php body_class(); ?>>
<?php wp_body_open(); ?>
```
The simplest thing to do is to just remove the `<?php body_class(); ?>` c... |
390,994 | <p>I am developing a plugin to extend BuddyBoss platform. Specifically I am sync'ing BB user info with Wordpress User meta data.</p>
<p>Most of my code works (country and regional organisation update fine), but sync'ing my 'gender' field is not working as expected. It seems to work for male, and female, but when Other ... | [
{
"answer_id": 390998,
"author": "roly151",
"author_id": 208221,
"author_profile": "https://wordpress.stackexchange.com/users/208221",
"pm_score": 0,
"selected": false,
"text": "<p>I changed the wordpress meta gender data to match the BuddyBoss data (i.e. his_Male, her_Female, their_Othe... | 2021/06/25 | [
"https://wordpress.stackexchange.com/questions/390994",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/208221/"
] | I am developing a plugin to extend BuddyBoss platform. Specifically I am sync'ing BB user info with Wordpress User meta data.
Most of my code works (country and regional organisation update fine), but sync'ing my 'gender' field is not working as expected. It seems to work for male, and female, but when Other is select... | In this code:
```
if ($gender == 'his_Male') {
$wpgender = 'Male';
} elseif ($gender = 'her_Female') {
$wpgender = 'Female';
} else {
$wpgender = 'Other';
}
```
You're not comparing `$gender` to `'her_Female'`, you're *setting* it to `'her_Female'`:
```
} elseif ($gender = 'her_Female') {
```
You shou... |
391,012 | <p>I have a basic question that has always stumped me. I'm trying to move the Star Rating into the comment meta, which will help me style it. Here's the template file <code>review.php</code> section:</p>
<pre><code><div class="comment-text">
<?php
/**
* The woocomme... | [
{
"answer_id": 390998,
"author": "roly151",
"author_id": 208221,
"author_profile": "https://wordpress.stackexchange.com/users/208221",
"pm_score": 0,
"selected": false,
"text": "<p>I changed the wordpress meta gender data to match the BuddyBoss data (i.e. his_Male, her_Female, their_Othe... | 2021/06/25 | [
"https://wordpress.stackexchange.com/questions/391012",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/200067/"
] | I have a basic question that has always stumped me. I'm trying to move the Star Rating into the comment meta, which will help me style it. Here's the template file `review.php` section:
```
<div class="comment-text">
<?php
/**
* The woocommerce_review_before_comment_meta hook.
... | In this code:
```
if ($gender == 'his_Male') {
$wpgender = 'Male';
} elseif ($gender = 'her_Female') {
$wpgender = 'Female';
} else {
$wpgender = 'Other';
}
```
You're not comparing `$gender` to `'her_Female'`, you're *setting* it to `'her_Female'`:
```
} elseif ($gender = 'her_Female') {
```
You shou... |
391,126 | <p>I'm working on a custom WooCommerce theme, and ideally would like to use the stable Gutenberg blocks shipped with WooCommerce. Obviously, instead of over-riding all of their styles with my own to match the design, I would rather remove them to improve page speed. Seems like it should be a simple process, but no resu... | [
{
"answer_id": 391127,
"author": "Buttered_Toast",
"author_id": 192133,
"author_profile": "https://wordpress.stackexchange.com/users/192133",
"pm_score": 1,
"selected": false,
"text": "<p>The dequeue handle is incorrect</p>\n<p>it should be <code>wp_dequeue_style('wc-block-style');</code... | 2021/06/28 | [
"https://wordpress.stackexchange.com/questions/391126",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/64689/"
] | I'm working on a custom WooCommerce theme, and ideally would like to use the stable Gutenberg blocks shipped with WooCommerce. Obviously, instead of over-riding all of their styles with my own to match the design, I would rather remove them to improve page speed. Seems like it should be a simple process, but no result ... | The dequeue handle is incorrect
it should be `wp_dequeue_style('wc-block-style');` and not `wp_dequeue_style('wc-block-style-css');`
~~A bit confusing at first i agree, every js and css that was enqued via `wp_enqueue_style` or `wp_enqueue_script` gets a suffix of css/js~~
Example
```
wp_enqueue_style('swiper', 'ht... |
391,141 | <p>I know there are several similar questions, but I couldn't find the one I wanted.
I want to get all commenters's on a post. But if there is a commenter who gives more than one comment, then he is not counted double. I don't want to display them individually like:</p>
<blockquote>
<p>foreach($comments as $comment){ /... | [
{
"answer_id": 391142,
"author": "Paul G.",
"author_id": 41288,
"author_profile": "https://wordpress.stackexchange.com/users/41288",
"pm_score": 1,
"selected": false,
"text": "<p>I'm a little unclear as to exactly the final data you're looking for. You said "array form", but th... | 2021/06/28 | [
"https://wordpress.stackexchange.com/questions/391141",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/208048/"
] | I know there are several similar questions, but I couldn't find the one I wanted.
I want to get all commenters's on a post. But if there is a commenter who gives more than one comment, then he is not counted double. I don't want to display them individually like:
>
> foreach($comments as $comment){ //echo }
>
>
>
... | I managed to get an array of user\_ids of all commenters in a post with the following method:
```
$args_user = array( 'role__in' => array( 'author', 'subscriber' ),
'fields' => 'ID'
);
$get_usersgroup = get_users($args_user);
... |
391,143 | <p>I have 2 different WP Query on the home page.
I need to check $home_query condition in functions.php then I want to do something if $home_query returns null.
I tried with pre_get_posts action I couldn't catch $home_query data and it's worked twice, because have two WP_Query on the page.</p>
<p>Using pagination by If... | [
{
"answer_id": 391145,
"author": "Fabian Mossberg",
"author_id": 207387,
"author_profile": "https://wordpress.stackexchange.com/users/207387",
"pm_score": 1,
"selected": false,
"text": "<p>You can check if the query returned any posts by doing <code>$home_query->have_posts()</code>.</... | 2021/06/28 | [
"https://wordpress.stackexchange.com/questions/391143",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/208298/"
] | I have 2 different WP Query on the home page.
I need to check $home\_query condition in functions.php then I want to do something if $home\_query returns null.
I tried with pre\_get\_posts action I couldn't catch $home\_query data and it's worked twice, because have two WP\_Query on the page.
Using pagination by If $h... | You can check if the query returned any posts by doing `$home_query->have_posts()`.
```php
$home_query = new WP_Query( array('posts_per_page' => get_query_var('posts_per_page'),'paged' => $current_page ) );
if( !$home_query->have_posts() ){
// Do this if $home_query had no posts.
}
``` |
391,271 | <p>I am new to wordpress development and I've read the documentation on how to do what I want to do but I can't find any decent answers.</p>
<p>I want to make a plugin that can show a popup window when someone goes to a certain page. the info in the popup will be customizable based on what the admin wants to show but I... | [
{
"answer_id": 391145,
"author": "Fabian Mossberg",
"author_id": 207387,
"author_profile": "https://wordpress.stackexchange.com/users/207387",
"pm_score": 1,
"selected": false,
"text": "<p>You can check if the query returned any posts by doing <code>$home_query->have_posts()</code>.</... | 2021/07/01 | [
"https://wordpress.stackexchange.com/questions/391271",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/208448/"
] | I am new to wordpress development and I've read the documentation on how to do what I want to do but I can't find any decent answers.
I want to make a plugin that can show a popup window when someone goes to a certain page. the info in the popup will be customizable based on what the admin wants to show but I cannot f... | You can check if the query returned any posts by doing `$home_query->have_posts()`.
```php
$home_query = new WP_Query( array('posts_per_page' => get_query_var('posts_per_page'),'paged' => $current_page ) );
if( !$home_query->have_posts() ){
// Do this if $home_query had no posts.
}
``` |
391,371 | <p>I'm developing a dynamic block that prints the following markup (for example) using the <code>ServerSideRender</code> component:</p>
<pre><code><div class="accordion">
<h3 class="accordion-title">A title</h3>
<div class="accordion-content">Lorem ipsum dol... | [
{
"answer_id": 391399,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 2,
"selected": false,
"text": "<blockquote>\n<p>BUT, for some reason, the <code>accordion</code> function from jQuery UI doesn't get attache... | 2021/07/03 | [
"https://wordpress.stackexchange.com/questions/391371",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/33049/"
] | I'm developing a dynamic block that prints the following markup (for example) using the `ServerSideRender` component:
```
<div class="accordion">
<h3 class="accordion-title">A title</h3>
<div class="accordion-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut ... | >
> BUT, for some reason, the `accordion` function from jQuery UI doesn't get attached to the `.accordion` class of my block in the block editor, so the accordion effect doesn't work.
>
>
>
The `ServerSideRender` component uses the REST API to fetch the dynamic block output, hence the above issue happens because b... |
391,403 | <p>I get this message when I go to add a new Plugin. Do you know a way to solve this?</p>
<p>An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.<a href="https://i.stack.imgur.com/Abhbc.png" rel="nofollow... | [
{
"answer_id": 391399,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 2,
"selected": false,
"text": "<blockquote>\n<p>BUT, for some reason, the <code>accordion</code> function from jQuery UI doesn't get attache... | 2021/07/04 | [
"https://wordpress.stackexchange.com/questions/391403",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/208567/"
] | I get this message when I go to add a new Plugin. Do you know a way to solve this?
An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.[:
```php
add_action( 'init', function() {
register_bl... | When you declare your block, you need to tell WP that it needs context, either by using `usesContext` in JS/JSON or `uses_context` in PHP.
E.g in PHP:
```php
'render_callback' => 'render_my_block',
'uses_context' => [ 'postId' ],
```
This value then takes an array of context identifiers, e.g. `postI... |
391,504 | <p><strong>See edit at bottom.</strong></p>
<p>I have a wp_query loop in a page template for a custom post type ("success_stories"). The loop itself works fine but I cannot seem to get pagination working. I've tried every solution I could find on these forums and everytime I try to navigate to /page/child-pag... | [
{
"answer_id": 391582,
"author": "Josh M",
"author_id": 9764,
"author_profile": "https://wordpress.stackexchange.com/users/9764",
"pm_score": 0,
"selected": false,
"text": "<p>The problem turned out to be the redirect_canonical filter. That was causing the 301 back to the child page itse... | 2021/07/06 | [
"https://wordpress.stackexchange.com/questions/391504",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/9764/"
] | **See edit at bottom.**
I have a wp\_query loop in a page template for a custom post type ("success\_stories"). The loop itself works fine but I cannot seem to get pagination working. I've tried every solution I could find on these forums and everytime I try to navigate to /page/child-page/page/2/ WordPress sends me b... | Glad that you managed to figure out a solution, which yes, does work. But you could make it more selectively, i.e. target just the specific pages, by using [`is_single( '<parent slug>/<child slug>' )`](https://developer.wordpress.org/reference/functions/is_single/), e.g. `is_single( 'family-law/success-stories' )` in y... |
391,519 | <p>I wrote a specific block for a customer. It is working well. I fill the data. I save and when I look on the website, it is quite perfect. But, when I refresh the editor, I am receiving this error.</p>
<p>Thank you so much!</p>
<blockquote>
<p>blocks.min.js?ver=9ed25ffa009c799f99a4340915b6dc6a:3 Block validation: Blo... | [
{
"answer_id": 391582,
"author": "Josh M",
"author_id": 9764,
"author_profile": "https://wordpress.stackexchange.com/users/9764",
"pm_score": 0,
"selected": false,
"text": "<p>The problem turned out to be the redirect_canonical filter. That was causing the 301 back to the child page itse... | 2021/07/06 | [
"https://wordpress.stackexchange.com/questions/391519",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/208672/"
] | I wrote a specific block for a customer. It is working well. I fill the data. I save and when I look on the website, it is quite perfect. But, when I refresh the editor, I am receiving this error.
Thank you so much!
>
> blocks.min.js?ver=9ed25ffa009c799f99a4340915b6dc6a:3 Block validation: Block validation failed fo... | Glad that you managed to figure out a solution, which yes, does work. But you could make it more selectively, i.e. target just the specific pages, by using [`is_single( '<parent slug>/<child slug>' )`](https://developer.wordpress.org/reference/functions/is_single/), e.g. `is_single( 'family-law/success-stories' )` in y... |
391,539 | <p>I'm trying to post to a WordPress server on an AWS Lightsail instance using node-wpapi.
However, the server returns a 401 error.</p>
<p>I already have a <code>.htaccess</code> file with <code>RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]</code> to my <code>.htaccess</code> file and I already use 'applicatio... | [
{
"answer_id": 391552,
"author": "MrWhite",
"author_id": 8259,
"author_profile": "https://wordpress.stackexchange.com/users/8259",
"pm_score": 0,
"selected": false,
"text": "<blockquote>\n<pre><code>RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]\n</code></pre>\n</blockquote>\n<p>... | 2021/07/07 | [
"https://wordpress.stackexchange.com/questions/391539",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/208687/"
] | I'm trying to post to a WordPress server on an AWS Lightsail instance using node-wpapi.
However, the server returns a 401 error.
I already have a `.htaccess` file with `RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]` to my `.htaccess` file and I already use 'application passwords' plugin.
How can I use node-w... | I've found a solution.
The WordPress made from AWS Lightsail instance image is bitnami WordPress.
And the bitnami WordPress is disabled Basic Authentication as default. So it needs some modification on `/opt/bitnami/apps/WordPress/conf/httpd-app.conf` to enable Basic Authentication. This modification is adding 3 lines... |
391,562 | <p>May I know how could I change the error text? Example, I want change it from.</p>
<p>[Error: This username is invalid because it uses illegal characters. Please enter a valid username.]</p>
<p>to</p>
<p>[Error: Username invalid. Please enter a valid username.]</p>
<p><a href="https://i.stack.imgur.com/tWUK9.png" rel... | [
{
"answer_id": 391585,
"author": "vancoder",
"author_id": 26778,
"author_profile": "https://wordpress.stackexchange.com/users/26778",
"pm_score": 0,
"selected": false,
"text": "<p>Unfortunately you cannot change it, as it is hard-coded and unfiltered in core.</p>\n<p>See <a href=\"https:... | 2021/07/07 | [
"https://wordpress.stackexchange.com/questions/391562",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/207928/"
] | May I know how could I change the error text? Example, I want change it from.
[Error: This username is invalid because it uses illegal characters. Please enter a valid username.]
to
[Error: Username invalid. Please enter a valid username.]
[](https... | You can achieve this via '[registration\_errors](https://developer.wordpress.org/reference/hooks/registration_errors/)' filter hook. The hook filters the WP\_Error object that holds all the current errors. The code used will be something like this:
```
add_filter( 'registration_errors', function( $errors ){
if( $e... |
391,579 | <p>I have been stuck on the following case for a while now. On a page I have a list of <code>tags</code> which I try to filter. When the post for example has an <code>ID</code> of <code>10586</code>, the only tag displayed should be <code>10586</code>.</p>
<p><a href="https://i.stack.imgur.com/jmOIN.jpg" rel="nofollow ... | [
{
"answer_id": 391585,
"author": "vancoder",
"author_id": 26778,
"author_profile": "https://wordpress.stackexchange.com/users/26778",
"pm_score": 0,
"selected": false,
"text": "<p>Unfortunately you cannot change it, as it is hard-coded and unfiltered in core.</p>\n<p>See <a href=\"https:... | 2021/07/07 | [
"https://wordpress.stackexchange.com/questions/391579",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/206573/"
] | I have been stuck on the following case for a while now. On a page I have a list of `tags` which I try to filter. When the post for example has an `ID` of `10586`, the only tag displayed should be `10586`.
[](https://i.stack.imgur.com/jmOIN.jpg)
The ... | You can achieve this via '[registration\_errors](https://developer.wordpress.org/reference/hooks/registration_errors/)' filter hook. The hook filters the WP\_Error object that holds all the current errors. The code used will be something like this:
```
add_filter( 'registration_errors', function( $errors ){
if( $e... |
391,600 | <p>If jQuery is included in WordPress, why do I get 'jQuery is undefined' errors?
I cannot find a tutorial (one would think this would be in the WordPress docs) on how to use jQuery in modern versions of WordPress (I'm using 5.7). Do I need to enqueue anything? Deregister anything? Do anything in functions.php. I've tr... | [
{
"answer_id": 391608,
"author": "JosF",
"author_id": 50460,
"author_profile": "https://wordpress.stackexchange.com/users/50460",
"pm_score": 2,
"selected": false,
"text": "<p>(I'm using 5.7.2) This is all you have to use: <code>const $ = jQuery.noConflict();</code>. However, you have to... | 2021/07/08 | [
"https://wordpress.stackexchange.com/questions/391600",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/153797/"
] | If jQuery is included in WordPress, why do I get 'jQuery is undefined' errors?
I cannot find a tutorial (one would think this would be in the WordPress docs) on how to use jQuery in modern versions of WordPress (I'm using 5.7). Do I need to enqueue anything? Deregister anything? Do anything in functions.php. I've tried... | (I'm using 5.7.2) This is all you have to use: `const $ = jQuery.noConflict();`. However, you have to make sure the file you load is loaded after jQuery to prevent timing issues. So either make jQuery a dependency of your script like this:
```
function _jf_load_scripts()
{
wp_register_script('main', get_templa... |
391,624 | <p>Trying to remove "/index.php/" from URL,</p>
<p>The .htaccess file location is</p>
<pre><code>./var/www/html/.htaccess
</code></pre>
<p>and the content</p>
<pre><code><IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ... | [
{
"answer_id": 391608,
"author": "JosF",
"author_id": 50460,
"author_profile": "https://wordpress.stackexchange.com/users/50460",
"pm_score": 2,
"selected": false,
"text": "<p>(I'm using 5.7.2) This is all you have to use: <code>const $ = jQuery.noConflict();</code>. However, you have to... | 2021/07/08 | [
"https://wordpress.stackexchange.com/questions/391624",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/193450/"
] | Trying to remove "/index.php/" from URL,
The .htaccess file location is
```
./var/www/html/.htaccess
```
and the content
```
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php/$1 [L]
</IfModule>
```
however it does... | (I'm using 5.7.2) This is all you have to use: `const $ = jQuery.noConflict();`. However, you have to make sure the file you load is loaded after jQuery to prevent timing issues. So either make jQuery a dependency of your script like this:
```
function _jf_load_scripts()
{
wp_register_script('main', get_templa... |
391,632 | <p><strong>I have added this snippet to functions.php to be able to order Slider Revolution slides:</strong></p>
<pre><code>// orderby slideshows
</code></pre>
<p>function modify_slider_order($query, $slider_id) {</p>
<pre><code>// only alter the order for slider with "x" ID
// https://tinyurl.com/zb6hzpc
if... | [
{
"answer_id": 391608,
"author": "JosF",
"author_id": 50460,
"author_profile": "https://wordpress.stackexchange.com/users/50460",
"pm_score": 2,
"selected": false,
"text": "<p>(I'm using 5.7.2) This is all you have to use: <code>const $ = jQuery.noConflict();</code>. However, you have to... | 2021/07/08 | [
"https://wordpress.stackexchange.com/questions/391632",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/62358/"
] | **I have added this snippet to functions.php to be able to order Slider Revolution slides:**
```
// orderby slideshows
```
function modify\_slider\_order($query, $slider\_id) {
```
// only alter the order for slider with "x" ID
// https://tinyurl.com/zb6hzpc
if($slider_id == 17 ) {
// Custom Meta key/name
... | (I'm using 5.7.2) This is all you have to use: `const $ = jQuery.noConflict();`. However, you have to make sure the file you load is loaded after jQuery to prevent timing issues. So either make jQuery a dependency of your script like this:
```
function _jf_load_scripts()
{
wp_register_script('main', get_templa... |
391,749 | <p>I am trying to replace the default Add Media icon in my Wordpress site. I searched for the same on the web and got this:</p>
<p><a href="https://wordpress.stackexchange.com/questions/284217/how-to-replace-default-icon-on-add-media-button">How to replace default icon on "Add Media" button?</a></p>
<p>This s... | [
{
"answer_id": 391655,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 1,
"selected": false,
"text": "<p>Your theme must contain a style.css file, and it needs to have a comment at the top with the theme deta... | 2021/07/11 | [
"https://wordpress.stackexchange.com/questions/391749",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/201912/"
] | I am trying to replace the default Add Media icon in my Wordpress site. I searched for the same on the web and got this:
[How to replace default icon on "Add Media" button?](https://wordpress.stackexchange.com/questions/284217/how-to-replace-default-icon-on-add-media-button)
This seems to work for the OP, and ofcours... | Your theme must contain a style.css file, and it needs to have a comment at the top with the theme details.
<https://developer.wordpress.org/themes/basics/main-stylesheet-style-css/> |
391,793 | <p>How do I pass arguments to my hook function?</p>
<pre><code>my_function($arg1, $arg2){
echo $arg1 . " " . $arg2;
}
add_action( 'init', 'my_function');
</code></pre>
<p>If I want my_function to echo "hello world" for instance, how would I send those parameters with the action hook?</p>
| [
{
"answer_id": 391794,
"author": "Auraylien",
"author_id": 208737,
"author_profile": "https://wordpress.stackexchange.com/users/208737",
"pm_score": 0,
"selected": false,
"text": "<p>According to the <a href=\"https://developer.wordpress.org/reference/functions/add_action/\" rel=\"nofoll... | 2021/07/12 | [
"https://wordpress.stackexchange.com/questions/391793",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/205473/"
] | How do I pass arguments to my hook function?
```
my_function($arg1, $arg2){
echo $arg1 . " " . $arg2;
}
add_action( 'init', 'my_function');
```
If I want my\_function to echo "hello world" for instance, how would I send those parameters with the action hook? | I would suggest first read the wordpress documentation about [actions](https://developer.wordpress.org/plugins/hooks/actions/) to understand how they work.
Actions are aplit into two section, `add_action` and `do_action`
`do_action` is the "location" where you hook into it.
A basic example of `do_action`
```
do_act... |
391,799 | <p>I'm coding a plugin. I want to put a Tools menu item on the Network Admin dashboard when the plugin is installed on a multisite WordPress instance.</p>
<p>How do I do that?</p>
| [
{
"answer_id": 392056,
"author": "tiago calado",
"author_id": 198152,
"author_profile": "https://wordpress.stackexchange.com/users/198152",
"pm_score": 0,
"selected": false,
"text": "<p>With this code on functions.php we make a dashboard tab with 3 pages (that should be created on the th... | 2021/07/12 | [
"https://wordpress.stackexchange.com/questions/391799",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13596/"
] | I'm coding a plugin. I want to put a Tools menu item on the Network Admin dashboard when the plugin is installed on a multisite WordPress instance.
How do I do that? | >
> I want to put a Tools menu item on the Network Admin dashboard
>
>
>
If you meant under the core top-level "Dashboard" menu as seen on the following screenshot, then you can use the [`network_admin_menu` hook](https://developer.wordpress.org/reference/hooks/network_admin_menu/) along with [`add_submenu_page()`... |
391,869 | <p>I am creating a theme for my site. I would like to display the last 5 articles on the home page but with a different display for the first articles.
So I created this code that I try to tweak but impossible to display the first article with the first template and the 4 others with the second template. I don't know i... | [
{
"answer_id": 392056,
"author": "tiago calado",
"author_id": 198152,
"author_profile": "https://wordpress.stackexchange.com/users/198152",
"pm_score": 0,
"selected": false,
"text": "<p>With this code on functions.php we make a dashboard tab with 3 pages (that should be created on the th... | 2021/07/13 | [
"https://wordpress.stackexchange.com/questions/391869",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/81397/"
] | I am creating a theme for my site. I would like to display the last 5 articles on the home page but with a different display for the first articles.
So I created this code that I try to tweak but impossible to display the first article with the first template and the 4 others with the second template. I don't know if i... | >
> I want to put a Tools menu item on the Network Admin dashboard
>
>
>
If you meant under the core top-level "Dashboard" menu as seen on the following screenshot, then you can use the [`network_admin_menu` hook](https://developer.wordpress.org/reference/hooks/network_admin_menu/) along with [`add_submenu_page()`... |
391,891 | <p>this is a bit messy and I cannot understand why my approach isn't working or what my error is.</p>
<p>I'm using a <strong>template part</strong> to include a custom <em>wp_query</em> into my theme. I'd like to have two different behaviours throughout the theme, so I'm using a conditional statement inside the templat... | [
{
"answer_id": 392056,
"author": "tiago calado",
"author_id": 198152,
"author_profile": "https://wordpress.stackexchange.com/users/198152",
"pm_score": 0,
"selected": false,
"text": "<p>With this code on functions.php we make a dashboard tab with 3 pages (that should be created on the th... | 2021/07/14 | [
"https://wordpress.stackexchange.com/questions/391891",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/208945/"
] | this is a bit messy and I cannot understand why my approach isn't working or what my error is.
I'm using a **template part** to include a custom *wp\_query* into my theme. I'd like to have two different behaviours throughout the theme, so I'm using a conditional statement inside the template part to output two differe... | >
> I want to put a Tools menu item on the Network Admin dashboard
>
>
>
If you meant under the core top-level "Dashboard" menu as seen on the following screenshot, then you can use the [`network_admin_menu` hook](https://developer.wordpress.org/reference/hooks/network_admin_menu/) along with [`add_submenu_page()`... |
391,893 | <p>I have two custom taxonomies: 'cities', & 'policy'. I'd like to display all the terms from each taxonomy at the bottom of a post, with links. This is what I would use for a single taxonomy - let's say cities:</p>
<p><code>echo get_the_term_list( $post->ID, 'cities', '', ' / ', '' );</code></p>
<p>But I want t... | [
{
"answer_id": 391895,
"author": "Nayan",
"author_id": 95164,
"author_profile": "https://wordpress.stackexchange.com/users/95164",
"pm_score": 2,
"selected": false,
"text": "<pre><code><?php\nwp_get_post_terms($post->ID, array('cities','policy'));\n\nor\nwp_get_object_terms($post-&... | 2021/07/14 | [
"https://wordpress.stackexchange.com/questions/391893",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/208948/"
] | I have two custom taxonomies: 'cities', & 'policy'. I'd like to display all the terms from each taxonomy at the bottom of a post, with links. This is what I would use for a single taxonomy - let's say cities:
`echo get_the_term_list( $post->ID, 'cities', '', ' / ', '' );`
But I want the list to include terms in citie... | ```
<?php
wp_get_post_terms($post->ID, array('cities','policy'));
or
wp_get_object_terms($post->ID, array('cities','policy'));
?>
``` |
391,901 | <p>The error I am getting is:</p>
<p>Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'wptexturize' not found or invalid function name in /home/ifd6vop3yes7/public_html/thematchcandleco.com/wp-includes/class-wp-hook.php on line 294</p>
<p>Warning: call_user_func_array() expects param... | [
{
"answer_id": 391895,
"author": "Nayan",
"author_id": 95164,
"author_profile": "https://wordpress.stackexchange.com/users/95164",
"pm_score": 2,
"selected": false,
"text": "<pre><code><?php\nwp_get_post_terms($post->ID, array('cities','policy'));\n\nor\nwp_get_object_terms($post-&... | 2021/07/14 | [
"https://wordpress.stackexchange.com/questions/391901",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/208952/"
] | The error I am getting is:
Warning: call\_user\_func\_array() expects parameter 1 to be a valid callback, function 'wptexturize' not found or invalid function name in /home/ifd6vop3yes7/public\_html/thematchcandleco.com/wp-includes/class-wp-hook.php on line 294
Warning: call\_user\_func\_array() expects parameter 1 t... | ```
<?php
wp_get_post_terms($post->ID, array('cities','policy'));
or
wp_get_object_terms($post->ID, array('cities','policy'));
?>
``` |
392,060 | <h2 id="background-creating-custom-gutenberg-blocks-and-the-challenges-with-breaking-changes-hh8p">Background: Creating Custom Gutenberg Blocks and the Challenges with Breaking Changes <br></h2>
<p>I am new to creating custom Gutenberg blocks (each block is a separate plugin) and have recently ran into the issue of bre... | [
{
"answer_id": 392175,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 4,
"selected": true,
"text": "<h2 id=\"general-block-name-search\">General block name search</h2>\n<p>One can e.g. use the general search in th... | 2021/07/16 | [
"https://wordpress.stackexchange.com/questions/392060",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/204220/"
] | Background: Creating Custom Gutenberg Blocks and the Challenges with Breaking Changes
-------------------------------------------------------------------------------------
I am new to creating custom Gutenberg blocks (each block is a separate plugin) and have recently ran into the issue of breaking changes when I upda... | General block name search
-------------------------
One can e.g. use the general search in the `/wp-admin` backend to find some text within the post's content that stores the blocks:
[](https://i.stack.imgur.com/w2Ckk.png)
We can search for a prefixed block name `wp:my-plugin/... |
392,065 | <p>I installed wordpress with apt, which ties in a lot of directories, so I suspect that using the built-in core update tool will break the installation; but wordfence constantly demands that I update using said tool -- which is probably much more up-to-date than the linux distro repository. Do I have to wipe it out a... | [
{
"answer_id": 392175,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 4,
"selected": true,
"text": "<h2 id=\"general-block-name-search\">General block name search</h2>\n<p>One can e.g. use the general search in th... | 2021/07/16 | [
"https://wordpress.stackexchange.com/questions/392065",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/209087/"
] | I installed wordpress with apt, which ties in a lot of directories, so I suspect that using the built-in core update tool will break the installation; but wordfence constantly demands that I update using said tool -- which is probably much more up-to-date than the linux distro repository. Do I have to wipe it out and s... | General block name search
-------------------------
One can e.g. use the general search in the `/wp-admin` backend to find some text within the post's content that stores the blocks:
[](https://i.stack.imgur.com/w2Ckk.png)
We can search for a prefixed block name `wp:my-plugin/... |
392,076 | <p>I'm having an issue with one of my meta box. I want the meta box displayed only on the default page template editing <code>page.php</code>.</p>
<p>The meta box doesn't show up on the editing page.</p>
<pre><code>add_action('add_meta_boxes', 'page_add_meta_boxes', 1);
function page_add_meta_boxes() {
global $post;
... | [
{
"answer_id": 392081,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 3,
"selected": true,
"text": "<p>If the "<em>Default Template</em>" option is selected from the Template dropdown, then WordPress ... | 2021/07/17 | [
"https://wordpress.stackexchange.com/questions/392076",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/110282/"
] | I'm having an issue with one of my meta box. I want the meta box displayed only on the default page template editing `page.php`.
The meta box doesn't show up on the editing page.
```
add_action('add_meta_boxes', 'page_add_meta_boxes', 1);
function page_add_meta_boxes() {
global $post;
if(!empty($post)) {
$pag... | If the "*Default Template*" option is selected from the Template dropdown, then WordPress will set the value of the `_wp_page_template` meta to `default` and not `page.php`, so that's most likely the reason why your meta box is not showing/added.
So I would use `if ( in_array( $pageTemplate, array( 'default', 'page.ph... |
392,125 | <p>I would like to override the default post archives, via category.</p>
<p>In some cases (not all), I have 2 level-categories, such as:</p>
<p>Parent Category: "Video"</p>
<ul>
<li>Subcategory "Comedy"</li>
<li>Subcategory "Action"</li>
</ul>
<p>But some other categories, are just single-... | [
{
"answer_id": 392712,
"author": "HEN",
"author_id": 209650,
"author_profile": "https://wordpress.stackexchange.com/users/209650",
"pm_score": 0,
"selected": false,
"text": "<p>You can try something like this:</p>\n<p>It checks, if category has parent</p>\n<pre><code><?php if ( have_p... | 2021/07/18 | [
"https://wordpress.stackexchange.com/questions/392125",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/78146/"
] | I would like to override the default post archives, via category.
In some cases (not all), I have 2 level-categories, such as:
Parent Category: "Video"
* Subcategory "Comedy"
* Subcategory "Action"
But some other categories, are just single-level.
Currently, no matter which category you choose, you get a list of p... | In your Avada's child theme update your category.php, if its there or else
create new file with that name and add the code as below:
```
<?php
$current_cat = get_queried_object();
echo 'Heading: '.$current_cat->name;
$subcategories = get_categories(
array( 'parent' => $current_cat->term_id )
);
if(!empty($subcat... |
392,240 | <p>I want to use two <code>meta_compare</code> in an array.</p>
<pre><code>// get posts
$posts = get_posts(array(
'post_type' => 'post',
'posts_per_page' => 150,
'meta_query' => array(
array(
'meta_key' => 'usp-custom-1',
'meta_value' => array('q... | [
{
"answer_id": 392243,
"author": "Buttered_Toast",
"author_id": 192133,
"author_profile": "https://wordpress.stackexchange.com/users/192133",
"pm_score": 2,
"selected": true,
"text": "<p>Ok so this way is a bit long but it will get the job done.</p>\n<p>We can use multiple meta_value che... | 2021/07/21 | [
"https://wordpress.stackexchange.com/questions/392240",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/202740/"
] | I want to use two `meta_compare` in an array.
```
// get posts
$posts = get_posts(array(
'post_type' => 'post',
'posts_per_page' => 150,
'meta_query' => array(
array(
'meta_key' => 'usp-custom-1',
'meta_value' => array('question','money', 'health','relationshi... | Ok so this way is a bit long but it will get the job done.
We can use multiple meta\_value checks with AND relation
```
// get posts
$posts = get_posts(array(
'post_type' => 'post',
'posts_per_page' => 150,
'meta_query' => array(
'relation' => 'AND',
array(
'key' =... |
392,258 | <p>I am working on my first plugin that adds a external script to the footer. Wordpress automatically adds the version number at the end, which I'm trying to remove. What I have so far:</p>
<pre><code>add_action('wp_enqueue_scripts', array($this,'print_code'));
public function print_code(){
$location... | [
{
"answer_id": 392243,
"author": "Buttered_Toast",
"author_id": 192133,
"author_profile": "https://wordpress.stackexchange.com/users/192133",
"pm_score": 2,
"selected": true,
"text": "<p>Ok so this way is a bit long but it will get the job done.</p>\n<p>We can use multiple meta_value che... | 2021/07/21 | [
"https://wordpress.stackexchange.com/questions/392258",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/135201/"
] | I am working on my first plugin that adds a external script to the footer. Wordpress automatically adds the version number at the end, which I'm trying to remove. What I have so far:
```
add_action('wp_enqueue_scripts', array($this,'print_code'));
public function print_code(){
$location = get_option('loc... | Ok so this way is a bit long but it will get the job done.
We can use multiple meta\_value checks with AND relation
```
// get posts
$posts = get_posts(array(
'post_type' => 'post',
'posts_per_page' => 150,
'meta_query' => array(
'relation' => 'AND',
array(
'key' =... |
392,274 | <p><strong>The Objective:</strong>
Create a custom post type and only give administrator and a custom role permission to view / control it.</p>
<p><strong>The Problem:</strong>
For administrators, it works perfectly fine but for the custom role I get:
<code>Sorry, you are not allowed to access this page.</code></p>
<p>... | [
{
"answer_id": 392293,
"author": "Anjan",
"author_id": 206231,
"author_profile": "https://wordpress.stackexchange.com/users/206231",
"pm_score": 0,
"selected": false,
"text": "<p>After your custom post registration complete use below type code it will help you as reference.</p>\n<pre><co... | 2021/07/21 | [
"https://wordpress.stackexchange.com/questions/392274",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/209263/"
] | **The Objective:**
Create a custom post type and only give administrator and a custom role permission to view / control it.
**The Problem:**
For administrators, it works perfectly fine but for the custom role I get:
`Sorry, you are not allowed to access this page.`
At first, I thought it could just be a matter of cap... | **SOLUTION:**
With some playing around I realized I am definitely an idiot and WAY over-thought things. While I had previously read and tried some of the things in [this similar post](https://wordpress.stackexchange.com/questions/299859/custom-post-type-role-permissions-wont-let-me-read), I ended up substituting their ... |
392,281 | <p>I do not have a lot of coding knowledge. How do I add a WordPress searching database shortcode to the frontend using the metavalue as if I were to search for "demo", the metavalue(named as serial) will display the database that has the word "demo". The furthest I can go is displaying all the valu... | [
{
"answer_id": 392293,
"author": "Anjan",
"author_id": 206231,
"author_profile": "https://wordpress.stackexchange.com/users/206231",
"pm_score": 0,
"selected": false,
"text": "<p>After your custom post registration complete use below type code it will help you as reference.</p>\n<pre><co... | 2021/07/22 | [
"https://wordpress.stackexchange.com/questions/392281",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/208729/"
] | I do not have a lot of coding knowledge. How do I add a WordPress searching database shortcode to the frontend using the metavalue as if I were to search for "demo", the metavalue(named as serial) will display the database that has the word "demo". The furthest I can go is displaying all the values from selecting the t... | **SOLUTION:**
With some playing around I realized I am definitely an idiot and WAY over-thought things. While I had previously read and tried some of the things in [this similar post](https://wordpress.stackexchange.com/questions/299859/custom-post-type-role-permissions-wont-let-me-read), I ended up substituting their ... |
392,379 | <p>Can't seem to find any valuable info on this at the moment - I just want to resize the height of the classic editor field for my Custom Post types.</p>
<p>I was hoping to just drop a function or code snippet into functions.php for this, if possible?</p>
<p>In this example I would have 3 Custom Post types: 'Tools', '... | [
{
"answer_id": 392384,
"author": "Den Isahac",
"author_id": 113233,
"author_profile": "https://wordpress.stackexchange.com/users/113233",
"pm_score": 1,
"selected": false,
"text": "<p>You can insert custom style in the WP admin section via <code>admin_head</code> action hook.</p>\n<pre><... | 2021/07/23 | [
"https://wordpress.stackexchange.com/questions/392379",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/207077/"
] | Can't seem to find any valuable info on this at the moment - I just want to resize the height of the classic editor field for my Custom Post types.
I was hoping to just drop a function or code snippet into functions.php for this, if possible?
In this example I would have 3 Custom Post types: 'Tools', 'Brand' and 'Com... | One way is to adjust the TinyMCE [settings](https://stackoverflow.com/a/12382735/2078474):
```
add_filter( 'tiny_mce_before_init', function( $settings ) {
$settings['height'] = '120';
$settings['autoresize_max_height'] = '120';
return $settings;
} );
```
and e.g. restrict further on post types and !bl... |
392,386 | <p>I am working on a plugin where a new page template is created on plugin activation. The template has a form for user input.</p>
<pre><code><form action="" method="post">
<textarea name="question"></textarea>
<input type="submit" name="submit_q... | [
{
"answer_id": 392388,
"author": "Ricardo Cruz",
"author_id": 209357,
"author_profile": "https://wordpress.stackexchange.com/users/209357",
"pm_score": 1,
"selected": false,
"text": "<p>Did you try to <code>exit;</code> after the <code>wp_redirect()</code>?</p>\n<p>“Note: wp_redirect() d... | 2021/07/23 | [
"https://wordpress.stackexchange.com/questions/392386",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/209353/"
] | I am working on a plugin where a new page template is created on plugin activation. The template has a form for user input.
```
<form action="" method="post">
<textarea name="question"></textarea>
<input type="submit" name="submit_question">
</form>
```
Value is properly stored in following way:
```
if ( is... | Did you try to `exit;` after the `wp_redirect()`?
“Note: wp\_redirect() does not exit automatically, and should almost always be followed by a call to exit;”
<https://developer.wordpress.org/reference/functions/wp_redirect/> |
392,406 | <p>I'm building my first Gutenberg block and the problem that I have is that the block control toolbar doesn't show.
I've spend hours comparing my code with other Gutenberg blocks, but couldn't find what is wrong in my code.
I would highly appreciate if someone could look at my code and advice.</p>
<p>Here is my code:<... | [
{
"answer_id": 392407,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 2,
"selected": false,
"text": "<p>Your <code>edit</code> function is just missing a <code>[</code> and <code>]</code>, i.e. you forgot to ac... | 2021/07/24 | [
"https://wordpress.stackexchange.com/questions/392406",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/209385/"
] | I'm building my first Gutenberg block and the problem that I have is that the block control toolbar doesn't show.
I've spend hours comparing my code with other Gutenberg blocks, but couldn't find what is wrong in my code.
I would highly appreciate if someone could look at my code and advice.
Here is my code:
```js
im... | Your `edit` function is just missing a `[` and `]`, i.e. you forgot to actually return an *array*, like so:
```js
return ([ // add that [
<InspectorControls key="lx-authors-block-setting" style={ { marginBottom:'40px'} }>
...
</InspectorControls>,
<div className="lx-authors-block wp-block" key="con... |
392,598 | <p>I have a simple WP_Query that displays posts:</p>
<pre><code><?php
function vertical_posts( $title, $category, $num_of_posts ) { ?>
<section class="vertical-posts">
<h2 class="title"><?php echo $title; ?></h2>
<div class="post-grid"&g... | [
{
"answer_id": 392439,
"author": "Buttered_Toast",
"author_id": 192133,
"author_profile": "https://wordpress.stackexchange.com/users/192133",
"pm_score": -1,
"selected": false,
"text": "<p>Have you tried any of the things you mentioned? doesn't seem like that big of a hassle to test it?<... | 2021/07/28 | [
"https://wordpress.stackexchange.com/questions/392598",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/37548/"
] | I have a simple WP\_Query that displays posts:
```
<?php
function vertical_posts( $title, $category, $num_of_posts ) { ?>
<section class="vertical-posts">
<h2 class="title"><?php echo $title; ?></h2>
<div class="post-grid">
<?php
$args = array('category_name' => $category, ... | By running `unregister_post_type()` custom posts are not deleted from database even they can be retrieved by custom query. They mustn't be appear in regular post loop since their `post_type` remain what was. |
392,659 | <p>One of the stores I manage is currently facing a <a href="https://github.com/woocommerce/woocommerce/issues/24184" rel="nofollow noreferrer">bug</a> that is not solved yet by WooCommerce, regarding rounding prices introduced without tax. So far one of the temp fixes that work is changing the whole store to 4 decimal... | [
{
"answer_id": 392439,
"author": "Buttered_Toast",
"author_id": 192133,
"author_profile": "https://wordpress.stackexchange.com/users/192133",
"pm_score": -1,
"selected": false,
"text": "<p>Have you tried any of the things you mentioned? doesn't seem like that big of a hassle to test it?<... | 2021/07/30 | [
"https://wordpress.stackexchange.com/questions/392659",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94417/"
] | One of the stores I manage is currently facing a [bug](https://github.com/woocommerce/woocommerce/issues/24184) that is not solved yet by WooCommerce, regarding rounding prices introduced without tax. So far one of the temp fixes that work is changing the whole store to 4 decimals to improve accuracy. Now the problem i... | By running `unregister_post_type()` custom posts are not deleted from database even they can be retrieved by custom query. They mustn't be appear in regular post loop since their `post_type` remain what was. |
392,723 | <p>how can I add an extra admin column with the Status of posts like Below Image. i know admin column plugin for this work but i don't want to use any plugin..so please suggest me if there any code to add an extra admin column with the Post Status</p>
<p><a href="https://i.stack.imgur.com/NtAbn.png" rel="nofollow noref... | [
{
"answer_id": 392736,
"author": "Kiriakos Grhgoriadhs",
"author_id": 209669,
"author_profile": "https://wordpress.stackexchange.com/users/209669",
"pm_score": 0,
"selected": false,
"text": "<p>This is the simplest use of adding custom columns:</p>\n<pre><code>// Add the custom columns t... | 2021/07/31 | [
"https://wordpress.stackexchange.com/questions/392723",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/202431/"
] | how can I add an extra admin column with the Status of posts like Below Image. i know admin column plugin for this work but i don't want to use any plugin..so please suggest me if there any code to add an extra admin column with the Post Status
[](https://i.stack.imgu... | The last function doesn't work. Use this instead to fill the status column:
```
// Add the data to the post columns:
add_action( 'manage_post_posts_custom_column' , 'custom_post_column', 10, 2 );
function custom_post_column( $column, $post_id ) {
if ( $column == "status" ) {
echo get_post_status($post_id);... |
392,824 | <p>We are converting our static HTML site to Wordpress. The conversion is going fine (for the most part) but the part I cannot figure out is how to build the menu so that I can retain the menu look from our HTML site (see graphic for the specific menu I'm referring too).</p>
<p>Original Site: <a href="http://humanetomo... | [
{
"answer_id": 392826,
"author": "challenge2022",
"author_id": 192901,
"author_profile": "https://wordpress.stackexchange.com/users/192901",
"pm_score": 0,
"selected": false,
"text": "<p>that header style is just a background image, rather than an actual css style.</p>\n<p>you could appl... | 2021/08/03 | [
"https://wordpress.stackexchange.com/questions/392824",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/85973/"
] | We are converting our static HTML site to Wordpress. The conversion is going fine (for the most part) but the part I cannot figure out is how to build the menu so that I can retain the menu look from our HTML site (see graphic for the specific menu I'm referring too).
Original Site: <http://humanetomorrow.org/>
[![ent... | Lookup `wp_nav_menu`
Simply take the HTML you have now and remove the `<ul>` or whatever elements you are using to list the menu links. If you want it to be dynamic, your theme template will need something similar to the following placed where you want the links to load in place of what you had in your regular HTML si... |
392,827 | <p>I want to create a site, where a normal user only is able to access the frontend.
So there is no admin bar and everytime, they try to visit the admin area, they are just redirected to the frontpage.</p>
<p>I tried to use something like:</p>
<pre class="lang-php prettyprint-override"><code>function redirect_non_admin... | [
{
"answer_id": 392826,
"author": "challenge2022",
"author_id": 192901,
"author_profile": "https://wordpress.stackexchange.com/users/192901",
"pm_score": 0,
"selected": false,
"text": "<p>that header style is just a background image, rather than an actual css style.</p>\n<p>you could appl... | 2021/08/03 | [
"https://wordpress.stackexchange.com/questions/392827",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56601/"
] | I want to create a site, where a normal user only is able to access the frontend.
So there is no admin bar and everytime, they try to visit the admin area, they are just redirected to the frontpage.
I tried to use something like:
```php
function redirect_non_admin_user(){
if ( is_user_logged_in() && !current_user... | Lookup `wp_nav_menu`
Simply take the HTML you have now and remove the `<ul>` or whatever elements you are using to list the menu links. If you want it to be dynamic, your theme template will need something similar to the following placed where you want the links to load in place of what you had in your regular HTML si... |
392,838 | <p>Currently i used this code to hide 1.Status 2.Visibility and 3.Published option from Publish box but these code is not working on my wordpress version 5.8..please help me to solve this problem</p>
<pre><code> function hide_publishing_actions(){
global $post;
if($pagenow == post.php){
echo '
... | [
{
"answer_id": 392826,
"author": "challenge2022",
"author_id": 192901,
"author_profile": "https://wordpress.stackexchange.com/users/192901",
"pm_score": 0,
"selected": false,
"text": "<p>that header style is just a background image, rather than an actual css style.</p>\n<p>you could appl... | 2021/08/03 | [
"https://wordpress.stackexchange.com/questions/392838",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/202431/"
] | Currently i used this code to hide 1.Status 2.Visibility and 3.Published option from Publish box but these code is not working on my wordpress version 5.8..please help me to solve this problem
```
function hide_publishing_actions(){
global $post;
if($pagenow == post.php){
echo '
<style typ... | Lookup `wp_nav_menu`
Simply take the HTML you have now and remove the `<ul>` or whatever elements you are using to list the menu links. If you want it to be dynamic, your theme template will need something similar to the following placed where you want the links to load in place of what you had in your regular HTML si... |
392,867 | <p>i have moved my website to another server and changed the domain name, then i installed an SSL certificate, and when i change my website form http to https in wp-options and wp-config and also set a redirection to https in .htaccess my website didn't work only if i use <a href="http://mywebsite.com" rel="nofollow no... | [
{
"answer_id": 392871,
"author": "VKS",
"author_id": 120224,
"author_profile": "https://wordpress.stackexchange.com/users/120224",
"pm_score": 1,
"selected": false,
"text": "<p>Add this code in to wp-config.php just before - <strong>require_once ABSPATH . 'wp-settings.php';</strong> line... | 2021/08/04 | [
"https://wordpress.stackexchange.com/questions/392867",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/209797/"
] | i have moved my website to another server and changed the domain name, then i installed an SSL certificate, and when i change my website form http to https in wp-options and wp-config and also set a redirection to https in .htaccess my website didn't work only if i use <http://mywebsite.com>
and when i change the http... | Add this code in to wp-config.php just before - **require\_once ABSPATH . 'wp-settings.php';** line
```
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';
``` |
393,004 | <p>Is there a way to fetch the <strong>ALT/TITLE</strong> of ALL images in the media gallery?</p>
<p>I think this would be an easy way for a website to have a Pictures page that just pulls all of the images from the media gallery, granted it would only be necessary in certain scenarios.</p>
<p>I don't need instruction... | [
{
"answer_id": 392871,
"author": "VKS",
"author_id": 120224,
"author_profile": "https://wordpress.stackexchange.com/users/120224",
"pm_score": 1,
"selected": false,
"text": "<p>Add this code in to wp-config.php just before - <strong>require_once ABSPATH . 'wp-settings.php';</strong> line... | 2021/08/07 | [
"https://wordpress.stackexchange.com/questions/393004",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/178422/"
] | Is there a way to fetch the **ALT/TITLE** of ALL images in the media gallery?
I think this would be an easy way for a website to have a Pictures page that just pulls all of the images from the media gallery, granted it would only be necessary in certain scenarios.
I don't need instructions on how to create a Pictures... | Add this code in to wp-config.php just before - **require\_once ABSPATH . 'wp-settings.php';** line
```
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';
``` |
393,044 | <p>I am using an unusual setup to host 3 Wordpress installations on CentOS 8 Linux.</p>
<p>In front I have HAProxy (to offload TLS), then I have <a href="https://www.eclipse.org/jetty/documentation/jetty-9/index.html#configuring-fastcgi" rel="nofollow noreferrer">Jetty configured for FastCGI</a> and php-fpm and finally... | [
{
"answer_id": 392871,
"author": "VKS",
"author_id": 120224,
"author_profile": "https://wordpress.stackexchange.com/users/120224",
"pm_score": 1,
"selected": false,
"text": "<p>Add this code in to wp-config.php just before - <strong>require_once ABSPATH . 'wp-settings.php';</strong> line... | 2021/08/08 | [
"https://wordpress.stackexchange.com/questions/393044",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/41372/"
] | I am using an unusual setup to host 3 Wordpress installations on CentOS 8 Linux.
In front I have HAProxy (to offload TLS), then I have [Jetty configured for FastCGI](https://www.eclipse.org/jetty/documentation/jetty-9/index.html#configuring-fastcgi) and php-fpm and finally Wordpress.
I am using the Wordpress around a... | Add this code in to wp-config.php just before - **require\_once ABSPATH . 'wp-settings.php';** line
```
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';
``` |
393,083 | <p>I know that WordPress v5.8 has just been released and I have started using the <code>theme.json</code> for managing some basic stuffs on the Gutenberg side. But as I have started using it, I have seen a couple of things:</p>
<p>The custom internal CSS added by WordPress after compiling the <code>theme.json</code> fi... | [
{
"answer_id": 392871,
"author": "VKS",
"author_id": 120224,
"author_profile": "https://wordpress.stackexchange.com/users/120224",
"pm_score": 1,
"selected": false,
"text": "<p>Add this code in to wp-config.php just before - <strong>require_once ABSPATH . 'wp-settings.php';</strong> line... | 2021/08/09 | [
"https://wordpress.stackexchange.com/questions/393083",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/50584/"
] | I know that WordPress v5.8 has just been released and I have started using the `theme.json` for managing some basic stuffs on the Gutenberg side. But as I have started using it, I have seen a couple of things:
The custom internal CSS added by WordPress after compiling the `theme.json` file to each and every page. Does... | Add this code in to wp-config.php just before - **require\_once ABSPATH . 'wp-settings.php';** line
```
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';
``` |
393,094 | <p>I have a project that contains a button supposed to generate get a link to a random Custom Post item.</p>
<p>I made my Custom Query as follow:</p>
<pre><code><div class="content">
<?php
$argsRandItem = array(
'post_type' => 'participant',
... | [
{
"answer_id": 392871,
"author": "VKS",
"author_id": 120224,
"author_profile": "https://wordpress.stackexchange.com/users/120224",
"pm_score": 1,
"selected": false,
"text": "<p>Add this code in to wp-config.php just before - <strong>require_once ABSPATH . 'wp-settings.php';</strong> line... | 2021/08/09 | [
"https://wordpress.stackexchange.com/questions/393094",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/210005/"
] | I have a project that contains a button supposed to generate get a link to a random Custom Post item.
I made my Custom Query as follow:
```
<div class="content">
<?php
$argsRandItem = array(
'post_type' => 'participant',
'posts_per_page' => 1,
... | Add this code in to wp-config.php just before - **require\_once ABSPATH . 'wp-settings.php';** line
```
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';
``` |
393,095 | <p>I'm trying to <strong>prevent moderation of forum posts</strong> for users with the 'moderate' capability OR an active 'premium' membership plan (WC Memberships).</p>
<p>I want replies from such authors to <em>not</em> be subject to our moderation rules (number of links, blocklisted words, etc.).</p>
<p>I've tried u... | [
{
"answer_id": 392871,
"author": "VKS",
"author_id": 120224,
"author_profile": "https://wordpress.stackexchange.com/users/120224",
"pm_score": 1,
"selected": false,
"text": "<p>Add this code in to wp-config.php just before - <strong>require_once ABSPATH . 'wp-settings.php';</strong> line... | 2021/08/09 | [
"https://wordpress.stackexchange.com/questions/393095",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129862/"
] | I'm trying to **prevent moderation of forum posts** for users with the 'moderate' capability OR an active 'premium' membership plan (WC Memberships).
I want replies from such authors to *not* be subject to our moderation rules (number of links, blocklisted words, etc.).
I've tried using the following filters with no ... | Add this code in to wp-config.php just before - **require\_once ABSPATH . 'wp-settings.php';** line
```
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';
``` |
393,144 | <p>I am searching for a good solution in which i can develop a wordpress site on my localhost and push the changes i made easily to my live server.</p>
<p>The idea is that i have some kind of plugin/software in which i just enter database and ftp credentials and i can just press "Push changes" and the changes... | [
{
"answer_id": 392871,
"author": "VKS",
"author_id": 120224,
"author_profile": "https://wordpress.stackexchange.com/users/120224",
"pm_score": 1,
"selected": false,
"text": "<p>Add this code in to wp-config.php just before - <strong>require_once ABSPATH . 'wp-settings.php';</strong> line... | 2021/08/11 | [
"https://wordpress.stackexchange.com/questions/393144",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/122013/"
] | I am searching for a good solution in which i can develop a wordpress site on my localhost and push the changes i made easily to my live server.
The idea is that i have some kind of plugin/software in which i just enter database and ftp credentials and i can just press "Push changes" and the changes get pushed from my... | Add this code in to wp-config.php just before - **require\_once ABSPATH . 'wp-settings.php';** line
```
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';
``` |
393,175 | <p>I developed several plugins which I localized using the standard approach with <code>__()</code> functions and the <code>.po</code> or rather the <code>.mo</code> files. All of this works like a charm.</p>
<p>What I now want to be able to do is set the locale for a function call of <code>__()</code>, to retrieve the... | [
{
"answer_id": 393178,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 1,
"selected": false,
"text": "<blockquote>\n<p>What I now want to be able to do is set the locale for a function call\nof <code>__()</code>... | 2021/08/11 | [
"https://wordpress.stackexchange.com/questions/393175",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/188571/"
] | I developed several plugins which I localized using the standard approach with `__()` functions and the `.po` or rather the `.mo` files. All of this works like a charm.
What I now want to be able to do is set the locale for a function call of `__()`, to retrieve the translation you defined on your plugin's `.mo` for a... | >
> What I now want to be able to do is set the locale for a function call
> of `__()`, to retrieve the translation you defined on your plugin's
> `.mo` for a translation which is different from the current locale.
>
>
>
>
> I'd prefer my translations to be translated all in the same way, using
> the same logic p... |
393,189 | <p>I'm used to creating custom shortcodes through my child theme and Elementor, never a problem.</p>
<p>However this time something is wrong, when I inserted the shortcode widget in Elementor editor my code is correctly showing, but after saving I visit the page, its blank, like the shortcode was never processed.</p>
<... | [
{
"answer_id": 393192,
"author": "Buttered_Toast",
"author_id": 192133,
"author_profile": "https://wordpress.stackexchange.com/users/192133",
"pm_score": 1,
"selected": false,
"text": "<p>The problem is with the <code>require_once</code>, you are passing a relative path and that path doe... | 2021/08/12 | [
"https://wordpress.stackexchange.com/questions/393189",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/210103/"
] | I'm used to creating custom shortcodes through my child theme and Elementor, never a problem.
However this time something is wrong, when I inserted the shortcode widget in Elementor editor my code is correctly showing, but after saving I visit the page, its blank, like the shortcode was never processed.
Anyone have a... | The problem is with the `require_once`, you are passing a relative path and that path doesn't exist.
Assuming the `test.php` file you want to require is in this path
`wp-content/themes/your-theme/views/test.php`
You can use the following
```php
require_once locate_template('views/test.php');
```
Consider using `i... |
393,237 | <p>I would like my website to point any URL</p>
<pre><code>website.com/about/
website.com/about/more/
</code></pre>
<p>to the homepage. However, I would also like to maintain the URL in the browser URL bar.</p>
<p>How can I achieve this?</p>
<p>A redirect can be achieved with</p>
<pre><code>RewriteRule .* / [L,R=301]
<... | [
{
"answer_id": 393192,
"author": "Buttered_Toast",
"author_id": 192133,
"author_profile": "https://wordpress.stackexchange.com/users/192133",
"pm_score": 1,
"selected": false,
"text": "<p>The problem is with the <code>require_once</code>, you are passing a relative path and that path doe... | 2021/08/13 | [
"https://wordpress.stackexchange.com/questions/393237",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/210135/"
] | I would like my website to point any URL
```
website.com/about/
website.com/about/more/
```
to the homepage. However, I would also like to maintain the URL in the browser URL bar.
How can I achieve this?
A redirect can be achieved with
```
RewriteRule .* / [L,R=301]
```
I have tried with
```
RewriteRule .* / [... | The problem is with the `require_once`, you are passing a relative path and that path doesn't exist.
Assuming the `test.php` file you want to require is in this path
`wp-content/themes/your-theme/views/test.php`
You can use the following
```php
require_once locate_template('views/test.php');
```
Consider using `i... |
393,260 | <p>I found a major bug inside our custom plugin, we simply adding the new rules and flushing the existing rewrite_rules on every page load("add_action('wp_loaded', 'flush_rules')"), which seems not a good practice. I am curious to know if there is any way to check the different between the existing rewrite_ru... | [
{
"answer_id": 393270,
"author": "JCV",
"author_id": 206323,
"author_profile": "https://wordpress.stackexchange.com/users/206323",
"pm_score": 0,
"selected": false,
"text": "<p>You could add a flush rewrite only upon submitting a form:</p>\n<pre><code>if ( (isset($_POST['update_myform'])... | 2021/08/13 | [
"https://wordpress.stackexchange.com/questions/393260",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/173772/"
] | I found a major bug inside our custom plugin, we simply adding the new rules and flushing the existing rewrite\_rules on every page load("add\_action('wp\_loaded', 'flush\_rules')"), which seems not a good practice. I am curious to know if there is any way to check the different between the existing rewrite\_rules(alre... | Here's the trick I've been using:
* Use an array to store the rewrites
* Hash the array
* Store the hashed array as an option
* Check to see if the stored option matches the curret rewrite hash; if not, update the rewrites
Greatly simplified code snippet (this is meant as a starting point, not a finished product):
`... |