INSTRUCTION
stringlengths 11
999
| RESPONSE
stringlengths 0
999
| SOURCE
stringlengths 16
38
| METADATA
dict |
---|---|---|---|
Using a number for limiting registering or banning on multisite
I want to ban people or limit registering on unique national ID (You can think it as 11 digit number). Is there any plugin or a code snippet you know? Site will based on MultiSite + BuddyPress.
**Update:** I am not looking for IP ban. You can think it like phone number.. And every user must have 1 unique phone number and i need to ban that phone number if need.
(Sorry for bad english)
|
first of all, thanks a lot for every answer and everyone who thought a solution for this.
my best possible solution without changing too much thing:
As i said in a comment, i will use < for registering. This plugin working even you disable wordpress user registeration. So i will disable user registeration and this plugin's form will be only way to register to this site. Critical option in there was "No Duplicates". I will select "No Duplicates" for this number input so plugin will use its previous form data for not letting 2 registeration with this number. So if i want to ban someone, i can just ban him with normal wordpress banning system and he cant register twice so problem is solved imo.
And again thanks a lot for trying to help :) **Note:** I am not doing adversitement or anything, just sharing my solution so i hope its ok.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "multisite, users, user registration"
}
|
List all sidebars in metabox
I'm trying to add a metabox to select a sidebar per page. In order to create the metaboxes I use this class
The construction is fairly easy:
$meta_boxes[] = array(
'id' => 'sidebars_side',
'title' => 'Page Sidebar',
'pages' => array('page', 'post'),
'context' => 'side',
'priority' => 'low',
'fields' => array(
array(
'name' => 'Sidebars',
'id' => 'tst_sidebars',
'type' => 'select',
'options' => array(
ARRAY OF SIDEBARS GOES HERE
),
'multiple' => false,
)
)
);
But I can't for the love of God to construct the array properly. I checked this post
which is great, but I'm stuck somehow. Any help would be highly appreciated.
|
The class you are using accepts value => name pair in the select options array so
foreach ( $GLOBALS['wp_registered_sidebars'] as $sidebar ) {
$sidebar_options[$sidebar['id']] = $sidebar['name'];
}
and then you can use `$sidebar_options`.
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 0,
"tags": "metabox, sidebar"
}
|
Which KSES should be used and when?
The WP source shows that `wp_filter_kses` and `wp_filter_post_kses` are passed data that's "expected to be escaped with slashes."
On the other hand, `wp_kses_data` is passed data that's "expected to not be escaped" and `wp_kses_post` has code that looks like wp_kses_data.
How safe is it to pass unknown (in terms of escaped with slashes) data to these functions?
Can the first set be preferred over the second or is preferring the second set safer?
Or is this a case where you absolutely need to know the condition of your data in terms of slashed?
\--update--
I'm now figuring that if you don't know whether the data is escaped you could use `wp_kses_data( stripslashes_deep( $data ) );` and run the return though addslashes() if you need escaped in the end.
|
From the codex:
> wp_filter_kses should generally be preferred over wp_kses_data because wp_magic_quotes escapes $_GET, $_POST, $_COOKIE, $_SERVER, and $_REQUEST fairly early in the hook system, shortly after 'plugins_loaded' but earlier then 'init' or 'wp_loaded'.
The first set is then preferred. More of a question of, "is stripping slashes more secure than not?" They both use the same allowed HTML. Well yeah it depends, in absolute cases, but I would assume that it is more secure to than not to.
Basic useage of kses:
$filtered = wp_kses($unfiltered, $allowed_html, $allowed_protocols);
All of the wordpress kses functions then just do
$filtered = wp_kses($unfiltered, $allowedtags);
SO:
$filtered = wp_kses_data($unfiltered);
$filtered = wp_filter_kses($unfiltered); // does the same, but will also slash escape the data
the `post` variations use a different set of tags; those allowed for use by non-admins.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 7,
"tags": "security, sanitization"
}
|
Can WordPress email the admin about PHP errors, while hiding them from the site?
Is it possible to have WordPress email the site administrator whenever a PHP error message is displayed? Ideally the message would also be filtered out of the HTML output, so as to avoid information disclosure.
I ask because, while `@ini_set('display_errors', 0);` is at the top of my `wp-config.php` and working nicely, I want to receive notifications about errors.
I will happily write a custom plugin to do this, if someone who knows more about WP can point me in the direction of where I might hook in to get the job done.
Final bit: Am I crazy for wanting something this out-of-the-ordinary?
|
Displaying PHP errors isn't really a WordPress thing, it is more of a PHP thing directly. No, I don't think you are crazy for wanting this, I had a similar need for a separate application and I wrote this blog post which should be helpful.
Essentially, define your own error handler.
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 1,
"tags": "php, errors"
}
|
Captions for More Fields groups, not just individual fields
I'm using More Fields to create some meta boxes on my custom post type. Is it possible to have a caption for each "group" of fields in the More Fields options? I would like to provide some basic information on the post edit screen.
I see you can enter a caption for each individual field but it would be handy to be able to give the group a caption also.
|
At this point in time I would just as soon not use the More Fields plugin at all, as there are native functions that can do everything you probably want with custom fields. There seems to be no good documentation afoot and the plugin site is obviously not being updated.
Alternatively, try WPAlchemy. Quite easy to make discrete meta boxes with multiple form elements and whatever else you want to put into them, including blocks of text.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "captions, customization"
}
|
How can I just get content inside a shortcode or just outside
Suppose I have content like
[xxx]
Here is some content in xxx
[/xxx]
Here is content outside xxx ...
Can I somehow just get
1. content inside `[xxx]` ONLY
2. content outside `[xxx]` ONLY
|
Depends on the shortcode. If you have access to the shortcode's handler function, that function's second argument is the content inside the shortcode:
function wpse20136_shortcode( $atts, $content ){
// $content has the content inside xxx
}
register_shortcode( 'xxx', 'wpse20136_shortcode' );
For getting all content not in shortcodes, that's easy. `strip_shortcodes()` does that:
strip_shortcodes( get_the_content() );
for example, will give you the content of the current post with only the content not inside shortcodes.
|
stackexchange-wordpress
|
{
"answer_score": 6,
"question_score": 4,
"tags": "shortcode"
}
|
Site stuck in "Database Update Required" loop
I just updated to 3.1.3 and now when I go to the admin I get the "Database Update Required" `/wp-admin/upgrade.php` screen. I click 'Upgrade Now' and it says it's done, but then trying to access anything in the admin gets me the same screen again. How do I get past this?
EDIT: In trying to use toscho's solution, I discovered that my wordpress db tables are not writable, which likely led to the error loop. Any ideas for how to track that down?
|
Discovered that the db files I copied over from another machine had incorrect ownership. Once I `chown -R mysql:mysql myblogdbdirectory` and restarted MySQL, the database upgrade worked.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 11,
"tags": "database, upgrade"
}
|
Send email to Admin when user/member updates specific user/member data
I have previously asked about How to automatically send email to Admin when a user/member changes his/hers profile data. And got some very good answers. Send automatic mail to Admin when user/member changes/adds profile
Now a follow up: I only want to send/email the data (profiledata) that was updated/added.
|
So, as Bainternet notes, you would need to compare the new field value to what it was right before the edit. In essence, you will need to build in version control for the profile fields. You will need to add a database table to store this info, using the the `$wpdb` object to write, and read from it.
Basically, on `personal_options_update` and `edit_user_profile_update` you will glean the data as in the previous answer, but then also compare it to your table storing the what existed in the previous save. You'll only send a particular field's data if there is mismatch.
|
stackexchange-wordpress
|
{
"answer_score": -1,
"question_score": 2,
"tags": "admin, email, updates, automation, profiling"
}
|
How do I fix my 'Path' field when editing pages via the Dashboard?
I am encountering the same problem described here: Unable to set path. In every module where I can edit a page, a `p` appears after the word 'Path'. I can click on it; clicking on it highlights some of the text.
How do I fix this issue? !enter image description here
|
The path in the editor is just for reference, most of the time users do not even bother looking at it and those that do use if to see what html tag there are in.
**Example:**
<p>
This is just a sample paragraph
</p>
<span>
This is just a sample span
</span>
<blockquote>
This is just a simple blockquote
</blockquote>
If i was in the blockquote tags the path would be `PATH: blockquote` or in the span `PATH: span`. All in all the feature is use full to most and use less to some OR use full to beginners and use less to advance
Just a side note it does not have anything to do with the path of your site that is the line below the title field
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 2,
"tags": "editor, dashboard"
}
|
Insert PHP code via shortcode?
I wanted to insert a form with a line of PHP code via shortcode. I am wondering if it's allowed? Has anyone tried it? Take the following for example:
function get_form($atts) {
return '<form method="post" action="">
<input type="input" name="myinput" value=""></input>
<input type="hidden" name="myvar" value="<?php echo $current_user->ID; ?>">
</form>';
}
add_shortcode('myshortcode', 'get_form');
I hope it's clear now...
|
`$current_user` isn't declared in the scope of that function. You'd want to modify the code to be more like this:
function get_form($atts) {
$current_user = wp_get_current_user();
return '<form method="post" action="">
<input type="input" name="myinput" value=""></input>
<input type="hidden" name="myvar" value="' . $current_user->ID . '">
</form>';
}
add_shortcode('myshortcode', 'get_form');
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 0,
"tags": "shortcode"
}
|
jQuery gallery plugin to interface with Picasa
I'm looking for a specific type of gallery plugin implementation.
First of all, it needs to be able to pull from Picasa.
Second, I would like it to basically be a static lightbox...and what I mean by this is:
* Single image displayed with previous/next buttons
* Able to display the image title/description
* Able to display `Image <x> of <y>`
* Preferably make use of jQuery
At this point, I'd prefer to hide all gallery thumbnails and give the focus on the main image. If thumbnails could be easily hidden and shown with a config option, that would be OK.
|
Picasa plugin i think it'll help you,or help to start a new plugin with some ideas..
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "plugins, gallery"
}
|
WP function/filter for modifying http headers?
Is there a dedicated WP function, action or filter to use when adding/modifying the HTTP headers?
For now I just hook a PHP header() call into the WP 'init' hook like this:
add_action('init', 'add_header_xua');
function add_header_xua(){
if(!is_admin()){
header('X-UA-Compatible: IE=edge,chrome=1');
}
}
But is this the correct way to do that?
|
The init action is the wrong place to do it. A better place would be at template_redirect, so that you only affect the front end view of the site and not the admin areas.
|
stackexchange-wordpress
|
{
"answer_score": 9,
"question_score": 18,
"tags": "api, headers"
}
|
Transient / object cache maximum key length
> **Possible Duplicate:**
> Long option names fail silently?
The WordPress Transients API makes it easy to save expensive values and look them up later. If you install an object backend (such as APC object cache, memcache or W3 Total Cache) you can cache these values between requests, gaining even more.
But I've noticed that when the name of a transient field is too long, it simply doesn't bother caching it. Aside from being somewhere in the region of 50 characters, I don't know what the maximum length of these names is.
Is this documented somewhere? Does it depend on what backend you're using?
|
A transient that doesn't expire has a max name length of 53 characters yet a transient that does expire has a max name length of 45 characters.
<
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 3,
"tags": "cache, plugin w3 total cache, transient"
}
|
Check if post/page has gallery?
I'd like to run some code only if a gallery (inserted with the `[gallery]` shortcode) has been inserted into a post/page. I did the following:
gallery_shortcode($post->ID) ?
$gallery = 1 : $gallery = 0;
However, this always sets `$gallery = 0` whether there's a gallery or not. Am I using this incorrectly?
|
try :
if (strpos($post->post_content,'[gallery') === false){
$gallery = 0;
}else{
$gallery = 1;
}
|
stackexchange-wordpress
|
{
"answer_score": 15,
"question_score": 6,
"tags": "shortcode, gallery"
}
|
Get posts by menu ID
I'm a little stuck here. I have a menu in Wordpress with some posts in it. What I would like is to retrieve all the posts as objects.
I think I'm pretty close, but the SQL query doesn't seem to work as I want.
This is wat I have so far:
$querystr = "
SELECT wposts.* FROM wp_posts wposts
LEFT JOIN wp_postmeta wmeta ON wposts.ID = wmeta.post_id
LEFT JOIN wp_term_relationships wrel ON wrel.object_id = wmeta.meta_value
LEFT JOIN wp_terms wterms ON wrel.term_taxonomy_id = wterms.term_id
WHERE wterms.term_id= $menu_id
";
$posts = $wpdb->get_results($querystr, OBJECT);
I'm pretty sure it's a stupid little SQL logic error, but I realy can't find it..
|
I recently needed the same thing, I had menu of categories and I needed to get the categories that in the menu. After a several hours digging in the WP core, I found the **wp_get_nav_menu_items()** function that helped me.
I finnally came with this, 220 was my menu_id
$navcat = wp_get_nav_menu_items('220');
foreach ($navcat as $obj) {
$catid = $obj->object_id;
$category = get_category($catid);
...
...
}
So, if you have a nav menu of posts, I assume you can do the same, something like this should work -
$nav_items = wp_get_nav_menu_items('220');
foreach ($nav_items as $obj) {
$objid = $obj->object_id;
$postobj = get_post($objid);
//do stuff with the post..
}
I think it can save you some complexed mySQL query...
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 4,
"tags": "wp query, query posts, database, mysql"
}
|
Add dollar sign and commas to a number?
I have a field on the admin side where a user enters a number for a price. If a user enters 1000000 I'd like to be able to display on the front-end $1,000,000.
Any ideas on how to accomplish this?
**Edit** More details, the post is a custom post type 'property'.
To add the meta fields on the back-end I'm using Meta Box Script, <
The code to display the numbers on the front-end I use
$meta = get_post_meta(get_the_ID(), 'rw_propPrice', true); echo $meta;
|
To format number, you can use the function `number_format_i18n` (it's not documented now, but you can see its source here). Its work is format the number based on the language. You might want to look at `number_format` (PHP built_in function, and is used by `number_format_i18n`) to have more control to decimal point and thousand separator.
In your case, this code will help you:
$meta = get_post_meta(get_the_ID(), 'rw_propPrice', true);
echo '$' . number_format($meta, 0, '.', ',');
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 3,
"tags": "formatting"
}
|
Restore a Plugin's Default Settings
Is there a way to code "Restore Defaults" button into a plugin options page?
I'm writing a plugin right now that has sets up some default values on activation (via `register_activation_hook`), and I'd like to give users the option to restore those defaults again with a click. Possible?
Thanks!
|
Nevermind, answered my own question:
<
Used that to update all the text and drop downs. Couldn't get it to work with my checkboxes, but a few other lines of jQuery took care of those. I like the idea of just auto filling the form with the defaults, rather than submitting it right away.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 2,
"tags": "plugins, options"
}
|
How does order=asc effect a wp_query (its acting pretty weird in a loop)
I have a wp_query for a custom post type: events. I have a seven day calendar that is showing featured events on a page. Here is the wp_query and supporting code:
<
you can see the calendar at seattleite.com/calendar/
the thing works great with one exception. It should be showing a featured event on Sunday. If I change the order => 'asc' to order => 'desc' I see the event for sunday but then I lose the event for today.
If I simply remove the order => item then I see what I see if I set order => 'desc'
any idea how order is affecting my loop?
|
If anyone comes across this question. WordPress Codex says the following to `'orderby' => 'meta_value'` and the `order` param:
> Note also that the sorting will be alphabetical which is fine for strings (i.e. words), but can be unexpected for numbers (e.g. 1, 3, 34, 4, 56, 6, etc, rather than 1, 3, 4, 6, 34, 56 as you might naturally expect).
You are querying event dates, so the order of the results might be wrong because of this alphabetical sorting.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 1,
"tags": "custom post types, customization, wp query"
}
|
How to create a public profile for authors/contributors/users?
I would like to add a public profile page to the authors and others contributors in my site. where visitors can see their profile info. I don't wanna use Buddypress, is it possible with WordPress alone?
|
bainternet posted something in **this thread** that will help you, (this is actually editing user profiles from frontend) but it will give you the idea, then just echo the fields out on **author.php**
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 4,
"tags": "users, profiles"
}
|
How to convert multi-site to single site
I need to take a site that is installed as a subdomain blog on a multi site install and move it to it's own domain on a standalone wordpress installation.
How can this be done?
I am running into trouble with the path to the images in posts because multi site uses `/blogs.dir/blogid/`
Can this be done?
|
Although I have not tested a use case such as yours.
If the trouble is with path to the images in the posts and other you can give WordPress OneClick Migration a try. It was designed with Database level migration but it should work. You may need to run it in forced mood. See the Readme file for full details.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 1,
"tags": "multisite, migration, single"
}
|
Server side validation for Contact Form 7
I'm trying to use contact form 7 on my site.
The only server side validation that it seems to do is check if required fields have been entered.
Isn't there a danger if someone sends several MB of data through tools like tamper data?
Will I need to rewrite the plugin code to take care of validation?
|
It doesn't take much to tamper data when you use HTML forms; you don't even need a plug-in to do that. That's inherent in all HTML forms.
If you're that worried about people tampering with your data, yes, you'll need to rewrite the plug-in code to use session variables or a digital signature.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 2,
"tags": "plugins, validation, plugin contact form 7"
}
|
Wireframe tool for WordPress theme
I want to develop a WordPress theme from scratch. Is there any wireframe tool in which I can design the a complete page and it exports the html/php file against it. I want a free tool.
|
I personally do not know of any free tool that would achieve what you are looking for. The closest thing would be to use a "slice and chop" company that would take your designs and slice them up for you at a price though.
There is a great "blank" wordpress theme out there that I use on all of my projects. It has all of the files you need for a theme, with most (if not all) of the queries that you need. All you have to do is pretty much style it.
However, the Wordpress Codex is a great resource for learning all the nuts and bolts of wordpress. I know it has been a life saver to me over the years.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "theme development"
}
|
Need category header to link to category archive list
I tried using wp_list_categories, but that just gives me a list of the categories. I currently have this code in my category-recipes.php file:
<ul class="subcats-list">
<h2 class="subcats-title"><?php echo get_cat_name(38); ?></h2>
<?php
$recipes = new WP_Query();
$recipes->query('showposts=5&orderby=rand&cat=38&post_type=recipe');
while ($recipes->have_posts()) : $recipes->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul><!-- subcat -->
I was thinking about putting a link tag before the `get_cat_name` but I am not sure what to include in it.
|
Use get_category_link. Your code (relevant part) will look like:
<h2 class="subcats-title">
<a href="<?php echo get_category_link(38); ?>">
<?php echo get_cat_name(38); ?>
</a>
</h2>
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "link category"
}
|
How to call the_excerpt() with tags or the_content() as an excerpt?
Is it possible to call the_excerpt() with tags intact? I'd like to create a excerpted listing of my posts in a specific category, but I'd also like the links and formatting carried over from the post content.
I'm currently using the_excerpt() which otherwise works fine, however, the tags are stripped out.
I can't find a filter to place on the_excerpt() to do this, so barring that, is it possible to filter the_content() to pull the first 100 words with tags and a read more link at the end?
|
Actually, I just did something like this for a Drupal site. I based my truncation function on this: Truncate text preserving HTML tags with PHP
Use the final version of the function at the end of the comments. The function takes its `$length` parameter in characters, not words, but you can probably use the general rule-of-thumb of 5 characters per word to estimate, if needed.
Hook your function to the `get_the_excerpt` filter, and you should be in pretty good shape.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 4,
"tags": "theme development, excerpt"
}
|
Broken wordpress permalinks on pages only
Not sure when it happened but the custom permalinks for pages on my client's Wordpress site have broken. I can fix it by reverting back to the default permalinks and then using the custom permalinks, but they break again whenever my clients edits a page. Blog posts, archives, tags, categories, and custom post types permalinks all work fine, it's only pages that 404 when using custom permalinks.
The site has an .htaccess file with 666 permissions with the following in the file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
It also has mod_rewrite enabled.
Using Wordpress 3.1.3
It's not the plugins because I have disabled all of them and the permalinks for pages still don't work.
Please help.
|
I was using the Custom Post Type UI Plugin and had generated the following code (which I added to the functions file) for a custom taxonomy through the plugin:
register_taxonomy( 'video_type',
array ( 0 => 'video' ),
array(
'hierarchical' => true,
'label' => 'Type',
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => '' ),
'singular_label' => 'video_type'
Somehow that code broke the theme. In Custom Post Type UI you can either create custom posts types and taxonomies and keep the plugin active or use the beta function to copy and paste generated code to your function file. So I ended up deleting that code and keeping the plugin active.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 4,
"tags": "permalinks, pages"
}
|
plugin_action_links Filter Hook Deprecated?
Says the hook is deprecated. However, the {$prefix}plugin_action_hook_{$plugin_file} is not. I poked around the `wp-admin/includes/class-wp-plugins-list-table.php` file for the hook, and found this:
$actions = apply_filters( $prefix . "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );
`$prefix` is defined a few lines above:
$prefix = $screen->is_network ? 'network_admin_' : '';
Since I was able to get my add_filter call to `plugin_actions_row_{$plugin_file}` to work, I'm assuming the filter hook is still there. Well, sort of: the filter is still available as it's not a network admin screen. Correct? And one could use...
add_filter( 'network_admin_plugin_action_links_{$plugin_file}', 'do_something' )
...to put a link into the network's plugin screen?
|
Yes, both should work as expected:
`"plugin_action_links_{$plugin_file}"`
`"network_admin_plugin_action_links_{$plugin_file}"`
Note that I'm using `"` instead of `'`.
PS: The term is _deprecated_ , not depreciated.
|
stackexchange-wordpress
|
{
"answer_score": 9,
"question_score": 3,
"tags": "plugins, filters"
}
|
Seperate WordPress catagories into sepeat list on seperate pages
Having issues showing my post in separate list based on category
I have a static home page set my page: "home" and I have the blog set to my page: "Inspiration"
I have 2 main categories "inspiration" and "Portfolio" and those catagories are also the titles of my menu items. So I have Home, Inspiration, and Portfolio. But when I go to portfolio it is just a page not a list of the post in the Portfolio category.
I have no problem editing the code since the whole theme is completely custom I am just not sure what to add to make the portfolio page a blog as well.
You can see the half finished site here. www.2020mediaonline.com/wordpress
I am using WordPress 3.1.1. Any help would be awesome.
|
i can't able to understand your question,but i guess ,My answer is login as a Wordpress Admin and select settings->Reading...In There you Select Static Page & Set Front Page and Post page as you want.I think you got Answer.if not means just mention what you want exactly? :)
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "categories"
}
|
Server crashed trying to restore wordpress multisite, images are not found pls help
I had an issue with a server that was serious enough to have to take it completely offline and then rebuild the os.
I have gotten to the point where the new server is up and running. I have managed to get all the wordpress files and database files transfered over to the new server.
**The Problem**
For some reason wordpress is not finding any of the images stored in the wp-content/blogs.dir/... folder.
One thing I did notice is that the htaccess file was not copied over, so my best guess is because wordpress reroutes via /folders/ etc that this may be the problem.
I did take the distrubtion .htaccess file that I was able to find and added that into the site, but it is not working.
Is htaccess the problem?
If so how do I regenerate one that will work for the multisite subdomain setup?
thanks
|
Here is the default .htaccess generated by Wordpress for Subdomain Multisite setup:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]
# END WordPress
Let me know If this one doesn't work for you.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 2,
"tags": "htaccess"
}
|
[Plugin: Posts 2 Posts] reciprocal connections
I'm using Posts 2 Posts plugin. I've got 2 custom types : movies and actors. I created a movie => actor connection so that for each movie I can see which actors play in.
But as far as I understand, in order to find out all the movies a particular actor has played in, you must create an actor => movie connection AS WELL.
So if create a The Dark Knight => Christian Bale connection, I MUST create a Christian Bale => The Dark Knight as well. Because otherwise I won't be able to know that Christian Bale played in that movie based on a "Christian Bale" search.
Is that correct ? If so, is there any way to make it less burdensome ?
|
To see connections on both edit screens, set `reciprocal` to `true`, but note this is for the UI only, it doesn't affect connections otherwise.
function my_connection_types() {
if ( !function_exists( 'p2p_register_connection_type' ) )
return;
p2p_register_connection_type( array(
'from' => 'movies',
'to' => 'actors',
'reciprocal' => true
) );
}
add_action( 'init', 'my_connection_types', 100 );
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 2,
"tags": "plugins, custom post types"
}
|
Filter all queries with a specific taxonomy
Is there any way to filter all post queries and add a specific taxonomy? Case in point, I have a taxonomy object of "Region" with terms like "Global", "Americas", "Europe", etc. (Users designate their region in their user profile through custom fields which is stored as a usermeta value and added the user cache object.)
The idea being that as the signed-in user navigates the site, they'd only see content designated within their region. Obviously I could write a custom query per page to include their region, but I was wondering if there was a way to tap into the query object and add the taxonomy requirement regardless of what the query was for (e.g, post, custom post type, archive page, etc.).
Any help would be much appreciated! Thanks.
|
Below code is an example that does what you want. See tax_query for more information.
function my_get_posts( $query ) {
// we only need to modify the query for logged in users
if ( !is_user_logged_in() ) return $query;
$current_user = wp_get_current_user();
// assuming that user's region is stored as user_region meta key
$user_region = get_user_meta( $current_user->ID, 'user_region', true );
$query->set( 'tax_query', array(
array(
'taxonomy' => 'region',
'field' => 'slug',
'terms' => $user_region
)
));
return $query;
}
add_filter( 'pre_get_posts', 'my_get_posts' );
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "custom taxonomy, query"
}
|
Help with wordpress custom query and advanced custom fields plugin
first of all sorry for my bad english. Let me explain what I`m trying to do:
I have a column inside a SQL table with a string using the following format: yy-mm-dd
The thing is, it doesn`t use a dateformat type.
So, I have my query, where I need to capture all fields with the following specification: value <= '{$thisyear}-{$thismonth}-{$last_day}' any way that I can do that withoung having to change the field format? As long as the tables are generated by the plugin.
Any help will be really appreciated, thank you guys!
|
$yesterday = array (
'year' => date('y'),
'month' => date('m'),
'day' => date('d')-1
);
$rows = $wpdb->query($wpdb->prepare(*emphasized text*
"SELECT id, yymmdd
FROM plugin_data
WHERE yymmdd LIKE '%d-%d-%d",
$yesterday['year'], $yesterday['month'], $yesterday['day']
));
foreach ( $rows as $r ) {
$id_for_yesterday_rows[]= $r->id;
}
Now you have all ids or rows that were submitted yesterday in an array.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "query"
}
|
Plugin to restrict login and unpublish content from an author
I am looking for a plugin or a code that will allow admin to select an author and "ban" him from logging in the system and also to unpublish his posted content until the admin decide to allow the entrance again.
This should include posts, author page and comments if it is possible.
Thank you for your replies.
|
You could try the User Control Plugin
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "plugins, plugin recommendation"
}
|
Issue with contextual help overwriting existing content
I'm missing something here:
function page_help($contextual_help, $screen_id, $screen) {
if ($screen_id == 'page') {
$contextual_help = '
<h5>Shortcodes</h5>
<p>Shortcodes help</p>
'.$contextual_help;
return $contextual_help;
}
elseif ($screen_id == 'post') {
$contextual_help = '
<h5>Post help</h5>
<p>Help is on its way!</p>
'.$contextual_help;
return $contextual_help;
}
}
add_filter('contextual_help', 'page_help', 10, 3);
The code is inserting into the correct screens but I am having two issues:
1. The code is inserting at the top, I'd like it at the bottom.
2. The code is deleting the help from all other screens except those mentioned above.
Thanks in advance for your tips!
Niels
|
In order to not delete help from all other screens, you need to always return the contextual help text, otherwise your filter doesn't return anything for non-page/post screens and so nothing will show up. Move the return to the bottom of the function, outside of your if/else. Also, the original contextual help is being concatenated to the end of your custom message, so move it to the front to have your text put at the bottom. Thus:
function myprefix_page_help($contextual_help, $screen_id, $screen) {
if ($screen_id == 'page') {
$contextual_help = $contextual_help.'
<h5>Shortcodes</h5>
<p>Shortcodes help</p>';
}
elseif ($screen_id == 'post') {
$contextual_help = $contextual_help.'
<h5>Post help</h5>
<p>Help is on its way!</p>';
}
return $contextual_help;
}
add_filter('contextual_help', 'myprefix_page_help', 10, 3);
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 1,
"tags": "plugin development, wp admin, contextual help, screen options"
}
|
Displaying Posts of a Custom Type
I currently have a new custom post type-- "Books." I have a custom rewrite url that I set when registering my post type:
'rewrite' => array( 'slug' => 'books', 'with_front' => false )
It works great when I visit a specific post, but how do I take control of the /books url for displaying a list of ALL of the books by date posted?
|
Once way of doing it - I am sure there are other ways too - is to make a page template for books: books.php You can make a copy of page.php and rename it. In the top of the file you place the usual Page Template code as in:
<?php
/*
Template Name: Books
*/
get_header(); ?>
Below the normal loop, you then place the code for a new loop:
<?php $loop = new WP_Query( array( 'post_type' => 'books') ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
Don't forget to close it with the call for `<?php endwhile; ?>` at the end.
With this method you can within WordPress add a Page called Books and assign this particular Template to it. This way you can still add general text to the page too and below display the list of all books.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "custom post types, url rewriting"
}
|
How to find all links between pages
I'm trying to have sort of a functionality that will let me find all internal links on my site that are pointing to a page. i.e - I want to know all pages on my site that are linking to (any) page in my site. I tried to find sort of a ready made plugin for that, but didn't seem to find. I can develop one by myself, but I wonder what will be the best way to have such functionality. Any ideas will be very welcomed . Thanks
|
### Post Search Approach
1. Pull out all of your posts and pages from the database
2. Iterate through all pages / posts and do a string search on the content - `substr_count( ' $page->content );`
3. Sum up the counts from all the posts / pages
This will of course miss allot of links made by plugins, navigation etc - hence "half-ass".
### Site Scraping Approach
1. Collect all the URLs you want to count links from
2. Iterate through the URL list and use `file_get_contents( $the_url )` to get the page / post as a string
3. Perform the string search described above and sum them all up
This approach will double count the links persistent through many pages (navigation and sidebars).
There is, I'm sure a much better way to do this - but that's all I could come up with off the top of my head. I'm sure you could tweak either approach to suit the degree of coverage you want.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 3,
"tags": "linking"
}
|
Duplicate and change a Theme Widget
Is there a way (a common one) to duplicate and change a theme widget ?
I'm asking this because, I have this widget that displays the recent news and if we click, it will display ALL news, but I wish to create a new widget that lists the latest articles (posts with a category "articles"), and if we click, that lists ALL articles.
Is there any widget like this that someone knows about ? If not, where should I look at in order to duplicate and change a theme widget ?
Thanks a lot
|
Widgets extend the Widget Class, search in the theme code for a class that `extends WP_Widget`. Copy/Paste it, rename it, and change what you'd like.
You can also look in the file `wp-includes/default-widgets.php` and use one of those as a starting point.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 3,
"tags": "themes, widgets"
}
|
Ajax in WordPress - path issue
I am trying out a bit of Ajax ( via jQuery ) in WordPresss. I have everything working correctly but for some reason I have to have the full URL to the PHP handler file even though it's located in the same directory as the script.
Here's the code:
$.post(' $("#form").serialize(), function(data){
do stuff
...
});
Why cant I just put "file.php" into that? Why does it need the full URL? Or more importantly, what can I put in there that would work on any site without the end user having to put in the full URL every time?
P.S. I have read the problem with Ajax and the path to the PHP page but I just got a bit more mixed up. I have also read the Ajax in plugins page on the WordPress codex but I couldn't see a relevant example in there. I suspect this might have something to do with `wp_localise_script()` but I'm not sure.
|
it needs a full URL because even though it may be the right location relatively on the back end, it's not on the same on the front end, at the URL where your page is ultimately served.
you're on the right path with `wp_localize_script`. you want to enqueue your ajax script, then pass the admin ajax url to `wp_localize_script`:
function my_init_method(){
wp_enqueue_script( 'my-ajax-request', plugin_dir_url( __FILE__ ) . 'js/my_ajax_script.js', array( 'jquery' ) );
wp_localize_script( 'my-ajax-request', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
}
add_action('init', 'my_init_method');
now within your ajax script you can refer to `MyAjax.ajaxurl` for the URL.
Check this post for a great writeup on properly using ajax in plugins and themes, this is what the WP Codex links to as an example.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 2,
"tags": "plugin development, jquery, ajax"
}
|
Is the object cached?
I have a function to instantiate a class to provide var access to other functions.
function my_data(){
global $post,$the_data;
$postid = get_the_ID();
$the_data = new MY_Class ( $postid );
return $the_data;
}
This function will be called by every post, and each post will call it many times whenever need a var from MY_Class. The data is saved in WordPress postmeta and retrived in My_Class. Does WP automatically cache the object, or should I find a way to cache it? How?
|
If you use the WordPress API to retrieve the metadata, then it should be cached for you.
If you do other complex stuff, there is the Transients API for caching data yourself, which will take advantage of whatever object cache you use with WordPress.
EDIT - I should clarify, it'll be loaded for each request unless you use some sort of caching plugin, though it should load only once for each request.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "cache, oop"
}
|
How can i remove the paragraph from shortcodes content?
If you have created shortcodes in Wordpress, you may have noticed that when you get the content of your shortcode, it's wrapped in html paragraph tags.
I don't know why the progammers did that. It seems like a very bad idea to me to add formatting to the actual content.
I've found a post that presents this solution :
<
But i'm wondering : Is there a solution proposed by the wordpress API itself, or something that i am missing here ?
|
The shortcodes, since they are inserted in the editor, comply to editor rules. Hitting the return in editor will generate a paragraph tag, just like any other text. It's one of the TinyMCE features. To read more about TinyMCE check out their forum and especially this thread
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "shortcode"
}
|
Single reusable value for post meta: Custom Taxonomy or Post Meta?
Suppose I have a post meta like "Region" it will contain values like "Region 1", "Region 2" etc. But it should only contain ONE value. Also I would like it to have an archive page. If I use custom taxonomy, users can select more than 1 value. Is it possible to have a drop down type selection instead?
|
For mutually exclusive values use post meta. It is faster to read than assigned taxonomies too.
It _is_ possible to create your own interface:
1. Set the parameter `show_ui` to `false` when you register the taxonomy.
2. Register a meta box where you print out all existing taxons with radio boxes.
3. Add a save action to assign the value to the taxonomy.
But in most cases you’re doing something wrong and misuse the taxonomy. ;)
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 2,
"tags": "custom taxonomy, post meta"
}
|
WordPress localization
In WordPress localization files (.po), does php map files by the line number eg. `comments.php:60` or msgid `msgid "<span class=\"meta-nav\">←</span> Older Comments"`.
So basically, if I have said string in comments.php in line 60, and move it to line 74, does it still get localized by the msgid?
|
> if I have said string in comments.php in line 60, and move it to line 74, does it still get localized by the msgid?
Yes it does. Localization does not depend on line numbers of strings.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 3,
"tags": "l10n"
}
|
Why are admin scripts not printed
I am trying to enqueue/print scripts in the admin area. But they dont seem to appear.
add_action('admin_init', function() {
add_meta_box('portfolio-meta', 'Details', 'portfolio_metabox_details', 'portfolio');
wp_register_script('jqeury-validate', '
wp_enqueue_script('jquery-validate');
wp_register_script('ae-admin', get_bloginfo('template_directory') . '/js/admin.js', array('jquery', 'jquery-validate'));
wp_enqueue_script('ae-admin');
wp_localize_script('ae-admin', 'WpAjax', array(
'AjaxUrl' => admin_url('admin-ajax.php')
));
wp_register_style('ae-validate', get_bloginfo('template_directory') . '/css/validate.css');
wp_enqueue_style('ae-validate');
});
But my script (`admin.js`) does not seem to get printed. I even tried to put those in 'init' instead of 'admin_init' still I dont see my scripts ... why is that? How can I debug?
|
Use the `admin_enqueue_scripts` hook instead of `admin_init`
Note: you should use hooks that target admin pages as specifically as possible. e.g.:
* **Plugins** : Use the `admin_print_scripts-{plugin-page}` hook
* **Themes** : Use the `admin_print_scripts-{theme-page}` hook (where `{theme-page}` is whatever string you use in the `add_theme_page()` call)
* **Custom Post-Type Edit Page** : Use the `admin_print_scripts-edit.php` hook,
For Custom Post Types, inside your function, do something like the following:
global $typenow;
if( 'portfolio' == $typenow ) {
// wp_enqueue_script() calls go here
}
(h/t t31os)
|
stackexchange-wordpress
|
{
"answer_score": 8,
"question_score": 4,
"tags": "wp admin, wp enqueue script"
}
|
How Can i Get 5 Recent Post Title With Corresponding Link?
I Want to Add My Latest 5 Post Title with Corresponding Link in My Header Position.What was the Actual Php code?Am Newbie ....
|
This sounds like an additional Loop on that page, right? You might want to use:
<ul>
<?php $posts_query = new WP_Query('posts_per_page=5');
while ($posts_query->have_posts()) : $posts_query->the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
Also read more here: <
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 1,
"tags": "posts, get posts, title"
}
|
How can I automatically add child pages to pages in a WP menu?
In the WP menu creation GUI there's the `Automatically add top level pages` option. I would like to do the opposite, for any page that is in the menu, automatically add it's child pages. Is there a way to do that ?
|
Simply put: no.
If you want dynamic updating of your menu items, you would probably be better-served using `wp_list_pages()` or `wp_page_menu()`.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "pages, menus, automation, children"
}
|
How to disable "Audio Player" to show up on the main page
I have a post with audio player with autostart enabled, and i decided to put it in the beginning of the post, before putting "read more" excerpt feature. So the problem is, that audio player plays music on the main page, but i want it to work only on post page. Is it possible to do? I've put my post in drafts for now, until i solve this little problem...
|
The simplest solution would be to put the audio player _after_ the read-more link.
If that would prove cumbersome (e.g. you've already got too may posts with audio players), you could try hooking into the `the_content` filter, and remove the audio player if not on a single-post view. e.g.:
function mytheme_remove_audio_player_from_home( $content ) {
// is_singular() is true for
// single posts, pages, and attachments
if ( ! is_singular() ) {
// do something, such as a str_replace() or
// whatever else would be appropriate, to
// filter out the audio player markup
}
return $content;
}
add_filter( 'the_content', 'mytheme_remove_audio_player_from_home' );
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "audio"
}
|
Multisite questions
I've got several questions regarding WP multisite, hoping someone who's used it extensively can help:
1. Is it possible to manage several WP sites over several different domains?
2. How can plugins be managed, some I'd like to use across all the sites but others I'd only like to use on certain sites. Also what happens to each of the plugin settings, are they rolled out across the board?
3. Updating - how can this be managed per site for both the plugins and WP itself.
|
1. Yes. Use the Domain Mapping Plugin.
2. Plugins can be enabled network-wide, or on a per-site basis. You can choose whether or not to give site admins the capability to activate/deactivate Plugins. Plugin settings are on a per-site basis.
3. The Network Administration handles updates to core, Plugins, and Themes, and automates updating the database tables for each network site, when applicable.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "multisite"
}
|
Comparing formidable pro and gravity forms
Has anyone come across any good reviews/comparisons of gravity forms and formidable pro? I am trying to find more information on both.
I have a couple of sites that need several forms for adding items to our physical collections, leave requests and reserving specific rooms and resources and the like. I need something that will email form submissions as well as store entries in a database and which I can use to generate reports.
Any information or personal experience with either of these or other options would be much appreciated.
|
I've just begun using Gravity Forms but I've used Formidable quite a lot. My biggest complaints about Formidable is the way it handles upgrades. If you have a 'Pro' account, when an upgrade is available you have to go through a multi-step, not very intuitive upgrade process every time.
Other than that, so far Formidable has worked very well for me. It doesn't have all the 'extras' that Gravity Forms seems to offer, like MailChimp integration, but that hasn't been that big a deal. And, it's far cheaper in the long term with a one-time, unlimited license for $99 (when I bought). Gravity Forms makes you renew every year or lose support.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "forms, plugin recommendation, plugin gravity forms"
}
|
Is user listing on wordpress private?
I'm creating a website using Wordpress. Users are registering on it as "Subscribers". When you register, you have a small panel with some custom info on it (that I made, creating a custom template)
Each user shouldn't know other users exist.
I started developing this without knowing if when registered users are available "to the world" (google indexing them, for example).
Is user registration data is publicy available in a Wordpress installation, by some url, perhaps? Can Anonymous users see registered ones, or can Registered Ones see all others registered ones? Where I can get this information on wordpress docs? Are registered users on Wordpress supposed to be available to all?
I couldn't get any information about this. Can someone help?
|
No, user data is not visible to the outside world, or to google, unless you specifically make it visible in the theme somehow.
One piece of user data is exposed for authors of posts though. Specifically, their login names are visible in many places.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "user access, private"
}
|
How does a mobile WordPress theme differ from a simple theme?
1. What should be taken care of while coding a mobile theme as compared to a simple one?
2. Is there any tutorial available that teaches how to develop a **mobile** theme from scratch?
|
It's really not a "wordpress" specific, it's just the css. You just give it a css for mobile browsers. That's it.
here are few good readings on how to get about the css for mobile:
* <
* <
if you still have some questions, feel free to ask. ;)
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "theme development, mobile"
}
|
500 internal server error
I am facing 500.0 Internal server quite frequently with my website.
The error details are given below.
HTTP Error 500.0 - Internal Server Error
C:\PHP\php-cgi.exe - The FastCGI process exceeded configured activity timeout
Module FastCgiModule
Notification ExecuteRequestHandler
Handler PHP_via_FastCGI
Error Code 0x80070102
Requested URL
Physical Path C:\HostingSpaces\coderefl\mydomain.com\wwwroot\index.php
Logon Method Anonymous
Logon User Anonymous
When I contacted the support team, they're saying that my site is making heavy SQL Queries. I am not sure how to debug this. But my site is very small and the database is optimized. I'm running wordpress as platform. How to resolve this issue.
|
Your site codereflect.com is not that heavy. Could be the Suffusion theme and its options making lots of DB calls. I'd use < to see what queries are being called and how many. And it also could be you're on a shared box at softlayer that is "too" shared with others.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "troubleshooting, 500 internal error"
}
|
Getting an ordered list of tags - via wp_tag_cloud or not?
I'm trying to output an ordered list of the top five tags for my site into the sidebar.
At the moment, I'm using `wp_tag_cloud` like this to get it to output a nice `<ul>`:
`wp_tag_cloud('smallest=12&largest=12&orderby=count&order=DESC&format=list&unit=px&number=5');`
However, I'd like it to output as an `<ol>` instead of a `<ul>`. Is it possible to do this without hacking the core? Presumably via functions.php or the like?
Also, in the output from `wp_tag_cloud`, the font size is being set by inline styles. Seeing as I don't need the tag cloud to actually function as a tag cloud, is there any way to simply remove all inline styling from it?
Finally, if there's an easier or less convoluted way of getting an ordered list of tags, please let me know.
Thanks.
|
one possibility: using the 'format=array' and 'echo=0' parameters; and building a foreach loop to output each tag:
<ol>
<?php
$wptc = wp_tag_cloud('smallest=12&largest=12&orderby=count&order=DESC&format=array&unit=px&number=5&echo=0');
foreach( $wptc as $wpt ) echo "<li>" . $wpt . "</li>\n";
?>
</ol>
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 3,
"tags": "tags, sidebar, list"
}
|
How to get all taxonomies of a post type?
**How can i get taxonomies of a post type?**
If I have a post type `event` and i need to find out the list of taxonomies that are attached to that post type. How do I find them?
|
I think I've got it! After looking at couple of functions in the taxonomy.php file in WordPress I have found the function `get_object_taxonomies();` which did the trick :)
|
stackexchange-wordpress
|
{
"answer_score": 48,
"question_score": 58,
"tags": "custom post types, custom taxonomy, taxonomy"
}
|
Disable update notification for individual plugins
Is there a way to disable update notifications for specific plugins?
As a plugin developer, I have some plugins installed on my personal site using the svn trunk version for testing, but the same plugins are available from the plugin site. In these cases WP considers the latest version to be the _most recently published_ version and constantly tries to warn me that updates are available.
I still want to see notifications for updates on other plugins, but it's anoying to constantly ignore the `Updates (2)` notice in the header!
|
For example if you don't want Wordpress to show update notifications for akismet, you will do it like:
function filter_plugin_updates( $value ) {
unset( $value->response['akismet/akismet.php'] );
return $value;
}
add_filter( 'site_transient_update_plugins', 'filter_plugin_updates' );
|
stackexchange-wordpress
|
{
"answer_score": 82,
"question_score": 64,
"tags": "plugins, updates, notifications"
}
|
Adding featured image via PHP
Currently I'm working on a project where site is driven by user articles, how it works:
1. Any user goes to compose post page and writes post along with few details, has upload file option for image and then submits
2. Post is uploaded in wordpress and the image attached is set as featured image
3. Admin approves the post and it gets published.
Here user is not required to have an account. I am using `wp_insert_post` to create a new post but not able to figure out how to add featured image via PHP.
|
Use the set_post_thumbnail function.
set_post_thumbnail( $post_ID, $thumbnail_id );
Require you use WordPress 3.1.0 or later.
You need call this function after you have successfully created your post via `wp_insert_post` and have a valid `$post_ID`.
|
stackexchange-wordpress
|
{
"answer_score": 6,
"question_score": 2,
"tags": "php, post thumbnails, uploads"
}
|
How to Get Recent 5 post in My Title bar?
I Installed Recent Posts Plugin in my Wordpress site.It Shows Correct Answer but it Shows "Recent Post" at Header position.I don't want that text. Unfortunately i can't remove that.please help me ...Is there any other php coding Available?
|
Ah gotcha. Either you can use a different plugin that allows you to leave the title blank, or using the default Recent Posts widget type a single blank space in the Title area and click Save. That way the title will show as blank. Hope this helps! Michelle
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "plugins, posts"
}
|
May i Use ShortCode in Template?
Am Using Wordpress Blog.Here i want Use Tweetmeme Plugin.I want to show the output of the Tweetmeme Plugin to Customizing place(Side of the Post[Not Before or After]).The Plugin Creators are providing Shortcode.Shall i Use this shortcode in Template?I Guess this is not possible.So we need to change Shortcode as a function.How to Create a function from Shortcode?please help me.
|
Have you tried using the `do_shortcode()` function?
**EDIT**
I'm not familiar with the TweetMeme shortcode, but here's an example usage for putting a NextGen Gallery directly into a template file:
echo do_shortcode( '[slideshow id="1" w="603" h="270"]' );
Simply replace with the appropriate shortcode (and parameters) for TweetMeme.
Codex ref: do_shortcode()
**EDIT 2**
With TweetMeme, you have another option:
1. Change the Plugin "where" setting from "shortcode" to "manual"
2. Place the `tweetmeme()` function in your Theme template file where you want to output the TweetMeme button.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "plugins, functions, shortcode"
}
|
What's the purpose of $wp_did_header?
It is referenced in load_template but Wp does nothing with it ?!!! so what's the use ?
1105 function load_template( $_template_file, $require_once = true ) {
1106 global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
1107
1108 if ( is_array( $wp_query->query_vars ) )
1109 extract( $wp_query->query_vars, EXTR_SKIP );
1110
1111 if ( $require_once )
1112 require_once( $_template_file );
1113 else
1114 require( $_template_file );
1115 }
|
It's a global variable that can be checked by user functions and filters to see whether or not WordPress has already sent headers. It's just there to help.
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 0,
"tags": "templates"
}
|
Value prints outside of the echo
My code validates and returns the custom field value. However, I can't get the value to return inside of the anchors.
Here is the code:
<div id="meta_mblink">
<?
if(function_exists('get_custom_field_data')) {
echo '<a href="'.get_custom_field_data('mblink', true).'"></a>';
}
?>
</div>
This is what is returned:
<div id="meta_mblink">
<a href=""></a>
</div>
|
This is how I would code this:
$url = get_post_meta( get_the_ID(), 'mblink', true );
if ( ! empty( $url ) ) {
print '<a href="' . esc_url( $url ) . '">MBLINK</a>';
}
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "php"
}
|
How to reduce repetitive code
I've been searching for how to do this for a while but to no avail. Part of my template is using a lot of the same code, i.e. retrieving a specific page.
If this was Javascript I'd set up a function and keep calling the function. How can I call the code below repeatedly?
<?php
$page = get_page_by_title('Excerpts Showreel'); <-- This piece of code will change
// the code below will never change.
?>
<?php
$my_id = $page;
$post_id = get_post($my_id, ARRAY_A);
$title = $post_id['post_title'];
$content = $post_id['post_content'];
?>
<?php
echo $content
?>
|
You can define your own custom functions in PHP just like you would in JavaScript. Here's your code example rewritten using a function:
$page = get_page_by_title('Excerpts Showreel'); <-- This piece of code will change
// the code below will never change.
function get_my_content( $page ) {
$my_id = $page;
$post_id = get_post($my_id, ARRAY_A);
$title = $post_id['post_title'];
$content = $post_id['post_content'];
return $content;
}
echo get_my_content($page);
So long as you have your `get_my_content()` function defined, you can use it anywhere you need to.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "theme development"
}
|
Display posts differently depending on which author wrote it
I've got a multi-author site running on Wordpress 3.1.3 .
I'm trying to place an extra header above the title for a specific author. So if "John" posts on the blog, it would have an above the post on the home page that says "John's Perpective", or something of that nature. The idea is that we want one of the many author's posts to be highlighted for users.
My issue is that I cannot figure out how to check for which user wrote the post within the loop. I am doing it on various other areas of the site via WP_Query.
I'm imagining I need something like this (pseudo code):
if ( author == 2 ) {
echo '<h2>John's Perspective</h2>'
}
Should be an easy fix, but I'm stumped.
Thanks in advance!
|
When you're in the loop, you can use `get_the_author()` to get the author's 'Public' name. Alternatively, you can use `get_the_author_meta( 'ID' )` in the loop to get the author ID.
So, modifying your psuedo-code:
if ( 2 == get_the_author_meta( 'ID' ) ) {
echo '<h2>John's Perspective</h2>'
}
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "author, loop"
}
|
Combining CSS files into a single cached one
I'm creating a theme where i want it to have different widgets and plugins. Each plugin would ideally have it's own css file. However, this approach is not so good because i can end up having multiple files included in my header.
Is there an approach where i can sort of cache all different css files in a single one upon the first user request and then just use that ?
|
Yes: put them all in a function, and then enqueue that function at the `wp_enqueue_scripts` hook. That way, you can define the CSS dynamically (e.g. based on Theme option settings), and let WordPress output it in the document head.
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 0,
"tags": "theme development, css"
}
|
The effect of x() family of functions
So I know that _x() and it's wrappers allow a developer to specify the context of a translated string. I'm pretty clear on "how" to use this function as well as "why" it should be used. I am wondering how this function is helpful to people who perform translations. Poedit does not seem to treat it any differently. Does use of this function aid in translation? Is there a way for translators to somehow see the context during the translation process?
|
When using other translation tools (other then poedit) like **GlotPress** you can see the context in which the string for translation is called upon.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "localization, translation"
}
|
How to remove the comments feed from WP 3.1.1?
I've tried a number of solutions available on the internet, but none seem to work in WP 3.1.1.
Thanks!
|
remove_action('wp_head', 'feed_links', 2);
add_action('wp_head', 'my_feed_links');
function my_feed_links() {
if ( !current_theme_supports('automatic-feed-links') ) return;
// post feed
?>
<link rel="alternate" type="<?php echo feed_content_type(); ?>"
title="<?php printf(__('%1$s %2$s Feed'), get_bloginfo('name'), ' » '); ?>"
href="<?php echo get_feed_link(); ?> " />
<?php
}
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "rss"
}
|
Portfolio + Blog: multisite or plugin?
I need to display both a portfolio and a blog on a website, and as a relative newcomer to WordPress, I was wondering what the most effective way is to do this: install a plugin, or create a multisite?
Essentially for the portfolio page I just need to display a thumbnail, category, and title, but when each entry is clicked, I need a full, blog-style post. Is there a plugin that will do this, or would a multisite (ie, running the Portfolio as a separate blog) be easier?
|
Set your blog as Blog category and your portfolio as Portfolio category. You might be also interested in Custom Post types (which I think is the right way to do it):
Run your Blog as a usual via Posts and set the Portfolio as Custom post type with its own categories, tags or what ever taxonomy you need.
Read more here: <
Multisite is a completely different concept.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "plugins, posts, multisite, blog"
}
|
Add author section on Author archive posts
I was looking at the section where you click on the author name on the homepage posts.
and it says the Archive posts from xxxx authors
so I thought of that while ago I found that some website has it and they including the twitter of that author and their bio with the pic
this is one of the example I would say
<
I'm trying to look for this kind of plugin or maybe I can edit this to have it myself
but needed to ask if this been done from some plugin because I couldn't find one
all I see is the widget on the sidebar
Thanks
* * *
For more information I have looked from the plugin page and the tags from wordpress official site about author plugin.... none of them are similar to what I want on the above example link.
Thanks!
|
<
<
<
<
Or you can use your own custom solution
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": -1,
"tags": "posts, archives, author"
}
|
Restrict categories to a custom post type
In the WP-Admin when creating a post or a custom post type I want to restrict certain categories to a custom post type. For example, Posts will only be able to select Category A and B. And custom post type A will only be able to select Category C and D.
Would I have to write some code to hook into somewhere or is there a function built-in to the framework?
Thanks in advance.
|
I think the best way to do this is to make a category (or taxonomy ) for a specific post type...
please see this link... <
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 2,
"tags": "custom post types, categories, customization, wp admin"
}
|
How to add search form in main page body?
I'm fairly new to wordpress. I'm trying to develop a website with search option to find available room information.
I would like to add a search box where people would be able to enter their information and hit the Search button. Then it'll display the available rooms. Something like the below website
<
If it's a duplicate question please accept my apologies.
Thanks.
|
I just wanted to add two small things for other peoples....
if your template supports it you can just add :
<?php include (TEMPLATEPATH . '/searchform.php'); ?>
2.adding the following code will put a text inside the search box. (like "Write your search and hit Enter" )
<form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
<div><input type="text" size="put_a_size_here" name="s" id="s" value="Write your search and hit Enter" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/>
<input type="submit" id="searchsubmit" value="Search" class="btn" />
</div>
</form>
and finally, combining those two advices, just save the code from part two as searchform.php in your template folder, and you can always call it with method number 1.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "plugin development, forms"
}
|
Switching database on the fly
I have read here about switching the current wp database on the fly using
$wpdb->select('database_name');
Once done, I understand that i will have to issue the same statement to the original database.
Questions:
* Right after changing the database, do i need to flush caches or similar stuff to get things working properly? Will I need to call again WP header?
* Potential issues?
|
Yes it works!
This is the code, assuming both the databases share the same username & password:
$wpdb->select('mydbname');
wp_cache_flush();
Once done, re-issue the same statements, with the original database name.
Can't see any performance issue at the moment, maybe because this is done when building a custom form picking data from two posts out of two databases. It may impact performance when used on a large amount of rows in batch loop...
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "database"
}
|
How do I turn off wordpress comments ability to capture a users ip address?
Going through the comments table on my wordpress site, I noticed that wordpress is storing the ip address of everyone who makes a comment on my site. How do I remove this functionality?
I'm not just talking about the display of the ip in the template, I mean I don't want wordpress to capture it in the first place.
|
Add this to your functions.php:
add_filter('pre_comment_user_ip', 'no_ips');
function no_ips($comment_author_ip){
return '';
}
You'll still have the comment_author_IP field in the db, but it will be empty...
And to remove existing IP records from the db run this query:
UPDATE `wp_comments` SET `comment_author_IP` = ''
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 4,
"tags": "comments, ip"
}
|
Installing a Plugin ( Which is already manually uploaded )
I need to install wordpress plugin for placing source codes to my blogs.
See, the following snapshot describes that I have already uploaded plugin to proper place. I didn't make even a single change to that directory & It is uploaded without any intact. What should be the next step for activating this plugin ? ( I am using my own domain )
!enter image description here
I have followed steps 1 & 2 from here. I am confused what to do for further steps.
Thanks in advance for sharing your knowledge.
Sugar.
|
Ok from here you have two options available:
1) Dont know if you have done this already but you will need to go to **wp-admin >> plugins** (its at the left of the wp-admin dashboard beneath "appearance") from here if all is well with your manual upload you should see your plugin title in the main area, just click activate plugin.
2) If its not there, then remove the files you have uploaded and go back to wp-admin plugins, at the top you see an area where it says "Plugins" and a button that says "Add New", click "add new" button and the page will re-load. Use the Search for the plugin from the wp repository (search for its title) and grab it from there, just follow the onscreen instructions.. very easy..
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "plugins, installation"
}
|
Wordpress - connection information
!enter image description here
I am entering valid details, though wordpress keep prompting same as follows. What would be the wrong thing ?
Edit : Even after modifying the permissions as follows, I am getting same errors.!enter image description here
|
It's almost certainly a permissions problem - your `wp-content` folder must be writable by your webserver user.
Typically setting permissions to `755` will sort this.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": -1,
"tags": "plugins, installation, hosting"
}
|
contact form 7 captcha support anyother captcha plugin?
I am Using Wordpress. I installed Contact form7.Now I Want To Add Captcha with Contact form7.I Don't like "Really Simple Captcha" because it shows very simple images.Any other Captcha Plugin Support Contact form7?
I Need Like the output of " **SI CAPTCHA Anti-Spam"** or "Fast Secure Contact Form",Here Unfortunately I can't Remove Contact form7 Plugin.So I Want to Add Captcha Plugin with my Contact form7.Please Help Me.
|
You can use reCAPTCHA with contact form 7.
<
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": -1,
"tags": "plugins, plugin development, plugin recommendation"
}
|
Query add html after set amount of posts?
Is it possible to add some html after a set amount of posts?
For the purposes of a slider after 6 posts i need it to enclose in a div/li or whatever then start a new div/li for the next 6 and so on.
Here is my custom query which just prints the post name in a list.
<ul>
<?php $args=array('post_type' => 'courses','post_status' => 'publish','posts_per_page' => -1);$my_query = null;$my_query = new WP_Query($args);if( $my_query->have_posts() ) {while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><h2><?php the_title(); ?></h2></li>
<?php endwhile;} wp_reset_query();?>
</ul>
After at the start and end of 6 posts i need to open a div then close it after the 6th post.
Is this possible with WordPress PHP?
Many thanks for any help :)
|
Here's one way of doing it:
<?php
$courses = get_posts( array(
'post_type' => 'courses',
'posts_per_page' => -1
) );
if ( $courses ) {
print "\n" . '<div style="background:pink">';
foreach ( $courses as $course_count => $post ) {
setup_postdata( $post );
the_title( "\n", '<br>' );
if ( 5 == $course_count ) {
print "\n" . '</div>';
print "\n" . '<div style="background:yellow;">';
}
}
print "\n" . '</div>';
}
wp_reset_postdata();
?>
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "query posts, customization"
}
|
Different post views for different category views
In my blog, my "pages" are really just posts sorted by categories. What's the best way to change the way the posts look for one of my category pages?
|
For styling archive index pages for a given category, target `body.category-slug` (where `slug` is the category slug) in CSS.
For styling single blog posts that have a given category, assuming your post container is a div, target `div.category-slug` (where `slug` is the category slug) in CSS.
For PHP operations, you can also use `is_category( 'slug' )`, which returns true if you are on the archive index page for a given category, and you can use `in_category( 'slug' )` which returns true if the current post is in a given category.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "posts, categories, pages"
}
|
Delete original image - keep thumbnail?
I'm using a lot of thumbnails but never the original file. To save space, I'd like to prevent the original from being saved on disk but only keep a thumbnail of 100px. How can I do this?
Thanks, Dennis
|
add_filter( 'wp_generate_attachment_metadata', 'delete_fullsize_image' );
function delete_fullsize_image( $metadata )
{
$upload_dir = wp_upload_dir();
$full_image_path = trailingslashit( $upload_dir['basedir'] ) . $metadata['file'];
$deleted = unlink( $full_image_path );
return $metadata;
}
|
stackexchange-wordpress
|
{
"answer_score": 12,
"question_score": 9,
"tags": "post thumbnails, attachments"
}
|
Set (featured) thumbnail for post?
I'm using wp_insert_post and media_sideload_image to create a post and attach a single image to the post. However, how can I mark this attached image as featured thumbnail? It would make listing the thumbnails significantly faster by using the_post_thumbnail instead of looping through each post manually showing the first image.
How can I mark the attached image as featured thumbnail?
Thanks, Dennis
|
Perhaps use `set_post_thumbnail()`? (Codex ref.)
**EDIT**
To get the attachment ID using the Post ID:
// Associative array of attachments, as $attachment_id => $attachment
$attachments = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
$attachment = $attachments[0]; // ID of your single, attached image.
Then to set it as the featured image:
set_post_thumbnail( $attachment );
I have to check to be sure; the docs are a bit confusing. The default output might be an object. Regardless, `get_children()` will get you to the ID of your lone attachment, given the Post ID.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 0,
"tags": "post thumbnails, attachments"
}
|
References to other site everywhere in Wordpress site
I am relatively new to Wordpress, have been handed a site developed by someone else on one server, and have to deploy it to another. This site has bbpress installed, plus a load of other stuff. However it also seems to contain (somewhere) references to the other developers server, so even though I have copied the site onto my server all the links still point to his. I'm assuming that somewhere in the template files or database there is a reference to his site but I don't know where. I've done a search / replace and replaced what I can find, but still the same thing happens. I'm just wondering if there is any really obvious place I need to look for things like that. It seems to me he has just done something pretty stupid by hard coding references to his site; but maybe it's for a good reason, I don't know.
|
There might be hardcoded links in the theme; download it and do a multifile search with a text editor.
Editing the text dump destroys serialized data; see another Q/A here: Why is my database import losing text widget data?
**Update 4/19/2015** To correctly change URLs in the database, the SQL queries below will work when run in phpmyadmin or adminer, _but it is much better to use a tool that correctly deserializes/reserializes php data, like_ <
UPDATE wp_options SET option_value = replace(option_value, ' ' WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, '
UPDATE wp_posts SET post_content = replace(post_content, ' '
UPDATE wp_postmeta SET meta_value = replace(meta_value, ' '
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 3,
"tags": "migration, configuration"
}
|
Query menu_order custom post types
I added `'supports' => 'page-attributes'` to my custom post type, and now i have the meta box for page ordering.
When i use the argument `'sort_column' => 'menu_order'` with `get_pages()` on my custom post type, everything orders properly.
So why do the custom pages not order properly when i query the posts using `query_posts(array('orderby' => 'menu_order'))`
And what can i do to get them to order by the menu order?
Here is the query im using incase anyone wants to see it.
<?php
$current_term = ($wp_query->query_vars['section'] <> '') ? $wp_query->query_vars['section'] : $menu_arr[0];
query_posts(array( 'post_type' => 'module',
'orderby' => 'menu_order',
'tax_query' => array(array( 'taxonomy' => 'section',
'field' => 'slug',
'terms' => $current_term )),
'post_parent' => 0 ));
?>
|
I've just had to do the same thing as you, here is what I did to get this working:
`'supports' => array('title', 'editor', 'thumbnail', 'page-attributes')`
Register the post type with supports of page attributes. This adds the menu order meta box to the edit screen. From there you can place the order.
Then run my custom query:
$args = array(
'numberposts' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'post_type' => 'staff'
);
$staff = get_posts($args);
set `orderby` to menu_order and `order` to ASC. Remember if you do not set a value in menu order it sets it to 0. So any posts without an order set will appear first.
|
stackexchange-wordpress
|
{
"answer_score": 16,
"question_score": 7,
"tags": "custom post types, php, menus"
}
|
How can I get a list of plugins and which blogs are using them?
I'm about to upgrade my Wordpress MU installation to wordpress 3
Before I update, I want to find out which blogs use which plugins.
I don't see a way to do that in the UI, is there?
What about a query of the mysql database?
Thanks
|
take a look at Plugin Commander which is a plugin management plugin for multi-site mode, which allows further control on network-activated plugins.
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "plugins, multisite, admin, sql"
}
|
How to count media attachments?
How do I count the number of media attachments a specific post has?
Output example: This post has 22 photos.
Thanks!
|
Use this code if you're in the loop:
$attachments = get_children( array( 'post_parent' => $post->ID ) );
$count = count( $attachments );
If you're not in the loop, substitute `$post->ID` with the ID of the specific post. But that should count all attachments.
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 2,
"tags": "attachments, media"
}
|
How to count post type that has a particular term?
What is the best method to count the number of posts in a post type that have a particular term? I don't believe `get_posts` accepts a term query and I have had no luck with `new WP_Query`, though I might be doing something wrong.
Usage example:
$posts = get_posts( array(
'post_type' => 'inventory',
array(
'taxonomy' => 'status',
'terms' => 'in-stock',
'field' => 'slug'
),
) );
$count = count( $posts );
echo $count;
|
$items = get_posts( array(
'post_type' => 'inventory',
'numberposts' => -1,
'taxonomy' => 'status',
'term' => 'in-stock'
) );
$count = count( $items );
echo $count;
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 0,
"tags": "wp query, query"
}
|
Adding the Admin Bar to a page with a custom template
I created a stripped-down page template to use for my landing pages. But I must have cut too much out of it, because I've lost the WordPress 3.1+ Admin Bar.
What functions do I need to call to get the Admin Bar to appear at the top of the page again?
|
Not sure exactly, but adding the following two functions should get it to work and save you other headaches as well:
Right before the closing head tag add:
<?php wp_head(); ?>
And right before the closing body tag add:
<?php wp_footer(); ?>
|
stackexchange-wordpress
|
{
"answer_score": 4,
"question_score": 2,
"tags": "page template, admin bar"
}
|
Why after a form post back, I get 404?
I am creating a contact form page. Perhaps I am doing it wrong? I have something like
<?php
// even when I remove this validation block it fails
if (isset($_POST['name'])) {
// do validation ...
}
get_header();
?>
...
<form id="frmContact" action="<?php the_permalink() ?>" method="post">
...
</form>
...
I used the same logic in another page and it works ... the URL is correct and if I refresh the page, it works. It just gives 404 on post back
|
Maybe try clearing out the action attribute: action=""
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "404 error, forms"
}
|
Images uploading to wrong folder
Images keep uploading to /uploads/2010/07 instead of /uploads/2011/06. Permissions are set to 777 just to find out if 755 is an issue, and it's not.
I don't have anything in Media to define a new path.
It just keeps uploading to the oldest folder. This was an XML dump from another WP to the new WP, so I'm not sure if that had anything to do with it, or not.
I can see the image files fine and they post in the post editor, they're just going to the oldest folder and it's not autocreating a new one.
I'm running the latest wp 3.1.3. I do have a bunch of plug-ins, the image thumbnail regenerator is one, and I've got a bunch of plugins for sidebar widgets, but nothing out of the ordinary.
|
Tony,
are you creating a new post or editing an older post from 2010/07?
I've found that the folder relates to when the post/page was created initially.
|
stackexchange-wordpress
|
{
"answer_score": 7,
"question_score": 3,
"tags": "images, uploads"
}
|
how to get original image using wp_get_attachment_image_src
I want to get the original image with the same width and height as uploaded.
My original image is 630*370.
Using the following function call I get a thumbnail sized at 630*198.
wp_get_attachment_image_src($PriImgId,array('630','370'));
How can I get it at 630*370
|
Try this :
wp_get_attachment_image_src( $PriImgId, 'full' );
Also, for more options see the Codex.
|
stackexchange-wordpress
|
{
"answer_score": 45,
"question_score": 14,
"tags": "images, attachments"
}
|
Creating an option for writing a post without an author attribution for a group blog on Wordpress
I'm developing a group blog on wordpress (first time working with it) and the client has requested that a 'None' option be added where an item can be posted without a "by" attribution. So basically there would be one article / excerpt template for attributed author's posts and another for the none option where the byline would just be the date posted without the "by [author name]." Is this possible with wordpress?
Thanks!
|
It's possible to do, but would take hacking up the theme. One convention I've seen is to create a user with a generic name, like Guest, or the name of your site.
If you would still like to hack away. Then put a condition around the line\s in the template that displays the author like so:
<?php if (get_the_author() != 'none') : ?>
<?php the_author(); ?>
<?php endif; ?>
or alternately, the shorthand...
<?php echo (get_the_author() != 'none') ? get_the_author() : ''; ?>
Then you define an author named 'none'.
The post will only display the author's name if the name isn't 'none'.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 0,
"tags": "theme development"
}
|
custom post types don't appear in RSS
I created custom post-types in my site but these posts are not shown in the RSS. Only the regular posts appear there.
What could be preventing them from showing up there
|
They don't normally show there That is how they are supposed to work. Each CPT has a feed of it's own by default Everything in WP has a feed it seems!
But if you want them in your main feed
this can go in your functions.php
// ADDS POST TYPES TO RSS FEED
function myfeed_request($qv) {
if (isset($qv['feed']) && !isset($qv['post_type']))
$qv['post_type'] = array('ve_products', 'post');
return $qv;
}
add_filter('request', 'myfeed_request');
You see this line:
$qv['post_type'] = array('ve_products', 'post');
That includes normal posts and my CPT of ve_products in my main feed
You would swap out that for your CPT, if you have more CPTs, add them into that array
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 3,
"tags": "custom post types, rss, post type"
}
|
What is the most secure way to store post meta data in WP?
Sony's recent security "holes" showed how unsafe it can be to store data unencrypted. As some of you may know, I 'm working on re-releasing the free CRM theme Driftwood.
What is the most secure way to store sensitive (ie non-public information) post meta in the database?
|
Use bcrypt.
<
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 4,
"tags": "database, post meta, security"
}
|
wp_localize_script $handle
Can anyone tell me what the "`$handle`" ( first parameter ) of `wp_localize_script` is normally used for. Thanks.
P.s.: I have no idea why but stackexchange is telling me this question dosen't meet quality standards.
Edit: When i put in my ps it accepted it so i suppose it's the length of the quesion.... if you feel like this is an unacceptable question then apologies
|
It's basically a unique id of the script you registered or enqueued before.
Let's say we enqueued a two scripts with wp_enqueue_script():
wp_enqueue_script( 'my_script_1','/js/some_script.js' );
wp_enqueue_script( 'my_script_2','/js/some_other_script.js' );
Now you want to pass your `$data` to the script #2 with wp_localize_script():
wp_localize_script( 'my_script_2', 'my_script_2_local', $data );
After this - when WordPress prints out your `my_script_2` it will print out your `$data` variables along with it so you can use them in your script.
As you can see `my_script_2` is our handle here - it makes the link between our script functions.
|
stackexchange-wordpress
|
{
"answer_score": 5,
"question_score": 3,
"tags": "plugin development, ajax, javascript, wp localize script"
}
|
How can I dynamically load another page template to provide an alternate layout of the posts?
I have a page that displays posts (4 on each row), with a thumbnail image & title for each. Is it possible to click a text/icon link and dynamically switch the page template? I'm looking to provide an alternate view of the posts, perhaps with larger images, more text/custom fields added etc.
I thought it would be easy just to link to another page template but it changes the url (would like the url to stay the same) and for some reason it loads the closest matching post, rather than the new page template (I have the page template nested within the first).
Something like this
domain.com/page/?view=list
|
I think I have a workable solution on what I was trying to do. This works but is there a better way? Also are there any implications I should be aware of when using $_GET? Didn't realize it would be this easy :) perhaps I'm missing something.
<?php $view = $_GET["view"]; ?>
Then if the URL is domain.com/page/?view=list I use an IF statement inside the loop to modify the markup as required:
<?php if ( $view == "list" ) : ?>
// code here for list view
<?php else : ?>
// code here for normal default view
<?php endif; ?>
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "page template"
}
|
How to set a custom title per language?
I am running Qtranslate for my website.
I am very impressed by this plugin. Now my only problem is that I cannot set a custom title and description for my homepage per language. I can only setup one line for the title in the general settings for my website.
I have installed Qtranslate META where I can set a custom title and description per page, but my only problem is the homepage.
Any help would be realy appreciated how to fix this!
Thanks
|
You have to use a static page in this case:
> Settings **->** General **->** Fron Page Display: A static Page
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 1,
"tags": "plugins, seo, multi language, plugin qtranslate, language"
}
|
Custom html widget with a Joomla-style assigment
I was unable to find a custom html widget with Joomla style assignment. Like you create a module (widget), define some HTML and assign it to certain menu items (or set it to show everywhere except the selected etc). Given WordPress doesn't have the same menu system, the widget has to be able to assign itself to certain pages, post categories and tags. Hardcoding conditional tags into the template won't work...
# Thanks for your help.
edited: I have come across this plugin. The problem is I need something easy to use for untechy guys. Like a set of checkboxes containing names of pages and categories.
|
This plugin might help you : Widget logic
**EDIT**
There are also many variants of this kind of plugin listed in this article. Maybe you'll find one that suits your needs there.
|
stackexchange-wordpress
|
{
"answer_score": 1,
"question_score": 1,
"tags": "widgets"
}
|
change default option in wp_dropdown_categories
I'm using **wp_dropdown_categories()** to output a dropdown.
In default view (without having clicked it) it shows the name of the _first category_ in the list. I'd like it to say _"Categories"_. Is this possible?
Thanks in advance
|
You can use the show_option_all argument:
<?php $args = array(
'show_option_all' => 'Categories'
);
wp_dropdown_categories( $args );
?>
Function Reference/wp dropdown categories
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 2,
"tags": "functions, pluggable"
}
|
show custom post types for a month
I have a custom post type called "cpt_docs": add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'cpt_docs',
array(
'labels' => array(
'name' => __( 'Docs' ),
'singular_name' => __( 'Doc' )
),
'public' => true,
'has_archive' => true,
)
);
}
I have tabs with months and i want to show the "docs" for that month. I need to show the custom post types in the home page, bu i dont how can i do that.
Should i use a hard coded sql query or there is another way?
thk all.
|
Well, it works if i use a filter like this:
add_filter('getarchives_where','docs_filter');
function docs_filter($where_clause) {
return "WHERE post_type = 'cpt_docs' AND post_status = 'publish'";
}
Thk all.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "custom post types"
}
|
Displaying child taxonomies
Imagine this: I have a custom post type called 'Animals' and I have registered a taxonomy for this post type called 'Types of Animal'. 'Types of Animal' would be 'dog', 'cat' and 'mouse' and so on. So that's straightforward.
But say I want to introduce child taxonomies based on the value of the Types of Animal taxonomy. I can use the fact that the taxonomy is hierarchical but if Types of Animal contained 100 terms with 50 possible sub-terms, that makes for a big mess when I'm editing.
So what I'd like to do is display a child taxonomy, say 'Breeds', when the editor selects 'dog' in the 'Types of Animal' taxonomy.
I could use tags but I'm afraid of the margin of error inputting tags. I would rather that editors had to check a box.
Is it possible to display a child/secondary taxonomy dynamically in this way?
|
Have a look at this tutorial for a possible solution: How To Show/Hide WordPress Meta Boxes By Selecting Categories.
Basically, all of the taxonomies would be hidden via javascript, and a function attached to the click event of the Animals taxonomy, which inspects the selected item's ID to show a corresponding child taxonomy. You'd also have to have a bit of logic on page load to show the taxonomies with terms that are already selected.
There are potential problems though - what happens if someone deselects "dog", but not any child terms?
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "custom post types, taxonomy, multi taxonomy query"
}
|
How to handle large number of images in a post?
I have a load of images - up to 16 per post plus a thumbnail and a logo. I want to figure out what the best way to handle them is. Since I'll be adding new entries quite regularly the number of images in the default uploads directory will get quite large.
Is this something I should be concerned about? As far as load times etc. I was going to create a co-gallery post type and attach the gallery images to this post type. Then set the gallery id on the Company edit page ( different post type ) to which the gallery belongs. A little code and I have an image gallery.
Or should I consider ( ad figure out how to ) uploading the images to a completely separate location/directory? Would doing this be worth the effort and is it really beneficial?
Hope that makes sense.
Thanx for your help.
|
1. Reduce image size using Photoshop, smush.it, or any other decent compressor. A decent rule is .jpg for photos with lots of colors and/or details and .gif for text and under 256 colors with less details.
2. Use exact image sizes, if you use php to resize the images make sure they are cached versions of the re-size.
3. Use a CDN or a non shared fast host.
4. Make the user cache the image in his browser by using;
`ExpiresByType image/jpeg "access plus 1 month"` or
`<FilesMatch "\.(gif|jpg|png|js|css)$"> Expires 2592000` if your on apache ( insert your own numerical values).
By far the most important thing to do is proper compression an sizing.
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 1,
"tags": "custom post types, images"
}
|
Removing title tags from each page
hello to all I am newbie to wordpress. I want to remove the title tags from every page.Is there any way to remove that part?Thanks in advance..
|
You can open your theme files and remove the code that adds this to the page. The typical files to look in are: index.php, page.php, post.php, single.php.
Look for this:
<h2><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></h2>
or it might look like this:
<?php the_title(); ?>
You might want to comment the part of code out so you can easily add it if you want to in the future. To use this method you would surround the part the_title(); with this /** the_title(); */ It would then look like this:
<?php /** the_title(); */?>
|
stackexchange-wordpress
|
{
"answer_score": 2,
"question_score": 2,
"tags": "theme development, title"
}
|
Count how many posts in category
This is what I'm trying to do:
if number of posts is greater than 20 -> display link to another page (which shows all posts) if number of posts is less than 20 -> don't display the link
So far I've been able to return the number of posts using
$count_posts = wp_count_posts('inventory');
$published_posts = $count_posts->publish;
but I don't know where to go from here, any suggestions?
|
If I remember right count of posts in category is stored persistently in category object. So use `get_category()` or variation of it and fetch the number out of object.
Example code (not tested):
$category = get_category($id);
$count = $category->category_count;
if( $count > $something ) {
// stuff
}
|
stackexchange-wordpress
|
{
"answer_score": 20,
"question_score": 6,
"tags": "posts, categories"
}
|
menu in different page in different style
I have a one column page for the home page where I have a mega menu and in side the site there is another page called about us where the mega menu is present but it is in small format just like it differs from the mega menu in width and height.So for home page I have used widget and now for about us page I want the small mega menu.So can any one tell me how to do that.I heared about if(front_page()), so I am using this but nothing is happening.So please guide me.Thanks in advance.
|
you can use this,
<?php if( is_front_page() ):?>
<div class="home-page-menu">
wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) );
</div>
<?php elseif; ?>
<div class="inside-page-menu">
wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) );
</div>
<?php endif; ?>
Here, you should be change your CSS style for home-page-menu and inside-page-menu . for more details about this `is_front_page()` follow this link <
|
stackexchange-wordpress
|
{
"answer_score": 0,
"question_score": 0,
"tags": "widgets, menus"
}
|
Add title, post content, and category like add_post_meta and update_post_meta
How can I update/add a new title, post content, and category to a post with hard PHP code similar to add_post_meta(), update_post_meta()?
|
By using `wp_update_post()`, found in wp-includes/post.php:
// Update post 42
$post = array();
$post['ID'] = 42;
$post['post_category'] = array( ... );
$post['post_content' ] = 'This is the updated content.';
$post['post_title' ] = 'This is the updated title.';
// Update the post into the database
wp_update_post( $post );
|
stackexchange-wordpress
|
{
"answer_score": 3,
"question_score": 1,
"tags": "categories, php, title, actions, description"
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.