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 |
|---|---|---|---|---|---|---|
281,226 | <p>We use this type of Add to Cart URL on our site a lot of times: <a href="http://yourdomain.com/cart/?add-to-cart=25" rel="nofollow noreferrer">http://yourdomain.com/cart/?add-to-cart=25</a>. The problem is after it redirects to the Cart page, if the client changes his/her mind and removes the recently added product,... | [
{
"answer_id": 290870,
"author": "dev_masta",
"author_id": 89164,
"author_profile": "https://wordpress.stackexchange.com/users/89164",
"pm_score": 2,
"selected": false,
"text": "<p>The solution would be to lose the <code>?add-to-cart=25</code>part of the URL.\nThe simplest way to do that... | 2017/09/27 | [
"https://wordpress.stackexchange.com/questions/281226",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/125003/"
] | We use this type of Add to Cart URL on our site a lot of times: <http://yourdomain.com/cart/?add-to-cart=25>. The problem is after it redirects to the Cart page, if the client changes his/her mind and removes the recently added product, the Cart page loads and adds it again since "?add-to-cart=25" is on the URL.
My q... | The solution would be to lose the `?add-to-cart=25`part of the URL.
The simplest way to do that is with javascript **History API**:
```
history.pushState(null, "", location.href.split("?")[0]);
```
Docs: <https://developer.mozilla.org/en-US/docs/Web/API/History_API>
>
> The DOM window object provides access to the... |
281,230 | <p>On <a href="https://www.altcinematic.co.uk/video-test/" rel="nofollow noreferrer">https://www.altcinematic.co.uk/video-test/</a> I have input a video header using advanced custom fields and a new page template.</p>
<p>Page template:</p>
<pre><code><?php
/*
Template Name: Video Banner
*/
?>
<?php get_heade... | [
{
"answer_id": 281237,
"author": "Sovai",
"author_id": 122599,
"author_profile": "https://wordpress.stackexchange.com/users/122599",
"pm_score": 0,
"selected": false,
"text": "<p>This question is nothing to do with WordPress. Your problem is position fixed of your header. Try to wrap you... | 2017/09/27 | [
"https://wordpress.stackexchange.com/questions/281230",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/91013/"
] | On <https://www.altcinematic.co.uk/video-test/> I have input a video header using advanced custom fields and a new page template.
Page template:
```
<?php
/*
Template Name: Video Banner
*/
?>
<?php get_header(); ?>
<main class="main-content">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<se... | You can target those devices using css, and put a declaration specifically for that.
Add this to your css file, and adjust to the suitable value:
```
@media screen and (max-width: 768px) {
.page-template-page-video-banner .fullscreen-intro {
margin-top: 135px !important;
}
}
```
[ );
$users = $user_query->get_results();
foreach( $users as $user)
{
// getting user data
}
</code></pre>
<p>Now w... | [
{
"answer_id": 281252,
"author": "Kuliraj",
"author_id": 128600,
"author_profile": "https://wordpress.stackexchange.com/users/128600",
"pm_score": 0,
"selected": false,
"text": "<p>This will return and loop though all of your subscribers.</p>\n\n<pre><code>$users = get_users( array(\n ... | 2017/09/27 | [
"https://wordpress.stackexchange.com/questions/281251",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/100940/"
] | I have more than 3000 users with role 'subscriber', and now i want to fetch all users with role 'subscriber'.
```
$user_query = new WP_User_Query( array( 'role' => 'Subscriber' ) );
$users = $user_query->get_results();
foreach( $users as $user)
{
// getting user data
}
```
Now when i tried with above code, the... | The problem here is that this query has pagination by default, and what you're asking for is not scalable.
For example, this query fetches 5 posts at a time, and displays the 6th page of users:
```
$user_query = new WP_User_Query( array(
'number' => 5,
'offset' => 25
) );
```
You can pass `-1` to fetch unli... |
281,261 | <p>I am developing a theme and I wonder if there anyway I can add a visual edit shortcut without selective refresh?</p>
<pre><code>$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
$wp_customize->selective_refresh->add_partial( 'blogname', array(
'selector' => '.site-title... | [
{
"answer_id": 281442,
"author": "Weston Ruter",
"author_id": 8521,
"author_profile": "https://wordpress.stackexchange.com/users/8521",
"pm_score": 0,
"selected": false,
"text": "<p>What you can to do is extend <code>wp.customize.selectiveRefresh.Partial</code> in JavaScript to create a ... | 2017/09/27 | [
"https://wordpress.stackexchange.com/questions/281261",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128610/"
] | I am developing a theme and I wonder if there anyway I can add a visual edit shortcut without selective refresh?
```
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
$wp_customize->selective_refresh->add_partial( 'blogname', array(
'selector' => '.site-title a',
'render_callback' =>... | There is a simple way to do this by using **\_\_return\_false** . The downside is you get a double refresh as it checks for a partial and then returns "false" which results in a full refresh. This is problematic if you are using javascript only to show a "realtime" preview. In that case, you'd have to go with Weston Ru... |
281,311 | <p>I have added some custom columns to users table using the following function</p>
<pre><code> public function modify_users_columns( $column_headers ) {
//Remove email, role, and posts column
unset( $column_headers['email'], $column_headers['role'], $column_headers['posts'] );
//Add sponsor id, level1 ... | [
{
"answer_id": 281312,
"author": "Abson Reavs",
"author_id": 128638,
"author_profile": "https://wordpress.stackexchange.com/users/128638",
"pm_score": -1,
"selected": false,
"text": "<p>Try this.... </p>\n\n<pre><code>case 'level1' :\n $level1 = get_user_meta( $user_id, 'level1', true )... | 2017/09/27 | [
"https://wordpress.stackexchange.com/questions/281311",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/52654/"
] | I have added some custom columns to users table using the following function
```
public function modify_users_columns( $column_headers ) {
//Remove email, role, and posts column
unset( $column_headers['email'], $column_headers['role'], $column_headers['posts'] );
//Add sponsor id, level1 and level2 col... | I was using the wrong filter name by adding an 's' in manage\_users\_custom\_columns. The correct filter name is without 's' : manage\_users\_custom\_column.
This was pointed out in the comments by @mmm. |
281,361 | <p>I don't know if I've complicated things a bit, so I'll explain things from the top. I have a set up with a custom post type (news), which is exposed via the REST API. The main endpoint (<code>/wp-json/wp/v2/news</code>) returns a list of <code>news</code> items, which needs to be sorted by popularity. I tried a few ... | [
{
"answer_id": 281366,
"author": "aalaap",
"author_id": 14411,
"author_profile": "https://wordpress.stackexchange.com/users/14411",
"pm_score": 1,
"selected": false,
"text": "<p>I looked around again with a more relaxed mind and figured out that <code>the_posts</code> is the action hook ... | 2017/09/28 | [
"https://wordpress.stackexchange.com/questions/281361",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14411/"
] | I don't know if I've complicated things a bit, so I'll explain things from the top. I have a set up with a custom post type (news), which is exposed via the REST API. The main endpoint (`/wp-json/wp/v2/news`) returns a list of `news` items, which needs to be sorted by popularity. I tried a few post view count plugins, ... | I looked around again with a more relaxed mind and figured out that `the_posts` is the action hook I was looking for. This is how I just did it:
```
add_action(
'the_post',
function ( $post ) {
$count = (int) get_field('views');
$count++;
update_field('views', $count);
}
);
```
No... |
281,382 | <p>I have a plugin that uses custom post type for holding content that I pull via a shortcode elsewhere. However on a new site I noticed one of the posts in the CPT started showing up in the google search results. The post isn't linked anywhere directly. How would that show up there? How can I hide it from showing up i... | [
{
"answer_id": 281383,
"author": "FluffyKitten",
"author_id": 63360,
"author_profile": "https://wordpress.stackexchange.com/users/63360",
"pm_score": 4,
"selected": true,
"text": "<p>If you are using an SEO plugin such as <strong>Yoast</strong>, it automatically adds all Custom Post Type... | 2017/09/28 | [
"https://wordpress.stackexchange.com/questions/281382",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24054/"
] | I have a plugin that uses custom post type for holding content that I pull via a shortcode elsewhere. However on a new site I noticed one of the posts in the CPT started showing up in the google search results. The post isn't linked anywhere directly. How would that show up there? How can I hide it from showing up in g... | If you are using an SEO plugin such as **Yoast**, it automatically adds all Custom Post Types (and Taxonomies) to the sitemap that is used by Google & other search engines.
You will need to explicitly exclude them from the sitemap e.g in Yoast, this is under the "Post Types"/"Taxomonies" tab in the "XML Sitemaps" sett... |
281,448 | <p>I browsed many articles to know the section Name of the "Menu" in the theme customizer. Here are the few resources that proclaim and identifies that the default section name is "nav" →</p>
<ol>
<li><a href="https://wptheming.com/2012/06/add-options-to-theme-customizer-default-sections/" rel="nofollow noreferrer">ht... | [
{
"answer_id": 281383,
"author": "FluffyKitten",
"author_id": 63360,
"author_profile": "https://wordpress.stackexchange.com/users/63360",
"pm_score": 4,
"selected": true,
"text": "<p>If you are using an SEO plugin such as <strong>Yoast</strong>, it automatically adds all Custom Post Type... | 2017/09/29 | [
"https://wordpress.stackexchange.com/questions/281448",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/105791/"
] | I browsed many articles to know the section Name of the "Menu" in the theme customizer. Here are the few resources that proclaim and identifies that the default section name is "nav" →
1. <https://wptheming.com/2012/06/add-options-to-theme-customizer-default-sections/>
2. <http://natko.com/changing-default-wordpress-t... | If you are using an SEO plugin such as **Yoast**, it automatically adds all Custom Post Types (and Taxonomies) to the sitemap that is used by Google & other search engines.
You will need to explicitly exclude them from the sitemap e.g in Yoast, this is under the "Post Types"/"Taxomonies" tab in the "XML Sitemaps" sett... |
281,462 | <p>i am running membership site. any one can registered on my site. </p>
<p>i want to disallow special characters(ie:!@#$%^&*), space, capital letter, dot(.) in user name on registration.</p>
<p>i don't have any code that can cover all my (special characters, space, capital letter, dot) requirement. i am using se... | [
{
"answer_id": 281383,
"author": "FluffyKitten",
"author_id": 63360,
"author_profile": "https://wordpress.stackexchange.com/users/63360",
"pm_score": 4,
"selected": true,
"text": "<p>If you are using an SEO plugin such as <strong>Yoast</strong>, it automatically adds all Custom Post Type... | 2017/09/29 | [
"https://wordpress.stackexchange.com/questions/281462",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/114481/"
] | i am running membership site. any one can registered on my site.
i want to disallow special characters(ie:!@#$%^&\*), space, capital letter, dot(.) in user name on registration.
i don't have any code that can cover all my (special characters, space, capital letter, dot) requirement. i am using separate separate func... | If you are using an SEO plugin such as **Yoast**, it automatically adds all Custom Post Types (and Taxonomies) to the sitemap that is used by Google & other search engines.
You will need to explicitly exclude them from the sitemap e.g in Yoast, this is under the "Post Types"/"Taxomonies" tab in the "XML Sitemaps" sett... |
281,473 | <p>I am looking for a solution to output nothing instead the default avatar when a user does not have any avatar.</p>
<p>I am currently using this line. I looked at the function and the only thing I got so far is to use <code>blank</code> as default avatar but its still occupies space and I do not want that.</p>
<pre... | [
{
"answer_id": 281477,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 0,
"selected": false,
"text": "<p>Unlikely to be worth your time to implement such a thing. You need to ask gravatar to give you the URL fo... | 2017/09/29 | [
"https://wordpress.stackexchange.com/questions/281473",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/38602/"
] | I am looking for a solution to output nothing instead the default avatar when a user does not have any avatar.
I am currently using this line. I looked at the function and the only thing I got so far is to use `blank` as default avatar but its still occupies space and I do not want that.
```
echo get_avatar( get_the_... | You can use the `get_avatar` filter to change the output or `avatar_defaults` to add new image that can be placed on your server.
Here is an example code for adding new avatar that you can set as default from the Settings > Discussion page.
```
add_filter( 'avatar_defaults', 'add_new_gravatar_image' );
function add_n... |
281,490 | <p>I'm using the WooCommerce plugin and I have a list of like 200+ products and I want to flip horizontally the images for every product.</p>
<p>If I will do this manually it will take me days probably to take them one by one. </p>
<p>I've looked for plugins which might help me do this automatically but no luck. </p>... | [
{
"answer_id": 281477,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 0,
"selected": false,
"text": "<p>Unlikely to be worth your time to implement such a thing. You need to ask gravatar to give you the URL fo... | 2017/09/29 | [
"https://wordpress.stackexchange.com/questions/281490",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12572/"
] | I'm using the WooCommerce plugin and I have a list of like 200+ products and I want to flip horizontally the images for every product.
If I will do this manually it will take me days probably to take them one by one.
I've looked for plugins which might help me do this automatically but no luck.
Is there any way to... | You can use the `get_avatar` filter to change the output or `avatar_defaults` to add new image that can be placed on your server.
Here is an example code for adding new avatar that you can set as default from the Settings > Discussion page.
```
add_filter( 'avatar_defaults', 'add_new_gravatar_image' );
function add_n... |
281,508 | <pre><code>$topics = query_posts( array(
'post_type' => 'topics',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => array(
'key' => 'forum_category',
'value' => $forum_id,
'compare' => '='
)
... | [
{
"answer_id": 281511,
"author": "lukgoh",
"author_id": 128475,
"author_profile": "https://wordpress.stackexchange.com/users/128475",
"pm_score": 2,
"selected": true,
"text": "<p>Changing the query to:</p>\n\n<pre><code> $topics = query_posts( \n array( \n 'post... | 2017/09/29 | [
"https://wordpress.stackexchange.com/questions/281508",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128475/"
] | ```
$topics = query_posts( array(
'post_type' => 'topics',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => array(
'key' => 'forum_category',
'value' => $forum_id,
'compare' => '='
)
)
);
```
Doesn't seem ... | Changing the query to:
```
$topics = query_posts(
array(
'post_type' => 'topics',
'meta_query' => array(
array(
'key' => 'forum_category',
'value' => $forum_id
)
... |
281,550 | <p>I am trying to query a list with all Categories, Subcategories and Posts of a custom post type.</p>
<p>e.g.:</p>
<pre><code>Maincat1
-Subcat1
-Post1
-Post2
-Subcat2
-Subcat3
Maincat2
-Subcat3
-Post3
Maincat3
-Post4
</code></pre>
<p>I'm getting mad trying to accomplish that. I tried out so... | [
{
"answer_id": 282372,
"author": "BlueSuiter",
"author_id": 92665,
"author_profile": "https://wordpress.stackexchange.com/users/92665",
"pm_score": 1,
"selected": false,
"text": "<p>@niko Please, find your required code, it will give you exact output you were seeking for. I think you wer... | 2017/09/30 | [
"https://wordpress.stackexchange.com/questions/281550",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/67490/"
] | I am trying to query a list with all Categories, Subcategories and Posts of a custom post type.
e.g.:
```
Maincat1
-Subcat1
-Post1
-Post2
-Subcat2
-Subcat3
Maincat2
-Subcat3
-Post3
Maincat3
-Post4
```
I'm getting mad trying to accomplish that. I tried out so many things that I found on the ... | @niko Please, find your required code, it will give you exact output you were seeking for. I think you were doing all right except in the final output you were missing the right structure.
Also, I recommand not to assign posts to the parent category as this structure not support that. However, I think with minor tweak... |
281,565 | <p>So here's what I'm trying to do. I'm working on a plugin and I want to check each comment and see if the author of that comment has a role of "administrator" or "editor". If they do, rather than display their user name and avatar, I would like to display the name of the website along with a company logo or something... | [
{
"answer_id": 282372,
"author": "BlueSuiter",
"author_id": 92665,
"author_profile": "https://wordpress.stackexchange.com/users/92665",
"pm_score": 1,
"selected": false,
"text": "<p>@niko Please, find your required code, it will give you exact output you were seeking for. I think you wer... | 2017/10/01 | [
"https://wordpress.stackexchange.com/questions/281565",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128795/"
] | So here's what I'm trying to do. I'm working on a plugin and I want to check each comment and see if the author of that comment has a role of "administrator" or "editor". If they do, rather than display their user name and avatar, I would like to display the name of the website along with a company logo or something. I... | @niko Please, find your required code, it will give you exact output you were seeking for. I think you were doing all right except in the final output you were missing the right structure.
Also, I recommand not to assign posts to the parent category as this structure not support that. However, I think with minor tweak... |
281,571 | <p>Based on an example <a href="https://wordpress.org/support/topic/confirm-that-publish_future_post-hook-does-not-work/" rel="nofollow noreferrer">found on this page</a>, I attempted to use this in my plugin. Nothing fired. A note <a href="https://codex.wordpress.org/Post_Status_Transitions" rel="nofollow noreferrer">... | [
{
"answer_id": 281572,
"author": "FluffyKitten",
"author_id": 63360,
"author_profile": "https://wordpress.stackexchange.com/users/63360",
"pm_score": 2,
"selected": false,
"text": "<p><strong>Update</strong>:</p>\n\n<p>Now that you've changed your question (and made my original answer lo... | 2017/10/01 | [
"https://wordpress.stackexchange.com/questions/281571",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/47326/"
] | Based on an example [found on this page](https://wordpress.org/support/topic/confirm-that-publish_future_post-hook-does-not-work/), I attempted to use this in my plugin. Nothing fired. A note [on this page](https://codex.wordpress.org/Post_Status_Transitions) stated publish\_future\_post is deprecated and replaced with... | Use `publish_future_post` action hook. Contrary to what Codex says, it is not deprecated, and it works with WordPress 4.8.2. Your code should be:
```
function my_test_future_post( $post_id ) {
update_post_meta( $post_id, 'hook_fired', 'true' );
}
add_action( 'publish_future_post', 'my_test_future_post' );
```
Te... |
281,580 | <p>3 weeks ago I uploaded all my files from localhost to cPanel. I want to switch it back , the issue I facing is my original database from the localhost is not updated . I downloaded the database from the cPanel and tried to set it in local host in wp-config.php , but its transferring me to installation every time and... | [
{
"answer_id": 281572,
"author": "FluffyKitten",
"author_id": 63360,
"author_profile": "https://wordpress.stackexchange.com/users/63360",
"pm_score": 2,
"selected": false,
"text": "<p><strong>Update</strong>:</p>\n\n<p>Now that you've changed your question (and made my original answer lo... | 2017/10/01 | [
"https://wordpress.stackexchange.com/questions/281580",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128812/"
] | 3 weeks ago I uploaded all my files from localhost to cPanel. I want to switch it back , the issue I facing is my original database from the localhost is not updated . I downloaded the database from the cPanel and tried to set it in local host in wp-config.php , but its transferring me to installation every time and th... | Use `publish_future_post` action hook. Contrary to what Codex says, it is not deprecated, and it works with WordPress 4.8.2. Your code should be:
```
function my_test_future_post( $post_id ) {
update_post_meta( $post_id, 'hook_fired', 'true' );
}
add_action( 'publish_future_post', 'my_test_future_post' );
```
Te... |
281,611 | <p>This code appears in my theme's <code>functions.php</code>, also in child theme's. I've deleted it for two times but it comes back. What is it?</p>
<pre><code>if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['password'] ) && ( $_REQUEST['password'] == '227972a1a62825660efb0f32126db07f' ) ) {
... | [
{
"answer_id": 281612,
"author": "Milan Petrovic",
"author_id": 126702,
"author_profile": "https://wordpress.stackexchange.com/users/126702",
"pm_score": 3,
"selected": false,
"text": "<p>Your website has been hacked. This is malicious code that gets triggered from the outside, loading m... | 2017/10/01 | [
"https://wordpress.stackexchange.com/questions/281611",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/125408/"
] | This code appears in my theme's `functions.php`, also in child theme's. I've deleted it for two times but it comes back. What is it?
```
if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['password'] ) && ( $_REQUEST['password'] == '227972a1a62825660efb0f32126db07f' ) ) {
$div_code_name = "wp_vcd";
switch (... | Your website has been hacked. This is malicious code that gets triggered from the outside, loading more malicious content from 'www.dolsh.cc' domain.
If the content comes back after you remove it, then you have hacked files somewhere else that will automatically rewrite functions.php any time page is loaded. You need ... |
281,629 | <p>I need to fetch the list of all users who are Authors (with Author capabilities)</p>
<p>get_users allows to fetch users with roles, but if users are filter with author role, it skips users with role admin and editor (but they can also create posts). </p>
<p>So I need some other way to fetch all users having capabi... | [
{
"answer_id": 281632,
"author": "Mostafa Soufi",
"author_id": 106877,
"author_profile": "https://wordpress.stackexchange.com/users/106877",
"pm_score": -1,
"selected": false,
"text": "<p>Use <a href=\"https://codex.wordpress.org/Function_Reference/get_role\" rel=\"nofollow noreferrer\">... | 2017/10/02 | [
"https://wordpress.stackexchange.com/questions/281629",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/11999/"
] | I need to fetch the list of all users who are Authors (with Author capabilities)
get\_users allows to fetch users with roles, but if users are filter with author role, it skips users with role admin and editor (but they can also create posts).
So I need some other way to fetch all users having capability of Author R... | Basically, there are 3 roles who have a right to publish post - "Administrator", "Editor" & "Author", unless you are adding any custom roles.
So you can do is specify an array of these 3 in your get\_users function. Something like this:
```
get_users( array(
'role__in' => array('administrator', 'editor', ... |
281,644 | <p>Cant seem to return to the index page with the Previous link using <a href="https://developer.wordpress.org/reference/functions/paginate_links/" rel="nofollow noreferrer">paginate_links()</a>. Previous link is linking to paged 2.</p>
<pre><code>$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ... | [
{
"answer_id": 281659,
"author": "Kuliraj",
"author_id": 128600,
"author_profile": "https://wordpress.stackexchange.com/users/128600",
"pm_score": 0,
"selected": false,
"text": "<p>I think you are passing to the query what you have in the url when clicking on the previous link.</p>\n\n<p... | 2017/10/02 | [
"https://wordpress.stackexchange.com/questions/281644",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/124147/"
] | Cant seem to return to the index page with the Previous link using [paginate\_links()](https://developer.wordpress.org/reference/functions/paginate_links/). Previous link is linking to paged 2.
```
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$_args = array(
'orderby' => '... | You are using the code from the example in the Codex, but this is for the default "plain" permalinks for the default blog homepage. My guess is that you are doing this for an archive rather than the homepage.
**Search & Archive pages**
By default, `paginate_links` assumes the pagination is for the blog on the homepag... |
281,645 | <p>I am in a <code>category.php</code>, and I have to write the category name outside of the Loop. The category name needs to be pulled dynamically through PHP.</p>
<pre><code><p>You are browsing <?php get_the_category ?> articles.</p>
</code></pre>
<p>I tried the above one, but it didn't work. Wha... | [
{
"answer_id": 281647,
"author": "Stephen Elliott",
"author_id": 126081,
"author_profile": "https://wordpress.stackexchange.com/users/126081",
"pm_score": -1,
"selected": false,
"text": "<p>I have to admit that I am not fully understanding your question. Would you want to write a plugin... | 2017/10/02 | [
"https://wordpress.stackexchange.com/questions/281645",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/105791/"
] | I am in a `category.php`, and I have to write the category name outside of the Loop. The category name needs to be pulled dynamically through PHP.
```
<p>You are browsing <?php get_the_category ?> articles.</p>
```
I tried the above one, but it didn't work. Whats the fix? | You're looking for `single_cat_title()`. |
281,661 | <p>How to change home page to another page after login for all user roles, not a specific one?</p>
| [
{
"answer_id": 281663,
"author": "Marcelo Henriques Cortez",
"author_id": 44437,
"author_profile": "https://wordpress.stackexchange.com/users/44437",
"pm_score": 0,
"selected": false,
"text": "<p>You can use a plugin, like 'Redirect After Login' (<a href=\"https://wordpress.org/plugins/r... | 2017/10/02 | [
"https://wordpress.stackexchange.com/questions/281661",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/126694/"
] | How to change home page to another page after login for all user roles, not a specific one? | By adding this to your theme **functions.php** file:
```
function login_redirect( $redirect_to, $request, $user ){
return home_url('/');
}
add_filter( 'login_redirect', 'login_redirect', 10, 3 );
``` |
281,666 | <p><a href="https://peaceloveandbirth.com/" rel="nofollow noreferrer">https://peaceloveandbirth.com/</a><br>
Underneath the 'Birth preparation for Mind, Body & Soul' line at the top I want to remove the grey divider line (you can especially see it when the navbar is collapsed to say phone display).<br>
I already ha... | [
{
"answer_id": 281668,
"author": "Marcelo Henriques Cortez",
"author_id": 44437,
"author_profile": "https://wordpress.stackexchange.com/users/44437",
"pm_score": 0,
"selected": false,
"text": "<p><strong>About your main question:</strong></p>\n\n<p>You are targeting the wrong div. You ne... | 2017/10/02 | [
"https://wordpress.stackexchange.com/questions/281666",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128242/"
] | <https://peaceloveandbirth.com/>
Underneath the 'Birth preparation for Mind, Body & Soul' line at the top I want to remove the grey divider line (you can especially see it when the navbar is collapsed to say phone display).
I already have this is my CSS which works for below the header area, but not for this:
`... | You are looking at the wrong element, it is `#site-navigation` that has the box shadow (and a white background, which also is a problem), so the following worked for me
```
#site-navigation {
box-shadow: none;
background-color: #fdd4ce;
}
```
A vendor prefix [should not be necessary](http://shouldiprefix.com/#bo... |
281,699 | <p>I am trying to make a plugin that allows users to add a shortcode to their website. The problem that I am facing is that once the shortcode is placed in a page the shortcode is being run on both the page editor and on the front end, where I want it to only run on the front end. </p>
<p><a href="https://i.stack.imgu... | [
{
"answer_id": 281702,
"author": "Marcello B.",
"author_id": 100883,
"author_profile": "https://wordpress.stackexchange.com/users/100883",
"pm_score": 2,
"selected": false,
"text": "<p>Thanks to @mmm I figured it out. What I am doing now is adding the form in between php tags. </p>\n\n<p... | 2017/10/02 | [
"https://wordpress.stackexchange.com/questions/281699",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/100883/"
] | I am trying to make a plugin that allows users to add a shortcode to their website. The problem that I am facing is that once the shortcode is placed in a page the shortcode is being run on both the page editor and on the front end, where I want it to only run on the front end.
[ to return a JSON string. However, the REST server provides the WP hook [rest\_pre\_serve\_request](https://developer.wordpress.org/reference/hooks/rest_pre... |
281,746 | <p>i'd like to show the CPT description on the archive.php page but it'd like to do it dynamically for all CPT's. I mean without specifying the current type myself. Something like the_archive_description but for CPT.</p>
| [
{
"answer_id": 281759,
"author": "Kuliraj",
"author_id": 128600,
"author_profile": "https://wordpress.stackexchange.com/users/128600",
"pm_score": 1,
"selected": false,
"text": "<pre><code>function get_the_post_type_description() {\n $post_type = get_query_var( 'post_type' );\n\n i... | 2017/10/03 | [
"https://wordpress.stackexchange.com/questions/281746",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/77283/"
] | i'd like to show the CPT description on the archive.php page but it'd like to do it dynamically for all CPT's. I mean without specifying the current type myself. Something like the\_archive\_description but for CPT. | Since 4.9.
```
if ( get_the_post_type_description()) {
echo get_the_post_type_description();
}
```
redeclaring the function will crash WordPress. |
281,760 | <p>I've followed <a href="https://dobsondev.com/2015/01/23/using-the-wordpress-media-uploader/" rel="nofollow noreferrer">this article</a> to use Media Uploader in my code. When I click the Browse button on my form, the media uploader opens and after selecting the image, I get the URL of that image added in my form fie... | [
{
"answer_id": 302962,
"author": "Darren",
"author_id": 143188,
"author_profile": "https://wordpress.stackexchange.com/users/143188",
"pm_score": 2,
"selected": false,
"text": "<p>It looks like the select and crop functionality is currently only used in the WordPress Customizer. </p>\n\n... | 2017/10/03 | [
"https://wordpress.stackexchange.com/questions/281760",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/119672/"
] | I've followed [this article](https://dobsondev.com/2015/01/23/using-the-wordpress-media-uploader/) to use Media Uploader in my code. When I click the Browse button on my form, the media uploader opens and after selecting the image, I get the URL of that image added in my form field. No issues so far.
But I want to enf... | First use the code given by @Darren on any page. For simplicity I've combined PHP and JS code in single block:
```
<?php $heading_picture = esc_attr(get_option( 'heading_picture' )); ?>
<input type="hidden" name="heading_picture" id="heading_picture" value="<?php echo $heading_picture; ?>" />
<img id="heading_pi... |
281,761 | <p>I want to disable the 'Add to cart' button when product is out of stock with PHP code or a WooCommerce admin setting.</p>
| [
{
"answer_id": 281763,
"author": "Sunil Dora",
"author_id": 128944,
"author_profile": "https://wordpress.stackexchange.com/users/128944",
"pm_score": 2,
"selected": false,
"text": "<p>Here are some plugins which provide the facilities to hide \"Add To Cart\" buttons from the shop and sin... | 2017/10/03 | [
"https://wordpress.stackexchange.com/questions/281761",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128942/"
] | I want to disable the 'Add to cart' button when product is out of stock with PHP code or a WooCommerce admin setting. | Here are some plugins which provide the facilities to hide "Add To Cart" buttons from the shop and single product page in woocommerce,
[ <https://wordpress.org/plugins/hide-add-to-cart-button/>) ]
[ <https://wordpress.org/plugins/remove-add-to-cart-woocommerce/> ]
These plugins will do,
1) Hide Add to Cart button f... |
281,775 | <p>I'm looking for a solution to dynamically create different templates for each category level.</p>
<p>Category</p>
<p>--Category</p>
<p>---Category</p>
<p>----Category</p>
<p>I thought of something to get the taxonomy current level ID, to use a function like below, but I did not find a solution.</p>
<p>I have n... | [
{
"answer_id": 281763,
"author": "Sunil Dora",
"author_id": 128944,
"author_profile": "https://wordpress.stackexchange.com/users/128944",
"pm_score": 2,
"selected": false,
"text": "<p>Here are some plugins which provide the facilities to hide \"Add To Cart\" buttons from the shop and sin... | 2017/10/03 | [
"https://wordpress.stackexchange.com/questions/281775",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128952/"
] | I'm looking for a solution to dynamically create different templates for each category level.
Category
--Category
---Category
----Category
I thought of something to get the taxonomy current level ID, to use a function like below, but I did not find a solution.
I have not found anything that returns me level or a ... | Here are some plugins which provide the facilities to hide "Add To Cart" buttons from the shop and single product page in woocommerce,
[ <https://wordpress.org/plugins/hide-add-to-cart-button/>) ]
[ <https://wordpress.org/plugins/remove-add-to-cart-woocommerce/> ]
These plugins will do,
1) Hide Add to Cart button f... |
281,778 | <p>Since 2017-09-26 I have terrible problems with performance on my website.</p>
<p>Loading single post or any other page takes even 20s.
I've been debugging it it found out, that the problems are DB queries.</p>
<p>For example this one is executing almost with every page load and takes about 36s:</p>
<pre><code>SEL... | [
{
"answer_id": 281763,
"author": "Sunil Dora",
"author_id": 128944,
"author_profile": "https://wordpress.stackexchange.com/users/128944",
"pm_score": 2,
"selected": false,
"text": "<p>Here are some plugins which provide the facilities to hide \"Add To Cart\" buttons from the shop and sin... | 2017/10/03 | [
"https://wordpress.stackexchange.com/questions/281778",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128953/"
] | Since 2017-09-26 I have terrible problems with performance on my website.
Loading single post or any other page takes even 20s.
I've been debugging it it found out, that the problems are DB queries.
For example this one is executing almost with every page load and takes about 36s:
```
SELECT t.*, tt.*, tr.object_id
... | Here are some plugins which provide the facilities to hide "Add To Cart" buttons from the shop and single product page in woocommerce,
[ <https://wordpress.org/plugins/hide-add-to-cart-button/>) ]
[ <https://wordpress.org/plugins/remove-add-to-cart-woocommerce/> ]
These plugins will do,
1) Hide Add to Cart button f... |
281,779 | <p>I am using Theme My Login plugin to change the login page from "/wp-login.php" to "/login".</p>
<p>My question is how do I redirect a user that has already logged in so that visiting "/login" instead takes them to my homepage?</p>
<p>Note: I am not talking about the initial redirect after logging in, but rather if... | [
{
"answer_id": 281780,
"author": "Temani Afif",
"author_id": 128913,
"author_profile": "https://wordpress.stackexchange.com/users/128913",
"pm_score": 1,
"selected": false,
"text": "<p>I advice you to try this, better to the action <strong>login_init</strong>:</p>\n\n<pre><code>add_actio... | 2017/10/03 | [
"https://wordpress.stackexchange.com/questions/281779",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128955/"
] | I am using Theme My Login plugin to change the login page from "/wp-login.php" to "/login".
My question is how do I redirect a user that has already logged in so that visiting "/login" instead takes them to my homepage?
Note: I am not talking about the initial redirect after logging in, but rather if someone was to v... | I advice you to try this, better to the action **login\_init**:
```
add_action('login_init', 'redirect_logged_in_user');
function redirect_logged_in_user()
{
global $action;
/* if the user call logout and is not logged in we do nothing*/
if ('logout' === $action || !is_user_logged_in()) {
return;
... |
281,861 | <p>I am trying to display WooCommerce product tags on the home page and category pages. Along with the product title the theme should display any tags in alphabetical order, separated by a “·”.</p>
<p>For example: Tag 1 · Tag 2 · Tag 3</p>
<p>This is what I have at the moment:</p>
<pre><code><?php echo get_the_ta... | [
{
"answer_id": 281866,
"author": "LWS-Mo",
"author_id": 88895,
"author_profile": "https://wordpress.stackexchange.com/users/88895",
"pm_score": 1,
"selected": true,
"text": "<p>I think <code>get_the_tag_list</code> is only used for the default WordPress tags. WooCommerce product tags are... | 2017/10/04 | [
"https://wordpress.stackexchange.com/questions/281861",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97267/"
] | I am trying to display WooCommerce product tags on the home page and category pages. Along with the product title the theme should display any tags in alphabetical order, separated by a “·”.
For example: Tag 1 · Tag 2 · Tag 3
This is what I have at the moment:
```
<?php echo get_the_tag_list('<span class="woocommerc... | I think `get_the_tag_list` is only used for the default WordPress tags. WooCommerce product tags are a custom taxonomy called `product_tag`. Therefore you cannot use this function to return these tags. (anyone please correct me if I am wrong here)
Instead you could use the WordPress `get_the_terms()` function, to get... |
281,916 | <p>Using WP 4.8.2</p>
<p>What is the best way to check the requesting URL when processing a request with the rest-api? </p>
<p>For example, a site receives a request and you want to check if it came from an 'allowed' URL. And fail if the URL is not allowed. </p>
<p>This does not work: </p>
<pre><code>function my_... | [
{
"answer_id": 282180,
"author": "ssnepenthe",
"author_id": 125601,
"author_profile": "https://wordpress.stackexchange.com/users/125601",
"pm_score": 4,
"selected": true,
"text": "<p>That filter is definitely not the one you are looking for. That filter fires before returning the result ... | 2017/10/04 | [
"https://wordpress.stackexchange.com/questions/281916",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16575/"
] | Using WP 4.8.2
What is the best way to check the requesting URL when processing a request with the rest-api?
For example, a site receives a request and you want to check if it came from an 'allowed' URL. And fail if the URL is not allowed.
This does not work:
```
function my_check_request_url( $request, $url ) {... | That filter is definitely not the one you are looking for. That filter fires before returning the result of `WP_REST_Request::from_url()` which appears to be a factory method that is only used internally to handle embeds.
A better option is to return a `WP_Error` instance on the [`rest_pre_dispatch` filter](https://de... |
281,939 | <p>Forgive my ignorance in the matter, as i've only just started delving into wordpress. But, i was wondering if theres a way to use <code>header_image()</code> in CSS.</p>
<p>So, for example my <code>functions.php</code> is allowing me to enqueue a php file with the header: </p>
<p><code><?php header("Content-typ... | [
{
"answer_id": 281941,
"author": "Pierpaolo Ercoli",
"author_id": 120008,
"author_profile": "https://wordpress.stackexchange.com/users/120008",
"pm_score": 3,
"selected": true,
"text": "<p>No, in general, it's not possible to use php in CSS. But you can set background image in php file. ... | 2017/10/05 | [
"https://wordpress.stackexchange.com/questions/281939",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129062/"
] | Forgive my ignorance in the matter, as i've only just started delving into wordpress. But, i was wondering if theres a way to use `header_image()` in CSS.
So, for example my `functions.php` is allowing me to enqueue a php file with the header:
`<?php header("Content-type: text/css; charset: UTF-8;"); ?>`
Allowing m... | No, in general, it's not possible to use php in CSS. But you can set background image in php file. Like..
```
<div class="headerimg" style="background-image: url(<?php echo header_image(); ?>)"></div>
```
Then in CSS file using class you can set all the other properties you need like height, width, background-positi... |
281,958 | <p>How to add a custom field to my post when created programmatically?</p>
<p>I am trying to create a post programmatically, and store a value in a column created directly from PhpMyAdmin.</p>
<p><a href="https://i.stack.imgur.com/CTjyu.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CTjyu.jpg" alt... | [
{
"answer_id": 281961,
"author": "cybmeta",
"author_id": 37428,
"author_profile": "https://wordpress.stackexchange.com/users/37428",
"pm_score": 2,
"selected": false,
"text": "<p>You have created a custom field by altering the post table in the database. Custom fields in WordPress API ar... | 2017/10/05 | [
"https://wordpress.stackexchange.com/questions/281958",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129073/"
] | How to add a custom field to my post when created programmatically?
I am trying to create a post programmatically, and store a value in a column created directly from PhpMyAdmin.
[](https://i.stack.imgur.com/CTjyu.jpg)
Here is how I am creating the ... | You have created a custom field by altering the post table in the database. Custom fields in WordPress API are considered meta fields; such fields are stored in `wp_postmeta` table and that is the table used by functions like `add_post_meta()` and the rest of the functions and methods related with post custom/meta fiel... |
281,981 | <p>I want to display all the posts separated by years. Like that.</p>
<p><strong>2017</strong></p>
<ul>
<li>Post 1 / december 17</li>
<li>Post 2 / July 7</li>
<li>Post 3 / March 25</li>
</ul>
<p><strong>2016</strong></p>
<ul>
<li>Post 1 / december 25</li>
<li>Post 2 / July 14</li>
<li>Post 3 / March 31</li>
</ul>
... | [
{
"answer_id": 281961,
"author": "cybmeta",
"author_id": 37428,
"author_profile": "https://wordpress.stackexchange.com/users/37428",
"pm_score": 2,
"selected": false,
"text": "<p>You have created a custom field by altering the post table in the database. Custom fields in WordPress API ar... | 2017/10/05 | [
"https://wordpress.stackexchange.com/questions/281981",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129080/"
] | I want to display all the posts separated by years. Like that.
**2017**
* Post 1 / december 17
* Post 2 / July 7
* Post 3 / March 25
**2016**
* Post 1 / december 25
* Post 2 / July 14
* Post 3 / March 31
The code I actually have is totally different of what i want, because after try a lot of posibilities doesnt wo... | You have created a custom field by altering the post table in the database. Custom fields in WordPress API are considered meta fields; such fields are stored in `wp_postmeta` table and that is the table used by functions like `add_post_meta()` and the rest of the functions and methods related with post custom/meta fiel... |
281,987 | <p>I am trying to add a menu item programmatically through a plugin to a menu based on location and i want this to be added to the location that is attached to the homepage's menu.</p>
<p>This is my code:</p>
<pre><code>//Add user menu item
add_filter( 'wp_nav_menu_items', 'add_user_link', 10, 2);
/**
* Add a login ... | [
{
"answer_id": 282011,
"author": "David Lee",
"author_id": 111965,
"author_profile": "https://wordpress.stackexchange.com/users/111965",
"pm_score": 2,
"selected": true,
"text": "<p>You can use <code>get_nav_menu_locations()</code> to get an array of locations that are being used (a menu... | 2017/10/05 | [
"https://wordpress.stackexchange.com/questions/281987",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/102224/"
] | I am trying to add a menu item programmatically through a plugin to a menu based on location and i want this to be added to the location that is attached to the homepage's menu.
This is my code:
```
//Add user menu item
add_filter( 'wp_nav_menu_items', 'add_user_link', 10, 2);
/**
* Add a login link to the members n... | You can use `get_nav_menu_locations()` to get an array of locations that are being used (a menu has been assigned to it), it shows like this:
```
Array
(
[header-menu] => 4
[extra-menu] => 6
)
```
the `4` and `6` are the menu IDs, i think you already have an ID so this should be enough, now the thing is, if ... |
282,022 | <p>I wish someone can give me a clue.</p>
<p>I am actually displaying all product category (product_cat taxonomy) on single page products, displaying also childs regarding the product itself. </p>
<p>For instance: Product-A has Cat1-parent > Cat1-child1, Cat1-child2 => The code display them properly but also will dis... | [
{
"answer_id": 282025,
"author": "socki03",
"author_id": 43511,
"author_profile": "https://wordpress.stackexchange.com/users/43511",
"pm_score": 3,
"selected": true,
"text": "<p><a href=\"https://developer.wordpress.org/reference/functions/get_terms/\" rel=\"nofollow noreferrer\"><code>g... | 2017/10/05 | [
"https://wordpress.stackexchange.com/questions/282022",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129102/"
] | I wish someone can give me a clue.
I am actually displaying all product category (product\_cat taxonomy) on single page products, displaying also childs regarding the product itself.
For instance: Product-A has Cat1-parent > Cat1-child1, Cat1-child2 => The code display them properly but also will display any other P... | [`get_terms`](https://developer.wordpress.org/reference/functions/get_terms/) relates to getting all the terms of a taxonomy. [`get_the_terms`](https://developer.wordpress.org/reference/functions/get_the_terms/) grabs all the terms related to the post.
The problem is that it sounds like you only want to return those t... |
282,026 | <p>I have a front end user profile template I am working on, and everything is working fine except for upload a profile picture. I have a custom user field created and I am trying to use the button file type to upload the picture and store the URL in my custom field. </p>
<p>Take a look -
<a href="https://pastebin.com... | [
{
"answer_id": 282392,
"author": "lukgoh",
"author_id": 128475,
"author_profile": "https://wordpress.stackexchange.com/users/128475",
"pm_score": 0,
"selected": false,
"text": "<pre><code>if ( !empty( $_FILES[agent-image][name] ) ) {\n\n $file = $_FILES[agent-image];\n\n ... | 2017/10/05 | [
"https://wordpress.stackexchange.com/questions/282026",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24067/"
] | I have a front end user profile template I am working on, and everything is working fine except for upload a profile picture. I have a custom user field created and I am trying to use the button file type to upload the picture and store the URL in my custom field.
Take a look -
<https://pastebin.com/rPErwCgU>
I'm cu... | UPDATE: As mentioned in the comments, you might want to learn how you do things like create meta boxes and do a file upload in Wordpress without using a framework like CMB2 first. However, as a seasoned Wordpress developer, I have found that using CMB2 greatly increased my productivity.
I highly recommend using [CMB2... |
282,036 | <p>I'm trying to setup a fallback image for featured image.<br><br>
The main problem I have is miss of filter for <code>get_the_post_thumbnail_url()</code>. I'm using this function to echo thumb url in many-many templates, because it is easy customizable. So, this is not a solution to make an if-condition for each usag... | [
{
"answer_id": 282392,
"author": "lukgoh",
"author_id": 128475,
"author_profile": "https://wordpress.stackexchange.com/users/128475",
"pm_score": 0,
"selected": false,
"text": "<pre><code>if ( !empty( $_FILES[agent-image][name] ) ) {\n\n $file = $_FILES[agent-image];\n\n ... | 2017/10/05 | [
"https://wordpress.stackexchange.com/questions/282036",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/28575/"
] | I'm trying to setup a fallback image for featured image.
The main problem I have is miss of filter for `get_the_post_thumbnail_url()`. I'm using this function to echo thumb url in many-many templates, because it is easy customizable. So, this is not a solution to make an if-condition for each usage. And even to set ... | UPDATE: As mentioned in the comments, you might want to learn how you do things like create meta boxes and do a file upload in Wordpress without using a framework like CMB2 first. However, as a seasoned Wordpress developer, I have found that using CMB2 greatly increased my productivity.
I highly recommend using [CMB2... |
282,065 | <p>Our small company is making a website using Wordpress free version. We had used wordpress in the past and would like to continue using it but our subdomain reads www.(ourname)blog.wordpress.com. Our website is not a blog and it would look bit more professional if the blog part is removed. Is there a way to get rid o... | [
{
"answer_id": 282392,
"author": "lukgoh",
"author_id": 128475,
"author_profile": "https://wordpress.stackexchange.com/users/128475",
"pm_score": 0,
"selected": false,
"text": "<pre><code>if ( !empty( $_FILES[agent-image][name] ) ) {\n\n $file = $_FILES[agent-image];\n\n ... | 2017/10/06 | [
"https://wordpress.stackexchange.com/questions/282065",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129141/"
] | Our small company is making a website using Wordpress free version. We had used wordpress in the past and would like to continue using it but our subdomain reads www.(ourname)blog.wordpress.com. Our website is not a blog and it would look bit more professional if the blog part is removed. Is there a way to get rid of i... | UPDATE: As mentioned in the comments, you might want to learn how you do things like create meta boxes and do a file upload in Wordpress without using a framework like CMB2 first. However, as a seasoned Wordpress developer, I have found that using CMB2 greatly increased my productivity.
I highly recommend using [CMB2... |
282,078 | <p>Our clients would like to schedule changes made to a given <strong>page</strong> (for instance by displaying the link to register to an event).</p>
<p>Typically, the same page (/registration) should display (before the registration opening):
"The registrations will be open by ..."</p>
<p>Once the time comes, the s... | [
{
"answer_id": 282079,
"author": "mmm",
"author_id": 74311,
"author_profile": "https://wordpress.stackexchange.com/users/74311",
"pm_score": 1,
"selected": false,
"text": "<p>you can do this with a shortcode like this</p>\n\n<pre><code>add_shortcode(\"custom_text_se282078\", function ($a... | 2017/10/06 | [
"https://wordpress.stackexchange.com/questions/282078",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/126698/"
] | Our clients would like to schedule changes made to a given **page** (for instance by displaying the link to register to an event).
Typically, the same page (/registration) should display (before the registration opening):
"The registrations will be open by ..."
Once the time comes, the same page should display:
"Regi... | you can do this with a shortcode like this
```
add_shortcode("custom_text_se282078", function ($attr, $content, $tag) {
$result = "";
if (date_i18n("H") > $attr["time"]) {
$result = $attr["text_after"];
} else {
$result = $attr["text_before"];
}
return $result;
});
```
with th... |
282,086 | <p>I have made custom taxonomies that I am using for few different post types:</p>
<pre><code><?php
add_action('init', function() {
register_post_type('intranet-categories', [
'labels' => [
'name' => 'Kategorier',
'singular_name' => 'Kategorier',... | [
{
"answer_id": 282087,
"author": "Randomer11",
"author_id": 62291,
"author_profile": "https://wordpress.stackexchange.com/users/62291",
"pm_score": 0,
"selected": false,
"text": "<p>You could use a plugin such as : <a href=\"https://en-gb.wordpress.org/plugins/admin-menu-editor/\" rel=\"... | 2017/10/06 | [
"https://wordpress.stackexchange.com/questions/282086",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/115898/"
] | I have made custom taxonomies that I am using for few different post types:
```
<?php
add_action('init', function() {
register_post_type('intranet-categories', [
'labels' => [
'name' => 'Kategorier',
'singular_name' => 'Kategorier',
'menu_name' ... | Referencing register\_taxonomy()
<https://codex.wordpress.org/Function_Reference/register_taxonomy>
**show\_in\_menu**
Where to show the taxonomy in the admin menu. show\_ui must be true.
Default: value of show\_ui argument
* 'false' - do not display in the admin menu
* 'true' - show as a submenu of associated obj... |
282,104 | <p>Are there any dependencies on which shortcode depends?</p>
<p><code>[news_weber][/news_weber]</code> → Didn't work, but when used with <code>do_shortcode</code> method it worked.</p>
<p>I installed <a href="https://downloads.wordpress.org/plugin/shortcodes-ultimate.latest-stable.zip" rel="nofollow noreferrer">Ulti... | [
{
"answer_id": 282123,
"author": "Patrice Poliquin",
"author_id": 32365,
"author_profile": "https://wordpress.stackexchange.com/users/32365",
"pm_score": 0,
"selected": false,
"text": "<p>Based on your question and my understanding of your question, you have to make sure that your shortc... | 2017/10/06 | [
"https://wordpress.stackexchange.com/questions/282104",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/105791/"
] | Are there any dependencies on which shortcode depends?
`[news_weber][/news_weber]` → Didn't work, but when used with `do_shortcode` method it worked.
I installed [Ultimate shortcode plugin](https://downloads.wordpress.org/plugin/shortcodes-ultimate.latest-stable.zip) to check whether that works or not. all the shortc... | Problem 1
---------
It doesn't work because you're using `new_weber` but you're registering `news_burner`, and they aren't the same
So instead use:
`[news_burner]`
You only need a closing shortcode if it's containing content which that plugin does not.
Problem 2
---------
Shortcodes don't work in text widgets out... |
282,133 | <p>Is there a way or a plugin to set a featured image from the first image's url (or tag) posted in the article?</p>
| [
{
"answer_id": 282197,
"author": "Maqk",
"author_id": 86885,
"author_profile": "https://wordpress.stackexchange.com/users/86885",
"pm_score": 0,
"selected": false,
"text": "<p>You can display the first image from your post content as a but can't set that as a featured image, but you can ... | 2017/10/06 | [
"https://wordpress.stackexchange.com/questions/282133",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129190/"
] | Is there a way or a plugin to set a featured image from the first image's url (or tag) posted in the article? | You can display the first image from your post content as a but can't set that as a featured image, but you can display it.
Create a function to find the first tag from the post content starting with `<img>` element using regex and echo the image where you wish to display the first image. In the below function we use ... |
282,142 | <p>I use insert_with_markers in a couple of my plugins to add some small bits of code to the htaccess file. What I'm unclear about is how to remove the code and markers.</p>
<p>For example, if I call the function like this:-</p>
<pre><code>insert_with_markers($htaccess, "marker","RewriteBase /foobar");
</code></pre>
... | [
{
"answer_id": 282197,
"author": "Maqk",
"author_id": 86885,
"author_profile": "https://wordpress.stackexchange.com/users/86885",
"pm_score": 0,
"selected": false,
"text": "<p>You can display the first image from your post content as a but can't set that as a featured image, but you can ... | 2017/10/06 | [
"https://wordpress.stackexchange.com/questions/282142",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/87826/"
] | I use insert\_with\_markers in a couple of my plugins to add some small bits of code to the htaccess file. What I'm unclear about is how to remove the code and markers.
For example, if I call the function like this:-
```
insert_with_markers($htaccess, "marker","RewriteBase /foobar");
```
The result in htaccess is:-... | You can display the first image from your post content as a but can't set that as a featured image, but you can display it.
Create a function to find the first tag from the post content starting with `<img>` element using regex and echo the image where you wish to display the first image. In the below function we use ... |
282,149 | <p>My code is like that </p>
<pre><code>$wp_customize->add_setting(
'scroll_logo',
array(
'default' => '',
'capability' => 'edit_theme_options',
'sanitize_callback' => 'esc_attr',
)
);
$wp_customize->add_control( new WP_Customize_Cropped_Image_Control... | [
{
"answer_id": 282420,
"author": "Weston Ruter",
"author_id": 8521,
"author_profile": "https://wordpress.stackexchange.com/users/8521",
"pm_score": 2,
"selected": false,
"text": "<p>It's always a good idea to sanitize values being accepted from the user. A <code>WP_Customize_Cropped_Imag... | 2017/10/07 | [
"https://wordpress.stackexchange.com/questions/282149",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129203/"
] | My code is like that
```
$wp_customize->add_setting(
'scroll_logo',
array(
'default' => '',
'capability' => 'edit_theme_options',
'sanitize_callback' => 'esc_attr',
)
);
$wp_customize->add_control( new WP_Customize_Cropped_Image_Control( $wp_customize, 'scroll_logo... | It's always a good idea to sanitize values being accepted from the user. A `WP_Customize_Cropped_Image_Control` will populate its associated setting with an attachment ID. Thus you could use `absint` as the sanitizing function.
Remember that `esc_attr` is an escaping function and should only be used when printing out... |
282,160 | <p>I am using Polylang. It is not obvious to me how the relationship between posts are established. I can switch between different language versions of the same post, and I can tell that they're (obviously) different posts in the database.
But I can see how Polylang establishes and maintains that relationship. I assum... | [
{
"answer_id": 282185,
"author": "mmm",
"author_id": 74311,
"author_profile": "https://wordpress.stackexchange.com/users/74311",
"pm_score": 3,
"selected": true,
"text": "<p>polylang stores translation in a taxinomy but it's better to access them with the polylang object like that : </p>... | 2017/10/07 | [
"https://wordpress.stackexchange.com/questions/282160",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3986/"
] | I am using Polylang. It is not obvious to me how the relationship between posts are established. I can switch between different language versions of the same post, and I can tell that they're (obviously) different posts in the database.
But I can see how Polylang establishes and maintains that relationship. I assumed ... | polylang stores translation in a taxinomy but it's better to access them with the polylang object like that :
```
// test if the plugin polylang is present
if (isset($GLOBALS["polylang"])) {
$translations = $GLOBALS["polylang"]->model->post->get_translations($post->ID);
// $translations contains an array wi... |
282,162 | <p>I have been developing the shortcodes for which am pulling the terms of custom taxonomies from a plugin. It was working fine prior to WordPress 4.5.0 and now realized it is not working after 4.5.0.</p>
<p>I am pulling those terms in an old method like below.</p>
<p><strong>Old Method</strong></p>
<pre><code>// Se... | [
{
"answer_id": 282164,
"author": "janh",
"author_id": 129206,
"author_profile": "https://wordpress.stackexchange.com/users/129206",
"pm_score": 1,
"selected": false,
"text": "<p>OK, wild guess:</p>\n\n<pre><code>$prefix_topic_terms= array();\nif ( ! empty( $iva_topic_terms ) ) {\n</code>... | 2017/10/07 | [
"https://wordpress.stackexchange.com/questions/282162",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/86885/"
] | I have been developing the shortcodes for which am pulling the terms of custom taxonomies from a plugin. It was working fine prior to WordPress 4.5.0 and now realized it is not working after 4.5.0.
I am pulling those terms in an old method like below.
**Old Method**
```
// Sermon Topics
$prefix_topic_terms= array();... | Got it fixed as I was checking the variables which are empty and defined as an array. Now converted the code into a function. Hope this is helpful for others
Earlier the condition was wrong. Now I am checking whether the passed variable is a WordPress Error with [is\_wp\_error](https://codex.wordpress.org/Function_Ref... |
282,163 | <p>I have a quick question. Did anyone managed to use Axios inside WordPress to do AJAX requests (wp_ajax with action - calling a function) not REST API and how did you do it?</p>
<p>It seems that Axios is sending a JSON and whenever I try the request I get a 0. However, using jQuery AJAX it works fine.</p>
| [
{
"answer_id": 282557,
"author": "Karthik Thayyil",
"author_id": 129405,
"author_profile": "https://wordpress.stackexchange.com/users/129405",
"pm_score": 3,
"selected": false,
"text": "<p>You need to send your data in application/x-www-form-urlencoded format.</p>\n\n<p>As axios sends js... | 2017/10/07 | [
"https://wordpress.stackexchange.com/questions/282163",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129209/"
] | I have a quick question. Did anyone managed to use Axios inside WordPress to do AJAX requests (wp\_ajax with action - calling a function) not REST API and how did you do it?
It seems that Axios is sending a JSON and whenever I try the request I get a 0. However, using jQuery AJAX it works fine. | you can use FormData
an example:
```
let form_data = new FormData;
form_data.append('action', 'myAction');
form_data.append('first_name', 'my first name');
form_data.append('phone', 'my phone');
axios.post(myVars.ajax_url, form_data).then(function(response){
console.log(response.data);
})
``` |
282,171 | <p>I have created a plugin that registers a custom post type. I would like to load a custom header and footer for the custom post type from the plugin.</p>
<p>After some google research I can see that it's not possible to use get_header() to load and so I have tried using:</p>
<pre><code><?php get_template_part('h... | [
{
"answer_id": 282172,
"author": "janh",
"author_id": 129206,
"author_profile": "https://wordpress.stackexchange.com/users/129206",
"pm_score": 1,
"selected": false,
"text": "<p>I don't believe you can change the loaded file for get_header/get_footer to something outside the stylesheet/t... | 2017/10/07 | [
"https://wordpress.stackexchange.com/questions/282171",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128475/"
] | I have created a plugin that registers a custom post type. I would like to load a custom header and footer for the custom post type from the plugin.
After some google research I can see that it's not possible to use get\_header() to load and so I have tried using:
```
<?php get_template_part('header', 'trademanager')... | Old question, but maybe my answer will help someone.
---
Short answer is:
use `load_template()` function with full file server path as first argument passed to it.
---
Long answer:
`get_header()` using the function `locate_template()` which uses the function `load_template()` which uses the function `require_once... |
282,214 | <p>I have different content on static pages and post in my WP site. On pages is not desirable to view meta in search result, but in my post is important.
Meta, I mean information about author, and date in search result.</p>
<p>I have created custom post-search.php. But i dont know, how to show meta information only fo... | [
{
"answer_id": 282172,
"author": "janh",
"author_id": 129206,
"author_profile": "https://wordpress.stackexchange.com/users/129206",
"pm_score": 1,
"selected": false,
"text": "<p>I don't believe you can change the loaded file for get_header/get_footer to something outside the stylesheet/t... | 2017/10/08 | [
"https://wordpress.stackexchange.com/questions/282214",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129235/"
] | I have different content on static pages and post in my WP site. On pages is not desirable to view meta in search result, but in my post is important.
Meta, I mean information about author, and date in search result.
I have created custom post-search.php. But i dont know, how to show meta information only for post in ... | Old question, but maybe my answer will help someone.
---
Short answer is:
use `load_template()` function with full file server path as first argument passed to it.
---
Long answer:
`get_header()` using the function `locate_template()` which uses the function `load_template()` which uses the function `require_once... |
282,220 | <p>by default I use the <code>author.php</code> template and it's working fine but I need to make a parent page for <code>author.php</code> like facebook and other social sites.</p>
<p>I want to do something like this:</p>
<pre><code>site.com/author/trello/settings
site.com/author/trello/personalinformation
</code><... | [
{
"answer_id": 282172,
"author": "janh",
"author_id": 129206,
"author_profile": "https://wordpress.stackexchange.com/users/129206",
"pm_score": 1,
"selected": false,
"text": "<p>I don't believe you can change the loaded file for get_header/get_footer to something outside the stylesheet/t... | 2017/10/08 | [
"https://wordpress.stackexchange.com/questions/282220",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/125375/"
] | by default I use the `author.php` template and it's working fine but I need to make a parent page for `author.php` like facebook and other social sites.
I want to do something like this:
```
site.com/author/trello/settings
site.com/author/trello/personalinformation
``` | Old question, but maybe my answer will help someone.
---
Short answer is:
use `load_template()` function with full file server path as first argument passed to it.
---
Long answer:
`get_header()` using the function `locate_template()` which uses the function `load_template()` which uses the function `require_once... |
282,253 | <p>I have a custom post type registered: 'jobs'</p>
<pre><code>// set up labels
$labels = array(
'name' => 'Jobs',
'singular_name' => 'Job',
'add_new' => 'Add New Job',
'add_new_item' => 'Add New Job',
'edit_item' =>... | [
{
"answer_id": 282256,
"author": "fatihsolhan",
"author_id": 119138,
"author_profile": "https://wordpress.stackexchange.com/users/119138",
"pm_score": 1,
"selected": false,
"text": "<p>Open <strong>Settings > Permalinks</strong> and just click on the Save Settings button without any chan... | 2017/10/08 | [
"https://wordpress.stackexchange.com/questions/282253",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128475/"
] | I have a custom post type registered: 'jobs'
```
// set up labels
$labels = array(
'name' => 'Jobs',
'singular_name' => 'Job',
'add_new' => 'Add New Job',
'add_new_item' => 'Add New Job',
'edit_item' => 'Edit Job',
'new_it... | Open **Settings > Permalinks** and just click on the Save Settings button without any changes. |
282,267 | <p>I am a Laravel developer that is learning WordPress. I have written some PHP code which displays some tables and some HTML and some get forms. At the minute I require the file on the index page in order to display it. I want to change that and only add a menu on the index page with links to my created files. Now I w... | [
{
"answer_id": 282273,
"author": "CK MacLeod",
"author_id": 35923,
"author_profile": "https://wordpress.stackexchange.com/users/35923",
"pm_score": 1,
"selected": false,
"text": "<p>Agree with the comments, but still might as well provide an answer for someone coming from a place of some... | 2017/10/08 | [
"https://wordpress.stackexchange.com/questions/282267",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/125481/"
] | I am a Laravel developer that is learning WordPress. I have written some PHP code which displays some tables and some HTML and some get forms. At the minute I require the file on the index page in order to display it. I want to change that and only add a menu on the index page with links to my created files. Now I want... | If you're coming from a Laravel background, you're going to hate Wordpress routing.
For our high-functioning Wordpress websites, I had to write a whole bunch of routing workarounds to Laravel-ise routes, and it's definitely not "The Wordpress Way."
There's no neat Wordpress way to add routes in code. Your best bet ... |
282,268 | <p>I am trying to install a second WP site on an Ubuntu 16 server running Nginx. I have successfully installed WordPress according to my server results, but I still only get the Nginx home page. I thought it might be the fact that the Group Owner was the User, so I changed group owner on web files to www-data:</p>
<pr... | [
{
"answer_id": 282273,
"author": "CK MacLeod",
"author_id": 35923,
"author_profile": "https://wordpress.stackexchange.com/users/35923",
"pm_score": 1,
"selected": false,
"text": "<p>Agree with the comments, but still might as well provide an answer for someone coming from a place of some... | 2017/10/08 | [
"https://wordpress.stackexchange.com/questions/282268",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109760/"
] | I am trying to install a second WP site on an Ubuntu 16 server running Nginx. I have successfully installed WordPress according to my server results, but I still only get the Nginx home page. I thought it might be the fact that the Group Owner was the User, so I changed group owner on web files to www-data:
```
microu... | If you're coming from a Laravel background, you're going to hate Wordpress routing.
For our high-functioning Wordpress websites, I had to write a whole bunch of routing workarounds to Laravel-ise routes, and it's definitely not "The Wordpress Way."
There's no neat Wordpress way to add routes in code. Your best bet ... |
282,270 | <p>When I filter media library to display only the images I want to include in a gallery (by a shortcode needing images id), it would be very useful if Wordpress showed somewhere a list of the ids of the displayed images. Currently I open images one by one to retrieve their id, and I feel this should not be the right w... | [
{
"answer_id": 282273,
"author": "CK MacLeod",
"author_id": 35923,
"author_profile": "https://wordpress.stackexchange.com/users/35923",
"pm_score": 1,
"selected": false,
"text": "<p>Agree with the comments, but still might as well provide an answer for someone coming from a place of some... | 2017/10/08 | [
"https://wordpress.stackexchange.com/questions/282270",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/113609/"
] | When I filter media library to display only the images I want to include in a gallery (by a shortcode needing images id), it would be very useful if Wordpress showed somewhere a list of the ids of the displayed images. Currently I open images one by one to retrieve their id, and I feel this should not be the right way ... | If you're coming from a Laravel background, you're going to hate Wordpress routing.
For our high-functioning Wordpress websites, I had to write a whole bunch of routing workarounds to Laravel-ise routes, and it's definitely not "The Wordpress Way."
There's no neat Wordpress way to add routes in code. Your best bet ... |
282,282 | <p>I added shortcodes to the theme I'm using, but when I try to use them in a page, it gives me a blank page. I have seen a solution to this problem saying to use <code>remove_filter("the_content", "wpautop");</code> but I'm not sure that this will work. If it will, please let me know, and please let me know where to p... | [
{
"answer_id": 282273,
"author": "CK MacLeod",
"author_id": 35923,
"author_profile": "https://wordpress.stackexchange.com/users/35923",
"pm_score": 1,
"selected": false,
"text": "<p>Agree with the comments, but still might as well provide an answer for someone coming from a place of some... | 2017/10/09 | [
"https://wordpress.stackexchange.com/questions/282282",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129266/"
] | I added shortcodes to the theme I'm using, but when I try to use them in a page, it gives me a blank page. I have seen a solution to this problem saying to use `remove_filter("the_content", "wpautop");` but I'm not sure that this will work. If it will, please let me know, and please let me know where to put that code. ... | If you're coming from a Laravel background, you're going to hate Wordpress routing.
For our high-functioning Wordpress websites, I had to write a whole bunch of routing workarounds to Laravel-ise routes, and it's definitely not "The Wordpress Way."
There's no neat Wordpress way to add routes in code. Your best bet ... |
282,285 | <p>How can I prevent WordPress and plugins from overwriting my <code>.htaccess</code> file? I use Wordpress to set the structure of my permalinks; so I doubt it is practical to deny all permissions to the file.</p>
<p>If it is unlikely that WordPress is responsible for overwriting the file, advice on determining what ... | [
{
"answer_id": 282288,
"author": "haz",
"author_id": 99009,
"author_profile": "https://wordpress.stackexchange.com/users/99009",
"pm_score": 2,
"selected": false,
"text": "<p>Wordpress will definitely rewrite your .htaccess file under certain circumstances, such as if you change Permalin... | 2017/10/09 | [
"https://wordpress.stackexchange.com/questions/282285",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129120/"
] | How can I prevent WordPress and plugins from overwriting my `.htaccess` file? I use Wordpress to set the structure of my permalinks; so I doubt it is practical to deny all permissions to the file.
If it is unlikely that WordPress is responsible for overwriting the file, advice on determining what is responsible would ... | If you place your "custom" directives outside of any `# BEGIN ...` / `# END ...` comment markers then WordPress (and plugins) *should not* overwrite them when they update. (Of course, if you have plugins that don't "play nice" then they could do anything to `.htaccess` if you let them, so you would need to do something... |
282,290 | <p>I want to call a function I have written from a shortcode handler. I have now simplified the code but I cannot find out why this won't work:</p>
<pre><code>public function handleShortcode($atts) {
return X();
}
private function X()
{
return 'Hi world';
}
</code></pre>
<p>but, if I try:</p>
<pre><code>pub... | [
{
"answer_id": 282295,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 1,
"selected": false,
"text": "<p>You're returning <code>X()</code>, but your <code>X()</code> function appears to be within a class. Pre... | 2017/10/09 | [
"https://wordpress.stackexchange.com/questions/282290",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129269/"
] | I want to call a function I have written from a shortcode handler. I have now simplified the code but I cannot find out why this won't work:
```
public function handleShortcode($atts) {
return X();
}
private function X()
{
return 'Hi world';
}
```
but, if I try:
```
public function handleShortcode($atts) {... | You're returning `X()`, but your `X()` function appears to be within a class. Presumably the same class as `handleShortcode()`. So you need to call it the normal way you call functions within a class:
```
public function handleShortcode($atts) {
return $this->X();
}
private function X()
{
return 'Hi world';
}... |
282,293 | <p>I want to show Woocommerce products on my custom template page How can i get product collection in that page,Please kindly give some suggestions how do i proceed to complete it</p>
<p>thanks</p>
| [
{
"answer_id": 282295,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 1,
"selected": false,
"text": "<p>You're returning <code>X()</code>, but your <code>X()</code> function appears to be within a class. Pre... | 2017/10/09 | [
"https://wordpress.stackexchange.com/questions/282293",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/123117/"
] | I want to show Woocommerce products on my custom template page How can i get product collection in that page,Please kindly give some suggestions how do i proceed to complete it
thanks | You're returning `X()`, but your `X()` function appears to be within a class. Presumably the same class as `handleShortcode()`. So you need to call it the normal way you call functions within a class:
```
public function handleShortcode($atts) {
return $this->X();
}
private function X()
{
return 'Hi world';
}... |
282,332 | <p>Everytime I try to login my WP, this fatal error appears and I have no idea of what happened and how to solve. Can anybody help me out? I've got "zero" knowledge in programming and coding.</p>
<p>This is what appears to me:</p>
<pre><code>Fatal error: Uncaught Error: Cannot use object of type WP_Post as array in
... | [
{
"answer_id": 282334,
"author": "Mostafa Soufi",
"author_id": 106877,
"author_profile": "https://wordpress.stackexchange.com/users/106877",
"pm_score": 0,
"selected": false,
"text": "<p>There is a problem in <code>mojo-marketplace-wp-plugin</code> plugin, you can disable or update this ... | 2017/10/09 | [
"https://wordpress.stackexchange.com/questions/282332",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129291/"
] | Everytime I try to login my WP, this fatal error appears and I have no idea of what happened and how to solve. Can anybody help me out? I've got "zero" knowledge in programming and coding.
This is what appears to me:
```
Fatal error: Uncaught Error: Cannot use object of type WP_Post as array in
/home1/tenhacon/pub... | Go to your plugins dir `wp-content/plugins/` and rename `mojo-marketplace-wp-plugin` folder.
This will deactivate `mojo-marketplace` and won't throw you an error when you try to login.
Then you can contact with their support and solve this issue. |
282,336 | <p>When I try to use profile_update hook inside a class the callback function is not called.</p>
<pre><code>public function __construct() {
add_action('profile_update', array( $this, 'user_profile_update', 10, 2) );
}
function user_profile_update( $user_id, $old_user_data ) {
die(var_dump($old_user_data));
}
<... | [
{
"answer_id": 282337,
"author": "Mike",
"author_id": 69112,
"author_profile": "https://wordpress.stackexchange.com/users/69112",
"pm_score": 1,
"selected": false,
"text": "<p>Careful where you are placing your brackets.</p>\n\n<p>The hook should look like;</p>\n\n<p><code>add_action('pr... | 2017/10/09 | [
"https://wordpress.stackexchange.com/questions/282336",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129293/"
] | When I try to use profile\_update hook inside a class the callback function is not called.
```
public function __construct() {
add_action('profile_update', array( $this, 'user_profile_update', 10, 2) );
}
function user_profile_update( $user_id, $old_user_data ) {
die(var_dump($old_user_data));
}
```
Outside ... | Careful where you are placing your brackets.
The hook should look like;
`add_action('profile_update', array( $this, 'user_profile_update' ), 10, 2 );`
Note the close bracket after the method name |
282,347 | <p>I have a WordPress site and I want to add a registration link for visitors.</p>
<p>So, I added a menu item called 'REGISTER' with the following link:</p>
<pre><code>http://mywebsite.com/wp-login.php?action=register
</code></pre>
<p>The problem is that this link opens the registration form for both users and visit... | [
{
"answer_id": 282348,
"author": "Mahafuz",
"author_id": 115945,
"author_profile": "https://wordpress.stackexchange.com/users/115945",
"pm_score": 2,
"selected": false,
"text": "<p>Add your registration or log in link inside of the <code>is_user_logged_in()</code> function. So If the cur... | 2017/10/09 | [
"https://wordpress.stackexchange.com/questions/282347",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129298/"
] | I have a WordPress site and I want to add a registration link for visitors.
So, I added a menu item called 'REGISTER' with the following link:
```
http://mywebsite.com/wp-login.php?action=register
```
The problem is that this link opens the registration form for both users and visitors and I want to show it only to... | i fixed the problem with Nav Menu Roles plugin
I added the registration link to the menu and with the plugin and i set it to only logged out users
This way it won't show to logged users |
282,369 | <p>In my plugin, I would like to load css only when the front-end current page is using one of my plugin shortcodes.</p>
<p>All my shortcodes are classes extending Shortcode class. Shortcode class helps me to automate the callback function.</p>
<p><strong>Shortcode abstract class</strong></p>
<pre><code>namespace Pl... | [
{
"answer_id": 282396,
"author": "David Lee",
"author_id": 111965,
"author_profile": "https://wordpress.stackexchange.com/users/111965",
"pm_score": 3,
"selected": true,
"text": "<p>If your class is called statically you need to use <code>get_called_class()</code> like this:</p>\n\n<pre>... | 2017/10/09 | [
"https://wordpress.stackexchange.com/questions/282369",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128094/"
] | In my plugin, I would like to load css only when the front-end current page is using one of my plugin shortcodes.
All my shortcodes are classes extending Shortcode class. Shortcode class helps me to automate the callback function.
**Shortcode abstract class**
```
namespace PluginFoo\Shortcodes;
abstract class Short... | If your class is called statically you need to use `get_called_class()` like this:
```
add_action('wp_enqueue_scripts', array( get_called_class(), 'set_bootstrap' ) );
```
since `$this` is not available. This also works if the class is extended. |
282,389 | <p>Using this code: </p>
<pre><code>add_filter( 'wp_nav_menu_items', 'my_custom_menu_item');
function my_custom_menu_item($items)
{
if(is_user_logged_in())
{
$user=wp_get_current_user();
$name=$user->display_name; // or user_login , user_firstname, user_lastname
$items .= '<li>... | [
{
"answer_id": 282391,
"author": "janh",
"author_id": 129206,
"author_profile": "https://wordpress.stackexchange.com/users/129206",
"pm_score": 2,
"selected": true,
"text": "<p>Works fine for me, nothing is replaced, it's just appended to the navigation. Are you sure that it's not just a... | 2017/10/09 | [
"https://wordpress.stackexchange.com/questions/282389",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/62291/"
] | Using this code:
```
add_filter( 'wp_nav_menu_items', 'my_custom_menu_item');
function my_custom_menu_item($items)
{
if(is_user_logged_in())
{
$user=wp_get_current_user();
$name=$user->display_name; // or user_login , user_firstname, user_lastname
$items .= '<li><a href="">Welcome '.$n... | Works fine for me, nothing is replaced, it's just appended to the navigation. Are you sure that it's not just a styling-issue? Have you looked at the document source to check if it really is replacing the other menu items?
What exactly do you mean by making it the parent item? Do you want to turn
```
<li><a href="">... |
282,395 | <pre><code> if ($_FILES) {
$uploaddir = wp_upload_dir();
$file = $_FILES[featured_image];
$uploadfile = $uploaddir['path'] . '/' . basename( $file['name'] );
move_uploaded_file( $file['tmp_name'] , $uploadfile );
$filename = basename( $uploadfile )... | [
{
"answer_id": 282399,
"author": "Tom J Nowell",
"author_id": 736,
"author_profile": "https://wordpress.stackexchange.com/users/736",
"pm_score": 2,
"selected": true,
"text": "<p>It appears you've taken the super long winded route and done each step of the upload manually.</p>\n\n<p>But ... | 2017/10/09 | [
"https://wordpress.stackexchange.com/questions/282395",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128475/"
] | ```
if ($_FILES) {
$uploaddir = wp_upload_dir();
$file = $_FILES[featured_image];
$uploadfile = $uploaddir['path'] . '/' . basename( $file['name'] );
move_uploaded_file( $file['tmp_name'] , $uploadfile );
$filename = basename( $uploadfile );
... | It appears you've taken the super long winded route and done each step of the upload manually.
But why not use the sideloading function that does it all for you? The majority of your code can be replaced with this:
```
// These files need to be included as dependencies when on the front end.
require_once( ABSPATH . '... |
282,414 | <p>How to query posts from categories with specific tags? For Example if I visit "<strong>localhost/tag/tutorial</strong>" the archive page would show all post from all category with tutorial tag.</p>
<p>But the view would be seperated by category. For example:</p>
<p>Category 1</p>
<ul>
<li>Category 1 Post 1 With t... | [
{
"answer_id": 282421,
"author": "Sid",
"author_id": 110516,
"author_profile": "https://wordpress.stackexchange.com/users/110516",
"pm_score": 0,
"selected": false,
"text": "<p>Please try this one and let me know if it helps.</p>\n\n<pre><code><?php\n $categories = get_categori... | 2017/10/10 | [
"https://wordpress.stackexchange.com/questions/282414",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129329/"
] | How to query posts from categories with specific tags? For Example if I visit "**localhost/tag/tutorial**" the archive page would show all post from all category with tutorial tag.
But the view would be seperated by category. For example:
Category 1
* Category 1 Post 1 With tutorial tag
* Category 1 Post 2 with tuto... | This will help to get the category post on tag archive page. Let me know.
```
<?php
$current_tag = single_tag_title( $prefix = '', $display = false );
$categories = get_categories( array('hide_empty' => TRUE) );
foreach($categories as $category) { ?>
<?php
$args=arra... |
282,423 | <p>I've gone through four or five Codex pages, a dozens Stackexchange pages, and four or five dev blogs trying to solve this. </p>
<p>I have a custom post type called authors. The CPT is set up correctly, I pulled the CPT framework from the Codex, and I've checked it against a CPT generator. The Admin screens create, ... | [
{
"answer_id": 282426,
"author": "Slam",
"author_id": 82256,
"author_profile": "https://wordpress.stackexchange.com/users/82256",
"pm_score": 0,
"selected": false,
"text": "<p>Yeah so it was user error after all.</p>\n\n<p>Months ago I had experiment with Yeost and had added a rewrite_ru... | 2017/10/10 | [
"https://wordpress.stackexchange.com/questions/282423",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/82256/"
] | I've gone through four or five Codex pages, a dozens Stackexchange pages, and four or five dev blogs trying to solve this.
I have a custom post type called authors. The CPT is set up correctly, I pulled the CPT framework from the Codex, and I've checked it against a CPT generator. The Admin screens create, edit, and ... | While you've found the problem already, here is some basic code to move a specific rule to the end of the rewrite rules with the [rewrite\_rules\_array](https://codex.wordpress.org/Plugin_API/Filter_Reference/rewrite_rules_array) filter for people stumbling across a similar problem.
Say I want to move the rule for `([... |
282,445 | <p>i want to add an animated background to the front page of my website so i use <a href="http://vincentgarreau.com/particles.js/" rel="nofollow noreferrer">the following plugin</a> but the problem is that i must apply an id to the body and i don't know how can i do it in the right way, can anyone help me with that ?<... | [
{
"answer_id": 282446,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 1,
"selected": false,
"text": "<p>There's no filter or anything, so you'll need to edit the body tag directly in the child theme. It prob... | 2017/10/10 | [
"https://wordpress.stackexchange.com/questions/282445",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129355/"
] | i want to add an animated background to the front page of my website so i use [the following plugin](http://vincentgarreau.com/particles.js/) but the problem is that i must apply an id to the body and i don't know how can i do it in the right way, can anyone help me with that ?
```
<body id="UNIQUE_ID_HERE"> </body>
... | Put this in your functions.php →
```
<?php
function body_id_dynamic() {
if (is_home()) {
echo ' id="home"';
} elseif (is_single()) {
echo ' id="single"';
} elseif (is_search()) {
echo ' id="search"';
} elseif (is_archive()) {
echo ' id="archive"';
}
}
?>
... |
282,467 | <p>Is there a way to doing this easily like</p>
<ol>
<li>There are three or may be more</li>
<li><p>I want to display the posts of above categories like</p>
<pre><code>Bring posts from categories
From Category A: 20% OR 2
From Category B: 50% OR 5
From Category C: 30% OR 3
</code></pre></li>
<li><p>The categories... | [
{
"answer_id": 282446,
"author": "Jacob Peattie",
"author_id": 39152,
"author_profile": "https://wordpress.stackexchange.com/users/39152",
"pm_score": 1,
"selected": false,
"text": "<p>There's no filter or anything, so you'll need to edit the body tag directly in the child theme. It prob... | 2017/10/10 | [
"https://wordpress.stackexchange.com/questions/282467",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/73953/"
] | Is there a way to doing this easily like
1. There are three or may be more
2. I want to display the posts of above categories like
```
Bring posts from categories
From Category A: 20% OR 2
From Category B: 50% OR 5
From Category C: 30% OR 3
```
3. The categories may be odd or even as well as the ratio (percentag... | Put this in your functions.php →
```
<?php
function body_id_dynamic() {
if (is_home()) {
echo ' id="home"';
} elseif (is_single()) {
echo ' id="single"';
} elseif (is_search()) {
echo ' id="search"';
} elseif (is_archive()) {
echo ' id="archive"';
}
}
?>
... |
282,493 | <p>I have a search that works fine with custom fields, and one term per taxonomy. However I want to select multiple terms from one taxonomy "property-type".</p>
<p>My current query looks like ---</p>
<pre><code>/?s=Search&property_city=Any+City&property_state=Any+State&address=&beds=Any&baths=Any&... | [
{
"answer_id": 282790,
"author": "Milan Petrovic",
"author_id": 126702,
"author_profile": "https://wordpress.stackexchange.com/users/126702",
"pm_score": 3,
"selected": true,
"text": "<p>You need to make only one change in the form, change the first line to:</p>\n\n<pre><code><select ... | 2017/10/10 | [
"https://wordpress.stackexchange.com/questions/282493",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24067/"
] | I have a search that works fine with custom fields, and one term per taxonomy. However I want to select multiple terms from one taxonomy "property-type".
My current query looks like ---
```
/?s=Search&property_city=Any+City&property_state=Any+State&address=&beds=Any&baths=Any&min_price=Any&max_price=Any&property_type... | You need to make only one change in the form, change the first line to:
```
<select name="property_type[]" class="form-control" multiple>
```
Name of the field has to include [] to be considered as an array when it arrives on the server side. In the query string it will be listed as:
```
property_type[]=condo&prop... |
282,494 | <p>I’d like to update a simple static HTML site to WordPress. This would be my first WP site and I already have a theme in mind to use. The static HTML site has seven pages and an images sub folder in the root directory. </p>
<p>My current thinking is to install WordPress into the root directory that the current stati... | [
{
"answer_id": 282790,
"author": "Milan Petrovic",
"author_id": 126702,
"author_profile": "https://wordpress.stackexchange.com/users/126702",
"pm_score": 3,
"selected": true,
"text": "<p>You need to make only one change in the form, change the first line to:</p>\n\n<pre><code><select ... | 2017/10/10 | [
"https://wordpress.stackexchange.com/questions/282494",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129375/"
] | I’d like to update a simple static HTML site to WordPress. This would be my first WP site and I already have a theme in mind to use. The static HTML site has seven pages and an images sub folder in the root directory.
My current thinking is to install WordPress into the root directory that the current static HTML sit... | You need to make only one change in the form, change the first line to:
```
<select name="property_type[]" class="form-control" multiple>
```
Name of the field has to include [] to be considered as an array when it arrives on the server side. In the query string it will be listed as:
```
property_type[]=condo&prop... |
282,498 | <p>I am trying to include a CSS file using wp_enqueue_style conditionally on whether I am on the front page. I am testing for the home page with this code:</p>
<pre><code>if ( is_front_page() ) wp_enqueue_style ('TBDhome', get_template_directory_uri() . '/css/TBDhome.css','all');
</code></pre>
<p>It worked find when ... | [
{
"answer_id": 282536,
"author": "disinfor",
"author_id": 103920,
"author_profile": "https://wordpress.stackexchange.com/users/103920",
"pm_score": 1,
"selected": true,
"text": "<p>Even though this question may get down voted - because not enough information has been provided and it's fa... | 2017/10/10 | [
"https://wordpress.stackexchange.com/questions/282498",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/127612/"
] | I am trying to include a CSS file using wp\_enqueue\_style conditionally on whether I am on the front page. I am testing for the home page with this code:
```
if ( is_front_page() ) wp_enqueue_style ('TBDhome', get_template_directory_uri() . '/css/TBDhome.css','all');
```
It worked find when I was testing in the hea... | Even though this question may get down voted - because not enough information has been provided and it's fairly easy to find tutorials elsewhere, I'll help you out.
In your `functions.php` file in your theme, you need to do this:
```
add_action( 'wp_enqueue_scripts', 'wp5849_scripts' );
function wp5849_scripts() {
... |
282,519 | <p>I am currently using a Mac computer and I cannot figure out how to refresh my website when I make changes to my WordPress stylesheet file. I have tried Cmd+R for hard reloading, I have tried emptying the caches, but nothing seems to work –
the old version is still loaded nonetheless. </p>
<p>I have used a windows... | [
{
"answer_id": 300209,
"author": "WP Vlad",
"author_id": 141413,
"author_profile": "https://wordpress.stackexchange.com/users/141413",
"pm_score": 2,
"selected": false,
"text": "<p><strong>\"Quick\" fix</strong>: Right Click -> view page source ( ctrl+U ), find .css file you changed, ope... | 2017/10/10 | [
"https://wordpress.stackexchange.com/questions/282519",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/125497/"
] | I am currently using a Mac computer and I cannot figure out how to refresh my website when I make changes to my WordPress stylesheet file. I have tried Cmd+R for hard reloading, I have tried emptying the caches, but nothing seems to work –
the old version is still loaded nonetheless.
I have used a windows computer ... | **"Quick" fix**: Right Click -> view page source ( ctrl+U ), find .css file you changed, open it in new tab and reload ( you should see change in place you've made it )
**ONLY in development mode** add php function time() in place of version number
```
wp_enqueue_style( $handle, $src, array(), time() , 'all' );
```
... |
282,524 | <p>I have a home template with a header, footer and a left sidebar.</p>
<pre><code><?php get_header(); ?>
<div class="content">
<?php get_sidebar('left'); ?>
<div class="middlebar">
this is the main content
</div>
</div>
<?php get_footer(); ?>
</code></pre>... | [
{
"answer_id": 282540,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 1,
"selected": false,
"text": "<p>If you want a site that have a \"state\", you will need to develop the theme to produce a sort of \"One P... | 2017/10/10 | [
"https://wordpress.stackexchange.com/questions/282524",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107094/"
] | I have a home template with a header, footer and a left sidebar.
```
<?php get_header(); ?>
<div class="content">
<?php get_sidebar('left'); ?>
<div class="middlebar">
this is the main content
</div>
</div>
<?php get_footer(); ?>
```
After a click on one of the multiple options of the menu, the p... | you can write the script with a conditions
```
<?php is_front_page(){ ?>
<script>
jQuery(window).ready(function($){
$("#sidebarRight").animate({right: '0px'});
});
</script>
<?php } ?>
```
alternatively you can set the cookie or localstorage that the animation has been completed
```
<script>
if(!localStora... |
282,528 | <p>Must have inadvertently changed something recently as when visiting the base URL (i.e. the homepage) for my local development site it returns a 404. All of the other pages seem to work fine.</p>
<p>As per other SE posts on the topics, have tested changing the permalinks settings and the .htacess file, from what I c... | [
{
"answer_id": 282738,
"author": "Pat J",
"author_id": 16121,
"author_profile": "https://wordpress.stackexchange.com/users/16121",
"pm_score": 1,
"selected": false,
"text": "<p>I haven't been able to find out how to do this automatically, but you can do it manually: Go to <strong>Networ... | 2017/10/10 | [
"https://wordpress.stackexchange.com/questions/282528",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128906/"
] | Must have inadvertently changed something recently as when visiting the base URL (i.e. the homepage) for my local development site it returns a 404. All of the other pages seem to work fine.
As per other SE posts on the topics, have tested changing the permalinks settings and the .htacess file, from what I can tell, s... | I haven't been able to find out how to do this automatically, but you can do it manually: Go to **Network Admin » Sites** and then click **Edit** on the site whose URL you want to change.
You'll need to make sure that your DNS is set correctly.
See [this answer](https://wordpress.stackexchange.com/a/184667/16121) (to... |
282,542 | <p>hey im trying to figure out how i can display only two terms that are associated with a custom post type. I tried using <code>$wpdb</code> but that doesn't work for me since i need the term links as well. any suggestions?</p>
<p>thanks</p>
| [
{
"answer_id": 282555,
"author": "grazdev",
"author_id": 129417,
"author_profile": "https://wordpress.stackexchange.com/users/129417",
"pm_score": 3,
"selected": true,
"text": "<p>Maybe this can help. First, get all the post's terms; then, cycle through them with a <code>foreach</code> l... | 2017/10/11 | [
"https://wordpress.stackexchange.com/questions/282542",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128699/"
] | hey im trying to figure out how i can display only two terms that are associated with a custom post type. I tried using `$wpdb` but that doesn't work for me since i need the term links as well. any suggestions?
thanks | Maybe this can help. First, get all the post's terms; then, cycle through them with a `foreach` loop to retrieve and echo each one's link. The last line of code will limit the cycle to the first two terms.
```
$terms = wp_get_post_terms(); // If you're not in the loop, you should pass the post's ID as an argument... |
282,547 | <p>I want to execute multiple different PHP snippets which all retrives 1 page ID (yes, I want to extend the code and display some other things then the page ID).</p>
<p>But if I execute 2 or more snippets at the same time, I get a blank page...</p>
<p>My question is, how can I fix this error and why and how does thi... | [
{
"answer_id": 282555,
"author": "grazdev",
"author_id": 129417,
"author_profile": "https://wordpress.stackexchange.com/users/129417",
"pm_score": 3,
"selected": true,
"text": "<p>Maybe this can help. First, get all the post's terms; then, cycle through them with a <code>foreach</code> l... | 2017/10/11 | [
"https://wordpress.stackexchange.com/questions/282547",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129413/"
] | I want to execute multiple different PHP snippets which all retrives 1 page ID (yes, I want to extend the code and display some other things then the page ID).
But if I execute 2 or more snippets at the same time, I get a blank page...
My question is, how can I fix this error and why and how does this error get cause... | Maybe this can help. First, get all the post's terms; then, cycle through them with a `foreach` loop to retrieve and echo each one's link. The last line of code will limit the cycle to the first two terms.
```
$terms = wp_get_post_terms(); // If you're not in the loop, you should pass the post's ID as an argument... |
282,563 | <p>I have comment.php in my template but when i change it not effect</p>
<p>What's problem? </p>
<p>I want add Welcome to + title of post + continue text .....</p>
<p></p>
<pre><code><?php
// You can start editing here -- including this comment!
if ( have_comments() ) : ?>
<h2 class="comments-title"&... | [
{
"answer_id": 282564,
"author": "Jaed Mosharraf",
"author_id": 129422,
"author_profile": "https://wordpress.stackexchange.com/users/129422",
"pm_score": 3,
"selected": true,
"text": "<p>You can use this filter hook to add this</p>\n\n<pre><code>apply_filters( 'pre_comment_content', stri... | 2017/10/11 | [
"https://wordpress.stackexchange.com/questions/282563",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128030/"
] | I have comment.php in my template but when i change it not effect
What's problem?
I want add Welcome to + title of post + continue text .....
```
<?php
// You can start editing here -- including this comment!
if ( have_comments() ) : ?>
<h2 class="comments-title">
<?php
$comments_number = get_co... | You can use this filter hook to add this
```
apply_filters( 'pre_comment_content', string $comment_content );
```
Here is the code how you can use this
```
function add_custom_comment_content( $comment_content ) {
// You can handle it many ways
$comment_content .= "Custom Content"
}
add_filter( 'pre_comme... |
282,571 | <p>I have the following file structure (simplified): </p>
<pre><code>— app
— header.php
- views
- header-default.php
</code></pre>
<p>In header.php, I'm using <code>get_template_part</code> as follows:</p>
<pre><code><?php get_template_part( 'app/views/header/header', 'default' ); ?>
</code></pre>
<p>... | [
{
"answer_id": 282564,
"author": "Jaed Mosharraf",
"author_id": 129422,
"author_profile": "https://wordpress.stackexchange.com/users/129422",
"pm_score": 3,
"selected": true,
"text": "<p>You can use this filter hook to add this</p>\n\n<pre><code>apply_filters( 'pre_comment_content', stri... | 2017/10/11 | [
"https://wordpress.stackexchange.com/questions/282571",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129417/"
] | I have the following file structure (simplified):
```
— app
— header.php
- views
- header-default.php
```
In header.php, I'm using `get_template_part` as follows:
```
<?php get_template_part( 'app/views/header/header', 'default' ); ?>
```
This works, but suppose in the future I need to change my folder s... | You can use this filter hook to add this
```
apply_filters( 'pre_comment_content', string $comment_content );
```
Here is the code how you can use this
```
function add_custom_comment_content( $comment_content ) {
// You can handle it many ways
$comment_content .= "Custom Content"
}
add_filter( 'pre_comme... |
282,586 | <p>I created extra fields for my subscribers, one of them is an image field, so they can upload an image to their profile.</p>
<p>I created the fields with ACF (Advanced Custom Fields).</p>
<p>I have a custom register form and a custom edit form, with the regular WordPress fields and the extra ones. Everything works ... | [
{
"answer_id": 282590,
"author": "Randomer11",
"author_id": 62291,
"author_profile": "https://wordpress.stackexchange.com/users/62291",
"pm_score": 2,
"selected": false,
"text": "<p>Maybe something like this will help : </p>\n\n<pre><code>// Deal with images uploaded from the front-end w... | 2017/10/11 | [
"https://wordpress.stackexchange.com/questions/282586",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/44437/"
] | I created extra fields for my subscribers, one of them is an image field, so they can upload an image to their profile.
I created the fields with ACF (Advanced Custom Fields).
I have a custom register form and a custom edit form, with the regular WordPress fields and the extra ones. Everything works perfectly... Exce... | Ok, I got it to work with the 'media\_handle\_upload' (pointed out by @Piyush) and tweaking a little bit with my form code.
**So, here is what I did:**
*First* - Make sure your form has the attribute 'enctype='multipart/form-data'.
*Second* - Be sure that your 'input=file' has no value attribute.
*Third* - Use the ... |
282,607 | <p>I have an issue with <code><p></p></code> tags appearing after my <code><img....></code>. Here is what appears when I view the generated page on my localhost...</p>
<pre><code><img src="/wp-content/themes/wunderful/assets/images/feedback-danielle.png" alt="Danielle Johnson Deal Town FC Treasure... | [
{
"answer_id": 282606,
"author": "WebElaine",
"author_id": 102815,
"author_profile": "https://wordpress.stackexchange.com/users/102815",
"pm_score": 1,
"selected": false,
"text": "<p>Sounds like you deleted some terms and/or taxonomies related to menus. You need to get those back into th... | 2017/10/11 | [
"https://wordpress.stackexchange.com/questions/282607",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129445/"
] | I have an issue with `<p></p>` tags appearing after my `<img....>`. Here is what appears when I view the generated page on my localhost...
```
<img src="/wp-content/themes/wunderful/assets/images/feedback-danielle.png" alt="Danielle Johnson Deal Town FC Treasurer">
<p></p>
```
Notice the randomly generated `<p></p>`... | I resolved my issue.
This was due to the lost of indexes, primary keys and auto\_increment feature in my database structure due to export/import database actions.
With bad export options, the indexes and primary keys at one point, weren't re-created during import and so on....
Always export your database with ri... |
282,633 | <p>I have navmenus <code>Home | Vendors | About | Contact</code> and i have <em>Fruits</em> and <em>Vegetables</em> as pages. And these pages are added using <code>href</code> under the Vendors page. I am using the id as a link.</p>
<pre><code><!-- HTML -->
<a href="<?php echo get_page_link(21); ?>">... | [
{
"answer_id": 282635,
"author": "WebElaine",
"author_id": 102815,
"author_profile": "https://wordpress.stackexchange.com/users/102815",
"pm_score": 0,
"selected": false,
"text": "<p>Out of the box WordPress does not provide a CSS class that you could use to target the parent of the curr... | 2017/10/11 | [
"https://wordpress.stackexchange.com/questions/282633",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/102678/"
] | I have navmenus `Home | Vendors | About | Contact` and i have *Fruits* and *Vegetables* as pages. And these pages are added using `href` under the Vendors page. I am using the id as a link.
```
<!-- HTML -->
<a href="<?php echo get_page_link(21); ?>"> Fruits </a>
<a href="<?php echo get_page_link(64); ?>"> Vegetables ... | **SOLUTION**
I found it by using the `<?php wp_list_pages( $args ); ?>` with customizing the args to display only selected children by id.
```
$args = array (
'title_li' => '',
'child_of' => $post->ID,
'include' => 47
)
<h4> <?php wp_list_pages( $args ); ?> </h4>
```
and setting the css to targe... |
282,641 | <p>I have a custom post type with a custom backend page.</p>
<p>I'm creating posts of that type using this code:</p>
<pre><code>$postarr = array(
"post_type" => "product_settings",
"post_status" => "published",
"post_title" => "$ean $name",
"post_content" => "$ean $name", ... | [
{
"answer_id": 282642,
"author": "ngearing",
"author_id": 50184,
"author_profile": "https://wordpress.stackexchange.com/users/50184",
"pm_score": 0,
"selected": false,
"text": "<p>According to the docs <code>post_title</code> & <code>post_content</code> are required, Wordpress will n... | 2017/10/11 | [
"https://wordpress.stackexchange.com/questions/282641",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/2161/"
] | I have a custom post type with a custom backend page.
I'm creating posts of that type using this code:
```
$postarr = array(
"post_type" => "product_settings",
"post_status" => "published",
"post_title" => "$ean $name",
"post_content" => "$ean $name", // to satisfy WP requirement
... | Ugggggggh.
```
"post_status" => "published",
```
is incorrect. It should be
```
"post_status" => "publish",
```
This apparently puts posts into a state of limbo in which they're not visible in the list (but still counted for some reason). |
282,646 | <p>on my <code>index.php</code> I display all my posts with infinite scroll. Before the WP loop I added a $counter, which counts up with every post. But if the infinite scroll loads new posts, the counter will be reset.</p>
<p>Example for counter:
0
1
2
3
4
5
6
7
(load new posts)
0
1
2
3
4
.
.
.</p>
<p>What can I do ... | [
{
"answer_id": 282642,
"author": "ngearing",
"author_id": 50184,
"author_profile": "https://wordpress.stackexchange.com/users/50184",
"pm_score": 0,
"selected": false,
"text": "<p>According to the docs <code>post_title</code> & <code>post_content</code> are required, Wordpress will n... | 2017/10/11 | [
"https://wordpress.stackexchange.com/questions/282646",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129479/"
] | on my `index.php` I display all my posts with infinite scroll. Before the WP loop I added a $counter, which counts up with every post. But if the infinite scroll loads new posts, the counter will be reset.
Example for counter:
0
1
2
3
4
5
6
7
(load new posts)
0
1
2
3
4
.
.
.
What can I do that the counter counts up a... | Ugggggggh.
```
"post_status" => "published",
```
is incorrect. It should be
```
"post_status" => "publish",
```
This apparently puts posts into a state of limbo in which they're not visible in the list (but still counted for some reason). |
282,688 | <p>I am coming from a Laravel background and using Bootstrap in Laravel is relatively easy. However I have a project I have been working on with Wordpress and I am using Bootstrap for my nav bars. The problem is that, they are messing up my header on the page. The theme I am using is Be Theme. This is my code:</p>
<pr... | [
{
"answer_id": 282689,
"author": "Punitkumar Patel",
"author_id": 117461,
"author_profile": "https://wordpress.stackexchange.com/users/117461",
"pm_score": 4,
"selected": true,
"text": "<p>You can add bootstrap in WordPress by following function in functions.php</p>\n\n<p>You can change ... | 2017/10/12 | [
"https://wordpress.stackexchange.com/questions/282688",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/125481/"
] | I am coming from a Laravel background and using Bootstrap in Laravel is relatively easy. However I have a project I have been working on with Wordpress and I am using Bootstrap for my nav bars. The problem is that, they are messing up my header on the page. The theme I am using is Be Theme. This is my code:
```
<!DOCT... | You can add bootstrap in WordPress by following function in functions.php
You can change url as you need if you have cdn.
```
<?php
/**
* Enqueue scripts and styles
*/
function your_theme_enqueue_scripts() {
// all styles
wp_enqueue_style( 'bootstrap', get_stylesheet_directory_uri() . '/css/bootstrap.css',... |
282,693 | <p>I have created Custom Button using following Code at <code>themes/package/woocommerce/single-product/add-to-cart/simple.php</code></p>
<pre><code><?php
if($_product->getCustom_button()){ //yes or no button
?>
<button type="button" title="<?php echo $_product->getCustom_button_name() ;?>... | [
{
"answer_id": 282696,
"author": "Jaed Mosharraf",
"author_id": 129422,
"author_profile": "https://wordpress.stackexchange.com/users/129422",
"pm_score": 0,
"selected": false,
"text": "<p>You can use this code to add anything like button, text using this below code</p>\n\n<pre><code>func... | 2017/10/12 | [
"https://wordpress.stackexchange.com/questions/282693",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107334/"
] | I have created Custom Button using following Code at `themes/package/woocommerce/single-product/add-to-cart/simple.php`
```
<?php
if($_product->getCustom_button()){ //yes or no button
?>
<button type="button" title="<?php echo $_product->getCustom_button_name() ;?>" class="btn btn-default" onclick="window.ope... | ```
add_action('woocommerce_after_add_to_cart_button','cmk_additional_button');
function cmk_additional_button() {
echo '<button type="submit" class="button alt">Change me please</button>';
}
```
add this code in your Child theme functions.php
Try this code |
282,694 | <p>I'm trying to style something unique to the Blog/Posts page, which isn't on the front page. The body tag right now looks like this:<code><body <?php body_class() ?>></code>
<br>
But doing this <code><body <?php body_class('blog') ?>></code> only returns <code><body class="logged-in"></c... | [
{
"answer_id": 282695,
"author": "Piyush Rawat",
"author_id": 73600,
"author_profile": "https://wordpress.stackexchange.com/users/73600",
"pm_score": -1,
"selected": false,
"text": "<p>You can pass your class as argument</p>\n\n<pre><code><body <?php if ( is_home()) { body_class('m... | 2017/10/12 | [
"https://wordpress.stackexchange.com/questions/282694",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129515/"
] | I'm trying to style something unique to the Blog/Posts page, which isn't on the front page. The body tag right now looks like this:`<body <?php body_class() ?>>`
But doing this `<body <?php body_class('blog') ?>>` only returns `<body class="logged-in">` or just `<body>` if I'm not logged in.
I've tried:
```
<body... | In your theme's functions file, use the `body_class` filter to add new classes:
```
function wpse_282694_body_class( $classes ) {
if ( is_home() ) {
$classes[] = 'blog';
}
return $classes;
}
add_filter( 'body_class', 'wpse_282694_body_class' );
```
If your category archives, tag archives, date a... |
282,699 | <p>I have a membership site I want to call a function when any fields of user will update from any where of site.</p>
<p>I was used this function but it is not Running:</p>
<pre><code>$current_user = wp_get_current_user();
$user_id = $current_user->ID;
function update_extra_profile_fields($user_id) {
if ( cu... | [
{
"answer_id": 282695,
"author": "Piyush Rawat",
"author_id": 73600,
"author_profile": "https://wordpress.stackexchange.com/users/73600",
"pm_score": -1,
"selected": false,
"text": "<p>You can pass your class as argument</p>\n\n<pre><code><body <?php if ( is_home()) { body_class('m... | 2017/10/12 | [
"https://wordpress.stackexchange.com/questions/282699",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129516/"
] | I have a membership site I want to call a function when any fields of user will update from any where of site.
I was used this function but it is not Running:
```
$current_user = wp_get_current_user();
$user_id = $current_user->ID;
function update_extra_profile_fields($user_id) {
if ( current_user_can('edit_use... | In your theme's functions file, use the `body_class` filter to add new classes:
```
function wpse_282694_body_class( $classes ) {
if ( is_home() ) {
$classes[] = 'blog';
}
return $classes;
}
add_filter( 'body_class', 'wpse_282694_body_class' );
```
If your category archives, tag archives, date a... |
282,716 | <p>I'm in the process of converting my existing WordPress site to use Preact/Redux on the frontend and use the WP REST API to get post data back from the admin.</p>
<p>I'll be using React Router and a rewrite in .htaccess to rewrite the URLs to the index.html file, and React Router should handle the requests.</p>
<p>... | [
{
"answer_id": 282726,
"author": "Stephen Sabatini",
"author_id": 83781,
"author_profile": "https://wordpress.stackexchange.com/users/83781",
"pm_score": 0,
"selected": false,
"text": "<p>Firstly, the REST API URL base would be:</p>\n\n<p><a href=\"https://peteschuster.com/wp-json/wp/v2/... | 2017/10/12 | [
"https://wordpress.stackexchange.com/questions/282716",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1388/"
] | I'm in the process of converting my existing WordPress site to use Preact/Redux on the frontend and use the WP REST API to get post data back from the admin.
I'll be using React Router and a rewrite in .htaccess to rewrite the URLs to the index.html file, and React Router should handle the requests.
Given an existing... | The core rewrite API does offer the function `url_to_postid()` (as mentioned by @stephen-sabatini) which can find a post ID from a URL. However it seems less than ideal to have to make a request up front just to determine the post ID...
The REST API does not natively offer the ability to query by date beyond setting `... |
282,718 | <p>This is a strange error because it wasn't happening earlier, it was actually all working fine. I have removed all the code I have added since I last tested it and it was working before it broke. </p>
<p>I have a custom post acting as a page to submit a form on and I am processing the form via a function in the func... | [
{
"answer_id": 282724,
"author": "lukgoh",
"author_id": 128475,
"author_profile": "https://wordpress.stackexchange.com/users/128475",
"pm_score": 0,
"selected": false,
"text": "<p>The problem was:</p>\n\n<pre><code>if ($_FILES) {}\n</code></pre>\n\n<p>Can someone explain this to me? The ... | 2017/10/12 | [
"https://wordpress.stackexchange.com/questions/282718",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/128475/"
] | This is a strange error because it wasn't happening earlier, it was actually all working fine. I have removed all the code I have added since I last tested it and it was working before it broke.
I have a custom post acting as a page to submit a form on and I am processing the form via a function in the functions.php ... | The problem was:
```
if ($_FILES) {}
```
Can someone explain this to me? The wp\_redirect() is outside of this if statement so why wouldn't it redirect? Is it because that if statement was still firing but ran into an error as no files were being uploaded? |
282,744 | <p>I have a WP query that searches for any custom posts under type 'tribe_events' tagged as 'featured' under the taxonomy 'tribe_events_cat'.</p>
<p>So, just to be clear:<br/>
post_type = 'tribe_events'<br/>
taxonomy = 'tribe_events_cat'<br/>
terms = 'featured', 'streamteam'</p>
<p>However, it returns nothing when ou... | [
{
"answer_id": 282724,
"author": "lukgoh",
"author_id": 128475,
"author_profile": "https://wordpress.stackexchange.com/users/128475",
"pm_score": 0,
"selected": false,
"text": "<p>The problem was:</p>\n\n<pre><code>if ($_FILES) {}\n</code></pre>\n\n<p>Can someone explain this to me? The ... | 2017/10/12 | [
"https://wordpress.stackexchange.com/questions/282744",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129539/"
] | I have a WP query that searches for any custom posts under type 'tribe\_events' tagged as 'featured' under the taxonomy 'tribe\_events\_cat'.
So, just to be clear:
post\_type = 'tribe\_events'
taxonomy = 'tribe\_events\_cat'
terms = 'featured', 'streamteam'
However, it returns nothing when outside of page ID... | The problem was:
```
if ($_FILES) {}
```
Can someone explain this to me? The wp\_redirect() is outside of this if statement so why wouldn't it redirect? Is it because that if statement was still firing but ran into an error as no files were being uploaded? |
282,765 | <p>If there is some variable from the user's password, I want the password that the user has entered for the wordpress account, to send to another server, so that the user can also log on to another server with the same data as on the wordpress, is there anyone a solution for this? thank you all for help</p>
| [
{
"answer_id": 282724,
"author": "lukgoh",
"author_id": 128475,
"author_profile": "https://wordpress.stackexchange.com/users/128475",
"pm_score": 0,
"selected": false,
"text": "<p>The problem was:</p>\n\n<pre><code>if ($_FILES) {}\n</code></pre>\n\n<p>Can someone explain this to me? The ... | 2017/10/13 | [
"https://wordpress.stackexchange.com/questions/282765",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129556/"
] | If there is some variable from the user's password, I want the password that the user has entered for the wordpress account, to send to another server, so that the user can also log on to another server with the same data as on the wordpress, is there anyone a solution for this? thank you all for help | The problem was:
```
if ($_FILES) {}
```
Can someone explain this to me? The wp\_redirect() is outside of this if statement so why wouldn't it redirect? Is it because that if statement was still firing but ran into an error as no files were being uploaded? |
282,778 | <p>I'm creating a plugin similar to <a href="https://www.wpbeaverbuilder.com/" rel="nofollow noreferrer">https://www.wpbeaverbuilder.com/</a>
You can drag & drop elements to create layouts, etc. </p>
<p>What would be the best way to store post content in this case? Ideally it shouldn't be lost after disabling the ... | [
{
"answer_id": 282724,
"author": "lukgoh",
"author_id": 128475,
"author_profile": "https://wordpress.stackexchange.com/users/128475",
"pm_score": 0,
"selected": false,
"text": "<p>The problem was:</p>\n\n<pre><code>if ($_FILES) {}\n</code></pre>\n\n<p>Can someone explain this to me? The ... | 2017/10/13 | [
"https://wordpress.stackexchange.com/questions/282778",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/121208/"
] | I'm creating a plugin similar to <https://www.wpbeaverbuilder.com/>
You can drag & drop elements to create layouts, etc.
What would be the best way to store post content in this case? Ideally it shouldn't be lost after disabling the plugin.
Current options are:
* save to WP\_POSTS table as shortcodes
* create my ... | The problem was:
```
if ($_FILES) {}
```
Can someone explain this to me? The wp\_redirect() is outside of this if statement so why wouldn't it redirect? Is it because that if statement was still firing but ran into an error as no files were being uploaded? |
282,798 | <p>Sometimes with Wordpress, I find myself writing long if/else chains to see if a field (a field I've created in advanced custom fields for example) exists, for example:</p>
<pre><code>$imagen1 = get_field("imagen1");
$imagen2 = get_field("imagen2");
$imagen3 = get_field("imagen3");
$... | [
{
"answer_id": 282806,
"author": "janh",
"author_id": 129206,
"author_profile": "https://wordpress.stackexchange.com/users/129206",
"pm_score": 1,
"selected": false,
"text": "<p>There is no hard limit, but when you have many fields (I'm talking hundreds or thousands, not dozens), you mig... | 2017/10/13 | [
"https://wordpress.stackexchange.com/questions/282798",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/115742/"
] | Sometimes with Wordpress, I find myself writing long if/else chains to see if a field (a field I've created in advanced custom fields for example) exists, for example:
```
$imagen1 = get_field("imagen1");
$imagen2 = get_field("imagen2");
$imagen3 = get_field("imagen3");
$imagen4 ... | There is no hard limit, but when you have many fields (I'm talking hundreds or thousands, not dozens), you might run into limits on execution time on your host.
In this case, I'd do something like this to turn it into a loop if you don't need specific HTML.
```
foreach(range(1, 5, 1) as $imageNumber) {
if ( $ima... |
282,814 | <p>I experienced that my server received a 99% CPU load and the site goes almost down.</p>
<p>Checked the access log file and there are tons of following entries:</p>
<pre><code>203.115.XXX.XXX - - [13/Oct/2017:12:40:01 +0000] "POST /wp-admin/admin-ajax.php HTTP/1.0" 200 178
212.92.XXX.XXX - - [13/Oct/2017:12... | [
{
"answer_id": 282821,
"author": "janh",
"author_id": 129206,
"author_profile": "https://wordpress.stackexchange.com/users/129206",
"pm_score": 0,
"selected": false,
"text": "<p>There is no magic bullet, I'm afraid. If you're too careful in blocking, you won't hit them, if you're not car... | 2017/10/13 | [
"https://wordpress.stackexchange.com/questions/282814",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/48490/"
] | I experienced that my server received a 99% CPU load and the site goes almost down.
Checked the access log file and there are tons of following entries:
```
203.115.XXX.XXX - - [13/Oct/2017:12:40:01 +0000] "POST /wp-admin/admin-ajax.php HTTP/1.0" 200 178
212.92.XXX.XXX - - [13/Oct/2017:12:40:01 +0000] "GET /wp-admin/... | No there isn't a way, any more than there is a way to block "spammers" from accessing you home page. I mean you could put all kind of checks, but in the end you will break how sites are supposed to behave which will mean that someone somewhere will not get his content. If all you have is a blog maybe you just do not ca... |
282,827 | <p>I would like to change the home_url for a custom post type that I have created. </p>
<p>The reason I would like to change the home_url is so that the site logo then links to a different URL when someone is viewing a custom post. </p>
<p>The custom post type is named 'usa', therefore I want to change the logo / hom... | [
{
"answer_id": 282828,
"author": "janh",
"author_id": 129206,
"author_profile": "https://wordpress.stackexchange.com/users/129206",
"pm_score": 1,
"selected": false,
"text": "<p>Your filter generally seems fine.</p>\n\n<p>I'd probably filter <code>option_home</code> instead of <code>home... | 2017/10/13 | [
"https://wordpress.stackexchange.com/questions/282827",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/102297/"
] | I would like to change the home\_url for a custom post type that I have created.
The reason I would like to change the home\_url is so that the site logo then links to a different URL when someone is viewing a custom post.
The custom post type is named 'usa', therefore I want to change the logo / home url to link t... | Your filter generally seems fine.
I'd probably filter `option_home` instead of `home_url`, but it results in the same thing for most use cases (`bloginfo("home")` will work and so will `get_home_url()`, but `get_option("home")` will only work correctly with `option_home`). |
282,833 | <p>I trying to get the ID of the post on edit page but its displaying the wrong ID</p>
<p><a href="https://i.stack.imgur.com/WIwY8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WIwY8.png" alt="Wrong post ID"></a></p>
<p>Custom Post:</p>
<pre><code>register_post_type( 'projetos', array(
'desc... | [
{
"answer_id": 282850,
"author": "L.Milo",
"author_id": 129596,
"author_profile": "https://wordpress.stackexchange.com/users/129596",
"pm_score": 1,
"selected": false,
"text": "<p>If you remove the line <code>global $post;</code> (and really you should remove it), there is no reason this... | 2017/10/13 | [
"https://wordpress.stackexchange.com/questions/282833",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129590/"
] | I trying to get the ID of the post on edit page but its displaying the wrong ID
[](https://i.stack.imgur.com/WIwY8.png)
Custom Post:
```
register_post_type( 'projetos', array(
'description' => 'Projetos do Scan'
,'exclude_from_search' => false
... | If you remove the line `global $post;` (and really you should remove it), there is no reason this shouldn't work, according to [the official documentation](https://developer.wordpress.org/reference/functions/add_meta_box/), unless as @rudtek mentioned, you run a custom query somewhere and the `$post` has changed |
282,905 | <p><strong>Note : Please note that I create this theme to re-sell, so I need little bit good way to add it.</strong></p>
<p>This is how I register the menus on my right sidebar:</p>
<pre><code>if(function_exists('register_sidebar')){
register_sidebar(array(
'name'=>'sidebar_default',
'bef... | [
{
"answer_id": 282908,
"author": "IXN",
"author_id": 80031,
"author_profile": "https://wordpress.stackexchange.com/users/80031",
"pm_score": 1,
"selected": false,
"text": "<p>If you are dealing with just one site and not creating a theme maybe the easiest solution is to do it \"manually\... | 2017/10/14 | [
"https://wordpress.stackexchange.com/questions/282905",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56652/"
] | **Note : Please note that I create this theme to re-sell, so I need little bit good way to add it.**
This is how I register the menus on my right sidebar:
```
if(function_exists('register_sidebar')){
register_sidebar(array(
'name'=>'sidebar_default',
'before_widget' => '<div class="panel pan... | If you are dealing with just one site and not creating a theme maybe the easiest solution is to do it "manually". It is not the most "professional" way to do it, but it works.
Take a text widget or the new html widget, paste your code, for example:
```
<ul class="list-group">
<li class="list-group-item">Cras justo ... |
282,918 | <pre><code>if( ! is_user_logged_in() && ( in_category( 'test2' ) || in_category( 'test1' ) ) && ( current_time( 'Y-m-d' ) <= get_the_date( 'Y-m-d', strtotime('+3 days') ) ) ){
echo 'sorry';
} else {
the_content();
}
</code></pre>
<p>my code in single.php loop. but not working. can i help ... | [
{
"answer_id": 282925,
"author": "Milan Petrovic",
"author_id": 126702,
"author_profile": "https://wordpress.stackexchange.com/users/126702",
"pm_score": 2,
"selected": true,
"text": "<p>Unfortunately, no. For something like that to work, WordPress (or some plugin to do that) would need ... | 2017/10/14 | [
"https://wordpress.stackexchange.com/questions/282918",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/129634/"
] | ```
if( ! is_user_logged_in() && ( in_category( 'test2' ) || in_category( 'test1' ) ) && ( current_time( 'Y-m-d' ) <= get_the_date( 'Y-m-d', strtotime('+3 days') ) ) ){
echo 'sorry';
} else {
the_content();
}
```
my code in single.php loop. but not working. can i help anyone? | Unfortunately, no. For something like that to work, WordPress (or some plugin to do that) would need to scan themes folder for changes, and that can be performance intensive operation. Maybe with some sort of scheduled scan running every few minutes.
I am not aware of any plugin that can do that. |