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 |
|---|---|---|---|---|---|---|
248,787 | <p>I made a short code in my plugin that pulls out one of the custom post featured image from one taxonomy term each, the taxonomy term under which the post is in, and two term metas.</p>
<p>I want the term of that taxonomy to be limited to only a certain number of characters e.g. 12 but my code below does not truncat... | [
{
"answer_id": 248791,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 2,
"selected": false,
"text": "<p>This is not working because <code>the_terms()</code> is echo-ing the output.</p>\n\n<p>It would make more sen... | 2016/12/09 | [
"https://wordpress.stackexchange.com/questions/248787",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/77779/"
] | I made a short code in my plugin that pulls out one of the custom post featured image from one taxonomy term each, the taxonomy term under which the post is in, and two term metas.
I want the term of that taxonomy to be limited to only a certain number of characters e.g. 12 but my code below does not truncate the long... | This is not working because `the_terms()` is echo-ing the output.
It would make more sense to trim down the lengthy term names, instead of doing it directly on the HTML output of `get_the_term_list()` that's used by `get_the_terms()`. That could give unvalid HTML, that could break the layout of your site.
Here's an e... |
248,814 | <p>I know it's easy to disable Wordpress from adding both <code>p</code> and <code>br</code> tags with:</p>
<pre><code>remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
</code></pre>
<p>but I want Wordpress to keep adding <code><br></code> where there is a line break.
I only... | [
{
"answer_id": 252582,
"author": "Maqk",
"author_id": 86885,
"author_profile": "https://wordpress.stackexchange.com/users/86885",
"pm_score": 0,
"selected": false,
"text": "<p>The \"the_content\" filter is used to filter the content of the post where filter function in <code>your_prefix_... | 2016/12/09 | [
"https://wordpress.stackexchange.com/questions/248814",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/6927/"
] | I know it's easy to disable Wordpress from adding both `p` and `br` tags with:
```
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
```
but I want Wordpress to keep adding `<br>` where there is a line break.
I only use text editor, visual editor is disabled.
It was working fine... | You'd better never disable those actions (what you say). Instead, insert `add_filter('the_content', 'MyFilter', 88 );` and create such function:
```
function MyFilter($content){
$tags = array( 'p', 'span');
///////////////////////////////////////////////////
///////// HERE INSERT ANY OF BELOW CODE ///////... |
248,826 | <p>How can I use <code>.htaccess</code> to rewrite a a page on a subdomain to a page on the parent? (E.g. people visiting mysite.com/landingpage will see the content from dev.mysite.com/landingpage)?</p>
<p>Ive been working to redesign a WordPress site, using a dev.mysite.com subdomain. The site isn't ready to replace... | [
{
"answer_id": 252582,
"author": "Maqk",
"author_id": 86885,
"author_profile": "https://wordpress.stackexchange.com/users/86885",
"pm_score": 0,
"selected": false,
"text": "<p>The \"the_content\" filter is used to filter the content of the post where filter function in <code>your_prefix_... | 2016/12/09 | [
"https://wordpress.stackexchange.com/questions/248826",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/68512/"
] | How can I use `.htaccess` to rewrite a a page on a subdomain to a page on the parent? (E.g. people visiting mysite.com/landingpage will see the content from dev.mysite.com/landingpage)?
Ive been working to redesign a WordPress site, using a dev.mysite.com subdomain. The site isn't ready to replace the live WP site yet... | You'd better never disable those actions (what you say). Instead, insert `add_filter('the_content', 'MyFilter', 88 );` and create such function:
```
function MyFilter($content){
$tags = array( 'p', 'span');
///////////////////////////////////////////////////
///////// HERE INSERT ANY OF BELOW CODE ///////... |
248,840 | <p>I tried to update Wordpress to version 4.7 and received a fatal error. I'm using windows and XAMPP for localhost development.</p>
<pre><code>Update WordPress
Downloading update from
https://downloads.wordpress.org/release/wordpress-4.7-new-bundled.zip…
Unpacking the update…
Fatal error: Maximum execution tim... | [
{
"answer_id": 248872,
"author": "nu everest",
"author_id": 106850,
"author_profile": "https://wordpress.stackexchange.com/users/106850",
"pm_score": 2,
"selected": true,
"text": "<p><strong>Manually updating Wordpress fixes this issue.</strong> </p>\n\n<p><strong><em>Upgrading WordPress... | 2016/12/09 | [
"https://wordpress.stackexchange.com/questions/248840",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106850/"
] | I tried to update Wordpress to version 4.7 and received a fatal error. I'm using windows and XAMPP for localhost development.
```
Update WordPress
Downloading update from
https://downloads.wordpress.org/release/wordpress-4.7-new-bundled.zip…
Unpacking the update…
Fatal error: Maximum execution time of 30 seconds... | **Manually updating Wordpress fixes this issue.**
***Upgrading WordPress Core Manually (How To)*** [WordFence Reference](https://www.wordfence.com/learn/how-to-manually-upgrade-wordpress-themes-and-plugins/)
* First create a full backup of your website. This is very important in
case you make a mistake.
* Download t... |
248,851 | <p>I have allow readers to select the posts order with different parameters. For a example users can order posts by "vote". (Vote is a custom post type.) </p>
<p>Then URL will be <code>http://example.com/?sort_by_type=vote</code></p>
<p>I have used <code>pre_get_posts</code> action to do orderthe posts. It works fine... | [
{
"answer_id": 248852,
"author": "Mostafa Soufi",
"author_id": 106877,
"author_profile": "https://wordpress.stackexchange.com/users/106877",
"pm_score": 0,
"selected": false,
"text": "<p>You should define a new pagination function for do it.</p>\n\n<pre><code><?php\nfunction custom_pa... | 2016/12/10 | [
"https://wordpress.stackexchange.com/questions/248851",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106350/"
] | I have allow readers to select the posts order with different parameters. For a example users can order posts by "vote". (Vote is a custom post type.)
Then URL will be `http://example.com/?sort_by_type=vote`
I have used `pre_get_posts` action to do orderthe posts. It works fine. The problem is pagination .
Paginati... | You can create your custom pagination using `paginate_link()` function and add custom query string after current url.
To add argument to the links of paginations you can pass them as array argument inside the 'add\_args'
```
if ( is_home() || is_archive() || is_search() ) :
echo paginate_links(array(
... |
248,877 | <p>How do I add the date before the entry title in Twenty Twelve with just functions.php?</p>
<p>Right now I have to add and modify many files in the child theme such as content.php, content-aside.php, content-image.php, content-link.php, content-quote.php, content-status.php. </p>
<p>Is there a way to do it with fil... | [
{
"answer_id": 248878,
"author": "Tunji",
"author_id": 54764,
"author_profile": "https://wordpress.stackexchange.com/users/54764",
"pm_score": 0,
"selected": false,
"text": "<p>You can use <code>the_title</code> filter. Example below.</p>\n\n<pre><code>function display_extra_title( $titl... | 2016/12/10 | [
"https://wordpress.stackexchange.com/questions/248877",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/87509/"
] | How do I add the date before the entry title in Twenty Twelve with just functions.php?
Right now I have to add and modify many files in the child theme such as content.php, content-aside.php, content-image.php, content-link.php, content-quote.php, content-status.php.
Is there a way to do it with filters? I tried to ... | Base on @Tunji answer.
You can add some conditions to the function to detect home-page, feeds...
```
function display_extra_title( $title, $id = null ) {
$date = the_date('', '', '', false);
if(is_home()){
$title = get_bloginfo( 'name' );
return $date . $title;
}
else{
return ... |
248,900 | <p>I have successfully translated a child theme, but not the same result in mu-plugins folder.</p>
<p>The name of the plugin is "mu-functions.php".
In this file I have added the "Text Domain: mu-functions" in the header and then I have loaded the textdomain:</p>
<pre><code>add_action( 'plugins_loaded', 'myplugin_mulo... | [
{
"answer_id": 248887,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 6,
"selected": true,
"text": "<p>4.7 has it enabled by default. The easy way to check if it is working is just to visit the example.com/wp-... | 2016/12/10 | [
"https://wordpress.stackexchange.com/questions/248900",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108695/"
] | I have successfully translated a child theme, but not the same result in mu-plugins folder.
The name of the plugin is "mu-functions.php".
In this file I have added the "Text Domain: mu-functions" in the header and then I have loaded the textdomain:
```
add_action( 'plugins_loaded', 'myplugin_muload_textdomain' );
fun... | 4.7 has it enabled by default. The easy way to check if it is working is just to visit the example.com/wp-json url, and you should get a list of registered end points there
There is no official option to disable it as (at least there was a talk about it not sure if it got in the release), some core functionality depen... |
248,904 | <p>I'm new at this.</p>
<p>I need a shortcode that returns the post id of the post in which the shortcode is inserted.</p>
<p>If someone could provide that it would open the doors of understanding for me :)</p>
<p>Much appreciated!</p>
| [
{
"answer_id": 248907,
"author": "CodeMascot",
"author_id": 44192,
"author_profile": "https://wordpress.stackexchange.com/users/44192",
"pm_score": 4,
"selected": true,
"text": "<p>Place the below code to your themes <code>functions.php</code> or inside your plugin and the <code>[return_... | 2016/12/11 | [
"https://wordpress.stackexchange.com/questions/248904",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108215/"
] | I'm new at this.
I need a shortcode that returns the post id of the post in which the shortcode is inserted.
If someone could provide that it would open the doors of understanding for me :)
Much appreciated! | Place the below code to your themes `functions.php` or inside your plugin and the `[return_post_id]` shortcode will print the post ID.
```
add_shortcode( 'return_post_id', 'the_dramatist_return_post_id' );
function the_dramatist_return_post_id() {
return get_the_ID();
}
```
Hope that helps. |
248,957 | <p>This is my code in functions.php for adding the custom field in comment form</p>
<pre><code>add_filter( 'comment_form_default_fields', 'add_phonenumber_field' );
function add_phonenumber_field($fields) {
$fields['phonenumber'] = '<p class="comment-form-phonenumber"><label for="phonenumber">Phone Num... | [
{
"answer_id": 248907,
"author": "CodeMascot",
"author_id": 44192,
"author_profile": "https://wordpress.stackexchange.com/users/44192",
"pm_score": 4,
"selected": true,
"text": "<p>Place the below code to your themes <code>functions.php</code> or inside your plugin and the <code>[return_... | 2016/12/12 | [
"https://wordpress.stackexchange.com/questions/248957",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/90228/"
] | This is my code in functions.php for adding the custom field in comment form
```
add_filter( 'comment_form_default_fields', 'add_phonenumber_field' );
function add_phonenumber_field($fields) {
$fields['phonenumber'] = '<p class="comment-form-phonenumber"><label for="phonenumber">Phone Number <span class="required"... | Place the below code to your themes `functions.php` or inside your plugin and the `[return_post_id]` shortcode will print the post ID.
```
add_shortcode( 'return_post_id', 'the_dramatist_return_post_id' );
function the_dramatist_return_post_id() {
return get_the_ID();
}
```
Hope that helps. |
248,967 | <p>We can get posts from a category using below request</p>
<pre><code> `/wp/v2/posts?categories=1&search=somequery`
</code></pre>
<p>It only gives results from category(1) only. How can we get results from category(1) and from all subcategories of category(1) also? Than You.</p>
| [
{
"answer_id": 248972,
"author": "Emil",
"author_id": 80532,
"author_profile": "https://wordpress.stackexchange.com/users/80532",
"pm_score": 0,
"selected": false,
"text": "<p>You'll need to do an additional call to find the IDs of the subcategories – there is no way to get posts from su... | 2016/12/12 | [
"https://wordpress.stackexchange.com/questions/248967",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107444/"
] | We can get posts from a category using below request
```
`/wp/v2/posts?categories=1&search=somequery`
```
It only gives results from category(1) only. How can we get results from category(1) and from all subcategories of category(1) also? Than You. | This answer has what you want <https://wordpress.stackexchange.com/a/314152/49962>
WP already does this out of the box thanks to the include\_children parameter of tax\_query which is true by default.
So you do not need to tell it the sub-terms, just do something like this:
```
/wp/v2/posts?categories=1
```
Where ... |
248,983 | <p>I'm using the following form html to generate a search function on a wordpress site:</p>
<pre><code><form method="get" action="<?php bloginfo('url'); ?>">
<fieldset>
<input type="text" name="s" value="" placeholder="search&hellip;" maxlength="50" required="required" />
<button type="s... | [
{
"answer_id": 248984,
"author": "The Sumo",
"author_id": 76021,
"author_profile": "https://wordpress.stackexchange.com/users/76021",
"pm_score": 4,
"selected": true,
"text": "<p>Ok, so I did a little more digging around and it turns out to be pretty easy. I just needed to add a hidden i... | 2016/12/12 | [
"https://wordpress.stackexchange.com/questions/248983",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/76021/"
] | I'm using the following form html to generate a search function on a wordpress site:
```
<form method="get" action="<?php bloginfo('url'); ?>">
<fieldset>
<input type="text" name="s" value="" placeholder="search…" maxlength="50" required="required" />
<button type="submit">Search</button>
</fieldset>
</form>
`... | Ok, so I did a little more digging around and it turns out to be pretty easy. I just needed to add a hidden input into the search form. Posting this here for anyone else looking for the answer:
```
<form class="search" action="<?php echo home_url( '/' ); ?>">
<input type="search" name="s" placeholder="Search&h... |
248,991 | <p>I'm making a plugin where the user can order something. But before he has to confirm his email, so I'm sending out that mail with the confirmation link, something like that: <code>mydomain.com/myconfirmation?token=MYTOKEN</code></p>
<p>How do I fetch this confirmation url <code>myconfirmation</code> in WordPress wi... | [
{
"answer_id": 248984,
"author": "The Sumo",
"author_id": 76021,
"author_profile": "https://wordpress.stackexchange.com/users/76021",
"pm_score": 4,
"selected": true,
"text": "<p>Ok, so I did a little more digging around and it turns out to be pretty easy. I just needed to add a hidden i... | 2016/12/12 | [
"https://wordpress.stackexchange.com/questions/248991",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/92649/"
] | I'm making a plugin where the user can order something. But before he has to confirm his email, so I'm sending out that mail with the confirmation link, something like that: `mydomain.com/myconfirmation?token=MYTOKEN`
How do I fetch this confirmation url `myconfirmation` in WordPress without the website owner having t... | Ok, so I did a little more digging around and it turns out to be pretty easy. I just needed to add a hidden input into the search form. Posting this here for anyone else looking for the answer:
```
<form class="search" action="<?php echo home_url( '/' ); ?>">
<input type="search" name="s" placeholder="Search&h... |
248,993 | <p>I would like to order a list of post title alphabetically.
I am using this specific query </p>
<pre><code>// WP_Query arguments
$args = array(
'category_name' => 'reportage',
'order' => 'ASC',
'orderby' => 'title',
);
// The Query
$query = new WP_Query($args);
// Th... | [
{
"answer_id": 249002,
"author": "tormorten",
"author_id": 49832,
"author_profile": "https://wordpress.stackexchange.com/users/49832",
"pm_score": 2,
"selected": false,
"text": "<p>Try adding <code>'suppress_filters' => true</code> to your query args. Maybe you have a plugin that modi... | 2016/12/12 | [
"https://wordpress.stackexchange.com/questions/248993",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/103072/"
] | I would like to order a list of post title alphabetically.
I am using this specific query
```
// WP_Query arguments
$args = array(
'category_name' => 'reportage',
'order' => 'ASC',
'orderby' => 'title',
);
// The Query
$query = new WP_Query($args);
// The Loop
if ($query->have... | Try adding `'suppress_filters' => true` to your query args. Maybe you have a plugin that modifies the queries.
You could also check if the posts out of order (the first one) is a sticky post. Sticky posts by default skip the order queue.
You can disable this by adding `'ignore_sticky_posts' => true` to your query arg... |
248,998 | <p>This is the code below I am using to create a table when installing plugin. But, I tried many ways and for some reason it is not working. Is there any other efficient way of doing this? Please Help, thanks in Advanced</p>
<pre><code>global $wpdb;
function creating_order_tables() {
global $wpdb;
$ptbd_table... | [
{
"answer_id": 248999,
"author": "Kamaro",
"author_id": 108796,
"author_profile": "https://wordpress.stackexchange.com/users/108796",
"pm_score": 2,
"selected": false,
"text": "<p>Try this one, Also remember int can have maximum of int(11)</p>\n\n<pre><code><?php\nglobal $wpdb;\n\n// ... | 2016/12/12 | [
"https://wordpress.stackexchange.com/questions/248998",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/89234/"
] | This is the code below I am using to create a table when installing plugin. But, I tried many ways and for some reason it is not working. Is there any other efficient way of doing this? Please Help, thanks in Advanced
```
global $wpdb;
function creating_order_tables() {
global $wpdb;
$ptbd_table_name = $wpdb-... | Try using a different method. WordPress fires a hook during plugin activation `activate_yourplugin/filename.php`. You can use this to create tables.
```
function creating_order_tables() {
if(!get_option('tables_created', false)) {
global $wpdb;
$ptbd_table_name = $wpdb->prefix . 'printtextbd_ord... |
249,003 | <p>I'm using the <code>WP_Customize_Cropped_Image_Control</code> for the user to upload and crop an image in the Customizer. However, the get theme mod function doesn't seem to be working for outputting it as I usually do.</p>
<p>This is what I have in my customizer.php file:</p>
<pre><code>$wp_customize->add_sett... | [
{
"answer_id": 249006,
"author": "Troy Templeman",
"author_id": 40536,
"author_profile": "https://wordpress.stackexchange.com/users/40536",
"pm_score": 0,
"selected": false,
"text": "<p>This did it for me, simplifying <a href=\"https://wordpress.stackexchange.com/users/8521/weston-ruter\... | 2016/12/12 | [
"https://wordpress.stackexchange.com/questions/249003",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40536/"
] | I'm using the `WP_Customize_Cropped_Image_Control` for the user to upload and crop an image in the Customizer. However, the get theme mod function doesn't seem to be working for outputting it as I usually do.
This is what I have in my customizer.php file:
```
$wp_customize->add_setting( 'bio_image', array(
'defau... | The theme mod here is storing the attachment post ID whereas your default value is a URL. So what you'd need to do is something like:
```
<?php
function get_bio_image_url() {
if ( get_theme_mod( 'bio_image' ) > 0 ) {
return wp_get_attachment_url( get_theme_mod( 'bio_image' ) );
} else {
return ... |
249,015 | <p>I have an issue with custom widgets and WordPress Coding Standards. When you create a custom widget, your class should have a "widget" method that will display the widget. Something like:</p>
<pre><code><?php
public function widget( $args, $instance ) {
echo $args['before_widget'];
?> <span><... | [
{
"answer_id": 249020,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 4,
"selected": true,
"text": "<p>These arguments contain arbitrary HTML and cannot be properly escaped. This is essentially a limitation on how Widge... | 2016/12/12 | [
"https://wordpress.stackexchange.com/questions/249015",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/76144/"
] | I have an issue with custom widgets and WordPress Coding Standards. When you create a custom widget, your class should have a "widget" method that will display the widget. Something like:
```
<?php
public function widget( $args, $instance ) {
echo $args['before_widget'];
?> <span><?php echo esc_html( 'Great wi... | These arguments contain arbitrary HTML and cannot be properly escaped. This is essentially a limitation on how Widgets code was designed and you can see in core Widget classes that no escaping is done on these.
Lessons to learn:
* WP core doesn't consistently adhere to its own coding standards (and getting there isn'... |
249,017 | <p>I am trying to develop a method in my admin panel that will allow for the creation of a CSV file within the plugin directory
Here is my code: where $amount is the next increment of filename calculated beforehand (if 1.csv and 2.csv exist, then create 3.csv) this calculation works fine as I have tried echoing the fi... | [
{
"answer_id": 249019,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 2,
"selected": false,
"text": "<p>Writing to a plugin directory is not considered a proper practice:</p>\n\n<ol>\n<li>Plugin directories are overwrit... | 2016/12/12 | [
"https://wordpress.stackexchange.com/questions/249017",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107110/"
] | I am trying to develop a method in my admin panel that will allow for the creation of a CSV file within the plugin directory
Here is my code: where $amount is the next increment of filename calculated beforehand (if 1.csv and 2.csv exist, then create 3.csv) this calculation works fine as I have tried echoing the filep... | If you plan to write to a pugin folder since you used `fopen`, `fwite`, `flose` you are using the wrong function:
```
File: wp-includes/link-template.php
3189: /**
3190: * Retrieves a URL within the plugins or mu-plugins directory.
3191: *
3192: * Defaults to the plugins directory URL if no arguments are supplied.
... |
249,034 | <p>I'm using a theme that I've pulled from WordPress' repo (example: <a href="https://wordpress.org/themes/twentysixteen/" rel="nofollow noreferrer">Twenty Sixteen</a>), the default URL structure looks like so:</p>
<pre><code>http://example.com/wp-content/themes/twentysixteen/...
</code></pre>
<p>I want to hide any r... | [
{
"answer_id": 249036,
"author": "Carl Willis",
"author_id": 69413,
"author_profile": "https://wordpress.stackexchange.com/users/69413",
"pm_score": 2,
"selected": true,
"text": "<p>changing the theme folder I guess it won't affect on updates but changing it's name do.</p>\n\n<p>So like ... | 2016/12/12 | [
"https://wordpress.stackexchange.com/questions/249034",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98212/"
] | I'm using a theme that I've pulled from WordPress' repo (example: [Twenty Sixteen](https://wordpress.org/themes/twentysixteen/)), the default URL structure looks like so:
```
http://example.com/wp-content/themes/twentysixteen/...
```
I want to hide any reference that this WordPress theme is coming from Twenty Sixtee... | changing the theme folder I guess it won't affect on updates but changing it's name do.
So like you said the best way that every professional company advice is to create a child-theme and modify everything you want on it. |
249,077 | <pre><code><?php
/*
* Plugin Name: Official Treehouse Badges Plugin
* Plugin URI: http://wptreehouse.com/wptreehouse-badges-plugin/
* Description: Provides both widgets and shortcodes to help you display your Treehouse profile badges on your website. The official Treehouse badges plugin.
* Version: 1.0
* ... | [
{
"answer_id": 249078,
"author": "Dave Romsey",
"author_id": 2807,
"author_profile": "https://wordpress.stackexchange.com/users/2807",
"pm_score": 3,
"selected": true,
"text": "<p>The only issue was that the capability was specified incorrectly when using <code>add_options_page()</code>.... | 2016/12/13 | [
"https://wordpress.stackexchange.com/questions/249077",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/105791/"
] | ```
<?php
/*
* Plugin Name: Official Treehouse Badges Plugin
* Plugin URI: http://wptreehouse.com/wptreehouse-badges-plugin/
* Description: Provides both widgets and shortcodes to help you display your Treehouse profile badges on your website. The official Treehouse badges plugin.
* Version: 1.0
* Author: Ed... | The only issue was that the capability was specified incorrectly when using `add_options_page()`. The capability should be `manage_options`. Note the underscore, no space:
```
function basic_treehouse_badges_menu() {
/*
* Use the add_options_page function
* add_options_page( $page_title, $menu_title, $ca... |
249,082 | <p>I am trying to manually add a new plugin to WordPress site (I need to add a customized plugin).</p>
<p>I do it by:</p>
<ol>
<li><p>uploading it via Ftp server (with FTPS connection) to <code>/var/www/html/wp-content/plugins</code></p></li>
<li><p>Copy/paste to <code>/var/www/html/wp-content/plugins</code></p></li>... | [
{
"answer_id": 249078,
"author": "Dave Romsey",
"author_id": 2807,
"author_profile": "https://wordpress.stackexchange.com/users/2807",
"pm_score": 3,
"selected": true,
"text": "<p>The only issue was that the capability was specified incorrectly when using <code>add_options_page()</code>.... | 2016/12/13 | [
"https://wordpress.stackexchange.com/questions/249082",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107436/"
] | I am trying to manually add a new plugin to WordPress site (I need to add a customized plugin).
I do it by:
1. uploading it via Ftp server (with FTPS connection) to `/var/www/html/wp-content/plugins`
2. Copy/paste to `/var/www/html/wp-content/plugins`
But, I am not able to see it on WordPress site under plugin secti... | The only issue was that the capability was specified incorrectly when using `add_options_page()`. The capability should be `manage_options`. Note the underscore, no space:
```
function basic_treehouse_badges_menu() {
/*
* Use the add_options_page function
* add_options_page( $page_title, $menu_title, $ca... |
249,109 | <p>Is there a way to hide user profiles in the front end, while still allowing their information to be accessible in the backend?</p>
<p>Something similar to setting posts or pages to "draft" but for users would function perfectly. Is there a way to do this?</p>
| [
{
"answer_id": 249204,
"author": "prosti",
"author_id": 88606,
"author_profile": "https://wordpress.stackexchange.com/users/88606",
"pm_score": 2,
"selected": false,
"text": "<p>The database table for users holds the <code>user_status</code> as integer:</p>\n\n<pre><code> $users_singl... | 2016/12/13 | [
"https://wordpress.stackexchange.com/questions/249109",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108864/"
] | Is there a way to hide user profiles in the front end, while still allowing their information to be accessible in the backend?
Something similar to setting posts or pages to "draft" but for users would function perfectly. Is there a way to do this? | The database table for users holds the `user_status` as integer:
```
$users_single_table = "CREATE TABLE $wpdb->users (
ID bigint(20) unsigned NOT NULL auto_increment,
user_login varchar(60) NOT NULL default '',
user_pass varchar(255) NOT NULL default '',
user_nicename varchar(50) NOT NULL default '',
us... |
249,115 | <p>I want to show author avatar in post info. So I use</p>
<pre><code><?php echo get_avatar( get_the_author_meta( 'ID' ) , 80); ?>
</code></pre>
<p>But how can I check if user has avatar? </p>
| [
{
"answer_id": 249117,
"author": "Oreo",
"author_id": 108862,
"author_profile": "https://wordpress.stackexchange.com/users/108862",
"pm_score": 1,
"selected": false,
"text": "<p><code>get_avatar()</code> returns An img element for the user's avatar or false on failure. The function does ... | 2016/12/13 | [
"https://wordpress.stackexchange.com/questions/249115",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/103556/"
] | I want to show author avatar in post info. So I use
```
<?php echo get_avatar( get_the_author_meta( 'ID' ) , 80); ?>
```
But how can I check if user has avatar? | `get_avatar()` returns An img element for the user's avatar or false on failure. The function does not output anything; you have to echo the return value.
so you can try something like that
```
if( get_avatar( get_the_author_meta( 'ID' ) ) == 0) {
// no img code
} else {
echo get_avatar( get_the_author_meta( 'I... |
249,190 | <p>I have put this code on author.php page</p>
<pre><code> <?php if ( have_posts() ) : while ( have_posts() ) : the_post();
//gets the number of comment(s) on a post
$comments_number = get_comments_number();
//adds all the comment counts up
$numbercomment += $comments_number;
?>
<?... | [
{
"answer_id": 249196,
"author": "Pim",
"author_id": 50432,
"author_profile": "https://wordpress.stackexchange.com/users/50432",
"pm_score": 3,
"selected": true,
"text": "<p>You could use <code>get_comments()</code>, this way you don't have to loop through posts.</p>\n\n<pre><code><?p... | 2016/12/14 | [
"https://wordpress.stackexchange.com/questions/249190",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/75425/"
] | I have put this code on author.php page
```
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
//gets the number of comment(s) on a post
$comments_number = get_comments_number();
//adds all the comment counts up
$numbercomment += $comments_number;
?>
<?php endwhile; ?>
<spa... | You could use `get_comments()`, this way you don't have to loop through posts.
```
<?php
$args = array(
'post_author' => '' // fill in post author ID
);
$author_comments = get_comments($args);
echo count($author_comments);
?>
``` |
249,202 | <p>Is it possible to order a tag page by the 'most commonly used' tag? </p>
<p>For example:</p>
<p>Say I have three tags: Apple, Orange, Banana, and 100 posts. </p>
<p>90 of those posts are tagged Apple, 50 are tagged Orange, and 20 are tagged Banana. (Some are tagged with more than 1 tag.) </p>
<p>So I want to or... | [
{
"answer_id": 249338,
"author": "CodeMascot",
"author_id": 44192,
"author_profile": "https://wordpress.stackexchange.com/users/44192",
"pm_score": 2,
"selected": true,
"text": "<p>I'm afraid <code>orderby</code> taxonomy terms post count is not possible by <code>WP_Query</code>. <a href... | 2016/12/14 | [
"https://wordpress.stackexchange.com/questions/249202",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/44848/"
] | Is it possible to order a tag page by the 'most commonly used' tag?
For example:
Say I have three tags: Apple, Orange, Banana, and 100 posts.
90 of those posts are tagged Apple, 50 are tagged Orange, and 20 are tagged Banana. (Some are tagged with more than 1 tag.)
So I want to order the posts listed on the tags... | I'm afraid `orderby` taxonomy terms post count is not possible by `WP_Query`. [See this answer](https://wordpress.stackexchange.com/questions/14306/using-wp-query-is-it-possible-to-orderby-taxonomy/14309#14309). So here I've written a SQL based function for you. It'll order your posts based on terms post count.
```
fu... |
249,214 | <p>I have a piece of code displaying a list of sites in my multisite, and I want to exclude the archived ones:</p>
<pre><code>$mySites = ( wp_get_sites( $args ) );
foreach ( $mySites as $blog ) {
if ( ! ( is_archived($blog) ) ) {
switch_to_blog( $blog['blog_id'] );
printf( '%s<a href="%s">... | [
{
"answer_id": 249222,
"author": "Emil",
"author_id": 80532,
"author_profile": "https://wordpress.stackexchange.com/users/80532",
"pm_score": 3,
"selected": true,
"text": "<p>Can you try out the following code somewhere and post the output?</p>\n\n<pre><code>$mySites = wp_get_sites($args... | 2016/12/14 | [
"https://wordpress.stackexchange.com/questions/249214",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/78708/"
] | I have a piece of code displaying a list of sites in my multisite, and I want to exclude the archived ones:
```
$mySites = ( wp_get_sites( $args ) );
foreach ( $mySites as $blog ) {
if ( ! ( is_archived($blog) ) ) {
switch_to_blog( $blog['blog_id'] );
printf( '%s<a href="%s">%s</a></li>' . "\r\... | Can you try out the following code somewhere and post the output?
```
$mySites = wp_get_sites($args);
foreach ($mySites as $blog){
print_r(get_blog_status($blog['blog_id'], 'archived'));
}
```
If this works, I suspect the code behind `is_archived()` used to understand blog-objects, but the [function is supposed ... |
249,218 | <p>WordPress has several APIs build in:</p>
<ul>
<li><a href="https://codex.wordpress.org/XML-RPC_WordPress_API" rel="noreferrer">XML-RPC</a></li>
<li><a href="http://v2.wp-api.org/" rel="noreferrer">REST API</a></li>
</ul>
<p>by default they don't return custom post types or protected meta keys.</p>
<p>I want to ac... | [
{
"answer_id": 263457,
"author": "J.C. Hiatt",
"author_id": 117545,
"author_profile": "https://wordpress.stackexchange.com/users/117545",
"pm_score": 0,
"selected": false,
"text": "<p>With the REST API, there's a <code>rest_query_vars</code> filter you can use:</p>\n\n<pre><code>function... | 2016/12/14 | [
"https://wordpress.stackexchange.com/questions/249218",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80953/"
] | WordPress has several APIs build in:
* [XML-RPC](https://codex.wordpress.org/XML-RPC_WordPress_API)
* [REST API](http://v2.wp-api.org/)
by default they don't return custom post types or protected meta keys.
I want to access the protected meta fields of a plugin. I tried to follow the examples given [here](https://jo... | To me, the simplest solution would be creating additional field in JSON response and populating it with selected post meta:
```
function create_api_posts_meta_field() {
// "tribe_venue" is your post type name,
// "protected-fields" is a name for new JSON field
register_rest_field( 'tribe_venue', 'protec... |
249,221 | <p>I was creating a custom plugin which was to send certain emails based on the content/category of a post, but whilst trying to do that, I ran into some problems just getting a basic email sent out. Am I hooking on to the wrong function here? When I publish a post, nothing happens.</p>
<pre><code><?php
/**
* Plugi... | [
{
"answer_id": 249256,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 2,
"selected": true,
"text": "<p>You need to add parameters <code>$old_status</code> and <code>$new_status</code> to the function. </p>\n\n<pre>... | 2016/12/14 | [
"https://wordpress.stackexchange.com/questions/249221",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/103117/"
] | I was creating a custom plugin which was to send certain emails based on the content/category of a post, but whilst trying to do that, I ran into some problems just getting a basic email sent out. Am I hooking on to the wrong function here? When I publish a post, nothing happens.
```
<?php
/**
* Plugin Name: Condition... | You need to add parameters `$old_status` and `$new_status` to the function.
```
function conditional_email( $old_status, $new_status) {
wp_mail('my@email.com','test','test');
}
```
You will see that in the example [here](https://codex.wordpress.org/Post_Status_Transitions)
Hope it works after ! |
249,233 | <p>I need to organize the pages on my website so that they appear with the proper hierarchy. The problem is that the category-derived page is appearing outside my hierarchy. This is the current hierarchy if you are on my site today:</p>
<pre><code>Home mysite.com
-> Internal (page) mysite.... | [
{
"answer_id": 249256,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 2,
"selected": true,
"text": "<p>You need to add parameters <code>$old_status</code> and <code>$new_status</code> to the function. </p>\n\n<pre>... | 2016/12/14 | [
"https://wordpress.stackexchange.com/questions/249233",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/51855/"
] | I need to organize the pages on my website so that they appear with the proper hierarchy. The problem is that the category-derived page is appearing outside my hierarchy. This is the current hierarchy if you are on my site today:
```
Home mysite.com
-> Internal (page) mysite.com/internal
... | You need to add parameters `$old_status` and `$new_status` to the function.
```
function conditional_email( $old_status, $new_status) {
wp_mail('my@email.com','test','test');
}
```
You will see that in the example [here](https://codex.wordpress.org/Post_Status_Transitions)
Hope it works after ! |
249,237 | <p>I'm using [feed to post RSS Aggregator] and get posts from 44 sites. main page loading is too slow. I checked GTmetrix and it seems good but I don't know how can I improve my website loading. <a href="http://akhbartop.ir/" rel="nofollow noreferrer">http://akhbartop.ir/</a></p>
| [
{
"answer_id": 249256,
"author": "Benoti",
"author_id": 58141,
"author_profile": "https://wordpress.stackexchange.com/users/58141",
"pm_score": 2,
"selected": true,
"text": "<p>You need to add parameters <code>$old_status</code> and <code>$new_status</code> to the function. </p>\n\n<pre>... | 2016/12/14 | [
"https://wordpress.stackexchange.com/questions/249237",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/101761/"
] | I'm using [feed to post RSS Aggregator] and get posts from 44 sites. main page loading is too slow. I checked GTmetrix and it seems good but I don't know how can I improve my website loading. <http://akhbartop.ir/> | You need to add parameters `$old_status` and `$new_status` to the function.
```
function conditional_email( $old_status, $new_status) {
wp_mail('my@email.com','test','test');
}
```
You will see that in the example [here](https://codex.wordpress.org/Post_Status_Transitions)
Hope it works after ! |
249,248 | <p>So I've got to edit my 404 page. Since my client's website has 5 languages, I'd like to let him edit and translate the 404 page by himself, with normal WordPress editor. Also, we're currently using Polylang as the localization plugin.</p>
<p>Is there a way to have the theme's <code>404.php</code> as a regular page?... | [
{
"answer_id": 249260,
"author": "Luca Reghellin",
"author_id": 10381,
"author_profile": "https://wordpress.stackexchange.com/users/10381",
"pm_score": 1,
"selected": false,
"text": "<p>Found a way.</p>\n\n<ul>\n<li><p>Create a regular page for 404 content, say 'Page not found';</p></li>... | 2016/12/14 | [
"https://wordpress.stackexchange.com/questions/249248",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10381/"
] | So I've got to edit my 404 page. Since my client's website has 5 languages, I'd like to let him edit and translate the 404 page by himself, with normal WordPress editor. Also, we're currently using Polylang as the localization plugin.
Is there a way to have the theme's `404.php` as a regular page?
I've tried to creat... | Found a way.
* Create a regular page for 404 content, say 'Page not found';
* In your 404.php file, get that page data and then write down your content or whatever...
For example:
```
$page = get_page_by_title("Page not found");
if($page) echo apply_filters('the_content',$page->post_content);
```
Obviously, you ... |
249,309 | <p>I logged into my wp-dashboard after a hack to find that there is a 'ghost' administrator of my site... the only problem is, I can't just list the user table and delete it. I don't know why, but here's all I get when I click on the Admin tab, or the subscribers tab for that matter:</p>
<p><a href="https://www.dropb... | [
{
"answer_id": 249325,
"author": "Self Designs",
"author_id": 75780,
"author_profile": "https://wordpress.stackexchange.com/users/75780",
"pm_score": 1,
"selected": false,
"text": "<p>Navigate to the wp_users table on your php myadmin and see if you are the only one on the table. If so c... | 2016/12/15 | [
"https://wordpress.stackexchange.com/questions/249309",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108987/"
] | I logged into my wp-dashboard after a hack to find that there is a 'ghost' administrator of my site... the only problem is, I can't just list the user table and delete it. I don't know why, but here's all I get when I click on the Admin tab, or the subscribers tab for that matter:
<https://www.dropbox.com/s/uf0uxw40le... | We can generate the SQL with:
```
$query = new WP_User_Query(
[
'role' => 'Administrator',
'count_total' => false,
]
);
echo $query->request;
```
that outputs:
```
SELECT wp_users.*
FROM wp_users
INNER JOIN wp_usermeta ON ( wp_users.ID = wp_usermeta.user_id )
WHERE 1=1
... |
249,330 | <p>I want to run a WordPress code Snippet that can show total posts by author.
something like this:</p>
<p>author1: 37 posts
author2: 12 posts
author3: 43 posts</p>
<p>is possible this?.
Thank you</p>
| [
{
"answer_id": 249333,
"author": "Ranuka",
"author_id": 106350,
"author_profile": "https://wordpress.stackexchange.com/users/106350",
"pm_score": 1,
"selected": false,
"text": "<p>First of all you need to get all users calling <code>get_users()</code> function. Then you can use <code>cou... | 2016/12/15 | [
"https://wordpress.stackexchange.com/questions/249330",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108998/"
] | I want to run a WordPress code Snippet that can show total posts by author.
something like this:
author1: 37 posts
author2: 12 posts
author3: 43 posts
is possible this?.
Thank you | First of all you need to get all users calling `get_users()` function. Then you can use `count_user_posts()` to display post count for a user.
Try below code.
```
<?php
$blogusers = get_users();
// Array of WP_User objects.
foreach ( $blogusers as $user ) {
echo 'Number of posts published by '... |
249,429 | <p>I created a plugin to override a theme's function. As I learn that function in plugin loads first but I got an error </p>
<blockquote>
<p>Fatal error: Cannot redeclare wooc_extra_register_fields() (previously
declared in ****/themes/****/functions.php:247) in
***/plugins/custom-plugin/custom-plugin.php on lin... | [
{
"answer_id": 249333,
"author": "Ranuka",
"author_id": 106350,
"author_profile": "https://wordpress.stackexchange.com/users/106350",
"pm_score": 1,
"selected": false,
"text": "<p>First of all you need to get all users calling <code>get_users()</code> function. Then you can use <code>cou... | 2016/12/16 | [
"https://wordpress.stackexchange.com/questions/249429",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/52602/"
] | I created a plugin to override a theme's function. As I learn that function in plugin loads first but I got an error
>
> Fatal error: Cannot redeclare wooc\_extra\_register\_fields() (previously
> declared in \*\*\*\*/themes/\*\*\*\*/functions.php:247) in
> \*\*\*/plugins/custom-plugin/custom-plugin.php on line 89... | First of all you need to get all users calling `get_users()` function. Then you can use `count_user_posts()` to display post count for a user.
Try below code.
```
<?php
$blogusers = get_users();
// Array of WP_User objects.
foreach ( $blogusers as $user ) {
echo 'Number of posts published by '... |
249,437 | <p>I have created a new role .Now I want to remove <strong>post</strong> ,<strong>media</strong>, <strong>setting</strong> capability for that role.
How can I achieve this?</p>
| [
{
"answer_id": 249440,
"author": "ehabdevel",
"author_id": 109068,
"author_profile": "https://wordpress.stackexchange.com/users/109068",
"pm_score": 1,
"selected": false,
"text": "<p>Remove a top level admin menu:</p>\n\n<pre><code> function custom_menu_page_removing() {\n remove_m... | 2016/12/16 | [
"https://wordpress.stackexchange.com/questions/249437",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109067/"
] | I have created a new role .Now I want to remove **post** ,**media**, **setting** capability for that role.
How can I achieve this? | Remove a top level admin menu:
```
function custom_menu_page_removing() {
remove_menu_page( $menu_slug );
}
add_action( 'admin_menu', 'custom_menu_page_removing' );
```
To remove only certain menu items include only those you want to hide within the function.
To remove menus for only certain users you may w... |
249,438 | <p>I have written a plugin for my own site where I have an issue like "after user login to the site if he logout then again if he clicks on browser back button then the previous page showing again instead of login page". for this issue I fixed it by using below js code:</p>
<pre><code>history.pushState(null, null, doc... | [
{
"answer_id": 249443,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 2,
"selected": false,
"text": "<p>When a user <a href=\"https://codex.wordpress.org/Function_Reference/wp_logout\" rel=\"nofollow noreferrer\">log... | 2016/12/16 | [
"https://wordpress.stackexchange.com/questions/249438",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106542/"
] | I have written a plugin for my own site where I have an issue like "after user login to the site if he logout then again if he clicks on browser back button then the previous page showing again instead of login page". for this issue I fixed it by using below js code:
```
history.pushState(null, null, document.URL);
wi... | When a user [logs out](https://codex.wordpress.org/Function_Reference/wp_logout) the current user session is destroyed and no new pages can be loaded for which a user must be logged in. However, when you hit the 'back' button on your browser, it typically retrieves the page from the local cache. There is no contact wit... |
249,456 | <p>I'm interested in using an old version of a plugin for a core feature on the site (it's not ideal but a compromise after months of effort) because the new version has incompatibilities. However I'm worried that someone - including myself - will mindlessly update the plugin in the future.</p>
<p>Is there any way to ... | [
{
"answer_id": 249482,
"author": "marikamitsos",
"author_id": 17797,
"author_profile": "https://wordpress.stackexchange.com/users/17797",
"pm_score": 2,
"selected": false,
"text": "<p>It is quite simple. All you have to do is add some code in a Custom Functions plugin.</p>\n\n<p>Lets say... | 2016/12/16 | [
"https://wordpress.stackexchange.com/questions/249456",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/96983/"
] | I'm interested in using an old version of a plugin for a core feature on the site (it's not ideal but a compromise after months of effort) because the new version has incompatibilities. However I'm worried that someone - including myself - will mindlessly update the plugin in the future.
Is there any way to prevent a ... | It is quite simple. All you have to do is add some code in a Custom Functions plugin.
Lets say you want to block the "Hello Dolly" plugin (comes prepacked with WordPress) from updating. In your "My Functions Plugin", `mycustomfunctions.php` (you can use any name really) you place the following:
```
/* Disable a plugi... |
249,472 | <p>I have written a code for inserting wordpress user if I try to add new user I am getting 3 warning errors saying like below: </p>
<p>"Warning: mysql_real_escape_string() expects parameter 1 to be string, object given in /home/intecom/public_html/app/wp-includes/wp-db.php on line 1129
" , </p>
<p>"Warning: Illegal ... | [
{
"answer_id": 249482,
"author": "marikamitsos",
"author_id": 17797,
"author_profile": "https://wordpress.stackexchange.com/users/17797",
"pm_score": 2,
"selected": false,
"text": "<p>It is quite simple. All you have to do is add some code in a Custom Functions plugin.</p>\n\n<p>Lets say... | 2016/12/16 | [
"https://wordpress.stackexchange.com/questions/249472",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106542/"
] | I have written a code for inserting wordpress user if I try to add new user I am getting 3 warning errors saying like below:
"Warning: mysql\_real\_escape\_string() expects parameter 1 to be string, object given in /home/intecom/public\_html/app/wp-includes/wp-db.php on line 1129
" ,
"Warning: Illegal offset type i... | It is quite simple. All you have to do is add some code in a Custom Functions plugin.
Lets say you want to block the "Hello Dolly" plugin (comes prepacked with WordPress) from updating. In your "My Functions Plugin", `mycustomfunctions.php` (you can use any name really) you place the following:
```
/* Disable a plugi... |
249,483 | <p>I have seen many articles mentioning that a <code>/%postname%/</code> permalink is the best for SEO. But what about a <code>/%post_id%/%postname%</code> structure, such as <code>myblog.com/123/the-slug-of-my-blog</code> ?</p>
<ul>
<li>It doesn't seem to affect search engine rankings (Stack Exchange and many others... | [
{
"answer_id": 249500,
"author": "Game Unity",
"author_id": 83769,
"author_profile": "https://wordpress.stackexchange.com/users/83769",
"pm_score": 0,
"selected": false,
"text": "<p>There shouldn't be any diffrents. I recommend you to use the ID version and you coold even make it prettie... | 2016/12/16 | [
"https://wordpress.stackexchange.com/questions/249483",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/101799/"
] | I have seen many articles mentioning that a `/%postname%/` permalink is the best for SEO. But what about a `/%post_id%/%postname%` structure, such as `myblog.com/123/the-slug-of-my-blog` ?
* It doesn't seem to affect search engine rankings (Stack Exchange and many others use this structure)
* You make each permalink u... | Note: we're talking here about the difference between permalinks `/%ID%/%name%/` and `%/name/%`. It would be a whole different story if we were to compare `/%ID%/%name%/` and `%/ID/%`.
Now, there are two use cases that affect performance:
**One. You have a permalink and WP needs to resolve it in order to serve the p... |
249,485 | <p>Sorry for the noob question.</p>
<p>Is a text-domain necessary for a child theme? I am building a simple child theme with no text-domain declared. So, when I use strings which are to be translated, should I use the parent theme text-domain (yes parent theme has text-domain loaded and also has .mo/.po files).</p>
<... | [
{
"answer_id": 249522,
"author": "gmazzap",
"author_id": 35541,
"author_profile": "https://wordpress.stackexchange.com/users/35541",
"pm_score": 4,
"selected": true,
"text": "<p><strong>TL;DR:</strong> If you use strings that are in the parent theme, exaclty how they are used in parent t... | 2016/12/16 | [
"https://wordpress.stackexchange.com/questions/249485",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/88136/"
] | Sorry for the noob question.
Is a text-domain necessary for a child theme? I am building a simple child theme with no text-domain declared. So, when I use strings which are to be translated, should I use the parent theme text-domain (yes parent theme has text-domain loaded and also has .mo/.po files).
For example add... | **TL;DR:** If you use strings that are in the parent theme, exaclty how they are used in parent theme, you don't need to have a text domain for your child theme.
But if you use strings that aren't used in parent theme, to make them translatable, you'll need another text domain with related translation (`.mo`) files.
... |
249,505 | <p>I need to get all meta keys/custom fields that are assigned to a post type.</p>
<p>I don't want to get the <code>post_meta</code> values for <code>post_meta</code> assigned to a particular post, or to all posts of a post type.</p>
<p>But, I want to get all possible custom fields that are 'assigned' to a post type.... | [
{
"answer_id": 249508,
"author": "Gareth Gillman",
"author_id": 33936,
"author_profile": "https://wordpress.stackexchange.com/users/33936",
"pm_score": 1,
"selected": false,
"text": "<p>query all posts in the post type and then get the meta keys from the posts e.g.</p>\n\n<p><strong>Not ... | 2016/12/16 | [
"https://wordpress.stackexchange.com/questions/249505",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/66961/"
] | I need to get all meta keys/custom fields that are assigned to a post type.
I don't want to get the `post_meta` values for `post_meta` assigned to a particular post, or to all posts of a post type.
But, I want to get all possible custom fields that are 'assigned' to a post type.
I have looked and I am starting to w... | Answer by @Gareth Gillman definitely works but its an expensive query if we have hundreds of posts.
The function below is less expensive and using the wp native function [get\_post\_custom\_keys()](https://codex.wordpress.org/Function_Reference/get_post_custom_keys)
```
if ( ! function_exists( 'us_get_meta_keys_for_p... |
249,512 | <p>I've got the opposite problem a lot of people can when switching servers. All the pages work fine, EXCEPT the home page, which is generating a 404. It's just the blog URL by itself (mysite.com/blogfolder/). Wordpress is installed in a folder in the site root, and worked fine at the old host. htaccess is all what it ... | [
{
"answer_id": 249508,
"author": "Gareth Gillman",
"author_id": 33936,
"author_profile": "https://wordpress.stackexchange.com/users/33936",
"pm_score": 1,
"selected": false,
"text": "<p>query all posts in the post type and then get the meta keys from the posts e.g.</p>\n\n<p><strong>Not ... | 2016/12/16 | [
"https://wordpress.stackexchange.com/questions/249512",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109108/"
] | I've got the opposite problem a lot of people can when switching servers. All the pages work fine, EXCEPT the home page, which is generating a 404. It's just the blog URL by itself (mysite.com/blogfolder/). Wordpress is installed in a folder in the site root, and worked fine at the old host. htaccess is all what it is ... | Answer by @Gareth Gillman definitely works but its an expensive query if we have hundreds of posts.
The function below is less expensive and using the wp native function [get\_post\_custom\_keys()](https://codex.wordpress.org/Function_Reference/get_post_custom_keys)
```
if ( ! function_exists( 'us_get_meta_keys_for_p... |
249,513 | <p>I have a weird issue on <a href="https://meta-game.org/" rel="nofollow noreferrer">my site that's only affecting mobile</a>. If you scroll down past the black "What's Hot" section, you'll see the standard posts with featured images. Now, if you refresh the page, the standard posts after the "What's Hot" section are ... | [
{
"answer_id": 249695,
"author": "bueltge",
"author_id": 170,
"author_profile": "https://wordpress.stackexchange.com/users/170",
"pm_score": 2,
"selected": false,
"text": "<p>The images there you load is always to big for teh view screen, as example this image - <code>https://meta-game.o... | 2016/12/16 | [
"https://wordpress.stackexchange.com/questions/249513",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107325/"
] | I have a weird issue on [my site that's only affecting mobile](https://meta-game.org/). If you scroll down past the black "What's Hot" section, you'll see the standard posts with featured images. Now, if you refresh the page, the standard posts after the "What's Hot" section are missing the featured images. Nothing sho... | [](https://i.stack.imgur.com/rweR4.png)
The images not being loaded are prefixed with the domain `https://i2.wp.com`
This is the [CDN](https://en.wikipedia.org/wiki/Content_delivery_network) used when you activate the **PHOTON module** in the [**Jetp... |
249,601 | <p>I have a function I'm using to display a login notification when a user without access tries to view a single post. The function also displays the post excerpt publicly on archive, widgets, etc , but shows the login notification only when the full post is viewed, i.e. <code>is_singular</code></p>
<p>This basically... | [
{
"answer_id": 249594,
"author": "Rikki B",
"author_id": 109162,
"author_profile": "https://wordpress.stackexchange.com/users/109162",
"pm_score": 3,
"selected": true,
"text": "<p>It was a stupid question, I just realized, if I just create a custom shortcode for it, the plugin will not w... | 2016/12/18 | [
"https://wordpress.stackexchange.com/questions/249601",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109165/"
] | I have a function I'm using to display a login notification when a user without access tries to view a single post. The function also displays the post excerpt publicly on archive, widgets, etc , but shows the login notification only when the full post is viewed, i.e. `is_singular`
This basically allows users without ... | It was a stupid question, I just realized, if I just create a custom shortcode for it, the plugin will not wrap it in `<p>` tags then, or even better still just create it as a plugin of it's own. |
249,612 | <p>Want to use a different featured image size for a custom post type and exclude it from main blog loop. And also want to display it on specific page.</p>
<p>What will be the fastest way to achieve this? With code mess up and plugins?</p>
<p>Prefer a code snippet solution, but main issue it should work out-of-box, a... | [
{
"answer_id": 249618,
"author": "Pete",
"author_id": 37346,
"author_profile": "https://wordpress.stackexchange.com/users/37346",
"pm_score": 1,
"selected": false,
"text": "<p>Make a custom post-type template with the specific featured size in the template or appropriate css applied to t... | 2016/12/18 | [
"https://wordpress.stackexchange.com/questions/249612",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/32880/"
] | Want to use a different featured image size for a custom post type and exclude it from main blog loop. And also want to display it on specific page.
What will be the fastest way to achieve this? With code mess up and plugins?
Prefer a code snippet solution, but main issue it should work out-of-box, as fast solution i... | This might help - [Set featured image size for a custom post type](https://wordpress.stackexchange.com/questions/32811/set-featured-image-size-for-a-custom-post-type?rq=1),
>
> Just add a new image size
>
>
>
> ```
> add_image_size( 'companies_thumb', 120, 120, true);
>
> ```
>
> Then in the post type template ... |
249,622 | <p>How can I check if post with name for example Weather exists? If not I want to create it.</p>
<pre><code>function such_post_exists($title) {
global $wpdb;
$p_title = wp_unslash( sanitize_post_field( 'post_title', $title, 0, 'db' ) );
if ( !empty ( $title ) ) {
return (int) $wpdb->query("SELECT FROM $wpdb-&... | [
{
"answer_id": 249624,
"author": "Tunji",
"author_id": 54764,
"author_profile": "https://wordpress.stackexchange.com/users/54764",
"pm_score": 4,
"selected": true,
"text": "<p>Wordpress has a <code>post_exists</code> function that returns the post ID or 0 otherwise.\nSo you can do</p>\n\... | 2016/12/18 | [
"https://wordpress.stackexchange.com/questions/249622",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/105218/"
] | How can I check if post with name for example Weather exists? If not I want to create it.
```
function such_post_exists($title) {
global $wpdb;
$p_title = wp_unslash( sanitize_post_field( 'post_title', $title, 0, 'db' ) );
if ( !empty ( $title ) ) {
return (int) $wpdb->query("SELECT FROM $wpdb->posts WHERE post_... | Wordpress has a `post_exists` function that returns the post ID or 0 otherwise.
So you can do
```
if ( 0 === post_exists( $title ) ) {
**YOUR_CODE_HERE**
}
``` |
249,630 | <p>This,</p>
<pre><code>if( has_term( 'jazz', 'genre' ) ) {
// do something
}
</code></pre>
<p>will check if a post has the term <code>jazz</code> from the custom taxonomy <code>genre</code>. But how to check if a post belongs to a custom taxonomy <code>genre</code>? No matter whatever term it has, as long as it ... | [
{
"answer_id": 249634,
"author": "Tunji",
"author_id": 54764,
"author_profile": "https://wordpress.stackexchange.com/users/54764",
"pm_score": 2,
"selected": false,
"text": "<pre><code>if ( has_term('', 'genre') ) {\n // whether it's jazz, blues, rock and roll; doesn't matter as long ... | 2016/12/18 | [
"https://wordpress.stackexchange.com/questions/249630",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/13291/"
] | This,
```
if( has_term( 'jazz', 'genre' ) ) {
// do something
}
```
will check if a post has the term `jazz` from the custom taxonomy `genre`. But how to check if a post belongs to a custom taxonomy `genre`? No matter whatever term it has, as long as it has something from the `genre` taxonomy, it will check.
So... | You can have the term input empty, e.g.
```
if( has_term( '', 'genre' ) ) {
// do something
}
```
to see if the current post object has any terms in the genre taxonomy.
It uses [`is_object_in_term()`](https://developer.wordpress.org/reference/functions/is_object_in_term/) where:
>
> The given terms are checke... |
249,670 | <p>I'm trying to check the output of a variable in my functions.php file that runs after a new woocommerce order. The code will get the order time from a new order and store it in a variable for me to use elsewhere the code being:</p>
<pre><code>$meeting_time = wc_get_order_item_meta($order_id, 'Time');
print_r($meeti... | [
{
"answer_id": 249672,
"author": "TCode",
"author_id": 109129,
"author_profile": "https://wordpress.stackexchange.com/users/109129",
"pm_score": 0,
"selected": false,
"text": "<p>wc_get_order_item_meta function requires an Order Item's ID, not the Order ID.</p>\n\n<pre><code>wc_get_order... | 2016/12/19 | [
"https://wordpress.stackexchange.com/questions/249670",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/107852/"
] | I'm trying to check the output of a variable in my functions.php file that runs after a new woocommerce order. The code will get the order time from a new order and store it in a variable for me to use elsewhere the code being:
```
$meeting_time = wc_get_order_item_meta($order_id, 'Time');
print_r($meeting_time);
```... | You can use [`var_dump()`](http://php.net/manual/en/function.var-dump.php) instead of `print_r()` - you get the type and the value of the variable and it will also work when your variable holds `FALSE` or `NULL`.
```
print_r( false ); # doesn't output anything
var_dump( false ); # output: bool(false)
print_r( NULL )... |
249,671 | <p>Very basic question, but I couldn't find an answer.</p>
<p>I am using the WP CLI post get command: <a href="https://wp-cli.org/commands/post/get/" rel="nofollow noreferrer">https://wp-cli.org/commands/post/get/</a></p>
<p>One of the option is [--field=], but I can't find in the doc the list of allowed values for t... | [
{
"answer_id": 249681,
"author": "RRikesh",
"author_id": 17305,
"author_profile": "https://wordpress.stackexchange.com/users/17305",
"pm_score": 3,
"selected": true,
"text": "<p>The list of fields is available on the <a href=\"https://wp-cli.org/commands/post/list/#available-fields\" rel... | 2016/12/19 | [
"https://wordpress.stackexchange.com/questions/249671",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/44388/"
] | Very basic question, but I couldn't find an answer.
I am using the WP CLI post get command: <https://wp-cli.org/commands/post/get/>
One of the option is [--field=], but I can't find in the doc the list of allowed values for this field.
What am I missing? | The list of fields is available on the [`wp post list`](https://wp-cli.org/commands/post/list/#available-fields) page.
>
> These fields will be displayed by default for each post:
>
>
>
> ```
> ID
> post_title
> post_name
> post_date
> post_status
>
> ```
>
> These fields are optionally available:
>
>
>
> ```... |
249,677 | <p>I use Wordpress 4.7 and I installed an accessibility module. This module requires pasting the following php code block before the body. I went through the mother-theme php files but didn't find something like html.php or html.tpl ... Should this file be created (and maybe also declared) somewhere?</p>
<pre><code>&l... | [
{
"answer_id": 249687,
"author": "Md. Amanur Rahman",
"author_id": 109213,
"author_profile": "https://wordpress.stackexchange.com/users/109213",
"pm_score": 3,
"selected": true,
"text": "<p>You should paste that code in the header.php file. Just before the closing code . And that should... | 2016/12/19 | [
"https://wordpress.stackexchange.com/questions/249677",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | I use Wordpress 4.7 and I installed an accessibility module. This module requires pasting the following php code block before the body. I went through the mother-theme php files but didn't find something like html.php or html.tpl ... Should this file be created (and maybe also declared) somewhere?
```
<?php if(functio... | You should paste that code in the header.php file. Just before the closing code . And that should be done. And if it is asking for pasting the code in the template then find the specific page where you want to place it. There may be different template for different page. |
249,697 | <p>I want to display a loop in my page-projets.php file.</p>
<pre><code><div class="loop center">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
get_template_part('content');
endwhile;
get_template_part('pagination');
endif; ?>
</... | [
{
"answer_id": 249687,
"author": "Md. Amanur Rahman",
"author_id": 109213,
"author_profile": "https://wordpress.stackexchange.com/users/109213",
"pm_score": 3,
"selected": true,
"text": "<p>You should paste that code in the header.php file. Just before the closing code . And that should... | 2016/12/19 | [
"https://wordpress.stackexchange.com/questions/249697",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/88389/"
] | I want to display a loop in my page-projets.php file.
```
<div class="loop center">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
get_template_part('content');
endwhile;
get_template_part('pagination');
endif; ?>
</div>
```
However, on the re... | You should paste that code in the header.php file. Just before the closing code . And that should be done. And if it is asking for pasting the code in the template then find the specific page where you want to place it. There may be different template for different page. |
249,707 | <p>Something really weird happened. I want to change the color of this text but the index file has an !important there and when i change the color on my style.css file it doesn't work. What can i do to over ride that !important.</p>
<p>This is how it looks in my css file</p>
<pre><code>h1.entry-title {
color: #9A... | [
{
"answer_id": 249687,
"author": "Md. Amanur Rahman",
"author_id": 109213,
"author_profile": "https://wordpress.stackexchange.com/users/109213",
"pm_score": 3,
"selected": true,
"text": "<p>You should paste that code in the header.php file. Just before the closing code . And that should... | 2016/12/19 | [
"https://wordpress.stackexchange.com/questions/249707",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109224/"
] | Something really weird happened. I want to change the color of this text but the index file has an !important there and when i change the color on my style.css file it doesn't work. What can i do to over ride that !important.
This is how it looks in my css file
```
h1.entry-title {
color: #9A7B5C ;
}
```
i want... | You should paste that code in the header.php file. Just before the closing code . And that should be done. And if it is asking for pasting the code in the template then find the specific page where you want to place it. There may be different template for different page. |
249,712 | <p>I originally made <a href="https://wordpress.stackexchange.com/questions/249357/ninja-forms-shortcode-not-producing-intended-results-in-custom-wordpress-theme">this post</a>, thinking that my problem was specific to the Ninja Forms plugin (the original post was obviously put on hold, for being off-topic). My reason ... | [
{
"answer_id": 249731,
"author": "Md. Amanur Rahman",
"author_id": 109213,
"author_profile": "https://wordpress.stackexchange.com/users/109213",
"pm_score": 0,
"selected": false,
"text": "<p>You should try to active the default wordpress theme like twenty eleven or like that and then see... | 2016/12/19 | [
"https://wordpress.stackexchange.com/questions/249712",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109018/"
] | I originally made [this post](https://wordpress.stackexchange.com/questions/249357/ninja-forms-shortcode-not-producing-intended-results-in-custom-wordpress-theme), thinking that my problem was specific to the Ninja Forms plugin (the original post was obviously put on hold, for being off-topic). My reason for thinking s... | As was pointed out by [Michael](https://wordpress.stackexchange.com/users/4884/michael), I had been missing the `wp_head()` and `wp_footer()` functions.
To anyone who might be in the same boat as I, you can have a look at the function references [here (head)](https://codex.wordpress.org/Function_Reference/wp_head) and... |
249,744 | <p>Brand new site. Not MU. No matter what I do, I cannot get a file uploaded that exceeds 2MB. I'm running a localhost server with WordPress 4.3.1</p>
<p>I've modified both relevant settings in the the site's <code>php.ini</code> as:</p>
<pre><code>upload_max_filesize = 64M
post_max_size = 64M
</code></pre>
<p>Howev... | [
{
"answer_id": 249737,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 3,
"selected": true,
"text": "<p>While I know version control approach to be used in practice, I don't think it's too common. WP has weak version con... | 2016/12/19 | [
"https://wordpress.stackexchange.com/questions/249744",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/366/"
] | Brand new site. Not MU. No matter what I do, I cannot get a file uploaded that exceeds 2MB. I'm running a localhost server with WordPress 4.3.1
I've modified both relevant settings in the the site's `php.ini` as:
```
upload_max_filesize = 64M
post_max_size = 64M
```
However, I'm still getting the message when tryin... | While I know version control approach to be used in practice, I don't think it's too common. WP has weak version control practices in general, so development of extensions doesn't quite plan for such.
Example of specific scenario which will cause issues might be changes in template hierarchy. Let's say you customized ... |
249,753 | <p>I am using the REST API to publish posts outside of WordPress, and have run into a problem where not all of my shortcodes are getting processed. Specifically, most of my plugins' shortcodes are getting processed but nothing from visual composer is getting converted to HTML. I find that if I var_dump my REST API's po... | [
{
"answer_id": 249737,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 3,
"selected": true,
"text": "<p>While I know version control approach to be used in practice, I don't think it's too common. WP has weak version con... | 2016/12/19 | [
"https://wordpress.stackexchange.com/questions/249753",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109253/"
] | I am using the REST API to publish posts outside of WordPress, and have run into a problem where not all of my shortcodes are getting processed. Specifically, most of my plugins' shortcodes are getting processed but nothing from visual composer is getting converted to HTML. I find that if I var\_dump my REST API's post... | While I know version control approach to be used in practice, I don't think it's too common. WP has weak version control practices in general, so development of extensions doesn't quite plan for such.
Example of specific scenario which will cause issues might be changes in template hierarchy. Let's say you customized ... |
249,761 | <p>I have create a form on a wordpress page, and I'm trying to pass the values of the form to a php page, so I can send an email with that information, but I don't know how to create the php page, in what folder do I have to save the page.</p>
<p>Thank you (fist time using wordpress);</p>
<p>This is my form:
And I ha... | [
{
"answer_id": 249737,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 3,
"selected": true,
"text": "<p>While I know version control approach to be used in practice, I don't think it's too common. WP has weak version con... | 2016/12/19 | [
"https://wordpress.stackexchange.com/questions/249761",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109259/"
] | I have create a form on a wordpress page, and I'm trying to pass the values of the form to a php page, so I can send an email with that information, but I don't know how to create the php page, in what folder do I have to save the page.
Thank you (fist time using wordpress);
This is my form:
And I have a different pa... | While I know version control approach to be used in practice, I don't think it's too common. WP has weak version control practices in general, so development of extensions doesn't quite plan for such.
Example of specific scenario which will cause issues might be changes in template hierarchy. Let's say you customized ... |
249,766 | <p>I have a website that I am updating, it has over 400 posts so updating these manually isn't a very good option. The theme that was used is no longer supported, it has a custom field setup for the featured image. I want to convert that featured image to the WordPress featured image. How can I do this? In the database... | [
{
"answer_id": 249767,
"author": "mayersdesign",
"author_id": 106965,
"author_profile": "https://wordpress.stackexchange.com/users/106965",
"pm_score": -1,
"selected": false,
"text": "<p><a href=\"https://wordpress.org/plugins/quick-featured-images/\" rel=\"nofollow noreferrer\">https://... | 2016/12/19 | [
"https://wordpress.stackexchange.com/questions/249766",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109261/"
] | I have a website that I am updating, it has over 400 posts so updating these manually isn't a very good option. The theme that was used is no longer supported, it has a custom field setup for the featured image. I want to convert that featured image to the WordPress featured image. How can I do this? In the database, t... | I ended up finding another post that helped me achieve what I was trying to do. <https://stackoverflow.com/questions/4371929/convert-custom-field-image-to-become-featured-image-in-wordpress>
```
$uploads = wp_upload_dir();
// Get all attachment IDs and filenames
$results = $wpdb->get_results("SELECT post_id, meta_val... |
249,797 | <p>I am trying to retrieve some basic information from the Wordpress database for a theme. However, when the query runs it returns no data. If I run the query on Phpmyadmin, it works fine. Note, wp_places_locator is a table used by a third party plugin.</p>
<pre><code>function get_info($postid) {
global $wpdb;
$info... | [
{
"answer_id": 249800,
"author": "CodeMascot",
"author_id": 44192,
"author_profile": "https://wordpress.stackexchange.com/users/44192",
"pm_score": 2,
"selected": true,
"text": "<p>Here you've did something wrong with <code>$wpdb->table_name</code>. It will only return the default Wor... | 2016/12/20 | [
"https://wordpress.stackexchange.com/questions/249797",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106918/"
] | I am trying to retrieve some basic information from the Wordpress database for a theme. However, when the query runs it returns no data. If I run the query on Phpmyadmin, it works fine. Note, wp\_places\_locator is a table used by a third party plugin.
```
function get_info($postid) {
global $wpdb;
$info = $wpdb->ge... | Here you've did something wrong with `$wpdb->table_name`. It will only return the default WordPress table names. Not custom table names. And also when you call `$wpdb->prepare` then pass the parameter as array. So your function will be like below-
```
function get_info($postid) {
global $wpdb;
// Here I assu... |
249,815 | <p>I am running a news website, most of the posts are from an Editor Account. I want to hide the author-box displaying at the bottom of the posts, only for this user. Only author box of Editor should be hidden from public.<br/>
Is there any way to hide the author box of a particular user from public, with a funtion?</p... | [
{
"answer_id": 249818,
"author": "dgarceran",
"author_id": 109222,
"author_profile": "https://wordpress.stackexchange.com/users/109222",
"pm_score": 2,
"selected": true,
"text": "<p>If you know the data of the author, you can wrap that box with an if and the function <a href=\"https://co... | 2016/12/20 | [
"https://wordpress.stackexchange.com/questions/249815",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109300/"
] | I am running a news website, most of the posts are from an Editor Account. I want to hide the author-box displaying at the bottom of the posts, only for this user. Only author box of Editor should be hidden from public.
Is there any way to hide the author box of a particular user from public, with a funtion?
Author... | If you know the data of the author, you can wrap that box with an if and the function [get\_the\_author](https://codex.wordpress.org/Function_Reference/get_the_author)
```
if( get_the_author() == "name_of_the_author" ){
// Don't do it
}else{
// Print box
}
```
EDIT with the final answer updated:
```
<?php echo $td_... |
249,826 | <p>I have written functionality for checking if custom post title exists or not while adding post. like below:</p>
<pre><code> function wp_exist_post_by_title( $title ) {
global $wpdb;
$return = $wpdb->get_row( "SELECT ID FROM wp_dxwe_posts WHERE post_title = '" . $title . "' && post_status = 'publ... | [
{
"answer_id": 300151,
"author": "Lucas Bustamante",
"author_id": 27278,
"author_profile": "https://wordpress.stackexchange.com/users/27278",
"pm_score": 2,
"selected": false,
"text": "<p>You can do it like so:</p>\n\n<pre><code>if (get_page_by_title('Some Title', OBJECT, 'post_type')) {... | 2016/12/20 | [
"https://wordpress.stackexchange.com/questions/249826",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106542/"
] | I have written functionality for checking if custom post title exists or not while adding post. like below:
```
function wp_exist_post_by_title( $title ) {
global $wpdb;
$return = $wpdb->get_row( "SELECT ID FROM wp_dxwe_posts WHERE post_title = '" . $title . "' && post_status = 'publish' && post_type = 'cour... | You can do it like so:
```
if (get_page_by_title('Some Title', OBJECT, 'post_type')) {
// Exists
}
```
**post\_type** can be "post", "page", a custom post type slug, etc.
Reference: <https://codex.wordpress.org/Function_Reference/get_page_by_title> |
249,827 | <p>I've been searching for a good few days now trying to get my WordPress event calendar by modern tribe working as I need it to.</p>
<p>I have hundreds of order by and delivery dates in DB each one separated by about 5-10 weeks. what I'm trying to achieve is a list where I can see the all the events starting on today... | [
{
"answer_id": 300151,
"author": "Lucas Bustamante",
"author_id": 27278,
"author_profile": "https://wordpress.stackexchange.com/users/27278",
"pm_score": 2,
"selected": false,
"text": "<p>You can do it like so:</p>\n\n<pre><code>if (get_page_by_title('Some Title', OBJECT, 'post_type')) {... | 2016/12/20 | [
"https://wordpress.stackexchange.com/questions/249827",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/91255/"
] | I've been searching for a good few days now trying to get my WordPress event calendar by modern tribe working as I need it to.
I have hundreds of order by and delivery dates in DB each one separated by about 5-10 weeks. what I'm trying to achieve is a list where I can see the all the events starting on today's or yest... | You can do it like so:
```
if (get_page_by_title('Some Title', OBJECT, 'post_type')) {
// Exists
}
```
**post\_type** can be "post", "page", a custom post type slug, etc.
Reference: <https://codex.wordpress.org/Function_Reference/get_page_by_title> |
249,854 | <p>I am trying to replace the image at <a href="https://imgur.com/a/IHwaC" rel="nofollow noreferrer">http://imgur.com/a/IHwaC</a> (wont let me upload it to here for some reason) with another image but whenever I do it it just seems to make the background white and not actually do anything.
The way I change them is by ... | [
{
"answer_id": 300151,
"author": "Lucas Bustamante",
"author_id": 27278,
"author_profile": "https://wordpress.stackexchange.com/users/27278",
"pm_score": 2,
"selected": false,
"text": "<p>You can do it like so:</p>\n\n<pre><code>if (get_page_by_title('Some Title', OBJECT, 'post_type')) {... | 2016/12/20 | [
"https://wordpress.stackexchange.com/questions/249854",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109320/"
] | I am trying to replace the image at [http://imgur.com/a/IHwaC](https://imgur.com/a/IHwaC) (wont let me upload it to here for some reason) with another image but whenever I do it it just seems to make the background white and not actually do anything.
The way I change them is by uploading the image to the WordPress med... | You can do it like so:
```
if (get_page_by_title('Some Title', OBJECT, 'post_type')) {
// Exists
}
```
**post\_type** can be "post", "page", a custom post type slug, etc.
Reference: <https://codex.wordpress.org/Function_Reference/get_page_by_title> |
249,881 | <p>I am trying to order blog posts by 'city' first and then order by 'street_name' within each city. I can't seem to get the 'street_name' to display in alphabetical order. I am using WP_Query:</p>
<pre><code> <?php
$args = array(
'post_type'=> 'property',
... | [
{
"answer_id": 249894,
"author": "ngearing",
"author_id": 50184,
"author_profile": "https://wordpress.stackexchange.com/users/50184",
"pm_score": 3,
"selected": false,
"text": "<p><code>meta_query</code> and <code>orderby</code> are seperate parameters, you just put them together in an a... | 2016/12/20 | [
"https://wordpress.stackexchange.com/questions/249881",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109345/"
] | I am trying to order blog posts by 'city' first and then order by 'street\_name' within each city. I can't seem to get the 'street\_name' to display in alphabetical order. I am using WP\_Query:
```
<?php
$args = array(
'post_type'=> 'property',
'm... | `meta_query` and `orderby` are seperate parameters, you just put them together in an array. You will have to do one then the other.
e.g.
```
<?php
$args = array(
'post_type' => 'property',
'meta_query' => array(
array(
'relation' => 'AND',
'city_clause' => array(
... |
249,900 | <p>I'm having issues with a query. I want to get the images attached to an individual post of the type <em>rental</em>.</p>
<p>My query is broken as it outputs all the images on the entire site:</p>
<pre><code>$image_query = new WP_Query(
array(
'post_type' => 'attachment',
'post_status' =&g... | [
{
"answer_id": 249894,
"author": "ngearing",
"author_id": 50184,
"author_profile": "https://wordpress.stackexchange.com/users/50184",
"pm_score": 3,
"selected": false,
"text": "<p><code>meta_query</code> and <code>orderby</code> are seperate parameters, you just put them together in an a... | 2016/12/21 | [
"https://wordpress.stackexchange.com/questions/249900",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109355/"
] | I'm having issues with a query. I want to get the images attached to an individual post of the type *rental*.
My query is broken as it outputs all the images on the entire site:
```
$image_query = new WP_Query(
array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'post_mime_... | `meta_query` and `orderby` are seperate parameters, you just put them together in an array. You will have to do one then the other.
e.g.
```
<?php
$args = array(
'post_type' => 'property',
'meta_query' => array(
array(
'relation' => 'AND',
'city_clause' => array(
... |
249,901 | <p>I want to break the loop into sections of posts so I can put content in between that doesn't repeat. Is it possible to end the loop and restart?</p>
<p>My code works for my layout works if there are 10 posts on a page. When I have fewer it breaks because the closing div for .grid is tied in with the 10th post showi... | [
{
"answer_id": 249906,
"author": "prosti",
"author_id": 88606,
"author_profile": "https://wordpress.stackexchange.com/users/88606",
"pm_score": -1,
"selected": false,
"text": "<p>You can use before the <code>while</code> loop</p>\n\n<pre><code>global $wp_query;\n$total_posts = $wp_query-... | 2016/12/21 | [
"https://wordpress.stackexchange.com/questions/249901",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/78026/"
] | I want to break the loop into sections of posts so I can put content in between that doesn't repeat. Is it possible to end the loop and restart?
My code works for my layout works if there are 10 posts on a page. When I have fewer it breaks because the closing div for .grid is tied in with the 10th post showing.
This... | This pattern can be reduced to two main sections, large box and grid boxes.
And you said you were having trouble closing the grid boxes when your posts are less than 10, an easy way to close off the grid would be to check if the current post is equal to the total posts.
Here is my interpretation of your loop:
```
<?... |
249,918 | <p>I am using wordpress 4.6.</p>
<p>I have template register form with page URL <code>domain-name/account/?action=register</code></p>
<p>I want to redirect it to home page after register but instead of that it show </p>
<p>message "You have logged in. You better go to Home" with page URL </p>
<pre><code>domain-name... | [
{
"answer_id": 249923,
"author": "Ranuka",
"author_id": 106350,
"author_profile": "https://wordpress.stackexchange.com/users/106350",
"pm_score": 2,
"selected": false,
"text": "<p>Instead of your code why don't you try which in the <a href=\"https://codex.wordpress.org/Plugin_API/Filter_... | 2016/12/21 | [
"https://wordpress.stackexchange.com/questions/249918",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109080/"
] | I am using wordpress 4.6.
I have template register form with page URL `domain-name/account/?action=register`
I want to redirect it to home page after register but instead of that it show
message "You have logged in. You better go to Home" with page URL
```
domain-name/account/?result=registered.
```
I already t... | Instead of your code why don't you try which in the [codex example](https://codex.wordpress.org/Plugin_API/Filter_Reference/registration_redirect).
This simple example will redirect a user to the `home_url()` upon successful registration.
```
add_filter( 'registration_redirect', 'my_redirect_home' );
function my_red... |
249,929 | <p>please give me advice Im very new to ajax, I have a list of posts, if I click it will display the posts information in a div without load the page. I know I must use ajax, so I create a file: loadcontent.php in a root folder and use this code below, but I don't know how to send and get data throught ajax. I need to ... | [
{
"answer_id": 249932,
"author": "Kaeles",
"author_id": 109375,
"author_profile": "https://wordpress.stackexchange.com/users/109375",
"pm_score": 4,
"selected": true,
"text": "<p>Use Ajax API provided by WordPress.</p>\n\n<p>In first time, fix your Ajax request :</p>\n\n<pre><code><sc... | 2016/12/21 | [
"https://wordpress.stackexchange.com/questions/249929",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/103681/"
] | please give me advice Im very new to ajax, I have a list of posts, if I click it will display the posts information in a div without load the page. I know I must use ajax, so I create a file: loadcontent.php in a root folder and use this code below, but I don't know how to send and get data throught ajax. I need to pas... | Use Ajax API provided by WordPress.
In first time, fix your Ajax request :
```
<script>
$(".post-link").click(function(){
var post_id = $(this).attr("rel"); //this is the post id
$("#post-container").html("content loading");
$.ajax({
url: myapiurl.ajax_url,
type: 'post|get|put',
da... |
249,931 | <p>I want to include a file only in single post page. I've following code but not working;</p>
<pre><code>if (is_single()){
require_once(dirname(__FILE__) . '/inc/lazy-load.php');
}
</code></pre>
<p>I mean i just want to load lazy-load in only single post page. but above code is not working. Any idea? Hope to get a s... | [
{
"answer_id": 249941,
"author": "Tunji",
"author_id": 54764,
"author_profile": "https://wordpress.stackexchange.com/users/54764",
"pm_score": 0,
"selected": false,
"text": "<p>The best way would be to create a child theme then duplicate your <code>single.php</code> template file and edi... | 2016/12/21 | [
"https://wordpress.stackexchange.com/questions/249931",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109374/"
] | I want to include a file only in single post page. I've following code but not working;
```
if (is_single()){
require_once(dirname(__FILE__) . '/inc/lazy-load.php');
}
```
I mean i just want to load lazy-load in only single post page. but above code is not working. Any idea? Hope to get a solve for this problem. | [is\_single](https://developer.wordpress.org/reference/functions/is_single/) function checks for $wp\_query global variable is loading single post of any post type or not , $wp\_query is set after running query\_posts function that loaded after [wp](https://codex.wordpress.org/Plugin_API/Action_Reference/wp) action hoo... |
249,933 | <p>I recently stumbled upon this and was wondering if calling <code>wp_mail()</code> in a theme is allowed or not as per WordPress standards. I should clarify that I'm not overriding it as a pluggable function in the theme, I am just calling it if it exists.</p>
<p>I'm asking here because I've been searching for this ... | [
{
"answer_id": 249941,
"author": "Tunji",
"author_id": 54764,
"author_profile": "https://wordpress.stackexchange.com/users/54764",
"pm_score": 0,
"selected": false,
"text": "<p>The best way would be to create a child theme then duplicate your <code>single.php</code> template file and edi... | 2016/12/21 | [
"https://wordpress.stackexchange.com/questions/249933",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97347/"
] | I recently stumbled upon this and was wondering if calling `wp_mail()` in a theme is allowed or not as per WordPress standards. I should clarify that I'm not overriding it as a pluggable function in the theme, I am just calling it if it exists.
I'm asking here because I've been searching for this but did not find any ... | [is\_single](https://developer.wordpress.org/reference/functions/is_single/) function checks for $wp\_query global variable is loading single post of any post type or not , $wp\_query is set after running query\_posts function that loaded after [wp](https://codex.wordpress.org/Plugin_API/Action_Reference/wp) action hoo... |
249,948 | <p>My post template won't load the stylesheet, what's going wrong?</p>
<pre><code>function wpse_enqueue_post_template_styles() {
if ( is_post_template( 'category-bedrijven.php' ) ) {
wp_enqueue_style( 'post-template', get_stylesheet_directory_uri() . '/layout-interieur.css' );
}
}
add_action( 'wp_enque... | [
{
"answer_id": 249951,
"author": "CodeMascot",
"author_id": 44192,
"author_profile": "https://wordpress.stackexchange.com/users/44192",
"pm_score": 1,
"selected": false,
"text": "<p>You can do it like-</p>\n\n<pre><code>function wpse_enqueue_post_template_styles() {\n if ( is_category... | 2016/12/21 | [
"https://wordpress.stackexchange.com/questions/249948",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109390/"
] | My post template won't load the stylesheet, what's going wrong?
```
function wpse_enqueue_post_template_styles() {
if ( is_post_template( 'category-bedrijven.php' ) ) {
wp_enqueue_style( 'post-template', get_stylesheet_directory_uri() . '/layout-interieur.css' );
}
}
add_action( 'wp_enqueue_scripts', '... | You can do it like-
```
function wpse_enqueue_post_template_styles() {
if ( is_category('bedrijven') ) {
wp_enqueue_style( 'post-template', get_stylesheet_directory_uri() . '/layout-interieur.css' );
}
}
add_action( 'wp_enqueue_scripts', 'wpse_enqueue_post_template_styles' );
```
Here ***bedrijven***... |
249,961 | <p>I am experiencing a really weird issue. </p>
<p>The built in function the_excerpt() as soon as the user inserts a custom excerpt form the back end return the excerpt which is produced dynamically by WP without a read more button. If the user does not insert a custom excerpt, the function returns the excerpt along w... | [
{
"answer_id": 249951,
"author": "CodeMascot",
"author_id": 44192,
"author_profile": "https://wordpress.stackexchange.com/users/44192",
"pm_score": 1,
"selected": false,
"text": "<p>You can do it like-</p>\n\n<pre><code>function wpse_enqueue_post_template_styles() {\n if ( is_category... | 2016/12/21 | [
"https://wordpress.stackexchange.com/questions/249961",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109321/"
] | I am experiencing a really weird issue.
The built in function the\_excerpt() as soon as the user inserts a custom excerpt form the back end return the excerpt which is produced dynamically by WP without a read more button. If the user does not insert a custom excerpt, the function returns the excerpt along with a rea... | You can do it like-
```
function wpse_enqueue_post_template_styles() {
if ( is_category('bedrijven') ) {
wp_enqueue_style( 'post-template', get_stylesheet_directory_uri() . '/layout-interieur.css' );
}
}
add_action( 'wp_enqueue_scripts', 'wpse_enqueue_post_template_styles' );
```
Here ***bedrijven***... |
250,032 | <p>I'm wondering how to get at custom field information attached to a page, not a post.</p>
<p>Using get_post_meta seems like the right idea, but I don't know how to tell the function to look at page ids and not post ids. Also it's no clear to me if this function can work outside the loop.</p>
<p>A short piece of cod... | [
{
"answer_id": 250034,
"author": "Mayeenul Islam",
"author_id": 22728,
"author_profile": "https://wordpress.stackexchange.com/users/22728",
"pm_score": 1,
"selected": true,
"text": "<p>Sometimes WordPress is criticized treating everything as a <code>post</code>. The matter of fact is, po... | 2016/12/22 | [
"https://wordpress.stackexchange.com/questions/250032",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109442/"
] | I'm wondering how to get at custom field information attached to a page, not a post.
Using get\_post\_meta seems like the right idea, but I don't know how to tell the function to look at page ids and not post ids. Also it's no clear to me if this function can work outside the loop.
A short piece of code showing how t... | Sometimes WordPress is criticized treating everything as a `post`. The matter of fact is, post type `pages`, post type `post` - both are actually Post in database. So no post will collide with any page ID. :)
So simply a `get_post_meta()` is enough.
But if you still want something specific to Pages, you can use:
```... |
250,041 | <p>I have created a a site on my localhost, But Now I need to upload website on live server so i need to export word press DB from Phpmyadmin, But I cant find any WP DB there.</p>
<p>Here is my <strong>wp-config file</strong></p>
<pre><code>/** The name of the database for WordPress */
define('DB_NAME', 'bitnami_wor... | [
{
"answer_id": 250043,
"author": "Bunty",
"author_id": 109377,
"author_profile": "https://wordpress.stackexchange.com/users/109377",
"pm_score": 0,
"selected": false,
"text": "<p>There is a plugin named 'adminer'. You can use that.</p>\n\n<p>And my all time favourite for moving wordpress... | 2016/12/22 | [
"https://wordpress.stackexchange.com/questions/250041",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/101083/"
] | I have created a a site on my localhost, But Now I need to upload website on live server so i need to export word press DB from Phpmyadmin, But I cant find any WP DB there.
Here is my **wp-config file**
```
/** The name of the database for WordPress */
define('DB_NAME', 'bitnami_wordpress');
/** MySQL database usern... | I don't see any reason to login as root if you only need the one database... Have you tried logging in to phpMyAdmin as the user with the same credentials as your WordPress installation?
```
user: bn_wordpress
pass: 0cca6aaab5
port: 3306
```
We could avoid phpMyAdmin all together... From the command line you can du... |
250,051 | <p>I have a query that works when I have a field view_type = sale but when the view_type = lead it doesn't return any records even when I know there is one. Here is the query...</p>
<pre><code> SELECT a.id, a.user_email, a.user_registered, a.user_login, b1.meta_value AS first_name, b2.meta_value as last_name, b3.me... | [
{
"answer_id": 250043,
"author": "Bunty",
"author_id": 109377,
"author_profile": "https://wordpress.stackexchange.com/users/109377",
"pm_score": 0,
"selected": false,
"text": "<p>There is a plugin named 'adminer'. You can use that.</p>\n\n<p>And my all time favourite for moving wordpress... | 2016/12/22 | [
"https://wordpress.stackexchange.com/questions/250051",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/88860/"
] | I have a query that works when I have a field view\_type = sale but when the view\_type = lead it doesn't return any records even when I know there is one. Here is the query...
```
SELECT a.id, a.user_email, a.user_registered, a.user_login, b1.meta_value AS first_name, b2.meta_value as last_name, b3.meta_value as ... | I don't see any reason to login as root if you only need the one database... Have you tried logging in to phpMyAdmin as the user with the same credentials as your WordPress installation?
```
user: bn_wordpress
pass: 0cca6aaab5
port: 3306
```
We could avoid phpMyAdmin all together... From the command line you can du... |
250,076 | <p><a href="https://stackoverflow.com/questions/4915753/how-can-i-remove-3-characters-at-the-end-of-a-string-in-php">This snippet</a> shows us how to remove 3 characters at the end of a string...</p>
<pre><code>echo substr($string, 0, -3);
</code></pre>
<p>I'd like to find a way to use a custom field value as the str... | [
{
"answer_id": 250078,
"author": "Nicolai Grossherr",
"author_id": 22534,
"author_profile": "https://wordpress.stackexchange.com/users/22534",
"pm_score": 2,
"selected": true,
"text": "<p>You have to consider that you're dealing with <a href=\"http://php.net/manual/en/function.substr.php... | 2016/12/22 | [
"https://wordpress.stackexchange.com/questions/250076",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/37346/"
] | [This snippet](https://stackoverflow.com/questions/4915753/how-can-i-remove-3-characters-at-the-end-of-a-string-in-php) shows us how to remove 3 characters at the end of a string...
```
echo substr($string, 0, -3);
```
I'd like to find a way to use a custom field value as the string. This is what I've tried with no ... | You have to consider that you're dealing with [`substr()`](http://php.net/manual/en/function.substr.php) a *string* related function as the **str** in the function name indicates. That does mean that the parameter `$string` you give actually has to be of the [type `string`](http://php.net/manual/en/language.types.intro... |
250,102 | <p>I've mistakenly deleted the <strong><code>functions.php</code></strong> file of my Twenty Sixteen WordPress Theme running the command below:</p>
<pre><code>rm /var/www/html/wp/wp-content/themes/twentysixteen/functions.php
</code></pre>
<p>The Twenty Sixteen Theme is my currently active theme and as such, my WordP... | [
{
"answer_id": 250108,
"author": "Tunji",
"author_id": 54764,
"author_profile": "https://wordpress.stackexchange.com/users/54764",
"pm_score": 0,
"selected": false,
"text": "<p>You can always re-download the Twenty Sixteen theme from the official <a href=\"https://wordpress.org/themes/tw... | 2016/12/22 | [
"https://wordpress.stackexchange.com/questions/250102",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/70405/"
] | I've mistakenly deleted the **`functions.php`** file of my Twenty Sixteen WordPress Theme running the command below:
```
rm /var/www/html/wp/wp-content/themes/twentysixteen/functions.php
```
The Twenty Sixteen Theme is my currently active theme and as such, my WordPress site is no longer accessible as it used to be... | To fix your site, you should get another [**`functions.php`**](https://github.com/WordPress/twentysixteen/blob/master/functions.php).
As such, you can get that from your most recent and operational backup and upload it unto the location of the mistakenly deleted one.
In case you don't have a backup, your last option ... |
250,147 | <p>I need your help.</p>
<p>There is my problem: I have custom post type "Player". And this <em>CPT</em> has custom field "Seasons". Seasons can have multiple values separated by comma - for example "2014,2015,2016" etc.</p>
<p>Now I need filter list of player who played in certain seasons - for example 2015 and 2016... | [
{
"answer_id": 250182,
"author": "dgarceran",
"author_id": 109222,
"author_profile": "https://wordpress.stackexchange.com/users/109222",
"pm_score": 0,
"selected": false,
"text": "<p>Here's how I would do it with <a href=\"https://codex.wordpress.org/The_Loop\" rel=\"nofollow noreferrer\... | 2016/12/23 | [
"https://wordpress.stackexchange.com/questions/250147",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/63734/"
] | I need your help.
There is my problem: I have custom post type "Player". And this *CPT* has custom field "Seasons". Seasons can have multiple values separated by comma - for example "2014,2015,2016" etc.
Now I need filter list of player who played in certain seasons - for example 2015 and 2016.
And now I need your h... | Expanding a bit on the answer from @dgarceran
Generally, using the `WP_Query` class is probably a good idea for querying posts.
We'll want to pass arguments to that query.
In your case we'll likely want use one of the following:
1. "**Custom Field Parameters**" - `meta_query`
2. "**Taxonomy Parameters**" - `tax_qu... |
250,150 | <p>I've got an array of images attached to a post, and can output them sequentually just fine:</p>
<p>1 2 3 4 5 6 7</p>
<p>How can I get three images at a time from the array, then step one image forward to create the following arrays of three images:</p>
<p>1 2 3</p>
<p>2 3 4</p>
<p>3 4 5</p>
<p>4 5 6</p>
<p>an... | [
{
"answer_id": 250158,
"author": "Tunji",
"author_id": 54764,
"author_profile": "https://wordpress.stackexchange.com/users/54764",
"pm_score": 3,
"selected": true,
"text": "<p>You can split your array using the following</p>\n\n<pre><code>$array = array(1,2,3,4,5,6);\n$number_of_elements... | 2016/12/23 | [
"https://wordpress.stackexchange.com/questions/250150",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109355/"
] | I've got an array of images attached to a post, and can output them sequentually just fine:
1 2 3 4 5 6 7
How can I get three images at a time from the array, then step one image forward to create the following arrays of three images:
1 2 3
2 3 4
3 4 5
4 5 6
and so on?
Here's my code:
```
global $rental;
$ima... | You can split your array using the following
```
$array = array(1,2,3,4,5,6);
$number_of_elements = 3;
$count = count( $array );
$split = array();
for ( $i = 0; $i <= $count - 1; $i++ ) {
$slices = array_slice( $array, $i , $number_of_elements);
if ( count( $slices ) != $number_of_elements )
break;
... |
250,164 | <p>I'm trying to do a count for pagination and its returning NULL why the query returns results correctly. In this case $total returns NULL which is not correct why? (I didn't include the $args as they work)</p>
<pre><code>$total_query = "SELECT COUNT(*) FROM (${args}) AS total_count";
$total = $wpdb->get_var( $tot... | [
{
"answer_id": 250158,
"author": "Tunji",
"author_id": 54764,
"author_profile": "https://wordpress.stackexchange.com/users/54764",
"pm_score": 3,
"selected": true,
"text": "<p>You can split your array using the following</p>\n\n<pre><code>$array = array(1,2,3,4,5,6);\n$number_of_elements... | 2016/12/23 | [
"https://wordpress.stackexchange.com/questions/250164",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/88860/"
] | I'm trying to do a count for pagination and its returning NULL why the query returns results correctly. In this case $total returns NULL which is not correct why? (I didn't include the $args as they work)
```
$total_query = "SELECT COUNT(*) FROM (${args}) AS total_count";
$total = $wpdb->get_var( $total_query );
$item... | You can split your array using the following
```
$array = array(1,2,3,4,5,6);
$number_of_elements = 3;
$count = count( $array );
$split = array();
for ( $i = 0; $i <= $count - 1; $i++ ) {
$slices = array_slice( $array, $i , $number_of_elements);
if ( count( $slices ) != $number_of_elements )
break;
... |
250,167 | <p>I am trying to update the value of one custom post type's meta when another custom post type is deleted.</p>
<p>When a space_rental is deleted, I need to update some meta value on a space.</p>
<p>I don't think I can use <code>delete_post</code> because it fires after the meta data has been deleted, but this isn't ... | [
{
"answer_id": 250176,
"author": "Tunji",
"author_id": 54764,
"author_profile": "https://wordpress.stackexchange.com/users/54764",
"pm_score": 1,
"selected": false,
"text": "<p>There's a <a href=\"https://codex.wordpress.org/Plugin_API/Action_Reference/trash_post\" rel=\"nofollow norefer... | 2016/12/23 | [
"https://wordpress.stackexchange.com/questions/250167",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23492/"
] | I am trying to update the value of one custom post type's meta when another custom post type is deleted.
When a space\_rental is deleted, I need to update some meta value on a space.
I don't think I can use `delete_post` because it fires after the meta data has been deleted, but this isn't working for me either (eith... | There's a [**trash post**](https://codex.wordpress.org/Plugin_API/Action_Reference/trash_post) hook
```
add_action( 'trash_post', 'my_func' );
function my_func( $postid ){
// We check if the global post type isn't ours and just return
global $post_type;
if ( $post_type != 'my_custom_post_type' ) return... |
250,191 | <p>I have written a plugin for my own site where I have an issue like "after user login to the site if he logout then again if he clicks on browser back button then the previous page showing again instead of login page". Iam trying the below code but it doesn't work.</p>
<pre><code><script>
window.onhashchang... | [
{
"answer_id": 250176,
"author": "Tunji",
"author_id": 54764,
"author_profile": "https://wordpress.stackexchange.com/users/54764",
"pm_score": 1,
"selected": false,
"text": "<p>There's a <a href=\"https://codex.wordpress.org/Plugin_API/Action_Reference/trash_post\" rel=\"nofollow norefer... | 2016/12/23 | [
"https://wordpress.stackexchange.com/questions/250191",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106542/"
] | I have written a plugin for my own site where I have an issue like "after user login to the site if he logout then again if he clicks on browser back button then the previous page showing again instead of login page". Iam trying the below code but it doesn't work.
```
<script>
window.onhashchange = function() {
... | There's a [**trash post**](https://codex.wordpress.org/Plugin_API/Action_Reference/trash_post) hook
```
add_action( 'trash_post', 'my_func' );
function my_func( $postid ){
// We check if the global post type isn't ours and just return
global $post_type;
if ( $post_type != 'my_custom_post_type' ) return... |
250,205 | <p>I'm preparing plugin and I have trouble to call (and return) javascript from each (same) shortcode in one wp page/post. Javascript returns values only to last shortcode in page.</p>
<p>PHP code here:</p>
<pre><code>add_shortcode( 'ada_chart', 'ada_chart_stranka' );
function ada_chart_stranka ($atts) { ... | [
{
"answer_id": 250176,
"author": "Tunji",
"author_id": 54764,
"author_profile": "https://wordpress.stackexchange.com/users/54764",
"pm_score": 1,
"selected": false,
"text": "<p>There's a <a href=\"https://codex.wordpress.org/Plugin_API/Action_Reference/trash_post\" rel=\"nofollow norefer... | 2016/12/23 | [
"https://wordpress.stackexchange.com/questions/250205",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109514/"
] | I'm preparing plugin and I have trouble to call (and return) javascript from each (same) shortcode in one wp page/post. Javascript returns values only to last shortcode in page.
PHP code here:
```
add_shortcode( 'ada_chart', 'ada_chart_stranka' );
function ada_chart_stranka ($atts) {
$a = shortcode_a... | There's a [**trash post**](https://codex.wordpress.org/Plugin_API/Action_Reference/trash_post) hook
```
add_action( 'trash_post', 'my_func' );
function my_func( $postid ){
// We check if the global post type isn't ours and just return
global $post_type;
if ( $post_type != 'my_custom_post_type' ) return... |
250,210 | <p>I'm using the customizer to upload an image. The code I have below displays the full size image ok but I would like to instead display a custom size of that image that I created below that. </p>
<p>This is the code in my template file:</p>
<pre><code><img src="<?php echo get_theme_mod( 'image-1' , get_templa... | [
{
"answer_id": 250217,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 2,
"selected": false,
"text": "<p>Apparently, your mod is storing the complete path to the image as a string. That leaves you little alternative b... | 2016/12/23 | [
"https://wordpress.stackexchange.com/questions/250210",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40536/"
] | I'm using the customizer to upload an image. The code I have below displays the full size image ok but I would like to instead display a custom size of that image that I created below that.
This is the code in my template file:
```
<img src="<?php echo get_theme_mod( 'image-1' , get_template_directory_uri().'/images... | Apparently, your mod is storing the complete path to the image as a string. That leaves you little alternative but to do a search and replace on the string:
```
$img = get_theme_mod('image-1');
if (!empty ($img)) {
$img = preg_replace ('.(jpg|jpeg|png|gif)$','-525x350$0');
if (!file_exists($img)) $img = get_templa... |
250,241 | <p>My WordPress (v4.7) site's media settings only shows sizes for Thumbnail, Medium, and Large. How do I add a Small size to it?</p>
| [
{
"answer_id": 250217,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 2,
"selected": false,
"text": "<p>Apparently, your mod is storing the complete path to the image as a string. That leaves you little alternative b... | 2016/12/23 | [
"https://wordpress.stackexchange.com/questions/250241",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/51855/"
] | My WordPress (v4.7) site's media settings only shows sizes for Thumbnail, Medium, and Large. How do I add a Small size to it? | Apparently, your mod is storing the complete path to the image as a string. That leaves you little alternative but to do a search and replace on the string:
```
$img = get_theme_mod('image-1');
if (!empty ($img)) {
$img = preg_replace ('.(jpg|jpeg|png|gif)$','-525x350$0');
if (!file_exists($img)) $img = get_templa... |
250,264 | <p>Every WordPress page can be described as having two titles:</p>
<ol>
<li><p>The page/post title, which is displayed within the page/post via the <code>the_title()</code> function call</p></li>
<li><p>The html <code><title></title></code> tag that displays the title on top of the browser</p></li>
</ol>
... | [
{
"answer_id": 250266,
"author": "pankaj choudhary",
"author_id": 109569,
"author_profile": "https://wordpress.stackexchange.com/users/109569",
"pm_score": 1,
"selected": false,
"text": "<p>Using this code on you page.php or page which you want to change\n<code><pre>\n<title>... | 2016/12/24 | [
"https://wordpress.stackexchange.com/questions/250264",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/34253/"
] | Every WordPress page can be described as having two titles:
1. The page/post title, which is displayed within the page/post via the `the_title()` function call
2. The html `<title></title>` tag that displays the title on top of the browser
I am writing a plugin which at one point should change the title of a page dyn... | A post or page has only one title, the title tag `<title>` is the document title.
The filter `wp_title` filters the output of `wp_title()` function, which was used before to output the title of the document. In WordPress 4.1, the title-tag support in themes was introduced and [`wp_get_document_title()`](https://develo... |
250,280 | <p>Considering regular WordPress ajax requests like these:</p>
<pre><code>add_action( 'wp_ajax_merrychristmas_happynewyear', array( $this, 'merrychristmas_happynewyear' ) );
add_action( 'wp_ajax_nopriv_merrychristmas_happynewyear', array( $this, 'merrychristmas_happynewyear' ) );
</code></pre>
<p>Will it be best to e... | [
{
"answer_id": 250282,
"author": "Tunji",
"author_id": 54764,
"author_profile": "https://wordpress.stackexchange.com/users/54764",
"pm_score": 4,
"selected": false,
"text": "<p>From the codex <a href=\"https://codex.wordpress.org/AJAX_in_Plugins\"><strong>AJAX in Plugins</strong></a></p>... | 2016/12/24 | [
"https://wordpress.stackexchange.com/questions/250280",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/88606/"
] | Considering regular WordPress ajax requests like these:
```
add_action( 'wp_ajax_merrychristmas_happynewyear', array( $this, 'merrychristmas_happynewyear' ) );
add_action( 'wp_ajax_nopriv_merrychristmas_happynewyear', array( $this, 'merrychristmas_happynewyear' ) );
```
Will it be best to end function `merrychristma... | Using `wp_die()` is the best of those options.
As others have noted, there are many reasons to prefer a WordPress-specific function over the plain `die` or `exit`:
* It allows other plugins to hook into the actions called by `wp_die()`.
* It allows a special handler for exiting to be used based on context (the behavi... |
250,288 | <p>can anyone help me </p>
<pre><code>define('FTP_PUBKEY','/home/use/.ssh/id_rsa');
define('FTP_PRIKEY','/home/user/.ssh/id_rsa');
define('FTP_USER','');
define('FTP_PASS','');
define('FTP_HOST','127.0.0.1:22');
</code></pre>
<p>install at located <code>home/user/wordpress</code></p>
<p>keys located at </p>
<p>gett... | [
{
"answer_id": 250320,
"author": "Tunji",
"author_id": 54764,
"author_profile": "https://wordpress.stackexchange.com/users/54764",
"pm_score": 2,
"selected": false,
"text": "<p>For connection through ssh, you have to specify the ssh user using <code>FTP_USER</code></p>\n\n<pre><code>defi... | 2016/12/24 | [
"https://wordpress.stackexchange.com/questions/250288",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109580/"
] | can anyone help me
```
define('FTP_PUBKEY','/home/use/.ssh/id_rsa');
define('FTP_PRIKEY','/home/user/.ssh/id_rsa');
define('FTP_USER','');
define('FTP_PASS','');
define('FTP_HOST','127.0.0.1:22');
```
install at located `home/user/wordpress`
keys located at
getting incorrect keys
keys permissons 600, 600 folfer... | For connection through ssh, you have to specify the ssh user using `FTP_USER`
```
define( 'FS_METHOD', 'ssh' );
define( 'FTP_BASE', '/home/user/wordpress' );
define( 'FTP_PUBKEY', '/home/user/.ssh/id_rsa.pub' );
define( 'FTP_PRIKEY', '/home/user/.ssh/id_rsa' );
define( 'FTP_USER', 'user' );
define( 'FTP_HOST', 'localh... |
250,304 | <p>Should <code>get_template_directory_uri()</code> be escaped using <code>esc_url()</code>?</p>
<p>I ask because taking an example from the default theme Twenty Fifteen the same function is used in two different places but only in one is it escaped.</p>
<pre><code>wp_enqueue_style( 'twentyfifteen-ie', get_template_d... | [
{
"answer_id": 250311,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 4,
"selected": true,
"text": "<p>In that function we find a hook:</p>\n\n<pre><code>return apply_filters( \n 'template_directory_uri', \n $templa... | 2016/12/24 | [
"https://wordpress.stackexchange.com/questions/250304",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17937/"
] | Should `get_template_directory_uri()` be escaped using `esc_url()`?
I ask because taking an example from the default theme Twenty Fifteen the same function is used in two different places but only in one is it escaped.
```
wp_enqueue_style( 'twentyfifteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twe... | In that function we find a hook:
```
return apply_filters(
'template_directory_uri',
$template_dir_uri,
$template,
$theme_root_uri
);
```
So, yes, the URI can be changed by plugins, and you should escape its returned value.
The same principle applies to all WordPress URI functions, like `get_ho... |
250,308 | <p>I do have an post/page where the shortcode "question" occurs many times.
What is the best way to get an array of all the "question" shortcodes with their related parms?</p>
<pre><code>[question a=1 b=2 c=3 ]
[question b=2 c=3 ]
[question a=1 b=2 ]
[question]
</code></pre>
| [
{
"answer_id": 250312,
"author": "Abhik",
"author_id": 26991,
"author_profile": "https://wordpress.stackexchange.com/users/26991",
"pm_score": 2,
"selected": true,
"text": "<pre><code>function wpse250308_get_questions() {\n global $post;\n if ( preg_match_all('/\\[question(.*?)\\]/... | 2016/12/24 | [
"https://wordpress.stackexchange.com/questions/250308",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109145/"
] | I do have an post/page where the shortcode "question" occurs many times.
What is the best way to get an array of all the "question" shortcodes with their related parms?
```
[question a=1 b=2 c=3 ]
[question b=2 c=3 ]
[question a=1 b=2 ]
[question]
``` | ```
function wpse250308_get_questions() {
global $post;
if ( preg_match_all('/\[question(.*?)\]/', $post->post_content, $questions ) ) {
$questions = array_key_exists( 1 , $questions) ? $questions[1] : array();
// $questions will contain the array of the question shortcodes
//Do your stu... |
250,349 | <p>I tried to remove Menus from WordPress customizer (see image)
<a href="https://i.stack.imgur.com/JwOz6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JwOz6.png" alt="enter image description here"></a></p>
<p>I tried the following code on functions.php file and every section was removed except Me... | [
{
"answer_id": 250356,
"author": "mxUser127",
"author_id": 25525,
"author_profile": "https://wordpress.stackexchange.com/users/25525",
"pm_score": -1,
"selected": false,
"text": "<p>Edit files in admin directory on your server. Even though you may find a plugin for this job. This will he... | 2016/12/25 | [
"https://wordpress.stackexchange.com/questions/250349",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/100679/"
] | I tried to remove Menus from WordPress customizer (see image)
[](https://i.stack.imgur.com/JwOz6.png)
I tried the following code on functions.php file and every section was removed except Menus
```
//Theme customizer
function mytheme_customize_re... | Try **nav\_menus** instead of **menus** with `remove_panel()`
```
function mytheme_customize_register( $wp_customize ) {
//All our sections, settings, and controls will be added here
$wp_customize->remove_section( 'title_tagline');
$wp_customize->remove_section( 'colors');
$wp_customize->remove_section( 'head... |
250,370 | <p>I am building a site using a custom WP theme, and I have been using:</p>
<pre><code><?php include('header-bar.php'); ?>
</code></pre>
<p>in order to include a navigation bar on each page. I intentionally didn't put the navigation in the header.php file because I don't need it on every page.</p>
<p>That bit... | [
{
"answer_id": 250371,
"author": "AddWeb Solution Pvt Ltd",
"author_id": 73643,
"author_profile": "https://wordpress.stackexchange.com/users/73643",
"pm_score": 3,
"selected": true,
"text": "<p>Hello CandyPaintedRIMS,</p>\n<p>Please try <a href=\"https://developer.wordpress.org/reference... | 2016/12/26 | [
"https://wordpress.stackexchange.com/questions/250370",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/101243/"
] | I am building a site using a custom WP theme, and I have been using:
```
<?php include('header-bar.php'); ?>
```
in order to include a navigation bar on each page. I intentionally didn't put the navigation in the header.php file because I don't need it on every page.
That bit of code is working fine in certain pla... | Hello CandyPaintedRIMS,
Please try [get\_template\_part()](https://developer.wordpress.org/reference/functions/get_template_part/) function to include any file into your custom template.
**Your code:**
```
<?php include('header-bar.php'); ?>
```
**It should be replaced with:**
```
<?php get_template_part( 'header... |
250,376 | <p>I'm building a phone numbers directory website. Using <code>wp_insert_post()</code> visitors are allowed to add phone numbers without having to register or log in.
There's a custom post type called "numbers" and phone numbers are stored in custom posts' meta values. Here's the code:</p>
<p><code>$post_id = wp_inser... | [
{
"answer_id": 250380,
"author": "Sofiane Achouba",
"author_id": 92790,
"author_profile": "https://wordpress.stackexchange.com/users/92790",
"pm_score": 1,
"selected": false,
"text": "<p>Hi you can do it like that:</p>\n\n<pre><code>$post_id = wp_insert_post(array (\n 'post_type' ... | 2016/12/26 | [
"https://wordpress.stackexchange.com/questions/250376",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/105471/"
] | I'm building a phone numbers directory website. Using `wp_insert_post()` visitors are allowed to add phone numbers without having to register or log in.
There's a custom post type called "numbers" and phone numbers are stored in custom posts' meta values. Here's the code:
`$post_id = wp_insert_post(array (
'post_type... | Try below code.
```
$args = array(
'fields' => 'ids',
'post_type' => 'numbers',
'meta_query' => array(
array(
'key' => 'number',
'value' => $number
)
)
);
$my_query = new WP_Query( $args );
if( empty($my_query->have_posts()) ) {
$post_id = wp_insert_post(array (
'post_ty... |
250,379 | <p>Im in the midst of customizing WooCommerce checkout, adding a dropdown field which get user's meta keys and show as select option in the checkout page. I also managed to save the selected option after checkout into the order. However, the option is displaying as an integer instead of text in the custom field.</p>
<... | [
{
"answer_id": 250380,
"author": "Sofiane Achouba",
"author_id": 92790,
"author_profile": "https://wordpress.stackexchange.com/users/92790",
"pm_score": 1,
"selected": false,
"text": "<p>Hi you can do it like that:</p>\n\n<pre><code>$post_id = wp_insert_post(array (\n 'post_type' ... | 2016/12/26 | [
"https://wordpress.stackexchange.com/questions/250379",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109645/"
] | Im in the midst of customizing WooCommerce checkout, adding a dropdown field which get user's meta keys and show as select option in the checkout page. I also managed to save the selected option after checkout into the order. However, the option is displaying as an integer instead of text in the custom field.
The foll... | Try below code.
```
$args = array(
'fields' => 'ids',
'post_type' => 'numbers',
'meta_query' => array(
array(
'key' => 'number',
'value' => $number
)
)
);
$my_query = new WP_Query( $args );
if( empty($my_query->have_posts()) ) {
$post_id = wp_insert_post(array (
'post_ty... |
250,403 | <p>Looking to discover how to alter my content.php code to add the thumbnail image of the specific posts to my search results located here for example:</p>
<p><a href="https://divesummit.com/?s=suunto&submit=Search" rel="nofollow noreferrer">https://divesummit.com/?s=suunto&submit=Search</a></p>
<p>I would li... | [
{
"answer_id": 250399,
"author": "Jami Gibbs",
"author_id": 75524,
"author_profile": "https://wordpress.stackexchange.com/users/75524",
"pm_score": 1,
"selected": false,
"text": "<p>It looks like server response time and stylesheet loading are causing the greatest delay:</p>\n\n<p><a hre... | 2016/12/26 | [
"https://wordpress.stackexchange.com/questions/250403",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109668/"
] | Looking to discover how to alter my content.php code to add the thumbnail image of the specific posts to my search results located here for example:
<https://divesummit.com/?s=suunto&submit=Search>
I would like a thumbnail of the featured post’s image listed along with the smaller blurb of the post in the search resu... | It looks like server response time and stylesheet loading are causing the greatest delay:
[](https://i.stack.imgur.com/z0aag.png)
[](https://i.stack.imgur.com/qam7s.png)
You can mea... |
250,427 | <p>So I'm pretty new at Wordpress development, and I'm a little confused by one thing. After going through and finishing my navigation in my header.php file, I went over to my template for the home page I'm working on. My question is: since the "body" tag is the only place you can write that actually shows up in the br... | [
{
"answer_id": 250461,
"author": "Third Essential Designer",
"author_id": 103698,
"author_profile": "https://wordpress.stackexchange.com/users/103698",
"pm_score": 0,
"selected": false,
"text": "<p><a href=\"https://stackoverflow.com/a/2913303/6887487\">This</a> may help you regarding ha... | 2016/12/27 | [
"https://wordpress.stackexchange.com/questions/250427",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108586/"
] | So I'm pretty new at Wordpress development, and I'm a little confused by one thing. After going through and finishing my navigation in my header.php file, I went over to my template for the home page I'm working on. My question is: since the "body" tag is the only place you can write that actually shows up in the brows... | Structure your theme so you start the `<body>` in the header and you close the `</body>` in the footer (same thing for the `<html>` tag):
header.php
```
<html>
...header content
<body> <!--- body is started in the header, used on every page -->
```
index.php, page.php, single.php, home.php - etc
```
...content
... |
250,452 | <p>Here is my custom type post code. I want to add the meta box in there...</p>
<pre><code>function events_cust(){
$label = array(
'name' => _x('Events'),
'singular_name' => _x('events'),
'menu_name' => __('Events'),
'add_new' => __('Add Event'),
... | [
{
"answer_id": 250456,
"author": "AddWeb Solution Pvt Ltd",
"author_id": 73643,
"author_profile": "https://wordpress.stackexchange.com/users/73643",
"pm_score": 1,
"selected": false,
"text": "<p>Try below code.</p>\n\n<pre><code>add_action('add_meta_boxes','create_events_metaboxes'); \nf... | 2016/12/27 | [
"https://wordpress.stackexchange.com/questions/250452",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109713/"
] | Here is my custom type post code. I want to add the meta box in there...
```
function events_cust(){
$label = array(
'name' => _x('Events'),
'singular_name' => _x('events'),
'menu_name' => __('Events'),
'add_new' => __('Add Event'),
'add_new_item' => _... | Try below code.
```
add_action('add_meta_boxes','create_events_metaboxes');
function create_events_metaboxes() {
add_meta_box('events-meta-box','Events Details','show_events_metaboxes','events-lists');
}
function show_events_metaboxes($post){ echo 'Hello Meta box'; }
```
Hope this will helps you.
Refer from [... |
250,478 | <p>After installing wordpress importer from Tools option in wordpress, when I try to activate it, it gives fatal error.</p>
<p><img src="https://i.imgur.com/0Ky3XqU.png" alt="Screenshot"></p>
<p>The relevant php code:</p>
<pre><code>class WXR_Parser {
function parse( $file ) {
// Attempt to use proper XM... | [
{
"answer_id": 250480,
"author": "Jami Gibbs",
"author_id": 75524,
"author_profile": "https://wordpress.stackexchange.com/users/75524",
"pm_score": 3,
"selected": true,
"text": "<p>That error suggests that the <code>WXR_Parser</code> class is already \"running\" or declared. It's possibl... | 2016/12/27 | [
"https://wordpress.stackexchange.com/questions/250478",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/106457/"
] | After installing wordpress importer from Tools option in wordpress, when I try to activate it, it gives fatal error.

The relevant php code:
```
class WXR_Parser {
function parse( $file ) {
// Attempt to use proper XML parsers first
if ( extension_loa... | That error suggests that the `WXR_Parser` class is already "running" or declared. It's possible that a theme or another plugin has incorporated that class and did not check if it existed already before initializing. ie. `if ( ! class_exists( 'WXR_Parser' ) )`.
To locate the source of the conflict, deactivate each *the... |
250,485 | <p>In order to use HTML5 markup for the comment forms, I add the following code snippet to <code>functions.php</code>:</p>
<pre><code>add_theme_support( 'html5', array( 'comment-form' ) );
</code></pre>
<p>However, it disables client side validation on form submit and I get redirected to an error page:</p>
<p><a hre... | [
{
"answer_id": 264807,
"author": "Frank P. Walentynowicz",
"author_id": 32851,
"author_profile": "https://wordpress.stackexchange.com/users/32851",
"pm_score": 2,
"selected": false,
"text": "<p>No, it is not a bug. This is how core handles it. If you look into <code>/wp-includes/comment-... | 2016/12/27 | [
"https://wordpress.stackexchange.com/questions/250485",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109650/"
] | In order to use HTML5 markup for the comment forms, I add the following code snippet to `functions.php`:
```
add_theme_support( 'html5', array( 'comment-form' ) );
```
However, it disables client side validation on form submit and I get redirected to an error page:
[` is true. But there are other html elements within comment form, w... |
250,513 | <p>I have a problem. I need to list only 2 roles: customer and shop_manager. 1. How can i do that with this script?</p>
<pre><code>add_action( 'register_form', 'myplugin_register_form' );
function myplugin_register_form() {
global $wp_roles;
echo '<select name="role" class="input">';
foreach ( $wp_... | [
{
"answer_id": 264807,
"author": "Frank P. Walentynowicz",
"author_id": 32851,
"author_profile": "https://wordpress.stackexchange.com/users/32851",
"pm_score": 2,
"selected": false,
"text": "<p>No, it is not a bug. This is how core handles it. If you look into <code>/wp-includes/comment-... | 2016/12/27 | [
"https://wordpress.stackexchange.com/questions/250513",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/109748/"
] | I have a problem. I need to list only 2 roles: customer and shop\_manager. 1. How can i do that with this script?
```
add_action( 'register_form', 'myplugin_register_form' );
function myplugin_register_form() {
global $wp_roles;
echo '<select name="role" class="input">';
foreach ( $wp_roles->roles as $ke... | No, it is not a bug. This is how core handles it. If you look into `/wp-includes/comment-template.php`, you'll notice, that the only difference in `<form>` element, is `novalidate` attribute added, when `current_theme_supports( 'html5', 'comment-form' )` is true. But there are other html elements within comment form, w... |
250,521 | <p>I have an issue reaching my Wordpress login page. <a href="http://www.everydaytherapy.ie/wp-admin" rel="nofollow noreferrer">http://www.everydaytherapy.ie/wp-admin</a>
I am redirected and a drop down menu appears to login in. But not the proper Wordpress login screen (check the URL yourself). I still tried to login ... | [
{
"answer_id": 264807,
"author": "Frank P. Walentynowicz",
"author_id": 32851,
"author_profile": "https://wordpress.stackexchange.com/users/32851",
"pm_score": 2,
"selected": false,
"text": "<p>No, it is not a bug. This is how core handles it. If you look into <code>/wp-includes/comment-... | 2016/12/28 | [
"https://wordpress.stackexchange.com/questions/250521",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/100619/"
] | I have an issue reaching my Wordpress login page. <http://www.everydaytherapy.ie/wp-admin>
I am redirected and a drop down menu appears to login in. But not the proper Wordpress login screen (check the URL yourself). I still tried to login but my details didn't work for it. It would just reset. I have tried deleting th... | No, it is not a bug. This is how core handles it. If you look into `/wp-includes/comment-template.php`, you'll notice, that the only difference in `<form>` element, is `novalidate` attribute added, when `current_theme_supports( 'html5', 'comment-form' )` is true. But there are other html elements within comment form, w... |
250,529 | <p>I've finally figured out how the post loop works (very new to coding), and I'm trying to figure out the best way to add a class to individual posts I'm displaying (title, author, etc when I add all of them) in the following code:</p>
<pre><code> $args = array( 'numberposts' => '5' );
$recent_posts = w... | [
{
"answer_id": 250534,
"author": "jetyet47",
"author_id": 91783,
"author_profile": "https://wordpress.stackexchange.com/users/91783",
"pm_score": 2,
"selected": false,
"text": "<p>Not totally clear what you're asking, but post_class is probably your best bet.</p>\n\n<pre><code><?php p... | 2016/12/28 | [
"https://wordpress.stackexchange.com/questions/250529",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/108586/"
] | I've finally figured out how the post loop works (very new to coding), and I'm trying to figure out the best way to add a class to individual posts I'm displaying (title, author, etc when I add all of them) in the following code:
```
$args = array( 'numberposts' => '5' );
$recent_posts = wp_get_recent_post... | Not totally clear what you're asking, but post\_class is probably your best bet.
```
<?php post_class(); ?>
```
More info: <https://codex.wordpress.org/Function_Reference/post_class> |