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 |
|---|---|---|---|---|---|---|
406,131 | <p>Custom quicktags not working after Wordpress 6.0</p>
<p>wp 5.8.x/5.9.x: working --
wp 6.0: not working</p>
<p>Buttons are not showing here: <a href="https://imgur.com/a/T05o0WX" rel="nofollow noreferrer">https://imgur.com/a/T05o0WX</a></p>
<p>Console error: Uncaught ReferenceError: QTags is not defined</p>
<p>I am u... | [
{
"answer_id": 406152,
"author": "Nick R.",
"author_id": 222590,
"author_profile": "https://wordpress.stackexchange.com/users/222590",
"pm_score": 2,
"selected": false,
"text": "<p>I had the same problem. I fixed it by using the ep_enqueue_script aproach shown here: <a href=\"https://cod... | 2022/05/26 | [
"https://wordpress.stackexchange.com/questions/406131",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/130775/"
] | Custom quicktags not working after Wordpress 6.0
wp 5.8.x/5.9.x: working --
wp 6.0: not working
Buttons are not showing here: <https://imgur.com/a/T05o0WX>
Console error: Uncaught ReferenceError: QTags is not defined
I am using this code.
```
function my_quicktags() {
if ( wp_script_is( 'quicktags' ) ) {
... | I had the same problem. I fixed it by using the ep\_enqueue\_script aproach shown here: <https://codex.wordpress.org/Quicktags_API> listed under "A more modern example".
It's the same thing that Tom mentions. Instead of using 'admin\_print\_fotter\_scripts' to write an inline script on the page, the example shows putt... |
406,260 | <p>/wp-includes/class-wp-widget.php gives me an error for one blog, but not the other, and both have the same version of class-wp-widget.php which makes no sense to me.</p>
<blockquote>
<p>PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to
function WP_Widget::__construct(), 0 passed in
/home/www/stacke... | [
{
"answer_id": 406263,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 0,
"selected": false,
"text": "<p>I suspect the cause is a custom widget that has been built incorrectly. Take a look at this example from the... | 2022/05/30 | [
"https://wordpress.stackexchange.com/questions/406260",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3453/"
] | /wp-includes/class-wp-widget.php gives me an error for one blog, but not the other, and both have the same version of class-wp-widget.php which makes no sense to me.
>
> PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to
> function WP\_Widget::\_\_construct(), 0 passed in
> /home/www/stackexchange.com... | In case you couldn’t revert to PHP older than 8.1 or fix the widget registration (and you trust your 10+ years old theme), you can update the line 61 of `wp-includes/class-wp-widget-factory.php` this way :
```
$this->widgets[ $widget ] = new $widget( $widget, $widget );
```
This may fix the widget registration. |
406,490 | <p>The problem:</p>
<p>I want to run Wordpress 6.x with PHP 8.x in development mode - meaning <code>define('WP_DEBUG', true);</code> but Wordpress 6.x <a href="https://make.wordpress.org/core/handbook/references/php-compatibility-and-wordpress-versions/" rel="nofollow noreferrer">partial support for PHP 8.x</a> throws ... | [
{
"answer_id": 406491,
"author": "Picard",
"author_id": 118566,
"author_profile": "https://wordpress.stackexchange.com/users/118566",
"pm_score": 2,
"selected": false,
"text": "<p>The key to the solution is <code>enable_wp_debug_mode_checks</code> filter but to use it you have to do some... | 2022/06/07 | [
"https://wordpress.stackexchange.com/questions/406490",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/118566/"
] | The problem:
I want to run Wordpress 6.x with PHP 8.x in development mode - meaning `define('WP_DEBUG', true);` but Wordpress 6.x [partial support for PHP 8.x](https://make.wordpress.org/core/handbook/references/php-compatibility-and-wordpress-versions/) throws a lot of deprecated warnings which do a lot of mess on th... | The key to the solution is `enable_wp_debug_mode_checks` filter but to use it you have to do something special.
As the [documentation](https://developer.wordpress.org/reference/hooks/enable_wp_debug_mode_checks/) says:
>
> This filter runs before it can be used by plugins. It is designed for
> non-web runtimes. Retu... |
406,541 | <p>I am using the following filter to select <code><a></code> tags from a specific menu that have no attributes (href, class, etc.) and replace them with <code><button></code> tags.</p>
<pre><code>add_filter( 'wp_nav_menu_items', 'filter_empty_anchor_items', 10, 2 );
function filter_empty_anchor_items( $ite... | [
{
"answer_id": 406548,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 1,
"selected": false,
"text": "<p>Just use <code>link_before</code> in your <code>wp_nav_menu</code> <code>$args</code> and add opening/clos... | 2022/06/08 | [
"https://wordpress.stackexchange.com/questions/406541",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/20357/"
] | I am using the following filter to select `<a>` tags from a specific menu that have no attributes (href, class, etc.) and replace them with `<button>` tags.
```
add_filter( 'wp_nav_menu_items', 'filter_empty_anchor_items', 10, 2 );
function filter_empty_anchor_items( $items, $args ) {
if( $args->theme_location == 'w... | Just use `link_before` in your `wp_nav_menu` `$args` and add opening/closing span tags:
```
$args = [
'link_before' => '<span>',
/* Add closing </span> to link_after */
'link_after' => '</span><svg>...</svg>',
// Other args
];
``` |
406,607 | <p>When I add 'author' I only get results from "post" but no results are received from the "my_post_type_name"
My code:</p>
<pre><code>$args = array(
'author' => $user_id,
'post_type' => array('my_post_type_name', 'post'),
);
$wp_query = new WP_Query( $args );
</code></pre... | [
{
"answer_id": 406548,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 1,
"selected": false,
"text": "<p>Just use <code>link_before</code> in your <code>wp_nav_menu</code> <code>$args</code> and add opening/clos... | 2022/06/09 | [
"https://wordpress.stackexchange.com/questions/406607",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/223011/"
] | When I add 'author' I only get results from "post" but no results are received from the "my\_post\_type\_name"
My code:
```
$args = array(
'author' => $user_id,
'post_type' => array('my_post_type_name', 'post'),
);
$wp_query = new WP_Query( $args );
```
Is it possible? Or do I need two query? | Just use `link_before` in your `wp_nav_menu` `$args` and add opening/closing span tags:
```
$args = [
'link_before' => '<span>',
/* Add closing </span> to link_after */
'link_after' => '</span><svg>...</svg>',
// Other args
];
``` |
406,640 | <p>I am trying to remove some script files added by wordpress. However, the code I wrote does not work. Where am I doing wrong? Can you show me the way?</p>
<p>I looked at many sources. But I couldn't find an answer for the ui. I have used the wp_dequeue_script function many times. But it doesn't work for Wordpress.</p... | [
{
"answer_id": 406645,
"author": "Community",
"author_id": -1,
"author_profile": "https://wordpress.stackexchange.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "<p>The related library is registered with a function called <a href=\"https://developer.wordpress.org/reference/func... | 2022/06/10 | [
"https://wordpress.stackexchange.com/questions/406640",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | I am trying to remove some script files added by wordpress. However, the code I wrote does not work. Where am I doing wrong? Can you show me the way?
I looked at many sources. But I couldn't find an answer for the ui. I have used the wp\_dequeue\_script function many times. But it doesn't work for Wordpress.
child th... | The related library is registered with a function called [wp\_default\_scripts](https://developer.wordpress.org/reference/functions/wp_default_scripts/).
File location (for Wordpress 6.0): **...[wp-includes/script-loader.php](https://github.com/WordPress/WordPress/blob/df0d9100070579ef83b4acd0db865232d4a0e58a/wp-includ... |
406,644 | <p>I have a template that adds a shortcode. The add_shortcode is at the top of the template, before any template output. Note that any attributes for the shortcode are optional. I don't care if they exist or not. I will just test for the attribute values and do something if they exist.</p>
<p>When are the shortcode att... | [
{
"answer_id": 406647,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 1,
"selected": false,
"text": "<blockquote>\n<p>I need access to the shortcode attributes <strong>before</strong> the content (and\nit's sho... | 2022/06/10 | [
"https://wordpress.stackexchange.com/questions/406644",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/29416/"
] | I have a template that adds a shortcode. The add\_shortcode is at the top of the template, before any template output. Note that any attributes for the shortcode are optional. I don't care if they exist or not. I will just test for the attribute values and do something if they exist.
When are the shortcode attributes ... | The answer from @SallyCJ got me started on the solution that worked best for me. It uses some of her code. There are references to other resources that helped out.
```
function my_get_shortcode_atts($shortcode_id) {
/* given the $shortcode_id you are looking for, find it in the content
before the loop
returns... |
406,687 | <p><strong>Hello</strong>, I have this code so when I place the <strong>[need_login]</strong> shortcode on a page, it redirects users who are not logged in to a <strong>Login page</strong>. The problem with this is the that it redirects them to the default WordPress page. How can I add the <strong>url</strong> of the p... | [
{
"answer_id": 406647,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 1,
"selected": false,
"text": "<blockquote>\n<p>I need access to the shortcode attributes <strong>before</strong> the content (and\nit's sho... | 2022/06/12 | [
"https://wordpress.stackexchange.com/questions/406687",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/223078/"
] | **Hello**, I have this code so when I place the **[need\_login]** shortcode on a page, it redirects users who are not logged in to a **Login page**. The problem with this is the that it redirects them to the default WordPress page. How can I add the **url** of the page I want them to be redirected to.
```
function sh... | The answer from @SallyCJ got me started on the solution that worked best for me. It uses some of her code. There are references to other resources that helped out.
```
function my_get_shortcode_atts($shortcode_id) {
/* given the $shortcode_id you are looking for, find it in the content
before the loop
returns... |
406,719 | <p><strong>My problem</strong>:</p>
<p>I use the wp-scripts node packages to create a gutenberg plugin. My configuration worked well for one or two weeks and soudainely it stop to work.</p>
<p>My package.json files is:</p>
<pre><code>{
"name": "wf-g",
"version": "0.1.0",
... | [
{
"answer_id": 406892,
"author": "Lovor",
"author_id": 135704,
"author_profile": "https://wordpress.stackexchange.com/users/135704",
"pm_score": 0,
"selected": false,
"text": "<p>It seems you are doing it unnecessarily complicated. You can use <code>@wordpress/create-block</code> to scaf... | 2022/06/13 | [
"https://wordpress.stackexchange.com/questions/406719",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/86085/"
] | **My problem**:
I use the wp-scripts node packages to create a gutenberg plugin. My configuration worked well for one or two weeks and soudainely it stop to work.
My package.json files is:
```
{
"name": "wf-g",
"version": "0.1.0",
"description": "Example static block scaffolded with Create Block tool.",
... | Finally i found the problem !
There was a problem in the scss file which stop the building script. I had no error message.
I think that the problem was that i used a sass variable which was too long. |
406,989 | <p>I have a mu-plugin that removes a branded "Welcome to X" dashboard meta box placed there by the hosting company I work for. It works fine mostly.</p>
<p>However, some of our agency clients are already removing it in functions.php, which is now causing a fatal error when the mu-plugin removes it and then fu... | [
{
"answer_id": 406892,
"author": "Lovor",
"author_id": 135704,
"author_profile": "https://wordpress.stackexchange.com/users/135704",
"pm_score": 0,
"selected": false,
"text": "<p>It seems you are doing it unnecessarily complicated. You can use <code>@wordpress/create-block</code> to scaf... | 2022/06/21 | [
"https://wordpress.stackexchange.com/questions/406989",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/218210/"
] | I have a mu-plugin that removes a branded "Welcome to X" dashboard meta box placed there by the hosting company I work for. It works fine mostly.
However, some of our agency clients are already removing it in functions.php, which is now causing a fatal error when the mu-plugin removes it and then functions.php tries a... | Finally i found the problem !
There was a problem in the scss file which stop the building script. I had no error message.
I think that the problem was that i used a sass variable which was too long. |
407,050 | <p>Can anyone help me here. I want to list all the custom posts with the type 'portfolio' in this loop, where they have the 'Project Categories' set to 'ABC'. The below doesn't work, I think the issue is that the '' array parameter is looking at the main WP 'Categories'. Can someone help me to get it working please? Ch... | [
{
"answer_id": 407051,
"author": "Sarequl Basar",
"author_id": 125457,
"author_profile": "https://wordpress.stackexchange.com/users/125457",
"pm_score": 1,
"selected": false,
"text": "<p>Is that <strong>category</strong> or custom <strong>taxonomy</strong>?</p>\n<p>if this is a category,... | 2022/06/23 | [
"https://wordpress.stackexchange.com/questions/407050",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/176049/"
] | Can anyone help me here. I want to list all the custom posts with the type 'portfolio' in this loop, where they have the 'Project Categories' set to 'ABC'. The below doesn't work, I think the issue is that the '' array parameter is looking at the main WP 'Categories'. Can someone help me to get it working please? Cheer... | Is that **category** or custom **taxonomy**?
if this is a category, then try this one.
```php
<?php
$loop = new WP_Query(
array(
'post_type' => 'portfolio',
'posts_per_page' => 50,
'category__in' => array('8','9','10'), // your category ids
)
);
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div... |
407,167 | <p>I'm trying to create a generic, re-usable function that shows the site name on the login screen. It works with just static text, but how do I pull in the site name dynamically? Here's what I've tried:</p>
<pre><code>function custom_login_message() {
$message = '<p class="natz-login">Log in to <... | [
{
"answer_id": 407173,
"author": "safir",
"author_id": 222127,
"author_profile": "https://wordpress.stackexchange.com/users/222127",
"pm_score": -1,
"selected": false,
"text": "<p>if you mean, the php to replace <code><?php echo get_option( 'name' ); ?></code><br />\nthen it's pro... | 2022/06/28 | [
"https://wordpress.stackexchange.com/questions/407167",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/222589/"
] | I'm trying to create a generic, re-usable function that shows the site name on the login screen. It works with just static text, but how do I pull in the site name dynamically? Here's what I've tried:
```
function custom_login_message() {
$message = '<p class="natz-login">Log in to <?php echo get_option( 'name' );... | The function you are looking for is [`get_bloginfo()`](https://developer.wordpress.org/reference/functions/get_bloginfo/).
```
function wpse407167_custom_login_message( $message ) {
$message = '<p class="natz-login">Log in to ' . get_bloginfo('name') . '</p><br>';
return $message;
}
add_filter( 'login_messag... |
407,263 | <p>Hello I'm new to Wordpress and I'm trying to create an ajax endpoint that outputs JSON so I can access it through jQuery Datatables. I'm using Air Light theme for my current site and what happens when I go into <code>/wp-admin/admin-ajax.php?action=ajax_endpoint</code> is that it just gives me 0. I tried querying po... | [
{
"answer_id": 407264,
"author": "Antti Koskinen",
"author_id": 144392,
"author_profile": "https://wordpress.stackexchange.com/users/144392",
"pm_score": 3,
"selected": true,
"text": "<p>You need to use the defined namespace as the prefix for the <code>add_action</code> callbacks so that... | 2022/07/01 | [
"https://wordpress.stackexchange.com/questions/407263",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/223649/"
] | Hello I'm new to Wordpress and I'm trying to create an ajax endpoint that outputs JSON so I can access it through jQuery Datatables. I'm using Air Light theme for my current site and what happens when I go into `/wp-admin/admin-ajax.php?action=ajax_endpoint` is that it just gives me 0. I tried querying posts, users, an... | You need to use the defined namespace as the prefix for the `add_action` callbacks so that PHP knows which function it is supposed to call. More on this here, [add\_action in namespace not working](https://wordpress.stackexchange.com/questions/284877/add-action-in-namespace-not-working)
The `add_action`s should look l... |
407,275 | <p>I'm currently setting up my first WP REST API and am attempting to understand how WP implements JSON Schema for the API endpoints, and the docs are imho really poor and confusing; so I wanted to make sure that I understand things properly:</p>
<ol>
<li><p>According to <a href="https://developer.wordpress.org/rest-ap... | [
{
"answer_id": 407280,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 3,
"selected": true,
"text": "<p>You're already providing a schema, the parameters in <code>args</code> are their own schemas, but WordPress d... | 2022/07/01 | [
"https://wordpress.stackexchange.com/questions/407275",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/188571/"
] | I'm currently setting up my first WP REST API and am attempting to understand how WP implements JSON Schema for the API endpoints, and the docs are imho really poor and confusing; so I wanted to make sure that I understand things properly:
1. According to [this](https://developer.wordpress.org/rest-api/extending-the-r... | You're already providing a schema, the parameters in `args` are their own schemas, but WordPress does not enforce this schema or perform sanitisation/validation by default.
You can make WordPress enforce it though by setting the validation and sanitisation callbacks to the following:
```php
'sanitize_callback' => 're... |
407,346 | <p>When using <code>@wordpress/create-block</code> to scaffhold a plugin for a block, the generated bundle is automatically registered via the <code>block.json</code> metadata :</p>
<pre class="lang-json prettyprint-override"><code>{
...
"name": "my-block",
"textdomain": "my-blo... | [
{
"answer_id": 407405,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 0,
"selected": false,
"text": "<p>Here's the problem:</p>\n<pre class=\"lang-php prettyprint-override\"><code> wp_set_script_translations( ... | 2022/07/04 | [
"https://wordpress.stackexchange.com/questions/407346",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/29500/"
] | When using `@wordpress/create-block` to scaffhold a plugin for a block, the generated bundle is automatically registered via the `block.json` metadata :
```json
{
...
"name": "my-block",
"textdomain": "my-block",
"editorScript": "file:./index.js",
...
}
```
No need to call `wp_register_script` myself. This... | [@drskullster](https://wordpress.stackexchange.com/users/29500/drskullster) already posted a good answer, but I thought I should share the following which explains why [`wp_set_script_translations()`](https://developer.wordpress.org/reference/functions/wp_set_script_translations/) needs to be called manually:
1. Yes i... |
407,347 | <p>I have to create the next feature fore the project:</p>
<p>We have two type of top-bar lines. We need to show every second user(or user session I think it's more easy) different types of banners. Okay I created a really simple code for this propose:
//Create a session
session_start();</p>
<pre><code>if(isset( $_SESS... | [
{
"answer_id": 407352,
"author": "Bruno Ribarić",
"author_id": 200784,
"author_profile": "https://wordpress.stackexchange.com/users/200784",
"pm_score": 2,
"selected": false,
"text": "<p>You could set a cookie that identifies a user as belonging to either group, then based on the cookie ... | 2022/07/04 | [
"https://wordpress.stackexchange.com/questions/407347",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/201628/"
] | I have to create the next feature fore the project:
We have two type of top-bar lines. We need to show every second user(or user session I think it's more easy) different types of banners. Okay I created a really simple code for this propose:
//Create a session
session\_start();
```
if(isset( $_SESSION ) ){
$_SES... | Instead of using the [Options API](https://developer.wordpress.org/plugins/settings/options-api/), you'd be better off using the [Transients API](https://developer.wordpress.org/apis/handbook/transients/), however in either case you'll be polluting the `*_options` table (even if you use transients with expiration times... |
407,391 | <p>How do I get the full category path including the subcategories?</p>
<p>I am using</p>
<pre><code>if ( is_archive() ) {
$term = get_queried_object();
$page_path = $term->slug;
}
</code></pre>
<p><code>https://mandoemedia.com/blog/topic/aaa-1ndustries/beauty/</code> this returns <code>beauty</code> only, <... | [
{
"answer_id": 407469,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 3,
"selected": true,
"text": "<blockquote>\n<p>How do I grab the parent category and subcategory, i.e. <code>aaa-1ndustries/beauty</code>?</... | 2022/07/06 | [
"https://wordpress.stackexchange.com/questions/407391",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3206/"
] | How do I get the full category path including the subcategories?
I am using
```
if ( is_archive() ) {
$term = get_queried_object();
$page_path = $term->slug;
}
```
`https://mandoemedia.com/blog/topic/aaa-1ndustries/beauty/` this returns `beauty` only, **not** `aaa-1ndustries/beauty`.
How do I grab the pare... | >
> How do I grab the parent category and subcategory, i.e. `aaa-1ndustries/beauty`?
>
>
>
Well if you meant the **current** category URL, where it looks like `https://example.com/blog/topic/aaa-1ndustries/beauty/`, and you just wanted to get the above category path from that URL, then try this:
```php
$request ... |
407,454 | <p>So I have a complex list of ACF repeaters for ingredients, but have a save hook to store them all as one comma delimited text string in a custom field to help. My current "advanced" search passes ingredient searches as a meta query and works, but non-exact matches return nothing. Like if you search "p... | [
{
"answer_id": 407469,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 3,
"selected": true,
"text": "<blockquote>\n<p>How do I grab the parent category and subcategory, i.e. <code>aaa-1ndustries/beauty</code>?</... | 2022/07/07 | [
"https://wordpress.stackexchange.com/questions/407454",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/221659/"
] | So I have a complex list of ACF repeaters for ingredients, but have a save hook to store them all as one comma delimited text string in a custom field to help. My current "advanced" search passes ingredient searches as a meta query and works, but non-exact matches return nothing. Like if you search "pepper and paprika"... | >
> How do I grab the parent category and subcategory, i.e. `aaa-1ndustries/beauty`?
>
>
>
Well if you meant the **current** category URL, where it looks like `https://example.com/blog/topic/aaa-1ndustries/beauty/`, and you just wanted to get the above category path from that URL, then try this:
```php
$request ... |
407,541 | <p>I've added a <code>wp_login</code> action and it's getting executed. Then within that function, I'm adding a filter to <code>the_content</code> so that a script gets inserted upon certain conditions but it's not getting executed. The filter within the <code>wp_login</code> action is:</p>
<pre><code>add_filter( 'the_... | [
{
"answer_id": 407547,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 2,
"selected": false,
"text": "<p>You've misunderstood how hooks, and PHP, work.</p>\n<p>Hooks are not persistent. Each time you visit a ... | 2022/07/11 | [
"https://wordpress.stackexchange.com/questions/407541",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/165118/"
] | I've added a `wp_login` action and it's getting executed. Then within that function, I'm adding a filter to `the_content` so that a script gets inserted upon certain conditions but it's not getting executed. The filter within the `wp_login` action is:
```
add_filter( 'the_content', 'my_function', 10, 1 );
```
If I m... | You've misunderstood how hooks, and PHP, work.
Hooks are not persistent. Each time you visit a page in WordPress the PHP scripts that comprise WordPress all get run. Every time. This includes plugins and the theme's the functions.php file. So when you run `add_action()` that queues up a callback function to run whenev... |
407,559 | <p>I've got a custom field set up using Advanced Custom Fields - the field is named "Company Logo" and is an image field which is returning an image url. I've tried the array and the image ID but nothing seems to work.</p>
<p>I'm attempting to use <code><img src="[acf field='company_logo']"></... | [
{
"answer_id": 407547,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 2,
"selected": false,
"text": "<p>You've misunderstood how hooks, and PHP, work.</p>\n<p>Hooks are not persistent. Each time you visit a ... | 2022/07/11 | [
"https://wordpress.stackexchange.com/questions/407559",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/221091/"
] | I've got a custom field set up using Advanced Custom Fields - the field is named "Company Logo" and is an image field which is returning an image url. I've tried the array and the image ID but nothing seems to work.
I'm attempting to use `<img src="[acf field='company_logo']">`
however it fails and displays
`<img sr... | You've misunderstood how hooks, and PHP, work.
Hooks are not persistent. Each time you visit a page in WordPress the PHP scripts that comprise WordPress all get run. Every time. This includes plugins and the theme's the functions.php file. So when you run `add_action()` that queues up a callback function to run whenev... |
407,578 | <p>I have FTP (SFTP) working on Filezilla and also on an "old" Wordpress site (I mean I set up the FTP for that site months ago), but it's not working on a new site.</p>
<p>I'm trying to duplicate that old Wordpress site on a new domain. I've copied all the files and ran the installer OK (I've changed the wp-... | [
{
"answer_id": 407547,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 2,
"selected": false,
"text": "<p>You've misunderstood how hooks, and PHP, work.</p>\n<p>Hooks are not persistent. Each time you visit a ... | 2022/07/12 | [
"https://wordpress.stackexchange.com/questions/407578",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/223970/"
] | I have FTP (SFTP) working on Filezilla and also on an "old" Wordpress site (I mean I set up the FTP for that site months ago), but it's not working on a new site.
I'm trying to duplicate that old Wordpress site on a new domain. I've copied all the files and ran the installer OK (I've changed the wp-config.php file bef... | You've misunderstood how hooks, and PHP, work.
Hooks are not persistent. Each time you visit a page in WordPress the PHP scripts that comprise WordPress all get run. Every time. This includes plugins and the theme's the functions.php file. So when you run `add_action()` that queues up a callback function to run whenev... |
407,600 | <p>I am learning WordPress Plugin Development. My Code is like below.</p>
<pre><code>class Admin
{
public function __construct()
{
add_action( 'admin_menu', [$this,'news_meta_boxes'] );
}
public function news_meta_boxes()
{
add_meta_box('news_settings', 'News Settings',... | [
{
"answer_id": 407607,
"author": "Antti Koskinen",
"author_id": 144392,
"author_profile": "https://wordpress.stackexchange.com/users/144392",
"pm_score": 0,
"selected": false,
"text": "<p>First thing you can do is to switch to using <a href=\"https://developer.wordpress.org/reference/hoo... | 2022/07/13 | [
"https://wordpress.stackexchange.com/questions/407600",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/65189/"
] | I am learning WordPress Plugin Development. My Code is like below.
```
class Admin
{
public function __construct()
{
add_action( 'admin_menu', [$this,'news_meta_boxes'] );
}
public function news_meta_boxes()
{
add_meta_box('news_settings', 'News Settings', [ $this, 'post_s... | *You shouldn’t*.
To get the data for the correct post you should be using the `$post` variable passed to the callback function. This represents the post being edited. Therefore to get the metadata for the correct post you should call `get_post_meta()` inside the callback function. |
407,604 | <p>i have a question about improving my solution.</p>
<p>For my task i build a Gutenberg block which shows the latest 5 Posts. This Posts show also the Category Name in the Frontend part which have different styling each.</p>
<p>so I'm using the get_post() function to get all Posts, but there comes no Categories which ... | [
{
"answer_id": 407607,
"author": "Antti Koskinen",
"author_id": 144392,
"author_profile": "https://wordpress.stackexchange.com/users/144392",
"pm_score": 0,
"selected": false,
"text": "<p>First thing you can do is to switch to using <a href=\"https://developer.wordpress.org/reference/hoo... | 2022/07/13 | [
"https://wordpress.stackexchange.com/questions/407604",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/223996/"
] | i have a question about improving my solution.
For my task i build a Gutenberg block which shows the latest 5 Posts. This Posts show also the Category Name in the Frontend part which have different styling each.
so I'm using the get\_post() function to get all Posts, but there comes no Categories which is the reason ... | *You shouldn’t*.
To get the data for the correct post you should be using the `$post` variable passed to the callback function. This represents the post being edited. Therefore to get the metadata for the correct post you should call `get_post_meta()` inside the callback function. |
407,610 | <p>This snippet used to work fine but with the update to PHP 8.0 it now breaks the site when a WC order is switched to this custom status</p>
<pre><code>//Add custom bulk action in dropdown
add_filter( 'bulk_actions-edit-shop_order', 'register_bulk_action_printed' );
function register_bulk_action_printed( $bulk_acti... | [
{
"answer_id": 407611,
"author": "Rup",
"author_id": 3276,
"author_profile": "https://wordpress.stackexchange.com/users/3276",
"pm_score": 3,
"selected": true,
"text": "<p>On this line in bulk_process_status_printed():</p>\n<pre class=\"lang-php prettyprint-override\"><code>'ids' => j... | 2022/07/13 | [
"https://wordpress.stackexchange.com/questions/407610",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/148232/"
] | This snippet used to work fine but with the update to PHP 8.0 it now breaks the site when a WC order is switched to this custom status
```
//Add custom bulk action in dropdown
add_filter( 'bulk_actions-edit-shop_order', 'register_bulk_action_printed' );
function register_bulk_action_printed( $bulk_actions ) {
... | On this line in bulk\_process\_status\_printed():
```php
'ids' => join( $_REQUEST['post'], ',' ),
```
you've got the arguments backwards: it should be [join(separator, array)](https://www.php.net/manual/en/function.implode.php):
```php
'ids' => join( ',', $_REQUEST['post'] ),
```
This is actually a PHP 8 change n... |
407,653 | <p>I have a custom post type I've created, and I've added an admin submenu page to display some data it generates. So far, so good. I'm displaying the data with my local extension of <code>WP_List_Table</code>, and I want one of the columns to link to a detailed view of the item in the row. So,</p>
<p>Add menu:</p>
<pr... | [
{
"answer_id": 407672,
"author": "philolegein",
"author_id": 194028,
"author_profile": "https://wordpress.stackexchange.com/users/194028",
"pm_score": 0,
"selected": false,
"text": "<p>It appears this has been causing consternation for 11+ years, as it was reported as <a href=\"https://c... | 2022/07/14 | [
"https://wordpress.stackexchange.com/questions/407653",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/194028/"
] | I have a custom post type I've created, and I've added an admin submenu page to display some data it generates. So far, so good. I'm displaying the data with my local extension of `WP_List_Table`, and I want one of the columns to link to a detailed view of the item in the row. So,
Add menu:
```
add_submenu_page('edit... | From your question:
>
> I've tried it both with and without the `esc_url` wrapper, but either
> way, it ends up moving the existing `page` query arg to the end, and
> prepending it with `#038;` instead of the ampersand.
>
>
>
And from your answer:
>
> The root cause was determined to be that `menu_page_url` run... |
407,741 | <p>I am reading a book called "Learn to Create WordPress Themes by Building 5 Projects" . In that to retrieve the parent for pages, they have a function to get the parent of the pages. The function is as follows,</p>
<pre><code>function page_is_parent(){
global $post;
$pages = get_pages('child_of='.$post->... | [
{
"answer_id": 407743,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 2,
"selected": true,
"text": "<p>It is concatenated because that's how we <a href=\"https://www.php.net/manual/en/language.operators.string.... | 2022/07/17 | [
"https://wordpress.stackexchange.com/questions/407741",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/224123/"
] | I am reading a book called "Learn to Create WordPress Themes by Building 5 Projects" . In that to retrieve the parent for pages, they have a function to get the parent of the pages. The function is as follows,
```
function page_is_parent(){
global $post;
$pages = get_pages('child_of='.$post->ID);
return count($pages);... | It is concatenated because that's how we [combine strings together in PHP](https://www.php.net/manual/en/language.operators.string.php), and string is passed because arguments **can be passed as a query string or an array of `key => value` pairs**.
See the [`get_pages()` documentation](https://developer.wordpress.org/... |
407,748 | <p>I'm starting to develop Gutenberg blocks. After</p>
<pre><code>npx @wordpress/create-block gutenpride
</code></pre>
<p>I have my gutenpride block ready to use. Since the generated plugin contains a structure for only one block I wonder what changes should I make to add another similar block in the same plugin.</p>
<... | [
{
"answer_id": 407752,
"author": "aitor",
"author_id": 77722,
"author_profile": "https://wordpress.stackexchange.com/users/77722",
"pm_score": 3,
"selected": true,
"text": "<ol>\n<li>Add a subfolder in <code>your-plugin/src</code> with the block name</li>\n<li>Put all <code>src</code> fi... | 2022/07/17 | [
"https://wordpress.stackexchange.com/questions/407748",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/77722/"
] | I'm starting to develop Gutenberg blocks. After
```
npx @wordpress/create-block gutenpride
```
I have my gutenpride block ready to use. Since the generated plugin contains a structure for only one block I wonder what changes should I make to add another similar block in the same plugin.
So, for the default structur... | 1. Add a subfolder in `your-plugin/src` with the block name
2. Put all `src` files inside this folder
3. Repeat 1 and 2 for other blocks that you want to add.
At this moment, the `src` folder looks like this:
[](https://i.stack.imgur.com/zgqDZ.png)
... |
407,759 | <p>Looking to <code>ORDER BY</code> the result of <a href="https://developer.wordpress.org/reference/classes/wp_query/" rel="nofollow noreferrer">WP_Query</a> based on presence of post thumbnail.</p>
<pre><code> $query_args = [
'post_type' => 'custom_project',
'post_status' => 'publish',
'posts... | [
{
"answer_id": 407752,
"author": "aitor",
"author_id": 77722,
"author_profile": "https://wordpress.stackexchange.com/users/77722",
"pm_score": 3,
"selected": true,
"text": "<ol>\n<li>Add a subfolder in <code>your-plugin/src</code> with the block name</li>\n<li>Put all <code>src</code> fi... | 2022/07/17 | [
"https://wordpress.stackexchange.com/questions/407759",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/48604/"
] | Looking to `ORDER BY` the result of [WP\_Query](https://developer.wordpress.org/reference/classes/wp_query/) based on presence of post thumbnail.
```
$query_args = [
'post_type' => 'custom_project',
'post_status' => 'publish',
'posts_per_page' => 20,
'orderby' => array( 'meta_value_num' => ... | 1. Add a subfolder in `your-plugin/src` with the block name
2. Put all `src` files inside this folder
3. Repeat 1 and 2 for other blocks that you want to add.
At this moment, the `src` folder looks like this:
[](https://i.stack.imgur.com/zgqDZ.png)
... |
407,784 | <p>How to Pass ID and fetch post meta data through Short Code like <code>[my-shortcode id="12"]</code> ?</p>
<p>My code is like below.</p>
<pre><code>add_shortcode( 'my-shortcode', 'shortcode_function' );
function shortcode_function( $id ) {
//I would like to get $id value 12 here
return $id;
}... | [
{
"answer_id": 407785,
"author": "DeltaG",
"author_id": 168537,
"author_profile": "https://wordpress.stackexchange.com/users/168537",
"pm_score": 0,
"selected": false,
"text": "<p>You can get the ID by extracting the shortcode attributes. Check out the example below:</p>\n<pre><code>func... | 2022/07/18 | [
"https://wordpress.stackexchange.com/questions/407784",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/65189/"
] | How to Pass ID and fetch post meta data through Short Code like `[my-shortcode id="12"]` ?
My code is like below.
```
add_shortcode( 'my-shortcode', 'shortcode_function' );
function shortcode_function( $id ) {
//I would like to get $id value 12 here
return $id;
}
``` | Your short code function receives the attributes as the first argument:
```php
function shortcode_function( $attributes ) {
```
Here `$attributes` is an array, and the attributes/values are inside that variable,
e.g. for `[my-shortcode abc="123" xyz="789"]`:
```php
echo $attributes['abc']; // prints 123
echo $attr... |
407,826 | <p>I'm developing a custom Gutenberg block and would like to use the same JavaScript code on frontend and backend.</p>
<p>In the save function of the block I generate the following html code (abridged):</p>
<pre><code>return (
<div {...blockProps}>
<table className="my-plugin-table" data-... | [
{
"answer_id": 407785,
"author": "DeltaG",
"author_id": 168537,
"author_profile": "https://wordpress.stackexchange.com/users/168537",
"pm_score": 0,
"selected": false,
"text": "<p>You can get the ID by extracting the shortcode attributes. Check out the example below:</p>\n<pre><code>func... | 2022/07/19 | [
"https://wordpress.stackexchange.com/questions/407826",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107117/"
] | I'm developing a custom Gutenberg block and would like to use the same JavaScript code on frontend and backend.
In the save function of the block I generate the following html code (abridged):
```
return (
<div {...blockProps}>
<table className="my-plugin-table" data-rows="50">
<thead>
... | Your short code function receives the attributes as the first argument:
```php
function shortcode_function( $attributes ) {
```
Here `$attributes` is an array, and the attributes/values are inside that variable,
e.g. for `[my-shortcode abc="123" xyz="789"]`:
```php
echo $attributes['abc']; // prints 123
echo $attr... |
407,877 | <p>I'm looking to set a cookie for one of my WordPress applications. Despite my research, I can't find why WordPress ignores the creation of the cookie.
Here is my code place in my app.
What do you think of my code? do they have errors?
wordpress 6.0.1
php 8.0
<a href="https://lysto.fr/tools/?categorie=461" rel="nofoll... | [
{
"answer_id": 407785,
"author": "DeltaG",
"author_id": 168537,
"author_profile": "https://wordpress.stackexchange.com/users/168537",
"pm_score": 0,
"selected": false,
"text": "<p>You can get the ID by extracting the shortcode attributes. Check out the example below:</p>\n<pre><code>func... | 2022/07/21 | [
"https://wordpress.stackexchange.com/questions/407877",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/222956/"
] | I'm looking to set a cookie for one of my WordPress applications. Despite my research, I can't find why WordPress ignores the creation of the cookie.
Here is my code place in my app.
What do you think of my code? do they have errors?
wordpress 6.0.1
php 8.0
<https://lysto.fr/tools/?categorie=461> (ajouter un article po... | Your short code function receives the attributes as the first argument:
```php
function shortcode_function( $attributes ) {
```
Here `$attributes` is an array, and the attributes/values are inside that variable,
e.g. for `[my-shortcode abc="123" xyz="789"]`:
```php
echo $attributes['abc']; // prints 123
echo $attr... |
407,955 | <p>I have one problem. I can't get the alt tag inside me repeater fields in ACF, I've tried multiple methods and nothing works for me, could you please help me? I can't fix this problem for a week :(
Something that I've tried and it should be working was this:</p>
<pre><code><?php while( have_rows('logo_list') ) : t... | [
{
"answer_id": 407785,
"author": "DeltaG",
"author_id": 168537,
"author_profile": "https://wordpress.stackexchange.com/users/168537",
"pm_score": 0,
"selected": false,
"text": "<p>You can get the ID by extracting the shortcode attributes. Check out the example below:</p>\n<pre><code>func... | 2022/07/24 | [
"https://wordpress.stackexchange.com/questions/407955",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/224338/"
] | I have one problem. I can't get the alt tag inside me repeater fields in ACF, I've tried multiple methods and nothing works for me, could you please help me? I can't fix this problem for a week :(
Something that I've tried and it should be working was this:
```
<?php while( have_rows('logo_list') ) : the_row();?>
<?ph... | Your short code function receives the attributes as the first argument:
```php
function shortcode_function( $attributes ) {
```
Here `$attributes` is an array, and the attributes/values are inside that variable,
e.g. for `[my-shortcode abc="123" xyz="789"]`:
```php
echo $attributes['abc']; // prints 123
echo $attr... |
407,995 | <p>I have a page where I want to add a custom class to all the images.</p>
<p>How to add this?</p>
<p>Thank you.</p>
| [
{
"answer_id": 407785,
"author": "DeltaG",
"author_id": 168537,
"author_profile": "https://wordpress.stackexchange.com/users/168537",
"pm_score": 0,
"selected": false,
"text": "<p>You can get the ID by extracting the shortcode attributes. Check out the example below:</p>\n<pre><code>func... | 2022/07/25 | [
"https://wordpress.stackexchange.com/questions/407995",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/183833/"
] | I have a page where I want to add a custom class to all the images.
How to add this?
Thank you. | Your short code function receives the attributes as the first argument:
```php
function shortcode_function( $attributes ) {
```
Here `$attributes` is an array, and the attributes/values are inside that variable,
e.g. for `[my-shortcode abc="123" xyz="789"]`:
```php
echo $attributes['abc']; // prints 123
echo $attr... |
408,051 | <p>I'm using a plugin that doesn't provide many hooks for its actions. I would like to be able to hook in when the plugin adds a row to a plugin-specific table, and update some other data elsewhere. (For context, it's a CRM. Whenever a log is added to its logs table, I would also like to update the CRM users table, upd... | [
{
"answer_id": 408054,
"author": "Brennan",
"author_id": 149131,
"author_profile": "https://wordpress.stackexchange.com/users/149131",
"pm_score": 3,
"selected": false,
"text": "<p>If you have access to the database, you could potentially create a trigger for that plugin-specific table. ... | 2022/07/27 | [
"https://wordpress.stackexchange.com/questions/408051",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/102815/"
] | I'm using a plugin that doesn't provide many hooks for its actions. I would like to be able to hook in when the plugin adds a row to a plugin-specific table, and update some other data elsewhere. (For context, it's a CRM. Whenever a log is added to its logs table, I would also like to update the CRM users table, updati... | If you have access to the database, you could potentially create a trigger for that plugin-specific table. This bypasses the need for a hook. Depending on how they handle database schema updates, it might even stick around after a plugin update. *I've never tried triggers on WP tables though, so take this with a grain ... |
408,081 | <p>On the post editor field, I have added an <code>iframe</code> code. But on the frontend, it is not showing the content with the <code>iframe</code> code.</p>
<p>I have added the below code to print the excerpt on the blog page:</p>
<pre class="lang-php prettyprint-override"><code><?php echo get_post_field('post_c... | [
{
"answer_id": 408054,
"author": "Brennan",
"author_id": 149131,
"author_profile": "https://wordpress.stackexchange.com/users/149131",
"pm_score": 3,
"selected": false,
"text": "<p>If you have access to the database, you could potentially create a trigger for that plugin-specific table. ... | 2022/07/28 | [
"https://wordpress.stackexchange.com/questions/408081",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/185965/"
] | On the post editor field, I have added an `iframe` code. But on the frontend, it is not showing the content with the `iframe` code.
I have added the below code to print the excerpt on the blog page:
```php
<?php echo get_post_field('post_content', $post['id']) ; ?>
```
It is not in the single post page, but I have ... | If you have access to the database, you could potentially create a trigger for that plugin-specific table. This bypasses the need for a hook. Depending on how they handle database schema updates, it might even stick around after a plugin update. *I've never tried triggers on WP tables though, so take this with a grain ... |
408,101 | <p>To clarify -- these files in the error were NOT edited at the time of the error, I checked twice. And I checked again by doing a diff with a fresh WordPress install. I had to remove the broken line -- shown below -- because it crashes WordPress. This line does not crash all WordPress blogs, obviously, and I have an... | [
{
"answer_id": 408102,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 2,
"selected": false,
"text": "<p><em><strong>Never edit core files, and definitely do not make this change.</strong></em></p>\n<p>Lookin... | 2022/07/29 | [
"https://wordpress.stackexchange.com/questions/408101",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3453/"
] | To clarify -- these files in the error were NOT edited at the time of the error, I checked twice. And I checked again by doing a diff with a fresh WordPress install. I had to remove the broken line -- shown below -- because it crashes WordPress. This line does not crash all WordPress blogs, obviously, and I have anothe... | When you use the deprecated `CUSTOM_TAGS` constant, you have to define the variables WordPress would normally create in `kses.php` at the top. If you do not then you will encounter this issue.
```php
/**
* Specifies the default allowable HTML tags.
*
* Using `CUSTOM_TAGS` is not recommended and should be considered... |
408,225 | <p>When you set up blocks in the block editor (Gutenberg), you typically get options on how to align them (i.e. none, wide, full). Or, if your theme doesn't have them, you can use the function <code>add_theme_support ();</code> to include them. This is really helpful because then I can style them with CSS like someth... | [
{
"answer_id": 408219,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 2,
"selected": true,
"text": "<p>In versions of WordPress prior to 4.2 terms could belong to multiple taxonomies. This is no longer the c... | 2022/08/02 | [
"https://wordpress.stackexchange.com/questions/408225",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12294/"
] | When you set up blocks in the block editor (Gutenberg), you typically get options on how to align them (i.e. none, wide, full). Or, if your theme doesn't have them, you can use the function `add_theme_support ();` to include them. This is really helpful because then I can style them with CSS like something below:
```
... | In versions of WordPress prior to 4.2 terms could belong to multiple taxonomies. This is no longer the case and in WordPress 4.2 or newer new terms cannot belong to multiple taxonomies and any existing terms that belong to multiple taxonomies are split into multiple terms whenever they are updated.
You can read this p... |
408,330 | <p>As a plugin developer who wants to provide better documentations to my customers I'm also including a dev section inside my docs.</p>
<p>This section should contain all provided hooks and filters by my plugin including the filename and line. Also, I want to grab the documentation above each hook to display it as doc... | [
{
"answer_id": 408733,
"author": "Johnny97",
"author_id": 151233,
"author_profile": "https://wordpress.stackexchange.com/users/151233",
"pm_score": 2,
"selected": true,
"text": "<p>I've tried using the parser, but it's build for WP docs and is a bit too complex for my needs. So I've inve... | 2022/08/05 | [
"https://wordpress.stackexchange.com/questions/408330",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/151233/"
] | As a plugin developer who wants to provide better documentations to my customers I'm also including a dev section inside my docs.
This section should contain all provided hooks and filters by my plugin including the filename and line. Also, I want to grab the documentation above each hook to display it as documentatio... | I've tried using the parser, but it's build for WP docs and is a bit too complex for my needs. So I've invented my own little plugin: HookR.
HookR provides a shortcode where you can pass a path to the uploads folder and a file inside containing all plugins hooks within a JSON format:
```
{
"created": "1660810923",
... |
408,331 | <p>I've been having issues using wp_mail and mail functions in an application when specifying header elements in the function.</p>
<p>I usually set up the header as an <em>associative</em> array, as in</p>
<pre><code>$mailheader = array(
'MIME-Version' => '1.0',
'Content-type' => ... | [
{
"answer_id": 408332,
"author": "Rick Hellewell",
"author_id": 29416,
"author_profile": "https://wordpress.stackexchange.com/users/29416",
"pm_score": 0,
"selected": false,
"text": "<p><strong>Added</strong></p>\n<p>Although wp_mail will accept a one-dimensional array, it will not accep... | 2022/08/05 | [
"https://wordpress.stackexchange.com/questions/408331",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/29416/"
] | I've been having issues using wp\_mail and mail functions in an application when specifying header elements in the function.
I usually set up the header as an *associative* array, as in
```
$mailheader = array(
'MIME-Version' => '1.0',
'Content-type' => ' text/html; charset=utf-8',
... | Both the [`mail()` function in PHP](https://www.php.net/manual/en/function.mail.php) and [`wp_mail()` in WordPress](https://developer.wordpress.org/reference/functions/wp_mail/) do support passing an array or string of headers, but the difference is:
* With `mail()`, the array keys are the header names and its values ... |
408,410 | <p>I'm trying to find a way to show different content if a post is set to "password protected", once the user entered the correct password.</p>
<p>I want to show the price of an art piece only on posts that are set to password protected.</p>
<p>I can't find any php code to achieve this, since all I can find i... | [
{
"answer_id": 408414,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 1,
"selected": false,
"text": "<p>There's two main ways:</p>\n<ol>\n<li>You can use the <a href=\"https://developer.wordpress.org/referen... | 2022/08/09 | [
"https://wordpress.stackexchange.com/questions/408410",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40572/"
] | I'm trying to find a way to show different content if a post is set to "password protected", once the user entered the correct password.
I want to show the price of an art piece only on posts that are set to password protected.
I can't find any php code to achieve this, since all I can find includes cookies managemen... | There's two main ways:
1. You can use the [`post_password_required()`](https://developer.wordpress.org/reference/functions/post_password_required/) function. This function returns `true` if the post has a password and `false` if the post doesn't have a password, but it also returns `false` if the post had a password b... |
408,447 | <p>I have a contact form 7 form and in that I have an acceptance checkbox for terms and condition and I want to make that checkbox required and add some class when checkbox is not checked and prevent form from submission.So I tried using preventDefault().</p>
<pre><code><script>
$(".wpcf7-form).submit(functi... | [
{
"answer_id": 408454,
"author": "DeltaG",
"author_id": 168537,
"author_profile": "https://wordpress.stackexchange.com/users/168537",
"pm_score": 0,
"selected": false,
"text": "<p>You can disable your submit button when your condition is met. That should do the job.</p>\n<pre><code>$('.w... | 2022/08/10 | [
"https://wordpress.stackexchange.com/questions/408447",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/224467/"
] | I have a contact form 7 form and in that I have an acceptance checkbox for terms and condition and I want to make that checkbox required and add some class when checkbox is not checked and prevent form from submission.So I tried using preventDefault().
```
<script>
$(".wpcf7-form).submit(function(event){
if($("#checkb... | If anyone still trying figure out the solution there is a additional settings which works like normal contact form 7 validation for other field just use `acceptance_as_validation: on`. |
408,506 | <p>Assume all the code below is in a theme's <code>function.php</code></p>
<p>If I add <code>get_post()</code> at the top, It'd get <code>null</code>, which is totally expected since I'm not in the loop, or nothing has been done.</p>
<p>But I add</p>
<pre><code>add_filter('template_include', 'call_get_post'));
functio... | [
{
"answer_id": 408507,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 0,
"selected": false,
"text": "<p>WordPress queries the correct posts from the database automatically on every page load based on the URL... | 2022/08/11 | [
"https://wordpress.stackexchange.com/questions/408506",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108358/"
] | Assume all the code below is in a theme's `function.php`
If I add `get_post()` at the top, It'd get `null`, which is totally expected since I'm not in the loop, or nothing has been done.
But I add
```
add_filter('template_include', 'call_get_post'));
function call_get_posT(){
var_dump(get_post())
}
```
Then I'll... | >
> I tried this in a fresh install of WP locally so I'd assume this is expected behavior, but I don't understand it. I'm not in the loop,
>
>
>
No but that doesn't mean a main query doesn't exist, it just means your code to display it hasn't run yet
>
> and I haven't called anything to start a query,
>
>
>
... |
408,528 | <p>I am an old-school embedded C programmer but a WP noob, so please bear with me.</p>
<p>Here is what I have done so far:-</p>
<h1>Added a Shortcode in a Theme</h1>
<ol>
<li>My function prints out 'Hello World' and is registered to a shortcode in the OceanWP theme, and stored here:</li>
</ol>
<p><strong>> wp-conten... | [
{
"answer_id": 408539,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 2,
"selected": false,
"text": "<blockquote>\n<p>In which functions.php file am I supposed to drop an include\nstatement, so that the Hell... | 2022/08/12 | [
"https://wordpress.stackexchange.com/questions/408528",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/224865/"
] | I am an old-school embedded C programmer but a WP noob, so please bear with me.
Here is what I have done so far:-
Added a Shortcode in a Theme
============================
1. My function prints out 'Hello World' and is registered to a shortcode in the OceanWP theme, and stored here:
**> wp-content / themes / oceanw... | >
> In which functions.php file am I supposed to drop an include
> statement, so that the Hello World shortcode plugin is 'executable'?
>
>
>
None. You don't do this. The file with the `Plugin Name: HELLO WORLD PLUGIN` comment is your main plugin file. To load it you activate the plugin in *Plugins*. This is all d... |
408,536 | <p>We have large media library with more than 300000 images.</p>
<p>We decide to delete all images < 2017 year manually using "FTP", from WP upload folder.</p>
<p>But after that in WP Admin > Media > Library, they still "exist" as <a href="https://prnt.sc/nLUFpjcy_7pS" rel="nofollow norefer... | [
{
"answer_id": 408537,
"author": "DeltaG",
"author_id": 168537,
"author_profile": "https://wordpress.stackexchange.com/users/168537",
"pm_score": 1,
"selected": false,
"text": "<p>Your images still exist in your Media Library because they are stored in the database, just like posts and p... | 2022/08/12 | [
"https://wordpress.stackexchange.com/questions/408536",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/206699/"
] | We have large media library with more than 300000 images.
We decide to delete all images < 2017 year manually using "FTP", from WP upload folder.
But after that in WP Admin > Media > Library, they still "exist" as [screenshot - broken media links in library](https://prnt.sc/nLUFpjcy_7pS)
We tried with couple of plug... | >
> We tried with couple of plugins , but there isn't any with option to bulk delete images by month or year.
>
>
>
If you have access to wp-cli you can try to delete attachments by **year** and **month** with:
```
wp post delete $(wp post list --post_type='attachment' -—year=2016 -—monthnum=12 --format=ids)
```... |
408,590 | <p>edd restrict content plugin creates this shortcodes and these are working in pages and posts :</p>
<pre><code>[edd_restrict id="any"]sample restricted html or text[/edd_restrict]
</code></pre>
<p>but i want to use it in my theme not in the posts or pages. i tried this :</p>
<pre><code><?php echo do_shor... | [
{
"answer_id": 408537,
"author": "DeltaG",
"author_id": 168537,
"author_profile": "https://wordpress.stackexchange.com/users/168537",
"pm_score": 1,
"selected": false,
"text": "<p>Your images still exist in your Media Library because they are stored in the database, just like posts and p... | 2022/08/14 | [
"https://wordpress.stackexchange.com/questions/408590",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/224925/"
] | edd restrict content plugin creates this shortcodes and these are working in pages and posts :
```
[edd_restrict id="any"]sample restricted html or text[/edd_restrict]
```
but i want to use it in my theme not in the posts or pages. i tried this :
```
<?php echo do_shortcode( '[edd_restrict id="any"]' sample php '[/... | >
> We tried with couple of plugins , but there isn't any with option to bulk delete images by month or year.
>
>
>
If you have access to wp-cli you can try to delete attachments by **year** and **month** with:
```
wp post delete $(wp post list --post_type='attachment' -—year=2016 -—monthnum=12 --format=ids)
```... |
408,612 | <p>I need to get the highest-level ancestor of the current page in the Block Editor.</p>
<p>I can use</p>
<pre><code>wp.data.select('core/editor').getCurrentPostAttribute('parent');
</code></pre>
<p>to get the immediate parent of the current page, but is there anything like the PHP <code>get_post_ancestors()</code> tha... | [
{
"answer_id": 408537,
"author": "DeltaG",
"author_id": 168537,
"author_profile": "https://wordpress.stackexchange.com/users/168537",
"pm_score": 1,
"selected": false,
"text": "<p>Your images still exist in your Media Library because they are stored in the database, just like posts and p... | 2022/08/15 | [
"https://wordpress.stackexchange.com/questions/408612",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/102815/"
] | I need to get the highest-level ancestor of the current page in the Block Editor.
I can use
```
wp.data.select('core/editor').getCurrentPostAttribute('parent');
```
to get the immediate parent of the current page, but is there anything like the PHP `get_post_ancestors()` that gets all the ancestors back to the top-... | >
> We tried with couple of plugins , but there isn't any with option to bulk delete images by month or year.
>
>
>
If you have access to wp-cli you can try to delete attachments by **year** and **month** with:
```
wp post delete $(wp post list --post_type='attachment' -—year=2016 -—monthnum=12 --format=ids)
```... |
408,618 | <p>I am working on a website with 700+ pages. Most of the pages have similar keywords/slugs. Using the traditional Appearance > Menus editor is nearly impossible because I can't find the pages I am looking for (whether using Search or Most Recent or View All). I know the ID of my specific page. I know the ID of ... | [
{
"answer_id": 408620,
"author": "bosco",
"author_id": 25324,
"author_profile": "https://wordpress.stackexchange.com/users/25324",
"pm_score": 3,
"selected": true,
"text": "<p>You can use <a href=\"https://developer.wordpress.org/reference/functions/wp_update_nav_menu_item/\" rel=\"nofol... | 2022/08/15 | [
"https://wordpress.stackexchange.com/questions/408618",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12294/"
] | I am working on a website with 700+ pages. Most of the pages have similar keywords/slugs. Using the traditional Appearance > Menus editor is nearly impossible because I can't find the pages I am looking for (whether using Search or Most Recent or View All). I know the ID of my specific page. I know the ID of the menu I... | You can use [`wp_update_nav_menu_item()`](https://developer.wordpress.org/reference/functions/wp_update_nav_menu_item/) to programmatically add a new menu item to the database. Since this change persists, you shouldn't execute this functionality on every page - it's best used as a one-off (though in that case it might ... |
408,667 | <p>I have a code in my <code>functions.php</code> and I would like to use <code>wp_dropdown_categories</code> for displaying list product categories but I wont in "select" only "checkbox".</p>
<p>I edited my code in <code>functions.php</code> and it looks like this now:</p>
<pre class="lang-php pret... | [
{
"answer_id": 408620,
"author": "bosco",
"author_id": 25324,
"author_profile": "https://wordpress.stackexchange.com/users/25324",
"pm_score": 3,
"selected": true,
"text": "<p>You can use <a href=\"https://developer.wordpress.org/reference/functions/wp_update_nav_menu_item/\" rel=\"nofol... | 2022/08/16 | [
"https://wordpress.stackexchange.com/questions/408667",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/203605/"
] | I have a code in my `functions.php` and I would like to use `wp_dropdown_categories` for displaying list product categories but I wont in "select" only "checkbox".
I edited my code in `functions.php` and it looks like this now:
```php
class List_Categories_Radiobuttons extends Walker_Category {
function start_el(... | You can use [`wp_update_nav_menu_item()`](https://developer.wordpress.org/reference/functions/wp_update_nav_menu_item/) to programmatically add a new menu item to the database. Since this change persists, you shouldn't execute this functionality on every page - it's best used as a one-off (though in that case it might ... |
408,779 | <p>We need to set posts to draft or to not be created if the_content contains certain words.</p>
<p>This is not something needed on current posts, it is needed on users who publish posts going forward. As an example, if users post a recipe and they have the words "word1" and "word2" within the conte... | [
{
"answer_id": 408620,
"author": "bosco",
"author_id": 25324,
"author_profile": "https://wordpress.stackexchange.com/users/25324",
"pm_score": 3,
"selected": true,
"text": "<p>You can use <a href=\"https://developer.wordpress.org/reference/functions/wp_update_nav_menu_item/\" rel=\"nofol... | 2022/08/19 | [
"https://wordpress.stackexchange.com/questions/408779",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/225083/"
] | We need to set posts to draft or to not be created if the\_content contains certain words.
This is not something needed on current posts, it is needed on users who publish posts going forward. As an example, if users post a recipe and they have the words "word1" and "word2" within the content area, the post should not... | You can use [`wp_update_nav_menu_item()`](https://developer.wordpress.org/reference/functions/wp_update_nav_menu_item/) to programmatically add a new menu item to the database. Since this change persists, you shouldn't execute this functionality on every page - it's best used as a one-off (though in that case it might ... |
408,832 | <p>I'm trying to prevent a post from being published if it contains certain words using the folowing:</p>
<pre><code>function jhnppWord($content)
{
global $post;
$content = $post->post_content;
$words = 'word1';
if (strpos($content, '$words') !== false )
wp_die( __('Y... | [
{
"answer_id": 408620,
"author": "bosco",
"author_id": 25324,
"author_profile": "https://wordpress.stackexchange.com/users/25324",
"pm_score": 3,
"selected": true,
"text": "<p>You can use <a href=\"https://developer.wordpress.org/reference/functions/wp_update_nav_menu_item/\" rel=\"nofol... | 2022/08/22 | [
"https://wordpress.stackexchange.com/questions/408832",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/225083/"
] | I'm trying to prevent a post from being published if it contains certain words using the folowing:
```
function jhnppWord($content)
{
global $post;
$content = $post->post_content;
$words = 'word1';
if (strpos($content, '$words') !== false )
wp_die( __('Your post contain... | You can use [`wp_update_nav_menu_item()`](https://developer.wordpress.org/reference/functions/wp_update_nav_menu_item/) to programmatically add a new menu item to the database. Since this change persists, you shouldn't execute this functionality on every page - it's best used as a one-off (though in that case it might ... |
408,860 | <p>I'm using <code>isSelected</code> to determine if a block is selected, but I'd also like to know if any innerblocks are selected.</p>
<p>I'm using <code>export default function Edit({ isSelected }) {}</code></p>
<p>I believe this is done with <code>useSelect</code> but I'm not sure how that works.</p>
| [
{
"answer_id": 408862,
"author": "bosco",
"author_id": 25324,
"author_profile": "https://wordpress.stackexchange.com/users/25324",
"pm_score": 3,
"selected": true,
"text": "<p>If you only need to know whether or not an inner-block is selected, you can leverage the <code>core/block-editor... | 2022/08/22 | [
"https://wordpress.stackexchange.com/questions/408860",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/120585/"
] | I'm using `isSelected` to determine if a block is selected, but I'd also like to know if any innerblocks are selected.
I'm using `export default function Edit({ isSelected }) {}`
I believe this is done with `useSelect` but I'm not sure how that works. | If you only need to know whether or not an inner-block is selected, you can leverage the `core/block-editor` store's [`hasSelectedInnerBlock()` selector](https://developer.wordpress.org/block-editor/reference-guides/data/data-core-block-editor/#hasselectedinnerblock). For example, if using a `useSelect()` hook in a fun... |
408,888 | <p>I created an additional description field for categories, but what I write in html is saved in MSQL without html, how can I add HTML support to this field?</p>
<p>For example, I write a statement like this:</p>
<p><code><div class="class-name">It's very hot these days</div></code></p>
<p>I am l... | [
{
"answer_id": 408892,
"author": "bosco",
"author_id": 25324,
"author_profile": "https://wordpress.stackexchange.com/users/25324",
"pm_score": 2,
"selected": false,
"text": "<p><a href=\"https://developer.wordpress.org/reference/functions/sanitize_text_field/\" rel=\"nofollow noreferrer\... | 2022/08/23 | [
"https://wordpress.stackexchange.com/questions/408888",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/161959/"
] | I created an additional description field for categories, but what I write in html is saved in MSQL without html, how can I add HTML support to this field?
For example, I write a statement like this:
`<div class="class-name">It's very hot these days</div>`
I am looking at phpmyadmin and the only saved is "It's very ... | I solved the problem, the codes that work are as follows;
```
/* Custom Field for Categories */
function dm_category_fields($term) {
if (current_filter() == 'category_edit_form_fields') {
$bottom_description = get_term_meta($term->term_id, 'bottom_description', true);
$description_field = 'bottom-d... |
409,095 | <p>I'm struggling to understand how I can use <code>pre_get_post</code> when the post's metadata is not stored in the wp_postmeta table. I use Pods (<a href="https://pods.io" rel="nofollow noreferrer">https://pods.io</a>) to create custom post types with custom fields, stored using the plugins <em>Table Storage</em> op... | [
{
"answer_id": 408892,
"author": "bosco",
"author_id": 25324,
"author_profile": "https://wordpress.stackexchange.com/users/25324",
"pm_score": 2,
"selected": false,
"text": "<p><a href=\"https://developer.wordpress.org/reference/functions/sanitize_text_field/\" rel=\"nofollow noreferrer\... | 2022/08/30 | [
"https://wordpress.stackexchange.com/questions/409095",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/223134/"
] | I'm struggling to understand how I can use `pre_get_post` when the post's metadata is not stored in the wp\_postmeta table. I use Pods (<https://pods.io>) to create custom post types with custom fields, stored using the plugins *Table Storage* option.
My desired outcome is to use `orderby` on the `meta_value` stored i... | I solved the problem, the codes that work are as follows;
```
/* Custom Field for Categories */
function dm_category_fields($term) {
if (current_filter() == 'category_edit_form_fields') {
$bottom_description = get_term_meta($term->term_id, 'bottom_description', true);
$description_field = 'bottom-d... |
409,113 | <p>On our website, we have a footer (built with WP-Bakery) that includes the typical information that is needed, plus there is a section that should show the different types of payment methods that we accept. But for an unknown reason, some of these SVG-Images (not even every time the same) are not visible. Looking at ... | [
{
"answer_id": 408892,
"author": "bosco",
"author_id": 25324,
"author_profile": "https://wordpress.stackexchange.com/users/25324",
"pm_score": 2,
"selected": false,
"text": "<p><a href=\"https://developer.wordpress.org/reference/functions/sanitize_text_field/\" rel=\"nofollow noreferrer\... | 2022/08/31 | [
"https://wordpress.stackexchange.com/questions/409113",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/225378/"
] | On our website, we have a footer (built with WP-Bakery) that includes the typical information that is needed, plus there is a section that should show the different types of payment methods that we accept. But for an unknown reason, some of these SVG-Images (not even every time the same) are not visible. Looking at the... | I solved the problem, the codes that work are as follows;
```
/* Custom Field for Categories */
function dm_category_fields($term) {
if (current_filter() == 'category_edit_form_fields') {
$bottom_description = get_term_meta($term->term_id, 'bottom_description', true);
$description_field = 'bottom-d... |
409,161 | <p>I added two menus</p>
<pre><code>register_nav_menus (
array(
'primary_menu' => esc_html__('Primary Menu', 'sre'),
'footer_menu' => esc_html__('Footer Menu', 'sre'),
)
);
</code></pre>
<p>But I'm unable to remove the two old ones, <code>Primary menu</code> and <code>Secondary menu</code>... | [
{
"answer_id": 409122,
"author": "tiago calado",
"author_id": 198152,
"author_profile": "https://wordpress.stackexchange.com/users/198152",
"pm_score": 2,
"selected": true,
"text": "<p>in the server if you are using cpanel restore the database there, on Databases » phpmyadmin » choose th... | 2022/09/01 | [
"https://wordpress.stackexchange.com/questions/409161",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/171060/"
] | I added two menus
```
register_nav_menus (
array(
'primary_menu' => esc_html__('Primary Menu', 'sre'),
'footer_menu' => esc_html__('Footer Menu', 'sre'),
)
);
```
But I'm unable to remove the two old ones, `Primary menu` and `Secondary menu`
[ and press go
[](https://i.stack.imgur.com/rGpg5.png)
[![enter i... |
409,209 | <p>I have a plugin that needs to do a "database update" sort of operation, going through all users and performing a particular database operation on each one. It's designed for sites with large numbers -- tens of thousands -- of users. I've worked out a good efficient way to do the operation in chunks of 1000... | [
{
"answer_id": 409477,
"author": "AuRise",
"author_id": 110134,
"author_profile": "https://wordpress.stackexchange.com/users/110134",
"pm_score": 3,
"selected": true,
"text": "<p>The <code>WP_DISABLE_CRON</code> constant only removes WP-Cron from loading on the page so it's no longer tri... | 2022/09/03 | [
"https://wordpress.stackexchange.com/questions/409209",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13596/"
] | I have a plugin that needs to do a "database update" sort of operation, going through all users and performing a particular database operation on each one. It's designed for sites with large numbers -- tens of thousands -- of users. I've worked out a good efficient way to do the operation in chunks of 1000 users. And I... | The `WP_DISABLE_CRON` constant only removes WP-Cron from loading on the page so it's no longer triggered by site traffic.
You can absolutely hit the wp-cron.php file directly to trigger it. I use <https://cron-job.org> to ping my private sites at `https://dev.example.com/wp-cron.php?doing_wp_cron` for example.
This i... |
409,243 | <p>I am not an expert. I have used a tutorial to write a custom query like this</p>
<pre><code>add_action( 'elementor/query/my_query_by_post_types', function( $query ) {
$query->set( 'post_type', [ 'libri', 'post'] );
} );
</code></pre>
<p>This has been deployes via snippets plugin. Works fine and filter 'libri' (... | [
{
"answer_id": 409523,
"author": "Tony Djukic",
"author_id": 60844,
"author_profile": "https://wordpress.stackexchange.com/users/60844",
"pm_score": 1,
"selected": false,
"text": "<p>This just requires adding additional parameters to the <code>query->set()</code> array... ...it's stan... | 2022/09/05 | [
"https://wordpress.stackexchange.com/questions/409243",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/225521/"
] | I am not an expert. I have used a tutorial to write a custom query like this
```
add_action( 'elementor/query/my_query_by_post_types', function( $query ) {
$query->set( 'post_type', [ 'libri', 'post'] );
} );
```
This has been deployes via snippets plugin. Works fine and filter 'libri' (which is a custom type) and... | This just requires adding additional parameters to the `query->set()` array... ...it's standard `WP_Query()` stuff. So you'd essentially be taking this line:
`$query->set( 'post_type', [ 'libri', 'post'] );`
...and expanding it to include a tax query...
```
$tax_query = array(
'relation' => 'OR', //can also use... |
409,255 | <p>I want to convert every PNG and JPEG to WebP on upload so that I can serve WebP and PNG/JPEG without requiring the user to upload a WebP version of every photo.<br />
I want to save the WebP in the same folder with the same name, for example:</p>
<pre><code>uploads/2022/09/image.png
uploads/2022/09/image.webp
</code... | [
{
"answer_id": 409523,
"author": "Tony Djukic",
"author_id": 60844,
"author_profile": "https://wordpress.stackexchange.com/users/60844",
"pm_score": 1,
"selected": false,
"text": "<p>This just requires adding additional parameters to the <code>query->set()</code> array... ...it's stan... | 2022/09/05 | [
"https://wordpress.stackexchange.com/questions/409255",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/225526/"
] | I want to convert every PNG and JPEG to WebP on upload so that I can serve WebP and PNG/JPEG without requiring the user to upload a WebP version of every photo.
I want to save the WebP in the same folder with the same name, for example:
```
uploads/2022/09/image.png
uploads/2022/09/image.webp
```
How can I do thi... | This just requires adding additional parameters to the `query->set()` array... ...it's standard `WP_Query()` stuff. So you'd essentially be taking this line:
`$query->set( 'post_type', [ 'libri', 'post'] );`
...and expanding it to include a tax query...
```
$tax_query = array(
'relation' => 'OR', //can also use... |
409,338 | <p>I have two files:</p>
<h1>abc.php</h1>
<pre><code><?php
/*
Template Name:ABC Template
*/
?>
<div id="div-image" class="div-child"> <img src="<?php echo get_template_directory_uri(); ?>/Images/Loading.gif" id="load" /> </div>
<script src="... | [
{
"answer_id": 409523,
"author": "Tony Djukic",
"author_id": 60844,
"author_profile": "https://wordpress.stackexchange.com/users/60844",
"pm_score": 1,
"selected": false,
"text": "<p>This just requires adding additional parameters to the <code>query->set()</code> array... ...it's stan... | 2022/09/08 | [
"https://wordpress.stackexchange.com/questions/409338",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/225610/"
] | I have two files:
abc.php
=======
```
<?php
/*
Template Name:ABC Template
*/
?>
<div id="div-image" class="div-child"> <img src="<?php echo get_template_directory_uri(); ?>/Images/Loading.gif" id="load" /> </div>
<script src="<?php echo get_template_directory_uri(); ?>/alphawords.js" type="text/javascript"></script... | This just requires adding additional parameters to the `query->set()` array... ...it's standard `WP_Query()` stuff. So you'd essentially be taking this line:
`$query->set( 'post_type', [ 'libri', 'post'] );`
...and expanding it to include a tax query...
```
$tax_query = array(
'relation' => 'OR', //can also use... |
409,354 | <p>I've implemented <a href="https://code.tutsplus.com/tutorials/create-a-license-controlled-update-system-doing-the-update--cms-22675" rel="nofollow noreferrer">this</a> update class in my plugin, but for some reason the update banner isn't diplayed.</p>
<p>Within the class <code>Wp_License_Manager_Client</code> I hav... | [
{
"answer_id": 409545,
"author": "Prits",
"author_id": 140083,
"author_profile": "https://wordpress.stackexchange.com/users/140083",
"pm_score": 0,
"selected": false,
"text": "<p>You can use this code to check if plugin updates is available :</p>\n<pre><code>add_action('admin_menu', arra... | 2022/09/09 | [
"https://wordpress.stackexchange.com/questions/409354",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/160916/"
] | I've implemented [this](https://code.tutsplus.com/tutorials/create-a-license-controlled-update-system-doing-the-update--cms-22675) update class in my plugin, but for some reason the update banner isn't diplayed.
Within the class `Wp_License_Manager_Client` I have this code:
```
add_filter('pre_set_site_transient_upda... | I ran across this a few weeks ago with a client site - maybe this will help.
```
/**
* Debug Pending Updates
*
* Crude debugging method that will spit out all pending plugin
* and theme updates for admin level users when ?debug_updates is
* added to a /wp-admin/ URL.
*/
function debug_pending_updates() {
/... |
409,409 | <p>Brand new WP application on Cloudways hosting. Their tech support unable to resolve. Updating via backend or WP CLI results in error. Directory created but files not copied into it. Seems to be a PHP error.</p>
<pre><code>Installing Media Cleaner – Clean & Optimize Space (6.4.5) ... | [
{
"answer_id": 409410,
"author": "Chris J. Zähller",
"author_id": 119814,
"author_profile": "https://wordpress.stackexchange.com/users/119814",
"pm_score": 0,
"selected": false,
"text": "<p>Looks like the Cloudways migration didn't complete properly. Reinstalling WordPress from the dashb... | 2022/09/12 | [
"https://wordpress.stackexchange.com/questions/409409",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/119814/"
] | Brand new WP application on Cloudways hosting. Their tech support unable to resolve. Updating via backend or WP CLI results in error. Directory created but files not copied into it. Seems to be a PHP error.
```
Installing Media Cleaner – Clean & Optimize Space (6.4.5) ... | For the benefit of anyone else finding this off the back of a search query, I had the same issue with `fcp_copy_dir()` function not found.
Cause: I'd migrated the site from a Flywheel instance. `fcp_copy_dir()` seems to be a custom Flywheel function they've added to WP core. Core WP runs into errors when run in non-Fl... |
409,446 | <p>I have two custom post type <strong>Author</strong> and <strong>Book</strong>. The book cpt have an <strong>ACF Object Field</strong> (<em>authors_object_field</em>) that is related to authors. On the author single page i want to display all <strong>books</strong> that have the <strong>author</strong> listed in thei... | [
{
"answer_id": 409410,
"author": "Chris J. Zähller",
"author_id": 119814,
"author_profile": "https://wordpress.stackexchange.com/users/119814",
"pm_score": 0,
"selected": false,
"text": "<p>Looks like the Cloudways migration didn't complete properly. Reinstalling WordPress from the dashb... | 2022/09/13 | [
"https://wordpress.stackexchange.com/questions/409446",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/175053/"
] | I have two custom post type **Author** and **Book**. The book cpt have an **ACF Object Field** (*authors\_object\_field*) that is related to authors. On the author single page i want to display all **books** that have the **author** listed in their **ACF Object Field**. I'm using **Elementor** as page builder. I used t... | For the benefit of anyone else finding this off the back of a search query, I had the same issue with `fcp_copy_dir()` function not found.
Cause: I'd migrated the site from a Flywheel instance. `fcp_copy_dir()` seems to be a custom Flywheel function they've added to WP core. Core WP runs into errors when run in non-Fl... |
409,489 | <p>I've originally hard-coded menu links into the mega menu of <a href="https://mandoemedia.com" rel="nofollow noreferrer">mandoemedia.com</a> in order to achieve the icon and description of each link.</p>
<p><a href="https://i.stack.imgur.com/ZQHjv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZQH... | [
{
"answer_id": 409492,
"author": "Steve",
"author_id": 3206,
"author_profile": "https://wordpress.stackexchange.com/users/3206",
"pm_score": 0,
"selected": false,
"text": "<p>I changed the function definition to</p>\n<pre><code>function start_el(&$output, $item, $depth = 0, $args=[],... | 2022/09/14 | [
"https://wordpress.stackexchange.com/questions/409489",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3206/"
] | I've originally hard-coded menu links into the mega menu of [mandoemedia.com](https://mandoemedia.com) in order to achieve the icon and description of each link.
[](https://i.stack.imgur.com/ZQHjv.png)
I'm wondering if it is possible to convert these... | An entirely different approach.
nav menu item are stored in posts table, so you can technically attach a post\_meta into it, even other data like nav item class already stored in post mata table. However this wasn't easy to do before.
but after 5.4.0 release, they have implemented hooks to easily do this.
Here's the... |
409,514 | <p>Did the Pullquote block styles disappear in the editor?</p>
<p>There used to be a <strong>Styles</strong> section in the sidebar panel with the "Default" and "Solid Color" options, as it is written in the <a href="https://wordpress.org/support/article/pullquote-block/" rel="nofollow noreferrer">d... | [
{
"answer_id": 409492,
"author": "Steve",
"author_id": 3206,
"author_profile": "https://wordpress.stackexchange.com/users/3206",
"pm_score": 0,
"selected": false,
"text": "<p>I changed the function definition to</p>\n<pre><code>function start_el(&$output, $item, $depth = 0, $args=[],... | 2022/09/15 | [
"https://wordpress.stackexchange.com/questions/409514",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/66405/"
] | Did the Pullquote block styles disappear in the editor?
There used to be a **Styles** section in the sidebar panel with the "Default" and "Solid Color" options, as it is written in the [documentation](https://wordpress.org/support/article/pullquote-block/):
[ component has [suggestions property](https://developer.wordpress.org/block-editor/reference-guides/components/form-token-field/#properties) which provides a list of suggestions when user start typing.
But, Form... | On a recent project I handled this by just filtering out invalid values in the `onChange` callback:
```
export default () => {
const [value, setValue] = useState([]);
const suggestions = ['lorem', 'ipsum', 'dolor', 'sit', 'amet'];
const onChange = (tokens) => {
const value = tokens.filter((t) => s... |
409,624 | <p>It seems not possible to write :</p>
<pre><code>register_taxonomy('category',array('events'), array(
'hierarchical' => true,
'labels' => $labels_category_events,
'show_ui' => true,
'show_in_rest' =... | [
{
"answer_id": 409629,
"author": "MMK",
"author_id": 148207,
"author_profile": "https://wordpress.stackexchange.com/users/148207",
"pm_score": 0,
"selected": false,
"text": "<p>No, as WordPress by default register a taxonomy called category (which is linked with blog posts). However, yo... | 2022/09/19 | [
"https://wordpress.stackexchange.com/questions/409624",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/201582/"
] | It seems not possible to write :
```
register_taxonomy('category',array('events'), array(
'hierarchical' => true,
'labels' => $labels_category_events,
'show_ui' => true,
'show_in_rest' => true,
'show_... | As said, you can't and here's the list of reserved terms: <https://codex.wordpress.org/Reserved_Terms> |
409,639 | <p>I'm trying to write a function that checks if a specific role exists. I found the following code on the web but it doesn't work for me:</p>
<pre><code>function role_exists( $role ) {
if ( ! empty( $role ) ) {
return $GLOBALS['wp_roles']->is_role( $role );
}
return false;
}
</code></pre>
<p>I ... | [
{
"answer_id": 409629,
"author": "MMK",
"author_id": 148207,
"author_profile": "https://wordpress.stackexchange.com/users/148207",
"pm_score": 0,
"selected": false,
"text": "<p>No, as WordPress by default register a taxonomy called category (which is linked with blog posts). However, yo... | 2022/09/19 | [
"https://wordpress.stackexchange.com/questions/409639",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/225929/"
] | I'm trying to write a function that checks if a specific role exists. I found the following code on the web but it doesn't work for me:
```
function role_exists( $role ) {
if ( ! empty( $role ) ) {
return $GLOBALS['wp_roles']->is_role( $role );
}
return false;
}
```
I get the following error mes... | As said, you can't and here's the list of reserved terms: <https://codex.wordpress.org/Reserved_Terms> |
409,659 | <p>I have some problem with the <a href="https://github.com/deliciousbrains/wp-background-processing" rel="nofollow noreferrer">wp-background-processing</a> that's when I change the <code>$url</code> in another file using <code>$this->process_single->url('https://anotherexample.com');</code> the url won't update ... | [
{
"answer_id": 409660,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": -1,
"selected": false,
"text": "<p>You need to change the method use for the variable $url</p>\n<ul>\n<li><p>public - the property or method can... | 2022/09/20 | [
"https://wordpress.stackexchange.com/questions/409659",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/214004/"
] | I have some problem with the [wp-background-processing](https://github.com/deliciousbrains/wp-background-processing) that's when I change the `$url` in another file using `$this->process_single->url('https://anotherexample.com');` the url won't update in handle function :/ but when I echo it in dispatch, it shows the u... | A huge thanks to @JacobPeattie
We should pass the url to `data` function and retrieve it using `_POST`
so the main file will be:
```php
<?php
/*
Plugin info...
*/
class Example_Background_Processing {
protected $process_single;
public function __construct() {
add_action( 'plugins_loaded', array( $th... |
409,720 | <p>I'm trying to add a new role to my website that is based on administrator's role. I want my new role to have all the capabilities admin has. Problem is, when I log in with my new user, I can't access the admin dashboard. I can only change my profile. Here's my code:</p>
<pre><code>function quick_remove_role() {
... | [
{
"answer_id": 409749,
"author": "ddur",
"author_id": 160028,
"author_profile": "https://wordpress.stackexchange.com/users/160028",
"pm_score": 0,
"selected": false,
"text": "<p>How about <a href=\"https://wpmudev.com/blog/change-wordpress-role-names/\" rel=\"nofollow noreferrer\">renami... | 2022/09/21 | [
"https://wordpress.stackexchange.com/questions/409720",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/225929/"
] | I'm trying to add a new role to my website that is based on administrator's role. I want my new role to have all the capabilities admin has. Problem is, when I log in with my new user, I can't access the admin dashboard. I can only change my profile. Here's my code:
```
function quick_remove_role() {
remove_role( ... | I found the solution to my problem. It had to do with my function that removes the manager role. I commented it out, and it works. My bad. Here's the working code:
```
if ( ! ( role_exists( 'manager' ) ) ) {
function new_role_manager() {
global $wp_roles;
if ( ! isset( $wp_roles ) ) {
... |
409,721 | <p>Each time I attempt to import my test server db into my production server, I get the error below:</p>
<blockquote>
<p>WordPress database error Table 'adminjsds_wordpress.wp_actionscheduler_actions' doesn't exist for query SELECT a.action_id FROM wp_actionscheduler_actions a WHERE 1=1 AND a.hook='action_scheduler/mig... | [
{
"answer_id": 409749,
"author": "ddur",
"author_id": 160028,
"author_profile": "https://wordpress.stackexchange.com/users/160028",
"pm_score": 0,
"selected": false,
"text": "<p>How about <a href=\"https://wpmudev.com/blog/change-wordpress-role-names/\" rel=\"nofollow noreferrer\">renami... | 2022/09/21 | [
"https://wordpress.stackexchange.com/questions/409721",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/190801/"
] | Each time I attempt to import my test server db into my production server, I get the error below:
>
> WordPress database error Table 'adminjsds\_wordpress.wp\_actionscheduler\_actions' doesn't exist for query SELECT a.action\_id FROM wp\_actionscheduler\_actions a WHERE 1=1 AND a.hook='action\_scheduler/migration\_ho... | I found the solution to my problem. It had to do with my function that removes the manager role. I commented it out, and it works. My bad. Here's the working code:
```
if ( ! ( role_exists( 'manager' ) ) ) {
function new_role_manager() {
global $wp_roles;
if ( ! isset( $wp_roles ) ) {
... |
409,777 | <p>I have a user base of hundreds of users, and trying to create a custom API endpoint to get users in a specific membership group.</p>
<p>The database structure is as follows (<strong>using Ultimate Member plugin</strong>):</p>
<ul>
<li>User is stored in <code>wpma_users</code> table</li>
<li>User metadata in table <c... | [
{
"answer_id": 409779,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 2,
"selected": false,
"text": "<p>This isn't possible, you can't safely/reliably query the internals of meta value strings that way, and you c... | 2022/09/23 | [
"https://wordpress.stackexchange.com/questions/409777",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/226048/"
] | I have a user base of hundreds of users, and trying to create a custom API endpoint to get users in a specific membership group.
The database structure is as follows (**using Ultimate Member plugin**):
* User is stored in `wpma_users` table
* User metadata in table `wpma_usermeta` contains user meta named `mygroups`,... | I found a solution, since the serialized array is always structured like this: `':"%s";'`, it is possible to write a meta\_query like:
```
'meta_query' => array(
array(
'key' => 'mygroups',
'value' => sprintf(':"%s";', $groupid),
'compare' => 'LIKE'
)
)
```
Works like a charm! |
409,818 | <p>I'm fairly new at this, so please excuse my ignorance.</p>
<p>I'm trying to order my posts in the site's categories with a button, 'ascending' / 'descending'.</p>
<p>I'm trying to use 'sortit' function because that's the only source I could find online; been working on this all the past week.</p>
<p>So what I did he... | [
{
"answer_id": 409779,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 2,
"selected": false,
"text": "<p>This isn't possible, you can't safely/reliably query the internals of meta value strings that way, and you c... | 2022/09/24 | [
"https://wordpress.stackexchange.com/questions/409818",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/226073/"
] | I'm fairly new at this, so please excuse my ignorance.
I'm trying to order my posts in the site's categories with a button, 'ascending' / 'descending'.
I'm trying to use 'sortit' function because that's the only source I could find online; been working on this all the past week.
So what I did here is;
```
... | I found a solution, since the serialized array is always structured like this: `':"%s";'`, it is possible to write a meta\_query like:
```
'meta_query' => array(
array(
'key' => 'mygroups',
'value' => sprintf(':"%s";', $groupid),
'compare' => 'LIKE'
)
)
```
Works like a charm! |
409,926 | <p>I created a custom taxonomies to work like category called projects to be used for the attachments.</p>
<p>I want to be able to create the archive page without having to use the CMS.</p>
<p>Currently the only thing I can figure out is to manually create the projects CMS page and attach the custom template there.</p>... | [
{
"answer_id": 409928,
"author": "Bob",
"author_id": 225603,
"author_profile": "https://wordpress.stackexchange.com/users/225603",
"pm_score": 0,
"selected": false,
"text": "<p>Did you set public to true? As I can remember without it you can't use your taxonomy in your theme.</p>\n<pre><... | 2022/09/27 | [
"https://wordpress.stackexchange.com/questions/409926",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/2661/"
] | I created a custom taxonomies to work like category called projects to be used for the attachments.
I want to be able to create the archive page without having to use the CMS.
Currently the only thing I can figure out is to manually create the projects CMS page and attach the custom template there.
Here is my code f... | If you register a taxonomy named `projects`, and create `taxonomy-projects.php`, the URL `mysite.com/projects` will not exist. There is no such page in WordPress.
If you create a term inside inside that taxonomy, "My Project", that term will be accessible at `mysite.com/projects/my-project` and that URL will use `taxo... |
409,945 | <p>I use a conditional statement to display a shortcode depending on which category archive is being displayed. The issue I have is that if I use get_queried_object_id, the archive page for the parent term shows the shortcode for the parent term and the first child term.</p>
<p>Here's the code which returns the parent ... | [
{
"answer_id": 409947,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 1,
"selected": false,
"text": "<blockquote>\n<p>The issue I have is that if I use get_queried_object_id, the archive\npage for the parent... | 2022/09/28 | [
"https://wordpress.stackexchange.com/questions/409945",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/226190/"
] | I use a conditional statement to display a shortcode depending on which category archive is being displayed. The issue I have is that if I use get\_queried\_object\_id, the archive page for the parent term shows the shortcode for the parent term and the first child term.
Here's the code which returns the parent **and*... | >
> The issue I have is that if I use get\_queried\_object\_id, the archive
> page for the parent term shows the shortcode for the parent term and
> the first child term.
>
>
>
That's not what's happening. `get_queried_object_id()` will only return the ID of the current category. When you add `[0]` you're just bre... |
409,985 | <p>Regarding to the <strong>performances</strong>, and the performances only (and not from the point of view of the readability of the code), is it a best practice to check if the post has a thumbnail <strong>before</strong> to check if we are on the front-page, the home page, a single page, etc. or to do the opposite ... | [
{
"answer_id": 409987,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 1,
"selected": false,
"text": "<p><strong>Neither, they are just as fast as each other, both are using information that has already been fetch... | 2022/09/29 | [
"https://wordpress.stackexchange.com/questions/409985",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/175093/"
] | Regarding to the **performances**, and the performances only (and not from the point of view of the readability of the code), is it a best practice to check if the post has a thumbnail **before** to check if we are on the front-page, the home page, a single page, etc. or to do the opposite ?
Will my website load faste... | **Neither, they are just as fast as each other, both are using information that has already been fetched in advance. *This is micro-optimising.***
Functions such as `is_front_page` or `is_singular` etc etc are just looking up variables already set in the main query object.
Likewise functions such as `has_post_thumbna... |
410,083 | <p>I have authors posting posts with a custom post type and have users with Editor roles publishing them. How can I get the editors who published them?</p>
| [
{
"answer_id": 410085,
"author": "Patryk Gielo",
"author_id": 226310,
"author_profile": "https://wordpress.stackexchange.com/users/226310",
"pm_score": 0,
"selected": false,
"text": "<p>wordpress don't have native functionality to handle changes around post/page from users. You need to w... | 2022/10/03 | [
"https://wordpress.stackexchange.com/questions/410083",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/217284/"
] | I have authors posting posts with a custom post type and have users with Editor roles publishing them. How can I get the editors who published them? | As far as I know, WordPress only stores original authors of the posts. If you want to also save the publisher's ID, you need to do a bit of custom coding, or use some 3rd party plugin.
Essentially what you need to do is to store the user ID whenever the post status is being changed to `publish`. For that you can use t... |
410,101 | <p>I have a question and couldn't find a solution for it.</p>
<p>We have a Wordpress page where the client wants multiple error pages.</p>
<p>1 error page is in the usual normal 404.php for the custom theme which we created. Now I want to add multiple error pages with different styling and html structure.</p>
<p>exampl... | [
{
"answer_id": 410113,
"author": "Bob",
"author_id": 225603,
"author_profile": "https://wordpress.stackexchange.com/users/225603",
"pm_score": 0,
"selected": false,
"text": "<p>If your client wants only visual differences may be should consider using the get_template_part() function.</p>... | 2022/10/03 | [
"https://wordpress.stackexchange.com/questions/410101",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/223996/"
] | I have a question and couldn't find a solution for it.
We have a Wordpress page where the client wants multiple error pages.
1 error page is in the usual normal 404.php for the custom theme which we created. Now I want to add multiple error pages with different styling and html structure.
example:
```
localhost/blo... | Thank you guys for the help and the tips.
@Dexter0015 Tip helped me in the end to get it done.
This is how my 404.php looks like now im only checking if in the url the string is present and show the template for it.
Thanks everyone again
***edit***:
i changed the search values to /services/ and /blog/ so it was a b... |
410,150 | <p>I have been told here that having my data saved as metadata is creating slow queries.</p>
<p>I'm starting to convert all data used to sort my posts to taxonomy data. I've converted all the data stored in 'wpcf-release-year' to a taxonomy called 'release-year' and have created terms for every year.</p>
<p>Now I'd lik... | [
{
"answer_id": 410113,
"author": "Bob",
"author_id": 225603,
"author_profile": "https://wordpress.stackexchange.com/users/225603",
"pm_score": 0,
"selected": false,
"text": "<p>If your client wants only visual differences may be should consider using the get_template_part() function.</p>... | 2022/10/04 | [
"https://wordpress.stackexchange.com/questions/410150",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/222023/"
] | I have been told here that having my data saved as metadata is creating slow queries.
I'm starting to convert all data used to sort my posts to taxonomy data. I've converted all the data stored in 'wpcf-release-year' to a taxonomy called 'release-year' and have created terms for every year.
Now I'd like to sort posts... | Thank you guys for the help and the tips.
@Dexter0015 Tip helped me in the end to get it done.
This is how my 404.php looks like now im only checking if in the url the string is present and show the template for it.
Thanks everyone again
***edit***:
i changed the search values to /services/ and /blog/ so it was a b... |
410,161 | <p>I am trying to create a pdf using fpdf, which opens in a browser window. Ultimately, the data will be passed from a form submit to a non-existent WP page called pdf.</p>
<p>I am checking for this in template_redirect hook, so if it is pdf being requested, it will generate the pdf, and exit, otherwise will continue f... | [
{
"answer_id": 410113,
"author": "Bob",
"author_id": 225603,
"author_profile": "https://wordpress.stackexchange.com/users/225603",
"pm_score": 0,
"selected": false,
"text": "<p>If your client wants only visual differences may be should consider using the get_template_part() function.</p>... | 2022/10/05 | [
"https://wordpress.stackexchange.com/questions/410161",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/153752/"
] | I am trying to create a pdf using fpdf, which opens in a browser window. Ultimately, the data will be passed from a form submit to a non-existent WP page called pdf.
I am checking for this in template\_redirect hook, so if it is pdf being requested, it will generate the pdf, and exit, otherwise will continue for norma... | Thank you guys for the help and the tips.
@Dexter0015 Tip helped me in the end to get it done.
This is how my 404.php looks like now im only checking if in the url the string is present and show the template for it.
Thanks everyone again
***edit***:
i changed the search values to /services/ and /blog/ so it was a b... |
410,164 | <p>I use plugin for submitting posts from frontend. It's a field builder.
Maybe it uses <code>wp_insert_post()</code> function, I really don't know.</p>
<p>Here I use my custom shortcode, please check here for the code:</p>
<pre><code>function my_custom_shortcode() {
global $wpdb;
$results = $wpdb->get_resul... | [
{
"answer_id": 410113,
"author": "Bob",
"author_id": 225603,
"author_profile": "https://wordpress.stackexchange.com/users/225603",
"pm_score": 0,
"selected": false,
"text": "<p>If your client wants only visual differences may be should consider using the get_template_part() function.</p>... | 2022/10/05 | [
"https://wordpress.stackexchange.com/questions/410164",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/196508/"
] | I use plugin for submitting posts from frontend. It's a field builder.
Maybe it uses `wp_insert_post()` function, I really don't know.
Here I use my custom shortcode, please check here for the code:
```
function my_custom_shortcode() {
global $wpdb;
$results = $wpdb->get_results( "SELECT city FROM slovak_citi... | Thank you guys for the help and the tips.
@Dexter0015 Tip helped me in the end to get it done.
This is how my 404.php looks like now im only checking if in the url the string is present and show the template for it.
Thanks everyone again
***edit***:
i changed the search values to /services/ and /blog/ so it was a b... |
410,178 | <p><a href="https://i.stack.imgur.com/Lmi7B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lmi7B.png" alt="enter image description here" /></a></p>
<p>I got page information. but now I can't print specific data from this array.</p>
<pre><code>$page_details = get_pages( array(
'post_type' => '... | [
{
"answer_id": 410113,
"author": "Bob",
"author_id": 225603,
"author_profile": "https://wordpress.stackexchange.com/users/225603",
"pm_score": 0,
"selected": false,
"text": "<p>If your client wants only visual differences may be should consider using the get_template_part() function.</p>... | 2022/10/05 | [
"https://wordpress.stackexchange.com/questions/410178",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/220933/"
] | [](https://i.stack.imgur.com/Lmi7B.png)
I got page information. but now I can't print specific data from this array.
```
$page_details = get_pages( array(
'post_type' => 'page',
'meta_key' => '_wp_page_template',
'hierarchical' => 0,
... | Thank you guys for the help and the tips.
@Dexter0015 Tip helped me in the end to get it done.
This is how my 404.php looks like now im only checking if in the url the string is present and show the template for it.
Thanks everyone again
***edit***:
i changed the search values to /services/ and /blog/ so it was a b... |
410,298 | <p>I am using this code to center a custom ajax spinner for gravity forms submission.</p>
<ol>
<li><p>The spinner is centered based on the location of the gravity forms. I would like the spinner to be always centered horizontally and vertically, irrespective of the scroll position of the user.</p>
</li>
<li><p>In addit... | [
{
"answer_id": 410282,
"author": "NBgr",
"author_id": 226498,
"author_profile": "https://wordpress.stackexchange.com/users/226498",
"pm_score": 1,
"selected": false,
"text": "<p>Got it - <strong>update_post_meta</strong> has to be used for <strong>_wp_attachment_image_alt</strong></p>\n"... | 2022/10/10 | [
"https://wordpress.stackexchange.com/questions/410298",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40727/"
] | I am using this code to center a custom ajax spinner for gravity forms submission.
1. The spinner is centered based on the location of the gravity forms. I would like the spinner to be always centered horizontally and vertically, irrespective of the scroll position of the user.
2. In addition, the semi-transparent bac... | Got it - **update\_post\_meta** has to be used for **\_wp\_attachment\_image\_alt** |
410,449 | <p>I hope you have a good day.<br/>
I get a query from the database,<br/>
If the query is empty, the message "Register" will be displayed
Otherwise, the message "Register" will be displayed<br/>
See the code below and please guide me.<br/>
<em>Nothing is displayed when the query is empty</em></p>
<p... | [
{
"answer_id": 410282,
"author": "NBgr",
"author_id": 226498,
"author_profile": "https://wordpress.stackexchange.com/users/226498",
"pm_score": 1,
"selected": false,
"text": "<p>Got it - <strong>update_post_meta</strong> has to be used for <strong>_wp_attachment_image_alt</strong></p>\n"... | 2022/10/16 | [
"https://wordpress.stackexchange.com/questions/410449",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/135260/"
] | I hope you have a good day.
I get a query from the database,
If the query is empty, the message "Register" will be displayed
Otherwise, the message "Register" will be displayed
See the code below and please guide me.
*Nothing is displayed when the query is empty*
```
function book_user(){
global $wpdb;... | Got it - **update\_post\_meta** has to be used for **\_wp\_attachment\_image\_alt** |
410,585 | <p>I need to add some shotrcodes for many taxonomies and I would like to display the value terms on a product page of woocommerce.
I tried with this but doesn't work, in this case the taxonomy name is "pagamento"</p>
<pre><code>$terms = get_terms( 'pagamento' );
if ( ! empty( $terms ) && ! is_wp_erro... | [
{
"answer_id": 410282,
"author": "NBgr",
"author_id": 226498,
"author_profile": "https://wordpress.stackexchange.com/users/226498",
"pm_score": 1,
"selected": false,
"text": "<p>Got it - <strong>update_post_meta</strong> has to be used for <strong>_wp_attachment_image_alt</strong></p>\n"... | 2022/10/20 | [
"https://wordpress.stackexchange.com/questions/410585",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/226777/"
] | I need to add some shotrcodes for many taxonomies and I would like to display the value terms on a product page of woocommerce.
I tried with this but doesn't work, in this case the taxonomy name is "pagamento"
```
$terms = get_terms( 'pagamento' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
echo '<ul>'... | Got it - **update\_post\_meta** has to be used for **\_wp\_attachment\_image\_alt** |
410,614 | <p>I've been able to successfully empty the meta_value for a specific meta_key. The problem is that a new meta_key will be created for all users in the database. I do not want all users to have the meta_key created in the database unless it already exist.</p>
<p>I think perhaps if I set 'guest_list_venue_names' as a ... | [
{
"answer_id": 410282,
"author": "NBgr",
"author_id": 226498,
"author_profile": "https://wordpress.stackexchange.com/users/226498",
"pm_score": 1,
"selected": false,
"text": "<p>Got it - <strong>update_post_meta</strong> has to be used for <strong>_wp_attachment_image_alt</strong></p>\n"... | 2022/10/21 | [
"https://wordpress.stackexchange.com/questions/410614",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/226812/"
] | I've been able to successfully empty the meta\_value for a specific meta\_key. The problem is that a new meta\_key will be created for all users in the database. I do not want all users to have the meta\_key created in the database unless it already exist.
I think perhaps if I set 'guest\_list\_venue\_names' as a vari... | Got it - **update\_post\_meta** has to be used for **\_wp\_attachment\_image\_alt** |
410,623 | <p>I have created a new custom post type in wordpress using <strong><code>register_post_type()</code></strong> function But when I click on <strong>add new</strong> in right side the editor not showing <strong>template</strong> choose option as you can see in <strong>Screenshot_01.png</strong>. In <strong>Screenshot_2<... | [
{
"answer_id": 410625,
"author": "t31os",
"author_id": 31073,
"author_profile": "https://wordpress.stackexchange.com/users/31073",
"pm_score": 2,
"selected": false,
"text": "<p>Not sure where these screenshots you're talking about have gone, no matter, i think i know the problem.</p>\n<p... | 2022/10/21 | [
"https://wordpress.stackexchange.com/questions/410623",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/225779/"
] | I have created a new custom post type in wordpress using **`register_post_type()`** function But when I click on **add new** in right side the editor not showing **template** choose option as you can see in **Screenshot\_01.png**. In **Screenshot\_2** you can see the default add post option has the **template** choose ... | Not sure where these screenshots you're talking about have gone, no matter, i think i know the problem.
You simply need to add support for the post type in the templates you want to be able to attach by adjusting the `Template Post Type:` line for the appropriate template files in your theme.
**Example**
```
Templat... |
410,658 | <p>Hello im really stuck and messing around now so i thought i give a try and ask the community.</p>
<p>Im working on a Blog Post page where im showing some posts. The user have the selection to search for posts via a search form or clicking on some categories and filtering the category. This works fine for now. But i ... | [
{
"answer_id": 410670,
"author": "Matheus Alves",
"author_id": 226852,
"author_profile": "https://wordpress.stackexchange.com/users/226852",
"pm_score": 1,
"selected": false,
"text": "<p>Depending on how many categories you will have, I would create result pages for each category.\nI wou... | 2022/10/22 | [
"https://wordpress.stackexchange.com/questions/410658",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/223996/"
] | Hello im really stuck and messing around now so i thought i give a try and ask the community.
Im working on a Blog Post page where im showing some posts. The user have the selection to search for posts via a search form or clicking on some categories and filtering the category. This works fine for now. But i couldn't ... | I found my own Answer:
due to my second array which i created to add some categories the filter only searched for each page separately. with 'cat' i could search for the category and with 's' i could search for a specific value like the title. so i put everything i needed in $args to make it work :
```
$searchBlog = ... |
410,659 | <p>How to upgrade WordPress automatically?</p>
<p>What is the standard way to upgrade an entire WordPress installation --- core <strong>or</strong> core and plugins, automatically?</p>
| [
{
"answer_id": 410660,
"author": "WebDeveloper.IM",
"author_id": 114235,
"author_profile": "https://wordpress.stackexchange.com/users/114235",
"pm_score": 0,
"selected": false,
"text": "<p>One of the advantages of WordPress is that it can be easily upgraded. New versions of WordPress are... | 2022/10/22 | [
"https://wordpress.stackexchange.com/questions/410659",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/226837/"
] | How to upgrade WordPress automatically?
What is the standard way to upgrade an entire WordPress installation --- core **or** core and plugins, automatically? | By default WordPress automatically updates itself, plugins, and themes.
If your WordPress install doesn't do that then you probably have something that disables this.
You can check your theme for something like this
```php
add_filter('auto_update_plugin', '__return_false');
add_filter('auto_update_theme', '__retur... |
410,733 | <p>I want to create a custom plugin to add a login with url functionality to my wordpress sites.</p>
<p>For example, I want to create a link as follows:</p>
<blockquote>
<p><a href="http://www.mysite.com/wp-admin?username=xxxx&pass=xxxxx" rel="nofollow noreferrer">www.mysite.com/wp-admin?username=xxxx&pass=xxxx... | [
{
"answer_id": 410660,
"author": "WebDeveloper.IM",
"author_id": 114235,
"author_profile": "https://wordpress.stackexchange.com/users/114235",
"pm_score": 0,
"selected": false,
"text": "<p>One of the advantages of WordPress is that it can be easily upgraded. New versions of WordPress are... | 2022/10/25 | [
"https://wordpress.stackexchange.com/questions/410733",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/226938/"
] | I want to create a custom plugin to add a login with url functionality to my wordpress sites.
For example, I want to create a link as follows:
>
> [www.mysite.com/wp-admin?username=xxxx&pass=xxxxx](http://www.mysite.com/wp-admin?username=xxxx&pass=xxxxx)
>
>
>
For implementing this i found a code which is to be ... | By default WordPress automatically updates itself, plugins, and themes.
If your WordPress install doesn't do that then you probably have something that disables this.
You can check your theme for something like this
```php
add_filter('auto_update_plugin', '__return_false');
add_filter('auto_update_theme', '__retur... |
410,789 | <p>I'm using a third-party theme with a custom child theme on a website and want to remove the Google Fonts from the parent theme within the child theme's functions.php. This is not working - nothing happens.</p>
<pre><code>/**
* Remove parent theme Google fonts
*/
function remove_parent_theme_google_fonts() {
wp... | [
{
"answer_id": 410791,
"author": "Gui",
"author_id": 182960,
"author_profile": "https://wordpress.stackexchange.com/users/182960",
"pm_score": 1,
"selected": false,
"text": "<p>As Buttered_Toast mentioned, I think the hook you want to use is <code>wp_enqueue_scripts</code> rather than <c... | 2022/10/27 | [
"https://wordpress.stackexchange.com/questions/410789",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40934/"
] | I'm using a third-party theme with a custom child theme on a website and want to remove the Google Fonts from the parent theme within the child theme's functions.php. This is not working - nothing happens.
```
/**
* Remove parent theme Google fonts
*/
function remove_parent_theme_google_fonts() {
wp_dequeue_styl... | As Buttered\_Toast mentioned, I think the hook you want to use is `wp_enqueue_scripts` rather than `after_setup_theme`. Changing the priority is also a good idea to make sure your function trigger after the initial call from the parent theme.
So your function would be:
```
/**
* Remove Accelerate Google fonts
*/
fu... |
410,855 | <p>The following applies to all attchment images on my site:</p>
<p>There is a PNG image attachment, its ID is 519271.</p>
<p><code>wp_get_attachment_image(519271, 'thumbnail', false, array( 'id' => 'esjb-preview-image' ))</code> returns "".</p>
<p><code>wp_get_attachment_image_src(519271)</code> returns <... | [
{
"answer_id": 410864,
"author": "Lisa",
"author_id": 75600,
"author_profile": "https://wordpress.stackexchange.com/users/75600",
"pm_score": 2,
"selected": false,
"text": "<p>Not sure how you're using it, but <code>wp_get_attachment_image_src()</code> returns an array. This should work:... | 2022/10/29 | [
"https://wordpress.stackexchange.com/questions/410855",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/190417/"
] | The following applies to all attchment images on my site:
There is a PNG image attachment, its ID is 519271.
`wp_get_attachment_image(519271, 'thumbnail', false, array( 'id' => 'esjb-preview-image' ))` returns "".
`wp_get_attachment_image_src(519271)` returns `false`.
`wp_attachment_is_image(519271)` returns `true`... | Culprit found!
The `wp_postmeta` table's `meta_id` field didn't have an `auto_increment` attribute.
I have no idea why the malware would remove the attribute.
How I found the solution:
I was checking if `wp_attachment_is('image')` would return true or false for a particular image. It returned false, while `get_post... |
410,860 | <p>I have a function that has a few and/or operators in it. I'm sure there is a better way to write this but can't seem to figure it out. I thought I could use arrays but ran into an issue with having more than one search value I need to check for.</p>
<p>My function: If the user (level 3) has clicked a button, user_me... | [
{
"answer_id": 410879,
"author": "Rup",
"author_id": 3276,
"author_profile": "https://wordpress.stackexchange.com/users/3276",
"pm_score": 0,
"selected": false,
"text": "<p>I don't completely follow what you're trying to do, but:</p>\n<ol>\n<li><p>If the user isn't logged in you probably... | 2022/10/29 | [
"https://wordpress.stackexchange.com/questions/410860",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/210760/"
] | I have a function that has a few and/or operators in it. I'm sure there is a better way to write this but can't seem to figure it out. I thought I could use arrays but ran into an issue with having more than one search value I need to check for.
My function: If the user (level 3) has clicked a button, user\_meta is up... | This answer is completely based on the code and help from -KIKO Software. I did have to add in the global '$current\_user' for it to work correctly. Also, per @kikosoftware foresight, I added a means to track by year, just in case a user did not visit the site until the same quarter the following year.
```
function al... |
410,983 | <p>since version 6.1, wordpress loads classic-themes.min.css on our websites and crashes all of my buttons styles.</p>
<p>I only want to see my own styles in the frontend, so i'm dequeueing WP Styles like this:</p>
<pre><code>function disable_gutenberg_wp_enqueue_scripts() {
wp_dequeue_style('wp-block-library');
... | [
{
"answer_id": 410985,
"author": "emot1onz",
"author_id": 227178,
"author_profile": "https://wordpress.stackexchange.com/users/227178",
"pm_score": 3,
"selected": false,
"text": "<p>Thanks to @t31os</p>\n<p>I achieved dequeuing the stylesheet with this code:</p>\n<pre><code>function disa... | 2022/11/03 | [
"https://wordpress.stackexchange.com/questions/410983",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/227178/"
] | since version 6.1, wordpress loads classic-themes.min.css on our websites and crashes all of my buttons styles.
I only want to see my own styles in the frontend, so i'm dequeueing WP Styles like this:
```
function disable_gutenberg_wp_enqueue_scripts() {
wp_dequeue_style('wp-block-library');
wp_dequeue_style(... | Thanks to @t31os
I achieved dequeuing the stylesheet with this code:
```
function disable_classic_theme_styles() {
wp_deregister_style('classic-theme-styles');
wp_dequeue_style('classic-theme-styles');
}
add_filter('wp_enqueue_scripts', 'disable_classic_theme_styles', 100);
``` |
411,113 | <p>I am using the following code to create a shortcode that generates the url of my website:</p>
<pre><code>add_shortcode( 'base_url', 'baseurl_shortcode' );
function baseurl_shortcode( $atts ) {
return site_url();
}
</code></pre>
<p>However, when the url is generated it has <code>https://</code> at the beginning... | [
{
"answer_id": 411115,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 3,
"selected": true,
"text": "<p>That would be: <code>return parse_url( get_site_url(), PHP_URL_HOST ) );</code></p>\n<p>Explanation:</p>\n<p><a h... | 2022/11/08 | [
"https://wordpress.stackexchange.com/questions/411113",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/179566/"
] | I am using the following code to create a shortcode that generates the url of my website:
```
add_shortcode( 'base_url', 'baseurl_shortcode' );
function baseurl_shortcode( $atts ) {
return site_url();
}
```
However, when the url is generated it has `https://` at the beginning of it. Is there a way to remove th... | That would be: `return parse_url( get_site_url(), PHP_URL_HOST ) );`
Explanation:
[get\_site\_url](https://developer.wordpress.org/reference/functions/get_site_url/) is the WP function that returns the full url (it is the function that `site_url` relies on). [parse\_url](https://www.php.net/manual/en/function.parse-u... |
411,187 | <p>I am using the following code and I can't see anything in the footer of my site on the front end where the wp_footer function is called. It does, however, appear before the opening <code><!DOCTYPE html></code> in the admin area.</p>
<pre><code>function xyz_footer_print() {
echo 'footer script here';
}
add_... | [
{
"answer_id": 411188,
"author": "WebElaine",
"author_id": 102815,
"author_profile": "https://wordpress.stackexchange.com/users/102815",
"pm_score": 2,
"selected": false,
"text": "<p>What's happening here is your <code>echo</code> is executing before anything else.</p>\n<p>Try using the ... | 2022/11/10 | [
"https://wordpress.stackexchange.com/questions/411187",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/66660/"
] | I am using the following code and I can't see anything in the footer of my site on the front end where the wp\_footer function is called. It does, however, appear before the opening `<!DOCTYPE html>` in the admin area.
```
function xyz_footer_print() {
echo 'footer script here';
}
add_action( 'wp_footer', xyz_foot... | That's because you're not using `add_action` correctly, what you've written is functionally the same as this:
```php
function xyz_footer_print() {
echo 'footer script here';
}
$value = xyz_footer_print();
add_action( 'wp_footer', $value );
```
`xyz_footer_print()` immediately runs the function and returns nothin... |
411,323 | <p>I made a WordPress plugin, so now what I want is, I want to set a logic like if a certain theme is active, then load the plugin. Else, only keep the plugin activated, but don't apply any changes on the site.
Any idea how can I achieve that? Sorry if I sound very nerdy :')</p>
| [
{
"answer_id": 411325,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 2,
"selected": true,
"text": "<p>Use <code>get_stylesheet()</code> to get the directory name of the theme being used. If a child theme is... | 2022/11/16 | [
"https://wordpress.stackexchange.com/questions/411323",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/227221/"
] | I made a WordPress plugin, so now what I want is, I want to set a logic like if a certain theme is active, then load the plugin. Else, only keep the plugin activated, but don't apply any changes on the site.
Any idea how can I achieve that? Sorry if I sound very nerdy :') | Use `get_stylesheet()` to get the directory name of the theme being used. If a child theme is being used you can determine the parent with `get_template()`.
At the top of the plugin file you can simply `return` early if the value is not what you want.
```
if ( 'my-theme' !== get_stylesheet() ) {
return;
}
``` |
411,478 | <p>I am pulling a response from an API using PHP to display a list of content on my WordPress website from an external service. The way they have their API set up, I need to create a loop that checks if there is a "next page" of data that I can access. The API returns a header item called "Links", w... | [
{
"answer_id": 411325,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 2,
"selected": true,
"text": "<p>Use <code>get_stylesheet()</code> to get the directory name of the theme being used. If a child theme is... | 2022/11/23 | [
"https://wordpress.stackexchange.com/questions/411478",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/227335/"
] | I am pulling a response from an API using PHP to display a list of content on my WordPress website from an external service. The way they have their API set up, I need to create a loop that checks if there is a "next page" of data that I can access. The API returns a header item called "Links", with the following conte... | Use `get_stylesheet()` to get the directory name of the theme being used. If a child theme is being used you can determine the parent with `get_template()`.
At the top of the plugin file you can simply `return` early if the value is not what you want.
```
if ( 'my-theme' !== get_stylesheet() ) {
return;
}
``` |
411,644 | <p>I made a true/false ACF field called <code>display_sorting</code>. It appears that it returns <code>null</code> no matter if I set the default value or not.</p>
<pre><code><?php var_dump(get_field('display_sorting'));?>
returns :
[...].php:26:null
</code></pre>
<p>If I update the value from the page the field ... | [
{
"answer_id": 411645,
"author": "Harit Panchal",
"author_id": 184415,
"author_profile": "https://wordpress.stackexchange.com/users/184415",
"pm_score": 2,
"selected": false,
"text": "<p>You will need to update every existing post otherwise, you will get NULL every time even if you set t... | 2022/11/29 | [
"https://wordpress.stackexchange.com/questions/411644",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/227910/"
] | I made a true/false ACF field called `display_sorting`. It appears that it returns `null` no matter if I set the default value or not.
```
<?php var_dump(get_field('display_sorting'));?>
returns :
[...].php:26:null
```
If I update the value from the page the field appears, the value will be correctly set to `true` o... | You will need to update every existing post otherwise, you will get NULL every time even if you set the default value to **TRUE**.
You can bulk edit/update altogether. |
411,663 | <p>I want to display an block attribute named "paragraph" that exists in each post inside a CPT named "test".
I have no issues displaying the current page attributes(selectLgColumns & borderClass). The problem is I am not able to get the block attributes from the post that are indise the CPT. I ... | [
{
"answer_id": 411659,
"author": "Scriptile",
"author_id": 125086,
"author_profile": "https://wordpress.stackexchange.com/users/125086",
"pm_score": 1,
"selected": true,
"text": "<p>Ok, so I had 5.5 version of wordpress and it was Incompatible with 8 PHP (on new server) so I updated Word... | 2022/11/29 | [
"https://wordpress.stackexchange.com/questions/411663",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/192926/"
] | I want to display an block attribute named "paragraph" that exists in each post inside a CPT named "test".
I have no issues displaying the current page attributes(selectLgColumns & borderClass). The problem is I am not able to get the block attributes from the post that are indise the CPT. I don't know much php. I used... | Ok, so I had 5.5 version of wordpress and it was Incompatible with 8 PHP (on new server) so I updated Wordpress to 6.1 and it worked. |
411,759 | <p>I am looking for a function to fill a user meta data automatically when they register.</p>
<p>In the registration form we ask for user email. Once they validate their registration, we want to get that value and store it in a custom field (already created) named "Form_URL" like this :
<a href="https://www.o... | [
{
"answer_id": 411659,
"author": "Scriptile",
"author_id": 125086,
"author_profile": "https://wordpress.stackexchange.com/users/125086",
"pm_score": 1,
"selected": true,
"text": "<p>Ok, so I had 5.5 version of wordpress and it was Incompatible with 8 PHP (on new server) so I updated Word... | 2022/12/02 | [
"https://wordpress.stackexchange.com/questions/411759",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/228013/"
] | I am looking for a function to fill a user meta data automatically when they register.
In the registration form we ask for user email. Once they validate their registration, we want to get that value and store it in a custom field (already created) named "Form\_URL" like this :
<https://www.ourwebsite.com/USEREMAIL/fo... | Ok, so I had 5.5 version of wordpress and it was Incompatible with 8 PHP (on new server) so I updated Wordpress to 6.1 and it worked. |