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 |
|---|---|---|---|---|---|---|
227,001 | <p>I'm trying to modify the <a href="https://wordpress.org/plugins/gd-mylist/" rel="nofollow">My Wish List plugin</a> so that I can retrieve some custom fields (I'm using the <a href="https://www.advancedcustomfields.com/" rel="nofollow">Advanced Custom Fields plugin</a> to create my custom fields in the admin end).</p... | [
{
"answer_id": 227002,
"author": "Karthikeyani Srijish",
"author_id": 86125,
"author_profile": "https://wordpress.stackexchange.com/users/86125",
"pm_score": 5,
"selected": true,
"text": "<p>No, it is not possible to create third level menu in admin panel. If you look at the definition o... | 2016/05/18 | [
"https://wordpress.stackexchange.com/questions/227001",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/2685/"
] | I'm trying to modify the [My Wish List plugin](https://wordpress.org/plugins/gd-mylist/) so that I can retrieve some custom fields (I'm using the [Advanced Custom Fields plugin](https://www.advancedcustomfields.com/) to create my custom fields in the admin end).
The plugin uses the custom query below to pull out speci... | No, it is not possible to create third level menu in admin panel. If you look at the definition of **add\_submenu\_page**, you need to mention the parent slug name. **For eg:**
```
add_menu_page ( 'Test Menu', 'Test Menu', 'read', 'testmainmenu', '', '' );
add_submenu_page ( 'testmainmenu', 'Test Menu', 'Child1', 'rea... |
227,003 | <p>I have a simple function, which returns the content of a page with the given pageID:</p>
<pre><code>function get_page_content(){
$id = $_REQUEST['id'];
$page_data = get_page($id);
echo apply_filters('the_content', $page_data->post_content);
//echo do_shortcode($page_data -> post_content);... | [
{
"answer_id": 227028,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 1,
"selected": false,
"text": "<p><code>the_content</code> is usually \"executed\" in the context of a loop when all relevant global data i... | 2016/05/18 | [
"https://wordpress.stackexchange.com/questions/227003",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/63609/"
] | I have a simple function, which returns the content of a page with the given pageID:
```
function get_page_content(){
$id = $_REQUEST['id'];
$page_data = get_page($id);
echo apply_filters('the_content', $page_data->post_content);
//echo do_shortcode($page_data -> post_content);
wp_die();
}
add... | Since version 4.9 visual composer added shortcode lazy loading. To use VC shortcodes on AJAX content use this function before printing the content `WPBMap::addAllMappedShortcodes();`. So below code may help you,
```
function get_page_content(){
$id = $_REQUEST['id'];
$page_data = get_page($id);
WPBMap::... |
227,006 | <p>I created page templates that use the page slug, for example, <code>page-contact.php</code>, <code>page-gallery.php</code> etc. or page id, for example, <code>page-2.php</code>, <code>page-11.php</code> etc.</p>
<p>How can I move these templates to a subfolder, for example <code>/mytheme/pages/</code>?</p>
| [
{
"answer_id": 227036,
"author": "Landing on Jupiter",
"author_id": 74534,
"author_profile": "https://wordpress.stackexchange.com/users/74534",
"pm_score": 2,
"selected": false,
"text": "<p>WordPress will recognize template files in /YOUR_THEME/page-templates/: <a href=\"https://develope... | 2016/05/18 | [
"https://wordpress.stackexchange.com/questions/227006",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94295/"
] | I created page templates that use the page slug, for example, `page-contact.php`, `page-gallery.php` etc. or page id, for example, `page-2.php`, `page-11.php` etc.
How can I move these templates to a subfolder, for example `/mytheme/pages/`? | /YOUR\_THEME/page-templates/ will only work for custom page templates assigned on the admin page edit screen, not for page-$slug or page-$id named templates.
The correct filter hook in my view is page\_template, but you don't (I assume!) want to throw out any other possible templates for your pages, not least because ... |
227,007 | <p>I'm having issues with images getting badly compressed when uploaded to my site. It's not an issue with photographs, but is very noticeable for images with solid blocks of colour and text.</p>
<p>I've uploaded a PNG with a solid grey background overlaid with white text, and it's being badly compressed when WordPres... | [
{
"answer_id": 227036,
"author": "Landing on Jupiter",
"author_id": 74534,
"author_profile": "https://wordpress.stackexchange.com/users/74534",
"pm_score": 2,
"selected": false,
"text": "<p>WordPress will recognize template files in /YOUR_THEME/page-templates/: <a href=\"https://develope... | 2016/05/18 | [
"https://wordpress.stackexchange.com/questions/227007",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93875/"
] | I'm having issues with images getting badly compressed when uploaded to my site. It's not an issue with photographs, but is very noticeable for images with solid blocks of colour and text.
I've uploaded a PNG with a solid grey background overlaid with white text, and it's being badly compressed when WordPress resizes ... | /YOUR\_THEME/page-templates/ will only work for custom page templates assigned on the admin page edit screen, not for page-$slug or page-$id named templates.
The correct filter hook in my view is page\_template, but you don't (I assume!) want to throw out any other possible templates for your pages, not least because ... |
227,029 | <p>I'm trying to write a simple permission admin page plugin.
So far I made a page with every role where I can check a certain menu page to be disabled from menu. I simply get <code>global $menu</code> and save to option encoded to JSON array. </p>
<p>Example:</p>
<pre><code> array(2) {
["sub_administrator"]=>... | [
{
"answer_id": 227036,
"author": "Landing on Jupiter",
"author_id": 74534,
"author_profile": "https://wordpress.stackexchange.com/users/74534",
"pm_score": 2,
"selected": false,
"text": "<p>WordPress will recognize template files in /YOUR_THEME/page-templates/: <a href=\"https://develope... | 2016/05/18 | [
"https://wordpress.stackexchange.com/questions/227029",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/87889/"
] | I'm trying to write a simple permission admin page plugin.
So far I made a page with every role where I can check a certain menu page to be disabled from menu. I simply get `global $menu` and save to option encoded to JSON array.
Example:
```
array(2) {
["sub_administrator"]=>
array(11) {
[0]=>
strin... | /YOUR\_THEME/page-templates/ will only work for custom page templates assigned on the admin page edit screen, not for page-$slug or page-$id named templates.
The correct filter hook in my view is page\_template, but you don't (I assume!) want to throw out any other possible templates for your pages, not least because ... |
227,037 | <p>Right now, when I click on a menu item in the wordpress admin menu, the section that that page belongs to is automatically expanded.</p>
<p>For instance, if I click on a link in the Settings section then the whole Settings section is expanded:</p>
<p><a href="https://i.stack.imgur.com/jnYlU.png" rel="nofollow nore... | [
{
"answer_id": 227045,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 1,
"selected": false,
"text": "<p>I see two options here - override the CSS, or remove the \"active\" classes with JavaScript (sadly there i... | 2016/05/18 | [
"https://wordpress.stackexchange.com/questions/227037",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94279/"
] | Right now, when I click on a menu item in the wordpress admin menu, the section that that page belongs to is automatically expanded.
For instance, if I click on a link in the Settings section then the whole Settings section is expanded:
[](https://i.... | I see two options here - override the CSS, or remove the "active" classes with JavaScript (sadly there is no action/filter that we can do this server-side) - I opted for the JS approach, it's cleaner, leaner and meaner:
```
function wpse_227037_remove_menu_classes() {
echo '<script>jQuery( ".wp-has-current-submenu... |
227,038 | <p>I have a fully functional Wordpress site and I want the to create a new separate website that displays the posts from the wordpress site using the Wordpress Rest API.
I understand that typing <a href="http://my-website/wp-json/wp/v2/posts" rel="nofollow">http://my-website/wp-json/wp/v2/posts</a> into a browser shows... | [
{
"answer_id": 227045,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 1,
"selected": false,
"text": "<p>I see two options here - override the CSS, or remove the \"active\" classes with JavaScript (sadly there i... | 2016/05/18 | [
"https://wordpress.stackexchange.com/questions/227038",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93762/"
] | I have a fully functional Wordpress site and I want the to create a new separate website that displays the posts from the wordpress site using the Wordpress Rest API.
I understand that typing <http://my-website/wp-json/wp/v2/posts> into a browser shows me this information but I want to code it into the new separate sit... | I see two options here - override the CSS, or remove the "active" classes with JavaScript (sadly there is no action/filter that we can do this server-side) - I opted for the JS approach, it's cleaner, leaner and meaner:
```
function wpse_227037_remove_menu_classes() {
echo '<script>jQuery( ".wp-has-current-submenu... |
227,059 | <p>I am using Events Manager to control my Events, but Essential Grids to display previews of these events in various places throughout my site. An example of this is <a href="http://staging-dbmax.transitiongraphics.co.uk/events/" rel="nofollow">http://staging-dbmax.transitiongraphics.co.uk/events/</a>.</p>
<p>Essenti... | [
{
"answer_id": 236290,
"author": "Marc",
"author_id": 101209,
"author_profile": "https://wordpress.stackexchange.com/users/101209",
"pm_score": 0,
"selected": false,
"text": "<p>It didn't work for me at first and I found out Essential Grid must have changed something. The shortcodes now ... | 2016/05/18 | [
"https://wordpress.stackexchange.com/questions/227059",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/91013/"
] | I am using Events Manager to control my Events, but Essential Grids to display previews of these events in various places throughout my site. An example of this is <http://staging-dbmax.transitiongraphics.co.uk/events/>.
Essentially I am trying to get Essential Grids to recognise the Date Field of the event and sort t... | After researching this quite a bit I managed to sort the Events Manager events by date in the [Essential Grid plugin](https://www.themepunch.com/portfolio/essential-grid-wordpress-plugin/).
If you started with the solution above, you can delete the added parameters field under source tab of Essential Grids, it's not n... |
227,079 | <p>In the admin section, the commments bubble is on the left side of the toolbar. I know how to remove the bubble. What I can't figure out is how to move it to the right hand side of the toolbar (next to 'Howdy, [username]).</p>
<p>Any ideas?</p>
| [
{
"answer_id": 227082,
"author": "JediTricks007",
"author_id": 49017,
"author_profile": "https://wordpress.stackexchange.com/users/49017",
"pm_score": 1,
"selected": false,
"text": "<p>One way to move it to the very right would be like this:</p>\n\n<pre><code>#wp-admin-bar-comments {\n ... | 2016/05/18 | [
"https://wordpress.stackexchange.com/questions/227079",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94279/"
] | In the admin section, the commments bubble is on the left side of the toolbar. I know how to remove the bubble. What I can't figure out is how to move it to the right hand side of the toolbar (next to 'Howdy, [username]).
Any ideas? | After you have removed the comments bubble, you [add it again](https://codex.wordpress.org/Class_Reference/WP_Admin_Bar/add_node). The trick is that in the `$args` of `add_node` you have to set `parent` to `top-secondary`.
So it will look like this:
```
add_action( 'admin_bar_menu', 'wpse227079_toolbar_link_to_bubble... |
227,115 | <p>I am new to wordpress. I am running wordpress setup on <code>http://localhost/wordpress/</code>. I am facing two problems right now:</p>
<ul>
<li>Only the logged in users can access the site. So, I am trying to redirect the guest from home page to login page using the following code which is somehow isn't working:<... | [
{
"answer_id": 227119,
"author": "Balas",
"author_id": 17849,
"author_profile": "https://wordpress.stackexchange.com/users/17849",
"pm_score": 1,
"selected": false,
"text": "<p>You can use following code to check home page or not:</p>\n\n<pre><code> if(is_home() && !is_use... | 2016/05/19 | [
"https://wordpress.stackexchange.com/questions/227115",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/27751/"
] | I am new to wordpress. I am running wordpress setup on `http://localhost/wordpress/`. I am facing two problems right now:
* Only the logged in users can access the site. So, I am trying to redirect the guest from home page to login page using the following code which is somehow isn't working:
>
> Path: `wp-content/t... | If I understood correctly, you need to check if the user is logged in, if not, redirect it to login page. If the user logs in succesfully, he should be redirected to the page he was trying to see. You can do this by using the `redirect` argument of [`wp_login_url()`](https://codex.wordpress.org/Function_Reference/wp_lo... |
227,124 | <p>In my application user can publish a custom post from front end . And later admin or capable user can update or delete the post . What I want to do , is to determine if that post is seen by admin or capable user from a dashboard . A post meta "is_seen" is attached to my post , by default it is false . I want to mak... | [
{
"answer_id": 227119,
"author": "Balas",
"author_id": 17849,
"author_profile": "https://wordpress.stackexchange.com/users/17849",
"pm_score": 1,
"selected": false,
"text": "<p>You can use following code to check home page or not:</p>\n\n<pre><code> if(is_home() && !is_use... | 2016/05/19 | [
"https://wordpress.stackexchange.com/questions/227124",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/56654/"
] | In my application user can publish a custom post from front end . And later admin or capable user can update or delete the post . What I want to do , is to determine if that post is seen by admin or capable user from a dashboard . A post meta "is\_seen" is attached to my post , by default it is false . I want to make i... | If I understood correctly, you need to check if the user is logged in, if not, redirect it to login page. If the user logs in succesfully, he should be redirected to the page he was trying to see. You can do this by using the `redirect` argument of [`wp_login_url()`](https://codex.wordpress.org/Function_Reference/wp_lo... |
227,136 | <p>I want to show the whole content of every page in feed .I search for it and found some plugin but I could not solve my problem.</p>
<p>I want when I enter <code>http://swissaudio.com/craftsmanship/feed</code> it provides me the page content in feed. How can I do that?</p>
| [
{
"answer_id": 227397,
"author": "Sumit",
"author_id": 32475,
"author_profile": "https://wordpress.stackexchange.com/users/32475",
"pm_score": 4,
"selected": true,
"text": "<p>First set the post type to display on main feed page i.e. <code>/feed</code> using <code>pre_get_posts</code> ho... | 2016/05/19 | [
"https://wordpress.stackexchange.com/questions/227136",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84928/"
] | I want to show the whole content of every page in feed .I search for it and found some plugin but I could not solve my problem.
I want when I enter `http://swissaudio.com/craftsmanship/feed` it provides me the page content in feed. How can I do that? | First set the post type to display on main feed page i.e. `/feed` using `pre_get_posts` hook
```
$q->set('post_type', array('post', 'page'));
```
On individual page WordPress shows comment feed then set it to `false` and display page content in feed.
```
$q->is_comment_feed = false;
```
In feed template WordPress... |
227,144 | <p>I have a custom post type called 'game' with some ACF fields. One of the fields is a Post Object(called review_link) that accepts posts from a category called 'reviews'. One other field is a taxonomy field(called gametags) looking for the post_tag taxonomy of the 'posts' </p>
<p>This is what I am trying to achieve:... | [
{
"answer_id": 227151,
"author": "majick",
"author_id": 76440,
"author_profile": "https://wordpress.stackexchange.com/users/76440",
"pm_score": 2,
"selected": true,
"text": "<p>I don't know if you can get one array to compare to the other directly, but you can create a loop to set up a <... | 2016/05/19 | [
"https://wordpress.stackexchange.com/questions/227144",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3639/"
] | I have a custom post type called 'game' with some ACF fields. One of the fields is a Post Object(called review\_link) that accepts posts from a category called 'reviews'. One other field is a taxonomy field(called gametags) looking for the post\_tag taxonomy of the 'posts'
This is what I am trying to achieve:
1. Whe... | I don't know if you can get one array to compare to the other directly, but you can create a loop to set up a `meta_query` array that will check for each of the IDs within the field separately:
```
$tag_ids = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );
$meta_query = array('relation' => 'OR');
foreach ... |
227,148 | <p>My theme has a lot of templates. Most of them contain messages in the usual way:</p>
<pre><code>echo __('This is the message','mytextdomain')
</code></pre>
<p>This has several disadvantages. For instance, if I want to change the Read More message I have to browse all files to see if it is there. There's a larger r... | [
{
"answer_id": 227149,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": -1,
"selected": false,
"text": "<p>There is an easy way to get around this problem. Store all frontend messages as options of your theme. Let's de... | 2016/05/19 | [
"https://wordpress.stackexchange.com/questions/227148",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/75495/"
] | My theme has a lot of templates. Most of them contain messages in the usual way:
```
echo __('This is the message','mytextdomain')
```
This has several disadvantages. For instance, if I want to change the Read More message I have to browse all files to see if it is there. There's a larger risk of typos and it is mor... | In my opinion you are focusing on a wrong issue in this case.
>
> For instance, if I want to change the Read More message I have to browse all files to see if it is there.
>
>
>
This doesn't indicate localization problem. This indicates *templating* problem.
What if you want to change *markup* of Read More of w... |
227,150 | <p>I'm building a gallery page for a website and want to use the images from post types as background images with lightboxes. The code im using currently is this:</p>
<pre><code><div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<div id="inner-content... | [
{
"answer_id": 227153,
"author": "bagpipper",
"author_id": 80397,
"author_profile": "https://wordpress.stackexchange.com/users/80397",
"pm_score": 1,
"selected": false,
"text": "<p>Well it seems you are using ACF. The you need not echo <code>the_field()</code> only echo <code>get_field('... | 2016/05/19 | [
"https://wordpress.stackexchange.com/questions/227150",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94367/"
] | I'm building a gallery page for a website and want to use the images from post types as background images with lightboxes. The code im using currently is this:
```
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<div id="inner-content" class="wrap cf">
<?... | Well it seems you are using ACF. The you need not echo `the_field()` only echo `get_field('')` |
227,165 | <p>My goal is to get wp_editor working in a simple widget which the admin can use to add text content on an admin options page.</p>
<p>Here we go in wp-admin/widgets.php everything looks sooo good right.
<a href="https://i.stack.imgur.com/NIQYd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NIQYd.p... | [
{
"answer_id": 227153,
"author": "bagpipper",
"author_id": 80397,
"author_profile": "https://wordpress.stackexchange.com/users/80397",
"pm_score": 1,
"selected": false,
"text": "<p>Well it seems you are using ACF. The you need not echo <code>the_field()</code> only echo <code>get_field('... | 2016/05/19 | [
"https://wordpress.stackexchange.com/questions/227165",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/88364/"
] | My goal is to get wp\_editor working in a simple widget which the admin can use to add text content on an admin options page.
Here we go in wp-admin/widgets.php everything looks sooo good right.
[](https://i.stack.imgur.com/NIQYd.png)
When we try to ... | Well it seems you are using ACF. The you need not echo `the_field()` only echo `get_field('')` |
227,205 | <p>I'm attempting to integrate the <code>custom-logo</code> functionality introduced in 4.5 and I'm running into some issues with the Customizer interface.</p>
<p>I'm checking <code>has_custom_logo</code> and, if it's false, I'm providing a text version of the site name and description as a fallback. It works perfectl... | [
{
"answer_id": 230516,
"author": "ngearing",
"author_id": 50184,
"author_profile": "https://wordpress.stackexchange.com/users/50184",
"pm_score": 2,
"selected": true,
"text": "<p>You have it around the wrong way <code>has_custom_logo()</code> will return false if there is no logo.\n<code... | 2016/05/19 | [
"https://wordpress.stackexchange.com/questions/227205",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/26817/"
] | I'm attempting to integrate the `custom-logo` functionality introduced in 4.5 and I'm running into some issues with the Customizer interface.
I'm checking `has_custom_logo` and, if it's false, I'm providing a text version of the site name and description as a fallback. It works perfectly fine when you add a custom log... | You have it around the wrong way `has_custom_logo()` will return false if there is no logo.
`function_exists( 'the_custom_logo' )` however will return true if you are using a version of Wordpress that support this function.
So if you seperate your if statement like below it will work.
```
if( function_exists( 'the_cu... |
227,229 | <p>I have registered custom commands that scaffording some files. These commands don't rely on any wordpress funcionality, basically outputs some files with content (what commands do is irrelevant in this problem, so I won't paste here any code).</p>
<p>Example command: <code>wp make:some file</code></p>
<p>When I ru... | [
{
"answer_id": 230516,
"author": "ngearing",
"author_id": 50184,
"author_profile": "https://wordpress.stackexchange.com/users/50184",
"pm_score": 2,
"selected": true,
"text": "<p>You have it around the wrong way <code>has_custom_logo()</code> will return false if there is no logo.\n<code... | 2016/05/19 | [
"https://wordpress.stackexchange.com/questions/227229",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93299/"
] | I have registered custom commands that scaffording some files. These commands don't rely on any wordpress funcionality, basically outputs some files with content (what commands do is irrelevant in this problem, so I won't paste here any code).
Example command: `wp make:some file`
When I run these command **when Wordp... | You have it around the wrong way `has_custom_logo()` will return false if there is no logo.
`function_exists( 'the_custom_logo' )` however will return true if you are using a version of Wordpress that support this function.
So if you seperate your if statement like below it will work.
```
if( function_exists( 'the_cu... |
227,241 | <p>I would like to load a css file in my Wordpress plugin by php. First I tried file_get_contents:</p>
<pre><code>$stylesheet = file_get_contents(plugins_url('assets/css/fonts.css', __FILE__ ));
</code></pre>
<p>But than I get this error:</p>
<blockquote>
<p>failed to open stream: HTTP request failed! HTTP/1.1 401... | [
{
"answer_id": 227242,
"author": "tehlivi",
"author_id": 54442,
"author_profile": "https://wordpress.stackexchange.com/users/54442",
"pm_score": 1,
"selected": false,
"text": "<p>You should use WordPress's built in function <code>wp_enqueue_style</code> for loading styles. </p>\n\n<pre><... | 2016/05/19 | [
"https://wordpress.stackexchange.com/questions/227241",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/90798/"
] | I would like to load a css file in my Wordpress plugin by php. First I tried file\_get\_contents:
```
$stylesheet = file_get_contents(plugins_url('assets/css/fonts.css', __FILE__ ));
```
But than I get this error:
>
> failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized
>
>
>
I noticed that on... | Looks like I blocked my self out…
I had an .htaccess with password protection running that prevented the script from accessing the file. |
227,244 | <p>I know the main query is fast, since it gets data after parsing the URL and after <code>WP_Query</code> has been instantiated. We are in OO PHP. </p>
<p>But is <code>query_posts</code> really slower than some secondary query that happens in a template for instance with <code>get_posts</code>, or native that you cal... | [
{
"answer_id": 227249,
"author": "Howdy_McGee",
"author_id": 7355,
"author_profile": "https://wordpress.stackexchange.com/users/7355",
"pm_score": 3,
"selected": false,
"text": "<p>You ask:</p>\n\n<blockquote>\n <p>is query_posts really slower than some secondary query...</p>\n</blockqu... | 2016/05/19 | [
"https://wordpress.stackexchange.com/questions/227244",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/88606/"
] | I know the main query is fast, since it gets data after parsing the URL and after `WP_Query` has been instantiated. We are in OO PHP.
But is `query_posts` really slower than some secondary query that happens in a template for instance with `get_posts`, or native that you call with
```
// WP_Query arguments
$args = ... | You ask:
>
> is query\_posts really slower than some secondary query...
>
>
>
The fact is that if you're calling `query_posts()` from a theme then **it already is a secondary query**. WordPress has already queried the database once to get a certain page then it hits your `query_posts()` function and queries the d... |
227,247 | <p>I have a custom loop to display a custom post type '<code>properties</code>' . The idea is to search properties based on different search parameters selected by users. Now the weird problem I am facing is that if the number of the search parameters increases to 7 the WP_Query doesn't return any results at all. </p>
... | [
{
"answer_id": 227249,
"author": "Howdy_McGee",
"author_id": 7355,
"author_profile": "https://wordpress.stackexchange.com/users/7355",
"pm_score": 3,
"selected": false,
"text": "<p>You ask:</p>\n\n<blockquote>\n <p>is query_posts really slower than some secondary query...</p>\n</blockqu... | 2016/05/19 | [
"https://wordpress.stackexchange.com/questions/227247",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/45901/"
] | I have a custom loop to display a custom post type '`properties`' . The idea is to search properties based on different search parameters selected by users. Now the weird problem I am facing is that if the number of the search parameters increases to 7 the WP\_Query doesn't return any results at all.
The properties w... | You ask:
>
> is query\_posts really slower than some secondary query...
>
>
>
The fact is that if you're calling `query_posts()` from a theme then **it already is a secondary query**. WordPress has already queried the database once to get a certain page then it hits your `query_posts()` function and queries the d... |
227,259 | <p>I use a <code><span></code> inside the loop and I would like to get each post format the post is containing as a class in separate <code>spans</code>.</p>
<p>Example: </p>
<p><strong>If</strong> the post format <strong>is video and private</strong>: I would like to render:</p>
<pre><code><span class="for... | [
{
"answer_id": 227249,
"author": "Howdy_McGee",
"author_id": 7355,
"author_profile": "https://wordpress.stackexchange.com/users/7355",
"pm_score": 3,
"selected": false,
"text": "<p>You ask:</p>\n\n<blockquote>\n <p>is query_posts really slower than some secondary query...</p>\n</blockqu... | 2016/05/20 | [
"https://wordpress.stackexchange.com/questions/227259",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/82313/"
] | I use a `<span>` inside the loop and I would like to get each post format the post is containing as a class in separate `spans`.
Example:
**If** the post format **is video and private**: I would like to render:
```
<span class="format-video"></span>
<span class="status-private"></span>
```
So far I have tried `<s... | You ask:
>
> is query\_posts really slower than some secondary query...
>
>
>
The fact is that if you're calling `query_posts()` from a theme then **it already is a secondary query**. WordPress has already queried the database once to get a certain page then it hits your `query_posts()` function and queries the d... |
227,301 | <p>I have updated my site manually, now I get below mentioned notice in the front and backend:</p>
<blockquote>
<p>Notice: register_sidebar was called incorrectly. No id was set in the
arguments array for the "Main Sidebar" sidebar. Defaulting to
"sidebar-1". Manually set the id to "sidebar-1&q... | [
{
"answer_id": 227303,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 1,
"selected": false,
"text": "<p>Looks like you have a very old theme. You'll have to search the <code>functions.php</code> file for <code>regist... | 2016/05/20 | [
"https://wordpress.stackexchange.com/questions/227301",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94426/"
] | I have updated my site manually, now I get below mentioned notice in the front and backend:
>
> Notice: register\_sidebar was called incorrectly. No id was set in the
> arguments array for the "Main Sidebar" sidebar. Defaulting to
> "sidebar-1". Manually set the id to "sidebar-1" to silence this notice
> and keep exi... | 1. Find file where is `register_sidebar` ( must be on theme folder or plugins )
2. add ID to sidebar
```
register_sidebar( array(
'name' => __( 'Main Sidebar', 'theme-slug' ),
'id' => 'change_me', // Add only this line
'description' => __( 'Widgets in this area will be shown on all posts and pages.', 'them... |
227,307 | <p>I have a custom post type with the fields <code>Exercise</code> and <code>Tempo</code>. Here is an example of how that might look:</p>
<p>Exercise 1 - 100<br>
Exercise 2 - 104<br>
Exercise 3 - 96<br>
Exercise 1 - 104<br>
Exercise 2 - 110<br>
Exercise 3 - 100 </p>
<p>How might I use WP_Query to return only the hig... | [
{
"answer_id": 227303,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 1,
"selected": false,
"text": "<p>Looks like you have a very old theme. You'll have to search the <code>functions.php</code> file for <code>regist... | 2016/05/20 | [
"https://wordpress.stackexchange.com/questions/227307",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93811/"
] | I have a custom post type with the fields `Exercise` and `Tempo`. Here is an example of how that might look:
Exercise 1 - 100
Exercise 2 - 104
Exercise 3 - 96
Exercise 1 - 104
Exercise 2 - 110
Exercise 3 - 100
How might I use WP\_Query to return only the highest `Tempo` of each `Exercise`?
The desire... | 1. Find file where is `register_sidebar` ( must be on theme folder or plugins )
2. add ID to sidebar
```
register_sidebar( array(
'name' => __( 'Main Sidebar', 'theme-slug' ),
'id' => 'change_me', // Add only this line
'description' => __( 'Widgets in this area will be shown on all posts and pages.', 'them... |
227,315 | <p>Facebook's Instant Articles rejects articles that contain hyperlinks to the current page (e.g. <code><a href="#_ftn1">[1]</a></code>). How can I filter the post content to remove these links before publishing to Facebook Instant Articles?</p>
<p>I'm aware of a similar question on StackOverflow: <a href=... | [
{
"answer_id": 227303,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 1,
"selected": false,
"text": "<p>Looks like you have a very old theme. You'll have to search the <code>functions.php</code> file for <code>regist... | 2016/05/20 | [
"https://wordpress.stackexchange.com/questions/227315",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/19528/"
] | Facebook's Instant Articles rejects articles that contain hyperlinks to the current page (e.g. `<a href="#_ftn1">[1]</a>`). How can I filter the post content to remove these links before publishing to Facebook Instant Articles?
I'm aware of a similar question on StackOverflow: [How to remove hyperlink of images in wor... | 1. Find file where is `register_sidebar` ( must be on theme folder or plugins )
2. add ID to sidebar
```
register_sidebar( array(
'name' => __( 'Main Sidebar', 'theme-slug' ),
'id' => 'change_me', // Add only this line
'description' => __( 'Widgets in this area will be shown on all posts and pages.', 'them... |
227,360 | <p>I feel there is a red button saying "Do not press" below <code>query_posts()</code>. For some time I am trying to demystify this phenomena with very low success to be honest. </p>
<p>For example, probable the main reason not to use this function is a broken pagination. Second, was it may be slow (read: calling twic... | [
{
"answer_id": 227362,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 3,
"selected": false,
"text": "<p><code>query_posts()</code> is useful in cases when there is <strong>no main query</strong>: calls to <code>wp-admin/a... | 2016/05/20 | [
"https://wordpress.stackexchange.com/questions/227360",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/88606/"
] | I feel there is a red button saying "Do not press" below `query_posts()`. For some time I am trying to demystify this phenomena with very low success to be honest.
For example, probable the main reason not to use this function is a broken pagination. Second, was it may be slow (read: calling twice), or there are bett... | Opposite from the common believes `query_posts` is harmless if you know how to use it. I tried [here](https://wordpress.stackexchange.com/questions/226960/why-query-posts-isnt-marked-as-deprecated/248955#248955) to provide more arguments.
In here I will add a simple outline that you never should rely on:
`$GLOBALS['wp... |
227,404 | <p>I have a custom post type in my plugin "Luckydraw" as 'voucher'. </p>
<p>By clicking on post link, wordpress generates its URL as :</p>
<pre><code>http://localhost:81/luckydraw/index.php/voucher/testing-2/
</code></pre>
<p>But I want to change it to:</p>
<pre><code>http://localhost:81/luckydraw/voucher/testing-2... | [
{
"answer_id": 227405,
"author": "Mukesh Ram",
"author_id": 93667,
"author_profile": "https://wordpress.stackexchange.com/users/93667",
"pm_score": -1,
"selected": false,
"text": "<p>Change or add the \n<code>'rewrite' => array( 'slug' => 'luckydraw', 'with_front' => false ),</... | 2016/05/21 | [
"https://wordpress.stackexchange.com/questions/227404",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/91044/"
] | I have a custom post type in my plugin "Luckydraw" as 'voucher'.
By clicking on post link, wordpress generates its URL as :
```
http://localhost:81/luckydraw/index.php/voucher/testing-2/
```
But I want to change it to:
```
http://localhost:81/luckydraw/voucher/testing-2/
```
How would I do this? | I am not sure I follow your question, title seems different from question itself.
You seem to want to get rid of `index.php` in URL?
It's hard to say confidently from outside, but it looks like [PATHINFO permalink](https://codex.wordpress.org/Using_Permalinks#PATHINFO:_.22Almost_Pretty.22).
If that's the case you wo... |
227,417 | <p>So, I'm building a theme for a client with one page layout functionality. Currently, I'm allowing the user to create a parent page, and the modules within that page are separate pages that will be set as children of the main page. </p>
<p>Clarifying. I have a home page. Within the home page, I need to have a sectio... | [
{
"answer_id": 227446,
"author": "Tim Malone",
"author_id": 46066,
"author_profile": "https://wordpress.stackexchange.com/users/46066",
"pm_score": 0,
"selected": false,
"text": "<p>The question you linked to doesn't <em>quite</em> do what you're wanting - it allows you to get the templa... | 2016/05/21 | [
"https://wordpress.stackexchange.com/questions/227417",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/83015/"
] | So, I'm building a theme for a client with one page layout functionality. Currently, I'm allowing the user to create a parent page, and the modules within that page are separate pages that will be set as children of the main page.
Clarifying. I have a home page. Within the home page, I need to have a section to displ... | I was able to figure this out and make it dynamic.
I created a variable `$template` that I put inside the loop, in which I stored the page template.
`$template = get_post_meta( $post->ID, '_wp_page_template', true );`
Then, I utilize this where I need the child pages to show up.
`<?php include(locate_template($temp... |
227,430 | <p>I want to make a menu with hover animations. My HTML syntax looks like this:</p>
<pre><code><ul class="menus">
<li class="current"><a href="#" data-hover="Home">Home</a></li>
<li><a href="#" data-hover="About Us">About Us</a></li>
<li><a href="#" ... | [
{
"answer_id": 227434,
"author": "Alex",
"author_id": 94487,
"author_profile": "https://wordpress.stackexchange.com/users/94487",
"pm_score": 2,
"selected": false,
"text": "<p>If you want WordPress to add these items dynamically you would need to add a custom walker class to your menu de... | 2016/05/22 | [
"https://wordpress.stackexchange.com/questions/227430",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16755/"
] | I want to make a menu with hover animations. My HTML syntax looks like this:
```
<ul class="menus">
<li class="current"><a href="#" data-hover="Home">Home</a></li>
<li><a href="#" data-hover="About Us">About Us</a></li>
<li><a href="#" data-hover="Blog">Blog</a></li>
<li><a href="#" data-hover="Services">Servi... | I found one small and nice solution.
```
add_filter( 'nav_menu_link_attributes', 'cfw_add_data_atts_to_nav', 10, 4 );
function cfw_add_data_atts_to_nav( $atts, $item, $args )
{
$atts['data-hover'] = $item->title;
return $atts;
}
```
I tested it and it works. |
227,435 | <p>I'm wondering if it is at all possible to set display a page template chosen by the user within the context of a <code>query_posts</code> using <code>get_template_part</code>. In other words, I have set up a page template to pull all of it's child pages and display them, but I need each child page to display accordi... | [
{
"answer_id": 227434,
"author": "Alex",
"author_id": 94487,
"author_profile": "https://wordpress.stackexchange.com/users/94487",
"pm_score": 2,
"selected": false,
"text": "<p>If you want WordPress to add these items dynamically you would need to add a custom walker class to your menu de... | 2016/05/22 | [
"https://wordpress.stackexchange.com/questions/227435",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/83015/"
] | I'm wondering if it is at all possible to set display a page template chosen by the user within the context of a `query_posts` using `get_template_part`. In other words, I have set up a page template to pull all of it's child pages and display them, but I need each child page to display according to the page template t... | I found one small and nice solution.
```
add_filter( 'nav_menu_link_attributes', 'cfw_add_data_atts_to_nav', 10, 4 );
function cfw_add_data_atts_to_nav( $atts, $item, $args )
{
$atts['data-hover'] = $item->title;
return $atts;
}
```
I tested it and it works. |
227,444 | <p>I have added a new field (time_last_seen) in my plugin (v1.1) table then uploaded my plugin as version 1.2 to wordpress svn repository.
When I update my plugin from admin panel, it is not creating the field (time_last_seen) in the table.</p>
<p>Here is what I have tried:</p>
<pre><code>function ulh_add_user_login... | [
{
"answer_id": 227449,
"author": "Tim Malone",
"author_id": 46066,
"author_profile": "https://wordpress.stackexchange.com/users/46066",
"pm_score": 3,
"selected": true,
"text": "<p><code>register_activation_hook()</code> only attaches a function to run on <em>activation</em> of your plug... | 2016/05/22 | [
"https://wordpress.stackexchange.com/questions/227444",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/85769/"
] | I have added a new field (time\_last\_seen) in my plugin (v1.1) table then uploaded my plugin as version 1.2 to wordpress svn repository.
When I update my plugin from admin panel, it is not creating the field (time\_last\_seen) in the table.
Here is what I have tried:
```
function ulh_add_user_logins_table() {
gl... | `register_activation_hook()` only attaches a function to run on *activation* of your plugin, not on updating. See [the docs](https://codex.wordpress.org/Function_Reference/register_activation_hook) for full details, particularly this part:
>
> 3.1 : This hook is now fired only when the user activates the plugin and n... |
227,464 | <p>Since Wordpress <a href="https://codex.wordpress.org/Sticky_Posts" rel="nofollow">sticky posts</a> feature allow the post checked as <em>sticky</em> in post publish panel to be placed at the top of the front page of posts. I was also intended to style the sticky post differently than normal ones within the loop by c... | [
{
"answer_id": 227466,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 1,
"selected": false,
"text": "<p>You'll have to move the part that says <code>$do_not_duplicate = $post->ID;</code> to the conditional stateme... | 2016/05/22 | [
"https://wordpress.stackexchange.com/questions/227464",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | Since Wordpress [sticky posts](https://codex.wordpress.org/Sticky_Posts) feature allow the post checked as *sticky* in post publish panel to be placed at the top of the front page of posts. I was also intended to style the sticky post differently than normal ones within the loop by customizing [The Loop](https://codex.... | You simply need the [`is_sticky()`](https://developer.wordpress.org/reference/functions/is_sticky/) conditional check and then act on that. You would probably still need the `is_home()` and `!is_paged()` conditional check to only target stikies on the first page of the home page
```
if ( have_posts() ) :
while ( h... |
227,482 | <p>In a lot of how to create a custom meta box tutorials, when saving data, i.e., update_post_meta the data is escaped:</p>
<pre><code>update_post_meta( $post_id, 'city', esc_attr( ucwords( $_POST['city'] ) ) );
</code></pre>
<p>Some tutorials do not esc when saving and do it on screen output.</p>
<p>However, escap... | [
{
"answer_id": 227483,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 3,
"selected": true,
"text": "<p>Yes it does. Escaping depends on context and in worst case like using <code>esc_html</code> when writing d... | 2016/05/22 | [
"https://wordpress.stackexchange.com/questions/227482",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/16641/"
] | In a lot of how to create a custom meta box tutorials, when saving data, i.e., update\_post\_meta the data is escaped:
```
update_post_meta( $post_id, 'city', esc_attr( ucwords( $_POST['city'] ) ) );
```
Some tutorials do not esc when saving and do it on screen output.
However, escaping protects the output to the ... | Yes it does. Escaping depends on context and in worst case like using `esc_html` when writing directly to the DB are just a security hole.
Even if there is no security issue, there is theoretical one. The user asked you to store A, and you are storing B. In a simple cases B is exactly how A should be displayed in the ... |
227,506 | <p>I am trying to create a REST APIs for my wordpress website which is used for facility listing using wordpress job manager plugin. </p>
<p>I have registered my custom post , taxonomies in \plugins\rest-api\plugin.php.</p>
<p>below API gives me all the listings with default response. </p>
<p><a href="http://localho... | [
{
"answer_id": 227515,
"author": "wpclevel",
"author_id": 92212,
"author_profile": "https://wordpress.stackexchange.com/users/92212",
"pm_score": 4,
"selected": true,
"text": "<p><code>$post</code> in the <a href=\"http://v2.wp-api.org/extending/modifying/#examples\" rel=\"noreferrer\">c... | 2016/05/23 | [
"https://wordpress.stackexchange.com/questions/227506",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94106/"
] | I am trying to create a REST APIs for my wordpress website which is used for facility listing using wordpress job manager plugin.
I have registered my custom post , taxonomies in \plugins\rest-api\plugin.php.
below API gives me all the listings with default response.
<http://localhost/sports/wp-json/wp/v2/joblisti... | `$post` in the [callback function](http://v2.wp-api.org/extending/modifying/#examples) is an array, not an object. So you cannot use `$post->id`. Change it to `$post['id']` and it should work:
```
function slug_get_phone_number($post, $field_name, $request)
{
return get_post_meta($post['id'], '_phone', true);
}
`... |
227,532 | <p>I got stuck with some modifications and maybe someone could give me some help. </p>
<p><strong>What am I doing</strong></p>
<p>I use the multiple theme plugin to switch themes for my WordPress project. To switch between the themes a URL Parameter is added <strong><code>www.mydomain/?parameter=XYZ</code></strong>.... | [
{
"answer_id": 227561,
"author": "majick",
"author_id": 76440,
"author_profile": "https://wordpress.stackexchange.com/users/76440",
"pm_score": 1,
"selected": false,
"text": "<p>You can set the <code>$_GET</code> global internally. By saving the parameter passed as user meta and/or a coo... | 2016/05/23 | [
"https://wordpress.stackexchange.com/questions/227532",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94531/"
] | I got stuck with some modifications and maybe someone could give me some help.
**What am I doing**
I use the multiple theme plugin to switch themes for my WordPress project. To switch between the themes a URL Parameter is added **`www.mydomain/?parameter=XYZ`**. So far everything works great.
**Where is the issue*... | You can set the `$_GET` global internally. By saving the parameter passed as user meta and/or a cookie and retrieving it later. This would probably have to be put in your `/wp-content/mu-plugins/` folder to work properly (so it is loaded early):
```
<?php
$parameter = 'theme'; // default for theme test drive
... |
227,542 | <p>I am using the following code to show next/previous posts in my wordpress theme.</p>
<pre><code><?php
previous_post_link('<span class="left">&larr; %link</span>');
next_post_link('<span class="right">%link &rarr;</span>'); ?>
</code></pre>
<p>It's working but I want to limit ... | [
{
"answer_id": 227565,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 0,
"selected": false,
"text": "<p>Both of these should trickle down to <code>get_adjacent_post_link()</code> function, which passes result through dy... | 2016/05/23 | [
"https://wordpress.stackexchange.com/questions/227542",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94072/"
] | I am using the following code to show next/previous posts in my wordpress theme.
```
<?php
previous_post_link('<span class="left">← %link</span>');
next_post_link('<span class="right">%link →</span>'); ?>
```
It's working but I want to limit the post title which is displayed in the link to a specific leng... | Here's a little coding that should implement this for you:
```
<?php $max_length = 5; // set max character length here
$next = get_next_post()->ID;
$prev = get_previous_post()->ID;
if( $prev ) {
$title = get_the_title( $prev );
$link = get_the_permalink( $prev );
$post_name = mb_strlen( $title ) > $max_l... |
227,545 | <p>This one should be easy, but I can't figure it out.
I want to send an email that is HTML formatted, but also has an attachment. The attachment is being sent correctly, but the message is delivered as plaintext, like this: </p>
<pre><code><p>Hello!</p>
<p>&nbsp;</p>
<p>Some text.<... | [
{
"answer_id": 227552,
"author": "flero",
"author_id": 13970,
"author_profile": "https://wordpress.stackexchange.com/users/13970",
"pm_score": 0,
"selected": false,
"text": "<p>as stated in the <a href=\"https://developer.wordpress.org/reference/functions/wp_mail/\" rel=\"nofollow\">link... | 2016/05/23 | [
"https://wordpress.stackexchange.com/questions/227545",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/41165/"
] | This one should be easy, but I can't figure it out.
I want to send an email that is HTML formatted, but also has an attachment. The attachment is being sent correctly, but the message is delivered as plaintext, like this:
```
<p>Hello!</p>
<p> </p>
<p>Some text.</p>
<p> </p>
<p>Best wishes,</p>
<p>Team</p>
... | Reference link [click here](https://developer.wordpress.org/reference/functions/wp_mail/).
Using below code you can send the mail with html format.
```
$to = 'sendto@example.com';
$subject = 'The subject';
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail( $to, $su... |
227,591 | <p>I have a Custom Post Type like</p>
<pre><code>function cpt_Projects() {
$labels = array(
'name' => 'Projects',
'singular_name' => 'Project',
'menu_name' => 'Projects',
'name_admin_bar' => 'Projects',
'parent_item_colon' ... | [
{
"answer_id": 227606,
"author": "vancoder",
"author_id": 26778,
"author_profile": "https://wordpress.stackexchange.com/users/26778",
"pm_score": 2,
"selected": false,
"text": "<p>Post type names cannot contain capital letters. So behind the scenes, your CPT is probably called projectscp... | 2016/05/23 | [
"https://wordpress.stackexchange.com/questions/227591",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/31793/"
] | I have a Custom Post Type like
```
function cpt_Projects() {
$labels = array(
'name' => 'Projects',
'singular_name' => 'Project',
'menu_name' => 'Projects',
'name_admin_bar' => 'Projects',
'parent_item_colon' => 'Parent Projects:',
... | Post type names cannot contain capital letters. So behind the scenes, your CPT is probably called projectscpt rather than ProjectsCPT - hence it not matching the value in your array. |
227,593 | <p>I have installed Visual Composer for a client and am now trying to remove the tab from the Dashboard menu. How can I do this?</p>
<p><a href="https://i.stack.imgur.com/FN3by.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/FN3by.jpg" alt="Remove Visual Composer tab from Dashboard menu"></a></p>
<pre><code... | [
{
"answer_id": 227601,
"author": "cpcdev",
"author_id": 93195,
"author_profile": "https://wordpress.stackexchange.com/users/93195",
"pm_score": 1,
"selected": false,
"text": "<p>I solved this by installing the <a href=\"https://wordpress.org/plugins/admin-menu-editor/\" rel=\"nofollow\">... | 2016/05/23 | [
"https://wordpress.stackexchange.com/questions/227593",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93195/"
] | I have installed Visual Composer for a client and am now trying to remove the tab from the Dashboard menu. How can I do this?
[](https://i.stack.imgur.com/FN3by.jpg)
```
function remove_menus(){
remove_menu_page( ‘js_composer.p... | It is not easy to find it out, but it is pretty easy if you know how.
Add this following code to your themes `functions.php`.
```
function custom_menu_page_removing() {
remove_menu_page('vc-welcome'); //vc
}
add_action( 'admin_init', 'custom_menu_page_removing' );
```
(Previously been `admin_menu`, now is `admi... |
227,604 | <p>I'm running a VPS with <code>Ubuntu 14.04.4 x64</code> and Apache <code>2.4.7</code>, and would like to set-up a WordPress site on it. Which apache-modules <em>must</em> I have enabled - and which <em>should</em> I enable (eg. for cool WP-features)? Are there any modules I absolutely should <em>not</em> enable?</p... | [
{
"answer_id": 227605,
"author": "Nefro",
"author_id": 86801,
"author_profile": "https://wordpress.stackexchange.com/users/86801",
"pm_score": 4,
"selected": true,
"text": "<p>Here is the list of minimum Apache modules which is required to run WordPress websites.</p>\n\n<pre><code>mod_al... | 2016/05/23 | [
"https://wordpress.stackexchange.com/questions/227604",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/31032/"
] | I'm running a VPS with `Ubuntu 14.04.4 x64` and Apache `2.4.7`, and would like to set-up a WordPress site on it. Which apache-modules *must* I have enabled - and which *should* I enable (eg. for cool WP-features)? Are there any modules I absolutely should *not* enable? | Here is the list of minimum Apache modules which is required to run WordPress websites.
```
mod_alias
mod_authz_host
mod_deflate
mod_dir
mod_expires
mod_headers
mod_mime
mod_rewrite
mod_log_config
mod_autoindex
mod_negotiation
mod_setenvif
``` |
227,608 | <p>I'm running a VPS with Ubuntu. I've installed the LAMP-stack, and would now like to make a couple of blogs/sites using WordPress. I'm thinking about creating new users for each blog and making a <code>public_html</code> directory for each user. This way each blog could be reached with <code>http://mysite/~some_bl... | [
{
"answer_id": 227605,
"author": "Nefro",
"author_id": 86801,
"author_profile": "https://wordpress.stackexchange.com/users/86801",
"pm_score": 4,
"selected": true,
"text": "<p>Here is the list of minimum Apache modules which is required to run WordPress websites.</p>\n\n<pre><code>mod_al... | 2016/05/23 | [
"https://wordpress.stackexchange.com/questions/227608",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/31032/"
] | I'm running a VPS with Ubuntu. I've installed the LAMP-stack, and would now like to make a couple of blogs/sites using WordPress. I'm thinking about creating new users for each blog and making a `public_html` directory for each user. This way each blog could be reached with `http://mysite/~some_blog`.
Space is howeve... | Here is the list of minimum Apache modules which is required to run WordPress websites.
```
mod_alias
mod_authz_host
mod_deflate
mod_dir
mod_expires
mod_headers
mod_mime
mod_rewrite
mod_log_config
mod_autoindex
mod_negotiation
mod_setenvif
``` |
227,620 | <p>Been hitting my head against the wall on this for a while. If I have a add_rewrite_rules like so:</p>
<pre><code> $aNewRules = array('my-books/?$' => 'index.php?pagename=my-books');
</code></pre>
<p>This works correctly; going to <a href="http://example.com/my-books/" rel="nofollow">http://example.com/my-b... | [
{
"answer_id": 261357,
"author": "Joshua Ostrom",
"author_id": 116227,
"author_profile": "https://wordpress.stackexchange.com/users/116227",
"pm_score": -1,
"selected": false,
"text": "<p>Not directly. The wordpress API is using preg_match / preg_replace but is not exposing the flags pa... | 2016/05/23 | [
"https://wordpress.stackexchange.com/questions/227620",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/11654/"
] | Been hitting my head against the wall on this for a while. If I have a add\_rewrite\_rules like so:
```
$aNewRules = array('my-books/?$' => 'index.php?pagename=my-books');
```
This works correctly; going to <http://example.com/my-books/> shows <http://example.com/index.php?pagename=my-books>.
However, this is ... | As the answer below mentions, it is not possible to pass a flag to `add_rewrite_rule()`; however, it *is* possible to use an inline modifier. In your example, you would do this:
`$aNewRules = array('(?i)my-books/?$' => 'index.php?pagename=my-books');`
(note the `(?i)` in the regular expression).
The advantage of thi... |
227,642 | <p>I am creating an RSS feed. I have created a table in my database with 400 post id's. I have the rss feed coded I am now trying to link the two so my RSS feed runs only for the list of 400 posts from my table. </p>
<p>On my RSS feed page I can create an array by using a couple of id's (see below)</p>
<pre><code>$m... | [
{
"answer_id": 227647,
"author": "Sumit",
"author_id": 32475,
"author_profile": "https://wordpress.stackexchange.com/users/32475",
"pm_score": 1,
"selected": false,
"text": "<p><code>post__in</code> accept array of post IDs e.g. <code>array(5, 4, 8, 9);</code></p>\n\n<p>Extending @bravok... | 2016/05/24 | [
"https://wordpress.stackexchange.com/questions/227642",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94581/"
] | I am creating an RSS feed. I have created a table in my database with 400 post id's. I have the rss feed coded I am now trying to link the two so my RSS feed runs only for the list of 400 posts from my table.
On my RSS feed page I can create an array by using a couple of id's (see below)
```
$myarray2 = array(12345,... | `post__in` accept array of post IDs e.g. `array(5, 4, 8, 9);`
Extending @bravokeyl comment. By default result is Object. As codex suggest you can change the output type of [`get_results()`](https://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results) to these values.
>
> * OBJECT - result will be output ... |
227,660 | <p>I realize that this question is being asked in a very generic fashion, without detailed specifics of the configuration in question, and thus I am not expecting answers that go beyond anything but <em>general</em> guidance.</p>
<p>With that, given a WordPress site that is:</p>
<ul>
<li><p>based on a typical "heavy"... | [
{
"answer_id": 227647,
"author": "Sumit",
"author_id": 32475,
"author_profile": "https://wordpress.stackexchange.com/users/32475",
"pm_score": 1,
"selected": false,
"text": "<p><code>post__in</code> accept array of post IDs e.g. <code>array(5, 4, 8, 9);</code></p>\n\n<p>Extending @bravok... | 2016/05/24 | [
"https://wordpress.stackexchange.com/questions/227660",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/54948/"
] | I realize that this question is being asked in a very generic fashion, without detailed specifics of the configuration in question, and thus I am not expecting answers that go beyond anything but *general* guidance.
With that, given a WordPress site that is:
* based on a typical "heavy" ("kitchen-sink included") them... | `post__in` accept array of post IDs e.g. `array(5, 4, 8, 9);`
Extending @bravokeyl comment. By default result is Object. As codex suggest you can change the output type of [`get_results()`](https://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results) to these values.
>
> * OBJECT - result will be output ... |
227,667 | <p>I have a custom post type called blogs (blog URL is saved as custom field). There are nearly 250 blog custom post types. When a custom post type (blogs) load I use <code>fetch_feed()</code> to get the recent posts of that blog.</p>
<p>Now my site is on localhost. One of my My friend said I can't host this site on s... | [
{
"answer_id": 227647,
"author": "Sumit",
"author_id": 32475,
"author_profile": "https://wordpress.stackexchange.com/users/32475",
"pm_score": 1,
"selected": false,
"text": "<p><code>post__in</code> accept array of post IDs e.g. <code>array(5, 4, 8, 9);</code></p>\n\n<p>Extending @bravok... | 2016/05/24 | [
"https://wordpress.stackexchange.com/questions/227667",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94595/"
] | I have a custom post type called blogs (blog URL is saved as custom field). There are nearly 250 blog custom post types. When a custom post type (blogs) load I use `fetch_feed()` to get the recent posts of that blog.
Now my site is on localhost. One of my My friend said I can't host this site on shared hosting because... | `post__in` accept array of post IDs e.g. `array(5, 4, 8, 9);`
Extending @bravokeyl comment. By default result is Object. As codex suggest you can change the output type of [`get_results()`](https://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results) to these values.
>
> * OBJECT - result will be output ... |
227,707 | <p>I'm looking for some advice on how to make a gallery of images.
it is a particular bit a gallery, because I would show the last 5 post and a fixed post, for a total of 6 posts, in a specific order. ie the fixed post must be the third in the list.
The only method that I believe it is possible to create 3 loops, the f... | [
{
"answer_id": 227708,
"author": "AntonChanning",
"author_id": 5077,
"author_profile": "https://wordpress.stackexchange.com/users/5077",
"pm_score": 0,
"selected": false,
"text": "<p>One way would be to use the built in counter to tell how many times you've been through the loop, then us... | 2016/05/24 | [
"https://wordpress.stackexchange.com/questions/227707",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/71371/"
] | I'm looking for some advice on how to make a gallery of images.
it is a particular bit a gallery, because I would show the last 5 post and a fixed post, for a total of 6 posts, in a specific order. ie the fixed post must be the third in the list.
The only method that I believe it is possible to create 3 loops, the firs... | I cannot think of a way of getting the latest 5 posts plus a specific one in a single query without using SQL.
If you don't mind using two queries, I think this would be an easy way to do what you intend:
```
//Get the latest 5 posts (which happens to be get_posts default 'posts_per_page' value)
$posts = get_posts();... |
227,714 | <p>I'm digging out on old question as no solution came out.
<a href="https://wordpress.stackexchange.com/questions/190634/how-to-limit-page-pagination">How to limit page pagination</a></p>
<p>I'm looking for a way to limit pages on homepage and categories (archive.php).
I have around 200k posts spread into about 50 ca... | [
{
"answer_id": 227730,
"author": "Antony Gibbs",
"author_id": 93359,
"author_profile": "https://wordpress.stackexchange.com/users/93359",
"pm_score": 1,
"selected": false,
"text": "<p>I was lucky, the theme used it's own function, so it was easy to override.\nInspired by worpdress native... | 2016/05/24 | [
"https://wordpress.stackexchange.com/questions/227714",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93359/"
] | I'm digging out on old question as no solution came out.
[How to limit page pagination](https://wordpress.stackexchange.com/questions/190634/how-to-limit-page-pagination)
I'm looking for a way to limit pages on homepage and categories (archive.php).
I have around 200k posts spread into about 50 categories.
If I leave ... | I was lucky, the theme used it's own function, so it was easy to override.
Inspired by worpdress native get\_the\_posts\_navigation (wp-includes/link-template.php) here is what I end up using:
```
function my_get_the_posts_navigation( $args = array() ) {
$limit = 5;
$navigation = '';
// Don't print empty ... |
227,724 | <p>I am working on adding some functionality on a Wordpress plugin which after a certain click needs to call on some shortcode through ajax.</p>
<p>What I first attempted was to call the shortcode inside of the ajax processing in my functions.php file:</p>
<pre><code>add_action( 'wp_ajax_nopriv_showads', 'showads' );... | [
{
"answer_id": 227730,
"author": "Antony Gibbs",
"author_id": 93359,
"author_profile": "https://wordpress.stackexchange.com/users/93359",
"pm_score": 1,
"selected": false,
"text": "<p>I was lucky, the theme used it's own function, so it was easy to override.\nInspired by worpdress native... | 2016/05/24 | [
"https://wordpress.stackexchange.com/questions/227724",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/40956/"
] | I am working on adding some functionality on a Wordpress plugin which after a certain click needs to call on some shortcode through ajax.
What I first attempted was to call the shortcode inside of the ajax processing in my functions.php file:
```
add_action( 'wp_ajax_nopriv_showads', 'showads' );
function showads(){... | I was lucky, the theme used it's own function, so it was easy to override.
Inspired by worpdress native get\_the\_posts\_navigation (wp-includes/link-template.php) here is what I end up using:
```
function my_get_the_posts_navigation( $args = array() ) {
$limit = 5;
$navigation = '';
// Don't print empty ... |
227,737 | <p>In my settings, I have New York defined as the time zone. But when I run plugins using PHP date() functions, I am getting a time zone of UTC as it shows in WP Admin > Settings > General.</p>
<p><a href="https://i.stack.imgur.com/7Fqlw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7Fqlw.png" alt... | [
{
"answer_id": 227800,
"author": "kaiser",
"author_id": 385,
"author_profile": "https://wordpress.stackexchange.com/users/385",
"pm_score": 2,
"selected": false,
"text": "<h2>Headers</h2>\n\n<p>First off: The <code>http-equiv</code> meta tags are the HTML <strong>equiv</strong>alent of a... | 2016/05/24 | [
"https://wordpress.stackexchange.com/questions/227737",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | In my settings, I have New York defined as the time zone. But when I run plugins using PHP date() functions, I am getting a time zone of UTC as it shows in WP Admin > Settings > General.
[](https://i.stack.imgur.com/7Fqlw.png)
[![enter image descript... | Headers
-------
First off: The `http-equiv` meta tags are the HTML **equiv**alent of an HTTP response header. They **can not** override a header already sent by your web server. So their only use is as a fallback and they rarely provide any real help. In reality, you want to go in and fix the headers your server(s) is... |
227,742 | <p>How do I enqueue a script on the header if the user is on an archive page of a custom post type? The custom post type is called <code>limitedrun</code> and the page is called <code>archive-limitedrun.php</code>.</p>
<p>I tried this and got no response:</p>
<pre><code>function opby_theme() {
wp_register_script('res... | [
{
"answer_id": 227745,
"author": "vancoder",
"author_id": 26778,
"author_profile": "https://wordpress.stackexchange.com/users/26778",
"pm_score": 2,
"selected": false,
"text": "<p><code>is_singular</code> doesn't handle archives.</p>\n\n<p>Try</p>\n\n<pre><code>is_post_type_archive( 'lim... | 2016/05/24 | [
"https://wordpress.stackexchange.com/questions/227742",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8049/"
] | How do I enqueue a script on the header if the user is on an archive page of a custom post type? The custom post type is called `limitedrun` and the page is called `archive-limitedrun.php`.
I tried this and got no response:
```
function opby_theme() {
wp_register_script('responsive-img', get_template_directory_uri() ... | You can save your time and server load by not using `wp_register_script` and `wp_register_style` when you don't need them definitely. `wp_enqueue_style` and `wp_enqueue_script` do the same job themselves when not involving excessive functions.
Here is easier and more readable code up to date with the accepted answer b... |
227,771 | <p>I have taken over a website where I work that was developed by a previous employee, it seems that recently this site has been the victim of a string of DDoS attacks through the use of the xmlrpc pingback proven by log entries like this:</p>
<p><code>154.16.63.40 - - [22/May/2016:06:52:49 +0100] "POST /xmlrpc.php HT... | [
{
"answer_id": 227745,
"author": "vancoder",
"author_id": 26778,
"author_profile": "https://wordpress.stackexchange.com/users/26778",
"pm_score": 2,
"selected": false,
"text": "<p><code>is_singular</code> doesn't handle archives.</p>\n\n<p>Try</p>\n\n<pre><code>is_post_type_archive( 'lim... | 2016/05/25 | [
"https://wordpress.stackexchange.com/questions/227771",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/77202/"
] | I have taken over a website where I work that was developed by a previous employee, it seems that recently this site has been the victim of a string of DDoS attacks through the use of the xmlrpc pingback proven by log entries like this:
`154.16.63.40 - - [22/May/2016:06:52:49 +0100] "POST /xmlrpc.php HTTP/1.1" 200 596... | You can save your time and server load by not using `wp_register_script` and `wp_register_style` when you don't need them definitely. `wp_enqueue_style` and `wp_enqueue_script` do the same job themselves when not involving excessive functions.
Here is easier and more readable code up to date with the accepted answer b... |
227,824 | <p>I have a custom post type called 'directory' and it includes a few meta/custom fields. The script below is meant to just change the post status only when run. This isn't on the admin panel where you save the post. This is a stand alone script run by itself.</p>
<pre><code>require('../../../wp-blog-header.php');
glo... | [
{
"answer_id": 227828,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 2,
"selected": false,
"text": "<p>I don't think this should happen by default. From quick look through the code the only case in which update call sh... | 2016/05/25 | [
"https://wordpress.stackexchange.com/questions/227824",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94667/"
] | I have a custom post type called 'directory' and it includes a few meta/custom fields. The script below is meant to just change the post status only when run. This isn't on the admin panel where you save the post. This is a stand alone script run by itself.
```
require('../../../wp-blog-header.php');
global $wpdb;
glo... | Not sure about the problem with `wp_update_post` but it is a simple enough SQL query:
```
global $wpdb;
$query = "UPDATE ".$wpdb->prefix."posts SET post_status='draft' WHERE ID = '".$directory->ID."'";
$wpdb->query($query);
``` |
227,854 | <p>This must be fairly simple, but I'm puzzled. And I may be going about it backwards.</p>
<p><em>How do I output a database option that is an array into a get_posts array?</em></p>
<p>I have an option in the database that stores some post IDs in the array format `1234,5678' . I can retrieve and echo them with</p>
<... | [
{
"answer_id": 227856,
"author": "Gareth Gillman",
"author_id": 33936,
"author_profile": "https://wordpress.stackexchange.com/users/33936",
"pm_score": 0,
"selected": false,
"text": "<p>get_posts doesn't have a post__in \"variable\", that's in wp_query, in get_posts (or get_pages) you wo... | 2016/05/25 | [
"https://wordpress.stackexchange.com/questions/227854",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/268/"
] | This must be fairly simple, but I'm puzzled. And I may be going about it backwards.
*How do I output a database option that is an array into a get\_posts array?*
I have an option in the database that stores some post IDs in the array format `1234,5678' . I can retrieve and echo them with
```
$options = get_option( '... | You could use [`wp_parse_id_list()`](https://developer.wordpress.org/reference/functions/wp_parse_id_list/) to sanitize your comma seperated list of post IDs. It's defined as:
```
function wp_parse_id_list( $list ) {
if ( !is_array($list) )
$list = preg_split('/[\s,]+/', $list);
return array_unique(ar... |
227,857 | <p>I have a big problem rendering shortcodes in my template I designed for my Tennis Club which works fine. However, now I wanted to integrate the standard WordPress Gallery, which is implemented by a shortcode but the shortcode is not being displayed as a normal Gallery, it is displayed as a text without any images. I... | [
{
"answer_id": 227927,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 1,
"selected": false,
"text": "<p><code>get_the_content</code> doesn't apply all of the filters that <code>the_content</code> runs before outputting... | 2016/05/25 | [
"https://wordpress.stackexchange.com/questions/227857",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94693/"
] | I have a big problem rendering shortcodes in my template I designed for my Tennis Club which works fine. However, now I wanted to integrate the standard WordPress Gallery, which is implemented by a shortcode but the shortcode is not being displayed as a normal Gallery, it is displayed as a text without any images. Is t... | `get_the_content` doesn't apply all of the filters that `the_content` runs before outputting the result. You can fix this by simply using:
```
<?php the_content(); ?>
```
in place of:
```
<?php echo $content; ?>
```
If you look at [the source for `the_content`](https://developer.wordpress.org/reference/functions/... |
227,871 | <p>Here's something odd, I want to print out a certain post on any page request, if you have a constant $idnumber of your favorite page/message, then add:</p>
<pre><code>$GLOBALS['post'] = get_post( $idnumber );
</code></pre>
<p><code>the_title();</code> echos that specific page's title, </p>
<p><code>get_permalink(... | [
{
"answer_id": 227873,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 2,
"selected": false,
"text": "<p>There are many globals that are being set in a loop, not only <code>$post</code>, and you need to set all... | 2016/05/26 | [
"https://wordpress.stackexchange.com/questions/227871",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25767/"
] | Here's something odd, I want to print out a certain post on any page request, if you have a constant $idnumber of your favorite page/message, then add:
```
$GLOBALS['post'] = get_post( $idnumber );
```
`the_title();` echos that specific page's title,
`get_permalink();` looks ok too,
but `the_content()` actually i... | There are many globals that are being set in a loop, not only `$post`, and you need to set all of them to get exactly the same behavior. To get this it is not enough to set `$post` but you also need to use [setup\_postdata](https://developer.wordpress.org/reference/functions/setup_postdata/) |
227,875 | <p>I am currently working on an entertainment website and I am having issues with page load time. I would love to know if there is any method I can use to remove blank spaces from PHP, JS , CSS scripts running via the website.</p>
<p>As I believe this will reduce load time efficiently. Also please any pointers to how ... | [
{
"answer_id": 227878,
"author": "bakar",
"author_id": 58787,
"author_profile": "https://wordpress.stackexchange.com/users/58787",
"pm_score": 0,
"selected": false,
"text": "<p>You should install Wp total Cache plugin and configure it as instructed on this page <a href=\"https://gtmetrix... | 2016/05/26 | [
"https://wordpress.stackexchange.com/questions/227875",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/81543/"
] | I am currently working on an entertainment website and I am having issues with page load time. I would love to know if there is any method I can use to remove blank spaces from PHP, JS , CSS scripts running via the website.
As I believe this will reduce load time efficiently. Also please any pointers to how can I sign... | I write one php code what totaly filter all html elements but is integrated in main index.php on the root. That made rendering a little faster but you also can do CDN for all your images and media. That will speedup your page a mutch better. I normaly point `/wp-content/uploads/` to subdomain and my WP get all media fr... |
227,882 | <p>Can I just get everyone's ok that using shortcodes embedded within templates is the 'correct' thing to do? I've tested them and they work just fine - but I just wanted everyone's thoughts. Thanks</p>
<p>Here's an example:</p>
<pre><code><?php echo do_shortcode('[course_complete]'); ?>
</code></pre>
| [
{
"answer_id": 227884,
"author": "cybmeta",
"author_id": 37428,
"author_profile": "https://wordpress.stackexchange.com/users/37428",
"pm_score": 1,
"selected": false,
"text": "<p>A shortcode is a placeholder for a PHP callback. As placeholder, it is intended to be used where PHP can not ... | 2016/05/26 | [
"https://wordpress.stackexchange.com/questions/227882",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93691/"
] | Can I just get everyone's ok that using shortcodes embedded within templates is the 'correct' thing to do? I've tested them and they work just fine - but I just wanted everyone's thoughts. Thanks
Here's an example:
```
<?php echo do_shortcode('[course_complete]'); ?>
``` | Is it Ok?
---------
Yes!
Is it Optimal?
--------------
No
What Would Be Better?
---------------------
Shortcodes map on to PHP functions, so why not cut out the middle man and go straight to the original function?
Are there any other downsides?
------------------------------
Yes!
That shortcode had to come from... |
227,892 | <p>I have created a custom post type <code>portfolio_posts</code> using the CPT UI plugin. Using the same plugin, I have created a taxonomy <code>portfolio_category</code>. I have made multiple entries under this taxonomy.</p>
<p>I want to list all the entries under <code>portfolio_category</code>, but all I'm getting... | [
{
"answer_id": 227898,
"author": "umair.ashfr",
"author_id": 93354,
"author_profile": "https://wordpress.stackexchange.com/users/93354",
"pm_score": 3,
"selected": true,
"text": "<p>Here is how i did it </p>\n\n<pre><code>$taxonomy = get_terms('portfolio_category', array( 'hide_empty' =&... | 2016/05/26 | [
"https://wordpress.stackexchange.com/questions/227892",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93354/"
] | I have created a custom post type `portfolio_posts` using the CPT UI plugin. Using the same plugin, I have created a taxonomy `portfolio_category`. I have made multiple entries under this taxonomy.
I want to list all the entries under `portfolio_category`, but all I'm getting is an empty array.
Here's what I've tried... | Here is how i did it
```
$taxonomy = get_terms('portfolio_category', array( 'hide_empty' => 0 ));
```
i am able get all the items under portfolio\_category. |
227,905 | <p>I have created a custom post type "brochures" which i am currently displaying with the code below (using ACF to display the brochure file).<br>
At the moment this displays all the brochures individually.<br></p>
<p>I have set up a custom taxonomy for this post type called "brochure_categories" so that i can categor... | [
{
"answer_id": 227898,
"author": "umair.ashfr",
"author_id": 93354,
"author_profile": "https://wordpress.stackexchange.com/users/93354",
"pm_score": 3,
"selected": true,
"text": "<p>Here is how i did it </p>\n\n<pre><code>$taxonomy = get_terms('portfolio_category', array( 'hide_empty' =&... | 2016/05/26 | [
"https://wordpress.stackexchange.com/questions/227905",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/91405/"
] | I have created a custom post type "brochures" which i am currently displaying with the code below (using ACF to display the brochure file).
At the moment this displays all the brochures individually.
I have set up a custom taxonomy for this post type called "brochure\_categories" so that i can categories the broc... | Here is how i did it
```
$taxonomy = get_terms('portfolio_category', array( 'hide_empty' => 0 ));
```
i am able get all the items under portfolio\_category. |
227,946 | <p>I'm using this plugin to add tags for a page:
<a href="http://wordpress.org/extend/plugins/post-tags-and-categories-for-pages/" rel="nofollow">http://wordpress.org/extend/plugins/post-tags-and-categories-for-pages/</a></p>
<p>And I've added tags support for the custom post:</p>
<pre><code>function codex_custom_ini... | [
{
"answer_id": 227948,
"author": "Gareth Gillman",
"author_id": 33936,
"author_profile": "https://wordpress.stackexchange.com/users/33936",
"pm_score": 2,
"selected": false,
"text": "<p>My first port of call is to call <code>global $post;</code> - as that sets you up to use <code>$post-&... | 2016/05/26 | [
"https://wordpress.stackexchange.com/questions/227946",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/22933/"
] | I'm using this plugin to add tags for a page:
<http://wordpress.org/extend/plugins/post-tags-and-categories-for-pages/>
And I've added tags support for the custom post:
```
function codex_custom_init() {
$args = array(
'public' => true,
'has_archive' => true,
'label' => 'Doing',
'taxonomi... | You need to specify a post type in your `WP_Query` arguments when you need to query any other post type accept the build in post type `post`.
By default, `post_type` is set to `post`, so when no specific post type is set manually by the user, `WP_Query` will query posts from the post type `post`
Additionally, `caller... |
227,972 | <p>I have a custom page template with a form, that any visitor of the website can upload a file. Now, I want to restrict the file type that will be upload (docx, doc and pdf only) and I limit the file size into 2MB only.</p>
<p>How to do this? I already have a function that the user allowed to upload, but I don't know... | [
{
"answer_id": 227979,
"author": "iyass.si",
"author_id": 94652,
"author_profile": "https://wordpress.stackexchange.com/users/94652",
"pm_score": 0,
"selected": false,
"text": "<p>You simply add an if statement like :</p>\n\n<pre>\n if ( $file[\"type\"] != \"application/pdf\" ){\n ... | 2016/05/27 | [
"https://wordpress.stackexchange.com/questions/227972",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/78787/"
] | I have a custom page template with a form, that any visitor of the website can upload a file. Now, I want to restrict the file type that will be upload (docx, doc and pdf only) and I limit the file size into 2MB only.
How to do this? I already have a function that the user allowed to upload, but I don't know how to re... | This is a full working example with file type and size limits and all the error handling.
Every step is commented. Let me know if you have any more questions.
* You can find all the mime types from [here](https://www.sitepoint.com/web-foundations/mime-types-summary-list/).
* Make sure to check if it's [allowed](http... |
227,989 | <p>I'm trying to display a list of all my custom taxonomy terms with an image field that I have created in ACF. The ACF image field I have is <code><img src="<?php the_field('brochure_logo'); ?>"></code>, but how can I display that image in my code below? I have left a gap where the field needs to go, but I... | [
{
"answer_id": 227990,
"author": "windyjonas",
"author_id": 221,
"author_profile": "https://wordpress.stackexchange.com/users/221",
"pm_score": 2,
"selected": false,
"text": "<p>You can pass the term object as the second parameter to the_field/get_field.</p>\n\n<pre><code>echo '<img s... | 2016/05/27 | [
"https://wordpress.stackexchange.com/questions/227989",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94771/"
] | I'm trying to display a list of all my custom taxonomy terms with an image field that I have created in ACF. The ACF image field I have is `<img src="<?php the_field('brochure_logo'); ?>">`, but how can I display that image in my code below? I have left a gap where the field needs to go, but I can't seem to output the ... | You can pass the term object as the second parameter to the\_field/get\_field.
```
echo '<img src="' . get_field( 'brochure_logo', $tax_term ) . '">';
``` |
228,004 | <p>trying to filter the output of term_description to include a class <a href="https://codex.wordpress.org/Function_Reference/term_description" rel="nofollow">https://codex.wordpress.org/Function_Reference/term_description</a></p>
<pre><code>function add_class_to_term_description() { ?>
<?php echo '<div cla... | [
{
"answer_id": 228309,
"author": "user3316",
"author_id": 3316,
"author_profile": "https://wordpress.stackexchange.com/users/3316",
"pm_score": 0,
"selected": false,
"text": "<p>you have to use passed <code>$value</code> instead of <code>term_description()</code> function:</p>\n\n<pre><c... | 2016/05/27 | [
"https://wordpress.stackexchange.com/questions/228004",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57838/"
] | trying to filter the output of term\_description to include a class <https://codex.wordpress.org/Function_Reference/term_description>
```
function add_class_to_term_description() { ?>
<?php echo '<div class="cell">' . term_description() . '</div>'; ?>
<?php }
add_filter( 'term_description', 'add_class_to_term_desc... | this does the trick
```
<?php function add_class_to_term_description($term_description) {
echo '<div class="cell">' . $term_description. '</div>';
}
add_filter( 'term_description', 'add_class_to_term_description' ); ?>
``` |
228,011 | <p>I want to display an archive page with pagination that lists all the categories on my site, and each link goes to that particular category archive page. So this would be like an archive page of category archives.</p>
<p>Each category on my site has a custom thumbnail created manually to match the category's permali... | [
{
"answer_id": 228035,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 1,
"selected": false,
"text": "<p>I'm not familiar with WP-PageNavi, but I suspect it assumes to be dealing with posts, so it might easily screw u... | 2016/05/27 | [
"https://wordpress.stackexchange.com/questions/228011",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94787/"
] | I want to display an archive page with pagination that lists all the categories on my site, and each link goes to that particular category archive page. So this would be like an archive page of category archives.
Each category on my site has a custom thumbnail created manually to match the category's permalink. I alre... | Paging a list of terms/categories/tags are quite easy, and to achieve that, you need minimal info.
Lets look at we need
* the amount of terms
* the amount of terms per page
* [`get_terms()`](https://developer.wordpress.org/reference/functions/get_terms/) (*Just note, the usage of `get_terms()` have changed in versio... |
228,031 | <p>I have a homepage, work (as parent pages) and several pages (as child), but when it comes to articles, I can't choose the relation between them and the page Blog.</p>
<p>Resuming, I can choose the hierarchy relation between pages, but I'm in trouble putting the articles under a "directory" called blog.
If change th... | [
{
"answer_id": 228035,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 1,
"selected": false,
"text": "<p>I'm not familiar with WP-PageNavi, but I suspect it assumes to be dealing with posts, so it might easily screw u... | 2016/05/27 | [
"https://wordpress.stackexchange.com/questions/228031",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94801/"
] | I have a homepage, work (as parent pages) and several pages (as child), but when it comes to articles, I can't choose the relation between them and the page Blog.
Resuming, I can choose the hierarchy relation between pages, but I'm in trouble putting the articles under a "directory" called blog.
If change the permalin... | Paging a list of terms/categories/tags are quite easy, and to achieve that, you need minimal info.
Lets look at we need
* the amount of terms
* the amount of terms per page
* [`get_terms()`](https://developer.wordpress.org/reference/functions/get_terms/) (*Just note, the usage of `get_terms()` have changed in versio... |
228,095 | <p>I can't figure out how to filter the comment permalink on certain WP page that I use like this:</p>
<pre><code>if(condition is met) {
(filter the comment url)
}
</code></pre>
<p>...so that all the comment permalinks inside the page can be changed from this:</p>
<pre><code>http://example.com/slug-to-page/#commen... | [
{
"answer_id": 228035,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 1,
"selected": false,
"text": "<p>I'm not familiar with WP-PageNavi, but I suspect it assumes to be dealing with posts, so it might easily screw u... | 2016/05/28 | [
"https://wordpress.stackexchange.com/questions/228095",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94080/"
] | I can't figure out how to filter the comment permalink on certain WP page that I use like this:
```
if(condition is met) {
(filter the comment url)
}
```
...so that all the comment permalinks inside the page can be changed from this:
```
http://example.com/slug-to-page/#comment-n
```
to this:
```
http://exampl... | Paging a list of terms/categories/tags are quite easy, and to achieve that, you need minimal info.
Lets look at we need
* the amount of terms
* the amount of terms per page
* [`get_terms()`](https://developer.wordpress.org/reference/functions/get_terms/) (*Just note, the usage of `get_terms()` have changed in versio... |
228,111 | <p>I'm currently working with a company to make a few basic tweeks to their WordPress site and I noticed that they have this on their sidebar:</p>
<p><a href="https://i.stack.imgur.com/H75vK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H75vK.png" alt="enter image description here"></a></p>
<p>I ... | [
{
"answer_id": 229075,
"author": "Mayeenul Islam",
"author_id": 22728,
"author_profile": "https://wordpress.stackexchange.com/users/22728",
"pm_score": 2,
"selected": true,
"text": "<p>WordPress Core post types are <code>post</code> and <code>page</code> that are visible in the admin men... | 2016/05/28 | [
"https://wordpress.stackexchange.com/questions/228111",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/86794/"
] | I'm currently working with a company to make a few basic tweeks to their WordPress site and I noticed that they have this on their sidebar:
[](https://i.stack.imgur.com/H75vK.png)
I am looking particularly at the "Clients", "Offers", "Portfolio" and ... | WordPress Core post types are `post` and `page` that are visible in the admin menu. Other than these can be either a registered custom post type or a menu page.
A menu page can be added with the [`add_menu_page()`](https://developer.wordpress.org/reference/functions/add_menu_page/) function, and a similar thing can be... |
228,123 | <p>Can anyone tell me how to enable Bootstrap on a site using the twentyeleven theme? I followed the instructions for activating Bootstrap with the <a href="https://wordpress.stackexchange.com/questions/163209/how-to-install-bootstrap-to-twentyfourteen-theme">twentyfourteen theme</a> without success.</p>
<p>This is th... | [
{
"answer_id": 228130,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 1,
"selected": false,
"text": "<p>Caching can be anywhere, starting with request caching on mysql components side (unlikely to impact in th... | 2016/05/29 | [
"https://wordpress.stackexchange.com/questions/228123",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94575/"
] | Can anyone tell me how to enable Bootstrap on a site using the twentyeleven theme? I followed the instructions for activating Bootstrap with the [twentyfourteen theme](https://wordpress.stackexchange.com/questions/163209/how-to-install-bootstrap-to-twentyfourteen-theme) without success.
This is the code I uploaded in ... | By default, WordPress uses `$wp_object_cache` which is an instance of [`WP_Object_Cache`](https://developer.wordpress.org/reference/classes/wp_object_cache/) to save on trips to the database.
Trace back [`username_exists()`](https://developer.wordpress.org/reference/functions/username_exists/#source-code) function, yo... |
228,152 | <p>Consider the simplest <code>archive.php</code> possible:</p>
<pre><code><?php
get_header();
while ( have_posts() ) {
the_post();
the_title();
}
get_footer();
</code></pre>
<p><strong>What address should I type into the browser to get to this page and display all posts?</strong> The permalink Custom S... | [
{
"answer_id": 228153,
"author": "dotancohen",
"author_id": 34330,
"author_profile": "https://wordpress.stackexchange.com/users/34330",
"pm_score": 0,
"selected": false,
"text": "<p>The URL for <code>archive.php</code> to list all posts which do not have a category assigned is:</p>\n\n<b... | 2016/05/29 | [
"https://wordpress.stackexchange.com/questions/228152",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/34330/"
] | Consider the simplest `archive.php` possible:
```
<?php
get_header();
while ( have_posts() ) {
the_post();
the_title();
}
get_footer();
```
**What address should I type into the browser to get to this page and display all posts?** The permalink Custom Struction is set as "/%category%/%postname%/". I have ... | `archive.php` is very broad template, possibly used for many kinds of archives.
If you mean common reverse chronological view the link to that would be return of [`get_post_type_archive_link()`](https://developer.wordpress.org/reference/functions/get_post_type_archive_link/) for the specific post type.
Note that the ... |
228,157 | <p>Is there any way to determine if a particular custom post type will be displayed on default archive pages or search results?</p>
<p>e.g.
Given a post type named (badly) <strong>books</strong>, is there a way to tell <strong>via code</strong> any of the following:</p>
<ul>
<li>If books show up on date archives</li>... | [
{
"answer_id": 228161,
"author": "Gregcta",
"author_id": 94533,
"author_profile": "https://wordpress.stackexchange.com/users/94533",
"pm_score": 0,
"selected": false,
"text": "<p>If you are on the front, on template you can use the <a href=\"https://codex.wordpress.org/Function_Reference... | 2016/05/29 | [
"https://wordpress.stackexchange.com/questions/228157",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/66020/"
] | Is there any way to determine if a particular custom post type will be displayed on default archive pages or search results?
e.g.
Given a post type named (badly) **books**, is there a way to tell **via code** any of the following:
* If books show up on date archives
* If books show up in search results
* If books sho... | You can [get the post type object](https://developer.wordpress.org/reference/functions/get_post_type_object/) and check its properties. For example:
```
$post_type = get_post_type_object( 'books' );
if( $post_type->exclude_from_search ) {
// The post type is not included in search results
}
if( $post_type->has_arc... |
228,163 | <p>I want to change some (20-30) of the defaults strings on Wordpress back-end (not to translate).</p>
<p>I know there is gettext filter but I think could lead to performance issues if we have a lot of strings.</p>
<p>Another method I tried was to create and use an admin-en_US.po file.</p>
<p>Which of the above meth... | [
{
"answer_id": 228164,
"author": "kaiser",
"author_id": 385,
"author_profile": "https://wordpress.stackexchange.com/users/385",
"pm_score": 2,
"selected": false,
"text": "<p>Yes, you can <a href=\"https://wordpress.stackexchange.com/questions/188332/override-default-wordpress-core-transl... | 2016/05/29 | [
"https://wordpress.stackexchange.com/questions/228163",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/30792/"
] | I want to change some (20-30) of the defaults strings on Wordpress back-end (not to translate).
I know there is gettext filter but I think could lead to performance issues if we have a lot of strings.
Another method I tried was to create and use an admin-en\_US.po file.
Which of the above methods are faster? Is ther... | Additionally to kaiser's answer, you can load customized .mo files that overrides the original file using [`load_textdomain_mofile` filter](https://developer.wordpress.org/reference/hooks/load_textdomain_mofile/). For example:
```
add_filter( 'load_textdomain_mofile', 'cyb_filter_load_textdomain_mofile', 10, 2 );
func... |
228,183 | <p>Can i add the <code>itemprop</code> to the <code>title</code> element and still use <code>wp_head()</code> and <code>add_theme_support( "title-tag" )</code>?</p>
<p>I want to create a theme and <a href="https://themes.trac.wordpress.org/ticket/29732#comment:23" rel="nofollow">get it approved on wordpres.org</a> wh... | [
{
"answer_id": 228203,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 1,
"selected": false,
"text": "<p>Unfortunately echoing the <code><title></code> tag is currently hardwired in <a href=\"https://github.com/... | 2016/05/29 | [
"https://wordpress.stackexchange.com/questions/228183",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/31759/"
] | Can i add the `itemprop` to the `title` element and still use `wp_head()` and `add_theme_support( "title-tag" )`?
I want to create a theme and [get it approved on wordpres.org](https://themes.trac.wordpress.org/ticket/29732#comment:23) which uses microdata.
The preceding mean i want the HTML code looks as follows:
`... | Since all `_wp_render_title_tag` does is check for `title-tag` theme support and wrap in `<title>` tags, there is really no reason why your existing implementation "shall not pass", since the proper implementation is already identical via:
```
<title itemprop="name"><?php echo wp_get_document_title(); ?></title>
```
... |
228,208 | <p>I have a multi author blog and i need show a global info message in top of add post page, so all authors can read it when they come in this specific page, how i can add it?
Thank you</p>
| [
{
"answer_id": 228211,
"author": "Christine Cooper",
"author_id": 24875,
"author_profile": "https://wordpress.stackexchange.com/users/24875",
"pm_score": 1,
"selected": false,
"text": "<p>You can do this by hooking into the <code>edit-post.php</code> page. There are a variety of hooks yo... | 2016/05/30 | [
"https://wordpress.stackexchange.com/questions/228208",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/28605/"
] | I have a multi author blog and i need show a global info message in top of add post page, so all authors can read it when they come in this specific page, how i can add it?
Thank you | You can do this by hooking into the `edit-post.php` page. There are a variety of hooks you could use, for example, if you want to display a message below the edit title field, you could hook into `edit_form_after_title`.
See the example code I have below with comments:
```
add_action(
'edit_form_after_title', // th... |
228,220 | <p>i'have added thumbnail image to Rss of my blog and I'm using this code to display the rss in another website .</p>
<p>please guide me how to add image thumbnail to this code ...</p>
<p>see the result at : <a href="http://pmanagers.org" rel="nofollow">Pmanagers.org</a></p>
<pre><code><?php // Get RSS Feed(s)
in... | [
{
"answer_id": 230983,
"author": "Tim Malone",
"author_id": 46066,
"author_profile": "https://wordpress.stackexchange.com/users/46066",
"pm_score": 1,
"selected": false,
"text": "<p>Answer from comments:</p>\n\n<p>First, create a conditional to check if the user has already 'published' a... | 2016/05/30 | [
"https://wordpress.stackexchange.com/questions/228220",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94919/"
] | i'have added thumbnail image to Rss of my blog and I'm using this code to display the rss in another website .
please guide me how to add image thumbnail to this code ...
see the result at : [Pmanagers.org](http://pmanagers.org)
```
<?php // Get RSS Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
// Get a Si... | Answer from comments:
First, create a conditional to check if the user has already 'published' a post. If yes, simply redirect them.
One can use `update_post_meta` with the post ID without any problem. Simply use that information to populate the fields. |
228,222 | <p>I'm looking for a way to show a certain pinterest pinboard in a post. </p>
<p>I've found in the <a href="https://en.support.wordpress.com/embed-from-pinterest/" rel="nofollow">WordPress.com Documentation</a> that you can simply post your pinboards URL there. This is not possible on a selfhosted Wordpress installati... | [
{
"answer_id": 228226,
"author": "Karthikeyani Srijish",
"author_id": 86125,
"author_profile": "https://wordpress.stackexchange.com/users/86125",
"pm_score": 0,
"selected": false,
"text": "<p><a href=\"https://i.stack.imgur.com/KCG6K.png\" rel=\"nofollow noreferrer\"><img src=\"https://i... | 2016/05/30 | [
"https://wordpress.stackexchange.com/questions/228222",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94921/"
] | I'm looking for a way to show a certain pinterest pinboard in a post.
I've found in the [WordPress.com Documentation](https://en.support.wordpress.com/embed-from-pinterest/) that you can simply post your pinboards URL there. This is not possible on a selfhosted Wordpress installation so I guess that is something spec... | I found that <https://wordpress.org/plugins/pinterest-widgets> actually has the needed functionality but doesn't mention it in the description.
After installing and activating you can add a pinboard to a post by using the following shortcodes
```
[pin_board url="http://www.pinterest.com/pinterest/pin-pets/"]
[pin_boa... |
228,223 | <p>I am including a partial file both in <code>header.php</code> and in <code>footer.php</code> with <code>get_template_part('content-form');</code> </p>
<p>Is there an <code>if</code> clause I can use to check from where the file is being called? If it is called from within <code>footer.php</code>, then I would like ... | [
{
"answer_id": 228233,
"author": "Ismail",
"author_id": 70833,
"author_profile": "https://wordpress.stackexchange.com/users/70833",
"pm_score": 2,
"selected": false,
"text": "<p>There are many good solutions for doing this, you should follow the link that cjbj has provided in the comment... | 2016/05/30 | [
"https://wordpress.stackexchange.com/questions/228223",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/85304/"
] | I am including a partial file both in `header.php` and in `footer.php` with `get_template_part('content-form');`
Is there an `if` clause I can use to check from where the file is being called? If it is called from within `footer.php`, then I would like to add a class name.
```
<div class="default-class <?php if (cal... | This is not a *true* solution to your problem (checking which template loaded another), but it will work to test if the footer has been loaded or not, and thus if it's loading your partial:
```
if ( did_action( 'get_footer' ) ) echo 'footer-class';
``` |
228,251 | <p>Using the google page speed test i saw that some images were too large and needed to be resized. I used the ftp to download the necessary images, resized them locally, and then used the media upload tool to import them into Wordpress. </p>
<p>I went to each relevant post and changed the feature image to use the new... | [
{
"answer_id": 228233,
"author": "Ismail",
"author_id": 70833,
"author_profile": "https://wordpress.stackexchange.com/users/70833",
"pm_score": 2,
"selected": false,
"text": "<p>There are many good solutions for doing this, you should follow the link that cjbj has provided in the comment... | 2016/05/30 | [
"https://wordpress.stackexchange.com/questions/228251",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/92793/"
] | Using the google page speed test i saw that some images were too large and needed to be resized. I used the ftp to download the necessary images, resized them locally, and then used the media upload tool to import them into Wordpress.
I went to each relevant post and changed the feature image to use the new ones. In ... | This is not a *true* solution to your problem (checking which template loaded another), but it will work to test if the footer has been loaded or not, and thus if it's loading your partial:
```
if ( did_action( 'get_footer' ) ) echo 'footer-class';
``` |
228,256 | <p>Semi-new to WordPress, so apologies is this is an obvious question!</p>
<p>I'm trying to execute some JavaScript on a WordPress site, but only on the child pages of a specific parent page - so, I have example.com/books, and I want the script to run on example.com/books/foo, example.com/books/bar, example.com/books/... | [
{
"answer_id": 228233,
"author": "Ismail",
"author_id": 70833,
"author_profile": "https://wordpress.stackexchange.com/users/70833",
"pm_score": 2,
"selected": false,
"text": "<p>There are many good solutions for doing this, you should follow the link that cjbj has provided in the comment... | 2016/05/30 | [
"https://wordpress.stackexchange.com/questions/228256",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94934/"
] | Semi-new to WordPress, so apologies is this is an obvious question!
I'm trying to execute some JavaScript on a WordPress site, but only on the child pages of a specific parent page - so, I have example.com/books, and I want the script to run on example.com/books/foo, example.com/books/bar, example.com/books/wee, and s... | This is not a *true* solution to your problem (checking which template loaded another), but it will work to test if the footer has been loaded or not, and thus if it's loading your partial:
```
if ( did_action( 'get_footer' ) ) echo 'footer-class';
``` |
228,266 | <p>I'm developing a WordPress theme using a template engine. I want my code to be as much compatible as possible with WP core functionality.</p>
<h2>Some context first</h2>
<p>My first problem was to find a way to <em>resolve</em> the template starting from a WP query. I solved that one using a library of mine, <a hr... | [
{
"answer_id": 228268,
"author": "gmazzap",
"author_id": 35541,
"author_profile": "https://wordpress.stackexchange.com/users/35541",
"pm_score": 3,
"selected": true,
"text": "<p>Not sure the following solution is <em>better</em> than the solution in OP, let's just say is an alternative, ... | 2016/05/30 | [
"https://wordpress.stackexchange.com/questions/228266",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/35541/"
] | I'm developing a WordPress theme using a template engine. I want my code to be as much compatible as possible with WP core functionality.
Some context first
------------------
My first problem was to find a way to *resolve* the template starting from a WP query. I solved that one using a library of mine, [Brain\Hiera... | Not sure the following solution is *better* than the solution in OP, let's just say is an alternative, probably more hackish, solution.
I think you can use a PHP exception to stop WordPress execution when `'comments_template'` filter is applied.
You can use a custom exception class as a DTO to *carry* the template.
... |
228,279 | <p>Playing with WordPress customization I created a meta box with several others that report back details of the post. One meta box evaluates the featured image but I am having trouble figuring out how to fire the AJAX in the content of the meta box. At first I thought I would need to look into <code>admin-ajax.php</... | [
{
"answer_id": 228384,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 2,
"selected": false,
"text": "<p>Very broad solution.</p>\n\n<p>There are two problems you are facing</p>\n\n<ol>\n<li><p>there are differ... | 2016/05/30 | [
"https://wordpress.stackexchange.com/questions/228279",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25271/"
] | Playing with WordPress customization I created a meta box with several others that report back details of the post. One meta box evaluates the featured image but I am having trouble figuring out how to fire the AJAX in the content of the meta box. At first I thought I would need to look into `admin-ajax.php` so I follo... | I couldn't find any WP specific event to hook in to. What you can do is set up an observer with a callback to respond to DOM changes using `MutationObserver` and check if the your featured image has been added in the callback.
There's [no support](http://caniuse.com/#feat=mutationobserver) in IE < 11 though, which may... |
228,284 | <p>So...here is part of my code for a plugin. I'm a newb of sorts so be kind. I've read up on global variables but I can't seem to get it to work and I've read you shouldn't use them anyway. So what would be the best way to write the code below without having to re-declare the variables for each function? Here is t... | [
{
"answer_id": 228384,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 2,
"selected": false,
"text": "<p>Very broad solution.</p>\n\n<p>There are two problems you are facing</p>\n\n<ol>\n<li><p>there are differ... | 2016/05/30 | [
"https://wordpress.stackexchange.com/questions/228284",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84806/"
] | So...here is part of my code for a plugin. I'm a newb of sorts so be kind. I've read up on global variables but I can't seem to get it to work and I've read you shouldn't use them anyway. So what would be the best way to write the code below without having to re-declare the variables for each function? Here is the [ful... | I couldn't find any WP specific event to hook in to. What you can do is set up an observer with a callback to respond to DOM changes using `MutationObserver` and check if the your featured image has been added in the callback.
There's [no support](http://caniuse.com/#feat=mutationobserver) in IE < 11 though, which may... |
228,287 | <p>I am working on a site for a client who has a theme built for them by a different developer. They have asked me to make some changes to the site, and I'd like to put all of my changes into a plugin as a courtesy to the original theme developer. So far this is simple with functions and CSS. Now I need to change a the... | [
{
"answer_id": 228288,
"author": "Tim Malone",
"author_id": 46066,
"author_profile": "https://wordpress.stackexchange.com/users/46066",
"pm_score": 3,
"selected": true,
"text": "<p><strong>TL;DR:</strong> Use a <strong><a href=\"https://codex.wordpress.org/Child_Themes\" rel=\"nofollow\"... | 2016/05/31 | [
"https://wordpress.stackexchange.com/questions/228287",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/73822/"
] | I am working on a site for a client who has a theme built for them by a different developer. They have asked me to make some changes to the site, and I'd like to put all of my changes into a plugin as a courtesy to the original theme developer. So far this is simple with functions and CSS. Now I need to change a theme ... | **TL;DR:** Use a **[child theme](https://codex.wordpress.org/Child_Themes)** instead :)
---
If we dig into the [code for get\_template\_part()](https://developer.wordpress.org/reference/functions/get_template_part/), there's an action there - `get_template_part_{$slug}` - which we could hook into.
Digging a bit furt... |
228,300 | <p>I am searching online and all I can see is how to <em>increase</em> file size for media upload, which I know how to do with <code>php.ini</code>, but what I need to do is limit the file size for media upload only.</p>
<p>The client and his associates have trouble with understanding: Please do not upload images that... | [
{
"answer_id": 228306,
"author": "Capiedge",
"author_id": 39150,
"author_profile": "https://wordpress.stackexchange.com/users/39150",
"pm_score": 4,
"selected": true,
"text": "<p>Yes, you can use the <code>wp_handle_upload_prefilter</code> that allows you to stop the uploading process if... | 2016/05/31 | [
"https://wordpress.stackexchange.com/questions/228300",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/58895/"
] | I am searching online and all I can see is how to *increase* file size for media upload, which I know how to do with `php.ini`, but what I need to do is limit the file size for media upload only.
The client and his associates have trouble with understanding: Please do not upload images that are bigger than 1MB because... | Yes, you can use the `wp_handle_upload_prefilter` that allows you to stop the uploading process if a specific condition is not accomplished.
In your case, you could try this code snippet:
```
function limit_upload_size( $file ) {
// Set the desired file size limit
$file_size_limit = 1024; // 1MB in KB
/... |
228,301 | <p>I am working on a plugin .I want to upload image from front end i.e by <code>input type="file"</code>.I did lot of google for it but could not upload image .Here is my code for uploading image</p>
<pre><code><form method="post" action="options.php">
<input type="file" name="my_image_upload" id="my_image_... | [
{
"answer_id": 228330,
"author": "Jebble",
"author_id": 81939,
"author_profile": "https://wordpress.stackexchange.com/users/81939",
"pm_score": 0,
"selected": false,
"text": "<p>You call for a WordPress function before WordPress is fully loaded.\nA quick and dirty way to fix this is to a... | 2016/05/31 | [
"https://wordpress.stackexchange.com/questions/228301",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84928/"
] | I am working on a plugin .I want to upload image from front end i.e by `input type="file"`.I did lot of google for it but could not upload image .Here is my code for uploading image
```
<form method="post" action="options.php">
<input type="file" name="my_image_upload" id="my_image_upload" multiple="false" />
<i... | Now I have an answer for my own question.I solved this issue by using this code.I add this code just for sharing and helping other as it works for me.
```
<input type="file" name="my_file_upload" id="my_file_upload_id" class="bg_checkbox" >
function register_team_show_case_setting() {
//register our settings
reg... |
228,322 | <p>I am facing a problem to set default value for the checkbox field in WordPress.
I have a checkbox input field (metabox) in a custom post. I want the checkbox to be checked by default. and if user uncheck it then it should be saved and unchecked and remain unchecked when page is refreshed. My problem is that I can no... | [
{
"answer_id": 228332,
"author": "Ismail",
"author_id": 70833,
"author_profile": "https://wordpress.stackexchange.com/users/70833",
"pm_score": 0,
"selected": false,
"text": "<p>Your code will make the value <code>yes</code> only when the user fills the form. You could check if the meta ... | 2016/05/31 | [
"https://wordpress.stackexchange.com/questions/228322",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93685/"
] | I am facing a problem to set default value for the checkbox field in WordPress.
I have a checkbox input field (metabox) in a custom post. I want the checkbox to be checked by default. and if user uncheck it then it should be saved and unchecked and remain unchecked when page is refreshed. My problem is that I can not s... | I think the problem might could be the logic with using `checked`...
```
<input type="checkbox" name="aps_display_post_title" value="yes" <?php if ($aps_display_post_title != 'no') {echo 'checked';} ?> />
```
...on the other hand then running `sanitize_text_field` on the checkbox value might also be causing the pr... |
228,356 | <p>I've seen there are several ways to display a user's last login date on the Users page without having to use a 3rd party plugin. Building on that, I'd really like to have the user's last login date column be sortable (hopefully orderby date). </p>
<p>I'm using the display user last login function via <a href="http:... | [
{
"answer_id": 228397,
"author": "brianjohnhanna",
"author_id": 65403,
"author_profile": "https://wordpress.stackexchange.com/users/65403",
"pm_score": 3,
"selected": true,
"text": "<p>I don't see anywhere in your code that the query is being modified. Just flagging a column to be sortab... | 2016/05/31 | [
"https://wordpress.stackexchange.com/questions/228356",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/54745/"
] | I've seen there are several ways to display a user's last login date on the Users page without having to use a 3rd party plugin. Building on that, I'd really like to have the user's last login date column be sortable (hopefully orderby date).
I'm using the display user last login function via [wpdailybits](http://wpd... | I don't see anywhere in your code that the query is being modified. Just flagging a column to be sortable doesn't mean it knows how to sort the data - it will just add the little up/down arrow and make the column clickable but you have to intercept the query var accordingly and tell WP what to do. You'll want to hook i... |
228,358 | <p>For version control purpose, our client has a WordPress app with directory structure like this:</p>
<pre><code>.
|_____app
| |_____themes
| |_____plugins
| |_____uploads
|_____index.php
|_____WordPress
|_____wp-config.php
</code></pre>
<p>In <code>wp-config.php</code>:</p>
<pre><code>define('WP_CONTENT_DIR', _... | [
{
"answer_id": 228368,
"author": "gmazzap",
"author_id": 35541,
"author_profile": "https://wordpress.stackexchange.com/users/35541",
"pm_score": 2,
"selected": false,
"text": "<p>If you look at the source of <a href=\"https://developer.wordpress.org/reference/functions/_wp_upload_dir/\" ... | 2016/05/31 | [
"https://wordpress.stackexchange.com/questions/228358",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/92212/"
] | For version control purpose, our client has a WordPress app with directory structure like this:
```
.
|_____app
| |_____themes
| |_____plugins
| |_____uploads
|_____index.php
|_____WordPress
|_____wp-config.php
```
In `wp-config.php`:
```
define('WP_CONTENT_DIR', __DIR__ . '/app');
define('WP_CONTENT_URL', WP_HO... | After digging around, I ended up with using [`upload_dir`](https://developer.wordpress.org/reference/hooks/upload_dir/) filter.
Here is what I tried in `functions.php` to change `uploads` to `media`. Hope it can help someone too :)
```
add_filter('upload_dir', function($uploads)
{
$custom = [];
foreach (... |
228,390 | <p>I have this shortcode to display a loop of user avatars with order by registration date.</p>
<pre><code>function Profiles() {
$args = array(
'orderby' => 'registered',
'order' => 'DESC',
'fields' => 'all_with_meta',
);
$user_query = new WP_User_Query( $args );
if ( ! empty( $use... | [
{
"answer_id": 228385,
"author": "user9447",
"author_id": 25271,
"author_profile": "https://wordpress.stackexchange.com/users/25271",
"pm_score": 3,
"selected": true,
"text": "<p>Based on what you're asking and what I am understanding there is <a href=\"https://codex.wordpress.org/Functi... | 2016/05/31 | [
"https://wordpress.stackexchange.com/questions/228390",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94925/"
] | I have this shortcode to display a loop of user avatars with order by registration date.
```
function Profiles() {
$args = array(
'orderby' => 'registered',
'order' => 'DESC',
'fields' => 'all_with_meta',
);
$user_query = new WP_User_Query( $args );
if ( ! empty( $user_query->results ) ) {
... | Based on what you're asking and what I am understanding there is [`the_modified_date()`](https://codex.wordpress.org/Function_Reference/the_modified_date) or if you just want the value [`get_the_modified_date()`](https://codex.wordpress.org/Function_Reference/get_the_modified_date).
If you ever want the creation date ... |
228,395 | <p>Oddly enough I can't seem to find anyone asking this question exactly in this fashion.</p>
<p>Is it at possible to make a page be a child of a CPT? In a repeatable fashion (see below for more info) n.b. I do not mean vice versa -- which is easy enough see: <a href="https://wordpress.stackexchange.com/questions/817... | [
{
"answer_id": 228396,
"author": "Jake Deichmann",
"author_id": 94445,
"author_profile": "https://wordpress.stackexchange.com/users/94445",
"pm_score": 1,
"selected": false,
"text": "<p>I can't really think of an easy and repeatable way to do this, but check out: <a href=\"https://wordpr... | 2016/05/31 | [
"https://wordpress.stackexchange.com/questions/228395",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8756/"
] | Oddly enough I can't seem to find anyone asking this question exactly in this fashion.
Is it at possible to make a page be a child of a CPT? In a repeatable fashion (see below for more info) n.b. I do not mean vice versa -- which is easy enough see: [Can a custom post type have a Parent Page?](https://wordpress.stacke... | I can't really think of a way that you would have a post type of page and have it be "repeatable." As Jake said, it's going to involve rewrite rules. I think the easiest way to do it would be to set up some templates for whatever these cases may be in your theme directory, and make use of query vars to populate them. S... |
228,402 | <p>In the plugin, The css file loads sitewide by default, I want to load it only on the Single post.</p>
<p>the conditional tags, i.e, is_single() isn’t working in plugins,</p>
<p>any idea how can we achieve that?</p>
| [
{
"answer_id": 228410,
"author": "Steve Clason",
"author_id": 94857,
"author_profile": "https://wordpress.stackexchange.com/users/94857",
"pm_score": 0,
"selected": false,
"text": "<p>You need something like this in your functions.php file:</p>\n\n<pre><code>if( is_single()) {\n wp_enqu... | 2016/05/31 | [
"https://wordpress.stackexchange.com/questions/228402",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/95019/"
] | In the plugin, The css file loads sitewide by default, I want to load it only on the Single post.
the conditional tags, i.e, is\_single() isn’t working in plugins,
any idea how can we achieve that? | **TL,DR;**
You are hooking early.
---
>
> In the plugin, the css file loads site-wide by default, I want to load
> it only on the single post.
>
>
>
It's a very good thought many developers don't take this into account while developing themes/plugins.
>
> **`is_single()`** isn’t working in plugins
>
>
>
... |
228,405 | <p>I've built a function within a plugin. I'd like to call it with an jQuery ajax function.</p>
<p>The function is defined as follows:</p>
<pre><code>add_action( 'wp_ajax_my_test_ajax', 'my_test_ajax' );
add_action( 'wp_ajax_nopriv_my_test_ajax', 'my_test_ajax' );
function my_test_ajax() {
$resp = array('t... | [
{
"answer_id": 228410,
"author": "Steve Clason",
"author_id": 94857,
"author_profile": "https://wordpress.stackexchange.com/users/94857",
"pm_score": 0,
"selected": false,
"text": "<p>You need something like this in your functions.php file:</p>\n\n<pre><code>if( is_single()) {\n wp_enqu... | 2016/06/01 | [
"https://wordpress.stackexchange.com/questions/228405",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/51378/"
] | I've built a function within a plugin. I'd like to call it with an jQuery ajax function.
The function is defined as follows:
```
add_action( 'wp_ajax_my_test_ajax', 'my_test_ajax' );
add_action( 'wp_ajax_nopriv_my_test_ajax', 'my_test_ajax' );
function my_test_ajax() {
$resp = array('title' => 'here is the... | **TL,DR;**
You are hooking early.
---
>
> In the plugin, the css file loads site-wide by default, I want to load
> it only on the single post.
>
>
>
It's a very good thought many developers don't take this into account while developing themes/plugins.
>
> **`is_single()`** isn’t working in plugins
>
>
>
... |
228,406 | <p>For some reason WordPress is ignoring my thumbnail sizes and keeping thumbnails cropped proportionately instead of specific dimensions. Here is what I have in <code>functions.php</code>:</p>
<pre><code>add_image_size( 'main-thumbnail', 728, 410, true );
</code></pre>
<p>and in <code>content.php</code>:</p>
<pre><... | [
{
"answer_id": 228410,
"author": "Steve Clason",
"author_id": 94857,
"author_profile": "https://wordpress.stackexchange.com/users/94857",
"pm_score": 0,
"selected": false,
"text": "<p>You need something like this in your functions.php file:</p>\n\n<pre><code>if( is_single()) {\n wp_enqu... | 2016/06/01 | [
"https://wordpress.stackexchange.com/questions/228406",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/73086/"
] | For some reason WordPress is ignoring my thumbnail sizes and keeping thumbnails cropped proportionately instead of specific dimensions. Here is what I have in `functions.php`:
```
add_image_size( 'main-thumbnail', 728, 410, true );
```
and in `content.php`:
```
<div class="thumbnail">
<a href="<?php the_permali... | **TL,DR;**
You are hooking early.
---
>
> In the plugin, the css file loads site-wide by default, I want to load
> it only on the single post.
>
>
>
It's a very good thought many developers don't take this into account while developing themes/plugins.
>
> **`is_single()`** isn’t working in plugins
>
>
>
... |
228,426 | <p><strong>Happy day scenario</strong>: I implement WP REST API that sends JSONs to a JavaScript client, which parses it and displays the data to the user. All is fine.</p>
<p><strong>What actually happens, inevitably</strong>: some WordPress code or plugin generates a PHP notice or warning, and the server is configur... | [
{
"answer_id": 228429,
"author": "AntonChanning",
"author_id": 5077,
"author_profile": "https://wordpress.stackexchange.com/users/5077",
"pm_score": -1,
"selected": false,
"text": "<p>You need to use a combination of <a href=\"https://stackoverflow.com/a/5373824/641534\">exception catchi... | 2016/06/01 | [
"https://wordpress.stackexchange.com/questions/228426",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12248/"
] | **Happy day scenario**: I implement WP REST API that sends JSONs to a JavaScript client, which parses it and displays the data to the user. All is fine.
**What actually happens, inevitably**: some WordPress code or plugin generates a PHP notice or warning, and the server is configured so that this garbage finds its wa... | If you are creating classes, the first thing in the construct would be this. Or you can drop it in with an action as early as possible. Maybe plugins\_loaded.
```
/*
* If WP DEBUG is not on do NOT return any php warning, notices, and/or fatal errors.
* Well If it is a fatal error then this return is FUBAR an... |
228,466 | <p>I created a plugin that sets up a custom route and then loads a template file for that url. Everything works fine, except that WordPress seems to think it's a 404 even though it's correctly rendering my template.</p>
<p>For instance it says 404 in the document title and an <code>error404</code> class is added to <c... | [
{
"answer_id": 258466,
"author": "Ahrengot",
"author_id": 23829,
"author_profile": "https://wordpress.stackexchange.com/users/23829",
"pm_score": 3,
"selected": true,
"text": "<p>Manually setting <code>is_404 = false;</code> fixed my issue. However I'm not sure this is the best way to do... | 2016/06/01 | [
"https://wordpress.stackexchange.com/questions/228466",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23829/"
] | I created a plugin that sets up a custom route and then loads a template file for that url. Everything works fine, except that WordPress seems to think it's a 404 even though it's correctly rendering my template.
For instance it says 404 in the document title and an `error404` class is added to `<body>`
The custom ur... | Manually setting `is_404 = false;` fixed my issue. However I'm not sure this is the best way to do it. I tried using the `pre_get_posts` filter instead without any luck.
Anyway, for anyone else in the same boat, you can do this to get rid of the 404 state:
```
public function add_response_template($template) {
glob... |
228,476 | <p>I read a lot about the <code>require_once</code> in stackoverflow.</p>
<p>But no anwser solved my problem.</p>
<p>I've a plugin with two files.</p>
<pre><code>dmd_main.php //main file
dmd_second.php //some WP functions
</code></pre>
<p>In my main file I've included this line:</p>
<pre><code>require_once (plugi... | [
{
"answer_id": 228496,
"author": "Ismail",
"author_id": 70833,
"author_profile": "https://wordpress.stackexchange.com/users/70833",
"pm_score": 0,
"selected": false,
"text": "<p>You can access the full list of available plugin updates with <a href=\"https://developer.wordpress.org/refere... | 2016/06/01 | [
"https://wordpress.stackexchange.com/questions/228476",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/78481/"
] | I read a lot about the `require_once` in stackoverflow.
But no anwser solved my problem.
I've a plugin with two files.
```
dmd_main.php //main file
dmd_second.php //some WP functions
```
In my main file I've included this line:
```
require_once (plugin_dir_path(__FILE__) . 'includes/dmd_second.php');
```
But o... | Not possible unless you plan in advance in your plugin for such a possibility. And even if it was somehow possible you are still not likely to have any user read the message and actually understand it.
A more realistic approach is to do a two steps upgrade, in the first vesion of your plugin to maintain appropriate ba... |
228,525 | <p>In Visual Studio, you can easily debug your application by running Debug mode and setting breakpoints in your application.</p>
<p>In Wordpress, how would you achieve same thing?</p>
<p>I have an issue in my website and there are no error or warnings thrown. I have spent enough time tweaking settings to figure this... | [
{
"answer_id": 228528,
"author": "Nebri",
"author_id": 94607,
"author_profile": "https://wordpress.stackexchange.com/users/94607",
"pm_score": 4,
"selected": true,
"text": "<p>Debugging in wordpress can be a bit difficult when your first starting out, while I don't use breakpoints such a... | 2016/06/01 | [
"https://wordpress.stackexchange.com/questions/228525",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/91516/"
] | In Visual Studio, you can easily debug your application by running Debug mode and setting breakpoints in your application.
In Wordpress, how would you achieve same thing?
I have an issue in my website and there are no error or warnings thrown. I have spent enough time tweaking settings to figure this out without luck... | Debugging in wordpress can be a bit difficult when your first starting out, while I don't use breakpoints such as what Visual Studio offers, I can offer advice on how to debug php in general, as well as turning on the debugging output from wordpress.
First start by opening up your wp-config.php and finding the followi... |
228,553 | <p>I managed to add a custom option-select for images with </p>
<pre><code>function attachment_field_credit( $form_fields, $post ) {
$field_value = get_post_meta( $post->ID, 'first_image', true );
$isSelected1 = $field_value == '1' ? 'selected ' : '';
$isSelected2 = $field_value != '1' ? 'selected ' : '... | [
{
"answer_id": 228559,
"author": "Capiedge",
"author_id": 39150,
"author_profile": "https://wordpress.stackexchange.com/users/39150",
"pm_score": 2,
"selected": false,
"text": "<p>Looking at the core, there's no trace of any filter or action in the <code>wp_link_dialog</code> function, w... | 2016/06/02 | [
"https://wordpress.stackexchange.com/questions/228553",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57245/"
] | I managed to add a custom option-select for images with
```
function attachment_field_credit( $form_fields, $post ) {
$field_value = get_post_meta( $post->ID, 'first_image', true );
$isSelected1 = $field_value == '1' ? 'selected ' : '';
$isSelected2 = $field_value != '1' ? 'selected ' : '';
$form_fiel... | The dialog HTML comes from `WP_Editors::wp_link_dialog()` but no hooks in there.
We could instead use jQuery to append the custom HTML to the link dialog and try to override e.g. the `wpLink.getAttrs()`, because it's very short ;-)
Demo example:
```
jQuery( document ).ready( function( $ ) {
$('#link-options').a... |
228,571 | <p>I made a simple loop to display product base from category and brand (custom taxonomy.)</p>
<p>Here piece of my loop:</p>
<pre><code><?php
$args = array(
'post_type' => 'product',
'posts_per_page' => 4,
'orderby' => 'DESC',
'tax_query' => array(
'relation' =&g... | [
{
"answer_id": 228578,
"author": "Champeau",
"author_id": 94714,
"author_profile": "https://wordpress.stackexchange.com/users/94714",
"pm_score": 1,
"selected": false,
"text": "<p>If I were you I would print_r($category) and make sure it is giving you ID's and not slugs. Also, you are s... | 2016/06/02 | [
"https://wordpress.stackexchange.com/questions/228571",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/89109/"
] | I made a simple loop to display product base from category and brand (custom taxonomy.)
Here piece of my loop:
```
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => 4,
'orderby' => 'DESC',
'tax_query' => array(
'relation' => 'AND',
array(
... | If I were you I would print\_r($category) and make sure it is giving you ID's and not slugs. Also, you are submitting $category to both product\_cat and brands.
If your field type were slug instead of id, and terms were exactly the same in both product\_cat and brands then this would work... though it doesn't make sen... |
228,579 | <p>I have an SQL query here:</p>
<pre><code>$data_listg = $wpdb->get_results( "SELECT ID FROM " . $wpdb->prefix . "posts where post_type='post' and SUBSTR(" . $wpdb->prefix . "posts.post_title, 1, 1) LIKE '%$data' and post_status='publish' LIMIT 2" );
</code></pre>
<p>The query shows posts by first word. For... | [
{
"answer_id": 228578,
"author": "Champeau",
"author_id": 94714,
"author_profile": "https://wordpress.stackexchange.com/users/94714",
"pm_score": 1,
"selected": false,
"text": "<p>If I were you I would print_r($category) and make sure it is giving you ID's and not slugs. Also, you are s... | 2016/06/02 | [
"https://wordpress.stackexchange.com/questions/228579",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/85340/"
] | I have an SQL query here:
```
$data_listg = $wpdb->get_results( "SELECT ID FROM " . $wpdb->prefix . "posts where post_type='post' and SUBSTR(" . $wpdb->prefix . "posts.post_title, 1, 1) LIKE '%$data' and post_status='publish' LIMIT 2" );
```
The query shows posts by first word. For example:
If titles start with "A"... | If I were you I would print\_r($category) and make sure it is giving you ID's and not slugs. Also, you are submitting $category to both product\_cat and brands.
If your field type were slug instead of id, and terms were exactly the same in both product\_cat and brands then this would work... though it doesn't make sen... |
228,585 | <p>I would like to start using the <a href="http://v2.wp-api.org/" rel="noreferrer">WordPress REST API v2</a> to query information from my site. I've noticed that when I visit an endpoint URL directly, I can see all of the data publicly. I've also seen that a lot of tutorials mention the use of test or local servers ra... | [
{
"answer_id": 228648,
"author": "wpclevel",
"author_id": 92212,
"author_profile": "https://wordpress.stackexchange.com/users/92212",
"pm_score": 6,
"selected": true,
"text": "<blockquote>\n<p>Is this meant to be used on sites in production?</p>\n</blockquote>\n<p>Yes. <a href=\"https://... | 2016/06/02 | [
"https://wordpress.stackexchange.com/questions/228585",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/88515/"
] | I would like to start using the [WordPress REST API v2](http://v2.wp-api.org/) to query information from my site. I've noticed that when I visit an endpoint URL directly, I can see all of the data publicly. I've also seen that a lot of tutorials mention the use of test or local servers rather than live sites.
My quest... | >
> Is this meant to be used on sites in production?
>
>
>
Yes. [Many sites have been already using it](https://make.wordpress.org/core/2015/07/23/rest-api-whos-using-this-thing/).
>
> Is there a security risk to allowing endpoints to be viewed by anyone, such as /wp-json/wp/v2/users/ which shows all users regis... |