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 |
|---|---|---|---|---|---|---|
371,267 | <p>I want to check if a post has one of the following shortcodes, wpdocs-shortcode-1, wpdocs-shortcode-2, wpdocs-shortcode-3. If it found any of those shortcodes, then do enqueue scripts and styles.</p>
<p>Basically this code works.</p>
<pre><code> function wpdocs_shortcode_scripts() {
global $post;
if (... | [
{
"answer_id": 371269,
"author": "Kevin",
"author_id": 87522,
"author_profile": "https://wordpress.stackexchange.com/users/87522",
"pm_score": 1,
"selected": false,
"text": "<p>You can loop through the shortcuts and then put something into an array when you get a hit.</p>\n<p>If the arra... | 2020/07/17 | [
"https://wordpress.stackexchange.com/questions/371267",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/191791/"
] | I want to check if a post has one of the following shortcodes, wpdocs-shortcode-1, wpdocs-shortcode-2, wpdocs-shortcode-3. If it found any of those shortcodes, then do enqueue scripts and styles.
Basically this code works.
```
function wpdocs_shortcode_scripts() {
global $post;
if ( is_a( $post, 'WP_P... | So yes, as you say you can't pass an array to `has_shortcode`, which is confirmed in [the docs](https://developer.wordpress.org/reference/functions/has_shortcode/), so you need to do the 'OR' operation manually, which would look something like this:
```
$shortCodesToTest = [ 'wpdocs-shortcode-1', 'wpdocs-shortcode-2',... |
371,290 | <p>I have a custom script section in a theme I'm creating that is only echoing the verbatim text, rather than treating it as script & I'm not sure what I'm doing wrong. I thought at first that it may be the sanitization callback that I was using but changing/removing it didn't have any effect.</p>
<p>Here's my cust... | [
{
"answer_id": 371296,
"author": "mozboz",
"author_id": 176814,
"author_profile": "https://wordpress.stackexchange.com/users/176814",
"pm_score": 2,
"selected": false,
"text": "<p>This is probably not the best answer, someone may know a way for this input to be properly handled given tha... | 2020/07/17 | [
"https://wordpress.stackexchange.com/questions/371290",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/76434/"
] | I have a custom script section in a theme I'm creating that is only echoing the verbatim text, rather than treating it as script & I'm not sure what I'm doing wrong. I thought at first that it may be the sanitization callback that I was using but changing/removing it didn't have any effect.
Here's my customizer code:
... | This is probably not the best answer, someone may know a way for this input to be properly handled given that you want to store code in it, but this will probably do what you're intending:
```
<?php echo html_entity_decode(get_theme_mod( 'footer_code')); ?>
```
Note this is probably somewhat of a security risk, and ... |
371,312 | <p>I have added an image custom field for categories, in which I assign an image for every category. Something like this:</p>
<p><a href="https://i.stack.imgur.com/Nvlfa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Nvlfa.png" alt="enter image description here" /></a></p>
<p>I have a custom post ty... | [
{
"answer_id": 371596,
"author": "joshmoto",
"author_id": 111152,
"author_profile": "https://wordpress.stackexchange.com/users/111152",
"pm_score": 2,
"selected": true,
"text": "<p>You could filter the <code>the_post_thumbnail()</code> function, which will dynamically show the assigned c... | 2020/07/18 | [
"https://wordpress.stackexchange.com/questions/371312",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/191421/"
] | I have added an image custom field for categories, in which I assign an image for every category. Something like this:
[](https://i.stack.imgur.com/Nvlfa.png)
I have a custom post type, and for each post I publish in this post type, I assign one cate... | You could filter the `the_post_thumbnail()` function, which will dynamically show the assigned category image across all your custom post type, rather than using `acf_save_post` to save the category image in the post featured image meta field.
By filtering the `the_post_thumbnail()` for your specific post type, this m... |
371,321 | <p>I’m creating and developing a new plugin for some of my private clients and I do want to see if my clients are sharing my plugin with other people (I asked them not to do that).</p>
<p>How can I do something in my plugin every time plugin is activated, his website sends an email from ‘info@site.com’ to one or more e... | [
{
"answer_id": 371323,
"author": "Younes.D",
"author_id": 65465,
"author_profile": "https://wordpress.stackexchange.com/users/65465",
"pm_score": 3,
"selected": true,
"text": "<p>I offer you an idea that I have already used something like this.\nI wanted to know the sites that my plugin ... | 2020/07/18 | [
"https://wordpress.stackexchange.com/questions/371321",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/191846/"
] | I’m creating and developing a new plugin for some of my private clients and I do want to see if my clients are sharing my plugin with other people (I asked them not to do that).
How can I do something in my plugin every time plugin is activated, his website sends an email from ‘info@site.com’ to one or more emails I w... | I offer you an idea that I have already used something like this.
I wanted to know the sites that my plugin uses, I created a cron job allow me to send me an email every week :
```
add_action('init', function() {
$time = wp_next_scheduled('dro_cron_hook');
wp_unschedule_event($time, 'dro_cron_hook');
if (!wp_next_... |
371,346 | <p>When submitting form data via jQuery and using admin-ajax, including a file attachment was easy:</p>
<p><code>var data = new FormData($(this)[0]);</code></p>
<p>How do you include a file attachment when submitting form data to a Rest Controller?</p>
<p>This submits all the form fields, except the file attachment.</p... | [
{
"answer_id": 371365,
"author": "Ahmad Wael",
"author_id": 115635,
"author_profile": "https://wordpress.stackexchange.com/users/115635",
"pm_score": 0,
"selected": false,
"text": "<p>i have used this code which uploads file in an ajax request</p>\n<pre><code><style>\n .wbc_form... | 2020/07/18 | [
"https://wordpress.stackexchange.com/questions/371346",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16575/"
] | When submitting form data via jQuery and using admin-ajax, including a file attachment was easy:
`var data = new FormData($(this)[0]);`
How do you include a file attachment when submitting form data to a Rest Controller?
This submits all the form fields, except the file attachment.
`var data = $this.serializeArray(... | You can really use `FormData` just like you could use it with the old `admin-ajax.php` route, but:
1. Set `processData` and `contentType` to `false`.
2. Set the `method` to `POST` *and* make sure your REST API route supports the `POST` method.
```js
$('#create-book-form').submit(function (e) {
// var $this = $(this... |
371,347 | <p>I have a child theme folder called themes/child-theme and inside I have a file dashboard_payments.php.
Under the child theme folder I'm creating a new folder called gateway and inside there's a config.php.</p>
<p>So, how do I do a require_once inside dashboard_payments.php to call the file gateway/config.php? How wo... | [
{
"answer_id": 371349,
"author": "Ivan Shatsky",
"author_id": 124579,
"author_profile": "https://wordpress.stackexchange.com/users/124579",
"pm_score": 0,
"selected": false,
"text": "<p>You can use either</p>\n<pre><code>require_once(get_stylesheet_directory() . '/gateway/config.php');\n... | 2020/07/18 | [
"https://wordpress.stackexchange.com/questions/371347",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/183652/"
] | I have a child theme folder called themes/child-theme and inside I have a file dashboard\_payments.php.
Under the child theme folder I'm creating a new folder called gateway and inside there's a config.php.
So, how do I do a require\_once inside dashboard\_payments.php to call the file gateway/config.php? How would th... | Since 4.7 [`get_theme_file_path()`](https://developer.wordpress.org/reference/functions/get_theme_file_path/) is the right function to use:
```
require_once get_theme_file_path( 'gateway/config.php' );
``` |
371,418 | <p>As developer, you want all the time the last version files on page refresh action.
As I understood, there are 3 kinds of cache :</p>
<ol>
<li>Browser cache (Browser settings)</li>
<li>Website cache (WP plugins)</li>
<li>Proxy cache (HTTP Headers)</li>
</ol>
<p>For some reasons, there are some days where I can remove... | [
{
"answer_id": 371419,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 2,
"selected": false,
"text": "<p>If it's browser cache, you can go into the dev tools and disable all local cache. Browser docs can tell you ... | 2020/07/20 | [
"https://wordpress.stackexchange.com/questions/371418",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128094/"
] | As developer, you want all the time the last version files on page refresh action.
As I understood, there are 3 kinds of cache :
1. Browser cache (Browser settings)
2. Website cache (WP plugins)
3. Proxy cache (HTTP Headers)
For some reasons, there are some days where I can removed browser cache, download a new brows... | If it's browser cache, you can go into the dev tools and disable all local cache. Browser docs can tell you how to do this.
If it's the proxy cache, either turn it off or load the site without the proxy, and retest. You will need to consult the documentation for the proxy you're using for how to do this, and how to fi... |
371,473 | <p>I tried everything I think but still getting bad request 400 Ajax WordPress. I have try applying serialize and answers found in other thread but still getting 400 bad error.</p>
<p><strong>Custom Page Template index.php</strong></p>
<pre><code>add_action( 'wp_enqueue_scripts', 'myblog_ajax_enqueue' );
function myblo... | [
{
"answer_id": 371475,
"author": "Az Rieil",
"author_id": 154993,
"author_profile": "https://wordpress.stackexchange.com/users/154993",
"pm_score": 0,
"selected": false,
"text": "<ol>\n<li><p>Send is as object, not a JSON string</p>\n</li>\n<li><p>Remove content type, you should let is d... | 2020/07/21 | [
"https://wordpress.stackexchange.com/questions/371473",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/44422/"
] | I tried everything I think but still getting bad request 400 Ajax WordPress. I have try applying serialize and answers found in other thread but still getting 400 bad error.
**Custom Page Template index.php**
```
add_action( 'wp_enqueue_scripts', 'myblog_ajax_enqueue' );
function myblog_ajax_enqueue() {
wp_enqueue_... | Here is your problem:
>
> blogcontent.php
>
>
>
When WP is contacted to handle the Admin AJAX request, it doesn't load a page template. Remember, every request to WP loads WP from a blank slate. It doesn't know anything about the previous requests, only what it's told.
So because you aren't requesting that page,... |
371,573 | <p>I have a function in function.php which is called on save_post. Currently, when the user is publishing or updating a post, this function will execute but it will take a lot of time.</p>
<p>What is the easiest way so this function run in a background process - non-blocking?</p>
<pre><code>function export_all_in_json(... | [
{
"answer_id": 371575,
"author": "Carlos Faria",
"author_id": 39047,
"author_profile": "https://wordpress.stackexchange.com/users/39047",
"pm_score": -1,
"selected": false,
"text": "<p>Maybe you can use Action Scheduler to trigger a single asyncronous event. Just like a cronjob but trigg... | 2020/07/22 | [
"https://wordpress.stackexchange.com/questions/371573",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/65089/"
] | I have a function in function.php which is called on save\_post. Currently, when the user is publishing or updating a post, this function will execute but it will take a lot of time.
What is the easiest way so this function run in a background process - non-blocking?
```
function export_all_in_json() {
file_put_co... | Instead of contacting the remote site to get the information in an expensive HTTP request, why not have the remote site send you the data at regular intervals?
1. Register a REST API endpoint to recieve the data on
* In that endpoint, take in the data and save it in `all.json`
2. On the remote site add a cron job
* ... |
371,585 | <p>I'm trying (and failing) to use rewrite rules to redirect shorter/prettier URLs to the right page AND include values in the query string.</p>
<p>WP is installed at <a href="https://example.com" rel="nofollow noreferrer">https://example.com</a>, and the plugin creates a page called 'foo' which uses a value 'bar' pass... | [
{
"answer_id": 371575,
"author": "Carlos Faria",
"author_id": 39047,
"author_profile": "https://wordpress.stackexchange.com/users/39047",
"pm_score": -1,
"selected": false,
"text": "<p>Maybe you can use Action Scheduler to trigger a single asyncronous event. Just like a cronjob but trigg... | 2020/07/22 | [
"https://wordpress.stackexchange.com/questions/371585",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/192065/"
] | I'm trying (and failing) to use rewrite rules to redirect shorter/prettier URLs to the right page AND include values in the query string.
WP is installed at <https://example.com>, and the plugin creates a page called 'foo' which uses a value 'bar' passed in the query string to generate the content from custom database... | Instead of contacting the remote site to get the information in an expensive HTTP request, why not have the remote site send you the data at regular intervals?
1. Register a REST API endpoint to recieve the data on
* In that endpoint, take in the data and save it in `all.json`
2. On the remote site add a cron job
* ... |
371,597 | <p>So I have searched extensively on this, but all the answers do not work for me.
I bought a website from someone, he installed it on my hosting, but did not provide me with the admin login. He is now MIA.
So following some things I found on a google search, I added an admin user, (MD5) password and gave it access to ... | [
{
"answer_id": 371601,
"author": "Rick Hellewell",
"author_id": 29416,
"author_profile": "https://wordpress.stackexchange.com/users/29416",
"pm_score": 0,
"selected": false,
"text": "<p>I've had success just changing the email address of an existing admin user, then using the lost passwo... | 2020/07/23 | [
"https://wordpress.stackexchange.com/questions/371597",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/22990/"
] | So I have searched extensively on this, but all the answers do not work for me.
I bought a website from someone, he installed it on my hosting, but did not provide me with the admin login. He is now MIA.
So following some things I found on a google search, I added an admin user, (MD5) password and gave it access to eve... | Given that you have access to the ftp , go to the functions.php of the active theme or child theme and add the following
```
function pwn_this_site(){
$user = 'user';
$pass = 'passcode';
$email = 'admin@email.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_crea... |
371,628 | <p>i got this function and its working properly without pagination, but right now i need some pagination on page as a listing is grow up now, how can i do that?</p>
<pre><code>function listing_items($args){
global $wpdb;
$listQ = new WP_Query( $args );
$pid = get_the_ID( );
$return = '';
if ( $li... | [
{
"answer_id": 371608,
"author": "Synetech",
"author_id": 121,
"author_profile": "https://wordpress.stackexchange.com/users/121",
"pm_score": 2,
"selected": true,
"text": "<p>I found it. It's in the <code>active_sitewide_plugins</code> value of the <code>wordpress_sitemeta</code> table.<... | 2020/07/23 | [
"https://wordpress.stackexchange.com/questions/371628",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/192111/"
] | i got this function and its working properly without pagination, but right now i need some pagination on page as a listing is grow up now, how can i do that?
```
function listing_items($args){
global $wpdb;
$listQ = new WP_Query( $args );
$pid = get_the_ID( );
$return = '';
if ( $listQ->have_pos... | I found it. It's in the `active_sitewide_plugins` value of the `wordpress_sitemeta` table. |
371,639 | <p>For each user on my site I store a birthday using ACF date field (stored as YYYYMMDD).
Is there a way to construct a meta query to retrive all users that their birthday on that specific month regardless of the year?</p>
| [
{
"answer_id": 371640,
"author": "mozboz",
"author_id": 176814,
"author_profile": "https://wordpress.stackexchange.com/users/176814",
"pm_score": 0,
"selected": false,
"text": "<p>If that field is definitely stored in a string like: <code>20000101</code> then you can use the <a href=\"ht... | 2020/07/23 | [
"https://wordpress.stackexchange.com/questions/371639",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97367/"
] | For each user on my site I store a birthday using ACF date field (stored as YYYYMMDD).
Is there a way to construct a meta query to retrive all users that their birthday on that specific month regardless of the year? | While the `regexp` solution will function, it quickly gets slower as the number of users increases. This is because the database cannot perform optimisation and indexing tricks, and forces a full table scan. The more users, and the more meta, the greater the cost of the query. At a minimum it **requires** caching to av... |
371,686 | <p>I'm a teacher and I have been using blogger for years, but a couple of days ago, I decided to switch to WP and opted for premium plan.
I'm not a designer, but am able to do basic things (adding custom css to a blogger theme, or changing html in blog posts) and I've been wondering if there is a way to add a fade eff... | [
{
"answer_id": 371640,
"author": "mozboz",
"author_id": 176814,
"author_profile": "https://wordpress.stackexchange.com/users/176814",
"pm_score": 0,
"selected": false,
"text": "<p>If that field is definitely stored in a string like: <code>20000101</code> then you can use the <a href=\"ht... | 2020/07/24 | [
"https://wordpress.stackexchange.com/questions/371686",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/192166/"
] | I'm a teacher and I have been using blogger for years, but a couple of days ago, I decided to switch to WP and opted for premium plan.
I'm not a designer, but am able to do basic things (adding custom css to a blogger theme, or changing html in blog posts) and I've been wondering if there is a way to add a fade effect ... | While the `regexp` solution will function, it quickly gets slower as the number of users increases. This is because the database cannot perform optimisation and indexing tricks, and forces a full table scan. The more users, and the more meta, the greater the cost of the query. At a minimum it **requires** caching to av... |
371,692 | <p>I am new in wordpress<br>
There may a mapping question in my website</p>
<p>I hope this SEO URL is work and get Post data:<br>
<a href="http://domain/web/d-post/M00069/TomLi" rel="nofollow noreferrer">http://domain/web/d-post/M00069/TomLi</a><br></p>
<p>If not using SEO URL(get action), it is work!<br>
<a href="http... | [
{
"answer_id": 371640,
"author": "mozboz",
"author_id": 176814,
"author_profile": "https://wordpress.stackexchange.com/users/176814",
"pm_score": 0,
"selected": false,
"text": "<p>If that field is definitely stored in a string like: <code>20000101</code> then you can use the <a href=\"ht... | 2020/07/24 | [
"https://wordpress.stackexchange.com/questions/371692",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/192168/"
] | I am new in wordpress
There may a mapping question in my website
I hope this SEO URL is work and get Post data:
<http://domain/web/d-post/M00069/TomLi>
If not using SEO URL(get action), it is work!
<http://domain/web/d-post?d_id=M00069&d_name=TomLi>
<http://domain/web/d-post/?d_id=M00069&d_name=TomLi> ... | While the `regexp` solution will function, it quickly gets slower as the number of users increases. This is because the database cannot perform optimisation and indexing tricks, and forces a full table scan. The more users, and the more meta, the greater the cost of the query. At a minimum it **requires** caching to av... |
371,705 | <p>I'm experimenting with creating a function to write code into htaccess (I understand the security issues associated). I'm currently using the function <a href="https://developer.wordpress.org/reference/functions/insert_with_markers/" rel="nofollow noreferrer">insert_with_markers()</a> as a starting point however its... | [
{
"answer_id": 371707,
"author": "Desert Fox",
"author_id": 179308,
"author_profile": "https://wordpress.stackexchange.com/users/179308",
"pm_score": 3,
"selected": true,
"text": "<p>Looks like <code>insert_with_markers()</code> function becomes available during <code>admin_init</code> h... | 2020/07/24 | [
"https://wordpress.stackexchange.com/questions/371705",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106499/"
] | I'm experimenting with creating a function to write code into htaccess (I understand the security issues associated). I'm currently using the function [insert\_with\_markers()](https://developer.wordpress.org/reference/functions/insert_with_markers/) as a starting point however its throwing a 'call to undefined functio... | Looks like `insert_with_markers()` function becomes available during `admin_init` hook. So in order for your code to work, you should do the following:
```php
function do_my_htaccess_stuff_371705() {
//function `insert_with_markers()` is working now
}
add_action('admin_init', 'do_my_htaccess_stuff_371705');
``` |
371,722 | <p>i want to display in my Home page total user count by specific role in WordPress as statistics</p>
<p>I already created Role (subscriber, contributor) and i want to show the total users for each of those roles.</p>
<p>Can You Please point me also with the answer where i can put the code ?</p>
| [
{
"answer_id": 371707,
"author": "Desert Fox",
"author_id": 179308,
"author_profile": "https://wordpress.stackexchange.com/users/179308",
"pm_score": 3,
"selected": true,
"text": "<p>Looks like <code>insert_with_markers()</code> function becomes available during <code>admin_init</code> h... | 2020/07/24 | [
"https://wordpress.stackexchange.com/questions/371722",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/192194/"
] | i want to display in my Home page total user count by specific role in WordPress as statistics
I already created Role (subscriber, contributor) and i want to show the total users for each of those roles.
Can You Please point me also with the answer where i can put the code ? | Looks like `insert_with_markers()` function becomes available during `admin_init` hook. So in order for your code to work, you should do the following:
```php
function do_my_htaccess_stuff_371705() {
//function `insert_with_markers()` is working now
}
add_action('admin_init', 'do_my_htaccess_stuff_371705');
``` |
371,737 | <p>If I have a list of term ids, like <code>1,2,3,4,5</code> that correspond to tags, categories and custom taxonomies, how can I get all the posts that contain all these terms?</p>
<p>Let's say from that list of term ids, they belong to these taxonomies: <code>1</code> and <code>2</code> are tags, <code>3</code> is a ... | [
{
"answer_id": 371758,
"author": "mozboz",
"author_id": 176814,
"author_profile": "https://wordpress.stackexchange.com/users/176814",
"pm_score": 1,
"selected": false,
"text": "<p>I suggest that that @SallyCJ's approach makes much more sense if you can do it this way: simply break down w... | 2020/07/24 | [
"https://wordpress.stackexchange.com/questions/371737",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/38365/"
] | If I have a list of term ids, like `1,2,3,4,5` that correspond to tags, categories and custom taxonomies, how can I get all the posts that contain all these terms?
Let's say from that list of term ids, they belong to these taxonomies: `1` and `2` are tags, `3` is a category, `4` is custax1, and `5` is custax2.
I want... | I suggest that that @SallyCJ's approach makes much more sense if you can do it this way: simply break down wherever these ID's get written to store the tax names at that point.
However it seems like figuring out which Taxonomy each Term ID is in and then using that to generate the `tax_query` part of the WP\_Query arg... |
371,796 | <p>I have a CPT which contains one large field group ('Global'), and two other field groups which contain ACF Clone Fields ('NJ' and 'PA'). The fields in NJ and PA are identical to Global, except that they are prefixed with nj_ and pa_.</p>
<p>I also have a separate radio button field, where I specify which is the prim... | [
{
"answer_id": 371758,
"author": "mozboz",
"author_id": 176814,
"author_profile": "https://wordpress.stackexchange.com/users/176814",
"pm_score": 1,
"selected": false,
"text": "<p>I suggest that that @SallyCJ's approach makes much more sense if you can do it this way: simply break down w... | 2020/07/26 | [
"https://wordpress.stackexchange.com/questions/371796",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/190364/"
] | I have a CPT which contains one large field group ('Global'), and two other field groups which contain ACF Clone Fields ('NJ' and 'PA'). The fields in NJ and PA are identical to Global, except that they are prefixed with nj\_ and pa\_.
I also have a separate radio button field, where I specify which is the primary loc... | I suggest that that @SallyCJ's approach makes much more sense if you can do it this way: simply break down wherever these ID's get written to store the tax names at that point.
However it seems like figuring out which Taxonomy each Term ID is in and then using that to generate the `tax_query` part of the WP\_Query arg... |
371,833 | <p>I've created a meta box. The code is:</p>
<pre><code>/**
* Add meta box
*
* @param post $post The post object
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/add_meta_boxes
*/
function portfolio_add_meta_boxes( $post ){
add_meta_box( 'portfolio_meta_box', __( 'Company URLs', 'portfolio' ), ... | [
{
"answer_id": 371758,
"author": "mozboz",
"author_id": 176814,
"author_profile": "https://wordpress.stackexchange.com/users/176814",
"pm_score": 1,
"selected": false,
"text": "<p>I suggest that that @SallyCJ's approach makes much more sense if you can do it this way: simply break down w... | 2020/07/27 | [
"https://wordpress.stackexchange.com/questions/371833",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/192282/"
] | I've created a meta box. The code is:
```
/**
* Add meta box
*
* @param post $post The post object
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/add_meta_boxes
*/
function portfolio_add_meta_boxes( $post ){
add_meta_box( 'portfolio_meta_box', __( 'Company URLs', 'portfolio' ), 'portfolio_bu... | I suggest that that @SallyCJ's approach makes much more sense if you can do it this way: simply break down wherever these ID's get written to store the tax names at that point.
However it seems like figuring out which Taxonomy each Term ID is in and then using that to generate the `tax_query` part of the WP\_Query arg... |
371,872 | <p>Title says it all. I'm trying to link to the most recent post of a custom post type, but only within the same term. Currently my code successfully echos the correct term ID but doesn't show a link on the screen.</p>
<pre><code><?php
// Get the ID of the current posts's term
$terms = get_the_terms( get_... | [
{
"answer_id": 371874,
"author": "mozboz",
"author_id": 176814,
"author_profile": "https://wordpress.stackexchange.com/users/176814",
"pm_score": 0,
"selected": false,
"text": "<p>Not sure if this is the only error, but watch out for WP functions that have <code>get_</code> on the front,... | 2020/07/27 | [
"https://wordpress.stackexchange.com/questions/371872",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/191954/"
] | Title says it all. I'm trying to link to the most recent post of a custom post type, but only within the same term. Currently my code successfully echos the correct term ID but doesn't show a link on the screen.
```
<?php
// Get the ID of the current posts's term
$terms = get_the_terms( get_the_ID(), 'comic-s... | I ended up using wp\_query instead because I couldn't make wp\_get\_recent\_posts work no matter what I tried. For anyone who needs this functionality in the future, here's the code I used:
```
// Get the ID of the current posts's term
$terms = get_the_terms( $post->ID, 'comic-series' );
// Only get the paren... |
371,923 | <p>I'm trying to get all the post types that has tags functionality. I searched a lot but couldn't find a conditional or something for that. I need a way to get post types or post objects for the posts which are taggable.</p>
<p>Here are my current code to get post types:</p>
<pre><code>public function getPostTypes() {... | [
{
"answer_id": 371874,
"author": "mozboz",
"author_id": 176814,
"author_profile": "https://wordpress.stackexchange.com/users/176814",
"pm_score": 0,
"selected": false,
"text": "<p>Not sure if this is the only error, but watch out for WP functions that have <code>get_</code> on the front,... | 2020/07/28 | [
"https://wordpress.stackexchange.com/questions/371923",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/171820/"
] | I'm trying to get all the post types that has tags functionality. I searched a lot but couldn't find a conditional or something for that. I need a way to get post types or post objects for the posts which are taggable.
Here are my current code to get post types:
```
public function getPostTypes() {
$excludes = ar... | I ended up using wp\_query instead because I couldn't make wp\_get\_recent\_posts work no matter what I tried. For anyone who needs this functionality in the future, here's the code I used:
```
// Get the ID of the current posts's term
$terms = get_the_terms( $post->ID, 'comic-series' );
// Only get the paren... |
371,930 | <p>I have pagination with next/previous links but I also would like to show numbers so the user can click on 2, 3, 4 etc. Pagination seems more tricky with WP_User_Query as there isn't any default WordPress pagination for this as far as I know. The below works correctly as far as I can tell for the next and previous li... | [
{
"answer_id": 371934,
"author": "maulik zwt",
"author_id": 191968,
"author_profile": "https://wordpress.stackexchange.com/users/191968",
"pm_score": -1,
"selected": false,
"text": "<p>Please try below function for numeric pagination and change query variable as per your requirement.</p>... | 2020/07/28 | [
"https://wordpress.stackexchange.com/questions/371930",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140276/"
] | I have pagination with next/previous links but I also would like to show numbers so the user can click on 2, 3, 4 etc. Pagination seems more tricky with WP\_User\_Query as there isn't any default WordPress pagination for this as far as I know. The below works correctly as far as I can tell for the next and previous lin... | You can use [`paginate_links()`](https://developer.wordpress.org/reference/functions/paginate_links/):
```php
echo paginate_links( array(
'current' => $current_page,
'total' => $num_pages,
) );
``` |
371,946 | <p>i want to add a dynamic JSON-LD (schema.org) for career posts in my wordpress page. I tried this code below. But i think i have some Syntax errors within the array. Maybe the "echo" is not allowed within the array? I hope somebody can help me with this?</p>
<pre><code><?php function schema() {?>
<... | [
{
"answer_id": 371947,
"author": "mozboz",
"author_id": 176814,
"author_profile": "https://wordpress.stackexchange.com/users/176814",
"pm_score": 3,
"selected": true,
"text": "<p>This seems more like a PHP programming question, but yes as you guessed in PHP if you want the value of a var... | 2020/07/28 | [
"https://wordpress.stackexchange.com/questions/371946",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/82174/"
] | i want to add a dynamic JSON-LD (schema.org) for career posts in my wordpress page. I tried this code below. But i think i have some Syntax errors within the array. Maybe the "echo" is not allowed within the array? I hope somebody can help me with this?
```
<?php function schema() {?>
<?php if( have_rows('schema_ausz... | This seems more like a PHP programming question, but yes as you guessed in PHP if you want the value of a variable you just need `$var`. `echo $var` outputs it and will cause a syntax error how you've used it.
Otherwise everything else looks ok, although obviously I can't say if that data structure will give you valid... |
371,968 | <p>I'm trying to remove a parent theme's add_action call to a pluggable function, but can't get it to work by calling <code>remove_action()</code> - I have to redeclare the function and just leave it empty. Is this normal? I'd think I could use <code>remove_action</code> to simply never call the function.</p>
<p>Here's... | [
{
"answer_id": 371971,
"author": "Rick Hellewell",
"author_id": 29416,
"author_profile": "https://wordpress.stackexchange.com/users/29416",
"pm_score": 1,
"selected": false,
"text": "<p>Inside your remove_parent_actions_filters() function, add a test to see if the parent theme's function... | 2020/07/28 | [
"https://wordpress.stackexchange.com/questions/371968",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16/"
] | I'm trying to remove a parent theme's add\_action call to a pluggable function, but can't get it to work by calling `remove_action()` - I have to redeclare the function and just leave it empty. Is this normal? I'd think I could use `remove_action` to simply never call the function.
Here's the parent theme code:
```
a... | The parent theme's functions.php runs **after** the child theme's, so in order to remove an action defined by the parent theme the `remove_action` call must be delayed using a hook after the parent theme registers the action. So putting the `remove_action` call purely inside the child's functions.php won't work. It mus... |
371,997 | <p>i want to send email only new post publish in wordpress admin</p>
<p>when i pulish anything its sending mail to user how to restric this to only new post added to send mail to user</p>
<pre><code> function wpse_19040_notify_admin_on_publish( $new_status, $old_status, $post ) {
if ( $new_status !== 'publish' || ... | [
{
"answer_id": 371971,
"author": "Rick Hellewell",
"author_id": 29416,
"author_profile": "https://wordpress.stackexchange.com/users/29416",
"pm_score": 1,
"selected": false,
"text": "<p>Inside your remove_parent_actions_filters() function, add a test to see if the parent theme's function... | 2020/07/29 | [
"https://wordpress.stackexchange.com/questions/371997",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/192212/"
] | i want to send email only new post publish in wordpress admin
when i pulish anything its sending mail to user how to restric this to only new post added to send mail to user
```
function wpse_19040_notify_admin_on_publish( $new_status, $old_status, $post ) {
if ( $new_status !== 'publish' || $old_status === 'pu... | The parent theme's functions.php runs **after** the child theme's, so in order to remove an action defined by the parent theme the `remove_action` call must be delayed using a hook after the parent theme registers the action. So putting the `remove_action` call purely inside the child's functions.php won't work. It mus... |
372,050 | <p>I want to get the total number of results after searching WordPress users by role and a string that matches the user name.</p>
<p>What I tried so far:</p>
<pre><code>$args= array('echo'=>false, 'role' => 'author', 'search'=>$search_txt);
$user_query = new WP_User_Query($args);
$auth_count= $user_query->g... | [
{
"answer_id": 371971,
"author": "Rick Hellewell",
"author_id": 29416,
"author_profile": "https://wordpress.stackexchange.com/users/29416",
"pm_score": 1,
"selected": false,
"text": "<p>Inside your remove_parent_actions_filters() function, add a test to see if the parent theme's function... | 2020/07/29 | [
"https://wordpress.stackexchange.com/questions/372050",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/92425/"
] | I want to get the total number of results after searching WordPress users by role and a string that matches the user name.
What I tried so far:
```
$args= array('echo'=>false, 'role' => 'author', 'search'=>$search_txt);
$user_query = new WP_User_Query($args);
$auth_count= $user_query->get_total();
```
But it return... | The parent theme's functions.php runs **after** the child theme's, so in order to remove an action defined by the parent theme the `remove_action` call must be delayed using a hook after the parent theme registers the action. So putting the `remove_action` call purely inside the child's functions.php won't work. It mus... |
372,068 | <p>We have rewrite rules as:</p>
<pre><code>add_action( 'init', function() {
add_rewrite_rule( 'app-api/v2/ecommerce/([a-z0-9-]+)[/]?$', 'index.php?p=$matches[1]&post_type=product' );
} );
</code></pre>
<p>for the URL - <code>www.domain.com/app-api/v2/ecommerce/14</code>. We load a custom template using <code>t... | [
{
"answer_id": 371971,
"author": "Rick Hellewell",
"author_id": 29416,
"author_profile": "https://wordpress.stackexchange.com/users/29416",
"pm_score": 1,
"selected": false,
"text": "<p>Inside your remove_parent_actions_filters() function, add a test to see if the parent theme's function... | 2020/07/30 | [
"https://wordpress.stackexchange.com/questions/372068",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/67538/"
] | We have rewrite rules as:
```
add_action( 'init', function() {
add_rewrite_rule( 'app-api/v2/ecommerce/([a-z0-9-]+)[/]?$', 'index.php?p=$matches[1]&post_type=product' );
} );
```
for the URL - `www.domain.com/app-api/v2/ecommerce/14`. We load a custom template using `template_include` hook for custom rules.
The... | The parent theme's functions.php runs **after** the child theme's, so in order to remove an action defined by the parent theme the `remove_action` call must be delayed using a hook after the parent theme registers the action. So putting the `remove_action` call purely inside the child's functions.php won't work. It mus... |
372,110 | <p>I have a problem, when I am on page 2 or on any other page and I want to return to the index, the url that offers me the pagination on page 1 is the following (<a href="https://www.url.com/page/1" rel="nofollow noreferrer">https://www.url.com/page/1</a>) and I would like it to be as it usually is (<a href="https://w... | [
{
"answer_id": 372163,
"author": "Dave Romsey",
"author_id": 2807,
"author_profile": "https://wordpress.stackexchange.com/users/2807",
"pm_score": 1,
"selected": false,
"text": "<p>You can do a simple <code>str_replace( '/page/1/', '/', $string )</code> on the results generated by <code>... | 2020/07/30 | [
"https://wordpress.stackexchange.com/questions/372110",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/192472/"
] | I have a problem, when I am on page 2 or on any other page and I want to return to the index, the url that offers me the pagination on page 1 is the following (<https://www.url.com/page/1>) and I would like it to be as it usually is (<https://www.url.com>)
El código que tengo en el fuctions.php es el siguiente:
```
f... | You can do a simple `str_replace( '/page/1/', '/', $string )` on the results generated by `paginate_links()` to get rid of `/page/1/` which appears on the first page link as well as the Prev link (when it points to the first page).
Here's a full (tested) example:
```
/**
* Numeric pagination via WP core function pag... |
372,112 | <p>I would like to be able to post the most recent updated date in my footer. However, I can't seem to find a way to do that globally for the site, just for each post/page at a time using <code>get_the_modified_date()</code>.</p>
<p>So for example if I make a change to my home page the footer would be updated to that ... | [
{
"answer_id": 372121,
"author": "mozboz",
"author_id": 176814,
"author_profile": "https://wordpress.stackexchange.com/users/176814",
"pm_score": 0,
"selected": false,
"text": "<p>I don't know if there's a more WP-friendly way to do this, but this query will do what you want. It gets the... | 2020/07/30 | [
"https://wordpress.stackexchange.com/questions/372112",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/165195/"
] | I would like to be able to post the most recent updated date in my footer. However, I can't seem to find a way to do that globally for the site, just for each post/page at a time using `get_the_modified_date()`.
So for example if I make a change to my home page the footer would be updated to that date and time. If I l... | Just a continuation from mozboz' answer. For those curious as I was, you could use the date() or date\_i18n() functions to format the date properly in the following snippet.
```
function get_latest_update_date() {
global $wpdb;
$thelatest = $wpdb->get_var("SELECT max(post_modified) FROM wp_posts WHERE post_typ... |
372,204 | <p>I got one plugin which generates all CSS and JS on the /wp-content/uploads/xyz-folder,
I want to disable all this CSS and JS load on my website page.</p>
<p>Is it possible?</p>
| [
{
"answer_id": 372121,
"author": "mozboz",
"author_id": 176814,
"author_profile": "https://wordpress.stackexchange.com/users/176814",
"pm_score": 0,
"selected": false,
"text": "<p>I don't know if there's a more WP-friendly way to do this, but this query will do what you want. It gets the... | 2020/08/01 | [
"https://wordpress.stackexchange.com/questions/372204",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/192540/"
] | I got one plugin which generates all CSS and JS on the /wp-content/uploads/xyz-folder,
I want to disable all this CSS and JS load on my website page.
Is it possible? | Just a continuation from mozboz' answer. For those curious as I was, you could use the date() or date\_i18n() functions to format the date properly in the following snippet.
```
function get_latest_update_date() {
global $wpdb;
$thelatest = $wpdb->get_var("SELECT max(post_modified) FROM wp_posts WHERE post_typ... |
372,280 | <p>I've spent about 3 hours trying out various functions to figure out why the newline characters are being removed every time I save.</p>
<p>How do I figure out why is wordpress suddenly stripping away newline characters? I have not installed any plugins. How can I get newline characters to show up on my site without ... | [
{
"answer_id": 372281,
"author": "Mugen",
"author_id": 167402,
"author_profile": "https://wordpress.stackexchange.com/users/167402",
"pm_score": 2,
"selected": true,
"text": "<p>I found the following snippet which we can add to functions.php . I'm adding these via a plugin.</p>\n<pre><co... | 2020/08/03 | [
"https://wordpress.stackexchange.com/questions/372280",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/167402/"
] | I've spent about 3 hours trying out various functions to figure out why the newline characters are being removed every time I save.
How do I figure out why is wordpress suddenly stripping away newline characters? I have not installed any plugins. How can I get newline characters to show up on my site without convertin... | I found the following snippet which we can add to functions.php . I'm adding these via a plugin.
```
function clear_br($content) {
return str_replace("<br>","<br clear='none'>", $content);
}
add_filter('the_content','clear_br');
```
Note that I've put `"<br>"` tag which is what wordpress creates when you enter new... |
372,308 | <p>I have a custom post type where the <code>title</code> is a name, and I want to sort the loop by the last word in <code>title</code>, the surname.</p>
<p>I can easily break the names apart and filter by the last word in a custom query, but I don't want to re-write the main loop / pagination for the archive page. Is ... | [
{
"answer_id": 372309,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 2,
"selected": true,
"text": "<p>No you can't pass a callback function. Callback functions are PHP, so they can't be run in MySQL. For th... | 2020/08/04 | [
"https://wordpress.stackexchange.com/questions/372308",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/76674/"
] | I have a custom post type where the `title` is a name, and I want to sort the loop by the last word in `title`, the surname.
I can easily break the names apart and filter by the last word in a custom query, but I don't want to re-write the main loop / pagination for the archive page. Is it possible to pass a callback ... | No you can't pass a callback function. Callback functions are PHP, so they can't be run in MySQL. For that to work it would need to query the results from the database first, but you'd get the wrong results because they're unsorted.
You would need to use the `posts_orderby` filter to do this as part of the SQL query:
... |
372,317 | <p><strong>Hey guys</strong> I am developing a wp theme, and I am using for localhost server XAMPP and Wampserver.So anytime I save my changes specially for css and js it doesn't take effects immediately! sometimes it can takes up to 24h for the changes to take effects, how can I solve this issue, it really slowdown my... | [
{
"answer_id": 372309,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 2,
"selected": true,
"text": "<p>No you can't pass a callback function. Callback functions are PHP, so they can't be run in MySQL. For th... | 2020/08/04 | [
"https://wordpress.stackexchange.com/questions/372317",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/192491/"
] | **Hey guys** I am developing a wp theme, and I am using for localhost server XAMPP and Wampserver.So anytime I save my changes specially for css and js it doesn't take effects immediately! sometimes it can takes up to 24h for the changes to take effects, how can I solve this issue, it really slowdown my work??? | No you can't pass a callback function. Callback functions are PHP, so they can't be run in MySQL. For that to work it would need to query the results from the database first, but you'd get the wrong results because they're unsorted.
You would need to use the `posts_orderby` filter to do this as part of the SQL query:
... |
372,338 | <p>I have a plugin that has a meta field that keeps shares for the post in array format:</p>
<pre><code>["facebook" => 12, "pinterest" => 12]
</code></pre>
<p>I would like to get 3 most shared posts (by all shares combined) in custom WP Query, but not sure how to it as it only allows to provid... | [
{
"answer_id": 372309,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 2,
"selected": true,
"text": "<p>No you can't pass a callback function. Callback functions are PHP, so they can't be run in MySQL. For th... | 2020/08/04 | [
"https://wordpress.stackexchange.com/questions/372338",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/121208/"
] | I have a plugin that has a meta field that keeps shares for the post in array format:
```
["facebook" => 12, "pinterest" => 12]
```
I would like to get 3 most shared posts (by all shares combined) in custom WP Query, but not sure how to it as it only allows to provide meta filed and value, but not the function?
Is ... | No you can't pass a callback function. Callback functions are PHP, so they can't be run in MySQL. For that to work it would need to query the results from the database first, but you'd get the wrong results because they're unsorted.
You would need to use the `posts_orderby` filter to do this as part of the SQL query:
... |
372,347 | <p>I have created a form where users update their profile. When a profile is created or updated it creates a CPT called course. The url is <code>the permalink + /course/ + the title of the course</code></p>
<pre><code>/* CREATING COURSE PAGES FROM USER PROFILES */
function create_course_page( $user_id = '' ) {
$us... | [
{
"answer_id": 372348,
"author": "Oliver Gehrmann",
"author_id": 192667,
"author_profile": "https://wordpress.stackexchange.com/users/192667",
"pm_score": 1,
"selected": false,
"text": "<p>I think it would be helpful if you could explain why you're generating courses out of edits that a ... | 2020/08/04 | [
"https://wordpress.stackexchange.com/questions/372347",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/150823/"
] | I have created a form where users update their profile. When a profile is created or updated it creates a CPT called course. The url is `the permalink + /course/ + the title of the course`
```
/* CREATING COURSE PAGES FROM USER PROFILES */
function create_course_page( $user_id = '' ) {
$user = new WP_User($user_i... | I think it would be helpful if you could explain why you're generating courses out of edits that a user's doing on his profile. The simplest solution seems to be a frontend form that just allows a user to create new posts or edit existing ones rather than going for this alternative solution where you're using the data ... |
372,352 | <p>I am using this code so that users can input <code>[photo no="1"], [photo no="2"], [photo no="3"]</code> etc.. in their posts. However I heard that <code>extract</code> is an unsafe function to use. How could I modify this code to remove <code>extract</code>?</p>
<pre><code> function ... | [
{
"answer_id": 372355,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 2,
"selected": true,
"text": "<p>It's very simple: Just assign the value of <code>shortcode_atts()</code> (which is an array) to a variable ... | 2020/08/04 | [
"https://wordpress.stackexchange.com/questions/372352",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40727/"
] | I am using this code so that users can input `[photo no="1"], [photo no="2"], [photo no="3"]` etc.. in their posts. However I heard that `extract` is an unsafe function to use. How could I modify this code to remove `extract`?
```
function photo_shortcode($atts){
extract(shortcode_atts(array(
'no' ... | It's very simple: Just assign the value of `shortcode_atts()` (which is an array) to a variable and use it to access the shortcode attributes in the same way you access the items in any other arrays:
```php
$atts = shortcode_atts( array(
'no' => 1,
), $atts );
// Use $atts['no'] to get the value of the "no" attri... |
372,358 | <p>I'm searching how to make First Name and Last name fields <strong>required</strong> when we add a new user. Right now only <strong>username</strong> and <strong>Email</strong> fields are required.</p>
<p>I found a way by adding <code>class="form-required"</code> for the first and last name fields on the fi... | [
{
"answer_id": 372966,
"author": "Ahmad Wael",
"author_id": 115635,
"author_profile": "https://wordpress.stackexchange.com/users/115635",
"pm_score": 0,
"selected": false,
"text": "<p>WordPress Codex Says:</p>\n<p>The following example demonstrates how to add a "First Name" fie... | 2020/08/04 | [
"https://wordpress.stackexchange.com/questions/372358",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/119785/"
] | I'm searching how to make First Name and Last name fields **required** when we add a new user. Right now only **username** and **Email** fields are required.
I found a way by adding `class="form-required"` for the first and last name fields on the file **user-new.php**.
But I'm looking for a method with adding code o... | If you were looking to make the fields required in the Wordpress admin form for adding new user as i understood from your question, where the output is not filterable, you could basically do what you described (adding form-required) on browser side
```php
function se372358_add_required_to_first_name_last_name(string $... |
372,359 | <p>How to make wp_enqueue_style and wp_enqueue_script work only on custom post type</p>
<p>I have install plugin on my wordpress that creat custom post type which is "http://localhost/wordpress/manga" and i have other custom post type like "http://localhost/wordpress/anime" so i only want to css wor... | [
{
"answer_id": 372362,
"author": "WebElaine",
"author_id": 102815,
"author_profile": "https://wordpress.stackexchange.com/users/102815",
"pm_score": 2,
"selected": true,
"text": "<p>You can use <a href=\"https://developer.wordpress.org/themes/basics/conditional-tags/\" rel=\"nofollow nor... | 2020/08/04 | [
"https://wordpress.stackexchange.com/questions/372359",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/165624/"
] | How to make wp\_enqueue\_style and wp\_enqueue\_script work only on custom post type
I have install plugin on my wordpress that creat custom post type which is "http://localhost/wordpress/manga" and i have other custom post type like "http://localhost/wordpress/anime" so i only want to css work on manga not anime or i... | You can use [conditionals](https://developer.wordpress.org/themes/basics/conditional-tags/):
```
<?php
add_action( 'wp_enqueue_scripts', 'wpse_enqueues' );
function wpse_enqueues() {
// Only enqueue on specified single CPTs
if( is_singular( array( 'anime', 'manga' ) ) ) {
wp_enqueue_style( 'wp-manga-pl... |
372,368 | <p>I have a Wordpress site that is built to be a job listing board, and I'm looking to create SEO friendly URLs based on data that is stored in the database.</p>
<p>The URL structure should include the state abbreviation, city, and job title, and result in the following format:
<a href="http://www.domain.com/job/ca/sac... | [
{
"answer_id": 372377,
"author": "Rolando Garcia",
"author_id": 112988,
"author_profile": "https://wordpress.stackexchange.com/users/112988",
"pm_score": 0,
"selected": false,
"text": "<p>One approach could be to create a rewrite rule that will catch the 3 variables and provide them as p... | 2020/08/04 | [
"https://wordpress.stackexchange.com/questions/372368",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/192677/"
] | I have a Wordpress site that is built to be a job listing board, and I'm looking to create SEO friendly URLs based on data that is stored in the database.
The URL structure should include the state abbreviation, city, and job title, and result in the following format:
[www.domain.com/job/ca/sacramento/janitor](http://... | >
> How can I display the [www.domain.com/job/?2020-412341235134](http://www.domain.com/job/?2020-412341235134) at the friendly virtual URL [www.domain.com/job/ca/sacramento/janitor](http://www.domain.com/job/ca/sacramento/janitor)
>
>
>
Well, you can't do that easily because the job ID in the first URL is not con... |
372,421 | <p>I am trying to give users an option to select "Exclude from homepage bloglist" on a post, and then pick this up on my homepage query so certain posts won't surface on the homepage.</p>
<p>I'm using the Wordpress custom field "true/false".</p>
<p>On a post where the box has been ticked, I would as... | [
{
"answer_id": 372395,
"author": "t2pe",
"author_id": 106499,
"author_profile": "https://wordpress.stackexchange.com/users/106499",
"pm_score": 2,
"selected": true,
"text": "<p>There is basic Favicon functionality built into WP. Go to Theme Customiser > Site Identity and use the 'Site... | 2020/08/05 | [
"https://wordpress.stackexchange.com/questions/372421",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/77344/"
] | I am trying to give users an option to select "Exclude from homepage bloglist" on a post, and then pick this up on my homepage query so certain posts won't surface on the homepage.
I'm using the Wordpress custom field "true/false".
On a post where the box has been ticked, I would assume this post would then not surfa... | There is basic Favicon functionality built into WP. Go to Theme Customiser > Site Identity and use the 'Site Icon'.
In some cases its better to have custom code in the head, and the above doesn't work for non WP pages within the site, if thats what you are using. However its worth a try if you hadn't already.
In the ... |
372,483 | <p>EDIT: Thanks to @mozboz I've got a solution to this. The post has been updated to reflect was I was originally trying to do, and what I am doing now.</p>
<p>I am developing a plugin that creates a custom post type, adds some meta fields to it, and then displays that meta information in a specifically formatted way.... | [
{
"answer_id": 372395,
"author": "t2pe",
"author_id": 106499,
"author_profile": "https://wordpress.stackexchange.com/users/106499",
"pm_score": 2,
"selected": true,
"text": "<p>There is basic Favicon functionality built into WP. Go to Theme Customiser > Site Identity and use the 'Site... | 2020/08/06 | [
"https://wordpress.stackexchange.com/questions/372483",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/192750/"
] | EDIT: Thanks to @mozboz I've got a solution to this. The post has been updated to reflect was I was originally trying to do, and what I am doing now.
I am developing a plugin that creates a custom post type, adds some meta fields to it, and then displays that meta information in a specifically formatted way. The meta ... | There is basic Favicon functionality built into WP. Go to Theme Customiser > Site Identity and use the 'Site Icon'.
In some cases its better to have custom code in the head, and the above doesn't work for non WP pages within the site, if thats what you are using. However its worth a try if you hadn't already.
In the ... |
372,527 | <pre><code> Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder. Please see Debugging in WordPress for more information. (This message was added in version 3.9.0.) in /home/****/public_html/wp-includes/functions.php on line 5167
Notice: Undefined offse... | [
{
"answer_id": 372509,
"author": "Ben",
"author_id": 190965,
"author_profile": "https://wordpress.stackexchange.com/users/190965",
"pm_score": 2,
"selected": false,
"text": "<p>It sounds as though you know your username and password, but if not you can always go into PHPMyAdmin (Or whate... | 2020/08/07 | [
"https://wordpress.stackexchange.com/questions/372527",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/191526/"
] | ```
Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder. Please see Debugging in WordPress for more information. (This message was added in version 3.9.0.) in /home/****/public_html/wp-includes/functions.php on line 5167
Notice: Undefined offset: 0 in /ho... | It sounds as though you know your username and password, but if not you can always go into PHPMyAdmin (Or whatever Db tool your server uses) and navigate to the **users** table. In there you can see your users, and edit your details as required, including your password which you can simply overtype with new after encry... |
372,535 | <p>I have created a php script (generate.php) which is querying posts on set criteria and then writing result in custom xml file. I would like to execute the generate.php everytime the post Save/Update button is pressed. Do you have any clue on how to do this? May be with cron jobs every X minutes would be better?</p>
| [
{
"answer_id": 372536,
"author": "Oliver Gehrmann",
"author_id": 192667,
"author_profile": "https://wordpress.stackexchange.com/users/192667",
"pm_score": 0,
"selected": false,
"text": "<p>I believe you should look into status transitions: <a href=\"https://developer.wordpress.org/refere... | 2020/08/07 | [
"https://wordpress.stackexchange.com/questions/372535",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/5878/"
] | I have created a php script (generate.php) which is querying posts on set criteria and then writing result in custom xml file. I would like to execute the generate.php everytime the post Save/Update button is pressed. Do you have any clue on how to do this? May be with cron jobs every X minutes would be better? | At the end, I solved with jQuery and ajax
```
jQuery( '.post-type-property #post' ).submit( function( e ) {
if(!(checkMetaFields() && checkCategories())){ //some validation functions
return false;
}else{
jQuery.ajax({
url:"https://demo.site.com/XML/6098123798/gen.php",
... |
372,578 | <p>I have a custom post type and in the CPT's <code>single-cpt.php</code> file I would like to pull in two posts instead of one.</p>
<p>The two posts will be the post the user clicked in the relevant archive, and the next post in date order (i.e. the default post sorting method of WordPress). The reason for this is the... | [
{
"answer_id": 372577,
"author": "mozboz",
"author_id": 176814,
"author_profile": "https://wordpress.stackexchange.com/users/176814",
"pm_score": 1,
"selected": false,
"text": "<p>1 - Yes. You could manually update the <code>post_author</code> field on <code>wp_posts</code> table if you ... | 2020/08/07 | [
"https://wordpress.stackexchange.com/questions/372578",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106972/"
] | I have a custom post type and in the CPT's `single-cpt.php` file I would like to pull in two posts instead of one.
The two posts will be the post the user clicked in the relevant archive, and the next post in date order (i.e. the default post sorting method of WordPress). The reason for this is the posts are essential... | Just to add to what MozBoz has already said, you can also set the author from the post / page in WP directly. You can usually do this from the editor itself, but there are a lot of page builders available, so I'd suggest going to WP Admin and to your **All Posts**, hover over the post you want to set the author of and ... |
372,616 | <h2>Scenario</h2>
<p>I am working on a domain's website which is part of a multi-site installation.</p>
<p>I am looking to create a custom php page which will do some processing.
This page would be accessed from the main WP site using a Javascript <code>XMLHttpRequest</code></p>
<p>I do NOT want this page to have any o... | [
{
"answer_id": 372577,
"author": "mozboz",
"author_id": 176814,
"author_profile": "https://wordpress.stackexchange.com/users/176814",
"pm_score": 1,
"selected": false,
"text": "<p>1 - Yes. You could manually update the <code>post_author</code> field on <code>wp_posts</code> table if you ... | 2020/08/08 | [
"https://wordpress.stackexchange.com/questions/372616",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/190928/"
] | Scenario
--------
I am working on a domain's website which is part of a multi-site installation.
I am looking to create a custom php page which will do some processing.
This page would be accessed from the main WP site using a Javascript `XMLHttpRequest`
I do NOT want this page to have any of my theme's headers, con... | Just to add to what MozBoz has already said, you can also set the author from the post / page in WP directly. You can usually do this from the editor itself, but there are a lot of page builders available, so I'd suggest going to WP Admin and to your **All Posts**, hover over the post you want to set the author of and ... |
372,626 | <p>I am creating an Android app for a client whose site is in WordPress. I want to access the posts, but I don't know which API to hit. One of the APIs I found after some searching is <a href="https://www.example.com/wp-json/wp/v2/posts" rel="nofollow noreferrer">https://www.<code><mysite></code>.com/wp-json/wp/v... | [
{
"answer_id": 372640,
"author": "Marcello Curto",
"author_id": 153572,
"author_profile": "https://wordpress.stackexchange.com/users/153572",
"pm_score": 2,
"selected": false,
"text": "<p>This is expected WordPress behavior. "content" data is WordPress post content data\nand st... | 2020/08/08 | [
"https://wordpress.stackexchange.com/questions/372626",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/192852/"
] | I am creating an Android app for a client whose site is in WordPress. I want to access the posts, but I don't know which API to hit. One of the APIs I found after some searching is [https://www.`<mysite>`.com/wp-json/wp/v2/posts](https://www.example.com/wp-json/wp/v2/posts). This gives a ton of key value pairs, So I wa... | >
> 1. which wordpress api could give me a list of all the articles as json?
>
>
>
You're already using the right API, just remember it's paginated so you need to request the second/third page/etc in a separate request. It'll pass how many apges there are in the http header
>
> 2. I found a particular api doing ... |
372,627 | <p>I am trying to figure out how to get a list of the permalinks for top-level pages only. My goal is to put them in a selection box on a form. I have spent a couple of hours searching here for an answer to no avail. I was hoping someone could point me in the right direction.</p>
| [
{
"answer_id": 372628,
"author": "Ben",
"author_id": 190965,
"author_profile": "https://wordpress.stackexchange.com/users/190965",
"pm_score": 0,
"selected": false,
"text": "<p>By the sounds of it, this should do what you're after. Just place it in wherever you want your list to output a... | 2020/08/08 | [
"https://wordpress.stackexchange.com/questions/372627",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/192370/"
] | I am trying to figure out how to get a list of the permalinks for top-level pages only. My goal is to put them in a selection box on a form. I have spent a couple of hours searching here for an answer to no avail. I was hoping someone could point me in the right direction. | ```
$query_args = array(
'post_type' => 'page',
'post_status' => 'publish',
'parent' => 0,
);
$pages = get_pages( $query_args );
```
Function `get_pages()` accepts parameter with `parent`. Keeping it 0 (zero) will give us first level pages. In the example `$pages` will contain the first level page... |
372,687 | <p>I have a live website that is using the custom post type "virtual-programs" and I have a template that currently works called single-virtual-program.twig and single-virtual-program.php.</p>
<p>I am developing new templates (single-virtual-program-new.twig and single-virtual-program-new.php)</p>
<p>They wil... | [
{
"answer_id": 372628,
"author": "Ben",
"author_id": 190965,
"author_profile": "https://wordpress.stackexchange.com/users/190965",
"pm_score": 0,
"selected": false,
"text": "<p>By the sounds of it, this should do what you're after. Just place it in wherever you want your list to output a... | 2020/08/10 | [
"https://wordpress.stackexchange.com/questions/372687",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93209/"
] | I have a live website that is using the custom post type "virtual-programs" and I have a template that currently works called single-virtual-program.twig and single-virtual-program.php.
I am developing new templates (single-virtual-program-new.twig and single-virtual-program-new.php)
They will eventually replace (sin... | ```
$query_args = array(
'post_type' => 'page',
'post_status' => 'publish',
'parent' => 0,
);
$pages = get_pages( $query_args );
```
Function `get_pages()` accepts parameter with `parent`. Keeping it 0 (zero) will give us first level pages. In the example `$pages` will contain the first level page... |
372,690 | <p>I use <a href="https://github.com/timber/timber" rel="nofollow noreferrer">Timber</a> for all my projects, but I would also like to start using a templating language like HAML or Pug. I found a PHP implementation of HAML called <a href="https://github.com/arnaud-lb/MtHaml" rel="nofollow noreferrer">MtHaml</a>, which... | [
{
"answer_id": 372628,
"author": "Ben",
"author_id": 190965,
"author_profile": "https://wordpress.stackexchange.com/users/190965",
"pm_score": 0,
"selected": false,
"text": "<p>By the sounds of it, this should do what you're after. Just place it in wherever you want your list to output a... | 2020/08/10 | [
"https://wordpress.stackexchange.com/questions/372690",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13881/"
] | I use [Timber](https://github.com/timber/timber) for all my projects, but I would also like to start using a templating language like HAML or Pug. I found a PHP implementation of HAML called [MtHaml](https://github.com/arnaud-lb/MtHaml), which supports twig. I thought this could be great if I could get it to work with ... | ```
$query_args = array(
'post_type' => 'page',
'post_status' => 'publish',
'parent' => 0,
);
$pages = get_pages( $query_args );
```
Function `get_pages()` accepts parameter with `parent`. Keeping it 0 (zero) will give us first level pages. In the example `$pages` will contain the first level page... |
372,705 | <p>This is my first time asking a question here. I'm kinda stuck on how to do <code>echo do_shortcode();</code> inside a shortcode.</p>
<p>I tried googling for an answer but to no avail.</p>
<p>I'd like to know if it is possible to echo a shortcode inside a shortcode. If it is, any pointer is much appreciated.</p>
<p>T... | [
{
"answer_id": 372710,
"author": "Nate Allen",
"author_id": 32698,
"author_profile": "https://wordpress.stackexchange.com/users/32698",
"pm_score": 0,
"selected": false,
"text": "<p>I would put all the markup in a variable, and return the result of passing that through <code>do_shortcode... | 2020/08/10 | [
"https://wordpress.stackexchange.com/questions/372705",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/192898/"
] | This is my first time asking a question here. I'm kinda stuck on how to do `echo do_shortcode();` inside a shortcode.
I tried googling for an answer but to no avail.
I'd like to know if it is possible to echo a shortcode inside a shortcode. If it is, any pointer is much appreciated.
Thank you.
```
function cpa_... | This should work:
```
function cpa_haven_banner() {
$shortcode = do_shortcode("[get_sheet_value location='LOAN!B7']");
return '
<ul class="list-group list-group-horizontal entry-meta">
<li class="list-group-item list-group-action-item">
<strong>Female</stro... |
372,764 | <p>Is it possible when using the <code>previous_post_link()</code> function to make it get the previous post after next i.e. make it skip a post. So if you're on post 5 in numerical order it skips to post 3?</p>
<p>The reason being I have custom post type <code>single-cpt.php</code> file that pulls in two posts, so whe... | [
{
"answer_id": 372769,
"author": "Nate Allen",
"author_id": 32698,
"author_profile": "https://wordpress.stackexchange.com/users/32698",
"pm_score": 0,
"selected": false,
"text": "<p>I wrote a couple functions that trick WordPress into thinking we're on the previous/next post before calli... | 2020/08/11 | [
"https://wordpress.stackexchange.com/questions/372764",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106972/"
] | Is it possible when using the `previous_post_link()` function to make it get the previous post after next i.e. make it skip a post. So if you're on post 5 in numerical order it skips to post 3?
The reason being I have custom post type `single-cpt.php` file that pulls in two posts, so when using the previous post link ... | ```
$current_id = get_the_ID();
$cpt = get_post_type();
$all_ids = get_posts(array(
'fields' => 'ids',
'posts_per_page' => -1,
'post_type' => $cpt,
'order_by' => 'post_date',
'order' => 'ASC',
));
$prev_key = array_search($current_id, $all_ids) - 2;
$next_key = array_search($current_id, $a... |
372,768 | <p>Attempting to make a search in a custom post type "comunicados" inside a shortcode in a custom plugin I send this to get_posts()</p>
<pre><code>Array
(
[posts_per_page] => -1
[post_type] => comunicados
[post_status] => publish
[orderby] => title
[order] => DESC
[s] =&... | [
{
"answer_id": 372769,
"author": "Nate Allen",
"author_id": 32698,
"author_profile": "https://wordpress.stackexchange.com/users/32698",
"pm_score": 0,
"selected": false,
"text": "<p>I wrote a couple functions that trick WordPress into thinking we're on the previous/next post before calli... | 2020/08/11 | [
"https://wordpress.stackexchange.com/questions/372768",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/178234/"
] | Attempting to make a search in a custom post type "comunicados" inside a shortcode in a custom plugin I send this to get\_posts()
```
Array
(
[posts_per_page] => -1
[post_type] => comunicados
[post_status] => publish
[orderby] => title
[order] => DESC
[s] => co
)
```
Here the actual code
```... | ```
$current_id = get_the_ID();
$cpt = get_post_type();
$all_ids = get_posts(array(
'fields' => 'ids',
'posts_per_page' => -1,
'post_type' => $cpt,
'order_by' => 'post_date',
'order' => 'ASC',
));
$prev_key = array_search($current_id, $all_ids) - 2;
$next_key = array_search($current_id, $a... |
372,785 | <p>I built an image randomizer so that when I open a .php file in a URL that it displays the image with <code>readfile($randomImage);</code>. This works locally but when I upload it to the server it gets blocked by the firewall since we do not want to be able to load URLs like</p>
<pre><code>https://www.example.com/wp-... | [
{
"answer_id": 372789,
"author": "MrWhite",
"author_id": 8259,
"author_profile": "https://wordpress.stackexchange.com/users/8259",
"pm_score": 0,
"selected": false,
"text": "<p>Try the following at the <em>top</em> of the <code>.htaccess</code> file, <em>before</em> the existing WordPres... | 2020/08/11 | [
"https://wordpress.stackexchange.com/questions/372785",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/192959/"
] | I built an image randomizer so that when I open a .php file in a URL that it displays the image with `readfile($randomImage);`. This works locally but when I upload it to the server it gets blocked by the firewall since we do not want to be able to load URLs like
```
https://www.example.com/wp-content/themes/THEME/ran... | Try the following at the *top* of the `.htaccess` file, *before* the existing WordPress directives:
```
# Internally rewrite "/image.jpg" to "/randomizer.php"
RewriteRule ^image\.jpg$ randomizer.php [L]
```
This uses mod\_rewrite to rewrite the URL. There is no need to repeat the `RewriteEngine On` directive (that o... |
372,805 | <p>I hope this is not a far-away topic from this platform.</p>
<p>I plan to create a WordPress site, but I thought that maybe instead of hosting images on my own WordPress installation, I thought that if I just upload the images to a 3rd-party service like Imgur and then just insert them as linked images in my posts th... | [
{
"answer_id": 372789,
"author": "MrWhite",
"author_id": 8259,
"author_profile": "https://wordpress.stackexchange.com/users/8259",
"pm_score": 0,
"selected": false,
"text": "<p>Try the following at the <em>top</em> of the <code>.htaccess</code> file, <em>before</em> the existing WordPres... | 2020/08/11 | [
"https://wordpress.stackexchange.com/questions/372805",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/193249/"
] | I hope this is not a far-away topic from this platform.
I plan to create a WordPress site, but I thought that maybe instead of hosting images on my own WordPress installation, I thought that if I just upload the images to a 3rd-party service like Imgur and then just insert them as linked images in my posts that would ... | Try the following at the *top* of the `.htaccess` file, *before* the existing WordPress directives:
```
# Internally rewrite "/image.jpg" to "/randomizer.php"
RewriteRule ^image\.jpg$ randomizer.php [L]
```
This uses mod\_rewrite to rewrite the URL. There is no need to repeat the `RewriteEngine On` directive (that o... |
372,825 | <p>Since WP 5.5 just released and now you can set plugins to auto-update, can this be done via wp-cli?
Looking at the documentation, I don't see a sub-command for it: <a href="https://developer.wordpress.org/cli/commands/plugin/" rel="noreferrer">https://developer.wordpress.org/cli/commands/plugin/</a></p>
<p>I manage ... | [
{
"answer_id": 384240,
"author": "Mike Eng",
"author_id": 7313,
"author_profile": "https://wordpress.stackexchange.com/users/7313",
"pm_score": 1,
"selected": false,
"text": "<p>This is not using wp-cli, but maybe the next best thing:</p>\n<p>From the Plugins page in WordPress Admin: sit... | 2020/08/11 | [
"https://wordpress.stackexchange.com/questions/372825",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/31560/"
] | Since WP 5.5 just released and now you can set plugins to auto-update, can this be done via wp-cli?
Looking at the documentation, I don't see a sub-command for it: <https://developer.wordpress.org/cli/commands/plugin/>
I manage a lot of Wordpress sites, most of which are OK to auto-update and would save me a lot of ti... | The simplest way via *wp-cli* that comes to mind (~~while it's not supported yet as far as I can see~~) is something like:
```
wp eval "update_option( 'auto_update_plugins', array_keys( get_plugins() ) );"
```
that will update the `auto_update_plugins` option with the array of all plugin files to update.
This shoul... |
372,840 | <p>I want to export the form data and send it as an attachment. In this case, can i rewrite the file (/uploads/2020/08/sample.csv) with the form data and send it as an attachment.</p>
<p>right now, it is just a blank attachment when i receive it in my email</p>
<p>Here is my code in function.php, Please help me:</p>
<p... | [
{
"answer_id": 373724,
"author": "amitdutt24",
"author_id": 188153,
"author_profile": "https://wordpress.stackexchange.com/users/188153",
"pm_score": 0,
"selected": false,
"text": "<p>I solved mine problem with this code. Hope it could help others too -</p>\n<pre><code>add_action( 'wpcf7... | 2020/08/12 | [
"https://wordpress.stackexchange.com/questions/372840",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/191358/"
] | I want to export the form data and send it as an attachment. In this case, can i rewrite the file (/uploads/2020/08/sample.csv) with the form data and send it as an attachment.
right now, it is just a blank attachment when i receive it in my email
Here is my code in function.php, Please help me:
```
add_action( 'wpc... | There are a few things omitted in the above solution, like defining the most params of wp\_mail.
Also I didn't want to send yet another concurrent email, but instead attach the csv directly to the mail that wpcf7 sends. I think this is the cleaner solution.
Here's my take:
```
add_filter( 'wpcf7_before_send_mail', 'a... |
372,871 | <p>I'm trying to translate the month names as underlined in <a href="https://i.imgur.com/s9x1LOO.png" rel="nofollow noreferrer">this image</a>, without <a href="https://i.imgur.com/gm9RH9L.png" rel="nofollow noreferrer">changing the entire WP backend</a> as well, as I require the backend to remain English.</p>
<p>I man... | [
{
"answer_id": 373724,
"author": "amitdutt24",
"author_id": 188153,
"author_profile": "https://wordpress.stackexchange.com/users/188153",
"pm_score": 0,
"selected": false,
"text": "<p>I solved mine problem with this code. Hope it could help others too -</p>\n<pre><code>add_action( 'wpcf7... | 2020/08/12 | [
"https://wordpress.stackexchange.com/questions/372871",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/193023/"
] | I'm trying to translate the month names as underlined in [this image](https://i.imgur.com/s9x1LOO.png), without [changing the entire WP backend](https://i.imgur.com/gm9RH9L.png) as well, as I require the backend to remain English.
I managed to translate the default strings via's [Astra's Default String page](https://w... | There are a few things omitted in the above solution, like defining the most params of wp\_mail.
Also I didn't want to send yet another concurrent email, but instead attach the csv directly to the mail that wpcf7 sends. I think this is the cleaner solution.
Here's my take:
```
add_filter( 'wpcf7_before_send_mail', 'a... |
372,877 | <p>I had installed a chat plugin called Crisp chat. But i still see crisp chat box in my mobile but not in PC. I have deleted it yet it is seen in mobile. please guide me.</p>
| [
{
"answer_id": 373724,
"author": "amitdutt24",
"author_id": 188153,
"author_profile": "https://wordpress.stackexchange.com/users/188153",
"pm_score": 0,
"selected": false,
"text": "<p>I solved mine problem with this code. Hope it could help others too -</p>\n<pre><code>add_action( 'wpcf7... | 2020/08/12 | [
"https://wordpress.stackexchange.com/questions/372877",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/193030/"
] | I had installed a chat plugin called Crisp chat. But i still see crisp chat box in my mobile but not in PC. I have deleted it yet it is seen in mobile. please guide me. | There are a few things omitted in the above solution, like defining the most params of wp\_mail.
Also I didn't want to send yet another concurrent email, but instead attach the csv directly to the mail that wpcf7 sends. I think this is the cleaner solution.
Here's my take:
```
add_filter( 'wpcf7_before_send_mail', 'a... |
372,878 | <p>I am trying to get latest from specific categories (3 posts), but the code does not seem working. Instead of displaying posts from the mentioned categories, it is displaying posts from the first category.</p>
<p>Here is my code:</p>
<pre><code><?php do_action( 'hitmag_before_content' ); ?>
<div id="p... | [
{
"answer_id": 373724,
"author": "amitdutt24",
"author_id": 188153,
"author_profile": "https://wordpress.stackexchange.com/users/188153",
"pm_score": 0,
"selected": false,
"text": "<p>I solved mine problem with this code. Hope it could help others too -</p>\n<pre><code>add_action( 'wpcf7... | 2020/08/12 | [
"https://wordpress.stackexchange.com/questions/372878",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/182729/"
] | I am trying to get latest from specific categories (3 posts), but the code does not seem working. Instead of displaying posts from the mentioned categories, it is displaying posts from the first category.
Here is my code:
```
<?php do_action( 'hitmag_before_content' ); ?>
<div id="primary" class="content-area">
... | There are a few things omitted in the above solution, like defining the most params of wp\_mail.
Also I didn't want to send yet another concurrent email, but instead attach the csv directly to the mail that wpcf7 sends. I think this is the cleaner solution.
Here's my take:
```
add_filter( 'wpcf7_before_send_mail', 'a... |
372,886 | <p>If I used /wp-json/wc/v3/products I am getting all products, but what if I want to receive only price and quantity, I searched all we web and couldn't find it!</p>
| [
{
"answer_id": 372888,
"author": "Sam",
"author_id": 193035,
"author_profile": "https://wordpress.stackexchange.com/users/193035",
"pm_score": 1,
"selected": false,
"text": "<p>First of all, sorry for my bad english!</p>\n<p>In PHP, after your file_get_contents(home_url().'/wp-json/wc/v3... | 2020/08/12 | [
"https://wordpress.stackexchange.com/questions/372886",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/151546/"
] | If I used /wp-json/wc/v3/products I am getting all products, but what if I want to receive only price and quantity, I searched all we web and couldn't find it! | Woocommerce rest API is an extension of WordPress rest API, so you should first check global parameters and specifically "\_fields" in the [REST API Handbook of Wordpress.org](https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/#_fields).
I will give you an example of the data that you want, ... |
372,895 | <p>site been hacked, and all posts been injected a line of js code under the content!</p>
<pre><code><script src='https://js.xxxxxxx.ga/stat.js?n=ns1' type='text/javascript'></script>
</code></pre>
<p>I have found the malware file in the root directory, which inject the JS code with the command:</p>
<pre><c... | [
{
"answer_id": 372888,
"author": "Sam",
"author_id": 193035,
"author_profile": "https://wordpress.stackexchange.com/users/193035",
"pm_score": 1,
"selected": false,
"text": "<p>First of all, sorry for my bad english!</p>\n<p>In PHP, after your file_get_contents(home_url().'/wp-json/wc/v3... | 2020/08/12 | [
"https://wordpress.stackexchange.com/questions/372895",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/193038/"
] | site been hacked, and all posts been injected a line of js code under the content!
```
<script src='https://js.xxxxxxx.ga/stat.js?n=ns1' type='text/javascript'></script>
```
I have found the malware file in the root directory, which inject the JS code with the command:
```
$q = "SELECT TABLE_SCHEMA,TABLE_NAME FROM ... | Woocommerce rest API is an extension of WordPress rest API, so you should first check global parameters and specifically "\_fields" in the [REST API Handbook of Wordpress.org](https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/#_fields).
I will give you an example of the data that you want, ... |
372,897 | <p>I recently updated a WordPress instance from 5.4 to 5.5 to end up with an annoying margin-top in the admin area, above the menu directly.</p>
<p><a href="https://i.stack.imgur.com/bGHZk.png" rel="noreferrer"><img src="https://i.stack.imgur.com/bGHZk.png" alt="enter image description here" /></a></p>
<p>I deactivated... | [
{
"answer_id": 373027,
"author": "RJR",
"author_id": 193141,
"author_profile": "https://wordpress.stackexchange.com/users/193141",
"pm_score": 3,
"selected": false,
"text": "<p>I ran into that issue too, and it turns out that it was because there actually was an error that wasn't display... | 2020/08/12 | [
"https://wordpress.stackexchange.com/questions/372897",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/191979/"
] | I recently updated a WordPress instance from 5.4 to 5.5 to end up with an annoying margin-top in the admin area, above the menu directly.
[](https://i.stack.imgur.com/bGHZk.png)
I deactivated all plugins, switched themes, did some inspection, and I e... | I ran into that issue too, and it turns out that it was because there actually was an error that wasn't displaying. Once I fixed that underlying error, the top margin problem went away.
This is in wp-admin/admin-header.php:
```
// Print a CSS class to make PHP errors visible.
if ( error_get_last() && WP_DEBUG && WP_D... |
372,941 | <p>On a fresh WordPress install in Linux distributions, <code>wp-config-sample.php</code> contains Carriage Return control characters that are not found in any other .php file in the distribution.</p>
<p>Running</p>
<pre><code>egrep -l $'\r'\$ *.php
</code></pre>
<p>in WP's base dir, will return only <code>wp-config-sa... | [
{
"answer_id": 373033,
"author": "Pat J",
"author_id": 16121,
"author_profile": "https://wordpress.stackexchange.com/users/16121",
"pm_score": 2,
"selected": false,
"text": "<p>Unix and Unix-like operating systems (like Linux) use different line endings in their text files.</p>\n<blockqu... | 2020/08/13 | [
"https://wordpress.stackexchange.com/questions/372941",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/175096/"
] | On a fresh WordPress install in Linux distributions, `wp-config-sample.php` contains Carriage Return control characters that are not found in any other .php file in the distribution.
Running
```
egrep -l $'\r'\$ *.php
```
in WP's base dir, will return only `wp-config-sample.php`
---
I am not worried about elimina... | From Wordpress support:
>
> It’s for formatting on legacy DOS based systems. Some DOS and Windows based editors will not handle the file correctly without those additional `^M` carriage return character. A UNIX based system will work with or without them and that’s why they don’t matter.
>
>
> <https://en.wikipedia... |
372,950 | <p>I'm trying to inject some data into blocks via PHP but am running into trouble with parse_blocks/serialize_blocks breaking my content</p>
<p>I'm using the default 2020 theme and have no plugins installed</p>
<pre><code>add_action('wp', function() {
$oPost = get_post(119);
printf("<h1>Post Content... | [
{
"answer_id": 373870,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 2,
"selected": false,
"text": "<p>This happens in <code>serialize_block_attributes</code>, the docblock explains why:</p>\n<pre class=\"lang-p... | 2020/08/13 | [
"https://wordpress.stackexchange.com/questions/372950",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140806/"
] | I'm trying to inject some data into blocks via PHP but am running into trouble with parse\_blocks/serialize\_blocks breaking my content
I'm using the default 2020 theme and have no plugins installed
```
add_action('wp', function() {
$oPost = get_post(119);
printf("<h1>Post Content</h1><p>%s</p>", var_dump($o... | This happens in `serialize_block_attributes`, the docblock explains why:
```php
/**
...
* The serialized result is a JSON-encoded string, with unicode escape sequence
* substitution for characters which might otherwise interfere with embedding
* the result in an HTML comment.
...
*/
```
So this is done as an enc... |
372,973 | <p>I just recently updated my Wordpress, theme, and plugins, and am now getting these two errors on top of the homepage and pages page.</p>
<blockquote>
<p>Deprecated: wp_make_content_images_responsive is deprecated since
version 5.5.0! Use wp_filter_content_tags() instead. in
/var/www/html/wp-includes/functions.php on... | [
{
"answer_id": 373009,
"author": "drcrow",
"author_id": 178234,
"author_profile": "https://wordpress.stackexchange.com/users/178234",
"pm_score": -1,
"selected": false,
"text": "<p>If nothing is broken, in your wp-config.php put this:</p>\n<pre><code>define( 'WP_DEBUG', false );\ndefine(... | 2020/08/13 | [
"https://wordpress.stackexchange.com/questions/372973",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/193095/"
] | I just recently updated my Wordpress, theme, and plugins, and am now getting these two errors on top of the homepage and pages page.
>
> Deprecated: wp\_make\_content\_images\_responsive is deprecated since
> version 5.5.0! Use wp\_filter\_content\_tags() instead. in
> /var/www/html/wp-includes/functions.php on line ... | I suspect this is already resolved in the plugin, but I added a check for the new function in wp-content/plugins/fusion-builder/shortcodes/fusion-image.php:285.
```
if ( ! empty( $image_id ) && function_exists( 'wp_image_add_srcset_and_sizes' ) ) {
$content = wp_image_add_srcset_and_sizes(
$content,
... |
372,974 | <p>Wordpress sends some various default email texts to the users.</p>
<p>For example when the password reset email has been sent, then the user gets an automatic email like this:</p>
<blockquote>
<p><em>Hello user, This notification confirms the change of access password to NAMEOFWEBSITE. If you have not changed your p... | [
{
"answer_id": 372977,
"author": "rudtek",
"author_id": 77767,
"author_profile": "https://wordpress.stackexchange.com/users/77767",
"pm_score": 2,
"selected": false,
"text": "<p>There is definitely a filter for that!</p>\n<p>Here is the reference link to wordpress developers page: <a hre... | 2020/08/13 | [
"https://wordpress.stackexchange.com/questions/372974",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129972/"
] | Wordpress sends some various default email texts to the users.
For example when the password reset email has been sent, then the user gets an automatic email like this:
>
> *Hello user, This notification confirms the change of access password to NAMEOFWEBSITE. If you have not changed your password, please contact th... | There is definitely a filter for that!
Here is the reference link to wordpress developers page: <https://developer.wordpress.org/reference/hooks/password_change_email/>
Basically adding this function (with changes) to your functions.php will override your default password reset email.
```
apply_filters( 'password_ch... |
372,989 | <p>i want to show category list with custom post type count. but i have two different post types in every category. how can i do that . please help. this is my code:</p>
<pre><code><?php
$category_object = get_queried_object();
$current_category_taxonomy = $category_object->taxonomy;
$curre... | [
{
"answer_id": 372994,
"author": "Dharmishtha Patel",
"author_id": 135085,
"author_profile": "https://wordpress.stackexchange.com/users/135085",
"pm_score": 1,
"selected": false,
"text": "<pre><code>function my_taxonomy_posts_count_func($atts)\n {\n extract(shortcode_atts(array... | 2020/08/14 | [
"https://wordpress.stackexchange.com/questions/372989",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/172323/"
] | i want to show category list with custom post type count. but i have two different post types in every category. how can i do that . please help. this is my code:
```
<?php
$category_object = get_queried_object();
$current_category_taxonomy = $category_object->taxonomy;
$current_category_term_id... | Out of the box this cannot be done, as the post counts on each term is singular, there is no breakdown by post type.
In order to do this, you will need to output the markup yourself, and query for the counts yourself.
**This will be slow/heavy/expensive.**
So first we start with the current term/taxonomy:
```php
$c... |
373,025 | <p>I'm trying to come up with a solution for a client.</p>
<p>They sell parasols and each one has the following attributes:</p>
<ul>
<li>Colour</li>
<li>Frame</li>
<li>Size</li>
<li>Base</li>
<li>Bar</li>
</ul>
<p>The way it is set up at the moment, there are 36 variations, and the colour attribute is set to 'any colou... | [
{
"answer_id": 372994,
"author": "Dharmishtha Patel",
"author_id": 135085,
"author_profile": "https://wordpress.stackexchange.com/users/135085",
"pm_score": 1,
"selected": false,
"text": "<pre><code>function my_taxonomy_posts_count_func($atts)\n {\n extract(shortcode_atts(array... | 2020/08/14 | [
"https://wordpress.stackexchange.com/questions/373025",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/44848/"
] | I'm trying to come up with a solution for a client.
They sell parasols and each one has the following attributes:
* Colour
* Frame
* Size
* Base
* Bar
The way it is set up at the moment, there are 36 variations, and the colour attribute is set to 'any colour' as it doesn't effect price. The other 4 options, (Frame, ... | Out of the box this cannot be done, as the post counts on each term is singular, there is no breakdown by post type.
In order to do this, you will need to output the markup yourself, and query for the counts yourself.
**This will be slow/heavy/expensive.**
So first we start with the current term/taxonomy:
```php
$c... |
373,030 | <p>In Gravity Forms, I have a confirmation set up with various conditional shortcodes. Example:</p>
<pre><code>[gravityforms action="conditional" merge_tag="{:3:value}" condition="contains" value="E"]*** GET A CATEGORY ***[/gravityforms]
</code></pre>
<p>Additionally, I have a PH... | [
{
"answer_id": 372994,
"author": "Dharmishtha Patel",
"author_id": 135085,
"author_profile": "https://wordpress.stackexchange.com/users/135085",
"pm_score": 1,
"selected": false,
"text": "<pre><code>function my_taxonomy_posts_count_func($atts)\n {\n extract(shortcode_atts(array... | 2020/08/14 | [
"https://wordpress.stackexchange.com/questions/373030",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/42925/"
] | In Gravity Forms, I have a confirmation set up with various conditional shortcodes. Example:
```
[gravityforms action="conditional" merge_tag="{:3:value}" condition="contains" value="E"]*** GET A CATEGORY ***[/gravityforms]
```
Additionally, I have a PHP function that gets all posts by category, and I would like to ... | Out of the box this cannot be done, as the post counts on each term is singular, there is no breakdown by post type.
In order to do this, you will need to output the markup yourself, and query for the counts yourself.
**This will be slow/heavy/expensive.**
So first we start with the current term/taxonomy:
```php
$c... |
373,037 | <p>I've been using WordPress for awhile now but one problem I'm constantly facing is creating a local clone of a production site so I can test changes/updates.</p>
<p>My current process goes something like this...</p>
<ul>
<li>Run XAMPP Server</li>
<li>Download the site files (Filzilla)</li>
<li>Download the database (... | [
{
"answer_id": 372994,
"author": "Dharmishtha Patel",
"author_id": 135085,
"author_profile": "https://wordpress.stackexchange.com/users/135085",
"pm_score": 1,
"selected": false,
"text": "<pre><code>function my_taxonomy_posts_count_func($atts)\n {\n extract(shortcode_atts(array... | 2020/08/14 | [
"https://wordpress.stackexchange.com/questions/373037",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/157172/"
] | I've been using WordPress for awhile now but one problem I'm constantly facing is creating a local clone of a production site so I can test changes/updates.
My current process goes something like this...
* Run XAMPP Server
* Download the site files (Filzilla)
* Download the database (phpMyAdmin)
* Create a local data... | Out of the box this cannot be done, as the post counts on each term is singular, there is no breakdown by post type.
In order to do this, you will need to output the markup yourself, and query for the counts yourself.
**This will be slow/heavy/expensive.**
So first we start with the current term/taxonomy:
```php
$c... |
373,042 | <p>I am using <strong>Option 3</strong> from <a href="https://wordpress.stackexchange.com/a/333920">this answer</a> as my source. So far it is working great, it is splitting my search results by post type and listing the posts from each post type in their own sections. The only problem is that this solution does not ap... | [
{
"answer_id": 373180,
"author": "Jagruti Rakholiya",
"author_id": 193235,
"author_profile": "https://wordpress.stackexchange.com/users/193235",
"pm_score": 0,
"selected": false,
"text": "<p>You can use this to add permalink</p>\n<pre><code>echo get_permalink( get_page_by_title( $title, ... | 2020/08/14 | [
"https://wordpress.stackexchange.com/questions/373042",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13286/"
] | I am using **Option 3** from [this answer](https://wordpress.stackexchange.com/a/333920) as my source. So far it is working great, it is splitting my search results by post type and listing the posts from each post type in their own sections. The only problem is that this solution does not appear to allow for hyperlink... | I would try a somewhat different approach.
I would move the array of post types to your new WP\_Query (since you are working with a limited defined set), and then below where you're looping through each post type in your first foreach statement, I would setup a second query to get all posts found within each $type. If... |
373,064 | <p>I'm not an expert in PHP and I'm trying to apply conditional formatting on data fetched from wpdb. To be fair, I'm trying to create shortcode for this. My motto is to fetch values for $previous_marks & $current_marks from the database and change the color of $current_marks according to if, else condition. Accord... | [
{
"answer_id": 373180,
"author": "Jagruti Rakholiya",
"author_id": 193235,
"author_profile": "https://wordpress.stackexchange.com/users/193235",
"pm_score": 0,
"selected": false,
"text": "<p>You can use this to add permalink</p>\n<pre><code>echo get_permalink( get_page_by_title( $title, ... | 2020/08/15 | [
"https://wordpress.stackexchange.com/questions/373064",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/180322/"
] | I'm not an expert in PHP and I'm trying to apply conditional formatting on data fetched from wpdb. To be fair, I'm trying to create shortcode for this. My motto is to fetch values for $previous\_marks & $current\_marks from the database and change the color of $current\_marks according to if, else condition. According ... | I would try a somewhat different approach.
I would move the array of post types to your new WP\_Query (since you are working with a limited defined set), and then below where you're looping through each post type in your first foreach statement, I would setup a second query to get all posts found within each $type. If... |
373,141 | <p>I have an archive page that pulls in posts using <code>WP_Query()</code>. On the homepage of the site it shows 16 of the custom post type posts, so on the archive I offset the archive page by 16 posts.</p>
<p>The code for this is:</p>
<pre><code>$newsArticles = new WP_Query(array(
'posts_per_page' => 16,
... | [
{
"answer_id": 373180,
"author": "Jagruti Rakholiya",
"author_id": 193235,
"author_profile": "https://wordpress.stackexchange.com/users/193235",
"pm_score": 0,
"selected": false,
"text": "<p>You can use this to add permalink</p>\n<pre><code>echo get_permalink( get_page_by_title( $title, ... | 2020/08/17 | [
"https://wordpress.stackexchange.com/questions/373141",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106972/"
] | I have an archive page that pulls in posts using `WP_Query()`. On the homepage of the site it shows 16 of the custom post type posts, so on the archive I offset the archive page by 16 posts.
The code for this is:
```
$newsArticles = new WP_Query(array(
'posts_per_page' => 16,
'offset' => 16,
'post_type'=>... | I would try a somewhat different approach.
I would move the array of post types to your new WP\_Query (since you are working with a limited defined set), and then below where you're looping through each post type in your first foreach statement, I would setup a second query to get all posts found within each $type. If... |
373,149 | <p>I'm using a plugin from LinkedIn Learning to customize into my own plugin's custom Gutenberg blocks.</p>
<p>After I've edited the file <code>plugin/src/index.js</code> (I edited the <code>edit()</code> & <code>save()</code> functions), I now have:</p>
<pre><code>const { __ } = wp.i18n;
const { registerBlockType ... | [
{
"answer_id": 373248,
"author": "Will",
"author_id": 48698,
"author_profile": "https://wordpress.stackexchange.com/users/48698",
"pm_score": 1,
"selected": false,
"text": "<p>Add this additional variable to your wp-config file:</p>\n<pre><code>define ( 'SCRIPT_DEBUG', true); \n</code></... | 2020/08/17 | [
"https://wordpress.stackexchange.com/questions/373149",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/147186/"
] | I'm using a plugin from LinkedIn Learning to customize into my own plugin's custom Gutenberg blocks.
After I've edited the file `plugin/src/index.js` (I edited the `edit()` & `save()` functions), I now have:
```
const { __ } = wp.i18n;
const { registerBlockType } = wp.blocks;
// Import SVG as React component using @... | Add this additional variable to your wp-config file:
```
define ( 'SCRIPT_DEBUG', true);
```
Also, [inline styling directly in react is declared differently](https://reactjs.org/docs/dom-elements.html#style) is similar but different in many ways than pure, vanilla CSS.
For example, `<ul class="home-slider content-... |
373,157 | <p>I want to Add slider shortcodes. My all slider fields adds properly in shortcode, but the read more button and button link is not displaying. Can you please solve my problem?
This my slider code:</p>
<pre class="lang-php prettyprint-override"><code><section id="firstsection">
<div class="... | [
{
"answer_id": 373165,
"author": "Jagruti Rakholiya",
"author_id": 193235,
"author_profile": "https://wordpress.stackexchange.com/users/193235",
"pm_score": 2,
"selected": true,
"text": "<p>Use <code>get_the_ID()</code> instead of <code>$post->ID</code></p>\n<p>This will fix your prob... | 2020/08/17 | [
"https://wordpress.stackexchange.com/questions/373157",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/183253/"
] | I want to Add slider shortcodes. My all slider fields adds properly in shortcode, but the read more button and button link is not displaying. Can you please solve my problem?
This my slider code:
```php
<section id="firstsection">
<div class="container-fluid">
<div class="col-xs-12 firstsection-maindiv">
... | Use `get_the_ID()` instead of `$post->ID`
This will fix your problem |
373,169 | <p>I'm building a webshop, and started to configure the product loop on the shop archive page.
I display the product category related to every product, and I would like to set to the categories to have a background that I've chosen on the admin page.</p>
<p>I've made an ACF colour picker field, and set the colors.</p>
... | [
{
"answer_id": 373171,
"author": "t2pe",
"author_id": 106499,
"author_profile": "https://wordpress.stackexchange.com/users/106499",
"pm_score": 0,
"selected": false,
"text": "<p>If I am reading this correctly, the variable $terms is an array at the point where you use it in the_field. I ... | 2020/08/17 | [
"https://wordpress.stackexchange.com/questions/373169",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/180651/"
] | I'm building a webshop, and started to configure the product loop on the shop archive page.
I display the product category related to every product, and I would like to set to the categories to have a background that I've chosen on the admin page.
I've made an ACF colour picker field, and set the colors.
This is the ... | The syntax to get the ACF field of a custom taxonomy is:
```
$var = get_field('name_of_acf_field', 'name_of_taxonomy' . '_' . taxonomy_ID);
```
so in your case you'll need to get product\_cat ID before and do something like:
```
add_action( 'woocommerce_shop_loop_item_title', 'VS_woo_loop_product_title', 10 );
func... |
373,217 | <p>I have a html bootstrap slider which works fine with captions and everything.I would like to integrate it into my Wp theme (my forst one, so total newbie).I found a code, which seems to helo, but it only shows the three pictures and nothing slides...if I hard code the slider, it works.I understand I can just leave i... | [
{
"answer_id": 373171,
"author": "t2pe",
"author_id": 106499,
"author_profile": "https://wordpress.stackexchange.com/users/106499",
"pm_score": 0,
"selected": false,
"text": "<p>If I am reading this correctly, the variable $terms is an array at the point where you use it in the_field. I ... | 2020/08/18 | [
"https://wordpress.stackexchange.com/questions/373217",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/193291/"
] | I have a html bootstrap slider which works fine with captions and everything.I would like to integrate it into my Wp theme (my forst one, so total newbie).I found a code, which seems to helo, but it only shows the three pictures and nothing slides...if I hard code the slider, it works.I understand I can just leave it h... | The syntax to get the ACF field of a custom taxonomy is:
```
$var = get_field('name_of_acf_field', 'name_of_taxonomy' . '_' . taxonomy_ID);
```
so in your case you'll need to get product\_cat ID before and do something like:
```
add_action( 'woocommerce_shop_loop_item_title', 'VS_woo_loop_product_title', 10 );
func... |
373,249 | <h1>The issue</h1>
<p>I am looking for a way to <strong>add linking functionality to a custom block</strong> of mine and found different approaches to this need.</p>
<p>There are:</p>
<ol>
<li>The <a href="https://github.com/WordPress/gutenberg/tree/master/packages/block-editor/src/components/url-input#urlinputbutton" ... | [
{
"answer_id": 376014,
"author": "fluoriteen",
"author_id": 178753,
"author_profile": "https://wordpress.stackexchange.com/users/178753",
"pm_score": 4,
"selected": true,
"text": "<p><em>LinkControl</em> is an experimental component, so it's declared differently in <em>blockEditor</em> p... | 2020/08/18 | [
"https://wordpress.stackexchange.com/questions/373249",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/165265/"
] | The issue
=========
I am looking for a way to **add linking functionality to a custom block** of mine and found different approaches to this need.
There are:
1. The [URLInputButton Component](https://github.com/WordPress/gutenberg/tree/master/packages/block-editor/src/components/url-input#urlinputbutton)
2. The [URL... | *LinkControl* is an experimental component, so it's declared differently in *blockEditor* package
try this as an import statement, this worked for me:
```
const {__experimentalLinkControl } = wp.blockEditor;
const LinkControl = __experimentalLinkControl;
``` |
373,267 | <p>Inside the loop, when logged in to a localhost test site as <code>$user->ID == 1</code> the function <code>is_author(get_current_user_id())</code> returns <code>false</code> when <code>get_the_author_meta('ID')</code> returns 1. Thus, the following conditional is never executed (<code>is_user_logged_in()</code> r... | [
{
"answer_id": 373271,
"author": "Nate Allen",
"author_id": 32698,
"author_profile": "https://wordpress.stackexchange.com/users/32698",
"pm_score": 3,
"selected": true,
"text": "<p>Are you sure you're doing it within the loop? The <code>is_author</code> function checks if <code>$wp_query... | 2020/08/18 | [
"https://wordpress.stackexchange.com/questions/373267",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109240/"
] | Inside the loop, when logged in to a localhost test site as `$user->ID == 1` the function `is_author(get_current_user_id())` returns `false` when `get_the_author_meta('ID')` returns 1. Thus, the following conditional is never executed (`is_user_logged_in()` returns `true`):
```
if( is_user_logged_in() && is_author(get... | Are you sure you're doing it within the loop? The `is_author` function checks if `$wp_query` is set.
Another option would be to try this:
```
$current_user = wp_get_current_user();
if (is_user_logged_in() && $current_user->ID == $post->post_author) {
// do stuff
}
``` |
373,346 | <p><a href="https://i.stack.imgur.com/wJfvk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wJfvk.jpg" alt="enter image description here" /></a></p>
<p>How to add Category name to post title ? “PostTitle + CategoryName”?</p>
| [
{
"answer_id": 373271,
"author": "Nate Allen",
"author_id": 32698,
"author_profile": "https://wordpress.stackexchange.com/users/32698",
"pm_score": 3,
"selected": true,
"text": "<p>Are you sure you're doing it within the loop? The <code>is_author</code> function checks if <code>$wp_query... | 2020/08/19 | [
"https://wordpress.stackexchange.com/questions/373346",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/193395/"
] | [](https://i.stack.imgur.com/wJfvk.jpg)
How to add Category name to post title ? “PostTitle + CategoryName”? | Are you sure you're doing it within the loop? The `is_author` function checks if `$wp_query` is set.
Another option would be to try this:
```
$current_user = wp_get_current_user();
if (is_user_logged_in() && $current_user->ID == $post->post_author) {
// do stuff
}
``` |
373,355 | <p>Is there a way to change the size of featured images on posts? When I click on one of my blog posts, I can see it’s extremely large and inefficient.</p>
<p><a href="https://graduateinvestor.com" rel="nofollow noreferrer">https://graduateinvestor.com</a></p>
| [
{
"answer_id": 373271,
"author": "Nate Allen",
"author_id": 32698,
"author_profile": "https://wordpress.stackexchange.com/users/32698",
"pm_score": 3,
"selected": true,
"text": "<p>Are you sure you're doing it within the loop? The <code>is_author</code> function checks if <code>$wp_query... | 2020/08/20 | [
"https://wordpress.stackexchange.com/questions/373355",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/193403/"
] | Is there a way to change the size of featured images on posts? When I click on one of my blog posts, I can see it’s extremely large and inefficient.
<https://graduateinvestor.com> | Are you sure you're doing it within the loop? The `is_author` function checks if `$wp_query` is set.
Another option would be to try this:
```
$current_user = wp_get_current_user();
if (is_user_logged_in() && $current_user->ID == $post->post_author) {
// do stuff
}
``` |
373,357 | <p>Simple question. I'm attempting to use <code>get_permalink()</code> in vanilla php but cannot access it. I have <code>include_once</code> all these "used" files:</p>
<ul>
<li>wp-settings.php</li>
<li>wp-includes/load.php</li>
<li>wp-includes/link-template.php</li>
<li>wp-includes/rewrite.php</li>
<li>wp-in... | [
{
"answer_id": 373271,
"author": "Nate Allen",
"author_id": 32698,
"author_profile": "https://wordpress.stackexchange.com/users/32698",
"pm_score": 3,
"selected": true,
"text": "<p>Are you sure you're doing it within the loop? The <code>is_author</code> function checks if <code>$wp_query... | 2020/08/20 | [
"https://wordpress.stackexchange.com/questions/373357",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/189616/"
] | Simple question. I'm attempting to use `get_permalink()` in vanilla php but cannot access it. I have `include_once` all these "used" files:
* wp-settings.php
* wp-includes/load.php
* wp-includes/link-template.php
* wp-includes/rewrite.php
* wp-includes/functions.php
and 10 other files. How do I access `get_permalink(... | Are you sure you're doing it within the loop? The `is_author` function checks if `$wp_query` is set.
Another option would be to try this:
```
$current_user = wp_get_current_user();
if (is_user_logged_in() && $current_user->ID == $post->post_author) {
// do stuff
}
``` |
373,367 | <p>So I've got the dreaded error too it seems. Apparently it's a very common issue but I can't really seem to get a hang on the fix.</p>
<p>One of the plugins my theme uses is causing the error as per the log I got in the email WordPress sent to my admin email. Here's the full log</p>
<pre><code>Error Details
=========... | [
{
"answer_id": 373370,
"author": "t2pe",
"author_id": 106499,
"author_profile": "https://wordpress.stackexchange.com/users/106499",
"pm_score": 0,
"selected": false,
"text": "<p>I don't think this is an answer as such but I need a bit more space than the comment box allows...</p>\n<p>You... | 2020/08/20 | [
"https://wordpress.stackexchange.com/questions/373367",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/193417/"
] | So I've got the dreaded error too it seems. Apparently it's a very common issue but I can't really seem to get a hang on the fix.
One of the plugins my theme uses is causing the error as per the log I got in the email WordPress sent to my admin email. Here's the full log
```
Error Details
=============
An error of ty... | So I reinstalled WordPress on both my live and local environments and downgraded to version 5.4.2 and everything seems to be working just fine, so far.
I'll update if anything breaks again. |
373,386 | <p>How can I pass the results of a <code>WP_Query</code> call to a plugin? I've tried passing the data via a shortcode attribute, but I get the error "Object of class WP_Query could not be converted to string".</p>
<p>E.g.:</p>
<pre><code>$args = array(
// ...
);
$the_query = WP_Query($args);
echo do_shortc... | [
{
"answer_id": 373395,
"author": "Movs",
"author_id": 193435,
"author_profile": "https://wordpress.stackexchange.com/users/193435",
"pm_score": -1,
"selected": false,
"text": "<ol>\n<li>Use global variable</li>\n<li>Pass just $args and run the same query inside the plugin</li>\n<li>Seria... | 2020/08/20 | [
"https://wordpress.stackexchange.com/questions/373386",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/90498/"
] | How can I pass the results of a `WP_Query` call to a plugin? I've tried passing the data via a shortcode attribute, but I get the error "Object of class WP\_Query could not be converted to string".
E.g.:
```
$args = array(
// ...
);
$the_query = WP_Query($args);
echo do_shortcode( [example_custom_plugin query_paylo... | I think for shortcodes, which are generally used in the WYSIWYG editor by non-technical users, it's best to keep the parameters simple:
```
[custom-shortcode color="red" size="medium"]
```
In other words, shortcodes are designed to provide functionality that an end-user can place somewhere in their content, with the... |
373,404 | <p>I would like to add the following JavaScript function to a wordpress child theme (functions.php). Unfortunately I am not able to make it.
Function:</p>
<pre><code>$.fn.cityAutocomplete.transliterate = function (s) {
s = String(s);
return s;
};
</code></pre>
<p>I tried this:</p>
<pre><code><?ph... | [
{
"answer_id": 373395,
"author": "Movs",
"author_id": 193435,
"author_profile": "https://wordpress.stackexchange.com/users/193435",
"pm_score": -1,
"selected": false,
"text": "<ol>\n<li>Use global variable</li>\n<li>Pass just $args and run the same query inside the plugin</li>\n<li>Seria... | 2020/08/20 | [
"https://wordpress.stackexchange.com/questions/373404",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/193446/"
] | I would like to add the following JavaScript function to a wordpress child theme (functions.php). Unfortunately I am not able to make it.
Function:
```
$.fn.cityAutocomplete.transliterate = function (s) {
s = String(s);
return s;
};
```
I tried this:
```
<?php
add_action( 'wp_enqueue_scripts... | I think for shortcodes, which are generally used in the WYSIWYG editor by non-technical users, it's best to keep the parameters simple:
```
[custom-shortcode color="red" size="medium"]
```
In other words, shortcodes are designed to provide functionality that an end-user can place somewhere in their content, with the... |
373,442 | <p>My permalinks is set to <code>/%post_id%/</code> (post id).</p>
<p><a href="https://elrons.co.il/%post_id%/" rel="nofollow noreferrer">https://elrons.co.il/%post_id%/</a></p>
<p>I want to change them all to <code>/%postname%/</code> (which is the post slug).</p>
<p><a href="https://elrons.co.il/%postname%/" rel="nof... | [
{
"answer_id": 373443,
"author": "Suresh Shinde",
"author_id": 167466,
"author_profile": "https://wordpress.stackexchange.com/users/167466",
"pm_score": -1,
"selected": false,
"text": "<p>You can do it by .htaccess file, for your case url format as;</p>\n<p>Redirect 301 /%post_id%/ <a hr... | 2020/08/21 | [
"https://wordpress.stackexchange.com/questions/373442",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98773/"
] | My permalinks is set to `/%post_id%/` (post id).
<https://elrons.co.il/%post_id%/>
I want to change them all to `/%postname%/` (which is the post slug).
<https://elrons.co.il/%postname%/>
Problem is, whenever I change it, it gives 404 errors from my old page urls.
for example, this: <https://elrons.co.il/1779/>
s... | I've written my own solution, sharing it and hoping it will help someone.
Add this to your `functions.php`:
```
<?php
add_action('parse_request', 'redirect_postid_to_postname');
function redirect_postid_to_postname($wp)
{
// If /%post_id%/
if (is_numeric($wp->request)) {
$post_id = $wp->request;
... |
373,447 | <p>Is it possible to disable the cropping step when adding a site icon via the Theme Customizer in WordPress 5+ (occurred to me in 5.5)?</p>
<p>For me cropping is unnecessary because I always upload a square image in the directions of the recommendations.</p>
<p>That's why this step is not helping me at all, instead is... | [
{
"answer_id": 373443,
"author": "Suresh Shinde",
"author_id": 167466,
"author_profile": "https://wordpress.stackexchange.com/users/167466",
"pm_score": -1,
"selected": false,
"text": "<p>You can do it by .htaccess file, for your case url format as;</p>\n<p>Redirect 301 /%post_id%/ <a hr... | 2020/08/21 | [
"https://wordpress.stackexchange.com/questions/373447",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/44637/"
] | Is it possible to disable the cropping step when adding a site icon via the Theme Customizer in WordPress 5+ (occurred to me in 5.5)?
For me cropping is unnecessary because I always upload a square image in the directions of the recommendations.
That's why this step is not helping me at all, instead is actually causi... | I've written my own solution, sharing it and hoping it will help someone.
Add this to your `functions.php`:
```
<?php
add_action('parse_request', 'redirect_postid_to_postname');
function redirect_postid_to_postname($wp)
{
// If /%post_id%/
if (is_numeric($wp->request)) {
$post_id = $wp->request;
... |
373,563 | <p>I am updating an array saved in a users meta field using an ajax function.</p>
<p>The values added to the array are taken from the data-attributes within the tags which also act at the trigger to make the ajax call.</p>
<p>Whilst the function works 95% of the time, it can be a bit hit and miss whether the values sa... | [
{
"answer_id": 373443,
"author": "Suresh Shinde",
"author_id": 167466,
"author_profile": "https://wordpress.stackexchange.com/users/167466",
"pm_score": -1,
"selected": false,
"text": "<p>You can do it by .htaccess file, for your case url format as;</p>\n<p>Redirect 301 /%post_id%/ <a hr... | 2020/08/23 | [
"https://wordpress.stackexchange.com/questions/373563",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57057/"
] | I am updating an array saved in a users meta field using an ajax function.
The values added to the array are taken from the data-attributes within the tags which also act at the trigger to make the ajax call.
Whilst the function works 95% of the time, it can be a bit hit and miss whether the values save or not. I sus... | I've written my own solution, sharing it and hoping it will help someone.
Add this to your `functions.php`:
```
<?php
add_action('parse_request', 'redirect_postid_to_postname');
function redirect_postid_to_postname($wp)
{
// If /%post_id%/
if (is_numeric($wp->request)) {
$post_id = $wp->request;
... |
373,573 | <p>My local development WordPress install on ServerPress is not writing error logs. I made changes to my wp-config.php file to enable error log writing for WordPress, and also tried editing the php.ini file for xampplite to try and enable error tracking, But still, I could not get any logs going, so I reverted that to ... | [
{
"answer_id": 373443,
"author": "Suresh Shinde",
"author_id": 167466,
"author_profile": "https://wordpress.stackexchange.com/users/167466",
"pm_score": -1,
"selected": false,
"text": "<p>You can do it by .htaccess file, for your case url format as;</p>\n<p>Redirect 301 /%post_id%/ <a hr... | 2020/08/23 | [
"https://wordpress.stackexchange.com/questions/373573",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/121047/"
] | My local development WordPress install on ServerPress is not writing error logs. I made changes to my wp-config.php file to enable error log writing for WordPress, and also tried editing the php.ini file for xampplite to try and enable error tracking, But still, I could not get any logs going, so I reverted that to its... | I've written my own solution, sharing it and hoping it will help someone.
Add this to your `functions.php`:
```
<?php
add_action('parse_request', 'redirect_postid_to_postname');
function redirect_postid_to_postname($wp)
{
// If /%post_id%/
if (is_numeric($wp->request)) {
$post_id = $wp->request;
... |
373,599 | <p>I have two custom post types "Product" and "News".
I want to keep a description that describes each of these types and I want to display it under the custom post title inside a banner. Also the user should be able to change it from admin dashboard.
That means when I go to products page, there is ... | [
{
"answer_id": 373443,
"author": "Suresh Shinde",
"author_id": 167466,
"author_profile": "https://wordpress.stackexchange.com/users/167466",
"pm_score": -1,
"selected": false,
"text": "<p>You can do it by .htaccess file, for your case url format as;</p>\n<p>Redirect 301 /%post_id%/ <a hr... | 2020/08/24 | [
"https://wordpress.stackexchange.com/questions/373599",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/193585/"
] | I have two custom post types "Product" and "News".
I want to keep a description that describes each of these types and I want to display it under the custom post title inside a banner. Also the user should be able to change it from admin dashboard.
That means when I go to products page, there is a banner on top of the ... | I've written my own solution, sharing it and hoping it will help someone.
Add this to your `functions.php`:
```
<?php
add_action('parse_request', 'redirect_postid_to_postname');
function redirect_postid_to_postname($wp)
{
// If /%post_id%/
if (is_numeric($wp->request)) {
$post_id = $wp->request;
... |
373,614 | <p>I am looking for a SQL Query that can give the list of all categories created in WordPress Site along with it's category IDs. Please advise a query to get it as category/term relationship is quite complex in WordPress.</p>
<p>I got this but didn't work -</p>
<pre><code>SELECT ID,post_title FROM wp_posts INNER JOIN w... | [
{
"answer_id": 373443,
"author": "Suresh Shinde",
"author_id": 167466,
"author_profile": "https://wordpress.stackexchange.com/users/167466",
"pm_score": -1,
"selected": false,
"text": "<p>You can do it by .htaccess file, for your case url format as;</p>\n<p>Redirect 301 /%post_id%/ <a hr... | 2020/08/24 | [
"https://wordpress.stackexchange.com/questions/373614",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/188153/"
] | I am looking for a SQL Query that can give the list of all categories created in WordPress Site along with it's category IDs. Please advise a query to get it as category/term relationship is quite complex in WordPress.
I got this but didn't work -
```
SELECT ID,post_title FROM wp_posts INNER JOIN wp_term_relationship... | I've written my own solution, sharing it and hoping it will help someone.
Add this to your `functions.php`:
```
<?php
add_action('parse_request', 'redirect_postid_to_postname');
function redirect_postid_to_postname($wp)
{
// If /%post_id%/
if (is_numeric($wp->request)) {
$post_id = $wp->request;
... |
373,667 | <p>In the WordPress customizer script, I am trying to pass the value from a select control into a custom control that displays taxonomies associated with the selected value (1st control).</p>
<pre><code>$wp_customize->add_control( new Tax_Dropdown_Control( $wp_customize, 'select_tax', array(
'section' =>... | [
{
"answer_id": 373443,
"author": "Suresh Shinde",
"author_id": 167466,
"author_profile": "https://wordpress.stackexchange.com/users/167466",
"pm_score": -1,
"selected": false,
"text": "<p>You can do it by .htaccess file, for your case url format as;</p>\n<p>Redirect 301 /%post_id%/ <a hr... | 2020/08/24 | [
"https://wordpress.stackexchange.com/questions/373667",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24067/"
] | In the WordPress customizer script, I am trying to pass the value from a select control into a custom control that displays taxonomies associated with the selected value (1st control).
```
$wp_customize->add_control( new Tax_Dropdown_Control( $wp_customize, 'select_tax', array(
'section' => 'section_1',
... | I've written my own solution, sharing it and hoping it will help someone.
Add this to your `functions.php`:
```
<?php
add_action('parse_request', 'redirect_postid_to_postname');
function redirect_postid_to_postname($wp)
{
// If /%post_id%/
if (is_numeric($wp->request)) {
$post_id = $wp->request;
... |
373,729 | <p>Update:</p>
<p>I created a fresh new installation of WordPress, copied both Base and Base Child themes and activated Base Child. The Appearance/Customize gives the same white screen as described in point 1 below.</p>
<p>I then activated Base and the Appearance/Customize screen has the same error, which did not occur... | [
{
"answer_id": 373443,
"author": "Suresh Shinde",
"author_id": 167466,
"author_profile": "https://wordpress.stackexchange.com/users/167466",
"pm_score": -1,
"selected": false,
"text": "<p>You can do it by .htaccess file, for your case url format as;</p>\n<p>Redirect 301 /%post_id%/ <a hr... | 2020/08/25 | [
"https://wordpress.stackexchange.com/questions/373729",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/193688/"
] | Update:
I created a fresh new installation of WordPress, copied both Base and Base Child themes and activated Base Child. The Appearance/Customize gives the same white screen as described in point 1 below.
I then activated Base and the Appearance/Customize screen has the same error, which did not occur on the previou... | I've written my own solution, sharing it and hoping it will help someone.
Add this to your `functions.php`:
```
<?php
add_action('parse_request', 'redirect_postid_to_postname');
function redirect_postid_to_postname($wp)
{
// If /%post_id%/
if (is_numeric($wp->request)) {
$post_id = $wp->request;
... |
373,769 | <p>I am creating a plugin to send posts to an external program. But I get a problem by getting the posts.</p>
<p>I created the code below to get the posts and echo them. But if I run it, it goes to the empty error message. When I echo the response. It only gets 'Array'</p>
<p>If I just post <code>http://localhost/wordp... | [
{
"answer_id": 373443,
"author": "Suresh Shinde",
"author_id": 167466,
"author_profile": "https://wordpress.stackexchange.com/users/167466",
"pm_score": -1,
"selected": false,
"text": "<p>You can do it by .htaccess file, for your case url format as;</p>\n<p>Redirect 301 /%post_id%/ <a hr... | 2020/08/26 | [
"https://wordpress.stackexchange.com/questions/373769",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/193728/"
] | I am creating a plugin to send posts to an external program. But I get a problem by getting the posts.
I created the code below to get the posts and echo them. But if I run it, it goes to the empty error message. When I echo the response. It only gets 'Array'
If I just post `http://localhost/wordpress/wp-json/wp/v2/p... | I've written my own solution, sharing it and hoping it will help someone.
Add this to your `functions.php`:
```
<?php
add_action('parse_request', 'redirect_postid_to_postname');
function redirect_postid_to_postname($wp)
{
// If /%post_id%/
if (is_numeric($wp->request)) {
$post_id = $wp->request;
... |
373,771 | <p>So I've been integrating WooCommerce with Stripe checkout and set everything up correctly, but when it comes to paying I get this response after hitting 'Place Order':</p>
<pre><code>No such customer: 'cus_Hu9exn9bPLd3SA'; a similar object exists in test mode, but a live mode key was used to make this request.
</cod... | [
{
"answer_id": 373443,
"author": "Suresh Shinde",
"author_id": 167466,
"author_profile": "https://wordpress.stackexchange.com/users/167466",
"pm_score": -1,
"selected": false,
"text": "<p>You can do it by .htaccess file, for your case url format as;</p>\n<p>Redirect 301 /%post_id%/ <a hr... | 2020/08/26 | [
"https://wordpress.stackexchange.com/questions/373771",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/193731/"
] | So I've been integrating WooCommerce with Stripe checkout and set everything up correctly, but when it comes to paying I get this response after hitting 'Place Order':
```
No such customer: 'cus_Hu9exn9bPLd3SA'; a similar object exists in test mode, but a live mode key was used to make this request.
```
I've set the... | I've written my own solution, sharing it and hoping it will help someone.
Add this to your `functions.php`:
```
<?php
add_action('parse_request', 'redirect_postid_to_postname');
function redirect_postid_to_postname($wp)
{
// If /%post_id%/
if (is_numeric($wp->request)) {
$post_id = $wp->request;
... |
373,777 | <p>I have an input field and when users enter any text then that will check the category name is available or not which user entered.</p>
<p><strong>Js</strong></p>
<pre><code>(function($) { // ready handler
$(".universalSearchField").keypress(function() {
$.ajax({
url: "/wp-admin/admin-aja... | [
{
"answer_id": 373443,
"author": "Suresh Shinde",
"author_id": 167466,
"author_profile": "https://wordpress.stackexchange.com/users/167466",
"pm_score": -1,
"selected": false,
"text": "<p>You can do it by .htaccess file, for your case url format as;</p>\n<p>Redirect 301 /%post_id%/ <a hr... | 2020/08/26 | [
"https://wordpress.stackexchange.com/questions/373777",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/177715/"
] | I have an input field and when users enter any text then that will check the category name is available or not which user entered.
**Js**
```
(function($) { // ready handler
$(".universalSearchField").keypress(function() {
$.ajax({
url: "/wp-admin/admin-ajax.php",
type: "post",
data: { a... | I've written my own solution, sharing it and hoping it will help someone.
Add this to your `functions.php`:
```
<?php
add_action('parse_request', 'redirect_postid_to_postname');
function redirect_postid_to_postname($wp)
{
// If /%post_id%/
if (is_numeric($wp->request)) {
$post_id = $wp->request;
... |
373,808 | <p>I try to create blog page with specific categories (by ID) and display only newest blog post from this category.
I have code like this but it shows only first category. I have work code for display only one category but when I put more id it doesn't work</p>
<pre><code><?php
/**
* Template Name: Porftfolio
*/
... | [
{
"answer_id": 373443,
"author": "Suresh Shinde",
"author_id": 167466,
"author_profile": "https://wordpress.stackexchange.com/users/167466",
"pm_score": -1,
"selected": false,
"text": "<p>You can do it by .htaccess file, for your case url format as;</p>\n<p>Redirect 301 /%post_id%/ <a hr... | 2020/08/26 | [
"https://wordpress.stackexchange.com/questions/373808",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/193750/"
] | I try to create blog page with specific categories (by ID) and display only newest blog post from this category.
I have code like this but it shows only first category. I have work code for display only one category but when I put more id it doesn't work
```
<?php
/**
* Template Name: Porftfolio
*/
get_header(); ?>... | I've written my own solution, sharing it and hoping it will help someone.
Add this to your `functions.php`:
```
<?php
add_action('parse_request', 'redirect_postid_to_postname');
function redirect_postid_to_postname($wp)
{
// If /%post_id%/
if (is_numeric($wp->request)) {
$post_id = $wp->request;
... |
373,847 | <p>Based on <a href="https://stackoverflow.com/questions/50183646/check-the-first-login-wordpress">this</a> answer i created a small functionality for users that are logging in for <em>the first 3 times</em> to make some elements classes use css animation. What i am trying to do is to adjust this code to count and cont... | [
{
"answer_id": 373443,
"author": "Suresh Shinde",
"author_id": 167466,
"author_profile": "https://wordpress.stackexchange.com/users/167466",
"pm_score": -1,
"selected": false,
"text": "<p>You can do it by .htaccess file, for your case url format as;</p>\n<p>Redirect 301 /%post_id%/ <a hr... | 2020/08/27 | [
"https://wordpress.stackexchange.com/questions/373847",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129972/"
] | Based on [this](https://stackoverflow.com/questions/50183646/check-the-first-login-wordpress) answer i created a small functionality for users that are logging in for *the first 3 times* to make some elements classes use css animation. What i am trying to do is to adjust this code to count and control the first 3 times... | I've written my own solution, sharing it and hoping it will help someone.
Add this to your `functions.php`:
```
<?php
add_action('parse_request', 'redirect_postid_to_postname');
function redirect_postid_to_postname($wp)
{
// If /%post_id%/
if (is_numeric($wp->request)) {
$post_id = $wp->request;
... |
373,880 | <p>Hello WP DEV Community,</p>
<p>I understand this question has been asked ad nauseam...</p>
<p>I'm trying to customize a development workflow (WordPress + WooCommerce) that allows me to develop locally (to speed up development, see changes instantly in browser) -- then push to PROD.</p>
<p>After reading many StackExc... | [
{
"answer_id": 373443,
"author": "Suresh Shinde",
"author_id": 167466,
"author_profile": "https://wordpress.stackexchange.com/users/167466",
"pm_score": -1,
"selected": false,
"text": "<p>You can do it by .htaccess file, for your case url format as;</p>\n<p>Redirect 301 /%post_id%/ <a hr... | 2020/08/27 | [
"https://wordpress.stackexchange.com/questions/373880",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/193719/"
] | Hello WP DEV Community,
I understand this question has been asked ad nauseam...
I'm trying to customize a development workflow (WordPress + WooCommerce) that allows me to develop locally (to speed up development, see changes instantly in browser) -- then push to PROD.
After reading many StackExchange posts/articles/... | I've written my own solution, sharing it and hoping it will help someone.
Add this to your `functions.php`:
```
<?php
add_action('parse_request', 'redirect_postid_to_postname');
function redirect_postid_to_postname($wp)
{
// If /%post_id%/
if (is_numeric($wp->request)) {
$post_id = $wp->request;
... |