INSTRUCTION
stringlengths 11
999
| RESPONSE
stringlengths 0
999
| SOURCE
stringlengths 16
38
| METADATA
dict |
---|---|---|---|
Custom Wordpress Does Not Display Anything But Background in IE
I have a custom, well kinda custom wordpress in only one page of my site, the background only displays in Internet explorer, no body or content just background though in firefox it's fine as with other browsers. Reverted back to the original twenty ten and it shows in IE. I know the code is horrible but it was a shot at making a custom theme and it worked fine before. If I thought I could fix it myself I wouldn't ask the pros here. You guys have helped me a ton !!
Also, if you view the source, it shows content being there.
<
Sincerely Mark | In your initial style declaration that sets the background color:
background:#000D37;
You have an open HTML comment but no close. Close that and you should be fine. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -1,
"tags": "themes"
} |
woocommerce and is_user_logged_in() if not redirect to homepage
I am currently using woocommerce and would like to redirect none logged in users to the home page, however i am having a little trouble determining where i should implements this
I have done research and determined that using the is_user_logged_in() i can see if the user is logged in.
I tryed implementing in the woocommerce/woocommerce-functions.php
// When default permalinks are enabled, redirect shop page to post type archive url
if (is_user_logged_in() && isset($_GET['page_id']) && $_GET['page_id'] > 0 && get_option( 'permalink_structure' )=="" && $_GET['page_id'] == woocommerce_get_page_id('shop') ) :
wp_safe_redirect( get_post_type_archive_link('product') );
exit;
endif;
but it still allows the page to be visible | You are going to want to insert your code at the top of the page templates for the Woo pages you would like the redirect to affect rather than the functions file. So for example if you want to redirect users when they try to access an individual product page you could put it at the top of the plugins->woocommerce->templates->single-product.php page.
When editing templates though I would recommend making a copy and placing it in your theme directory, so that when Woo updates it will not override any changes you made. So for the example I gave above (applied to my theme). I would copy single-product.php and place it in the themes->agency file and then make the changes to that file, there. Your theme will then always use that file before the one in the Woo template file. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 2,
"tags": "php, login, plugins, membership"
} |
How to hide trackbacks on wp-admin/edit-comments.php
How to hide (or not to show, better said) trackbacks on wp-admin/edit-comments.php page?
I want to hide the comments with no email (also known as trackbacks) and comments with a specific email from the edit-comments.php page. | While this is not impossible, this is very likely to have ton of edge cases and backfire in some. In a nutshell comments are retrieved with comment query, which can be adjusted with something like this (if in admin and comment type not specified then only fetch normal comments):
add_action( 'pre_get_comments', 'exclude_pings' );
function exclude_pings( $comment_query ) {
if( ! is_admin() )
return;
if ( empty( $comment_query->query_vars['type'] ) )
$comment_query->query_vars['type'] = 'comment';
}
However the problem is "any comment query in admin" is too broad and there isn't much it can be narrowed down by.
Overall I would not recommend to mess with this.
PS excluding by author is not supported by native arguments and would be even more tricky with need to filter SQL. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "comments"
} |
How to make wordpress use www.example.com/blog/wp-includes/ instead of www.example.com/wp-includes/?
I have WordPress at address < now I want it to be accessible as < without moving wordpress to root directory.
I have made appropriate .htaccess changes.
wp-config.php:
define("WP_HOME", "
define('WP_CONTENT_DIR', $_SERVER["DOCUMENT_ROOT"] . "/blog/wp-content");
define('WP_CONTENT_URL', "
One thing that doesn't work is WordPress uses www.example.com/wp-includes/ instead of www.example.com/blog/wp-includes/
There are even includes like www.example.com/%post-name%/wp-includes/js/jquery/jquery.js?ver=1.7.2
I have fixed it through .htaccess:
RewriteRule wp-includes/(.*) /blog/wp-includes/$1 [L]
Is threre a better way? | Add to `wp-config.php`:
define('WP_SITEURL', '
On the codex.
This is all you need. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "url rewriting"
} |
How to use command 'wp post create' in wp-cli properly?
I need to create a single post with title, content and excerpt with this command as it's described in the utility documentation. Could you please show me an example of how to use it? I couldn't find nor in official documentation neither on Google. Thanks! | If you type `wp help post create` you will get all the info you need.
Example:
wp post create --post_type=page --post_status=publish --post_title='A new page' | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 5,
"tags": "command line, wp cli"
} |
get_query_var returns null
My pretty permalink clearly shows the query_var:
localhost/site/?tree=312
Yet when I run
var_dump(get_query_var('tree'));
I get NULL returned.
Any reason why? Also when I print_r($wp_query), I can't find 'tree' anywhere. | You have to add any query vars that are not WordPress objects to the array of recognized query vars to be able to retrieve it from the `$wp_query` global:
add_filter( 'query_vars', 'wpa66452_query_vars' );
function wpa66452_query_vars( $query_vars ){
$query_vars[] = 'tree';
return $query_vars;
} | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 1,
"tags": "wp query"
} |
Possible to use conditionals within add_feed() callback?
I'm using `add_feed()` to create some custom feeds but calls to `is_singular()`, `is_home()` etc... just don't seem to work within the callback. Is there a workaround for this?
Example code:
add_action( 'init', 'my_init' );
function my_init() {
add_feed( 'new_feed', 'feed_output' );
}
function feed_output() {
if ( is_home() )
load_template( '/path/to/feed/home/template.php' );
else
load_template( '/path/to/feed/template.php' );
}
I've added a trac ticket for this too. | You can only use conditional tags after the `posts_selection` action hook has run.
According to the codex article on add_feed it should be called with the `init` action, which runs before. Now I don't know when and how you run it, because you don't say so in the above example, but I'd assume you do it before `posts_selection` \- that would explain your dilemma anyway. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 3,
"tags": "conditional tags, feed"
} |
How can i display in a archive page a number of post i want
How can i display in a archive themplate ( post type) page a number of post,
Let say i want to display a number of 20 post....in archive page, under i want to display the pages...
Please look here :
<
I use post type pages... all the archive pages are now displayng 12 post..
I want to be able to display a number...
let say 20 post for trailers - for the trailers category let say 10 post for actori- for actori category...
Now i use :
<?php is_tag(); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
Thanks in advance | Just use the `current_post` property in the loop:
if ( have_posts() )
{
while( have_posts() )
{
global $wp_query;
the_post();
// Show current post number:
echo $wp_query->current_post;
} // endwhile;
} // endif; | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "categories"
} |
Add custom fields after post/page title
I am using the Headway theme, and I need to add custom field code to page & posttitles. This is what I need to be able to do.
example [edit:image has been deleted]
The red button will be added through a custom field. It needs to be shown inline with the title. I have worked out I can do this using the `headway_after_entry_title` hook, but I can't seem to get the code right to retrieve the custom fields. I got this far :
//Add custom field image after entry title
function title_btn() {
echo '<div class="title-btn">[custom field code to go here]</div>';
}
add_action('headway_after_entry_title', 'title_btn');
and the outcome should be:
<a href="xxx"><img src="xxx"></a>
where the xxx is the custom field url code
Hope anybody can help me out with this. | There's the `get_post_meta()` function to retrieve those data.
So basically, you'd write a function in your functions.php file (or in a custom plugin - take "Hello Dolly" as example) and hook it.
<?php
/* Plugin Name: (#66495) »kaiser« Headway Title Button */
function wpse66495_headway_title_button()
{
return printf(
'<div class="title-btn"><a href="%s" alt="%s"><img src="%s /></a></div>'
,get_post_meta( get_the_ID(), 'meta_key_link_url', true )
,get_the_title()
,get_post_meta( get_the_ID(), 'meta_key_thumb_url', true )
);
}
add_action( 'headway_after_entry_title', 'wpse66495_headway_title_button' ); | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "functions, custom field, hooks, post meta"
} |
add_menu_page() with different name for first submenu item
The `add_menu_page` documentation says to pass the menu title as the second parameter:
add_menu_page('Page Title', 'Menu Title', ...);
When adding more pages later via `add_submenu_page`, the main page becomes the first entry in the submenu:
!enter image description here
* * *
However, I want the first item in the list to have a different name (but still point to the same page), the way Wordpress itself does it:
!enter image description here
* * *
How could I accomplish that in my plugin? | You can make the 'slug' for the submenu page equal that of the top level page, and they'll point to the same place:
add_action('admin_menu', 'my_menu_pages');
function my_menu_pages(){
add_menu_page('My Page Title', 'My Menu Title', 'manage_options', 'my-menu', 'my_menu_output' );
add_submenu_page('my-menu', 'Submenu Page Title', 'Whatever You Want', 'manage_options', 'my-menu' );
add_submenu_page('my-menu', 'Submenu Page Title2', 'Whatever You Want2', 'manage_options', 'my-menu2' );
}
E.g.
!enter image description here | stackexchange-wordpress | {
"answer_score": 171,
"question_score": 122,
"tags": "plugin development, menus, add menu page, add submenu page"
} |
How can I convert some categories to a custom taxonomy?
I have a WordPress install that has a ton of categories. I want to convert some of these categories into a custom taxonomy. For example, I have:
Categories:
* Category A
* Subcategory 1
* Subcategory 2
* Category B
* Subcategory 1
* Subcategory 2
* Category C
* Subcategory 1
* Subcategory 2
And I would like to make Category C and all of its subcategories into a completely separate custom taxonomy. Is there a way that I can make this conversion, while keeping the relationships between Category C and existing posts intact? | You can create whatever new taxonomies you want to by adding register_taxonomy() function in functions.php
After that you can simply assign all the posts related to Category C to that custom taxonomy using Convert Post types plugin. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 2,
"tags": "categories, custom taxonomy, taxonomy"
} |
Remove Open Sans from Twenty Twelve theme
I´m creating a child theme for Twenty Twelve v1.0 and I want to remove the Open Sans font.
Open Sans is added in Twenty Twelve´s functions.php:
wp_enqueue_style( 'twentytwelve-fonts', add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" ), array(), null );
I´ve tried to deregister/dequeue the stylesheet in my childtheme´s functions.php (see examples below) but to no effect:
function example_scripts_styles() {
wp_deregister_style( 'twentytwelve-fonts' );
wp_dequeue_style( 'twentytwelve-fonts' );
}
add_action( 'wp_enqueue_scripts', 'example_scripts_styles' );
Any ideas how I can remove this file? Thanks! | Found the answer here:
> Script dequeuing calls should be added to the wp_print_scripts action hook(..). This is because scripts are typically enqueued on the wp_enqueue_script hook, which happens early in the wp_head process. The wp_print_scripts hook happens right before scripts are printed, and thus is latest in the process. (Otto)
Following the same logic we can use `wp_print_styles` to remove the Open Sans font:
function remove_open_sans() {
wp_dequeue_style( 'twentytwelve-fonts' );
}
add_action('wp_print_styles','remove_open_sans');
This did the trick. | stackexchange-wordpress | {
"answer_score": 12,
"question_score": 16,
"tags": "css, wp enqueue style, theme twenty twelve"
} |
different theme in one website
Assume this is my site name : `www.example.com.`
I saw different websites have different themes in a site. For example I want to have different themes for `www.example.com` and `www.example.com/othertheme.` I know it should have different database for that. But how? | This is one of the best use cases for WordPress Multisite. There are some plugins (like this one) that do this on a per-page or per-category basis, but I've never used them.
Multisite has a lot of nice advantages (network-wide updates, user management, etc), along with some fun extra bugs (a lot of the recent core security updates have been for multisite-specific issues) and plugins that don't work on multisite.
I would recommend reading "Don't Use WordPress Multisite" from .org support guru @ipstenu first, but it sounds like your use case is a good one for multisite. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "themes, database"
} |
How to show beneath posts the full category path?
My portal has the following category structure: **CategoryLevel1=>CategoryLevel2=>CategoryLevel3=>CategoryLevel4**
I assign posts to CategoryLevel4 but I want to show the full category path beneath each post. Each node should be clickable.
Thanks. | Assuming your categories are in a parent=>child hierarchy as listed(ie category4 is a child of category 3, etc) then this should give you what you're after:
the_category("»", "multiple", $post->ID); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "posts, categories"
} |
How to disable main query?
I don't use The Loop, because I use different queries to fetch posts (I use 3 queries instead of one).
How to disable main query for home, category and search pages? | This is not trivial, because "home,category and search" are logically determined while main query churns through stuff. I am pretty sure I read this is possible, but that was in context of syndicating site that hadn't used posts/loop at all and scrapped it to do different stuff.
More typical approaches are:
1. Integrate custom logic into main query, by using `pre_get_posts`, `posts_*` and other relevant filters.
2. Leave main query for one of loops and implement other loops as secondary. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 3,
"tags": "wp query"
} |
Multiple multisite instances connecting to the same database
I like the idea of making developers connect their copies to the same database and just set `WP_HOME` and `WP_SITEURL` to configure the domain name as they like it. In this model, we don't need to keep migrating databases between servers, and the content will be kept in sync between developers. We also use this for staging, as each version has its own `wp-config.php` file.
If we try to make the same with multisite installs it won't work because it relies much more in the database values for domain names. So, what would be the best way of making multiple multisite development copies with different domains connect to the same database for development purposes like the non-multisite sites we're already dealing with? | Instead of changing WP_HOME etc, it would be best to enforce a single domain, e.g. local.example.com or shared.example.com and then use the HOSTS file to set that address to 127.0.0.1
This way there is no change to the URLs at all as it is unnecessary, and the shared DB content is consistent (this menu doesn't work on Alice' machine because Bob created it on his machine, and he uses a different domain name to Alice )
Also keep in mind your situation has the fatal flaw of sharing post content, but not post attachment files/uploads. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "multisite, database"
} |
What's the difference between wp_insert_user() and wp_create_user()
I know the former allows additional parameters, so you can more user info, but other then that, why do both exist?
The specific reason I want to know is that wp_insert_user() is happening REALLY slowly. Somewhere between 5 - 10 seconds. I don't remember having this problem in the past, when I was using create_user, so I'm wondering if there's a lot more happening behind the scenes with one as opposed to the other.
Thanks. | None. The whole source of `wp_create_user()` is:
function wp_create_user($username, $password, $email = '') {
$user_login = esc_sql( $username );
$user_email = esc_sql( $email );
$user_pass = $password;
$userdata = compact('user_login', 'user_email', 'user_pass');
return wp_insert_user($userdata);
}
It just calls _insert_ version almost immediately, basically a shorthand wrapper. As for why it exists - core works in mysterious ways and (short of hunting down developer by version control history and asking) there is rarely way to tell. :) | stackexchange-wordpress | {
"answer_score": 13,
"question_score": 9,
"tags": "performance, user registration, wp create user"
} |
Hierarchy of Subcategories on Permalink (bug?)
I found out something weird today.
The current permalink is set to `/%category%/%postname%/` but this happens (example):
I have a parent category `Food` and 4 subcategories `Burger`, `Pancake`, `Waffles`, and `Pizza`. As expected, the link should appear like this: `foo.com/food/burger/post-name` but it only works on 2 of my categories and looks like so:
foo.com/food/burger/post-name-1
foo.com/food/pancake/post-name-2
foo.com/food/post-name-3
foo.com/food/post-name-4
I'm refreshing the permalink settings but it doesn't seem to work.
I've even tried renaming Burger and Pancake to something else, both of them still look fine. But even if I rename Waffles and Pizza to Burger and Pancake, they still don't appear in the permalink.
Any quick solutions for this? Do I have to enter a custom taxonomy thingy? | When a post belongs to more than one category, regardless of their parent/child structure, WordPress will use the category with the lowest ID in the permalink. If that lower ID belongs to a child category, you'll see the parent/child structure in the permalink.
If you always want parent/child category appearing in the permalink, a simple solution would be to only assign the child category to the post. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "permalinks"
} |
Were the language toggles removed from WP recently?
I need to change my weblogs language to "English".
I am refering to the article: < which allegedly was "Last modified: July 16, 2012".
I only looked for this option in v.3.4 forward and I cannot find it. It's also absent in v.3.5 beta 1. I initially installed and still use the German locale.
Thus: 1). Were these simple drop-down menus removed from more recent versions? Because I can find neither of the two.
2). Could my webhoster be at fault somehow? They offered the "WP One-Click-Install" option, which I thought shouldn't hurt things - I guess I was wrong...
3). Could be my German locale at fault, i.e. maybe only the "international" or "English" version has this toggle, but not any of the downloadable locales? Just a guess.
I am aware of the fact that I can change the language of WP manually, but first I need a clarification what happened to the above feature since July 16th this year. | No, they were never there. The link you posted is for WordPress.com hosted blogs, not self-hosted WordPress.org software.
Refer to Installing WordPress in Your Language for info on use in other languages. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "multi language, language"
} |
Force image crop size in media editor
I've searched high and low for this but think the answer I seek is being buried by the more common questions.
I am developing a theme for a client that has two specific image sizes (100x127 for thumbnail, 300x380 for medium). I have the media settings cropping like this when an image is uploaded, but if the user goes in to edit a thumbnail it doesn't re-crop to the sizes specified in media settings.
What I am ideally looking for is either a plugin or something I can add to functions.php that will restrict the crop "draw" feature to the aspect ratio and then when the crop button is hit, will automatically resize the thumbnail to 100x127.
Does anything like this exist? I don't even want the end user to have the option of entering in custom pixel sizes or aspect ratios. I'd rather that menu went away entirely. | There is a very good plugin that I believe covers all you are looking for, and more: Scissors Continued. I've been using it extensively on several websites, and recommend it. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "media, thumbnails, cropping, images"
} |
How to do get_users() with multiple meta_keys
In the codex it says its possible to do get_users() with multiple meta keys by using the meta_query parameter but it doesn't explain how. Can someone give me an example? | As it mentions in the Codex page for `get_users`, it works the same as a `WP_Query` `meta_query`, see that page for full arguments list and examples.
$args = array(
'meta_query' => array(
array(
'key' => 'some_key',
'value' => 'foo',
'compare' => '='
),
array(
'key' => 'another_key',
'value' => array( 'bar', 'baz' )
'compare' => 'IN'
)
)
); | stackexchange-wordpress | {
"answer_score": 10,
"question_score": 6,
"tags": "users"
} |
Remove post content from buddypress activity
I'm trying to remove the post content from the buddypress activity stream and would like to replace the content/body with a custom field that I've added in.
Any ideas where I should be looking? I've been looking around for a while and cant seem to figure it out.
I am using WordPress 3.4.1 & Buddypress 1.5.6 | You should state which versions of WP and BP you're using.
This should change the content part of what is recorded. You can put it in your theme's functions.php
add_filter( 'bp_blogs_activity_new_post_content', 'record_post_activity_content', 1, 3 );
function record_post_activity_content($activity_content, $post, $post_permalink ){
if( $post->post_type == 'post' ) {
$activity_content = 'your custom field';
}
return $activity_content;
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "buddypress"
} |
How to Access Global $multipage or Global $numpages outside the loop?
I am writing a code in the header that pertains to link rel='prev' and link rel='next' thing but I need to check if the post is multipage. I check out these global variables:
$numpages $multipage
However they don't work in header.php or outside the loop? Example code to verify in header (just a test, but it does not work):
<?php
global $wp_query;
global $numpages;
global $multipage;
If ($multipage) {
echo 'This is a multipage post';
} else {
echo 'This is not multipage';
}
?>
I am wondering how to do this, can somebody help me please? Thanks. | Just inspect the current post content for `'<!--nextpage-->'`:
function wpse_check_multi_page()
{
$num_pages = substr_count(
$GLOBALS['post']->post_content,
'<!--nextpage-->'
) + 1;
$current_page = get_query_var( 'page' );
return array ( $num_pages, $current_page );
}
On page 2 of 3 that returns:
Array
(
[0] => 3
[1] => 2
)
On an unpaged post it returns:
Array
(
[0] => 1
[1] => 0
) | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 3,
"tags": "wp query"
} |
wp_set_post_terms is assigning only the last of several terms to a post
I have this really simple setup where I loop through an array of actors, and for each actor name I successfully insert a term. Then I use wp_set_post_terms to assign the terms to a post, but this only assigns the last term to that post. I am new to using taxonomy/terms so maybe there's an obvious solution. Here's my code:
foreach ($cast as $actor) {
$actor_term_id = wp_insert_term( $actor[name], 'actor', array(
'description' => $bio[0]["desc"]
)
);
// Assign term id to post
wp_set_post_terms( $post_id, $actor_term_id, 'actor' );
} | You need send a fourth argument to the function:
wp_set_post_terms($post_id, $actor_term_id, 'actor', true);
Each time the function executes, you're replacing any existing terms. The fourth argument specifies that you wish to append them.
< | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "terms"
} |
Strategy for making a mobile version of an existing site?
I have a site setup with content, themes, plugins, and modified code.
However, I want a mobile version.
I googled this and it looked like there use to be plugins that helped with this, but it seems most have been dis-continued.
Is there a strategy for making a site mobile? | You have 3 choices
1. choose a Responsive Theme for your site (Responsive adapts for different screen sizes)
2. choose a plugin (such as WPTouchPro - which is both plugin and theme)
3. build a second site which you access at m.example.com, this duplicates all the content and has its own theme
... there is a 4th option ... being polite... there are dozens of great books and websites about WordPress & Mobile Web Development like this one from Wrox | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "mobile"
} |
Help Understanding Template Hierarchy
I must be thick, but I could use some help grasping the way template files are chosen to be used. I noticed loop.php is no longer around, and looking at the file structure for twentytwelve there is now a 'page-templates' directory. As well as content-* files. We have index.php, page.php, content.php which one is used when? I know index.php is the "last resort" choice, however does content or page come first? And what is the difference between them? Thank you. | Template hierarchy consist of templates, but not every template file is necessarily in hierarchy.
Essentially hierarchy determines entry points (one of matching templates with pre-defined name structure), but from there template can further load additional arbitrary files.
`page-templates` directory holds custom templates for pages (`is_page()` branch in hierarchy). It's recent development that they can now reside in sub-folder.
`content-*.php` templates are called by Twenty Twelve like this from other templates: `get_template_part( 'content', get_post_format() );`. They are named arbitrarily and not part of template hierarchy - just a code organization choice that developers of this specific theme made. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "templates, template hierarchy"
} |
Setting default category for display
The default category for the page News is news.
But I want the _page_ news to show all posts.
Not just _news_ posts.
All posts, includes news posts and engineering posts.
When you hit the main site is < it does indeed do this, as you can verify.
But when you go to News it it only shows the news category.
How do I fix so that it show both? | I'm not sure you are understanding what a 'category page' is doing; for example your news page:
this is pulling out all post with the categoy 'news' which has cat id equal to 1.
depending on your needs there are two possible things you can do.
1 - if you simply want all posts with N categories displayed without any other customisations, you need to create a menu entry link which calls both of your categories i.e. which you can test in the browser:
2 - if you want something more complicated you will need to create a specific page and modify the loop; these might give you an idea: multiple categories < multiple cat with selection control <
hope it helps
lorenzo | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "posts, customization"
} |
Why do I get Fatal error: Call to undefined function get_most_recent_post_of_user()?
I am using WordPress 3.4.2. The codex doesn't say anything about this function being deprecated: < | get_most_recent_post_of_user() is for multisite installs to get the most recent post of the user from each blog.
Here is a comparable function you can use that will return the post object of the defined users most recent post.
function wpse_get_user_recent( $user ) {
global $wpdb;
$recent = $wpdb->get_row( $wpdb->prepare("SELECT ID, post_date_gmt FROM {$prefix}posts WHERE post_author = %d AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1", (int)$user ), ARRAY_A);
if( ! isset( $recent['ID'] ) )
return new WP_Error( 'No post found for selected user' );
return get_post( $recent['ID'], 'ARRAY_A' );
}
Usage:
$post = wpse_get_user_recent( 36 );
setup_post_data( $post );
the_title();
the_content();
wp_reset_postdata(); | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 3,
"tags": "functions"
} |
Force Plugin to English Translation
Here's my thing:
I'm using a plugin that has multilang capabilities. The point is that the language translation in my country lang is very bad and it makes more complex than simpler my work. :D. So is there a way to force a plugin to not to use multilanguage and be showed, at least, in English? | What's the plugin? Is it using custom translations in mo/po files? Is there an admin interface which allows you to set the plugin locale?
There is a generic filter which you might be able to add to the plugin code to set the language which might look something like the following (obviously set the language to what you want:
add_filter('locale', 'wpse_get_locale');
// returns the locale based on user preference
function wpse_get_locale($locale) {
// get_current_user_id uses wp_get_current_user which may not be available the first time(s) get_locale is called
if (function_exists('wp_get_current_user'))
$loc = get_user_meta(get_current_user_id(), 'user_lang', 'true');
return isset($loc) && $loc ? $loc : $locale;
}
However I wonder if it might not be easier to improve the translation of the plugin by editing the mo/po files or whatever they use for the string translation? | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 4,
"tags": "plugins, multi language, translation"
} |
how to place a link on the first post only using a plugin
i want to add a link to the first post of every WP blog that i have. For example this simple function adds the link to every post.
function add_link($link){
$link .= '<a href="
return $link;
}
add_filter('the_content','add_link');
so basically instead of the link showing below each post, I want it to show only at the bottom of the first post only.
thanks. | Just remove the filter when it is called the first time:
function add_link($link)
{
// this will guarantee the filter will not be called again.
remove_filter( current_filter(), __FUNCTION__ );
return $link . '<a href="
} | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "plugins, the content"
} |
Hook into the rendering of a WordPress Template
I have to use WordPress as some meta templating system and include some `JSP` snipptes which will be evaluated later with Tomcat after rendering the page statically. But naturally the `JSP` Code could not be interpreted by the php parser. This results in plain text strings mixed with the interpreted template parts.
**Is there any way to hook into the (pre) rendering of a WordPress Template?**
I need way get access the rendered template so i can strip out the `JSP`-Tags. Maybe wrapped between some unique tags or something else. But this ist not part of this question.
## Example
<?php get_header(); ?>
<render:jsp>
<%= request.getParameter("title") %>
</render:jsp>
<?php get_footer(); ?> | You can, but WP doesn't offer you the possibility to do it in a nice way, so you have to use output buffering.
Something like:
// before template is included
add_action('template_redirect', function(){
// you can do some checks here
// perhaps you need this only a certain page?
if(!is_home())
return;
// capture output from here on...
ob_start(function($html){
// this function runs after the capture ends,
// you can replace your tags here
$html = strtr($html, array(
'<render:jsp>' => '<!--',
'</render:jsp>' => '-->',
));
return $html;
});
});
The contents of the buffer are automatically sent by PHP to the output just before the script finishes execution. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "plugins, plugin development"
} |
Displaying the most recently used tags
Is it possible to just show the most recent tags from e.g. the latest 10 posts as a tag cloud?
The only things that I found were the WP Recent Tags plugin which is a bit outdated and no tags are displayed when I use the widget.
I found the following posts:
> <
> <
But they don’t work for me either. | Sure, just feed your tag list to wp_generate_tag_cloud:
$found_tags = $final_tags = $id_records = array();
// get last 10 posts
$last_posts = get_posts('numberposts=10');
// gather tags
foreach($last_posts as $post)
$found_tags = array_merge($found_tags, wp_get_post_tags($post->ID));
// prepare final tags for the cloud
foreach($found_tags as $tag){
// ignore duplicates
if(in_array($tag->term_id, $id_records))
continue;
// track ids...
$id_records[] = $tag->term_id;
// generate links
$tag->link = get_tag_link($tag);
// keep it
$final_tags[] = $tag;
}
// feed to the cloud
print wp_generate_tag_cloud($final_tags);
You might want to cache this, because it makes quite a few queries | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 1,
"tags": "tags"
} |
Using a specific template for front page only
I am using supersized full slider for my themes, but it need all the script and stylesheet gets enqueued before wp_head. So it becomes the part of the header.
Now whenever I use the header template (which is essential) Supersized also get included in all pages. I want to use it in front and home page only. I have a default home page for sliders only. | Well first of all it depends how you are enqueing your other scripts but make sure you dont add them before the jQuery library itself has been included.
There is nothing stopping you using conditional code in header.php to add scripts depending on the page that is loading, or even the template, category etc;
<?php
if ( is_home() || is_front_page() ) { ?>
// add your scripts in normal way
<?php } ?> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "templates, frontpage"
} |
How to get post meta value and post in one query?
When query a post, I need not only the post but also the post_meta. But seems the post query and meta query can not be done together.
With WP_Query, I first get the posts, then, I need to do `get_post_meta(get_the_ID(),'key',true)`
Is this the way WP works? Or, is there a way to query both in one hit? | ## When you do a query WordPress already gets the post_meta.
Even though you are calling `get_post_meta()` It is not performing another query. It is retrieving the value from the post meta cache.
Now if you don't need the post meta you can set a flag that will eliminate the additional MySql query. To do this you set `'update_post_meta_cache' => false` in your args. | stackexchange-wordpress | {
"answer_score": 9,
"question_score": 1,
"tags": "wp query"
} |
How do I programatically empty trash?
I need to create an "Empty Trash" button inside my plugin. How would I do it using PHP code? | You can use `wp_delete_post`.
To get all posts with the "trash" status:
`$trash = get_posts('post_status=trash&numberposts=-1');`
Then:
foreach($trash as $post)
wp_delete_post($post->ID, $bypass_trash = true); | stackexchange-wordpress | {
"answer_score": 10,
"question_score": 11,
"tags": "buttons, trash"
} |
Post processing of uploaded file
When a file with the `.xml` extension has been uploaded on my blog (via the Add Media uploader) I would like to automatically replace some attributes.
For example, if I upload a file with this content:
<content creator="foo"></content>
I would like that Wordpress modifies it automatically in:
<content creator="bar"></content>
What hook should I use and how? | You can do this using the `wp_handle_upload` hook:
Create a function and add it to this hook so it runs last, it will be passed an array. The array contains the location of the newly uploaded file:
add_filter('wp_handle_upload','wpse_66775_handle_upload',1000,1);
function wpse_66775_handle_upload($args){
$filename = $args['file'];
$type = $args['type'];
// test if it's an XML file and do some work on it
if(the file is an xml file){
super_magic_xml_file_modifier($filename);
}
return $args;
}
function super_magic_xml_file_modifier($filename){
// General PHP/XML stuff that doesn't belong on WPSE
}
Modifying the XML file etc, is another task that is not within the scope of this site. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "uploads, xml"
} |
Wordpress Migration error phpupdate_option is not a function
I'm trying to migrate my wordpress from a subfolde to the root. I've already done it from localhost to the subfolder with the same method
update_option('siteurl','
update_option('home','
But this time it does not look to work... It says "Call to undefined function phpupdate_option() in functions.php line 1.
In config.php there is no url define().
Is there someone who had a solution for it?
Thanks in advance. | It sounds like your opening `<?php` tag is abutting your first call to update_option. If it isn't directly adjacent to it, perhaps the whitespace between the two is unrecognized for one reason or another (this can happen from copying and pasting from some sources). Have your functions.php file start off like this:
<?php
update_option('siteurl','
update_option('home',' | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "functions, migration"
} |
how to retrieve WP_Query without ordering by date
> **Possible Duplicate:**
> Orderby = none not working
I want to use `$query = new WP_Query( 'post__in' => array( 2, 5, 12, 14, 20 ) ) );` to retrieve posts by ID, I do and the result ordered by publish date but I want to retrieve in same of IDs in this example in this order: 2, 5, 12, 14, 20 | In WordPress 3.5, you'll be able to do this with the 'orderby' parameter set to 'post__in'.
Until then, this question is basically identical to another one, which I wrote an answer for already: Orderby = none not working | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "wp query, order"
} |
Search within table?
I have a nice plugin that is called Select WP-Table Reloaded and that works well, except the contents don't show up in a useful manner.
The page the table is embedded shows up in a search, but not the specific term.
Is there any way to remedy this?
This is the page the table is embedded in: <
If you were to search for an author, like "Baake", only the page with the short blurb would show up. | Suggested here by JLeuse. It seems the contents within WP Table Reloaded is indeed separated from the post, which means the default Wordpress search function won't be able to fetch it... | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "search, table"
} |
Page for custom post type
I'm a newbie in WordPress and I've just created a new custom-post type called arts. Is there a way I can create a custom page to display the 'art's custom type? The custom-post type has thumbnails which I'll be displaying on the post and 'arts'are a bit more different form other posts. Any help offered will be highly regarded. | I f you set the argument `has_archive` in `register_post_type()` to `TRUE` you get an archive automatically.
Depending on your slug it will be available on `/arts/` probably.
To customize the look of that page use a template `archive-{post_type}.php`. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "custom post types, pages"
} |
Resizing to bigger proportions as original not working
E.g. if I use this code inside functions.php
add_image_size( 'featured-extra-image', 600, 300, true );
and the uploaded image is only 550px width, it does not resize it to 600x300 px but only to 550x300 px.
How to force WP to resize it to my custom size, even it is bigger than original uploaded image? | When you add the image to the post
1. Select "Full Size"
2. Click "Edit Image"
3. Click the "Scale" button
4. Manually edit the dimensions
5. Save all changes
6. Check to see if "Full Size" has your new dimensions
7. Click "Use as featured image" | stackexchange-wordpress | {
"answer_score": 1,
"question_score": -1,
"tags": "images"
} |
Stop Wordpress removing <script> tags when switching from HTML to Visual (TinyMCE)
Ok, I've seen solutions which go halfway to sorting out this problem, but nothing definitive, and nothing that 100% solves my problem.
Scenario:
* In HTML mode, I add some javascript to a post I'm editing.
* I switch to Visual, then back to HTML, and the tag and all of its content are gone.
How do I stop this from happening? I've tried adding custom code to my functions.php trying to access the extended_valid_elements for TinyMCE, but nothing works.
Please help! | Adding JS to the content is **very, very bad practice** , and it's just asking to be **hacked**.
Add it via a shortcode, or if you really must, use a post meta/custom fields to store the js and display it after the content in your template using `echo get_post_meta($post->ID,'post_javascript',true );` | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 2,
"tags": "tags, tinymce"
} |
How to display BBpress statistics?
This seems like a fairly simple question, and I'm sure I'm overlooking something, but how does one display forum statistics (registered users, posts, etc.)? I see there is a template in the theme compatibility folder called `page-forum-statistics.php` which seems to display some of this info but I'd like it to display in the footer on the homepage.
Is there something I'm missing? Or do they have to be called manually? | It seems BBPress got a function called `bbp_get_statistics()` read source. You can throw an array of `$args = array();` in it.
You also have a filter to modify the output:
apply_filters( 'bbp_get_statistics', $statistics, $args );
_Disclaimer: I'm no BBPress expert - I haven't even installed it somewhere, just found this via google._ | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "bbpress, statistics"
} |
How can I setup custom templates for a meta-data query
I have a post-meta field for Neighborhood. I want to setup a url like: url.com/neighborhood/NEIGHBORHOOD-NAME
I know this would typically be handled by a CPT or custom taxonomy but it has to be done with a post-meta field in this case.
I also want this to use a custom template, not one of the standard templates.
I can easily link to the url but it returns a 404 page because nothing is associated with it.
Wordpress doesn't know what content to grab. Any ideas? | There's the core function `add_*/get_query_arg()` that you can use to append stuff to the query and retrieve it.
So simply add a link somewhere, that points to your custom post types single.php template
single-{$custom_post_type}.php
Then append the query arg which would be `?wpse_meta_key=wpse_some_val` and then do a switch on top of your template:
if ( 'wpse_some_val' === get_query_arg( 'wpse_meta_key' ) )
{
get_template_part( 'special_query_template' );
}
else
{
// do default stuff
} | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "templates, post meta"
} |
Wordpress Admin Tables in Post View
I'm trying to add my custom Wordpress table (similar to the links table) into the "New Post" view of a custom post type. I hope that makes sense. | Ok. So the only way that I found to do this is wrap the WordPress table in a custom meta box. This is not ideal, because I would like to see the table span the entire container, but it works. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "posts, admin, wp list table"
} |
Create a permalink for a post's attachments
I'm trying to create a custom permalink structure. I'd like to have a custom page which displays each post's image attachments, using the following structure:
_www.mysite.com/hello-world/images_
If anyone visited this URL, it would serve up a page of images that are attached to hello-world. It's kind of like having a subpage I guess, but I'd want it for posts (not pages) and I'd want it to be automatic.
I have a template .php coded-up for this purpose; it will grab all attached images and display them. I'm just looking for a way that people can get to it via the above URL structure.
I'm not sure how to go about doing this ie. if there's an easy way in Wordpress, or if I need to look into Rewrite rules in my .htaccess. Any thoughts would be appreciated, thanks - | You could achieve that by adding a rewrite endpoint via `add_rewrite_endpoint`.
This post from a WordPress developer has a good explanation of how they work. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "permalinks, attachments"
} |
How to repeat a loop after 4 posts
> **Possible Duplicate:**
> How to mark every 3rd post
> Style every four posts differently
Is it possible to repeat this loop after four posts? (post 5 = post 1 css, post 6 = post 2 css, etc..)
<?php
if (have_posts()):
while (have_posts()) :
the_post();
$count++;
if ($count == 1) : ?>
<div>Styled post 1</div>
<?php elseif ($count == 2) : ?>
<div>Styled post 2</div>
<?php elseif ($count == 3) : ?>
<div>Styled post 3</div>
<?php elseif ($count == 4) : ?>
<div>Styled post 4</div>
<?php else : ?>
<?php endif;
endwhile;
endif; ?> | Assuming that you're only using the counter to decide what style to use, the easiest way to achieve what you want would be to reset the $count variable once it gets to 4.
<?php elseif ($count == 4) : ?>
<div>Styled post 4</div>
<?php $count = 0; ?>
<?php else : ?> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "posts, loop"
} |
Script to run at completion of Page Loading
On the home page I a have 2 lines of code I would like to run in JavaScript.
Where should I put these two lines of code.
Does WP have a specific way to do this. Or should I just pick the last .js file that loads and add it there? | yes, WordPress has a function for loading javascript files: <
the last argument takes either true or false to load in the footer | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 5,
"tags": "javascript"
} |
Highlight comments made by registered users of the site
How can I highlight comments that have been made by registered users of my blog? | Comments that are left by registered users are given the class "byuser" - so you can create a style in your theme's stylesheet to point out these comments. Something like:
.commentlist li.byuser {
background:#FF0000;
}
That would make the background of users' comments red (insert a more appropriate color).
If you are not using a custom theme, I'd recommend creating a child theme to do this. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "comments, templates, css, conditional tags, registered"
} |
running function during post save and adding variable to post meta
I'm creating a page that is pulling info from Vimeo using oEmbed. Everything works fine but the multiple calls to vimeo are causing page load issues (obviously).
I was wondering if it would be possible to make the same oEmbed call when the post is being created/saved, then populating various post meta variables with the information. | Yes, most definitely. Take this skeleton code below as a base for a function that would do what you want, and place it in your functions.php:
function your_vimeo_meta_function ($post_id) {
// some verifications first
if ( $post_id == null || empty($_POST) )
return;
if ( !isset( $_POST['post_type'] ) || $_POST['post_type']!='post' )
return;
if ( wp_is_post_revision( $post_id ) )
$post_id = wp_is_post_revision( $post_id );
global $post;
if ( empty( $post ) )
$post = get_post($post_id);
/*
* do your vimeo stuff here
*/
update_post_meta($post_id, 'your_vimeo_key_name', $your_vimeo_value);
// if this key doesn't exist, it will be created. If it exists, it will be updated
}
add_action('save_post', 'your_vimeo_meta_function', 12 ); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "post meta"
} |
WP_Query() and get_posts() can't handle over a thousand posts?
So I have a search function that just fetch custom posts and return them as a list.
function search() {
// post query args
$args = array(
'post_type' => 'post_type',
'posts_per_page' => -1,
'post_status' => 'publish'
);
// markup
$markup = '<ul>';
//the loop
$loop = new WP_Query($args);
while ($loop->have_posts()) {
$loop->the_post();
$markup .= '<li></li>';
} wp_reset_postdata();
$markup .='</ul>';
echo $markup;
}
This works with under a hundred posts but with over a thousand posts, it doesn't. It just throws an error. If I switch to get_posts(), the same thing happens. Is there another way I could this? | If it's not timing out, you're likely running out of memory. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "wp query, get posts"
} |
How to cache custom pages using W3 Total Cache?
Some posts are requested through Ajax.
<?php
// Filename: ajax-posts.php
require_once "wp-load.php";
echo my_get_post($_GET["id"]);
?>
How can I make theese Ajax requests cacheable by W3 Total Cache? | Short answer: You can't. Getting W3 Total Cache to talk to a non-WP call in manor listed above isn't (easily) possible. I completely agree with @allenericr comments. The Transients API is very straight forward and quite simple to implement. In addition, @allenericr, comment on using admin-ajax.php is also spot on. It's not sure it's best practices to just include wp-load and call it good (sounds like a big security hole). | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 3,
"tags": "plugin w3 total cache"
} |
How can I add an "ALL CATEGORIES" entry in wp_dropdown_categories?
I want to let the users search posts by categories. So I use wp_dropdown_categories to build a drop-donw list with all categories. Trouble is I want to allow them to set this to "ALL CATEGORIES" as well. So how can I add another entry in the drop-down list? Thanks, | **Should be easy to do**
(check the codex: wp dropdown categories)
<h2><?php _e('Categories:'); ?></h2>
<div>
<?php wp_dropdown_categories('show_option_all=ALL CATEGORIES&show_count=1&hierarchical=1'); ?>
</div>
**p.s**
if you want to wrap with translation this is the way:
<h2><?php _e('Categories:'); ?></h2>
<div>
<?php wp_dropdown_categories('show_option_all='.__('All Categories', 'your_text_domain').'&show_count=1&hierarchical=1'); ?>
</div> | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "categories"
} |
Is there a reason why Pages are not publicly_queryable?
I am building a segmented search (by post type) with the ability to filter to a specific post type and realized pages were not publicly queryable. What I know I can do is the following:
function fix_page_query() {
if ( post_type_exists( 'page' ) ) {
global $wp_post_types;
$wp_post_types['page']->publicly_queryable = true;
}
}
add_action( 'init', 'fix_page_query', 1 );
which does allow them to use `post_type` as a query var, but are there any shortcomings to doing this? Was there a specific reason they are not by default? I did see this ticket about the subject, but could not decipher a clear answer. Thanks! | Just to close this one out - you can set Pages to be `publicly_queryable` using the function provided above. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "wp query, pages, query"
} |
Disabling the Admin Bar | Where does code go?
I need to disable the admin bar for subscribing user ( not the admin).
I found these code snippets here on SE.
* Best Option
* Another Option
However I don't know what file to edit or where to put the code exactly. I have experience with PHP, HTML, etc. Just not so much with the WP (3.4.2).
Thanks. | This would go in your theme's `functions.php` file. This is a small tweak, but things to remember are that:
* If you ever change your theme, you'll need to remember to copy this over to the new theme
* It'd be better to put these types of "system tweaks" into your own plugin, which you can read about here
Go with this one | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "admin bar"
} |
Exclude Author by ID
How can I exclude authors by ID from this:
<?php
//displays all users with their avatar and their posts (titles)
$blogusers = get_users_of_blog();
if ($blogusers) {
foreach ($blogusers as $bloguser) {
echo '<div class="content-slider-body">';
$user = get_userdata($bloguser->user_id);
echo '<div class="grid col-140">' . get_avatar( $user->ID, 128 ) . '</div>';
$args=array(
'author' => $user->ID,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
//echo 'List of Posts for ' . user->user_firstname . ' ' . $user->user_lastname;
while ($my_query->have_posts()) : $my_query->the_post(); ?> | Where `$that_user_your_filtering_out` is the user/author ID you wan't to filter out, make this modification to your loop
foreach ($blogusers as $bloguser) {
// modification starts here
if($bloguser->user_id == $that_user_your_filtering_out){
continue;
}
// modification ends here
echo '<div class="content-slider-body">';
$user = get_userdata($bloguser->user_id); | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "author, exclude, list authors"
} |
Use MarkItUp as editor and not the default
Does anyone know if it is possible to use this editor as my WordPress editor and not the default. If so, how? | Yes, It is possible ... there is a good article on DigWP \- which points out one warning that MarkDown is not reversible (ie articles written in Markdown get saved in Markdown so if you ever turn off MarkDown, then you're left with goo on your screen).
There is a MarkitUp plugin on the WordPress.org ... While the project has a warning about its age, I think you could find it still works.
Have a search on WordPress.org there are other markdown plugins
And a note from me about compatibility - you may find it easier to just use a MarkDown editor on your computer / tablet / whatever and then just export / cut n paste the finished product into your WordPress post or publish with a blog editor tool like MarsEdit. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "editor, markdown"
} |
How to get user contact info
In the user profile in Dashboard I have a section 'Contact info' containing email, URL, aim, yahoo, jabber. I would like to build a widget and output that user info within the widget. What function should I use to get just the contact info of a user? | It sounds like you're after the get_userdata() function.
As a basic example, you could retrieve a users email like this:
<?php
if ( $user_id ) {
$user = get_userdata($user_id);
echo 'Users Email is: ' . $user->user_email;
}
?> | stackexchange-wordpress | {
"answer_score": 3,
"question_score": -3,
"tags": "users"
} |
Modify the_content after the more tag
I have created a custom plugin that pulls video and images out of a post and puts them into a nicely formatted set of galleries. The only problem is that the plugin doesn't allow me to put a video or image before the more tag without creating a mini gallery. Is there a name or way to adjust my plugin to make it only read the_content that comes AFTER the more tag? | I think you can use the `get_extended( $post )` function; that returns an array with different parts of the content. See this example which works inside the Loop:
$content_arr = get_extended( get_the_content() );
var_dump( $content_arr );
echo $content_arr['main']; //Display the part before the more tag | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 2,
"tags": "plugins, the content, read more"
} |
Register new user in the frontend
I hava a big form and when a user fill it I need to create a new user in Wordpress from there.
Its posible to create and user from the frontend and add some custom information?
Thanks | Yes, yes you can.
The relevant functions to do this are:
* `wp_create_user` Creates a user given a user/pass/email
* `wp_insert_user` Creates or updates a user given user/pass/email
* `add_user_meta` Adds User Meta ( same as Post Meta/Custom fields but for users rather than posts )
You'll find examples on how to use those functions, and links to more possibly relevant functions. Use these functions in your form handling code on submission, make sure to escape all values entered. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "users, front end"
} |
Front-end login problem: requires re-authorization when accessing dashboard
I have created front-end login form that allows users to login from front-end. However, when trying to access Admin section (dashboard), WP's default login form is displayed and user authorization is required.
$user_arr = array( 'user_login' => $u_name, 'user_password' => $u_pass, 'remember' => $u_remember );
$sign_user_on = wp_signon( $user_arr, true );
Any idea? | OK, I've got it! According to wp codex, second parameter of wp_signon() function refers to whether to use auth cookie or not. So if you use
wp_signon( $user_arr, false );
...re-auth will not be required. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "login, front end"
} |
Allowed memory size exhausted. WordPress side solution
I'm getting a well known error from the question title. The problem is, website is running on a shared server and I don't have access to php.ini file.
I've set `php_value memory_limit' inside .htaccess to higher value.
I've set `WP_MEMORY_LIMIT` inside wp_config.php to higher value.
`phpinfo()` says that `max_execution_time` is set to 30 and `safe_mode` is off.
My question is, can I change something inside my WordPress installation to make my website work? I've read about `set_time_limit`. Can it help me somehow, or the only solution is to move onto another server? | You can simply create a text file and call it php.ini . Make sure the file has the text encoding "Unicode no BOM", as that will work best for both linux and windows. Use an FTP client to make a new file on the server and that will generate a file with the correct permissions and text encoding.
Put just this line in it:
memory_limit = 64M
_But that will not raise your memory allocation_ if the host doesn't allow individual php.ini files in accounts which override the server php.ini, which sounds like is the case, since they don't allow .htaccess to override the server. And it's doubtful they will change your php.ini file for you.
Usually bumping memory in wp-config.php is sufficient, and there's no need to edit .htaccess. Many hosts allow individual php.ini files. You're on a very restrictive host. I'd change hosts. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "uploads, memory, fatal error, limit"
} |
Disable WordPress cache programmatically on a request
How do I turn off the WP Super Cache & W3 Total Cache functionality programmatically? For instance, I neither want to make it use the cache on some requests nor cache the output of the request, do they support that using filters? I couldn't find anything useful in their documentation. | Easiest way to do this was to define a constant programmatically:
// Tell WP Super Cache & W3 Total Cache to not cache WPReadable requests
define( 'DONOTCACHEPAGE', true ); | stackexchange-wordpress | {
"answer_score": 7,
"question_score": 5,
"tags": "plugin w3 total cache, cache, plugin wp supercache"
} |
Where does the gallery shortcode gets its attachments from?
I know that media are an attachment post type that are children to a post, but how are galleries stored in WordPress? | This completely depends on how your gallery shortcode looks like.
If you replaced it with something custom, then you'll have to take a look at the plugin (or the theme).
The default gallery shortcode gets it from a query:
$query_args = array(
'post_status' => 'inherit'
,'post_type' => 'attachment'
,'post_mime_type' => 'image'
,'order' => $order
,'orderby' => $orderby
);
Then it decides to add additional args for either `include` or `exclude`.
Here're the 3 scenarios that add the additional/non-shared arguments.
'include' => preg_replace( '/[^\D,]+/', '', $include )
'exclude' => preg_replace( '/[^\D,]+/', '', $include )
// default
'post_parent' => $id | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "attachments, gallery, media library"
} |
include <p> content within conditional statement?
I have a gallery page wherein there are multiple individual galleries/sub-pages. I handle this function by using-
<?php
if( is_page( 39 ) ) {
echo do_shortcode('[nggallery id=1]');
} else {
}
?>
I'm wondering, is there a way to include page specific content in that? For example, if that code is used to show A's gallery, how can I include A's bio info within that statement(using `<p>`)? | You can do that via `echo`, just place it on a new line inside the if conditionals braces `{` and `}`
e.g.
if(this statement is true)
{ // <- do everything between here
/*
stuff that happens if the statement is true
*/
} // <-- and here
else
{
// stuff that happens if the statement is not true
}
So you could do this:
if( is_page( 39 ) ) {
echo do_shortcode('[nggallery id=1]');
// add more stuff here, e.g. echo "<p>Bio info etc</p>";
echo "<p>Bio</p>";
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "php, conditional content"
} |
Post Format Link Validation Error
For link post formats to appear in my archive.php I'm using the following code:
<a href="<?php echo wp_trim_words( get_the_content(), 100 ); ?>">
<?php the_content(); ?>
</a>
**Of course, this creates a validation error due to a`<p>` being inside an `<a>`. I'm seeking a solution to fix this validation error.**
This is the most intuitive way I can dream up for easy link post formats (of course, I'm open to suggestions). | You can temporarily remove the filter that adds paragraph tags:
// remove the filter
remove_filter( 'the_content', 'wpautop' );
// output content
the_content();
// add the filter again
add_filter( 'the_content', 'wpautop' ); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "the content, post formats, validation"
} |
How do you set the default page in WordPress?
Assuming I have a page with the URL ` that I want to set as the default, what do I need to do so that when a user types in just ` they see that page?
Is it a simple configuration option or do I need a plugin of some sort? | From your dashboard, visit `Settings > Reading` and select and for the first option, `Front page displays` select `A static page (select below)` and then select that specific page (and then another page you create for your posts to show up on if you would like). | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "pages, configuration, customization"
} |
Hard Define Custom Field Value
Is it possible to hard define a custom field value with a function?
As in, no matter what WordPress will always set the value of 'some_meta' => 'this' | Instead of directly grabbing the meta, wrap it in a function, then you can provide a default, or, comment out the innards and just return "this" | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom field, post meta"
} |
Check if any users are logged in before running update
Before I update a Wordpress install (including the theme and various plugins) I wanted to ensure no one is logged in and editing the site.
Is there a way to do this?
Thanks! | Because of the stateless nature of webpages, you can't do this without a high margin of error.
You can install a plugin to log last visits for logged in users, but that will not tell you if they're editing posts or if they loaded a page then went to lunch or shut down their computer.
Instead, use maintenance mode and arrange beforehand when to update the site. Anybody who wants to make edits or modifications at those times knows theres a chance it will be lost and they do so at their own risk. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 3,
"tags": "updates"
} |
Is it wise to delete post revisions and autosaves from database?
I'm just wondering is it wise to delete all post revisions and autosaves from database every once in a while?
I mean they take a lot of database space and apparently have no use after the post has been published. | It all depends on your workflow. If you have no use for the post revisions and autosaves then disable them in wp-config and WordPress will clean them up on its own. You may also prefer to limit how many you keep at once.
Also the space they take up is unlikely to be of a great impact itself unless you're running on a tiny tiny server
Don't go deleting them manually through the database. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 3,
"tags": "database, revisions, autosave"
} |
Delete a specific item menu when I deactivate my plugin
When I activate my plugin (`register_activation_hook`), I add a new specific page and a corresponding item menu in the custom menu. No problem here.
When I deactivate my plugin (`register_deactivation_hook`), I delete the specific page but I don't know how to delete the corresponding item menu from the custom menu? | WordPress automatically handles that if you force delete the page instead of thrashing it. The following function takes a parameter to force delete -> `wp_delete_post( $postid, $force_delete )` | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "plugin development, menus, customization"
} |
Allow all file types for upload
I'm using Wordpress 3.4.2 for a private blog, i.e. one on which only I can post. Now, Wordpress prevents me from uploading certain file types (like C# source files). As far as I understand it, there's a white-list that defines what can be uploaded.
Is there a plugin that can extend - or better, even disable - this white-list?
All other answers tell me I should edit my theme but I'd rather have a plugin for that (so that I don't need to edit all my themes).
Also, I found this plugin but, again, it requires me to edit some file on my server (that's probably overwritten when the plugin is updated).
So, is there anything else? | Unfortunately, toscho's answer doesn't work - at least not in Wordpress 3.4 and above.
The correct solution is the following:
#
# For this, see: wp-includes/capabilities.php > map_meta_cap()
#
function wpse_6533_map_unrestricted_upload_filter($caps, $cap) {
if ($cap == 'unfiltered_upload') {
$caps = array();
$caps[] = $cap;
}
return $caps;
}
add_filter('map_meta_cap', 'wpse_6533_map_unrestricted_upload_filter', 0, 2); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 9,
"tags": "plugins, uploads"
} |
Add share links to all blog posts on homepage
I need to figure out a way to add share links to each blog post on the homepage. This way users can share specific posts without actually going into the post. Is there a way to do this easily through a WP plugin?
The only tricky thing to me is they will be sharing URLs from pages which they are not actually on so I'm unsure how to proceed with that.. does anyone have any ideas? | There's an option to do this in Jetpack, if you have sharing tured on. Just click on "Front Page, Archive Pages"... etc
!jetpack sharing
Then it'll show up on the homepage, for example on my homepage:
!enter image description here | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugin recommendation, social sharing"
} |
Website loading slowly - Advanced Custom Fields images
I'm currently using `get_field` with Advanced Custom Fields plugin (see here) to get a single image for search results. The end result is that these pages are loading slow, as I believe this is due to MySQL returning the whole array of all images in the gallery for the specified page, which ends up being huge.
To load the image, I am currently doing the following:
$image = get_field('house_photos');
if ($image) {
echo '<img src="' . $image[0]['sizes']['house_search'] . '" />';
}
Is there a more efficient way just to get this single image without requesting the entire array? | I have managed to work it out - the function was leading to a lot of queries, so I rewrote it as follows:
$housePhotos = get_post_custom_values('house_photos');
$housePhotos = explode(';',$housePhotos[0]);
preg_match_all('`"([^"]*)"`', $housePhotos[1], $results);
$imageURL = wp_get_attachment_image_src( $results[1][0], 'house_search' );
if (!empty($results[1][0])) {
echo '<img src="' . $imageURL[0] .'" alt="" />';
} | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "custom taxonomy, images, advanced custom fields"
} |
Change post title during post saving process
My theme and Qtranslate plugin have a conflict and cause many issues on my website's post titles. I cannot trace what causes the issue and I thought that I could handle the title saving myself instead.
I would like to be able to change post title that wordpress uses when saving a post from backend.
How can I do that? | You can hook into `wp_insert_post_data` and change things.
<?php
add_filter('wp_insert_post_data', 'wpse67262_change_title');
function wpse67262_change_title($data)
{
$data['post_title'] = 'This will change the title';
return $data;
}
Obviously you're going to have to some checks and stuff so you don't change every post title. That hook will also fire every time the post is saved (adding a new post, updating, trashing a post, etc) and for every post type. `$data` is an associative array with every column you'd find in the `{$wpdb->prefix}_posts` table as keys. So if you just wanted to changed posts:
<?php
add_filter('wp_insert_post_data', 'wpse67262_change_title');
function wpse67262_change_title($data)
{
if('post' != $data['post_type'])
return $data;
$data['post_title'] = 'This will change the title';
return $data;
} | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 1,
"tags": "admin, title, customization"
} |
Display all posts starting with given letter?
I'm trying to build Wordpress based dictionary, basically it will have 26 pages (one for each letter):
> A B C ... X Y Z
And every page will display all posts starting with given letter, so after opening the "A" page it should display something like:
> aback
>
> abacus
>
> abalone
>
> (...) azure
I was thinking about custom post types at first, but creating and maintaining 26 custom post types sounds like an overkill.
What will be the most efficient way of sorting posts like that? Database query, splitting loop with PHP? I am aiming for 1000s of posts (yes, it has to be Wordpress :)). | Don't use post types, use taxonomy terms!
On save, set the object terms in an A-Z taxonomy, using the first letter of the post title. Make sure to force upper or lowercase for consistency. Make sure to create terms for each letter of the alphabet, and a term for numbers and other non alphanumeric symbols.
This should be faster than querying the first letter of each post title, and it gives you a taxonomy you can do more stuff with, like tag clouds, or term lister widgets! It's also a much faster way of determining which letters have associated posts and how many, without forcing the database to manually count, and you can use standard WordPress term APIs out of the box to do more complex queries, like posts starting with vowels | stackexchange-wordpress | {
"answer_score": 10,
"question_score": 12,
"tags": "custom post types, loop"
} |
Beginner Resources for Roots Theme Framework
I'm building a WordPress theme, using Roots as a starter theme. Are there any tutorials telling me how to build a theme off of Roots? I've worked with starter themes before, but this one is a whole new monster. I don't know what I'm supposed to edit, and what I'm not supposed to edit. | Roots theme comes with a nice set of Docs < but if you want to make sure you don't overwrite something important or want to keep updating your theme then you should create a child theme. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -1,
"tags": "framework, theme roots"
} |
Possible to add "Even/Odd Classes" to image attachments via wp_get_attachment_image?
Im looking for a way to add an alternating even/odd class directly to each image attachment when its outputted via my function below:
<?php
function nongallery_img_slide( $post_id = null ) {
if ( $post_id == null ) return;
$images = get_posts(
array(
'numberposts' => -1,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_parent' => $post_id,
'orderby' => 'menu_order',
'order' => 'ASC',
//'exclude' => get_post_thumbnail_id( $post_id )
)
);
if ( count( $images ) > 0 ) {
foreach ( $images as $image ) {
echo wp_get_attachment_image( $image->ID, 'photogallery-img' );
}
}
}
?>
Can this be done?
Thanks! | `wp_get_attachment_image()` has a fourth parameter for custom attributes. Use it:
if ( count( $images ) > 0 ) {
$i = 0;
foreach ( $images as $image ) {
echo wp_get_attachment_image(
$image->ID,
'photogallery-img',
FALSE,
array (
'class' => 'attachment-photogallery-img '
. ( ( $i++ % 2 === 0 ) ? 'even' : 'odd' )
)
);
}
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "attachments, images"
} |
Why is jQuery not working properly?
I've enqueue'd jQuery from Google and it's displaying in the source code but no matter where I put my scripts they don't seem to work.
Here is the site in question - <
Near the bottom of the page, there are a couple of testimonials, these should appear one at a time in a slideshow, but, as you can see that's not happening.
I'm not a jQuery master by any means but I can hold my own and I've never had any issues before...
Any help would be greatly appreciated | Upon first glance, both cycle.js and your javascript code need to be in the page AFTER jQuery is included. Right now, they are before so they both generate errors that `jQuery is not defined`. Make sure that jQuery is included first before you try to use jQuery.
In the future, I would also strongly suggest that you always check your browser's error console or your debuggers console for javascript errors as this is one of the first places to look when things are not working for a clue. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -2,
"tags": "jquery, scripts"
} |
Collapse subcategories in post edit screen
Is there a plugin to collapse/expand subcategories in the post edit screen?
In other words, I'm looking for analog of CMS Tree Page View plugin, but for categories. | Found it!
Intuitive Category Checklist | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "categories, admin, plugin recommendation"
} |
Replace default avatar
I've searched google quite a bit and every site has the same filter but it doesn't seem to be working for me. Not sure if it's my setup or just old code.
I'm trying this:
add_filter( 'avatar_defaults', 'newgravatar' );
function newgravatar ($avatar_defaults) {
$myavatar = get_bloginfo('template_directory') . '/img/blog_noPhoto.jpg';
$avatar_defaults[$myavatar] = "Default Avatar";
return $avatar_defaults;
}
However, when I look at my template code it's adding < before the full URL of the image. I am using the "User Avatar" plugin but it seemed to be the same if I disabled that. | I figured this out. The server I am working on doesn't have access to the outside. So, even though the image is in my template folder, the gravatar.com call in front of the image path was causing the error. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "avatar, gravatar"
} |
How to add a custom font in a theme
I want to add a custom font into my theme. Please let me know if this is just as simple as uploading the font to a new folder named "fonts" and then changing the css and renaming the font-family property there or it's somewhat different procedure. I am not sure about it. Please help me. | To use a custom font, simply upload the font to your theme folder and then add a CSS `@font-face` declaration to the top of your theme's `style.css` file pointing to the new font:
@font-face {
font-family: CustomFont;
src: url('CustomFont.ttf');
}
You can then reference that custom font in other CSS styles, for example:
.entry-content { font-family: "CustomFont", sans-serif; } | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "add theme support"
} |
How to update custom image sizes?
I've added multiple custom image sizes using the `add_image_size` function. The problem here is when I need to update the proportions of these sizes, the changed sized won't apply.
My guess is that wordpress inserts those sizes in the database and it fails to update them upon code change.
How can I update the image size? | With this plugin you can choose which specific image sizes should be updated:
AJAX Thumbnail Rebuild
Or you can use Simple Image Sizes, too.
More infos on wpbeginner. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "post thumbnails, images"
} |
How to log out without confirmation 'Do you really want to log out?"?
Right now when I log out via:
<a href="<?php bloginfo('url'); ?>/wp-login.php?action=logout">Log out</a>
it redirects me to the page where I need to confirm the log out.
How to eliminate the confirmation and redirect to the homepage after logout? | This happens because you are missing the neccessary nonce in the URL, which is being checked in `wp-login.php`
case 'logout' :
check_admin_referer('log-out');
...
Use `wp_logout_url` in order to retreive the URL including the nonce. If you want to redirect to a custom URL, simply pass it as an argument.
<a href="<?php echo wp_logout_url('/redirect/url/goes/here') ?>">Log out</a>
You could also use `wp_loginout` which generates the link for you including translation:
echo wp_loginout('/redirect/url/goes/here') | stackexchange-wordpress | {
"answer_score": 45,
"question_score": 27,
"tags": "logout"
} |
Get page content using slug
I'm trying to get page content when I only know the slug string.
Is there a function for this, or an easy way to do this or is this a case of doing it via SQL?
Thanks very much | Use `get_posts()` and the parameter `name` which is the slug:
$page = get_posts([ 'name' => 'your-slug' ]);
if ( $page )
{
echo $page[0]->post_content;
}
Be aware that the post type in `get_posts()` defaults to `'post'`. If you want a **page** use …
$page = get_posts([
'name' => 'your-slug',
'post_type' => 'page'
]);
If you want **all** public post types (except attachments) set the post type argument to `'any'`. Then you could get more than one result because slugs are not unique across different post types. | stackexchange-wordpress | {
"answer_score": 36,
"question_score": 14,
"tags": "plugin development, php, pages, slug"
} |
CPT archive page - show one post from each taxonomy term
Basic loop question:
I have a custom post type with a custom taxonomy and 3 terms.
On the archive page (archive-custom_post_type.php), I would like to display one post from each taxonomy term.
Is this possible within the standard `if (have_posts()) : while (have_posts()) : the_post();` loop, or do I have to make separate loops for each one? | So I went ahead and did the multiple loop thing, as I had done before. I'm always interested in seemingly cleaner/simpler solutions, but sometimes you just have to keep moving. This is the code I'm using:
<?php
$args = array(
'post_type' => 'projects',
'project_category' => 'websites',
'orderby' => 'menu_order',
'showposts' => 1
);
$posts = get_posts( $args );
foreach ($posts as $post) : setup_postdata($post);
?>
// Get the post stuff here
<?php endforeach; wp_reset_postdata(); ?>
I can repeat this as needed, changing the taxonomy (in this case the taxonomy is project_category) term each time.
Please feel free to comment an tell me if this isn't a good way to do it. I'm far from an expert at the PHP side of WordPress. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "custom post types, categories, loop, custom post type archives, advanced taxonomy queries"
} |
Two exact templates, sidebar showing in one but not the other
I'm using the Roots WP Theme and for some reason when copy pasting the page-custom.php to create a home page template. The new homepage template is showing the sidebar but not the original page-custom template even though the two template files are exactly the same at this moment.
Can anyone explain why this might be? | Look at the `config.php`:
function roots_display_sidebar() {
$sidebar_config = new Roots_Sidebar(
/**
* Conditional tag checks (
* Any of these conditional tags that return true won't show the sidebar
*/
array(
'is_404',
'is_front_page'
),
/**
* Page template checks (via is_page_template())
* Any of these page templates that return true won't show the sidebar
*/
array(
'page-custom.php'
)
);
return $sidebar_config->display;
}
So if your _home_ is not the front page the sidebar will be displayed. There is probably a way to adjust these settings per filter, but you can also just change the first array to …
array(
'is_404',
'is_front_page',
'is_home'
),
… to hide the sidebar. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "templates, theme roots"
} |
How to order custom post type by multiple custom fields?
How to display posts with 'Event' custom type ordered by 'Start_Hour' and then by 'Start_Minute'?
'Start_Hour' and 'Start_Minute' are numeric custom fields.
I tried this, but it doesn't work:
$args = array(
'post_type'=>'Events',
'orderby' => 'meta_value',
'meta_key' => 'Start_Hour Start_Minute',
'order' => 'ASC'
);
$loop = new WP_Query( $args ); | Thanks to Bainternet I found the solution:
function orderbyreplace($orderby) {
return str_replace('menu_order', 'mt1.meta_value, mt2.meta_value', $orderby);
}
and...
$args = array(
'post_type'=>'Events',
'orderby' => 'menu_order',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'Start_Hour',
'value' => '',
'compare' => 'LIKE'
),
array(
'key' => 'Start_Minute',
'value' => '',
'compare' => 'LIKE'
)
)
); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 6,
"tags": "custom post types, wp query"
} |
Missing thumbnails
For all the pics I upload to Wordpress I get such a link to the pic:
src='
Anf ofcourse Wordpress does not find it.
But if I change to with the firebug:
src='
Wordpress displays the picture. Where I should look for the problem? Thanks. | Seems to me you use a WordPress theme which uses some kind of php library to resize images. You should really use WordPress default `add_image_size()` and `wp_get_attachment_image` but if you were the one who created the theme you would already know that.
There are 3 things you can do:
* find a new theme that is not **that** outdated
* dive into `mytheme/thumb.php` and find out whats going on and where it fails
* update the theme wherever it uses thumbnails and/or different image sizes with the above default WP functions | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "post thumbnails"
} |
local WAMP admin user has lost privileges
I have a Wordpress 3.4.1 installed on a local WAMP server.
I am in the process of upgrading it to a network, but I now realise my admin account has no admin privileges:
1. No access to the Updates page (update-core.php) - I receive "You do not have sufficient permissions to access this page."
2. No ability to install plugins.
3. No ability to edit users.
4. No ability to go to Tools > Network Setup - same error as above.
* The **wp_capabilities** of my user account is **a:1:{s:13:"administrator";b:1;}**
* The **wp_user_level** is **10**
What is wrong here?
**Update** \- I added another admin account using PHPMyAdmin following this tutorial, but I receive the same symptoms for this 2nd admin account. | I've just done a new install of a newly download zip file, and the installation process stops at:
This page is blank, and nothing progresses.
I now recall this happened on my previous installation also.
If I refresh this page, I receive a message: "Already Installed You appear to have already installed WordPress. To reinstall please clear your old database tables first."
I can elect to log in from here, and doing so presents me with the ability to install Plugins, which I can't do on my other installation. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "admin"
} |
delete category name in the pages
I'm looking for a way so that I can delete category's name in the pages.
I tried to find something for category in index.php but I couldn't find anything.
Please help me to solve this problem.
Thanks in advance | _**What theme are you running?_**
Are you referring to **Pages** or **Posts** because they are two different **types** or rather, what we call **Post Types**.
* **Pages** are normally controlled via your `page.php` template file
* **Posts** are normally controlled via your `single.php` template file
Commonly you will find category and tag functions in your `single.php` file, but calls to such functions are not strictly limited to a `single.php` file. They can in fact be used in multiple theme files.
So for example,
* if you are viewing a **Single Post** , then look within `single.php`
* if you are viewing a **list of your Posts** , then look within `archive.php`
You will be looking for template tags such as,
<?php the_category(); ?>
or...
<?php the_tags(); ?> | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "categories"
} |
Nonce best practices: hidden input vs. wp_localize_script?
I noticed while looking at the HTML of an edit page that WordPress uses a lot of hidden input elements for storing nonces. Is there a significant advantage to using either this style of storing nonces for AJAX use or using those stored via the `wp_localize_script` style? | Depends, will the form work with AJAX turned off?
If so use an input and degrade gracefully.
Otherwise, define nonces used by JS using JS for consistency, and to prevent grabbing stuff from the DOM | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 3,
"tags": "nonce, wp localize script"
} |
Using do_shortcode with variables?
Struggling to get the format right for the PHP in this do_shortcode embed using variables from Advanced Custom Fields plugin. I think I've tried every variation on ., ', and ". After reading every resource I could find I'm still no closer.
<?php
$address = get_field('cong_streetaddress');
$city = get_field('cong_city');
$province = get_field('cong_province');
$postalcode = get_field('cong_postalcode');
echo do_shortcode('[pw_map address="'" . $address . " . " . $city . " . " . $province . " . " . $postalcode . "'" width="100%" height="200px"]');
?>
Doing it with just one variable, like so `echo do_shortcode('[pw_map address="'. $postalcode . '" width="100%" height="200px"]');` works fine. | Your syntax is broken, the quote marks do not match. Try to separate data from the shortcode template, and use `sprintf()`:
$shortcode = sprintf(
'[pw_map address="%1$s %2$s %3$s %4$s" width="%5$s" height="200px"]',
$address,
$city,
$province,
$postalcode,
'100%'
);
echo do_shortcode( $shortcode );
That’s much easier to read, and it is harder to create syntax errors. :) | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 1,
"tags": "shortcode"
} |
XML-RPC and post_date
I'm trying to set the post_date via XML-RPC and keep getting an error saying the XML isn't formatted properly. The code goes something like:
$post = get_post( $post_id );
$response = $client->query(
'wp.editPost',
array(
0,
$user,
$pw,
array(
'post_date' => $post->post_date
)
)
);
I'm hitting the same issue with `wp.newPost`. I know the date should be formatted ISO8601 but I'm just having no luck getting it formatted right. | There are a couple of issues here. First of all, `wp.editPost` takes a fourth parameter before the content struct -> the ID of the post you're trying to edit (should be an integer).
Second, you're passing a string for the `post_date`, so the client automatically converts this to a `<string>` tag before sending it to the server ... unfortunately, the server expects a `<dateTime.iso8601>` tag.
You can fix this by parsing the string date and passing an instance of the `IXR_Date` class instead. The client will parse it properly and the server will react appropriately. I've tested the following scenario on my own server:
$date = new IXR_Date( strtotime( $post->post_date ) ); // Parse the date to an IXR_Date object.
$response = $client->query(
'wp.editPost',
array(
0,
$user,
$pwd,
$post_id,
array(
'post_date' => $date
)
)
); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "posts, date, xml rpc"
} |
how to use the slide show of Skylark in showcase?
I created a page and I set the template as _showcase_ and then I went to setting->reading and as a static page I choose my created page.
I'm wondering how I can add slideshows with pictures and sticky posts. I went to documentation in the link but unfortunately I couldn't find anything. | Welcome ... this forum is more suited for WordPress selfhosted not WordPress.com sites.
However ... reading the WordPress.com theme documents it says
> The Showcase page template offers a featured slider for sticky posts. If you’d like a post to appear in the slider, mark it as sticky and assign it a featured image that’s at least 500 pixels wide.
!enter image description here
So please Add a new post and mark it as sticky and add an image. If you're still stuck, try the WordPress.com forums. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "themes, wordpress.com hosting, slideshow"
} |
Pass get_option value to an array
I want to pass get_option value to an array value. This the value that I want to pass to the array.
<?php echo stripslashes(get_option('a')); ?>
and this is what I am trying to do.
<?php $var = array( 'foo' =>'echo stripslashes(get_option('a'));');
Please let me know how can I achieve this. | Use a simple variable to store the value.
$a_val = stripslashes(get_option('a'));
$var = array( 'foo' => $a_val); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "php"
} |
How to add text to comment form #content textarea?
I have a plugin that does validation on user submitted comments. When validation fails, I want to redirect them back to the comment form, and have their comment still appear in the comment box, so they don't have to type it again.
How can I add custom content to the comment form #content textarea? | You can filter `'comment_form_defaults'` to change the `textarea`. You get an array with the default fields as argument:
add_filter( 'comment_form_defaults', 'wpse_67503_textarea_insert' );
function wpse_67503_textarea_insert( $fields )
{
if ( /* your condition */ )
{
$fields['comment_field'] = str_replace(
'</textarea>',
'EXTRA CONTENT</textarea>',
$fields['comment_field']
);
}
return $fields;
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "comments, content, custom content, esc textarea"
} |
Two installs conflicting - Pages redirecting
I have two installs of wordpress on my server.
**Site 1.** mysite.com
**Site 2.** mysite.com/othersite
The first wordpress install is located in mysite.com/wordpress, but is viewable at mysite.com, and the second install located in mysite.com/othersite, and viewable at the same address. I have page slugs activated for both sites.
**Site 1.** works perfect. I can login to both admin panels and they work perfect. On **Site 2.** i can view the index page, but all other pages redirect as follows:
1. redirect to the 404 page of **Site 1.**
2. if a page has a similar name in both sites e.g. mysite.com/contact and mysite.com/othersite/contact, it will redirect to the page on **Site 1.**
My guess is that something in the wordpress core files uses redirection for slugs. But this is a stab in the dark, and i have no idea how to solve it.
Any help with this issue would be very much appreciated.
Thanks | You have to ignore the "otherside" in the htaccess file of your "root" blog.
You can try to add something like that above the (root) WordPress' .htaccess code:
# stuff to let through (ignore)
RewriteCond %{REQUEST_URI} "/otherside/"
RewriteRule (.*) $1 [L]
# | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "multisite, redirect, slug"
} |
Remove Content after <!--more-> tags
Here with the structure of content in text editor
Content Before
<!--more->
Content After
I wanted to remove the "Content Before" in my single post
so instead I have this
Content Before
Content After
I will have the "Content After" on my single post only
Content After
How can I achieve this display? | set the `$stripteaser` parameter to `true`;
the_content('readmore', true);
< | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 0,
"tags": "posts, themes, read more"
} |
How to disable buddypress top mini adminbar
I am having trouble with adminbar in my site. I have buddypress installed on my site. i have disabled wordpress default admin bar using few lines of code. But it still showing i am pretty sure its coming from buddypress. is there any simeple lines of code that can remove top admin bar? I don't want to use plugin.
Thanks in advance for help. | write this code in config.php
This file is located in the root directory.
** THis Will Remove disgusting Buddypress Top Admin Bar. Add this line of code at last of the previous codes and you are done */
define( 'BP_DISABLE_ADMIN_BAR', true ); | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -1,
"tags": "buddypress"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.