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 |
|---|---|---|---|---|---|---|
247,018 | <p>I use the <code>WP_Customize_Image_Control</code> to add the image.</p>
<p>But, The <code>default</code> value is accessible in <code>Customizer</code> only!!!
On front-end It return <code>empty</code>.</p>
<h3>How to reproduce?</h3>
<p>Copy below code snippet and paste in your themes <code>functions.php</code>.... | [
{
"answer_id": 247046,
"author": "Felipe Rodrigues",
"author_id": 104101,
"author_profile": "https://wordpress.stackexchange.com/users/104101",
"pm_score": 1,
"selected": false,
"text": "<p>The default value that you set on the image <code>add_setting</code> will only be applyed if there... | 2016/11/22 | [
"https://wordpress.stackexchange.com/questions/247018",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/52167/"
] | I use the `WP_Customize_Image_Control` to add the image.
But, The `default` value is accessible in `Customizer` only!!!
On front-end It return `empty`.
### How to reproduce?
Copy below code snippet and paste in your themes `functions.php`.
Visit URL `http://YOUR_SITE/wp-admin/customize.php?autofocus[section]=secti... | The default value that you set on the image `add_setting` will only be applyed if there is a any option called 'reset to default' on the image control. This argument will not output any default value to the page.
The second argument of the function `get_option( 'option_name', $default )`. The `$default` parameter **wi... |
247,023 | <p>If I have a front-end post form where a user enters a url, is it OK and recommended to use <code>esc_url()</code> twice - once for cleaning the input before using <code>update_post_meta</code> for database storage, and again on output.</p>
<pre><code>// escape url before using update_post_meta
update_post_meta( $po... | [
{
"answer_id": 247025,
"author": "socki03",
"author_id": 43511,
"author_profile": "https://wordpress.stackexchange.com/users/43511",
"pm_score": 1,
"selected": false,
"text": "<p>According to the Wordpress codex, it appears it would be better to pass the first URL using <a href=\"https:/... | 2016/11/22 | [
"https://wordpress.stackexchange.com/questions/247023",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/88767/"
] | If I have a front-end post form where a user enters a url, is it OK and recommended to use `esc_url()` twice - once for cleaning the input before using `update_post_meta` for database storage, and again on output.
```
// escape url before using update_post_meta
update_post_meta( $post_id, 'url', esc_url( $url ) );
//... | It's okay to use it more than once, but not encouraged. However, in your first example, you're saving the URL to the database. When you do that, or when using the URL in the `wp_remote_*` context, or a redirect, or any other non-display context, you should be using `esc_url_raw()` instead.
Also note that `get_post_met... |
247,040 | <p>I am trying to query some wordpress posts, they have a custom post status of <code>closed</code>.</p>
<p>When I run this query, they get returned despite their custom status being set to <code>closed</code>, even though I've asked for <code>published</code>:</p>
<pre><code>$now = strtotime(date('d.m.Y H:i:s'));
$a... | [
{
"answer_id": 247042,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": -1,
"selected": false,
"text": "<p>The post_status <code>closed</code> is not part of the default post_status.</p>\n\n<p>This custom post status... | 2016/11/22 | [
"https://wordpress.stackexchange.com/questions/247040",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/27357/"
] | I am trying to query some wordpress posts, they have a custom post status of `closed`.
When I run this query, they get returned despite their custom status being set to `closed`, even though I've asked for `published`:
```
$now = strtotime(date('d.m.Y H:i:s'));
$args = array(
'post_type' => 'vacancy',
'post_s... | The correct [`post_status`](https://codex.wordpress.org/Class_Reference/WP_Query#Status_Parameters) for a 'published' post is 'publish':
```
'post_status' => 'publish',
``` |
247,041 | <p>Currently, wordpress default is returning 200 on either failed or successfull login attempt.
The modern standard, used by all web application framework is to return 401 (or 403) on failed login attempts.</p>
<p>This allows third party tools (think waf, fail2ban, etc) to detect brute forcing attempt and block it fr... | [
{
"answer_id": 247331,
"author": "Amit Rahav",
"author_id": 30989,
"author_profile": "https://wordpress.stackexchange.com/users/30989",
"pm_score": 2,
"selected": false,
"text": "<p>WordPress handles login failed in two ways:</p>\n\n<ol>\n<li><p>If it is a bad credential, and both userna... | 2016/11/22 | [
"https://wordpress.stackexchange.com/questions/247041",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/6129/"
] | Currently, wordpress default is returning 200 on either failed or successfull login attempt.
The modern standard, used by all web application framework is to return 401 (or 403) on failed login attempts.
This allows third party tools (think waf, fail2ban, etc) to detect brute forcing attempt and block it from outside... | WordPress handles login failed in two ways:
1. If it is a bad credential, and both username and password have a value, then this action can be captured by wp\_login\_failed
2. If both, or one, of the options are empty, then WordPress generates the error object as the first parameter in the authenticate filter; it does... |
247,056 | <p>How do I find out the correct hooks that are being used when installed plugins and themes insert their own menus into the WordPress admin top menu bar?</p>
<p>I know how to remove them from the admin sidebar from the following the instructions in the following post </p>
<p><a href="https://wordpress.stackexchange.... | [
{
"answer_id": 247061,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 1,
"selected": false,
"text": "<p>You can play around the <code>WP_Admin_Bar</code> class</p>\n\n<pre><code>add_action( 'admin_bar_menu', 'modif... | 2016/11/22 | [
"https://wordpress.stackexchange.com/questions/247056",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/105345/"
] | How do I find out the correct hooks that are being used when installed plugins and themes insert their own menus into the WordPress admin top menu bar?
I know how to remove them from the admin sidebar from the following the instructions in the following post
[How to remove admin menu pages inserted by plugins?](http... | You can play around the `WP_Admin_Bar` class
```
add_action( 'admin_bar_menu', 'modify_admin_bar' );
function modify_admin_bar( $wp_admin_bar ){
// do something with $wp_admin_bar;
$wp_admin_bar->get_nodes();
}
```
Have look to the codex [WP\_Admin\_Bar](https://codex.wordpress.org/Class_Reference/WP_Admin_Bar) ... |
247,067 | <p>I'm using groupblog feature and hence multisite is required with it .</p>
<p>If a new user(not logged in) reaches any of the groupblog directly viz. a subsite and clicks the login button he's redirected to www.mainsite.com/subsite/wp-login.php whereas i want him to reach at www.mainsite.com/wp-login.php .
How can i... | [
{
"answer_id": 247061,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 1,
"selected": false,
"text": "<p>You can play around the <code>WP_Admin_Bar</code> class</p>\n\n<pre><code>add_action( 'admin_bar_menu', 'modif... | 2016/11/22 | [
"https://wordpress.stackexchange.com/questions/247067",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107529/"
] | I'm using groupblog feature and hence multisite is required with it .
If a new user(not logged in) reaches any of the groupblog directly viz. a subsite and clicks the login button he's redirected to www.mainsite.com/subsite/wp-login.php whereas i want him to reach at www.mainsite.com/wp-login.php .
How can i do this ? | You can play around the `WP_Admin_Bar` class
```
add_action( 'admin_bar_menu', 'modify_admin_bar' );
function modify_admin_bar( $wp_admin_bar ){
// do something with $wp_admin_bar;
$wp_admin_bar->get_nodes();
}
```
Have look to the codex [WP\_Admin\_Bar](https://codex.wordpress.org/Class_Reference/WP_Admin_Bar) ... |
247,083 | <p>I've defined a variable in my child theme header.php.</p>
<p>I'd like to get the value of this variable from one of the templates that is rendered after the request in which the header.php is called.</p>
<p>So, in header I've got this:</p>
<pre><code>$foo = "bar"
</code></pre>
<p>If I test for this value with he... | [
{
"answer_id": 247084,
"author": "JHoffmann",
"author_id": 63847,
"author_profile": "https://wordpress.stackexchange.com/users/63847",
"pm_score": -1,
"selected": true,
"text": "<p>It the template is called via <code>get_template_part()</code>, then it is in a new variable scope. to acce... | 2016/11/23 | [
"https://wordpress.stackexchange.com/questions/247083",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/51378/"
] | I've defined a variable in my child theme header.php.
I'd like to get the value of this variable from one of the templates that is rendered after the request in which the header.php is called.
So, in header I've got this:
```
$foo = "bar"
```
If I test for this value with header.php, it returns "bar".
But if I tes... | It the template is called via `get_template_part()`, then it is in a new variable scope. to access it, you have to use the `global` keyword in you template file:
```
global $foo;
echo $foo;
```
As `header.php` probalbly is also called in a function scope, you have to make sure there the variable is used in global sc... |
247,102 | <p>I have a front-end form and I'm using a POST handler in a plugin using the init hook. Basically, it's:</p>
<pre><code><form action="" method="POST" id="mktinto-form" class="profile-form">
<!-- form fields here -->
<input type="hidden" name="action" value="profile-form">
<input type="submi... | [
{
"answer_id": 247104,
"author": "GKS",
"author_id": 90674,
"author_profile": "https://wordpress.stackexchange.com/users/90674",
"pm_score": 0,
"selected": false,
"text": "<p>You can fix it through Session. try</p>\n\n<pre><code>function vv_process_profile_forms() {\n session_start();... | 2016/11/23 | [
"https://wordpress.stackexchange.com/questions/247102",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107550/"
] | I have a front-end form and I'm using a POST handler in a plugin using the init hook. Basically, it's:
```
<form action="" method="POST" id="mktinto-form" class="profile-form">
<!-- form fields here -->
<input type="hidden" name="action" value="profile-form">
<input type="submit" value="Submit">
</form>
```
An... | I meant to answer this earlier. Turns out the problem was developer error (me!). I was using a javascript form handler that would process data and pass it on to the php form handler. Turns out that I was actually loading the .js file twice on the page. Kicked myself real hard for wasting the better part of a day figuri... |
247,109 | <h2>Question:</h2>
<p>Where is the <em>proper</em> WordPress place to add a filter for <code>pre_get_table_charset</code>, prior to it getting executed?</p>
<p>The <code>pre_get_table_charset</code> filter is triggered in <code>wp-db.php::get_table_charset()</code>.</p>
<hr>
<p><strong>Update: Solution</strong></p>... | [
{
"answer_id": 247104,
"author": "GKS",
"author_id": 90674,
"author_profile": "https://wordpress.stackexchange.com/users/90674",
"pm_score": 0,
"selected": false,
"text": "<p>You can fix it through Session. try</p>\n\n<pre><code>function vv_process_profile_forms() {\n session_start();... | 2016/11/23 | [
"https://wordpress.stackexchange.com/questions/247109",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/99009/"
] | Question:
---------
Where is the *proper* WordPress place to add a filter for `pre_get_table_charset`, prior to it getting executed?
The `pre_get_table_charset` filter is triggered in `wp-db.php::get_table_charset()`.
---
**Update: Solution**
Mark Kaplun pointed me in the right direction, which is to put the filte... | I meant to answer this earlier. Turns out the problem was developer error (me!). I was using a javascript form handler that would process data and pass it on to the php form handler. Turns out that I was actually loading the .js file twice on the page. Kicked myself real hard for wasting the better part of a day figuri... |
247,126 | <p>Parse error: syntax error, unexpected 'add_action' (T_STRING), expecting function (T_FUNCTION) in C:\xampp\htdocs\web\wp-content\themes\Total\functions.php on line 283</p>
| [
{
"answer_id": 247127,
"author": "GKS",
"author_id": 90674,
"author_profile": "https://wordpress.stackexchange.com/users/90674",
"pm_score": 1,
"selected": false,
"text": "<p>Open this file </p>\n\n<p><code>C:\\xampp\\htdocs\\web\\wp-content\\themes\\Total\\functions.php</code> </p>\n\n<... | 2016/11/23 | [
"https://wordpress.stackexchange.com/questions/247126",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107565/"
] | Parse error: syntax error, unexpected 'add\_action' (T\_STRING), expecting function (T\_FUNCTION) in C:\xampp\htdocs\web\wp-content\themes\Total\functions.php on line 283 | Open this file
`C:\xampp\htdocs\web\wp-content\themes\Total\functions.php`
go to on line `283` and check how you have added add\_action function.
It must be like this.
```
add_action('tag','function_callback' );
```
`add_action` is a function which allows you to attach a function to an action hook and it must n... |
247,152 | <p>I am attempting to edit a specific page via the WordPress admin area while logged in as an Editor, however, the page dies with the following error:</p>
<blockquote>
<p>Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) in <strong>[PATH]</strong>/htdocs/wp-includes/meta.php ... | [
{
"answer_id": 247162,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 3,
"selected": true,
"text": "<p>Because of this line in <code>wp-admin/admin.php</code>:</p>\n\n<pre><code>if ( current_user_can( 'manage_o... | 2016/11/23 | [
"https://wordpress.stackexchange.com/questions/247152",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107581/"
] | I am attempting to edit a specific page via the WordPress admin area while logged in as an Editor, however, the page dies with the following error:
>
> Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) in **[PATH]**/htdocs/wp-includes/meta.php on line 841
>
>
>
This is onl... | Because of this line in `wp-admin/admin.php`:
```
if ( current_user_can( 'manage_options' ) ) {
wp_raise_memory_limit( 'admin' );
}
```
In other words, WordPress raises the memory limit to `WP_MAX_MEMORY_LIMIT` within the admin, but only for users with the `manage_options` capability i.e. administrators.
Your b... |
247,196 | <p>I want the conditional to be applied and that it is only displayed on pages, but it does not work, what is wrong?</p>
<pre><code> function luc_add_cutom_fields_to_content( $content ) {
$custom_fields = get_post_custom();
$content .= "<div class='cta-div'>";
if( isset( $custom_fields['luc_nam... | [
{
"answer_id": 247202,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 0,
"selected": false,
"text": "<p>Maybe the filter is firing well, but There is no global scope for the current post and the if(isset(...)) can'... | 2016/11/23 | [
"https://wordpress.stackexchange.com/questions/247196",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107241/"
] | I want the conditional to be applied and that it is only displayed on pages, but it does not work, what is wrong?
```
function luc_add_cutom_fields_to_content( $content ) {
$custom_fields = get_post_custom();
$content .= "<div class='cta-div'>";
if( isset( $custom_fields['luc_name'] ) ) {
$... | [`is_page()`](https://developer.wordpress.org/reference/functions/is_page/) requires `WP_Query` to be initialized and I assume your code runs before this. You can use this function within the filter callback instead:
```
add_filter('the_content', function($c){
return is_page() ? luc_add_cutom_fields_to_content($c)... |
247,197 | <p>How to I get the current post id while in admin? I want to use a custom upload dir based on the post ID but i cant seem to retreive it?</p>
<pre><code>add_filter( 'wp_handle_upload_prefilter', 'do_pre_upload' );
function do_pre_upload( $file ) {
add_filter( 'upload_dir', 'do_custom_upload_dir' );
return $... | [
{
"answer_id": 247201,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 1,
"selected": false,
"text": "<p><code>$post</code> is an object, you can get the post id like this</p>\n\n<pre><code> $id = $post->ID;\n</... | 2016/11/23 | [
"https://wordpress.stackexchange.com/questions/247197",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/101113/"
] | How to I get the current post id while in admin? I want to use a custom upload dir based on the post ID but i cant seem to retreive it?
```
add_filter( 'wp_handle_upload_prefilter', 'do_pre_upload' );
function do_pre_upload( $file ) {
add_filter( 'upload_dir', 'do_custom_upload_dir' );
return $file;
}
functi... | Based on your comments, it sounds like you just want a custom directory for your post type called `client_gallery` which is fairly straight-forward actually. The below just uses the `upload_dir` hook to achieve this:
```
/**
* Modify Upload Directory Based on Post Type
*
* @param Array $dir
*
* @return Array $dir... |
247,200 | <p>As a thank you to the hundreds of people who have contributed to my blog through comments, I have created a page which (1) lists them, with (2) how many comments they have made. So far, so good! What would be a great final touch however would be to show (3) how many days since they last posted, and that's where it's... | [
{
"answer_id": 247201,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 1,
"selected": false,
"text": "<p><code>$post</code> is an object, you can get the post id like this</p>\n\n<pre><code> $id = $post->ID;\n</... | 2016/11/23 | [
"https://wordpress.stackexchange.com/questions/247200",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107611/"
] | As a thank you to the hundreds of people who have contributed to my blog through comments, I have created a page which (1) lists them, with (2) how many comments they have made. So far, so good! What would be a great final touch however would be to show (3) how many days since they last posted, and that's where it's go... | Based on your comments, it sounds like you just want a custom directory for your post type called `client_gallery` which is fairly straight-forward actually. The below just uses the `upload_dir` hook to achieve this:
```
/**
* Modify Upload Directory Based on Post Type
*
* @param Array $dir
*
* @return Array $dir... |
247,206 | <p>I've created a page template and used this code to call a post which contains a shortcode: </p>
<pre><code>$post_id = 129;
if( get_post_status( $post_id ) == 'publish' ) {
the_content();
}
</code></pre>
<p>The problem is that this code works fine in the index.php but not in my page template. Why is that?</p>
... | [
{
"answer_id": 247207,
"author": "GKS",
"author_id": 90674,
"author_profile": "https://wordpress.stackexchange.com/users/90674",
"pm_score": 0,
"selected": false,
"text": "<p>You can use <code>get_post()</code> function to get the post content by post id. </p>\n\n<pre><code>$post_id = 12... | 2016/11/23 | [
"https://wordpress.stackexchange.com/questions/247206",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107615/"
] | I've created a page template and used this code to call a post which contains a shortcode:
```
$post_id = 129;
if( get_post_status( $post_id ) == 'publish' ) {
the_content();
}
```
The problem is that this code works fine in the index.php but not in my page template. Why is that?
Help please. | The reason your post is not displaying properly is because functions such as [`the_title()`](https://codex.wordpress.org/Function_Reference/the_title), [`the_permalink()`](https://codex.wordpress.org/Function_Reference/the_permalink), and [`the_content()`](https://developer.wordpress.org/reference/functions/the_content... |
247,215 | <p>I have enabled SVG-file-linking on my WP site using the <a href="https://wordpress.org/plugins/safe-svg/" rel="nofollow noreferrer">Safe SVG plug-in</a>, and I'm mostly happy with it. However, I'm having an issue with styling the SVG-paths contained in the external-file I am calling/linikng. Currently, I am unable... | [
{
"answer_id": 247207,
"author": "GKS",
"author_id": 90674,
"author_profile": "https://wordpress.stackexchange.com/users/90674",
"pm_score": 0,
"selected": false,
"text": "<p>You can use <code>get_post()</code> function to get the post content by post id. </p>\n\n<pre><code>$post_id = 12... | 2016/11/23 | [
"https://wordpress.stackexchange.com/questions/247215",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/105196/"
] | I have enabled SVG-file-linking on my WP site using the [Safe SVG plug-in](https://wordpress.org/plugins/safe-svg/), and I'm mostly happy with it. However, I'm having an issue with styling the SVG-paths contained in the external-file I am calling/linikng. Currently, I am unable to create the interactivitiy I desire bec... | The reason your post is not displaying properly is because functions such as [`the_title()`](https://codex.wordpress.org/Function_Reference/the_title), [`the_permalink()`](https://codex.wordpress.org/Function_Reference/the_permalink), and [`the_content()`](https://developer.wordpress.org/reference/functions/the_content... |
247,219 | <p>I'm using the following code (<a href="http://www.ordinarycoder.com/paginate_links-class-ul-li-bootstrap/" rel="nofollow noreferrer">from here</a>) to paginate links:</p>
<pre><code>function custom_pagination() {
global $wp_query;
$big = 999999999; // need an unlikely integer
$pages = paginate_links( ar... | [
{
"answer_id": 247225,
"author": "socki03",
"author_id": 43511,
"author_profile": "https://wordpress.stackexchange.com/users/43511",
"pm_score": 0,
"selected": false,
"text": "<p>Tracking through this, it appears that there isn't a way to pass a class through the <code>paginate_links</co... | 2016/11/23 | [
"https://wordpress.stackexchange.com/questions/247219",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107619/"
] | I'm using the following code ([from here](http://www.ordinarycoder.com/paginate_links-class-ul-li-bootstrap/)) to paginate links:
```
function custom_pagination() {
global $wp_query;
$big = 999999999; // need an unlikely integer
$pages = paginate_links( array(
'base' => str_replace( $big, '%#%'... | The `paginate_links()` function, located in [`wp-includes/general-template.php`](https://github.com/WordPress/WordPress/blob/master/wp-includes/general-template.php#L3233), doesn't allow for certain parts of the HTML (such as the `page-numbers` class) to be customized.
A simple string replacement will not work due to... |
247,251 | <p>This is really a two stage question, for not very relevant context you can look at this question - <a href="https://wordpress.stackexchange.com/questions/227245/how-to-customize-a-shortcode-using-the-customizer">How to customize a shortcode using the customizer</a>. In brief I got a widget and a shortcode that imple... | [
{
"answer_id": 247514,
"author": "Weston Ruter",
"author_id": 8521,
"author_profile": "https://wordpress.stackexchange.com/users/8521",
"pm_score": 4,
"selected": true,
"text": "<p><strong>tl;dr</strong> See <a href=\"https://gist.github.com/westonruter/d4a21d8c891974e808975dcdfe97625d\"... | 2016/11/24 | [
"https://wordpress.stackexchange.com/questions/247251",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23970/"
] | This is really a two stage question, for not very relevant context you can look at this question - [How to customize a shortcode using the customizer](https://wordpress.stackexchange.com/questions/227245/how-to-customize-a-shortcode-using-the-customizer). In brief I got a widget and a shortcode that implement the same ... | **tl;dr** See [standalone example plugin](https://gist.github.com/westonruter/d4a21d8c891974e808975dcdfe97625d) that demonstrates initiating a full refresh when a selective refresh request enqueues different scripts or styles and also which re-initializes JS behaviors for selectively-refreshed partial placement contain... |
247,258 | <p>How to check if search query contain some characters? For example I would like to check if search query contain "/".</p>
<p>I tried <a href="https://stackoverflow.com/questions/17940444/if-search-query-is-met-function">this answer</a> but it is not working for me. Just to say I am using custom search base.</p>
<p>... | [
{
"answer_id": 247264,
"author": "Emil",
"author_id": 80532,
"author_profile": "https://wordpress.stackexchange.com/users/80532",
"pm_score": 0,
"selected": false,
"text": "<p>You'll need to hook onto the search query through <code>pre_get_posts</code>. The following snippet will search ... | 2016/11/24 | [
"https://wordpress.stackexchange.com/questions/247258",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25053/"
] | How to check if search query contain some characters? For example I would like to check if search query contain "/".
I tried [this answer](https://stackoverflow.com/questions/17940444/if-search-query-is-met-function) but it is not working for me. Just to say I am using custom search base.
Example:
site.com/myseachba... | After the question's update, I think that you need to set the canonical URL:
```
add_action( 'wp_head', 'cyb_search_results_canonical_URL' );
function cyb_search_results_canonical_URL() {
if( is_search() ) {
$link = get_search_link();
echo '<link rel="canonical" href="' . esc_url( $link ) . '">';
... |
247,328 | <p>I'm working within a child theme so I don't want to edit the file that is registering a Portfolio CPT to my site. I used a plugin to change the name from Portfolio to Stories, but the plugin doesn't give an option for the slug.</p>
<p>I tried using the following function:</p>
<pre><code>function change_slug_of_pos... | [
{
"answer_id": 247330,
"author": "Dave Romsey",
"author_id": 2807,
"author_profile": "https://wordpress.stackexchange.com/users/2807",
"pm_score": 6,
"selected": true,
"text": "<p>The <a href=\"https://developer.wordpress.org/reference/hooks/register_post_type_args/\" rel=\"noreferrer\">... | 2016/11/24 | [
"https://wordpress.stackexchange.com/questions/247328",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/96257/"
] | I'm working within a child theme so I don't want to edit the file that is registering a Portfolio CPT to my site. I used a plugin to change the name from Portfolio to Stories, but the plugin doesn't give an option for the slug.
I tried using the following function:
```
function change_slug_of_post_type_portfolio() {
... | The [`register_post_type_args`](https://developer.wordpress.org/reference/hooks/register_post_type_args/) filter can be used to modify post type arguments:
```
add_filter( 'register_post_type_args', 'wpse247328_register_post_type_args', 10, 2 );
function wpse247328_register_post_type_args( $args, $post_type ) {
i... |
247,332 | <p>I need to import images from an url and return the image id</p>
<p>is it possible to make a function like this?</p>
<pre><code> <?php
$link = 'https://mosaic01.ztat.net/vgs/media/pdp-zoom/NI/11/3D/03/4D/11/NI113D034-D11@12.jpg';
$title = 'the image title';
$alt = 'the image alt';
$image_id = insert_image($l... | [
{
"answer_id": 247333,
"author": "Felipe Rodrigues",
"author_id": 104101,
"author_profile": "https://wordpress.stackexchange.com/users/104101",
"pm_score": 0,
"selected": false,
"text": "<p>What id? The HTML ID? If not, maybe you need a regex to search the url in order to find a pattern ... | 2016/11/24 | [
"https://wordpress.stackexchange.com/questions/247332",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107702/"
] | I need to import images from an url and return the image id
is it possible to make a function like this?
```
<?php
$link = 'https://mosaic01.ztat.net/vgs/media/pdp-zoom/NI/11/3D/03/4D/11/NI113D034-D11@12.jpg';
$title = 'the image title';
$alt = 'the image alt';
$image_id = insert_image($link, $title, $alt);
?>
... | Take a look at side loading images. [`media_sideload_image()`](https://codex.wordpress.org/Function_Reference/media_sideload_image)/[`wp_handle_sideload()`](https://codex.wordpress.org/Function_Reference/wp_handle_sideload) and get the ID from the URL. [`attachment_url_to_postid`](https://developer.wordpress.org/refere... |
247,367 | <p>I would like to have a different template for categories and subcategories
The categories template is set in categories.php
is it somehow possible to load the subcategories template from subcategories.php or something like that?</p>
| [
{
"answer_id": 247376,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 4,
"selected": true,
"text": "<p><a href=\"https://developer.wordpress.org/themes/basics/template-hierarchy/#filter-hierarchy\" rel=\"nofollow noref... | 2016/11/25 | [
"https://wordpress.stackexchange.com/questions/247367",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107713/"
] | I would like to have a different template for categories and subcategories
The categories template is set in categories.php
is it somehow possible to load the subcategories template from subcategories.php or something like that? | [The template hierarchy has filters](https://developer.wordpress.org/themes/basics/template-hierarchy/#filter-hierarchy) for all types of templates. Here we can use `category_template`, check if the current category has a parent, and load the `subcategory.php` file in that case:
```
function wpd_subcategory_template( ... |
247,371 | <p>In my Customizer, I have a checkbox to "Display Title". I want the title to display by default (which it is in the Customizer) but the Customizer settings need to be saved in order for it to display on the live site. I would like it to display without having to save the settings first.</p>
<p>This is the code I hav... | [
{
"answer_id": 247373,
"author": "cybmeta",
"author_id": 37428,
"author_profile": "https://wordpress.stackexchange.com/users/37428",
"pm_score": 3,
"selected": true,
"text": "<p><code>get_theme_mod()</code> has a second parameter where you can set the default value, the value to use if t... | 2016/11/25 | [
"https://wordpress.stackexchange.com/questions/247371",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40536/"
] | In my Customizer, I have a checkbox to "Display Title". I want the title to display by default (which it is in the Customizer) but the Customizer settings need to be saved in order for it to display on the live site. I would like it to display without having to save the settings first.
This is the code I have in my te... | `get_theme_mod()` has a second parameter where you can set the default value, the value to use if the option is not set.
So, if the default value is `"1"`, you can use:
```
get_theme_mod( 'display_header_image_title', '1' )
```
Then, if there is not value for `display_header_image_title` (no value in database), `"1... |
247,399 | <p>On our blog, only one page is responsive. All other pages are not reorganized when they we access them. I checked all of the settings and searched the web for a while but I could not find a hint about why this happens.</p>
<p>Here's the page that works: <a href="http://blog.tryd.com.br/archives/4494" rel="nofollow... | [
{
"answer_id": 247373,
"author": "cybmeta",
"author_id": 37428,
"author_profile": "https://wordpress.stackexchange.com/users/37428",
"pm_score": 3,
"selected": true,
"text": "<p><code>get_theme_mod()</code> has a second parameter where you can set the default value, the value to use if t... | 2016/11/25 | [
"https://wordpress.stackexchange.com/questions/247399",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107738/"
] | On our blog, only one page is responsive. All other pages are not reorganized when they we access them. I checked all of the settings and searched the web for a while but I could not find a hint about why this happens.
Here's the page that works: <http://blog.tryd.com.br/archives/4494>
Any other page looks wrong on c... | `get_theme_mod()` has a second parameter where you can set the default value, the value to use if the option is not set.
So, if the default value is `"1"`, you can use:
```
get_theme_mod( 'display_header_image_title', '1' )
```
Then, if there is not value for `display_header_image_title` (no value in database), `"1... |
247,402 | <p>I am enqueuing some javascript that injects SVGs into my page's DOM (called <a href="https://github.com/iconic/SVGInjector" rel="nofollow noreferrer">SVGInjector</a>); it works great except for one thing: there is an undesirable "blink"/shift of elements on my screen where the injected elements are placed... | [
{
"answer_id": 247373,
"author": "cybmeta",
"author_id": 37428,
"author_profile": "https://wordpress.stackexchange.com/users/37428",
"pm_score": 3,
"selected": true,
"text": "<p><code>get_theme_mod()</code> has a second parameter where you can set the default value, the value to use if t... | 2016/11/25 | [
"https://wordpress.stackexchange.com/questions/247402",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/105196/"
] | I am enqueuing some javascript that injects SVGs into my page's DOM (called [SVGInjector](https://github.com/iconic/SVGInjector)); it works great except for one thing: there is an undesirable "blink"/shift of elements on my screen where the injected elements are placed upon loading. Apparently this blink has a name I f... | `get_theme_mod()` has a second parameter where you can set the default value, the value to use if the option is not set.
So, if the default value is `"1"`, you can use:
```
get_theme_mod( 'display_header_image_title', '1' )
```
Then, if there is not value for `display_header_image_title` (no value in database), `"1... |
247,409 | <p>I have a custom post type <strong><code>books</code></strong> and a custom taxonomy <strong><code>books-categories</code></strong>. <code>wp_insert_post()</code> and it works. How can i add a second taxonomy called <strong><code>location</code></strong>? This code doeasn't save my custom taxonomy called <strong><co... | [
{
"answer_id": 247417,
"author": "Dan.",
"author_id": 97196,
"author_profile": "https://wordpress.stackexchange.com/users/97196",
"pm_score": 0,
"selected": false,
"text": "<p>The problem is that you have two inputs both sending data with <code>name</code> of <code>cat</code>.</p>\n\n<p>... | 2016/11/25 | [
"https://wordpress.stackexchange.com/questions/247409",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107745/"
] | I have a custom post type **`books`** and a custom taxonomy **`books-categories`**. `wp_insert_post()` and it works. How can i add a second taxonomy called **`location`**? This code doeasn't save my custom taxonomy called **`location`**.
Can anyone help me please?
```
<?php
if( 'POST' == $_SERVER['REQUEST_METHOD'] && ... | **wp\_set\_post\_terms() function will only work on the native post type**.
For a taxonomy on a custom post type use [wp\_set\_object\_terms()](https://codex.wordpress.org/Function_Reference/wp_set_object_terms).
Change your code to:
```
wp_set_object_terms( $pid, $_POST['cat'], 'books-categories', false );
wp_set_o... |
247,411 | <p>I've setup checkbox controls in my theme Customizer to show/hide the Logo and Site Title when they are checked/unchecked. By default, I want the Logo to display and the Site Title to be hidden.</p>
<p>Everything is working as it should except the Site Title won't display in the live preview when the checkbox is che... | [
{
"answer_id": 247417,
"author": "Dan.",
"author_id": 97196,
"author_profile": "https://wordpress.stackexchange.com/users/97196",
"pm_score": 0,
"selected": false,
"text": "<p>The problem is that you have two inputs both sending data with <code>name</code> of <code>cat</code>.</p>\n\n<p>... | 2016/11/25 | [
"https://wordpress.stackexchange.com/questions/247411",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40536/"
] | I've setup checkbox controls in my theme Customizer to show/hide the Logo and Site Title when they are checked/unchecked. By default, I want the Logo to display and the Site Title to be hidden.
Everything is working as it should except the Site Title won't display in the live preview when the checkbox is checked, unle... | **wp\_set\_post\_terms() function will only work on the native post type**.
For a taxonomy on a custom post type use [wp\_set\_object\_terms()](https://codex.wordpress.org/Function_Reference/wp_set_object_terms).
Change your code to:
```
wp_set_object_terms( $pid, $_POST['cat'], 'books-categories', false );
wp_set_o... |
247,439 | <p>I've updated my plugin, <a href="https://wordpress.org/plugins/disable-blogging/" rel="nofollow noreferrer">Disable Blogging</a>, to the latest version which is available in the WordPress repository.</p>
<p>Everything works as it should. However, one of my users has encountered an error when updating my plugin.</p>... | [
{
"answer_id": 247430,
"author": "LebCit",
"author_id": 102912,
"author_profile": "https://wordpress.stackexchange.com/users/102912",
"pm_score": 0,
"selected": false,
"text": "<p>You can learn about Template Hierarchy on the developer handbook\n<a href=\"https://developer.wordpress.org/... | 2016/11/25 | [
"https://wordpress.stackexchange.com/questions/247439",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98212/"
] | I've updated my plugin, [Disable Blogging](https://wordpress.org/plugins/disable-blogging/), to the latest version which is available in the WordPress repository.
Everything works as it should. However, one of my users has encountered an error when updating my plugin.
>
> **Fatal error**: Can’t use function return v... | First plugins are loaded, then templates.
Media is not loaded until called (afaik) from either a plugin or theme.
Widgets, enqueued scripts and CSS can be called from both plugins and templates so it depends where they are defined. |
247,447 | <p>I am working on a plugin that has a piece of meta data attached to each post. The fields are editable in a meta box on the post. This is all working fine.</p>
<p>I would like to prevent anyone from modifying the settings in meta box once the post has been published. By virtue of the application looking for this met... | [
{
"answer_id": 247452,
"author": "GKS",
"author_id": 90674,
"author_profile": "https://wordpress.stackexchange.com/users/90674",
"pm_score": 2,
"selected": true,
"text": "<p>We can do this by storing the value into postmeta when post is published first time. </p>\n\n<pre><code>function ... | 2016/11/26 | [
"https://wordpress.stackexchange.com/questions/247447",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107763/"
] | I am working on a plugin that has a piece of meta data attached to each post. The fields are editable in a meta box on the post. This is all working fine.
I would like to prevent anyone from modifying the settings in meta box once the post has been published. By virtue of the application looking for this meta data, it... | We can do this by storing the value into postmeta when post is published first time.
```
function save_ispublished( $post_id ) {
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return;
$published_once = get_post_meta( $post_id, 'is_published', true );
// Check if 'is_published' meta value is e... |
247,450 | <p>I have built a plug in and it appears to hook in ok. It runs at least. However it loads very slowly. I have attached my console log results. It appears as though the base url is not correctly built in some cases. www.mydomain.com/wordpress/plugin is combining with /wp-includes/js/jquery/. These entries should b... | [
{
"answer_id": 247452,
"author": "GKS",
"author_id": 90674,
"author_profile": "https://wordpress.stackexchange.com/users/90674",
"pm_score": 2,
"selected": true,
"text": "<p>We can do this by storing the value into postmeta when post is published first time. </p>\n\n<pre><code>function ... | 2016/11/26 | [
"https://wordpress.stackexchange.com/questions/247450",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/82889/"
] | I have built a plug in and it appears to hook in ok. It runs at least. However it loads very slowly. I have attached my console log results. It appears as though the base url is not correctly built in some cases. www.mydomain.com/wordpress/plugin is combining with /wp-includes/js/jquery/. These entries should be www.my... | We can do this by storing the value into postmeta when post is published first time.
```
function save_ispublished( $post_id ) {
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return;
$published_once = get_post_meta( $post_id, 'is_published', true );
// Check if 'is_published' meta value is e... |
247,503 | <p>I'm getting a HTTP 500 Error on my website. Not sure what it could be. But when I refresh the page, everything works correctly. Here goes the exact error</p>
<pre><code>The www.brothas.online page isn’t working
</code></pre>
<p>www.brothas.online is currently unable to handle this request.
HTTP ERROR 500</p>
<p>U... | [
{
"answer_id": 247452,
"author": "GKS",
"author_id": 90674,
"author_profile": "https://wordpress.stackexchange.com/users/90674",
"pm_score": 2,
"selected": true,
"text": "<p>We can do this by storing the value into postmeta when post is published first time. </p>\n\n<pre><code>function ... | 2016/11/27 | [
"https://wordpress.stackexchange.com/questions/247503",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107806/"
] | I'm getting a HTTP 500 Error on my website. Not sure what it could be. But when I refresh the page, everything works correctly. Here goes the exact error
```
The www.brothas.online page isn’t working
```
www.brothas.online is currently unable to handle this request.
HTTP ERROR 500
Usually it happens when trying to ... | We can do this by storing the value into postmeta when post is published first time.
```
function save_ispublished( $post_id ) {
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return;
$published_once = get_post_meta( $post_id, 'is_published', true );
// Check if 'is_published' meta value is e... |
247,504 | <p>I have used WPML multi currency for a while, but recently I turned it off and use the other currency plugin.</p>
<p>Most of the amount have converted correctly, but for some amount still remain at the default currency even after I changed to another one:</p>
<p>1) Booking cost from Woocommerce Booking plugin </p>... | [
{
"answer_id": 247838,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 1,
"selected": false,
"text": "<p>First at all, I just use WPML one time and I really don't liked it.</p>\n\n<p>It comes to me, that you maybe l... | 2016/11/27 | [
"https://wordpress.stackexchange.com/questions/247504",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/88666/"
] | I have used WPML multi currency for a while, but recently I turned it off and use the other currency plugin.
Most of the amount have converted correctly, but for some amount still remain at the default currency even after I changed to another one:
1) Booking cost from Woocommerce Booking plugin
2) Extra option cost... | First at all, I just use WPML one time and I really don't liked it.
It comes to me, that you maybe leave some po/mo files in the `wp-content/languages/woocommerce-multilingual/` or wpml one.
I found on a [thread](https://wpml.org/forums/topic/how-to-get-wpml-to-use-mo-files/) saying
>
> 1. Visit WPML > Theme and plu... |
247,507 | <p>What is the reason for using a style sheet header on page templates, where critcal values are assigned within a comments block in php, instead of just declaring constants, objects, or some other php structure?</p>
<p>The style sheet header is like this:</p>
<pre><code>/*
Theme Name: Twenty Fifteen Child
Theme URI:... | [
{
"answer_id": 247511,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 2,
"selected": false,
"text": "<p>The headers have to be read without the files being executed. The files are parsed to extract the headers without ... | 2016/11/27 | [
"https://wordpress.stackexchange.com/questions/247507",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107811/"
] | What is the reason for using a style sheet header on page templates, where critcal values are assigned within a comments block in php, instead of just declaring constants, objects, or some other php structure?
The style sheet header is like this:
```
/*
Theme Name: Twenty Fifteen Child
Theme URI: *
Description: Twen... | The headers have to be read without the files being executed. The files are parsed to extract the headers without executing the php code they contain. |
247,522 | <p>I'm making a custom meta field for posts.</p>
<p>In the back-end, get_post_meta works fine and returns the value.</p>
<p>In the front-end, it returns NULL:</p>
<pre><code>$my_custom_field = get_post_meta( $post_id, 'my_custom_field', true );
var_dump($my_custom_field); // NULL
echo $my_custom_field // ''
</code>... | [
{
"answer_id": 248258,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 0,
"selected": false,
"text": "<p>In a function context, <code>output_my_custom_field()</code> can not use template tag like <code>get_the_ID()<... | 2016/11/27 | [
"https://wordpress.stackexchange.com/questions/247522",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8652/"
] | I'm making a custom meta field for posts.
In the back-end, get\_post\_meta works fine and returns the value.
In the front-end, it returns NULL:
```
$my_custom_field = get_post_meta( $post_id, 'my_custom_field', true );
var_dump($my_custom_field); // NULL
echo $my_custom_field // ''
```
Things I tried and looked i... | Not 100% sure I understand the question or problem, but this ought to work, I think:
```
add_action( 'the_post', 'output_my_custom_field');
function output_my_custom_field( $post_object ) {
$post_id = $post_object->ID;
// why the conditional (and redundant !empty) ?
// if ( !empty($post_id) ) ) {
... |
247,530 | <p>I have a custom post type <strong><code>books</code></strong> and 3 custom taxonomies attached to <strong><code>books</code></strong>. The custom taxonomies are: <strong><code>books-categories</code></strong> , <strong><code>location</code></strong> , <strong><code>services_c</code></strong>. How should i edit my fo... | [
{
"answer_id": 248258,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 0,
"selected": false,
"text": "<p>In a function context, <code>output_my_custom_field()</code> can not use template tag like <code>get_the_ID()<... | 2016/11/27 | [
"https://wordpress.stackexchange.com/questions/247530",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107745/"
] | I have a custom post type **`books`** and 3 custom taxonomies attached to **`books`**. The custom taxonomies are: **`books-categories`** , **`location`** , **`services_c`**. How should i edit my form to get my taxonomies work;
I'm trying to solve this for 3 days and but i can't. Can anyone help me please?
```
<?php
if... | Not 100% sure I understand the question or problem, but this ought to work, I think:
```
add_action( 'the_post', 'output_my_custom_field');
function output_my_custom_field( $post_object ) {
$post_id = $post_object->ID;
// why the conditional (and redundant !empty) ?
// if ( !empty($post_id) ) ) {
... |
247,558 | <p>I have code in function and plugin widget, please see my code below.</p>
<p><code>function.php</code> //show count</p>
<pre><code>function hwd_post_views(){
$post_id = get_the_ID();
$count_key = 'post_views_count';
$n = get_post_meta($post_id, $count_key, true);
if ($n > 999999999) {
$n_format = number_form... | [
{
"answer_id": 248258,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 0,
"selected": false,
"text": "<p>In a function context, <code>output_my_custom_field()</code> can not use template tag like <code>get_the_ID()<... | 2016/11/27 | [
"https://wordpress.stackexchange.com/questions/247558",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106929/"
] | I have code in function and plugin widget, please see my code below.
`function.php` //show count
```
function hwd_post_views(){
$post_id = get_the_ID();
$count_key = 'post_views_count';
$n = get_post_meta($post_id, $count_key, true);
if ($n > 999999999) {
$n_format = number_format($n / 1000000000, 1) . 'B';
} els... | Not 100% sure I understand the question or problem, but this ought to work, I think:
```
add_action( 'the_post', 'output_my_custom_field');
function output_my_custom_field( $post_object ) {
$post_id = $post_object->ID;
// why the conditional (and redundant !empty) ?
// if ( !empty($post_id) ) ) {
... |
247,589 | <p>I have a very simple wordpress problem, but I'm still struggling to figure out the solution. I have an anchor tag, and I want it to open an image gallery in a lightbox (as the default behavior when user clicks on one of the images from the image gallery) on click.</p>
<p>The image gallery should be hidden otherwise... | [
{
"answer_id": 248258,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 0,
"selected": false,
"text": "<p>In a function context, <code>output_my_custom_field()</code> can not use template tag like <code>get_the_ID()<... | 2016/11/17 | [
"https://wordpress.stackexchange.com/questions/247589",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | I have a very simple wordpress problem, but I'm still struggling to figure out the solution. I have an anchor tag, and I want it to open an image gallery in a lightbox (as the default behavior when user clicks on one of the images from the image gallery) on click.
The image gallery should be hidden otherwise, visible ... | Not 100% sure I understand the question or problem, but this ought to work, I think:
```
add_action( 'the_post', 'output_my_custom_field');
function output_my_custom_field( $post_object ) {
$post_id = $post_object->ID;
// why the conditional (and redundant !empty) ?
// if ( !empty($post_id) ) ) {
... |
247,624 | <p>I made multiple custom search on my wordpress site to find post with category search. Like this:</p>
<pre><code> <select id="category-select" name="category-select">
<option value="6">Todo</option>
<option value="7">Spain</option>
<option value="8">Europe&... | [
{
"answer_id": 248258,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 0,
"selected": false,
"text": "<p>In a function context, <code>output_my_custom_field()</code> can not use template tag like <code>get_the_ID()<... | 2016/11/28 | [
"https://wordpress.stackexchange.com/questions/247624",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/42606/"
] | I made multiple custom search on my wordpress site to find post with category search. Like this:
```
<select id="category-select" name="category-select">
<option value="6">Todo</option>
<option value="7">Spain</option>
<option value="8">Europe</option>
<option value="30">Rest of the Wor... | Not 100% sure I understand the question or problem, but this ought to work, I think:
```
add_action( 'the_post', 'output_my_custom_field');
function output_my_custom_field( $post_object ) {
$post_id = $post_object->ID;
// why the conditional (and redundant !empty) ?
// if ( !empty($post_id) ) ) {
... |
247,645 | <p>I have one template file <code>videos.php</code> which has the following line of code in it (aswell as a load of HTML):</p>
<p><code><?php get_template_part('loop', 'feed-videos' ); ?></code></p>
<p>inside that template part, I have the following:</p>
<pre><code><?php $video = 'video-' . $post->ID; ?&... | [
{
"answer_id": 247646,
"author": "Dan.",
"author_id": 97196,
"author_profile": "https://wordpress.stackexchange.com/users/97196",
"pm_score": 4,
"selected": true,
"text": "<p>If you use <code>locate_template()</code> instead of <code>get_template_part()</code> you can use all variables i... | 2016/11/28 | [
"https://wordpress.stackexchange.com/questions/247645",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | I have one template file `videos.php` which has the following line of code in it (aswell as a load of HTML):
`<?php get_template_part('loop', 'feed-videos' ); ?>`
inside that template part, I have the following:
```
<?php $video = 'video-' . $post->ID; ?>
<?php get_template_part( 'include', 'modal-video' ); ?>
```
... | If you use `locate_template()` instead of `get_template_part()` you can use all variables in that script:
```
include(locate_template('include-modal-video.php'));
```
Then, `<h2>00: <?php echo $video; ?></h2>` will work.
**UPDATE:**
Since WP version 5.5, you can pass arbitrary data to `get_template_part()` for use... |
247,654 | <p>I have part search function in my WordPress website which uses dynamic dependent select box.</p>
<p>However, now I have the following problem:</p>
<p><strong>If only select the first one box, or select the first two boxes, and click the <code>Search</code> button, it successfully jumps to the result page.</strong>... | [
{
"answer_id": 264147,
"author": "Nate",
"author_id": 87380,
"author_profile": "https://wordpress.stackexchange.com/users/87380",
"pm_score": 0,
"selected": false,
"text": "<p>You don't need any mySQL queries. WordPress's default search is submitting \"s\" with the URL. You can accomplis... | 2016/11/28 | [
"https://wordpress.stackexchange.com/questions/247654",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107752/"
] | I have part search function in my WordPress website which uses dynamic dependent select box.
However, now I have the following problem:
**If only select the first one box, or select the first two boxes, and click the `Search` button, it successfully jumps to the result page.**
**However, if continuously select the t... | To create your own independent search functionality, follow these steps.
**1-** You need a form to send the data for you. This is a simple form that can do this for you:
```
<form method="post" name="car-select" action="<?php echo site_url('/my-page/'); ?>">
<select name="make">
<option value="benz">Benz<... |
247,680 | <p>I have categories the names of which are 1 to 25. But the WordPress ordering system doesn't work correctly. It orders them as 1,10,11,12,13...2,21,22,23,24,25. I don't want to add 0 to 1-9 numbers. How can I fix this issue? </p>
<p>This is my code:</p>
<pre><code><li class="categoriesx <?php echo print_categ... | [
{
"answer_id": 247682,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 0,
"selected": false,
"text": "<p>WordPress will order your categories alphabetically, which leads to the result you get. You want to order them n... | 2016/11/28 | [
"https://wordpress.stackexchange.com/questions/247680",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106214/"
] | I have categories the names of which are 1 to 25. But the WordPress ordering system doesn't work correctly. It orders them as 1,10,11,12,13...2,21,22,23,24,25. I don't want to add 0 to 1-9 numbers. How can I fix this issue?
This is my code:
```
<li class="categoriesx <?php echo print_category_slug( get_the_category(... | Based on the research I've done on this, using term meta data is a better all around approach to ordering terms.
However, I was able come up with this snippet which does sort the terms by their name, numerically:
```
add_filter( 'terms_clauses', 'wpse247680_terms_clauses', 10, 3 );
function wpse247680_terms_clauses( ... |
247,685 | <p>I have a code which wraps every 4 posts in div. How can I adapt it to wrap every month posts in div.</p>
<pre><code><?php
$args = array(
'post_type' => 'posts',
'posts_per_page' => -1,
'order' => 'DESC'
);
$the_query = new WP_Query($args);
if ($the_query->have_posts()) :
$counter = 0... | [
{
"answer_id": 247771,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 3,
"selected": true,
"text": "<pre><code>$last_month = null;\n\nwhile ( $the_query->have_posts() ) :\n $the_query->the_post();\n ... | 2016/11/28 | [
"https://wordpress.stackexchange.com/questions/247685",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40822/"
] | I have a code which wraps every 4 posts in div. How can I adapt it to wrap every month posts in div.
```
<?php
$args = array(
'post_type' => 'posts',
'posts_per_page' => -1,
'order' => 'DESC'
);
$the_query = new WP_Query($args);
if ($the_query->have_posts()) :
$counter = 0;
while ($the_query->have... | ```
$last_month = null;
while ( $the_query->have_posts() ) :
$the_query->the_post();
$the_month = get_the_time( 'Ym' ); // e.g. 201611
if ( $last_month !== $the_month ) {
if ( $last_month !== null ) {
// Close previously opened <div class="row" />
echo '</div>';
}
... |
247,699 | <p>I am looking for the font used in Wordpress, in the Customizer, describing what theme you are using see my graphic.
<a href="https://i.stack.imgur.com/3Mo6e.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3Mo6e.jpg" alt="Font used in Customizer"></a></p>
| [
{
"answer_id": 247700,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 2,
"selected": false,
"text": "<p>As of core version 4.6 WP went from web fonts back to using system fonts:</p>\n\n<blockquote>\n <p>As such, the fo... | 2016/11/29 | [
"https://wordpress.stackexchange.com/questions/247699",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107909/"
] | I am looking for the font used in Wordpress, in the Customizer, describing what theme you are using see my graphic.
[](https://i.stack.imgur.com/3Mo6e.jpg) | As of core version 4.6 WP went from web fonts back to using system fonts:
>
> As such, the font stack includes the following:
>
>
> * -apple-system for Safari (iOS & macOS) and Firefox macOS
> * BlinkMacSystemFont for Chrome macOS
> * Segoe UI for Windows
> * Roboto for Android and Chrome OS
> * Oxygen-Sans for KDE... |
247,708 | <p>Like the title suggests, I'm not too sure how to change the version of a .css file in my theme. At the moment the .css versioning is like this: </p>
<pre><code><link rel='stylesheet' id='xxxx' href='https://www. site css/ styles.css?ver=4.6.1' type='text/css' media='all' />
</code></pre>
<p>Is there a scrip... | [
{
"answer_id": 247709,
"author": "Dave Romsey",
"author_id": 2807,
"author_profile": "https://wordpress.stackexchange.com/users/2807",
"pm_score": 5,
"selected": true,
"text": "<p>The fourth argument, <code>$ver</code> for <a href=\"https://developer.wordpress.org/reference/functions/wp_... | 2016/11/29 | [
"https://wordpress.stackexchange.com/questions/247708",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93691/"
] | Like the title suggests, I'm not too sure how to change the version of a .css file in my theme. At the moment the .css versioning is like this:
```
<link rel='stylesheet' id='xxxx' href='https://www. site css/ styles.css?ver=4.6.1' type='text/css' media='all' />
```
Is there a script that I need to run - where sho... | The fourth argument, `$ver` for [`wp_enqueue_style()`](https://developer.wordpress.org/reference/functions/wp_enqueue_style/) allows you to set the version:
```
wp_enqueue_style( string $handle,
string $src = false,
array $deps = array(),
string|bool|null $ver = fa... |
247,711 | <p>I'm learning from a plugin development course, and encountered two different internationalization functions:</p>
<pre><code><?php __('Newsletter Subscriber', 'ns_domain'); ?>
</code></pre>
<p>&</p>
<pre><code><?php _e('Title:'); ?>
</code></pre>
<p>I cannot find any reference information on when ... | [
{
"answer_id": 247712,
"author": "Dave Romsey",
"author_id": 2807,
"author_profile": "https://wordpress.stackexchange.com/users/2807",
"pm_score": 3,
"selected": true,
"text": "<p><a href=\"https://codex.wordpress.org/Function_Reference/_2\" rel=\"nofollow noreferrer\"><code>__()</code><... | 2016/11/29 | [
"https://wordpress.stackexchange.com/questions/247711",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3206/"
] | I'm learning from a plugin development course, and encountered two different internationalization functions:
```
<?php __('Newsletter Subscriber', 'ns_domain'); ?>
```
&
```
<?php _e('Title:'); ?>
```
I cannot find any reference information on when to use each one of these.
Can you point me in the right directio... | [`__()`](https://codex.wordpress.org/Function_Reference/_2) "Retrieves the translated string from the translate() function" without echoing. `_e()` does the same thing but echos the output.
For more information, take a look at these help articles:
* [Internationalization](https://developer.wordpress.org/plugins/inter... |
247,729 | <p>I have written a functionality like super admin can put user accounts on "hold". I have to make sure the user account which put his account on hold unable to login. The problem here is the user is able to login if still his account is on hold. I am using a 'custom user meta' field called 'holdUser' while super admin... | [
{
"answer_id": 247731,
"author": "Dan.",
"author_id": 97196,
"author_profile": "https://wordpress.stackexchange.com/users/97196",
"pm_score": 0,
"selected": false,
"text": "<p>Use the <code>wp_authenticate_user</code> filter and return a <code>WP_Error</code> to stop the login.</p>\n\n<p... | 2016/11/29 | [
"https://wordpress.stackexchange.com/questions/247729",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106542/"
] | I have written a functionality like super admin can put user accounts on "hold". I have to make sure the user account which put his account on hold unable to login. The problem here is the user is able to login if still his account is on hold. I am using a 'custom user meta' field called 'holdUser' while super admin pu... | ```
function myplugin_authenticate_on_hold($user)
{
// username and password are correct
if ($user instanceof WP_User) {
$on_hold = get_user_meta($user->ID, 'is_on_hold', true);
if ($on_hold) {
return new WP_Error('on_hold_error', 'You are on hold');
}
}
return $user... |
247,730 | <p>How can I retrieve the current URL (whether homepage, archive, post type archive, category archive, etc) but always <strong>without</strong> the <code>/page/{pagenum}/</code> part if it's present? So, if the real URL is: </p>
<p><code>example.com/category/uncategorized/</code> </p>
<p>OR</p>
<p><code>example.com/... | [
{
"answer_id": 247732,
"author": "Fabian Marz",
"author_id": 77421,
"author_profile": "https://wordpress.stackexchange.com/users/77421",
"pm_score": -1,
"selected": false,
"text": "<p>While this question was already answered <a href=\"https://wordpress.stackexchange.com/questions/83999/g... | 2016/11/29 | [
"https://wordpress.stackexchange.com/questions/247730",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/47359/"
] | How can I retrieve the current URL (whether homepage, archive, post type archive, category archive, etc) but always **without** the `/page/{pagenum}/` part if it's present? So, if the real URL is:
`example.com/category/uncategorized/`
OR
`example.com/category/uncategorized/page/2/`
then the return value will alwa... | You can get the current URL through `home_url( $wp->request )`.
Try the example below:
```
global $wp;
// get current url with query string.
$current_url = home_url( $wp->request );
// get the position where '/page.. ' text start.
$pos = strpos($current_url , '/page');
// remove string from the specific postion
... |
247,751 | <p>I have found the following function to change the behavour of the Wordpress tag cloud:</p>
<pre><code>function widget_custom_tag_cloud($args) {
$args['orderby'] = 'count';
return $args;
}
add_filter( 'widget_tag_cloud_args', 'widget_custom_tag_cloud' );
</code></pre>
<p>However, I need to change the order... | [
{
"answer_id": 247752,
"author": "Dan.",
"author_id": 97196,
"author_profile": "https://wordpress.stackexchange.com/users/97196",
"pm_score": 3,
"selected": true,
"text": "<p>Tags (terms) do not have a <code>menu_order</code> (see the design of the table in the DB). </p>\n\n<p>If you wan... | 2016/11/29 | [
"https://wordpress.stackexchange.com/questions/247751",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84924/"
] | I have found the following function to change the behavour of the Wordpress tag cloud:
```
function widget_custom_tag_cloud($args) {
$args['orderby'] = 'count';
return $args;
}
add_filter( 'widget_tag_cloud_args', 'widget_custom_tag_cloud' );
```
However, I need to change the order from 'count' to 'menu\_or... | Tags (terms) do not have a `menu_order` (see the design of the table in the DB).
If you want to give terms a 'menu\_order' you will need to create this yourself.
As long as your WP is >= 4.4.0, you can make use of the feature `term_meta`.
This is to terms what post meta is to posts.
You can create a 'menu\_order' ... |
247,766 | <p>I've installed Woocomerce plugin and custom post type 'product'. There are also categories of this type named 'product_cat'. I need to display name of categories on single-product.php</p>
<p>I've tried in this way:</p>
<pre><code><?php $term = get_term_by( 'name', get_query_var( 'term' ), get_query_var( 'taxono... | [
{
"answer_id": 247752,
"author": "Dan.",
"author_id": 97196,
"author_profile": "https://wordpress.stackexchange.com/users/97196",
"pm_score": 3,
"selected": true,
"text": "<p>Tags (terms) do not have a <code>menu_order</code> (see the design of the table in the DB). </p>\n\n<p>If you wan... | 2016/11/29 | [
"https://wordpress.stackexchange.com/questions/247766",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107941/"
] | I've installed Woocomerce plugin and custom post type 'product'. There are also categories of this type named 'product\_cat'. I need to display name of categories on single-product.php
I've tried in this way:
```
<?php $term = get_term_by( 'name', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->na... | Tags (terms) do not have a `menu_order` (see the design of the table in the DB).
If you want to give terms a 'menu\_order' you will need to create this yourself.
As long as your WP is >= 4.4.0, you can make use of the feature `term_meta`.
This is to terms what post meta is to posts.
You can create a 'menu\_order' ... |
247,773 | <p>I'm looking to create and display a separate menu for a specific page. This menu needs to be in the primary location. So for example, on the Home page and the Contact page you would have: Home | About us | Contact. And on the "About us" page, you could show a different menu for example: Menu link 1 | Menu link 2 | M... | [
{
"answer_id": 247776,
"author": "Fabian Marz",
"author_id": 77421,
"author_profile": "https://wordpress.stackexchange.com/users/77421",
"pm_score": 2,
"selected": true,
"text": "<p>As you can read from the <a href=\"https://codex.wordpress.org/Function_Reference/register_nav_menu\" rel=... | 2016/11/29 | [
"https://wordpress.stackexchange.com/questions/247773",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98778/"
] | I'm looking to create and display a separate menu for a specific page. This menu needs to be in the primary location. So for example, on the Home page and the Contact page you would have: Home | About us | Contact. And on the "About us" page, you could show a different menu for example: Menu link 1 | Menu link 2 | Menu... | As you can read from the [documentation](https://codex.wordpress.org/Function_Reference/register_nav_menu) `register_nav_menu` is used to register a menu in the menu editor. Your code will affect the backend only. Also you should pass a slug like string as the first parameter. If you want to change the display of the m... |
247,782 | <p>Is there a way (and if so, 'how?') to apply a conditional to a page/post for which the slug contains a specific word.</p>
<p>In the case of the Codex example of:</p>
<pre><code>is_single( 'beef-stew' )
</code></pre>
<p>The condition will still apply if the slug contains 'beef', rather than being 'beef-stew'.</p>
... | [
{
"answer_id": 247783,
"author": "Howdy_McGee",
"author_id": 7355,
"author_profile": "https://wordpress.stackexchange.com/users/7355",
"pm_score": 3,
"selected": false,
"text": "<p>WordPress has no conditional for substring testing but you can do this using PHPs built-in function: <a hre... | 2016/11/29 | [
"https://wordpress.stackexchange.com/questions/247782",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/103213/"
] | Is there a way (and if so, 'how?') to apply a conditional to a page/post for which the slug contains a specific word.
In the case of the Codex example of:
```
is_single( 'beef-stew' )
```
The condition will still apply if the slug contains 'beef', rather than being 'beef-stew'.
UPDATE: In response to a request for... | WordPress has no conditional for substring testing but you can do this using PHPs built-in function: [`strpos()`](http://php.net/manual/en/function.strpos.php)
```
global $post;
if( false !== strpos( $post->post_name, 'beef' ) ) {
// Do Things
}
```
The above returns true if `beef` is found somewhere in the pos... |
247,790 | <p>Is there a possible way to get the alt text from the media file by just knowing the URL? For example, if the path to my image is <code>/bc/wp-content/uploads/placeholder-image.png</code> is there a way (just by using that URL) to get the alt text of that image. I know you usually need the ID and such, trying to find... | [
{
"answer_id": 247792,
"author": "socki03",
"author_id": 43511,
"author_profile": "https://wordpress.stackexchange.com/users/43511",
"pm_score": 3,
"selected": false,
"text": "<p>Using the function found <a href=\"https://pippinsplugins.com/retrieve-attachment-id-from-image-url/\" rel=\"... | 2016/11/29 | [
"https://wordpress.stackexchange.com/questions/247790",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93770/"
] | Is there a possible way to get the alt text from the media file by just knowing the URL? For example, if the path to my image is `/bc/wp-content/uploads/placeholder-image.png` is there a way (just by using that URL) to get the alt text of that image. I know you usually need the ID and such, trying to find a way around ... | Using the function found [here](https://pippinsplugins.com/retrieve-attachment-id-from-image-url/), you could add this to your functions.php
```
// retrieves the attachment ID from the file URL
function pippin_get_image_id($image_url) {
global $wpdb;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM ... |
247,800 | <p>I know this has been discussed in a couple of other posts but none of them seem to have the correct answer/solution to the question. I tried using all the suggested functions mentioned in the other posts but none seem to work. When a wrong password is introduced nothing happens(just the standard redirect to the same... | [
{
"answer_id": 247942,
"author": "Michelle",
"author_id": 16,
"author_profile": "https://wordpress.stackexchange.com/users/16",
"pm_score": 1,
"selected": false,
"text": "<p>Try this:</p>\n\n<pre><code>add_filter( 'the_password_form', 'wpse_71284_custom_post_password_msg' );\n\n/**\n * A... | 2016/11/29 | [
"https://wordpress.stackexchange.com/questions/247800",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107950/"
] | I know this has been discussed in a couple of other posts but none of them seem to have the correct answer/solution to the question. I tried using all the suggested functions mentioned in the other posts but none seem to work. When a wrong password is introduced nothing happens(just the standard redirect to the same pa... | Try this:
```
add_filter( 'the_password_form', 'wpse_71284_custom_post_password_msg' );
/**
* Add a message to the password form.
*
* @wp-hook the_password_form
* @param string $form
* @return string
*/
function wpse_71284_custom_post_password_msg( $form )
{
// No cookie, the user has not sent anything u... |
247,806 | <p>I have a page that I designated as my front page using the <code>reading</code> portion of settings in the dashboard. When I place a script inside of an if statement using <code>is_front_page</code> in functions.php, it only runs on that designated front-page, and not the others (indicating the page has been designa... | [
{
"answer_id": 247811,
"author": "sMyles",
"author_id": 51201,
"author_profile": "https://wordpress.stackexchange.com/users/51201",
"pm_score": 4,
"selected": true,
"text": "<p>Yes it should work in the header file just like normal. Try using a standard IF statement instead of shorthand... | 2016/11/29 | [
"https://wordpress.stackexchange.com/questions/247806",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/105196/"
] | I have a page that I designated as my front page using the `reading` portion of settings in the dashboard. When I place a script inside of an if statement using `is_front_page` in functions.php, it only runs on that designated front-page, and not the others (indicating the page has been designated correctly).
However... | Yes it should work in the header file just like normal. Try using a standard IF statement instead of shorthand:
```
if( is_front_page() ){
echo 'Front page!';
}
```
You must have it configured in the settings to use:
`A static page (select below)` instead of `Your latest posts`
If you want `is_front_page()` to... |
247,808 | <p>I have an expiry date ACF field <code>'post_end_date'</code> which has been applied to multiple post types, including <code>'post'</code>.</p>
<p>I'm trying to filter out any posts, across the entire site, where today's date is greater than the value <code>'post_end_date'</code>; in other words the post has expired... | [
{
"answer_id": 247811,
"author": "sMyles",
"author_id": 51201,
"author_profile": "https://wordpress.stackexchange.com/users/51201",
"pm_score": 4,
"selected": true,
"text": "<p>Yes it should work in the header file just like normal. Try using a standard IF statement instead of shorthand... | 2016/11/29 | [
"https://wordpress.stackexchange.com/questions/247808",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/47170/"
] | I have an expiry date ACF field `'post_end_date'` which has been applied to multiple post types, including `'post'`.
I'm trying to filter out any posts, across the entire site, where today's date is greater than the value `'post_end_date'`; in other words the post has expired. I've checked that `'post_end_date'` value... | Yes it should work in the header file just like normal. Try using a standard IF statement instead of shorthand:
```
if( is_front_page() ){
echo 'Front page!';
}
```
You must have it configured in the settings to use:
`A static page (select below)` instead of `Your latest posts`
If you want `is_front_page()` to... |
247,858 | <p>I am creating a menu for a documentation site very much like this: <a href="http://getbootstrap.com/components/" rel="nofollow noreferrer">http://getbootstrap.com/components/</a></p>
<p>I am using a hierarchical custom post type (manual).
I am currently using wp_list_pages() to output the list. This gives me the n... | [
{
"answer_id": 247864,
"author": "GKS",
"author_id": 90674,
"author_profile": "https://wordpress.stackexchange.com/users/90674",
"pm_score": 0,
"selected": false,
"text": "<p>You can done this by creating you custom Walker class and pass it's instance as argument while calling <code>wp_l... | 2016/11/30 | [
"https://wordpress.stackexchange.com/questions/247858",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/99008/"
] | I am creating a menu for a documentation site very much like this: <http://getbootstrap.com/components/>
I am using a hierarchical custom post type (manual).
I am currently using wp\_list\_pages() to output the list. This gives me the nested structure that I am looking for:
```
<ul>
<li>Parent Post</li>
<ul>
... | You could add a filter on `post_type_link`, which allows modification of custom post type permalinks before they are output.
The filter passes the custom post object as the 2nd argument, so we can use that to get the ID and form the new permalink:
```
function wpd_list_pages_permalink_filter( $permalink, $page ){
... |
247,859 | <p>I need to get the category id of the current post outside the loop. First I get the category based on the post id:</p>
<pre><code>global $wp_query;
$postcat = get_the_category( $wp_query->post->ID );
</code></pre>
<p>Now how to get the category id? I tried: <code>$cat_id = $postcat->term_id;</code> but it... | [
{
"answer_id": 247860,
"author": "GKS",
"author_id": 90674,
"author_profile": "https://wordpress.stackexchange.com/users/90674",
"pm_score": 4,
"selected": false,
"text": "<p>When you use <code>get_the_category()</code> function to get category's data, it return the array of object so yo... | 2016/11/30 | [
"https://wordpress.stackexchange.com/questions/247859",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/68414/"
] | I need to get the category id of the current post outside the loop. First I get the category based on the post id:
```
global $wp_query;
$postcat = get_the_category( $wp_query->post->ID );
```
Now how to get the category id? I tried: `$cat_id = $postcat->term_id;` but it's not working. | ```
function catName($cat_id) {
$cat_id = (int) $cat_id;
$category = &get_category($cat_id);
return $category->name;
}
function catLink($cat_id) {
$category = get_the_category();
$category_link = get_category_link($cat_id);
echo $category_link;
}
function catCustom() {
$cats = get_the_catego... |
247,862 | <p>The WP REST API exposes a lot of information so I filter endpoints that aren't needed to expose. </p>
<p>I can't filter everything: The location of needed media files are exposed for example.</p>
<p>As an extra protection I'd like to mystify the default uri.</p>
<p>I would like to change for example: <code>http:/... | [
{
"answer_id": 247882,
"author": "Dan.",
"author_id": 97196,
"author_profile": "https://wordpress.stackexchange.com/users/97196",
"pm_score": 0,
"selected": false,
"text": "<p>You could use the <code>json_url_prefix</code> hook to remove <code>'wp-json'</code> across all API routes. The ... | 2016/11/30 | [
"https://wordpress.stackexchange.com/questions/247862",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/44262/"
] | The WP REST API exposes a lot of information so I filter endpoints that aren't needed to expose.
I can't filter everything: The location of needed media files are exposed for example.
As an extra protection I'd like to mystify the default uri.
I would like to change for example: `http://example.com/wp-json/wp/v2/` ... | Please note that for current versions of WordPress, using the `json_url_prefix` filter no longer works.
On WordPress 4.7 (and using the REST API from the core instead of a plugin), this is what I needed to change the API prefix.
```
add_filter( 'rest_url_prefix', 'my_theme_api_slug');
function my_theme_api_slug( $s... |
247,888 | <p>I have created a custom post type for "Solutions" which will eventually replace all products that have been added in Woocommerce as I no longer have the need for a shopping cart.</p>
<p>So I need to copy the data from each product to a new 'solution' CPT. </p>
<p>I have the below code to set up the new post type:... | [
{
"answer_id": 248142,
"author": "Vitaliy Kukin",
"author_id": 34421,
"author_profile": "https://wordpress.stackexchange.com/users/34421",
"pm_score": 0,
"selected": false,
"text": "<p>You are replaced only slug but not a post type. To move all post type product to solution you should go... | 2016/11/30 | [
"https://wordpress.stackexchange.com/questions/247888",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/70019/"
] | I have created a custom post type for "Solutions" which will eventually replace all products that have been added in Woocommerce as I no longer have the need for a shopping cart.
So I need to copy the data from each product to a new 'solution' CPT.
I have the below code to set up the new post type:
```
function cre... | Looks like slugs have to be unique for all posts according to wordpress documentation.
>
> Post slugs must be unique across all posts
>
>
>
Therefore it is not possible to have the same slug for woocommcerce products and the CPT as I assume Woocommcerce Products are just posts. I will have to have a different slu... |
247,895 | <p>I'm using the following code to filter posts on category pages so only sticky posts are displayed.</p>
<pre><code>add_action( 'pre_get_posts', function( \WP_Query $q ) {
if( ! is_admin() && $q->is_category() && $q->is_main_query() ) {
$sticky_posts = get_option( 'sticky_posts' );
if( !... | [
{
"answer_id": 247898,
"author": "Ellimist",
"author_id": 28296,
"author_profile": "https://wordpress.stackexchange.com/users/28296",
"pm_score": 3,
"selected": true,
"text": "<p>Just set 'post__in' to a null array.</p>\n\n<pre><code>add_action( 'pre_get_posts', function( \\WP_Query $q )... | 2016/11/30 | [
"https://wordpress.stackexchange.com/questions/247895",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/68414/"
] | I'm using the following code to filter posts on category pages so only sticky posts are displayed.
```
add_action( 'pre_get_posts', function( \WP_Query $q ) {
if( ! is_admin() && $q->is_category() && $q->is_main_query() ) {
$sticky_posts = get_option( 'sticky_posts' );
if( ! empty( $sticky_posts ) )
$q... | Just set 'post\_\_in' to a null array.
```
add_action( 'pre_get_posts', function( \WP_Query $q ) {
if( ! is_admin() && $q->is_category() && $q->is_main_query() ) {
$sticky_posts = get_option( 'sticky_posts' );
//If there are sticky posts
if( ! empty( $sticky_posts ) ) {
$q->set( 'post__in', (array)... |
247,899 | <p>I have multiple Wordpress installations on MAMP, which all have their own file structure (wp-admin, wp-includes etc.).</p>
<p>Because they are all development sites, it doesn't make sense to include the whole wordpress installation for every site.</p>
<p>Is it possible to only have one instance of Wordpress, and s... | [
{
"answer_id": 247898,
"author": "Ellimist",
"author_id": 28296,
"author_profile": "https://wordpress.stackexchange.com/users/28296",
"pm_score": 3,
"selected": true,
"text": "<p>Just set 'post__in' to a null array.</p>\n\n<pre><code>add_action( 'pre_get_posts', function( \\WP_Query $q )... | 2016/11/30 | [
"https://wordpress.stackexchange.com/questions/247899",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/48745/"
] | I have multiple Wordpress installations on MAMP, which all have their own file structure (wp-admin, wp-includes etc.).
Because they are all development sites, it doesn't make sense to include the whole wordpress installation for every site.
Is it possible to only have one instance of Wordpress, and somehow link the c... | Just set 'post\_\_in' to a null array.
```
add_action( 'pre_get_posts', function( \WP_Query $q ) {
if( ! is_admin() && $q->is_category() && $q->is_main_query() ) {
$sticky_posts = get_option( 'sticky_posts' );
//If there are sticky posts
if( ! empty( $sticky_posts ) ) {
$q->set( 'post__in', (array)... |
247,948 | <p>I am trying to get from this kind of url:</p>
<pre><code>domain.com/page/classes/?language=english&need=pro
</code></pre>
<p>To this:</p>
<pre><code>domain.com/class/english-pro
</code></pre>
<hr>
<p><strong>MORE INFORMATIONS</strong></p>
<p>Both variables have been added as <code>query_vars</code>. <code>... | [
{
"answer_id": 248322,
"author": "Varun Kumar",
"author_id": 103095,
"author_profile": "https://wordpress.stackexchange.com/users/103095",
"pm_score": 1,
"selected": false,
"text": "<p>Hope this will work out for as it did for me.</p>\n\n<pre><code>add_filter('rewrite_rules_array', 'inse... | 2016/11/30 | [
"https://wordpress.stackexchange.com/questions/247948",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/54879/"
] | I am trying to get from this kind of url:
```
domain.com/page/classes/?language=english&need=pro
```
To this:
```
domain.com/class/english-pro
```
---
**MORE INFORMATIONS**
Both variables have been added as `query_vars`. `classes` is the current page and `page` is the parent page.
---
**WHAT I'VE TRIED**
Her... | Alright, I've changed my way of thinking about this issue and as I don't really know where the problem comes from I have opted for another solution.
**I am using a `wp_safe_redirect` to the url of the corresponding custom post type**.
For those interested in the solution, my form action is the `permalink` of a page ... |
247,967 | <p>I have a custom post type 'University' on my website. Each university has post type 'Students'. So this is how it appears on hyperlinks: </p>
<p>www.abc.com/university/ali</p>
<p>now I want to make another university list and want the information to be displayed as </p>
<ul>
<li>www.abc.com/2015/university/ali </... | [
{
"answer_id": 248022,
"author": "Sonali",
"author_id": 84167,
"author_profile": "https://wordpress.stackexchange.com/users/84167",
"pm_score": 0,
"selected": false,
"text": "<p>Use '<a href=\"https://wordpress.org/plugins/custom-post-type-permalinks/\" rel=\"nofollow noreferrer\">custom... | 2016/11/30 | [
"https://wordpress.stackexchange.com/questions/247967",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24020/"
] | I have a custom post type 'University' on my website. Each university has post type 'Students'. So this is how it appears on hyperlinks:
www.abc.com/university/ali
now I want to make another university list and want the information to be displayed as
* www.abc.com/2015/university/ali
* www.abc.com/2016/university/... | I have created 'project' posttype and 'project\_category' texonomy.Now you have to do is that go to add new project and add that project category that you want to show before your custom posttype name and permalink means add any post inside 2016 category.And set link as custom posttype '/%postname%/.try this code in yo... |
248,006 | <p>I have a problem with ACF plugin.</p>
<pre><code>function add_custom_post(/* .. */){}
$post_id = wp_insert_post(array(
//....
));
update_field('fieldname', $value, $post_id);
return (bool)$post_id;
}
</code></pre>
<p>Symptoms: <code><?php the_field('fieldname'); ?></code> does not retur... | [
{
"answer_id": 248007,
"author": "Dan.",
"author_id": 97196,
"author_profile": "https://wordpress.stackexchange.com/users/97196",
"pm_score": 2,
"selected": false,
"text": "<p>You can do this instead of using <code>update_field()</code>:</p>\n\n<pre><code>update_post_meta($post_id, 'fiel... | 2016/12/01 | [
"https://wordpress.stackexchange.com/questions/248006",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108073/"
] | I have a problem with ACF plugin.
```
function add_custom_post(/* .. */){}
$post_id = wp_insert_post(array(
//....
));
update_field('fieldname', $value, $post_id);
return (bool)$post_id;
}
```
Symptoms: `<?php the_field('fieldname'); ?>` does not return value in template;
Fields are saved and v... | You can do this instead of using `update_field()`:
```
update_post_meta($post_id, 'fieldname', $value);
update_post_meta($post_id, '_fieldname', 'field_' . uniqid()); // `uniqid() is a native PHP function. This is also how ACF creates the field keys
```
Also, depending where you are retrieving the value, you may als... |
248,011 | <p>I want to know that is it possible to fire a stored procedure once the plugin is activated? <br></p>
<pre><code>//action hook for plugin activation
register_activation_hook( __FILE__, 'my_func' );
//function to create stored procedure
function my_func()
{
//code goes here to create a stored procedure
}
</code></pr... | [
{
"answer_id": 248007,
"author": "Dan.",
"author_id": 97196,
"author_profile": "https://wordpress.stackexchange.com/users/97196",
"pm_score": 2,
"selected": false,
"text": "<p>You can do this instead of using <code>update_field()</code>:</p>\n\n<pre><code>update_post_meta($post_id, 'fiel... | 2016/12/01 | [
"https://wordpress.stackexchange.com/questions/248011",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/82089/"
] | I want to know that is it possible to fire a stored procedure once the plugin is activated?
```
//action hook for plugin activation
register_activation_hook( __FILE__, 'my_func' );
//function to create stored procedure
function my_func()
{
//code goes here to create a stored procedure
}
```
Any help would be app... | You can do this instead of using `update_field()`:
```
update_post_meta($post_id, 'fieldname', $value);
update_post_meta($post_id, '_fieldname', 'field_' . uniqid()); // `uniqid() is a native PHP function. This is also how ACF creates the field keys
```
Also, depending where you are retrieving the value, you may als... |
248,026 | <p>I am using <a href="https://developer.wordpress.org/reference/functions/wp_dropdown_categories/" rel="nofollow noreferrer">wp_dropdown_categories</a> to create a dropdown in the frontend. It creates a nice dropdown select. Now I would like to add <code>onchange="myFunc()"</code> to the <code><select></code>. I... | [
{
"answer_id": 248007,
"author": "Dan.",
"author_id": 97196,
"author_profile": "https://wordpress.stackexchange.com/users/97196",
"pm_score": 2,
"selected": false,
"text": "<p>You can do this instead of using <code>update_field()</code>:</p>\n\n<pre><code>update_post_meta($post_id, 'fiel... | 2016/12/01 | [
"https://wordpress.stackexchange.com/questions/248026",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25508/"
] | I am using [wp\_dropdown\_categories](https://developer.wordpress.org/reference/functions/wp_dropdown_categories/) to create a dropdown in the frontend. It creates a nice dropdown select. Now I would like to add `onchange="myFunc()"` to the `<select>`. I need this to trigger some js function when someone selects specif... | You can do this instead of using `update_field()`:
```
update_post_meta($post_id, 'fieldname', $value);
update_post_meta($post_id, '_fieldname', 'field_' . uniqid()); // `uniqid() is a native PHP function. This is also how ACF creates the field keys
```
Also, depending where you are retrieving the value, you may als... |
248,051 | <p>I've got the following code on my home page</p>
<pre><code><?php echo '<img class="img-responsive" src="',
wp_get_attachment_image_src( get_post_thumbnail_id(), 'Large' )[0], '">'; ?>
</code></pre>
<p>The large size in this case is 1920x245. This works fine in a browser but when the image scales ... | [
{
"answer_id": 248048,
"author": "Tyler Johnson",
"author_id": 57451,
"author_profile": "https://wordpress.stackexchange.com/users/57451",
"pm_score": 1,
"selected": false,
"text": "<p>Honestly, the best way to do this is to run some queries on the database using regex to search and repl... | 2016/12/01 | [
"https://wordpress.stackexchange.com/questions/248051",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/101491/"
] | I've got the following code on my home page
```
<?php echo '<img class="img-responsive" src="',
wp_get_attachment_image_src( get_post_thumbnail_id(), 'Large' )[0], '">'; ?>
```
The large size in this case is 1920x245. This works fine in a browser but when the image scales down on smaller screens it's too thin ... | Honestly, the best way to do this is to run some queries on the database using regex to search and replace, after the database has been backed up of course.
Before learning more about SQL, I used this: <https://interconnectit.com/products/search-and-replace-for-wordpress-databases/>, which should work for you in this... |
248,064 | <p>I have a wordpress website which I want to change, and it will takes me some months. My idea is create a subfolder in the root directory where I can set the a clone of my website to make some changes over it and at the same time keep the old website alive. </p>
<p>So if my website is:</p>
<pre><code>mysite.com
</c... | [
{
"answer_id": 248066,
"author": "socki03",
"author_id": 43511,
"author_profile": "https://wordpress.stackexchange.com/users/43511",
"pm_score": 1,
"selected": false,
"text": "<p>I'd recommend against using the same database for both. Primarily because the permalink structure would real... | 2016/12/01 | [
"https://wordpress.stackexchange.com/questions/248064",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107058/"
] | I have a wordpress website which I want to change, and it will takes me some months. My idea is create a subfolder in the root directory where I can set the a clone of my website to make some changes over it and at the same time keep the old website alive.
So if my website is:
```
mysite.com
```
My developing clon... | I'd recommend against using the same database for both. Primarily because the permalink structure would really only work for one, but also because it's very likely you'd make a change in the dev site that adversely affects your production site. If you decided to attempt something like this, all your media would still b... |
248,146 | <p>i am using wordpress custom post and register_taxonomy bellow is my code .</p>
<pre>
<code>
function epg_works_register() {
$labels = array(
'name' => __('Works'),
'singular_name' => __('Works'),
'add_new' => __('Add Works Item'),
'add_new_item' => __('Add New Works Item'),
... | [
{
"answer_id": 248152,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 2,
"selected": true,
"text": "<p>The only thing that I see is the argument <code>'query_var'=>true</code>, it can be set to false, but the de... | 2016/12/02 | [
"https://wordpress.stackexchange.com/questions/248146",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/83449/"
] | i am using wordpress custom post and register\_taxonomy bellow is my code .
```
function epg_works_register() {
$labels = array(
'name' => __('Works'),
'singular_name' => __('Works'),
'add_new' => __('Add Works Item'),
'add_new_item' => __('Add New Works Item'),
'edit_item'... | The only thing that I see is the argument `'query_var'=>true`, it can be set to false, but the default value is the taxonomy name, so set it to true is maybe the cause of the failure, even the codex example set it to true, I think it can be great to try
```
register_taxonomy(
'works_category',
'works', ... |
248,149 | <p>In chrome, firefox everything is fine.</p>
<p>On mobile ios safari it looks like the pic. The columns won't collapse into rows.</p>
<p>Tried the guide but didn't seem to work
<a href="https://css-tricks.com/accessible-simple-responsive-tables/" rel="nofollow noreferrer">https://css-tricks.com/accessible-simple-res... | [
{
"answer_id": 248175,
"author": "Rosenbruger",
"author_id": 108057,
"author_profile": "https://wordpress.stackexchange.com/users/108057",
"pm_score": 1,
"selected": false,
"text": "<p>I know it's bad practice to use !important frequently but you could use it on any style that's not show... | 2016/12/02 | [
"https://wordpress.stackexchange.com/questions/248149",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/102722/"
] | In chrome, firefox everything is fine.
On mobile ios safari it looks like the pic. The columns won't collapse into rows.
Tried the guide but didn't seem to work
<https://css-tricks.com/accessible-simple-responsive-tables/>
I've tried
-setting to display:block to collapse columns into rows on responsive mobile.
-set... | I know it's bad practice to use !important frequently but you could use it on any style that's not showing just to check if your theme is overriding your code. |
248,168 | <p>I'm encountering a strange issue with WordPress. I'm building a theme and the theme customization is driven by Customizer.</p>
<p>So, basically in functions.php I'm adding</p>
<pre><code>add_theme_support( 'widget-customizer' );
</code></pre>
<p>i'm registering a sidebar with:</p>
<pre><code>register_sidebar( ar... | [
{
"answer_id": 248175,
"author": "Rosenbruger",
"author_id": 108057,
"author_profile": "https://wordpress.stackexchange.com/users/108057",
"pm_score": 1,
"selected": false,
"text": "<p>I know it's bad practice to use !important frequently but you could use it on any style that's not show... | 2016/12/03 | [
"https://wordpress.stackexchange.com/questions/248168",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108200/"
] | I'm encountering a strange issue with WordPress. I'm building a theme and the theme customization is driven by Customizer.
So, basically in functions.php I'm adding
```
add_theme_support( 'widget-customizer' );
```
i'm registering a sidebar with:
```
register_sidebar( array(
'name' => __( 'Test Sidebar' ),
'... | I know it's bad practice to use !important frequently but you could use it on any style that's not showing just to check if your theme is overriding your code. |
248,182 | <p>All around the Interwebs I see advice from people who say that when you want to get posts in a custom taxonomy you should use the filter parameter, for example:</p>
<pre><code>https://example.com/wp-json/wp/v2/posts?filter[genre]=fiction
</code></pre>
<p>This seems like a very handy parameter. But in v2 of the WP ... | [
{
"answer_id": 248175,
"author": "Rosenbruger",
"author_id": 108057,
"author_profile": "https://wordpress.stackexchange.com/users/108057",
"pm_score": 1,
"selected": false,
"text": "<p>I know it's bad practice to use !important frequently but you could use it on any style that's not show... | 2016/12/03 | [
"https://wordpress.stackexchange.com/questions/248182",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14984/"
] | All around the Interwebs I see advice from people who say that when you want to get posts in a custom taxonomy you should use the filter parameter, for example:
```
https://example.com/wp-json/wp/v2/posts?filter[genre]=fiction
```
This seems like a very handy parameter. But in v2 of the WP REST API it just doesn't w... | I know it's bad practice to use !important frequently but you could use it on any style that's not showing just to check if your theme is overriding your code. |
248,207 | <p>I have a wordpress installation and I need this query on every post:</p>
<pre><code>select post_id, meta_key from wp_postmeta where meta_key = 'mykey' and meta_value = 'somevalue'
</code></pre>
<p>I have 3M rows on that table, and the query takes about 6 sec to complete. I think it should be much faster. If I show... | [
{
"answer_id": 280957,
"author": "Rick James",
"author_id": 120226,
"author_profile": "https://wordpress.stackexchange.com/users/120226",
"pm_score": 2,
"selected": false,
"text": "<p><code>wp_postmeta</code> has inefficient indexes. The published table (see Wikipedia) is </p>\n\n<pre><... | 2016/12/03 | [
"https://wordpress.stackexchange.com/questions/248207",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/105492/"
] | I have a wordpress installation and I need this query on every post:
```
select post_id, meta_key from wp_postmeta where meta_key = 'mykey' and meta_value = 'somevalue'
```
I have 3M rows on that table, and the query takes about 6 sec to complete. I think it should be much faster. If I show the index of the table, i... | `wp_postmeta` has inefficient indexes. The published table (see Wikipedia) is
```
CREATE TABLE wp_postmeta (
meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
post_id bigint(20) unsigned NOT NULL DEFAULT '0',
meta_key varchar(255) DEFAULT NULL,
meta_value longtext,
PRIMARY KEY (meta_id),
KEY post_id (p... |
248,276 | <p>I want to make a user-create snippet, but it must not includes plain password.</p>
<pre><code> $ wp user create username username@example.com --role=administrator --user_pass=password
</code></pre>
<p>So can I create (or update) user password by hashed value?</p>
| [
{
"answer_id": 248321,
"author": "thebigtine",
"author_id": 76059,
"author_profile": "https://wordpress.stackexchange.com/users/76059",
"pm_score": 2,
"selected": false,
"text": "<p>This should work:</p>\n\n<pre><code>wp user update USERNAME --user_pass=PASSWORD\n</code></pre>\n\n<p>Foun... | 2016/12/05 | [
"https://wordpress.stackexchange.com/questions/248276",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108292/"
] | I want to make a user-create snippet, but it must not includes plain password.
```
$ wp user create username username@example.com --role=administrator --user_pass=password
```
So can I create (or update) user password by hashed value? | There is not "one command" in Wordpress CLI that does the job: <https://github.com/wp-cli/wp-cli/issues/2270>
However using other commands, you can overide the user password directly in the database using the following:
```
USER_ID=$(wp user list --login="$USR_LOGIN" --format=ids)
wp db query "UPDATE wp_users SET use... |
248,279 | <p>I'd like to redirect user to login page on specific pages, after displaying message "You need to login to view this page".
I followed this documentation, but couldn't get through. <a href="https://codex.wordpress.org/Function_Reference/auth_redirect" rel="nofollow noreferrer">https://codex.wordpress.org/Function_Re... | [
{
"answer_id": 248280,
"author": "Sonali",
"author_id": 84167,
"author_profile": "https://wordpress.stackexchange.com/users/84167",
"pm_score": 0,
"selected": false,
"text": "<p>It works fine in our file, will you please give us bit of code in which filter or action you are running this ... | 2016/12/05 | [
"https://wordpress.stackexchange.com/questions/248279",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94247/"
] | I'd like to redirect user to login page on specific pages, after displaying message "You need to login to view this page".
I followed this documentation, but couldn't get through. <https://codex.wordpress.org/Function_Reference/auth_redirect> | You can do it like this in admin section-
```
add_action( 'admin_init', 'redirect_non_logged_users_to_specific_page' );
function redirect_non_logged_users_to_specific_page() {
if ( !is_user_logged_in() && is_page('add page slug or i.d here') &&
$_SERVER['PHP_SELF'] != '/wp-admin/admin-ajax.php' ) {
... |
248,311 | <p>I know how it is possible to wrap HTML around anchor elements with the inbuilt arguments for <code>wp_get_archives</code>. Is there a way to alter the content of the anchors in order to add a wrapping span for the anchor text?
The intention is to use it for a list of yearly archives on a category (i.e. an automated... | [
{
"answer_id": 248313,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 4,
"selected": true,
"text": "<h2>Span outside anchor tags</h2>\n\n<p>I think you're looking for the <code>before</code> and <code>after</code>... | 2016/12/05 | [
"https://wordpress.stackexchange.com/questions/248311",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25245/"
] | I know how it is possible to wrap HTML around anchor elements with the inbuilt arguments for `wp_get_archives`. Is there a way to alter the content of the anchors in order to add a wrapping span for the anchor text?
The intention is to use it for a list of yearly archives on a category (i.e. an automated list of years... | Span outside anchor tags
------------------------
I think you're looking for the `before` and `after` arguments (*PHP 5.4+*):
```
wp_get_archives(
[
'before' => '<span>',
'after' => '</span>'
]
);
```
if you want to wrap the `<span>` tag around the `<a>` tag:
```
<li><span><a href="xx">Lin... |
248,332 | <p>I need change the tagline to a custom, specific tagline, further describing my business such as - "self-funded revenue increase" but I can't find it.</p>
| [
{
"answer_id": 248313,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 4,
"selected": true,
"text": "<h2>Span outside anchor tags</h2>\n\n<p>I think you're looking for the <code>before</code> and <code>after</code>... | 2016/12/05 | [
"https://wordpress.stackexchange.com/questions/248332",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108330/"
] | I need change the tagline to a custom, specific tagline, further describing my business such as - "self-funded revenue increase" but I can't find it. | Span outside anchor tags
------------------------
I think you're looking for the `before` and `after` arguments (*PHP 5.4+*):
```
wp_get_archives(
[
'before' => '<span>',
'after' => '</span>'
]
);
```
if you want to wrap the `<span>` tag around the `<a>` tag:
```
<li><span><a href="xx">Lin... |
248,343 | <p>I am the owner of a small company that makes wordpress websites for entrepeneurs. When we go to a customer, we want to show some examples of themes we could be going to use. We want the themes to display some information of the customer, like a logo. a header title and some personal information. We will probably be ... | [
{
"answer_id": 248313,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 4,
"selected": true,
"text": "<h2>Span outside anchor tags</h2>\n\n<p>I think you're looking for the <code>before</code> and <code>after</code>... | 2016/12/05 | [
"https://wordpress.stackexchange.com/questions/248343",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108345/"
] | I am the owner of a small company that makes wordpress websites for entrepeneurs. When we go to a customer, we want to show some examples of themes we could be going to use. We want the themes to display some information of the customer, like a logo. a header title and some personal information. We will probably be add... | Span outside anchor tags
------------------------
I think you're looking for the `before` and `after` arguments (*PHP 5.4+*):
```
wp_get_archives(
[
'before' => '<span>',
'after' => '</span>'
]
);
```
if you want to wrap the `<span>` tag around the `<a>` tag:
```
<li><span><a href="xx">Lin... |
248,357 | <p>In a page, I need to display a list of all sub categories of a specify category.</p>
<p>For example, in the category <em>Sport</em> have 6 subcategories:</p>
<blockquote>
<ul>
<li>Swim</li>
<li>Football</li>
<li>Basket</li>
<li>Ski</li>
<li>Hockey</li>
</ul>
</blockquote>
<p>Each subcategory has a f... | [
{
"answer_id": 259174,
"author": "ricotheque",
"author_id": 34238,
"author_profile": "https://wordpress.stackexchange.com/users/34238",
"pm_score": 1,
"selected": false,
"text": "<p><strong>How can I add the featured image?</strong></p>\n\n<p>From what I can tell in your code, you've sto... | 2016/12/05 | [
"https://wordpress.stackexchange.com/questions/248357",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/51160/"
] | In a page, I need to display a list of all sub categories of a specify category.
For example, in the category *Sport* have 6 subcategories:
>
> * Swim
> * Football
> * Basket
> * Ski
> * Hockey
>
>
>
Each subcategory has a featured image, title and description, which I'd like to display.
I've add featured image... | **How can I add the featured image?**
From what I can tell in your code, you've stored all category featured images in the `category_images` option. So you can use `get_option` to retrieve the featured image for each category:
```
$image_urls = get_option( 'category_images', array() );
foreach ( $categories as $... |
248,367 | <p><br />I want to call the wordpress media uploader with a button in my theme options page. The thing is that I need three upload media buttons on the same page. I'm trying to do that using jQuery multiple IDs selector. The code is working fine: I click the button and the media uploader is launched, however when I upl... | [
{
"answer_id": 264126,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 1,
"selected": false,
"text": "<p>This depends on your business model. If your theme is free (or freemium, meaning people can download for free bu... | 2016/12/05 | [
"https://wordpress.stackexchange.com/questions/248367",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108354/"
] | I want to call the wordpress media uploader with a button in my theme options page. The thing is that I need three upload media buttons on the same page. I'm trying to do that using jQuery multiple IDs selector. The code is working fine: I click the button and the media uploader is launched, however when I upload anyth... | This depends on your business model. If your theme is free (or freemium, meaning people can download for free but unlock features when they pay you), you should post it into the wordpress.org repository. There's a whole lot of rules you must stick to, which you can [read about here](https://developer.wordpress.org/them... |
248,392 | <p>So basically, what I'm trying to do is to hook a static method of a class to another static method of that same class.</p>
<p>Code is here :</p>
<pre><code>class LocatorMap {
public static function init() {
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'register_scripts' ) );
}
/* a... | [
{
"answer_id": 248414,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 5,
"selected": true,
"text": "<p><code>register_activation_hook</code> only runs once i.e. when the plugin is first activated - use the <co... | 2016/12/06 | [
"https://wordpress.stackexchange.com/questions/248392",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/58147/"
] | So basically, what I'm trying to do is to hook a static method of a class to another static method of that same class.
Code is here :
```
class LocatorMap {
public static function init() {
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'register_scripts' ) );
}
/* add_action( 'wp_enqueue_... | `register_activation_hook` only runs once i.e. when the plugin is first activated - use the `init` hook instead to "boot up" your plugin:
```
add_action( 'init', 'LocatorMap::init' );
``` |
248,405 | <p>I want to replace the dashes before the page title in the dashboard page list. For each hierarchy below the first, a dash is prepended (as seen in the screenshot below):</p>
<p><a href="https://i.stack.imgur.com/QQUCY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QQUCY.png" alt="enter image des... | [
{
"answer_id": 248407,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 2,
"selected": false,
"text": "<p>This is <a href=\"https://github.com/WordPress/WordPress/blob/88a72182ca1129f76c1abbf84725d0d01ddad93a/wp-admin/inclu... | 2016/12/06 | [
"https://wordpress.stackexchange.com/questions/248405",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40821/"
] | I want to replace the dashes before the page title in the dashboard page list. For each hierarchy below the first, a dash is prepended (as seen in the screenshot below):
[](https://i.stack.imgur.com/QQUCY.png)
It seems that the filter `the_title` doe... | You can't change dashes using any filter because there is no filter available to change it.
but still you can change this using jQuery put this code inside functions.php
```
add_action('admin_head',function(){
global $pagenow;
// check current page.
if( $pagenow == 'edit.php' ){ ?>
<script>
jQuery(fu... |
248,416 | <p>I have a problem with WordPress widgets. I want to create a widget like in the images. I know how to create a widget but I don't know query and show the results as in the image.</p>
<p>Explain: We get 10 posts from a category, then show it as title 1 is the first post we get, then Title from 2-10 as in the images. ... | [
{
"answer_id": 248439,
"author": "Den Pat",
"author_id": 103569,
"author_profile": "https://wordpress.stackexchange.com/users/103569",
"pm_score": 0,
"selected": false,
"text": "<p>as bravokeyl told , just try place counter and see if value is 1 , assign some special class and than add s... | 2016/12/06 | [
"https://wordpress.stackexchange.com/questions/248416",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108391/"
] | I have a problem with WordPress widgets. I want to create a widget like in the images. I know how to create a widget but I don't know query and show the results as in the image.
Explain: We get 10 posts from a category, then show it as title 1 is the first post we get, then Title from 2-10 as in the images.
Could yo... | Your question is a little short on detail, but let's suppose you have retrieved the posts using [`wp_query`](https://codex.wordpress.org/Class_Reference/WP_Query) and are looping through it like this:
```
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
... |
248,419 | <p>I have this action in my plugin page.</p>
<pre><code>add_action ( 'init', 'myStartSession', 1 );
function join_action() {
$a = 1;
include "includes/join.php";
}
add_action ( 'admin_post_nopriv_join', 'join_action' );
add_action ( 'admin_post_join', 'join_action' );
</code></pre>
<p>and I call this from my ... | [
{
"answer_id": 248439,
"author": "Den Pat",
"author_id": 103569,
"author_profile": "https://wordpress.stackexchange.com/users/103569",
"pm_score": 0,
"selected": false,
"text": "<p>as bravokeyl told , just try place counter and see if value is 1 , assign some special class and than add s... | 2016/12/06 | [
"https://wordpress.stackexchange.com/questions/248419",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108395/"
] | I have this action in my plugin page.
```
add_action ( 'init', 'myStartSession', 1 );
function join_action() {
$a = 1;
include "includes/join.php";
}
add_action ( 'admin_post_nopriv_join', 'join_action' );
add_action ( 'admin_post_join', 'join_action' );
```
and I call this from my angularjs app as follows: ... | Your question is a little short on detail, but let's suppose you have retrieved the posts using [`wp_query`](https://codex.wordpress.org/Class_Reference/WP_Query) and are looping through it like this:
```
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
... |
248,455 | <p>I'm currently running Wordpress on version <strong>4.6.1</strong> and I'm attempting to search for posts that contains the character <code>-</code> (hyphen). However, the search parameter is taking my hyphen for a negation.</p>
<p>From the <a href="https://codex.wordpress.org/Class_Reference/WP_Query" rel="noreferr... | [
{
"answer_id": 248558,
"author": "prosti",
"author_id": 88606,
"author_profile": "https://wordpress.stackexchange.com/users/88606",
"pm_score": 2,
"selected": false,
"text": "<p>You can use the fact that <code>NOT LIKE '%%'</code> is very unique. It can happen only in cases where you sea... | 2016/12/06 | [
"https://wordpress.stackexchange.com/questions/248455",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/104711/"
] | I'm currently running Wordpress on version **4.6.1** and I'm attempting to search for posts that contains the character `-` (hyphen). However, the search parameter is taking my hyphen for a negation.
From the [WP\_Query](https://codex.wordpress.org/Class_Reference/WP_Query) documentation:
>
> Prepending a term with ... | One approach is to modify the *exclusion prefix* through the [`wp_query_search_exclusion_prefix`](https://developer.wordpress.org/reference/hooks/wp_query_search_exclusion_prefix/) filter that's supported in WP 4.7+.
See ticket [#38099](https://core.trac.wordpress.org/ticket/38099).
Here's an example how we can change... |
248,462 | <p>I have yet to find a concise, start to finish description of how to create a multilingual WordPress theme.</p>
<p>I am a fairly competent developer and have made a few custom themes in my time. For a project I am working on, I am just starting the process of converting my wireframes into WordPress. I already know t... | [
{
"answer_id": 248466,
"author": "Daniel Mulder",
"author_id": 86859,
"author_profile": "https://wordpress.stackexchange.com/users/86859",
"pm_score": 2,
"selected": false,
"text": "<p>Myself I have done it a few times in recent year but then only for plug-ins that I made. But I think it... | 2016/12/06 | [
"https://wordpress.stackexchange.com/questions/248462",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/104663/"
] | I have yet to find a concise, start to finish description of how to create a multilingual WordPress theme.
I am a fairly competent developer and have made a few custom themes in my time. For a project I am working on, I am just starting the process of converting my wireframes into WordPress. I already know that this s... | Daniel's answer was very similar, but applied to plugins rather than themes. For that reason I'll explain how I specifically did it for themes for anyone else who comes across this problem.
1. Create a folder in the root of your theme called "languages"
2. Go to <https://wpcentral.io/internationalization/>, search for... |
248,464 | <p>What is the best way to pass/get data to/from the <code>data-product_variations</code> attr form in Product Single pages. I am working on some interactions with the product gallery images and the product variations, all of these while using WooCommerce.</p>
<p>Basically, I need to be able to trigger some stuff on t... | [
{
"answer_id": 368161,
"author": "Michael Aro",
"author_id": 189311,
"author_profile": "https://wordpress.stackexchange.com/users/189311",
"pm_score": 1,
"selected": false,
"text": "<pre><code> jQuery(document).on('found_variation.wc-variation-form', 'form.variations_form', function(eve... | 2016/12/06 | [
"https://wordpress.stackexchange.com/questions/248464",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/35530/"
] | What is the best way to pass/get data to/from the `data-product_variations` attr form in Product Single pages. I am working on some interactions with the product gallery images and the product variations, all of these while using WooCommerce.
Basically, I need to be able to trigger some stuff on the `woocommerce_varia... | ```
jQuery(document).on('found_variation.wc-variation-form', 'form.variations_form', function(event, variation_data) {
//this is called when a valid productis found
});
jQuery(document).on('change.wc-variation-form', 'form.variations_form', function(event) {
//this function is called when the user clicks ... |
248,480 | <p>Is there a filter available that would let you specify that a module is active, without you having to use the admin area? I've found filters that let you <em>hide</em> modules, but so far nothing for <em>activating</em> modules.</p>
<p>Essentially, I want to be able to define it as <em>always on</em> so that A) a c... | [
{
"answer_id": 248483,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 2,
"selected": false,
"text": "<p>Third party plugins (yeah, including jetpack) are off topic on WPSE, but well, here you go: Jetpack has a filter... | 2016/12/06 | [
"https://wordpress.stackexchange.com/questions/248480",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/60767/"
] | Is there a filter available that would let you specify that a module is active, without you having to use the admin area? I've found filters that let you *hide* modules, but so far nothing for *activating* modules.
Essentially, I want to be able to define it as *always on* so that A) a client can't accidentally disabl... | Third party plugins (yeah, including jetpack) are off topic on WPSE, but well, here you go: Jetpack has a filter [`jetpack_get_available_modules`](https://developer.jetpack.com/hooks/jetpack_get_available_modules/), which lets you edit the array of active modules. You can disable a module by unsetting it from the array... |
248,489 | <p>I have a particular issue. I have only 2 roles on my site, admin and a secondary role used for various administrative tasks in the backend. </p>
<p>This secondary role needs to normally redirect to a frontend page when they login, UNLESS the redirect_to URL parameter is set while they're logging in. </p>
<p>I have... | [
{
"answer_id": 248507,
"author": "pixeline",
"author_id": 82,
"author_profile": "https://wordpress.stackexchange.com/users/82",
"pm_score": 2,
"selected": false,
"text": "<p>The login_redirect hook does seem to be the right hook.</p>\n\n<p>Can you try this :</p>\n\n<p>(Adapted from the <... | 2016/12/06 | [
"https://wordpress.stackexchange.com/questions/248489",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/72933/"
] | I have a particular issue. I have only 2 roles on my site, admin and a secondary role used for various administrative tasks in the backend.
This secondary role needs to normally redirect to a frontend page when they login, UNLESS the redirect\_to URL parameter is set while they're logging in.
I have tried using log... | The login\_redirect hook does seem to be the right hook.
Can you try this :
(Adapted from the [Codex](https://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect) )
```
function redirect_users_by_role( $redirect_to, $request, $user ) {
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
... |
248,501 | <p>I am using a currency widget to show live currencies for different countries. I also use W3 Total Cache plugin and the widget data is cached. For example yesterday's prices are shown for today and I have to manually purge all caches to get the new data. </p>
<p>Is there anyway to disable cache for certain widgets? ... | [
{
"answer_id": 248504,
"author": "pixeline",
"author_id": 82,
"author_profile": "https://wordpress.stackexchange.com/users/82",
"pm_score": 0,
"selected": false,
"text": "<p>The recommended solution is to have your currency widget refresh its data via ajax.</p>\n"
},
{
"answer_id... | 2016/12/06 | [
"https://wordpress.stackexchange.com/questions/248501",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108450/"
] | I am using a currency widget to show live currencies for different countries. I also use W3 Total Cache plugin and the widget data is cached. For example yesterday's prices are shown for today and I have to manually purge all caches to get the new data.
Is there anyway to disable cache for certain widgets? or clear t... | You need to use fragment caching so enable PHP in the widget and then use the following tags:
```
<!-- mfunc -->
```
The following links should help:
<https://wordpress.org/support/topic/using-shortcodes-with-fragment-caching/>
<https://www.justinsilver.com/technology/wordpress/w3-total-cache-fragment-caching-word... |
248,559 | <p>Is it possible to change the comment-meta fields?</p>
<p>I have tried searching the file structure and cannot see what function is writing it - all I want to do is change the word "says"</p>
<pre><code><ol class="comment-list">
<li id="comment-2" class="comment byuser comment-author-james bypo... | [
{
"answer_id": 248522,
"author": "GKS",
"author_id": 90674,
"author_profile": "https://wordpress.stackexchange.com/users/90674",
"pm_score": 0,
"selected": false,
"text": "<p>Instead of delete, you can move all files from <code>/wp</code> to <code>root</code> folder. </p>\n\n<p>Then use ... | 2016/12/07 | [
"https://wordpress.stackexchange.com/questions/248559",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/104443/"
] | Is it possible to change the comment-meta fields?
I have tried searching the file structure and cannot see what function is writing it - all I want to do is change the word "says"
```
<ol class="comment-list">
<li id="comment-2" class="comment byuser comment-author-james bypostauthor even thread-even dept... | Instead of delete, you can move all files from `/wp` to `root` folder.
Then use this script to replace url from `example.com/wp` to `example.com` inside the database <https://interconnectit.com/products/search-and-replace-for-wordpress-databases/>
Follow these few steps.
1. Move all your website files to root from... |
248,567 | <p>How do I display the commentor's first name and last name in the comments?... rather than their username as currently shows.</p>
| [
{
"answer_id": 248591,
"author": "Felipe Rodrigues",
"author_id": 104101,
"author_profile": "https://wordpress.stackexchange.com/users/104101",
"pm_score": 0,
"selected": false,
"text": "<p>Take a look at the <code>'callback'</code> argument of the function <code>wp_list_comments</code>.... | 2016/12/07 | [
"https://wordpress.stackexchange.com/questions/248567",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/37346/"
] | How do I display the commentor's first name and last name in the comments?... rather than their username as currently shows. | This will get you a first name + last name combination if available, or just the first name or last name if that's all your user submitted.
This assumes you're interested in registered user's names. If you're going to add first and last names to your commenting form... or treat first + last name as "display name" from... |
248,570 | <p>I'm having some issues getting the default values set in the WordPress Customizer to save to the database upon initial install without first having the user save the Customizer to set them. I've tried the solution from this thread with no luck:</p>
<p><a href="https://wordpress.stackexchange.com/questions/143789/us... | [
{
"answer_id": 248591,
"author": "Felipe Rodrigues",
"author_id": 104101,
"author_profile": "https://wordpress.stackexchange.com/users/104101",
"pm_score": 0,
"selected": false,
"text": "<p>Take a look at the <code>'callback'</code> argument of the function <code>wp_list_comments</code>.... | 2016/12/07 | [
"https://wordpress.stackexchange.com/questions/248570",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108509/"
] | I'm having some issues getting the default values set in the WordPress Customizer to save to the database upon initial install without first having the user save the Customizer to set them. I've tried the solution from this thread with no luck:
[Use default value of wp\_customizer in theme\_mod output?](https://wordpr... | This will get you a first name + last name combination if available, or just the first name or last name if that's all your user submitted.
This assumes you're interested in registered user's names. If you're going to add first and last names to your commenting form... or treat first + last name as "display name" from... |
248,618 | <p>I have set up links to the next/previous posts on my <code>single.php</code> template. Currently I am using <code><?php previous_post_link(); ?></code> and <code><?php next_post_link(); ?></code> which gives me the title of the next/previous posts, but I would also like to be able to display the author o... | [
{
"answer_id": 248620,
"author": "MaximOrlovsky",
"author_id": 15294,
"author_profile": "https://wordpress.stackexchange.com/users/15294",
"pm_score": 3,
"selected": true,
"text": "<p>Yes, you can do that. Change <code><?php previous_post_link(); ?></code> and <code><?php next_p... | 2016/12/07 | [
"https://wordpress.stackexchange.com/questions/248618",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13286/"
] | I have set up links to the next/previous posts on my `single.php` template. Currently I am using `<?php previous_post_link(); ?>` and `<?php next_post_link(); ?>` which gives me the title of the next/previous posts, but I would also like to be able to display the author of those posts below the title. Is this possible? | Yes, you can do that. Change `<?php previous_post_link(); ?>` and `<?php next_post_link(); ?>` with the following code:
For previous post:
```
<?php
$prev_post = get_previous_post();
$prev_user = get_user_by( 'id', $prev_post->post_author );
if (!empty( $prev_post )): ?>
<a href="<?php echo $prev_... |
248,621 | <p>I just upgraded to WP 4.7, and suddenly code that uses get_post_type($id) stopped returning anything, and didn't throw an error either.</p>
<p>After trying a few things, I found that it would start working again if I changed my code from </p>
<pre><code>get_post_type($id)
</code></pre>
<p>to</p>
<pre><code>get_p... | [
{
"answer_id": 248627,
"author": "Howdy_McGee",
"author_id": 7355,
"author_profile": "https://wordpress.stackexchange.com/users/7355",
"pm_score": 1,
"selected": false,
"text": "<p>As far as I can tell this is untrue. Let's fall down the rabbit hole...</p>\n\n<p>First we call <a href=\"h... | 2016/12/07 | [
"https://wordpress.stackexchange.com/questions/248621",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/11023/"
] | I just upgraded to WP 4.7, and suddenly code that uses get\_post\_type($id) stopped returning anything, and didn't throw an error either.
After trying a few things, I found that it would start working again if I changed my code from
```
get_post_type($id)
```
to
```
get_post_type(intval($id))
```
But I can't fi... | According to the devs at WP (<https://core.trac.wordpress.org/ticket/39164>):
"This was an intentional change to get\_post() in 4.7 - passing an invalid parameter may have previously returned a result, but it could've been an incorrect resource, for example, a value being cast to a numeric 1 and fetching from the inco... |
248,647 | <p>I have a modal category and in my modal category i have three sub-categories in it. Here is the structure of my modal category.</p>
<pre><code>-Modal
-Water Pumps
-Water Heaters
-Electrical
</code></pre>
<p>Here, i want to only get a post from my water pumps sub-category from my Modal category and to be disp... | [
{
"answer_id": 248627,
"author": "Howdy_McGee",
"author_id": 7355,
"author_profile": "https://wordpress.stackexchange.com/users/7355",
"pm_score": 1,
"selected": false,
"text": "<p>As far as I can tell this is untrue. Let's fall down the rabbit hole...</p>\n\n<p>First we call <a href=\"h... | 2016/12/08 | [
"https://wordpress.stackexchange.com/questions/248647",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/105020/"
] | I have a modal category and in my modal category i have three sub-categories in it. Here is the structure of my modal category.
```
-Modal
-Water Pumps
-Water Heaters
-Electrical
```
Here, i want to only get a post from my water pumps sub-category from my Modal category and to be displayed in my modal. Here is... | According to the devs at WP (<https://core.trac.wordpress.org/ticket/39164>):
"This was an intentional change to get\_post() in 4.7 - passing an invalid parameter may have previously returned a result, but it could've been an incorrect resource, for example, a value being cast to a numeric 1 and fetching from the inco... |
248,701 | <p>I am struggling to make this script working on Wordpress. On Fiddle it works well <a href="https://jsfiddle.net/xqxk2qdg/2/" rel="nofollow noreferrer">https://jsfiddle.net/xqxk2qdg/2/</a> Any idea why could I have this problem? It is properly enqueued and loaded on page.</p>
<pre><code>var array = [];
var array1 = ... | [
{
"answer_id": 248713,
"author": "depiction",
"author_id": 101731,
"author_profile": "https://wordpress.stackexchange.com/users/101731",
"pm_score": 2,
"selected": false,
"text": "<p>By default, jQuery runs in no conflict mode in WordPress. You have an anonymous function that passes the ... | 2016/12/08 | [
"https://wordpress.stackexchange.com/questions/248701",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/105189/"
] | I am struggling to make this script working on Wordpress. On Fiddle it works well <https://jsfiddle.net/xqxk2qdg/2/> Any idea why could I have this problem? It is properly enqueued and loaded on page.
```
var array = [];
var array1 = $('#input_8_3').val().split(',');
$("#input_8_3").val(array.join());
(function($){
$... | By default, jQuery runs in no conflict mode in WordPress. You have an anonymous function that passes the jQuery object so you can use it.
Your code will error on line two because it doesn't know what $ is. Move the first three lines into the anonymous function to resolve this.
```
(function($){
var array = [];
var a... |
248,702 | <p>i need help for optimizing my wordpress website without using plugins incloding wp-total-cache or wp-super-cache.check this link
<a href="https://gtmetrix.com/reports/akhbartop.ir/fF37Flwa" rel="nofollow noreferrer">https://gtmetrix.com/reports/akhbartop.ir/fF37Flwa</a>
my website needs otimize in <strong>Use a Cont... | [
{
"answer_id": 248713,
"author": "depiction",
"author_id": 101731,
"author_profile": "https://wordpress.stackexchange.com/users/101731",
"pm_score": 2,
"selected": false,
"text": "<p>By default, jQuery runs in no conflict mode in WordPress. You have an anonymous function that passes the ... | 2016/12/08 | [
"https://wordpress.stackexchange.com/questions/248702",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/101761/"
] | i need help for optimizing my wordpress website without using plugins incloding wp-total-cache or wp-super-cache.check this link
<https://gtmetrix.com/reports/akhbartop.ir/fF37Flwa>
my website needs otimize in **Use a Content Delivery Network (CDN)** and **Configure entity tags (ETags)**
also i cant use MAXCDN :) pleas... | By default, jQuery runs in no conflict mode in WordPress. You have an anonymous function that passes the jQuery object so you can use it.
Your code will error on line two because it doesn't know what $ is. Move the first three lines into the anonymous function to resolve this.
```
(function($){
var array = [];
var a... |
248,730 | <p>I need to pass the info from <code>wp_get_current_user()</code> to the front end for a script that uses it. To achieve this, I am using <code>wp_localize_script()</code> to pass the information. I put the code at the top of my <code>functions.php</code> file but it doesn't work.</p>
<p>Here it is. The idea is that ... | [
{
"answer_id": 248711,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 1,
"selected": false,
"text": "<p>In a nutshell, if a client (in the technical sense) has valid username and password then it can provide it to the W... | 2016/12/08 | [
"https://wordpress.stackexchange.com/questions/248730",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108612/"
] | I need to pass the info from `wp_get_current_user()` to the front end for a script that uses it. To achieve this, I am using `wp_localize_script()` to pass the information. I put the code at the top of my `functions.php` file but it doesn't work.
Here it is. The idea is that on the login event, the `add_to_login()` fu... | In a nutshell, if a client (in the technical sense) has valid username and password then it can provide it to the WP installation to be checked and be placed in a "privileged" context for all the code to run.
Being web app, native WP authentication is mostly browser/cookie centric. So for a mobile app it highly depend... |
248,765 | <p>I am testing my theme against WordPress theme unit test, which states that:</p>
<blockquote>
<p>Large number of categories/tags should not adversely impact layout.</p>
</blockquote>
<p>I was able to manage the number of tags but could not help myself in case of categories. Here is the code I'm using to limit the... | [
{
"answer_id": 248711,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 1,
"selected": false,
"text": "<p>In a nutshell, if a client (in the technical sense) has valid username and password then it can provide it to the W... | 2016/12/09 | [
"https://wordpress.stackexchange.com/questions/248765",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108376/"
] | I am testing my theme against WordPress theme unit test, which states that:
>
> Large number of categories/tags should not adversely impact layout.
>
>
>
I was able to manage the number of tags but could not help myself in case of categories. Here is the code I'm using to limit the number of tags displayed.
Can i... | In a nutshell, if a client (in the technical sense) has valid username and password then it can provide it to the WP installation to be checked and be placed in a "privileged" context for all the code to run.
Being web app, native WP authentication is mostly browser/cookie centric. So for a mobile app it highly depend... |