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 |
|---|---|---|---|---|---|---|
209,363 | <p>I don't understand why wordpress stores that kind of data: posts' content and pages' content, directly within the database instead of storing it in the filesystem and referencing them in the database with an URL/path. Could someone please explain it to me? </p>
<p>--EDIT</p>
<p>As far as I know storing raw images ... | [
{
"answer_id": 209349,
"author": "jas",
"author_id": 80247,
"author_profile": "https://wordpress.stackexchange.com/users/80247",
"pm_score": 2,
"selected": true,
"text": "<pre><code>$tags = get_the_tags( $post->ID );\n$separator = ' ';\n$output = '';\nif($tags){\necho '<div class=\... | 2015/11/20 | [
"https://wordpress.stackexchange.com/questions/209363",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/81710/"
] | I don't understand why wordpress stores that kind of data: posts' content and pages' content, directly within the database instead of storing it in the filesystem and referencing them in the database with an URL/path. Could someone please explain it to me?
--EDIT
As far as I know storing raw images in within the dat... | ```
$tags = get_the_tags( $post->ID );
$separator = ' ';
$output = '';
if($tags){
echo '<div class="entry-tags">';
echo "<p><span>" . __('Tags', 'tracks') . "</span>";
foreach($tags as $tag) {
// dpm($tag) here by uncomment you can check tag slug which you want to exclude
if($tag->sl... |
209,392 | <p>I just installed <strong>[first time]</strong> WordPress 4.3.1, but I was facing the problem with it so I downgraded and installed 4.2.5 and facing same problem.</p>
<p><strong>Problem</strong>:
<strong>index.php is not loading, I clicked on link and also write in url but still not working</strong></p>
<p>I uninst... | [
{
"answer_id": 209394,
"author": "Craig Pearson",
"author_id": 17295,
"author_profile": "https://wordpress.stackexchange.com/users/17295",
"pm_score": 1,
"selected": false,
"text": "<p>It appears that you don't have the mod_rewrite module enabled in apache. This explains why you can acce... | 2015/11/21 | [
"https://wordpress.stackexchange.com/questions/209392",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17941/"
] | I just installed **[first time]** WordPress 4.3.1, but I was facing the problem with it so I downgraded and installed 4.2.5 and facing same problem.
**Problem**:
**index.php is not loading, I clicked on link and also write in url but still not working**
I uninstalled and then later I reinstalled and tried again but f... | It appears that you don't have the mod\_rewrite module enabled in apache. This explains why you can access the dashboard found at `wp-admin/index.php`, but not the main index.php. Your .htaccess is depending on the rewrite module to do its work, which isn't active.
To enable it in your http.conf file you need to find ... |
209,467 | <p>I have a custom post type named 'advert' and a related custom taxonomy named 'advert_category', created by a 3rd party plugin. I run in a plugin an <code>if</code> statement that must to set (as I expect) a specific theme layout for single adverts (example.com/advert/a-single-advert.html) and for custom taxonomy arc... | [
{
"answer_id": 209468,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 4,
"selected": true,
"text": "<p>You hava a lot of issues here:</p>\n<ul>\n<li><p><code>pre_get_posts</code> is not the correct hook to s... | 2015/11/22 | [
"https://wordpress.stackexchange.com/questions/209467",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25187/"
] | I have a custom post type named 'advert' and a related custom taxonomy named 'advert\_category', created by a 3rd party plugin. I run in a plugin an `if` statement that must to set (as I expect) a specific theme layout for single adverts (example.com/advert/a-single-advert.html) and for custom taxonomy archive pages (e... | You hava a lot of issues here:
* `pre_get_posts` is not the correct hook to set templates. `pre_get_posts` are used to alter the ain query query vars just before the SQL are build to run the main query's query
* A filter should **always** return something. Not doing this will have unexpected behavior, and forgetting a... |
209,503 | <p>I have a custom comments loop on my <code>author.php</code> page. I am trying to get the post id so that I can echo the permalink for the post that the comment belongs to. Also so I can echo some post meta custom fields. </p>
<p>This is what my loop looks like now -</p>
<pre><code><?php
$object = get_queried_ob... | [
{
"answer_id": 209504,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 3,
"selected": true,
"text": "<p>Note that it might be easier to use <code>get_comments()</code> here, since it's defined as:</p>\n\n<pre><code... | 2015/11/22 | [
"https://wordpress.stackexchange.com/questions/209503",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/24067/"
] | I have a custom comments loop on my `author.php` page. I am trying to get the post id so that I can echo the permalink for the post that the comment belongs to. Also so I can echo some post meta custom fields.
This is what my loop looks like now -
```
<?php
$object = get_queried_object();
$authorID = get_queried_obj... | Note that it might be easier to use `get_comments()` here, since it's defined as:
```
function get_comments( $args = '' ) {
$query = new WP_Comment_Query;
return $query->query( $args );
}
```
If you need the *comment url*, within your `foreach` comment loop, you can use:
```
$comment_url = esc_url( get_com... |
209,506 | <p>When I insert a large image into a post, I would like the image to open in a new browser tab rather than within the existing tab. </p>
<p>I know that this can be accomplished by adding <code>target="_blank"</code> to the link, but how do I add this attribute to the image links?</p>
| [
{
"answer_id": 209504,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 3,
"selected": true,
"text": "<p>Note that it might be easier to use <code>get_comments()</code> here, since it's defined as:</p>\n\n<pre><code... | 2015/11/22 | [
"https://wordpress.stackexchange.com/questions/209506",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/70476/"
] | When I insert a large image into a post, I would like the image to open in a new browser tab rather than within the existing tab.
I know that this can be accomplished by adding `target="_blank"` to the link, but how do I add this attribute to the image links? | Note that it might be easier to use `get_comments()` here, since it's defined as:
```
function get_comments( $args = '' ) {
$query = new WP_Comment_Query;
return $query->query( $args );
}
```
If you need the *comment url*, within your `foreach` comment loop, you can use:
```
$comment_url = esc_url( get_com... |
209,529 | <p>I want to order a custom post type by post meta field. This query works fine partially and load results. The problem is that the order of results vary at each time this query is executed. I have found some duplicates also in last few pages. Can you please help me figure out what sort of thing going there?</p>
<p... | [
{
"answer_id": 209504,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 3,
"selected": true,
"text": "<p>Note that it might be easier to use <code>get_comments()</code> here, since it's defined as:</p>\n\n<pre><code... | 2015/11/23 | [
"https://wordpress.stackexchange.com/questions/209529",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/64277/"
] | I want to order a custom post type by post meta field. This query works fine partially and load results. The problem is that the order of results vary at each time this query is executed. I have found some duplicates also in last few pages. Can you please help me figure out what sort of thing going there?
```
SELECT S... | Note that it might be easier to use `get_comments()` here, since it's defined as:
```
function get_comments( $args = '' ) {
$query = new WP_Comment_Query;
return $query->query( $args );
}
```
If you need the *comment url*, within your `foreach` comment loop, you can use:
```
$comment_url = esc_url( get_com... |
209,530 | <p>Is there a way to use different templates for different <em>levels</em> within a hierarchical taxonomy, specified by filename. I know about <code>taxonomy-taxonomyname.php</code> and <code>taxonomy-taxonomyname-term.php</code> templates. Looking for a more generic "per taxonomy level" based method.</p>
<p>So, a tax... | [
{
"answer_id": 209504,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 3,
"selected": true,
"text": "<p>Note that it might be easier to use <code>get_comments()</code> here, since it's defined as:</p>\n\n<pre><code... | 2015/11/23 | [
"https://wordpress.stackexchange.com/questions/209530",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/44795/"
] | Is there a way to use different templates for different *levels* within a hierarchical taxonomy, specified by filename. I know about `taxonomy-taxonomyname.php` and `taxonomy-taxonomyname-term.php` templates. Looking for a more generic "per taxonomy level" based method.
So, a taxonomy named **Earth** might contain:
1... | Note that it might be easier to use `get_comments()` here, since it's defined as:
```
function get_comments( $args = '' ) {
$query = new WP_Comment_Query;
return $query->query( $args );
}
```
If you need the *comment url*, within your `foreach` comment loop, you can use:
```
$comment_url = esc_url( get_com... |
209,531 | <p>The following coding is the out come of an other page php echo</p>
<pre><code>user_list.php:
$myarray=array();
...
...
$myjson = json_encode($myarray);
echo $myuser->searchUser($myjson);
</code></pre>
<p>and the result of html is:</p>
<pre><code>[{"userID":"1","username":"\u9ec3\u9ec3\u9ec3",
"sex":"F","passw... | [
{
"answer_id": 209535,
"author": "Dijo David",
"author_id": 4026,
"author_profile": "https://wordpress.stackexchange.com/users/4026",
"pm_score": 0,
"selected": false,
"text": "<p>Change the format in the following method.</p>\n\n<pre><code>$myuser->searchUser($myjson)\n</code></pre>\... | 2015/11/23 | [
"https://wordpress.stackexchange.com/questions/209531",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84094/"
] | The following coding is the out come of an other page php echo
```
user_list.php:
$myarray=array();
...
...
$myjson = json_encode($myarray);
echo $myuser->searchUser($myjson);
```
and the result of html is:
```
[{"userID":"1","username":"\u9ec3\u9ec3\u9ec3",
"sex":"F","password":"1bbd886460827015e5d605ed44252251",... | There are two methods to access the object.
**1. Ajax response.**
```
$.ajax({
url:"your_file.php",
type : "POST",
data : your_data,
dataType: "json",
success:function(data){
// Retrieve the object
var result = data[0];
// Grab username from the object
console.log(result['username']);
},... |
209,532 | <p>I've added functionality to upload profile picture by following <a href="http://www.flyinghippo.com/blog/adding-custom-fields-uploading-images-wordpress-users/" rel="noreferrer">THIS guide</a>.</p>
<p>I can't find an online guide or any documentation about WP hooks.. <strong>How to replace Gravatar profile pictures... | [
{
"answer_id": 209536,
"author": "PHP Team",
"author_id": 60469,
"author_profile": "https://wordpress.stackexchange.com/users/60469",
"pm_score": -1,
"selected": true,
"text": "<p>If you are set your custom or uploaded profile picture and need to see on front end, you can use below func... | 2015/11/23 | [
"https://wordpress.stackexchange.com/questions/209532",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80903/"
] | I've added functionality to upload profile picture by following [THIS guide](http://www.flyinghippo.com/blog/adding-custom-fields-uploading-images-wordpress-users/).
I can't find an online guide or any documentation about WP hooks.. **How to replace Gravatar profile pictures (in comment section) with custom uploaded i... | If you are set your custom or uploaded profile picture and need to see on front end, you can use below function .
```
<?php echo get_avatar( $id_or_email, $size, $default, $alt, $args ); ?>
```
If you have to change your gravatar to custom profile picture you can refer below link :
<http://www.wpbeginner.com/wp-tut... |
209,537 | <p>In my project I want to show product list in two ways on single page.</p>
<ol>
<li>First in gallery way in which 4 products in one row.(This I have already created).</li>
<li>And second in list way(one product at a row) which I will create.</li>
</ol>
<p>But I actually what I want is that to provide an option to c... | [
{
"answer_id": 209540,
"author": "garth",
"author_id": 80997,
"author_profile": "https://wordpress.stackexchange.com/users/80997",
"pm_score": 1,
"selected": true,
"text": "<p>Set a button, or dropdown menu, that calls a function to set a cookie and to switch between CSS files which cont... | 2015/11/23 | [
"https://wordpress.stackexchange.com/questions/209537",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/81621/"
] | In my project I want to show product list in two ways on single page.
1. First in gallery way in which 4 products in one row.(This I have already created).
2. And second in list way(one product at a row) which I will create.
But I actually what I want is that to provide an option to customers whether he/she want the ... | Set a button, or dropdown menu, that calls a function to set a cookie and to switch between CSS files which contain the `_style` ID:
```
function switchStyle(style) {
var file = $TMPL_URL + '/css/' + style;
jQuery('head').append('<link rel="stylesheet" href="' + file + '" type="text/css" />');
jQuery.cooki... |
209,549 | <p>i'm using this function in my Wordpress index:</p>
<pre><code><?php echo get_the_excerpt(); ?>
</code></pre>
<p>But if the article contains an image in the first 50 words, I get the link of the image in this form:</p>
<blockquote>
<p>Immagine: <a href="https://i.imgur.com/UUsXR3w.jpg" rel="nofollow norefe... | [
{
"answer_id": 209540,
"author": "garth",
"author_id": 80997,
"author_profile": "https://wordpress.stackexchange.com/users/80997",
"pm_score": 1,
"selected": true,
"text": "<p>Set a button, or dropdown menu, that calls a function to set a cookie and to switch between CSS files which cont... | 2015/11/23 | [
"https://wordpress.stackexchange.com/questions/209549",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/79884/"
] | i'm using this function in my Wordpress index:
```
<?php echo get_the_excerpt(); ?>
```
But if the article contains an image in the first 50 words, I get the link of the image in this form:
>
> Immagine: [http://i.imgur.com/UUsXR3w.jpg](https://i.imgur.com/UUsXR3w.jpg)
>
>
>
How can I exclude images from the e... | Set a button, or dropdown menu, that calls a function to set a cookie and to switch between CSS files which contain the `_style` ID:
```
function switchStyle(style) {
var file = $TMPL_URL + '/css/' + style;
jQuery('head').append('<link rel="stylesheet" href="' + file + '" type="text/css" />');
jQuery.cooki... |
209,555 | <p>I know javascript pretty well now but I am new to php and wordpress theme building. I have searched a fair bit and can't find a solution to something that seems like a pretty simple task, all I would like to accomplish is get all the grandchildren of a page only, not the direct children, like so:</p>
<p><strong>Por... | [
{
"answer_id": 209556,
"author": "1inMillion",
"author_id": 84112,
"author_profile": "https://wordpress.stackexchange.com/users/84112",
"pm_score": 0,
"selected": false,
"text": "<p>This for so you can get an idea, havent tested this code but maybe you should try.</p>\n\n<pre><code><?... | 2015/11/23 | [
"https://wordpress.stackexchange.com/questions/209555",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84107/"
] | I know javascript pretty well now but I am new to php and wordpress theme building. I have searched a fair bit and can't find a solution to something that seems like a pretty simple task, all I would like to accomplish is get all the grandchildren of a page only, not the direct children, like so:
**Portfolio**
* chil... | There is no native way to do this AFAIK. The easiest way will be:
* to simply query all the pages in the hierarchy of the page ID passed
* then return all the parent ID's (*$post\_parent property of the post object*) from all pages in an array
* loop through the pages and compare the page ID against the ID's in the pa... |
209,560 | <p>Is it possible that when user submit multipart form for creating a new post in wordpress, all the images are inserted using <code>wp_insert_attachment()</code> to media library with compression so the uploading time will be reduce?</p>
| [
{
"answer_id": 209556,
"author": "1inMillion",
"author_id": 84112,
"author_profile": "https://wordpress.stackexchange.com/users/84112",
"pm_score": 0,
"selected": false,
"text": "<p>This for so you can get an idea, havent tested this code but maybe you should try.</p>\n\n<pre><code><?... | 2015/11/23 | [
"https://wordpress.stackexchange.com/questions/209560",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84114/"
] | Is it possible that when user submit multipart form for creating a new post in wordpress, all the images are inserted using `wp_insert_attachment()` to media library with compression so the uploading time will be reduce? | There is no native way to do this AFAIK. The easiest way will be:
* to simply query all the pages in the hierarchy of the page ID passed
* then return all the parent ID's (*$post\_parent property of the post object*) from all pages in an array
* loop through the pages and compare the page ID against the ID's in the pa... |
209,570 | <p>I would like to replace the <code>permalink</code> for all products in a woocommerce/wp installation with a custom link, if it set in a <code>custom_post_meta</code>.</p>
<p>The <code>custom_post_meta</code> is setup and working fine. From all I have read, the function below should do the trick:</p>
<pre><code>fun... | [
{
"answer_id": 209574,
"author": "tao",
"author_id": 45169,
"author_profile": "https://wordpress.stackexchange.com/users/45169",
"pm_score": 0,
"selected": false,
"text": "<p>Silly me. Haven't used WP in a while and completely forgot ID should be capitalized. </p>\n\n<p>Changed <code>pos... | 2015/11/23 | [
"https://wordpress.stackexchange.com/questions/209570",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/45169/"
] | I would like to replace the `permalink` for all products in a woocommerce/wp installation with a custom link, if it set in a `custom_post_meta`.
The `custom_post_meta` is setup and working fine. From all I have read, the function below should do the trick:
```
function eli_changeProductLink($permalink, $post) {
i... | The `$post` in your callback handler is an object, and object properties, like variables, are [case sensitive](http://php.net/manual/en/language.variables.basics.php). So you have to use `$post->ID`, not `$post->id`.
The question here is: *How can we prevent errors like this one during development?*
For objects, ther... |
209,591 | <p>I would like to organise users by date registered every time an admin visits the users page, without having to click again from:</p>
<pre><code>http://localhost:8888/wp-admin/users.php
</code></pre>
<p>I can add the date registered column and the sorting but I can't seem to find any documentation on how to pre sor... | [
{
"answer_id": 239697,
"author": "Dave Romsey",
"author_id": 2807,
"author_profile": "https://wordpress.stackexchange.com/users/2807",
"pm_score": 3,
"selected": false,
"text": "<p>This code will add the sortable user registration date column and it will handle default sorting of the use... | 2015/11/23 | [
"https://wordpress.stackexchange.com/questions/209591",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84127/"
] | I would like to organise users by date registered every time an admin visits the users page, without having to click again from:
```
http://localhost:8888/wp-admin/users.php
```
I can add the date registered column and the sorting but I can't seem to find any documentation on how to pre sort the users without actual... | This code will add the sortable user registration date column and it will handle default sorting of the user table by registration date.
The majority of this code was taken from [Mika Epstein's Recently Registered plugin](https://wordpress.org/plugins/recently-registered/). I added the bit to handle the default sort ... |
209,628 | <p>So this works:</p>
<pre><code>the_title( '<h1 class="entry-title">', '</h1>' );
</code></pre>
<p>But this does not:</p>
<pre><code>the_date( '<h4 class="entry-date">', '</h4>' );
</code></pre>
<p>I don't know enough if this is reserved for <code>the_title()</code> or if the twentyfifteen ... | [
{
"answer_id": 209630,
"author": "Howdy_McGee",
"author_id": 7355,
"author_profile": "https://wordpress.stackexchange.com/users/7355",
"pm_score": 3,
"selected": true,
"text": "<p><a href=\"https://codex.wordpress.org/Function_Reference/the_date\" rel=\"nofollow\">The Codex</a> ( or <a h... | 2015/11/23 | [
"https://wordpress.stackexchange.com/questions/209628",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/45709/"
] | So this works:
```
the_title( '<h1 class="entry-title">', '</h1>' );
```
But this does not:
```
the_date( '<h4 class="entry-date">', '</h4>' );
```
I don't know enough if this is reserved for `the_title()` or if the twentyfifteen theme has specified this functionality in functions. I don't see it but I could be m... | [The Codex](https://codex.wordpress.org/Function_Reference/the_date) ( or [Developer Resources](https://developer.wordpress.org/reference/functions/the_date/) ) is a fantastic tool when you're unsure about a function. Looking at the parameter list for [`the_date()`](https://codex.wordpress.org/Function_Reference/the_da... |
209,634 | <p>I want to add HTML5 required for the client side validation on textarea generated by </p>
<pre><code><?php
$content = '';
$editor_id = 'YOURID';
wp_editor( $content, $editor_id );
?>
</code></pre>
<p>What is the best way to add <code>required</code> on textarea?
Thank you.</p>
| [
{
"answer_id": 209643,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 1,
"selected": true,
"text": "<p>The visual editor is not a textarea, it is an iframe, therefor even if you could set an attribute it will ... | 2015/11/23 | [
"https://wordpress.stackexchange.com/questions/209634",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/74171/"
] | I want to add HTML5 required for the client side validation on textarea generated by
```
<?php
$content = '';
$editor_id = 'YOURID';
wp_editor( $content, $editor_id );
?>
```
What is the best way to add `required` on textarea?
Thank you. | The visual editor is not a textarea, it is an iframe, therefor even if you could set an attribute it will do nothing. You can set the attribute on the hidden textarea that will be sent to the server but since it is hidden I am not sure how an alert about it not being filled will be displayed and it might be different b... |
209,636 | <p>I am trying to use this code:</p>
<pre><code><?php if(count(get_post_ancestors($post->ID)) == 2 ) : ?>
<script>...</script>
<?php endif ?>
</code></pre>
<p>to add a script to a page <strong>but only if</strong> the page is a <strong>grandchild page</strong> (3rd level down, when ... | [
{
"answer_id": 209740,
"author": "Douglas.Sesar",
"author_id": 19945,
"author_profile": "https://wordpress.stackexchange.com/users/19945",
"pm_score": 0,
"selected": false,
"text": "<p>Try checking the $post->ID right at the wp hook:</p>\n\n<pre><code>add_action('wp','your_awesome_functi... | 2015/11/23 | [
"https://wordpress.stackexchange.com/questions/209636",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40679/"
] | I am trying to use this code:
```
<?php if(count(get_post_ancestors($post->ID)) == 2 ) : ?>
<script>...</script>
<?php endif ?>
```
to add a script to a page **but only if** the page is a **grandchild page** (3rd level down, when it has 2 ancestors):
**Desired Result (with code above):**
* Parent Page
+ C... | Something is changing your results from `get_ancestors()` or something is changing your query which "changes" your child pages to grandchild pages when queried on the page. It also seems from comments that the post ID's does not stay constant on the page.
What immediately catches my eye from your updated code is that... |
209,641 | <p>I would like to display a list of any users whose emails are detected to have email addresses from an array of domains.</p>
<p><code>$domains = array('domain1.com', 'domain2.com', 'domain3.com');</code></p>
<p>If any users match those domains they would be listed in an un-ordered list, such as:</p>
<p><code>user1... | [
{
"answer_id": 209740,
"author": "Douglas.Sesar",
"author_id": 19945,
"author_profile": "https://wordpress.stackexchange.com/users/19945",
"pm_score": 0,
"selected": false,
"text": "<p>Try checking the $post->ID right at the wp hook:</p>\n\n<pre><code>add_action('wp','your_awesome_functi... | 2015/11/24 | [
"https://wordpress.stackexchange.com/questions/209641",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84161/"
] | I would like to display a list of any users whose emails are detected to have email addresses from an array of domains.
`$domains = array('domain1.com', 'domain2.com', 'domain3.com');`
If any users match those domains they would be listed in an un-ordered list, such as:
`user1@domain1.com
user2@domain1.com
user3@d... | Something is changing your results from `get_ancestors()` or something is changing your query which "changes" your child pages to grandchild pages when queried on the page. It also seems from comments that the post ID's does not stay constant on the page.
What immediately catches my eye from your updated code is that... |
209,649 | <p>This is so basic, but i couldn't understand why it's not working, i'm trying to send parameter from add_action(), this is my code in my function.php:</p>
<pre><code>function testingID( $testParam) {
var_dump($testParam);
die();
}
add_action( 'init', 'testingID', 1,1);
</code></pre>
<p>I expect to have the scree... | [
{
"answer_id": 209650,
"author": "Aparna_29",
"author_id": 84165,
"author_profile": "https://wordpress.stackexchange.com/users/84165",
"pm_score": 0,
"selected": false,
"text": "<p>Where are you initializing the value of <code>$testParam</code>?</p>\n\n<p><code>add_action( 'init', 'testi... | 2015/11/24 | [
"https://wordpress.stackexchange.com/questions/209649",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/83610/"
] | This is so basic, but i couldn't understand why it's not working, i'm trying to send parameter from add\_action(), this is my code in my function.php:
```
function testingID( $testParam) {
var_dump($testParam);
die();
}
add_action( 'init', 'testingID', 1,1);
```
I expect to have the screen print '1' instead just ... | When an action is defined, the parameters passed to the callback are defined as well. For example, you can define an action with 4 parameters:
```
$a = 1;
$b = 2;
$c = 3;
$d = 4;
do_action( 'name_of_my_action', $a, $b, $c, $d );
```
Then, when you hook in that action, you can tell how many of those parameters will b... |
209,684 | <p>Can I pass dynamically to shortcode attributes like as the following example shows </p>
<pre><code>[ authoorsposts author = get_the_author_id(); ]
</code></pre>
| [
{
"answer_id": 209685,
"author": "Hans Spieß",
"author_id": 27933,
"author_profile": "https://wordpress.stackexchange.com/users/27933",
"pm_score": 0,
"selected": false,
"text": "<p>You could access the author object inside the <a href=\"https://codex.wordpress.org/Shortcode_API\" rel=\"... | 2015/11/24 | [
"https://wordpress.stackexchange.com/questions/209684",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84181/"
] | Can I pass dynamically to shortcode attributes like as the following example shows
```
[ authoorsposts author = get_the_author_id(); ]
``` | Not quite like that, but you can achieve the same result if you use a pre-defined value or argument in your shortcode to act as a "flag":
```
[authoorsposts author="post"]
```
...then in your handler:
```
function wpse_209684_author( $atts ) {
if ( ! empty( $atts['author'] ) ) {
$author = $atts['author'... |
209,694 | <p>I have to add a bubble notification in WordPress <code>wp_nav_menu</code> like the following code. </p>
<pre><code><ul>
<li> Tickets <span class="unread">2</span></li>
<li> Log-out</li>
</ul>
</code></pre>
<p>Here I have to add this part in ... | [
{
"answer_id": 209696,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 3,
"selected": true,
"text": "<p>For flexibility, you could assign the CSS <em>bubblecount</em> class to the corresponding menu item:</p>\n\n<p... | 2015/11/24 | [
"https://wordpress.stackexchange.com/questions/209694",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/43308/"
] | I have to add a bubble notification in WordPress `wp_nav_menu` like the following code.
```
<ul>
<li> Tickets <span class="unread">2</span></li>
<li> Log-out</li>
</ul>
```
Here I have to add this part in it.
```
<span class="unread">2</span>
```
I have seen this one and tried it.
``... | For flexibility, you could assign the CSS *bubblecount* class to the corresponding menu item:
[](https://i.stack.imgur.com/MaDdX.gif)
and then target it with:
```
if( in_array( 'bubblecount', (array) $item->classes ) )
$output .= '<span class="u... |
209,700 | <p>I am trying to generate a WordPress shortcode which will display a <a href="http://bxslider.com/" rel="nofollow">bxSlider</a>. The shortcode function itself works like a charm; I can pass my data and the shortcode is rendered properly.</p>
<p><strong>The problem:</strong></p>
<p>In the shortcode I also added an at... | [
{
"answer_id": 209696,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 3,
"selected": true,
"text": "<p>For flexibility, you could assign the CSS <em>bubblecount</em> class to the corresponding menu item:</p>\n\n<p... | 2015/11/24 | [
"https://wordpress.stackexchange.com/questions/209700",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/63422/"
] | I am trying to generate a WordPress shortcode which will display a [bxSlider](http://bxslider.com/). The shortcode function itself works like a charm; I can pass my data and the shortcode is rendered properly.
**The problem:**
In the shortcode I also added an attribute `id`, which will be used to pass an ID used to c... | For flexibility, you could assign the CSS *bubblecount* class to the corresponding menu item:
[](https://i.stack.imgur.com/MaDdX.gif)
and then target it with:
```
if( in_array( 'bubblecount', (array) $item->classes ) )
$output .= '<span class="u... |
209,706 | <p>I'm working on a plugin that modifies user capabilities and turns off a lot of things in the Admin pages. I'm having some problems with order of execution with my code, so I want to refactor it and make sure I completely understand when action hooks fire in WP, so I can tie my code to those hooks correctly.</p>
<p... | [
{
"answer_id": 209709,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 0,
"selected": false,
"text": "<p>The order of the hooks should not be important. If your plugin relays on the order then maybe you are doi... | 2015/11/24 | [
"https://wordpress.stackexchange.com/questions/209706",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/83299/"
] | I'm working on a plugin that modifies user capabilities and turns off a lot of things in the Admin pages. I'm having some problems with order of execution with my code, so I want to refactor it and make sure I completely understand when action hooks fire in WP, so I can tie my code to those hooks correctly.
I did a si... | I'm not sure if you mean some custom login dialog, but let's do some logging when we are on the `wp-login.php` page, where we fill the *login form* and press `enter`:
```
#-----------------
# Page Load #1
#-----------------
2015-11-24: 14:45:41 --- $_SERVER: Array
(
[REQUEST_URI] => /wp-login.php
[SCRI... |
209,712 | <p>I want to query attachments and exclude all images. </p>
<p>I can see how to include <em>only</em> images, using <code>'post_mime_type' => 'image/*'</code>, but I couldn't find any way of achieving the opposite. Is there any mime_type equivalent of <code>posts__not_in</code>?</p>
| [
{
"answer_id": 209714,
"author": "Howdy_McGee",
"author_id": 7355,
"author_profile": "https://wordpress.stackexchange.com/users/7355",
"pm_score": 5,
"selected": true,
"text": "<p>Pretty much the solution is to include all mimes <em>except</em> images. WordPress has a nifty little functi... | 2015/11/24 | [
"https://wordpress.stackexchange.com/questions/209712",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/63673/"
] | I want to query attachments and exclude all images.
I can see how to include *only* images, using `'post_mime_type' => 'image/*'`, but I couldn't find any way of achieving the opposite. Is there any mime\_type equivalent of `posts__not_in`? | Pretty much the solution is to include all mimes *except* images. WordPress has a nifty little function where it keeps all it's accepted mime-types called [`get_allowed_mime_types()`](https://codex.wordpress.org/Function_Reference/get_allowed_mime_types) ( cleverly named ) which returns an Array() of mimes. All we need... |
209,717 | <p>I'm trying to create a plugin for wordpress where the form stores data in a database.
I'm trying to make a submit button to update the status (field) of one row from 0 to 1 but its updating all the column, how can i make to update only the selected one.</p>
<p>Look at the code...</p>
<pre><code><table class="wi... | [
{
"answer_id": 209718,
"author": "nipeco",
"author_id": 84195,
"author_profile": "https://wordpress.stackexchange.com/users/84195",
"pm_score": 1,
"selected": false,
"text": "<p>Well I would add another parameter to the <code>change()</code> function like <strong>id</strong>.\nI am a lit... | 2015/11/24 | [
"https://wordpress.stackexchange.com/questions/209717",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84200/"
] | I'm trying to create a plugin for wordpress where the form stores data in a database.
I'm trying to make a submit button to update the status (field) of one row from 0 to 1 but its updating all the column, how can i make to update only the selected one.
Look at the code...
```
<table class="widefat">
<thead>
<tr><th ... | Well I would add another parameter to the `change()` function like **id**.
I am a little bit confused that your PHP code is wrapped in JavaScript Tags :D
In PHP i would do it like that:
```
function change($id) {
$sql="UPDATE wp_applications SET status = '1' WHERE id = '$id'";
...
```
In the form i assume the i... |
209,729 | <p>Trying to use <code>admin-ajax.php</code> to upload image from front-end form. I'm keep getting <code>0</code> with below code I have and not sure how to debug this or where it goes wrong.</p>
<p>I have HTML input file</p>
<pre><code><input type="file" name="wh_image_upload" id="wh_image_upload" multiple="false... | [
{
"answer_id": 209734,
"author": "Howdy_McGee",
"author_id": 7355,
"author_profile": "https://wordpress.stackexchange.com/users/7355",
"pm_score": 4,
"selected": true,
"text": "<h2><a href=\"https://codex.wordpress.org/Debugging_in_WordPress\" rel=\"noreferrer\">Enable Debugging</a></h2>... | 2015/11/24 | [
"https://wordpress.stackexchange.com/questions/209729",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/74171/"
] | Trying to use `admin-ajax.php` to upload image from front-end form. I'm keep getting `0` with below code I have and not sure how to debug this or where it goes wrong.
I have HTML input file
```
<input type="file" name="wh_image_upload" id="wh_image_upload" multiple="false" />
```
and localized script for AJAX reque... | [Enable Debugging](https://codex.wordpress.org/Debugging_in_WordPress)
----------------------------------------------------------------------
WordPress has constants defined in `wp-config.php` where you can print errors to the screen and log them in a separate file located `/wp-content/debug.log`. It looks like this:
... |
209,743 | <p>Hypothetical example but real world applicability (for someone learning, like me).</p>
<p>Given this code:</p>
<pre><code><?php
function send_money_to_grandma() {
internetofThings("send grandma","$1");
}
add_action('init','send_money_to_grandma');
add_action('init','send_money_to_grandma');
</code></pre>... | [
{
"answer_id": 209751,
"author": "tao",
"author_id": 45169,
"author_profile": "https://wordpress.stackexchange.com/users/45169",
"pm_score": 2,
"selected": false,
"text": "<p>You can't add the <strong>same action</strong> to the <strong>same action hook</strong>, with the <strong>same pr... | 2015/11/24 | [
"https://wordpress.stackexchange.com/questions/209743",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/83299/"
] | Hypothetical example but real world applicability (for someone learning, like me).
Given this code:
```
<?php
function send_money_to_grandma() {
internetofThings("send grandma","$1");
}
add_action('init','send_money_to_grandma');
add_action('init','send_money_to_grandma');
```
ok, now I bring up my WP site a... | Here are some random thoughts on this:
Question #1
-----------
>
> How much money did we send to grandma?
>
>
>
For 100 page loads, we sent her 100 x $1 = $100.
*Here we actually mean `100 x do_action( 'init' )` calls.*
It didn't matter that we added it twice with:
```
add_action( 'init','send_money_to_grand... |
209,768 | <p>We can easily asses a user's role using <code>current_user_can()</code>, but it doesn't support an array of user roles but a single role. So we have to check each of the role multiple times:</p>
<pre><code>if( current_user_can('administrator') || current_user_can('editor') ) {
//do this
}
</code></pre>
<p>I'm ma... | [
{
"answer_id": 209751,
"author": "tao",
"author_id": 45169,
"author_profile": "https://wordpress.stackexchange.com/users/45169",
"pm_score": 2,
"selected": false,
"text": "<p>You can't add the <strong>same action</strong> to the <strong>same action hook</strong>, with the <strong>same pr... | 2015/11/25 | [
"https://wordpress.stackexchange.com/questions/209768",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84224/"
] | We can easily asses a user's role using `current_user_can()`, but it doesn't support an array of user roles but a single role. So we have to check each of the role multiple times:
```
if( current_user_can('administrator') || current_user_can('editor') ) {
//do this
}
```
I'm making a WordPress Plugin, I need the a... | Here are some random thoughts on this:
Question #1
-----------
>
> How much money did we send to grandma?
>
>
>
For 100 page loads, we sent her 100 x $1 = $100.
*Here we actually mean `100 x do_action( 'init' )` calls.*
It didn't matter that we added it twice with:
```
add_action( 'init','send_money_to_grand... |
209,770 | <p>Here's a very simple plugin, which I drop into mu_plugins in my multisite installation:</p>
<pre><code><?php
/*
Plugin Name: Test
*/
class myclass {
function __construct() {
error_log("I just punched myself in the head.");
}
} // end of class definition
/* start of plugin functions */
funct... | [
{
"answer_id": 209751,
"author": "tao",
"author_id": 45169,
"author_profile": "https://wordpress.stackexchange.com/users/45169",
"pm_score": 2,
"selected": false,
"text": "<p>You can't add the <strong>same action</strong> to the <strong>same action hook</strong>, with the <strong>same pr... | 2015/11/25 | [
"https://wordpress.stackexchange.com/questions/209770",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/83299/"
] | Here's a very simple plugin, which I drop into mu\_plugins in my multisite installation:
```
<?php
/*
Plugin Name: Test
*/
class myclass {
function __construct() {
error_log("I just punched myself in the head.");
}
} // end of class definition
/* start of plugin functions */
function run_plugin()... | Here are some random thoughts on this:
Question #1
-----------
>
> How much money did we send to grandma?
>
>
>
For 100 page loads, we sent her 100 x $1 = $100.
*Here we actually mean `100 x do_action( 'init' )` calls.*
It didn't matter that we added it twice with:
```
add_action( 'init','send_money_to_grand... |
209,774 | <p>I have a folder with name:</p>
<pre><code>wordpress_install/dev/abc
</code></pre>
<p>Now, I have created a index.php in abc folder and I want all the urls like:</p>
<pre><code>wordpress_install/dev/abc/asdfasdfsdf (a 404 page)
</code></pre>
<p>to be redirected to </p>
<pre><code>wordpress_install/dev/abc/index.... | [
{
"answer_id": 209751,
"author": "tao",
"author_id": 45169,
"author_profile": "https://wordpress.stackexchange.com/users/45169",
"pm_score": 2,
"selected": false,
"text": "<p>You can't add the <strong>same action</strong> to the <strong>same action hook</strong>, with the <strong>same pr... | 2015/11/25 | [
"https://wordpress.stackexchange.com/questions/209774",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/75662/"
] | I have a folder with name:
```
wordpress_install/dev/abc
```
Now, I have created a index.php in abc folder and I want all the urls like:
```
wordpress_install/dev/abc/asdfasdfsdf (a 404 page)
```
to be redirected to
```
wordpress_install/dev/abc/index.php
```
My motive that any request (404 or anyt other) sho... | Here are some random thoughts on this:
Question #1
-----------
>
> How much money did we send to grandma?
>
>
>
For 100 page loads, we sent her 100 x $1 = $100.
*Here we actually mean `100 x do_action( 'init' )` calls.*
It didn't matter that we added it twice with:
```
add_action( 'init','send_money_to_grand... |
209,792 | <p>I need to make a shortcode to display some HTML on a page based on site admins "role"? Not the logged in user but the site admin's role. By default the role is 'administrator' and the only other role is 'pro_user'. So if they are a "pro_user" I want to echo the the first "HTML type 1" and if not to output "HTML type... | [
{
"answer_id": 209825,
"author": "AddWeb Solution Pvt Ltd",
"author_id": 73643,
"author_profile": "https://wordpress.stackexchange.com/users/73643",
"pm_score": 1,
"selected": false,
"text": "<p>I think below line of code is unnecessary, which is wrong if you looking for logged in user r... | 2015/11/25 | [
"https://wordpress.stackexchange.com/questions/209792",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/63757/"
] | I need to make a shortcode to display some HTML on a page based on site admins "role"? Not the logged in user but the site admin's role. By default the role is 'administrator' and the only other role is 'pro\_user'. So if they are a "pro\_user" I want to echo the the first "HTML type 1" and if not to output "HTML type ... | I think below line of code is unnecessary, which is wrong if you looking for logged in user result.
```
if( ! is_user_logged_in() )
```
Please use below code, I make some changes for solution.
```
//Add a hook for a shortcode 'add_my_form' tag...
add_shortcode( 'add_my_form', 'get_form_on_role' );
//Create sortco... |
209,818 | <p>So I have this <a href="http://workteamfun.ro/wp2/" rel="nofollow">site</a> and on the bottom of the site you can see the map and search. I have 2 problems with that:</p>
<ol>
<li>The search if offset not in line with the other elements.</li>
<li>I want/need it to be full width just like in the Take a Quick and FRE... | [
{
"answer_id": 209825,
"author": "AddWeb Solution Pvt Ltd",
"author_id": 73643,
"author_profile": "https://wordpress.stackexchange.com/users/73643",
"pm_score": 1,
"selected": false,
"text": "<p>I think below line of code is unnecessary, which is wrong if you looking for logged in user r... | 2015/11/25 | [
"https://wordpress.stackexchange.com/questions/209818",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/83780/"
] | So I have this [site](http://workteamfun.ro/wp2/) and on the bottom of the site you can see the map and search. I have 2 problems with that:
1. The search if offset not in line with the other elements.
2. I want/need it to be full width just like in the Take a Quick and FREE Tour page (scroll down a bit to see the map... | I think below line of code is unnecessary, which is wrong if you looking for logged in user result.
```
if( ! is_user_logged_in() )
```
Please use below code, I make some changes for solution.
```
//Add a hook for a shortcode 'add_my_form' tag...
add_shortcode( 'add_my_form', 'get_form_on_role' );
//Create sortco... |
209,823 | <p>I'm trying to send a query to a database, WHERE works fine if I'm querying for a number but not for a string. Example, if I try: </p>
<pre><code>$all_pages = $wpdb->get_results('SELECT post_title, guid FROM wp_11_posts WHERE ID = 30', OBJECT); I get a result, no problem
</code></pre>
<p>However when I try a str... | [
{
"answer_id": 209831,
"author": "AddWeb Solution Pvt Ltd",
"author_id": 73643,
"author_profile": "https://wordpress.stackexchange.com/users/73643",
"pm_score": -1,
"selected": false,
"text": "<p>Answer for: <strong><em>it doesn't return anything, wonder if anyone can spot the reason why... | 2015/11/25 | [
"https://wordpress.stackexchange.com/questions/209823",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/83847/"
] | I'm trying to send a query to a database, WHERE works fine if I'm querying for a number but not for a string. Example, if I try:
```
$all_pages = $wpdb->get_results('SELECT post_title, guid FROM wp_11_posts WHERE ID = 30', OBJECT); I get a result, no problem
```
However when I try a string, eg
```
$all_pages = $wp... | You do not need to use quotes around some data types in SQL, integers being one of those types. That is why the first block of code works. It is a perfectly valid SQL statement.
You do need to quote strings in SQL. That is why your second block of code does not work. The correct form would be:
```
$all_pages = $wpdb... |
209,840 | <p>I created a sub page to "users.php" where I can add a user in a customized way. I used a lot of the code from "<strong>user-new.php</strong>". However, user-new.php seems to rely on some javascript file to display the password when clicking the button, and to display errors, and maybe more.</p>
<p>How do I know wha... | [
{
"answer_id": 209842,
"author": "Aparna_29",
"author_id": 84165,
"author_profile": "https://wordpress.stackexchange.com/users/84165",
"pm_score": 1,
"selected": false,
"text": "<p>You must have created submenu page using add_submenu_page() hook, so you can use wp_enqueue_script inside c... | 2015/11/25 | [
"https://wordpress.stackexchange.com/questions/209840",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/82394/"
] | I created a sub page to "users.php" where I can add a user in a customized way. I used a lot of the code from "**user-new.php**". However, user-new.php seems to rely on some javascript file to display the password when clicking the button, and to display errors, and maybe more.
How do I know what script files "user-ne... | You must have created submenu page using add\_submenu\_page() hook, so you can use wp\_enqueue\_script inside callback function of add\_submenu\_page hook. It will load script only on your submenu page.
```
add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug,'callback');
function callbac... |
209,860 | <p>I'm currently building a custom WordPress template and I've run into a problem with the search box.</p>
<p>When I use the searchbox from the homepage, it works as intended. It also works as long as Permalinks are set to default. (<code>url.com/?page_id=1</code>) </p>
<p>However, when I use the searchbox from anoth... | [
{
"answer_id": 209867,
"author": "jgraup",
"author_id": 84219,
"author_profile": "https://wordpress.stackexchange.com/users/84219",
"pm_score": 1,
"selected": true,
"text": "<p>Currently your form looks like:</p>\n\n<pre><code><form id=\"search-query\">\n <p class=\"in-englis... | 2015/11/25 | [
"https://wordpress.stackexchange.com/questions/209860",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/82005/"
] | I'm currently building a custom WordPress template and I've run into a problem with the search box.
When I use the searchbox from the homepage, it works as intended. It also works as long as Permalinks are set to default. (`url.com/?page_id=1`)
However, when I use the searchbox from another page when using pretty pe... | Currently your form looks like:
```
<form id="search-query">
<p class="in-english"><a href="http://localhost/hermodswp/?page_id=76">Information in English</a></p>
<div class="search-box">
<div>
<label class="screen-reader-text" for="s"></label>
<input type="text"... |
209,870 | <p>I am wondering how to write code to order a list of posts by their terms from custom taxonomies?</p>
<p><strong>Here is what I have so far</strong>:</p>
<ul>
<li>I have a page that lists all the posts in a Custom Post Type, on one
page.</li>
<li>Under each CPT Post, I have retrieved the Custom Taxonomies to show.<... | [
{
"answer_id": 210346,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 3,
"selected": true,
"text": "<p>WordPress core (as expressed by involved people on multiple occasions) strongly discourages sort by terms. It sees t... | 2015/11/25 | [
"https://wordpress.stackexchange.com/questions/209870",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/83426/"
] | I am wondering how to write code to order a list of posts by their terms from custom taxonomies?
**Here is what I have so far**:
* I have a page that lists all the posts in a Custom Post Type, on one
page.
* Under each CPT Post, I have retrieved the Custom Taxonomies to show.
* I have allowed for the CPT posts to be ... | WordPress core (as expressed by involved people on multiple occasions) strongly discourages sort by terms. It sees terms as exclusively *grouping* mechanism, with no ordering capabilities implied.
So in your specific case WP would understand that there are different directors, that there are groups of shows done by th... |
209,890 | <p>I am converting a custom built site into a WordPress site. Unfortunately, the custom site has a completely different URL structure, which we would like to set up 301 redirects for. The site receives upwards of 300k unique visitors per month, therefore we wish to minimise the loss of traffic - especially the articles... | [
{
"answer_id": 209924,
"author": "Envision eCommerce",
"author_id": 84031,
"author_profile": "https://wordpress.stackexchange.com/users/84031",
"pm_score": 0,
"selected": false,
"text": "<p>Solution, Permalink > Common Settings > Custom Structure </p>\n\n<p>Use this slug: <code>/%categor... | 2015/11/25 | [
"https://wordpress.stackexchange.com/questions/209890",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84275/"
] | I am converting a custom built site into a WordPress site. Unfortunately, the custom site has a completely different URL structure, which we would like to set up 301 redirects for. The site receives upwards of 300k unique visitors per month, therefore we wish to minimise the loss of traffic - especially the articles li... | The cause of this issue for future reference was the '.' in the category base, which was added to resolve a previous issue. Removing this and using /category/postname (per question) works, so will look for an alternative resolution to the category base issue. |
209,920 | <p>Can you please take a Look at <a href="http://rumioptical.com/new-arrivals/" rel="nofollow noreferrer">this page</a> (please hove over the image to see the paragraph) and let me know why the <code>the_content()</code> is jumping out of paragraph tag?</p>
<pre><code> echo '<p style="color:#fff !important; font-s... | [
{
"answer_id": 209922,
"author": "mukto90",
"author_id": 57944,
"author_profile": "https://wordpress.stackexchange.com/users/57944",
"pm_score": 3,
"selected": true,
"text": "<p>The function <code>the_content()</code> prints the content with a <code>p</code> tag itself. I mean, if you us... | 2015/11/26 | [
"https://wordpress.stackexchange.com/questions/209920",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/31793/"
] | Can you please take a Look at [this page](http://rumioptical.com/new-arrivals/) (please hove over the image to see the paragraph) and let me know why the `the_content()` is jumping out of paragraph tag?
```
echo '<p style="color:#fff !important; font-size:16px; line-height:18;">'.the_content().'</p>';
```
Here us ... | The function `the_content()` prints the content with a `p` tag itself. I mean, if you use
```
echo '<p class="our_p">' . the_content() . '</p>;
```
It actually outputs-
```
<p class="our_p"><p>lorem ipsum dolor sit amet...</p></p>
```
Use `get_the_content()` instead. It will return the unfiltered content. Someth... |
209,928 | <p>I need your help to upload a media image in my wordpress blog via the Wp-rest-api v2 and Oauth2 authentication. </p>
<p>I did not find in the REST API documentation the way to send my image data (name of field, sending mode...?).</p>
<pre><code>require('OAuth2/Client.php');
require('OAuth2/GrantType/IGrantType.php... | [
{
"answer_id": 217588,
"author": "MikeNGarrett",
"author_id": 1670,
"author_profile": "https://wordpress.stackexchange.com/users/1670",
"pm_score": 5,
"selected": true,
"text": "<p>SO! This is fun. </p>\n\n<p>Keep in mind the WP-API is still very, very much a work-in-progress. </p>\n\n<h... | 2015/11/26 | [
"https://wordpress.stackexchange.com/questions/209928",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84303/"
] | I need your help to upload a media image in my wordpress blog via the Wp-rest-api v2 and Oauth2 authentication.
I did not find in the REST API documentation the way to send my image data (name of field, sending mode...?).
```
require('OAuth2/Client.php');
require('OAuth2/GrantType/IGrantType.php');
require('OAuth2/G... | SO! This is fun.
Keep in mind the WP-API is still very, very much a work-in-progress.
Content-Disposition
-------------------
I found [an issue reported on the WP-API issue queue](https://github.com/WP-API/WP-API/issues/1744) about Content-Disposition. This is a required header for posting new media content and th... |
209,940 | <p>I require to retrieve a list of the recently created blog posts or any Query-based usage of WP posts inside my PHP website and not within WP framework.</p>
<p>I am new to Wordpress and stucked here. I already tried with include <code>wp-includes/post.php</code> file but i guess its still not working. Facing error r... | [
{
"answer_id": 209941,
"author": "Bozidar Sikanjic",
"author_id": 84223,
"author_profile": "https://wordpress.stackexchange.com/users/84223",
"pm_score": 0,
"selected": false,
"text": "<blockquote>\n <p>I require to retrieve a list of the recently created blog posts</p>\n</blockquote>\n... | 2015/11/26 | [
"https://wordpress.stackexchange.com/questions/209940",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84297/"
] | I require to retrieve a list of the recently created blog posts or any Query-based usage of WP posts inside my PHP website and not within WP framework.
I am new to Wordpress and stucked here. I already tried with include `wp-includes/post.php` file but i guess its still not working. Facing error regarding `undefined c... | It's just simple, same reply from Error in [WP\_update\_post](https://wordpress.stackexchange.com/questions/209919/error-in-wp-update-post/209921#209921) but in your case there is small change.
Just use `wp-load.php` as include. No need to include `post.php`. Once the `wp-load.php` file is included, the entire wealth ... |
209,979 | <p>I have custom post type 'Partnerzy' already set. While adding new 'Partner', you select a category (kredyty, leasingi, etc.). And having that, I need to show them on a page, like this:
<a href="https://i.stack.imgur.com/IU0vw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IU0vw.png" alt="enter im... | [
{
"answer_id": 209980,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 2,
"selected": false,
"text": "<p>I honestly don't know what problem you are trying to solve. It is not clear what you are trying to accomplis... | 2015/11/26 | [
"https://wordpress.stackexchange.com/questions/209979",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/77857/"
] | I have custom post type 'Partnerzy' already set. While adding new 'Partner', you select a category (kredyty, leasingi, etc.). And having that, I need to show them on a page, like this:
[](https://i.stack.imgur.com/IU0vw.png)
I figured out that all I n... | I honestly don't know what problem you are trying to solve. It is not clear what you are trying to accomplish with this code, but:
>
> `echo count($the_query_partnerzy);`
>
>
> really is counting elements in this query, but shows only 1 (weird).
> And having that, I'm not able to move further than this.
>
>
>
... |
210,008 | <p>I need help with this.
I need repeat taxonomy in two places, are post, and coupones post, this code is in clipper theme.</p>
<p>this code put taxonomy stores in coupon.</p>
<pre><code>add_action('init', 'clpr_post_type', 0);
// remove_action('init', 'create_builtin_taxonomies', 0); // in case we want to remove all... | [
{
"answer_id": 209980,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 2,
"selected": false,
"text": "<p>I honestly don't know what problem you are trying to solve. It is not clear what you are trying to accomplis... | 2015/11/26 | [
"https://wordpress.stackexchange.com/questions/210008",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/82358/"
] | I need help with this.
I need repeat taxonomy in two places, are post, and coupones post, this code is in clipper theme.
this code put taxonomy stores in coupon.
```
add_action('init', 'clpr_post_type', 0);
// remove_action('init', 'create_builtin_taxonomies', 0); // in case we want to remove all default WP taxonomie... | I honestly don't know what problem you are trying to solve. It is not clear what you are trying to accomplish with this code, but:
>
> `echo count($the_query_partnerzy);`
>
>
> really is counting elements in this query, but shows only 1 (weird).
> And having that, I'm not able to move further than this.
>
>
>
... |
210,044 | <p>I have created a way of choosing different layouts for posts(sidebar right, sidebar left, full width). This is done through a meta box that displays radio buttons with an image for each layout type. When I, for example, select the first layout image single.php file is loaded, when I chose the second image single-tem... | [
{
"answer_id": 210051,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 1,
"selected": false,
"text": "<p>The differences does not seem to be big enough to make it worth 3 different templates.</p>\n\n<p>You can ... | 2015/11/27 | [
"https://wordpress.stackexchange.com/questions/210044",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/82982/"
] | I have created a way of choosing different layouts for posts(sidebar right, sidebar left, full width). This is done through a meta box that displays radio buttons with an image for each layout type. When I, for example, select the first layout image single.php file is loaded, when I chose the second image single-templa... | The differences does not seem to be big enough to make it worth 3 different templates.
You can probably just use the [body\_class](https://codex.wordpress.org/Plugin_API/Filter_Reference/body_class) filter to add a class based on the meta and adjust the CSS to hide or show the sidebar at a specific location based on t... |
210,064 | <p>I would like to hide this particular taxonomy box in the admin on the add new post page.</p>
<p><a href="https://i.stack.imgur.com/YUsbG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YUsbG.jpg" alt="enter image description here"></a></p>
| [
{
"answer_id": 210068,
"author": "jas",
"author_id": 80247,
"author_profile": "https://wordpress.stackexchange.com/users/80247",
"pm_score": 0,
"selected": false,
"text": "<p>Hi I assume its your meta box while adding new post:</p>\n\n<p>Please go to <code>http://www.example.com/wp-admin... | 2015/11/27 | [
"https://wordpress.stackexchange.com/questions/210064",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17862/"
] | I would like to hide this particular taxonomy box in the admin on the add new post page.
[](https://i.stack.imgur.com/YUsbG.jpg) | The following worked for me in functions.php
```
/**
* [remove_meta_boxes remove the resource type standard meta box from the side sortables in the resource post edit screen
* @return [type] [description]
*/
function remove_meta_boxes(){
remove_meta_box( 'resourcetypesdiv', 'resource','side' );
}
add_action( 'admi... |
210,069 | <p>For testing purposes I keep short time intervals for cron and when the functionality is working fine, I change it to the required time interval. Whenever I change the time intervals for ex: from 'three_days' to 'five_minutes' or from 'five_minutes' to 'fifteen_minutes', the cron is running with earlier frequency and... | [
{
"answer_id": 210074,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 2,
"selected": true,
"text": "<blockquote>\n<p>Whenever I change the time intervals for ex: from 'three_days' to 'five_minutes' or from 'fiv... | 2015/11/27 | [
"https://wordpress.stackexchange.com/questions/210069",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84378/"
] | For testing purposes I keep short time intervals for cron and when the functionality is working fine, I change it to the required time interval. Whenever I change the time intervals for ex: from 'three\_days' to 'five\_minutes' or from 'five\_minutes' to 'fifteen\_minutes', the cron is running with earlier frequency an... | >
> Whenever I change the time intervals for ex: from 'three\_days' to 'five\_minutes' or from 'five\_minutes' to 'fifteen\_minutes', the cron is running with earlier frequency and not the updated one.
>
>
>
Because you only reschedule the event if it does not exist:
```
if ( ! wp_next_scheduled( 'bd_cron_cache' ... |
210,071 | <p>So basically I need to access the value of checked() in order to load diferent template parts in my single.php file.</p>
<p>This is my meta box:</p>
<pre><code><?php
function my_theme_add_meta_box_post_template_switcher() {
dd_meta_box( 'my_theme-post-layout', __( 'Post template', 'my_theme' ), 'my_... | [
{
"answer_id": 210074,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 2,
"selected": true,
"text": "<blockquote>\n<p>Whenever I change the time intervals for ex: from 'three_days' to 'five_minutes' or from 'fiv... | 2015/11/27 | [
"https://wordpress.stackexchange.com/questions/210071",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/82982/"
] | So basically I need to access the value of checked() in order to load diferent template parts in my single.php file.
This is my meta box:
```
<?php
function my_theme_add_meta_box_post_template_switcher() {
dd_meta_box( 'my_theme-post-layout', __( 'Post template', 'my_theme' ), 'my_theme_show_post_template... | >
> Whenever I change the time intervals for ex: from 'three\_days' to 'five\_minutes' or from 'five\_minutes' to 'fifteen\_minutes', the cron is running with earlier frequency and not the updated one.
>
>
>
Because you only reschedule the event if it does not exist:
```
if ( ! wp_next_scheduled( 'bd_cron_cache' ... |
210,097 | <p>I'm looking for option to change language_attributes manually without hardcoding it like </p>
<pre><code>html lang="en-US"
</code></pre>
<p>in html it self.
The reason for this is I have three language site, using same WP engine and I want one and each of them run with specific lang attribute. Is this possible?
It... | [
{
"answer_id": 210101,
"author": "jgraup",
"author_id": 84219,
"author_profile": "https://wordpress.stackexchange.com/users/84219",
"pm_score": 2,
"selected": false,
"text": "<p>You can use a filter to modify the value before it is set</p>\n\n<pre><code>function __language_attributes($la... | 2015/11/27 | [
"https://wordpress.stackexchange.com/questions/210097",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84388/"
] | I'm looking for option to change language\_attributes manually without hardcoding it like
```
html lang="en-US"
```
in html it self.
The reason for this is I have three language site, using same WP engine and I want one and each of them run with specific lang attribute. Is this possible?
It would be nice to have so... | You can use a filter to modify the value before it is set
```
function __language_attributes($lang){
// ignore the supplied argument
$langs = array( 'en-US', 'KO', 'JA' );
// change to whatever you want
$my_language = $langs[0];
// return the new attribute
return 'lang="'.$my_language.'"';
}
add_filter... |
210,099 | <p>I have a multilingual site setup: www.jeroenbrugman.com</p>
<p>The main dutch version uses Fluxus. On the artwork page I output a link using this from Functions.php</p>
<pre><code>function prefix_term_name($terms, $post_id, $taxonomy ) {
foreach ($terms as &$term) {
$term->name = 'Terug naar '.$term-&... | [
{
"answer_id": 210102,
"author": "Abhik",
"author_id": 26991,
"author_profile": "https://wordpress.stackexchange.com/users/26991",
"pm_score": 2,
"selected": true,
"text": "<p>You need to make the function pluggable, that means, to support child themes, the functions in parent theme shou... | 2015/11/27 | [
"https://wordpress.stackexchange.com/questions/210099",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/83929/"
] | I have a multilingual site setup: www.jeroenbrugman.com
The main dutch version uses Fluxus. On the artwork page I output a link using this from Functions.php
```
function prefix_term_name($terms, $post_id, $taxonomy ) {
foreach ($terms as &$term) {
$term->name = 'Terug naar '.$term->name;
}
}
return $terms;... | You need to make the function pluggable, that means, to support child themes, the functions in parent theme should use:
```
if ( !function_exists( 'function_name' )) {
function function_name() {
//Stuffs
}
}
```
You should have seen a PHP Error message if you have [debugging enabled](https://codex... |
210,109 | <p>A 3rd party plugin that I use adds a shortcode that displays a list of adverts (CPT posts). The shortcode function includes (with an <code>include</code> statement) a template - the <code>list.php</code> file, that displays a search form and, in its turn, includes a second template - the <code>list-item.php</code> f... | [
{
"answer_id": 210102,
"author": "Abhik",
"author_id": 26991,
"author_profile": "https://wordpress.stackexchange.com/users/26991",
"pm_score": 2,
"selected": true,
"text": "<p>You need to make the function pluggable, that means, to support child themes, the functions in parent theme shou... | 2015/11/27 | [
"https://wordpress.stackexchange.com/questions/210109",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25187/"
] | A 3rd party plugin that I use adds a shortcode that displays a list of adverts (CPT posts). The shortcode function includes (with an `include` statement) a template - the `list.php` file, that displays a search form and, in its turn, includes a second template - the `list-item.php` file, that displays the list of adver... | You need to make the function pluggable, that means, to support child themes, the functions in parent theme should use:
```
if ( !function_exists( 'function_name' )) {
function function_name() {
//Stuffs
}
}
```
You should have seen a PHP Error message if you have [debugging enabled](https://codex... |
210,116 | <p>This is what I have:</p>
<pre><code>global $wpdb, $month;
$months = $wpdb->get_results( "SELECT *
FROM $wpdb->posts
WHERE post_type = 'post' AND post_status = 'publish'
AND DATE_FORMAT( post_date_gmt, '%Y' ) = $y
GROUP BY DATE_FORMAT( post_date_gmt, '%Y-%m' )
ORDER BY post_date_gmt DESC
"... | [
{
"answer_id": 210118,
"author": "Gyanendra Giri",
"author_id": 47270,
"author_profile": "https://wordpress.stackexchange.com/users/47270",
"pm_score": 0,
"selected": false,
"text": "<p>To show all posts from a category ID 11. Use following loop. It will show all posts from category ID 1... | 2015/11/27 | [
"https://wordpress.stackexchange.com/questions/210116",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/48130/"
] | This is what I have:
```
global $wpdb, $month;
$months = $wpdb->get_results( "SELECT *
FROM $wpdb->posts
WHERE post_type = 'post' AND post_status = 'publish'
AND DATE_FORMAT( post_date_gmt, '%Y' ) = $y
GROUP BY DATE_FORMAT( post_date_gmt, '%Y-%m' )
ORDER BY post_date_gmt DESC
");
```
The problem... | it's quite easy:
```
$months = $wpdb->get_col("SELECT DATE_FORMAT(post_date_gmt, '%m')
FROM $wpdb->posts
LEFT JOIN $wpdb->term_relationships as t
ON ID = t.object_id
WHERE post_type = 'post' AND post_statu... |
210,126 | <p>I am writing a plugin that instantiates a custom post type (among other things). It is a multisite plugin and lives in the directory <strong>mu-plugins</strong>.</p>
<p>What is the best practice for handling <strong>flush_rewrite_rules()</strong> in this situation? For a 'normal' plugin you'd do this in an activa... | [
{
"answer_id": 216647,
"author": "Leon Francis Shelhamer",
"author_id": 25927,
"author_profile": "https://wordpress.stackexchange.com/users/25927",
"pm_score": 0,
"selected": false,
"text": "<p>If your mu-plugin has options I would put the flush right after updating them:</p>\n\n<pre><co... | 2015/11/28 | [
"https://wordpress.stackexchange.com/questions/210126",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/83299/"
] | I am writing a plugin that instantiates a custom post type (among other things). It is a multisite plugin and lives in the directory **mu-plugins**.
What is the best practice for handling **flush\_rewrite\_rules()** in this situation? For a 'normal' plugin you'd do this in an activation hook -- which is not going to b... | The `flush_rewrite_rules` function is reliable in some contexts like a theme or a plugin based on hooks but I'm not sure if it works for a `mu-plugin`
My statement is based on the fact that WordPress is initialized in this way:
* call the `wp-settings.php` file
* call the `do_action( 'muplugins_loaded' );` hook, here... |
210,127 | <p>I am trying to built fancybox plugins.I added all js and css file to my php file and add one image to it ,but I found this error.</p>
<blockquote>
<p>The plugins generated 3265 characters of unexpected output during activation.</p>
<p>If you notice “headers already sent” messages, problems with syndication feeds or ... | [
{
"answer_id": 216647,
"author": "Leon Francis Shelhamer",
"author_id": 25927,
"author_profile": "https://wordpress.stackexchange.com/users/25927",
"pm_score": 0,
"selected": false,
"text": "<p>If your mu-plugin has options I would put the flush right after updating them:</p>\n\n<pre><co... | 2015/11/28 | [
"https://wordpress.stackexchange.com/questions/210127",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84167/"
] | I am trying to built fancybox plugins.I added all js and css file to my php file and add one image to it ,but I found this error.
>
> The plugins generated 3265 characters of unexpected output during activation.
>
>
> If you notice “headers already sent” messages, problems with syndication feeds or other issues, tr... | The `flush_rewrite_rules` function is reliable in some contexts like a theme or a plugin based on hooks but I'm not sure if it works for a `mu-plugin`
My statement is based on the fact that WordPress is initialized in this way:
* call the `wp-settings.php` file
* call the `do_action( 'muplugins_loaded' );` hook, here... |
210,169 | <p>I would like to get relative path from a php file without knowing the absolute path.
I have succeeded to do it but for a reason which I don't know, on some servers (in rare case) it doesn't work when I enqueue css/js. Slashes are missing...</p>
<p>Here the code:</p>
<pre><code>define('PATH', trailingslashit(str_re... | [
{
"answer_id": 210170,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 1,
"selected": false,
"text": "<p>Just don't do it, you can never know if the plugins directory is even \"below\" ABSPATH, and you can not ... | 2015/11/28 | [
"https://wordpress.stackexchange.com/questions/210169",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/35097/"
] | I would like to get relative path from a php file without knowing the absolute path.
I have succeeded to do it but for a reason which I don't know, on some servers (in rare case) it doesn't work when I enqueue css/js. Slashes are missing...
Here the code:
```
define('PATH', trailingslashit(str_replace('\\', '/', dirn... | Just don't do it, you can never know if the plugins directory is even "below" ABSPATH, and you can not know the URL out of the directory path <https://codex.wordpress.org/Determining_Plugin_and_Content_Directories>.
Just use the core api of plugins\_utl etc, don't reinvent the wheel. |
210,199 | <p>The error I'm seeing is that the way I currently have my category page set up, if a post on that page has more than 1 category, the loop won't load the posts that follow the one with multiple categories. </p>
<p>Currently I have about 10 posts in my test installation of WordPress. 9 of them have the same category, ... | [
{
"answer_id": 210200,
"author": "Hans Spieß",
"author_id": 27933,
"author_profile": "https://wordpress.stackexchange.com/users/27933",
"pm_score": 2,
"selected": true,
"text": "<h3>Multiple Loops</h3>\n\n<p>Outside the loop you can get available terms of the core taxonomy <em>category</... | 2015/11/29 | [
"https://wordpress.stackexchange.com/questions/210199",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/35549/"
] | The error I'm seeing is that the way I currently have my category page set up, if a post on that page has more than 1 category, the loop won't load the posts that follow the one with multiple categories.
Currently I have about 10 posts in my test installation of WordPress. 9 of them have the same category, lets call ... | ### Multiple Loops
Outside the loop you can get available terms of the core taxonomy *category* with [`get_terms( 'taxonomy_name' )`](https://codex.wordpress.org/Function_Reference/get_terms). The resulting array contains objects like
```
object(stdClass)#141 (9) {
["term_id"] => string(1) "3"
["name"] => str... |
210,218 | <p>I am trying to make a site with two languages. I was looking for a solution and didn't find a simple how-to answer. Also, I prefer not to use plugins when it is possible.</p>
<p>What I'm trying to do:</p>
<p>1) To have a <code>domain.com/en</code> and <code>domain.com/ru</code> while default redirect is at <code>d... | [
{
"answer_id": 210200,
"author": "Hans Spieß",
"author_id": 27933,
"author_profile": "https://wordpress.stackexchange.com/users/27933",
"pm_score": 2,
"selected": true,
"text": "<h3>Multiple Loops</h3>\n\n<p>Outside the loop you can get available terms of the core taxonomy <em>category</... | 2015/11/29 | [
"https://wordpress.stackexchange.com/questions/210218",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84453/"
] | I am trying to make a site with two languages. I was looking for a solution and didn't find a simple how-to answer. Also, I prefer not to use plugins when it is possible.
What I'm trying to do:
1) To have a `domain.com/en` and `domain.com/ru` while default redirect is at `domain.com/en`.
2) One WP engine install, s... | ### Multiple Loops
Outside the loop you can get available terms of the core taxonomy *category* with [`get_terms( 'taxonomy_name' )`](https://codex.wordpress.org/Function_Reference/get_terms). The resulting array contains objects like
```
object(stdClass)#141 (9) {
["term_id"] => string(1) "3"
["name"] => str... |
210,222 | <p>Why does Woocommerce use hooks rather than including template parts?</p>
<p>I'm in the process of creating my first Woocommerce theme, and it seems that deactivating the current hooks and then readding them to change the order of a section real overkill. To me, it makes more sense that you just include each of the ... | [
{
"answer_id": 210225,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 2,
"selected": false,
"text": "<p>I'm not familiar with Woocommerce, but in short, <a href=\"https://developer.wordpress.org/reference/fu... | 2015/11/29 | [
"https://wordpress.stackexchange.com/questions/210222",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/27866/"
] | Why does Woocommerce use hooks rather than including template parts?
I'm in the process of creating my first Woocommerce theme, and it seems that deactivating the current hooks and then readding them to change the order of a section real overkill. To me, it makes more sense that you just include each of the template p... | I'm not familiar with Woocommerce, but in short, [`get_template_part()`](https://developer.wordpress.org/reference/functions/get_template_part/) only look for template parts in parent and child themes, not in plugins.
If you look at the source code, `get_template_part()` uses [`locate_template`](https://developer.word... |
210,229 | <p>I am using wp_insert_post and all the fields are working except tax_input is working. Is there something wrong with my code?</p>
<pre><code>$customtax = array(
'product_link' => $link,
'product_price' => $price,
'product_description' => $desc );
$my_post = array(
'post_title' => $title,
'post_co... | [
{
"answer_id": 210233,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 5,
"selected": false,
"text": "<p>The most common reason is that you run this code without user context (cron, etc). Within <code>wp_insert_post()</c... | 2015/11/29 | [
"https://wordpress.stackexchange.com/questions/210229",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84458/"
] | I am using wp\_insert\_post and all the fields are working except tax\_input is working. Is there something wrong with my code?
```
$customtax = array(
'product_link' => $link,
'product_price' => $price,
'product_description' => $desc );
$my_post = array(
'post_title' => $title,
'post_content' => $content,
... | The most common reason is that you run this code without user context (cron, etc). Within `wp_insert_post()` context WP will check if user has permissions to a taxonomy. No user equals no permissions equals no terms being assigned.
The workaround is to create post first, then assign terms to it. When terms are assigne... |
210,285 | <p>I am trying to figure out how to use another single.php for a custom plugin I'm making. It's for a custom post type.</p>
<p>Because if people install this plugin, they won't have the custom single-product.php in their theme folder. That's why I want it to be in the plugin folder.</p>
<p>Is there a way to change th... | [
{
"answer_id": 210286,
"author": "flomei",
"author_id": 65455,
"author_profile": "https://wordpress.stackexchange.com/users/65455",
"pm_score": 4,
"selected": true,
"text": "<p>I think a hook into <code>template_include</code> like <a href=\"https://wordpress.stackexchange.com/questions/... | 2015/11/30 | [
"https://wordpress.stackexchange.com/questions/210285",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/67623/"
] | I am trying to figure out how to use another single.php for a custom plugin I'm making. It's for a custom post type.
Because if people install this plugin, they won't have the custom single-product.php in their theme folder. That's why I want it to be in the plugin folder.
Is there a way to change the path of this cu... | I think a hook into `template_include` like [described here](https://wordpress.stackexchange.com/questions/55763/is-it-possible-to-define-a-template-for-a-custom-post-type-within-a-plugin-indep) could be a proper way to do this.
Code could be like this:
```
add_filter('template_include', 'my_plugin_templates');
funct... |
210,304 | <p>Is it possible to add a page that is totally blank and doesn't use any components of the site's theme? Or is the best way to do that to upload it separately to the web server outside of WordPress?</p>
| [
{
"answer_id": 210306,
"author": "phatskat",
"author_id": 20143,
"author_profile": "https://wordpress.stackexchange.com/users/20143",
"pm_score": 4,
"selected": true,
"text": "<p><strong>Edit:</strong> Updated with the added context from your comment.</p>\n\n<p>You could do this with a c... | 2015/11/30 | [
"https://wordpress.stackexchange.com/questions/210304",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/81877/"
] | Is it possible to add a page that is totally blank and doesn't use any components of the site's theme? Or is the best way to do that to upload it separately to the web server outside of WordPress? | **Edit:** Updated with the added context from your comment.
You could do this with a custom Page template. In your theme, create a new file. In this example, my theme will be "mytheme2015," my new file is "template-holiday-card.php":
in wp-content/themes/mytheme2015/template-holiday-card.php
```
<?php
/**
* Template... |
210,305 | <p>Using underscores, I made a lot of small, simple custome themes. I was more interested in CSS and simple layout modifications, but I'm not used to vanilla PHP. What I need I think is a simple code, but I can't wrap my head around it and I've been trying for hours.
I'm trying to have a different layout for my front p... | [
{
"answer_id": 210307,
"author": "designarti",
"author_id": 84495,
"author_profile": "https://wordpress.stackexchange.com/users/84495",
"pm_score": 0,
"selected": false,
"text": "<p>Oh, boy. I did manage to fix that and I will answer my first question here on WPSE.\nIt shouldn't work wit... | 2015/11/30 | [
"https://wordpress.stackexchange.com/questions/210305",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84495/"
] | Using underscores, I made a lot of small, simple custome themes. I was more interested in CSS and simple layout modifications, but I'm not used to vanilla PHP. What I need I think is a simple code, but I can't wrap my head around it and I've been trying for hours.
I'm trying to have a different layout for my front page... | Your first code sample didn't work because the `elseif` had no condition. `elseif` is a concatenation of `else` and `if`:
```
if ( something ) {
} elseif ( something else ) {
} else {
}
```
Or
```
<?php if ( something ): ?>
<?php elseif ( something else ): ?>
<?php else: ?>
<?php endif; ?>
```
Also, if you ... |
210,320 | <p>The basic challenge:
I have a 'normal' custom query, e.g. of news posts from a certain category and want to add in several elements (CTAs, generally speaking) at every nth position, while the loop of cta_elements (see below) is being repeated when more news posts exist than cta_elements could fill up. HTML example ... | [
{
"answer_id": 210324,
"author": "Michelle",
"author_id": 16,
"author_profile": "https://wordpress.stackexchange.com/users/16",
"pm_score": 0,
"selected": false,
"text": "<p>I'd go the custom post type / custom taxonomy route. Then you can set up your archives with a for/each loop to cou... | 2015/11/30 | [
"https://wordpress.stackexchange.com/questions/210320",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25245/"
] | The basic challenge:
I have a 'normal' custom query, e.g. of news posts from a certain category and want to add in several elements (CTAs, generally speaking) at every nth position, while the loop of cta\_elements (see below) is being repeated when more news posts exist than cta\_elements could fill up. HTML example b... | For anyone interested in something similar, this is what a fellow pro did come up with, it’s 1. registering a specific sidebar for my widget insertion, 2. getting the DOM node from the sidebar as HTML string and 3. putting it together while looping through the available widgets.
Put this into your **functions.php**:
... |
210,322 | <p>I'm setting up some transactionals emails on my site and I'd like to send one 3 days after a user signed up if he didn't post. Here is what I have:</p>
<pre><code>function set_mail_html_content_type() {
return 'text/html';
}
add_action( 'user_help_signup', 10 ,2 );
function user_help_signup( $ID, //DURATION SI... | [
{
"answer_id": 210324,
"author": "Michelle",
"author_id": 16,
"author_profile": "https://wordpress.stackexchange.com/users/16",
"pm_score": 0,
"selected": false,
"text": "<p>I'd go the custom post type / custom taxonomy route. Then you can set up your archives with a for/each loop to cou... | 2015/11/30 | [
"https://wordpress.stackexchange.com/questions/210322",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/68671/"
] | I'm setting up some transactionals emails on my site and I'd like to send one 3 days after a user signed up if he didn't post. Here is what I have:
```
function set_mail_html_content_type() {
return 'text/html';
}
add_action( 'user_help_signup', 10 ,2 );
function user_help_signup( $ID, //DURATION SINCE SIGN UP ) ... | For anyone interested in something similar, this is what a fellow pro did come up with, it’s 1. registering a specific sidebar for my widget insertion, 2. getting the DOM node from the sidebar as HTML string and 3. putting it together while looping through the available widgets.
Put this into your **functions.php**:
... |
210,330 | <p>How do I change specific section background image in wordpress?</p>
<p>I have a background image set via CSS:</p>
<pre><code>.section3 {
background: url(bg.jpg) no repeat;
}
</code></pre>
<p>Say I want to change this image later via the WordPress dashboard. How would I do this? I want to add functionality so ... | [
{
"answer_id": 210324,
"author": "Michelle",
"author_id": 16,
"author_profile": "https://wordpress.stackexchange.com/users/16",
"pm_score": 0,
"selected": false,
"text": "<p>I'd go the custom post type / custom taxonomy route. Then you can set up your archives with a for/each loop to cou... | 2015/11/30 | [
"https://wordpress.stackexchange.com/questions/210330",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84503/"
] | How do I change specific section background image in wordpress?
I have a background image set via CSS:
```
.section3 {
background: url(bg.jpg) no repeat;
}
```
Say I want to change this image later via the WordPress dashboard. How would I do this? I want to add functionality so that user can change the image in... | For anyone interested in something similar, this is what a fellow pro did come up with, it’s 1. registering a specific sidebar for my widget insertion, 2. getting the DOM node from the sidebar as HTML string and 3. putting it together while looping through the available widgets.
Put this into your **functions.php**:
... |
210,358 | <p>I've tried searching for this using various terminology, but I always end up at questions pertaining to the php template files. That's not what I'm looking for, so I'm asking a new question. I apologize if this is a duplicate.</p>
<p>Basically, I'm looking for a way to create template posts. I'm using ACF Pro on a ... | [
{
"answer_id": 210363,
"author": "jgraup",
"author_id": 84219,
"author_profile": "https://wordpress.stackexchange.com/users/84219",
"pm_score": 1,
"selected": false,
"text": "<p>It's possible you may have to define your own <a href=\"http://www.advancedcustomfields.com/resources/creating... | 2015/11/30 | [
"https://wordpress.stackexchange.com/questions/210358",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/45704/"
] | I've tried searching for this using various terminology, but I always end up at questions pertaining to the php template files. That's not what I'm looking for, so I'm asking a new question. I apologize if this is a duplicate.
Basically, I'm looking for a way to create template posts. I'm using ACF Pro on a custom "Jo... | I know I posted an answer to this already, but I've found a better solution, so I wanted to take the time to share that.
As it turns out, there is one small hiccup with the JS solution in my previous answer that didn't surface until I had a friend test my in progress application.
The Problem
-----------
Previously, ... |
210,359 | <p>I would like a WordPress site to redirect all URLs to the <code>www</code> subdomain. Using the <code>.htaccess</code> configuration below, the homepage is properly redirected (i.e. visiting <code>example.com/</code> redirects to <code>www.example.com/</code>) but internal pages aren't getting redirected (both <code... | [
{
"answer_id": 210363,
"author": "jgraup",
"author_id": 84219,
"author_profile": "https://wordpress.stackexchange.com/users/84219",
"pm_score": 1,
"selected": false,
"text": "<p>It's possible you may have to define your own <a href=\"http://www.advancedcustomfields.com/resources/creating... | 2015/11/30 | [
"https://wordpress.stackexchange.com/questions/210359",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/76695/"
] | I would like a WordPress site to redirect all URLs to the `www` subdomain. Using the `.htaccess` configuration below, the homepage is properly redirected (i.e. visiting `example.com/` redirects to `www.example.com/`) but internal pages aren't getting redirected (both `www.example.com/page` and `example.com/page` resolv... | I know I posted an answer to this already, but I've found a better solution, so I wanted to take the time to share that.
As it turns out, there is one small hiccup with the JS solution in my previous answer that didn't surface until I had a friend test my in progress application.
The Problem
-----------
Previously, ... |
210,374 | <p>I am working on an area of my site for members. However, I need a link on my menu that when clicked it will take people to my login form then back to the page they were previously on. I need the same with log out.</p>
<p>Example:
Bob logs in on page A.
Bob has a successful login.
Bob is returned to page A.</p>
<p>... | [
{
"answer_id": 210379,
"author": "mukto90",
"author_id": 57944,
"author_profile": "https://wordpress.stackexchange.com/users/57944",
"pm_score": 1,
"selected": false,
"text": "<p>Use <code>wp_login_url()</code> function with <code>get_permalink()</code> as a parameter, if a user is not l... | 2015/12/01 | [
"https://wordpress.stackexchange.com/questions/210374",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/82369/"
] | I am working on an area of my site for members. However, I need a link on my menu that when clicked it will take people to my login form then back to the page they were previously on. I need the same with log out.
Example:
Bob logs in on page A.
Bob has a successful login.
Bob is returned to page A.
Bob clicks the lo... | Use `wp_login_url()` function with `get_permalink()` as a parameter, if a user is not logged in. Something like this:
```
<a href="<?php echo wp_login_url( get_permalink() ); ?>" title="Login">Login</a>
```
And `wp_logout_url` function with `get_permalink()` as a parameter, if a user is logged in.
```
<a href="<?ph... |
210,392 | <p>I'm building a new site for client based on Wordpress.They already have a non-Wordpress site that logged in visitors can access (on a different domain). I've searched a solution for this all over for the last month or so but I cant seem to find a solution.</p>
<p>What I need is to add a pop up login form to a menu ... | [
{
"answer_id": 210379,
"author": "mukto90",
"author_id": 57944,
"author_profile": "https://wordpress.stackexchange.com/users/57944",
"pm_score": 1,
"selected": false,
"text": "<p>Use <code>wp_login_url()</code> function with <code>get_permalink()</code> as a parameter, if a user is not l... | 2015/12/01 | [
"https://wordpress.stackexchange.com/questions/210392",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84539/"
] | I'm building a new site for client based on Wordpress.They already have a non-Wordpress site that logged in visitors can access (on a different domain). I've searched a solution for this all over for the last month or so but I cant seem to find a solution.
What I need is to add a pop up login form to a menu item on th... | Use `wp_login_url()` function with `get_permalink()` as a parameter, if a user is not logged in. Something like this:
```
<a href="<?php echo wp_login_url( get_permalink() ); ?>" title="Login">Login</a>
```
And `wp_logout_url` function with `get_permalink()` as a parameter, if a user is logged in.
```
<a href="<?ph... |
210,394 | <pre><code><?php
/* Template Name : Home
*/
?>
get_header(); ?>
<?php get_footer(); ?>
</code></pre>
<p>When I type anything on content editor of the page it doesn't show any thing. </p>
<p>How do I make it working?</p>
| [
{
"answer_id": 210379,
"author": "mukto90",
"author_id": 57944,
"author_profile": "https://wordpress.stackexchange.com/users/57944",
"pm_score": 1,
"selected": false,
"text": "<p>Use <code>wp_login_url()</code> function with <code>get_permalink()</code> as a parameter, if a user is not l... | 2015/12/01 | [
"https://wordpress.stackexchange.com/questions/210394",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84503/"
] | ```
<?php
/* Template Name : Home
*/
?>
get_header(); ?>
<?php get_footer(); ?>
```
When I type anything on content editor of the page it doesn't show any thing.
How do I make it working? | Use `wp_login_url()` function with `get_permalink()` as a parameter, if a user is not logged in. Something like this:
```
<a href="<?php echo wp_login_url( get_permalink() ); ?>" title="Login">Login</a>
```
And `wp_logout_url` function with `get_permalink()` as a parameter, if a user is logged in.
```
<a href="<?ph... |
210,423 | <p>I am using <a href="https://metabox.io/docs/" rel="nofollow">Metabox</a> to create metaboxes for Worpdress Post and it works like a charm. Now I have installed <a href="https://metabox.io/plugins/custom-post-type/" rel="nofollow">MetaBox Custom Post Type Extension</a> for create CPT and it works good to. I have <a h... | [
{
"answer_id": 210379,
"author": "mukto90",
"author_id": 57944,
"author_profile": "https://wordpress.stackexchange.com/users/57944",
"pm_score": 1,
"selected": false,
"text": "<p>Use <code>wp_login_url()</code> function with <code>get_permalink()</code> as a parameter, if a user is not l... | 2015/12/01 | [
"https://wordpress.stackexchange.com/questions/210423",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16412/"
] | I am using [Metabox](https://metabox.io/docs/) to create metaboxes for Worpdress Post and it works like a charm. Now I have installed [MetaBox Custom Post Type Extension](https://metabox.io/plugins/custom-post-type/) for create CPT and it works good to. I have [Types](https://wordpress.org/plugins/types/) plugin instal... | Use `wp_login_url()` function with `get_permalink()` as a parameter, if a user is not logged in. Something like this:
```
<a href="<?php echo wp_login_url( get_permalink() ); ?>" title="Login">Login</a>
```
And `wp_logout_url` function with `get_permalink()` as a parameter, if a user is logged in.
```
<a href="<?ph... |
210,438 | <p>We have a class which is common to few plugins that we develop. As time goes we improve the class and add new functions so we have class variable which is the class version. </p>
<p>Because multiple plugins have this class with different versions it's happen that a plugin initiate an older version of the class beca... | [
{
"answer_id": 210440,
"author": "jdm2112",
"author_id": 45202,
"author_profile": "https://wordpress.stackexchange.com/users/45202",
"pm_score": 1,
"selected": false,
"text": "<p>If you are using a version control (like Git) then using a submodule seems the best way to version a common p... | 2015/12/01 | [
"https://wordpress.stackexchange.com/questions/210438",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/28237/"
] | We have a class which is common to few plugins that we develop. As time goes we improve the class and add new functions so we have class variable which is the class version.
Because multiple plugins have this class with different versions it's happen that a plugin initiate an older version of the class because it's l... | [CMB2](https://github.com/WebDevStudios/CMB2) has a clever way of handling the same situation. It establishes a version constant that is a high number for the first release (9999), and on each subsequent release, the version constant is decremented. The version number is used for the priority of the action that instant... |
210,459 | <p>To further clarify my question: Reviewing sites like Polygon have sections where you click on Reviews, and it shows you a page with a grid of all their reviews (latest will be at the top though). They usually have a thumbnail of the game on the left, some text in the middle, and then a score on the right. Here's an ... | [
{
"answer_id": 210440,
"author": "jdm2112",
"author_id": 45202,
"author_profile": "https://wordpress.stackexchange.com/users/45202",
"pm_score": 1,
"selected": false,
"text": "<p>If you are using a version control (like Git) then using a submodule seems the best way to version a common p... | 2015/12/01 | [
"https://wordpress.stackexchange.com/questions/210459",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84582/"
] | To further clarify my question: Reviewing sites like Polygon have sections where you click on Reviews, and it shows you a page with a grid of all their reviews (latest will be at the top though). They usually have a thumbnail of the game on the left, some text in the middle, and then a score on the right. Here's an [ex... | [CMB2](https://github.com/WebDevStudios/CMB2) has a clever way of handling the same situation. It establishes a version constant that is a high number for the first release (9999), and on each subsequent release, the version constant is decremented. The version number is used for the priority of the action that instant... |
210,463 | <p>I have IDs for my child categories, <code>11,14,21,35,38,39</code>, where these all are various child categories from their main category:</p>
<ul>
<li>Parent category <code>1</code> has: <code>11,14</code></li>
<li>Parent category <code>2</code> has: <code>21</code></li>
<li>Parent category <code>3</code> has: <co... | [
{
"answer_id": 210471,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 2,
"selected": true,
"text": "<p>The quick take would be something like this:</p>\n\n<pre><code>$categories = [ ];\n$parent_categories = get_c... | 2015/12/01 | [
"https://wordpress.stackexchange.com/questions/210463",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84151/"
] | I have IDs for my child categories, `11,14,21,35,38,39`, where these all are various child categories from their main category:
* Parent category `1` has: `11,14`
* Parent category `2` has: `21`
* Parent category `3` has: `35,38,39`
How can I group my child IDs as per their parent category, like below?
```
array(
... | The quick take would be something like this:
```
$categories = [ ];
$parent_categories = get_categories( [ 'parent' => 0 ] );
foreach ( $parent_categories as $parent_category ) {
$id = $parent_category->term_id;
$categories[ $id ] = wp_list_pluck( get_categories( [ 'parent' => $id ] ), '... |
210,493 | <p>I have this piece of code:</p>
<pre><code>$normal_args = array(
'order' => 'desc',
'ignore_sticky_posts' => 1,
'meta_query' => array(
array(
'key' => 'rw_show_at_position',
'value' => '1',
'compare' => '='
... | [
{
"answer_id": 210613,
"author": "bosco",
"author_id": 25324,
"author_profile": "https://wordpress.stackexchange.com/users/25324",
"pm_score": 3,
"selected": true,
"text": "<p>You could use the <a href=\"https://codex.wordpress.org/Metadata_API\" rel=\"nofollow noreferrer\">Metadata API<... | 2015/12/02 | [
"https://wordpress.stackexchange.com/questions/210493",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16412/"
] | I have this piece of code:
```
$normal_args = array(
'order' => 'desc',
'ignore_sticky_posts' => 1,
'meta_query' => array(
array(
'key' => 'rw_show_at_position',
'value' => '1',
'compare' => '='
)
),
'post__not_in' ... | You could use the [Metadata API](https://codex.wordpress.org/Metadata_API) to retrieve the `rw_advertising_position` metadata for each post, seperate the ads from the content, and then re-insert the ads at the proper locations:
```
/**
* Extracts from an array posts with positional metadata and re-inserts them at the... |
210,496 | <p>I want to prepend a hashtag (#) in front of the tags on my post pages in Wordpress using jQuery. This code is not working:</p>
<pre><code>$('div.tags a').prepend('#');
</code></pre>
<p>This is the php:</p>
<pre><code><div class="tags">
<?php the_tags( ' ', ' ', '' ); ?>
</div>
</code></pre>
... | [
{
"answer_id": 210511,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 2,
"selected": false,
"text": "<p>Using JS is not really the best possible solution as it can be disabled on client side. You can also us... | 2015/12/02 | [
"https://wordpress.stackexchange.com/questions/210496",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/69541/"
] | I want to prepend a hashtag (#) in front of the tags on my post pages in Wordpress using jQuery. This code is not working:
```
$('div.tags a').prepend('#');
```
This is the php:
```
<div class="tags">
<?php the_tags( ' ', ' ', '' ); ?>
</div>
```
I don't want the "#" to be part of the the stored tag, just add... | I didn't want to edit the tags themselves, I just wanted to add the "#" for visual purposes.
I decided to add this to the CSS to solve the problem:
```
.tags a::before {
content: '#';
}
```
Thanks for your time and input. |
210,505 | <p>The below will return the other post in the same category but it will also return the current post too. </p>
<p>Is there a way to exclude the current post from the query?</p>
<pre><code>$args = array(
'post_type' => 'custom_post_type',
'tax_query' => array(
array(
'taxonomy' => 'custo... | [
{
"answer_id": 210513,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 4,
"selected": true,
"text": "<p>Simply add</p>\n\n<pre><code>'post__not_in' => [get_queried_object_id()],\n</code></pre>\n\n<p>to you... | 2015/12/02 | [
"https://wordpress.stackexchange.com/questions/210505",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/54374/"
] | The below will return the other post in the same category but it will also return the current post too.
Is there a way to exclude the current post from the query?
```
$args = array(
'post_type' => 'custom_post_type',
'tax_query' => array(
array(
'taxonomy' => 'custom_taxo',
'field' =... | Simply add
```
'post__not_in' => [get_queried_object_id()],
```
to your array of query arguments. `get_queried_object_id()` will return the post ID of the currently viewed single post, and `post__not_in` will skip the posts whos ID's was passed as an array to the parameter |
210,518 | <p>Is that possible to get current post ID without passing in shortcode as parameter. Like [related-post] I want to get the post ID in which post this shortcode will use.</p>
<pre><code>add_shortcode( 'related-article', 'related_article_title' );
function related_article_title( $atts ) {
$post_id = get_the_ID();
... | [
{
"answer_id": 263938,
"author": "Erenor Paz",
"author_id": 90143,
"author_profile": "https://wordpress.stackexchange.com/users/90143",
"pm_score": 2,
"selected": false,
"text": "<p>Just as @gorakh-shrestha was trying, using <code>global $post</code> and then <code>$post->ID</code>, i... | 2015/12/02 | [
"https://wordpress.stackexchange.com/questions/210518",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80519/"
] | Is that possible to get current post ID without passing in shortcode as parameter. Like [related-post] I want to get the post ID in which post this shortcode will use.
```
add_shortcode( 'related-article', 'related_article_title' );
function related_article_title( $atts ) {
$post_id = get_the_ID();
echo $post_... | ```
add_shortcode( 'related-article', 'related_article_title' );
function related_article_title( $atts ) {
global $post;
echo $post->ID; // currently viewing post id
ob_start();
$query = new WP_Query( array(
'post_type' => 'post',
'posts_per_page' => 1,
'order' => 'DESC',
... |
210,520 | <p>I am getting too frustrated while creating new home page using template in Storefront theme. <a href="https://wordpress.org/themes/storefront/" rel="nofollow">https://wordpress.org/themes/storefront/</a>.</p>
<p>With the help of this <a href="https://developer.wordpress.org/themes/template-files-section/page-templa... | [
{
"answer_id": 210532,
"author": "Envision eCommerce",
"author_id": 84031,
"author_profile": "https://wordpress.stackexchange.com/users/84031",
"pm_score": 0,
"selected": false,
"text": "<p>First create a new page in theme directory</p>\n\n<p>example <code>template-newhomepage.php</code>... | 2015/12/02 | [
"https://wordpress.stackexchange.com/questions/210520",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25404/"
] | I am getting too frustrated while creating new home page using template in Storefront theme. <https://wordpress.org/themes/storefront/>.
With the help of this <https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/>
i tried bt not getting success.. anyone can tell me how can ... | First step in modifying a theme, is [creating a child theme](https://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme).
Now that you have a theme that is basically the same as the original, you can simply copy files of the original theme that you want to modify into exactly the same relative location as in... |
210,534 | <p>i has create galley in post as: <code>[gallery columns="6" link="file" ids="156,113,99,67,103,102"]</code></p>
<p>Now, how to show list image in <code>[gallery columns="6" link="file" ids="156,113,99,67,103,102"]</code> in to index as:</p>
<pre><code><a href="#" title=""><img src="link image in gallery"&g... | [
{
"answer_id": 210532,
"author": "Envision eCommerce",
"author_id": 84031,
"author_profile": "https://wordpress.stackexchange.com/users/84031",
"pm_score": 0,
"selected": false,
"text": "<p>First create a new page in theme directory</p>\n\n<p>example <code>template-newhomepage.php</code>... | 2015/12/02 | [
"https://wordpress.stackexchange.com/questions/210534",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/65359/"
] | i has create galley in post as: `[gallery columns="6" link="file" ids="156,113,99,67,103,102"]`
Now, how to show list image in `[gallery columns="6" link="file" ids="156,113,99,67,103,102"]` in to index as:
```
<a href="#" title=""><img src="link image in gallery">
.....
<a href="#" title=""><img src="link image in g... | First step in modifying a theme, is [creating a child theme](https://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme).
Now that you have a theme that is basically the same as the original, you can simply copy files of the original theme that you want to modify into exactly the same relative location as in... |
210,551 | <p>I'm trying to do is the following.
<strong>If the excerpt length is shorter than 30 charakters</strong>, than do..</p>
<pre><code><?php if ( get_the_excerpt() <= 30 AND has_post_thumbnail() ) : ?>
<div></div>
<?php else : ?>
<div></div>
<?php endif; ?>
</code></pre... | [
{
"answer_id": 210557,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 2,
"selected": true,
"text": "<p>This is more PHP as you need to use <a href=\"http://php.net/manual/en/function.str-word-count.php\" rel... | 2015/12/02 | [
"https://wordpress.stackexchange.com/questions/210551",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/77898/"
] | I'm trying to do is the following.
**If the excerpt length is shorter than 30 charakters**, than do..
```
<?php if ( get_the_excerpt() <= 30 AND has_post_thumbnail() ) : ?>
<div></div>
<?php else : ?>
<div></div>
<?php endif; ?>
```
But it seems like that's not the way to read out the length.
I was playing aro... | This is more PHP as you need to use [`str_word_count()`](http://php.net/manual/en/function.str-word-count.php) to count the amount of words in the excerpt. Just note, to be safe, if you allow any tags in the excerpt, you would want to use `strip_tags()` to remove html tags to avoid incorrect word counts.
EXAMPLE:
----... |
210,564 | <p>I am following a tutorial that will hopefully allow me to insert templates straight from my plugin into WordPress. I am using the template_include filter, I can't get my head around how the whole filter process works. </p>
<p>Here is the code.</p>
<pre><code>public function view_project_template( $template ) {
... | [
{
"answer_id": 210566,
"author": "Nicolai Grossherr",
"author_id": 22534,
"author_profile": "https://wordpress.stackexchange.com/users/22534",
"pm_score": 0,
"selected": false,
"text": "<p>You have no effect, because you haven't done anything with <code>$template</code> - not that you ha... | 2015/12/02 | [
"https://wordpress.stackexchange.com/questions/210564",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/64115/"
] | I am following a tutorial that will hopefully allow me to insert templates straight from my plugin into WordPress. I am using the template\_include filter, I can't get my head around how the whole filter process works.
Here is the code.
```
public function view_project_template( $template ) {
global $post;
... | You are using the filter wrongly, that is why you might not get the desired result. Lets first look at the `template_include` filter which you can check out in [`wp-includes/template-loader.php`](https://core.trac.wordpress.org/browser/tags/4.3.1/src/wp-includes/template-loader.php#L74) (*current version 4.3.1*)
```
4... |
210,578 | <p>I have a private theme and I want to deploy new theme versions of it as smoothly as possible.</p>
<p>I've heard about:</p>
<ul>
<li>hosting the theme somewhere like wp-updates.com</li>
<li>using plugins to update theme automatically directly from a repository (using plugins like <a href="https://github.com/afragen... | [
{
"answer_id": 210649,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 0,
"selected": false,
"text": "<p>With direct access to server <em>typically</em> people just upload/sync file changes on top. However this leaves po... | 2015/12/02 | [
"https://wordpress.stackexchange.com/questions/210578",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84627/"
] | I have a private theme and I want to deploy new theme versions of it as smoothly as possible.
I've heard about:
* hosting the theme somewhere like wp-updates.com
* using plugins to update theme automatically directly from a repository (using plugins like <https://github.com/afragen/github-updater> or <https://wordpre... | I've been using this approach for private theme updates using versioned archives and it seems to work for me pretty well.
No problems found yet.
So I guess for private themes - it is a good one.
Also I came up with a script for building versioned theme archive like this:
```
#!/bin/bash
echo "======================"... |
210,597 | <p>Using v2 of the REST API, I'm wanting to query some posts by <strong>multiple</strong> meta keys. With v1 I was able to format the url like <code>&filter[meta_value][month]=12&[meta_value][year]=2015</code> and it worked (after exposing the meta values to the API).</p>
<p>Now with v2, I can only get this to... | [
{
"answer_id": 212113,
"author": "jgraup",
"author_id": 84219,
"author_profile": "https://wordpress.stackexchange.com/users/84219",
"pm_score": 4,
"selected": true,
"text": "<p>Adding a <a href=\"http://v2.wp-api.org/extending/adding/\" rel=\"noreferrer\">custom endpoint</a> is pretty st... | 2015/12/02 | [
"https://wordpress.stackexchange.com/questions/210597",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25756/"
] | Using v2 of the REST API, I'm wanting to query some posts by **multiple** meta keys. With v1 I was able to format the url like `&filter[meta_value][month]=12&[meta_value][year]=2015` and it worked (after exposing the meta values to the API).
Now with v2, I can only get this to work by using the methods listed on this ... | Adding a [custom endpoint](http://v2.wp-api.org/extending/adding/) is pretty straightforward.
I also modified the url to look more like
`http://example.com/wp-json/namespace/v2/posts?filter[meta_value][month]=12&filter[meta_value][year]=2015`
```
function wp_json_namespace_v2__init()
{
// create json-api endpoi... |
210,604 | <p>The output I am trying to achieve is this:</p>
<pre><code><div class="row">
<div class="small-1 large-4 columns"><a href="some link"><img src="some image"></a></div>
<div class="small-1 large-4 columns"><a href="some link"><img src="some image"></a></di... | [
{
"answer_id": 210641,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 3,
"selected": true,
"text": "<p>You could simplify things by using the <a href=\"http://php.net/manual/en/function.array-chunk.php\" rel=\"nof... | 2015/12/03 | [
"https://wordpress.stackexchange.com/questions/210604",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84666/"
] | The output I am trying to achieve is this:
```
<div class="row">
<div class="small-1 large-4 columns"><a href="some link"><img src="some image"></a></div>
<div class="small-1 large-4 columns"><a href="some link"><img src="some image"></a></div>
<div class="small-1 large-4 columns"><a href="some link"><img src="some im... | You could simplify things by using the [`array_chunk()`](http://php.net/manual/en/function.array-chunk.php) PHP function, to split an array into smaller chunks. Then you don't need to worry about opening and closing divs with some math tricks.
Let's rewrite your code snippet and hopefully make it easier to work with:
... |
210,609 | <p>I'm trying to create a post when a user registers using the code from here:</p>
<p><a href="https://wordpress.stackexchange.com/questions/53328/create-posts-on-user-registration">Create posts on user registration</a></p>
<p>The user registers and the post is created BUT the user firstname and user lastname is not ... | [
{
"answer_id": 210641,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 3,
"selected": true,
"text": "<p>You could simplify things by using the <a href=\"http://php.net/manual/en/function.array-chunk.php\" rel=\"nof... | 2015/12/03 | [
"https://wordpress.stackexchange.com/questions/210609",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84671/"
] | I'm trying to create a post when a user registers using the code from here:
[Create posts on user registration](https://wordpress.stackexchange.com/questions/53328/create-posts-on-user-registration)
The user registers and the post is created BUT the user firstname and user lastname is not working. Each time a post is... | You could simplify things by using the [`array_chunk()`](http://php.net/manual/en/function.array-chunk.php) PHP function, to split an array into smaller chunks. Then you don't need to worry about opening and closing divs with some math tricks.
Let's rewrite your code snippet and hopefully make it easier to work with:
... |
210,639 | <p>Is it possible to grab the custom post type post id just only from slug? </p>
<p>As much i know we can get from id by using title. But there can be same title in a custom post type so as slugs are unique is it possible???</p>
| [
{
"answer_id": 210646,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 7,
"selected": true,
"text": "<p>You can use <a href=\"https://developer.wordpress.org/reference/functions/get_page_by_path/\" rel=\"norefer... | 2015/12/03 | [
"https://wordpress.stackexchange.com/questions/210639",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/82119/"
] | Is it possible to grab the custom post type post id just only from slug?
As much i know we can get from id by using title. But there can be same title in a custom post type so as slugs are unique is it possible??? | You can use [`get_page_by_path()`](https://developer.wordpress.org/reference/functions/get_page_by_path/) - don't let the name fool you, third argument is the post type:
```
if ( $post = get_page_by_path( 'the_slug', OBJECT, 'post_type' ) )
$id = $post->ID;
else
$id = 0;
``` |
210,666 | <p>I have this function:</p>
<pre><code>function wpse_210493_apply_advertising_position( &$posts, $return = false ) {
$ad_posts = array();
$content_posts = array_filter(
$posts,
function ( $post ) {
$position = get_post_meta( $post->ID, 'rw_adversiting_position', true );
... | [
{
"answer_id": 210668,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 5,
"selected": true,
"text": "<p>You can simply use <code>var_dump()</code> to do this. That is how I check values inside functions and f... | 2015/12/03 | [
"https://wordpress.stackexchange.com/questions/210666",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16412/"
] | I have this function:
```
function wpse_210493_apply_advertising_position( &$posts, $return = false ) {
$ad_posts = array();
$content_posts = array_filter(
$posts,
function ( $post ) {
$position = get_post_meta( $post->ID, 'rw_adversiting_position', true );
if ( empty(... | You can simply use `var_dump()` to do this. That is how I check values inside functions and filters.
I have the following line of code in a file which I simply copy and paste where needed to dump the value of a variable
```
?><pre><?php var_dump( $variable_to_test ); ?></pre><?php
```
The `pre` tags dump a nice re... |
210,667 | <p>I have created a custom excerpt length in my functions.php, I would like to extend this function to increase the excerpt length of the first post in a loop.</p>
<p><strong>My function at the moment:</strong></p>
<pre><code>/* Change Excerpt length */
function custom_excerpt_length( $length ) {
return 30;
}
</c... | [
{
"answer_id": 210668,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 5,
"selected": true,
"text": "<p>You can simply use <code>var_dump()</code> to do this. That is how I check values inside functions and f... | 2015/12/03 | [
"https://wordpress.stackexchange.com/questions/210667",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71177/"
] | I have created a custom excerpt length in my functions.php, I would like to extend this function to increase the excerpt length of the first post in a loop.
**My function at the moment:**
```
/* Change Excerpt length */
function custom_excerpt_length( $length ) {
return 30;
}
```
**Was thinking of something alo... | You can simply use `var_dump()` to do this. That is how I check values inside functions and filters.
I have the following line of code in a file which I simply copy and paste where needed to dump the value of a variable
```
?><pre><?php var_dump( $variable_to_test ); ?></pre><?php
```
The `pre` tags dump a nice re... |
210,683 | <p>I have a dynamic list of checkboxes that are showing on a user profile in the admin area (user-edit.php). A user should be able to select the checkboxes which will save their selections as an array in a usermeta field. Easy enough. However when I load the user profile after Updating the User, the boxes are not ch... | [
{
"answer_id": 210668,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 5,
"selected": true,
"text": "<p>You can simply use <code>var_dump()</code> to do this. That is how I check values inside functions and f... | 2015/12/03 | [
"https://wordpress.stackexchange.com/questions/210683",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/34548/"
] | I have a dynamic list of checkboxes that are showing on a user profile in the admin area (user-edit.php). A user should be able to select the checkboxes which will save their selections as an array in a usermeta field. Easy enough. However when I load the user profile after Updating the User, the boxes are not checked ... | You can simply use `var_dump()` to do this. That is how I check values inside functions and filters.
I have the following line of code in a file which I simply copy and paste where needed to dump the value of a variable
```
?><pre><?php var_dump( $variable_to_test ); ?></pre><?php
```
The `pre` tags dump a nice re... |
210,701 | <p>I want to display an admin_notice error message on the custom admin page of my plugin - but I want it to only be displayed from a jQuery event. </p>
<p>All of my jQuery is working. I can send data, see alerts, receive data. But I cannot get the error message to work from the jQuery event.</p>
<p>This displays the ... | [
{
"answer_id": 210707,
"author": "Douglas.Sesar",
"author_id": 19945,
"author_profile": "https://wordpress.stackexchange.com/users/19945",
"pm_score": 2,
"selected": false,
"text": "<p>You can add the error message HTML in the success function of your AJAX call: </p>\n\n<pre><code>jQuery... | 2015/12/03 | [
"https://wordpress.stackexchange.com/questions/210701",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84705/"
] | I want to display an admin\_notice error message on the custom admin page of my plugin - but I want it to only be displayed from a jQuery event.
All of my jQuery is working. I can send data, see alerts, receive data. But I cannot get the error message to work from the jQuery event.
This displays the error message on... | You can add the error message HTML in the success function of your AJAX call:
```
jQuery(document).ready(function() {
jQuery("#my-button").click(function() {
jQuery.ajax({
type: 'POST',
url: myAjax.ajaxurl,
data: {
"action": "test_function"
},
success: function(... |
210,717 | <p>I have set up my plugin option on admin panel with</p>
<pre><code> /**
* Register and add settings
*/
public function page_init()
{
register_setting(
'my_option_group', // Option group
'write_here_options', // Option name
array( $this, 'sanitiz... | [
{
"answer_id": 210781,
"author": "s_ha_dum",
"author_id": 21376,
"author_profile": "https://wordpress.stackexchange.com/users/21376",
"pm_score": 2,
"selected": false,
"text": "<p>Your code will certainly use <a href=\"http://codex.wordpress.org/Function_Reference/get_option\" rel=\"nofo... | 2015/12/03 | [
"https://wordpress.stackexchange.com/questions/210717",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/74171/"
] | I have set up my plugin option on admin panel with
```
/**
* Register and add settings
*/
public function page_init()
{
register_setting(
'my_option_group', // Option group
'write_here_options', // Option name
array( $this, 'sanitize' ) // Saniti... | I added below code to set default value to DB when plugin is activated.
```
function write_here_activation_actions(){
do_action( 'wp_writehere_extension_activation' );
}
register_activation_hook( __FILE__, 'write_here_activation_actions' );
// Set default values here
function write_here_default_options(){
$def... |
210,752 | <p>I want to change the status of already publish post to draft using its id.</p>
<pre><code> add_action( 'save_post', 'change_post_status', 1 );
function change_post_status( $post_id ){
$my_post = array(
'ID' => 1,
'post_status' => 'draft',
);
// unhook this function so it doesn't ... | [
{
"answer_id": 210756,
"author": "jas",
"author_id": 80247,
"author_profile": "https://wordpress.stackexchange.com/users/80247",
"pm_score": 2,
"selected": false,
"text": "<p>In your <code>functions.php</code> :</p>\n\n<pre><code>add_action('publish_post', 'check_user_publish', 10, 2);\n... | 2015/12/04 | [
"https://wordpress.stackexchange.com/questions/210752",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84740/"
] | I want to change the status of already publish post to draft using its id.
```
add_action( 'save_post', 'change_post_status', 1 );
function change_post_status( $post_id ){
$my_post = array(
'ID' => 1,
'post_status' => 'draft',
);
// unhook this function so it doesn't loop infinitely
... | In your `functions.php` :
```
add_action('publish_post', 'check_user_publish', 10, 2);
function check_user_publish ($post_id, $post) {
if($post_id == 1){
$query = array(
'ID' => $post_id,
'post_status' => 'draft',
);
wp_update_post( $query, true );
}
}
``` |
210,758 | <p>I'm trying to add some static (welcome) text above my post excerpts, for which the posts page has been set up to display a category, in this case <code>News</code>. <a href="http://www.westcoast-mountainguides.co.uk/category/news/" rel="nofollow">Link</a></p>
<p>I've tried entering the following:</p>
<pre><code>&l... | [
{
"answer_id": 210756,
"author": "jas",
"author_id": 80247,
"author_profile": "https://wordpress.stackexchange.com/users/80247",
"pm_score": 2,
"selected": false,
"text": "<p>In your <code>functions.php</code> :</p>\n\n<pre><code>add_action('publish_post', 'check_user_publish', 10, 2);\n... | 2015/12/04 | [
"https://wordpress.stackexchange.com/questions/210758",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84743/"
] | I'm trying to add some static (welcome) text above my post excerpts, for which the posts page has been set up to display a category, in this case `News`. [Link](http://www.westcoast-mountainguides.co.uk/category/news/)
I've tried entering the following:
```
<?php echo category_description(); ?>
```
into the `index.... | In your `functions.php` :
```
add_action('publish_post', 'check_user_publish', 10, 2);
function check_user_publish ($post_id, $post) {
if($post_id == 1){
$query = array(
'ID' => $post_id,
'post_status' => 'draft',
);
wp_update_post( $query, true );
}
}
``` |
210,765 | <p>I have read that it is advised (especially with php 7) to not close the php files with <code>?></code></p>
<p>Many of my WP php files end like this:</p>
<pre><code><?php get_sidebar(); ?>
<?php get_footer(); ?>
</code></pre>
<p>Should I remove the closing tag and have something like this</p>
<pre>... | [
{
"answer_id": 210790,
"author": "gmazzap",
"author_id": 35541,
"author_profile": "https://wordpress.stackexchange.com/users/35541",
"pm_score": 6,
"selected": true,
"text": "<p>Yes, please avoid closing PHP tags at the end of the file, not only with PHP 7, but with PHP 5 as well.</p>\n\... | 2015/12/04 | [
"https://wordpress.stackexchange.com/questions/210765",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80031/"
] | I have read that it is advised (especially with php 7) to not close the php files with `?>`
Many of my WP php files end like this:
```
<?php get_sidebar(); ?>
<?php get_footer(); ?>
```
Should I remove the closing tag and have something like this
```
<?php get_sidebar(); ?>
<?php get_footer();
```
at the end of... | Yes, please avoid closing PHP tags at the end of the file, not only with PHP 7, but with PHP 5 as well.
Reason is that if you close the tag, anything that is after the tag, even a blank line, will be sent to output and will make PHP to send headers as well preventing cookie to be set, redirect to work, feed to be vali... |
210,770 | <p>I added a custom column to a custom post type:</p>
<pre><code>add_filter('manage_posts_columns', 'custom_columns', 10);
add_action('manage_posts_custom_column', 'custom_columns_thumb', 10, 2);
function custom_columns($columns) {
$columns = array(
'cb' => '<input type="checkbox" />... | [
{
"answer_id": 211498,
"author": "Abhik",
"author_id": 26991,
"author_profile": "https://wordpress.stackexchange.com/users/26991",
"pm_score": 2,
"selected": false,
"text": "<p>Try adding the <code>Thumb</code> Column instead of re-defining the whole columns.</p>\n\n<pre><code>function c... | 2015/12/04 | [
"https://wordpress.stackexchange.com/questions/210770",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1613/"
] | I added a custom column to a custom post type:
```
add_filter('manage_posts_columns', 'custom_columns', 10);
add_action('manage_posts_custom_column', 'custom_columns_thumb', 10, 2);
function custom_columns($columns) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => '... | Here I tested this code and its working fine and steps here.
1. I am just creating a dummy `custom_post_type` here `book` with the following code.
```
function kv_custom_post_books() {
$args = array(
'public' => true,
'label' => 'Books',
'taxonomies' => array('category', 'post_tag') ,
'supports... |
210,793 | <p>how can I get a pagination link URL instead of a made-up anchor link?
currently, I used</p>
<pre><code><?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
</code></pre>
<p>for pagination but it returns <code>a</code>, I want to know is there any way to get just the next/prev URL?</p>
| [
{
"answer_id": 210795,
"author": "flomei",
"author_id": 65455,
"author_profile": "https://wordpress.stackexchange.com/users/65455",
"pm_score": -1,
"selected": false,
"text": "<p>There are <a href=\"https://codex.wordpress.org/Function_Reference/get_previous_posts_link\" rel=\"nofollow\"... | 2015/12/04 | [
"https://wordpress.stackexchange.com/questions/210793",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/58133/"
] | how can I get a pagination link URL instead of a made-up anchor link?
currently, I used
```
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
```
for pagination but it returns `a`, I want to know is there any way to get just the next/prev URL? | If you check out the source, they're both wrappers around `*_posts()`, which in turn are wrappers for `get_*_posts_page_link()` (where the wildcard indicates either `next` or `previous`).
For example, [`next_posts()`](https://developer.wordpress.org/reference/functions/next_posts/) will echo or return the escaped URL,... |
210,816 | <p><a href="http://thewowstudio.com/quad/" rel="nofollow">http://thewowstudio.com/quad/</a></p>
<p>I want my titles to be clickable</p>
<p>Can anyone help me to figure it out how do I do this? I have been trying since a hour but no help.</p>
<p>thanks</p>
<pre><code><?php
/**
* The default template for displayi... | [
{
"answer_id": 210795,
"author": "flomei",
"author_id": 65455,
"author_profile": "https://wordpress.stackexchange.com/users/65455",
"pm_score": -1,
"selected": false,
"text": "<p>There are <a href=\"https://codex.wordpress.org/Function_Reference/get_previous_posts_link\" rel=\"nofollow\"... | 2015/12/04 | [
"https://wordpress.stackexchange.com/questions/210816",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84503/"
] | <http://thewowstudio.com/quad/>
I want my titles to be clickable
Can anyone help me to figure it out how do I do this? I have been trying since a hour but no help.
thanks
```
<?php
/**
* The default template for displaying content
*
* Used for both single and index/archive/search.
*
* @package WordPress
* @su... | If you check out the source, they're both wrappers around `*_posts()`, which in turn are wrappers for `get_*_posts_page_link()` (where the wildcard indicates either `next` or `previous`).
For example, [`next_posts()`](https://developer.wordpress.org/reference/functions/next_posts/) will echo or return the escaped URL,... |
210,817 | <p>With this loop I am displaying single posts on an archive page. The posts are being sorted by the category 'Banks'. In addition to that, how can I display them in alphabetical order? I've tried using <code>WP_Query</code>, but cannot get it to work; it breaks my loop each time.</p>
<pre><code><h3>Banks & ... | [
{
"answer_id": 210822,
"author": "thebigtine",
"author_id": 76059,
"author_profile": "https://wordpress.stackexchange.com/users/76059",
"pm_score": 4,
"selected": false,
"text": "<p>To display posts in descending alphabetical order add this to your <code>args</code> array (taken from the... | 2015/12/04 | [
"https://wordpress.stackexchange.com/questions/210817",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84767/"
] | With this loop I am displaying single posts on an archive page. The posts are being sorted by the category 'Banks'. In addition to that, how can I display them in alphabetical order? I've tried using `WP_Query`, but cannot get it to work; it breaks my loop each time.
```
<h3>Banks & Credit Unions</h3>
<?php if ( have... | To display posts in descending alphabetical order add this to your `args` array (taken from the wp codex)
```
'orderby' => 'title',
'order' => 'DESC',
```
To display posts in ascending alphabetical order just switch `DESC` to `ASC`.
So the whole thing would look like:
```
$args = array(
'orderby' => 'title',... |
210,821 | <p>I figured how to add an input value as a meta key value to a new post from a frontend post form (thanks to <a href="https://wordpress.stackexchange.com/a/210662/25187">@thedeadmedic</a>), but I can't figure <strong>how to add two or more meta keys at once</strong>. Is this possible with the next code? These meta key... | [
{
"answer_id": 210833,
"author": "mrbobbybryant",
"author_id": 64953,
"author_profile": "https://wordpress.stackexchange.com/users/64953",
"pm_score": 1,
"selected": false,
"text": "<p>As @milo was saying above each value that you wish to save as post meta will need it's own call to upda... | 2015/12/04 | [
"https://wordpress.stackexchange.com/questions/210821",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25187/"
] | I figured how to add an input value as a meta key value to a new post from a frontend post form (thanks to [@thedeadmedic](https://wordpress.stackexchange.com/a/210662/25187)), but I can't figure **how to add two or more meta keys at once**. Is this possible with the next code? These meta keys are named 'location2' and... | As @milo commented above, each value that I wish to save as post meta will need it's own call to `update_post_meta`. And because the **$post\_id** variable will return the ID of the new post, it was sufficient instead of:
```
$post_id = add_post_meta($post_id, 'location2', $data['postLocation2']);
```
to insert, for... |
210,829 | <p>I'm trying to redirect my attachment-id pages to the correct post-id page (woocommerce single page). </p>
<p>I got this URL with the attachment_id = 17381. How do I retrieve the products/post ID, which uses this attachment_id? I've searched for hours, and tried different approaches, but I can't find a solution.</p>... | [
{
"answer_id": 210832,
"author": "mrbobbybryant",
"author_id": 64953,
"author_profile": "https://wordpress.stackexchange.com/users/64953",
"pm_score": 0,
"selected": false,
"text": "<p>WordPress uses the post_parent column in the database to track which posts an attachment is linked to. ... | 2015/12/04 | [
"https://wordpress.stackexchange.com/questions/210829",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/52622/"
] | I'm trying to redirect my attachment-id pages to the correct post-id page (woocommerce single page).
I got this URL with the attachment\_id = 17381. How do I retrieve the products/post ID, which uses this attachment\_id? I've searched for hours, and tried different approaches, but I can't find a solution.
<https://w... | It looks like the image (for which you've done a var\_dump) is not attached to any post. If an image is attached to a post - the post's ID would appear as `'post_parent'`, which in this case equals `0`. This is often the case if you upload the image directly from withing media library ('Media Library' page in your WP a... |