question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
Under "Personal Options" on user profile page, there are: (1) disable visual editor (2) admin color scheme (3) keyboard shortcuts (4) show admin bar I can remove admin color scheme using remove_action, but not the rest. Is there a way to remove them all at once? Or one by one using remove_action or style or js?
I think this is the kind of thing you had in mind. <code> add_action( 'admin_print_styles-profile.php', 'remove_profile_fields' ); add_action( 'admin_print_styles-user-edit.php', 'remove_profile_fields' ); function remove_profile_fields( $hook ) { ?&gt; &lt;style type="text/css"&gt; form#your-profile p+h3, form#your-profile p+h3+table { display:none!important;visibility:hidden!important; } &lt;/style&gt; &lt;?php } </code> There aren't any actions or filters to remove the items you're referring to(with exception the admin color scheme), and the table they sit in does not have a unique identifier, which in turn means the only solution to getting rid of them is using CSS or jQuery selectors, neither of which will work for every user. IE6 for example won't understand the CSS i've written above and will just ignore it. jQuery solutions are possible, but like the above, they won't work for every user. @Jeremy, Whilst it's nice you've shown how to add a stylesheet to the admin, it's not really ideal to suggest adding one to every admin page when the requirement was to only load additional CSS or JS for a specific one or two pages, you should ideally also be using <code> plugins_url() </code> for generating the URL to plugin files.
How to remove all the items under "Personal Options" on user profile page?
wordpress
I want to remove the below text links in Edit Post screen: All (8) | Published (5) | Draft (1) | Pending (2) | Trash (2) After searching, i found that this can be done by this code here , but sadly it only works with 'post' type. I'm failed to make it works with my custom post type: <code> add_action( 'views_edit-post', 'remove_edit_post_views' ); function remove_edit_post_views( $views ) { if( get_post_type() === 'movie' ) { unset($views['all']); unset($views['publish']); unset($views['trash']); } return $views; } </code> What's wrong with my code ?
Further down on the page you linked to is this comment: Similar views can be edited by hooking into 'views_' . $screen-> id where $screen is the global $current_screen (or get_current_screen()). Draft, Pending, Mine and Sticky could all be removed in a similar manner. When you're editing a post, you're on the "edit-post" screen, so the action you use is <code> views_edit-post </code> . If you're working with a custom post type called "gallery," the edit screen is "edit-gallery" and you'd hook into the <code> views_edit-gallery </code> action. In your case I'd do the following: <code> function remove__views( $views ) { unset($views['all']); unset($views['publish']); unset($views['trash']); return $views; } add_action( 'views_edit-post', 'remove_views' ); add_action( 'views_edit-movie', 'remove_views' ); </code> This will remove "all", "publish", and "trash" from both posts and the custom post type "movie." Removing these views from other post types is as simple as adding the following line: <code> add_ection( 'views_edit-{post-type-slug}', 'remove_views' ); </code> Just replace <code> {post-type-slug} </code> with the name of your custom post type.
Remove All, Published and Trashed Post Views in Custom Post Type
wordpress
I'm trying to make a script that uploads a file to a specific folder in the wordpress installation. Basically I want to upload to /uploads. However, in order to do this I need to know the server path for the WordPress installation. How can I get this?
Use wp_upload_dir() for path to uploads, and use get_bloginfo() to get paths to the WP location
WordPress upload file - get path to WordPress installation
wordpress
I'd like to be able to have a workflow that works like so: Create a post and assign it a password Have a single-field form on the home page User enters password on home page, and is sent to the corresponding post Does anyone know if this is possible?
Thanks to Tom's help, here's what I ended up with. This uses the built in functionality for password-protecting a post, so a visitor only has to enter a password on the home page, then they are taken to the post and are able to directly view the post content without re-entering the password. On home page: <code> &lt;form method="post" action=""&gt; &lt;input type="password" name="passwordfield"&gt; &lt;input type="hidden" name="homepagepassword" value="1"&gt; &lt;input type="submit" value="Submit"&gt; &lt;/form&gt; </code> In <code> functions.php </code> (of course this could be converted to a plugin): <code> if(isset($_POST['homepagepassword'])){ global $wpdb; $post_password = $_POST['passwordfield']; $post_id = $wpdb-&gt;get_var( $wpdb-&gt;prepare("SELECT ID FROM $wpdb-&gt;posts WHERE post_password = %d", $post_password) ); $q = new WP_Query( 'p=$post_id' ); if($q-&gt;have_posts()){ while($q-&gt;have_posts()){ $q-&gt;the_post(); wp_redirect(get_permalink()); die(); } } else { // oh dear, there isnt a post with this 'password', put a redirect to a fallback here wp_redirect('http://www.google.com'); die(); } wp_reset_query(); } </code>
Is it possible to direct users to a certain post based on a password entered on the home page?
wordpress
Is there any reason for getting this error? I tested a couple of installations so far. Any suggestion?
It's WordPress 3.1 function - so you're probably testing it on older versions.
Fatal error: Call to undefined function get_users()
wordpress
Our site is quite high traffic and we use both nginx and w3 total cache to handle the load. We've previously been using wp-postviews to count the page views, but it seems to be locking the postmeta table now, and often doesnt count views at all. It's unreliable at best. Can anyone suggest a way for us to count page views and put them into the DB, or any specific workable solutions? My initial thoughts are to have the view count done via javascript to update a separate database, then a cron job at the end of each day to merge the results, but I'm not sure where to start. Thanks in advance
It really depends what you need to view counts for - if it's just for seeing traffic stats, then use Google Analytics or any number of javascript tracker based analytics tools. If you need integration of page view counts and the ability to do things like order post by views, then you can either spend some time optimising your database - some options and things to consider more memory for MySQL change the postmeta table to be InnoDB get a separate database server make sure you've tuned your MySQL settings (use mysqltuner as a starting point) OR Use something like Piwik and spend time integrating it (it has a decent API) with WordPress.
Counting pageviews on high-traffic cached sites
wordpress
New to WP. I soon realized there are some files that need to be writable by the web server, otherwise various operations fail. Moreover, the lists seem to be different for different tasks. Not sure I'm in love with the concept, but okay, I'll work with it. The trouble is, I can't figure out a simple way to determine which files / folders could be written to by the web server during the course of various actions. The documentation I've found seems either geared towards less technically-abled users ("just enable everything!") or focused on very narrow aspects. Does anybody have the minimal lists of writable files for various operations, such as: uploading content, installing a plugin or a theme, upgrading WP (this one is easy: everything needs to be writable), etc. Thanks!
The short answer is that you're correct... You don't want the web server (or web user) accounts to have full write access to your WordPress installation. Your user account , however, will need write permissions for the entire application because many of the WordPress features (such as automatic updates among others) require access to the core files. The Codex article Hardening WordPress has a section that specifically addresses your concerns called File Permissions . You can also checkout Changing File Permissions , but I think you'll find the first article most helpful. Here's a short excerpt from the Codex article... Some of WordPress' cool features come from allowing some files to be writable by web server. However, letting an application have write access to your files is a dangerous thing, particularly in a public environment. It is best, from a security perspective, to lock down your file permissions as much as possible and to loosen those restrictions on the occasions that you need to allow write access, or to create special folders with more lax restrictions for the purpose of doing things like uploading images. Here is one possible permission scheme. All files should be owned by your user account, and should be writable by you. Any file that needs write access from WordPress should be group-owned by the user account used by the webserver. ... much more goodness in those articles. Have fun!
List of files/folders writable by the web server?
wordpress
I have a custom post type for 'Teams' set up using the code below. However, the fields for 'Latest Discussion' and 'Next Fixture' isn't showing up in the dashboard. I went over the code numerous times and can't find anything wrong with it. I was hoping someone here could help me figure it out. <code> // Register Teams add_action('init', 'register_teams'); function register_teams() { $labels = array( 'name' =&gt; _x('Teams', 'post type general name'), 'singular_name' =&gt; _x('Team', 'post type singular name'), 'add_new' =&gt; _x('Add New', 'team item'), 'add_new_item' =&gt; __('Add New Team'), 'edit_item' =&gt; __('Edit Team'), 'new_item' =&gt; __('New Team'), 'view_item' =&gt; __('View Team'), 'search_items' =&gt; __('Search Teams'), 'not_found' =&gt; __('Nothing found'), 'not_found_in_trash' =&gt; __('Nothing found in Trash'), 'parent_item_colon' =&gt; '' ); $args = array( 'labels' =&gt; $labels, 'public' =&gt; true, 'publicly_queryable' =&gt; true, 'show_ui' =&gt; true, 'query_var' =&gt; true, 'rewrite' =&gt; true, 'capability_type' =&gt; 'post', 'hierarchical' =&gt; false, 'menu_position' =&gt; null, 'menu_icon' =&gt; get_stylesheet_directory_uri() . '/images/menu-teams.png', 'supports' =&gt; array( 'title', 'editor', 'thumbnail' ), 'has_archive' =&gt; true ); register_post_type( 'teams' , $args ); } // Add Fields add_action("admin_init", "add_teams_fields"); function add_teams_fields(){ add_meta_box("latest_discussion", "Latest Discussion", "latest_discussion", "latest discussions", "side", "low"); add_meta_box("next_fixture", "Next Fixture", "next_fixture", "next fixture", "side", "low"); } function latest_discussion(){ global $post; $custom = get_post_custom($post-&gt;ID); $latest_discussion = $custom["latest_discussion"][0]; ?&gt; &lt;label&gt;Latest Discussion URL:&lt;/label&gt;&lt;br /&gt;&lt;br /&gt; &lt;input size="40" name="latest_discussion" value="&lt;?php echo $latest_discussion; ?&gt;" /&gt; &lt;?php } function next_fixture(){ global $post; $custom = get_post_custom($post-&gt;ID); $next_fixture = $custom["next_fixture"][0]; ?&gt; &lt;label&gt;Next Fixture:&lt;/label&gt;&lt;br /&gt;&lt;br /&gt; &lt;input size="40" name="next_fixture" value="&lt;?php echo $next_fixture; ?&gt;" /&gt; &lt;?php } // Save Fields add_action('save_post', 'save_teams_details'); function save_teams_details(){ global $post; update_post_meta($post-&gt;ID, "latest_discussion", $_POST["latest_discussion"]); update_post_meta($post-&gt;ID, "next_fixture", $_POST["next_fixture"]); } </code>
The fourth argument for <code> add_meta_box() </code> is the context, which in this case would be <code> teams </code> , not <code> latest discussion </code> or <code> next fixture </code> as you have here. Also, since you want these metaboxes to show on the new and edit screens for your CPT only, it's easiest to register a metabox callback for your specific CPT and get rid of the action on <code> admin_init </code> . Add it to your $args array, e.g. <code> 'register_meta_box_cb' =&gt; 'prefix_teams_cpt_add_metaboxes' </code> . So, a modified version of your code: <code> // Register Teams add_action('init', 'register_teams'); function register_teams() { $labels = array( 'name' =&gt; _x('Teams', 'post type general name'), 'singular_name' =&gt; _x('Team', 'post type singular name'), 'add_new' =&gt; _x('Add New', 'team item'), 'add_new_item' =&gt; __('Add New Team'), 'edit_item' =&gt; __('Edit Team'), 'new_item' =&gt; __('New Team'), 'view_item' =&gt; __('View Team'), 'search_items' =&gt; __('Search Teams'), 'not_found' =&gt; __('Nothing found'), 'not_found_in_trash' =&gt; __('Nothing found in Trash'), 'parent_item_colon' =&gt; '' ); $args = array( 'labels' =&gt; $labels, 'public' =&gt; true, 'publicly_queryable' =&gt; true, 'show_ui' =&gt; true, 'query_var' =&gt; true, 'rewrite' =&gt; true, 'capability_type' =&gt; 'post', 'hierarchical' =&gt; false, 'menu_position' =&gt; null, 'menu_icon' =&gt; get_stylesheet_directory_uri() . '/images/menu-teams.png', 'supports' =&gt; array( 'title', 'editor', 'thumbnail' ), 'has_archive' =&gt; true, 'register_meta_box_cb' =&gt; 'prefix_teams_cpt_add_metaboxes' ); register_post_type( 'teams' , $args ); } // Add Metaboxes function prefix_teams_cpt_add_metaboxes(){ add_meta_box("latest_discussion", "Latest Discussion", "prefix_latest_discussion_metabox", "teams", "side", "low"); add_meta_box("next_fixture", "Next Fixture", "prefix_next_fixture_metabox", "teams", "side", "low"); } function prefix_latest_discussion_metabox(){ global $post; $custom = get_post_custom($post-&gt;ID); $latest_discussion = $custom["latest_discussion"][0]; ?&gt; &lt;label&gt;Latest Discussion URL:&lt;/label&gt;&lt;br /&gt;&lt;br /&gt; &lt;input size="40" name="latest_discussion" value="&lt;?php echo $latest_discussion; ?&gt;" /&gt; &lt;?php } function prefix_next_fixture_metabox(){ global $post; $custom = get_post_custom($post-&gt;ID); $next_fixture = $custom["next_fixture"][0]; ?&gt; &lt;label&gt;Next Fixture:&lt;/label&gt;&lt;br /&gt;&lt;br /&gt; &lt;input size="40" name="next_fixture" value="&lt;?php echo $next_fixture; ?&gt;" /&gt; &lt;?php } // Save Fields add_action('save_post', 'prefix_save_teams_details'); function prefix_save_teams_details(){ global $post; update_post_meta($post-&gt;ID, "latest_discussion", $_POST["latest_discussion"]); update_post_meta($post-&gt;ID, "next_fixture", $_POST["next_fixture"]); } </code> Note that I've changed some function names - be sure that you always prefix your functions, and it's way easier to keep track of things like a metabox creating function if the name really describes what it does.
Custom Post Type fields not showing in dashboard
wordpress
I am creating a plugin in which I will need to display content on a page. I have seen plugins that allow an administrator to put something like [display-content] in the visual editor which displays the plugin content to a website visitor. How is this done?
With the Shortcode API .
Plugin to Display Content on Page
wordpress
I use this in functions.php to change "howdy" to "Logged in as...." But now under 3.1 I get "Logged in as Your Profile" rather than "Logged in as <code> &lt;current user&gt; </code> " What needs to be changed so that "user" below (commented below as <code> //get current user?) </code> returns the current user in 3.1? <code> if (is_admin()) { add_action('init', 'better_howdy_h'); add_action('admin_footer', 'better_howdy_f'); function better_howdy_h() { wp_enqueue_script('jquery'); } function better_howdy_f() { ?&gt; &lt;script type="text/javascript"&gt; /* &lt;![CDATA[ */ var user = jQuery('#user_info p a:first').text(); var howdy = jQuery('#user_info p') .html() .replace(/&lt;.+&gt;/ig,'') .replace(/\ \|\n/ig,''); jQuery('#user_info p') .html( jQuery('#user_info p') .html() .replace(user,'My Profile') .replace(howdy,'Logged in as ' + user + ' | ') //get current user? .replace('!',' |') .replace('| |','|') ); /* ]]&gt; */ &lt;/script&gt; &lt;?php } } </code>
Why fiddle around with jQuery when you could just run a filter on <code> gettext </code> to specifically target that text? Perhaps you simply don't know you can do that, so here's how.. <code> add_filter( 'gettext', 'change_howdy_text', 10, 2 ); function change_howdy_text( $translation, $original ) { if( 'Howdy, %1$s' == $original ) $translation = 'Logged in as %1$s'; return $translation; } </code> Hope that helps. :)
Get current logged in user under 3.1, re: remove "Howdy"
wordpress
I'm using wp_list_categories to give me a list of links to categories (no surprise there) Is it possible to get Wordpress to link to the first post of a given category instead of calling the taxonomy template which displays links to all posts in that category?
Ended up resolving it by using this in the taxonomy template instead... <code> &lt;?php /* Redirect To First Child */ if (have_posts()) { while (have_posts()) { the_post(); $pagekids = get_pages("child_of=".$post-&gt;ID."&amp;sort_column=menu_order"); $firstchild = $pagekids[0]; wp_redirect(get_permalink($firstchild-&gt;ID)); } } </code> ?>
wp_list_categories link to first post of category instead of calling taxonomy template
wordpress
What happens, when I click <code> Save Changes </code> on a option page, which was created by <code> add_menu_page() </code> ? Where is the submitted data stored before the database transmission? A <code> print_r($_REQUEST) </code> returns only the two <code> $_GET </code> parameters <code> page </code> and <code> settings-updated </code> . I've checked the manual for <code> add_settings_field </code> and there is only the following hint: ... the saving will be done behind the scenes. Background I'd like to optimize my process of creating a plugin settings page. I've already jumped on the WP Settings API with <code> add_settings_section </code> and <code> add_settings_field </code> long time ago, but it feels a bit uncomfortable to create a new callback function every time. So instead of creating the specific field/section code inside a callback, I'd like to create the complete settings page with <code> Zend_View </code> . All input fields would be created with <code> Zend_Form </code> and also attached to the view. In the end, the callback of <code> add_menu_page() </code> will return the rendered View-Object instead of the normal HTML output. The HTML is stored inside a View-Template, located in <code> views/pages/admin/ </code> (e.g. <code> default.phtml </code> ). The basic principle is already working I'm very happy with the result. Due to the use of <code> Zend_View </code> , I've to do the saving on my own. But WordPress seems to delete the submitted $_POST array. If I debug the output after a successfull form submission, only the two <code> $_GET </code> params above are set. I've also attached the output of the function <code> settings_fields() </code> to the view, which generates the required hidden fields ( <code> option_page </code> , <code> action </code> , <code> _wp_nonce </code> ). Any ideas?
I've finally found my fault. The "problem" with <code> Zend_View </code> and <code> Zend_Form </code> is, that you have to check and save the submitted settings by yourself. But if you register a sanitize hook with <code> register_setting() </code> , WordPress will indeed not return any <code> $_POST </code> array and will immediatly submit the data to the defined option in the database. The solution was to remove the call to <code> register_setting() </code> completely. I've also removed the call to <code> settings_field() </code> and set the hidden fields manually in the <code> Zend_Form </code> object. <code> $form = new Zend_Form(); $form-&gt;setAction('options.php?page=' . $this-&gt;getMenuSlug()) -&gt;setMethod('post'); $wpnonce = $form-&gt;createElement('hidden', '_wp_nonce'); $wpnonce-&gt;setValue(wp_create_nonce($this-&gt;getMenuSlug())); </code> The method <code> $this-&gt;getMenuSlug() </code> will return the id of the current generate admin page used in <code> add_page_menu() </code> . The last part was to do the form validation before echoing the <code> Zend_View </code> object. This is done in the <code> renderView() </code> method, which will be called as callback in <code> add_menu_page() </code> . <code> public function renderView() { try { if($_POST['submit']) { // Check wp nonce if(!wp_verify_nonce($_POST['_wp_nonce'], $this-&gt;getMenuSlug())) { wp_die(__('Nonce incorrect!')); } else { if($this-&gt;_form-&gt;isValid($_POST)) { echo '&lt;div id="message" class="updated fade"&gt;&lt;p&gt;&lt;strong&gt;' . __('Settings saved.') . '&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;'; foreach ($this-&gt;_form-&gt;getElements() as $element) { if(in_array($element-&gt;getName(), $this-&gt;_skipElements)) { continue; } Webeo_Option::getInstance()-&gt;setValue($element-&gt;getName(), $element-&gt;getValue()); } Webeo_Option::getInstance()-&gt;commit(); } else { echo '&lt;div id="message" class="error fade"&gt;&lt;p&gt;&lt;strong&gt;' . __('Errors occured.') . '&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;'; } } } echo $this-&gt;_form-&gt;render($this-&gt;_view); //echo $this-&gt;_view-&gt;render($this-&gt;getViewTemplate()); } catch (Zend_View_Exception $e) { echo $e-&gt;getMessage(); } } </code> The <code> Webeo_Option </code> is just an object storage and could be replaced with <code> update_option() </code> .
Where is the submitted $_POST array stored after an option page submission?
wordpress
I added the following code which allows categories on my 'Page' post type. <code> add_action('init', 'edit_page_type'); function edit_page_type() { register_taxonomy_for_object_type('category', 'page'); } </code> Now i realize the permalinks dont exactly match... How can i rewrite the page permalinks to act like the post permalinks? (which include the category before the page title)
Can you not just use Posts thats was they're designed for. You don't really categorise pages you structure them so they have parents and so on.
Page permalink rewrite
wordpress
I've created a custom post, <code> events </code> , and saved the meta data <code> event_year </code> to each event. I'm trying to get a year's event archive. When I go the the following URL, the <code> meta_key </code> and <code> meta_value </code> are not set for some reason, and thus the event archive is unfiltered. <code> /?post_type=events&amp;meta_key=event_year&amp;meta_value=2011 </code> Debugging the values: <code> echo $wp_query-&gt;query_vars['post_type']; // 'events' echo $wp_query-&gt;query_vars['meta_key']; // -blank- echo $wp_query-&gt;query_vars['meta_value']; // -blank- </code> Why can't I set the meta_key and meta_value? The meta_values are saved to the events. I've successfully displayed them: <code> get_post_meta($post-&gt;ID, 'event_year', true); // '2011' </code>
That's because 'meta_key' and 'meta_value' are not public query vars. In other words, you can't use them in URLs directly, nor should you. Instead, register a specific query var, like so: <code> function register_my_qv() { global $wp; $wp-&gt;add_query_var( 'my_qv' ); } add_action( 'init', 'register_my_qv' ); </code> Then, you can go to a URL like this: <code> ?my_qv=foobar </code> All you need to do now is map your query var to the actual query you want to do: <code> function map_my_qv( $wp_query ) { if ( $meta_value = $wp_query-&gt;get( 'my_qv' ) ) { $wp_query-&gt;set( 'meta_key', 'some_meta_key' ); $wp_query-&gt;set( 'meta_value', $meta_value ); } } add_action( 'parse_query', 'map_my_qv' ); </code>
I can't set meta_key in my custom post type query
wordpress
<code> foreach((get_the_category()) as $cat) { if (!($cat-&gt;cat_name=='Featured')) echo $cat-&gt;cat_name . ' '; } </code> this is what has been recommended in the forums but its not working for me. I need to split off the echo piece like the following to show an image. <code> &lt;li&gt;&lt;img src="&lt;?php bloginfo('template_url'); ?&gt;/images/cats/&lt;?php echo $category-&gt;slug ?&gt;-icon.png"/&gt; &lt;?php echo $category-&gt;cat_name ?&gt; &lt;/li&gt; </code> any ideas?
Try this: <code> foreach((get_the_category()) as $cat) { if ($cat-&gt;cat_name != 'Featured') { echo '&lt;li&gt;&lt;img src="' . get_bloginfo('template_url') . '/images/cats/' . $category-&gt;slug . '-icon.png"/&gt;' . $category-&gt;cat_name . '&lt;/li&gt;'; } } </code>
using get_the_category to get all post categories except one
wordpress
I am looking for a way to make it so multiple authors/moderators within wordpress get notified when there is a new comment waiting approval. I'm thinking of switching over to Disqus for this type of thing, but was wondering if it's possible without swapping out the commenting interface.
I have used the plugin Comment Notifier. http://wordpress.org/extend/plugins/comments-notifier/ And it works adequately.
Multiple Comment Moderators and Notifications
wordpress
I just moved a site (by exporting &amp; importing all posts &amp; pages, and copying theme files over), and on the new site the various page and post templates are unavailable for selection on post and page edit screens. The files did have Windows line endings, which I fixed, but that did not eliminate the problem. Any other things to try?
Sounds like it could be an issue with the database and serialization of the plugin options. I've had problems before with plugin settings etc when moving a site using the xml export. The category templates plugin writes a lot of options to the db and they could be corrupted. As a test try creating a php file and putting it in the themes root directory. Add the basic template header: <code> &lt;?php /* * Template Name: Template Test */ ?&gt; </code> See if it's available to choose from. If you still have access to the old site / server try doing an mysql dump of the database then create a new blank database and import the dump file. Also you didn't mention the server / hosting environment of the new and old locations. That info might help debug the issue. Also wanted to mention that the Category Templates plugin has issues which may or may not be the cause of the problem. The plugin uses serialize and unserialize in its update_option() and get_option() calls. WordPress already does the serialization for those functions see: http://andrewnacin.com/2010/04/18/wordpress-serializing-data/ If you look at the first few lines of the plugin: <code> function cat_temp_menus() { add_submenu_page('themes.php','Category Templates', 'Category Templates', 8, basename(__FILE__), 'cat_temp_options_page'); if (function_exists('add_meta_box')) { add_meta_box('cat_template_select','Post Template','cat_temp_meta','post','side','low'); } } </code> The add_submenu_page function is using user roles (the 8) which was deprecated in version 2.0. The syntax should be: <code> &lt;?php add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function ) ?&gt; </code> It's also using <code> basename(__FILE__) </code> as the admin menu page slug which is a minor security issue. Notes For $menu_slug please don't use FILE it makes for an ugly URL, and is a minor security nuance. ( See Codex ) That line in the code should be: <code> function cat_temp_menus() { add_submenu_page('themes.php','Category Templates', 'Category Templates', 'activate_plugins', 'themes.php?page=cat_temp_options_page', 'cat_temp_options_page'); if (function_exists('add_meta_box')) { add_meta_box('cat_template_select','Post Template','cat_temp_meta','post','side','low'); } } </code> So my answer is that the problem is most likely the plugin and my suggestion would be to either rewrite it or find another one. Update: I decided to rewrite the plugin fixing all the issues since the author isn't really supporting it anymore. For now it's on GitHub: https://github.com/c3mdigital/Category-Templates
Template files missing after moving site
wordpress
I've got jwplayer installed in wordpress and have it showing in a single.php page... the way I have it I need to get a custom field in the javascript and I;m having no luck echoing it in there. I know you cant straight up run PHP in a javascript function, hence I'm here asking noob questions :) <code> &lt;script type='text/javascript'&gt; jwplayer("lbp-inline-href-1").setup({ 'flashplayer': '/wp-content/uploads/jw-player-plugin-for-wordpress/player/player.swf', 'image': '/wp-content/themes/sometheme/images/vid.png', 'file': '&lt;?php echo get_post_meta($post-&gt;ID, 'video', true); ?&gt;', 'skin': '/wp-content/plugins/jw-player-plugin-for-wordpress/skins/skewd.zip', 'stretching': 'exactfit', 'controlbar': 'bottom', 'width': '640', 'height': '360' }); &lt;/script&gt; </code> is it possible to get <code> &lt;?php echo get_post_meta($post-&gt;ID, 'video', true); ?&gt; </code> Running in there for the file path? Thanks for any advice.
Have a read through this article: Adding Scripts Properly to WordPress Part 2 – JavaScript Localization What you are doing here is passing your PHP values to the WordPress JS localization system. This then allows your JS code to get access to those variables you have passed.
PHP echo inside javascript
wordpress
I need to export the last two week's worth of blog posts from one site into another site, including all meta data and post author info. Is there a good SQL statement to do this, or a plugin that will help me accomplish this?
The native import/export tool can do most of this, though I don't think it will grab all the author profile information (not sure on that - I know it doesn't bring over passwords, but it might bring the rest). In the WP admin panel go to Tools > Export and walk through the various option screens. Best of luck!
How to export 2 week's worth of posts
wordpress
In several theme templates I have code to retrieve the category name and slug for the present post or category page. It is outside the loop. Here is the repeated code: <code> global $post; $categories = get_the_category($post-&gt;ID); if ( $categories ) { foreach ($categories as $category) { $dw_category_slug = $category-&gt;slug; $dw_category_name = $category-&gt;name; } }else { $dw_category_slug = 'utopia'; } </code> I would like to be able to include this in the functions file instead of writing it in several places. This is what I have tried in my functions file: <code> add_action('wp_head', 'dw_get_category'); function dw_get_category() { global $post; $categories = get_the_category($post-&gt;ID); if ( $categories ) { foreach ($categories as $category) { $dw_category_slug = $category-&gt;slug; $dw_category_name = $category-&gt;name; } } else { $dw_category_slug = 'utopia'; } $dw_category[] = array('name' =&gt; $dw_category_name, 'slug' =&gt; $dw_category_slug); return $dw_category; } </code> I would like to be able to write something like <code> $dw_category['name'] </code> in the template files to call the category name. I know this is the wrong way to do it. Do I need to divide this into 2 functions so there is only one value returned for the function? Or is there some other way to do this? Writing it as a class? If interested the url is http://lenoremalenblog.com Thanks for your time.
You don't need to hook the <code> dw_get_category() </code> function. Simply do it like this: <code> function dw_get_category() { global $post; $categories = get_the_category($post-&gt;ID); if ( $categories ) { foreach ($categories as $category) { $dw_category_slug = $category-&gt;slug; $dw_category_name = $category-&gt;name; } } else { $dw_category_slug = 'utopia'; } $dw_category = array('name' =&gt; $dw_category_name, 'slug' =&gt; $dw_category_slug); return $dw_category; } </code> Then call it like this: <code> $the_post_cats = dw_get_category(); echo 'Category: '.$the_post_cats['name']; echo 'Slug: '.$the_post_cats['slug']; </code>
create function to call category name and slug
wordpress
I'm trying to make Yoast's Custom RSS feeds post display in an add_feed function. Just putting Yoast's snippet inside add_feed results in: ERROR: feedname is not a valid feed template. I have tried two rewrite functions, but to no avail. What could I be missing? Yoast's function untouched: <code> &lt;?php /* Template Name: Custom Feed */ $numposts = 5; function yoast_rss_date( $timestamp = null ) { $timestamp = ($timestamp==null) ? time() : $timestamp; echo date(DATE_RSS, $timestamp); } function yoast_rss_text_limit($string, $length, $replacer = '...') { $string = strip_tags($string); if(strlen($string) &gt; $length) return (preg_match('/^(.*)\W.*$/', substr($string, 0, $length+1), $matches) ? $matches[1] : substr($string, 0, $length)) . $replacer; return $string; } $posts = query_posts('showposts='.$numposts); $lastpost = $numposts - 1; header("Content-Type: application/rss+xml; charset=UTF-8"); echo '&lt;?xml version="1.0"?&gt;'; ?&gt;&lt;rss version="2.0"&gt; &lt;channel&gt; &lt;title&gt;Yoast E-mail Update&lt;/title&gt; &lt;link&gt;&lt;a class="linkclass" href="http://yoast.com/"&gt;http://yoast.com/&lt;/a&gt;&lt;/link&gt; &lt;description&gt;The latest blog posts from Yoast.com.&lt;/description&gt; &lt;language&gt;en-us&lt;/language&gt; &lt;pubDate&gt;&lt;?php yoast_rss_date( strtotime($ps[$lastpost]-&gt;post_date_gmt) ); ?&gt;&lt;/pubDate&gt; &lt;lastBuildDate&gt;&lt;?php yoast_rss_date( strtotime($ps[$lastpost]-&gt;post_date_gmt) ); ?&gt;&lt;/lastBuildDate&gt; &lt;managingEditor&gt;&lt;a class="linkclass" href="mailto:[email protected]"&gt;[email protected]&lt;/a&gt;&lt;/managingEditor&gt; &lt;?php foreach ($posts as $post) { ?&gt; &lt;item&gt; &lt;title&gt;&lt;?php echo get_the_title($post-&gt;ID); ?&gt;&lt;/title&gt; &lt;link&gt;&lt;?php echo get_permalink($post-&gt;ID); ?&gt;&lt;/link&gt; &lt;description&gt;&lt;?php echo '&lt;![CDATA['.yoast_rss_text_limit($post-&gt;post_content, 500).'&lt;br/&gt;&lt;br/&gt;Keep on reading: &lt;a href="'.get_permalink($post-&gt;ID).'"&gt;'.get_the_title($post-&gt;ID).'&lt;/a&gt;'.']]&gt;'; ?&gt;&lt;/description&gt; &lt;pubDate&gt;&lt;?php yoast_rss_date( strtotime($post-&gt;post_date_gmt) ); ?&gt;&lt;/pubDate&gt; &lt;guid&gt;&lt;?php echo get_permalink($post-&gt;ID); ?&gt;&lt;/guid&gt; &lt;/item&gt; &lt;?php } ?&gt; &lt;/channel&gt; &lt;/rss&gt; </code> Function one : <code> function myPlugin_add_feed( ) { global $wp_rewrite; add_feed('feedname', 'my_feed'); add_action('generate_rewrite_rules', 'myPlugin_rewrite_rules'); $wp_rewrite-&gt;flush_rules(); } add_action('init', 'myPlugin_add_feed'); </code> and function two : <code> function custom_feed_rewrite($wp_rewrite) { $feed_rules = array( 'feed/(.+)' =&gt; 'index.php?feed=' . $wp_rewrite-&gt;preg_index(1), '(.+).xml' =&gt; 'index.php?feed='. $wp_rewrite-&gt;preg_index(1) ); $wp_rewrite-&gt;rules = $feed_rules + $wp_rewrite-&gt;rules; } add_filter('generate_rewrite_rules', 'custom_feed_rewrite'); </code>
You have <code> add_feed('feedname', 'my_feed'); </code> but no my_feed function to actually generate the feed output. Create a my_feed function and have it call the template to generate the feed output. Like this: <code> function my_feed() { include 'path-to-that-template-file.php'; } add_feed('feedname','my_feed'); </code> Then regenerate your permalinks, one time only, by resaving the permalink settings. Also, you don't need any of that extra rewrite nonsense at all. Just the add_feed is enough. WP handles the rest, and your feed will be at /feed/feedname.
Yoast custom feed template as add_feed function?
wordpress
I want my post-links to look like /%post_id62%_%postname%/ where %post_id62% is the post ID in base62 encoding (e.g. http://example.com/y9Rlf_test/ ) and my shortlinks to consist of /%post_id62% only (e.g. http://example.com/y9Rlf ). This is what i've got so far (in my <code> functions.php </code> ) which obviously doesn't work: <code> add_action( 'init', 'yoyo_init' ); function yoyo_init() { add_rewrite_tag( '%post_id62%', '([A-Za-z0-9]+)' ); } add_action('generate_rewrite_rules','yoyo_generate_rewrite_rules'); function yoyo_generate_rewrite_rules($yoyo_rewrite) { global $wp_rewrite; $new_rules['/([0-9A-Za-z]+)/?$'] = 'index.php?p=' . base622dec($wp_rewrite-&gt;preg_index(1)); // DOESNT WORK OF COURSE (executed only once when rewrite_rules are generated) $wp_rewrite-&gt;rules = array_merge($new_rules, $wp_rewrite-&gt;rules); } add_filter( 'post_link', 'yoyo_post_link', 10, 2 ); function yoyo_post_link( $permalink, $post ) { if ( false !== strpos( $permalink, '%post_id62%' ) ) { $post_id62 = dec2base62( $post-&gt;ID ); $permalink = str_replace( '%post_id62%', $post_id62, $permalink ); } return $permalink; } add_filter('pre_get_shortlink', 'yoyo_custom_shortlink', 10, 4); function yoyo_custom_shortlink($false, $post_id, $context, $allow_slugs) { global $wp_query; if($post_id or ($context == 'query' and $post_id = $wp_query-&gt;get_queried_object_id())) { return home_url('/' . dec2base62($post_id)); } return false; } function dec2base62($number) { $digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; $string = ''; while($number &gt; 0) { $string = $digits[$number % 62] . $string; $number = floor($number / 62); } return $string; } function base622dec($string) { $digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; $number = 0; while(strlen($string) and ($number *= 62 or strlen($string))) { $number += strpos($digits, $string[0]); $string = substr($string, 1); } return $number; } </code> Any idea how to tackle the problem? Bonus points for avoiding the -N slug suffix when there's another post with the same title created (which might be avoided actually when setting the link structure to "/%post_id62%_%postname%/" but in order to have the shortlink functionality it should be "/%post_id62%" I guess; cf. stackexchange-url ("Turn off %postname% auto-incrementing?"))! Thanks!
You only made a mistake in the final step, when you convert the base62-encoded ID back to a decimal ID. You should not do this by changing the rewrite rules, as they are only patterns, not actual rules per post. What you want is take an incoming URL, let WordPress parse it using the rewrite rules, but then before it is passed to the query engine, check for the <code> post_id62 </code> variable and set the actual <code> p </code> (post id) variable based on it. You can do this in the <code> request </code> filter, which is applied in <code> WP::parse_request() </code> . <code> add_action( 'request', 'wpse22253_request' ); function wpse22253_request( $query_vars ) { if ( array_key_exists( 'post_id62', $query_vars ) ) { $query_vars['p'] = base622dec( $query_vars['post_id62'] ); } return $query_vars; } </code> However, this will not solve the <code> postname-N </code> problem. WordPress will still call <code> wp_unique_post_slug </code> on the <code> post_name </code> field, and <code> post_name </code> will not include the <code> post_id62 </code> part (since the database is independent of the rewrite rules). As Mike suggested in stackexchange-url ("the followup comments to his answer"), you should either figure out a way to include the <code> post_id62 </code> part in the <code> post_name </code> field, or (and this might be the better way) ignore the <code> %postname% </code> part in the URL and just slap a postname-with-stripped-number-suffix string at the end. You will also run into issues with your shortlinks, since they have the same format (any letter or digit) as a page. Is <code> /banana/ </code> a page with the title "Banana" or a shortlink to the post with ID 34440682410 - which is <code> banana </code> in your base-62 encoding?
custom permalink/shortlink with base62 encoded post ID
wordpress
I'd like to force a user to a specific page upon login based on their role using <code> if ( current_user_can('contributor') ) </code> and the main login function <code> function wp_loginout($redirect = '', $echo = true) { if ( ! is_user_logged_in() ) $link = '&lt;a href="' . esc_url( wp_login_url(get_permalink()) ) . '"&gt;' . __('Log in') . '&lt;/a&gt;'; else $link = '&lt;a href="' . esc_url( wp_logout_url(get_permalink()) ) . '"&gt;' . __('Log out of account') . '&lt;/a&gt;'; if ( $echo ) echo apply_filters('loginout', $link); else return apply_filters('loginout', $link); } </code> I've tried a number of combinations and seem to be failing. Any help would be appreciated.
filter <code> login_redirect </code> : <code> function my_login_redirect_contributors() { if ( current_user_can('contributor') ){ return 'url-to-redirect-to'; } } add_filter('login_redirect', 'my_login_redirect_contributors'); </code>
How do I redirect upon login a specific user based on role?
wordpress
I have a custom post type set up on a subsite in a multisite network which the code is in a plugin to activate it only for the subsite. I have some code that inserts a post using code but I belive it is trying to insert it into the main site. it is simply a php page with require( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' ); then some $_POST to grab some data and use that to create a post. This works fine in a standalone install of WordPress but on the multisite it does not work. Is there a way to choose the site to add the post to?
You probably need to switch your context to the subsite in which the posts need to be created. Have a look at the switch_to_blog() and restore_current() functions in wp-includes/ms-blogs.php See http://phpxref.ftwr.co.uk/wordpress/wp-includes/ms-blogs.php.source.html#l437
Insert post into subsite using code
wordpress
I'm pretty new to WordPress and i'm trying to customise my theme to send an email to myself when a upgrade is required. I'd rather not use a plugin as this means I have to install it for each wordpress site. The code below is based from the update notifier plugin. <code> add_action('check_updates_daily', 'check_updates'); function check_updates_daily() { if (!wp_next_scheduled('check_updates')) { wp_schedule_event(time(), 'daily', 'check_updates'); } } function check_updates() { $update_core = get_site_transient( 'update_core' ); if (!empty($update_core) &amp;&amp; isset($update_core-&gt;updates) &amp;&amp; is_array($update_core-&gt;updates) &amp;&amp; isset($update_core-&gt;updates[0]-&gt;response) &amp;&amp; 'upgrade' == $update_core-&gt;updates[0]-&gt;response) { $newversion = $update_core-&gt;updates[0]-&gt;current; $oldversion = $update_core-&gt;version_checked; $blogurl = esc_url( home_url() ); $message = "It's time to update the version of WordPress running at $blogurl from version $oldversion to $newversion.\n\n"; // don't let $wp_version mangling plugins mess this up if (!preg_match( '/^(\d+\.)?(\d+\.)?(\d+)$/', $oldversion)) { include( ABSPATH . WPINC . '/version.php' ); $message = $wp_version == $newversion ? '' : "It's time to update the version of WordPress running at $blogurl from version $wp_version to $newversion.\n\n"; } } //Send email if (!empty($message)) { $subject = apply_filters( 'updatenotifier_subject', 'Updates are available for '.get_bloginfo('name').'.'); wp_mail('[email protected]', $subject, $message); } } </code> I did change it to check hourly to test if it worked but I didn't recieve any emails I also secheduled it to just send an email without checking for updates and this also didn't work. Any help appreciated, thanks =D
I forked the above plugin you mentioned as WP Updates Notifier Maybe you want to look at that instead? If you want to include it in your theme all you do is copy the plugin file and place in your theme functions file instead. If you need further help modifying this plugin leave a comment and I'll see what I can do.
Email user on wordpress upgrade
wordpress
Why I can't add tags since Wordpress 3.2 ?! Ajax doesn't seem to work... I gonna be crazy. Any help please ?
I believe this to be an issue with a jQuery conflict. Since version 3.2 of WP jQuery has been updates. There might be other plugins you are using that doesn't play nice with the new jQuery version which is then triggering a JS error, thus stopping the tag/AJAX functionality from working. Try disabling all your plugins and see if this fixes the issue. If it does enable one by one to target which plugin is causing the issue. Once you know what plugin is causing the issue then you can either contact the plugin author for a fix and try asking a question here to see if we can fix it.
Tags in Wordpress 3.2
wordpress
I know this is a vague question, please just spend time on it if you are in the mood, I don't need to be flamed for not being more precise. I'm having a problem with a theme I'm developing, for some reason it breaks the export function of WordPress. I'm not asking for anyone to solve my problems here, but after having spend some hours on it now, I'd like to ask, if anyone recognizes this problem, and would give me a hint as to in what direction to look for the problem. Somehow I have a feeling it has to do with a nonce check failure, but not sure.. Anyway the problem is, that if i click the Export button in the page <code> http://www.myserver.com/wp-admin/export.php </code> then I get the WP Failure Notice Screen. The url I'm taking to is this: <code> http://www.myserver.com/wp-admin/export.php?download=true&amp;content=all&amp;cat=0&amp;post_author=0&amp;post_start_date=0&amp;post_end_date=0&amp;post_status=0&amp;page_author=0&amp;page_start_date=0&amp;page_end_date=0&amp;page_status=0&amp;submit=Download+Export+File </code> and the page says: Are you sure you want to do this? Please try again. I think this must be coming from wp_explain_nonce() inside wp-includes/functions.php If I switch to the twenty ten theme the problem is gone. Back to my theme, and it's there, so it must be the theme.. Any advice on where to look or how to approach catching the bug in my theme is welcome.
The basic idea for debug here is that theme apparently influences something it totally should not. Either something is done in a wrong way or in a wrong place. Check that theme is not running any functionality directly in <code> functions.php </code> . Check that all of theme's functionality runs on appropriate hooks. For hooks that are used both on front-end and back-end conditionally exclude theme's functionality that is not supposed to work on back-end.
my theme breaks WP export
wordpress
How can I remove the width and height attributes from the post_thumbnail when inserting with <code> &lt;?php the_post_thumbnail(); ?&gt; </code> ? <code> &lt;img width="800" height="533" src="http://domain.com/wp-content/uploads/2011/02/image.jpg" class="attachment-post-thumbnail wp-post-image" /&gt; </code>
Related: stackexchange-url ("Filter to remove image dimension attributes?") There's a filter on <code> post_thumbnail_html </code> which receives as its argument the full html element representing the post thumbnail image before it's echoed to the page. You can filter out the dimensions with a bit of regex: <code> add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10, 3 ); function remove_thumbnail_dimensions( $html, $post_id, $post_image_id ) { $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html ); return $html; } </code>
How do you remove hard coded thumbnail image dimensions?
wordpress
I have a question. I made a simply ajax function. When I'm logged in, it works perfectly. When I'm logged out, it returns me -1 (since Wordpress 3.1) Why ? I don't understand. Precisely, it returns -1 and my entire HTML code. (lol) I'm gonna be crazy again. PHP (in functions.php) <code> function say_coucou(){ check_ajax_referer( 'hello', 'nonce' ); echo "Hello"; die(); // this is required to return a proper result exit; } add_action('wp_ajax_hello_hello', 'say_coucou'); add_action('wp_ajax_nopriv_hello_hello', 'say_coucou'); </code> * JAVASCRIPT / JQUERY / AJAX (in footer.php) * <code> function blabla(){ var toSend = { action:"hello_hello", post_id: "&lt;?php echo $wp_query-&gt;post-&gt;ID; ?&gt;", nonce: "&lt;?php echo js_escape( wp_create_nonce('hello')); ?&gt;" }; url_action = 'http://www.***********/wp-admin/admin-ajax.php'; $.ajaxSetup({cache:true}); $.ajax({ url: url_action, type:'POST', data: toSend, cache: false, success:function(results) { alert(results) } }); } </code> Any help, please ? Thanks.
Found It! I had done a redirect, so my ajax function status was 302... I deleted the redirect and it worked ! Thanks guys.
Ajax function returns -1
wordpress
I am using the below function to update the post meta from the front end. How can I add add best a textarea that updates <code> the_content() </code> using <code> wp_update_post() </code> ? <code> if ( isset( $_POST['albums'] ) &amp;&amp; wp_verify_nonce($_POST['albums'],'update_albums_postmeta') ) { //if nonce check succeeds. global $post; $postid = $post-&gt;ID; $data = $_POST['priceone']; update_post_meta($postid,'_releasedate',$data); $data = $_POST['pricetwo']; update_post_meta($postid,'_amazonlink',$data); } </code> - Edit: So this snippet is posting changes to the database, however when the page refreshes on-submit the old <code> the_content() </code> is being shown. The post must manually be refreshed to see the changes. Is my snippet malformed? <code> if ( isset( $_POST['drw_inventory'] ) &amp;&amp; wp_verify_nonce($_POST['drw_inventory'],'update_drw_postmeta') ) { //if nonce check succeeds. global $post; $data_content = $_POST['description']; $my_post = array(); $my_post['ID'] = $post-&gt;ID; $my_post['post_content'] = $data_content; wp_update_post( $my_post ); } </code>
It depends on where you're using this. Is global $post giving you the specific post that you want to update? Your Wordpress update post code looks right to me, but is the if-statement valid, and is $post-> ID yielding the correct int?
wp_update_post() example... how to update the_content in a textarea?
wordpress
I use the Chat plugin , but I found a bug when using it with the Twenty Eleven theme in WordPress 3.2. If you scroll, the chat window goes behind the header image. I used this plugin with no problems up to WordPress 3.1.4, and it works find in 3.2 - except for this problem. I guess the <code> z-index </code> is the reason, but I am not sure about that.
It is indeed a <code> z-index </code> problem. The <code> #branding </code> element has a <code> z-index </code> of 2, in other themes (like Twenty Ten, the default in 3.0 and 3.1), it was not set. A simple solution is to set the <code> z-index </code> of <code> #chat-block-site </code> to something higher. <code> #chat-block-site { z-index: 10; } </code>
Chat window hiding behind Twenty Eleven header
wordpress
Is there an easy way (a plugin maybe?) to export and then import into a different WordPress installation all links in the blogroll including descriptions and categories? I know you can export links by going to /wp-links-opml.php, but I believe doing it this way you loose the link descriptions. When importing, I'd like links to be put in their categories - if the categore does not exist it should be created. I would prefer a way to do this without hacking any core WordPress files if at all possible.
You can export/import the wp_links database table using PhpMyAdmin or similar database tool. Just make sure in the file that exports you change the database name at the top of the file to the name of the database in your destination wordpress site. Note that importing the table will remove any links that you currently have in the destination Wordpress install.
Blogroll import/export with categories and descriptions
wordpress
In the parent theme, the following is at the bottom of the functions.php file. <code> require_once(TEMPLATEPATH . '/admin/admin-menu.php'); </code> In the child theme's function.php , this code will include the child admin panel. <code> require_once(STYLESHEETPATH . '/admin/admin-menu.php'); </code> As you can see, I shouldn't use both files b/c the bottom file includes <code> get_stylesheet_directory_uri() </code> instead of <code> get_template_directory_uri() </code> for certain localized files (js, css). Thus, I need to remove the parent file from loading I believe I need to use the <code> remove_action </code> hook, but I'm not sure how to do this right. Can't find a good answer on Google either. I started writing the following in the functions.php file in my child theme, but I don't know how to write it properly. <code> function remove_parent_admin_panel { remove_action('remove_panel', '[WHAT-GOES-HERE?]'); } </code> Then I guess I need to use a <code> add_action </code> hook to add the above function to remove the parent admin panel. Should I wrap the parent <code> require_once </code> with a function statement? Am I on the right track?
For cases where you want to require/include PHP files, but still allow child themes to replace those PHP files outright, then you should use the locate_template function. Example: Parent does this: <code> locate_template( 'admin/file.php', true ); </code> This finds the admin/file.php file in either the child or the parent theme, then does a require on it (that's what the true is for). So to replace the file in the child, you just replace the file in the child. Simple. Easy. Note: The method defaults to using require_once. If you just want to require only, then pass a third parameter of false.
How do I remove a require_once admin panel from the parent theme from the child theme functions.php?
wordpress
I am trying to find a way to get the current page number of an article that has been splitted into several pages with the use of: <code> &lt;!-- nextpage --&gt; </code> There is an example that can be found here: http://codex.wordpress.org/Conditional_Tags#Testing_for_paginated_Pages But this doesn't work for me – it always returns 0: <code> $paged = $wp_query-&gt;get( 'paged' ); echo $paged; </code> Any idea? Thank you!
For multi-page posts: The <code> $page </code> global variable returns the current page of a multi-page post. The <code> $numpages </code> global variable returns the total number of pages in a multi-page post. For paginated archive index pages: The <code> $paged </code> global variable returns the current page number of a paginated archive index. To use any of these variables, simply globalize them first: <code> global $page; echo 'The current page number of this post is ' . $page . '.'; </code>
Get current page number of splitted article
wordpress
I have a new site and I'm using bbpress beta-3 with it, I've created custom login/register/lost-password pages with the custom templates supplied with bbpress and I can't seem to find the filter/hook/action that "hijacks" the calls to <code> wp-login.php </code> . My biggest problem is with the <code> lost-password </code> page, I want to redirect with a notice, I can catch the error but I can't catch the <code> sent password </code> event. I'm now using in function.php: <code> function get_password_retrieve_errors(){ wp_redirect( site_url('lost-password').'?getpass=failed' ); } add_filter('lostpassword_redirect', 'get_password_retrieve_errors', 1); </code> and in form-user-lost-pass.php: <code> &lt;?php if ( $_GET['getpass'] == 'failed' ) { ?&gt; &lt;div class="bbp-template-notice error"&gt; &lt;p&gt;Invalid username or e-mail, please try again.&lt;/p&gt; &lt;/div&gt; &lt;?php } ?&gt; </code> Is there a way to do it? Is there a global $error object which I can always refer to? Is there a global $notifications object I can always refer to? Thanks!
not sure i really follow you either, BUT what about filtering the wp_lostpassword_url from wp-includes/general-template.php <code> function wp_lostpassword_url( $redirect = '' ) { $args = array( 'action' =&gt; 'lostpassword' ); if ( !empty($redirect) ) { $args['redirect_to'] = $redirect; } $lostpassword_url = add_query_arg( $args, network_site_url('wp-login.php', 'login') ); return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect ); } </code> looks like it has a filter you could use to point it to your custom URL, and even add your 'getpass' query var Here's a very basic example: <code> function custom_login_lostpassword_url() { // use a site_url/plugins_url to output the correct URL. return "http://.../my-custom-lostpassword-screen.php"; } add_filter("lostpassword_url", "custom_login_lostpassword_url"); </code>
how to redirect to a custom password retrieval page
wordpress
After updating to Wordpress 3.2, the show/hide functionality of the event authoring area on "The Events Calendar" is backwards - when the "All Day Event?" checkbox is checked, the time boxes appear. When it is unchecked, the time boxes disappear. This is opposite behavior of what should happen. I suspect it's a Jquery issue. Has anyone else discovered this issue?
I discovered the answer: The new version of Wordpress using version 1.6 of JQuery. In the file events-meta-box.php, change anywhere where it says: <code> .attr('checked') == true </code> to: <code> .prop("checked", true) </code> There should be three locations where you fix it.
"The Events Calendar" Issues in WP 3.2
wordpress
I'm creating a wordpress theme that I aim to sell at some point. Now, I've discovered that some of the wordpress.org plugins would be great for things that I want to do. They already hold much of the functionality I aim to achieve, so I thought of using them directly (they are under GPL I suppose). I would probably need to adjust stuff, but I was wondering. Is there any universal-like way to include wordpress plugins inside my theme and not in the separate plugins folder ? That would be ideal, because I do not really want customers to have to copy to different folders. At first glance of the plugins, it seems not possible, but I suppose it never hurts to ask :)
Let me make a recommendation: do not bundle plugins with your theme! On first glance, yes this is a very easy way to add default functionality with your theme, but there are a slew of reasons not to include the plugins this way: Updates : If the plugin is freely available from WordPress.org already, then so are automatic updates to the plugin. The original author can add features, fix bugs, and deploy them quickly. Your clients and customers then benefit from on-going development. If you were to package them in your theme, though, you are essentially freezing the code at that point in time - any further updates, bug fixes, etc. would have to come from you . This means you'll need to continuously release theme updates whenever the included plugins update. Updates : When WordPress updates, some plugins will break. This is because the original authors didn't take the time to remove deprecated functionality or test with new versions of WP. Do you really want to commit to maintaining your theme + someone else's code? Interoperability : As the great stackexchange-url ("mfields") once said, "If you're building a bathroom and you change the wallpaper, the toilet shouldn't disappear, too." Users should be able to swap out themes whenever they want without losing their content, their custom data, or the additional functionality they have on their site. Remember, themes are meant for presentation , plugins are meant for functionality. There have been plenty of other people who've talked stackexchange-url ("about this in the past"). The better way to do this would be to have your theme check for specific plugins and prompt the user for installation if they're missing.
Add Plugins to Wordpress Theme
wordpress
I have defined a walker in function.php to display comments in a certain way. I use the following code: <code> function speld_comment($comment, $args, $depth) { $GLOBALS['comment'] = $comment; ?&gt; &lt;?php global $comment_count; $comment_count++; ?&gt; &lt;!-- &lt;?php echo $comment_count; ?&gt; --&gt; &lt;li &lt;?php comment_class(); ?&gt; id="li-comment-&lt;?php comment_ID() ?&gt;"&gt; &lt;div id="comment-&lt;?php comment_ID(); ?&gt;"&gt; &lt;div class="comment-author_pic"&gt; &lt;?php echo get_avatar($comment,$size='48',$default='http://www.speld.nl/wp-content/themes/speld5/images/avatar.png' ); ?&gt; &lt;p class="comment_number"&gt;&lt;?php echo $comment_count; ?&gt;&lt;/p&gt; &lt;/div&gt; &lt;div class="comment_text"&gt; &lt;?php if ($comment-&gt;comment_approved == '0') : ?&gt; &lt;em&gt;&lt;?php _e('Een moment geduld, uw reactie wordt beoordeeld door de Speld Waarheidscommissie.') ?&gt;&lt;/em&gt; &lt;?php endif; ?&gt; &lt;div class="comment-meta commentmetadata"&gt; &lt;?php printf(__('%s'), get_comment_author_link()) ?&gt; &amp;bull; &lt;a href="&lt;?php echo htmlspecialchars( get_comment_link( $comment-&gt;comment_ID ) ) ?&gt;"&gt;&lt;?php printf(__('%1$s, %2$s'), get_comment_date(), get_comment_time()) ?&gt;&lt;/a&gt; &lt;?php // we want to add 'Zie profiel' here.. comment_author_link() ?&gt; &lt;/div&gt; &lt;?php comment_text() ?&gt; &lt;div class="comment_tools"&gt; &lt;?php comment_reply_link(array_merge( $args, array('depth' =&gt; $depth, 'reply_text'=&gt;'Reageer', 'max_depth' =&gt; $args['max_depth']))) ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code> I've also enabled reacting to a comment (1 level deep). The problem is in the comment_count variable. Whenever somebody replies to a comment, the numbering for all comments below the reply shifts one number down. I'd like to prevent that from happening. Is it possible to make an if statement in the walker that allows reactions to a comment to not contain the comment_count variable? Any help would be greatly appreciated!
Just use the $depth arg: <code> if ( $depth ) { // it's a child comment } else { // it's a parent comment } </code>
Displaying comments with a walker: how to distinguish between parent and child comments
wordpress
I want to generate slug for some strings without going through WordPress slug generation flow. Therefore, I want to know which functions it calls to get a neat slug. I tried sanitize_title() but it leaves %c2 %a0 in result.
You are almost there. The function you need is sanitize_title_with_dashes( $title )
Is sanitize_title enough to generate post slugs?
wordpress
I know that Google +1 is quite new (at time of writing), but I wondered if there were any plugins that support these. By "Social Interaction tracking on Google Analytics" I mean - that use this code - http://code.google.com/apis/analytics/docs/tracking/gaTrackingSocial.html?utm_source=helpCenter&amp;utm_medium=helpCenter&amp;utm_campaign=social&amp;utm_content=socialPluginTracking The alternative is to find a plugin that supports the first two and add my own analytics, but I wondered if someone had done it already.
In the end I went with the plugin from addthis.com which can be customised to work with +1.
Are there any plugins yet that support Facebook Like, Google +1 and allow Social Interaction tracking on Google Analytics
wordpress
I got a set of meta boxes containing different form fields. All of them are build inside a set of classes. Now I have the problem that I have to hook the construction of the fields early enough to hook the needed scripts &amp; styles. Everything is fine - I can display them, styles &amp; scripts appear &amp; work, saving the data works - but I can't retrieve the post meta data to fill the values of the fields. Point is that the fields get hooked at <code> admin_menu </code> , which is too early to get the <code> $post_id </code> . Now I saw that I could also use <code> $_GET['post'] </code> to retrieve the ID. What speaks against this?
Once you're in the function that actually prints the html for the metabox, the global $post object should always be set the to current post. Is there a specific reason that you need to know the post_id during init?
$_GET & $post_ID
wordpress
Currently, to call comments I am simply using: <code> &lt;?php wp_list_comments(); ?&gt; </code> in comments.php. This is calling up gravatars, which I would like to be able to set the size of. How can I set the size of gravatars in my comments.
Quite simple, actually: <code> wp_list_comments( 'avatar_size=80' ); </code> Just change <code> avatar_size=80 </code> to whatever is appropriate. Here's a bit more information on customizing Gravatars in WordPress .
Gravatar Size Via Theme Functions?
wordpress
I am using the Yoko theme and would like to show the most recent full post in category 1 on the home page. I am a Wordpress newbie, but my approach was going to be to provide my own index.php in a child theme. The parent theme has relevant code that looks like this: <code> &lt;?php /* Start the Loop */ ?&gt; &lt;?php while ( have_posts() ) : the_post(); ?&gt; &lt;?php get_template_part( 'content', get_post_format() ); ?&gt; &lt;?php endwhile; ?&gt; &lt;?php /* Display navigation to next/previous pages when applicable */ ?&gt; </code> I had thought I needed to place a line like this prior to the while loop: <code> &lt;?php query_posts('cat=1&amp;posts_per_page=1'); ?&gt; </code> However, I see the partial post only. I have also tried to do the same sort of thing with single.php. I am sure I am missing something simple. Can someone school me on the loop?
You can alter query_posts - see http://codex.wordpress.org/The_Loop - but maybe the best thing to do is use a page template with a new query. WP will default to home.php instead of index.php if one exists, so you can leave index.php alone for other page to use. See http://codex.wordpress.org/Class_Reference/WP_Query Sample query; remove the permalink and/or title, if needed: <code> &lt;?php $my_query = new WP_Query('cat=1&amp;showposts=1'); ?&gt; &lt;?php while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt; &lt;a href="&lt;?php the_permalink() ?&gt;" title="&lt;?php the_title(); ?&gt;"&gt; &lt;?php the_title(); ?&gt;&lt;/a&gt; &lt;?php the_content(); ?&gt; &lt;?php endwhile; ?&gt; </code>
How to show full post on home page
wordpress
Is there a way to use WordPress Multisite to collaborate all subsites into the main site? My thought is to have all the subsites to be departments of an organization and the main site be the front page for the organization. Navigation would be created automagically: one for the main site, then a separate navigation that would list the departments (subsites) with drop downs for the pages of those sites. I'm sure this could all be scripted to work, but I'm curious if there's a solution already out there to roll with right out of the box.
It's definitely possible. And there are a few plugins to help make it easier Diamon Multisite Widgets Bloglist, recent posts and comments from the whole network. Wordpress MU Sitewide Tags A central area where all the posts on a WordPress MU or WordPress MS site can be collected. This plugin creates a new blog on your server for all the posts on your site, much like http://wordpress.com/tags/
Different use for WordPress Multisite
wordpress
I am involved with several WordPress support websites including this one (recently). I seem to get the question "Can WordPress be used as a CMS/Membership Website?". I haven't needed to set one up, so I always refer them to suggestion from other forums. I've decided that it's only a matter of time until I will be required to implement this type of a WP website so I've decided to be Pro-Active and set up a development version. I've been looking at Magic Members specifically, but I don't know anyone that has used it. My question has two parts: 1) Does anyone have first hand experience using Magic Members. If so is it worth the $197. 2) Do you have any recommendations an an alternative? NOTE: I've tried out many of the plug-ins from the repository, but for a business I haven't found one that fits all the requirements. Here is a list of the features that are most likely needed: Membership access control on various levels Public and Private content Simplified User Interface (this isn't as important since I know a few tricks including ones I've discovered here. Document sharing Content Available to Author created content that can only be changed/updated by them and the Administrator. I know this is a pretty in depth questions, but any pointers or personal experience will be greatly appreciated. Thanks, Jeremy Jared
You could use a combination of the Members plugin to manage user roles (ie employee types or levels) along with the Custom Post Type UI plugin to manage various post types. With the Custom Post Type UI you could create posts types. Then you could allow or deny rights for various operations on each type of post separately (edit, publish, edit after publish, delete, submit for publish by an admin, view, edit other's posts) for each employee type role. You could create posts that an employee of type 1 could publish and be viewable only by other type 1 employees. Along side those, there could be some other post that employee type 1's could read but not publish too. And still another post type that could be viewable by the public. Etc, etc, etc... The combo of these two plugins would give you very granular control over what different types of employees would be able to do. Check out this simple example of restricting rights on one custom post type .
WordPress as a CMS Membership website
wordpress
I have a custom meta box that is supposed to accept HTML, but the text I'm trying to input contains both double and single quotes (and ampersands), and it's messing up the saved data - each time I reload the post, the data is duplicated with an extra single quote (and angle bracket) inserted at the end. I'm guessing its trying to "close" what it thinks is an unclosed phrase in single quotes, when really its an apostrophe. I can temporarily fix this right now by using the html character code for my apostrophe, but (a) that is not ultimately a solution as I can't control what other users might enter once the theme is rolled out, and (b) once the page reloads, the html character has been replaced by an apostrophe again, which means if I save any further changes, I'm back at square one. So, how do I "escape" html content in a metabox without stripping the html tags? Is there a special wordpress function/hook/action/etc or a special metabox format I should be using, or should I just be looking this up in the PHP manual instead? PS: It also "strips out" any html characters like <code> &amp;amp; </code> , so the post won't validate properly because there are now plain <code> &amp; </code> in the text. UPDATE: So who knew single vs double quotes made any difference in simple php? I managed to fix the weird duplication and "correction" of apostrophe by swapping out my quotes in my code. My original code was this: <code> echo "&lt;textarea class='meta-textarea' style='width: 100%;' cols='20' rows='2' name='" . $meta_box['name'] . "_value' value='" . $meta_box_value . "'&gt;" . $meta_box_value . "&lt;/textarea&gt;&lt;br /&gt;"; </code> If I save the following phrase: <code> &lt;p&gt;Blah &amp;amp; blah 'blah'&lt;/p&gt; </code> into the resulting text box, it would return <code> '&gt;&lt;p&gt;Blah &amp; blah 'blah'&lt;/p&gt; </code> . If I just swap out the single and double quotes in my code, like so: <code> echo '&lt;textarea class="meta-textarea" style="width: 100%;" cols="20" rows="2" name="' . $meta_box['name'] . '_value" value="' . $meta_box_value . '"&gt;' . $meta_box_value . '&lt;/textarea&gt;&lt;br /&gt;'; </code> then it works just fine (apart from the html-entity thing, which is still a problem). Those two lines of code together, so you can see I haven't left out any quotes (top one works, bottom doesn't): <code> echo '&lt;textarea class="meta-textarea" style="width: 100%;" cols="20" rows="2" name="' . $meta_box['name'] . '_value" value="' . $meta_box_value . '"&gt;' . $meta_box_value . '&lt;/textarea&gt;&lt;br /&gt;'; echo "&lt;textarea class='meta-textarea' style='width: 100%;' cols='20' rows='2' name='" . $meta_box['name'] . "_value' value='" . $meta_box_value . "'&gt;" . $meta_box_value . "&lt;/textarea&gt;&lt;br /&gt;"; </code> So, now, the question of weird duplication has been fixed (although I don't understand why - I thought single and double quotes were interchangeable if you weren't doing any odd substitution, etc. The remaining question is - how do I stop the text from getting <code> htmlspecialchars_decode </code> applied, or whatever is happening here...
If I'm allowed to answer my own question here: I found a way to stop the conversion of my html entities back to characters by using <code> &lt;?php esc_textarea( $text ) ?&gt; </code> , as detailed by the codex here: http://codex.wordpress.org/Function_Reference/esc_textarea . Not sure if this is the right way of doing it, but its working. My (snipped) metabox code now looks like so: <code> &lt;?php if ( $meta_box['type'] == "textarea" ) { $meta_box_value = esc_textarea( get_post_meta($post-&gt;ID, $meta_box['name'].'_value', true) ); echo '&lt;textarea class="meta-textarea" style="width: 100%;" cols="20" rows="2" name="' . $meta_box['name'] . '_value"&gt;' . $meta_box_value . '&lt;/textarea&gt;&lt;br /&gt;'; } ?&gt; </code> This, combined with the single/double quote thing above, works fine now.
How do I stop HTML entities in a custom meta box from being un-htmlentitied?
wordpress
How do I change my index.php to display only the desired categories posts in the main page ? I tought that changing this would workout but instead it just print nothing: <code> query_posts( array( 'post_type' =&gt; array( 'post', $include_reviews, $include_screenshots, $include_videos ), 'paged' =&gt; $paged ) ); </code> Change from <code> 'post', </code> to <code> 'cat=10', </code> not very sure how to do this. This is my index.php file: <code> &lt;?php get_header(); ?&gt; &lt;?php $slider_number = get_option('lp_slides_number'); $args = array( 'post_type' =&gt; 'slider', 'showposts' =&gt; $slider_number ); $slider_loop = new WP_Query( $args ); if ($slider_loop-&gt;have_posts()) : ?&gt; &lt;!-- BEGIN SLIDER --&gt; &lt;div class="slider"&gt; &lt;div class="sliderContent"&gt; &lt;?php while ( $slider_loop-&gt;have_posts() ) : $slider_loop-&gt;the_post(); $src = wp_get_attachment_image_src( get_post_thumbnail_id($post-&gt;ID), false, '' ); ?&gt; &lt;div class="featured-item" style="background:&lt;?php echo get_post_meta($post-&gt;ID, 'feature_bg', true); ?&gt; url(&lt;?php echo $src[0]; ?&gt;) no-repeat center; height:280px;"&gt; &lt;div class="featured-inner"&gt; &lt;div class="featured-inner"&gt; &lt;div class="featured-arrows"&gt;&lt;/div&gt; &lt;h1&gt;&lt;a href="&lt;?php echo get_post_meta($post-&gt;ID, 'feature_url', true); ?&gt;" rel="bookmark" title="Link Permanente: &lt;?php the_title(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h1&gt; &lt;p class="featured-meta"&gt;Por &lt;?php the_author(); ?&gt;, &lt;?php the_time( get_option('date_format') ); ?&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php endwhile; wp_reset_query(); ?&gt; &lt;/div&gt; &lt;div class="top-overlay"&gt;&lt;/div&gt; &lt;div class="bottom-overlay"&gt;&lt;/div&gt; &lt;/div&gt; &lt;!-- END SLIDER --&gt; &lt;?php endif; ?&gt; &lt;!-- BEGIN MAIN WRAPPER --&gt; &lt;div id="main-wrapper"&gt; &lt;!-- BEGIN MAIN --&gt; &lt;div id="main"&gt; &lt;!-- BEGIN NEWS WRAPPER --&gt; &lt;div id="news-wrapper"&gt; &lt;h3 class="section-title"&gt;Last News&lt;/h3&gt; &lt;!-- BEGIN NEWS ITEMS --&gt; &lt;?php if(get_option('lp_include_reviews') == "true") { $include_reviews = "'reviews',"; } if(get_option('lp_include_videos') == "true") { $include_videos = "'videos',"; } if(get_option('lp_include_screenshots') == "true") { $include_screenshots = "'screenshots',"; } query_posts( array( 'post_type' =&gt; array( 'post', $include_reviews, $include_screenshots, $include_videos ), 'paged' =&gt; $paged ) ); ?&gt; &lt;?php if (have_posts()) : ?&gt; &lt;?php while (have_posts()) : the_post(); ?&gt; &lt;?php if ( get_post_type() == 'reviews' ) : ?&gt; &lt;?php include( TEMPLATEPATH . '/includes/show-reviews-frontpage.php' ); ?&gt; &lt;?php elseif ( get_post_type() == 'videos' ) : ?&gt; &lt;?php include( TEMPLATEPATH . '/includes/show-videos-frontpage.php' ); ?&gt; &lt;?php elseif ( get_post_type() == 'screenshots' ) : ?&gt; &lt;?php include( TEMPLATEPATH . '/includes/show-screenshots-frontpage.php' ); ?&gt; &lt;?php else: ?&gt; &lt;?php include( TEMPLATEPATH . '/includes/show-posts.php' ); ?&gt; &lt;?php endif; ?&gt; &lt;?php endwhile; ?&gt; &lt;?php kriesi_pagination(); ?&gt; &lt;?php wp_reset_query(); ?&gt; &lt;?php endif; ?&gt; &lt;!-- END NEWS ITEMS --&gt; &lt;/div&gt; &lt;!-- END NEWS WRAPPER --&gt; &lt;/div&gt; &lt;!-- END MAIN --&gt; &lt;?php get_sidebar(); ?&gt; &lt;?php get_footer(); ?&gt; </code>
Your syntax is wrong, change: <code> query_posts( array( 'post_type' =&gt; array( 'post', $include_reviews, $include_screenshots, $include_videos ), 'paged' =&gt; $paged ) ); </code> to: <code> query_posts( array( 'tax_query' =&gt; array( array( 'taxonomy' =&gt; 'category', 'field' =&gt; 'slug', 'terms' =&gt; array( $include_reviews, $include_screenshots, $include_videos ) )), 'paged' =&gt; $paged, 'post_type' =&gt; 'post') ); </code>
Change from all posts to specific categories post on main page?
wordpress
I'm using this class http://www.deluxeblogtips.com/p/meta-box-script-for-wordpress.html to create custom meta-box in which it contains some WYSIWYG editors. It works fine until I upgraded my WP to 3.2. The WYSIWYG editors are now have white text background and all tinyMCE buttons are gone! I guess they've changed quite a lot of things in TinyMCE editor in this 3.2 version to accommodate the "full screen editing" stuff. Bad for me though, it destroys my custom metabox... And there is no documents about this change, at all
as per here , add this to your functions.php <code> add_action("admin_head","myplugin_load_tiny_mce"); function myplugin_load_tiny_mce() { wp_tiny_mce( false ); // true gives you a stripped down version of the editor } </code>
WordPress 3.2 - Problem with WYSIWYG editors in a custom post type?
wordpress
Is it possible to add a link category on plugin activation? What I mean is the Links section, as you know by default it has the Blogroll link category. I want to add a new link category when my plugin is activated, is there a quick and easy way to do this? What is the best method to use? Thanks.
Link category is a simple taxonomy just like categories , named: <code> link_category </code> so to add one you can use <code> wp_insert_term() </code> eg: <code> wp_insert_term( 'My link category', // the term 'link_category', // the taxonomy array( 'description'=&gt; 'this is a description.', 'slug' =&gt; 'my-link-category' ) ); </code> and to make all this happen on plugin activation take a look at <code> register_activation_hook </code>
Add Link Category on Activation?
wordpress
I am using twenty-eleven theme for my site, I just saw that in single posts page, .i.e single.php, the sidebar is absent, which means no widgets in single.php page How do I bring it back
Write before <code> &lt;?php get_footer(); ?&gt; </code> <code> &lt;?php get_sidebar(); ?&gt; </code> or <code> &lt;?php get_sidebar( $your_custom_sidebar ); ?&gt; </code>
twenty eleven single.php
wordpress
I'm creating a custom taxonomy whose terms must remain fixed by all users. Once I've set up the starting set of terms, I want them to be immutable. I also don't want to clutter up the Admin UI with additional links and metaboxes where they're not needed. However, setting <code> public =&gt; 'false' </code> , or <code> show_ui =&gt; 'false' </code> not only hides the manage tax link, but also prevents the user from assigning the term to a new post. I need a way to hide the "manage" link within the post type pulldown, show the term selector metabox on the post page, but (hopefully) disable the "Add Term" option at the bottom of this metabox. Does such a feature exist? Or are taxonomies always supposed to be user editable? Custom taxonomy capabilities get me most of the way there, since you can independently set CRUD rights based on capability. But how to disable even admins from modification? (I know this sounds like a bad idea but it's viable.)
You talking categories (hierarchical) or tags? You just need a hidden taxonomy + custom widget. If it's categories, it easier to do, if tags... depends if the number of items is decent. And you can hide them from public view only for non-Administrators. That way you can manage them easily while the others can't touch them. Thanks.
Read-only taxonomy (user can assign term but can't create or edit existing terms)
wordpress
In the <code> functions.php </code> of my plugin I've added the following code: <code> function relativePathForUploads( $fileinfo ) { global $blog_id; $path = get_blog_option($blog_id,'siteurl'); $fileinfo['url'] = str_replace($path,'',$fileinfo['url']); return $fileinfo; } add_filter('wp_handle_upload', 'relativePathForUploads'); </code> But in the error log I get the following message: <code> PHP Fatal error: Call to undefined function get_blog_option() </code> Do I need to include something before I'm able to call <code> get_blog_option </code> ? If so, what?
I think that function is only available in multi-user mode. Try: <code> if(is_multisite()){ $path = get_blog_option($blog_id,'siteurl'); }else{ $path = get_option('siteurl');` } </code>
Call to undefined function get_blog_option()
wordpress
I would like to accomplish something like this: <code> &lt;?php $custom_posts = new WP_Query(); ?&gt; &lt;?php $custom_posts-&gt;query('category_name=Business OR category_name=Technology OR category_name= Lifestyle'); ?&gt; &lt;?php while ($custom_posts-&gt;have_posts()) : $custom_posts-&gt;the_post(); ?&gt; &lt;div class="content-block-14"&gt; &lt;h2&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?&gt;" rel="bookmark"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt; &lt;?php the_content(); ?&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; </code> So that if the post belongs to only one of those categories it should be listed in that loop. Any suggestions?
If you have the category ID you can use the <code> category__in </code> parameter eg: <code> &lt;?php $custom_posts-&gt;query(array('category__in' =&gt;array(1,2,3))); ?&gt; </code>
How to add an "or" instead of and "and" (&) in a Wordpress query?
wordpress
There are different PHP logging frameworks out there e.g. Log4php, KLogger. I want to choose one based on its experience with WordPress. Please suggest me one.
I would suggest to go with KLogger more specifically a fork of it which is simple and clean, and i have a few sites logging using this simple class with no problems or complains.
PHP logging framework to be used with WordPress
wordpress
I am using the brand new twenty eleven theme, my home page is set to show latest posts, but it displays the entire posts, I want to only show the excerpts, not the entire content, Here is the index.php code <code> &lt;div id="content" role="main"&gt; &lt;?php if ( have_posts() ) : ?&gt; &lt;?php twentyeleven_content_nav( 'nav-above' ); ?&gt; &lt;?php /* Start the Loop */ ?&gt; &lt;?php while ( have_posts() ) : the_post(); ?&gt; &lt;?php get_template_part( 'content', get_post_format() ); ?&gt; &lt;?php endwhile; ?&gt; &lt;?php twentyeleven_content_nav( 'nav-below' ); ?&gt; &lt;?php else : ?&gt; &lt;article id="post-0" class="post no-results not-found"&gt; &lt;header class="entry-header"&gt; &lt;h1 class="entry-title"&gt;&lt;?php _e( 'Nothing Found', 'twentyeleven' ); ?&gt;&lt;/h1&gt; &lt;/header&gt;&lt;!-- .entry-header --&gt; &lt;div class="entry-content"&gt; &lt;p&gt;&lt;?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?&gt;&lt;/p&gt; &lt;?php get_search_form(); ?&gt; &lt;/div&gt;&lt;!-- .entry-content --&gt; &lt;/article&gt;&lt;!-- #post-0 --&gt; &lt;?php endif; ?&gt; &lt;/div&gt; </code>
The template you're actually after is "content.php" You'll want to change this line: <code> &lt;?php if ( is_search() ) : // Only display Excerpts for Search ?&gt; &lt;div class="entry-summary"&gt; &lt;?php the_excerpt(); ?&gt; &lt;/div&gt;&lt;!-- .entry-summary --&gt; &lt;?php else : ?&gt; &lt;div class="entry-content"&gt; &lt;?php the_content( __( 'Continue reading &lt;span class="meta-nav"&gt;&amp;rarr;&lt;/span&gt;', 'twentyeleven' ) ); ?&gt; &lt;?php wp_link_pages( array( 'before' =&gt; '&lt;div class="page-link"&gt;&lt;span&gt;' . __( 'Pages:', 'twentyeleven' ) . '&lt;/span&gt;', 'after' =&gt; '&lt;/div&gt;' ) ); ?&gt; &lt;/div&gt;&lt;!-- .entry-content --&gt; &lt;?php endif; ?&gt; </code> To this: <code> &lt;?php if ( is_search() ) : // Only display Excerpts for Search ?&gt; &lt;div class="entry-summary"&gt; &lt;?php the_excerpt(); ?&gt; &lt;/div&gt;&lt;!-- .entry-summary --&gt; &lt;?php else : ?&gt; &lt;div class="entry-content"&gt; &lt;?php the_excerpt(); ?&gt; &lt;?php wp_link_pages( array( 'before' =&gt; '&lt;div class="page-link"&gt;&lt;span&gt;' . __( 'Pages:', 'twentyeleven' ) . '&lt;/span&gt;', 'after' =&gt; '&lt;/div&gt;' ) ); ?&gt; &lt;/div&gt;&lt;!-- .entry-content --&gt; &lt;?php endif; ?&gt; </code> Note the change of <code> the_content() </code> to <code> the_excerpt() </code>
Twenty Eleven home page show only excerpt
wordpress
My question pertains to where I should create an ajax function that I'd like to call from my page view. I am using a jQuery validator on a custom form that should check the inputted zipcode against my database of valid zipcodes. I just need to know where this function should exist. Normally when using a non wordpress site I'd create a PHP file with my ajax functions and call them by referencing the URL to this page and passing some parameters. How can I achieve this with wordpress? Where can i explicitly call a php file and pass it arguments? Note: I'd like to call the ajax function like so: <code> $.post('http://mysite.com/ajax-functions.php?fxn=zipcodes', {zipCode:00000}, function(response){ // do stuff }); </code> Thanks
In WordPress the way of handling Ajax calls is a bit different the plain PHP but still very simple, all ajax calls should be to <code> wp-admin/admin-ajax.php </code> and you just define your own functions by hooks, Take a look at What's the preferred method of writing AJAX in WordPress
Creating custom AJAX requests
wordpress
I'm getting this when saving a post after editing: <code> Forbidden You don't have permission to access /wp-admin/post.php on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. </code> All file permissions are 644 and directory permission are 755 and owner is myftpuser:myftpuser (this is my FTP user login). I've tried changing all permission to 755 but didn't work. Has anyone had this issue, is there a solution?
Sometimes hosting providers will implement mod_security (and not mention anything). Or else, mod_security was already on but a recent installation of a plugin or theme may have exposed this new problem for you. You can try these four things... Add the following to your .htaccess file (add to .htaccess, don't replace the other stuff already in it) <code> &lt;IfModule mod_security.c&gt; SecFilterEngine Off SecFilterScanPOST Off &lt;/IfModule&gt; </code> chmod all your folders (including plugin and theme folders) to 777 temporarily just to confirm that it's really not a permissions issue with file owner permissions. If it is, then you can go from there (maybe your site isn't really running as 'myftpuser'. Deactivate your plugins, one by one, testing your post after deactivating each one. (See if a plugin is causing this). Does the content you're testing have the word "from" in it? If so, can you post without using that word as a test?
permissions access error
wordpress
I'm starting a website (more complicated than a blog) and would appreciate advice on which framework to use. A person on my team uses wordpress and is enthusiastic about its possibilities, but a friend who works on rails is lobbying against it ("But it's for blogs!"). Both can help me get started so I'll probably chose either wordpress or rails because of that. The question is : which? What I want to do : The site is centered around comparing and commenting constitution articles. Users will browse articles by country and by topic, comment and vote on the articles, suggest topics for the articles (=tag them), post their suggestions of articles. Users will create polls (like Facebook questions more or less) that other users can answer. I'd also like a forum section where they can start discussions about a given article or a topic. Users will also post links/documents relevant to an article or topic. I want my users to be registered, give me certain info (gender, age, country…) and then get statistics about who voted/commented on what articles (It will be helpful for research). Wordpress looks cool because of how easy it looks to get something together and integrate plugins, even for a non-technical person, and there's a huge number of plugins. But it's designed for blogs so I'll probably run into trouble and do dirty hacks because what I want to do is not a blog. Rails looks cool because it's designed to do things like that so I can get precisely what I want, but there aren't as many plugins, and it will require longer to code. I'll be spending the next 2 months on this, and when I leave the the person who has to take care of the site has little technical background (except wordpress), and I don't want to have to do heavy maintenance after I leave. I'm not scared of learning, but I do have limited time and I'm the only developer (though I might get help from volunteers.). I might not get all the functionality I want before I leave, but I do need to get something together. What is your opinion here? Thanks for your help!
Your friend is a diva. WordPress started as a blog platform, but now it has grown beyond that and is encroaching on becoming a mid-tier content management system out of the box. If you like it and it is easy for you, use it. It seems to match up with what you are trying to do. Articles are essentially blog posts anyway. You wouldn't clean your dishes with an orbital buffer. Use what makes sense.
Can I use wordpress for a non-blog site?
wordpress
I'm trying to decontruct (and recreate) a serialized option value in wp_options called 'my_options' How would I build the array to recreate this option_value that currently exists for 'my_options'? update_option('my_options', ?) After the update, the wp-options table would hold this value for 'my_options': <code> a:3:{s:12:"my_widget-1";a:2:{ etc... </code>
You can't use it as-is because it will get double-serialized. So as per comment you unserialize it first and it will get serialized back when saved into option. <code> $array = unserialize( $stuff ); update_option('my_options', $array); </code>
Decontruct serialized data array from wp_options
wordpress
How can i get a page ID from the Admin backend? I'm saving data into a metabox on a 'Page' post type, and I need to return that data on the page in another area. But $post-> ID obviously dose not work... What will work? Thanks
This is what I needed <code> $_REQUEST['post'] </code>
Get Page ID from Backend
wordpress
My theme has a custom.css file that I use to allow designer's to customize the it to their liking. However, when clicking on "Appearance > Editor", the style.css file is loaded there by default. Since I don't want custom edits done on this file, I'd like to minimize the chances that someone edits it by placing custom.css there instead. Is this possible? Perhaps with the shiny new 3.2 codebase?
Unfortunately you can't control what files are loaded on that page... But you can disable the editor page and provide the user with theme options that allow him to include his own CSS. To deal with this I'm creating and activating a child theme automatically if possible: <code> if(!is_child_theme()){ require_once(ABSPATH.'wp-admin/includes/file.php'); if(!WP_Filesystem()){ // fail, proably no write-access, use the parent theme... }else{ $parent = get_theme_data(TEMPLATEPATH.'/style.css'); $name = get_stylesheet().'-extend'; $destination = trailingslashit($GLOBALS['wp_filesystem']-&gt;wp_themes_dir()).$name; $style = "/*\n" ."Theme Name: {$parent['Name']} - Extend\n" ."Theme URI: {$parent['URI']}\n" ."Description: Automatically generated child theme of {$parent['Name']}. Please leave this one activated for proper customizations to {$parent['Name']}.\n" ."Version: 1.0\n" ."Author: {$parent['Author']}\n" ."Author URI: {$parent['AuthorURI']}\n" ."Template: ".get_template()."\n" ."*/\n\n" ."/* You can safely edit this file, but keep the Template tag above unchanged! */\n"; if(!$GLOBALS['wp_filesystem']-&gt;is_dir($destination)) if($GLOBALS['wp_filesystem']-&gt;mkdir($destination, FS_CHMOD_DIR) &amp;&amp; $GLOBALS['wp_filesystem']-&gt;put_contents($destination.'/style.css', $style, FS_CHMOD_FILE)){ // copy screenshot and license.txt $GLOBALS['wp_filesystem']-&gt;copy(TEMPLATEPATH.'/screenshot.png', $destination.'/screenshot.png'); $GLOBALS['wp_filesystem']-&gt;copy(TEMPLATEPATH.'/license.txt', $destination.'/license.txt'); switch_theme(get_template(), $name); wp_redirect(admin_url("themes.php")); die(); // stop execution of the current page }else{ // fail again... } } } </code>
How to assign the default file at "Appearance > Editor"?
wordpress
Haven't worked much with XML so I'm hitting a bit of a wall: <code> function getapi() { $api_response = wp_remote_get( "http://example.com/getXML" ); $data = wp_remote_retrieve_body( $api_response ); $output = new SimpleXMLElement ($data ); return $output; } </code> Get or set the Transient <code> function transient() { $transient = get_transient( 'transient_value' ); if ( ! $transient ) { $transient = getapi(); set_transient( 'transient_value', $transient, 180 ); } return $transient; } </code> I can easily show the data, but calling it up from a stored transient results in this error being shown: <code> Node no longer exists in C:\xampplite\htdocs\... </code> Not sure what the extra step is that I need to perform in order to store the data correctly. Many thanks! Noel
According to this ticket: Cannot serialize object wrapping 3rd party library structs. Must serialize the xml (to a string) and store that to session and reload the xml when restoring from session When you are storing object in transient it gets serialized and not all objects are capable of that correctly. Store textual XML data in transient instead.
Storing an XML Response (Transient)?
wordpress
What is the best way to filter the posts being displayed? For example in my functions.php file I want to have something like <code> add_filter( $tag, 'filter_posts'); function filter_posts(){ if(is_home()){ //return custom post query that will be used in loop } } </code>
Actually, you're going about this the wrong way. Don't filter the posts in <code> functions.php </code> , instead, define custom loops and include them when needed . In a simplified example, let's say your theme only has <code> header.php </code> , <code> footer.php </code> , <code> sidebar.php </code> , and <code> index.php </code> for the structural files. Your <code> index.php </code> would look something like: <code> &lt;?php get_header(); ?&gt; &lt;div id="content"&gt; &lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt; &lt;h2&gt;&lt;?php the_title();?&gt;&lt;/h2&gt; &lt;div id="main"&gt; &lt;?php the_content(); ?&gt; &lt;/div&gt; &lt;?php endwhile; else: ?&gt; &lt;p&gt;&lt;?php _e('Sorry, no posts matched your criteria.'); ?&gt;&lt;/p&gt; &lt;?php endif; ?&gt; &lt;/div&gt; &lt;?php get_sidebar(); ?&gt; &lt;?php get_footer(); ?&gt; </code> Pretty simple. You have a header, a sidebar, and a footer in external files and the main page content defined in the main file. But you can add some logic here and, rather than include a generic loop each time, you can have a custom loop for everything. So instead, your <code> index.php </code> would look like: <code> &lt;?php get_header(); ?&gt; &lt;div id="content"&gt; &lt;?php if( is_home() ) { get_template_part( 'loop', 'home' ); } else if ( is_single() ) { get_template_part( 'loop', 'single' ); } else { get_template_part( 'loop' ); } ?&gt; &lt;/div&gt; &lt;?php get_sidebar(); ?&gt; &lt;?php get_footer(); ?&gt; </code> Then you define your custom loops in <code> loop-home.php </code> , <code> loop-single.php </code> , and <code> loop.php </code> . These custom loop pages can define any custom query you can think of.
Filter have_posts()/ the_post()
wordpress
I've just upgraded from 3.1.2 to 3.2, and now "featured image" is no longer listed at the bottom right of a post in admin. Has this feature of WP been removed? Can it be added back, or turned back on? My old posts still have their old featured image, but it cannot be added to new ones.
I had to restart my browser, and after logging back into admin featured image has reappeared. I made no changes to settings.
Featured Image missing in Wordpress 3.2 Admin
wordpress
I'm implementing a site that allows users to switch stylesheets (to show a high contrast version for people with vision impairments). The switcher essentially just changes the <code> &lt;link&gt; </code> ref to whichever stylesheet is appropriate. However, I've just realised that this will lead to problems when I switch on caching (either using WP Supercache or W3 Total Cache) - as only one version of the page will be cached and thus displayed to the user. Any thoughts on possible solutions?
Turns out the answer is fairly simple (at least for WP Supercache). Use either PHP or legacy caching (ie not mod_rewrite) Turn on late init (either from the UI - recommended, or by setting <code> $wp_super_cache_late_init = 1; </code> in <code> wp-content/wp-cache-config.php </code> Use the <code> &lt;!--dynamic-cached-content--&gt; </code> directive to wrap the content that should remain dynamic. An example: <code> &lt;!--dynamic-cached-content--&gt;&lt;?php display_high_contrast_link(); ?&gt;&lt;!-- display_high_contrast_link(); --&gt;&lt;!--/dynamic-cached-content--&gt; </code> As you can see, the dynamic content has been added twice - from the WP Supercache FAQ The first code is executed when the page is cached, while the second chunk of code is executed when the cached page is served to the next visitor.
Stylesheet switching and caching
wordpress
writingyourwaytosuccess.com/blog Attempting to view a single post returns the following error: <code> Fatal error: Call to undefined function atmosphere_posted_on() in /home/content/46/7460046/html/wp-content/themes/atmosphere-2010/single.php on line 17 </code> Thanks!
Looks like you are using this theme: Atmosphere 2010 Looking through the theme files the function <code> atmosphere_posted_on </code> is used a couple times in loop.php and single.php. The <code> undefined function </code> error indicates that the function does not exist which leads me to believe that your functions.php has been modified or is otherwise missing this function. In the version I downloaded, the function looks like this in functions.php starting at line 281: <code> if ( ! function_exists( 'atmosphere_posted_on' ) ) : function atmosphere_posted_on() { printf( __( '&lt;span class="%1$s"&gt;Posted on&lt;/span&gt; %2$s &lt;span class="meta-sep"&gt;by&lt;/span&gt; %3$s', 'atmosphere' ), 'meta-prep meta-prep-author',sprintf( '&lt;a href="%1$s" title="%2$s" rel="bookmark"&gt;&lt;span class="entry-date"&gt;%3$s&lt;/span&gt;&lt;/a&gt;', get_permalink(),esc_attr( get_the_time() ), get_the_date()), sprintf( '&lt;span class="author vcard"&gt;&lt;a class="url fn n" href="%1$s" title="%2$s"&gt;%3$s&lt;/a&gt;&lt;/span&gt;', get_author_posts_url( get_the_author_meta( 'ID' ) ), sprintf( esc_attr__( 'View all posts by %s', 'atmosphere' ), get_the_author() ), get_the_author())); } endif; </code> You might try uploading a new version of functions.php or see if your modified version still contains this function.
single.php error
wordpress
I'm getting a problem displaying tweets that include reply's (ie when you @username someone). It's showing the @ symbol but then cutting off the rest of the tweet. (Check out www.teamworksdesign.com in the bottom right hand corner) Can anyone help with this or suggest a good plugin? <code> &lt;?php function parseTweet($text) { $pattern_url = '~(?&gt;[a-z+]{2,}://|www\.)(?:[a-z0-9]+(?:\.[a-z0-9]+)?@)?(?:(?:[a-z](?:[a-z0-9]|(?&lt;!-)-)*[a-z0-9])(?:\.[a-z](?:[a-z0-9]|(?&lt;!-)-)*[a-z0-9])+|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?:/[^\\/:?*"|\n]*[a-z0-9])*/?(?:\?[a-z0-9_.%]+(?:=[a-z0-9_.%:/+-]*)?(?:&amp;[a-z0-9_.%]+(?:=[a-z0-9_.%:/+-]*)?)*)?(?:#[a-z0-9_%.]+)?~i'; '@([A-Za-z0-9_]+)'; $tweet = preg_replace('/(^|\s)#(\w+)/', '\1#&lt;a href="http://search.twitter.com/search?q=%23\2″ rel="nofollow"&gt;\2&lt;/a&gt;', $text); $tweet = preg_replace('/(^|\s)@(\w+)/', '\1@&lt;a href="http://www.twitter.com/\2″ rel="nofollow"&gt;\2&lt;/a&gt;', $tweet); $tweet = preg_replace("#(^|[\n ])(([\w]+?://[\w\#$%&amp;~.\-;:=,?@\[\]+]*)(/[\w\#$%&amp;~/.\-;:=,?@\[\]+]*)?)#is", "\\1&lt;a href=\"\\2\" title=\"\\2\" rel=\"nofollow\"&gt;[link]&lt;/a&gt;", $tweet); return $tweet; } $username='teamworksdesign'; // set user name $format='json'; // set format $tweet=json_decode(file_get_contents("http://api.twitter.com/1/statuses/user_timeline/{$username}.{$format}")); // get tweets and decode them into a variable $theTweet = parseTweet($tweet[0]-&gt;text); $newTweet = substr($theTweet,0,65); echo '&lt;a class="tweet" rel="nofollow" href="http://www.twitter.com/teamworksdesign"&gt; "' . $newTweet . '..."&lt;/a&gt;'; ?&gt; </code>
Hi Rob@:try with this plugin Tweet This .you can set your custom image also.:) or Try this code... Open the sidebar.php Locate the “twitter-feed” div <code> &lt;div class=”twitter-feed”&gt; &lt;h2&gt;What I’m up to…&lt;/h2&gt; &lt;ul id=”twitter_update_list”&gt;&lt;/ul&gt; &lt;script type=”text/javascript” src=”http://twitter.com/javascripts/blogger.js”&gt;&lt;/script&gt; &lt;script type=”text/javascript” src=”http://twitter.com/statuses/user_timeline/JunLoayza.json?callback=twitterCallback2&amp;amp;count=1″&gt;&lt;/script&gt; &lt;div class=”follow-on-twitter”&gt; &lt;a rel=”nofollow” href=”"&gt;Follow me on Twitter&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; </code> Replace with Twitter username <code> &lt;script type=”text/javascript” src=”http://twitter.com/statuses/user_timeline/AddYourUsernameHere.json?callback=twitterCallback2&amp;amp;count=1″&gt;&lt;/script&gt; </code> Now you will want to add your twitter URL to the “Follow me on Twitter” link. The following code is listed in blue above: <code> &lt;a rel=”nofollow” href=”http://Twitter.com/AddYourUsernameHere“&gt;Follow me on Twitter&lt;/a&gt; </code> The final code <code> &lt;div class=”twitter-feed”&gt; &lt;h2&gt;What I’m up to…&lt;/h2&gt; &lt;ul id=”twitter_update_list”&gt;&lt;/ul&gt; &lt;script type=”text/javascript” src=”http://twitter.com/javascripts/blogger.js”&gt;&lt;/script&gt; &lt;script type=”text/javascript” src=”http://twitter.com/statuses/user_timeline/AddYourUsernameHere.json?callback=twitterCallback2&amp;amp;count=1″&gt;&lt;/script&gt; &lt;div class=”follow-on-twitter”&gt; &lt;a rel=”nofollow” href=”http://Twitter.com/AddYourUsernameHere“&gt;Follow me on Twitter&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; </code> save and run :)
Displaying tweets problem with @username
wordpress
When the user clicks on the vote image, the image changes to the voted state. If the user clicks the image in the voted state again, a message pops up saying: You Had Already Rated This Post. Post ID #X I want it so that this message does not pop up and the 'voted' image stays as is. Below is what I believe to be the relevant code needed to make this change. It is from lines 558-633 of wp-postratings.php . If someone can take a look and let me know what I need to change, I'd be very grateful. <code> ### Function: Process Ratings process_ratings(); function process_ratings() { global $wpdb, $user_identity, $user_ID; $rate = intval($_GET['rate']); $post_id = intval($_GET['pid']); if($rate &gt; 0 &amp;&amp; $post_id &gt; 0 &amp;&amp; check_allowtorate()) { // Check For Bot $bots_useragent = array('googlebot', 'google', 'msnbot', 'ia_archiver', 'lycos', 'jeeves', 'scooter', 'fast-webcrawler', 'slurp@inktomi', 'turnitinbot', 'technorati', 'yahoo', 'findexa', 'findlinks', 'gaisbo', 'zyborg', 'surveybot', 'bloglines', 'blogsearch', 'ubsub', 'syndic8', 'userland', 'gigabot', 'become.com'); $useragent = $_SERVER['HTTP_USER_AGENT']; foreach ($bots_useragent as $bot) { if (stristr($useragent, $bot) !== false) { return; } } header('Content-Type: text/html; charset='.get_option('blog_charset').''); postratings_textdomain(); $rated = check_rated($post_id); // Check Whether Post Has Been Rated By User if(!$rated) { // Check Whether Is There A Valid Post $post = get_post($post_id); // If Valid Post Then We Rate It if($post &amp;&amp; !wp_is_post_revision($post)) { $ratings_max = intval(get_option('postratings_max')); $ratings_custom = intval(get_option('postratings_customrating')); $ratings_value = get_option('postratings_ratingsvalue'); $post_title = addslashes($post-&gt;post_title); $post_ratings = get_post_custom($post_id); $post_ratings_users = intval($post_ratings['ratings_users'][0]); $post_ratings_score = intval($post_ratings['ratings_score'][0]); // Check For Ratings Lesser Than 1 And Greater Than $ratings_max if($rate &lt; 1 || $rate &gt; $ratings_max) { $rate = 0; } $post_ratings_users = ($post_ratings_users+1); $post_ratings_score = ($post_ratings_score+intval($ratings_value[$rate-1])); $post_ratings_average = round($post_ratings_score/$post_ratings_users, 2); if (!update_post_meta($post_id, 'ratings_users', $post_ratings_users)) { add_post_meta($post_id, 'ratings_users', $post_ratings_users, true); } if(!update_post_meta($post_id, 'ratings_score', $post_ratings_score)) { add_post_meta($post_id, 'ratings_score', $post_ratings_score, true); } if(!update_post_meta($post_id, 'ratings_average', $post_ratings_average)) { add_post_meta($post_id, 'ratings_average', $post_ratings_average, true); } // Add Log if(!empty($user_identity)) { $rate_user = addslashes($user_identity); } elseif(!empty($_COOKIE['comment_author_'.COOKIEHASH])) { $rate_user = addslashes($_COOKIE['comment_author_'.COOKIEHASH]); } else { $rate_user = __('Guest', 'wp-postratings'); } $rate_userid = intval($user_ID); // Only Create Cookie If User Choose Logging Method 1 Or 3 $postratings_logging_method = intval(get_option('postratings_logging_method')); if($postratings_logging_method == 1 || $postratings_logging_method == 3) { $rate_cookie = setcookie("rated_".$post_id, $ratings_value[$rate-1], time() + 30000000, COOKIEPATH); } // Log Ratings No Matter What $rate_log = $wpdb-&gt;query("INSERT INTO $wpdb-&gt;ratings VALUES (0, $post_id, '$post_title', ".$ratings_value[$rate-1].",'".current_time('timestamp')."', '".get_ipaddress()."', '".@gethostbyaddr(get_ipaddress())."' ,'$rate_user', $rate_userid)"); // Output AJAX Result echo the_ratings_results($post_id, $post_ratings_users, $post_ratings_score, $post_ratings_average); exit(); } else { printf(__('Invalid Post ID. Post ID #%s.', 'wp-postratings'), $post_id); exit(); } // End if($post) } else { printf(__('You Had Already Rated This Post. Post ID #%s.', 'wp-postratings'), $post_id); exit(); }// End if(!$rated) } // End if($rate &amp;&amp; $post_id &amp;&amp; check_allowtorate()) } </code> EDIT: You can find the Plugin here
Just comment out (or change) the following line: <code> // printf(__('You Had Already Rated This Post. Post ID #%s.', 'wp-postratings'), $post_id); </code> If you just want to not have the <code> $post_id </code> , change the line to the following: <code> _e('You Had Already Rated This Post. Post ID #%s.', 'wp-postratings'); </code> Btw: If you change a plugin and then make an update, all your changes are gone.
How to remove message output for the WP-PostRatings Plugin?
wordpress
There are several plugins that handle the auto retrieval/display of photos from my personal facebook profile, but i'm looking for one that will work w/ my facebook group. the group is way more active than the actual website and it'd be a bonus for the website to pull more content from FB. have already looked at: Facebook Photo Fetcher Fotobook neither would allow me to grant access to the group's photos even though i am an admin. i'm sure there were a few more but it was a while back and i must have deleted them out of my plugins directory.
take a look on Embed Facebook . Just paste the URL of a facebook album, photo, event, video, page, group, or note in a WordPress post/page, the plugin will embed it for you. For one more plugin is Facebook Photos .:)
Looking for Plugin that displays Facebook group's photos
wordpress
My hosting company infrom me that they do not allow loopback connections, which are required to run the following cron task on my server. I need to run a cron task for this plugin: http://tribulant.com/plugins/view/1/wordpress-newsletter-plugin <code> wget -O /dev/null "http://localhost/?wpmlmethod=docron&amp;auth=XXXXXXXX" &gt; /dev/null 2&gt;&amp;1 </code> They provide the following code which I have adapted for my hosting (path to wget being /usr/bin/php I blieve). I've also tried letting wp-cron.php do the job itself, and it fails, I've also tried making a simple server cron job that manually fires wp-cron.php, this worked once and didn't fire again. I'm now testing the latter with a longer schedule. Ahhh! Thanks.
You could just try the alternate WP Cron method, which doesn't require loopbacks. Add <code> define('ALTERNATE_WP_CRON', true); </code> to your wp-config.php file.
WP CRON on shared hosting that does not allow loopback connections?
wordpress
Maybe it's just the site I'm running but has the 3.2 update removed the ability to select a page template in the page attributes when adding a new page? It's kinda essential unless anyone knows a way around it?
It seems as though it was a personal problem. A knew install solved the problem so it must've been clashing with some legacy data.
Wordpress 3.2 - removed ability to select a page template in the page attributes when adding a new page?
wordpress
I have a page that displays a list of all tags of my blog. Iuse this code which works fine: <code> &lt;?php $poststocount=get_tags($args); echo '&lt;h2&gt;Alphabetic Index of All '&lt;/h2&gt;'; ?&gt; &lt;?php $taxonomy = 'post_tag'; $tax_terms = get_terms($taxonomy); ?&gt; &lt;ul&gt; &lt;?php foreach ($tax_terms as $tax_term) { echo '&lt;li&gt;' . '&lt;a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term-&gt;name ) . '" ' . '&gt;' . $tax_term-&gt;name.'&lt;/a&gt;&lt;/li&gt;'; } ?&gt; &lt;/ul&gt; </code> Question: how can I paginate this lidt (say 40 per page). What would the code to accompish that, preferably with an option to "see all tags". Thanks.
you could paginate your page by simply adding <code> /page/n </code> to the end of the URL, where <code> n </code> is the desired page number. creating your next/prev links will be a manual affair though. the page number will then be accessible via <code> get_query_var('paged') </code> . then use the <code> number </code> argument for <code> get_terms </code> to select 40 at a time, use the <code> offset </code> argument, which will be your page number -1 * number per page, to select the current "page" of terms: <code> $page = ( get_query_var('paged') ) ? get_query_var( 'paged' ) : 1; $taxonomy = 'post_tag'; $offset = ( $page-1 ) * 40; $args = array( 'number' =&gt; 40, 'offset' =&gt; $offset ); $tax_terms = get_terms( $taxonomy, $args ); </code> as for viewing all, maybe append a GET var to the URL, <code> ?showall=true </code> , then check <code> isset( $_GET['showall'] ) </code> and change the number to fetch accordingly. EDIT here's a quick template I made to show an example. I tested it on a page on a test install with pretty permalinks, the page was 'about', so the pagination links were: <code> http://localhost/about/page/2/ http://localhost/about/?showall=true </code> if your permalinks are different, you'll have to edit the pagination section to reflect your setup. <code> &lt;?php get_header(); // if show all is set if( isset($_GET['showall']) ): $args = array( 'hide_empty' =&gt; 0 ); else: // else show paged $page = ( get_query_var('paged') ) ? get_query_var( 'paged' ) : 1; // number of tags to show per-page $per_page = 40; $offset = ( $page-1 ) * $per_page; $args = array( 'number' =&gt; $per_page, 'offset' =&gt; $offset, 'hide_empty' =&gt; 0 ); endif; $taxonomy = 'post_tag'; $tax_terms = get_terms( $taxonomy, $args ); echo '&lt;ul&gt;'; foreach ($tax_terms as $tax_term) { echo '&lt;li&gt;' . '&lt;a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term-&gt;name ) . '" ' . '&gt;' . $tax_term-&gt;name.'&lt;/a&gt;&lt;/li&gt;'; } echo '&lt;/ul&gt;'; // pagination // if showall isn't set if( !isset($_GET['showall']) ): $total_terms = wp_count_terms( 'post_tag' ); $pages = ceil($total_terms/$per_page); // if there's more than one page if( $pages &gt; 1 ): echo '&lt;ul&gt;'; for ($pagecount=1; $pagecount &lt;= $pages; $pagecount++): echo '&lt;li&gt;&lt;a href="'.get_permalink().'page/'.$pagecount.'/"&gt;'.$pagecount.'&lt;/a&gt;&lt;/li&gt;'; endfor; echo '&lt;/ul&gt;'; // link to show all echo '&lt;a href="'.get_permalink().'?showall=true"&gt;show all&lt;/a&gt;'; endif; else: // showall is set, show link to get back to paged mode echo '&lt;a href="'.get_permalink().'"&gt;show paged&lt;/a&gt;'; endif; get_footer(); ?&gt; </code>
How to paginate a list of tags
wordpress
I have a question. I just installed Wordpress 3.2. And ever since then, when I want to add a custom field, precisely when I clicked on "Add custom field", my page is refreshed. And no custom field is added. What is it ? Ajax bug ? Wordpress 3.2 ? Can you help me please ?
Try to re-install your wordpress, it might help you, and also try using different browser, to check the cache problem
Custom field bug in Wordpress 3.2
wordpress
So I originally designed the site without the www. I've since realized that it's going to cause more problems than necessary. I created a rewrite rule that converts to www. I then changed the domain in wp-config <code> define( 'DOMAIN_CURRENT_SITE', 'openeye.net' ); define( 'PATH_CURRENT_SITE', '/' ); define( 'SITE_ID_CURRENT_SITE', 1 ); define( 'BLOG_ID_CURRENT_SITE', 1 ); define('WP_HOME','http://www.openeye.net'); define('WP_SITEURL','http://www.openeye.net'); define('WP_MEMORY_LIMIT', '96M'); </code> I'm now not able to edit pages or access wp-admin. What would cause that?
You don't need a rewrite rule in .htaccess to add www back in. Remove the rewrite rule, remove all the defines in wp-config and try to login. If that doesn't work, delete permalinks in .htaccess to force them back to default. After you're in, add the www in Dashboard> > Settings and save. Then reset permalinks.
Why am I unable to login after converting to www?
wordpress
I am working on backup-related plugin and from some research of existing plugins - they seem to favor using PHP's <code> mysql_* </code> functions, rather than <code> $wpdb </code> . Is <code> $wpdb </code> overhead considerable enough that it is unsuitable for such task as querying whole database tables?
There is a significant amount of memory usage if you use the $wpdb for queries that return very large result sets. $wpdb loads the entire results from any given query into memory. So if you're, say, selecting all the posts, then it'll try to load the whole thing into memory immediately. So for something like a backup plugin, direct calls to mySQL with loops for retrieving the data make more sense.
Does wpdb add considerable overhead on queries with large result sets?
wordpress
The Browse Happy interruption would only appear to logged-in admin users, correct? It won't show up on my public facing site? I can't really fire up IE6 very easily to find out.
Yes, it always was and still is only showing in the admin area.
Browse Happy in 3.2
wordpress
I want list the popular posts.popular post is defined by number of comments.If number of comment is high it will consider as popular. How can i do this !
You can easily sort by native post fields, so try something like this: <code> $posts = get_posts( array( 'numberposts' =&gt; 10, 'orderby' =&gt; 'comment_count', ) ); </code>
How to list most popular post
wordpress
Simply put, I need to hide all posts on the frontend if they are written by authors with a specific role. The role I have created is called 'Suspended'. I'm happy with putting a simple IF statement around the loop which prevents posts from a certain role ID from appearing. Preferably though it would be something I can enter into the WP_Query. I Can't use user ID as there would be xx number of users with the same role. Does anyone know how this could/ would be done? Any help would be very much appreciated. Thanks in advance.
Use <code> WP_User_Query </code> to build a list of suspended authors` ids, then use that list with minuses for inversion as author parameter in query .
Hide posts from users with a specific role
wordpress
On a Wordpress based website, when I add text using wordpress visual editor or HTML source to a particular page - it gives "page not found error". I tried by adding some other text and its working fine. Then I typed all the text again and in between kept checking if it is giving any errors. Finally I am able to point to the exact word that is causing problem - from. If I put frm , rom or from it works. Only when I use "from" - it gives page not found error. Another thing, the error is only this page not on any other page. I have used "from" on many other pages and there is no problem at all. Its a client website and I do not have access to the server. I only have wordpress login/password. Any help would be appreciated. Update: I even tried HTML entities and it does not work. Right now we are using "fróm" instead of "from" as a workaround.
What form are your pretty permalinks taking, and what is the title of that page? I've had something similar happen and it had to do with the page title. Try flushing your permalinks (go to Settings > Permalinks and switch to a different default, save, then switch back again to what you were using). Though of course this doesn't explain at all why putting the word 'from' in the body of the post would make any difference at all. :(
Wordpress "Page not found error" when I edit a page
wordpress
This morning I updated my wp, and after that few of the jquery of my site is not working. I am using woo themes premium newspaper theme. After the upgrade, the categories drop down menu(superfish menu) stopped working. I was using lightbox plugin for images, that stopped working. I deactivated all plugins and checked the theme, but still the superfish was not working, I updated the themes framework with latest, but still no effect. Can any one help me in this? My website URL is:http://webstutorial.com/ and the theme which I am using is this:http://demo.woothemes.com/?name=premiumnews
The problem is with the theme. On the theme demo the superfish drop downs are not working and for some reason the theme is loading jquery 2 times version 1.3.1 from the theme directory and version 1.6.1 from the WordPress includes directory. Your site is actually loading jquery 3 times. I would contact the theme support.
WooThemes PremiumNews Theme jQuery Conflict with WordPress 3.2
wordpress
I am grabbing an image that is uploaded to that post working with this function: wp_get_attachment_image_src <code> &lt;?php $images = get_children( array( 'post_parent' =&gt; $post-&gt;ID, 'post_type' =&gt; 'attachment', 'post_mime_type' =&gt; 'image', 'orderby' =&gt; 'menu_order', 'order' =&gt; 'ASC', 'numberposts' =&gt; 2 ) ); if ( $images ) : $total_images = count( $images ); $image = array_shift( $images ); $image_img_tag = wp_get_attachment_image_src( $image-&gt;ID, 'full' ); ?&gt; &lt;div class="two_images"&gt; &lt;img src="&lt;?php echo $image_img_tag[0] ?&gt;"&gt; &lt;/div&gt; </code> How do I grab the first two images that are uploaded to a post? I guess I need help with a foreach statement.. and limit it to two. I tried this but it just printed the same first image over and over.. <code> &lt;?php foreach ($image as $images) { echo "&lt;img src='$image_img_tag[0]'&gt;"; } ?&gt; </code> IF I echo <code> $total_images </code> then I get the correct count of 2 Thanks for any help! Here is the paste of the page
Looks like you may have just not had a loop setup, try this one <code> &lt;div class="two_images"&gt; &lt;?php global $post; $args = array( 'post_parent' =&gt; $post-&gt;ID, 'post_type' =&gt; 'attachment', 'post_mime_type' =&gt; 'image', 'orderby' =&gt; 'menu_order', 'order' =&gt; 'ASC', 'numberposts' =&gt; 2 ); $images = get_posts($args); if ( $images ) { $i = 0; while($i &lt;= 1){ echo wp_get_attachment_image( $images[$i]-&gt;ID, 'full' ); $i++; } } ?&gt; &lt;/div&gt; </code>
How grab first two image attachments?
wordpress
Hi all I have this template page which get the page's post and then a list of posts from the category news. <code> &lt;?php /* * Template Name: News &amp; Info */ get_header(); ?&gt; &lt;div id="cLeft"&gt; &lt;?php if (function_exists('yoast_breadcrumb')) { yoast_breadcrumb('&lt;p id="breadcrumb"&gt;', '&lt;/p&gt;'); } ?&gt; &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt; &lt;div id="title"&gt; &lt;h1&gt;&lt;?php the_title(); ?&gt;&lt;/h1&gt; &lt;/div&gt; &lt;div id="freetext"&gt; &lt;?php the_content(); ?&gt; &lt;/div&gt; &lt;?php endwhile; endif; ?&gt; &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt; &lt;?php query_posts('cat=32'); ?&gt; &lt;div class="post"&gt; &lt;h2&gt;&lt;a href=""&gt;&lt;/a&gt;&lt;/h2&gt; &lt;div class="postDescr"&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php endwhile; endif; ?&gt; &lt;/div&gt; &lt;div id="cRight"&gt; &lt;h2&gt;News &amp;amp; Info:&lt;/h2&gt; &lt;ul id="submenu"&gt; &lt;?php wp_list_pages('hide_empty=0&amp;child_of=26&amp;title_li=&amp;sort_column=menu_order'); ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;?php get_footer(); ?&gt; </code> The second loop gets in infinite loop and I don't know what am I doing wrong. Thanks in advance
It was correctly pointed out what the issue is, but I also want to explain it so you have better idea of mechanics: when you use <code> query_posts() </code> it writes down generated <code> WP_Query </code> object into global <code> $wp_query </code> variable; <code> have_posts() </code> and <code> the_post() </code> functions are wrappers for methods of same name called using global <code> $wp_query </code> object; so what you are doing in that code is keep overwriting <code> $wp_query </code> and keep asking it if there are posts to process. And there are always posts because as soon as you process post you kick query back to new clean state. Also see stackexchange-url ("When should you use WP_Query vs query_posts() vs get_posts()?")
Why this code causes infinite loop?
wordpress
I plan to use the category descriptions as outputted content into my posts for site user searches within my site, but I want to know when I make the site live to search engines will that presence of multiple category descriptions (duplicates) effect my seo in a negative way, i.e. getting blacklisted. So I will used the category description value in a custom field of a post, so that users can search the custom field of a post and get results of any posts with that category description. I would just use the search everything plugin, but unfortunately it doesn't work together with the existing search fields of my particular theme. My theme's advanced search allows multiple fields searches at the same time, which I need for dual search criteria. This goes back to reason why Im outputting the category description into a custom field of my post. I need to include all post meta content to be searchable, but because my theme is limited in that area I have to use an altenative solution, by directly inputted the value into the post to that it can be searched through a custom field. Will this negatively effect my search engine rankings? If there any tips or advice on other solutions for what Im trying to achieve please let me know. Thanks a lot.
You won't get blacklisted. Small descriptive duplicate content on the same url tends to be a non-factor since it is very common, duplicate content over multiple urls, different parent urls, or large amounts of it can often become diluted, thus the use of canonical urls. ps. This question has nothing to do with WordPress.
Will multiple category descriptions effect my search engine optimization?
wordpress
I have a listing wordpress site and want to integrate geo data into the Wordpress MySQL Database for custom search functionality I want to utilize different aspects to create different things... City values will become taxonomies State values will become taxonomies Zip Code values will become taxonomies Latitude - will become custom fields Longitude - will become custom fields County will be come taxonomies City Taxonomy -> City Taxonomy Terms State Taxonomy -> State Taxonomy Terms Zip Code Taxonomy -> Zip Code Taxonomy Terms Latitude -> Custom Field Value Longitude -> Custom Field Value County Taxonomy -> County Taxonomy Terms Here are a couple sample entries from the SQL files I have: <code> DROP TABLE IF EXISTS `cities_extended`; CREATE TABLE `cities_extended` ( `city` varchar(50) NOT NULL, `state_code` char(2) NOT NULL, `zip` int(5) unsigned zerofill NOT NULL, `latitude` double NOT NULL, `longitude` double NOT NULL, `county` varchar(50) NOT NULL ) TYPE=MyISAM; INSERT INTO `cities_extended` VALUES ('Holtsville', 'NY', '00501', '40.8152', '-73.0455', 'Suffolk'); INSERT INTO `cities_extended` VALUES ('Holtsville', 'NY', '00544', '40.8152', '-73.0455', 'Suffolk'); INSERT INTO `cities_extended` VALUES ('Adjuntas', 'PR', '00601', '18.1788', '-66.7516', 'Adjuntas'); </code> Is this doable with Wordpress Database? Thanks
To answer your question... Yes, it's doable. But to give you some pointers into the right direction... I've known some folks who have had good success using the WordPress Importer plugin. You could conceivably export your geo data from your database (using whatever DB management tool you're comfortable with) to the import format that this plugin expects. Depending on your comfort level with PHP and DB schemas, you could even tweak this plugin to suit your needs. But since you're probably looking for a "one time" import, you might even whip up a PHP script and leverage the wp_insert_term function. (Again, depending on your comfort with PHP). This is probably how I'd do it. In general, I'd create a DB connection to my geo database, loop all the records, and inside the loop use wp_insert_term (keeping track of which cities, states, zips I've already inserted if necessary so that I don't insert 20 "Holtsville" records). So again... The answer is "Yes" definitely doable. But it might take a little work. Hope that helps a little. Good luck on the project!
Importing Geo data into wordpress database
wordpress
Anyone know any resources to help me install my widget when my plugin is activated?
By "install" your widget, I'm assuming you mean "automatically add the new widget to the sidebar for your user after the plugin gets 'activated'". (Because if you activate the plugin, which also contains a widget, your widget should be visible in the widgets area immediately, without any more work needed). Jordan Bosch has a great write-up on how to create a plugin that automatically assigns a widget to the sidebar without intervention from the user. If you're already familiar with plugin / widget development, that should get you going pretty quickly. Good luck!
Install widget on plugin activation
wordpress
I would love to be able to use spaces in usernames, but this does not seem possible. Is there a writeup in the codex or somewhere that explains what characters are allowed and why it was restricted to that set or is it just alphas only and suck it up? If I want users to use something other than a username with no spaces, is my only real option a plugin that allows users to login with their email addresses instead, but still requires an alpha only username at account creation? Oh, and I am on a WPMU/network site.
You can use spaces in usernames, no problem. Several users on wordpress.org have spaces in their usernames. Strict mode only allows these characters: <code> a-z0-9&lt;space&gt;_.\-@ </code> However WP doesn't default to strict mode. Now, multisite has different restrictions, and it may strip spaces there. This is because usernames are used to create independent blogs and such on multisite installs.
Where can I find documentation on what characters are allowed in user names and why?
wordpress
I'm testing different layouts for my admin pages, and the easiest way I found to determine which layout to load is with URL parameters. One of those parameters is "fullscreen=1" which hides the admin menu, for instance. The problem is, whenever I save a post / custom post type by submitting a form, WordPress will redirect me without preserving my parameter, thus breaking my layout by adding back the admin menu... Is there an easy way to achieve this?
I finally figured this one out. Turns out I was so focused on filters and actions that I forgot about the basics. In order to preserve any custom URL parameters after saving a post (via submitting the form) do the following: Filter your admin URL with a conditional that checks for the parameter you want to preserve (stackexchange-url ("based on this answer")), like this: <code> add_filter('admin_url','add_fullscreen_param'); function add_fullscreen_param( $link ) { if(isset($_REQUEST['fullscreen']) &amp;&amp; $_REQUEST['fullscreen'] == '1') { $params['fullscreen'] = '1'; } $link = add_query_arg( $params, $link ); return $link; } </code> Then, all you have to do is make sure you send that request along with your form, because it will activate the filter above prior to redirecting back to your post / page / custom post type. To do this, simply add a hidden input. <code> if(isset($_REQUEST['fullscreen']) &amp;&amp; $_REQUEST['fullscreen'] == '1') { echo('&lt;input type="hidden" name="fullscreen" value="1" /&gt;'); } </code> So if you access <code> /wp-admin/post.php?post=100&amp;action=edit&amp;fullscreen=1 </code> , that last parameter will be there after saving the form.
Preserve custom URL parameter after saving post
wordpress
I am unable to see custom taxonomy box in the wordpress new menu system. I can see the post types but custom taxonomies are not available. I saw the screen options aswell custom taxonomies are not listed there. I am using more taxonomy plugin to create taxonomy.
Glad it was of use to you askkirati, I commented the code in order to make it easy to see where the plugin needs to be fixed, it really wasn't a big change and to be honest I don't know why it wasn't included.
Custom taxonomy not appearing in menu administration panel
wordpress
On my custom menus page, I'm getting a limit (e.g. the users cannot add more menu items). I have done some research and have found that my suhosin settings may not be allowing wordpress enough memory. What is the best way to fix the config so that my menus won't be limited?
I found the answer , so I'm posting it to help others out: In this file (depending on your server setup): <code> /etc/php5/apache2/conf.d </code> Change suhosin.ini on the following lines (remove the semicolons if applicable): <code> suhosin.post.max_vars = 5000 suhosin.request.max_vars = 5000 </code> The default 1000 will not work - 5000 seems to work well for my needs (so far!)
How to set up suhosin.ini for unlimited menus
wordpress
How to replace "wp-content/blogs.dir" with "media" for attachment permalinks in a multisite environment? This is how links look now: http://url.com/wp-content/blogs.dir/21/files/2011/06/650026_x640_21.jpg -or- http://subdomain.url.com/wp-content/blogs.dir/21/files/2011/06/650026_x640_21.jpg Ideally this is how the would look: http://url.com/media/2011/06/650026_x640_21.jpg -or- http://subdomain.url.com/media/2011/06/650026_x640_21.jpg Thank you!
Actually ... the <code> blogs.dir </code> part isn't used except for internally. Let's say you have a network with two sites - <code> http://url.com </code> and <code> http://sub.url.com </code> . The files will be located in (respectively): <code> http://url.com/files/2011/06/... </code> <code> http://sub.url.com/files/2011/06/... </code> The <code> blogs.dir </code> directory is where the images exist physically, yes, but your <code> .htaccess </code> file is routing the virtual directories I just listed above to the correct location. I'm guessing you're manually putting together the URLs you reference above ... because that's not how Multisite is set up to work by default. Update I just tested this on my own network installation to give you a specific example. My main blog is http://mindsharestrategy.com (custom domain mapped to a subdomain network installation - http://business.eamann.com is the same site). A recent post with images: How to Publish a WordPress Plugin - Subversion . The first image in the post is: http://mindsharestrategy.com/files/2011/05/checkout.png But an alternate link that also works: http://eamann.com/wp-content/blogs.dir/2/files/2011/05/checkout.png WordPress automatically maps the <code> /files </code> directory for this site to <code> /wp-content/blogs.dir/2/files </code> via the <code> .htaccess </code> file. So your image permalinks will work with the shortened version ... there's nothing you need to do there. It sounds like your problem is actually with the way the <code> [gallery] </code> shortcode outputs content.
How to replace "wp-content/blogs.dir" with "media" for attachment permalinks?
wordpress
I'm creating my own wordpress theme. I've decided to use a different way to handle the theming and not use the standard get_header() and so functions. What i do is have a general main.php page that is loaded by every page like blog.php, index.php, page.php and more. This main page, will be then responsible for creating the necessary templates and presenting the related page. Now, i would ideally want to create sort of like the standard switch that includes files, like : <code> $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 'home'; switch($page) { case 'home': break; case 'mail': break; case 'contact': break; default: $page = 'home'; } include("$page.php"); </code> How can i do such a thing for wordpress ? Is there a clean way to know whether an included page is a blog.php, a single.php or other page, so that i can distinguish them?
First, Why this is a bad idea WordPress already provides a rich templating API that allows for other plugins to hook in to your theme where needed. If a plugin needs to provide additional JavaScript or CSS, they tie in to <code> wp_head </code> . If they need to defer some JavaScript to the bottom of the page, they hook into <code> wp_footer </code> . If they add plugins, they use the built-in dynamic sidebar. By completely bypassing the theme, you're essentially preventing the user from doing anything with their site that you haven't already built in to your display engine. You're also throwing out about half of WordPress from the get-go. An alternative Instead, I suggest you work with the existing system. WordPress provides a lot of hooks, template tags, and conditional flags that let you detect which page you're on and load different templates when needed. There's a really good discussion of the general template hierarchy in the Codex . You can set up a different page template for each page, then when you write the page in WordPress you just select the right template. So rather than <code> include("$page.php") </code> , you'd have three files in your theme: <code> page_home.php </code> <code> page_mail.php </code> <code> page_contact.php </code> Then, at the top of each of these files, you include the following header: <code> &lt;?php /** * Template Name: [YourPageTemplateName] * Describe what the template is for * * @package [YourThemeName] */ </code> For example, from <code> page_contact.php </code> in my "Stacked" theme: <code> &lt;?php /** * Template Name: Contact * This file handles contact pages. * * @package StackedTheme */ </code>
Custom Wordpress File Inclusion
wordpress
This may be obvious to someone other than myself. I think I remember reading somewhere that an "image" is indeed a form of "post". I have a custom post type called "listing" I have a custom WP role of "client" When I'm logged in as the "client", and I launch the media popup, browse to an image, click "show" to open it up, and then click "edit image", I get a -1. Ie. nothing else displays but "-1". I can fix this issue by assigning my custom role the capability of "edit_posts". Why is this? As soon as I do this, I'm plagued with another problem, the "client" user role now has access to posts, comments &amp; tools, which I don't want. Perhaps I haven't set up my custom post type correctly with the capabilities? How can I allow the "client" to edit the images but not have access to posts? <code> $args = array( 'label' =&gt; 'Listing', 'description' =&gt; '', 'public' =&gt; true, 'show_ui' =&gt; true, 'show_in_menu' =&gt; true, 'show_in_nav_menus' =&gt; true, 'map_meta_cap' =&gt; true, 'capability_type' =&gt; 'listing', 'capabilities' =&gt; array( 'edit_post' =&gt; 'edit_listing', 'read_post' =&gt; 'read_listing', 'delete_post' =&gt; 'delete_listing', 'edit_posts' =&gt; 'edit_listings', 'edit_others_posts' =&gt; 'edit_others_listings', 'publish_posts' =&gt; 'publish_listings', 'read_private_posts' =&gt; 'read_private_listings', 'delete_posts' =&gt; 'delete_listings', 'delete_private_posts' =&gt; 'delete_private_listings', 'delete_published_posts' =&gt; 'delete_published_listings', 'delete_others_posts' =&gt; 'delete_others_listings', 'edit_private_posts' =&gt; 'edit_private_listings', 'edit_published_posts' =&gt; 'edit_published_listings', ), 'menu_position' =&gt; 5, 'hierarchical' =&gt; false, 'has_archive' =&gt; false, 'rewrite' =&gt; array('slug' =&gt; 'listing'), 'query_var' =&gt; true, 'supports' =&gt; array('title'), 'labels' =&gt; $labels ); </code>
If I had to guess: because images are Attachments , and Attachments are a Post-Type . Thus, in order to edit an image, which is an attachment, which is a post, requires the <code> edit_post </code> capability. EDIT Don't you have your <code> capability </code> mapping array keys/values reversed? e.g. you have <code> 'edit_posts' =&gt; 'edit_listings' </code> . Shouldn't it instead be <code> 'edit_listings' =&gt; 'edit_posts' </code> ?
Why does my custom WP role need edit_posts to edit images?
wordpress
I wish to do something as simple as the_post_thumbnail('large') but I want the URL of the image only, not the HTML which goes with it. Is that possible ?
Use <code> get_post_thumbnail_id() </code> to retrieve ID, then <code> wp_get_attachment_image_src() </code> to retrieve array, that will have URL as first element.
Getting only the URL of the post thumbnail
wordpress
I have posted this on StackOverflow too, not sure if that's allowed - if not let me know and I'll remove one (I don't want to look like I'm spamming). Anyway.... I have a custom post type and have used the Verve Meta Boxes plugin to create some custom meta values for the post type. The meta box is called 'Subjects' and has a checkbox list of subjects to assign values to it. For example, I have ticked Math, English and Science. Now I want to perform a WP_Query which will take an array of subjects selected by the user as an array, compare those subjects to those selected for the custom post type, and return posts if any of them match. Here's the code so far: <code> $subjects_array = explode("_", $_GET["subjects"]); $args = array( 'post_status' =&gt; 'publish', 'post_type' =&gt; 'any', 'meta_query' =&gt; array( // Not sure what type of meta query to do ) ); $query = new WP_Query($args); </code> To cut a long story short, I just need to know if there's a way to perform a meta_query which will compare an array against whatever format the data in the meta box is in? If this is not possible, I just need to know then I'll look at a different way of doing it, but I'm thinking there's perhaps some meta_query ability I don't know about. Any help would be much appreciated.
Take a look at the codex for a better understanding of queries of custom fields but it should look something like this: <code> $subjects_array = explode("_", $_GET["subjects"]); $args = array( 'post_status' =&gt; 'publish', 'post_type' =&gt; 'any', 'meta_query' =&gt; array( array( 'key' =&gt; 'field_name', 'value' =&gt; $subjects_array, 'compare' =&gt; 'IN' ) ) ); $query = new WP_Query($args); </code>
WP_Query with checkbox meta_query
wordpress
i need a solid solution for checking if a post has pagination or not, regardless of the number of current page in the pagination, and even if the post is in the first page of the pagination. the check is inside the loop. thanks.
Just check for the global <code> $numpages </code> variable: <code> &lt;?php global $numpages; if ( is_singular() &amp;&amp; $numpages &gt; 1 ) { // This is a single post // and has more than one page; // Do something. } ?&gt; </code>
how to know if the post has pagination ( ) or not
wordpress
Title says it all, I pretty much just want to put a dropdown list on the front end that will list all the posts of custom post type 'agent', preferably in alphabetical order, and go to that post when user clicks on it.
try this: <code> //first get all agents $agents = new WP_Query(array('post_type' =&gt; 'agent', 'posts_per_page' =&gt; -1, 'order' =&gt; 'ASC', 'orderby' =&gt; 'title')); //then just print out the dropdown: if ($agents-&gt;have_posts()){ echo '&lt;select id="agent"&gt;'; while ($agents-&gt;have_posts()){ $agents-the_post(); echo '&lt;option value="'.get_permalink($post-&gt;ID).'"&gt;'.get_the_title($post-&gt;ID).'&lt;/option&gt;'; } ?&gt; &lt;/select&gt; &lt;script type="text/javascript"&gt; &lt;!-- var dropdown = document.getElementById("agent"); function onCatChange() { if ( dropdown.options[dropdown.selectedIndex].value &gt; 0 ) { location.href = dropdown.options[dropdown.selectedIndex].value; } } dropdown.onchange = onCatChange; --&gt; &lt;/script&gt; &lt;?php } </code>
Front End Dropdown Showing All Custom Post Type 'Agent'
wordpress
I'm trying to make some modifications to a wordpress multisite and i could use some help from someone more experienced. I want to restrict the acces to my blogs unless the user has an account. In detail : i have a series of blogs, each one with an admin/autor. If a user wants to read posts from a blog, he should first go on the main site, to wp-signup.php and create an account. I'm planning on creating a plugin, active on all subsites. Is this possible? if yes, could someone give me some directions - wich hooks, filters and functions i would need ? Thank you!
Test if the current visitor is logged in and registered as user <code> // If the user's not registered &amp; logged in, abort if ( ! is_user_logged_in() ) return; </code> Test if the currently logged in user has a capability for the specific blog <code> $blog_id = ''; // You need to retrieve and set that here // If the currently logged in user hasn't got the 'manage_options' cap - which is assigned to admins and above - abort if ( ! current_user_can_for_blog( $blog_id, 'manage_options' ) ) return; </code> If it's not necessary to check for a specific blog, we can test just the capability. <code> // If the currently logged in user hasn't got the 'manage_options' cap - which is assigned to admins and above - abort if ( ! current_user_can( 'manage_options' ) ) return; </code> This (old and not maintained) plugin gives you better in-depth look at what users deliver.
User Signup in Multisite - Need Plugin or Advice
wordpress
(I am using a child theme of twenty-ten) For most of my pages I like to use the single column template. I noticed that (after I updated to 3.14) my single posts were using the default template (which has a sidebar for widgets). How do I get rid of this? I could style the sidebar away but is there a way to tell WP to apply the single-column template for my single-posts? Note that the main blog page applies the single-column template to it, so this is only happening when I bring up individual posts.
You could duplicate the single-column template and rename it single.php.
How do I apply a template to my single posts?
wordpress
I'm trying to create an "admin only" meta box using WPAlchemy. The box for example may contain a "feature post" check box and other functionality. How can I show this meta box for only the admin, yet have it work properly? I'm currently using the following code below, but I receive a "Fatal error: Call to a member function the_meta() on a non-object" when trying to echo the value of whatever is inside on the front-end. Everything works as intended if I don't use current_user_can and works also if I'm logged in as admin and viewing the front-end. <code> if (current_user_can('administrator')) { $custom_admin_mb = new WPAlchemy_MetaBox(array( 'id' =&gt; '_custom_admin_meta', 'title' =&gt; 'Admin only', 'template' =&gt; TEMPLATEPATH . '/custom/admin_meta.php', )); </code> }
try the following: <code> $custom_admin_mb = new WPAlchemy_MetaBox(array( 'id' =&gt; '_custom_admin_meta', 'title' =&gt; 'Admin only', 'template' =&gt; get_stylesheet_directory() . '/custom/admin_meta.php', 'output_filter' =&gt; 'my_output_filter', )); function my_output_filter() { if (current_user_can('administrator')) return true; return false; } </code>
Creating an "admin only" meta box with WPAlchemy. Getting a fatal error on front-end when using current_user_can
wordpress
I'm working on a simple addition to the widget options to allow the user to set the "context" in which widgets show be shown. Here's what I've got so far, with my questions in the comments... 1) Append the widget form to all widgets... <code> add_filter('in_widget_form', 'wse_widget_context_form'); function wse_widget_context_form($widget){ //echo 'the widget id is: '.$widget-&gt;id; //do we need to reference the widget-&gt;id to avoid variable overwrites on multiple widgets? ?&gt; &lt;div class="wse_context"&gt; &lt;ul&gt; &lt;li&gt;Hide this widget on: &lt;/li&gt; &lt;li id='home'&gt;&lt;label&gt;&lt;input value="on" type="checkbox" name="noHome" id="noHome"&lt;?php if(isset($noHome)) echo $noHome ?&gt; /&gt; home&lt;/label&gt;&lt;/li&gt; &lt;li id='posts'&gt;&lt;label&gt;&lt;input value="on" type="checkbox" name="noPosts" id="noPosts"&lt;?php if(isset($noPosts)) echo $noPosts ?&gt; /&gt; posts&lt;/label&gt;&lt;/li&gt; &lt;li id='pages'&gt;&lt;label&gt;&lt;input value="on" type="checkbox" name="noPages" id="noPages"&lt;?php if(isset($noPages)) echo $noPages ?&gt; /&gt; pages&lt;/label&gt;&lt;/li&gt; &lt;li id='cats'&gt;&lt;label&gt;&lt;input value="on" type="checkbox" name="noCats" id="noCats"&lt;?php if(isset($noCats)) echo $noCats ?&gt; /&gt; categories&lt;/label&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code> 2) Create a callback function to handle when widgets are saved...(so far, this is the part I'm stuck on) <code> &lt;?php add_filter('widget_update_callback', 'wse_widget_context_callback'); add_filter('widget_update_callback', 'wse_widget_context_callback'); function wse_widget_context_callback($instance, $new_instance, $old_instance){ echo 'instance: '.$instance.'&lt;br/&gt;'; // returns array echo 'new_instance: '.$new_instance.'&lt;br/&gt;'; //returns '' echo 'old_instance: '.$old_instance.'&lt;br/&gt;'; //returns '' } </code> 3) Show/Hide widget based on widget settings <code> add_filter('widget_display_callback', 'wse_widget_display_callback'); function wse_widget_display_callback() { //how do I read the values and unset widgets as appopriate? } </code>
Just like you would from a widget() method: <code> function wse_widget_display_callback($instance) { $show_it = true; if(isset($instance['noHome']) &amp;&amp; $instance['noHome'] &amp;&amp; is_home()) $show_it = false; if(isset($instance['noPages']) &amp;&amp; $instance['noPages'] &amp;&amp; is_page()) $show_it = false; ... if($show_it) return $instance; else return false; } </code> I've posted here the functions I use to accomplish this, it might be helpful. The form hooks are here , but they are part of a class...
Context aware widgets. My work in progress
wordpress