INSTRUCTION
stringlengths 11
999
| RESPONSE
stringlengths 0
999
| SOURCE
stringlengths 16
38
| METADATA
dict |
---|---|---|---|
Multiplile values checkbox or select in custom meta box
I have followed the great answer by Jan Fabry in this question .
How to make multicheck for post/page meta box
this works great. My question though would be , what if someone WANTS a serialized value (array e.g. :"banana,apple,grapes" in ONE field ? ) and not separate values ?
It is strange how in all the tutorials, example, and classes, everyone ignores multiple selection (also in select list) | In his answer , Jan Fabry made a brilliant solution, but it saves the values one by one (for each his own field )
for your question, we need to "reverse" that , but it is actually easy .
BEFORE lines 409-413 , Jan Fabry made an if-else clause to seperate values into fields and save / update. we do not need it .
Instead , we take the already constructed array and save it as a whole. so you just need to add this instead of the whole bigger clause (and do not forget to drop the ELSE:
if ( 'multicheck' == $field['type'] ) {
// If it is a multicheck , implode the array and get a string...
$new =implode(",", $new);
}
That´s all . and do not foget to thatnk JAN Fabry for it - not me :-) | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom field, metabox, customization"
} |
How to make a conditional statement that checks if the page is the child of a certain page?
I know that you can use `is_page` to check the current page. How to check if the current page is the child of a certain page? | global $post;
if($post->post_parent=='certain page'){
/// Her goes your code......
}
Remember 'certain page' is your parent page id. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": -1,
"tags": "pages"
} |
Where this validating message come from?
I wrote a simple form, including text field, textarea, select and some validating by WP_error. When I try to submit the form without filling text field or textarea, I got a popup tip pointing the blank text field, it says "please fill in the field". This is different from the error message I wrote, and I didn't write any ajax for validating-- my validating messages comes after the form submitted and redirected. Is this validating part of WP3.3 new feature? or it's a firefox feature?
Edit: Thanks to joseph, found the reason-- it's html5 new feature-- required attribute
> The required attribute applies to all form controls except controls with the type hidden, image inputs, buttons (submit, move-up, etc), and select and output elements. For disabled or readonly controls, the attribute has no effect. | Could you please show us your code or better yet provide an example? Sight unseen, my preliminary thought based on your description is that you are using some of the new HTML5 form elements and/or attributes. In particular, the `required` attribute would cause the error that you are seeing depending on the browser that you are viewing the page in (Firefox in this case). | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "forms, validation"
} |
How to test site speed?
I'm looking to measure how fast my site is processed. Is there any software out there that can do this?
If it depends on the server, is there any way to monitor the speed from my localhost (purely CPU load?) | I usually use the timer_stop() function via the WordPress 'shutdown' hook, like this:
// Grab the page load time upon WordPress shutdown.
function page_load_time() {
echo '<p>Page load time: '.timer_stop(0, 5).' seconds.</p>';
}
add_action( 'shutdown', 'page_load_time' ); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "performance"
} |
Display gallery on top before content
Is it possible to execute the gallery shortcode before any other content no matter where the shortcode is in the post HTML? | function gallery_first( $content) {
$expr = '/\[gallery(.*?)\]/i';
return preg_replace_callback( $expr, create_function('$matches', 'return do_shortcode($matches[0]);'), $content);
}
add_filter( 'the_content', 'gallery_first', 6); // prio 6 executes this function previous to all other filter functions | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "functions, shortcode, gallery"
} |
Retrieve query var within functions.php
I have query var set using the following filter:
add_filter('init', 'add_query_vars');
function add_query_vars() {
global $wp;
$wp->add_query_var('user_login');
}
I am able to retrieve the query var using `get_query_var('user_login');` in page templates without any hiccup. However, on using `get_query_var('user_login');` within a function inside of functions.php, no value is returned.
What is the correct way to retrieve the query var within a function inside of functions.php? | function gqv() {
echo get_query_var('user_login');
}
add_action('parse_query', 'gqv'); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "url rewriting, query"
} |
Query_vars not working for me
I'm trying to add an all pages link to posts when I have `?all=1` at the end of the URL it's returning "not set", I'm not sure what I'm doing wrong. I've looked here and my code is the same as here: <
functions.php
add_filter('query_vars', 'all_pages' );
function all_pages( $qvars ) {
$qvars[] = 'all';
return $qvars;
}
single.php
global $wp_query;
if (isset($wp_query->query_vars['all'])) {
$remove_pagination = $wp_query->query_vars['all'];
echo "all set";
} else { echo "not set"; }; | My issue was with nginx, specifically:
location / {
index index.php index.html;
try_files $uri $uri/ /index.php;
}
Which I changed `try_files $uri $uri/ /index.php;` to `try_files $uri $uri/ /index.php?$args;` as outlined here which also fixed another issue that I was having with URL parameters. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "wp query"
} |
Auto add content such as pages upon plugin activation?
I'm creating my first plugin and it requires some pages with content to functionally work properly.
I was wondering if it is possible to show a message like "Click here to automatically add the required pages for this plugin" in the wordpress plugins area.
So when the user activates the plugin this message will show and if the user clicks the button a function will run that will add the pages necessary.
Any help in direction most appreciated.
Matt | You can add those without a button:
register_activation_hook( __FILE__, 'my_plugin_install_function');
function my_plugin_install_function()
{
//post status and options
$post = array(
'comment_status' => 'closed',
'ping_status' => 'closed' ,
'post_author' => 1,
'post_date' => date('Y-m-d H:i:s'),
'post_name' => 'Checklists',
'post_status' => 'publish' ,
'post_title' => 'Checklists',
'post_type' => 'page',
);
//insert page and save the id
$newvalue = wp_insert_post( $post, false );
//save the id in the database
update_option( 'hclpage', $newvalue );
}
This function will run when the user installs the plugin. For super smart control you should check if that option already exists and if the id is not 0 (that means failure) | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 1,
"tags": "plugins, plugin development, automation, activation"
} |
Create a User Role with permissions to only upload files to the media library?
Some of the employees at my organization need to be able to upload files to a folder and share a link with others. It’s primarily documents like pictures, pdf’s and Word documents. And instead of creating a completely new File Management System, I was thinking about just using the built-in Wordpress Media Library function for this task.
But my problem is, that I want to create a User Role with permissions to **only** do that and nothing else. If possible, also hide all other option panels, custom post types, etc.
I’ve been reading a bit about User Roles and Capabilities, and founded a Plugin but I think it is a bit much to install a large plugin when it is the only User Role I need to create. And more, I would like to learn some more about it and I think this is a good way to do it.
Any help would appreciate.
Sincere \- Mestika | Install Justin Tadlock's Members Plugin. It has per-configured roles that allow in-depth control over users. If the standard roles don't allow the amount of access control you want, you can create a custom role and assign your specific access level. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "media library, uploads, user roles, user access, capabilities"
} |
Is there a plugin for feedback like Kissmetrics available?
Kissmetrics has a little widget thing that pops up from the bottom-right corner of the page, asking for comments or offering a short feedback survey.
Is there anything like this available for Wordpress for free? I'm on a shoestring and need a free plugin.
I don't mean a subscription-based service: just a plugin that can pop up a little form for feedback/ a survey, collecting and storing the data locally. | At Pagerati.com we recommend the Total Feedback plugin to clients. You can find it at < | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "plugins, plugin recommendation, user interface"
} |
Getting Custom Field value in WP_Query
i am trying to display first post of 3 categs on my index page. so for that i wrote a little function as follows:
function excateg($categ) {
$recent = new WP_Query("cat=$categ&showposts=1");
while($recent->have_posts()) : $recent->the_post();
$imageurl = get_post_meta($post->ID, 'post-img', true);
endwhile;
}?>
Afterwards the Html for showing the image and title and image.. but i am unable to get the custom field as above in $imageurl to get a value..
Help is appreciated! | You need to define the `$post` global variable if you want to access its ID property:
function excateg($categ) {
global $post;
$recent = new WP_Query("cat=$categ&showposts=1");
while($recent->have_posts()){
$recent->the_post();
$imageurl = get_post_meta($post->ID, 'post-img', true);
}
}
Use it after the_post() because that function will set up that variable.
Alternatively you can use the `$recent->post` property instead of `$post->ID`... | stackexchange-wordpress | {
"answer_score": 2,
"question_score": -1,
"tags": "customization, wp query"
} |
Upgraded to 3.3, My Widgets Disappeared
I upgraded to 3.3 an my widgets went bye-bye. Here's the code I'm using... anybody else having this problem?
This code worked perfectly fine for me before the upgrade.
<!-- Enable Widgets -->
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar() ) : ?>
<?php endif; ?> | * Check if your theme is compatible with WP 3.3. To check, you may try switching to the default theme (twentyeleven) for a moment by renaming your current theme's folder in wp-content/themes. The idea is to force WordPress to fall back to the default theme to rule out any theme-specific issue.
-also, make sure all your plugins are uptodate and compatible with the 3.3. deactivating ALL plugins temporarily to narrow down the problem. If the problem goes away, activate them individually (one-by-one) to find the problematic plugin.
-Ipstenu has put togather an extensive 3.3 troubleshooting guide. Please review it as well. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "widgets, sidebar"
} |
Facebook Registration Tool: how to use in Wordpress?
Facebook provides a Tool to let Facebook users register to third party websites:
<
How to integrate this tool into Wordpress?
I would like to facilitate registration and creation of WP users with this tool. | Simple Facebook Connect uses this exact registration widget.
< | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "facebook, authentication, user registration, single sign on, signup"
} |
Recommend a guide to catching plugin errors, please?
I'm working on a small plugin and on some WP installations it throws up the white screen of death.
I'm new to this, and would like to know if there is a decent guide out to there (so far my googling over the white screen of death hasn't turned up anything for developers), or some best practices I should be following to make sure I catch errors or avoid anything foolish.
Any and all links or tips would be massively appreciated. | A white screen of death is typically a fatal PHP error, most of the time due to a syntax error. This often sends no errors to the browser.
Some things you can do:
Turn on PHP `error_log` in your php.ini file and set the `error_reporting` levels. <
Error info: <
Alternatively or in combination you can turn this on in your wp-config as well (from wordpress codex). <
/**
* This will log all errors notices and warnings to a file called debug.log in
* wp-content only when WP_DEBUG is true
*/
define('WP_DEBUG', true); // false
if (WP_DEBUG) {
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors',0);
}
Turn on WordPress debugging and saved queries, (wp debug is same as above example) in your wp-config.php.
define('WP_DEBUG', true);
define('SAVEQUERIES', true);
And install the debug bar, <
I also recommend using something like xDebug, | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 2,
"tags": "errors, customization, fatal error"
} |
How do I remove the "http://" from network_site_url?
I'm using `echo network_site_url();` to place the url of each site in a WordPress MultiSite installation. This outputs ` How do I remove the ` and trailing slash?
Thanks. | preg_replace("~^(?:f|ht)tps?://~i", '', $url);
Replaces http https and FTP in string $url | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 0,
"tags": "multisite"
} |
Convert HTML to HTML 5?
I have a website which is in XHTML (wordpress coded). I need to convert it into HTML 5. I just started learning about HTML 5 tags like section, nav, footer etc. While finding deep into it, I came across a site which actually converts the XHTML code into HTML 5.
Now I am confused, any how I have to learn HTML 5, but for the time sake is it a good decision to use that site? The converted HTML 5 code contains all the new tags, but is that actual pure method to do that? Will this converted code will be approved by W3C as HTML 5?
Here is the site:
< | You shouldn't use any converters. That make your Code Buggy. You should use your own knowledge and convert it manually! Learn HTML5 and it is very useful four you and the future. :-) | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "html5"
} |
Adding rel="next" & rel="prev" for paginated archives
Does someone perhaps know a plugin or snippet (besides Yoast's WordPress SEO) to accomplish this perhaps? Pagination with rel=“next” and rel=“prev”
The only thing I've come across seems to be an 3-month old Trac ticket. | Try putting this snippet in your functions.php
<?php
function rel_next_prev(){
global $paged;
if ( get_previous_posts_link() ) { ?>
<link rel="prev" href="<?php echo get_pagenum_link( $paged - 1 ); ?>" /><?php
}
if ( get_next_posts_link() ) { ?>
<link rel="next" href="<?php echo get_pagenum_link( $paged +1 ); ?>" /><?php
}
}
add_action( 'wp_head', 'rel_next_prev' );
?>
And if you don't want the next and prev rel links to show up on the singular pages just wrap the output markup in a `!is_singular()` if condition | stackexchange-wordpress | {
"answer_score": 10,
"question_score": 6,
"tags": "seo, headers"
} |
How can I add a page that shows posts from a single category?
Is it possible to add a page that shows posts for a certain category? Do I need to create a page and have it redirect to ` | Did you mean this? Menus --> Select an Category --> Add to Menu. Click Save! The link to this page should be available on your menu! | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "posts, categories, pages"
} |
How to change theme programmatically from a external application?
I have a one-click Wordpress install as part of my services. After install I want to show my clients a set of themes so they can choose one and their pages will start working without any configuration needed. The problem is I need to know how to change the theme from an external (PHP) application, perhaps accessing directly to the database or to one of the installation files. | Take a look at the options table:
$opt_table = "{$GLOBALS['wpdb']->prefix}_options";
$parent_theme = $opt_table + template;
$child_theme = $opt_table + stylesheet; | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "php, themes"
} |
Do I need to use a new WordPress.com account for each Jetpack installation
I manage lots of WordPress.org installations for different clients. Typically they do not manage the posts or pages themselves, preferring to stay out of things and let me do it.
JetPack functionality is great, but obviously you need to sign into a WordPress.com account within the installation to access it.
My question is - is it recommended to create new WordPress.com accounts for each client, or shall I just sign in to mine on each installation? What are the pros / cons e.g. are the WP-stats merged (this would obviously be bad)?
Many thanks | Nope, you only need it to activate. I use it on 4 sites with same account. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "wordpress.com hosting, plugin jetpack"
} |
Drawing the line between theme & plugin on large scale bespoke projects
With most of my sites, sprinkling in the functionality within the theme seemed the logical way to go. For example, a site with a 'product' post type, or a few options in a meta box or setting page.
On a couple of much larger projects though, it would've been crazy to keep it all in the theme, & was a lot easier to abstract the functioniality into reusable plugins.
But now I'm at the stage where the requirements are so specific, I'm writing a bespoke plugin to work alongside the theme, and I'm struggling with deciding what (if anything) should remain in the theme or go in the plugin (& furthermore, to break up the plugin into several to handle each component of the site).
It'd be great to hear of other similar situations, & generally how you guys approach large scale projects on WordPress. | I've spent the last month and a half working around the clock on a fairly large scale project based on BuddyPress and WordPress. Very little of the functionality is actually contained in the theme itself. Most of it wound up being broken into at least six different plugins that each serve a slightly different yet similar purpose. The smaller bits that were more general or otherwise did not make sense as a plugin got thrown into `functions.php`. I did it that way so that the client could turn off and back on each component as necessary.
Just as I did, you will have to sit down and determine what makes the most sense to you and best suits you or your client's needs. Planning is your best friend, trust me. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "plugin development, theme development, cms"
} |
How do I add a fixed value to get_post_meta();?
I'm using the following to display a custom field value in my posts:
`<?php echo get_post_meta($post->ID, 'wikipedia', true); ?>`
How do I add this value to the output, where '$tag' takes the tag of the post:
`- <a href="wikipedia.org/wiki/**$tag**">Wikipedia</a>`
What I've tried, unsuccessfully:
`<?php echo get_post_meta($post->ID, 'wikipedia', true . '- <a href="wikipedia.org/wiki/$tag">Wikipedia</a>'); ?>` | <?php $tag = get_post_meta($post->ID, 'wikipedia', true); ?>
<?php if (isset($tag) && $tag != '') : ?>
<a href="wikipedia.org/wiki/<?php echo $tag; ?>" title="Wiki this!">Wikipedia</a>
<?php endif; ?>
To explain it a bit: First you put the data in a variable, then if the variable has some data, it will show the link and echo the data after /wiki/. You can use the variable also on other places like so: `<a href="wikipedia.org/wiki/<?php echo $tag; ?>">Wikipedia (<?php echo $tag; ?>)</a>` | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "post meta"
} |
Free chat plugin
Is there a WordPress plugin that allows users to have a private chat with an admin but that there is no need for a payment plan (like you have with support sites such as OGG or 123flashchat).
I just want a simple chat box that tells users whether I'm online or not and lets them contact me through it. | I think I know exactly what you need: LiveAgent - <
You can register free chat account which allows you to chat with your customers directly as they browse your pages.
All you need to do is to use this plugin: <
and it'll create your free account and integrate chat button in to your pages automatically. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -1,
"tags": "plugin recommendation"
} |
Stop 'alt' from being added to the_post_thumbnail
I'm using the_post_thumbnail to display a specific thumbnail size. The function outputs an 'alt=' tag with the description of the attachment. Is it possible to clear the value in the ouput? So it'll display `alt=""`? | If you look here: < you will see that you can change the alt. You have to add an array with the value for the alt in the second parameter like so: `<?php the_post_thumbnail('thumbnail', array( 'alt' => false )); ?>` | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "thumbnails"
} |
Conditional Statement - Best Way to Remove Nav on Contact Page
I was thinking of removing navigation on my contact page.
I was thinking of inserting a conditional statement and an inline CSS style to "display: none;" if the page template was the contact page.
Is there a better way?
I'm using Twenty Eleven as a parent theme. | You could try putting this code in your functions.php
function remove_contact_nav( $nav_menu, $args ){
if( is_page_template('template-contact.php') || is_page( 'contact' ) ) {
$nav_menu = null;
}
return $nav_menu;
}
add_filter( 'wp_nav_menu', 'remove_contact_nav', 11, 2 );
The if condition need to be modified as per your template name or the second condition would also do if your contact page slug is `contact` | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 1,
"tags": "conditional content, theme twenty eleven"
} |
Alphabetically sort a taxonomy.php template by post title
Simply put, is it possible to sort a taxonomy.php template via the same methods you can with something like `wp_query` so that the archive shows all posts in an ascending order alphabetically by title? | you can `query_posts` and `orderby=title`:
<?php //*The Query*//
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
query_posts($query_string . '&post_type=YOUR-POST-TYPE&posts_per_page=1&orderby=title&order=asc&paged='.$paged);
if(have_posts()) : while(have_posts()) : the_post();
?>
<?php endwhile; ?>
<?php else : ?>
<?php endif; wp_reset_query(); ?>
more info: WP_Query#Order/Orderby Parameters | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "custom post types, custom taxonomy, taxonomy, custom post type archives"
} |
how do I create a breadcrumb to work with multiple custom taxonomies
I have created several custom post types, and custom taxonomies to manage my large art portfolio. All of this is working very well. There is a post type for "art" and "design" as well as custom taxonomies for stuff like "color"
I want to add breadcrumbs that will show the taxonomy the user clicked on to arrive at a particular image. For example:
from the `achive-art.php` someone clicks on the custom taxonomy "color" and then the classification of purple they are taken to a `taxonomy-color.php` page that lists the results. When they click a thumbnail to see the full post I would like to see a breadcrumb that reads:
art > purple > title of the post
I've tried a ton of plug-ins but they only work with one taxonomy or will show:
art > title of the post.
I'm still kind of new to wordpress and trying to wrap my head around everything. | The easiest way you can remember which taxonomy the user arrived through to a certain post is by storing it in a cookie. This is essentially what the Smarter Navigation plugin does, except it can handle all archives, not just taxonomy archives. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom post types, custom taxonomy, plugin recommendation, breadcrumb"
} |
How to configure self hosted wordpress so that everything can be upgraded/installed from dashboard
I have a blog on shiplu.mokadd.im. After installing wordpress I see upgrade notice time to time. Sometimes its core upgrade and sometimes its plugin or theme upgrade. Each time I try to upgade any of them I see wordpress asks for ftp credential. To resolve this I have created ftp account. But somehow wordpress fails to log in.
My question is how can I make this upgrade working directly from dashboard? If its an ftp account what type of privileges would it require? If its ch{mod,own}, what is the secure way?
I am using **version 3.2.1** | I have solved this problem by changing the owner of the wordpress directory to `www-data`.
chmod -R www-data:www-data /path/to/wordpress/on/apache/ | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "apache, php"
} |
Wordpress Settings API: saving multiple rows of similar data
I've been experimenting with the plugin options starter kit but can't find a way to save multiple rows of similar data using the Settings API. Example of what I'm trying to save:
_________________________________________
|____Order#____|___Image URL___|_Enabled_|
| 1 | | Y |
| 2 | | N |
........
Can this be generated and saved using just one register_setting? I can't work out how this would be done, especially with the format of the data being saved to the database.
Thanks, Alex | These are the best two articles i've read(i'm sure there are others to) on creating multiple options using the Settings API, one covers usage inside a theme and the other inside a plugin, but essentially both actuall cover doing the same thing(registering a page and having some savable fields inside that page).
* Themeshaper
\- Incorporating the settings api in WordPress Themes
* Alisothegeek
\- WordPress Settings API Tutorial: Part 1
Both have a few pieces here and there i don't agree with, i can't recall specifically what, but it's the nature of writing code, you're not always going to agree with the way certain coders approach particular things. I don't have time to run over them now and pick out what i'd do different, but both are still very good examples of how to use the API.
Hope that helps. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "plugin development, settings api"
} |
Moved to a new server, backup was a day old and missing 3 posts, anyway to recover them from old host?
I made a backup for my clients site the other night, apparently after I made the backup they made a few posts. I then moved the site to another host and resetup wordpress and imported the database and backup files.
Now my question is, I still have access to the old host, I can login via FTP or cPanel, is there anyway I can grab the posts from the database possibly? In phpMyAdmin? Thing is I cant just login since the nameservers are changed.
Thanks, Matt | Thanks, what I ended up doing was dumping all the tables in the POSTS section within phpMyAdmin then logged into the new server and imported it. Worked like a charm. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "posts, database, server"
} |
What is a good plugin for making a template that can be reused to make several objects on a single page?
I'm looking for a plugin or an idea that would allow a user to add a mini-post to a page. Each post would contain a .pdf, and a mini description.
I found Custom Field Template.. but I think once you fill it out once, you can't fill out another one for the same page.
Thanks! | I actually wrote a plugin to accomplish this very thing ...
WP Publication Archive is a plugin for WordPress that specifically adds the ability to create objects like this. It introduces a custom post type for documents/publications that feature a downloadable file (i.e. PDF) with a title, description, tags, and authors taxonomy.
You can create multiple "collections" of publications by applying categories, then using a category filter within the shortcode on a page. For example:
[wp-publication-archive categories=cat-1 /]
Would present a list of all publications in the "cat-1" category.
Here's an example of what an unstyled publication list (with only one download) would look like:
!Example output of WP Publication Archive | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "plugins"
} |
Admin bar and fixed header issue?
I've styled my header to have a fixed top position. While logged in to wordpress, the wp admin nav bar covers the top section of my header making imposible to access my top navigation. I would like for the wp admin nav to push my top navigation below so both are visible. Does anyone know of any solution to fix this problem?
An example of my problem can be found at... www.nickriversdesign.com/dev | in your css you could try something like: `body.logged-in{margin-top:20px;}` or if this doesnt work some other code using the `.logged-in` class | stackexchange-wordpress | {
"answer_score": 10,
"question_score": 12,
"tags": "headers, admin bar"
} |
sprintf bloginfo odditie
Why the _disco funk_ this is happening I can't quite put my finger on - but I guarantee you it's because I'm probably missing some simple PHP best-practice:
<?php echo '<h3>' . sprintf(__('Welcome to %s', 'roots'), bloginfo('name')) . '</h3>'; ?>
For some reason outputs:
Site Name<h3>Welcome to </h3>
Any light nudges in the right direction would be really appreciated - and maybe a slap on the head once I figure out what's going on ;) Thanks! | Try using `get_bloginfo()` instead of `bloginfo()`. The former _returns_ the value; the latter _echoes_ the value. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "localization, bloginfo"
} |
How do I query the title (or handle?) of post meta fieldset (created with Simple Fields Plugin)
I am having a heck of a time trying to retrieve the title (or handle?) of my custom post meta fields.
I am using the slmple fields plugin. < (as I understand it, this just makes use of 'normal' post-meta stuff.
I have tried the `simple_fields_get_post_group_values()` function provided by plugin, as well as the following code I found in the WP codex, to no avail:
<?php $checkit = get_post_custom( 22 );
print_r($checkit);?>
I have also tried searching the database for the phrases themselves within phpMyAdmin, and they don't appear to be there, which is perplexing.
I'm pretty new to all this stuff, so I am sure I am missing something obvious ;-)
I would be extremely grateful for any advice or help anyone could offer.
* * *
I've circled (badly) the info I am trying to query.
!enter image description here | The values you have circled are not part of the custom fields. They are part of the configuration data of Simple Fields. You can find them in the dadabase in table wp_options in the row with option_name=simple_fields_groups. Field option_value contains a string of serialized data.
You can read the option with WP function get_option(). It is deserialize automatically. Use var_dump() or a plugin like SM Debug Bar to display the content. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "custom field, post meta"
} |
HTML tables in content areas
Is there a plugin that would allow me to create and edit tables within the content block in posts and pages? I suppose a bit like the 'insert table' command in MS Word. | I did a quick Google search and it took me to this article. I have not used either of the plugins mentioned but they are TinyMCE Advanced and WP-Table Reloaded hopefully one of those work out for you. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "html, content, formatting, table, html editor"
} |
Custom Field box history
I entered a test value ("hhhhhhhhhhhhhhhhhhhh") in my custom field box at some point, and now it always appears in the drop down when I am trying to select a value. Is there some way to get rid of this?
!enter image description here | I did a search for this phrase: "wordpress remove custom field value from the drop down menu". A bit verbose perhaps, but it got me this link: <
From that page, the author states that you can do one of the following:
* Delete Custom Field from all posts.
* Delete it from the database.
* Delete it using a plugin.
There's a lot more detail in the link above, but to not steal their thunder, I'll let you following the link itself. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "custom field"
} |
Adding a navigation page state to individual blog and portfolio pages
I'm using a Woo Themes template (Simplicity) for a client's web site.
I'm using the portfolio page as the profile pages (Our Trainers).
Also have a blog category in the main nav.
How do I get the individual "portfolio" and blog pages to set the nav current page (.current_page_item)? | If it's in a menu you could use .current-menu-parent otherwise something like .current-post-parent or .current-page-parent
I hope this is what you mean. Otherwise a link to your current site would help alot. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "php, css, navigation"
} |
Upgrade DB Loop - WordPress DB Version Conflict
So I did an auto update to WP 3.3 and got a screen telling me there was a DB upgrade needed. I hit continue and it said the upgrade was a success. I hit continue again and the same screen popped up telling me the DB needed upgrading... repeat cycle.
Then I changed the DB version in version.php (18226) to match what was in the database under the options table for DB version (19470). This allows me to access the backend, but nothing will update. Can't update any post or pages. It says the page is updated, but it never actually does...
I have read and tried all of these solutions:
Site stuck in "Database Update Required" loop
<
<
Any suggestions?
Thanks | I fixed the issue by changing the DB credentials in wp-config.php. Apparently, they were wrong... | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "mysql"
} |
Using chunk theme from wordpress.com on my own host
I am new to wordpress so please excuse this question if it is obvious, but I was not able to find a good answer here or via the more general internet.
I want to use the Chunk theme from wordpress.com but:
* I can't find it via the theme admin area of my local wordpress installation
* I can't find a way to download a `.zip` file
Is there a way to do this? If any further information is required I can provide as needed. | The Chunk theme is currently under review. It has been set as unapproved by the WordPress.org theme review team. If the author makes the corrections it will be available in the WordPress theme repository. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 3,
"tags": "themes, migration"
} |
Trying to get more space removed from my header
The last time , you help me to remove the header from all the pages besides the Home page (thanks again by the way). The reason for me to do so , is because I don' t want my music player for example to be too below , having people to need to scroll down.
I am still looking for more space , and get rid off the title for example, or make it smaller . And know that I added a follow button of Twitter , the top takes more space , and the music player is more below .
Any advice would be appreciated. Thanks, Daniel | Your music player looks okay to me. On line 1090 of your style.css file, you have the top padding of class `.singular.page .hentry` set to `3.5em`. Start there. You might also want to remove padding and/or margins from the elements above the player, such as the navigation. If you want to remove the title, add `if ( ! is_front_page() ) :` before your call to `the_title()`. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -1,
"tags": "title, headers, customization"
} |
highlight "starred" comments by admin
I'm looking for a **wordpress plugin, hook function or directions** for these specific needs (I'm okay writing my own plugin):
* when moderating comments, a wordpress admin should be able to change its status (approved/pending/spam, like usual) and "star this comment" or set its status to a new status "approved and starred"
* These "starred" comments would show up **highlighted** , **sorted first** or **diplayed in a tab-like interface** on the post page
Ideas? | < Give it a try. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "comments"
} |
On home page remove link from logo
I'd like to remove the link that is generated around the logo when users are on the home page. Does wordpress have a built in function so I can wrap an if condition around the logo in the template so if the current page is the home page I can have the output without the a tag, and the else would simply be the current code. | Its a template specific thing mate. You might have to edit the `header.php` and add a condition like:
<?php
//Check for homepage
if(!is_front_page())
{
//The link around logo markup
}
else
{
//Just the logo markup without the link
}
?> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "homepage, logo"
} |
css targeting submenu current-menu-item list item
Hi trying to target the only the first list item of a sub menu with current-menu-item class, but having no joy. Any help link to example jsfiddle | I was able to get the current menu item to be blue using this:
.current-menu-item li a{
color: blue
} | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -1,
"tags": "css"
} |
Menu item with no page, but with dropdown
I am using 2010 theme menu. Is it possible to have a menu item that has a drop down when hovered, but will not click though to a page/post. Just a dropdown, using the wp_nav_menu. | The easiest way would be to create a custom menu item from the Appearance>Menu's section of the admin area. When you create the custom menu item just add a # for the link URL. You can name it whatever you want. Then just place the desired pages under that menu item. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "menus, dropdown"
} |
Change headline text for post thumbnail meta box
How can I change the headline text for the post thumbnail meta box in the edit post screen? | Featured Image box is internally a meta box, added using `add_meta_box` (ref. `edit-form-advanced.php` line no. 128). As far as my research went, there is no filter applied to the meta box title (ref. `template.php` line no. 846). Hence you cant change the metabox title using a filter. Though you can try printing the contents of `global $wp_meta_boxes` (returned blank in my case), or use a jQuery trick to get your job done. But if you ever want to change the inner text, 'Set featured image' (or the html for that matter), you can use the filter `admin_post_thumbnail_html`. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "metabox, post thumbnails"
} |
More than one search results page template
On my current project, I have to create 2, distinct templates to receive 2 distinct search results of the same site.
Both researches are coming from different forms on different templates/pages.
Thing is, there is only one search.php file in Wordpress, and I don't think it's possible to create another one. (like search-taxonomy.php)
Is there a way to separate one search result of the other, and to then display the correct search page template in relation to which search form has been filled? | You could make a page template <
And then you could post some data via $_GET /search2/?search=xxx to that page and do a custom wp_query where you use 's=' . $_GET['search'] <
Something like this:
$args = array(
's' => $_GET['search']
);
$the_query = new WP_Query( $args );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile; | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 2,
"tags": "search, templates"
} |
wp_list_pages by taxonomy?
I need help creating a Walker for wp_list_categories that filters through taxonomies and actually lists the pages at the end element.
I'm completely lost on how to go about this. I've successfully implemented a Walker for the wp_list_pages function but that obviously doesn't apply in this case because my wp_list_pages Walker relied on child-parent relationships
* * *
Additionally, I'd like to be able to specify which terms I want to return. Basically, I need a list filtered by taxonomy and terms. | wp_list_categories()
Would be the way to go for taxonomies. Further functionality can be done either with a custom walker on this function (This seems to be the one resource: <
or write a custom SQL script.
In the end, I went with wp_list_pages and sorted by custom post type where:
post_type => 'custom-post-type'
is listed as an argument. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "wp list pages"
} |
How Do I Protect My Premium WordPress App Theme from Copying?
They say WordPress is GPL, and therefore all plugins and themes made with it are supposed to be GPL. Fine, but if I spent three months coding an extremely complex app theme with the intent on selling it repeatedly for profit, such as a medical office scheduling system theme, then how can I protect my investment, if even a moderate amount? | In addition to the other two suggestions, there is another possible approach: move all of your custom-app functionality _out of the Theme_ , and into a _hosted web service_ , to which the Theme connects via **API key**. That way, redistribution of the Theme itself does not impact your custom app-based business model, because the app would require Theme **plus** valid API key.
This approach may or may not work, depending on the nature of your custom app, but it is a successful model for some commercial Plugins, and is fully GPL compliant. | stackexchange-wordpress | {
"answer_score": 27,
"question_score": 34,
"tags": "theme development, licensing, premium"
} |
filtering special chars from post slug
Is there a way to prevent WordPress from including special characters like – (long dash), ", ', etc.. from the post slugs?
Basically, I'd like to run the post-slug through a filter when it is created, and strip any special chars.
The reason is, that it's giving me problems as these show up as utf8-urlencoded in my rss feed, and those links don't work. | Found the answer I was looking for:
<?php
// Cleans special characters out of the slug, if the slug hasn't been set yet
add_filter('name_save_pre', 'clean_slugs', 0);
?> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "permalinks, slug"
} |
Why is taxonmy-[taxonomyname].php not working?
I've registered a couple of custom taxonomies to go with a couple of custom post types but I'm having some trouble getting a template file to work.
I've tried taxonomy.php, taxonomy-[termname].php, taxonomy-[taxonomyname].php but none seem to register and the link reverts to index.php
You can see an example of this here - < just click on any of the links inside the yellow box and instead of going to a specific taxonomy template page it uses index.php
I'm not sure if it makes a difference, but this is the code I'm using to register the taxonomy
register_taxonomy('cat', 'portfolio', array('hierarchical' => false, 'label' => 'Category','query_var' => true, 'rewrite' => true)); | I think this is because you use a reserved name: <
Try changing in to something else like:
register_taxonomy('portfolio_category', 'portfolio', array('hierarchical' => false, 'label' => 'Category','query_var' => true, 'rewrite' => true)); | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "taxonomy, templates"
} |
how to create a fav icon shortcode?
i wonder if there is a good way to create a shortcode that retrives a remote website FAV icon... i found this: ANSWER and tried to create a shortcode using it but failed (since i sux at shortcodes!)
A quote from the answer i linked up:
<?php
$url = '
$doc = new DOMDocument();
$doc->strictErrorChecking = FALSE;
$doc->loadHTML(file_get_contents($url));
$xml = simplexml_import_dom($doc);
$arr = $xml->xpath('//link[@rel="shortcut icon"]');
echo $arr[0]['href'];
?>
Any help would be apreaciated ;) | OK... as it sometimes goes i cant rest until i find
a way and i found a way to get the fave icon to
proeprly display using google :)
its really simple:
// here i get my URL from my custom post type
$directoryNoHttpUrl = get_post_meta( $post->ID, 'directory_url', true );
//here i clean the url from HTTP or it wont work
$directoryNoHttpUrl = str_replace(" "", $directoryNoHttpUrl);
// here i get the favICON using google..
$imgurl = " . $directoryNoHttpUrl;
.
So.. from here on its easy.
Sorry to trouble anyone entering to help
but thanks for your intention
Cheers, Sagive. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "shortcode, favicon"
} |
Description of a sub-taxonomy
I am using this code to display description of a taxonomy.
<?php $my_taxonomy = 'institute'; $terms = wp_get_post_terms( $post->ID, $my_taxonomy ); echo term_description($terms[0]->term_id, $my_taxonomy); ?>
What to do if I want to show description of sub or even sub-taxonomy? | Term description works only with term id and the taxonomy name, so if you want to get the sub term's description, you should first get all the children of a term(and their children, if its another level deep) and loop over their ids with a single `term_description` call per id.
<?php
$my_taxonomy = 'institute';
$terms = wp_get_post_terms( $post->ID, $my_taxonomy );
echo term_description($terms[0]->term_id, $my_taxonomy);
//Assuming you have only 1 parent term, if multiple then loop over the $terms array
$term_children = get_term_children( $terms[0]->term_id, $my_taxonomy );
foreach($term_children as $term_child)
{
echo term_description($term_child->term_id, $my_taxonomy).'<br />';
}
?>
This should give you an idea. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "taxonomy, description"
} |
List of all posts in one custom post type in the edit screen of another
Please forgive me if this doesn't make a whole lot of sense.
Is there a way to list all the posts created under one custom post type (eg: Blueprints) in the edit screen of another (eg: Buildings) in a checklist (or similar) so that individual bluebrints can be associated with individual buildings?
I hope that made sense. | if you are trying to make ralationship links between post types, the easiest way is to use the great "posts 2 posts" plugin by Scribu : <
here is the documentation : <
hope that could help.
seb.
EDIT :
> Is there a way to list all the posts created under one custom post type (eg: Blueprints) in the edit screen of another (eg: Buildings) in a checklist (or similar)
yes ! in the edit screen of each post types depending on the associations you create between them. not a checklist, but similar, well, better ! this plugin gives you the ability to add/remove/reorder, with drag and drop, your linked posts/post types/pages and even users if you need...
> so that individual bluebrints can be associated with individual buildings?
absolutely ! not only "one to one" relationships inbetween different post types, but also "many to many" and "one to many"... you choose. see the manual. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "custom post types, metabox"
} |
Tiny MCE not adding p tag when saving theme option
I am adding tinymce edior with new `wp_editor()` function on theme option page. On submit the theme option sends data to `option.php` where it saves. But tinymce doesn't seem to convert the line breaks into `<p>` tags as we see in the post and pages from the edit page. Other styles and htmls that I add from the editors are okey.
Do i have to use any filter on it before it saves?
I am showing the content with a `echo`.
<?php echo theme_option('homepage_content'); ?> | If you want the contents of an option, variables, or anything for that matter to be treated like post content you'll need to call the post content filters.
<?php echo apply_filters( 'the_content', $your_var ); ?>
Your data is then treated in the same way as post content is, inline with the code sample you've posted, the call should go like this..
<?php echo apply_filters( 'the_content', theme_option('homepage_content') ); ?>
Hope that helps. :) | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 3,
"tags": "tinymce, wp editor"
} |
Redirect Tag to Post with the same name
I would like to check if the tag name is the title of a post. And load that post page instead of a tag page.
I have post_type "Cities" and suppose that users will tag normal posts with city names. And when user selects a tag, I would like to check if a "Cities" post exists with this tag name. And show this post if it does.
I am thinking of redirecting from tag page to post page, but don't know when and how to run the check. Is it the right way? Can anyone help? | Try the code from this article: <
It checks `$wp_query->post_count` and redirects to the only article of an archive if there is just one. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "tags, redirect"
} |
Dealing with variables with gettext function
I've found tweaking some of the text in WordPress to be pretty easy by adding in the following function (in lieu of using a separate plugin):
add_filter( 'gettext', 'of_site_translations', 9999, 2 );
function of_site_translations( $translation, $text ) {
if ( $text == 'Posts' )
return 'News Posts';
return $translation;
}
The issue I'm running into is (in my above example) while it will change `Posts` to `News Posts` in the WP Sidebar - areas that are dynamically created based on the post type labels; when you click on `Posts` from the sidebar and it leads you to a page that says `Posts`. Is there a way to override post type labels using this method? If so, any pointers that could push me along a bit? Really appreciate it, thanks! | You could just rename the labels associated with that post type.
class News_Post_Type {
const POST_TYPE = 'post';
public static function init() {
$post_obj = get_post_type_object('post');
$post_obj->labels->name = __('News Post', 'textdomain');
$post_obj->labels->singular_name = __('News Post', 'textdomain');
// You can continue to rename all the label properties, this is just an example
}
}
add_action( 'init', array( 'News_Post_Type', 'init' ) ); | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom post types, translation"
} |
Variables declared in header not available in other includes
I have a var set in my header.php file:
$myBool = false;
and in page.php, I try to echo it:
echo $myBool;
But the variable is never set. This doesn't help either:
global $myBool;
echo $myBool;
Does anyone know what the problem is?
Note: I'm using a custom theme based on the blank theme ( < ) but the same behaviour is evident when using twentyten / eleven so the theme seems to have nothing to do with this | You need to globalize it before you set the value, so in your header.php
global $myBool;
$myBool = false;
and then in your page.php
global $myBool;
echo $myBool;
just make sure you page.php includes the header.php file either directly or by calling `get_header();` | stackexchange-wordpress | {
"answer_score": 8,
"question_score": 4,
"tags": "php, variables"
} |
adding custom script to functions file
I have a problem adding a custom script to my functions.php file:
add_action('wp_print_scripts', 'load_AJAX_URL__');
function load_AJAX_URL__() {
wp_localize_script( 'ajax_URL', 'MyAjax', array( 'ajaxurl' => admin_url('admin-ajax.php') ) );
}
Why is not working? any ideas? | The function `wp_localize_script()` is used to send variables to a script that has already been registered and enqueued. Do you have a js file that has been registered and enqueued and has the handle of 'ajax_URL'? If not, then that explains why it isn't working.
Also, ajaxurl is already a js variable that is accessible via any scripts you enqueue, so I'm not quite sure what you're trying to do here.
If you're just trying to add a new js file into your theme, you want to look at the `wp_enqueue_script()` function. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "functions, headers, wp localize script"
} |
How to make a theme with more than one CSS file?
I've made my first theme and now I want to create different "profiles". These profiles are just independent CSS files that user can try. The point is, how to make these files to allow users to choose the color scheme through the admin panel? It is, I don't want to allow users to access to the file system, so they will have to change the CSS file using the admin panel. How to do it? Is there any plugin that allows to change CSS files? | This article should answer your question:
Add a style switcher to your wordpress theme
The article that I have linked above explains and walks you through on how to add a stylesheet switcher to your admin panel for your theme.
It walks you through on how to use and add options to your theme. This is particularly intuitive if your developing a theme for a client who once in a while may want to change their colors / imagery or something on a whim.
I have used this numerous times when theme developing. Also in using this method you can add as many stylesheets as your heart desires. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 5,
"tags": "theme development, themes, admin, css"
} |
Is it possible to "freeze" a WordPress blog?
I'm currently running a 365 photos project and it's based on a WordPress platform. Currently this is very helpful because I can upload the photos easily and manage comments and stuff.
Because we are reaching the end of the year, I would like to "freeze" the blog. I mean, remove all the WordPress engine code and leave all the pages as statics HTML. This will allow me not to have to get updates for WordPress, or worry about security.
**Is there any way to "freeze" a WordPress blog?** Do I have to download the entire site with, say, HTTrack and re-upload it or is there a fancier way to do this?
BTW, I have no interest of keeping the comments on or any interactivity that the blog has. I just want a static website. | Take a look at this Wordpress plugin WP Static HTML output
> This plugin produces a static HTML version of your wordpress install, incredibly useful for anyone who would like the publishing power of wordpress but whose webhost doesn't allow dynamic PHP driven sites - such as MobileMe. You can run your development site on a different domain or offline, and the plugin will change all relevant URLs when you publish your site. It's a simple but powerful plugin, and after hitting the publish button, the plugin will output a ZIP file of your entire site, ready to upload straight to it's new home. | stackexchange-wordpress | {
"answer_score": 7,
"question_score": 7,
"tags": "plugins, images, export"
} |
How to add filter to __() and _e()?
I would wish to add a filter to `_e()` and `__()` functions. The filter is **FilterTextOfEmail()**. This will basically detect any emails and add anti-spam method to it.
I assume, the function for filtering should look like:
function my_wp_text_email_filtering ($content) {
return FilterTextOfEmail($content)
}
But how to call it? | The filter name is `gettext`, and you would add it like this:
add_filter( 'gettext', 'my_wp_text_email_filtering', 10, 3 );
function my_wp_text_email_filtering( $translated, $text, $domain ) {
return FilterTextOfEmail( $translated );
}
The **$text** argument is there also in case you want to access the pre-translated text. | stackexchange-wordpress | {
"answer_score": 11,
"question_score": 5,
"tags": "filters"
} |
Is there a limit to the number of items that can be added using the Appearance Menus Screen?
I can add up to 17 items to my Menu. As soon as I add one more item by clicking the checkbox for the page that I want to add in the Pages box in the left hand column and save the menu, the item that is last in the list drops off.
The Appearance Menus Screen page in the Wordpress codex makes no mention of this limit.
I am using a child theme of the Thematic theme; but I have had this problem before with other themes too.
If there is a limit, is there anything that I can do to override this? | Could possibly be this bug < and < but 17 menu items is very low threshold.
**Try raising your php memory allocation** using FTP:
1) You can edit the memory_limit line in your php.ini (if you have access to that file) to 64M:
`memory_limit = 64M;`
2) If you can't get to the php.ini file, add this line at the top of your .htaccess file:
`php_value memory_limit 64M`
3) If that doesn't work or throws a "500 Internal Server Error", delete the line from .htaccess.
Then try adding the line below near the top of your wp-config.php file, right after the opening `<?php`
`define('WP_MEMORY_LIMIT', '64M');`
**If you have a php.ini,** also check and raise the execution time limits:
max_execution_time = 600
max_input_time = 600
**If the server is running suhosin,** try these new limits:
suhosin.post.max_vars = 5000
suhosin.request.max_vars = 5000 | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "admin menu"
} |
query_posts - slightly more advanced query
I'd like to edit the front page posts query to be slightly more advanced. Right now it excludes all posts in the Featured category. I'd like it to exclude the first 5 posts (or first n posts, really), but include the rest in the results.
Here is the current call:
<?php query_posts("cat=-".$GLOBALS['ex_feat'].",-".$GLOBALS['ex_vid'].",-".$GLOBALS['ex_aside']."&paged=$paged"); ?>
How would I edit this to include all featured posts as well, except the first 5? | I ended up asking this in a better way, and received an answer:
Add a special filter link to All Posts in admin | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "query posts"
} |
wordpress superfish dropdown menu
I am learning how to integrate superfish drop down menus in wordpress and i am following this tutorial <
I am using this theme with superfish integrated <
Has anyone else successfully been able to make the menus show?. | I finally solved it.I had to add menus under the appearance menu and worked perfectly. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "menus, navigation"
} |
How to remove some options in visual editor?
I want remove some options in visual editor. How to remove them?
For example i want to remove the following.
1. Align left option
2. Align center option
3. Align right option
4. More tag option
5. Add media
6. Toggle fullscreen
7. Toggle spellchecker
8. Show/hide kitchen sink
9. strikethrough
Please help me to remove them from my wordpress visual editor. Thanks | Try this plugin. It allows you to add/remove buttons on the visual editor -> < | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "visual editor"
} |
WP 3.3 > Still no option to enable automatic image overwrites?
I was really excited to see the new functionality with the media manager in WP 3.3 (specifically drag and drop uploads and automatic file type recognition)
But I was disheartened to see no relief in terms of the confusing manner in which WP continues to handle image overwrites (by appending a number to the image and creating a duplicate version).
Does anyone have a workaround that I can implement in my theme's functions.php to enable automatic image overwrites, replacing the original image with the new one, and without changing the filename? | There's another plugin out there worth checking out:
> **Enable Media Replace**
> _This plugin allows you to replace a file in your media library by uploading a new file in its place. No more deleting, renaming and re-uploading files!_ | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 5,
"tags": "uploads"
} |
Creating an Events Feed with Sub Pages/Posts for Each Event
I am currently working on creating an events section for a website. My original plan was to create a custom post type for Events and create a new post for each event. Then I would query the top five events on the home page. My problem is that I need to have sub pages/posts for each event. These pages/posts will need to show up in a sidebar when the single event post is viewed. Is that possible?
Can I create a parent/child relationship with each event post and its sub posts or would it be better to use custom taxonomies to organize this information? The site will be client updated, so I need to create a system that is straightforward and sustainable with a logical permalink structure.
Any help would be greatly appreciated. Thanks! | when you create a custom post type, and make it hierarchical, it will behave like pages. so you can have sub events the same way you have sub pages.
look at `register_post_type` function arguments here : <
then use `wp_list_pages` function to list subpages. see : <
something like this (not tested) :
<?php
$args = array(
'title_li' => '',
'child_of' => $post->ID,
'post_type' => 'event',
'title_li' => __('Sub events'),
'echo' => 0,
)
$children = wp_list_pages( $args );
if ( $children ) {
?>
<ul>
<?php echo $children ?>
</ul>
<?php } ?>
please, see this topic on the WordPress forum also.
all you need seems to be in the codex. do not hesitate to follow its rules. here you will find nearly all the tools you wish : <
seb. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "custom post types, hierarchical, events"
} |
simply loop through posts
I know this is a really newbie question, but I can't seem to get the loop to pull from the posts. all it is doing is pulling from the page itself.
I made a template and added the loop to it.
<?php
if( have_posts() ) {
while( have_posts() ) {
the_post();
?>
<h2><?php the_title(); ?></h2>
<?php
}
}
?>
edit: here is all the code: < | Because you're on a page, that's only going to display the query for that page. As such, you'd have to create a new query to bring in the posts you want. Replace your loop with this:
<?php
$args = array(
'post_type' => 'post'
);
$post_query = new WP_Query($args);
if($post_query->have_posts() ) {
while($post_query->have_posts() ) {
$post_query->the_post();
?>
<h2><?php the_title(); ?></h2>
<?php
}
}
?>
Here some more information on the query: < | stackexchange-wordpress | {
"answer_score": 24,
"question_score": 9,
"tags": "posts"
} |
Proper formatting of post_date for wp_insert_post?
What is the proper way to define the post date when submitting a post from the front end using wp_insert_post (Trac)?
My snippet now is publishing with the mysql time...
if (isset ($_POST['date'])) {
$postdate = $_POST['Y-m-d'];
}
else {
$postdate = $_POST['2011-12-21'];
}
// ADD THE FORM INPUT TO $new_post ARRAY
$new_post = array(
'post_title' => $title,
'post_content' => $description,
'post_date' => $postdate,
'post_status' => 'publish',
'post_parent' => $parent_id,
'post_author' => get_current_user_id(),
);
//SAVE THE POST
$pid = wp_insert_post($new_post); | If you don't add a post_date then WordPress fills it automatically with the current date and time.
To set another date and time `[ Y-m-d H:i:s ]` is the right structure. An example below with your code.
$postdate = '2010-02-23 18:57:33';
$new_post = array(
'post_title' => $title,
'post_content' => $description,
'post_date' => $postdate,
'post_status' => 'publish',
'post_parent' => $parent_id,
'post_author' => get_current_user_id(),
);
//SAVE THE POST
$pid = wp_insert_post($new_post); | stackexchange-wordpress | {
"answer_score": 28,
"question_score": 16,
"tags": "date time, wp insert post"
} |
Functions.php: Exclude Category from "Blog"
So it's quite obvious to how exclude certain categories from within a template, but I don't want to have to modify 4 templates so that they ignore a certain category.
Is there a way that I can exclude a category from showing up within the "blog" set within the Reading settings? I'm assigning the blog to a Page named "Blog" ... but obviously archives and searches are going to need to be blind to this one exceeded category too.
I'd just do much rather do it within `functions.php` | <
add_action( 'pre_get_posts', 'foo_modify_query_exclude_category' );
function foo_modify_query_exclude_category( $query ) {
if ( $query->is_main_query() && ! $query->get( 'cat' ) )
$query->set( 'cat', '-5' );
}
> So it's quite obvious to how exclude certain categories from within a template, ...
Actually it's not. Are you talking about query_posts() !? | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "categories, blog, exclude"
} |
What is the importance of mod_rewrite?
If my hosting provider does not provide mod_rewrite mode. What thing will get effect on my wordpress?
I bought a hosting, they claim they does not provide it. I have installed WP and the web is running. I dont know what features I am missing.
The output of following command does not have mod_rewrite anywhere.
<? php phpinfo(); ?>
I put following contents in my .htaccess file. And mydomain.com/google.html redirect to google.com.
Options +FollowSymLinks
Redirect /google.html
That means mod_rewrite is working? And my hosting representative does not know this.
Thanks. | the `Redirect` directive is part of Apache's `mod_alias`, not `mod_rewrite`.
`mod_rewrite` enables "pretty" permalinks, ie: ` rather than "ugly" permalinks ie:`
WordPress will operate just fine without mod_rewrite and pretty permalinks, it's just not as attractive or SEO friendly. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "mod rewrite, shared hosting"
} |
melville and its child theme
hello guys im making child theme of melville and i wanna make a custom page with a static menu (as in not made with wp ) of my own and under it i wanna display the content and i use this `get_template_part('loop' ,'home-page')`where the home-page its name of my custom page and i do have the loop file in my child theme please if anyone knows whats my msitake i would be thankfull
my issue is the content doesnt show up
Edit : here's my code im using nothing fancy
`
get_header(); ?>
some xhtml here
<?php get_template_part('loop' ,'home-page') ?>
<?php //comments_template( '', true ); ?>
<?php get_footer(); ?>
` | According to the codex your file needs to be called `childtheme/loop-home-page.php` if you did just then `<?php get_template_part('loop' ,'home-page') ?>`you would call it loop.php not sure if that helps at all.
Another thing is make sure your page is using your custom template file as this could also be your problem. What is the name of your custom page file? if it's home.php this may be the problem. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -2,
"tags": "child theme"
} |
custom Background not showing after upgrade?
I've been using wp3 custom background feature. Today I updated to the latest version and now my custom background isn't showing. Strange thing is Appearance > Background still shows the custom background I'm using. Has anyone seen this problem?
Thanks in advance. | This blog post helped me solve my issue.
Changing `<body>` in header.php to
<body <?php body_class(''); ?>> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "theme development, themes"
} |
Theme Options Menu Item - Permission Issue
I am trying to create a theme options menu item for my custom theme. However, when I add the following piece of code in the functions.php file...
add_menu_page('Page title', 'Asteria', 'manage_options', 'ThemeOptions', 'my_magic_function');
It gives me the following error when clicking on the menu item...
> You do not have sufficient permissions to access this page.
The entire folder, and all contents are 777'd. I am logged in as an administrator. I have tried this on 2 different servers. One of the servers is running a network of blogs (the preferred server), the other is just a single blog setup.
Any ideas on where I went wrong? | Theme Options should use the `edit_theme_options` permission, _not_ the `manage_options` permission. The former is the permission intended for editing Theme options; the latter is the permission intended for editing **site** options. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "themes, customization, menus, options"
} |
WordPress/BuddyPress plugin to allow users to create members-only posts
I'm setting up a site using BuddyPress and I'd like to be able to give members the option to create new blog posts that are viewable only to members of the blog itself. I've found a couple of plugins (s2member, for example < ) that seem to do a great job of allowing the admin to restrict posts and content behind a paywall, but nothing that really seems to add anything into the Post Edit screen that's simple for an end user to interact with.
Basically, I'm looking for something that adds a "Members only" radio button option to the Visibility selector in the Publish meta box. I've checked the BuddyPress plugin repo and the WordPress one as well, but haven't really found anything. I'm almost ready to roll my own, but didn't want to re-invent the wheel. Anyone know of anything, or should I get coding?
Oh, one other option: is this built into WP or BP and I'm just being really, really stupid? | I'm not sure if this is what you're looking for but it has worked for me in the past: <
You may have to modify it to allow members to check the box but it's a start. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "buddypress, plugin members, privacy"
} |
How to set file type in wp_handle_upload?
I'm using `wp_handle_upload` to allow users upload `.csv` files in the front end and it's working fine. I was wondering how can I limit this to only allow `.csv` files though since currently it accepts a wide variety of file types. According to the doc this should be possible by overriding the `$overrides` param but I'm not sure what should I pass it to do so.
Thanks in advance! | Got it, looking at the source code I came up with this:
wp_handle_upload($file_input, array('test_form' => false, 'mimes' => array('csv' => 'text/csv')));
To override the mime types just pass `mimes` as an array wit the key being the file extension and the value as the mime type. | stackexchange-wordpress | {
"answer_score": 8,
"question_score": 3,
"tags": "uploads"
} |
Is this the correct way to add post-slug input field?
I added slug input field in my custom post type and allow users to edit it at front end. Then, when insert post, I use this:
$wp_insert_post_args = array(
'post_status' => 'publish',
'post_type' => MY_POST_TYPE,
'post_author' => $this->creator_id,
'post_title' => $this->name
'post_name' => sanitize_title( $this->slug )
);
My custom post type already suports 'title', so, it suppose to auto generate post_name. Now I add $slug as 'post_name' as described above, **will woredpress use 'title' to generate 'post_name', or use my 'slug'?** will wordpress perform slug exist checking as it does on normal posts, or should I take care of the checking myself? | If the slug exsit WordPress will add a number to the end. For example if you had two post named "test" you would get "test" and "test-1"
Hope that helps | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom post types, slug, wp insert post"
} |
How to check an array of $curauth fields?
How do I check an array of $curauth user data? I need to check to see if one or more $curauth fields have data, and if so, print some html. This throws an array error:
<?php if ( !empty( array ( $curauth->facebook, $curauth->linkedin, $curauth->twitter)))
{ echo 'echo me if any $curauth info exists for the fields in the array above'; } ?>
**Update - this works:**
<?php if (!empty ($curauth->facebook) || ($curauth->linkedin) || ($curauth->twitter))
{ echo 'echo me if any $curauth info exists for the fields in the array above'; } ?> | Try
<?php
if ( !empty( array ( $curauth->facebook ) ) ||
!empty ( array ( $curauth->linkedin ) ) ||
!empty( array( $curauth->twitter ) ) )
{
echo 'echo me if any $curauth info exists';
}
?>
**Note:** This can be all on fewer lines, I've just put in additional line-breaks to make it all fit to avoid a horizontal scrollbar.
* * *
**Update** :
Reading up on Author Templates made me realise that once you've set the `$curauth` variable, e.g.
$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
you should be able to use this instead:
<?php
if ( !empty ( $curauth->facebook ) ||
!empty ( $curauth->linkedin ) ||
!empty ( $curauth->twitter ) )
{
echo 'echo me if any $curauth info exists';
}
?> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 2,
"tags": "array"
} |
How to override my plugin's php classes with duplicates that are in my child theme folder
I have a child theme in wordpress and one of the plugins I am using is called jigoshop.
I made a copy of a few php classes from the plugin and placed them in my child theme folder. I want these clases to override the ones from the plugin folder.
How would I go about doing that?
Thanks!! | I'm assuming this is mostlikly a hiearcy problem. For example, your stylesheets load in the order of child theme then plugin. What you need is to load the plugin styles first then your child theme.
You have a few options:
1. Add the Css for your plugin manually after `wp_head()` in your `header.php`
2. Unregister the plugin css file and then load all the styles in your theme's `styles.css`
3. Register a new style to be inserted after the plugin runs.
Without really digging into the plugin or your code it's hard to give you an example. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 2,
"tags": "plugins, child theme, css"
} |
Taxonomy search filters
I have developed an educational courses database of several countries using several taxonomies. Country, institute, study level and some other are taxonomies. If user click on some country, all courses in that country will appear. How the result can be filtered (institute, study level etc) while remaining in the same country.
I would like to put it on archive page so each search could be further filtered. | You could make use of `add_query_arg()` and `remove_query_arg()` here. For example would show results of Pune University in India. You could add `s=symbiosis` to search in the filtered results too. Basically this url would help you out -> < | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "filters, search"
} |
Thesis Theme Custom Loop
I am building a website using Thesis theme and am using Thesis Custom Loop API with custom WP_Query . When I do this on single page it doesn't show the comments form. How can I add a comment form on the single post page | Insert this code after the loop:
<?php comment_form(); ?> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "comments"
} |
qTranslate with my own theme and settings
Basically I have my own theme and my own settings page. In that settings page I have a textfield which contains a Welcome Text to show at the top of the website.
Now, I want this theme to works with qTranslate. To make the content of this textfield multi-language, it would be easy just to let the user add the qTranslate tags by himself within it.
However, internally, while I'm rendering the Welcome Text, which function of qTranslate should I call? It would be perfect if I could pass to it only the text (with the tags) in argument, and depending on the current language qTranslate would give me back the right part of the text.
Thanks a lot for your help :) |
You can use `_e();` function to echo your variable and `__();` to return your variable. Qtranslate hooks into these functions and translates following your input. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "theme development, themes, theme options, plugin qtranslate"
} |
How do I set a custom page template for a custom post type?
I need to set a custom template for a custom post type with standard wordpress functionality like this: Creating_Your_Own_Page_Templates
I found these: 1 - custom post template , 2 - single post template , but its not working for a custom post type and this works only for built-in wordpress posts. | I went through the same problem a few months back. After several different ways I finally found a way that worked. Try adding this to your themes functions.php file _(be sure to replace both instances of portfolio to match the actual names you use)_ :
<?php
add_action("template_redirect", 'your_cust_pt_redir');
function your_cust_pt_redir() {
global $wp;
global $wp_query;
if ($wp->query_vars["post_type"] == "portfolio") { // Change Portfolio to your Post Type
if (have_posts()) {
include(TEMPLATEPATH . '/portfolio.php'); // The Custom Template
die();
} else {
$wp_query->is_404 = true;
}
}
}
?> | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "custom post types, themes"
} |
For homepage images (for small business website), is it better to use custom fields or post_thumbnail?
Already searched on here and couldn't find question so forgive me if it's been asked. _I'm trying to use dynamic images on a homepage so my client can maintain the images._ I've seen tutorials where one person uses post_thumbnails while another uses custom fields. Do I need to create a post for each image and display post_thumbnail on homepage? Or is it better to use custom fields for one post to display multiple images?
Reference:
`the_post_thumbnail()` <
`get_post_custom()` <
similar question | If your page is a portfolio index, where each image is meant to relate to a post or page, then post thumbnails would be the way to go.
If your page is simply a gallery page, and the images don't relate to any content beyond that page, then the best method would be to upload images as attachments to that page and output them in your template with get_posts. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "custom field, images, post thumbnails, homepage, customization"
} |
What is the php function for "user's public profile"
My header looks like this.
!enter image description here
I chnaged my author base from "author" to "user"
So the user profile url looks like this.
<
What is the php function to get this url.
I'm using like this
<a href="<?php echo esc_url( home_url( '/' ) ); ?>user/<?php echo $current_user->user_login ?>"><?php echo $current_user->user_login ?></a>
Its working. But its hard coded.
Is there any other php function to get the url? | For all author meta details you can use `the_author_meta`
<
<a href="<?php the_author_meta('user_url', $current_user->ID);?>"><?php the_author_meta('display_name', $current_user->ID);?></a>
If its for user meta use `get_user_meta`
<
<a href="<?php echo get_user_meta($current_user->ID, 'user_url');?>"><?php echo get_user_meta($current_user->ID, 'display_name');?></a> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "profiles"
} |
$wpdb->insert not working in any way
I know this type of question has been asked over and over, but I couldn't find a solution for my problem, so I hope you can help me. I am using WP 3.3. and I have created a custom table. Now I want to insert some data into it, but I can't get it working. This is my code:
global $wpdb;
$table_name = $wpdb->prefix . "my_data";
$wpdb->insert($table_name, array(
'my_id' => NULL,
'my_day' => $day,
'my_month' => $month,
'my_abbr' => $abbr,
'my_venue' => $venue,
'my_geo' => $geo_one.", ".$geo_two,
'my_artist' => $artist,
'my_link' => $link
)
);
I am trying to insert data for several hours now without luck. To my eyes the code is correct, but I guess I am just mussing something important here. Any pointers would be appreciated! Thank you | When `$wpdb` method doesn't perform as it should it is likely issue with resulting SQL query (because of wrong input or something else).
Follow `wpdb reference in Codex` for troubleshooting:
* enable database error display via `$wpdb->show_errors()`
* check what query is being formed and run via `$wpdb->last_query` | stackexchange-wordpress | {
"answer_score": 17,
"question_score": 9,
"tags": "wpdb"
} |
hide wp-content from urls
Here is what I am thinking of trying to hide wp-content from the urls of files included in page source.
defining the following in wp-settings.php
define ('WP_CONTENT_URL','
and adding this to `.htaccess`
RewriteRule ^myownfoldername/(.*) /wp-content/$1 [QSA,L]
This seems to work fine with no additional plugins on localhost `but will it work seamlessly on the online site with a few plugins. I am more concerned about w3 total cache.
I guess I need now worry about a few reference of wp-content in database as even if it exists there it is still a valid link? | You don’t need a separate rule in your .htaccess. Add …
define( 'WP_CONTENT_DIR', 'YOUR_LOCAL_PATH' );
define( 'WP_CONTENT_URL', 'YOUR_PUBLIC_PATH' );
… to your `wp-config.php`. Do **not** write into `wp-settings.php`. This file will be overwritten during the next update – never touch a core file. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 0,
"tags": "urls, htaccess, plugin w3 total cache, wp config, settings api"
} |
Author template help. How to check if field exists in the profile?
I'm coding my author template.
I want something like this
<?php if(Author filled about me)) { ?>
<div class="title">About me</div>
<div class="descwrap">
<div class="descinner"><?php echo about me; ?>
</div>
</div>
<?php } ?>
I tried this code. But its not working.
<?php if(isset($curauth->description)) { ?>
<div class="title">About me</div>
<div class="descwrap">
<div class="descinner"><?php echo $curauth->description; ?>
</div>
</div>
<?php } ?>
CAn anyone help me? Thanks | <?php if(!empty($curauth->description)) { ?>
<div class="title">About me</div>
<div class="descwrap">
<div class="descinner">
<?php echo $curauth->description; ?>
</div>
</div>
<?php } ?>
This should work for you. It checks if the variable is empty or not ( | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "templates, author, author template"
} |
How to customize wordpress sidebar widget
**This is how i registered my sidebar:**
register_sidebar(array(
'name' => 'Post Sidebar',
'before_widget' => '<div class="widgetdiv"><div id="%1$s" class="widget %2$s">',
'after_widget' => '</div></div>',
'before_title' => '<div class="titlediv">',
'after_title' => '</div>',
));
**The problem I have:**
Title div wrapped inside widgetdiv. The above code output like this.
<div class="widgetdiv">
<div class="titlediv">My title
</div>
</div>
**My requirement:**
<div class="titlediv">My title
</div>
<div class="widgetdiv">
</div>
I mean titlediv should be outside widgetdiv
Can anyone give me good solution?. Thanks | register_sidebar(array(
'name' => 'Post Sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div></div>',
'before_title' => '<div class="titlediv">',
'after_title' => '</div><div class="widgetdiv">',
));
You will have a wrapper div, then your title div and then your widgetdiv. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "widgets, css, register sidebar"
} |
Modify Notification Message When Profile Updated
I have added new fields on the user profile page.
I want to display a message that says: "It's good ... or not"
I couldn't find a hook in the WordPress codex.
I don't want to use a plugin only my own code I want change this code :
<div id="message" class="updated">
<p><strong>Updated profile </strong></p>
</div> | You will have to use a gettext filter as there are no hooks or filters associated with your request.
function custom_user_message($translation, $text){
if('Profile updated.' == $text){
$current_user = wp_get_current_user();
$foo_condition = ''; //Do some checking here for user custom field
if(!$foo_condition)
return $text.' Custom Message';
}
return $translation;
}
add_filter( 'gettext', 'custom_user_message', 10, 2 ); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "hooks, profiles"
} |
Can I use the same nonce for multiple requests on the same page?
Or does this break the purpose of the nonce, which I admint I don't quite understand it? :)
For example on two ajax requests that run on page load, or when something is clicked:
$.ajax({
type: 'post',
url: 'admin-ajax.php',
data: { action: 'foo',
_ajax_nonce: '<?php echo $nonce; ?>' }
});
$.ajax({
type: 'post',
url: 'admin-ajax.php',
data: { action: 'foo2',
_ajax_nonce: '<?php echo $nonce; ?>' }
}); | The WordPress nonce creation function is to be called only on the `init` hook:
> Use the init or any subsequent action to call this function. Calling it outside of an action can lead to troubles. See #14024 for details.
Since the `init` hook "runs after WordPress has finished loading but before any headers are sent", nonces are created on every full-page request (not ajax request). So, technically, you can use the same nonce on multiple requests, but **you should make them unique on each request** , as other answers have pointed out.
* * *
To shed some more light about what nonces are:
**Nonces are sent on each Ajax request as a security token,** to ensure the request was intended by the user. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 13,
"tags": "php, ajax, nonce"
} |
Problems with my conditionals in single.php by category
In my single.php file I would like to have a conditional that checks for the category of the post and display certain images and layout. Here is what I have: < | Look at <
Example:
<?php if ( in_category('rabbis-weekly-commentary') ) : ?>
<div id="inner_header">
<img src=" border="0">
...
<?php elseif ( in_category('yaels-weekly-commentary') ) : ?>
<div id="inner_header">
<img src=" border="0"> | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "categories, conditional content, single"
} |
Human time difference in months instead of days. How?
I use the following code in my template.
<?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago'; ?>
It shows like 2 days ago, 20 days ago, 90 days ago.
Is there a way to show 1 week ago instead of 7 days ago, 1 month ago instead of 30 days ago, 1 year ago instead of 365 days ago?
Thanks | As far as I know that's as deep as wordpress can go, you will have to use php to get it into weeks/months/etc.
You have 2 options:
Use `human_time_diff` and create a function that just calculates the differences(pretty easy to figure out 7 days = 1 week, etc). I would honestly not use `human_time_diff` though and use `strtotime()` with this method instead.
The other option is to use the DateTime and DateInterval objects in php 5.3 +. You can see an example here ( second answer), < | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "date time, timestamp"
} |
Disable a plugin's widget
I wonder if possible to disable a widget that belongs to a plugin that is currently active w/o touching the plugin code.
For sample, I normally use a code like this to disable wordpress widgets,
unregister_widget('WP_Widget_Text');
Now, I want to also deactivate let's say for sample the widget called "The other Widget"
is that possible?
Thanks in advanced. | You must use `widgets_init` hook with a high priority for example this will remove the default WP Widgets
function unregister_default_wp_widgets() {
unregister_widget('WP_Widget_Pages');
unregister_widget('WP_Widget_Calendar');
unregister_widget('WP_Widget_Archives');
unregister_widget('WP_Widget_Links');
unregister_widget('WP_Widget_Meta');
unregister_widget('WP_Widget_Search');
unregister_widget('WP_Widget_Text');
unregister_widget('WP_Widget_Categories');
unregister_widget('WP_Widget_Recent_Posts');
unregister_widget('WP_Widget_Recent_Comments');
unregister_widget('WP_Widget_RSS');
unregister_widget('WP_Widget_Tag_Cloud');
}
add_action('widgets_init', 'unregister_default_wp_widgets', 1); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "widgets"
} |
Grant a person permission to moderate all comments on a blog without giving them the ability to edit other peoples post
I'm trying to figure out how to create a wordpress role that grants the user the ability to only moderate all comments (including for posts that aren't there own). The only way I've been able to do this is by granting them the ability to edit other peoples posts, but I don't want to give them that much permission.
Any idea how to do it? | Justin Tadlocks Members Plugin is a great start. Create a new role and give them the permission of `moderate_comments` and you should be good to go. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "comments, user roles, user access"
} |
Get posts by meta data OR title
I have a _working_ query that calls all my posts that have a certain meta value for one of two meta keys:
$term = filter_var( $_GET['term'] );
$query = get_posts( [
'post_type' => 'some_cpt_name',
'meta_query' => [
'relation' => 'OR',
[
'key' => 'foo',
'value' => $term,
'compare' => 'LIKE',
],
[
'key' => 'bar',
'value' => $term,
'compare' => 'LIKE',
],
]
] );
I need to query all posts that have the `$term` as meta key "foo" or "bar" or as post title. Problem is _how to_ add the post title as additional possible key?
> **Q:** How can I _also_ check if the `$term` maybe is in the `post_title`? | As with most questions involving `OR` clauses, the answer is the same: use a custom query or alter `WP_Query` using the `'posts_clauses'` filter. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 3,
"tags": "wp query, query posts, query, get posts"
} |
RSVP form for Facebook events from a Wordpress post?
Is there a way to add a RSVP form to a Facebook event in a Wordpress post?
(let's assume I have a website linked to a Facebook application and I want to publish public events I have published on a Facebook page also on my website, letting people RSVP from Wordpress and only from my FB page)
thanks | I'm also working on this right now, I'd love if you post your final solution once you get there. Here are two tutorials that may help you.
<
< | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "facebook, forms, events, customization"
} |
Post show up as post and pages
I am having a weird issue lately, in the WP Admin panel, all my Post show up under Post and under Pages, they all link to the same article. If I create a new Post it shows up under Pages as well. I am running the newest stable version of WP, I have tried all my themes even the twentyten and twentyeleven themse, it still happens. I have never had anything like this happen, any ideas?
* * *
**UPDATE**
Ok I have no idea what the actual cause is but I did install a fresh version of WP and then made a post and it worked as normal, only showed up under post and not under pages. I then installed the theme I am working on and made a post, it showed up under post and pages so it has to be an issue somewhere in my theme...pretty weird issue though, because even with my theme not in use, it still makes it happen just by being there | I just wanted to post the solution here instead of deleting just in case this ever helps anyone else.
The problem was this 1 small function I had tucked away in a setting file...
/**
* change number of posts shown per page in admin area
*/
function admin_pagination(){
global $wp_query;
$per_page = 5;
$wp_query->query('showposts='. $per_page);
}
add_action('admin_head', 'admin_pagination');
This caused all `Post` to show up under the Admin section for `Post` and `Pages` so do not use it! I had found this snippet on a WP site somewhere | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "errors"
} |
category filter doesn't work
I am assuming because I don't have a category template it is defaulting to the archive template, would that affect the outcome.
it seems to output all the posts that have categories: <
this is source for archive page: < | this is the problem, starting at line 46:
$args = array(
'post_type' => 'post'
);
$post_query = new WP_Query($args);
if($post_query->have_posts() ) {
while($post_query->have_posts() ) {
$post_query->the_post();
//stuff
endwhile;
endif;
you're not using the original query for the page, which contains just posts from the current category, and you're replacing it with a new query that's loading posts of `post_type` = `post`, regardless of category.
to use the original query, change your loop to use the default query:
if( have_posts() ) {
while( have_posts() ) {
the_post();
//stuff
endwhile;
endif;
note the removal of `$post_query->` everywhere. this loop will now use the global `$wp_query` instead, which contains the posts you want to output. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "categories, filters"
} |
Two domains on one Wordpress Installation
I recently changed the base domain on my Wordpress website from < to < I would like to create various of 301 from old domain to new one, but for some reason I can still access pages using the old domain www.fsdegrees.com/blog I though it should come back with 404. I'm just afraid that Google will penalize me for double content.
Any idea why that's happening. Many thanks, | I just did this on a client site. I set up my rules like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)fsdegrees.com [NC]
RewriteRule ^(.*)$ [R=301,L]
The first rule checks the incoming domain and verifies that it is the old domain. The second sends a 301 redirect and visitors are sent to the corresponding page on the new domain, assuming that the URL structure has remained the same. You do not want to just serve up a 404 page as you will lose all of the indexed links in search engines. 301 redirects will tell search engines where the new replacement pages are. (You'll get 404 ONLY if the new pages cannot be found.)
And these rules will work whether both domains point to the same folder or if they point to different folders. In the case that they point to different folders, you will have to add these rules to an .htaccess file in the old domain folder. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 2,
"tags": "htaccess, installation, domain, core modifications"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.