question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
My problem is when on the main plugin file i include a php file something like this: <code> include(WP_PLUGIN_URL . '/wordpress-group-buying/ipn/paypal-ipn.php'); //or include_once(WP_PLUGIN_URL . '/wordpress-group-buying/ipn/paypal-ipn.php'); //or require(WP_PLUGIN_URL . '/wordpress-group-buying/ipn/paypal-ipn.php'); //or require_once(WP_PLUGIN_URL . '/wordpress-group-buying/ipn/paypal-ipn.php'); </code> and on that file i have a call to a WordPress function like add_action('hook,'callback'); and i get Fatal Error: Call to undefined function add_action() .... now before you say "use if( function_exists ('add_action')){" if i use that then it just doesn't work. the questions: what would be the correct way to do that? what are the difference between include ,include_once,require and when do i use witch? thanks for any help!
First , thank you to everyone who answered, My problem was calling the included files with full url that way they don't go through WordPress. and that happened because as i stated on the question i was calling them from the main plugin file. so the fix ended up using: <code> include_once('/ipn/paypal-ipn.php'); </code> i read about at the WordPress support . and again thanks for answering!
How to include PHP files in plugins the correct way
wordpress
I want create 5 pages when user active my theme. I found a code from wpcanyon which can create one page only. From this code how do I create 5 pages without repeat it 5 times. <code> if (isset($_GET['activated']) &amp;&amp; is_admin()){ $new_page_title = 'This is the page title'; $new_page_content = 'This is the page content'; $new_page_template = ''; //ex. template-custom.php. Leave blank if you don't want a custom page template. //don't change the code bellow, unless you know what you're doing $page_check = get_page_by_title($new_page_title); $new_page = array( 'post_type' =&gt; 'page', 'post_title' =&gt; $new_page_title, 'post_content' =&gt; $new_page_content, 'post_status' =&gt; 'publish', 'post_author' =&gt; 1, ); if(!isset($page_check-&gt;ID)){ $new_page_id = wp_insert_post($new_page); if(!empty($new_page_template)){ update_post_meta($new_page_id, '_wp_page_template', $new_page_template); } } } </code> Let me know.
Ehm, just repeat the page creation code several times, providing different content and such. Is there any issue with that?..
How do I create multiple page while active a theme
wordpress
Is it possible to move a post to an another category if post_meta field is 0 ? I'm building a reverse order vote, every post have by default 10 votes and after a user vote, removes one vote by updating the post_meta, now i try to move the post to an another category if the votes field is 0 or 2 days old. I have found a solution stackexchange-url ("here") that moves a post to an another category if is a past date from this in the database. It runs every hour to do the check <code> if (!wp_next_scheduled('sfn_expire_hook')){ wp_schedule_event( time(), 'hourly', 'sfn_expire_hook'); } add_action( 'sfn_expire_hook', 'sfn_show_expire'); function sfn_show_expire(){ global $wpdb; $server_time = date('mdy'); $result = $wpdb-&gt;get_results("SELECT * FROM $wpdb-&gt;posts WHERE post_type = 'post' AND post_status = 'publish'"); if( !empty($result)) foreach ($result as $a){ $show_time = get_the_time('mdy', $a-&gt;ID); if ( $server_time &gt; $show_time ){ $my_post = array(); $my_post['ID'] = $a-&gt;ID; $my_post['post_status'] = 'draft'; wp_update_post( $my_post ); } } // end foreach } </code> can someone help me to extend this to check for 2 days old posts and if post_meta "votes" is "0" also? thanks a lot, Philip
When you remove vote check for your condition, then if needed: fetch categories with <code> wp_get_object_terms() </code> (low level func, you can specify to fetch names or ids only since you don't need full objects for this) modify array (remove category you don't need, add the one you do) set categories with <code> wp_set_post_categories() </code> (it will overwrite all categories so those you remove from array will be gone)
Move Post to different category if post_meta field is 0 or is 2 days old?
wordpress
I'm working on a site that will make use of a few custom taxonomies (for custom post types). I've chosen to make some of the taxonomies hierarchical because the method of inputting values (checking boxes) is more desirable for this site than the free-form input of non-hierarchical taxonomies. However, what I would really like is to be able to use radio button inputs instead of check boxes. Additionally, I'd like to remove the dropdown that is used to choose the parent item in the taxonomy. Am I going about this the wrong way? Should I start with non-hierarchical taxonomies and modify the input methods on those instead? I'm completely open to input and will gladly answer any questions or supply more information if I can.
Hi @tnorthcutt: Sure thing, just use CSS and the <code> 'admin_head' </code> hook to make it disappear. I believe this is what you are looking for? Just add the following to your theme's <code> functions.php </code> file or to a <code> .php </code> file of a plugin that you might be writing. Note that I included an <code> 'init' </code> hook to define the "Home" post type and the "Bath" taxonomy so others can more easily follow the example. Also note that if your taxonomy is named Baths" you'll need to change the CSS selector to be <code> #newbaths_parent </code> instead of <code> #newbath_parent </code> : <code> add_action('admin_head','remove_bath_parents'); function remove_bath_parents() { global $pagenow; if (in_array($pagenow,array('post-new.php','post.php'))) { // Only for the post add &amp; edit pages $css=&lt;&lt;&lt;STYLE &lt;style&gt; &lt;!-- #newbath_parent { display:none; } --&gt; &lt;/style&gt; STYLE; echo $css; } } add_action('init','add_homes_and_baths'); function add_homes_and_baths() { register_post_type('home', array( 'label' =&gt; 'Homes', 'public' =&gt; true, 'rewrite' =&gt; array('slug' =&gt; 'homes'), 'hierarchical' =&gt; false, ) ); register_taxonomy('bath', 'home', array( 'hierarchical' =&gt; true, 'label' =&gt; 'Baths', 'rewrite' =&gt; array('slug' =&gt; 'baths' ), ) ); } </code> UPDATE So it seems I missed the radio button part of the question. Unfortunately WordPress does not make this easy but you can make it happen by using PHP output buffering (via the <code> ob_start() </code> and <code> ob_get_clean() </code> functions.) Just find a hook before the metabox is output ( <code> 'add_meta_boxes' </code> ) and a hook after it is output ( <code> 'dbx_post_sidebar' </code> ) and then search the captured HTML for <code> 'checkbox' </code> and replace with <code> 'radio' </code> , echo it to the screen and yer done! Code follows: <code> add_action('add_meta_boxes','mysite_add_meta_boxes',10,2); function mysite_add_meta_boxes($post_type, $post) { ob_start(); } add_action('dbx_post_sidebar','mysite_dbx_post_sidebar'); function mysite_dbx_post_sidebar() { $html = ob_get_clean(); $html = str_replace('"checkbox"','"radio"',$html); echo $html; } </code> And the evidence:
Altering the appearance of custom taxonomy inputs
wordpress
On my single.php and index.php I'm including the comment entry routine with this code... <code> &lt;?php if(get_option('allow_comments_posts')){comments_template();} ?&gt; </code> However, when the specific post being viewed in single.php has "Allow Comments" unchecked, I don't want the comment template to appear. I was under the impression that the comments_template() routine automatically managed this, but apparently I need to wrap it or pass a paramater?
As far as I remember main purpose of <code> comments_template() </code> is to load template and specific logic should be handled inside that template. Snippet from Twenty Ten <code> comments.php </code> : <code> if ( ! comments_open() ) : ?&gt; &lt;p class="nocomments"&gt;&lt;?php _e( 'Comments are closed.', 'twentyten' ); ?&gt;&lt;/p&gt; &lt;?php endif; // end ! comments_open() ?&gt; </code>
Comment entry screen shows even though "Allow Comments" is unchecked
wordpress
I am trying to create a custom search page for a site I developed, but I lack the information needed to create the custom sql queries. Are there any useful resources you guys might know of?
See Database Description in Codex.
Database structure cheatsheet
wordpress
I have a piece of code, which is used to display images on every post from RSS FEEDS, the images will be fetched from yahoo images search, I will paste this code into my single.php file, so that it will appear after my post, This code I found in one of the website where, this was used for the same reason to fetch images but not from yahoo but from different feeds The code which I am using is this:- <code> &lt;?php include_once(ABSPATH.WPINC.'/rss.php'); // path to include script $feed = fetch_rss('http://news.search.yahoo.com/news/rss?p=car'); // specify feed url $items = array_slice($feed-&gt;items, 0, 5); // specify first and last item ?&gt; &lt;?php if (!empty($items)) : ?&gt; &lt;?php foreach ($items as $item) : ?&gt; &lt;h4&gt;&lt;img id="niraj" src=" &lt;?php $pubdate = substr($item['pubdate'], 0, 16); $a='http://mbas.in/wp-content/uploads/'; $a.=substr($pubdate,12,4); $a.='/'; $m=substr($pubdate,8,3); if($m == 'Jan'){$a.='01';} elseif($m == 'Feb'){$a.='02';} elseif($m == 'Mar'){$a.='03';} elseif($m == 'Apr'){$a.='04';} elseif($m == 'May'){$a.='05';} elseif($m == 'Jun'){$a.='06';} elseif($m == 'Jul'){$a.='07';} elseif($m == 'Aug'){$a.='08';} elseif($m == 'Sep'){$a.='09';} elseif($m == 'Oct'){$a.='10';} elseif($m == 'Nov'){$a.='11';} else{$a.='12';} $a.='/'; echo $a; $str= $item['link']; $len=strlen($str); $test=substr($str,27,($len-1)); echo $test; ?&gt;.jpg" width="90" height="60" alt=&lt;?php echo $item['title']; ?&gt; style="border: none;align:left;"/&gt;&lt;div style="clear:both"&gt;&lt;/div&gt;&lt;a href="&lt;?php echo $item['link']; ?&gt;"&gt;&lt;?php echo $item['title']; ?&gt;&lt;/a&gt;&lt;/h4&gt; &lt;?php endforeach; ?&gt; &lt;?php endif; ?&gt; </code> I tried this code, but the problem is the images are not coming. If this is not a correct way to fetch images from yahoo search, then is there any appropriate way to do it?
First <code> fetch_rss() </code> is long deprecated, use <code> fetch_feed() </code> . As for images I don't know if that is what you want but you build URL to your own computer by using <code> localhost </code> and there is no way to know what it going on there or what is expected from those links.
images are broken
wordpress
I use this function to exclude from the query posts that are 30 days old, <code> function filter_where($where = '') { //posts in the last 30 days $where .= " AND post_date &gt; '" . date('Y-m-d', strtotime('-30 days')) . "'"; return $where; } // Register the filtering function add_filter('posts_where', 'filter_where'); // Perform the query, the filter will be applied automatically query_posts($query_string); </code> is it possible to do something like this to exclude posts that have a meta_key=votes and meta_value=0 ?
I think you'll need to add a posts_join filter, to join the posts and postmeta tables. This link should be helpful: http://codex.wordpress.org/Custom_Queries , in particular this piece of example code: <code> add_filter('posts_join', 'geotag_search_join' ); add_filter('posts_where', 'geotag_search_where' ); function geotag_search_join( $join ) { global $geotag_table, $wpdb; if( is_search() ) { $join .= " LEFT JOIN $geotag_table ON " . $wpdb-&gt;posts . ".ID = " . $geotag_table . ".geotag_post_id "; } return $join; } function geotag_search_where( $where ) { if( is_search() ) { $where = preg_replace( "/\(\s*post_title\s+LIKE\s*('[^']+')\s*\)/", "(post_title LIKE $1) OR (geotag_city LIKE $1) OR (geotag_state LIKE $1) OR (geotag_country LIKE $1)", $where ); } return $where; } </code>
Exclude from the query posts with meta_key and meta_value
wordpress
I've got a number of plug-in's hosted on the wordpress.org svn server ... with the immenent release of 3.1, I would like to update the "Tested up to" meta data. There will be no functional changes to the code, just the meta data. Is it necessary to change the revision number for such a trivial change?
I would only increase the version number if users needed to download the plugin again. The "Tested up to" variable is not used when the plugin is installed, only when people want to install it or want to upgrade. In that case, the information comes from the server anyway, so you don't need to force a new download of your plugin. Of course, if your <code> readme.txt </code> in the <code> trunk </code> directory has <code> Stable tag </code> indicator, you should update the <code> readme.txt </code> in the correct <code> tags </code> subdirectory, otherwise it will get ignored. There is no problem updating a file in the <code> tags </code> directory and not creating a new version, for Subversion it's a normal directory just like all others, it's only a convention to use it for tagged historical releases.
Is it necessary to bump a plug-in's version if you're just updating the "Tested up to" attribute?
wordpress
I would like to group posts of a custom post type based on tags, but the default functionality does not do for the project I am working on. I want the user to be able to select only one tag, not multiple tags, from a list of all the tags entered for that custom post type (drop down or radio buttons). The user can create as many tags as he wants from the page for adding a custom taxonomy, and all these tags will be listed in the meta box on the single custom post page. Any suggestion?
In my last project i had the same issue and i just used this: first get the list of tags to a var using the get_categories function by passing the right taxonomy like this: <code> $args = array( 'orderby' =&gt; 'name', 'order' =&gt; 'ASC', 'hide_empty' =&gt; 0, 'taxonomy' =&gt; 'post_tag' ); $categories=get_categories($args); foreach($categories as $category) { $tags[] = $category-&gt;name ; } </code> then create the arguments for the meta box <code> $prefix = 'CPT_my_meta'; $meta_box = array( 'id' =&gt; 'custom-meta-box', 'title' =&gt; 'tags', 'page' =&gt; 'CPT name', 'context' =&gt; 'normal', 'priority' =&gt; 'high', 'fields' =&gt; array( array( 'name' =&gt; 'tags', 'desc' =&gt; 'select a tag', 'id' =&gt; $prefix . 'name', 'type' =&gt; 'select', 'options' =&gt; $tags ))) </code> then add the meta box <code> add_action('admin_menu', 'add_my_box'); // Add meta box function add_my_box() { global $meta_box; add_meta_box($meta_box['id'], $meta_box['title'], 'metabox_callback', $meta_box['page'], $meta_box['context'], $meta_box['priority']); } </code> then all you have to do is create a function to show the meta box <code> //show meta box function metabox_callback(){ global $meta_box, $post; // Use nonce for verification echo '&lt;input type="hidden" name="META_BOX_NONEC" value="', wp_create_nonce(basename(__FILE__)), '" /&gt;'; echo '&lt;table class="form-table"&gt;'; foreach ($meta_box['fields'] as $field) { // get current post meta data $meta = get_post_meta($post-&gt;ID, $field['id'], true); echo '&lt;tr&gt;', '&lt;th style="width:20%"&gt;&lt;label for="', $field['id'], '"&gt;', $field['name'], '&lt;/label&gt;&lt;/th&gt;', '&lt;td&gt;'; switch ($field['type']) { case 'select': echo '&lt;select name="', $field['id'], '" id="', $field['id'], '"&gt;'; foreach ($field['options'] as $option) { echo '&lt;option', $meta == $option ? ' selected="selected"' : '', '&gt;', $option, '&lt;/option&gt;'; } echo '&lt;/select&gt;'; break; } echo '&lt;/td&gt;&lt;/tr&gt;'; } echo '&lt;/table&gt;'; } </code> and save it on post save <code> //hook save function add_action('save_post', 'save_my_meta_box'); // Save data from meta box function save_my_meta_box($post_id) { global $meta_box; // verify nonce if (!wp_verify_nonce($_POST['META_BOX_NONEC'], basename(__FILE__))) { return $post_id; } // check autosave if (defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE) { return $post_id; } // check permissions if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } elseif (!current_user_can('edit_post', $post_id)) { return $post_id; } foreach ($meta_box['fields'] as $field) { $old = get_post_meta($post_id, $field['id'], true); $new = $_POST[$field['id']]; if ($new &amp;&amp; $new != $old) { update_post_meta($post_id, $field['id'], $new); } elseif ('' == $new &amp;&amp; $old) { delete_post_meta($post_id, $field['id'], $old); } } } </code> hope this helps
Display list of tags as drop down menu or radio buttons in a meta box?
wordpress
I’m planning ahead for a class website, where students will have the choice to either build their pages from scratch, or to use a WordPress multisite install as a CMS. I would like their work to sport URLs such as : http:// myschool.edu/2011/project1 ➤ WP blog http:// myschool.edu/2011/project2 ➤ serves files directly uploaded by the students http:// myschool.edu/2011/project3 ➤ WP blog And to have it work for future years too (2012, etc.). My gut feeling is that this would be possible to achieve with some Redirect rules in the Apache configuration. Even if I have to manually write them. Can someone with more experience with the WP Network feature and ModRewrite confirm this is possible? Or suggest an altogether better alternative? Thanks!
If a folder physically exists on the server, that will override the blog address in multisite. No fancy rewrites needed. Your only issue is making sure that they have access to that folder and that folder only, if they choose the static one. ;) Also: You cannot nest URLs in multisite. You'd need a new install in each year folder to get what you want.
Static directories in a WordPress multisite network
wordpress
I've been trying to use the front page from the Autofocus theme in a different theme by copy pasting the code from index.php in the Autofocus theme to my new archive.php file. I have also copied the related functions from functions.php from Autofocus, I also tried to get some of the css over to the new theme. I have tried this for a long time and with multiple tweaks but I can't get it to work. I get both images and text, but not in the same style as in the Autofocus theme, and definitely not with the cropping autofocus has on its front screen. Am I missing something here? Shouldn't it work if I copy the whole fuctions.php in to the new one and copy all the css?
I think if you just copy-paste the functions and styles, you're still missing a lot of code in the actual templates (those PHP files). Like others said, you might be missing classes... you might also be missing entire DIVs and other stuff, too, though.
Designing a custom archive.php inspired by the Autofocus theme
wordpress
The default WordPress insert/edit link inspector window has options for URL, Target, Title and Class. I would like to add a checkbox labeled " Make link nofollow " that, when checked, adds rel="nofollow" to the link. It would also need to know if the link already has nofollow and default to checked in the case of a link edit. Is there an existing filter or action to hook into this dialog to add the required bits?
You could add the advlink plugin in to tinyMCE. I don't think I can attach the code, so to do it you'll need to download a copy of tinyMCE: http://tinymce.moxiecode.com/download/download.php Then copy over the advlink directory (from the plugins folder) to your Wordpress plugins folder, and open up the link.htm file. In there edit the 4 script tags at the top from: <code> &lt;script type="text/javascript" src="../../tiny_mce_popup.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="../../utils/mctabs.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="../../utils/form_utils.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="../../utils/validate.js"&gt;&lt;/script&gt; </code> to: <code> &lt;script type="text/javascript" src="../../../wp-includes/js/tinymce/tiny_mce_popup.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="../../../wp-includes/js/tinymce/utils/mctabs.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="../../../wp-includes/js/tinymce/utils/form_utils.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="../../../wp-includes/js/tinymce/utils/validate.js"&gt;&lt;/script&gt; </code> Lastly add this filter function to your theme's functions.php file: <code> function tiny_mce_advlink($plugins) { $newPlugins=array('advlink' =&gt; WP_PLUGIN_URL.'/advlink/editor_plugin.js' ); return $plugins+$newPlugins; } add_filter('mce_external_plugins', 'tiny_mce_advlink'); </code> Then you should have a more advanced dialog when you click on a link. In the Advanced tab you'll notice a drop down that says 'Relationship page to target' and you can select the 'No Follow' option. You can of course use this tinyMCE plugin as the basis to write your own if you wanted.
How can I add a field to make link nofollow to the WordPress Link Inspector Window?
wordpress
I'm looking for a plugin or example of code that can intercept the save/publish event and verify that all external links within the post content have rel="nofollow" attributes. Is it possible to use add_filter or add_action on the post save/publish event?
I would try "wp_insert_post_data" filter. <code> add_filter('wp_insert_post_data', 'new_content' ); function new_content($content) { preg_match_all('~&lt;a.*&gt;~isU',$content["post_content"],$matches); for ( $i = 0; $i &lt;= sizeof($matches[0]); $i++){ if ( !preg_match( '~nofollow~is',$matches[0][$i]) ){ $result = trim($matches[0][$i],"&gt;"); $result .= ' rel="nofollow"&gt;'; $content['post_content'] = str_replace($matches[0][$i], $result, $content['post_content']); } } return $content; } </code> Obviously needs work, just a PoC.
How to filter content on Save/Publish to add rel="nofollow" to all external links?
wordpress
I just created a custom post type and a custom taxonomy: <code> // === CUSTOM TAXONOMIES === // add_action('init', 'my_custom_taxonomies', 0); function my_custom_taxonomies() { register_taxonomy( 'location', // internal name = machine-readable taxonomy name 'static_content', // object type = post, page, link, or custom post-type array( 'hierarchical' =&gt; true, 'labels' =&gt; array( 'name' =&gt; __( 'Location' ), 'singular_name' =&gt; __( 'Location' ), 'add_new_item' =&gt; 'Add New Location', 'edit_item' =&gt; 'Edit Location', 'new_item' =&gt; 'New Location', 'search_items' =&gt; 'Search Location', 'not_found' =&gt; 'No Location found', 'not_found_in_trash' =&gt; 'No Location found in trash', ), 'query_var' =&gt; true, // enable taxonomy-specific querying 'rewrite' =&gt; array( 'slug' =&gt; 'location' ), // pretty permalinks for your taxonomy? ) ); wp_insert_term('Footer', 'location'); wp_insert_term('Header', 'location'); } // === CUSTOM POST TYPES === // add_action( 'init', 'create_my_post_types' ); function create_my_post_types() { register_post_type( 'static_content', array( 'labels' =&gt; array( 'name' =&gt; __( 'Static Content' ), 'singular_name' =&gt; __( 'Static Content' ), 'add_new_item' =&gt; 'Add New Static Content', 'edit_item' =&gt; 'Edit Static Content', 'new_item' =&gt; 'New Static Content', 'search_items' =&gt; 'Search Static Content', 'not_found' =&gt; 'No Static Content found', 'not_found_in_trash' =&gt; 'No Static Content found in trash', ), '_builtin' =&gt; false, 'public' =&gt; true, 'hierarchical' =&gt; false, 'taxonomies' =&gt; array( 'location'), 'supports' =&gt; array( 'title', 'editor', 'excerpt' ), 'rewrite' =&gt; array( 'slug' =&gt; 'static_content', 'with_front' =&gt; false ) ) ); } </code> But when I enter the edit page of my custom post type, on the sidebar it says "All Categories." It should say "All Locations." How do I change that label?
Add this to the <code> labels </code> array: <code> 'all_items' =&gt; __( 'All Locations' ), </code> See <code> register_taxonomy() </code> docs for full description of <code> labels </code> argument.
How to change the "All Categories" label within the panel of my custom post type?
wordpress
I'm using the Front Slider plugin to display featured articles on my site . I've done some editing to the plugin to make it look the way I want. Somewhere along the way, I must have missed changing a value, because the top half to the image for the article being displayed links to the article while the bottom half does not. Assuming it's as simple as I think, all I need to know is what code I need to find and replace. Thanks in advance.
It's because the div#imglink is set to height: 150px; in your css. Change it to the same height as the images in the slider.
How Do I Link My Whole Featured Article Image?
wordpress
I am from Turkey and we have "şŞçÇğĞüÜöÖıİ" characters in our alphabet. I want to use those characters in permalinks/slugs/usernames. I found temporary solution for permalinks/slugs with core-hacking. There is no other option for it except core-hacking seems. You can find solution here: http://core.trac.wordpress.org/ticket/15248 My problem is, user registration need a little fix after this one too. Fortunately there is filter i can use but couldnt handle it: in wordpress includes/formatting.php : <code> function sanitize_user( $username, $strict = false ) { $raw_username = $username; $username = wp_strip_all_tags( $username ); $username = remove_accents( $username ); // Kill octets $username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username ); $username = preg_replace( '/&amp;.+?;/', '', $username ); // Kill entities // If strict, reduce to ASCII for max portability. if ( $strict ) $username = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $username ); $username = trim( $username ); // Consolidate contiguous whitespace $username = preg_replace( '|\s+|', ' ', $username ); return apply_filters( 'sanitize_user', $username, $raw_username, $strict ); } </code> This section of code is producing error: <code> if ( $strict ) $username = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $username ); </code> Somehow i need to disable this section. But i am not sure how to do it.
Try this (not tested, I hope I am not short circuiting it into endless loop): <code> add_filter('sanitize_user', 'non_strict_login', 10, 3); function non_strict_login( $username, $raw_username, $strict ) { if( !$strict ) return $username; return sanitize_user(stripslashes($raw_username), false); } </code>
Allowing non-latin characters in registration
wordpress
I'm (still) working on a custom post type plugin for my workplace and came across an easier method of marking Visitors (my custom post type) as either "Here" (aka checked-in) or "Not Here" (not checked-in). I've explored the Edit Flow plugin and, to be honest, I can't really follow what all is going on here... I did however come across a function that appears to be in WordPress' core, but I can't seem to find much documentation on the web (none on wordpress.org even). The function is <code> register_post_status </code> but the best I found was this resource which at best only shows me the arguments that go with the function's <code> $args </code> parameter. Anyone ever tried this? Or am I the only one who's really needed custom post statuses for custom post types? EDIT: I've read this and this as per stackexchange-url ("the answers/comments I've received"). Here is an implementation that I'm not 100% sure about because documentation is lacking. I know it doesn't work, but I don't get why it doesn't work. Neither of the two statuses show up in the status list. My next course of action is to hack it with a taxonomy and just create my own 'Publish' meta box. <code> register_post_status('in', array( 'label' =&gt; _x( 'Logged In', $post_type ), 'protected' =&gt; true, 'label_count' =&gt; _n_noop( 'Visitors logged in &lt;span class="count"&gt;(%s)&lt;/span&gt;', 'Visitors logged in &lt;span class="count"&gt;(%s)&lt;/span&gt;' ), 'show_in_admin_status_list' =&gt; true, )); register_post_status('out', array( 'label' =&gt; _x( 'Logged Out', $post_type ), 'protected' =&gt; true, 'label_count' =&gt; _n_noop( 'Visitors logged out &lt;span class="count"&gt;(%s)&lt;/span&gt;', 'Visitors logged out &lt;span class="count"&gt;(%s)&lt;/span&gt;' ), 'show_in_admin_status_list' =&gt; true, )); </code>
Custom post statuses do exist in the core code of WordPress, so you can register them, but they are not yet properly implemented in the admin screens (e.g. they don't show in the dropdown list of statuses alongside Pending Review, Draft, Published). So essentially you can do very little with them at the moment. You can read more on Trac ticket 12706.
Custom Post Type Statuses
wordpress
I would like to retrieve all posts of a blog via the XML-RPC API of Wordpress. There are the methods of <code> blogger.getRecentPosts </code> and <code> metaWeblog.getRecentPosts </code> which - given a sufficiently high value as number of posts (or -1) in theory should return all posts. However, this does not work for very large blogs or very weak servers that cannot hold the whole blog in memory. In that case, these functions will not return anything at best or throw an error into the response XML. A solution would be to retrieve smaller chunks of, e.g. 50, posts at a time and put it all together on the receiving side. For this to work one would need to specify an offset for the posts to get. I was not able to find a way to specify such an offset in the documented API. Is there any way to make this work, either by specifying an offset or by using other than the methods mentioned above? I'm not looking for a description on how to write a plugin or modify Wordpress itself in any way. I can do that, sure, but I'm talking about authorized retrieval of data of arbitrary Wordpress blogs. Edit: I've opened a trac ticket at Wordpress with a suggestion for solution: http://core.trac.wordpress.org/ticket/16316
According to topic in official forums [xmlrpc] How to get posts with offset? The existing XML-RPC APIs don't really provide a way for collecting all of the post data right now. (Joseph Scott) Topic is somewhat old and I am not aware if there were some changes since, but from quick look at source it doesn't seem so.
How to get all posts (in chunks) via XML-RPC?
wordpress
What's the best way to alter the query being run on the Posts Edit screen (edit.php)? The current method I'm using is by passing an argument to the global $wp_query like so: <code> $wp_query-&gt;query( array ('category__in' =&gt; array(14,9,2) ) ); </code> However, this doesn't really work as expected once the user pages back and forth, filters, or searches.
Few days ago I wrote a quick solution using pre_get_posts filter to hide some pages in admin area. Maybe you could use it as a good starting point for whatever you'd like to achieve. <code> if ( is_admin() ) add_filter('pre_get_posts', 'mau_filter_admin_pages'); function mau_filter_admin_pages($query) { $query-&gt;set('post__not_in', array(1,2,3) ); // Do not display posts with IDs 1, 2 and 3 in the admin area. return $query; } </code> But be careful: <code> pre_get_posts </code> affects almost all post queries on your site. You will have to use some conditions to make it work only where desired. <code> if (is_admin()) </code> was enough for me, but like I said it was quick solution and I haven't tested it properly yet. Im sure some local wp ninja will correct this if it's too dirty .)
Alter query on edit.php
wordpress
Can't find the answer in the codex or on here. Just need to know what file to look in to find the e-mail template. The default e-mail that gets sent upon new user registration has a link which points to wp-admin, and I need it to point to frontend.
Have you looked at this question? stackexchange-url ("How do I customise the new user welcome email")
How to edit the Wordpress e-mail that gives the user their password?
wordpress
I need to add a "last" class to the last post that appears in loop.php. Can someone tell me how to accomplish this?
assuming you're using <code> post_class() </code> : <code> add_filter('post_class', function($classes){ global $wp_query; if(($wp_query-&gt;current_post + 1) == $wp_query-&gt;post_count) $classes[] = 'last'; return $classes; }); </code>
How to add a "last" class to the last post in loop.php?
wordpress
I need to display the "sticky" post in a section that is outside the "loop". Can someone tell me how to do this?
I am using this query; <code> &lt;?php $sticky = get_option( 'sticky_posts' ); // Get all sticky posts rsort( $sticky ); // Sort the stickies, latest first $sticky = array_slice( $sticky, 0, 1 ); // Number of stickies to show query_posts( array( 'post__in' =&gt; $sticky, 'caller_get_posts' =&gt; 1 ) ); // The query if (have_posts() ) { while ( have_posts() ) : the_post(); ?&gt; &lt;h2&gt;&lt;a href="&lt;?php the_permalink() ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt; &lt;?php endwhile;?&gt; &lt;?php } else { echo ""; }?&gt; </code> Hope it works for you too.. :)
How to retrieve "sticky" post outside the "loop"?
wordpress
I'm creating a simple directory from the user accounts and want to simplify it as much as possible for the users. I changed the label on nickname to Lastname, Firstname so that the users can be alphabetized by the nickname field, but I want the display_name to default, or even force, to the nickname field. I haven't seen a plugin, so I'm looking for something I can add to the functions to do this. Any ideas?
You can force this with a hook that activates when the profile is updated. The next step would be to hide the <code> display_name </code> select box, you can do that with some Javascript. <code> add_action( 'user_profile_update_errors', 'wpse7352_set_user_display_name_to_nickname', 10, 3 ); function wpse7352_set_user_display_name_to_nickname( &amp;$errors, $update, &amp;$user ) { if ( ! empty( $user-&gt;nickname ) ) { $user-&gt;display_name = $user-&gt;nickname; } } </code>
How to default/force the user's display_name to their nickname?
wordpress
I saw stackexchange-url ("this post") on SO but the selected solution got a couple of really unflattering comments... I need to add a png fix script to my theme to handle issues with PNG support on IE6 predominantly. I have customers who say that IE6 is upwards of 1/3rd of their traffic if you can believe that. I know that Google is completely abandoning IE6 in Google apps, including Gmail this year, which will hopefully put the nail in the coffin, but until then... What's the best PNG fix for use with WP? Ideally, I want something that works but is very concise in code footprint.
Drawbacks using javascript to fix the PNG issue: higher chances theat the IE-6 visitor doesn't have javascript turned on, than on a modern browser ~1-2 sec. flicker until page finishes loading and javascript completes processing (on IE-6 js is slow) fixing repeating transparent background images is very buggy in these type of scripts, in most cases you'll get a CSS mess... So I don't recommend any PNG "fix" script. Instead create 8 bit PNG images with alpha transparency: http://www.ethanandjamie.com/blog/37-user-interface/81-png8-transparency-without-fireworks You'll need to follow that tutorial because Photoshop can't save in this type of format. Then simply use them for IE 6 in a dedicated stylesheet. The only drawback here is the lower quality of 8 bit (256 color) PNG images converted from a image with a high number of colors (which should really be rare on a website because of their size). But that shouldn't be a problem because IE 6 users are used to sh* quality anyway :)
What PNG Fix script do you recommend for IE6?
wordpress
How can I define a custom field that works as an image upload? Should be fairly basic but I can't seem to find the solution. Let's say you create the post type 'book' and want to create 3 fields: cover, back, index... I don't know... I've done similar stuff in the past with flutter/magic fields but they don't seem to be updated or support native WP3 custom post types. Alternatives anyone? Thanks in advance
Try the Multiple Post Thumbnails plugin, http://wordpress.org/extend/plugins/multiple-post-thumbnails/ . It will allow you to set a post type to have more than one post thumbnail, so you can set a front, back, index separately using the built-in handling.
Create custom fields as image uploads
wordpress
I need to modify the markup of the tag cloud widget. Can someone tell me how to go about doing this without modifying any of the files outside of the theme directory so my changes don't get overwritten when updating WordPress?
What sort of custom markup do you need? Can you elaborate a little more?
Modifying the markup in the Tag Cloud widget?
wordpress
In the function below, I'm trying to remove the current post from the output loop (since this is a list of "related" posts). However, when I try to pass the current post $post-> ID to the "post__not_in" parameter, all hell breaks loose. Warning: array_map() [function.array-map]: Argument #2 should be an array in C:\xampplite\htdocs\theteareport\wp-includes\query.php on line 1826 Warning: implode() [function.implode]: Invalid arguments passed in C:\xampplite\htdocs\theteareport\wp-includes\query.php on line 1826 Warning: array_diff() [function.array-diff]: Argument #2 is not an array in C:\xampplite\htdocs\theteareport\wp-includes\query.php on line 2496 What is the proper method? <code> //get related posts by category function ce4_get_related_by_category() { global $post; $cat = implode(',',get_cats()); $catHidden=get_cat_ID('hidden'); $myqueryCurrent = new WP_Query(); //$myqueryCurrent-&gt;query(array('cat' =&gt; "$cat,-$catHidden",'post__not_in' =&gt; get_option('sticky_posts'))); $myqueryCurrent-&gt;query(array('cat' =&gt; "$cat,-$catHidden",'post__not_in' =&gt; $post-&gt;ID)); $totalpostcount = $myqueryCurrent-&gt;found_posts; if($totalpostcount &gt; 0) { echo "&lt;ul&gt;"; $myposts = get_posts(array('cat' =&gt; "$cat,-$catHidden",'numberposts' =&gt; $cb2_current_count)); foreach($myposts as $idx=&gt;$post) { ?&gt; &lt;li&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;?php the_excerpt(); ?&gt;&lt;/li&gt; &lt;?php } echo "&lt;/ul&gt;"; } } </code>
<code> post__not_in </code> only takes arrays - so it should such, even if you are only passing single value. Simply pass <code> array($post-&gt;ID) </code> .
How to remove the current post from the query?
wordpress
I'm building a plugin and I want to add bits of javascript in the admin head but only for certain admin pages. I don't mean pages as in a WordPress page that you create yourself but rather existing admin section pages like 'Your Profile', 'Users', etc. Is there a wp function specifically for this task? I've been looking and I can only find the boolean function <code> is_admin </code> and action hooks but not a boolean function that just checks.
The way to do this is to use the 'admin_enqueue_scripts' hook to en-queue the files you need. This hook will get passed a $hook_suffix that relates to the current page that is loaded: <code> function my_admin_enqueue($hook_suffix) { if($hook_suffix == 'appearance_page_theme-options') { wp_enqueue_script('my-theme-settings', get_template_directory_uri() . '/js/theme-settings.js', array('jquery')); wp_enqueue_style('my-theme-settings', get_template_directory_uri() . '/styles/theme-settings.css'); ?&gt; &lt;script type="text/javascript"&gt; //&lt;![CDATA[ var template_directory = '&lt;?php echo get_template_directory_uri() ?&gt;'; //]]&gt; &lt;/script&gt; &lt;?php } } add_action('admin_enqueue_scripts', 'my_admin_enqueue'); </code>
How can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?
wordpress
I've searched all over Google with no luck. Can someone point me in the right direction for learning how to send out batch emails with the wp_mail() function?
While according to <code> wp_mail() </code> docs you can pass array of emails addressees it would be bad email tone since it will expose addresses between them. There is no explicit bcc (blind copy) argument from quick look at source it does seems to be processed if passed in headers . Note that many hosting providers are very nervous about mass outgoing emails and can react... poorly. :) It's better to check in advance how many and how often emails you are allowed to send.
Batch Emails with WP-Mail()
wordpress
I'm trying to add a replica of the default WP text widget, with my own css class parameter, to functions.php so that it appears in the widgets manager and can be added to a sidebar. My first attempt is below, but I'm certain there has to be an easier way than how I'm doing it. Can this be done in a simpler manner? In functions.php, I've got this... <code> $google_search = TEMPLATEPATH . "/google_search.php";require_once($google_search); add_action('widgets_init', create_function('', "register_widget('My_Widget_Search');")); </code> In google_search.php, I've got... (Everything works except the textarea field contents aren't being saved) <code> &lt;?php class My_Widget_Search extends WP_Widget { function My_Widget_Search() { $widget_ops = array( 'classname' =&gt; 'widget_search', 'description' =&gt; __( "Google Adsense Search Widget Placeholder" ) ); $this-&gt;WP_Widget('adsense_search', __('Adsense Search Widget'), $widget_ops); } function widget( $args, $instance ) { extract( $args ); $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( '' ) : $instance['title']); $text = apply_filters('widget_text', empty( $instance['text'] ) ? __( '' ) : $instance['text']); } function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['text'] = $new_instance['text']; return $instance; } function form( $instance ) { //Defaults $instance = wp_parse_args( (array) $instance, array( 'title' =&gt; '') ); $title = esc_attr( $instance['title'] ); $text = $instance['text']; ?&gt; &lt;p&gt;&lt;label for="&lt;?php echo $this-&gt;get_field_id('title'); ?&gt;"&gt;&lt;?php _e( 'Title:' ); ?&gt;&lt;/label&gt; &lt;input class="widefat" id="&lt;?php echo $this-&gt;get_field_id('title'); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name('title'); ?&gt;" type="text" value="&lt;?php echo $title; ?&gt;" /&gt;&lt;/p&gt; &lt;textarea class="widefat" rows="16" cols="20" id="&lt;?php echo $this-&gt;get_field_id('text'); ?&gt;" name=""&lt;?php echo $this-&gt;get_field_name('text'); ?&gt;"&gt;&lt;?php echo $text; ?&gt;&lt;/textarea&gt; &lt;?php } } </code>
One idea would be to go into the widgets file from the core files, COPY the text widget code into your functions.php file, and edit your version to see fit. Just an idea, hopefully it'd solve some problems.
How can I add a custom "Text" widget to Appearance manager from functions.php?
wordpress
Possible Duplicate: stackexchange-url ("How to show custom meta box on "Quick Edit" screen?") I'm trying to edit the quick edit screen on my custom post type "visitor" so that I can add some options for my end-users. My custom post type doesn't require/need a post date, password to view, publish status, or large taxonomy boxes for custom categories of visitors on it. I've already added a custom meta box for the actual edit page, but would like to enable quick-edit support of those post meta fields while disabling the current quick-edit options. I also found a post (linked in my possible duplicate) over on wordpress.org's forums, but not sure exactly what it does.
I use this to add form fields to the quick edit. It's not entirely easy to do this in WP (yet) and it can be very difficult to find info on how to do it. You have to really dig through the source to find it too. Add Form fields to Quick Edit <code> &lt;?php add_action('quick_edit_custom_box', 'quickedit_posts_custom_box', 10, 2); add_action('admin_head-edit.php', 'quick_add_script'); function quickedit_posts_custom_box( $col, $type ) { if( $col != 'COLUMN_NAME' || $type != 'post' ) { return; } ?&gt; &lt;fieldset class="inline-edit-col-right"&gt;&lt;div class="inline-edit-col"&gt; &lt;div class="inline-edit-group"&gt; &lt;label class="alignleft"&gt; &lt;input type="checkbox" name="yourformfield" id="yourformfield_check"&gt; &lt;span class="checkbox-title"&gt;This Post Has Cake&lt;/span&gt; &lt;/label&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;?php } function quick_add_script() { ?&gt; &lt;script type="text/javascript"&gt; jQuery(document).ready(function() { jQuery('a.editinline').live('click', function() { var id = inlineEditPost.getId(this); var val = parseInt(jQuery('#inline_' + id + '_yourformfield').text()); jQuery('#yourformfield_check').attr('checked', !!val); }); }); &lt;/script&gt; &lt;?php } </code>
Quick edit screen customization
wordpress
We developed the wordpress site here: wwww.kirschfamilycomputerservices.com/sam/wheresthefairness ^^ URL does not exist now. When the website was done, we transferred the database &amp; theme over to a new host. The issue is odd and really critical. We have to present the website to the client tonight, and none of our URLs are working properly. the index to the new host is this: http://www.advertisingagency.me/wheresthefairness/ The links just under the header to the right are called in a list in the header PHP file and look like this: <code> &lt;div id="wtfloginfb"&gt; &lt;?php if ( is_user_logged_in() ) { echo 'Welcome Back!'; } else { echo 'Hello! New to WTF?!'; }; ?&gt; &lt;?php wp_register( ' ' , ' ' , ' ' ); ?&gt;/ &lt;?php wp_loginout( home_url() ); ?&gt; | &lt;a href="&lt;?php bloginfo('template_url'); ?&gt;/new-case"&gt;State Your Case&lt;/a&gt;| &lt;a href="&lt;?php bloginfo('template_url'); ?&gt;/cases"&gt;View Cases&lt;/a&gt; &lt;/div&gt; </code> The only file outside of the theme directory that I edited while designing the site was the general-template.php file, in which I changed the Site Admin link to display as "Dashboard" and made it point to root/dashboard. So the problem is this.. When you go to the website and hover over a link, it shows the correct path to the file in question, however, when trying to navigate to ANY page directly, we are always given this error: Not Found The requested URL /sam/wheresthefairness/index.php was not found on this server. So what do you guys think the problem could be? Could it be somewhere in the WP files themselves? Or does this sound like a database error? I've honestly never encountered something like this. I've never pointed my browser to a very specific path, and had it tell me that it couldn't load the page, because it tried to go to a different path... 1/19/11-4:36pm Edit to add: We get this error whenever we try to direct link to a post or a page. So essentially, the only pages we can actually view on the new host is the index page, and wp-admin.
Posting as an answer from the @OneTrickPony comment above: Verify that <code> mod_rewrite </code> is enabled on your server. Assuming that <code> mod_rewrite </code> is enabled, ensure that the root WordPress install directory is WordPress-writeable, or that, if it exists, the <code> .htaccess </code> file in the root WordPress install directory is WordPress-writeable. (See file permission scheme for WordPress , and Hardening WordPress: File Permissions .) Then, in your WordPress admin area, go to <code> Dashboard -&gt; Settings -&gt; Permalinks </code> . Click "save" (no need to change settings), which will force a flush of the WordPress URL rewrite rules, and will rewrite the <code> mod_rewrite </code> rules to the <code> .htaccess </code> file.
Critical error in final stage of website launch - URLs are BROKEN!
wordpress
The function below is typically used when inside a loop of categories in order to return each category's description. I'm trying to use it to return the individual category's description when viewing a category landing page (mysite/category/somecategory). How do I pass the equivalent object that represents the category? On header.php <code> if(is_archive()) { //get the category description echo get_cat_desc(get_query_var( 'category' )) } </code> In functions.php <code> function get_cat_desc($category){ $the_description = strip_tags($category-&gt;description); if(strlen($the_description) &gt; 200 ) return SUBSTR( $the_description,0,STRPOS( $the_description,".",200)+1); else return $the_description; } </code> Here is the function where I'm successfully passing in the category object to the function above... <code> function my_category_index(){ $categories=get_categories('exclude=1&amp;exclude_tree=1'); foreach($categories as $category) {echo ce4_get_cat_desc($category);} } </code>
<code> get_cat_desc(get_category(get_query_var( 'category' ))); </code> ( get_category )
How do I pass the category object to a function when is_archive() is true?
wordpress
How can I add a rel="nofollow" attribute to my category widget listings? I'm currently filtering the call to wp_list_categories with this code in my functions.php... <code> function my_wp_list_categories($cat_args){ $cat_args['title_li'] = ''; $cat_args['exclude_tree'] = 1;\ $cat_args['exclude'] = 1; $cat_args['use_desc_for_title'] = 0; return $cat_args; } add_filter('widget_categories_args', 'my_wp_list_categories', 10, 2); </code> Update: When I try this... <code> add_filter('wp_list_categories','wp_rel_nofollow'); </code> My links come out with escape slashes... <code> &lt;li class=\"cat-item cat-item-5\"&gt; &lt;a href=\"http://mysite/category/chinese-tea/\" title=\"View all...Chinese Tea\" rel=\"nofollow\"&gt;Chinese Tea&lt;/a&gt; &lt;/li&gt; </code>
try: <code> add_filter('wp_list_categories','esc_wp_rel_nofollow'); function esc_wp_rel_nofollow($output){ return stripslashes(wp_rel_nofollow($output)); } </code>
How do I add a filter to wp_list_categories() to make links nofollow?
wordpress
I have several images attached to each post. I need to generate a gallery, but because it's heavily customized I don't want to use a gallery plugin, nor the gallery short code. It's also situated in a DIV that is totally separated from the post content/title etc. so it has to be stand-alone code in PHP, hard-coded. Basically if there's a method to retrieve the list of attachments in a URL format.. and then pull in the proper sizes (filename_80X80.jpg or something along those lines - I know the filenames are manipulated after the thumbnail size). I already have the thumbnail sizes covered using <code> add_image_size( 'ourwork_full', 589, 315, true ); add_image_size( 'ourwork_thumb', 80, 80, true ); </code> in the funtions.php file of the template. How can I achieve this? Do I need to use custom WP query? Or is there a function/template tag that I am missing?
Query for image attachments would be something like this (taken from Get The Image plugin/extension) with <code> get_children() </code> : <code> $attachments = get_children( array( 'post_parent' =&gt; $args['post_id'], 'post_status' =&gt; 'inherit', 'post_type' =&gt; 'attachment', 'post_mime_type' =&gt; 'image', 'order' =&gt; 'ASC', 'orderby' =&gt; 'menu_order ID' ) ); </code> Then you can loop through array and retrieve URLs with <code> wp_get_attachment_image_src() </code> which will get you URL and dimensions.
How to query details of images in gallery that is attached to a post
wordpress
Is there a parameter that can be passed to wp_list_categories, to get a certain number of posts from each category? Or a plugin that does something like that? A similar question was in the Wordpress support forum , but it doesn't do exactly what I want.
The code that thread links to seems very close to what you are describing - looping through categories and retrieving some amount of posts for each. If you want to integrate posts into <code> wp_list_categories() </code> you can do that by extending <code> Walker_Category </code> class and using it as custom walker passed via <code> walker </code> argument... but it's not pretty for nested categories (I just tried and it seems to be messy to accurately insert posts). Some example code, I am not entirely sure it handles nesting properly: <code> wp_list_categories( array( 'walker' =&gt; new Walker_Category_Posts(), ) ); class Walker_Category_Posts extends Walker_Category { function start_el(&amp;$output, $category, $depth, $args) { $this-&gt;category = $category; parent::start_el($output, $category, $depth, $args); } function end_el(&amp;$output, $page, $depth, $args) { if ( 'list' != $args['style'] ) return; $posts = get_posts( array( 'cat' =&gt; $this-&gt;category-&gt;term_id, 'numberposts' =&gt; 3, ) ); if( !empty( $posts ) ) { $posts_list = '&lt;ul&gt;'; foreach( $posts as $post ) $posts_list .= '&lt;li&gt;&lt;a href="' . get_permalink( $post-&gt;ID ) . '"&gt;'.get_the_title( $post-&gt;ID ).'&lt;/a&gt;&lt;/li&gt;'; $posts_list .= '&lt;/ul&gt;'; } else { $posts_list = ''; } $output .= "{$posts_list}&lt;/li&gt;\n"; } } </code>
plugin for wp_list_categories with posts
wordpress
I want to allow my users to upload files in admin panel, but I'm not sure where should I upload these files and how the script should look like? <code> &lt;p&gt;Please provide link to a file or click "Upload" to upload it from your PC:&lt;/p&gt; &lt;form&gt; Link: &lt;input type="text" name ="logo_url"&gt; Upload: &lt;input type="file" name="logo_file"&gt; &lt;input type="Submit" value="Upload"&gt; </code> How should back-end look for that script? I mean the type="file" part :) Oh and of course I have fully working theme option page (so the first input works like a charm).
See this stackexchange-url ("very similar question"). The answer can be adjusted to work with all types of files, not just images.
Uploading files in admin panel?
wordpress
I am trying to remove the default widgets in a theme that I found here: http://top-wordpress.net/ The theme is Terapathy. In case of some of the most used themes, if I select the custom widgets, the default theme widgets disappear. But with Terapathy theme or any of the themes found in that site it is not possible. Is there anything I can do to remove those widgets.
you can remove them by adding a blank text widget or you can open the sidebar.php file of the theme witch looks like this: <code> &lt;!-- begin box about --&gt; &lt;!-- begin sidebar --&gt; &lt;div id="sidebar"&gt; &lt;h2&gt;About&lt;/h2&gt; &lt;div class="sidebox"&gt; &lt;img id="aboutimg" src="&lt;?php echo get_option('cici_about_image')?&gt;" alt="about" /&gt; &lt;p&gt;&lt;?php echo stripslashes(get_option('cici_about_txt')); ?&gt;&lt;/p&gt; &lt;/div&gt; &lt;h2&gt;Advertisement&lt;/h2&gt; &lt;div class="sidebox"&gt; &lt;?php if(get_option('cici_ads')=='yes'){?&gt; &lt;?php include (TEMPLATEPATH . '/ad1.php'); ?&gt; &lt;?php }?&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php if(get_option('cici_videos')=='yes'){?&gt; &lt;?php include (TEMPLATEPATH . '/video.php'); ?&gt; &lt;?php }?&gt; &lt;h2&gt;Popular Articles&lt;/h2&gt; &lt;ul class="popular"&gt; &lt;?php pp_popular_posts(4); ?&gt; &lt;/ul&gt; &lt;h2&gt;Flickr Photos&lt;/h2&gt; &lt;div id="flickr"&gt; &lt;?php if (function_exists('get_flickrRSS')) get_flickrRSS(); ?&gt; &lt;/div&gt; &lt;?php /* Widgetized sidebar */ if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?&gt; &lt;?php endif; ?&gt; &lt;/div&gt; &lt;!-- end sidebar --&gt; &lt;/div&gt; &lt;!-- end colRight --&gt; </code> and remove all of the static widgets so you get something like this: <code> &lt;!-- begin box about --&gt; &lt;!-- begin sidebar --&gt; &lt;div id="sidebar"&gt; &lt;?php /* Widgetized sidebar */ if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?&gt; &lt;?php endif; ?&gt; &lt;/div&gt; &lt;!-- end sidebar --&gt; &lt;/div&gt; &lt;!-- end colRight --&gt; </code> this is right about the Terapathy theme, but you get the point and you can do that to any other theme with static widgets in sidebars.
Removing default theme widgets
wordpress
Does anybody know a "related post" plugin with behavior like the one at inc.com. For a demo, visit any article at inc.com (ex: http://www.inc.com/guides/2010/10/how-to-design-a-great-about-us-page.html ) scroll down to the end of the article and you will notice a box sliding in from the bottom right corner of the page. Although this is just like any other related post plugin, I feel its behavior increases site retention. Any pointers will be helpful. Thanks in advance
The plugin I think you're looking for is http://wordpress.org/extend/plugins/upprev-nytimes-style-next-post-jquery-animated-fly-in-button/ "Just like the NYTimes button, upPrev allows WordPress site admins to provide the same functionality for their readers. When a reader scrolls to the bottom of a single post, a button animates in the page’s bottom right corner, allowing the reader to select the next available post in the single post’s category (the category is also clickable to access an archive page). If no next post exists, no button is displayed."
Looking for a related post plugin which slides-in like the one at inc.com does
wordpress
I'm trying to mark up my posts using their custom taxonomy slug as the div class so that they can be filtered... So far what I have displays the taxonomy name but what I need is the slug so I have a nice-space-free-name, I have the below so far outputting the name: <code> &lt;div class="box-item cocktails-box &lt;?php $terms_as_text = strip_tags( get_the_term_list( $wp_query-&gt;post-&gt;ID, 'cocktail_type', '', ' ', '' ) ); echo $terms_as_text; ?&gt;"&gt; </code> Any help would be much appreciated - I'm getting a bald patch from scratching my head on this..
@Ambitious Amoeba's answer works. But have you looked into the <code> post_class </code> function? It'd do what you want, and save you a lot of trouble. Just use this as your div opener: <code> &lt;div &lt;?php post_class('box-item cocktails-box'); ?&gt;&gt; </code> where you pass the classes you want applied to all posts as a list or array, and let WordPress handle the rest (it'll add classes for all taxonomies that the post is in, and you can filter it to add additional class depending on the view, if you want).
Get wordpress taxonomy slug name(s) to use as div class
wordpress
according with stackexchange-url ("Pagination with custom loop"). I use the custom loop for display flash game. For make a pagination on the page with posts from one category (mydomain/category/categoryName) I used: <code> add_action( 'pre_get_posts', 'wpse5477_pre_get_posts' ); function wpse5477_pre_get_posts( &amp;$wp_query ) { if ( $wp_query-&gt;is_category() ) { $wp_query-&gt;set( 'post_type', 'game' ); $wp_query-&gt;set( 'posts_per_page', 9 ); } } </code> I have the section on the main page of my site, where displayed three game from each category. But according with code above I can't display only 3 games, even if I determine in array('post_per_page', 3) or smth like this, because this number have been already determine in $wp-query. how could I kill two birds with one stone? Thanks.
You can check for the existence of a variable, so you don't overwrite it: <code> add_action( 'pre_get_posts', 'wpse7262_pre_get_posts' ); function wpse7262_pre_get_posts( &amp;$wp_query ) { if ( $wp_query-&gt;is_category() ) { if ( ! array_key_exists( 'post_type', $wp_query-&gt;query_vars ) ) { $wp_query-&gt;set( 'post_type', 'game' ); } if ( ! array_key_exists( 'posts_per_page', $wp_query-&gt;query_vars ) ) { $wp_query-&gt;set( 'posts_per_page', 9 ); } } } </code>
Display different number of posts from one category on the different pages
wordpress
Hey hi, I am using a piece of code, where with help of it I can display the description of the term to my archives page. My idea of doing this is simple, I have MBA website and I have 3 custom-taxonomies with 1000's of terms in each, for-eg:- I have a term mba-in-accounts, so its description will be displayed on the archive page of mba-in-accounts, But now the main problem is, this description comes well, but it is just displayed to logged in users I want to make it display to all users who visits my website, I am using this code to display <code> &lt;?php if ( is_tax( 'location' ) ) { echo term_description(); } elseif (is_tax('mba_courses')){ echo term_description(); } elseif (is_tax('duration')){ echo term_description(); } ?&gt; </code> How can I make it display to all users, and I am also using allow-html-in-category-descriptions plugin to enable HTML in description box
There is nothing in <code> term_description() </code> and deeper (that I see) that checks for user. You can try this and see if it returns <code> WP_Error </code> that might make <code> term_description() </code> return empty string: <code> get_term_field( 'description', $term, $taxonomy ) </code>
terms_description and admin problem
wordpress
I had a page.. and I by mistake added another one, so the permalink got appended by "-2" at the end. I had to delete one of the pages, so I happened to delete the one without the -2 attached. Now I'm trying to change the slug of the page so that it becomes "pagetitle/" rather than "pagetitle-2" but everytime I edit the permalink it reverts back to "pagetitle-2" any ideas?
Turns out I had not deleted the page from trash, so the URL has was still taken up! Once trash was emptied it worked.
Permalink of a page that has already been deleted
wordpress
The two functions below are designed to return a list of posts that share the same category as the current post being viewed in single.php However, when I var_dump on $cat (should be a list of the categories assigned to the current post), I'm not getting what I'm expecting. Do I need to deserialize the array before passing it to the get_posts query? <code> function get_cats() { $post_cats= array(); $categories = get_the_category(); foreach($categories as $cat){ array_push($post_cats, $cat-&gt;cat_ID); } return $post_cats; } //get related posts by category function ce4_get_related_by_category() { global $post; $cat = implode(',',get_cats()); $catHidden=get_cat_ID('hidden'); $myqueryCurrent = new WP_Query(); $myqueryCurrent-&gt;query(array('cat' =&gt; "$cat,-$catHidden",'post__not_in' =&gt; get_option('sticky_posts'))); $totalpostcount = $myqueryCurrent-&gt;found_posts; if($totalpostcount &gt; 0) { echo "&lt;ul&gt;"; $myposts = get_posts(array('cat' =&gt; "$cat,-$catHidden",'numberposts' =&gt; $cb2_current_count)); foreach($myposts as $idx=&gt;$post) { ?&gt; &lt;li&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;?php the_excerpt(); ?&gt;&lt;/li&gt; &lt;?php } echo "&lt;/ul&gt;"; } } </code>
You can use get_the_category() It will return an array of category IDs belonging to the current post. <code> $post_cats= array(); $categories = get_the_category(); foreach($categories as $cat) : array_push($post_cats, $cat-> cat_id); endforeach; </code> Then the $post_cats array will have a list of all the ids.
How do I obtain a list of categories assigned to the current post?
wordpress
I am working on a user dashboard for my site using wp user front end and Mingle. I decided the best way to integrate this is by creating a custom sidebar and using that in a new template, which I did. However.. None of my content is showing up and it's driving me nuts. sidebar-dashboard.php <code> &lt;?php /*** The Sidebar containing the dashboard links **/ ?&gt; &lt;?php if ( is_active_sidebar( 'dashboard-sidebar' ) ) : ?&gt; &lt;div id="secondary" class="widget-area" role="complementary"&gt; &lt;ul class="xoxo"&gt; &lt;?php dynamic_sidebar( 'dashboard-sidebar' ); ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;?php endif; ?&gt; </code> dashboard.php <code> &lt;?php /* Template Name: User Dashboard */ ?&gt; &lt;?php get_header(); ?&gt; &lt;div id="content" role="main"&gt; &lt;/div&gt;&lt;!-- #content --&gt; &lt;?php get_sidebar( 'dashboard' );?&gt; &lt;?php get_footer(); ?&gt; </code> functions.php... <code> // Area 7, the sidebar for the dashboard panel register_sidebar( array( 'name' =&gt; __( 'Dashboard Sidebar', 'twentyten' ), 'id' =&gt; 'dashboard-sidebar', 'description' =&gt; __( 'The dashboard sidebar', 'twentyten' ), 'before_widget' =&gt; '&lt;li id="%1$s" class="widget-container %2$s"&gt;', 'after_widget' =&gt; '&lt;/li&gt;', 'before_title' =&gt; '&lt;h3 class="widget-title"&gt;', 'after_title' =&gt; '&lt;/h3&gt;', ) ); </code> So then I go and make all the dashboard pages have the "User Dashboard" template expecting that the sidebar would be on the left and the content would be on the right, but that's not the case. The sidebar shows up but no content whatsoever. What am I doing wrong? Edit: Also, if someone knows any PHP hooks for Mingle that I can use in template pages that would be great, I can't find any documentation on it and they haven't answered me. It's not really a fix to the core issue, but it's a cheap way around it. For WP User Frontend I can just use the do_shortcode function, but Mingle doesn't even seem to have any shortcodes.
the problem is you never call the content!!! change your dashboard.php to something like this <code> &lt;?php /* Template Name: User Dashboard */ ?&gt; &lt;?php get_header(); ?&gt; &lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt; &lt;div id="content" role="main"&gt; &lt;?php the_content(); ?&gt; &lt;/div&gt;&lt;!-- #content --&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;?php get_sidebar( 'dashboard' );?&gt; &lt;?php get_footer(); ?&gt; </code>
Content not showing up when using custom template + sidebar
wordpress
I'm currently creating a new theme for my blog and I intend to make it in a magazine style manner. So, to clarify the question in the title: what I want to do is to create a text assigned to the post, but not displayed in the post itself. Lets say that the user Tom writes a review of the movie Black Swan - what I want to be able to do is summarize that review in a sentence or two - and use that text as an "excerpt" on the front page. Any ideas? It's probably a lot harder than I think it is.
It's not. I believe when you go to make a post, there's a box just below it that says "Excerpt" Whatever you put in that box will only show up as the excerpt. I tested it out and it works. You can view it on the website i'm currently developing here: http://www.kirschfamilycomputerservices.com/sam/wheresthefairness/ The first post. Note how the excerpt is different from the post itself! Also, if you want to run it in a loop instead of making a post I think there's a way to do that, too. check here: http://codex.wordpress.org/Excerpt Good luck and hope this helped.
How can I create an "excerpt" with text that won't be displayed in the post itself?
wordpress
I'm at a loss. I've got a custom meta box with the 'multicheck' code that Jan created. It's working great. My issue now is getting the data to return properly. Scenario: there are 5 possible values, each with the same meta_key. What I am trying to do is display specific content if a value is stored with one of the 5 possible values. What is happening is that the content is repeating. Current site: http://dev.andrewnorcross.com/yoga/locations/tampa/ Current code: <code> &lt;?php global $post; $offerings = get_post_meta($post-&gt;ID, "evol_offerings_select", false); if ($offerings[0]=="") { ?&gt; &lt;!-- If there are no custom fields, show nothing --&gt; &lt;?php } else { ?&gt; &lt;div class="offerings"&gt; &lt;h3&gt;offerings:&lt;/h3&gt; &lt;?php foreach ($offerings as $offering) { if ($offering["hot"]==true) { echo "&lt;div class='single_offering'&gt;"; echo "&lt;h3&gt;Hot 90&lt;/h3&gt;"; echo "&lt;p class='class_info'&gt;temp: 105&amp;deg;&amp;nbsp;&amp;nbsp;&amp;nbsp;time: 90 min&lt;/p&gt;"; echo '&lt;/div&gt;'; } if ($offering["flow"]==true) { echo "&lt;div class='single_offering'&gt;"; echo "&lt;h3&gt;Flow 75&lt;/h3&gt;"; echo "&lt;p class='class_info'&gt;temp: 80&amp;deg;&amp;nbsp;&amp;nbsp;&amp;nbsp;time: 75 min&lt;/p&gt;"; echo '&lt;/div&gt;'; } if ($offering["warm"]==true) { echo "&lt;div class='single_offering'&gt;"; echo "&lt;h3&gt;Warm 60&lt;/h3&gt;"; echo "&lt;p class='class_info'&gt;temp: 90&amp;deg;&amp;nbsp;&amp;nbsp;&amp;nbsp;time: 60 min&lt;/p&gt;"; echo '&lt;/div&gt;'; } if ($offering["chill"]==true) { echo "&lt;div class='single_offering'&gt;"; echo "&lt;h3&gt;Chill 30&lt;/h3&gt;"; echo "&lt;p class='class_info'&gt;temp: 75-80&amp;deg;&amp;nbsp;&amp;nbsp;&amp;nbsp;time: 30 min&lt;/p&gt;"; echo '&lt;/div&gt;'; } if ($offering["kids"]==true) { echo "&lt;div class='single_offering'&gt;"; echo "&lt;h3&gt;Kids Class&lt;/h3&gt;"; echo "&lt;p class='class_info'&gt;temp: comfy&amp;nbsp;&amp;nbsp;&amp;nbsp;time: 60 min&lt;/p&gt;"; echo '&lt;/div&gt;'; } } ?&gt; </code>
Your foreach is the problem. You're iterating once for each offering, yet you're evaluating ALL offering values in the array each time. So your PHP is dutifully printing all available offerings * the number of offerings. I'd say go without the foreach() and see what happens. EDIT 1 Also please note, you're casting strings to arrays. You're trying to look up values in an array based on an invalid key. $offerings["hot"] - $offerings["kids"] don't exist, as far as PHP is concerned. $offerings[0] - $offerings[4] DO exist. EDIT 2 Okay, you want the following in place of your foreach(): <code> if(in_array("hot", $offerings)){ // print hot results } if(in_array("chill", $offerings)){ //print chill results } </code> etc. EDIT 3 Or, if I think about it further, you could stick with the foreach() in the following manner: <code> foreach($offerings as $offering){ switch($offering){ case "hot": //print hot stuff break; case "chill": //print chill stuff break; } } </code> EDIT 4 If you were dealing with a larger data set, I would probably go with the switch() version, as the in_array() calls scan the whole array each time, which could get expensive, while the foreach() will simply iterate through the array and move the array pointer with each iteration. Your call, but I'm thinking that would be the way to go in order to future-proof and performance-proof. (The performance hit on a 5 value array for in_array() is likely minuscule, but these things add up.)
Custom field values repeating
wordpress
I´m using the following code to create a new post type: <code> /* Create custom post type: "Tilbud" */ register_post_type('tilbud', array( 'label' =&gt; __('Tilbud'), 'public' =&gt; true, 'show_ui' =&gt; true, 'capability_type' =&gt; 'post', 'hierarchical' =&gt; false, 'rewrite' =&gt; array('slug' =&gt; '???'), 'query_var' =&gt; false, 'taxonomies' =&gt; array('post_tag','category'), 'supports' =&gt; array('title'), 'register_meta_box_cb' =&gt; 'add_tilbud_metaboxes', )); </code> I would like the premalink of these custom posts to contain the custom post type name followed by the post category: .../custom-post-type-name/post-category/post-title/ I´m aware that I use the rewrite argument to add a slug, but I don´t know what to write in order to insert the post type name and category name dynamically. Any ideas? Thanks!
My plugin here: http://wordpress.org/extend/plugins/custom-post-permalinks/ does exactly what you need. All you need to do with that code is remove the query_var argument and change the rewrite slug to 'tilbud' (or whatever you'd like to have in the permastruct).
Custom permalink structure for custom post type
wordpress
I'm migrating content from an existing site into wordpress. The old site has cross links that I'd like to maintain in the new site. I can convert the old links to wordpress format links (based on post-id), but in order to do that I need to assign the posts their own ID's on migration. is there any way to do that ? The old site is NOT wordpress based...
Yes, use the "import_id" field in the post, when calling wp_insert_post. This is treated as a "suggested" ID for the post that will be used if no post with that ID already exists. <code> $post = array( 'post_title'=&gt;'whatever', 'post_content'=&gt;'whatever', 'import_id'=&gt;123 ); wp_insert_post($post); </code>
How can I assign post a specific ID on creation?
wordpress
I'm adding an extra menu item in admin menu by using add_menu_page . <code> add_menu_page('Calendar', 'Calendar', 'edit_posts', 'wp-eventcal/eventcal-manager.php'); </code> Still my editors do not see the menu item. Why not? Any user that can edit a post, should now be able to see the menu item. Update This is the code: <code> // Define some constants define('WP_CAL_PLUGIN_DIR', trailingslashit( str_replace("\\","/", dirname(__FILE__) ) ) ); define('WP_CAL_PLUGIN_URL', trailingslashit( str_replace("\\","/", dirname(__FILE__) ) ) ); // Plugin activation / deactivation script register_activation_hook(__FILE__,'event_cal_install'); // create custom plugin settings menu if ( function_exists('add_action') ) { add_action('admin_menu', 'event_cal_menu'); add_shortcode('eventcal', 'shortcode_display_event'); } function event_cal_menu() { //create new top-level menu add_menu_page('Calendar', 'Calendar', 'read', 'wp-eventcal/eventcal-manager.php'); } </code> Could it be <code> admin_init </code> in <code> add_action </code> that gives me problems? Update 2 If I log in as administrator, I can see the menu item.
Must be a problem with the surrounding code, your <code> add_menu_page </code> code works fine inside my test code, i can see the item as an admin or editor. <code> add_action( 'admin_menu' , 'admin_menu_new_items' ); function admin_menu_new_items() { add_menu_page('Calendar', 'Calendar', 'edit_posts', 'wp-eventcal/eventcal-manager.php'); } </code> Works just fine for me.. Are you using any plugins for managing the admin menu, such as Adminize? Or alternatively using any CSS to hide elements in the menu? Only two reasons i could think it would be hidden(aside from a problem with surrounding code).
Not able to give editors acess to new admin menu item
wordpress
How do I add a link under my home page banner to my blog summary page. My default page is a "page", not a "post". http://nealwalters.com on 3.0.4
Create a empty page called "Blog", go in Settings > Reading and select "Blog" as the Posts page. Then add the "Blog" page in your custom menu (Appearance > Menus). Create a custom menu if you didn't already do so...
What's the URL to my blogs (from my home page - which is a "page")
wordpress
I am stuck on two issues in trying to get my custom post type for events to function correctly in the admin area. 1st) I have upgraded to wordpress 3.1 after which the code (below) which was working fine on wordpress 3.0 no longer shows any results and I can't figure out what might have messed this up. Essentially, in the code below I had the admin area sorting all posts by the event data/time. <code> // SET A CUSTOM SORT ORDER FOR EVENTS function set_event_list_admin_order($wp_query) { if (is_admin()) { // GET THE POST TYPE FROM THE QUERY $todaysDate = time(); $post_type = $wp_query-&gt;query['post_type']; if ( $post_type == 'events') { // 'meta_key' VALUE CAN BE ANY CUSTOM FIELD $wp_query-&gt;set('meta_key', '_mbcombined_datetime'); // 'meta_compare' VALUE CAN BE ANY POST STATUS $wp_query-&gt;set('meta_compare', '&gt;='); // 'meta_value' VALUE CAN BE ANY POST STATUS $wp_query-&gt;set('meta_value', '$todaysDate'); // 'orderby' VALUE CAN BE ANY COLUMN NAME $wp_query-&gt;set('orderby', 'meta_value'); // 'order' VALUE CAN BE ASC or DESC $wp_query-&gt;set('order', 'ASC'); // 'post_status' VALUE CAN BE ANY POST STATUS $wp_query-&gt;set('post_status', 'publish,pending,draft,future,private'); } } } add_filter('pre_get_posts', 'set_event_list_admin_order'); </code> 2nd) I have not been able to figure out what code I would need to add so that a checkbox is added above the list (by the filter by area) which let's a user check/uncheck "past events". Essentially, all I would like to do here is extend the code I have above so that by default it does not show any events where the date is older than tomorrows date. However, I do need to provide the checkbox option to "include past events" which should auto-reload the list. Any thoughts on this?
I followed this guide and I've got it working for the most part right now.
WP 3.1 & Sorting Admin Post List
wordpress
When certain conditions are met (e.g. post vs. page or a category is tagged, etc) I would like to load an additional CSS file. This file would, in theory, change link colors. Or perhaps change the background color. Cosmetic changes. My thinking was to add code to functions.php, however, I don't think this is actually adding the CSS page. Even (even though right now there is no conditional, it should always just add this new page). Help? <code> /* * register with hook 'wp_print_styles' */ add_action('wp_print_styles', 'add_my_stylesheet'); /* * Enqueue style-file, if it exists. */ function add_my_stylesheet() { $myStyleUrl = WP_THEME_URL . '/newStyle.css'; $myStyleFile = WP_THEME_URL . '/newStyle.css'; if ( file_exists($myStyleFile) ) { wp_register_style('myStyleSheets', $myStyleUrl); wp_enqueue_style( 'myStyleSheets'); } } </code> Thank you
It seems like copy/paste gone wrong - both your variables point to same URL link and so <code> file_exists() </code> fails because it expects local path. Change <code> $myStyleFile </code> to local path and it should work.
How to add CSS style sheet dynamically in wordpress
wordpress
On the page where one adds/removes/modifies taxonomies, what would I need to add to my functions.php file to remove the tag cloud?
I am not sure what filter you would add to your functions.php, but I believe you could get rid of the tag cloud with the Adminimize plugin. http://wordpress.org/extend/plugins/adminimize/
How to remove tag cloud from taxonomy admin edit page?
wordpress
Description: The university radio station I volunteer at uses WordPress 3's Network Mode for the entirety of its web content. It uses the format: Top-Level <code> (.com/*) </code> -- Basic station information, links to feeds, etc. The main site. Subdomains <code> (*.domain.com) </code> -- Station departments (I.e., "music", "spoken word", etc.) Program Top-Level Sub-Directory <code> (.com/program/*) </code> -- Custom post type ("Program") for individual shows airing on the station. Locally-written proprietary code. Most producers have existing social media property (Facebook/Twitter/MySpace/Soundcloud/Tumblr, to name but a few), and we're wanting to encourage producers who don't currently use social media to start using it. To this end, I need two facilities -- a blog system and a RSS importer. Questions: Blog system -- Users should be able to post directly to the WP system, but be restricted to individual program categories. I can probably figure out the first part with roles, but is there any way to restrict where a particular user is able to post? I've also thought about doing this as another custom content type so as to keep it separate from the main station posts system, but it might be difficult to get an RSS importer plugin (See below.) to work with this. RSS importer -- I don't want to force users to use the station's WP system if they're already using other social media tools. Because most social media tools worth their salt produce RSS feeds, I figure the easiest way to accomplish this is via a RSS importer. I've used feedwordpress in the past, but I worry it'll be both too confusing and too powerful for the users I want to access it. Think this is simple enough I could code it from scratch, or is there a particular plugin I should use? Thank you!
At the end of the day, the developer I'm working with and I came up with two solutions: Create a new blog (via Network mode) for each individual blog and just import into that using, say, FeedWordPress. Create a new custom content type and do some mod_rewrite tweaks to put it in the path structure specified above. In the Program content type, a new field that defines the blog's RSS feed (whether it be on-site or off-site) directs a single text link to the latest blog post. We ended up doing the second option because it was closer to the spec and really much more elegant.
Sub-Sub-Blogs -- creating and importing content into a custom sub-type
wordpress
Is there a plugin or a way where I can restrict or limit the buttons on the admin interface for a certain user? For example: for the user who has a role of a writer, he/she can only post content, the other buttons are deactivated. for the designer he/she can only change the "Appearance Tab", all the others are deactivated. Is there a solution for that?
Check out Adminimize, its done by Frank Bueltge a well known plugin author from germany. Link
Limit User Iinterface for Admin?
wordpress
I've been trying to include the jquery ui effects (more specifically the shake effect) on my wordpress theme. So far, I've only been able to include the jQuery script, but I really have no clue where to place the ui scripts and how to enqueue them. This is the code I have. It obviously doesnt work: <code> &lt;?php wp_enqueue_script("jquery"); ?&gt; &lt;?php wp_enqueue_script("jquery-ui-core"); ?&gt; &lt;?php wp_head(); ?&gt; &lt;link rel="stylesheet" type="text/css" href="&lt;?php bloginfo('stylesheet_url'); ?&gt;" /&gt; &lt;script type="text/javascript"&gt; var $j = jQuery.noConflict(); $j(document).ready(function() { $j("#manita-imagen").mouseover(function(){ //$j(this).animate({ opacity: "hide" }) // alert('asd'); $j(this).effect("shake", { times:3 }, 300); }); }); &lt;/script&gt; </code> Thanks for your help!
While WordPress does include the jQuery UI libraries, it does not include the UI/Effects library. That library is separate and standalone. You'll need to include a copy of the effects.core.js file and enqueue it separately. Note that you should name it jquery-effects-core when en-queuing it, for naming consistency. You can include it like this: <code> wp_enqueue_script("jquery-effects-core",'http://example.com/whatever/effects.core.js', array('jquery'), '1.8.8'); </code> Edit : This answer was written before WordPress 3.3, which now includes the various effects libraries as part of core. You can simply enqueue the pieces of the effects library that you need to use now. The list of slugs for these files can be found in wp-includes/script-loader.php, but the core's slug is jquery-effects-core. <code> wp_enqueue_script("jquery-effects-core"); </code>
How to correctly include jquery-ui effects on wordpress
wordpress
Is there a simple PHP or Javascript method of getting the total number of FaceBook friends? Twitter makes it super easy to do that, and I need to do the same for one of my WordPress installs.
To get your friends as a JSON object from Facebook, you can use their Graph API. Easiest way is to visit this page: http://developers.facebook.com/docs/reference/api/user/ Scroll down until you find the Friends link in the "Connections" table. That link will give you a JSON object containing all your friends. Note that the URL on that page is unique to you and contains your access token. Don't share the link. You can use this sort of code in WP to get and use that information: <code> $body = wp_remote_retrieve_body(wp_remote_get('YOUR_FB_URL', array('sslverify'=&gt;false))); $dec = json_decode($body); echo count($dec-&gt;data); </code> You'll want to use transients or something similar to cache the data so that you don't ask FB for it all the time.
Get FaceBook Friend Count
wordpress
Wordpress default taxonomy (Categories) has the item Uncategorized by default. How to add a default item to a new custom taxonomy? functions.php: <code> // === CUSTOM TAXONOMIES === // function my_custom_taxonomies() { register_taxonomy( 'block', // internal name = machine-readable taxonomy name 'static_content', // object type = post, page, link, or custom post-type array( 'hierarchical' =&gt; true, 'labels' =&gt; array( 'name' =&gt; __( 'Blocks' ), 'singular_name' =&gt; __( 'Block' ), 'add_new_item' =&gt; 'Add New Block', 'edit_item' =&gt; 'Edit Block', 'new_item' =&gt; 'New Block', 'search_items' =&gt; 'Search Block', 'not_found' =&gt; 'No Block found', 'not_found_in_trash' =&gt; 'No Block found in trash', ), 'query_var' =&gt; true, // enable taxonomy-specific querying 'rewrite' =&gt; array( 'slug' =&gt; 'block' ), // pretty permalinks for your taxonomy? ) ); } add_action('init', 'my_custom_taxonomies', 0); </code> EDIT: I just want to have the taxonomy item there when the theme is installed. It doesn't have to automatically be added to any empty term .
Have a look here: http://wordpress.mfields.org/2010/set-default-terms-for-your-custom-taxonomies-in-wordpress-3-0/ Basically what you need to do is use the save_post hook to check the terms for the post and add the default term from your taxonomy if it's empty. If you just want to have an initial term set in your custom taxonomy, then you can use <code> wp_insert_term() </code> . Probably easiest to add it in the same function that you're using to create your custom taxonomy. As t3ios adds in the comments, you should call <code> get_term() </code> first, and only insert the term if the return value is null (ie the term doesn't exist). This example code is from the Codex: http://codex.wordpress.org/Function_Reference/wp_insert_term <code> $parent_term = term_exists( 'fruits', 'product' ); // array is returned if taxonomy is given $parent_term_id = $parent_term['term_id']; // get numeric term id wp_insert_term( 'Apple', // the term 'product', // the taxonomy array( 'description'=&gt; 'A yummy apple.' 'slug' =&gt; 'apple' 'parent'=&gt; $parent_term_id ) ); </code>
How to add a default item to a custom taxonomy?
wordpress
This the url format: <code> www.mysite.com/pageone </code> How do I get the page name? what is the wordpress function/method for this? bloginfo('name') return the site name. I want the function that returns (return not echo) the name of the current page.
To display title of current page you use <code> the_title() </code> template tag. Related and slightly more specific functions are: <code> get_the_title() </code> that returns title without echoing and can retrieve title of another page/post, given its ID as input; <code> the_title_attribute() </code> that returns a little more cleaned up version (safer to use in link titles without breaking markup and such) and takes arguments in query string format.
return page name in url
wordpress
This is sort of complicated. I am looking for some php help related to WordPress blog. The basic requirement is that some HTML code (ad code) is not supposed to run on posts with a specific tag. In simple terms... I do not want to run ads in posts which have a specific tag! How can it be accomplished? I believe this would use this WordPress function: http://codex.wordpress.org/Function_Reference/has_tag I am not very proficient at PHP. I suppose this can be easily used to run specific code if the post has a specific tag. I want to do the opposite!
This is more of basic PHP. You are correct in choice of function, you merely need to reverse the condition with logical Not operator : <code> if( !has_tag('test') ) { } </code>
Do not run this code on posts with a specific tag!
wordpress
This is a general question to discuss approaches to filtering WordPress image sizes based on the browser/platform (such as a smart phone or netbook or desktop). The idea being that on a mobile we don't want to force people to download a 100kb image when a 20kb one would be big enough for their screen, thus saving them and yourself, bandwidth. The outcome would be to make using CSS media queries a viable alternative to a separate theme for a mobile version of a site. There are a few points to consider: User Interface What would be the best way to allow a user to control the thumbnail and medium image sizes etc... for different platforms or indeed just for different screen sizes? Device Detection What would the best way to detect the device/UA's screen capabilities on the server side. Are there any plugins that do this already? Implementation How would you go about writing the code to create the different thumbnails, and then to alter WPs output according to the device / screen size? Ideally this would be theme agnostic so a call to <code> the_post_thumbnail('medium') </code> would return the appropriate size of image for the device/platform.
Try tinysrc.net , they do the hard work for you. I haven’t tested it, but it sounds promising.
How to serve different thumbnails/images depending on users browser/platform
wordpress
I have a site driven by Wordpress and a few custom directories that I've got at the top level. Some of these top-level directories work and the content inside of them are being read as expected. However, I've just created a new folder directory with an index.html inside and when I try to visit it, Wordpress is overriding it and displaying a 404 error (since that directory structure doesn't exist in the Wordpress database). I've disabled the W3 cache and I've checked the .htaccess file in the event that I put in a redirect in the past, but nothing that would indicate a redirect back to Wordpress.
WordPress tries to be transparent for physical files and folders. So either something gets broken at server configuration level or at WP rewrites level. The first things to check in such cases would be disabling pretty permalinks and if there might be come paths generated by WP that conflict with that specific folder name.
Wordpress overriding actual subdirectories
wordpress
I'm working with a couple of plugins that ask for a list of category IDs to include/exclude. When I go to the categories section and select "Edit" I don't see an ID field listed on the page, though I see all the other details. Since I will be relaying this information onto other users, how can I find the category ID for them?
there are some plugins that reveal the ID's on the admin side like WP Show IDs and by code like this: <code> //as dropdown $categories= get_categories(array('hide_empty' =&gt; 0,'taxonomy' =&gt; 'category')); echo '&lt;select&gt;'; foreach ($categories as $category) { $option = '&lt;option value="'.$category-&gt;category_id.'"&gt;'; $option .= $category-&gt;cat_name; $option .= '&lt;/option&gt;'; echo $option; } echo '&lt;/select&gt;'; //or just print the categories names by ids like this $categories= get_categories(array('hide_empty' =&gt; 0,'taxonomy' =&gt; 'category')); foreach ($categories as $category) { echo $category-&gt;category_id; echo $category-&gt;cat_name; } </code>
Is there an easy way to get a list of Category IDs?
wordpress
I am trying to add a RSS link on my website archive-pages, which means, Suppose I am on page <code> http://mbas.in/location/mba-in-usa/ </code> then on this page, I will be having a RSS LINK named link, when I click on this link, it should redirect me to <code> http://mbas.in/location/mba-in-usa/feed </code> When anyone navigates through my archive-pages, they will get RSS FEED OF THAT PAGE just by clicking one link, for this I tried the following code <code> &lt;a href="&lt;?php get_permalink(); ?&gt;/feed"&gt;RSS feed of this page&lt;/a&gt; </code> but I am not getting that, instead its giving me <code> http://mbas.in/feed </code>
I made a mess of this in comments, so will start from scratch. The feed links for archive pages are usually only outputted for browser detection by <code> feed_links_extra() </code> . From looking at its source there is number of different function to get link for the archive pages: <code> get_category_feed_link( $cat_id ) </code> ; <code> get_tag_feed_link( $tag_id ) </code> ; <code> get_term_feed_link( $term_id, $taxonomy ) </code> (this one I found separately, not currently used in automatic feed links). So catch-all archive feed link that will work for any taxonomy (including categories and terms) can be built like this: <code> function archive_feed_link() { if( is_archive() ) { global $wp_query; $taxonomy = $wp_query-&gt;get_queried_object(); return get_term_feed_link( $taxonomy-&gt;term_id, $taxonomy-&gt;taxonomy ); } } </code>
RSS feed link on archives page not working
wordpress
Currently with organize series plugin author level user cannot manage their own series. I am trying to add feature to the plugin so that author level user can create &amp; manage their own post and admin and editor can manage all series post. After a little bit searching I have found that that can be done by creating a 'series owner' metadata for series taxonomy and filter by this 'series owner=authorid' to show &amp; manage authors' own post. For adding meta for series taxonomy I have found some tuts and plugin wordpress.org/extend/plugins/taxonomy-metadata/ and shibashake.com/wordpress-theme/add-term-or-taxonomy-meta-data. Now how can I do that? Any help will be appreciated.
May I suggest using the Posts 2 Posts plugin instead. You can create a 'serie' custom post type, specifying the appropriate capabilites, which would allow authors to add descriptions, order posts using drag-and-drop, etc.: https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage https://github.com/scribu/wp-posts-to-posts/wiki/Connection-ordering
'Organize Series Plugin' as muti author feature
wordpress
I have two totally separate WP websites setup. Different domains, different databases. I manage both of them and they are both hosted on a dedicated server. I am trying to include some basic content that requires just a tad more than an RSS feed. I need to pull data from SITE-1 and display it on SITE-2, using basic WP formatting from a loop. Everywhere I've looked makes it seem impossible. I've tried calling wp-load.php but can't get it to work, and am not sure if it is even the right way to go. I have access to both sites' root servers, and even the server root if necessary. Is there anyway to do this? Thanks!
Yeah <code> $wpdb2 = new wpdb('dbuser', 'dbpassword', 'dbname', 'dbhost'); // get 10 posts, assuming the other WordPress db table prefix is "wp_" $query = "SELECT post_title, guid FROM wp_posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date DESC LIMIT 10"; $someposts = $wpdb2-&gt;get_results($query, OBJECT); foreach($someposts as $somepost) echo "&lt;a href=\"{$somepost-&gt;guid}\"&gt;{$somepost-&gt;post_title}&lt;/a&gt;&lt;br /&gt;"; </code> Another way is to use the HTTP api : Code in your first site, where you want to display the data: <code> $send = array( 'body' =&gt; array( 'action' =&gt; 'get_some_posts', // send other data here, maybe a user/password if you're querying senstive data ), 'user-agent' =&gt; 'RodeoRamsey; '.get_bloginfo('url') ); $response = wp_remote_post('http://yoursiteurl.com/', $send); if (!is_wp_error($response) &amp;&amp; ($response['response']['code'] == 200)) echo $response['body']; </code> Code in your second site, in the theme's functions.php (or create a plugin): <code> add_action('template_redirect', 'process_post_request'); function process_post_request(){ if($_POST['action'] == 'get_some_posts'): $posts = new WP_Query(); $query = array('posts_per_page' =&gt; 10); $posts-&gt;query($query); while ($posts-&gt;have_posts()): $posts-&gt;the_post(); // here's the usual loop ?&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt; &lt;?php the_content(); ?&gt; &lt;?php endwhile; die(); endif; } </code> The 2nd method is easier and more flexible from the "formatting" perspective. For example here you could easily echo the post thumbnail as html, while using the database approach it would be very hard for you to get the link to the thumbnail image...
Displaying content from one WP site on separate WP site
wordpress
Is there any email alert list for security fixes? I'd rather not rely on just an RSS feed.
There is a plug-in that will send you an email whenever an update becomes available (security updates and otherwise). This will be one of the easiest ways to get notified via email: Update Notifier Alternatively, there are usually emails on the WP-Testers email list immediately following an update. You can always subscribe to that to see both when updates are ready and when users find exotic bugs that might affect your system. Finally, the core team is fairly consistent in blogging about security patches on the WordPress Development Updates site . And, conveniently, the site offers email updates :-) So there are three different options ... hopefully one will work for you.
Subscribe to email for security fixes?
wordpress
Now that wp-supercache has some built in support for CDNs, I've tried using the CDN Sync Tool to do an initial upload of files to Cloudfront. But, I'm getting 2 sets of errors when syncing (I'm having to use force upload, as for some reason CDN Sync Tool thinks all my files have been uploaded already). cURL error: Failed to open/read local data from file/application (26) This error isn't actually preventing the files from being uploaded though [function.fopen]: failed to open stream: Too many open files in /var/www/xxxxx/wp-content/plugins/cdn-sync-tool/lib/awssdk/lib/requestcore/requestcore.class.php This error does stop files from being uploaded -> S3. So, the 2nd error occurs after a certain (changeable) number of files have been uploaded, and then affects all remaining uploads. Any ideas why or what can be done? [Update] After updating to version 0.9, am now getting the following errors repeatedly (after about 2000 files have been synced) Warning: fclose(): supplied argument is not a valid stream resource in [filepath]/lib/awssdk/lib/requestcore/requestcore.class.php on line 276 The stream size for the streaming upload cannot be determined. done Syncing [2411/4732] img2343435.jpg Warning: fopen(/var/www/xx/wp-content/uploads/2010/12/mg2343435.jpg) [function.fopen]: failed to open stream: No such file or directory in [filepath]/lib/awssdk/lib/requestcore/requestcore.class.php on line 527
What OS you running? As this actually sounds like an AWS php sdk issue. Having a look though their source code shows they don't seem to use fclose and your OS must have a limit on open files. If you email me at iain.cambridge - at - fubra.com I'll send you a copy of the sdk with a bug fix aswell.
Errors when using CDN Sync Tool plugin
wordpress
I'm trying to uplaod video files,my upload file size limit is 96mb,and I can upload videos until 10mb size,but I want to uplaod videos that have 20mb size.If I try to uplaod bigger video I get http error,I found on web a lot of solutions but none of them acctualy help me.Is there any other solution how to fix http uplaod error and uplaod bigger files on my wordpress site? I have tried every thing from there links : http://wordpress.org/support/topic/http-error-on-image-upload-still http://wordpress.org/support/topic/flash-uploader-logs-out-during-crunching-phase http://wordpress.org/support/topic/http-error-image-upload Tnx in advance. Anybody have idea why is this happening ?
Are you on shared hosting by any chance? Shared hosts tend to limit the max uploadable file size on their end and there is nothing you can add to your scripts to change that. If not, then I am mistaken and this is not the solution you are looking for. However, if you are on shared hosting it might pay to contact them and ask them the max allowed file sizes they allow their shared hosting accounts to have. Some hosts however let you create a php.ini file, drop it into your site root directory set some hosting variables like upload limits, etc. Try creating a file called 'php.ini' without the quotes and put in the following: <code> upload_max_filesize = 64M post_max_size = 64M </code> Then place the php.ini file you just created into your Wordpress root directory. A good way to see if it is your host or Wordpress installation is to create a simple file uploading test and then try uploading the same file. If you have the same issue, it isn't Wordpress and is your server configuration. Create a page called "file.php" and then add in the following code: <code> &lt;form enctype="multipart/form-data" action="upload.php" method="POST"&gt; &lt;input type="hidden" name="MAX_FILE_SIZE" value="512000" /&gt; Send this file: &lt;input name="userfile" type="file" /&gt; &lt;input type="submit" value="Send File" /&gt; &lt;/form&gt; </code> Now create a file called "upload.php" and add in the following: <code> &lt;?php $uploaddir = 'uploads'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); echo "&lt;p&gt;"; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Upload failed"; } echo "&lt;/p&gt;"; echo '&lt;pre&gt;'; echo 'Here is some more debugging info:'; print_r($_FILES); print "&lt;/pre&gt;"; ?&gt; </code> Example code taken from here: http://snippets.dzone.com/posts/show/3729 Now see if that lets you upload a large file. If not, then we'll further try and debug your Wordpress installation to try and rectify the issue.
wordpress upload http error?
wordpress
In wp-admin when I enter widgets I see their bars, but the titles of widgets are missing. only :Something remain visible and the others are gone. What happened? How do I fix that? Edit: Found it in wp-admin/includes/widgets.php line that was <code> &lt;div class="widget-title"&gt;&lt;h4&gt;&lt;?php $widget_title ?&gt;&lt;span class="in-widget-title"&gt;&lt;/span&gt;&lt;/h4&gt;&lt;/div&gt; </code> should be <code> &lt;div class="widget-title"&gt;&lt;h4&gt;&lt;?php echo $widget_title ?&gt;&lt;span class="in-widget-title"&gt;&lt;/span&gt;&lt;/h4&gt;&lt;/div&gt; </code> Is that a wordpress bug or somebody on my team had to edit this? [noone takes the blame ;)]
Just to make sure, I took a look in the actual source code of the WordPress repository. The line in question is: <code> &lt;div class="widget-title"&gt;&lt;h4&gt;&lt;?php echo $widget_title ?&gt;&lt;span class="in-widget-title"&gt;&lt;/span&gt;&lt;/h4&gt;&lt;/div&gt; </code> I also went through and checked previous changesets to see if we ever accidentally released broken code. If you want to look at the revision log yourself, it's freely available on Trac . But the long story made short is that you weren't seeing a WordPress bug. Someone on your team would have had to explicitly made that change ... even if they weren't willing to take the blame. All the more reason you should be keeping everything under source control. Then you'd know exactly who made the change, when, and possibly have some idea as to why.
Wp-admin widgets have no title texts
wordpress
I've created a custom post type. It requires a file to be uploaded. I found the following tutorial which I've successfully adapted to do what I need with one exception: http://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/ The tutorial provides JavaScript code to override the "send to editor" button, however that's not what I want to do. I want to set the filename as a meta value of the post so I can pull it out in my display template. Ideally I want to display another custom link in the file upload thickbox, similar to "set as post thumbnail", which will do this. My custom JavaScript file contains this (the first function has been customised to my post type, the second hasn't): <code> jQuery(document).ready(function() { jQuery('#upload_resource_button').click(function() { formfield = jQuery('#upload_resource').attr('name'); tb_show('', 'media-upload.php?type=file&amp;amp;TB_iframe=true'); return false; }); window.send_to_editor = function(html) { imgurl = jQuery('img',html).attr('src'); jQuery('#upload_image').val(imgurl); tb_remove(); } }); </code> If I need an additional hidden field to assign the filename back to, I can probably work that out - really what I need to know is what hook to use to add a new link to the thickbox to use instead of "Send To Editor". I hope that makes sense - I'm not sure of all the correct terminology. Thanks!
i cant say I've tried this but if you have the url of the file and all you need is the file name then you can just change your code from this: <code> window.send_to_editor = function(html) { imgurl = jQuery('img',html).attr('src'); jQuery('#upload_image').val(imgurl); tb_remove(); } </code> to this: <code> window.send_to_editor = function(html) { imgurl = jQuery('img',html).attr('src'); filename = substring(imgurl.lastIndexOf('/'), imgurl.length); jQuery('#upload_resource').val(filename); tb_remove(); } </code> and this way your "send to editor" button will insert just the file name.
Custom post type with file upload - need to "set as field" instead of "send to editor"
wordpress
I have to add forum feature in my wordpress blog.I see bbpress but would like to add forum similar to stackexchange or stackoverflow. Please let me know.
Plugins: Question and Answer Forum Plugin WP-Answers Plugin Themes: AskIt Instant Q&amp;A
Open Source Forum for wordpress similar to stackexchange or stackoverflow
wordpress
I have searched high and low for a simple solution to this, but to no avail. Wordpress keeps on wrapping my images in p tags and because of the eccentric nature of the layout for a site I am working on, this is highly annoying. I have created a jQuery solution to unwrap images, but it isn't that great. It lags because of other stuff loading on the page and so the changes are slow to be made. Is there a way to prevent Wordpress wrapping just images with p tags? A hook or filter perhaps that can be run. This is happening when uploading an image and then inserting it into the WYSIWYG editor. Manually going into the code view and removing the p tags is not an option as the client is not that technically inept. I understand that images are inline, but the way I have the site coded images are inside of divs and set to block, so they are valid code.
here's what we did yesterday on a client site that we were having this exact problem with... I created a quick filter as a plugin and activated it. <code> &lt;?php /* Plugin Name: Image P tag remover Description: Plugin to remove p tags from around images in content outputting, after WP autop filter has added them. (oh the irony) Version: 1.0 Author: Fublo Ltd Author URI: http://fublo.net/ */ function filter_ptags_on_images($content) { // do a regular expression replace... // find all p tags that have just // &lt;p&gt;maybe some white space&lt;img all stuff up to /&gt; then maybe whitespace &lt;/p&gt; // replace it with just the image tag... return preg_replace('/&lt;p&gt;(\s*)(&lt;img .* \/&gt;)(\s*)&lt;\/p&gt;/iU', '\2', $content); } // we want it to be run after the autop stuff... 10 is default. add_filter('the_content', 'filter_ptags_on_images'); </code> If you drop that into a php file in your /wp-content/plugins folder and then activate it, it should remove the p tags from any para that just contains an image. I'm not sure how strong the regexp is in terms of if it will fail with outputs from other editors - for example if the img tag is closed with just > it will fail. If anyone has anything stronger, that would be really helpful. Cheers, James --- Improved filter --- To work with images that are wrapped in links, it keeps the links in the output and removes the p tags. <code> return preg_replace('/&lt;p&gt;\s*(&lt;a .*&gt;)?\s*(&lt;img .* \/&gt;)\s*(&lt;\/a&gt;)?\s*&lt;\/p&gt;/iU', '\1\2\3', $content); </code>
Stop Wordpress Wrapping Images In A "P" Tag
wordpress
What do i need to do to enable categories and tags for a custom post type i´ve made? I use the following code: <code> /* Create custom post type: "Tilbud" */ register_post_type('tilbud', array( 'label' =&gt; __('Tilbud'), 'singular_label' =&gt; __('Tilbud'), 'public' =&gt; true, 'show_ui' =&gt; true, 'capability_type' =&gt; 'post', 'hierarchical' =&gt; false, 'rewrite' =&gt; false, 'query_var' =&gt; false, 'supports' =&gt; array('title') )); </code>
It worked when I added the following code: <code> function add_tags_categories() { register_taxonomy_for_object_type('category', 'tilbud'); register_taxonomy_for_object_type('post_tag', 'tilbud'); } add_action('init', 'add_tags_categories'); </code>
tags & categories with custom post type
wordpress
In wordpress 3.1 they finally added the option of allowing posts belonging to a custom post type to be marked as "sticky"... what I can't figure out though is how to enable this so the admin menu option shows up. I was thinking it might have something to do with the "supports" argument when the post type is defined in the functions.php file however I can't find any references. Any I on how I can get these sticky options to show up in the admin area?
As noted in the trac ticket, you need to add that UI element in yourself. If you're still looking for it, I made a plugin to add custom post type sticky support, available here: http://www.superann.com/sticky-custom-post-types/
Wordpress 3.1 - How does one add sticky post capabilities to post types
wordpress
I'm looking for an easy way to place the user registration form on the front-end of a WordPress site. I've already used wp_login_form() to place the login form on the front end, but now I need to do the same with the signup form. Any ideas?
Jeff Starr wrote a great tutorial on front-end registration, login and password recovery taking the similar approach as stackexchange-url ("suggested by onetrickpony"). So take this as a follow up to his answer and as another resource that might help you get it done: http://digwp.com/2010/12/login-register-password-code/ Now you have two examples how to code this yourself and trust me - it's definitely worth doing it this (your own) way. It's not that hard and it gives you freedom , flexibility and reusability that no plugin can offer.
Front-end Register Form
wordpress
I'm currently writing my first plugin, which will let the site admin/editor use a different image as a background/header for each post/page, and I would also like to have defaults for each category. Here is where I'm not sure how to proceed: If for each post/page the image (which is an attachment, so is just an id in the db) is a simple post meta field, there is no such (implicit) thing for categories. So there are more ways to go: Create an option for every category - something like <code> background_cat_$id_ </code> Add the categories which correspond to a certain image to the attachment post ( <code> corresponding_cats </code> ? ) Modify the term_taxonomy table to add a column (last resort? bad design?) Right now I believe I'll go with my first option but I'm really curios how you handle such issues.
Best way would be to use this plugin: http://wordpress.org/extend/plugins/simple-term-meta/
Best/Correct way to add an option to a category
wordpress
I have a plugin that sets up a custom rewrite rule. I can access the short URL and the content is returned correctly, but the HTTP response is <code> 404, Page not found </code> . From searching the web it seems like WordPress is returning 404, because it thinks this is not a valid WP page (http://wordpress.org/support/topic/404-on-custom-non-wordpress-pages). Is there a recommended solution to this problem? How can I get WP to return a normal status code for a rewritten URL? <code> global $wp_rewrite; add_rewrite_rule('list-data$', '/wp-content/plugins/data-lister/list-data.php', 'top'); </code> Thanks! Mark
This has been an issue in core for a while, http://core.trac.wordpress.org/ticket/10722 . The simplest solution is to just overwrite the headers on 'template_redirect'. You can replace them as long as you haven't started any output yet, which you shouldn't have at this point. Just call status_header( 200 ); No cache headers are also sent when the WP Class sends the 404 headers, so you'll probably want to replace those with information based on the content you're pulling from that PHP page.
Custom rewrite rule serves content, but returns 404 error code
wordpress
I'm planning a site for a client who wants users to be able to filter upcoming events by the following criteria: Type i.e. Comedy, Theatre, Music etc. Date Daily or Weekend Duration Daily or Half day I want to delve into Custom posts more, so will set up a Custom Post Type for 'Events' (non-hierarchical) and when creating a new post I'll add Custom Fields for Type, Date and Duration. The question I have is how would I use query_posts() to: List the events so that the soonest (i.e. next event to occur) appears first and later events last? Filter by multiple meta values (Type, Date and Duration)? I presume I need to create a series of options in my form's dropdown lists based on the custom field values right? I've created a list of Events for a client before, but with no filtering possibilities. I used this query_posts() code to get the custom posts and order things: <code> // List the events by custom field 'Date': $todaysDate = date('Y/m/d'); // set todays date to check against custom field // query posts query_posts('post_type=Event&amp;meta_key=Date&amp;meta_compare=&gt;=&amp;meta_value=' . $todaysDate . '&amp;orderby=meta_value&amp;order=ASC'); </code> However, I can't see how I might change this code to filter by multiple custom fields...any ideas? Thanks
you can use custom taxonomies and make you query_posts much easier! by that i mean create a custom taxonomy for type,duration like so: <code> add_action('init','register_event_tax'); function register_event_tax(){ register_taxonomy('even_type',array('events'), array( 'hierarchical' =&gt; false, 'labels' =&gt; 'type', 'show_ui' =&gt; true, 'query_var' =&gt; true, 'rewrite' =&gt; array( 'slug' =&gt; 'type' ), )); register_taxonomy('even_duration',array('events'), array( 'hierarchical' =&gt; false, 'labels' =&gt; 'type', 'show_ui' =&gt; true, 'query_var' =&gt; true, 'rewrite' =&gt; array( 'slug' =&gt; 'duration' ), )); } </code> then you can query posts like this: <code> query_posts('post_type=Event&amp;duration=DAILY&amp;type=COMEDY&amp;meta_key=Date&amp;meta_compare=&gt;=&amp;meta_value=' . $todaysDate . '&amp;orderby=meta_value&amp;order=ASC'); </code> and you can change the duration and type to filter what ever type or duration you want. hope this helps.
How to filter custom posts by tags and custom fields?
wordpress
I have a site with CPT (short for custom post type) "bagp_deals" and custom taxonomies "ba_locations" and "ba_cats" basically Its post type of "Deals" with "Location" and "Categories" as hierarchical taxonomies. On the default edit screen i want to limit the selection to just one of each (one location and one category) and i'm trying to do that with JQuery, i notice that the field custom taxonomy of ba_locations is named "tax_input[ba_locations][]" and so far i have this code: <code> jQuery("input[name=tax_input[ba_locations][]]").click(function () { selected = jQuery("input[name=tax_input[ba_locations][]]").filter(":checked").length; if (selected &gt; 1){ jQuery("input[name=tax_input[ba_locations][]]").each(function () { jQuery(this).attr("checked", false); }); jQuery(this).attr("checked", true); } }); </code> witch is suppose to limit the checkbox selection to one. For some reason i can't get this to work. The Question So the question is why isn't this working ? or do you have a better solution to limit the selection to just one? any help is appreciated. update: this is the working code i used: <code> jQuery("input[name=\"tax_input[ba_locations][]\"]").click(function () { selected = jQuery("input[name=\"tax_input[ba_locations][]\"]").filter(":checked").length; if (selected &gt; 1){ jQuery("input[name=\"tax_input[ba_locations][]\"]").each(function () { jQuery(this).attr("checked", false); }); jQuery(this).attr("checked", true); } }); </code>
Instead of hacking it with jQuery, a more reliable solution would be to replace the meta box with your own, in PHP. Anyway, the problem is most likely with the '[' and ']' characters in the selector: <code> "input[name=tax_input[ba_locations][]]" </code> could be rewritten as <code> "input[name=tax_input\\[ba_locations\\]\\[\\]]" </code> See stackexchange-url ("stackexchange-url
limit selection of custom taxonomies to one?
wordpress
I am new to using subversion, trac and do not clearly understand how the wordpress plugin repository works. When committing WP Responder I put all the files in a directory called "trunk" and committed it to the server. It worked. It may be useful to make previous versions of the plugin available for download. So I copied all the files from a previous version (4.9) as well as the current version (4.9.5.1) and placed it in the "tags" directory of the repository. So tags had two directories: 4.9 and 4.9.5.1. The 4.9.5.1 had the same content as the trunk directory. When I did this the downloadable archive had only the php files directly under the trunk directory and not the sub directories that are part of plugin. So I had to removed all the directories within the tags directory to restore it to the previous state. What am I doing wrong? How can I make previous versions available for download?
See Task 3: "Tagging" a new version: http://wordpress.org/extend/plugins/about/svn/
How to make previous versions available for users?
wordpress
I'm using WordPress 3.0 Menus, which the WPML (wordpress multilingual) plugin claims to have added support for in a recent release . I am using the most current version of the plugin. My problem is that using the following to call my nav menus <code> &lt;?php wp_nav_menu( array( 'theme_location' =&gt; 'primary', 'container_class' =&gt; 'menu-header', 'menu_id' =&gt; 'menu-primary-navigation' ) ); ?&gt; </code> is pulling up only the English translation of the menu. Here is an image of the WPML admin panel and how the menus are setup multilingual: [link to image] http://cl.ly/42RW [link to image] http://cl.ly/42o0 You can see the site currently in development: http://anasmadance.com.s66112.gridserver.com/ The problem is that when you go to the French translated page, the menu is still in English (despite the fact that I've already set up the French menu) http://anasmadance.com.s66112.gridserver.com/fr/
I ended up having to manually detect the language, here's how I solved it: <code> &lt;?php if (ICL_LANGUAGE_CODE == 'fr') { // display the menu en francais wp_nav_menu( array( 'menu' =&gt; 'Navigation principale', 'theme_location' =&gt; 'primary', 'container_class' =&gt; 'menu-header', 'menu_id' =&gt; 'menu-primary-navigation' ) ); } else { // show them the menu in English wp_nav_menu( array( 'menu' =&gt; 'Primary Navigation', 'theme_location' =&gt; 'primary', 'container_class' =&gt; 'menu-header', 'menu_id' =&gt; 'menu-primary-navigation' ) ); }; ?&gt; </code>
WPML Plugin Not displaying multilingual Menus
wordpress
I, like many others, have numerous links all over my website. Some are in the body, some are in the sidebars, some are in comments. When links go to an external site, I would very much like to have that website's favicon appear to the left of the link. I have seen this in many places. E.g a link to Wikipedia page, should have that wikipedia favicon. The plugin File Icons appears to do that, but for file types (you link to a PDF, you get a PDF icon). But the question is, how do you do this for general types of links? You could add URLS to the File Icons plugin by hand, but that is a pain, and I have heard of Google's S2 which should find most fav icons automatically. So my question is; is there a plugin that will auto find any links on a post/page/etc. and insert the URL's fav icon to the left of the text?
(from the closing duplicate) I typed this plugin very quickly during posting this... It seems to work, see http://leau.co (where I quickly tested it) or http://edward.de.leau.net (where I have tested it against more links in the post content) e.g. see the bottom left sidebar or some posts with multiple links in it. Hmmm, I will add in v0.3: caching file types to ignore if i find out how a different default icon urls to ignore Notes: Get it here : http://wordpress.org/extend/plugins/wp-favicons/ (v.0.1) If there are additional RFC/Bugs other than above (TODO) drop a comment :) Styling can be done in the admin pages Update: In the meanwhile it is to version 0.4.8 and scans pages directly for icon tags, /favicon.ico in root, checks google and other provides. IT also can replace content in any area where filters are provided, there is after processing support for the image such as auto png conversion, can excluded urls by extension, provides defaults such as identicons and has a cache. version 0.4.8 temporarily disables ALL of this (read http://wp.leau.co/2011/03/04/wp-favicons-part-1-preventing-duplication-of-meta-data-attached-to-uris-such-as-favicons/ ) except for 'check google' so lets wait for 0.4.9 which gets it going again.
Plugin that inserts favicon next to links
wordpress
I need to get posts that have two meta-values. It tried the following code, but this is getting empty result <code> &lt;?php $featuredquery = " SELECT wposts.* FROM $wpdb-&gt;posts wposts, $wpdb-&gt;postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND (wpostmeta.meta_key = 'article_level' AND wpostmeta.meta_value = 'Hovedsak') AND (wpostmeta.meta_key = 'article_genre' AND wpostmeta.meta_value = 'X6.no (Spill og underholdning)') AND wposts.post_status = 'publish' AND wposts.post_type = 'post' AND wposts.post_date &lt; NOW() ORDER BY wposts.post_date DESC LIMIT 0 , 4 "; $featuredposts = $wpdb-&gt;get_results($featuredquery, OBJECT); ?&gt; </code> Any ideas for this? I tried searching around, but didn't find anything that suited me.. :/ Thanks for all help
I'm not an SQL expert, but I would think you might have to JOIN twice to pick two distinct rows out of <code> wp_postmeta </code> : <code> $featuredquery = " SELECT wposts.* FROM $wpdb-&gt;posts wposts JOIN $wpdb-&gt;postmeta article_level ON ( wposts.ID = article_level.post_id AND article_level.meta_key = 'article_level' ) JOIN $wpdb-&gt;postmeta article_genre ON ( wposts.ID = article_genre.post_id AND article_genre.meta_key = 'article_genre' ) WHERE article_level.meta_value = 'Hovedsak' AND article_genre.meta_value = 'X6.no (Spill og underholdning)' AND wposts.post_status = 'publish' AND wposts.post_type = 'post' AND wposts.post_date &lt; NOW() ORDER BY wposts.post_date DESC LIMIT 0 , 4 "; </code>
Custom query, multiple custom keys
wordpress
My question is actually quite simple, but I think there are a number of answers to choose from: If one were to use WordPress, what would be the most elegant way of creating a part of the website that has "People Profiles", whereby; they can update their own mini-blog, add images, assign them a multitude of taxonomies, etc. (basically having a very light version of Facebook functionality plus some e-commerce products specific to the person). Scalability would obviously be key too, would need to work for 10, 100, 1000+ profiles. I think my first instinct would be to try and go with BuddyPress as a support application from which these profiles would originate, but there are possibly other solutions? What do you think? Thank you!
You can accomplish that with: a regular instal of WordPress but with a lot of work and hacking around to get it where you want. a multisite install of WordPress that would make it a bit easier but still a lot of work and customization. a fairly easy case with BuddyPress. Basically it just installing BuddyPress ,some plugins and configuring it a bit not only the profiles but also the mini-blogs,multitude of taxonomies,images and e-commerce products specific to the person. its just for that. So I'd say your best of with BuddyPress, and why not?
How-to leverage WordPess for creating Extended Social Profiles
wordpress
I'm look for a custom SQL query that will let me pull in the latest comments from across a WP multi-site install. The end result will be identical to a regular recent comments widget, but from all sites within the installation. Ideas? Thanks
Ok, I did some research based on stackexchange-url ("בניית אתרים")'s solution here, as I'm interested in this too. First you need to get a list of blog IDs, and <code> get_blog_list() </code> is deprecated because it seems to be a " suicidal database query " :) Anyway looks like there will be a alternative in WP 3.2 called wp_get_sites() . So use this function instead. I suggest you pass the <code> 'sort_column =&gt; 'last_updated' </code> argument, and <code> 'limit' </code> the results to 20 or something like that. This would make the next query much faster. So: <code> global $wpdb; $number = 20; // maximum number of comments to display $selects = array(); foreach (wp_get_sites() as $blog) // select only the fields you need here! $selects[] = "(SELECT comment_post_ID, comment_author, comment_author_email, comment_date_gmt, comment_content, post_title, {$blog['blog_id']} as blog_id FROM {$wpdb-&gt;base_prefix}{$blog['blog_id']}_comments LEFT JOIN {$wpdb-&gt;base_prefix}{$blog['blog_id']}_posts ON comment_post_id = id WHERE post_status = 'publish' AND post_password = '' AND comment_approved = '1' AND comment_type = '' ORDER BY comment_date_gmt DESC LIMIT {$number})"; // real number is (number * # of blogs) $comments = $wpdb-&gt;get_results(implode(" UNION ALL ", $selects)." ORDER BY comment_date_gmt DESC", OBJECT); </code> Then render the output: <code> &lt;ul&gt; &lt;?php $count = 0; foreach((array)$comments as $comment): $count++; if($count == $number+1) break; ?&gt; &lt;li&gt; &lt;?php echo get_avatar($comment-&gt;comment_author_email, 32); ?&gt; &lt;a href="&lt;?php echo get_blog_permalink($comment-&gt;blog_id, $comment-&gt;comment_post_ID); ?&gt;" title="commented on &lt;?php echo strip_tags($comment-&gt;post_title); ?&gt;"&gt; &lt;?php echo $comment-&gt;comment_author; ?&gt; wrote: &lt;?php echo convert_smilies(wp_trim_excerpt($comment-&gt;comment_content)); ?&gt; (&lt;?php echo human_time_diff(strtotime("{$comment-&gt;comment_date_gmt}")); ?&gt;) &lt;/a&gt; &lt;/li&gt; &lt;?php endforeach; ?&gt; &lt;/ul&gt; </code> You should also cache the results, and flush the cache like once every 10 minutes or so.
List Recent Comments from Across a Multi-site Network
wordpress
I have a Wordpress Network that I am tasked with disabling the WP Cron and replacing it with an Apache Cron. I have set up a PHP script that when called by an Apache Cron will loop through all sites under the network and make a request to that site's wp-cron.php page, thus executing its cron. I would like to use Wordpress' transient feature to limit my PHP script as Wordpress limits its own cron. However, when I dig into the code I see the doing_cron transient is set ( in cron.php #217 ) but never unset. Is the transient ever unset or does Wordpress wait 60 seconds to fire up the cron again ( in cron.php #200 ) Any thoughts on the doing_cron transient or perhaps another means to throttle my cron script would be appreciated.
Transients expire on their own. No need to unset them. And to call wp-cron manually is simple. Just define DISABLE_WP_CRON to true in the wp-config file to disable the normal cron spawning process. Then make your cron system hit wp-cron.php manually every so often to process pending jobs. There is no other special trick that you need to do. No need to fool around with transients or special coding.
wp-cron.php - How are WP's Cron transients removed?
wordpress
Can add_filter() be used to intercept a plugin function? I'm not having any success, so I'm thinking perhaps I'm doing this wrong. The plugin is "All in One SEO" and the function I'm trying to intercept is in the All_in_One_SEO_Pack class and its called get_original_title() Here's the code I'm trying to intercept...specifically, when the is_404() method is called... <code> class All_in_One_SEO_Pack { function rewrite_title($header) { global $aioseop_options; global $wp_query; if (!$wp_query) { $header .= "&lt;!-- no wp_query found! --&gt;\n"; return $header; } $post = $wp_query-&gt;get_queried_object(); // the_search_query() is not suitable, it cannot just return global $s; global $STagging; if (is_home() &amp;&amp; !$this-&gt;is_static_posts_page()) { $title = $this-&gt;internationalize($aioseop_options['aiosp_home_title']); if (empty($title)) { $title = $this-&gt;internationalize(get_option('blogname')); } $title = $this-&gt;paged_title($title); $header = $this-&gt;replace_title($header, $title); } else if (is_attachment()) { $title = get_the_title($post-&gt;post_parent).' '.$post-&gt;post_title.' – '.get_option('blogname'); $header = $this-&gt;replace_title($header,$title); } else if (is_single()) { // we're not in the loop :( $authordata = get_userdata($post-&gt;post_author); $categories = get_the_category(); $category = ''; if (count($categories) &gt; 0) { $category = $categories[0]-&gt;cat_name; } $title = $this-&gt;internationalize(get_post_meta($post-&gt;ID, "_aioseop_title", true)); if (!$title) { $title = $this-&gt;internationalize(get_post_meta($post-&gt;ID, "title_tag", true)); if (!$title) { $title = $this-&gt;internationalize(wp_title('', false)); } } $title_format = $aioseop_options['aiosp_post_title_format']; /* $new_title = str_replace('%blog_title%', $this-&gt;internationalize(get_bloginfo('name')), $title_format); $new_title = str_replace('%blog_description%', $this-&gt;internationalize(get_bloginfo('description')), $new_title); $new_title = str_replace('%post_title%', $title, $new_title); $new_title = str_replace('%category%', $category, $new_title); $new_title = str_replace('%category_title%', $category, $new_title); $new_title = str_replace('%post_author_login%', $authordata-&gt;user_login, $new_title); $new_title = str_replace('%post_author_nicename%', $authordata-&gt;user_nicename, $new_title); $new_title = str_replace('%post_author_firstname%', ucwords($authordata-&gt;first_name), $new_title); $new_title = str_replace('%post_author_lastname%', ucwords($authordata-&gt;last_name), $new_title); */ $r_title = array('%blog_title%','%blog_description%','%post_title%','%category%','%category_title%','%post_author_login%','%post_author_nicename%','%post_author_firstname%','%post_author_lastname%'); $d_title = array($this-&gt;internationalize(get_bloginfo('name')),$this-&gt;internationalize(get_bloginfo('description')),$title, $category, $category, $authordata-&gt;user_login, $authordata-&gt;user_nicename, ucwords($authordata-&gt;first_name), ucwords($authordata-&gt;last_name)); $title = trim(str_replace($r_title, $d_title, $title_format)); // $title = $new_title; // $title = trim($title); $title = apply_filters('aioseop_title_single',$title); $header = $this-&gt;replace_title($header, $title); } else if (is_search() &amp;&amp; isset($s) &amp;&amp; !empty($s)) { if (function_exists('attribute_escape')) { $search = attribute_escape(stripcslashes($s)); } else { $search = wp_specialchars(stripcslashes($s), true); } $search = $this-&gt;capitalize($search); $title_format = $aioseop_options['aiosp_search_title_format']; $title = str_replace('%blog_title%', $this-&gt;internationalize(get_bloginfo('name')), $title_format); $title = str_replace('%blog_description%', $this-&gt;internationalize(get_bloginfo('description')), $title); $title = str_replace('%search%', $search, $title); $header = $this-&gt;replace_title($header, $title); } else if (is_category() &amp;&amp; !is_feed()) { $category_description = $this-&gt;internationalize(category_description()); if($aioseop_options['aiosp_cap_cats']){ $category_name = ucwords($this-&gt;internationalize(single_cat_title('', false))); }else{ $category_name = $this-&gt;internationalize(single_cat_title('', false)); } //$category_name = ucwords($this-&gt;internationalize(single_cat_title('', false))); $title_format = $aioseop_options['aiosp_category_title_format']; $title = str_replace('%category_title%', $category_name, $title_format); $title = str_replace('%category_description%', $category_description, $title); $title = str_replace('%blog_title%', $this-&gt;internationalize(get_bloginfo('name')), $title); $title = str_replace('%blog_description%', $this-&gt;internationalize(get_bloginfo('description')), $title); $title = $this-&gt;paged_title($title); $header = $this-&gt;replace_title($header, $title); } else if (is_page() || $this-&gt;is_static_posts_page()) { // we're not in the loop :( $authordata = get_userdata($post-&gt;post_author); if ($this-&gt;is_static_front_page()) { if ($this-&gt;internationalize($aioseop_options['aiosp_home_title'])) { //home title filter $home_title = $this-&gt;internationalize($aioseop_options['aiosp_home_title']); $home_title = apply_filters('aioseop_home_page_title',$home_title); $header = $this-&gt;replace_title($header, $home_title); } } else { $title = $this-&gt;internationalize(get_post_meta($post-&gt;ID, "_aioseop_title", true)); if (!$title) { $title = $this-&gt;internationalize(wp_title('', false)); } $title_format = $aioseop_options['aiosp_page_title_format']; $new_title = str_replace('%blog_title%', $this-&gt;internationalize(get_bloginfo('name')), $title_format); $new_title = str_replace('%blog_description%', $this-&gt;internationalize(get_bloginfo('description')), $new_title); $new_title = str_replace('%page_title%', $title, $new_title); $new_title = str_replace('%page_author_login%', $authordata-&gt;user_login, $new_title); $new_title = str_replace('%page_author_nicename%', $authordata-&gt;user_nicename, $new_title); $new_title = str_replace('%page_author_firstname%', ucwords($authordata-&gt;first_name), $new_title); $new_title = str_replace('%page_author_lastname%', ucwords($authordata-&gt;last_name), $new_title); $title = trim($new_title); $title = $this-&gt;paged_title($title); $title = apply_filters('aioseop_title_page',$title); $header = $this-&gt;replace_title($header, $title); } } else if (function_exists('is_tag') &amp;&amp; is_tag()) { global $utw; if ($utw) { $tags = $utw-&gt;GetCurrentTagSet(); $tag = $tags[0]-&gt;tag; $tag = str_replace('-', ' ', $tag); } else { // wordpress &gt; 2.3 $tag = $this-&gt;internationalize(wp_title('', false)); } if ($tag) { $tag = $this-&gt;capitalize($tag); $title_format = $aioseop_options['aiosp_tag_title_format']; $title = str_replace('%blog_title%', $this-&gt;internationalize(get_bloginfo('name')), $title_format); $title = str_replace('%blog_description%', $this-&gt;internationalize(get_bloginfo('description')), $title); $title = str_replace('%tag%', $tag, $title); $title = $this-&gt;paged_title($title); $header = $this-&gt;replace_title($header, $title); } } else if (isset($STagging) &amp;&amp; $STagging-&gt;is_tag_view()) { // simple tagging support $tag = $STagging-&gt;search_tag; if ($tag) { $tag = $this-&gt;capitalize($tag); $title_format = $aioseop_options['aiosp_tag_title_format']; $title = str_replace('%blog_title%', $this-&gt;internationalize(get_bloginfo('name')), $title_format); $title = str_replace('%blog_description%', $this-&gt;internationalize(get_bloginfo('description')), $title); $title = str_replace('%tag%', $tag, $title); $title = $this-&gt;paged_title($title); $header = $this-&gt;replace_title($header, $title); } } else if (is_archive()) { $date = $this-&gt;internationalize(wp_title('', false)); $title_format = $aioseop_options['aiosp_archive_title_format']; $new_title = str_replace('%blog_title%', $this-&gt;internationalize(get_bloginfo('name')), $title_format); $new_title = str_replace('%blog_description%', $this-&gt;internationalize(get_bloginfo('description')), $new_title); $new_title = str_replace('%date%', $date, $new_title); $title = trim($new_title); $title = $this-&gt;paged_title($title); $header = $this-&gt;replace_title($header, $title); } else if (is_404()) { $title_format = $aioseop_options['aiosp_404_title_format']; $new_title = str_replace('%blog_title%', $this-&gt;internationalize(get_bloginfo('name')), $title_format); $new_title = str_replace('%blog_description%', $this-&gt;internationalize(get_bloginfo('description')), $new_title); $new_title = str_replace('%request_url%', $_SERVER['REQUEST_URI'], $new_title); $new_title = str_replace('%request_words%', $this-&gt;request_as_words($_SERVER['REQUEST_URI']), $new_title); $new_title = str_replace('%404_title%', $this-&gt;internationalize(wp_title('', false)), $new_title); $header = $this-&gt;replace_title($header, $new_title); } return $header; }} </code>
It is, but you're doing this wrong. I'm not familiar with that plugin, but chances are it's hooking into the wp_title hook. You should be able to a) call remove_filter() from your theme to disable the plugin's title manipulation, and/or b) override the result returned by the plugin by plugging into the same hook (just make sure your "priority" is "higher", i.e. your function gets called later).
Is it possible to use add_filter from a theme to alter a plugin's function?
wordpress
I would like to create a theme options page based only on changing the site wide CSS styling. For instance body/container background colors, font-sizes, font colors, etc. I have accomplished this by using a stylesheet link to a php file in the header that echo's the CSS and uses get_option. For instance <code> background-color: &lt;?php echo get_option('background_color'); ?&gt;; </code> Would I be correct in assuming this is a bad idea performance wise if there are many options? I have tried other methods but they all seem to add inline or embedded styles, which I do not want, how would one get around this? Would creating a custom script that writes to the static CSS file be a good idea? Is there any way the settings API can handle this? ** PS. Great answer but I have decided to actually go with writing to a static file as it provides way less overhead.
creating a custom script that writes to the static CSS file is a bad idea!!! you would need to regenerate the file each time you save any changes. a better solution would be to save all options in an array of options say for example: <code> $MyCSS['background_color'] = #009988; $MyCSS['background_repeat'] = no-repeat; update_option('theme_settings',$MyCSS); </code> and that why you only call the "get_option()" function once. <code> $MyCSS = get_option('theme_settings'); // and use : echo $MyCSS['background_color']; </code> and make much less calls to the database and use less resources if you are thinking performance wise.
Best practices for a Style/CSS based theme options page?
wordpress
I've been all over this site and google, and the WP codex looking for an answer to this one. I know it's out there, and I know it's easy. Maybe has something to do with user_nicename, but I just can't make it work. What I'm trying to do for the site I'm working on is eliminate any need and any ability for the user to see the backend of the blog. This means front-page everything: Login, Post, and if I can swing it - a dash board. I envision changing the "site admin" link on the wp login/logout code to link to a blog page called "User Dashboard" there, the user could view a list of their posts and comments. Really reaching for the stars, they should also be able to see a list of comments on their posts, and really really reaching for the stars - some kind of messaging system. I'm currently simply trying to get the post list down! I can't figure out how to return the_author post list based on a dynamic setting of where the request is coming from. IE: Only list the current logged in users posts/comments. There is a plugin called Full Author User List or something to that affect, that doesn't work anymore as it's outdated. Any help?
there you go, i'm not the only one trying to bring back-end functionality to the front-end. anyway its not that hard go to your "USER DASHBOARD" template's file and locate where the loop starts something like: <code> &lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt; </code> and just above it paste this code: <code> &lt;?php /* First get the user info */ get_currentuserinfo(); /* Then query_posts by user id */ query_posts(array('author'=&gt;$current_user-&gt;ID)); /* And Last just loop thrugh the posts */ ?&gt; </code> hope this helps :)
Post list based on the user that is logged in
wordpress
This question is a bit unique. It is in part a "challenge" I'm issuing to the WordPress team ( or anyone else ) related to trac tickets: #16048, #16050 and #16204. The Goal The goal is to get around the three (3) issues illustrated in the screenshot below when trying to modify the WordPress Admin menu section: Get the "Microsite" submenu page to be highlighted when editing an Attorney (for this we need to somehow be able to apply "current" to the submenu item,_ and some hooks in the _wp_menu_output() function would provide what's needed here) , Get the Attorney Menu Page link to link to <code> /wp-admin/edit.php?post_type=attorney </code> when editing an Attorney (and those same needed hooks in the _wp_menu_output() function could handle this) , and Get the "Microsite" link not to trigger a "You do not have sufficient permissions to access this page" error *(this is the nastiest one to resolve, and a hook on the return value of <code> user_can_access_admin_page() </code> could handle this issue nicely.) More than just my use-case These three (3) issues are for my use-case but their are emblematic of the issues related to configure the admin menus in WordPress. Several on the WordPress team said that it's easy and thus implied I'm missing something (which may be right) but I've looked at this problem for weeks and not figured out how to get around it so I created the plugin you see below ( also downloadable from Gist ) as the simplest use-case example of the issues. The code in <code> admin_menu2() </code> is rather hackish but that's pretty much what's required to modify the Admin Menus in WordPress. Note that I did not try to use the new <code> remove_menu_page() </code> nor the new <code> remove_submenu_page() </code> functions in 3.1 because it would have taken longer to create the plugin -- I already had the code in <code> admin_menu2() </code> from an existing project -- and I don't believe they would address the problem anyway. What do I need? I need one of two (2) things: A solution to the problems that I expose with this plugin and explain in this question and in the screenshot (BTW, I'll disqualify your solution if you use PHP Output Buffering to solve any part of this) , or To have the WordPress Team recognize that there is indeed a need for these hooks and to get them to reconsider their position on the tickets. How do you Take the Challenge? Download and install a pristine new copy of WordPress 3.1 (any revision will probably do) , Download, install and activate the "The Great WordPress Admin Menu Challenge of Jan 2011" plugin below (or download the plugin from Gist) , and then Follow the instructions found on the plugin page for this plugin (see the following screenshot) but basically load the screenshot you see above and then try to figure out the three (3) issues described: One Ray of Hope Fortunately Andrew Nacin of the WordPress team offered to look at this once I'd coded it so I'm primarily posting here for him to review and comment as well as having others to comment. I know he is busy but I do hope he (or even you) can take the time to install this plugin on a pristine install of v3.1 and see if he can resolve the issue. If you Agree the Challenge is Impossible? If after trying this challenge you come to the same conclusion as me, and if you'd like to see the WordPress Admin menus be more configurable please comment on these trac tickets (#16048 - #16050 - #16204) and vote this question up to show support for it. I'll Gladly Admit I Missed Something, If I Did Of course it's possible I could be completely brain dead on this and someone could point out exactly how to do it. Actually, I really hope that ends up being the case; I'd rather be wrong and have this working than vice-versa. And Here's the Plugin You can also downloadable if from Gist : <code> &lt;?php /* Plugin Name: The Great WordPress Admin Menu Challenge of Jan 2011 Description: &lt;em&gt;"The Great WordPress Admin Menu Challenge of Jan 2011"&lt;/em&gt; was inspired by the WordPress team's apparent lack of understanding of the problems addressed by trac tickets &lt;a href="http://core.trac.wordpress.org/ticket/16048"&gt;#16048&lt;/a&gt; and &lt;a href="http://core.trac.wordpress.org/ticket/16050"&gt;#16050&lt;/a&gt; &lt;em&gt;(See also: &lt;a href="http://core.trac.wordpress.org/ticket/16204"&gt;#16204&lt;/a&gt;)&lt;/em&gt; and suggestion that the &lt;a href="http://wordpress.org/extend/plugins/admin-menu-editor/&gt;Admin Menu Editor&lt;/a&gt; plugin handles the use-cases that the tickets address. Debate spilled over onto Twitter with participation from &lt;a href="http://twitter.com/nacin"&gt;@nacin&lt;/a&gt;, &lt;a href="http://twitter.com/aaronjorbin"&gt;@aaronjorbin&lt;/a&gt;, &lt;a href="http://twitter.com/petemall"&gt;@petemall&lt;/a&gt;, &lt;a href="http://twitter.com/westi"&gt;@westi&lt;/a&gt;, &lt;a href="http://twitter.com/janeforshort"&gt;@janeforshort&lt;/a&gt;, &lt;a href="http://twitter.com/PatchesWelcome"&gt;@PatchesWelcome&lt;/a&gt;; supportive comments from &lt;a href="http://twitter.com/ramsey"&gt;@ramsey&lt;/a&gt;, &lt;a href="http://twitter.com/brianlayman"&gt;@brianlayman&lt;/a&gt;, &lt;a href="http://twitter.com/TheLeggett"&gt;@TheLeggett&lt;/a&gt;, a retweeting of @nacin's simple yet &lt;em&gt;(AFAICT)&lt;/em&gt; insufficient solution by &lt;a href="http://twitter.com/vbakaitis"&gt;@vbakaitis&lt;/a&gt;, &lt;a href="http://twitter.com/Viper007Bond"&gt;@Viper007Bond&lt;/a&gt;, &lt;a href="http://twitter.com/nickopris"&gt;@nickopris&lt;/a&gt;, &lt;a href="http://twitter.com/Trademark"&gt;@Trademark&lt;/a&gt;, &lt;a href="http://twitter.com/favstar_pop"&gt;@favstar_pop&lt;/a&gt;, &lt;a href="http://twitter.com/designsimply"&gt;@designsimply&lt;/a&gt;, &lt;a href="http://twitter.com/darylkoop"&gt;@darylkoop&lt;/a&gt;, &lt;a href="http://twitter.com/iamjohnford"&gt;@iamjohnford&lt;/a&gt;, &lt;a href="http://twitter.com/markjaquith"&gt;@markjaquith&lt;/a&gt;, &lt;a href="http://twitter.com/JohnJamesJacoby"&gt;@JohnJamesJacoby&lt;/a&gt; and &lt;a href="http://twitter.com/dd32"&gt;@dd32&lt;/a&gt;. Also see &lt;a href="http://andrewnacin.com/2010/12/20/better-admin-menu-controls-custom-post-types-wordpress-3-1/#comment-6360"&gt;comments&lt;/a&gt; on @nacin's blog post entitled "&lt;em&gt;Better admin menu handling for post types in WordPress 3.1&lt;/em&gt;." &lt;strong&gt;The desired goal of the &lt;em&gt;"challenge"&lt;/em&gt;&lt;/strong&gt; is to simply either to find a solution that has eluded me or, to get those who are dismissing it as solvable without added hooks in WordPress to have a tangible example to explore in hopes they will recognize that there is indeed a need for at least some of the requested hooks. &lt;strong&gt;There are three (3) steps to the challenge:&lt;/strong&gt; 1.) Get the "Microsite" submenu page to be highlighted when editing an Attorney, 2.) Get the Attorney Menu Page link to link &lt;a href="/wp-admin/edit.php?post_type=attorney"&gt;here&lt;/a&gt; when editing an Attorney, and 3.) Get the "Microsite" link not to trigger a "You do not have sufficient permissions to access this page" error. Here is &lt;a href="http://mikeschinkel.com/websnaps/skitched-20110114-235302.png" target="_blank"&gt;&lt;strong&gt;a screenshot&lt;/strong&gt; that attempts to illustrate the callenge&lt;/a&gt;. The code can be found on gist &lt;a href="https://gist.github.com/780709"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt;. Activate it as a plugin in a WordPress 3.1 install and go &lt;a href="/wp-admin/post.php?post=10&amp;action=edit"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt; to see what the screenshot illustrates. &lt;strong&gt;Be sure to load the &lt;a href="http://mikeschinkel.com/websnaps/skitched-20110114-235302.png" target="_blank"&gt;screenshot&lt;/a&gt; in another browser tab or window first&lt;/strong&gt;. Author: Mike Schinkel Author URI: http://about.me/mikeschinkel Plugin URI: https://gist.github.com/780709 */ if (!class_exists('TheGreatWordPressAdminMenuChallenge')) { class TheGreatWordPressAdminMenuChallenge { static function on_load() { add_action('init',array(__CLASS__,'init')); add_action('admin_menu',array(__CLASS__,'admin_menu1')); // Simulates generic "Microsite" plugin add_action('admin_menu',array(__CLASS__,'admin_menu2'),100); // Simulates website-specific plugin add_action('post_row_actions',array(__CLASS__,'post_row_actions'),10,2); } static function post_row_actions($actions,$post) { $url = admin_url(self::this_microsite_url($post-&gt;ID)); $actions = array_merge(array('microsite'=&gt;"&lt;a href=\"{$url}\" title=\"Manage this Microsite\"&gt;Microsite&lt;/a&gt;"),$actions); return $actions; } static function the_microsite_editor() { echo "We are in the Microsite Editor for " . self::post_title(); } static function admin_menu1() { if (self::this_post_id() &amp;&amp; in_array(self::this_post_type(),array('attorney','practice_area'))) { add_submenu_page( self::this_parent_slug(), self::microsite_page_title(), self::microsite_page_title(), $capability = 'edit_posts', 'microsite', array($microsite,'the_microsite_editor') ); global $wp_post_types; $parent_type_meta = $wp_post_types[self::this_post_type()]; global $menu; $slug = false; foreach($menu as $index =&gt; $menu_page) if ($menu_page[0]===$parent_type_meta-&gt;label) { $slug = $menu_page[2]; break; } if ($slug) { global $pagenow; global $submenu; // Setting this makes gives the link to the microsite in the menu the highlight for "current" menu option global $submenu_file; $submenu_file = self::this_microsite_url(); $index = end(array_keys($submenu[$slug])); $submenu[$slug][$index][12] = $submenu_file; } } } static function this_parent_slug() { return "edit.php?post_type=" . self::this_post_type(); } static function post_title() { $post_id = self::this_post_id(); return ($post_id ? get_post($post_id)-&gt;post_title : false); } static function microsite_page_title() { return 'Microsite for ' . self::post_title(); } static function this_post_type($get_post=true) { $post_type = (isset($_GET['post_type']) ? $_GET['post_type'] : false); if (!$post_type &amp;&amp; $get_post) { $post_id = self::this_post_id(); $post_type = get_post($post_id)-&gt;post_type; } return $post_type; } static function this_post_id() { $post_id = false; $post_type = self::this_post_type(false); if (isset($_GET[$post_type])) $post_id = intval($_GET[$post_type]); else if (isset($_GET['post'])) $post_id = intval($_GET['post']); return $post_id; } static function this_microsite_url($post_id=false) { $post_type = self::this_post_type(); $post_id = $post_id ? intval($post_id) : self::this_post_id(); return "edit.php?post_type={$post_type}&amp;page=microsite&amp;attorney={$post_id}"; } static function admin_menu2() { // The code required for this is super, nasty, ugly and shouldn't be, but at least it *is* doable global $menu; global $submenu; global $microsite; $parent_type = self::this_post_type(); foreach(array('attorney','practice_area') as $post_type) { $slug = "edit.php?post_type={$post_type}"; if ($post_type==$parent_type) { // If a microsite remove everything except the microsite editor $microsite_url = self::this_microsite_url(); foreach($submenu[$slug] as $submenu_index =&gt; $submenu_page) { if ($submenu_page[2]!=$microsite_url) { unset($submenu[$slug][$submenu_index]); } } } else { $submenu[$slug] = array(); } } // Remove the Submenus for each menu unset($submenu['index.php']); unset($submenu['edit.php?post_type=article']); unset($submenu['edit.php?post_type=event']); unset($submenu['edit.php?post_type=case_study']); unset($submenu['edit.php?post_type=news_item']); unset($submenu['edit.php?post_type=transaction']); unset($submenu['edit.php?post_type=page']); unset($submenu['upload.php']); unset($submenu['users.php'][13]); // Removed the "Add New" $remove = array_flip(array( 'edit.php', 'link-manager.php', 'edit-comments.php', 'edit.php?post_type=microsite-page', )); if (!current_user_can('manage_tools')) $remove['tools.php'] = count($remove); foreach($menu as $index =&gt; $menu_page) { if (isset($remove[$menu_page[2]])) { unset($submenu[$menu_page[2]]); unset($menu[$index]); } } $move = array( 'edit.php?post_type=page' =&gt; array( 'move-to' =&gt; 35, 0 =&gt; 'Other Pages' ), 'separator2' =&gt; array( 'move-to' =&gt; 40 ), 'upload.php' =&gt; array( 'move-to' =&gt; 50, 0 =&gt; 'Media Library' ), ); $add = array(); foreach($menu as $index =&gt; $menu_page) { if (isset($move[$menu_page[2]])) { foreach($move[$menu_page[2]] as $value_index =&gt; $value) { if ($value_index==='move-to') { $move_to = $value; } else { $menu_page[$value_index] = $value; } } $add[$move_to] = $menu_page; unset($menu[$index]); } } foreach($add as $index =&gt; $value) $menu[$index] = $value; add_menu_page( 'Attorney Positions', 'Attorney Positions', 'edit_posts', 'edit-tags.php?taxonomy=attorney-position&amp;amp;post_type=attorney', false, false, 55); ksort($menu); // Need to sort or it doesn't come out right. } static function init() { register_post_type('attorney',array( 'label' =&gt; 'Attorneys', 'public' =&gt; true, )); register_post_type('practice_area',array( 'label' =&gt; 'Practice Areas', 'public' =&gt; true, )); register_taxonomy('attorney-position','attorney',array( 'label'=&gt;'Attorney Positions', )); register_post_type('article',array( 'label' =&gt; 'Articles &amp; Presentations', 'public' =&gt; true, )); register_post_type('case_study',array( 'label' =&gt; 'Case Studies', 'public' =&gt; true, )); register_post_type('news_item',array( 'label' =&gt; 'Firm News', 'public' =&gt; true, )); register_post_type('event',array( 'label' =&gt; 'Events', 'public' =&gt; true, )); register_post_type('transaction',array( 'label' =&gt; 'Transactions', 'public' =&gt; true, )); // Install the test data $post_id = 10; $attorney = get_post($post_id); if (!$attorney) { global $wpdb; $wpdb-&gt;insert($wpdb-&gt;posts,array( 'ID' =&gt; $post_id, 'post_title' =&gt; 'John Smith', 'post_type' =&gt; 'attorney', 'post_content' =&gt; 'This is a post about the Attorney John Smith.', 'post_status' =&gt; 'publish', 'post_author' =&gt; 1, )); } } } TheGreatWordPressAdminMenuChallenge::on_load(); } </code> To all who read this, I'm really hoping you can help. Thanks in advance.
Mike, I've taken a look at the code and your ideal end use case ... and some of them, frankly, aren't possible with the current system. Again, your requirements: Get the "Microsite" submenu page to be highlighted when editing an Attorney Get the Attorney Menu Page link to link to <code> /wp-admin/edit.php?post_type=attorney </code> when editing an Attorney Get the "Microsite" link not to trigger a "You do not have sufficient permissions to access this page" error And the key issue here is #2. What I tried I tried adding a custom post type for Attorneys and was immediately reminded that <code> /wp-admin/edit.php?post_type=attorney </code> will give you a list of attorneys, not an actual edit screen. The actual editing take place on <code> /wp-admin/post.php?post=10&amp;action=edit </code> . So if you're really tied to #2 ... the other two criteria won't work. This is why #3 fails in implementation ... and I wasn't even able to attempt #1 because I couldn't get that far.
The Great WordPress Admin Menu Challenge of Jan 2011 (a.k.a. How to Resolve Some Challenges when Modifying the WordPress Admin Menu System?)
wordpress
i need advice in implementing rotating header (has fade or slide effect) in my theme. I'm building a theme based on Thematic and I'm looking for a good approach on how to implement the header. I have 2 option, I can use a Plug or I can inject the header in my functions.php. Help me decide on best way to do it. The are Pros and Cons on its approach, Plugin Pros : Easy to Install--no codes needed, client friendly-has an admin interface, Plugin Cons : not usually what you looking for.. sometime you you just work on what's available out there.. functions.php Pros -- You have full control of the design. functions Cons : no admin interface -- it would be hard for clients to update. Header Example: www[dot]haardtline[dot]de - (blind effect) www[dot]sweetsinthecitychicago[dot]com - (fade effect ) www[dot]collaborative-coaching[dot]com - (sliding effect) I'm looking for an approach where i can re-use it to other project. where I can just tweak the dimensions and effect. For the clients it's easy for them to maintain. I apologize for confusion The simplest question I could think is. How do you do it on your client? What is the best and well used approach... Do you use a plugin? what plugin? or code it? (in coding it, my one problem is the admin interface, I need my functions.php to generate an admin interface where user can easily upload images and set some settings.) Thanks!
I find using custom post types in Wordpress is the easiest way to achieve this. I have used them on quite a few websites and on a major record label website I am currently working on to create multiple carousels with relationships throughout the site. I would recommend a post type UI tool like Easy Post Types to create custom post types and then use features like "featured thumbnail image" and custom fields to create simple carousels that can be accessed by get_posts, query_posts and creating a new instance of WP_query.
sliding/fading header plugin or approach suggestion
wordpress
I am currently in the middle of developing quite an extensive and complicated record label website that uses post types and a whole bunch of relationship mapping to map post types to one another. Part of the major functionality of the site is a store. Because I have an "Artists" post type called "artists" I would like to use a store plugin that offers variations as I will be dealing with physical and digital music sales, as well as selling merchandise and would like to use a plugin that takes advantage of custom post types. I would like to be able to relate one or more items to a particular artist in the "artist" post type so that I don't have to make the client enter the artists names again, thus having to different locations storing the same data. I've taken a look at MarketPress created by WPMU Dev, but it seems as though support for variations isn't quite there yet. WP E-Commerce 3.8 (currently in beta) by Instinct supposedly uses custom post types, but to me it doesn't appear to be using custom post types whatsoever, but rather it's own interface. I also tried PHPPurchase as well, but out-of-the-box it uses pages instead of post types. I did find a tutorial telling you how to supposedly use custom post types with it, but it hardly seemed like true post type integration, the tutorial is located here . If you have a way I can relate my artists post type to any pre-existing shop plugins for Wordpress, that would be awesome too and I wouldn't mind having to add in different code to relate the two. Commercial and free solutions welcomed.
You Should look at dukapress it a fairly new E-Commerce plugin but its loaded with features and it uses Custom post types. and as for the relation part, i had that same challenge as your are having in developing a site for one of my customers, i needed to relate a CPT (custom post type) named "Question" to Groups of CTP named "Answer" so i could display all answers of a question in the same page as the question itself and i ended up doing like this for each answer i added a custom field named "Q_ID" an just set its value to the corresponding Question Post type ID. made things real easy as far as using query_posts or a custom WP_Query cant remember and only selecting posts of type "Answer" with Custom Filed named Q_ID that equals to my Question Post Type ID. <code> $q= array( "POST_TYPE"=&gt;'Answer', 'meta_key' =&gt;'Q_ID', 'meta_compare' =&gt; '=' 'meta_value' =&gt; $Questions_Post_TYPE_ID ); query_posts($q); </code> hope this helps.
Need Help Finding a Wordpress E-Commerce Plugin That Utilises Custom Post Types
wordpress
Under Appearance > Menus I seem to be able to add Categories, Pages, or Custom Links as my menu/sub-menu dropdown items...but I can't add posts. I would like to have posts in my dropdown (posts of a given category), but I can't seem to do this without writing custom links, which is going to be time-consuming. Is there any way around this?
Check the Screen Options dropdown tab at the top right on the menus page. There's a checkbox there to enable posts and more. Cheers, CW
Wordpress Menu options in the Admin: Posts for the dropdowns
wordpress
My plugin is freezing the execution of the page at the point where it calls the functions below. I have two problems... 1) How can I recode the function so that if there is an error, the plugin does not stop the page from loading, but rather, returns an error message? 2) How can I feedback what the error might be? Its just freezing but not outputting the error. <code> function rseo_get_seo($check, $post){ //return false; switch ($check) { case "h1": return rseo_doTheParse('h1', $post); case "h2": return rseo_doTheParse('h2', $post); case "h3": return rseo_doTheParse('h3', $post); case "img-alt": return rseo_doTheParse('img-alt', $post); } } function rseo_doTheParse($heading, $post) { $content = $post-&gt;post_content; if($content=="") return false; $keyword = trim(strtolower(rseo_getKeyword($post))); @$dom = new DOMDocument; @$dom-&gt;loadHTML(strtolower($post-&gt;post_content)); $xPath = new DOMXPath(@$dom); switch ($heading) { case "img-alt": return $xPath-&gt;evaluate('boolean(//img[contains(@alt, "'.$keyword.'")])'); default: return $xPath-&gt;evaluate('boolean(/html/body//'.$heading.'[contains(.,"'.$keyword.'")])'); } } </code> Here's my attempt to change the 2nd function with try catch but I get a fatal error on plugin activation... <code> function rseo_doTheParse($heading, $post){ try { //I get a FATAL error here. unexpected '{' $content = $post-&gt;post_content; if($content=="") return false; $keyword = trim(strtolower(rseo_getKeyword($post))); @$dom = new DOMDocument; @$dom-&gt;loadHTML(strtolower($post-&gt;post_content)); $xPath = new DOMXPath(@$dom); switch ($heading) { case "img-alt": return $xPath-&gt;evaluate('boolean(//img[contains(@alt, "'.$keyword.'")])'); default: return $xPath-&gt;evaluate('boolean(/html/body//'.$heading.'[contains(.,"'.$keyword.'")])'); } } catch (Exception $e) { echo 'Exception caught: ', $e-&gt;getMessage(), "\n"; } } </code>
This line is wrong: <code> $xPath = new DOMXPath(@$dom); </code> Should be this: <code> $xPath = new DOMXPath($dom); </code>
How can I gracefully escape an error condition?
wordpress
I have a plugin that has a single method that requires PHP5. How can I code around the fact that the server may have PHP4? Code is below... (I'm thinking its the DOMDocument object that's freezing the plugin when running on a PHP4 server. <code> function rseo_doTheParse($heading, $post){ $content = $post-&gt;post_content; if($content=="" || is_php4()) return false; $keyword = trim(strtolower(rseo_getKeyword($post))); @$dom = new DOMDocument; @$dom-&gt;loadHTML(strtolower($post-&gt;post_content)); $xPath = new DOMXPath(@$dom); switch ($heading) { case "img-alt": return $xPath-&gt;evaluate('boolean(//img[contains(@alt, "'.$keyword.'")])'); default: return $xPath-&gt;evaluate('boolean(/html/body//'.$heading.'[contains(.,"'.$keyword.'")])'); } } function is_php4(){//code here} </code>
<code> function is_php4(){ return version_compare(phpversion(),'5','&lt;'); } </code>
Does WordPress have a built in reference to the PHP version its running under?
wordpress
Here is the code I'm using right now. It fetches the posts from all the categories in the 'sp_events' post type. <code> &lt;?php $feat_art = new WP_Query(array('post_type' =&gt; 'sp_events','post_status' =&gt; 'publish','posts_per_page' =&gt; 1)); while($feat_art-&gt;have_posts()) : $feat_art-&gt;the_post(); ?&gt; </code> I want to display the posts only from a category named 'eventcat1'. I tried the following code, but it did not work. <code> &lt;?php $feat_art = new WP_Query(array('post_type' =&gt; 'sp_events','category_name'=&gt; 'eventcat1','post_status' =&gt; 'publish','posts_per_page' =&gt; 1)); while($feat_art-&gt;have_posts()) : $feat_art-&gt;the_post(); ?&gt; </code> How to specify either the category name or the id in the query? Any help would be appreciated. Thanks
The following code worked. <code> &lt;?php $feat_art = new WP_Query(array('post_type' =&gt; 'sp_events','sp_events_cat'=&gt; 'eventcat1','post_status' =&gt; 'publish','posts_per_page' =&gt; 1)); while($feat_art-&gt;have_posts()) : $feat_art-&gt;the_post(); ?&gt; </code>
How to include category name/id in wp_query for retrieving "custom post type" from a particular category?
wordpress
Suppose that I create a page in the admin section (under 'Pages') and I have permalinks turned on and this pages slug is 'my-new-page', then is there a WordPress function that will work outside the (blog) Loop that I can use in that page's template on my theme that will retrieve that page's permalink?
Hi @racl101: I think what you are after is to use <code> get_page_link($post-&gt;ID) </code> . The value <code> $post </code> will have been set by the default query to be equal to the post for the current page and should be in scope when your page template is run.
Is there a wordpress function that I can use to retrieve the current page that is loaded?
wordpress