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 |
|---|---|---|---|---|---|---|
296,440 | <p>I want to build a plugin to remove all posts by specific users from rest json output.
How can I add a <strong>filter</strong> or <strong>hook</strong> to do that?</p>
| [
{
"answer_id": 296444,
"author": "Alex Sancho",
"author_id": 2536,
"author_profile": "https://wordpress.stackexchange.com/users/2536",
"pm_score": 3,
"selected": true,
"text": "<p>If you're using WP 4.7+ you can filter the query using the <a href=\"https://developer.wordpress.org/referen... | 2018/03/11 | [
"https://wordpress.stackexchange.com/questions/296440",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/45010/"
] | I want to build a plugin to remove all posts by specific users from rest json output.
How can I add a **filter** or **hook** to do that? | If you're using WP 4.7+ you can filter the query using the [`rest_{$this->post_type}_query`](https://developer.wordpress.org/reference/hooks/rest_this-post_type_query/) hook `wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:L267`
This is a working example that filters current query by given terms
```... |
296,442 | <p>We use SASS when building custom themes, and sometimes clients need a quick change made which is easier to do on the server rather than locally and pushing new changes. To that end, we've installed SASS on our server to watch for file changes. The problem is, if we use the WordPress Appearance Editor to edit SASS fi... | [
{
"answer_id": 296449,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 3,
"selected": true,
"text": "<p>The WordPress theme/plugin (file) editor uses <a href=\"http://codemirror.net/\" rel=\"nofollow noreferrer\... | 2018/03/11 | [
"https://wordpress.stackexchange.com/questions/296442",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/90498/"
] | We use SASS when building custom themes, and sometimes clients need a quick change made which is easier to do on the server rather than locally and pushing new changes. To that end, we've installed SASS on our server to watch for file changes. The problem is, if we use the WordPress Appearance Editor to edit SASS files... | The WordPress theme/plugin (file) editor uses [CodeMirror](http://codemirror.net/) for syntax highlighting, and with the hook [`wp_enqueue_code_editor`](https://developer.wordpress.org/reference/functions/wp_enqueue_code_editor/) (which is available starting from WordPress version 4.9.0), you can filter the default Cod... |
296,490 | <p>I made profile page. And i am getting values directly from inputs with $_POST method. Users update their profile in this page. I wonder is this security method? And i am using this in wp_list_table too.</p>
| [
{
"answer_id": 296492,
"author": "CodeMascot",
"author_id": 44192,
"author_profile": "https://wordpress.stackexchange.com/users/44192",
"pm_score": 3,
"selected": true,
"text": "<p>You have to sanitize or escape the data based on type and application of the data. Like below-</p>\n\n<pre>... | 2018/03/12 | [
"https://wordpress.stackexchange.com/questions/296490",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/133897/"
] | I made profile page. And i am getting values directly from inputs with $\_POST method. Users update their profile in this page. I wonder is this security method? And i am using this in wp\_list\_table too. | You have to sanitize or escape the data based on type and application of the data. Like below-
```
$title = sanitize_text_field( $_POST['title'] );
update_post_meta( $post->ID, 'title', $title );
```
It's a quite huge topic. You better read this [Validating Sanitizing and Escaping User Data](https://codex.wordpress.... |
296,512 | <p>Currently, I have a meta box that all Editors of my site can see. I want all contributers to see this meta box. </p>
<p>I've used a user-role plugin and it looks like the meta box is linked to post settings. As when I enable any user to publish post they can see this meta box. </p>
<p>Is there a way to make this m... | [
{
"answer_id": 296492,
"author": "CodeMascot",
"author_id": 44192,
"author_profile": "https://wordpress.stackexchange.com/users/44192",
"pm_score": 3,
"selected": true,
"text": "<p>You have to sanitize or escape the data based on type and application of the data. Like below-</p>\n\n<pre>... | 2018/03/12 | [
"https://wordpress.stackexchange.com/questions/296512",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/137717/"
] | Currently, I have a meta box that all Editors of my site can see. I want all contributers to see this meta box.
I've used a user-role plugin and it looks like the meta box is linked to post settings. As when I enable any user to publish post they can see this meta box.
Is there a way to make this meta-box viewable ... | You have to sanitize or escape the data based on type and application of the data. Like below-
```
$title = sanitize_text_field( $_POST['title'] );
update_post_meta( $post->ID, 'title', $title );
```
It's a quite huge topic. You better read this [Validating Sanitizing and Escaping User Data](https://codex.wordpress.... |
296,529 | <p>I want to get unique results from this function</p>
<pre><code>global $wpdb;
$helloworld_id = $wpdb->get_results(
"SELECT * FROM $wpdb->postmeta WHERE meta_key = 'wc_billing_field_3465'"
);
foreach( $helloworld_id as $result ) {
echo $result->meta_value;
}
</code></pre>
| [
{
"answer_id": 296530,
"author": "Zachary Reese",
"author_id": 83342,
"author_profile": "https://wordpress.stackexchange.com/users/83342",
"pm_score": 0,
"selected": false,
"text": "<p>You'd want to use an array to store the results, then the <a href=\"http://php.net/manual/en/function.a... | 2018/03/12 | [
"https://wordpress.stackexchange.com/questions/296529",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/89477/"
] | I want to get unique results from this function
```
global $wpdb;
$helloworld_id = $wpdb->get_results(
"SELECT * FROM $wpdb->postmeta WHERE meta_key = 'wc_billing_field_3465'"
);
foreach( $helloworld_id as $result ) {
echo $result->meta_value;
}
``` | It would likely be more efficient to change your database query to
>
> SELECT DISTINCT meta\_value FROM $wpdb->postmeta WHERE meta\_key = 'wc\_billing\_field\_3465'
>
>
> |
296,537 | <p>I am making a category template page with pagination and below is my code:</p>
<pre><code><?php
$current_page = get_queried_object();
$category = $current_page->slug;
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$query = new WP_Query(
array(
'paged' => $paged,
... | [
{
"answer_id": 296548,
"author": "Run",
"author_id": 89898,
"author_profile": "https://wordpress.stackexchange.com/users/89898",
"pm_score": 1,
"selected": false,
"text": "<p>This how I fix this problem:</p>\n\n<pre><code>// Fix 404 on category pagination.\n// https://teamtreehouse.com/c... | 2018/03/12 | [
"https://wordpress.stackexchange.com/questions/296537",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/89898/"
] | I am making a category template page with pagination and below is my code:
```
<?php
$current_page = get_queried_object();
$category = $current_page->slug;
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$query = new WP_Query(
array(
'paged' => $paged,
'category_name'... | The steps WordPress takes to serve a front end request are roughly-
1. The incoming URL is parsed and converted to query vars.
2. These query vars form the **Main Query**, which is sent to the database.
3. WordPress looks at the results and determines if the request was successful or not, which determines what status ... |
296,589 | <p>I try every solution what I find on the net, but none of them work. I using generatepress.</p>
<p>My latest trying that, but not working...:</p>
<pre><code>if ( is_front_page() && is_home() ) {
remove_theme_support( 'title-tag' );
echo '<title>' . get_bloginfo( 'name' ) . ' | mydomain.com<... | [
{
"answer_id": 296593,
"author": "Jignesh Patel",
"author_id": 111556,
"author_profile": "https://wordpress.stackexchange.com/users/111556",
"pm_score": 3,
"selected": true,
"text": "<p>If first check in your header.php file and check in title tag what is print. if in title tag bloginfo ... | 2018/03/13 | [
"https://wordpress.stackexchange.com/questions/296589",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/134567/"
] | I try every solution what I find on the net, but none of them work. I using generatepress.
My latest trying that, but not working...:
```
if ( is_front_page() && is_home() ) {
remove_theme_support( 'title-tag' );
echo '<title>' . get_bloginfo( 'name' ) . ' | mydomain.com</title>';
}
```
Very frustrating... | If first check in your header.php file and check in title tag what is print. if in title tag bloginfo then it's replace with wp\_title('') because bloginfo is not replace with code.
Header.php
```
<title><?php wp_title(''); ?></title>
```
After function.php file put this code:
```
function wpdocs_theme_name_w... |
296,592 | <p>I have wordpress installed in root folder of domain.com</p>
<p>I want to load index.html when domain.com is visited and domain.com/my-posts/ should load normal wordpress posts.</p>
<p>I am doing this to increase speed of my wordpress homepage.I dont want any php to be involved.</p>
<p>Will renaming index.php to i... | [
{
"answer_id": 296816,
"author": "Dave Hunt",
"author_id": 1769,
"author_profile": "https://wordpress.stackexchange.com/users/1769",
"pm_score": 2,
"selected": false,
"text": "<p>If your concern is that PHP or MySQL is causing the page load speed to decrease, I recommend installing a Cac... | 2018/03/13 | [
"https://wordpress.stackexchange.com/questions/296592",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/138510/"
] | I have wordpress installed in root folder of domain.com
I want to load index.html when domain.com is visited and domain.com/my-posts/ should load normal wordpress posts.
I am doing this to increase speed of my wordpress homepage.I dont want any php to be involved.
Will renaming index.php to index.html and putting my... | I **strongly** advise you to heed the advice already given. If your PHP is well structured and you take advantage of caching methods, it won't have a significant increase on your page load time. We've got pages with extremely complex queries that are hardly optimized, but using some clever caching methods, we're able t... |
296,612 | <p>I try to build an plugin with an custom db table. So I include the notifications.php in the plugin index.php file. If I do a die; in the public function init() (in notifications.php), it dies so it's loaded, but the register_activation_hook not triggers on activate te plugin and the my_notifications_install fuction ... | [
{
"answer_id": 296615,
"author": "Sebastian Kurzynowski",
"author_id": 108925,
"author_profile": "https://wordpress.stackexchange.com/users/108925",
"pm_score": 1,
"selected": false,
"text": "<pre><code>register_activation_hook( __FILE__, array( $this, 'my_notifications_install' ) );\n</... | 2018/03/13 | [
"https://wordpress.stackexchange.com/questions/296612",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/54693/"
] | I try to build an plugin with an custom db table. So I include the notifications.php in the plugin index.php file. If I do a die; in the public function init() (in notifications.php), it dies so it's loaded, but the register\_activation\_hook not triggers on activate te plugin and the my\_notifications\_install fuction... | The rule of thumb is to never do anything which is not triggered by action or filter.
In this case you try register a hook before wordpress even finished to "boot". This may work sometimes, but totally not an healthy idea. Use at least the 'init' hook (and even better the 'wp\_loaded' if you can), to trigger you init... |
296,620 | <p>I'm writing a plugin which collects a pretty large feed. From each feed item a custom post will be created. The feed can also contain images for each item that is uploaded from the remote url. Processing the entire feed can take some time and since I would like to do the processing in the background I am looking int... | [
{
"answer_id": 296615,
"author": "Sebastian Kurzynowski",
"author_id": 108925,
"author_profile": "https://wordpress.stackexchange.com/users/108925",
"pm_score": 1,
"selected": false,
"text": "<pre><code>register_activation_hook( __FILE__, array( $this, 'my_notifications_install' ) );\n</... | 2018/03/13 | [
"https://wordpress.stackexchange.com/questions/296620",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14870/"
] | I'm writing a plugin which collects a pretty large feed. From each feed item a custom post will be created. The feed can also contain images for each item that is uploaded from the remote url. Processing the entire feed can take some time and since I would like to do the processing in the background I am looking into c... | The rule of thumb is to never do anything which is not triggered by action or filter.
In this case you try register a hook before wordpress even finished to "boot". This may work sometimes, but totally not an healthy idea. Use at least the 'init' hook (and even better the 'wp\_loaded' if you can), to trigger you init... |
296,699 | <p>For the purposes of my site, I have my Permalinks set to <code>/blog/%postname%/</code> for all posts.</p>
<p>However, I need to give Posts with a specific Category (in this case, "Testimonials") its own permalink structure, where each individual post assigned the Category "Testimonials" returns as <code>/testimoni... | [
{
"answer_id": 296703,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 4,
"selected": true,
"text": "<p>Try these steps:</p>\n\n<p><strong>Step #1:</strong> Replace this:</p>\n\n<pre><code>add_action( 'init', 'c... | 2018/03/13 | [
"https://wordpress.stackexchange.com/questions/296699",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/118009/"
] | For the purposes of my site, I have my Permalinks set to `/blog/%postname%/` for all posts.
However, I need to give Posts with a specific Category (in this case, "Testimonials") its own permalink structure, where each individual post assigned the Category "Testimonials" returns as `/testimonials/%postname%/` and the C... | Try these steps:
**Step #1:** Replace this:
```
add_action( 'init', 'custom_rewrite_rules' );
function custom_rewrite_rules() {
add_rewrite_rule(
'testimonials/([^/]+)(?:/([0-9]+))?/?$',
'index.php?category_name=testimonials&name=$matches[1]&page=$matches[2]',
'top' // The rule position; e... |
296,716 | <p>I'm developing 'multi category select search form'.
And make it like this</p>
<pre><code><form role="search" action="http://localhost:5757/alpool/" method="get">
<input type="hidden" name="alp-search" value="true">
<div class="ui fluid search dropdown huge selection multiple">
<se... | [
{
"answer_id": 296719,
"author": "danielh",
"author_id": 110001,
"author_profile": "https://wordpress.stackexchange.com/users/110001",
"pm_score": 0,
"selected": false,
"text": "<p>%5B%5D is urlencoded for <code>[]</code>, as specified with <code>cat_s[]</code>.</p>\n\n<p>If you want it ... | 2018/03/14 | [
"https://wordpress.stackexchange.com/questions/296716",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/136439/"
] | I'm developing 'multi category select search form'.
And make it like this
```
<form role="search" action="http://localhost:5757/alpool/" method="get">
<input type="hidden" name="alp-search" value="true">
<div class="ui fluid search dropdown huge selection multiple">
<select name="cat_s[]" multiple="multi... | >
> My question are these.
>
>
> 1. What is %5B%5D ?
> 2. How can I change the url like this
>
>
> `http://localhost:5757/alpool/?alp-search=true&cat_s=358,399`
>
>
>
1. `%5B` and `%5D` are *percent-encoded*/URL-encoded version of the `[` (left square bracket) and `]` (right square bracket) characters, respect... |
296,726 | <p>I want to set margin-bottom:10px for article in <a href="http://104.223.65.117/wp/?s=emmet" rel="nofollow noreferrer">http://104.223.65.117/wp/?s=emmet</a>.</p>
<p>Method 1:</p>
<p>sudo cat /var/www/html/wp/wp-content/themes/twentyfourteen-child/style.css</p>
<pre><code>*{
font-family:"DejaVu Sans Mono" !im... | [
{
"answer_id": 296719,
"author": "danielh",
"author_id": 110001,
"author_profile": "https://wordpress.stackexchange.com/users/110001",
"pm_score": 0,
"selected": false,
"text": "<p>%5B%5D is urlencoded for <code>[]</code>, as specified with <code>cat_s[]</code>.</p>\n\n<p>If you want it ... | 2018/03/14 | [
"https://wordpress.stackexchange.com/questions/296726",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/119358/"
] | I want to set margin-bottom:10px for article in <http://104.223.65.117/wp/?s=emmet>.
Method 1:
sudo cat /var/www/html/wp/wp-content/themes/twentyfourteen-child/style.css
```
*{
font-family:"DejaVu Sans Mono" !important;
}
.site {
max-width: 1920px;
}
.site::before{
width:400px;
}
.site-header {
max-w... | >
> My question are these.
>
>
> 1. What is %5B%5D ?
> 2. How can I change the url like this
>
>
> `http://localhost:5757/alpool/?alp-search=true&cat_s=358,399`
>
>
>
1. `%5B` and `%5D` are *percent-encoded*/URL-encoded version of the `[` (left square bracket) and `]` (right square bracket) characters, respect... |
296,727 | <p>I'm not talking about subdomain/subfolder. I am talking about moving my whole Wordpress Multisite installation to example.com/ms/. And keeping the root for another non-multisite install of wordpress.
I tried creating a folder /ms/ in the root. Moved everything there. Went to wp-config, changed to define('DOMAIN_CURR... | [
{
"answer_id": 296719,
"author": "danielh",
"author_id": 110001,
"author_profile": "https://wordpress.stackexchange.com/users/110001",
"pm_score": 0,
"selected": false,
"text": "<p>%5B%5D is urlencoded for <code>[]</code>, as specified with <code>cat_s[]</code>.</p>\n\n<p>If you want it ... | 2018/03/14 | [
"https://wordpress.stackexchange.com/questions/296727",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/138051/"
] | I'm not talking about subdomain/subfolder. I am talking about moving my whole Wordpress Multisite installation to example.com/ms/. And keeping the root for another non-multisite install of wordpress.
I tried creating a folder /ms/ in the root. Moved everything there. Went to wp-config, changed to define('DOMAIN\_CURREN... | >
> My question are these.
>
>
> 1. What is %5B%5D ?
> 2. How can I change the url like this
>
>
> `http://localhost:5757/alpool/?alp-search=true&cat_s=358,399`
>
>
>
1. `%5B` and `%5D` are *percent-encoded*/URL-encoded version of the `[` (left square bracket) and `]` (right square bracket) characters, respect... |
296,775 | <p>Basically, I'm trying to override some files of the Uncode theme. But this is not a theme-specific question: it can be applied to any theme. The Uncode theme has a custom dir <code>'partials'</code> (<code>/uncode/partials/</code>) that contains some layout elements. On my child theme I created a 'partials' folder a... | [
{
"answer_id": 296791,
"author": "weston deboer",
"author_id": 8926,
"author_profile": "https://wordpress.stackexchange.com/users/8926",
"pm_score": 0,
"selected": false,
"text": "<p>That is a very good question, the theme directory can be quite confusing sometimes. </p>\n\n<p>The answer... | 2018/03/14 | [
"https://wordpress.stackexchange.com/questions/296775",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10381/"
] | Basically, I'm trying to override some files of the Uncode theme. But this is not a theme-specific question: it can be applied to any theme. The Uncode theme has a custom dir `'partials'` (`/uncode/partials/`) that contains some layout elements. On my child theme I created a 'partials' folder as well (`my-child-theme/p... | It depends entirely on the parent theme. While WordPress will check the child theme for templates in the [Template Hierarchy](https://developer.wordpress.org/themes/basics/template-hierarchy/) and use those if they are present, it's up to theme authors to decide how much overwriting by child themes they want to support... |
296,778 | <p>So I'm working on a medical site that has a custom post type "doctors". Within this post type are custom taxonomies for "locations" and "procedures". I've created a custom taxonomy-locations.php file to control how my locations pages look, on this page is some general information like contact info, maps, related doc... | [
{
"answer_id": 296781,
"author": "WebElaine",
"author_id": 102815,
"author_profile": "https://wordpress.stackexchange.com/users/102815",
"pm_score": 2,
"selected": false,
"text": "<p>You should be able to change these lines</p>\n\n<pre><code>if ( !empty($terms) ) {\n foreach( $terms a... | 2018/03/14 | [
"https://wordpress.stackexchange.com/questions/296778",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/138635/"
] | So I'm working on a medical site that has a custom post type "doctors". Within this post type are custom taxonomies for "locations" and "procedures". I've created a custom taxonomy-locations.php file to control how my locations pages look, on this page is some general information like contact info, maps, related doctor... | You should be able to change these lines
```
if ( !empty($terms) ) {
foreach( $terms as $term ) {
echo $term->term_id . ',';
}
}
```
to this:
```
if ( !empty($terms) ) {
// create an empty array
$procedures_to_include = array();
foreach( $terms as $term ) {
// now instead of ec... |
296,780 | <p><strong>I have this situation:</strong></p>
<ol>
<li>I activated Multisite mode to develop the main website in a secondary site with subdomain "beta";</li>
</ol>
<blockquote>
<p>EX: www.mysite.com, beta.mysite.com</p>
</blockquote>
<ol start="2">
<li><p>I duplicated the default theme with "beta" suffix, but ... | [
{
"answer_id": 296781,
"author": "WebElaine",
"author_id": 102815,
"author_profile": "https://wordpress.stackexchange.com/users/102815",
"pm_score": 2,
"selected": false,
"text": "<p>You should be able to change these lines</p>\n\n<pre><code>if ( !empty($terms) ) {\n foreach( $terms a... | 2018/03/14 | [
"https://wordpress.stackexchange.com/questions/296780",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/136313/"
] | **I have this situation:**
1. I activated Multisite mode to develop the main website in a secondary site with subdomain "beta";
>
> EX: www.mysite.com, beta.mysite.com
>
>
>
2. I duplicated the default theme with "beta" suffix, but it is not set as a child theme;
3. every site has applied with the own respective... | You should be able to change these lines
```
if ( !empty($terms) ) {
foreach( $terms as $term ) {
echo $term->term_id . ',';
}
}
```
to this:
```
if ( !empty($terms) ) {
// create an empty array
$procedures_to_include = array();
foreach( $terms as $term ) {
// now instead of ec... |
296,805 | <p>I have thousands of posts that I am displaying on my home page. I want to control number of posts so for this I am using <code>posts_per_page</code>but it is not working for me. All other arguments works but <code>posts_per_page</code> is not working. I have pagination on this page and <code>posts_per_page</code> wo... | [
{
"answer_id": 296807,
"author": "mad2kx",
"author_id": 138622,
"author_profile": "https://wordpress.stackexchange.com/users/138622",
"pm_score": 0,
"selected": false,
"text": "<p>Did you try this one?</p>\n\n<pre><code>function posts_on_homepage( $query ) {\n if ( $query->is_home(... | 2018/03/14 | [
"https://wordpress.stackexchange.com/questions/296805",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/120693/"
] | I have thousands of posts that I am displaying on my home page. I want to control number of posts so for this I am using `posts_per_page`but it is not working for me. All other arguments works but `posts_per_page` is not working. I have pagination on this page and `posts_per_page` works for all other pages of paginatio... | Did you try this one?
```
<?php
$blogpost = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 6
));
?>
<?php while($blogpost->have_posts()) : $blogpost->the_post(); ?>
// Writhe your Blog article Here.
<?php endwhile; ?>
``` |
296,817 | <p>So, I have a loop that works great.</p>
<p>But I need to count how many posts that loop has, and I need to do it via a query to the DB.</p>
<p>My loop looks like:</p>
<pre><code>$adsArg = array(
'offset' => $offset,
'post_type' => 'ads',
'meta_key' => $metaKey,
... | [
{
"answer_id": 296818,
"author": "David Sword",
"author_id": 132362,
"author_profile": "https://wordpress.stackexchange.com/users/132362",
"pm_score": 3,
"selected": true,
"text": "<p>To get the number of posts you can do it easily without a second query with</p>\n\n<pre><code>$adsQuery-... | 2018/03/14 | [
"https://wordpress.stackexchange.com/questions/296817",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/44437/"
] | So, I have a loop that works great.
But I need to count how many posts that loop has, and I need to do it via a query to the DB.
My loop looks like:
```
$adsArg = array(
'offset' => $offset,
'post_type' => 'ads',
'meta_key' => $metaKey,
'tax_query' => $taxQuery... | To get the number of posts you can do it easily without a second query with
```
$adsQuery->post_count;
```
But if there's some reason (I'd love to know the context!) I can't grasp that the same query has to be run twice and to the database directly- to answer your question as to why it's not working:
* Has `$table_... |
296,852 | <p>I would like to change the "Product has been added to your cart." text for variable products to include the variation.</p>
<p>For example if I added a size 7 Shoe to my cart it should say: "Shoe in Size 7 was added to your cart"</p>
<p>What do I have to edit to change this?</p>
| [
{
"answer_id": 296853,
"author": "melvin",
"author_id": 130740,
"author_profile": "https://wordpress.stackexchange.com/users/130740",
"pm_score": 3,
"selected": true,
"text": "<pre><code>add_filter( 'wc_add_to_cart_message', 'my_add_to_cart_function', 10, 2 ); \n\nfunction my_add_to_cart... | 2018/03/15 | [
"https://wordpress.stackexchange.com/questions/296852",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128837/"
] | I would like to change the "Product has been added to your cart." text for variable products to include the variation.
For example if I added a size 7 Shoe to my cart it should say: "Shoe in Size 7 was added to your cart"
What do I have to edit to change this? | ```
add_filter( 'wc_add_to_cart_message', 'my_add_to_cart_function', 10, 2 );
function my_add_to_cart_function( $message, $product_id ) {
$message = sprintf(esc_html__('« %s » has been added by to your cart.','woocommerce'), get_the_title( $product_id ) );
return $message;
}
```
The above code will help ... |
296,882 | <p>I have big problem with white screen in WordPress.</p>
<p>I would like to migrate site from live to localhost, I don't have credentials for hosting, and I've migrated site using All In One Import Plugin.</p>
<p><strong>Steps:</strong></p>
<ol>
<li>I've extracted <code>.wpress</code> file using <code>wpress-extrac... | [
{
"answer_id": 296853,
"author": "melvin",
"author_id": 130740,
"author_profile": "https://wordpress.stackexchange.com/users/130740",
"pm_score": 3,
"selected": true,
"text": "<pre><code>add_filter( 'wc_add_to_cart_message', 'my_add_to_cart_function', 10, 2 ); \n\nfunction my_add_to_cart... | 2018/03/15 | [
"https://wordpress.stackexchange.com/questions/296882",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/132584/"
] | I have big problem with white screen in WordPress.
I would like to migrate site from live to localhost, I don't have credentials for hosting, and I've migrated site using All In One Import Plugin.
**Steps:**
1. I've extracted `.wpress` file using `wpress-extractor`.
2. On Localhost installed fresh WordPress
3. Creat... | ```
add_filter( 'wc_add_to_cart_message', 'my_add_to_cart_function', 10, 2 );
function my_add_to_cart_function( $message, $product_id ) {
$message = sprintf(esc_html__('« %s » has been added by to your cart.','woocommerce'), get_the_title( $product_id ) );
return $message;
}
```
The above code will help ... |
296,942 | <p>It's the first I have seen this.
In a project I'm working on, I tried to switch on the debug mode for wordpress to see logs. Even if I activate the debug_log in <code>wp-config.php</code>, <code>debug.log</code> file is never created in <code>/htdocs/wp-content/</code></p>
<p><strong>wp-config.php</strong></p>
<pr... | [
{
"answer_id": 301298,
"author": "J.BizMai",
"author_id": 128094,
"author_profile": "https://wordpress.stackexchange.com/users/128094",
"pm_score": 4,
"selected": true,
"text": "<p>I found the problem.\nIn the Apache server, inside the php.ini, the variable...</p>\n\n<pre><code>track_err... | 2018/03/15 | [
"https://wordpress.stackexchange.com/questions/296942",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128094/"
] | It's the first I have seen this.
In a project I'm working on, I tried to switch on the debug mode for wordpress to see logs. Even if I activate the debug\_log in `wp-config.php`, `debug.log` file is never created in `/htdocs/wp-content/`
**wp-config.php**
```
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
de... | I found the problem.
In the Apache server, inside the php.ini, the variable...
```
track_errors = Off
```
To get this information, you can do in a phpfile `phpinfo();`.
So, to write the debug log file, you need to set `track_errors` as `'On'`. |
296,947 | <p>I was reading <a href="https://stackoverflow.com/a/4447615/1080355">this answer</a>, and tried to used its guide to <a href="http://www.bestwpthemez.com/wordpress/how-to-hide-your-wp-admin-login-page-2437/" rel="nofollow noreferrer">hide login page</a>. It suggest to edit <code>.htaccess</code> file of my website t... | [
{
"answer_id": 296948,
"author": "Oliver Leach",
"author_id": 138726,
"author_profile": "https://wordpress.stackexchange.com/users/138726",
"pm_score": -1,
"selected": false,
"text": "<p>No it shouldn't interfere, I have rules inside that block and they are all still active, even after c... | 2018/03/15 | [
"https://wordpress.stackexchange.com/questions/296947",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/86163/"
] | I was reading [this answer](https://stackoverflow.com/a/4447615/1080355), and tried to used its guide to [hide login page](http://www.bestwpthemez.com/wordpress/how-to-hide-your-wp-admin-login-page-2437/). It suggest to edit `.htaccess` file of my website to something like this:
```
RewriteEngine On
RewriteBase /
###... | Wordpress uses those markers to put its rules between. I never have and never would put custom rules in there.
Check out `insert_with_markers()` and `save_mod_rewrite_rules()` in
[`wp-admin/includes/misc.php`](https://github.com/WordPress/WordPress/blob/d7025e778704c7cd98f0a3544fbe93cacbef7ae6/wp-admin/includes/misc.... |
296,953 | <p>I'm working on a site that uses FacetWP for an events location page and one critical feature is not working. Last year, another dev set up a custom solution to list out FacetWP posts and have them sorted by the state they are in. They used a custom taxonomy for this, but since then, the plugin and is map add-on have... | [
{
"answer_id": 296957,
"author": "digDoug",
"author_id": 138731,
"author_profile": "https://wordpress.stackexchange.com/users/138731",
"pm_score": 0,
"selected": false,
"text": "<p>All you need to do is list out the custom field values in a few foreach loops like so: </p>\n\n<pre><code>&... | 2018/03/15 | [
"https://wordpress.stackexchange.com/questions/296953",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/118681/"
] | I'm working on a site that uses FacetWP for an events location page and one critical feature is not working. Last year, another dev set up a custom solution to list out FacetWP posts and have them sorted by the state they are in. They used a custom taxonomy for this, but since then, the plugin and is map add-on have ha... | I finally fixed it:
```
<?php
$state_posts = array();
while ($query->have_posts()) {
$query->the_post();
$state = get_post_meta(get_the_ID(), 'state', true);
$state_posts[$state][] = $post;
}
wp_reset_query();
foreach ($state_posts as $state_post => $state_title) {
?>
... |
296,956 | <p>I'm working on a messy customer project.
To debug it, I would like to work on it on localhost.
I'm using Wampserver.</p>
<p>This is what I did :</p>
<p>1 - I made a virtualhost</p>
<p><strong>httpd-vhosts.conf</strong></p>
<pre><code><VirtualHost *:80>
ServerName devfoo.pro
DocumentRoot "c:/path/t... | [
{
"answer_id": 296960,
"author": "JBoulhous",
"author_id": 137648,
"author_profile": "https://wordpress.stackexchange.com/users/137648",
"pm_score": 1,
"selected": false,
"text": "<p>I also had this experience with chrome and firefox, they switch http to https and did not find a way to o... | 2018/03/15 | [
"https://wordpress.stackexchange.com/questions/296956",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128094/"
] | I'm working on a messy customer project.
To debug it, I would like to work on it on localhost.
I'm using Wampserver.
This is what I did :
1 - I made a virtualhost
**httpd-vhosts.conf**
```
<VirtualHost *:80>
ServerName devfoo.pro
DocumentRoot "c:/path/to/project/src/www"
<Directory "c:/path/to/project/... | I also had this experience with chrome and firefox, they switch http to https and did not find a way to overcome it, so i used internet explorer in that windows machine.
I don't think you can have ssl on localhost or an ip address, i guess you know it as you used devfoo.pro. SSL certificate could be generated only f... |
296,966 | <p>I'm working on a Wordpress theme for a website that makes heavy use of its default media player. In the process of styling its playlists, I found that a core file injects hardcoded characters that can't be made invisible just by using CSS, so I'm a bit clueless about how to hide/remove them. </p>
<p>These character... | [
{
"answer_id": 296967,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 4,
"selected": true,
"text": "<p>Inside the shortcode function for playlists, there is this line:</p>\n\n<pre><code>do_action( 'wp_playli... | 2018/03/16 | [
"https://wordpress.stackexchange.com/questions/296966",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/86030/"
] | I'm working on a Wordpress theme for a website that makes heavy use of its default media player. In the process of styling its playlists, I found that a core file injects hardcoded characters that can't be made invisible just by using CSS, so I'm a bit clueless about how to hide/remove them.
These characters are inje... | Inside the shortcode function for playlists, there is this line:
```
do_action( 'wp_playlist_scripts', $atts['type'], $atts['style'] );
```
Hooked into that is `wp_playlist_scripts()` which hooks the templates into the footer:
```
add_action( 'wp_footer', 'wp_underscore_playlist_templates', 0 );
add_action( 'admin_... |
296,983 | <p>I want to change heading tags from child theme but i can't figure out how to add filter to parent theme function. </p>
<p>Parent theme function that i want to change:</p>
<pre><code>if(! class_exists('WpkPageHelper')) {
class WpkPageHelper
{
public static function zn_get_subheader( $args = array(), $is_pb_elem... | [
{
"answer_id": 296986,
"author": "Dharmishtha Patel",
"author_id": 135085,
"author_profile": "https://wordpress.stackexchange.com/users/135085",
"pm_score": -1,
"selected": false,
"text": "<p>I do not see you actually calling child_remove_parent_function() in your code.</p>\n\n<p>Another... | 2018/03/16 | [
"https://wordpress.stackexchange.com/questions/296983",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/138751/"
] | I want to change heading tags from child theme but i can't figure out how to add filter to parent theme function.
Parent theme function that i want to change:
```
if(! class_exists('WpkPageHelper')) {
class WpkPageHelper
{
public static function zn_get_subheader( $args = array(), $is_pb_element = false )
{
... | There is no filter. To filter a value the developer needs to create a filter by wrapping the filterable value in a call to `apply_filters()` with a name for that filter. They have not done that.
What they *have* done is make the `WpkPageHelper` class *pluggable*. This means that it's possible for a child theme to rep... |
296,988 | <pre><code>add_action('admin_menu', 'remove_admin_menu_links');
function remove_admin_menu_links(){
$user = wp_get_current_user();
if( $user && isset($user->user_email) && 'email@address.com' == $user->user_email ) {
remove_menu_page('upload.php'); ... | [
{
"answer_id": 297008,
"author": "Beee",
"author_id": 103402,
"author_profile": "https://wordpress.stackexchange.com/users/103402",
"pm_score": 1,
"selected": true,
"text": "<p>The admin bar is hooked incorrectly.It should be hooked to <code>wp_before_admin_bar_render</code>.</p>\n\n<p>T... | 2018/03/16 | [
"https://wordpress.stackexchange.com/questions/296988",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/136745/"
] | ```
add_action('admin_menu', 'remove_admin_menu_links');
function remove_admin_menu_links(){
$user = wp_get_current_user();
if( $user && isset($user->user_email) && 'email@address.com' == $user->user_email ) {
remove_menu_page('upload.php'); // Media - works(remove)
... | The admin bar is hooked incorrectly.It should be hooked to `wp_before_admin_bar_render`.
This is what I use (and works):
```
function alter_admin_bar() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu( 'customize' );
$wp_admin_bar->remove_menu( 'ddw-gravityforms-toolbar' );
$wp_admin_bar->remove_men... |
296,999 | <p>I am creating a plugin that adds a custom sortable column(Reputation Score) to the users table displayed at admin page > users, the problem is the column's data should be fetched from a MySQL table wp_user_reputation (<code>userid</code>,<code>user_reputation_score</code>) [created for our own purpose].</p>
<p>My a... | [
{
"answer_id": 297013,
"author": "Florian",
"author_id": 10595,
"author_profile": "https://wordpress.stackexchange.com/users/10595",
"pm_score": 0,
"selected": false,
"text": "<p>You would have to construct a custom MySQL-query to retrieve the sorted <code>userid</code> from your <code>w... | 2018/03/16 | [
"https://wordpress.stackexchange.com/questions/296999",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/138763/"
] | I am creating a plugin that adds a custom sortable column(Reputation Score) to the users table displayed at admin page > users, the problem is the column's data should be fetched from a MySQL table wp\_user\_reputation (`userid`,`user_reputation_score`) [created for our own purpose].
My assessment is that I would need... | To avoid a second query just for sorting you could use the `pre_user_query` hook to support a custom `orderby` value.
This code will enable sorting users by reputation in a single query just by setting `orderby` to `reputation`.
```
function wpse_296999_pre_user_query( $user_query ) {
global $wpdb;
$order = ... |
297,007 | <p>I am using a premium theme on my page. The theme only accepts one menu in the whole site.</p>
<p>The site is a single page site. And the way the theme works is that we have to set up a Home Page and then use the Menu items in order to make the sections of the site. </p>
<p>So, I created a Menu with all the section... | [
{
"answer_id": 297010,
"author": "Interactive",
"author_id": 52240,
"author_profile": "https://wordpress.stackexchange.com/users/52240",
"pm_score": -1,
"selected": false,
"text": "<p>There are good plugins for this without paying...</p>\n\n<p>But you can also (which you should have alre... | 2018/03/16 | [
"https://wordpress.stackexchange.com/questions/297007",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/138772/"
] | I am using a premium theme on my page. The theme only accepts one menu in the whole site.
The site is a single page site. And the way the theme works is that we have to set up a Home Page and then use the Menu items in order to make the sections of the site.
So, I created a Menu with all the sections I want to have ... | I'm not sure, but if I understand correctly you should create a second menu which is only visible on your Spanish language page.
```
if (is_page($english_page_id)) {
wp_nav_menu( array('menu'=>$english_menu) );
}
if (is_page($spanish_page_id)) {
wp_nav_menu( array('menu'=>$spanish_menu) )
}
```
[`is_page()`... |
297,024 | <p>I am looking for a way to remove/unhook all assets (css and javascript) files added to customize_controls_enqueue_scripts hook when the query string <code>mo-reset=true</code> is added to the customize url.</p>
| [
{
"answer_id": 297025,
"author": "Beee",
"author_id": 103402,
"author_profile": "https://wordpress.stackexchange.com/users/103402",
"pm_score": 0,
"selected": false,
"text": "<p>Check <a href=\"https://codex.wordpress.org/Function_Reference/wp_deregister_script\" rel=\"nofollow noreferre... | 2018/03/16 | [
"https://wordpress.stackexchange.com/questions/297024",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/59917/"
] | I am looking for a way to remove/unhook all assets (css and javascript) files added to customize\_controls\_enqueue\_scripts hook when the query string `mo-reset=true` is added to the customize url. | You can use the `global $wp_scripts` and `global $wp_styles;` to get all registerd scripts and styles.
Eg.
[](https://i.stack.imgur.com/7uDac.png)
All **Scripts**
```
// All Scripts
global $wp_scripts;
$all_scripts = array();
foreach( $wp_scripts... |
297,026 | <p>I need to hook after file uploaded to server, get the file path, and then prevent WordPress from saving the attachment post.</p>
<p>I found this filter <code>add_filter('attachment_fields_to_save', 'attachment_stuff');</code> but this is after the attachment post was created, I want to hook before the post save.</p... | [
{
"answer_id": 297032,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 2,
"selected": false,
"text": "<p>Uploading the file and creating an attachment for it is handled by the function <a href=\"https://developer.word... | 2018/03/16 | [
"https://wordpress.stackexchange.com/questions/297026",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/62909/"
] | I need to hook after file uploaded to server, get the file path, and then prevent WordPress from saving the attachment post.
I found this filter `add_filter('attachment_fields_to_save', 'attachment_stuff');` but this is after the attachment post was created, I want to hook before the post save.
**Update 26.03.2018**
... | Based on your comment you appear to be using the REST API. There's no hook between uploading the file and creating the attachment post that could be used for this purpose in the API endpoint.
The best you can do appears to be to use the `rest_insert_attachment` action. It provides callback functions with the `WP_Post`... |
297,041 | <p>Let me give you a scenario of what I'm trying to do. I have a custom post type "customer" and I can go in and "add new customer". Here I see my custom fields such as name, logo, review, etc. The problem is Wordpress generates a URL for this. This isn't meant to be a page so I just redirect all of my <a href="http://... | [
{
"answer_id": 297042,
"author": "jdm2112",
"author_id": 45202,
"author_profile": "https://wordpress.stackexchange.com/users/45202",
"pm_score": 3,
"selected": false,
"text": "<p>One of the parameters for <code>register_post_type()</code> is <code>publicly_queryable</code>. Simply set t... | 2018/03/16 | [
"https://wordpress.stackexchange.com/questions/297041",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/135049/"
] | Let me give you a scenario of what I'm trying to do. I have a custom post type "customer" and I can go in and "add new customer". Here I see my custom fields such as name, logo, review, etc. The problem is Wordpress generates a URL for this. This isn't meant to be a page so I just redirect all of my <http://website.com... | OK, so there are some arguments of `register_post_type` that you should use.
The crucial arguments for you are:
* `public` - Controls how the type is visible to authors (`show_in_nav_menus`, `show_ui`) and readers (`exclude_from_search`, `publicly_queryable`). If it's false, then `exclude_from_search` will be true, `... |
297,059 | <p>I've written a class to play about with ajax. I had originally used <code>check_admin_referer</code> (in <code>hello()</code>) without arguments but got this warning: "PHP Notice: check_admin_referer was called <strong>incorrectly</strong>. You should specify a nonce action to be verified by using the first paramet... | [
{
"answer_id": 298099,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 3,
"selected": true,
"text": "<p>In the JS script, include the <em>nonce</em> in <code>data</code>, as in the following example:</p>\n\n<pre... | 2018/03/17 | [
"https://wordpress.stackexchange.com/questions/297059",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/74293/"
] | I've written a class to play about with ajax. I had originally used `check_admin_referer` (in `hello()`) without arguments but got this warning: "PHP Notice: check\_admin\_referer was called **incorrectly**. You should specify a nonce action to be verified by using the first parameter."
So I headed to the codex and ha... | In the JS script, include the *nonce* in `data`, as in the following example:
```
jQuery(document).ready(function($){
data = {
action: 'hello',
token: $( '#token' ).val()
}
$('#stupid_form').submit(function(){
$.post(ajaxurl, data, function(response){
$('#response').html... |
297,063 | <p>I am creating a clothing store. The clothing are variable products based on size (xs, s, m, l, xl etc..). I am trying to create filters to display products that are in stock, based on a filter. So, clicking the "xs" filter should show products that both have the XS variation, and have that variation in stock.</p>
<... | [
{
"answer_id": 298099,
"author": "Sally CJ",
"author_id": 137402,
"author_profile": "https://wordpress.stackexchange.com/users/137402",
"pm_score": 3,
"selected": true,
"text": "<p>In the JS script, include the <em>nonce</em> in <code>data</code>, as in the following example:</p>\n\n<pre... | 2018/03/17 | [
"https://wordpress.stackexchange.com/questions/297063",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94213/"
] | I am creating a clothing store. The clothing are variable products based on size (xs, s, m, l, xl etc..). I am trying to create filters to display products that are in stock, based on a filter. So, clicking the "xs" filter should show products that both have the XS variation, and have that variation in stock.
So far, ... | In the JS script, include the *nonce* in `data`, as in the following example:
```
jQuery(document).ready(function($){
data = {
action: 'hello',
token: $( '#token' ).val()
}
$('#stupid_form').submit(function(){
$.post(ajaxurl, data, function(response){
$('#response').html... |
297,069 | <p>I use the All In One Seo Pack on my multisite, but this plugin have admin pages, what is not fall under the rule what restrict the plugin pages from my users, so I using the <code>remove_cap( $cap );</code> about 'edit_plugins', 'install_plugins', 'upload_plugins', but this not solving my issue. I want restrict this... | [
{
"answer_id": 297078,
"author": "David Sword",
"author_id": 132362,
"author_profile": "https://wordpress.stackexchange.com/users/132362",
"pm_score": 1,
"selected": false,
"text": "<p>To remove from the admin menu, you could use <a href=\"https://codex.wordpress.org/Function_Reference/r... | 2018/03/17 | [
"https://wordpress.stackexchange.com/questions/297069",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/134567/"
] | I use the All In One Seo Pack on my multisite, but this plugin have admin pages, what is not fall under the rule what restrict the plugin pages from my users, so I using the `remove_cap( $cap );` about 'edit\_plugins', 'install\_plugins', 'upload\_plugins', but this not solving my issue. I want restrict this pages on m... | You can restrict any pages from your users with this code, you can know only an any part of the url. (The example restrict the all pages of AIOSP (so the all url-s on the backend what associated with the keys: all-in-one-seo-pack or aioseop) what are wriggle out of from the `remove_cap( 'edit_plugins', 'install_plugins... |
298,111 | <p>Currently I am using <code>AJAX</code> to request a simple <code>JSON</code> response from an external API. The problem is, that the API key is exposed. I'm aware the best method is to process this through <code>admin-ajax</code> and set call the url through PHP. What is the most secure method to do this, and how ca... | [
{
"answer_id": 298112,
"author": "JBoulhous",
"author_id": 137648,
"author_profile": "https://wordpress.stackexchange.com/users/137648",
"pm_score": 0,
"selected": false,
"text": "<p><strong>It depends on what the external API offers</strong>, basically <strong>read/write access</strong>... | 2018/03/17 | [
"https://wordpress.stackexchange.com/questions/298111",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/87036/"
] | Currently I am using `AJAX` to request a simple `JSON` response from an external API. The problem is, that the API key is exposed. I'm aware the best method is to process this through `admin-ajax` and set call the url through PHP. What is the most secure method to do this, and how can this be requested through PHP?
``... | I would break this problem in to 2 parts.
First, you could sent an Ajax request to your server, sending only the `dataString` variable.
Then, you can use either `cURL` or [`wp_remote_get()`](https://codex.wordpress.org/Function_Reference/wp_remote_get) on the server to access the real API.
This could be the only so... |
298,132 | <p>I need your help with multiple values in meta_query. I have a checkbox filter. This is the query I came up:</p>
<p>But, I'm worried that query is not optimized, and that it will slow down the site. </p>
<p>I read the solution asked in this question:
<a href="https://wordpress.stackexchange.com/questions/250147/met... | [
{
"answer_id": 298142,
"author": "CodeMascot",
"author_id": 44192,
"author_profile": "https://wordpress.stackexchange.com/users/44192",
"pm_score": 1,
"selected": false,
"text": "<p>Without some other info it's pretty tough to give any solution to your this above issue. But it seems like... | 2018/03/18 | [
"https://wordpress.stackexchange.com/questions/298132",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/137724/"
] | I need your help with multiple values in meta\_query. I have a checkbox filter. This is the query I came up:
But, I'm worried that query is not optimized, and that it will slow down the site.
I read the solution asked in this question:
[meta\_query with multiple values](https://wordpress.stackexchange.com/questions/... | Post meta data was never designed to be used efficiently in queries. Using it with `LIKE` based matching will only make it more horrible.
You need to rethink your DB. For example use taxonomy terms to indicate which social network is associated with a post. |
298,154 | <p>I will use an $variable who is outside the function.
In the shortcode function.</p>
<p>This is what i will do:</p>
<pre><code>function shortcodevariable( $atts ){
return 'echo $variable';
}
add_shortcode('variable', 'shortcodevariable');
</code></pre>
<p>I think we need an array but I dont now how, can somebo... | [
{
"answer_id": 298165,
"author": "maheshwaghmare",
"author_id": 52167,
"author_profile": "https://wordpress.stackexchange.com/users/52167",
"pm_score": -1,
"selected": false,
"text": "<p>You have missing <code>shortcode_atts</code> and passing arguments in a shortcode. E.g </p>\n\n<pre><... | 2018/03/18 | [
"https://wordpress.stackexchange.com/questions/298154",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/139888/"
] | I will use an $variable who is outside the function.
In the shortcode function.
This is what i will do:
```
function shortcodevariable( $atts ){
return 'echo $variable';
}
add_shortcode('variable', 'shortcodevariable');
```
I think we need an array but I dont now how, can somebody help?
Thank you very much. | If you're using PHP > 5.3, then you can use a closure on the `the_content` filter. This filter needs to be added after the `$variable` has been defined and before the `the_content` filter has fired.
```
add_filter( 'the_content', function( $content ) use ( $variable ) {
return str_replace( '[variable][/variable]', $... |
298,155 | <p>I’m trying to add a custom field to image and gallery edit screen.</p>
<p>I’m aware there are similar questions here, although answers either don’t work with the current version or they add field only to <strong>upload</strong> screen while I need a field to be visible in all <strong>edit</strong> screens (see belo... | [
{
"answer_id": 299527,
"author": "Mr Rethman",
"author_id": 27393,
"author_profile": "https://wordpress.stackexchange.com/users/27393",
"pm_score": 0,
"selected": false,
"text": "<p>In my my own personal implementations of this functionality (without ACF), this is how I was able to achie... | 2018/03/18 | [
"https://wordpress.stackexchange.com/questions/298155",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/121208/"
] | I’m trying to add a custom field to image and gallery edit screen.
I’m aware there are similar questions here, although answers either don’t work with the current version or they add field only to **upload** screen while I need a field to be visible in all **edit** screens (see below).
For this, I believe, you’ll hav... | Here is the working code (working fine for me), did you tried this? Just add to theme 'functions.php' and change the custom field names as needed.
```
//function to add custom media field
function custom_media_add_media_custom_field( $form_fields, $post ) {
$field_value = get_post_meta( $post->ID, 'custom_media_st... |
298,225 | <p>I'm playing with Gutenberg ahead of its inclusion in core, and I'd like to know how to extend the existing gallery block to change its display. For example, instead of a grid of thumbnails I'd like to show a slideshow of images. Is it possible? If so, how? Any help would be appreciated.</p>
| [
{
"answer_id": 298441,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 5,
"selected": true,
"text": "<p>Ok, I've been playing with this for a little bit and have managed to change the output of the Gallery bl... | 2018/03/19 | [
"https://wordpress.stackexchange.com/questions/298225",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/33049/"
] | I'm playing with Gutenberg ahead of its inclusion in core, and I'd like to know how to extend the existing gallery block to change its display. For example, instead of a grid of thumbnails I'd like to show a slideshow of images. Is it possible? If so, how? Any help would be appreciated. | Ok, I've been playing with this for a little bit and have managed to change the output of the Gallery block, with the following caveats:
* The preview does not match the output. I think this is possible but appears to be a bit more involved.
* Certain classes and markup are required in the output for the block to be a... |
298,238 | <p>I'm looking to add a formatted text at the bottom of each excerpt text when I read an archive page. The code is the same for all the posts.</p>
<p>I have found for the category based archive page by modifying the category.php file in my child theme folder. But i don't know where to write my code for the date based ... | [
{
"answer_id": 298245,
"author": "Amol Sawant",
"author_id": 138676,
"author_profile": "https://wordpress.stackexchange.com/users/138676",
"pm_score": 1,
"selected": false,
"text": "<p>Open archive.php from your theme's directory the code will look like this </p>\n\n<pre><code><?php\n... | 2018/03/19 | [
"https://wordpress.stackexchange.com/questions/298238",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/139939/"
] | I'm looking to add a formatted text at the bottom of each excerpt text when I read an archive page. The code is the same for all the posts.
I have found for the category based archive page by modifying the category.php file in my child theme folder. But i don't know where to write my code for the date based archive or... | Open archive.php from your theme's directory the code will look like this
```
<?php
/*
Template Name: Archives
*/
get_header(); ?>
<div id="container">
<div id="content" role="main">
<?php the_post(); ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php get_search_form(); ?>
... |
298,241 | <p>I want to check plugin version using following API</p>
<pre><code>https://api.wordpress.org/stats/plugin/1.0/{slug}
</code></pre>
<p>For that how can I get Slug of All Active Plugins ?</p>
| [
{
"answer_id": 298243,
"author": "mmm",
"author_id": 74311,
"author_profile": "https://wordpress.stackexchange.com/users/74311",
"pm_score": 0,
"selected": false,
"text": "<p>If your are not on a multisite installation, you can have activated plugins with this code : </p>\n\n<pre><code>$... | 2018/03/19 | [
"https://wordpress.stackexchange.com/questions/298241",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/110795/"
] | I want to check plugin version using following API
```
https://api.wordpress.org/stats/plugin/1.0/{slug}
```
For that how can I get Slug of All Active Plugins ? | Use option `active_plugins` to get all plugin init files. e.g.
```
$current = get_option( 'active_plugins', array() );
// print_r( $current );
```
Here, `htmlpress` is the plugin slug.
[](https://i.stack.imgur.com/J4fBJ.png) |
298,251 | <p>I want to check latest version of plugin is available or not. For that I required current version of active plugins. How can I get current version of all active plugins programmatically ?</p>
| [
{
"answer_id": 298252,
"author": "Cristian",
"author_id": 121995,
"author_profile": "https://wordpress.stackexchange.com/users/121995",
"pm_score": -1,
"selected": false,
"text": "<p>You can use this code:</p>\n\n<pre><code><?php \n\n// Check if get_plugins() function exists. This is ... | 2018/03/19 | [
"https://wordpress.stackexchange.com/questions/298251",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/110795/"
] | I want to check latest version of plugin is available or not. For that I required current version of active plugins. How can I get current version of all active plugins programmatically ? | Problem Analysis
================
To get information about installed plugins, which provides plugin's version, we'll use `get_plugins()` function. Keep in mind, that this function is available in back end only, so our code must reside there. Data, returned from this function, does not tell us, which plugins are active... |
298,297 | <p>I'm trying to upload files using AJAX and I'm hooking in my functions so they get called within admin-ajax. I can't get it to work tough, and I didn't have any idea what was wrong or where to look at all. I narrowed it down, however, by modifying admin-ajax.php a little bit:</p>
<pre><code>// Require an action para... | [
{
"answer_id": 298300,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 1,
"selected": false,
"text": "<p>Here's the problem:</p>\n\n<pre><code> var formData = new FormData();\n formData.append( \"userfile\",... | 2018/03/20 | [
"https://wordpress.stackexchange.com/questions/298297",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/139991/"
] | I'm trying to upload files using AJAX and I'm hooking in my functions so they get called within admin-ajax. I can't get it to work tough, and I didn't have any idea what was wrong or where to look at all. I narrowed it down, however, by modifying admin-ajax.php a little bit:
```
// Require an action parameter
if ( emp... | Here's the problem:
```
var formData = new FormData();
formData.append( "userfile", $(this)[0].files[0] );
formData.append( "action", "vibesoft_files_upload" );
formData.append( "_wpnonce", vbsoft.nonce_upload );
console.log( formData );
$.ajax({
type: "post",
url: vbsoft.ajax... |
298,324 | <pre><code><?php
// Get the assigned tag_id
$tag_ids = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );
// Check if there is any tag_ids, if print wp_tag_cloud
if ( $tag_ids ) {
wp_tag_cloud( array(
... | [
{
"answer_id": 298325,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 0,
"selected": false,
"text": "<p>If you're outside the loop, use <a href=\"https://developer.wordpress.org/reference/functions/get_the_t... | 2018/03/20 | [
"https://wordpress.stackexchange.com/questions/298324",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/137481/"
] | ```
<?php
// Get the assigned tag_id
$tag_ids = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );
// Check if there is any tag_ids, if print wp_tag_cloud
if ( $tag_ids ) {
wp_tag_cloud( array(
'unit' ... | `wp_tag_cloud()` accepts a `separator` parameter, so you can modify your call like this:
```
wp_tag_cloud( array(
'separator' => ", ", // Default value: "\n"
'unit' => 'px', // font sizing choice (pt, em, px, etc)
'include' => $tag_ids, // ID's of tags to include, displays none except ... |
298,355 | <p>I am trying to make a simple Gutenberg block which implements <code><InspectorControls></code>, but I'm getting a React error no matter which I component I use.</p>
<pre><code>const { __ } = wp.i18n;
const {
registerBlockType,
RichText,
AlignmentToolbar,
BlockControls,
InspectorControls,
... | [
{
"answer_id": 298361,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 3,
"selected": false,
"text": "<p><code>InspectorControls</code> is deprecated as of v2.4</p>\n\n<p><a href=\"https://github.com/WordPress/gut... | 2018/03/20 | [
"https://wordpress.stackexchange.com/questions/298355",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/111172/"
] | I am trying to make a simple Gutenberg block which implements `<InspectorControls>`, but I'm getting a React error no matter which I component I use.
```
const { __ } = wp.i18n;
const {
registerBlockType,
RichText,
AlignmentToolbar,
BlockControls,
InspectorControls,
TextControl
} = wp.blocks;
... | `TextControl` is from `wp.components` not `wp.blocks`.
```
const {
registerBlockType,
RichText,
AlignmentToolbar,
BlockControls,
InspectorControls,
} = wp.blocks;
const {
TextControl
} = wp.components;
```
Changing that I was able to get your block to work fine instead of error in `Gutenberg ... |
298,364 | <p>I want to add metabox to pull list of custom posts and select any two of them on edit or add post screen. And At last when the post is published display them on single post page. Please help me!
Any help will be appreciated....</p>
<pre><code> add_action( 'add_meta_boxes', function () {
add_meta_box(
... | [
{
"answer_id": 298372,
"author": "David Sword",
"author_id": 132362,
"author_profile": "https://wordpress.stackexchange.com/users/132362",
"pm_score": 3,
"selected": true,
"text": "<p>You can add a metabox in the edit screen with</p>\n\n<pre><code>add_action( 'add_meta_boxes', function (... | 2018/03/20 | [
"https://wordpress.stackexchange.com/questions/298364",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140003/"
] | I want to add metabox to pull list of custom posts and select any two of them on edit or add post screen. And At last when the post is published display them on single post page. Please help me!
Any help will be appreciated....
```
add_action( 'add_meta_boxes', function () {
add_meta_box(
'yourcustom_s... | You can add a metabox in the edit screen with
```
add_action( 'add_meta_boxes', function () {
add_meta_box(
'yourcustom_sectionid',
__( ' Custom Meta Box', 'yourtextdomain' ),
function ( $post ) {
wp_nonce_field( plugin_basename( __FILE__ ), 'yourcustom_noncename' );
... |
298,445 | <p>I have created a new WordPress site in a folder inside of another WordPress site.</p>
<p>Example
- mainsite.com
- mainsite.com/secondsite</p>
<p>I have created a plugin and I use <code>$wpdb</code> to insert data to the database and the plugin inserts the data to the database of the first/parent site.</p>
<p>The... | [
{
"answer_id": 298446,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 2,
"selected": false,
"text": "<p><code>$_SERVER['DOCUMENT_ROOT'];</code> is not going to include <code>secondsite</code>. So all the fil... | 2018/03/21 | [
"https://wordpress.stackexchange.com/questions/298445",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/110915/"
] | I have created a new WordPress site in a folder inside of another WordPress site.
Example
- mainsite.com
- mainsite.com/secondsite
I have created a plugin and I use `$wpdb` to insert data to the database and the plugin inserts the data to the database of the first/parent site.
The code I use to include `$wpdb` is t... | `$_SERVER['DOCUMENT_ROOT'];` is not going to include `secondsite`. So all the files, including `wp-config.php` with the database details, are coming from the root public directory.
To get the current directory, including subdirectories, use any of these:
```
getcwd();
dirname(__FILE__);
basename(__DIR__);
```
But... |
298,451 | <p>Hello I'm currently developing a wordpress application. I have been able to accomplish almost everything the application needs. I was even able to use Jquery-Ajax to insert data into my custom database table and get a background feedback of the submission.</p>
<p>But where I'm stock right now is autopopulating my t... | [
{
"answer_id": 298455,
"author": "Sumit Parkash",
"author_id": 140109,
"author_profile": "https://wordpress.stackexchange.com/users/140109",
"pm_score": 1,
"selected": false,
"text": "<p>You need to change the data that you are sending in the ajax request.\nFor ajax to work in WordPress ... | 2018/03/21 | [
"https://wordpress.stackexchange.com/questions/298451",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140101/"
] | Hello I'm currently developing a wordpress application. I have been able to accomplish almost everything the application needs. I was even able to use Jquery-Ajax to insert data into my custom database table and get a background feedback of the submission.
But where I'm stock right now is autopopulating my textfields ... | You need to change the data that you are sending in the ajax request.
For ajax to work in WordPress you need to send the **action** variable in ajax post request.
Change
```
data: {package: package},
```
to
```
data: {action: 'ajaxAutopopulate', package: package}
```
Also you can use the wordpress default fun... |
298,453 | <p>I'm currently working with php 7.2 and when I use get_the_content() or get_the_excerpt() outside of a single template, in the functions.php for example, I get the following Warning:</p>
<p><em>Warning: count(): Parameter must be an array or an object that implements Countable in /Applications/MAMP/htdocs/wordpress... | [
{
"answer_id": 320699,
"author": "Anton Lukin",
"author_id": 126253,
"author_profile": "https://wordpress.stackexchange.com/users/126253",
"pm_score": 0,
"selected": false,
"text": "<p>This bug related to WordPress core bug\n<a href=\"https://core.trac.wordpress.org/ticket/42814\" rel=\"... | 2018/03/21 | [
"https://wordpress.stackexchange.com/questions/298453",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/28159/"
] | I'm currently working with php 7.2 and when I use get\_the\_content() or get\_the\_excerpt() outside of a single template, in the functions.php for example, I get the following Warning:
*Warning: count(): Parameter must be an array or an object that implements Countable in /Applications/MAMP/htdocs/wordpress/wp-kona/w... | Yes, I already knew the cause of what you're experiencing:
The $page and $pages global variable have not been set up and a call to `get_the_content` or `get_the_excerpt` would return that error: count(pages)
===============================================================================================================... |
298,459 | <p>I am simply trying to get rid of the Read More button on my blog posts.</p>
<p>I would like my blog to show my full article.</p>
| [
{
"answer_id": 320699,
"author": "Anton Lukin",
"author_id": 126253,
"author_profile": "https://wordpress.stackexchange.com/users/126253",
"pm_score": 0,
"selected": false,
"text": "<p>This bug related to WordPress core bug\n<a href=\"https://core.trac.wordpress.org/ticket/42814\" rel=\"... | 2018/03/21 | [
"https://wordpress.stackexchange.com/questions/298459",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140110/"
] | I am simply trying to get rid of the Read More button on my blog posts.
I would like my blog to show my full article. | Yes, I already knew the cause of what you're experiencing:
The $page and $pages global variable have not been set up and a call to `get_the_content` or `get_the_excerpt` would return that error: count(pages)
===============================================================================================================... |
298,481 | <p>I created my own contact form and I'm using <code>WP_List_Table</code> to display submitted forms in wp-admin. I edited <a href="https://github.com/pmbaldha/WP-Custom-List-Table-With-Database-Example" rel="nofollow noreferrer">this</a> example WP_List_Table from <strong>github</strong> and it works fine. </p>
<p>Th... | [
{
"answer_id": 298491,
"author": "Krzysiek Dróżdż",
"author_id": 34172,
"author_profile": "https://wordpress.stackexchange.com/users/34172",
"pm_score": 4,
"selected": true,
"text": "<p>OK, so it has nothing to do with WP_List_Table, to be precise. All you need to do is to add some addit... | 2018/03/21 | [
"https://wordpress.stackexchange.com/questions/298481",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/133897/"
] | I created my own contact form and I'm using `WP_List_Table` to display submitted forms in wp-admin. I edited [this](https://github.com/pmbaldha/WP-Custom-List-Table-With-Database-Example) example WP\_List\_Table from **github** and it works fine.
This is how I add my custom admin menu page:
```
function contact_form... | OK, so it has nothing to do with WP\_List\_Table, to be precise. All you need to do is to add some additional info during registration of your custom admin page.
There are two classes used by WordPress to display these notification bubbles:
* update-plugins
* awaiting-mod
Your notifications have nothing to do with p... |
298,525 | <p>I am using this query for my loop and it is working except when <code>meta_value</code> is empty. In this case it returns empty result. Instead I want to get all results when <code>meta_value</code> is empty.</p>
<p>Here is my code</p>
<pre><code>$query = new WP_Query( array(
'post_type' => 'my_post_type',... | [
{
"answer_id": 298531,
"author": "wplearner",
"author_id": 120693,
"author_profile": "https://wordpress.stackexchange.com/users/120693",
"pm_score": 0,
"selected": false,
"text": "<p>This code is working for me </p>\n\n<pre><code>$query = new WP_Query( array(\n 'post_type' => 'my_... | 2018/03/21 | [
"https://wordpress.stackexchange.com/questions/298525",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/120693/"
] | I am using this query for my loop and it is working except when `meta_value` is empty. In this case it returns empty result. Instead I want to get all results when `meta_value` is empty.
Here is my code
```
$query = new WP_Query( array(
'post_type' => 'my_post_type',
'meta_query' => array(
array(
... | If I understand your question correctly, you want to query for region field only if `$region` variable is not empty? If so, this should work and it will be much prettier code than the one you suggested:
```
$meta_query = array(
array(
'key' => 'state',
'value' => 'Alabama',
),
);
if ( $r... |
298,551 | <p>Is there a wordpress function like - </p>
<p><strong>If someone recently commented in one of my posts (not other author post), I want his/her ID?</strong> </p>
<p>If there is no function like that, how can I achieve it? </p>
<hr>
<p>Actually, I am building a notification system and it will be something like... | [
{
"answer_id": 298531,
"author": "wplearner",
"author_id": 120693,
"author_profile": "https://wordpress.stackexchange.com/users/120693",
"pm_score": 0,
"selected": false,
"text": "<p>This code is working for me </p>\n\n<pre><code>$query = new WP_Query( array(\n 'post_type' => 'my_... | 2018/03/22 | [
"https://wordpress.stackexchange.com/questions/298551",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/121174/"
] | Is there a wordpress function like -
**If someone recently commented in one of my posts (not other author post), I want his/her ID?**
If there is no function like that, how can I achieve it?
---
Actually, I am building a notification system and it will be something like this
***UserName*** is commented on your ... | If I understand your question correctly, you want to query for region field only if `$region` variable is not empty? If so, this should work and it will be much prettier code than the one you suggested:
```
$meta_query = array(
array(
'key' => 'state',
'value' => 'Alabama',
),
);
if ( $r... |
298,588 | <p>I'm using azure as a hosting service and I tried to create a new virtual directory for my subdomain.
So I created a folder in my ftp then I created directory in below image
<a href="https://i.stack.imgur.com/tHAuR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tHAuR.png" alt=""></a></p>
<p>Then ... | [
{
"answer_id": 373806,
"author": "Ryan",
"author_id": 144151,
"author_profile": "https://wordpress.stackexchange.com/users/144151",
"pm_score": 2,
"selected": false,
"text": "<p><strong>Caveat</strong><br />\nI know this question is a little out of date and our question/issue is technica... | 2018/03/22 | [
"https://wordpress.stackexchange.com/questions/298588",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/134029/"
] | I'm using azure as a hosting service and I tried to create a new virtual directory for my subdomain.
So I created a folder in my ftp then I created directory in below image
[](https://i.stack.imgur.com/tHAuR.png)
Then I've edited my web.config file But unfortunately I got this e... | **Caveat**
I know this question is a little out of date and our question/issue is technically regarding an [Azure Wordpress Resource](https://azure.microsoft.com/en-us/blog/how-to-host-a-scalable-and-optimized-wordpress-for-azure-in-minutes/) not a hosted environment... but I thought it might be helpful to answer fo... |
298,651 | <p>I'm attempting to make an archive template that will apply only to subcategories of a particular term. My structure looks something like this:</p>
<ul>
<li>Events (main taxonomy)
<ul>
<li>Tradeshow
<ul>
<li>Show subcat 1</li>
<li>Show subcat 2</li>
</ul></li>
<li>Other taxonomies</li>
</ul></li>
</ul>
<p>I want ... | [
{
"answer_id": 298652,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 4,
"selected": true,
"text": "<p>There are two problems that have thwarted your check:</p>\n\n<pre><code> $term = get_queried_object()->... | 2018/03/23 | [
"https://wordpress.stackexchange.com/questions/298651",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/118681/"
] | I'm attempting to make an archive template that will apply only to subcategories of a particular term. My structure looks something like this:
* Events (main taxonomy)
+ Tradeshow
- Show subcat 1
- Show subcat 2
+ Other taxonomies
I want `Show subcat 1` and `Show subcat 2` (and any other subcategories) to all g... | There are two problems that have thwarted your check:
```
$term = get_queried_object()->term_id;
if ( $term->parent == 'tradeshow' ) {
```
Starting with:
```
$term = get_queried_object()->term_id;
```
Here `$term` contains the ID of a term, not a term object. Lets assume this is term number 5, the res... |
298,710 | <p>When you enqueue scripts or styles with the following:</p>
<pre><code>function themeslug_enqueue_style() {
wp_enqueue_style( 'core', '/style.css', false );
}
add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_style' );
</code></pre>
<p>You get the following:</p>
<pre><code><link rel='stylesheet' id='cor... | [
{
"answer_id": 298696,
"author": "Dragos Micu",
"author_id": 110131,
"author_profile": "https://wordpress.stackexchange.com/users/110131",
"pm_score": 1,
"selected": false,
"text": "<p>There is a custom post type also called clients which is already using that slug. Try using a different... | 2018/03/23 | [
"https://wordpress.stackexchange.com/questions/298710",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40536/"
] | When you enqueue scripts or styles with the following:
```
function themeslug_enqueue_style() {
wp_enqueue_style( 'core', '/style.css', false );
}
add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_style' );
```
You get the following:
```
<link rel='stylesheet' id='core-css' href='http://localhost:8080/word... | There is a custom post type also called clients which is already using that slug. Try using a different slug/page name or work with the default archive page. |
298,723 | <p>I have been trying to figure out how i get the ressource on a WC-order, from the product line data, but i seem not to be able to figure this out in WC 3.0+ - pre that it was pretty easy.<br>
I have looked at both the booking meta data, the order meta data, and everything else i can think of, but still unable to find... | [
{
"answer_id": 298828,
"author": "TurtleTread",
"author_id": 117263,
"author_profile": "https://wordpress.stackexchange.com/users/117263",
"pm_score": 1,
"selected": false,
"text": "<p>For existing orders, you need to use the <code>wc_get_order()</code> function.</p>\n"
},
{
"ans... | 2018/03/23 | [
"https://wordpress.stackexchange.com/questions/298723",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/116092/"
] | I have been trying to figure out how i get the ressource on a WC-order, from the product line data, but i seem not to be able to figure this out in WC 3.0+ - pre that it was pretty easy.
I have looked at both the booking meta data, the order meta data, and everything else i can think of, but still unable to find wha... | So i found a "solution" even though it's not as good as i hoped - or atleast not as good as the way it was done pre 3.0.
```
$iOrderID = $_POST['iOrderID'];
$aBookingQuery = new WP_Query(
array(
'post_parent' => (int)$iOrderID,
'post_type' => 'wc_booking',
'posts_per_page' ... |
298,734 | <p>The company I work for has an enterprise Wordpress site that was acquired from a different company. I don't know if there was a past hack or if it's just accumulated spam or what, but the <code>wp_redirection_404</code> table has grown to roughly 7GB. </p>
<p>I tried grepping the table for <em>Viagra</em>, <em>Ver... | [
{
"answer_id": 298828,
"author": "TurtleTread",
"author_id": 117263,
"author_profile": "https://wordpress.stackexchange.com/users/117263",
"pm_score": 1,
"selected": false,
"text": "<p>For existing orders, you need to use the <code>wc_get_order()</code> function.</p>\n"
},
{
"ans... | 2018/03/23 | [
"https://wordpress.stackexchange.com/questions/298734",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/65569/"
] | The company I work for has an enterprise Wordpress site that was acquired from a different company. I don't know if there was a past hack or if it's just accumulated spam or what, but the `wp_redirection_404` table has grown to roughly 7GB.
I tried grepping the table for *Viagra*, *Versace*, *Nike*, etc. and got page... | So i found a "solution" even though it's not as good as i hoped - or atleast not as good as the way it was done pre 3.0.
```
$iOrderID = $_POST['iOrderID'];
$aBookingQuery = new WP_Query(
array(
'post_parent' => (int)$iOrderID,
'post_type' => 'wc_booking',
'posts_per_page' ... |
298,741 | <p>I'm building a theme, in which, I have 2 menus:</p>
<ol>
<li>Footer menu (<code>footer-menu</code>)</li>
<li>Main menu (<code>main-menu</code>)</li>
</ol>
<p>However, when I called the main one in the <code>header.php</code> file it uses the same links added in the footer navigation.</p>
<p>Please see my code.</p... | [
{
"answer_id": 298744,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 1,
"selected": false,
"text": "<p><code>wp_nav_menu</code> expects an array of arguments, not a string. If <code>main-menu</code> and <code>footer-m... | 2018/03/23 | [
"https://wordpress.stackexchange.com/questions/298741",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/122279/"
] | I'm building a theme, in which, I have 2 menus:
1. Footer menu (`footer-menu`)
2. Main menu (`main-menu`)
However, when I called the main one in the `header.php` file it uses the same links added in the footer navigation.
Please see my code.
**Registering the navs**
```
register_nav_menus( array(
'main-men... | Just the fact that they have the same name doesn't mean that WP knows the menu "main-menu" goes in the location "main-menu". You will have to specify this, as you can see from the source code of [`wp_nav_menu`](https://developer.wordpress.org/reference/functions/wp_nav_menu/):
```
$args = array (
'menu' =>... |
298,762 | <p>I have a javascript snippet that I want to inject into the footer of the page. It's a tracking code, let's say similar to Google analytics. It has no dependencies, it's a standalone snippet.</p>
<p>I can do something like this</p>
<pre><code>function render_tracking_code(){
wp_enqueue_script( 'depends-js', 'h... | [
{
"answer_id": 298766,
"author": "Dave Romsey",
"author_id": 2807,
"author_profile": "https://wordpress.stackexchange.com/users/2807",
"pm_score": 3,
"selected": false,
"text": "<p><strong>Update:</strong> WordPress added support for adding inline scripts and styles without a dependency... | 2018/03/23 | [
"https://wordpress.stackexchange.com/questions/298762",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/45255/"
] | I have a javascript snippet that I want to inject into the footer of the page. It's a tracking code, let's say similar to Google analytics. It has no dependencies, it's a standalone snippet.
I can do something like this
```
function render_tracking_code(){
wp_enqueue_script( 'depends-js', 'https://rdiv.com/dummy.... | `wp_add_inline_style()` - without dependency
--------------------------------------------
The `wp_add_inline_style()` can be used without a source file dependency.
Here's an [example](https://wordpress.stackexchange.com/a/282868/26350) from @Flix:
```
wp_register_style( 'dummy-handle', false );
wp_enqueue_style( 'd... |
298,767 | <p>I have a custom WP_Query inside of an archive. I know this is not ideal, but when I try switching it out for a pre_get_posts option, then my page just enters an infinite loop, so I'd rather stick with the WP Query. The problem is that pagination sends me to a 404 error on /page/2.</p>
<p>My query (it also has some ... | [
{
"answer_id": 298775,
"author": "Jordan Carter",
"author_id": 94213,
"author_profile": "https://wordpress.stackexchange.com/users/94213",
"pm_score": 4,
"selected": true,
"text": "<p>Found the answer!!!</p>\n\n<p>Put this in functions.php (or a required file). Of course, change it to su... | 2018/03/23 | [
"https://wordpress.stackexchange.com/questions/298767",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94213/"
] | I have a custom WP\_Query inside of an archive. I know this is not ideal, but when I try switching it out for a pre\_get\_posts option, then my page just enters an infinite loop, so I'd rather stick with the WP Query. The problem is that pagination sends me to a 404 error on /page/2.
My query (it also has some taxonom... | Found the answer!!!
Put this in functions.php (or a required file). Of course, change it to suit your needs. I needed something that only worked for product category archives.
```
function modify_product_cat_query( $query ) {
if (!is_admin() && $query->is_tax("product_cat")){
$query->set('posts_per_page', 2)... |
298,819 | <p>For example, to redirect old URLs of the form:</p>
<p><code>/2016/10/mukunda-murari-kannada-songs-download.html</code></p>
<p>To</p>
<p><code>/mukunda-murari-kannada-songs-download.html</code></p>
<p>I have already changed the permalink structure in WordPress, but wish to redirect the old URLs to the new, in the... | [
{
"answer_id": 298820,
"author": "Rick Hellewell",
"author_id": 29416,
"author_profile": "https://wordpress.stackexchange.com/users/29416",
"pm_score": 1,
"selected": false,
"text": "<p>Why not change your permalinks to \"Post Name\" in Settings, Permalinks?</p>\n"
},
{
"answer_i... | 2018/03/24 | [
"https://wordpress.stackexchange.com/questions/298819",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140381/"
] | For example, to redirect old URLs of the form:
`/2016/10/mukunda-murari-kannada-songs-download.html`
To
`/mukunda-murari-kannada-songs-download.html`
I have already changed the permalink structure in WordPress, but wish to redirect the old URLs to the new, in the most efficient way, in order to help preserve SEO.
... | Assuming you have already changed the permalinks structure as @RickHellewell suggests, then you can do something like the following near the top of your `.htaccess` file (before the existing WP front-controller) to redirect the old URLs (with the stated format) in order to preserve SEO.
```
RewriteRule ^\d{4}/\d\d/([a... |
298,903 | <p>I'm creating a webshop, that imports a lot of products from a csv file. I need to link to available accessories etc., which individually is determined and imported by the respectable products SKU. </p>
<p>I know it is possible to get the product ID with a simple products SKU with this:</p>
<pre><code>wc_get_produc... | [
{
"answer_id": 305918,
"author": "Tim",
"author_id": 118534,
"author_profile": "https://wordpress.stackexchange.com/users/118534",
"pm_score": 3,
"selected": false,
"text": "<p>I was stuck on a very similar problem. I couldn't find anything in the woocommerce code that would let you dire... | 2018/03/26 | [
"https://wordpress.stackexchange.com/questions/298903",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140470/"
] | I'm creating a webshop, that imports a lot of products from a csv file. I need to link to available accessories etc., which individually is determined and imported by the respectable products SKU.
I know it is possible to get the product ID with a simple products SKU with this:
```
wc_get_product_id_by_sku('PRODUCT_... | I was stuck on a very similar problem. I couldn't find anything in the woocommerce code that would let you directly look up the parent product from the variation sku.
But, as product variations are stored in the `wp_posts` table with the type `product_variation`, and the SKUs are stored in the `wp_post_meta` table, it... |
298,916 | <p>I'm having some difficulty comparing between a negative and positive number. This code works fine when it's between two positive numbers but not when it's between a negative then a positive one.</p>
<p>This is part of my 'meta_query':</p>
<pre><code>array_push($metaQuery,
array('relation' => 'AND',
... | [
{
"answer_id": 298940,
"author": "mmm",
"author_id": 74311,
"author_profile": "https://wordpress.stackexchange.com/users/74311",
"pm_score": 2,
"selected": false,
"text": "<p>I tried the following code: </p>\n\n<pre><code>$posts = get_posts([\n \"post_type\" => \"CUSTOM_POST_TYPE\"... | 2018/03/26 | [
"https://wordpress.stackexchange.com/questions/298916",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/66977/"
] | I'm having some difficulty comparing between a negative and positive number. This code works fine when it's between two positive numbers but not when it's between a negative then a positive one.
This is part of my 'meta\_query':
```
array_push($metaQuery,
array('relation' => 'AND',
array(
'key... | I tried the following code:
```
$posts = get_posts([
"post_type" => "CUSTOM_POST_TYPE",
"meta_query" => [
'relation' => 'AND',
[
'key' => 'longitude',
'value' => [-0.9895, 1.3125],
'compare' => 'BETWEEN',
"type" => "NUMERIC",
],
],
])... |
298,920 | <p><a href="https://i.stack.imgur.com/nSb4b.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/nSb4b.jpg" alt="Not Available"></a></p>
<p>I am trying to go to wp-admin, but after I login I keep seeing this. I already tried renaming plugin but still I can't login to wp-admin.</p>
| [
{
"answer_id": 298930,
"author": "Amol Sawant",
"author_id": 138676,
"author_profile": "https://wordpress.stackexchange.com/users/138676",
"pm_score": -1,
"selected": false,
"text": "<p>Do the following steps one by one and so you can check what causing you this error ...</p>\n\n<p>1) Re... | 2018/03/26 | [
"https://wordpress.stackexchange.com/questions/298920",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140483/"
] | [](https://i.stack.imgur.com/nSb4b.jpg)
I am trying to go to wp-admin, but after I login I keep seeing this. I already tried renaming plugin but still I can't login to wp-admin. | There are different reasons why this can happen. In your case I think it may be a security plugin that has changed the deafult login URL to something else.
When I go to <http://www.philenglish.com.cn/wp-login.php> I get a 404 error, which is something such plugins also do: they make the default login URLs unavailable... |
298,928 | <p>We've got some custom endpoints set up that do various things, which we access via <code>/wp/wp-admin/admin-ajax.php?action=some_action</code></p>
<p>However whenever there is an error as we're developing, such as syntax, logical, fatal etc, we simply get "500 Internal Server Error"</p>
<p>Every other page on the ... | [
{
"answer_id": 298931,
"author": "codiiv",
"author_id": 91561,
"author_profile": "https://wordpress.stackexchange.com/users/91561",
"pm_score": -1,
"selected": false,
"text": "<p>You can try the WP_Ajax_Response </p>\n\n<pre><code>$response = array(\n 'what'=>'stuff',\n 'action'=&... | 2018/03/26 | [
"https://wordpress.stackexchange.com/questions/298928",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/116411/"
] | We've got some custom endpoints set up that do various things, which we access via `/wp/wp-admin/admin-ajax.php?action=some_action`
However whenever there is an error as we're developing, such as syntax, logical, fatal etc, we simply get "500 Internal Server Error"
Every other page on the site when there's an error, ... | WordPress by default hide errors for ajax request call. This can be confirmed from the source file [`wp-includes/load.php#L352`](https://core.trac.wordpress.org/browser/trunk/src/wp-includes/load.php#L353), here:
```php
if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP... |
298,937 | <p>I am trying to learn how to make themes for WordPress now I am unable to find how to make a <a href="https://i.stack.imgur.com/U6V7y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U6V7y.png" alt="enter image description here"></a>custom menu in admin panel related to theme option </p>
<p>want to... | [
{
"answer_id": 298931,
"author": "codiiv",
"author_id": 91561,
"author_profile": "https://wordpress.stackexchange.com/users/91561",
"pm_score": -1,
"selected": false,
"text": "<p>You can try the WP_Ajax_Response </p>\n\n<pre><code>$response = array(\n 'what'=>'stuff',\n 'action'=&... | 2018/03/26 | [
"https://wordpress.stackexchange.com/questions/298937",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140035/"
] | I am trying to learn how to make themes for WordPress now I am unable to find how to make a [](https://i.stack.imgur.com/U6V7y.png)custom menu in admin panel related to theme option
want to show a menu in this admin panel | WordPress by default hide errors for ajax request call. This can be confirmed from the source file [`wp-includes/load.php#L352`](https://core.trac.wordpress.org/browser/trunk/src/wp-includes/load.php#L353), here:
```php
if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP... |
298,961 | <p>I am creating a field that needs to add a custom field to every post on a site. I am using the ACF plugin in my plugin to do so. I have followed <a href="https://www.smashingmagazine.com/2016/04/three-approaches-to-adding-configurable-fields-to-your-plugin/#approach-3-integrating-acf-advanced-custom-fields-into-your... | [
{
"answer_id": 298931,
"author": "codiiv",
"author_id": 91561,
"author_profile": "https://wordpress.stackexchange.com/users/91561",
"pm_score": -1,
"selected": false,
"text": "<p>You can try the WP_Ajax_Response </p>\n\n<pre><code>$response = array(\n 'what'=>'stuff',\n 'action'=&... | 2018/03/26 | [
"https://wordpress.stackexchange.com/questions/298961",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/31284/"
] | I am creating a field that needs to add a custom field to every post on a site. I am using the ACF plugin in my plugin to do so. I have followed [this tutorial](https://www.smashingmagazine.com/2016/04/three-approaches-to-adding-configurable-fields-to-your-plugin/#approach-3-integrating-acf-advanced-custom-fields-into-... | WordPress by default hide errors for ajax request call. This can be confirmed from the source file [`wp-includes/load.php#L352`](https://core.trac.wordpress.org/browser/trunk/src/wp-includes/load.php#L353), here:
```php
if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP... |
298,963 | <p>I want to know use of <strong>esc_attr()</strong>?
how it is used?
Any example would be highly help!</p>
<pre><code>esc_attr( $variable )
</code></pre>
| [
{
"answer_id": 298964,
"author": "Niv Asraf",
"author_id": 125474,
"author_profile": "https://wordpress.stackexchange.com/users/125474",
"pm_score": 4,
"selected": true,
"text": "<p>esc_attr() is written specifically for escaping a string that is to be used as an html attribute, which me... | 2018/03/26 | [
"https://wordpress.stackexchange.com/questions/298963",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140003/"
] | I want to know use of **esc\_attr()**?
how it is used?
Any example would be highly help!
```
esc_attr( $variable )
``` | esc\_attr() is written specifically for escaping a string that is to be used as an html attribute, which means also escaping single and double-quote characters etc.
In general, it's better to use the data validation API that WP provides rather than the generic PHP functions. |
298,971 | <p>I'm working on a custom theme. For my comment section, if the user role is administrator I want to display "Admin", if subscriber "Subscriber", etc.</p>
<p>The problem is, I will add this code and "Admin" shows beside all users even if not admin (I've tried changing the role, this is just an admin example):</p>
<p... | [
{
"answer_id": 298973,
"author": "phatskat",
"author_id": 20143,
"author_profile": "https://wordpress.stackexchange.com/users/20143",
"pm_score": 2,
"selected": false,
"text": "<p>You are passing a role name, <code>administrator</code>, to <code>current_user_can</code>. Looking at <a hre... | 2018/03/26 | [
"https://wordpress.stackexchange.com/questions/298971",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/133371/"
] | I'm working on a custom theme. For my comment section, if the user role is administrator I want to display "Admin", if subscriber "Subscriber", etc.
The problem is, I will add this code and "Admin" shows beside all users even if not admin (I've tried changing the role, this is just an admin example):
```
if ( current... | You are passing a role name, `administrator`, to `current_user_can`. Looking at [the Codex page](https://codex.wordpress.org/Function_Reference/current_user_can) this is supported but not guaranteed to work, and should generally be avoided:
>
> Passing role names to current\_user\_can() is discouraged as this is not ... |
298,978 | <p>I want to run a function when my theme is activated. I have to add the theme activation hook within a php class:</p>
<pre><code>final class My_Class_Name {
public static function getInstance() {
if (self::$instance == null) {
self::$instance = new self;
self::$ins... | [
{
"answer_id": 298980,
"author": "Welcher",
"author_id": 27210,
"author_profile": "https://wordpress.stackexchange.com/users/27210",
"pm_score": 3,
"selected": true,
"text": "<p>It looks like you are adding the hook just inside the body of the class. Try adding it into an <code>init()</c... | 2018/03/26 | [
"https://wordpress.stackexchange.com/questions/298978",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1613/"
] | I want to run a function when my theme is activated. I have to add the theme activation hook within a php class:
```
final class My_Class_Name {
public static function getInstance() {
if (self::$instance == null) {
self::$instance = new self;
self::$instance->actions... | It looks like you are adding the hook just inside the body of the class. Try adding it into an `init()` method and calling it after it is instantiated or at the very least in the constructor.
I think the issues is that the hook is being registered before the class has been fully read by PHP?
Try this:
```
final clas... |
298,982 | <p>I’ve been using basic user rights functionality on a multi-user WP site for a while and its worked out great, having most user accounts just have access to their own posts but a few “editors” having access to everyone’s posts. This was assisted by the <em>wp-front</em> plugin that allows you to easily define user ro... | [
{
"answer_id": 301429,
"author": "Clemens Tolboom",
"author_id": 136493,
"author_profile": "https://wordpress.stackexchange.com/users/136493",
"pm_score": -1,
"selected": false,
"text": "<p>As you now have two roles for the same company I would go for <a href=\"https://wordpress.org/plug... | 2018/03/26 | [
"https://wordpress.stackexchange.com/questions/298982",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/28543/"
] | I’ve been using basic user rights functionality on a multi-user WP site for a while and its worked out great, having most user accounts just have access to their own posts but a few “editors” having access to everyone’s posts. This was assisted by the *wp-front* plugin that allows you to easily define user roles.
Howe... | Here's my approach. Bear in mind that it covers the basic needs you've described but could be easily expanded into more robust solution. Few steps to follow (all code goes to your `functions.php`):
1. Save company name as user meta
=================================
The first thing we need to do is assigning a company... |
298,984 | <p>I am working on a site built in visual composer/wp bakery. I do not want to work in the admin but in a php file. </p>
<p>How can I get code like </p>
<pre><code>[vc_column_text]
<h3><a href="home">home</a></h3>
[/vc_column_text]
</code></pre>
<p>to parse from a a php file, rather than WP... | [
{
"answer_id": 299042,
"author": "Jon",
"author_id": 14416,
"author_profile": "https://wordpress.stackexchange.com/users/14416",
"pm_score": 4,
"selected": true,
"text": "<p>Based on Toms comment this will work:</p>\n\n<pre><code><?php echo do_shortcode( ' \n[vc_column_text]\n<h3&g... | 2018/03/26 | [
"https://wordpress.stackexchange.com/questions/298984",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14416/"
] | I am working on a site built in visual composer/wp bakery. I do not want to work in the admin but in a php file.
How can I get code like
```
[vc_column_text]
<h3><a href="home">home</a></h3>
[/vc_column_text]
```
to parse from a a php file, rather than WP admin? | Based on Toms comment this will work:
```
<?php echo do_shortcode( '
[vc_column_text]
<h3><a href="home">home</a></h3>
[/vc_column_text]
' );?>
``` |
298,989 | <p>I'm trying to find anything out there that will list posts under a specific category by date. Here's my example:</p>
<p><strong>Photography</strong> (being the category name)</p>
<p><strong>2018</strong></p>
<ul>
<li>Post title shows here</li>
<li>Post title shows here</li>
<li>Post title shows here</li>
</ul>
<... | [
{
"answer_id": 299041,
"author": "Friss",
"author_id": 62392,
"author_profile": "https://wordpress.stackexchange.com/users/62392",
"pm_score": 2,
"selected": true,
"text": "<p>Even though it is not the most conventional way of doing, I would proceed like this:</p>\n\n<p><strong>Edit : pr... | 2018/03/26 | [
"https://wordpress.stackexchange.com/questions/298989",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/132008/"
] | I'm trying to find anything out there that will list posts under a specific category by date. Here's my example:
**Photography** (being the category name)
**2018**
* Post title shows here
* Post title shows here
* Post title shows here
**2017**
* Post title shows here
* post title shows here
* Post title shows her... | Even though it is not the most conventional way of doing, I would proceed like this:
**Edit : precision**
I create a new file category.php which is the template for categories, and put this piece of code inside.
```
$args = array( 'post_type'=>'post',
'posts_per_page'=> -1,
'post_status'=>'publish',
'ord... |
299,015 | <pre><code>add_action( 'init', 'wc_readd_add_to_cart_buttons' );
function wc_readd_add_to_cart_buttons() {
//add to cart button loop
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
}
</code></pre>
<p>I am adding back a button in WooCommerceand need to have a <code><... | [
{
"answer_id": 299018,
"author": "Pabamato",
"author_id": 60079,
"author_profile": "https://wordpress.stackexchange.com/users/60079",
"pm_score": 2,
"selected": false,
"text": "<p>Not sure why you are using init and then adding the function to the WC action.\nThe following should work:</... | 2018/03/26 | [
"https://wordpress.stackexchange.com/questions/299015",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140534/"
] | ```
add_action( 'init', 'wc_readd_add_to_cart_buttons' );
function wc_readd_add_to_cart_buttons() {
//add to cart button loop
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
}
```
I am adding back a button in WooCommerceand need to have a `<br>` before the button. Ho... | Not sure why you are using init and then adding the function to the WC action.
The following should work:
```
add_action( 'woocommerce_after_shop_loop_item', 'wc_readd_add_to_cart_buttons', 10 );
if (!function_exists('wc_readd_add_to_cart_buttons')){
function wc_readd_add_to_cart_buttons() {
//add to cart butto... |
299,049 | <p>As an admin, I can preview scheduled posts. In the post listing, there's a "preview" link which appears if you hover over the scheduled post title.</p>
<p>As a contributor, I can preview a post if it is in draft or pending. I can no longer preview the post once it has been scheduled. </p>
<p>Contributors are curio... | [
{
"answer_id": 299018,
"author": "Pabamato",
"author_id": 60079,
"author_profile": "https://wordpress.stackexchange.com/users/60079",
"pm_score": 2,
"selected": false,
"text": "<p>Not sure why you are using init and then adding the function to the WC action.\nThe following should work:</... | 2018/03/27 | [
"https://wordpress.stackexchange.com/questions/299049",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140561/"
] | As an admin, I can preview scheduled posts. In the post listing, there's a "preview" link which appears if you hover over the scheduled post title.
As a contributor, I can preview a post if it is in draft or pending. I can no longer preview the post once it has been scheduled.
Contributors are curious to see what th... | Not sure why you are using init and then adding the function to the WC action.
The following should work:
```
add_action( 'woocommerce_after_shop_loop_item', 'wc_readd_add_to_cart_buttons', 10 );
if (!function_exists('wc_readd_add_to_cart_buttons')){
function wc_readd_add_to_cart_buttons() {
//add to cart butto... |
299,059 | <p>Does anyone know if there is a way to handle a custom taxonomy for the <code>nav_menu_item</code> built'in post type?
When I assign my custom taxonomy to this post type, i don't see any change in the menu editor...
It works well with <code>posts</code>, <code>pages</code> and <code>custom post types</code>.</p>
<p... | [
{
"answer_id": 299061,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 2,
"selected": true,
"text": "<p>This is not how you enable adding your taxonomy terms to menus. To do that you just set <code>show_in_na... | 2018/03/27 | [
"https://wordpress.stackexchange.com/questions/299059",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/136422/"
] | Does anyone know if there is a way to handle a custom taxonomy for the `nav_menu_item` built'in post type?
When I assign my custom taxonomy to this post type, i don't see any change in the menu editor...
It works well with `posts`, `pages` and `custom post types`.
Here how I've registered my custom taxonomy:
```
a... | This is not how you enable adding your taxonomy terms to menus. To do that you just set `show_in_nav_menus` to `true` when registering the taxonomy. You have it set to `false`.
```
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => ... |
299,065 | <p>3/26: I created the Wordpress website on a live server. I downloaded a copy to my XAMPP server. I exported the database and created a local one.
I modified the wp-config.php file to connect to it. That all works.</p>
<p>However, I am not able to use any of the links in the navbar and otherwise to open any of the pa... | [
{
"answer_id": 299068,
"author": "keithschm",
"author_id": 109256,
"author_profile": "https://wordpress.stackexchange.com/users/109256",
"pm_score": 1,
"selected": true,
"text": "<p>did you change the urls in the database?</p>\n\n<p>add these to your wp-config.php </p>\n\n<pre><code>def... | 2018/03/27 | [
"https://wordpress.stackexchange.com/questions/299065",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140574/"
] | 3/26: I created the Wordpress website on a live server. I downloaded a copy to my XAMPP server. I exported the database and created a local one.
I modified the wp-config.php file to connect to it. That all works.
However, I am not able to use any of the links in the navbar and otherwise to open any of the pages and po... | did you change the urls in the database?
add these to your wp-config.php
```
define('WP_HOME', 'http://example.com');
define('WP_SITEURL, 'http://example.com');
```
Then update the ones in settings and remove those from the config file.
also update your permalinks as well |
299,069 | <p>currently I am developing a site using the Dokan multivendor plugin. I added a custom field in the registration form and </p>
<p>The below code is being used to add the custom field in the registration form</p>
<pre><code><p class="form-row form-group form-row-wide">
<label for="tskypeid"><?php ... | [
{
"answer_id": 299070,
"author": "Welcher",
"author_id": 27210,
"author_profile": "https://wordpress.stackexchange.com/users/27210",
"pm_score": 2,
"selected": false,
"text": "<p>If you're asking how to get those meta keys via WordPress, you can use the <code>get_user_meta()</code> - <a ... | 2018/03/27 | [
"https://wordpress.stackexchange.com/questions/299069",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/124702/"
] | currently I am developing a site using the Dokan multivendor plugin. I added a custom field in the registration form and
The below code is being used to add the custom field in the registration form
```
<p class="form-row form-group form-row-wide">
<label for="tskypeid"><?php _e( 'Skype ID', 'dokan-lite' ); ?> <... | If you're asking how to get those meta keys via WordPress, you can use the `get_user_meta()` - <https://codex.wordpress.org/Function_Reference/get_user_meta>
`get_user_meta( $user_id, 'tskypeid', true )` |
299,073 | <p>I just learned that it is possible to create differtent header.php files in your theme by creating a new File and calling it something like: header-myname.php.</p>
<p>To call, i would use the header templates tag like this:</p>
<pre><code>get_header( 'myname' );
</code></pre>
<p>But that way I would have to put ... | [
{
"answer_id": 299074,
"author": "kero",
"author_id": 108180,
"author_profile": "https://wordpress.stackexchange.com/users/108180",
"pm_score": 2,
"selected": false,
"text": "<p>No. The function adds a string of <code>\"header-{$name}.php\"</code> to the search for templates. You can't p... | 2018/03/27 | [
"https://wordpress.stackexchange.com/questions/299073",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140133/"
] | I just learned that it is possible to create differtent header.php files in your theme by creating a new File and calling it something like: header-myname.php.
To call, i would use the header templates tag like this:
```
get_header( 'myname' );
```
But that way I would have to put my file in the main directory of m... | No. The function adds a string of `"header-{$name}.php"` to the search for templates. You can't prepend it.
However, if you're not reyling on the `get_header` action, you can just as well use [`get_template_part()`](https://developer.wordpress.org/reference/functions/get_template_part/), as these functions work very s... |
299,132 | <p>How can <code>$post_id</code> be used while echoing posts in single.php?</p>
<p>Is it a global variable?</p>
| [
{
"answer_id": 299134,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 5,
"selected": true,
"text": "<p>No, <code>$post_id</code> is not a global variable. You can see a list of global variables WordPress cre... | 2018/03/28 | [
"https://wordpress.stackexchange.com/questions/299132",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140003/"
] | How can `$post_id` be used while echoing posts in single.php?
Is it a global variable? | No, `$post_id` is not a global variable. You can see a list of global variables WordPress creates here: <https://codex.wordpress.org/Global_Variables>
`$post_id` is just a common naming convention for a variable that contains a post ID. In tutorials and example code it shows that the value is expected to be a post ID,... |
299,138 | <p>I used <a href="https://wordpress.stackexchange.com/a/537/3206">this answer's</a> code to generate a widget that displays all subpages of the parent's page:</p>
<pre><code>if (is_page()) {
global $wp_query;
if( empty($wp_query->post->post_parent) ) {
$parent = $wp_query->post->ID;
} else {
... | [
{
"answer_id": 299180,
"author": "Alex Davison",
"author_id": 140648,
"author_profile": "https://wordpress.stackexchange.com/users/140648",
"pm_score": 2,
"selected": false,
"text": "<p>I believe you're currently only grabbing the parent, and not checking for the top level ancestor.</p>\... | 2018/03/28 | [
"https://wordpress.stackexchange.com/questions/299138",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3206/"
] | I used [this answer's](https://wordpress.stackexchange.com/a/537/3206) code to generate a widget that displays all subpages of the parent's page:
```
if (is_page()) {
global $wp_query;
if( empty($wp_query->post->post_parent) ) {
$parent = $wp_query->post->ID;
} else {
$parent = $wp_query->post->post_par... | Here is a function that will output the top level parent along with all of the children of the current page. Helpful menu classes are added to the output. E.g. `page_item_has_children`, `current_page_item`, `current_page_ancestor`, etc.
This solution is [based on one of the examples](https://developer.wordpress.org/re... |
299,185 | <p>How can i anonymize any comment after a certain time?
Is there a way to do this?
It's for data protection.</p>
| [
{
"answer_id": 299192,
"author": "bueltge",
"author_id": 170,
"author_profile": "https://wordpress.stackexchange.com/users/170",
"pm_score": 2,
"selected": false,
"text": "<p>I don't have a ready to use solution. Howeder I think is not to heavy to build a custom plugin, that do that.</p>... | 2018/03/28 | [
"https://wordpress.stackexchange.com/questions/299185",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/111201/"
] | How can i anonymize any comment after a certain time?
Is there a way to do this?
It's for data protection. | I don't have a ready to use solution. Howeder I think is not to heavy to build a custom plugin, that do that.
1. Update the comment data, use [`wp_update_comment()`](https://codex.wordpress.org/Function_Reference/wp_update_comment).
2. For anonymize the IP you can use [`wp_privacy_anonymize_ip()`](https://core.trac.wo... |
299,240 | <p>my site when it loads in a responsive mode the sidebar is below almost everything else is there any way I can move it up a bit, any css i can put the theme is nanomag</p>
| [
{
"answer_id": 299192,
"author": "bueltge",
"author_id": 170,
"author_profile": "https://wordpress.stackexchange.com/users/170",
"pm_score": 2,
"selected": false,
"text": "<p>I don't have a ready to use solution. Howeder I think is not to heavy to build a custom plugin, that do that.</p>... | 2018/03/29 | [
"https://wordpress.stackexchange.com/questions/299240",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129261/"
] | my site when it loads in a responsive mode the sidebar is below almost everything else is there any way I can move it up a bit, any css i can put the theme is nanomag | I don't have a ready to use solution. Howeder I think is not to heavy to build a custom plugin, that do that.
1. Update the comment data, use [`wp_update_comment()`](https://codex.wordpress.org/Function_Reference/wp_update_comment).
2. For anonymize the IP you can use [`wp_privacy_anonymize_ip()`](https://core.trac.wo... |
299,249 | <p>Is it possible to append <code>?ref=myref</code> to all external URLs?</p>
<p>If so I'm guessing I will also need to check if a <code>?</code> already exists and use <code>&</code> if so.</p>
<p>I'm a WP noob just coming from Joomla, any tips / help would be a very nice warm welcome. :) </p>
<p>Not sure if it... | [
{
"answer_id": 299251,
"author": "Ben",
"author_id": 140703,
"author_profile": "https://wordpress.stackexchange.com/users/140703",
"pm_score": 0,
"selected": false,
"text": "<p>You can check if the request headers contain <code>http referer</code>, and then check if the <code>http refere... | 2018/03/29 | [
"https://wordpress.stackexchange.com/questions/299249",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140699/"
] | Is it possible to append `?ref=myref` to all external URLs?
If so I'm guessing I will also need to check if a `?` already exists and use `&` if so.
I'm a WP noob just coming from Joomla, any tips / help would be a very nice warm welcome. :)
Not sure if it can be done on page or `.htaccess`. | Inbound vs Outbound links:
==========================
I guess it'll be helpful to clarify these concepts:
**Inbound links** = links from another website to your own website.
**Outbound links** = links from your website to another website.
An [external link](https://moz.com/learn/seo/external-link) would be any link... |
299,267 | <p>I am working in the theme called Understrap. I work in the child-theme. The theme </p>
<p>allready has a style.css and functions.php. I want to create my own style.css file </p>
<p>and overwrite that style.css they have included. Any suggestions?</p>
<p>Thank you very much </p>
| [
{
"answer_id": 299278,
"author": "AddWeb Solution Pvt Ltd",
"author_id": 73643,
"author_profile": "https://wordpress.stackexchange.com/users/73643",
"pm_score": -1,
"selected": false,
"text": "<p>You need to add following code to your child-theme's functions.php</p>\n\n<pre><code> /**... | 2018/03/29 | [
"https://wordpress.stackexchange.com/questions/299267",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140728/"
] | I am working in the theme called Understrap. I work in the child-theme. The theme
allready has a style.css and functions.php. I want to create my own style.css file
and overwrite that style.css they have included. Any suggestions?
Thank you very much | Take a look at the official docs:
<https://codex.wordpress.org/Child_Themes>
<https://developer.wordpress.org/themes/advanced-topics/child-themes/>
Make sure you are within your child theme `functions.php` and use this code to make sure the function is firing. It will kill the page if it is working correctly.
```
... |
299,324 | <p>I've created an rewrite endpoint with the <a href="https://developer.wordpress.org/reference/functions/add_rewrite_endpoint/" rel="nofollow noreferrer">add_rewrite_endpoint</a> function … here is the whole contruct:</p>
<pre><code>// Register to query vars
add_filter( 'query_vars', 'add_query_vars');
function ad... | [
{
"answer_id": 299333,
"author": "Friss",
"author_id": 62392,
"author_profile": "https://wordpress.stackexchange.com/users/62392",
"pm_score": 3,
"selected": false,
"text": "<p>EDIT 2</p>\n\n<p>To use pretty permalinks, such as example.com/account/john\nyou need to activate in your admin... | 2018/03/29 | [
"https://wordpress.stackexchange.com/questions/299324",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/52227/"
] | I've created an rewrite endpoint with the [add\_rewrite\_endpoint](https://developer.wordpress.org/reference/functions/add_rewrite_endpoint/) function … here is the whole contruct:
```
// Register to query vars
add_filter( 'query_vars', 'add_query_vars');
function add_query_vars( $vars ) {
$vars[] = 'account';
... | Rewrite rules only handle incoming requests, they aren't involved in link generation.
The primary WordPress rewrite system is parsed internally with PHP, you won't see any changes to an `.htaccess` file when you add an endpoint. The basic .htaccess rules essentially say "If this isn't a request for a physical file or ... |
299,346 | <p>I'm looking to mass remove or clear the default attribute for variable products in Woocommerce. </p>
<p><a href="https://i.stack.imgur.com/BdWNd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BdWNd.png" alt="enter image description here"></a></p>
<p>Is there an easy way to mass clear this value... | [
{
"answer_id": 299352,
"author": "mmm",
"author_id": 74311,
"author_profile": "https://wordpress.stackexchange.com/users/74311",
"pm_score": 1,
"selected": false,
"text": "<p>you can modify the default attribute with the following code. this code retrieve the complet list of products the... | 2018/03/30 | [
"https://wordpress.stackexchange.com/questions/299346",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/118984/"
] | I'm looking to mass remove or clear the default attribute for variable products in Woocommerce.
[](https://i.stack.imgur.com/BdWNd.png)
Is there an easy way to mass clear this value? If not, would you be able to direct me on where I can find this va... | Default attributes of WooCommerce variable products are stored as post meta in the database.
You can find them in the `wp_postmeta` table, where the `post_id` column is the post ID of the parent product (Variable product), and the `meta_key` column is `_default_attributes`.
You can clear and remove default attributes ... |
299,361 | <p>For example I have page on which I have only custom post types (books or music or testimonials) and don't have standard WordPress posts.</p>
<p>Can I use home.php to display my custom post types which are on pages, books or music or testimonials, and single-posttype.php for single post of each post type? Or do I ne... | [
{
"answer_id": 299370,
"author": "Krzysiek Dróżdż",
"author_id": 34172,
"author_profile": "https://wordpress.stackexchange.com/users/34172",
"pm_score": 2,
"selected": false,
"text": "<p>The simple answer is “yes, you can”, but I’m pretty sure it won’t satisfy you ;)</p>\n\n<p>So... How ... | 2018/03/30 | [
"https://wordpress.stackexchange.com/questions/299361",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/135678/"
] | For example I have page on which I have only custom post types (books or music or testimonials) and don't have standard WordPress posts.
Can I use home.php to display my custom post types which are on pages, books or music or testimonials, and single-posttype.php for single post of each post type? Or do I need to crea... | The simple answer is “yes, you can”, but I’m pretty sure it won’t satisfy you ;)
So... How can you achieve this and show only custom posts on home.php? All you need is to use pre\_get\_posts hook like so:
```
add_action( 'pre_get_posts', 'add_custom_post_types_to_home_query' );
function add_custom_post_types_to_home... |
299,367 | <p>I want to resize a particular image on the fly with the_post_thumbnail() which I have done like so:</p>
<pre><code><?php the_post_thumbnail( array (475, 317 ) ); ?>
</code></pre>
<p>This works in resizing the image to the specified size but I also want to add a class to this. If I try add a class then the si... | [
{
"answer_id": 299372,
"author": "Simo Patrek",
"author_id": 133002,
"author_profile": "https://wordpress.stackexchange.com/users/133002",
"pm_score": 3,
"selected": true,
"text": "<p>Try To Use it Like This :</p>\n\n<pre><code><?php the_post_thumbnail( array (475, 317), [ 'class' =&g... | 2018/03/30 | [
"https://wordpress.stackexchange.com/questions/299367",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140276/"
] | I want to resize a particular image on the fly with the\_post\_thumbnail() which I have done like so:
```
<?php the_post_thumbnail( array (475, 317 ) ); ?>
```
This works in resizing the image to the specified size but I also want to add a class to this. If I try add a class then the size dimensions are still correc... | Try To Use it Like This :
```
<?php the_post_thumbnail( array (475, 317), [ 'class' => 'border--round' ] ); ?>
``` |
299,375 | <p>I have a class called "switchable" which basically switches the text and image from left to right, to right to left. I want this to happen for every second record. So, the first one on the left, and the second on the right etc. I just don't know how to achieve this with the below code. Every second record should hav... | [
{
"answer_id": 299377,
"author": "swissspidy",
"author_id": 12404,
"author_profile": "https://wordpress.stackexchange.com/users/12404",
"pm_score": 2,
"selected": true,
"text": "<p>Inside the loop you can use <code>$the_query->current_post</code> to get the index of the post currently... | 2018/03/30 | [
"https://wordpress.stackexchange.com/questions/299375",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140276/"
] | I have a class called "switchable" which basically switches the text and image from left to right, to right to left. I want this to happen for every second record. So, the first one on the left, and the second on the right etc. I just don't know how to achieve this with the below code. Every second record should have i... | Inside the loop you can use `$the_query->current_post` to get the index of the post currently being displayed. You can then check if the index is an odd or even number and conditionally add the class. Example:
```
if ( 1 === $the_query->current_post % 2 ) {
echo 'class="switchable"';
}
``` |
299,386 | <p>I am currently working on my <code>home.php</code> file for my theme, and I'm planning on displaying my the last Blog posts in a "grid view", so that there are 4 containers in a row, containing the title and some more information.</p>
<p>I tried out some things, but nothing worked the way I wanted it to. The last t... | [
{
"answer_id": 299387,
"author": "jkresse",
"author_id": 140133,
"author_profile": "https://wordpress.stackexchange.com/users/140133",
"pm_score": 0,
"selected": false,
"text": "<p>Solved it by myself, here is how i did it: </p>\n\n<pre><code> <?php\n\n $x = 0;\n ... | 2018/03/30 | [
"https://wordpress.stackexchange.com/questions/299386",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140133/"
] | I am currently working on my `home.php` file for my theme, and I'm planning on displaying my the last Blog posts in a "grid view", so that there are 4 containers in a row, containing the title and some more information.
I tried out some things, but nothing worked the way I wanted it to. The last thing I did was puttin... | It's a little bit hard to guess, what exactly do you want to achieve (you've mentioned something about four posts in a row and then there is number 6 in your for loop), but...
If you want to display only 4 posts in your loop, then you can use `current_post` field of `$wp_query`, so the loop may look like this:
```
<?... |
299,437 | <p>Is it possible to use wp_remote_post to send http post requests to 3rd party api's? I wasn't able to successfully save the user object as a javascript variable, so I was hoping I could make an http request with php and handle the javascript manipulation in my node express app. </p>
<p>Current attempt:</p>
<pre><co... | [
{
"answer_id": 299438,
"author": "Somin",
"author_id": 140832,
"author_profile": "https://wordpress.stackexchange.com/users/140832",
"pm_score": 0,
"selected": false,
"text": "<p>You can try below code for wp_remote_post.might be you are missing remote post url parameter.</p>\n\n<p>Also... | 2018/03/31 | [
"https://wordpress.stackexchange.com/questions/299437",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140794/"
] | Is it possible to use wp\_remote\_post to send http post requests to 3rd party api's? I wasn't able to successfully save the user object as a javascript variable, so I was hoping I could make an http request with php and handle the javascript manipulation in my node express app.
Current attempt:
```
function identif... | The 'body' needs to be an array, not including the 'json\_encode($user)' piece.
```
$response = wp_remote_post( 'myapp.com/endpoint', array(
'method' => 'POST',
'headers' => array('Content-Type' => 'application/json; charset=utf-8'),
'body' => $user
)
);
```
I have this in my function since I also had issues... |
299,521 | <p>I am new to Wordpress development and am tired of fighting with Contact form 7 to style it how I would like. Is it possible and not considered 'bad practice' to put a html form on my contact page and have it post to a php page which handles the form submission? Or is that just simply not done?</p>
| [
{
"answer_id": 299525,
"author": "Mr Rethman",
"author_id": 27393,
"author_profile": "https://wordpress.stackexchange.com/users/27393",
"pm_score": 1,
"selected": false,
"text": "<p>Since your not performing CRUD on the DB, I don't see why not. I've done it before where I used a page tem... | 2018/04/01 | [
"https://wordpress.stackexchange.com/questions/299521",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140276/"
] | I am new to Wordpress development and am tired of fighting with Contact form 7 to style it how I would like. Is it possible and not considered 'bad practice' to put a html form on my contact page and have it post to a php page which handles the form submission? Or is that just simply not done? | This is my very simple implementation of contact form:
```
class WPSE_299521_Form {
/**
* Class constructor
*/
public function __construct() {
$this->define_hooks();
}
public function controller() {
if( isset( $_POST['submit'] ) ) { // Submit button
$full_name... |
299,533 | <p>I have a few years worth of experience building <a href="https://developer.wordpress.org/themes/advanced-topics/child-themes/" rel="nofollow noreferrer">Child Themes</a> in WordPress, which is generally my preferred route when developing a new website as I am not a theme developer per say.</p>
<p>I am now doing a c... | [
{
"answer_id": 299525,
"author": "Mr Rethman",
"author_id": 27393,
"author_profile": "https://wordpress.stackexchange.com/users/27393",
"pm_score": 1,
"selected": false,
"text": "<p>Since your not performing CRUD on the DB, I don't see why not. I've done it before where I used a page tem... | 2018/04/01 | [
"https://wordpress.stackexchange.com/questions/299533",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/52120/"
] | I have a few years worth of experience building [Child Themes](https://developer.wordpress.org/themes/advanced-topics/child-themes/) in WordPress, which is generally my preferred route when developing a new website as I am not a theme developer per say.
I am now doing a couple of projects which want to leverage the WP... | This is my very simple implementation of contact form:
```
class WPSE_299521_Form {
/**
* Class constructor
*/
public function __construct() {
$this->define_hooks();
}
public function controller() {
if( isset( $_POST['submit'] ) ) { // Submit button
$full_name... |
299,542 | <p>This is not really a question but a guide on how to make authenticated requests to the Wordpress API using JWT. I'm writing this as a reminder to myself and for those who may need some help with the same topic. </p>
| [
{
"answer_id": 302024,
"author": "grazdev",
"author_id": 129417,
"author_profile": "https://wordpress.stackexchange.com/users/129417",
"pm_score": 6,
"selected": true,
"text": "<p><strong>Why JWT authentication</strong></p>\n\n<p>I'm building a site that uses Wordpress as the back-end, a... | 2018/04/01 | [
"https://wordpress.stackexchange.com/questions/299542",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129417/"
] | This is not really a question but a guide on how to make authenticated requests to the Wordpress API using JWT. I'm writing this as a reminder to myself and for those who may need some help with the same topic. | **Why JWT authentication**
I'm building a site that uses Wordpress as the back-end, and a React+Redux app as the front-end, so I'm pulling all the content in the front-end by making requests to the Wordpress API. Some requests (mainly, POST requests) must be authenticated, which is when I came across JWT.
**What we n... |
299,548 | <p>i am not good in php</p>
<p>but i am using advanced custom fields plugin to improve my web site , now in my website i using about 25 "text" advanced custom fields and 1 "choice - select" advanced custom field</p>
<p>and I also have a plugin like woocommerce it use about 15 custom fields</p>
<p>now i have about 40... | [
{
"answer_id": 302024,
"author": "grazdev",
"author_id": 129417,
"author_profile": "https://wordpress.stackexchange.com/users/129417",
"pm_score": 6,
"selected": true,
"text": "<p><strong>Why JWT authentication</strong></p>\n\n<p>I'm building a site that uses Wordpress as the back-end, a... | 2018/04/01 | [
"https://wordpress.stackexchange.com/questions/299548",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140950/"
] | i am not good in php
but i am using advanced custom fields plugin to improve my web site , now in my website i using about 25 "text" advanced custom fields and 1 "choice - select" advanced custom field
and I also have a plugin like woocommerce it use about 15 custom fields
now i have about 40 custom field for every ... | **Why JWT authentication**
I'm building a site that uses Wordpress as the back-end, and a React+Redux app as the front-end, so I'm pulling all the content in the front-end by making requests to the Wordpress API. Some requests (mainly, POST requests) must be authenticated, which is when I came across JWT.
**What we n... |
299,569 | <p>I am trying to hack together something in mySQL to allow me to change from one plugin to another without having to do manual data entry for all of my products on my woocommerce store.</p>
<p>The goal is to change every meta_value with the meta_key <strong>_woofv_video_embed</strong> from this format <code>https://y... | [
{
"answer_id": 299572,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 0,
"selected": false,
"text": "<p>Never manipulate the DB directly, instead write some small wordpress plugin to do it. The amount of gotch... | 2018/04/02 | [
"https://wordpress.stackexchange.com/questions/299569",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/140965/"
] | I am trying to hack together something in mySQL to allow me to change from one plugin to another without having to do manual data entry for all of my products on my woocommerce store.
The goal is to change every meta\_value with the meta\_key **\_woofv\_video\_embed** from this format `https://youtu.be/JCdljysorMo` to... | I misplaced a single quote. This query worked for me and solved my problem.
update `wp_postmeta` set `meta_value`= concat( 'a:1:{s:3:"url";s:28:"', `meta_value`, '";}' ) where `meta_key` = '\_woofv\_video\_embed' |