question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I just upgraded from 3.0 to 3.1.2 and in the comments column under Posts in the WP Admin, this error keeps appearing for every row: Warning: number_format() expects parameter 1 to be double, string given in /path/mysite/wp-includes/functions.php on line 155 Can someone tell me how to fix this?
The "Comments" column is not a default/core column in the "Posts" page. Perhaps it is being generated by your Disqus Plugin? Try temporarily disabling the Disqus Plugin, and see if the PHP notices go away. EDIT: actually, it is a default column. But I still suspect Disqus is causing the PHP warning.
How to fix this PHP warning in WP-Admin after upgrading to 3.1.2?
wordpress
Is there a way to display (css and html) in a different way the "reply" form and the main "comment" form?
Well, it is the same form, but it is moved to another place in the DOM tree. So you could create one style for just <code> .comments #respond </code> , and one for <code> .comments .comment #respond </code> for the moved reply form.
Style reply form different than comment form
wordpress
If I want to "safely" delete a post. I want to make sure that no link exists (within my blog) to "to-be-deleted" post. How do I do that?
After reading this thread I saw that I might need this also sometimes. So here is the result: The internal link checker plugin It adds a meta box at your post edit screens that shows links to all posts who link internally to the currently displayed post. If you want to alter the output (add something for eg.), please use the provided filter. An example of how to use the filter can be found at the readme file. The Plugin is GPL2 licensed. Maybe I'll also put it in the official repo to allow installation from inside your self hosted blog. Edit: Done. Grab it for free over at github ...or at... WordPress.org - Extend ...or in our own stackexchange-url ("WPSE Plugin Repository")
How do I check if I linked to a post before I delete it?
wordpress
I'm working on a project in which I'm creating a custom post type and custom data entered via meta boxes associated with my custom post type. For whatever reason I decided to code the meta boxes in such a way that the inputs in each metabox are part of an array. For instance, I'm storing longitude and latitude: <code> &lt;p&gt; &lt;label for="latitude"&gt;Latitude:&lt;/label&gt;&lt;br /&gt; &lt;input type="text" id="latitude" name="coordinates[latitude]" class="full-width" value="" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="longitude"&gt;Longitude:&lt;/label&gt;&lt;br /&gt; &lt;input type="text" id="longitude" name="coordinates[longitude]" class="full-width" value="" /&gt; &lt;/p&gt; </code> For whatever reason, I liked the idea of having a singular postmeta entry for each metabox. On the <code> save_post </code> hook, I save the data like so: <code> update_post_meta($post_id, '_coordinates', $_POST['coordinates']); </code> I did this because I have three metaboxes and I like just having 3 postmeta values for each post; however, I've now realized a potential issue with this. I may want to use WP_Query to only pull out certain posts based these meta values. For instance, I may want to get all posts that have latitude values above 50. If I had this data in the database individually, perhaps using the key <code> latitude </code> , I would do something like: <code> $args = array( 'post_type' =&gt; 'my-post-type', 'meta_query' =&gt; array( array( 'key' =&gt; 'latitude', 'value' =&gt; '50', 'compare' =&gt; '&gt;' ) ) ); $query = new WP_Query( $args ); </code> Since I have the latitude as part of the <code> _coordinates </code> postmeta, this would not work. So, my question is, is there a way to utilize <code> meta_query </code> to query a serialized array like I have in this scenario?
No, it is not possible. I strongly recommend you unserialise your data and modify your save routine. Something similar to this should convert your data to the new format: <code> $args = array( 'post_type' =&gt; 'my-post-type', 'meta_key' =&gt; '_coordinates', 'posts_per_page' =&gt; -1 ); $query = new WP_Query( $args ); if($query-&gt;have_posts()){ while($query-&gt;have_posts()){ $query-&gt;the_post(); $c = get_post_meta($post-&gt;id,'_coordinates',true); add_post_meta($post-&gt;ID,'_longitude',$c['longitude']); add_post_meta($post-&gt;ID,'_latitude',$c['latitude']); delete_post_meta($post-&gt;ID,'_coordinates',$c); } } </code> Then you'll be able to query as you want with individual keys
meta_query with meta values as serialize arrays
wordpress
I created an option panel following a tutorial. But each time I try to save the settings I get the following: You do not have sufficient permissions to access this page. Any suggestions to fix this? (Not sure if this helps but I'm using Wordpress 3.1.2) EDIT: I don't have the permission issue if I place the code directly in the <code> functions.php </code> file in my theme folder. I have the file in <code> functions/custom-functions.php </code> . I have to change the 'header Location,' not sure how: <code> function mytheme_add_admin() { global $themename, $shortname, $options; if ( $_GET['page'] == basename(__FILE__) ) { if ( 'save' == $_REQUEST['action'] ) { foreach ($options as $value) update_option( $value['id'], $_REQUEST[ $value['id'] ] ); foreach ($options as $value) { if( isset( $_REQUEST[ $value['id'] ] ) ) update_option( $value['id'], $_REQUEST[ $value['id'] ] ); else delete_option( $value['id'] ); } header("Location: admin.php?page=functions.php&amp;saved=true"); die; } else if ( 'reset' == $_REQUEST['action'] ) { foreach ($options as $value) delete_option( $value['id'] ); header("Location: admin.php?page=functions.php&amp;reset=true"); die; } } add_menu_page($themename, $themename, 'administrator', basename(__FILE__), 'mytheme_admin'); } </code>
You're adding the menu page using the "administrator" role. Is the account you're using an administrator? Note: 1) You should be using an appropriate capability , rather than a user role . Generally, the appropriate capability for editing Theme options is <code> edit_theme_options </code> . 2) There is a known bug with WordPress, in that currently, <code> manage_options </code> is required for the form submit on <code> options.php </code> , which is used by Theme settings pages. This is only an issue for user roles below editor, and will hopefully be fixed in 3.2 or 3.3. 3) If this is a public Theme, you should be using <code> add_theme_page() </code> (which adds a submenu to the "Appearance" menu), rather than <code> add_menu_page() </code> (which adds a top-level menu page). 4) That tutorial is considerably out of date.
I don't have permission to save the theme options I created myself?
wordpress
How do I make a menu entry that's just plain text, not a link? My kludge workaround is linking to "/", but I'd prefer no link at all.
If this is for a dynamic menu you can use a 'Custom Links' and use a # for the URL then click add to menu. Once it's in the menu, remove the # from the URL in the menu and save the menu. It'll then be a text only no link item. (you can then add sub menu's that are linked) which is what I use this method for.
Do not hyperlink menu heading
wordpress
I have a .htaccess file <code> &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &lt;/IfModule&gt; </code> the config for the vhost looks like <code> &lt;VirtualHost *:80&gt; ServerName elements DocumentRoot /works/web/elements &lt;Directory /works/web/elements&gt; Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from 127.0.0.1 &lt;/Directory&gt; &lt;/VirtualHost&gt; </code> But I am still getting 404 when I view pages, why is that?
The problem was not having mod_rewrite enabled ... Resolved it through <code> sudo a2enmod rewrite </code>
Already have htaccess but permalink settings not working. Getting 404
wordpress
How do I make menu items open in a new tab/page instead of replacing the current page?
Go to Appearance > Menu click screen options (near top of page) tick "Link target" Now, when you click a menu item drop down, you can choose what the link target is (you want to choose New window or tab)
Make menu items open in new tab/page
wordpress
When I visit Appearance → Menu , I can add custom links, but not any links I've already created under Links . How can I do this?
You can't add link/blogroll type items to the main navigation - add them as custom links instead. [Update] To be more precise, you could do it, but you would need to write some code that hooked into the menu creation/editing section, present a list of blogroll links in a metabox, allowed you to choose from them, and then added these links to your menu. Seems easier to just add the ones you want as custom links.
Adding existing links to custom navigation menus?
wordpress
The posts on our music blog usually include multiple tracks of music. I want to have each individual track be its own entity--a custom post type called "track" --which I want to be able to insert freely into a post where I wish using a shortcode. The image below explains pretty well what I am looking to do. (Link to the page that I took the screenshot from: http://iloveomfg.com/210/don-rimini-whatever-kaptain-cadillac-remix/ ) I want to create a shortcode, [track] , which echoes the entire contents of the 'track' custom post type which id is specified. For example, if the track id is 34, the shortcode to display it within the post would be: [track id=34] or [track id="34"] . I have taken a look at all the posts related to this topic on this site, and have tried a few of the solutions, but to no avail, so I decided to go ahead and ask for my problem specifically. Can you tell me exactly what I need to do to achieve this? Let me know if you need me to clarify anything.
I would suggest creating a new custom taxonomy for relations between a post and its "tracks" or grouping of track posts if you'd like that way you can easily create a shortcode that will query all the needed tracks at once using a shortcode instead of calling your shortcode over and over and to order them you can create a custom field in track so in your query you can order by that field so it would be something like this (this assumes that you have a custom taxonomy named " post_tracks " and that all of the posts tracks were added to the same term of that taxonomy, also that you have a custom field to order you tracks named " in_order " : <code> function get_tracks($atts, $content = null) { extract(shortcode_atts(array( "post_tracks" =&gt; '', "tracks" =&gt; '', ), $atts)); //if post_tracks relation term was passed: if ($atts['post_tracks'] != ''){ $tracks = NEW WP_Query(array('post_type' =&gt; 'track', 'post_tracks' =&gt; $atts['post_tracks'], 'orderby' =&gt; 'meta_value', 'meta_key' =&gt; 'in_order' )); while($tracks-&gt;have_posts()){ $tracks-&gt;the_post(); //do whatever you want with each track eg: $out .= '&lt;div class="track"&gt; &lt;h3&gt;'.get_the_title($post-&gt;ID).'&lt;h3&gt; &lt;div class="track_inner"&gt; &lt;div class="track_img"&gt;'. get_the_post_thumbnail($post-&gt;ID, 'thumbnail').'&lt;/div&gt; &lt;div class="track_content"&gt;'.apply_filters('the_content',get_the_content()).'&lt;div&gt; &lt;/div&gt;&lt;/div&gt;'; } return $out; } //if its a single track you want: $tracks = NEW WP_Query(array('post_type' =&gt; 'track','post__in' =&gt; array($tracks) )); while($tracks-&gt;have_posts()){ $tracks-&gt;the_post(); //do whatever you want with each track eg: $out .= '&lt;div class="track"&gt; &lt;h3&gt;'.get_the_title($post-&gt;ID).'&lt;h3&gt; &lt;div class="track_inner"&gt; &lt;div class="track_img"&gt;'. get_the_post_thumbnail($post-&gt;ID, 'thumbnail').'&lt;/div&gt; &lt;div class="track_content"&gt;'.apply_filters('the_content',get_the_content()).'&lt;div&gt; &lt;/div&gt;&lt;/div&gt;'; } return $out; } add_shortcode('tracks','get_tracks'); </code> with this you can simple call your shortcode like this: <code> [tracks post_tracks="relation_tern_name"] </code> or just get your single track on at a time: <code> [tracks tracks="track_id"] </code>
Post the content of a specific "Custom Post Type" post within a post using a shortcode
wordpress
I have created one theme. The theme was denied today for the following reasons: Theme Review: Themes should be reviewed using <code> define('WP_DEBUG', true); </code> in <code> wp-config.php </code> Themes should be reviewed using the test data from the Theme Checklists (TC) <code> wp-config.php </code> is the WordPress setting file. How do I alter my custom theme? the theme registers some custom functionality in the function <code> warmHome_setup() </code> however this function in not hooked so the functionality is not available. Recommend hooking the theme to the <code> after_setup_theme </code> hook. The following is my themes <code> warmHome_setup() </code> function. How should I alter it? <code> function warmHome_setup() { // This theme styles the visual editor with editor-style.css to match the theme style. add_editor_style(); // Add default posts and comments RSS feed links to head add_theme_support( 'automatic-feed-links' ); // Make theme available for translation // Translations can be filed in the /languages/ directory load_theme_textdomain( 'warm-home', TEMPLATEPATH . '/languages' ); $locale = get_locale(); $locale_file = TEMPLATEPATH . "/languages/$locale.php"; if ( is_readable( $locale_file ) ) require_once( $locale_file ); // This theme uses wp_nav_menu() in one location. register_nav_menus( array( 'primary' =&gt; __( 'Primary Navigation', 'warm home' ), ) ); // This theme allows users to set a custom background add_custom_background(); } </code>
To answer your questions: the wp-config.php is wordpress setting file. how to alter my custom theme? you don't need to alter your theme, its simply telling you to turn debug to true within wp-config.php and review your theme, to see if it creating any warnings or errors. put this line <code> define('WP_DEBUG', true); </code> in your wp-config.php and play around with your site, see if you get any warnings or errors and correct them. the following is my themes warmHome_setup() function. how to alter it? many thanks. simply add <code> add_action('after_setup_theme','warmHome_setup'); </code> to your functions.php file For example: <code> function warmHome_setup() { // all your setup functionality goes here } add_action( 'after_setup_theme', 'warmHome_setup'); </code>
Questions about WordPress.org theme review
wordpress
I have a unique plugin whose purpose is to set up a new WordPress site with a theme, default widgets, default plugins, custom menus, pages, posts, etc. The plugin does everything it needs to do when activated and never runs again. I'm looking for suggestions on how I might, as the last step in the activation routine, deactivate and delete the plugin. Any help, suggestions, or example references appreciated.
You can deactivate it with: <code> deactivate_plugins( basename( __FILE__ ) ); </code> I don't think you can delete it. It would be a big security risk, IMO. But if the folder has the correct (but insecure) permissions, you could use the PHP function rmdir
Can a plugin deactivate and delete itself once installed and activated?
wordpress
Sadly my "reply" link for threaded comments is not working. The current situation: First i load the comments reply script (check if scripts content load: works) into the <code> &lt;head&gt; </code> using two functions (the first <code> wp_register_script() </code> at the init hook, the second <code> wp_print_scripts() </code> at the wp_head hook): Then i add the Reply link: <code> comment_reply_link( array( 'reply_text' =&gt; __( 'Reply', OXO_TEXTDOMAIN ) ,'depth' =&gt; isset( $args['args']['depth'] ) ? $args['args']['depth'] : (int) 3 ,'max_depth' =&gt; isset( $args['args']['max_depth'] ) ? $args['args']['max_depth'] : (int) 5 ) ,get_comment_ID() ,$post-&gt;ID ); </code> which produces this html-output (example) <code> &lt;a onclick="return addComment.moveForm("comment-11", "11", "respond", "149")" href="/wordpress/?p=149&amp;cpage=2&amp;replytocom=11#respond" class="comment-reply-link"&gt;Reply&lt;/a&gt; </code> I got everything according to any recommendation i read: My comments are within a <code> &lt;div id="comments"&gt; </code> and the comments form above it within a <code> &lt;div id="respond"&gt; </code> . I still get dropped to the #respond-anchor and the comment form above the comments ( <code> http://localhost/wordpress/?p=149&amp;cpage=2&amp;replytocom=11#respond </code> ), instead of getting the comment form displayed below the comment i want to reply to. What may i do wrong? Google, tutorials, how-to and else were so far of no help. Everything seems to be according to the recommended standard... Thanks a lot.
Don't link the script file directly. Enqueue it instead, e.g. in <code> functions.php </code> : <code> function mytheme_enqueue_comment_reply() { // on single blog post pages with comments open and threaded comments if ( is_singular() &amp;&amp; comments_open() &amp;&amp; get_option( 'thread_comments' ) ) { // enqueue the javascript that performs in-link comment reply fanciness wp_enqueue_script( 'comment-reply' ); } } // Hook into wp_enqueue_scripts add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_comment_reply' ); </code> You can also do this, in the document head, prior to the <code> wp_head() </code> call: <code> &lt;?php // on single blog post pages with comments open and threaded comments if ( is_singular() &amp;&amp; comments_open() &amp;&amp; get_option( 'thread_comments' ) ) { // enqueue the javascript that performs in-link comment reply fanciness wp_enqueue_script( 'comment-reply' ); } ?&gt; </code> EDIT: Hooking into <code> wp_head </code> , rather than e.g. <code> wp_print_scripts </code> , is important. The <code> wp_print_scripts </code> does not work in the same way that <code> wp_print_styles </code> does, to output stylesheet links. So: if you're using <code> wp_print_scripts </code> , change the hook to <code> wp_head </code> . EDIT 2: Based on your pastebin-linked code, have you tried the following, to rule out potential issues? Remove callback function from <code> wp_comment_list() </code> Move <code> wp_comment_list() </code> call to before <code> comment_form() </code> call Remove the argument array from <code> comment_form() </code> I don't know that any of those will solve your problem, but they may help us track down its origin.
comments reply script not working
wordpress
My site has a few custom post types, news, events, you-tube, etc. I'd like to create an rss feed for each post type as well as a main with all. I've experimented an bit and found how to combine them into one but I haven't determined how to segment each. Do I need to create separate feed-rss.php for the templates as well as a custom function? This is the function I'm currently using to combine them into one feed. <code> //Custom post feeds function myfeed_request($qv) { if (isset($qv['feed']) &amp;&amp; !isset($qv['post_type'])) $qv['post_type'] = array('post', 'youtube', 'event', 'news' ); return $qv; } add_filter('request', 'myfeed_request'); </code>
Look at this: http://www.seodenver.com/custom-rss-feed-in-wordpress/
Creating separate feeds for custom post types
wordpress
I used the following code in order to add a Theme Options panel in my Wordpress admin: <code> &lt;?php $themename = "Nettuts"; $shortname = "nt"; $categories = get_categories('hide_empty=0&amp;orderby=name'); $wp_cats = array(); foreach ($categories as $category_list ) { $wp_cats[$category_list-&gt;cat_ID] = $category_list-&gt;cat_name; } array_unshift($wp_cats, "Choose a category"); $options = array ( array( "name" =&gt; $themename." Options", "type" =&gt; "title"), array( "name" =&gt; "General", "type" =&gt; "section"), array( "type" =&gt; "open"), array( "name" =&gt; "Colour Scheme", "desc" =&gt; "Select the colour scheme for the theme", "id" =&gt; $shortname."_color_scheme", "type" =&gt; "select", "options" =&gt; array("blue", "red", "green"), "std" =&gt; "blue"), array( "name" =&gt; "Logo URL", "desc" =&gt; "Enter the link to your logo image", "id" =&gt; $shortname."_logo", "type" =&gt; "text", "std" =&gt; ""), array( "name" =&gt; "Custom Option", "desc" =&gt; "Enter the link to your logo image", "id" =&gt; $shortname."_custom", "type" =&gt; "text", "std" =&gt; ""), array( "name" =&gt; "Custom CSS", "desc" =&gt; "Want to add any custom CSS code? Put in here, and the rest is taken care of. This overrides any other stylesheets. eg: a.button{color:green}", "id" =&gt; $shortname."_custom_css", "type" =&gt; "textarea", "std" =&gt; ""), array( "type" =&gt; "close"), array( "name" =&gt; "Homepage", "type" =&gt; "section"), array( "type" =&gt; "open"), array( "name" =&gt; "Homepage header image", "desc" =&gt; "Enter the link to an image used for the homepage header.", "id" =&gt; $shortname."_header_img", "type" =&gt; "text", "std" =&gt; ""), array( "name" =&gt; "Homepage featured category", "desc" =&gt; "Choose a category from which featured posts are drawn", "id" =&gt; $shortname."_feat_cat", "type" =&gt; "select", "options" =&gt; $wp_cats, "std" =&gt; "Choose a category"), array( "type" =&gt; "close"), array( "name" =&gt; "Footer", "type" =&gt; "section"), array( "type" =&gt; "open"), array( "name" =&gt; "Footer copyright text", "desc" =&gt; "Enter text used in the right side of the footer. It can be HTML", "id" =&gt; $shortname."_footer_text", "type" =&gt; "text", "std" =&gt; ""), array( "name" =&gt; "Google Analytics Code", "desc" =&gt; "You can paste your Google Analytics or other tracking code in this box. This will be automatically added to the footer.", "id" =&gt; $shortname."_ga_code", "type" =&gt; "textarea", "std" =&gt; ""), array( "name" =&gt; "Custom Favicon", "desc" =&gt; "A favicon is a 16x16 pixel icon that represents your site; paste the URL to a .ico image that you want to use as the image", "id" =&gt; $shortname."_favicon", "type" =&gt; "text", "std" =&gt; get_bloginfo('url') ."/favicon.ico"), array( "name" =&gt; "Feedburner URL", "desc" =&gt; "Feedburner is a Google service that takes care of your RSS feed. Paste your Feedburner URL here to let readers see it in your website", "id" =&gt; $shortname."_feedburner", "type" =&gt; "text", "std" =&gt; get_bloginfo('rss2_url')), array( "type" =&gt; "close") ); function mytheme_add_admin() { global $themename, $shortname, $options; if ( $_GET['page'] == basename(__FILE__) ) { if ( 'save' == $_REQUEST['action'] ) { foreach ($options as $value) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } foreach ($options as $value) { if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else { delete_option( $value['id'] ); } } header("Location: admin.php?page=options.php&amp;saved=true"); die; } else if( 'reset' == $_REQUEST['action'] ) { foreach ($options as $value) { delete_option( $value['id'] ); } header("Location: admin.php?page=options.php&amp;reset=true"); die; } } add_menu_page($themename, $themename, 'administrator', basename(__FILE__), 'mytheme_admin'); } function mytheme_add_init() { $file_dir=get_bloginfo('template_directory'); wp_enqueue_style("functions", $file_dir."/functions/functions.css", false, "1.0", "all"); } function mytheme_admin() { global $themename, $shortname, $options; $i=0; if ( $_REQUEST['saved'] ) echo '&lt;div id="message" class="updated fade"&gt;&lt;p&gt;'.$themename.' settings saved.&lt;/p&gt;&lt;/div&gt;'; if ( $_REQUEST['reset'] ) echo '&lt;div id="message" class="updated fade"&gt;&lt;p&gt;'.$themename.' settings reset.&lt;/p&gt;&lt;/div&gt;'; ?&gt; &lt;div class="wrap rm_wrap"&gt; &lt;h2&gt;&lt;?php echo $themename; ?&gt; Settings&lt;/h2&gt; &lt;div class="rm_opts"&gt; &lt;form method="post"&gt; &lt;?php foreach ($options as $value) { switch ( $value['type'] ) { case "open": ?&gt; &lt;?php break; case "close": ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;br /&gt; &lt;?php break; case "title": ?&gt; &lt;p&gt;To easily use the &lt;?php echo $themename;?&gt; theme, you can use the menu below.&lt;/p&gt; &lt;?php break; case 'text': ?&gt; &lt;div class="rm_input rm_text"&gt; &lt;label for="&lt;?php echo $value['id']; ?&gt;"&gt;&lt;?php echo $value['name']; ?&gt;&lt;/label&gt; &lt;input name="&lt;?php echo $value['id']; ?&gt;" id="&lt;?php echo $value['id']; ?&gt;" type="&lt;?php echo $value['type']; ?&gt;" value="&lt;?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id']) ); } else { echo $value['std']; } ?&gt;" /&gt; &lt;small&gt;&lt;?php echo $value['desc']; ?&gt;&lt;/small&gt;&lt;div class="clearfix"&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php break; case 'textarea': ?&gt; &lt;div class="rm_input rm_textarea"&gt; &lt;label for="&lt;?php echo $value['id']; ?&gt;"&gt;&lt;?php echo $value['name']; ?&gt;&lt;/label&gt; &lt;textarea name="&lt;?php echo $value['id']; ?&gt;" type="&lt;?php echo $value['type']; ?&gt;" cols="" rows=""&gt;&lt;?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id']) ); } else { echo $value['std']; } ?&gt;&lt;/textarea&gt; &lt;small&gt;&lt;?php echo $value['desc']; ?&gt;&lt;/small&gt;&lt;div class="clearfix"&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php break; case 'select': ?&gt; &lt;div class="rm_input rm_select"&gt; &lt;label for="&lt;?php echo $value['id']; ?&gt;"&gt;&lt;?php echo $value['name']; ?&gt;&lt;/label&gt; &lt;select name="&lt;?php echo $value['id']; ?&gt;" id="&lt;?php echo $value['id']; ?&gt;"&gt; &lt;?php foreach ($value['options'] as $option) { ?&gt; &lt;option &lt;?php if (get_settings( $value['id'] ) == $option) { echo 'selected="selected"'; } ?&gt;&gt;&lt;?php echo $option; ?&gt;&lt;/option&gt;&lt;?php } ?&gt; &lt;/select&gt; &lt;small&gt;&lt;?php echo $value['desc']; ?&gt;&lt;/small&gt;&lt;div class="clearfix"&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php break; case "checkbox": ?&gt; &lt;div class="rm_input rm_checkbox"&gt; &lt;label for="&lt;?php echo $value['id']; ?&gt;"&gt;&lt;?php echo $value['name']; ?&gt;&lt;/label&gt; &lt;?php if(get_option($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = "";} ?&gt; &lt;input type="checkbox" name="&lt;?php echo $value['id']; ?&gt;" id="&lt;?php echo $value['id']; ?&gt;" value="true" &lt;?php echo $checked; ?&gt; /&gt; &lt;small&gt;&lt;?php echo $value['desc']; ?&gt;&lt;/small&gt;&lt;div class="clearfix"&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php break; case "section": $i++; ?&gt; &lt;div class="rm_section"&gt; &lt;div class="rm_title"&gt;&lt;h3&gt;&lt;?php echo $value['name']; ?&gt;&lt;/h3&gt;&lt;span class="submit"&gt;&lt;input name="save&lt;?php echo $i; ?&gt;" type="submit" value="Save changes" /&gt; &lt;/span&gt;&lt;div class="clearfix"&gt;&lt;/div&gt;&lt;/div&gt; &lt;div class="rm_options"&gt; &lt;?php break; } } ?&gt; &lt;input type="hidden" name="action" value="save" /&gt; &lt;/form&gt; &lt;form method="post"&gt; &lt;p class="submit"&gt; &lt;input name="reset" type="submit" value="Reset" /&gt; &lt;input type="hidden" name="action" value="reset" /&gt; &lt;/p&gt; &lt;/form&gt; &lt;div style="font-size:9px; margin-bottom:10px;"&gt;Icons: &lt;a href="http://www.woothemes.com/2009/09/woofunction/"&gt;WooFunction&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php } ?&gt; &lt;?php add_action('admin_init', 'mytheme_add_init'); add_action('admin_menu', 'mytheme_add_admin'); ?&gt; </code> I would like to add an upload button like this one: I searched all the Internet and this StackExchange site but didn't find the answer (there is only one but it is for custom write panels in 'Pages'). Any suggestions?
Referring to this post stackexchange-url ("How to use media upload on theme option page?") Check if you find anything helpful. Thanks!
How to add an upload image button (just like the one in the Custom Header) in the Theme Options I just created?
wordpress
I have a Custom Post Type called 'Property'. I display a list of CPT properties on a page: 10 per page with pagination. I would like to add an "Email friend" link to every property on the list, so a user can email that property url to multiple email addresses easily. Is there a plugin that can do this? Otherwise, what's the best approach for to do it? Many thanks, Dasha
I ended up using a simple "mailto" link. Not sure this is the best approach for this question, but it seems to work. If someone knows a better solution (ideally plugin or code) please feel free to add it. Thanks, Dasha
Email friend for each Custom Post Type posts on a page
wordpress
I'd like my archive.php page's daily view (is_day) to display scheduled posts (post_status=future). For example, if I go to mysite.com/2011/05/20 I would see all posts scheduled to appear on May 20. The archive page's loop starts with: <code> if ( have_posts() ) the_post(); </code> and ends with: <code> rewind_posts(); get_template_part( 'loop', 'archive' ); </code> Do I need to make a second loop, or can I modify this single loop to show scheduled posts? If so, how? Thank you.
Keep things simple - leave your archive templates alone and place this in your <code> functions.php </code> ; <code> if ( !is_admin() ) : function __include_future( $query ) { if ( $query-&gt;is_date() || $query-&gt;is_single() ) $GLOBALS[ 'wp_post_statuses' ][ 'future' ]-&gt;public = true; } add_filter( 'pre_get_posts', '__include_future' ); endif; </code> Essentially, it says; If we're on a date archive, or viewing a single post, make future posts publicly visible. As a result, WordPress behaves normally when you view archives for any given date, except now it also includes posts 'from the future'!.
Show scheduled posts in archive page
wordpress
I having trouble with the results, the url and the pagination shows correctly, but when I'm on page 2 or 3 etc... there only show the results from the first page. this is my code. <code> &lt;?php $portfolioloop = new WP_Query( array( 'post_type' =&gt; 'portfolio', 'posts_per_page' =&gt; 12 ) ); ?&gt; &lt;?php while ( $portfolioloop-&gt;have_posts() ) : $portfolioloop-&gt;the_post(); ?&gt; Code for the loop here &lt;?php endwhile; // end of the loop. ?&gt; &lt;?php if (function_exists('wp_pagenavi')) { wp_pagenavi( array( 'query' =&gt; $portfolioloop ) ); } ?&gt; </code> WP Page Navi - Versión 2.74 Permalink structure - "/%postname%/"
you are quering the same posts over and over, and that is way you are getting the same posts, to fix it just add <code> 'paged' =&gt; get_query_var('paged') </code> to your query arguments, so change: <code> &lt;?php $portfolioloop = new WP_Query( array( 'post_type' =&gt; 'portfolio', 'posts_per_page' =&gt; 12 ) ); ?&gt; </code> into: <code> &lt;?php $portfolioloop = new WP_Query( array( 'paged' =&gt; get_query_var('paged'), 'post_type' =&gt; 'portfolio', 'posts_per_page' =&gt; 12 ) ); ?&gt; </code> and just to make sure you are ok and to avoid errors add <code> wp_reset_postdata(); </code> at the end of your code.
Pagenavi Plugin and Custom Post Type - Multipage results
wordpress
I've been using WPML to have multilanguage capabilities in my WordPress implementations. Now WPML has gone commercial, and I'm looking for a open source non-commercial replacement. My main concerns are: It should be easy to use for the content administrator. It should be fairly flexible. It should let me decide the URL structure for each language (subdomain, folder, parameter, etc.) It should perform relatively well (Specially the queries) It should support all major WP features (eg: Custom post types, menus, widgets) I'm in the process of testing a few plugins, but I'd want to know if any of you have good advice.
I'd look into qTranslate . I haven't ever used it, but it's the only free alternative to WPML that I've ever seen. That being said, I'd suggest you just pony up the $30-80 for WPML. It's by far the best-maintained and cleanest multilingual plugin you can get and it's absolutely dirt cheap, considering what you get. And with their (very reasonable) pricing structure, what you're really paying for is DEDICATED SUPPORT. That's a pretty big deal in the open source world. Also, you're not looking for an open source replacement, you're looking for a free replacement. WPML is GPL licensed, so it's definitely open source.
Multilingual WordPress plugins
wordpress
I have been trying to find a way to return page information in order to create a landing page. I have done this with posts before, to create a blog reel, and would like to achieve the same overall result with pages. The Scenario: I use a drop menu with pages created in the WordPress. Nesting the pages builds the menu. The Goal: I would like to get the subpages of the parent page. When a user navigates to the parent page I would like it to return links to the subpages with a part of the content of the child page. For example, I would like to display the <code> &lt;div&gt; </code> with class <code> header </code> . A Starting Point: <code> $mypages = get_pages('child_of='.$post-&gt;ID.'&amp;sort_column=post_date&amp;sort_order=desc'); foreach($mypages as $page) { $content = $page-&gt;post_content; if(!$content) // Check for empty page continue; $content = apply_filters('the_content', $content); ?&gt; &lt;h2&gt;&lt;a href="&lt;?php echo get_page_link($page-&gt;ID) ?&gt;"&gt;&lt;?php echo $page-&gt;post_title ?&gt;&lt;/a&gt;&lt;/h2&gt; &lt;div class="entry"&gt;&lt;?php echo $content ?&gt;&lt;/div&gt; &lt;?php } </code> So far function returns all of <code> the_content </code> for all of the children and grandchildren pages. I would like it to specifically return only 1 div with a specific class from each child page and disregard all of the grandchildren pages.
Two suggestions: To output your "Loop" only for Child Pages, and not for Grandchild etc. Pages, add a conditional. e.g. <code> foreach ( $mypages as $page ) { if ( $page-&gt;post_parent == $post-&gt;ID ) { // Loop goes here } } </code> To output only an excerpt of each Child Page, enable excerpt support for Pages, and then output <code> $page-&gt;post_excerpt </code> . In <code> functions.php </code> : <code> add_post_type_support('page', 'excerpt'); </code> Then in your "Loop": <code> foreach ( $mypages as $page ) { if ( $page-&gt;post_parent == $post-&gt;ID ) { $content = $page-&gt;post_excerpt; // changed post_content to post_excerpt if( ! $content ) // Check for empty page continue; $content = apply_filters( 'the_content', $content ); ?&gt; &lt;h2&gt;&lt;a href="&lt;?php echo get_page_link( $page-&gt;ID ) ?&gt;"&gt;&lt;?php echo $page-&gt;post_title ?&gt;&lt;/a&gt;&lt;/h2&gt; &lt;div class="entry"&gt;&lt;?php echo $content ?&gt;&lt;/div&gt; &lt;?php } } </code>
Displaying part of every child page?
wordpress
OK so i have a main menu and a sub-menu How can i make a menu item active when viewing a single post. The sub-menu uses taxonomies so i know i need to make the taxonomy active when one of the posts has the taxonomy in use
So i ended up doing some jquery and lots of it. The downside is that i have to add the code each time i create a new menu. I am looking into re-creating this but do not want to bother with it right now. This is the link to the solution. It is very very temporary so if you wish to use it go ahead but there are better ways. You may be able to hook into the wp_nav_menu classes and add a active class to the current active item and then use some jquery to finish it off.
Show nav link highlighted
wordpress
I've gotten my custom post types to display as it should in date based archives; the structure example.com/year/month/day (and above) works properly as long as it's extended with '?post_type=post_type_name'. With stackexchange-url ("Bainternets") solution I've also gotten wp_get_archives to properly list archives based on whether or not they contain my CPT. The problem is that wp_get_archives still returns the default archive permalinks, like this: example.com/year/month/day but as I mentioned earlier, I need: example.com/year/month/day?post_type=post_type_name Any suggestions on how to achieve this?
From comment: Use the plugin Custom Post Type Archives . It is slightly more flexible than the argument <code> 'has_archive' =&gt; TRUE </code> for <code> register_post_type() </code> .
Extend the wp_get_archives output with '?post_type=foo'?
wordpress
I am using WP 3.0.3 and I would like to exclude sticky posts from my query: This doesn't seem to work: <code> &lt;?php query_posts( 'posts_per_page=9&amp;cat=-1,-2&amp;ignore_sticky_posts=1' );?&gt; </code> To get JUST the sticky post I use the following: <code> $sticky = get_option('sticky_posts'); $args = array( 'posts_per_page' =&gt; 1, 'post__in' =&gt; $sticky ); query_posts($args); </code>
<code> ignore_sticky_posts </code> was introduced in WordPress 3.1. Before this version, you can use <code> caller_get_posts </code> , which will have the same effect (this option was used when you queried the posts via <code> get_posts() </code> , which uses the same <code> WP_Query </code> class in the background, but should ignore sticky posts). The name was a bit confusing, and thus changed in 3.1 .
ignore_sticky_posts in WordPress 3.0.3?
wordpress
My Wordpress site uses a custom front page ( <code> home.php </code> ). The blog page uses a template ( <code> blog.php </code> ). However when I visit the blog page the navigation bar does not highligt the current page. This is because the class <code> .current-menu-item </code> (and the class <code> .current_page_item </code> ) are missing from the navigation <code> li </code> . This class is correctly included when I visit all other pages that use the default page template. Here is the template for the blog page: <code> &lt;?php /* Template Name: Blog */ // Which page of the blog are we on? $paged = get_query_var('paged'); query_posts('cat=-0&amp;paged='.$paged); // make posts print only the first part with a link to rest of the post. global $more; $more = 0; //load index to show blog load_template(TEMPLATEPATH . '/index.php'); ?&gt; </code> I've noticed that if I remove the call to <code> query_posts </code> then the nav bar styling works correctly, but the page is left blank. Any ideas?
The custom navigation menu uses the global <code> $wp_query </code> object to figure out what page is the current page and should get that class. <code> query_posts() </code> replaces this <code> $wp_query </code> object, so the navigation menu can't apply the correct classes. Why do you use a separate template for this page? If you specify no template, it should use the home template ( <code> home.php </code> or <code> index.php </code> ) with the correct posts in the loop, and you should not need your own <code> query_posts() </code> .
Navigation list not correctly styled on pages with custom template (missing .current-menu-item)
wordpress
I'm using Alex Rabe's NextGEN Gallery in a lot of client sites as a centralized image repository, and am finding I often need to load an entire gallery into a lightbox (invoked via a single thumbnail), without displaying more than a single thumbnail on page. Thus, I could have a series of four thumbnails on a page, each thumbnail opening a different set of pictures in a lightbox when clicked. Any idea how I could do this? Thanks.
Output all images of each gallery in your HTML. Use an anchor tag that links to the fullsize image around each thumbnail. Depending on the lightbox plugin you prefer to use, group all images from the same gallery (often done using the <code> rel </code> attribute in HTML). At that point, just hide all but one thumbnail per gallery. Hook your lightbox plugin to the galleries. Check it out: http://jsfiddle.net/8WcUp/1/
Load entire NextGEN gallery from single thumbnail?
wordpress
I have an installation of wordpress with the core wordpress files in a sub-directory as described here: http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory . I've also changed wp-content to just content and moved it outside the wordpress core directory. Everything works fine except the media upload dialog does not load via Thickbox. It will load in the browser window and functions fine. So it seems it's just Thickbox that is not working. Any ideas on what I may have missed, or how to correct this problem?
Update: I fixed the issue myself. The problem was resulting from where I had removed jQuery output from the front end of my site (using my own version) improperly. It was not an issue with Wordpress itself. The function I was using to unset it removed it from the admin as well. I hadn't realized that some of the hooks that can be accessed in the functions.php file can affect the admin as well as the front-end.
How to fix broken admin Thickbox?
wordpress
I followed this tutorial in order too add a custom upload button in the Wordpress admin. It displays the picture you just uploaded right after saving: The problem is that I can't manage to display the picture in the front end, in a template file. This is the section that displays the picture: <code> function ud_section_text() { $options = get_option('ud_options'); echo '&lt;p&gt;Upload your file here:&lt;/p&gt;'; if ($file = $options['file']) { // var_dump($file); echo "&lt;img src='{$file['url']}' /&gt;"; } } </code> So I tried this: <code> &lt;?php var_dump($file['url']); ?&gt; </code> but it returns NULL. Any suggestions? code: <code> &lt;?php /* Plugin Name: Upload Demo Description: Demonstrate a plugin that lets you upload an image Author: Otto Author URI: http://ottodestruct.com License: GPL2 Copyright 2010 Samuel Wood (email : [email protected]) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2, as published by the Free Software Foundation. You may NOT assume that you can use any other version of the GPL. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. The license for this software can likely be found here: http://www.gnu.org/licenses/gpl-2.0.html */ // add the admin page and such add_action('admin_init', 'ud_admin_init'); function ud_admin_init() { register_setting( 'ud_options', 'ud_options', 'ud_options_validate' ); add_settings_section('ud_main', 'Main Section', 'ud_section_text', 'ud'); add_settings_field('ud_filename', 'File:', 'ud_setting_filename', 'ud', 'ud_main'); } // add the admin options page add_action('admin_menu', 'ud_admin_add_page'); function ud_admin_add_page() { $mypage = add_options_page('Upload Demo', 'Upload Demo', 'manage_options', 'ud', 'ud_options_page'); } // display the admin options page function ud_options_page() { ?&gt; &lt;div class="wrap"&gt; &lt;h2&gt;Upload Demo&lt;/h2&gt; &lt;p&gt;You can upload a file. It'll go in the uploads directory.&lt;/p&gt; &lt;form method="post" enctype="multipart/form-data" action="options.php"&gt; &lt;?php settings_fields('ud_options'); ?&gt; &lt;?php do_settings_sections('ud'); ?&gt; &lt;p class="submit"&gt; &lt;input type="submit" name="Submit" class="button-primary" value="&lt;?php esc_attr_e('Save Changes') ?&gt;" /&gt; &lt;/p&gt; &lt;/form&gt; &lt;/div&gt; &lt;?php } function ud_section_text() { $options = get_option('ud_options'); echo '&lt;p&gt;Upload your file here:&lt;/p&gt;'; if ($file = $options['file']) { // var_dump($file); echo "&lt;img src='{$file['url']}' /&gt;"; } } function ud_setting_filename() { echo '&lt;input type="file" name="ud_filename" size="40" /&gt;'; } function ud_options_validate($input) { $newinput = array(); if ($_FILES['ud_filename']) { $overrides = array('test_form' =&gt; false); $file = wp_handle_upload($_FILES['ud_filename'], $overrides); $newinput['file'] = $file; } return $newinput; } </code>
simple answer to this, if you wan to display the image use: <code> $options = get_option('ud_options'); if (isset($options['file'])) { echo "&lt;img src='{$options['file']['url']}' /&gt;"; } </code>
Can't manage to display an uploaded picture (uploaded from a custom button) in the front end
wordpress
I thought about adding it as inline CSS with code from the <code> functions.php </code> (not really sure how to do it). Something like this: <code> function addcss() { background: $this_is_the_css_value; } </code> I would like to know that. But if there's is a better option (without adding inline CSS). I would like to know it too.
One way of doing this would be to create a "CSS" file from PHP. In other words, create a file, call it something like <code> style.css.php </code> , and at the beginning of the file put: <code> &lt;?php header("Content-type: text/css"); </code> Then, link that file in the head of your theme file. Because the <code> style.css.php </code> file is a PHP file, anything you can do in a normal PHP file can be done in this file. As such, you can pull theme option values from the database and use them. For example: <code> #header{ background: &lt;?php echo get_option('my-header-background-color'); ?&gt; } </code> Of course, you need to get the options into the database first, but since your question didn't address that, I won't go into it here.
Best way of adding CSS which can be manipulated by the user via theme option panels?
wordpress
I read somewhere that I can set a constant in the wp-config.php to update WordPress from the latest trunk version and not the stable version. Stupid as I am, I can't find the site anymore where it was written. I know I could also update with SVN, but I thought the autoupdater was a smarter version.
http://wordpress.org/extend/plugins/wordpress-beta-tester/ Sets you up for the nightlies, if that is what you are looking for. I've got it running on my dev install @ cdn.rvoodoo.com. Works great there
How to update WordPress from the latest trunk
wordpress
I have already read this question and answer to it ( stackexchange-url ("Where do I start from") ). So I have slightly different question. If I basicaly have no knowledge of how the WordPress code is structured and I have some ideas for plugin I would like to write should I start at the same place where author of the answer sugested in the post linked above or there is some other path? Thanks to all who will contribute to this question. P.S. I have more than 3.5 years of experience with PHP and other web technologies.
The book Digging into WordPress is a good start. I bought this myself. I found it to be full of useful resources. If you want plugin development then stackexchange-url ("Professional WordPress Plugin Development") is a great book. Another book I bought and I used it to develop my first plugin. Other places to keep visit are Wordpress Codex stackexchange-url ("WordPress StackExchange") and the stackexchange-url ("chat room")
Where is it better to start learning how to develop for Wordpress?
wordpress
So I have written my first WordPress plugin for production and in the next few days I will be starting up on another project where I might have to write two plugins for the same WP site because they do two distinct set of tasks. Now I was reviewing some of the code I had written for the first plugin I thought it would be great if the two plugins could share some of that code that I had written for the first plugin from my earlier project. At first I thought maybe I should just write one plugin that does it all but after some pondering I've come to the conclusion that I wanted my plugins to be small and do few tasks rather than having a bloated plugin that does too much. It would be hard to maintain later. So I was wondering if anyone has ever written a code base for that multiple plugins can share and how you accomplished this. Any relevant links would be appreciated.
Yes, you can easily set up plugins that share a code base. If you make use of global variables and constants, you will be able to read data stored in one plugin by the other. Also, remember that any function registered in one plugin, will be available to all other plugins (unless they're private class functions), as long as the plugin with the function is active.
Is it possible for two WordPress plugins to share the same code base?
wordpress
I want to specify which css file gets loaded when the user clicks on "Appearance > Editor". However, its always loading style.css for some reason. Any way to enforce that a specific file gets loaded there?
This seems to be controlled by global <code> $file </code> variable, which is filled from request (GET or POST) by WordPress. So you will need to pass file you want in request or hook somewhere and override value of the variable. If latter be careful that you don't lock editing to single file altogether. See source for details.
Can I specify that custom.css gets loaded at Appearance > Editor instead of style.css?
wordpress
I'm getting the following PHP warnings when using the WordPress plug-in " Feed JSON ". Can someone tell me how to fix them? Warning: Invalid argument supplied for foreach() in /mypath/wp-content/plugins/feed-json/feed-json-template.php on line 39 Warning: Cannot modify header information - headers already sent by (output started at /mypath/wp-content/plugins/feed-json/feed-json-template.php:39) in /mypath/wp-content/plugins/feed-json/feed-json-template.php on line 53 Here is the code used in feed-json-template. Lines 39 and 53 are highlighted with ** around each line. <code> &lt;?php /** * JSON Feed Template for displaying JSON Posts feed. * */ $callback = trim(esc_html(get_query_var('callback'))); $charset = get_bloginfo('charset'); if ( have_posts() ) { $json = array(); while ( have_posts() ) { the_post(); $id = (int) $post-&gt;ID; $single = array( 'id' =&gt; $id , 'title' =&gt; get_the_title() , 'permalink' =&gt; get_permalink(), 'content' =&gt; get_the_content(), 'excerpt' =&gt; get_the_excerpt(), 'date' =&gt; the_date('Y-m-d H:i:s','','',false) , 'author' =&gt; get_the_author() , ); // thumbnail if (has_post_thumbnail($id)) { $single["thumbnail"] = preg_replace("/^.*['\"](https?:\/\/[^'\"]*)['\"].*/i","$1",get_the_post_thumbnail($id)); } // category $categories = array(); foreach((get_the_category()) as $category) { $categories[] = $category-&gt;cat_name; } $single["categories"] = $categories; // tag $tags = array(); **foreach((get_the_tags()) as $tag) {** $tags[] = $tag-&gt;name; } $single["tags"] = $tags; $json[] = $single; } $json = json_encode($json); nocache_headers(); if (!empty($callback)) { header("Content-Type: application/x-javascript; charset=$charset"); echo "$callback($json);"; } else { **header("Content-Type: application/json; charset=$charset");** echo "$json"; } } else { header("HTTP/1.0 404 Not Found"); wp_die("404 Not Found"); } ?&gt; </code>
Probably get_the_tags() is returning an empty array. Try changing the function to: <code> $my_tags = get_the_tags(); if ($my_tags){ foreach($my_tags as $tag) { $tags[] = $tag-&gt;name; } } </code>
How to fix these PHP Warnings with the "Feed JSON" plug-in?
wordpress
I tried to find anything about adding a widget within a widget area. That widget should be a widget group / sub widget area. I've found a plugin that does this: http://wordpress.org/extend/plugins/extensible-widgets/ http://jidd.jimisaacs.com/files/2010/02/wpew-screen-9.png What I really want is to dynamically create something like this without the help from plugins: http://www.gabfirethemes.com/demos/newspro/ Any bright ideas?
if you take a look at Tabber Tabs Widget plugin does it you will see that it creates a widget and a new "sidebar", now if you place widgets in that sidebar they will show only where you place the plugins widget. and if you look at what Tabbed Widgets plugin does, it creates a widgets that pulls a list of all registered widgets in to a dropdown and lets you choose which ones you want. both seem like nice ways to achieve that , depends on what you need.
Widgets with groups / sub widgets? Widget in a widget?
wordpress
Okay... I turned every stone on the internet and I couldn't find plugin that I need. I want to have a dedicated page for each tag. When I click on a tag I want to get a page with "posts cloud" - all posts tagged with that tag. Post font should be proportional to "popularity" of a post... Is there such thing on earth?
Take a look at CloudClutter theme and see how its done http://wordpress.org/extend/themes/cloudclutter
Posts cloud - Anyone?
wordpress
I have came across the WordPress logout error several times but I really never figured out the cause of it. In earlier days, it was generally that I was missing a nonce but now even with logout link generated by <code> wp_logout_url(); </code> , I am greeted with the WP die screen: <code> You are attempting to log out of SITE Do you really want to log out? </code> What causes this to trigger at the first place? Edit: Like I mentioned it was happening randomly, I think I figured out something. IT works fine with link generated by <code> wp_logout_url(); </code> but as soon as I use a <code> $redirect </code> parameter in <code> wp_logout_url( $redirect ); </code> , I start facing the issue. Any light on the matter?
This message is raised by <code> wp_nonce_ays() </code> which is called by <code> check_admin_referer() </code> . Your browser has probably not sent a referer header, so WordPress could not validate the nonce. This may be a problem in your browser settings or your network connection.
WordPress failure when logging out
wordpress
What's the <code> .php </code> file which generates the <code> Appereance-&gt;Custom Background </code> page in Wordpress' admin panel?
<code> wp-admin/custom-background.php </code>
What's the .php file which generates the Custom Background page in the admin panel?
wordpress
I am trying to find a solution to toggle (hide/show) threaded comments. I need to see only comments 1,2,3 etc... and hide 1.1,1.2,1.3 etc... Clicking "show comments" will toggle and display the thread of comments. example: 1 --- -----clicking "show more comments" shows ----- 1.1 ----- 1.2 ----- 1.3 ----- ... 2 --- -----clicking "show more comments" shows ----- 2.1 ----- 2.2 ----- 2.3 ----- ...
http://jsfiddle.net/K3gr7/4/ I used an ordered list to markup the comments. You probably need to tweak it to your own setup, and cache some variables for optimization, but the functionality is in there. <code> $(document).ready(function() { // Toggle all $('#toggle-all').click(function() { var $subcomments = $('#comments').find('&gt; li &gt; ol'); if ($subcomments.filter(':hidden').length) { $subcomments.slideDown(); } else { $subcomments.slideUp(); } }); // Add buttons to threaded comments $('#comments').find('&gt; li &gt; ol') .before('&lt;button class="toggle"&gt;Show more comments&lt;/button&gt;'); // Toggle one section $('#comments').find('button.toggle').click(function() { $(this).next('ol').slideToggle(); }); }); </code> I misread your question at first, that's why I added a "toggle all" button and left it in there as a free bonus.
Toggle nested comments
wordpress
I want to show post #4/100 at the top for each post for which I'm using following code <code> function updateNumbers() { /* numbering the published posts: preparation: create an array with the ID in sequence of publication date, / / save the number in custom field 'incr_number' of post with ID / / to show in post (within the loop) use &lt;?php echo get_post_meta($post-&gt;ID,'incr_number',true); ?&gt; / alchymyth 2010 */ global $wpdb; $querystr = "SELECT $wpdb-&gt;posts.* FROM $wpdb-&gt;posts WHERE $wpdb-&gt;posts.post_status = 'publish' AND $wpdb-&gt;posts.post_type = 'post' "; $pageposts = $wpdb-&gt;get_results($querystr, OBJECT); $counts = 0 ; if ($pageposts): foreach ($pageposts as $post): setup_postdata($post); $counts++; add_post_meta($post-&gt;ID, 'incr_number', $counts, true); update_post_meta($post-&gt;ID, 'incr_number', $counts); endforeach; endif; } add_action ( 'publish_post', 'updateNumbers' ); add_action ( 'deleted_post', 'updateNumbers' ); add_action ( 'edit_post', 'updateNumbers' ); &lt;?php echo get_post_meta($post-&gt;ID,'incr_number',true); ?&gt; </code> This code seems to work fine for me but I just want to filter posts by category slug &amp; only count posts for that particular category Thanks
You should use one of query functions - <code> get_posts() </code> , it allows to very flexibly configure set of posts to retrieve.
Wordpress Post # of # filtered by category slug
wordpress
Im looking a way to change the following HTML: <code> &lt;div class="votes"&gt;Rating: &lt;strong&gt;+5&lt;/strong&gt; (from 5 votes)&lt;/div&gt; </code> and produce: <code> &lt;div class="votes"&gt;&lt;div class="calculated-rating"&gt;+5&lt;/div&gt;&lt;/div&gt; </code> Thanks in advance.
<code> &lt;script type="text/javascript"&gt; jQuery(document).ready(function(){ jQuery('.votes').each(function(){ votes = jQuery('strong',this).html(); jQuery(this).html('&lt;div class="calculated-rating"&gt;'+votes+'&lt;/div&gt;'); }); }); &lt;/script&gt; </code>
Delete some text and change html tag with Jquery
wordpress
I have my front page setup to display a custom post type via: <code> add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() &amp;&amp; false == $query-&gt;query_vars['suppress_filters'] ) $query-&gt;set( 'post_type', array( 'jwf_portfolio', 'attachment' ) ); $query-&gt;set( 'order', 'menu_order' ); return $query; } </code> What's the most efficient way to have these ordered by the number value in the Order input in the Attributes metabox for each custom post? Currently I'm trying <code> &lt;?php query_posts( $query_string . '&amp;orderby=menu_order' ); ?&gt; &lt;?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?&gt; </code> on my <code> index.php </code> and that's not cutting it.
This did it: <code> add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() &amp;&amp; false == $query-&gt;query_vars['suppress_filters'] ) $query-&gt;set( 'post_type', array( 'jwf_portfolio', 'attachment' ) ); $query-&gt;set('orderby', 'menu_order'); $query-&gt;set('order', 'ASC'); return $query; } </code> No need to mess with <code> index.php </code> now.
Best way to arrange custom post types by Attributes -> Order metabox value?
wordpress
Using JQuery: While the user types, Im trying to find a way to restrict a field to only accept a-z and 0-9, restricting a-z be lowercase without accents like ñ or ó. <code> &lt;input type="text" value="" id="signup_username" name="signup_username"&gt; </code> Thanks in advance.
Jquery is my favorite js library anything you can think of already has a plugin, in your case check out jQuery AlphaNumeric http://www.itgroup.com.ph/alphanumeric/
Accept a-z and 0-9 (restrict a-z to be lowercase without accents like ñ or ó)
wordpress
I'm trying to display the 'Tag Description' on my tagged pages. I've added an if statement to loop-page.php already to only show custom text when a tagged page is being displayed... <code> &lt;?php } elseif ( is_tax ( 'product_tag' ) ){ ?&gt;&lt;h1 class="entry-title"&gt;&lt;?php the_title(); ?&gt; print out this text on page&lt;/h1&gt; </code> ... but I don't know the code to output the tag description. Does anyone know the code to display the tag description? I want it to go after the H1 in the above code. I'm trying to output the description that is entered when you go into Wordpress Admin> Products> Product Tags> Description using WPeC 3.8. I'm using the Twenty10 theme, WPec 3.8 and WP 3.1 Thanks for your help ChainsawDR
get the term by its slug and echo out the descriptions <code> elseif {is_tax ( 'product_tag' ) ){ $term_slug = get_query_var( 'term' ); $taxonomyName = get_query_var( 'taxonomy' ); $current_term = get_term_by( 'slug', $term_slug, $taxonomyName ); ?&gt;&lt;h1 class="entry-title"&gt;&lt;?php echo $current_term-&gt;description; ?&gt;&lt;/h1&gt; &lt;?php } </code>
How to echo tag description on loop-page.php using WPeC 3.8
wordpress
In Wordpress> Settings> Permalinks there is an option at the bottom of the page to change the 'Tag Base'. I've entered 'testtag' in this option and saved, but my tag pages are still displaying as 'tagged' (eg www.example.com/tagged/tagcategory). wpsc-functions.php in the wp-ecommerce> wpsc-core folder... on line 319 'tagged' can be renamed which will change the URL's generated by things like the tag cloud, which in part solves the problem - but when you click on and request those new URL's it generates a 404 error. Does anyone have any ideas please on how I can rename this. I'm using WP 3.1 and Wordpress E-commerce Plugin 3.8. I've got a test site on www.chainsawdr.com. An example of a tag URL can be found by clicking a link in the tag cloud. Any tips or advice would be greatly appreciated. Thanks for reading ChainsawDR.com
Tags are a custom taxonomy called <code> product_tag </code> in WPEC 3.8+, they're not the same taxonomy as default WordPress tags so that's why tagbase has no effect. Line 315 in wpsc-core/wpsc-functions.php: <code> register_taxonomy( 'product_tag', 'wpsc-product', array( 'hierarchical' =&gt; false, 'labels' =&gt; $labels, 'rewrite' =&gt; array( 'slug' =&gt; '/' . sanitize_title_with_dashes( _x( 'tagged', 'slug, part of url', 'wpsc' ) ), 'with_front' =&gt; false ) ) ); </code> *Edit- I somehow skipped over the part of your question where you point out the above, however, changing the slug in this file and then flushing your rewrite rules WILL change the slug, but you're editing core files which is always bad. The question I suppose should then be "Is it possible to override something set elsewhere in a <code> register_taxonomy </code> call?"
How to rename 'Tag Base' with WPeC 3.8?
wordpress
Hey guys, My WordPress permalink structure is set to `/%postname%/. When I create a page with a name "FAQs" the permalink generated is "mydomain.com/faqs". When I link to this page in my code (hardcoded) like this... <code> &lt;a href="&lt;?php bloginfo('home'); ?&gt;/faqs#b" title="FAQ's"&gt;FAQs&lt;/a&gt; </code> (pay attention to the #b hash at the end) ...wordpress somehow automatically notices that there is a page <code> /faqs </code> and replaces <code> /faqs#b </code> just with <code> /faqs </code> (without the hash). Is there a chance I can write a kind of exception to my .htaccess file so WordPress doesn't do that? Any idea how I could make that work?
If your permalink structure is <code> /%postname%/ </code> with a trailing slash, you need to pass the hash like this: <code> /faqs/#b </code> with the trailing slash.
mod-rewrite exception? keep #hash in matching urls?
wordpress
I'm using the plugin comments rating (thumbs up - thumbs down) on my comments template. It stores "karma" in the db column "comment_karma" in comments table. I am looking for a way to sort wp_list_comments by higher karma to lowest. Have tried something like <code> &lt;?php wp_list_comments('callback=mu_custom_callback&amp;orderby=comment_karma&amp;order=DESC') ?&gt; </code> but it's not working. thanks UPDATE I got it working placing in functions.php ` <code> function comment_comparator($a, $b) { $compared = 0; if($a-&gt;comment_karma != $b-&gt;comment_karma) { $compared = $a-&gt;comment_karma &lt; $b-&gt;comment_karma ? 1:-1; } return $compared; } </code> and in comments.php <code> global $wp_query; $comment_arr = $wp_query-&gt;comments; usort($comment_arr, 'comment_comparator'); wp_list_comments('callback=gtcn_basic_callback', $comment_arr); </code> Found on this website
Just incase if you have not checked out the plugin developers page but heres something that you could try <code> if (function_exists(ckrating_get_comments)) { $post_id = $post-&gt;ID; $mycomments = ckrating_get_comments( "post_id=$post_id&amp;status=approve&amp; orderby=comment_karma&amp;order=DESC"); } else $mycomments = null; wp_list_comments(array(), $mycomments); </code> UPDATE I got it working placing in functions.php I got it working placing in functions.php `function comment_comparator($a, $b) <code> function comment_comparator($a, $b) { $compared = 0; if($a-&gt;comment_karma != $b-&gt;comment_karma) { $compared = $a-&gt;comment_karma &lt; $b-&gt;comment_karma ? 1:-1; } return $compared; } </code> and in comments.php <code> global $wp_query; $comment_arr = $wp_query-&gt;comments; usort($comment_arr, 'comment_comparator'); wp_list_comments('callback=gtcn_basic_callback', $comment_arr); </code> Found on this website
Sort comments by karma
wordpress
I'm making a custom activity calendar for a client here: http://arbeidshesten.com/aktivitetskalender/ The backend is a custom post type "aktiviteter", with custom fields for the date ("dato") and some more details. The code looks like this: <code> &lt;table&gt; &lt;tr&gt; &lt;th&gt;Aktivitet&lt;/th&gt; &lt;th&gt;Sted&lt;/th&gt; &lt;th&gt;Dato&lt;/th&gt; &lt;th&gt;kontaktperson&lt;/th&gt; &lt;/tr&gt; &lt;?php $loop = new WP_Query( array( 'post_type' =&gt; 'aktiviteter', 'meta_key' =&gt; 'dato', 'meta_value' =&gt; date('Y-m-d'), 'meta_compare' =&gt; '&gt;=', 'orderby' =&gt; 'meta_value', 'order' =&gt; 'ASC' ) ); ?&gt; &lt;?php while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); ?&gt; &lt;?php $display_date = date('d.m.Y', strtotime(get_post_meta($post-&gt;ID, "dato", true))); ?&gt; &lt;tr&gt; &lt;td&gt;&lt;?php the_title( '&lt;a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark"&gt;', '&lt;/a&gt;' ); ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo get_post_meta($post-&gt;ID, "sted", true); ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $display_date; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo get_post_meta($post-&gt;ID, "kontaktperson", true); ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php endwhile; ?&gt; &lt;/table&gt; </code> Funny thing is that the query returns just 2 aktivities, even though I entered (and published) about 5 future activities. Anyone a clue?
I wonder if adding <code> 'posts_per_page' =&gt; XXX </code> to your query would give the desired results? Just a thought. Good luck!
custom post-type query just returns two posts
wordpress
I'm trying to hook into the "save_post" action from an AJAX callback in my plugin, but it doesn't seem to work. In fact, hooking into "save_posts" only seems to work from a few key action execution points (e.g. "init" or "admin_init") but not from others (e.g. an "add_meta_boxes" callback). In my particular case, I'd like to click a button on the Edit Post screen to add a new custom metabox, and have it save the metabox's data properly. But of course by the time I click that button and add that metabox, I've already hooked the "save_post" action once and WP seemingly doesn't want to let me hook it again. Looking briefly through the WP source code, I don't see any obvious reasons why I shouldn't be able to hook that action again. Any ideas how to work around this apparent limitation, or at least an explanation as to why it's not working?
Adding function to hooks is runtime operation, it is not persistent. Whatever hook operation you run in Ajax actions - they are performed in separate WP instance and expire as soon as Ajax response is returned. They have no influence on currently loaded page. You probably need to hook your functionality to <code> save_post </code> as usual (not in Ajax action) and check for your additional metabox to handle it.
Why can't I hook into save_posts after admin_init?
wordpress
I am trying to set up a category archive (editing category.php) that displays a list of posts from one single category. If I left the twentyten default code <code> (get_template_part( 'loop', 'category' );) </code> and i go to www.mysite.com/categoryname it correctly filters the posts only for the categoryname. If I try to use my custom query code, going to www.mysite.com/categoryname every post is displayed, despite of category. This is the loop code: <code> &lt;?php if (have_posts()) : ?&gt; &lt;?php $args = array( 'post_type' =&gt; 'post', 'posts_per_page' =&gt; 5, 'orderby' =&gt; comment_count, ); query_posts($args); while (have_posts()) : the_post();?&gt; MY CUSTOM CONTENT &lt;?php endwhile; ?&gt; &lt;?php else : ?&gt; &lt;?php endif; ?&gt; </code> thanks
That happens because you are overwriting the query with you $args, If you want to modify it and not overwrite it then use this format: <code> //get the $query_string in to your $args array global $query_string; parse_str( $query_string, $args ); //modify whatever you want $args['post_type'] = 'post'; $args['posts_per_page'] = 5; $args['orderby'] = 'comment_count'; query_posts($args); </code>
Category page showing posts from all categories
wordpress
<code> get_option() </code> provides couple of filters <code> 'pre_option_'.$option </code> and <code> 'option_'.$option </code> . However most times I tried to make use of these it usually explodes and not worth the trouble - either I need to check another option inside my filter, which triggers my filter, which triggers my filter... Another common case is that I need to get current option that I am filtering and I cannot do that because I am filtering it. Just curious - is there some practical logic to follow here? I know I could juggle my filter, but that is overhead that I don't like and filter removal is considered not too reliable by some. ;) For recent practical example - I want to filter <code> posts_per_rss </code> to my option, but provide WordPress value if my option is not set (for the record I know that recommended way to mess with it is via <code> post_limits </code> ).
Usually I remove the filter, then add it back on afterwards; <code> function _my_custom_option( $option ) { remove_filter( 'pre_option_name', '_my_custom_option' ); // do what you like with $option add_filter( 'pre_option_name', '_my_custom_option' ); return $option; } add_filter( 'pre_option_name', '_my_custom_option' ); </code>
get_option() filtering and getting out of recursion
wordpress
I'd like to be able to have categories of a custom post type, how do you set this up? update I want to keep the default categories for regular blog posts, but a separate set of categories just CPT.
You need to add 'taxonomies' => array('category') in your register_post_type() function.
How do you add categories to custom post types in WordPress?
wordpress
I am writing a media plugin that uses custom tables to store its contents. (eg not the post tables where wordpress stores it attachment data). Now i'm looking for a way to use the default wordpress comment system to add comments to it. (These comments will not be in the regular comment table but also a custom table. I need two things: A hook that allows me to intercept the comment submit and process it with my own code if criteria are met. The criteria itself is arbitrary and not important, just need a way to get to the post data before Wordpress processes it. A filter that allows me to replace the wp_list_comments() data with my own tabledata. It's a hacky idea, I know, but the post/attachment table is too limiting for what I need. Any ideas?
<code> wp_list_comments() </code> has no filters or hooks so its going to be a bit hard, what you can do is use <code> comments_array </code> filter hook <code> add_filter('comments_array','my_custom_comments_list'); function my_custom_comments_list($comments, $post_id){ //if criteria are met //pull your comments from your own table //in to an array and return it. return $my_comments; //else return $comments } </code> and as for "intercept the comment submit and process" chips answer would be the best way using <code> preprocess_comment </code> filter hook but you want be able to avoid WordPress form inserting the comment to the default table as well, so you can use <code> wp_insert_comment </code> action hook to remove the comment from the default table right after its inserted: <code> add_action('wp_insert_comment','remove_comment_from_default_table'); function remove_comment_from_default_table( $id, $comment){ //if criteria are met //and the comment was inserted in your own table //remove it from the default table: wp_delete_comment($id, $force_delete = true); } </code>
Intercept comment form submit/list by hook/filter
wordpress
I'm developing Wordpress plugins. When i activate my plugin, i'm getting a message The plugin generated 293 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin. Plugin working very well but i don't know why i'm getting this message. My plugin is : http://wordpress.org/extend/plugins/facebook-send-like-button/
My guess is you get a PHP error, which generates output before the headers are sent. If you have <code> E_NOTICE </code> enabled, calling <code> $_POST['foo'] </code> may generate a "Notice: undefined variable" error if that variable is not set. Best practice: never assume anything about GET, POST, COOKIE and REQUEST variables. Always check first using <code> isset() </code> or <code> empty() </code> . <code> if ( isset( $_POST['foo'] ) ) { $foo = (string) $_POST['foo']; // apply more sanitizations here if needed } </code>
Wordpress Plugin Development - Headers Already Sent Message
wordpress
I have the plugin CustomPress from wpmudev. I know longer have my membership there as it was just to pricey. I am also using there theme wpmu_dixi with some of my own customizations and tweaks. None of those tweaks where to its cor files i just added some new widget locations and messed with the css. Anyways when i go to add a menu item from the custom taxonomy (ie action) which is under the taxonomy type Movies it spits out the following error in the custom menu area (wp-admin/nav-menus.php) <code> Catchable fatal error: Object of class WP_Error could not be converted to string path-to-site/entertain/wp-admin/includes/nav-menu.php on line 73 </code> *i removed out my path I am using wordpress in network mode and have tried creating a tag that was far off and still nothing. The tag action appears on another sub-site but since i tried using a random tag this should not be the problem. I have searched on a few articles and the closest i could find is this one http://premium.wpmudev.org/forums/topic/custompress-error-adding-custom-post-type-via-taxonomies-to-menu
I found out that it is the plugin i am using and have instead decided to use the register function
Error when adding custom taxonomy to wp nav menu
wordpress
I am running a Buddypress site, but I am not getting emails when a new subscriber registers. I have used a code in my functions.php that removes the activation email the user would receive (I want them auto activated and I am using a mailchimp auto responder to contact them upon registering instead). I don't see where this code would disable the email that I should receive when they register, but I am a very novice wordpress user. Can anyone see something that I can change to allow me (the admin) to be notified when a user registers, but not send an activation email to the user? <code> function disable_validation( $user_id ) { global $wpdb; $wpdb-&gt;query( $wpdb-&gt;prepare( "UPDATE $wpdb-&gt;users SET user_status = 0 WHERE ID=%d", $user_id ) ); } add_action( 'bp_core_signup_user', 'disable_validation' ); function fix_signup_form_validation_text() { return false; } add_filter( 'bp_registration_needs_activation', 'fix_signup_form_validation_text' ); function disable_activation_email() { return false; } add_filter( 'bp_core_signup_send_activation_key', 'disable_activation_email' ); </code> Thanks in advance.
Just go to your Network Admin dashboard. Click on Network Settings under Settings tab. and Mark the Check box Registration notification Send the network admin an email notification every time someone registers a site or user account. Now when ever a new user will register you will receive an email.
Buddypress send admin notification email when new subscriber registers
wordpress
My apologies if this question has already been asked somewhere else, I searched but couldn't find anything. I am working on a tours website, there will be individual package pages that show some text, images and some other stuff. On the right hand side of my single package pages I have a comparison table which is merely a custom WP_Query pulling out all packages from the database using the following code: <code> // Package fetching arguments $pargs = array( "numberposts" =&gt; -1, "post_status" =&gt; "publish", "post_type" =&gt; "packages", ); // Get out packages $cpackages = new WP_Query($pargs); </code> I however would like the first item of this comparison table to be the current package the visitor is viewing. Say for example the user is viewing a package called "Tour A" on the right hand side I would like to pull out all packages but make sure that Tour A is at the beginning and highlighted then the other posts displayed. I've looked into sticky posts, but they don't really apply to what I am wanting to do, because if someone is on Tour B, then it needs to be displayed first in the comparison table and then so on.
Loop over the <code> $cpackages </code> results twice, and <code> rewind_posts() </code> in between. first time only output when the id matches the current post id, then skip that id the second time through.
How Can I Always Display A Particular Post First Using WP_Query?
wordpress
I'm using a feed to receive special YouTube feeds organized via playlists. Unfortunately, the URL is not included in the description field, but I can get the videos to display by including the source URL on post. This works fine except since the URL is not in the post area in the editor, the YouTube thumbnail grabbers I have tried don't retrieve these thumbnails. Does anyone know a way I can fetch the featured image through the published version of the post? It needs to be automated because I have way to many post items to adjust them manually.
Each YouTube video has 4 generated images. They are predictably formatted as follows <code> http://img.youtube.com/vi/&lt;insert-youtube-video-id-here&gt;/0.jpg http://img.youtube.com/vi/&lt;insert-youtube-video-id-here&gt;/1.jpg http://img.youtube.com/vi/&lt;insert-youtube-video-id-here&gt;/2.jpg http://img.youtube.com/vi/&lt;insert-youtube-video-id-here&gt;/3.jpg </code> The first one in the list is a full size image and others are thumbnail images. so if you have the video url the you can extract the video id from it call your image, and to do that on posts that are already posted you can use <code> the_content </code> filter hook.
Grab YouTube Thumbnail AFTER Post?
wordpress
How to install WP-cumulus add-on into WordPress ? Thanks,
there you go: Installing wp-cumulus
WordPress Cumulus
wordpress
I have the following query, what it does is get a list of "Books" (custom post type). This list is displayed on a page which also has a small form with a dropdown populated with the terms of "Editors" (custom taxonomy). When a user chooses an "Editor", it reloads the page and the query returns the corresponding "Books". <code> // Taxonomy query $tax_query = array('relation' =&gt; 'AND'); if($_POST['editor']) array_push($tax_query,array('taxonomy' =&gt; 't_editor','terms' =&gt; array($_POST['editor']),'field' =&gt; 'slug')); // Pagination if($_POST['reset_pagination'] || !get_query_var('paged')){ $paged = 1; }else if (get_query_var('paged')) { $paged = get_query_var('paged'); } // Query $myquery = array( 'post_status' =&gt; 'publish', 'post_type' =&gt; 'books', 'orderby' =&gt; 'title', 'order' =&gt; 'ASC', 'tax_query' =&gt; $tax_query, 'paged' =&gt; $paged ); </code> As there are many many "Books", I use pagination. Now, the problem. Lets say I'm on the general list (non-filtered by "Editor"), I have 200 results, with a pagination of ten per page. Let's say I browse until page 8. Then, if I decide to filter my choice by "Editor", the page reloads and displays only those results. The problem is that as I was on page 8, my URL has /page/8/ attached to it. I found how to reset "paged" to 1 after a filtering has been made (with a hidden "reset_pagination" field on the form), it works and I have the results of page 1 after a filtering, BUT in the URL the pagination (/page/8/) remains. How can I remove "/page/x/" from the URL ? Edit : Here's the code for the form <code> &lt;form action="" method="post" id="filter"&gt; &lt;ol&gt; &lt;li&gt; &lt;?php include(TEMPLATEPATH . '/includes/forms/filter_editors.php'); ?&gt; &lt;/li&gt; &lt;li&gt; &lt;input type="hidden" name="reset_pagination" value="1"/&gt; &lt;input type="submit" class="submit" value="&lt;?php _e('Ok'); ?&gt;" /&gt; &lt;/li&gt; &lt;/ol&gt; </code>
Your form will post back to the URL specified in the <code> action </code> parameter, or to the same URL if you don't specify it. You start at <code> /books/page/8/ </code> , so if your <code> action </code> parameter is empty, the resulting URL will also be <code> /books/page/8/ </code> . Just fill in the <code> action </code> parameter with <code> /books/ </code> , and it should work.
Pagination : How to remove /page/x/ after a 'POST' action on a form returning to page 1
wordpress
I am getting this error when I try to return the post_title value from my WP_Query: <code> **Fatal error:** Cannot use object of type WP_Query as array </code> Here is the code: <code> $query = new WP_Query( array( 'meta_key' =&gt; 'Old ID', 'meta_value' =&gt; $atts['oldid'] ) ); return $query['post_title']; </code> How can I show the elements of the post after this query? I am using WP_Query because I am making a shortcode to be used within Posts and Pages.
I'm not sure you understand the logic of <code> WP_Query </code> . Rather than explain in words, here's a code example; <code> $query = new WP_Query( array( 'meta_key' =&gt; 'Old ID', 'meta_value' =&gt; $atts['oldid'] ) ); if ( $query-&gt;have_posts() ) return $query-&gt;posts[0]-&gt;post_title; return ''; </code> Check out the codex on interacting with WP_Query . UPDATE : To use the query as you would normally, i.e. The Loop ; <code> &lt;?php if ( $query-&gt;have_posts() ) : ?&gt; &lt;?php while ( $query-&gt;have_posts() ) : $query-&gt;the_post(); ?&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt; &lt;?php endwhile; ?&gt; &lt;?php endif; ?&gt; &lt;?php wp_reset_postdata(); ?&gt; </code>
What kind of object type is WP_Query?
wordpress
In custom theme development, how does one enable default built-in widgets? Note I mean default built-in widgets, not custom ones. I tried the following example for a WP 3.12 blog by placing it in my theme's functions.php file, trying to activate Pages by default. It didn't work, but I don't know why. <code> function mytheme_widget_init(){ $asOps = array( 'classname' =&gt; 'widget_pages', 'description' =&gt; __( "") ); wp_register_sidebar_widget('pages', __('Pages'), 'wp_widget_pages', $asOps); } add_action('widgets_init','mytheme_widget_init'); </code> What am I doing wrong? EDIT: THE SOLUTION In my theme, I needed to re-edit sidebar.php and use this markup instead. <code> &lt;?php ?&gt; &lt;div id="sidebar" role="complementary"&gt; &lt;ul&gt; &lt;?php if ( !dynamic_sidebar(1) ) : ?&gt; &lt;?php endif; ?&gt; &lt;?php if ( !is_active_sidebar(1) ) : ?&gt; &lt;li id="search" class="widget-container widget_search"&gt; &lt;?php get_search_form(); ?&gt; &lt;/li&gt; &lt;li id="categories" class="widet-container widget_categories"&gt; &lt;?php wp_list_categories('show_option_none=&amp;title_li=&lt;h2&gt;' . __('Categories') . '&lt;/h2&gt;' ); ?&gt; &lt;/li&gt; &lt;li id="archives" class="widget-container widget_archives"&gt; &lt;h2 class="widget-title"&gt;Archives&lt;/h2&gt; &lt;ul&gt; &lt;?php wp_get_archives( 'type=monthly' ); ?&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li id="pages" class="widget-container widget_pages"&gt; &lt;ul&gt; &lt;?php wp_list_pages('title_li=&lt;h2&gt;' . __('Pages') . '&lt;/h2&gt;'); ?&gt; &lt;/ul&gt; &lt;/li&gt; &lt;?php endif; ?&gt; &lt;/ul&gt; &lt;/div&gt;&lt;!-- sidebar --&gt; </code>
that's not the way, <code> wp_register_sidebar_widget </code> is used to create widgets. if you want your sidebar to display widgets by default use <code> [dynamic_sidebar()][1] </code> in your theme eg from the 2010 theme: <code> &lt;div id="primary" class="widget-area" role="complementary"&gt; &lt;ul class="xoxo"&gt; &lt;?php /* When we call the dynamic_sidebar() function, it'll spit out * the widgets for that widget area. If it instead returns false, * then the sidebar simply doesn't exist, so we'll hard-code in * some default sidebar stuff just in case. */ if ( ! dynamic_sidebar( 'primary-widget-area' ) ) : ?&gt; &lt;li id="search" class="widget-container widget_search"&gt; &lt;?php get_search_form(); ?&gt; &lt;/li&gt; &lt;li id="archives" class="widget-container"&gt; &lt;h3 class="widget-title"&gt;&lt;?php _e( 'Archives', 'twentyten' ); ?&gt;&lt;/h3&gt; &lt;ul&gt; &lt;?php wp_get_archives( 'type=monthly' ); ?&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li id="meta" class="widget-container"&gt; &lt;h3 class="widget-title"&gt;&lt;?php _e( 'Meta', 'twentyten' ); ?&gt;&lt;/h3&gt; &lt;ul&gt; &lt;?php wp_register(); ?&gt; &lt;li&gt;&lt;?php wp_loginout(); ?&gt;&lt;/li&gt; &lt;?php wp_meta(); ?&gt; &lt;/ul&gt; &lt;/li&gt; &lt;?php endif; // end primary widget area ?&gt; &lt;/ul&gt; &lt;/div&gt;&lt;!-- #primary .widget-area --&gt; </code>
Enabling Default Widgets in a Custom Theme
wordpress
I am working with someone that has a host (internetplanners.com) that uses fantastico to install WordPress. Basically, my question is has anyone had bad experiences with fantastico or webhost internetplanners.com? Note, I have installed Wordpress on my local machine (Windows) and didn't have any trouble. I don't have experience installing on a hosting service manually but think I could do it needed. Since I wasn't familiar with fantastico one-click install, I did a search and found 2 links about reasons not to use fantastico: http://www.howtospoter.com/web-20/wordpress/3-reasons-not-to-use-fantastico-for-wordpress 1) simplicity = false security (if upgrade breaks, it can be difficult to fix); 2) upgrade doesn't put in maintenance mode or back up database, 3) upgrade doesn't deactivate plug ins. from http://wordpress.org/support/topic/installing-from-justhost : I agree with ZGani. Fantastico doesn't upgrade the third party scripts version frequently. So you have to wait for Fantastico upgrade to get latest version of WordPress. Thanks.
I always thought that Fantastico essentially just; Placed a copy of WordPress on your server (not always the latest version, as you say, this is a local copy limited by the update frequency of Fantastico) Set-up a database (and user) automatically Configured <code> wp-config.php </code> accordingly Then you'd just continue to use WordPress for maintenance as you would normally. In the past, I've worked on WP sites that were set-up with it, and don't recall any issues updating it. Personally, being a geek, I always run a manual install. Just feels cleaner, plus I know I'm always starting with the latest and greatest version.
Fantastico pros and cons
wordpress
I have a custom taxonomy registered for my custom post type. I need to make it possible for a user to specify the order in which the taxonomy terms should appear (something like menu order for pages). Then when displaying the taxonomy terms on the site I will use the specified custom order to order them. What is the best way to do it? Is there any plugin for it? Many thanks, Dasha
Thank you everyone for advice and apologies, I haven't realised that I hadn't have selected the answer for this question. Since I've asked it, I came across Category Order and Taxonomy Terms Order plugin. I mainly use this plugin for ordering.
Custom order of terms for custom taxonomy in admin and website
wordpress
A custom background plugin has started to cause certain browsers (FF, IE8,9, Safari) to reveal an appended url string when viewing the index page: http://dearearth.net - this mostly shows when not visiting the site directly, but rather when going through, for example, google. This persists in IE 9 even after refresh or page reload, but does not on the other browsers. Screenshot: http://i55.tinypic.com/2nv9fh3.jpg I have the following custom permalink structure enabled: <code> /%category%/%postname%/ </code> Thanks for any input!
This doesn't have to be a plugin issue. If someone puts a link on their website to your blog say for example: www.example.com but not only that they place some random string: www.example.com/?foo=bar in that link to your site then when search engines crawl this page with the link to your site on google or any other search engine will see it and try to follow the link to your website. As is the URL is technically valid the search engine will cache it and serve this new URL to its users. Have a read over this post at Perishable Press that talks about it in detail. http://perishablepress.com/clean-up-links-htaccess/
Plugin Appends ugly url string to index
wordpress
I came across a strange problem while working on my dev environment for a site we're making. We have custom post types, so I'm not sure if that's the reason why it's not working correctly. However, I managed to get the posts to display 5 at a time instead of normal 10. However, in one of the categories, it only displays 10 out of 20 posts. What's weird is that if I go to a different category, it'll run correctly. <code> &lt;?php echo category_description(); ?&gt; &lt;?php if (have_posts()) : ?&gt; &lt;?php $i = 0; while (have_posts() &amp;&amp; $i &lt; 5) : the_post(); ?&gt; &lt;div class = "post"&gt; &lt;h3 class="listing-&lt;?php the_ID(); ?&gt;"&gt; &lt;br&gt; &lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="Permanent Link to &lt;?php the_title(); ?&gt;"&gt; &lt;?php the_title(); ?&gt; &lt;/a&gt; &lt;/h3&gt; &lt;/br&gt; &lt;div class = "city"&gt; &lt;b&gt; City:&lt;/b&gt; &lt;?php $City = get_post_meta($post-&gt;ID, 'City', true); echo $City;?&gt; &lt;/div&gt; &lt;div class = "price"&gt; &lt;b&gt; Price:&lt;/b&gt; &lt;?php $Price = get_post_meta($post-&gt;ID, 'Price', true); echo $Price;?&gt; &lt;/div&gt; &lt;b&gt;Rating:&lt;/b&gt; &lt;div class = "rating"&gt; &lt;?php wp_gdsr_render_article(); ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;br&gt; &lt;/br&gt; &lt;?php $i++; endwhile; ?&gt; &lt;div class="navigation"&gt; &lt;div class="alignleft"&gt; &lt;?php previous_posts_link(); ?&gt; &lt;?php next_posts_link(); ?&gt; &lt;/div&gt; </code> Answer : Thanks for the help everyone! The way to get around it is to go to: <code> WP Dashboard &gt; Settings &gt; Reading </code> and change the number at "blog pages show at most" option to the number of pages to display.
The problem is that your query is selecting 10 posts per page, but you're only limiting the view to 5, so you're losing 5 posts per page. The proper way to change the number of posts per page is to modify the query before the loop: <code> &lt;?php $myquery = wp_parse_args($query_string); $myquery['posts_per_page'] = 5; query_posts($myquery); if (have_posts()) : // etc. </code>
Displaying Custom Posts
wordpress
Here is what I have: A custom post type that has a custom meta value added to a post that stores the posts expiry date. When the post passes this expiry date it no longer shows on the site. This works but I'm using something like this to list the terms for the custom post type: <code> $termcats = get_terms('dcategory', 'hide_empty=0&amp;orderby=name&amp;pad_counts=1'); </code> I'm showing the count of posts in the listed terms but the problem here is that the count shows all post whether or not if the post has expired. So for example I have one post in the term called <code> test </code> and that post is expired. The above code shows there is one post but when the user click the category they get a blank list. So I need a way to hook into get_terms() to ignore posts that have expired according to my date field in meta values.
As far as I remember counts for terms are stored in database, so there is nothing to modify when you fetch them - you simply get ready-made numbers. So you will either need to implement and maintain your special logic for counts completely separately or try to recalculate and modify native counts, see <code> wp_update_term_count_now() </code> .
How to hook get_terms() to only show count of posts that have custom meta
wordpress
I am not sure how to add multiple capabilities to 'assign_terms' capability. My code is below, notice the capabilities array within the register_taxonomy function <code> /* Registers taxonomies. */ function cflnk_wod_score_register_taxonomies() { /* Set up the artist taxonomy arguments. */ $wod_name_args = array( 'hierarchical' =&gt; false, 'query_var' =&gt; 'wod_name', 'show_tagcloud' =&gt; true, 'rewrite' =&gt; array( 'slug' =&gt; 'wod/name', 'with_front' =&gt; false ), here ---&gt;&gt;&gt; 'capabilities' =&gt; array ( 'manage_terms' =&gt; 'administrator', 'edit_terms' =&gt; 'administrator', 'delete_terms' =&gt; 'administrator', 'assign_terms' =&gt; 'administrator', 'editor', 'author', 'contributor' ), 'labels' =&gt; array( 'name' =&gt; 'WOD Names', 'singular_name' =&gt; 'WOD Name', 'edit_item' =&gt; 'Edit WOD Name', 'update_item' =&gt; 'Update WOD Name', 'add_new_item' =&gt; 'Add New WOD Name', 'new_item_name' =&gt; 'New WOD Name Name', 'all_items' =&gt; 'All WOD Names', 'search_items' =&gt; 'Search WOD Names', 'popular_items' =&gt; 'Popular WOD Names', 'separate_items_with_commas' =&gt; 'Separate wod names with commas', 'add_or_remove_items' =&gt; 'Add or remove wod names', 'choose_from_most_used' =&gt; 'Choose from the most popular wod names', ), ); </code>
When assigning capabilities to 'capabilities' argument of <code> register_taxonomy() </code> you need to assign the capability and not the role! so use capabilities that only a specific role has eg: <code> 'capabilities' =&gt; array ( 'manage_terms' =&gt; 'manage_options', //by default only admin 'edit_terms' =&gt; 'manage_options', 'delete_terms' =&gt; 'manage_options', 'assign_terms' =&gt; 'edit_posts' // means administrator', 'editor', 'author', 'contributor' ) </code>
How to assign multiple roles for capabilities array withini register_taxonomy function?
wordpress
I'd like to display 9 posts and be able to insert a sticky post with its custom html template in between 4th &amp; 5th post. Currently the sticky post gets displayed in both the "sticky container" and regular posts. have_posts()) : $my_query-> the_post(); ?> <code> &lt;?php if ($count &lt;= 9 ){ ;?&gt; &lt;article&gt; &lt;?php echo get_the_content(); ?&gt; &lt;/article&gt; &lt;?php if ($count == 3) { $sticky = get_option('sticky_posts'); $args = array( 'posts_per_page' =&gt; 1, 'post__in' =&gt; $sticky, 'ignore_sticky_posts' =&gt; 1 ); query_posts($args); if ( have_posts() ) : while ( have_posts() ) : the_post(); if($sticky[0]) { ?&gt; &lt;article&gt; &lt;h1&gt;CUSTOM HTML&lt;/h1&gt; &lt;?php echo get_the_content(); ?&gt; &lt;/article&gt; &lt;?php } endwhile; else: endif; wp_reset_query(); }?&gt; &lt;?php } $count++; ?&gt; &lt;?php endwhile; ?&gt; </code>
Your code looks odd to me, typically to insert something between posts you add a counter and count each loop, then add custom code on a particular count, this is for the main loop, for a non main loop or secondary loop us wp_query. <code> &lt;?php if (have_posts()) : ?&gt; &lt;?php $count = 0; ?&gt; &lt;?php query_posts( 'posts_per_page=9' );?&gt; &lt;?php while (have_posts()) : the_post(); ?&gt; &lt;?php $count++; ?&gt; &lt;?php if ($count == 4) : ?&gt; // Your custom sticky post and html goes here &lt;?php else : ?&gt; // the regular loop code goes here such as the below &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 the_excerpt(); ?&gt; &lt;?php endif; ?&gt; &lt;?php endwhile; ?&gt; &lt;?php endif; ?&gt; </code>
How to display sticky post with custom html
wordpress
How to create a blog in a sibling directory of an already installed WordPress directory? The domain is <code> example.com </code> and there is an existing installation in <code> blog </code> directory and the root directory at <code> example.com/ </code> is free. Is it possible to create a blog at <code> example.com/anotherblog/ </code> through multisite instead of <code> example.com/blog/anotherblog/ </code> ? On a new installation at the root this can be achieved by simply installing WordPress at the root and having two multisite blogs in two directories. However, that is total of 3 blogs(including the one at the root). Can the same be achieved without the 3rd blog and keep the root free?
I'm pretty sure that this can't be done. I think WP multisite can only control blogs that are underneath it - which is why you'd have to install WP at the root. I was once looking to do the same thing, and unfortunately all my research pointed to "no" being the answer.
Multisite installation on an existing single installation
wordpress
Can someone recommend me a nice countdown widget plugin for Wordpress? I've been using the Countdown widget under Blogger and it's exactly what I need. A simple number from now until date or from date. I can't seem to find a very simple, easy countdown that does the same thing in Wordpress.
Yes, there's a great widget called the jQuery T-Minus Countdown Widget Enjoy!
Countdown Widget
wordpress
I'm building a site for a magazine using WP and am needing to display a month of posts at a time. How would I make the next_posts_link(); and previous_posts_link(); functions return results, shorted as one month per page? If I can't do it via those functions, how would I make the front page display in an archive-like mode? Thanks!
You have to modify the query that selects the posts to select by month. This bit of code placed in the template will get the page number and subtract that from the current month. <code> &lt;?php $page = get_query_var('paged') ? get_query_var('paged') : 1; $subtractor = $page-1; $date = date("Y-m-d H:i:s"); $current_month = date('n', strtotime($date.'-'.$subtractor.'months')); $current_year = date('Y', strtotime($date.'-'.$subtractor.'months')); query_posts("monthnum=$current_month&amp;year=$current_year&amp;order=DESC"); if (have_posts()) : while (have_posts()) : the_post(); // rest of the loop below </code> Ultimately this is probably best hooked into pre_get_posts to keep it out of the template. You'd have to make your own pagination links as well, something like: <code> &lt;?php if($page&gt;1) echo '&lt;a href="/page/'.($page-1).'/"&gt;next&lt;/a&gt;'; echo '&lt;a href="/page/'.($page+1).'/"&gt;prev&lt;/a&gt;'; </code> of course, you'd have to figure out how far back the posts go to know when to stop providing a previous month link, hmm...
Making next_posts_link(); return posts by month
wordpress
In stackexchange-url ("this post on wordpress.stackexchange.com") I asked whether using get_template_part(), as demonstrated in the TwentyTen theme, is a recommended best practice. The general consensus I got was that it was not necessarily the best practice in all situations. This related question then is: can you provide me with an example where using get_template_part() would be the recommended approach, over simply defining the separate template.php files? For example, I can either define archive.php, single.php and page.php; or I can define loop-archive.php, loop-single.php and loop-page.php. In what circumstances would it be preferable to use get_template_part('loop', 'single') and leverage loop-single.php versus simply defining single.php?
A recommended approach for using <code> get_template_part </code> would be for including bits of code that would otherwise be repeated frequently in all your templates. Like if you had conditionals defined within your loop that you wanted to include in archive.php, search.php, single.php etc. It also allows child themes to override that file and include additional more specific files. For example if you used <code> get_template_part( 'loop', 'single' ) </code> and your theme only has a file named loop.php then a child theme could include a file named loop-single.php that would override your loop.php. It's basically a custom includes tag for template files other than header, sidebar, or footer.
When is get_template_part() preferable to simply using the template.php files?
wordpress
I am running a theme on my Wordpress install that was built for Wordpress 2.8, prior to the time that Wordpress started using featured images for posts. I am switching to a theme that was built for Wordpress 3.1 and it uses the featured image instead of looking for a custom field. I have a lot of old posts with the custom field for the image. Is there a tool I can use that takes the custom field image URL and turns it into the post's featured image? I Googled this and also searched here on Wordpress Answers to no avail. I did find a custom script on the Wordpress forums, but I didn't try it because some people had responded saying it didn't work correctly.
http://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature LIsts a plugin: http://wordpress.org/extend/plugins/get-the-image I'm not sure by the article and description if what you are looking for is exactly what it does? It seems to imply that, but I'm not 100%
How can I migrate all of my custom field thumbnails to the built-in post featured image?
wordpress
We're trying to use WordPress as a light CMS system and we need to be able to section off parts of WordPress so that editors for one product aren't able to edit other products. Seems like out of the box WP has 5 user levels but there isnt any thought around fine grain access (without using WP Network)
Google is your friend ;) Restrict categories Role Scoper
How can I limit WordPress editor roles to a specific category?
wordpress
I have the following code: <code> &lt;?php if ((is_home()) OR (!is_single()) OR (!is_page('171'))) : ?&gt; &lt;body&gt; &lt;?php else: ?&gt; &lt;body class="last-page"&gt; &lt;?php endif; ?&gt; </code> However it doesn't seem to work as expected. I want the class "last-page" to be applied to the body of the page with the id of 171 and pages that display single posts. If I take the third condition out, the "last-page" class is applied correctly to single post pages but with the third condition there it doesn't get applied to any of the two. I want the "last-page" class to be applied to both single post pages and page 171. Appreciate the help.
from your verbal desription, i would think this should work: <code> &lt;?php if ( is_single() OR is_page('171') ) : ?&gt; &lt;body class="last-page"&gt; &lt;?php else: ?&gt; &lt;body&gt; &lt;?php endif; ?&gt; </code>
How to apply style to the body tag of a particular page?
wordpress
I have a plugin I want to use, but it depends on the $ identifier, as apposed to using jQuery. Is it possible to enable the $, to save me recoding the plugin? EDIT The plugin automatically adds the javascript, therefore I can't wrap it.
Try this: <code> jQuery(function ($) { /* You can safely use $ in this code block to reference jQuery Call your plugin here */ }) </code> I think you already know this. But still for reference http://api.jquery.com/jQuery.noConflict/
how can I make $ work in wordpress for jQuery?
wordpress
I'm trying to do some WordPress URL rewriting ... Specifically I have custom post type that currently works like this: <code> http://mydomain.com/videos/post-title/ </code> But I would like to have it located at: <code> http://mydomain.com/videos/author-name/post-title/ </code> Is there any way to achieve this?
using Jhon's Custom Post Permalinks plugin it should be easy using: <code> /%post_type%/%author%/%postname%/ </code>
Adding %author% in custom post type URL structure?
wordpress
I'm using the WP-TweetButton but when I set the settings to add the button manually. Nothing is displayed. Settings: The Code: <code> &lt;div id="social-buttons"&gt; &lt;div id="tweet-button"&gt; &lt;?php tweetbutton(); ?&gt; &lt;/div&gt; &lt;div id="fb-share"&gt;&lt;?php if (function_exists('fbshare_manual')) echo fbshare_manual(); ?&gt;&lt;/div&gt; &lt;div id=fb-like&gt;&lt;iframe src="http://www.facebook.com/plugins/like.php?href=&lt;?php echo urlencode(get_permalink($post-&gt;ID)); ?&gt;&amp;amp;layout=standard&amp;amp;show_faces=false&amp;amp;width=450&amp;amp;action=like&amp;amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:60px"&gt;&lt;/iframe&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="next"&gt;&lt;?php previous_posts_link( __( 'next &amp;rarr;', 'twentyten' ) ); ?&gt;&lt;/div&gt; &lt;?php endif; ?&gt; &lt;/div&gt; </code> I'm using Wordpress 3.1.2 and the last version of the plugin. Is anyone having this problem too? Have anyone managed to fix it?
I finally, got it; <code> &lt;?php echo tweetbutton(); ?&gt; </code>
WP-TweetButton is not displaying the tweet button if this is set to "Manual."
wordpress
What is the best way to add php to the edit link? For example: insert <code> &lt;?php echo of_get_option('dappo_actionbtncolor', 'dappblue' ); ?&gt; </code> into the span tag of <code> &lt;?php edit_post_link( __( 'Edit this', 'mytheme' ), '&lt;span class="edit-link"&gt;', '&lt;/span&gt;' ); ?&gt; </code>
The easiest way might be to use <code> get_edit_post_link() </code> ( Codex ref ), which returns just the link, allowing you to use it however you need, according to your purposes.
PHP in Edit Post link
wordpress
I am using <code> $wpdb-&gt;update </code> to update a custom table I have in my database. When I <code> var_dump </code> the result it returns: <code> int(0) </code> So I tried <code> $wpdb-&gt;print_error() </code> to see what's wrong. However, it shows nothing. I also tried <code> $wpdb-&gt;show_errors() </code> , but again it showed nothing. The wpdb docs don't go into much detail on how to use these functions, so I am unsure if I am using them correctly. But why would the result of updating a table return 0, and not show any errors?
I would recommend running the following code right after your query to see what's happening: <code> exit( var_dump( $wpdb-&gt;last_query ) ); </code> This should print the last query that hit your database. In cases like these, I usually will manually run such a query through phpMyAdmin to see if it runs without errors and to see if it even affects the database. Additionally, by seeing the query that was actually run, you may find problems in the query that results from your code. For instance, the query may not return any MySQL errors, but it could run a query that is different than you expect it to be. With this debug code, you'll at least be able to see what it is and continue on the wonderful debug trail! Furthermore, you may want to explore more of the "Class Variables" (Codex Ref) for <code> $wpdb </code> as they may help further troubleshoot your issue.
Showing errors with $wpdb update
wordpress
Situation: I'm working on a plugin and I'm developing it as a class, everything worked fine until I run into this situation. I wanted to make things a bit cleaner and tried this.. <code> class MyPlugin { function __construct() { add_action('admin_menu', array(&amp;$this, 'myplugin_create_menus'); } //I don't want to write a function for every options page I create //so I prefer to just load the content from an external file. function load_view($filename) { $view = require(dirname(__FILE__).'/views/'.$filename.'.php'); return $view; } //Here is where the problem comes function myplugin_create_menus() { add_menu_page( 'Plugin name', 'Plugin name', 'manage_options', 'my-plugin-settings', array(&amp;$this, 'load_view') // Where do I specify the value of $filename?? ); } }#end of class </code> I've tried a bunch of different options but nothing works, maybe I'm in front of it but I can't see it. Of course this is a re-creation, I've prefixed all my functions and they are not exactly as I wrote here but I hope you got the idea of I'm asking for. Thanks in advance. P.D.: If you want to see the original source code I'll be glad to paste it and give you the link.
You can't pass an argument to the callback function. <code> add_menu_page() </code> adds it as an action handler , and <code> admin.php </code> fires the action , without any arguments. I see two simple solutions to this problem. One is to store all filename in an array in your class, indexed by hook name. Then you can use this to look up what file you need to load (you can also store additional data in this array). <code> class WPSE16415_Plugin { protected $views = array(); function load_view() { // current_filter() also returns the current action $current_views = $this-&gt;views[current_filter()]; include(dirname(__FILE__).'/views/'.$current_views.'.php'); } function myplugin_create_menus() { $view_hook_name = add_menu_page( 'Plugin name', 'Plugin name', 'manage_options', 'my-plugin-settings', array(&amp;$this, 'load_view'), ); $this-&gt;views[$view_hook_name] = 'options'; } } </code> The other is to skip the callback argument, so WordPress will include the file indicated by the slug name itself, as Brady suggests in his answer.
Passing arguments to a admin menu page callback?
wordpress
I have downloaded a plugin called Stream Video Player , which has a shortcode. If I put the shortcode into the content editor, it works well and it displays the video. However, if, inside a template I am creating, I call it through the <code> do_shortcode() </code> function, it doesn't work, it just shows the text <code> [stream bla bla] </code> . Can anyone help me and tell me why this is happening?
It's not really a shortcode, its a content filter but you can try calling the plugins function directly: <code> if (function_exists('StreamVideo_Parse_content')){ echo StreamVideo_Parse_content("[stream flv=xxx.es/wp-content/uploads/2011/04/VIDEO-UE.mp4 mp4=xxx.es/wp-content/uploads/2011/04/VIDEO-UE.mp4 provider=video img=xxx.es/wp-content/uploads/2011/04/previo-video.jpg embed=false share=false width=500 height=333 dock=true controlbar=over bandwidth=high autostart=false opfix=true /]"); } </code>
Stream Video Player does not work with do_shortcode()?
wordpress
I'll just like to add that I have a current working solution in place and works well but I'm looking for ideas of being able to do it better or cleaner if possible. We have hundreds of properties in a custom post type with metakey/metavalue holding the properties longitude and latitude co-ordinates. We allow a visitor to type in a location and a radius to search for those properties in that area. Kind of like a store locator. Here is how I'm doing it at the moment: <code> // Work out square radius if(!empty($_SESSION['s_property_radius'])) {$dist = $_SESSION['s_property_radius'];}else{$dist = 50;} $orig_lat = $_SESSION['s_property_address_lat']; $orig_lon = $_SESSION['s_property_address_lng']; $lon1 = $orig_lon - $dist / abs( cos( deg2rad( $orig_lat ) ) * 69 ); $lon2 = $orig_lon + $dist / abs( cos( deg2rad( $orig_lat ) ) * 69 ); $lat1 = $orig_lat - ( $dist / 69 ); $lat2 = $orig_lat + ( $dist / 69 ); // Compile a map search query to get all property ID's. $mapsearchquery = " SELECT `t`.`ID` , 3956 * 2 * ASIN( SQRT( POWER( SIN( ( ".$orig_lat." - CAST(`t`.`property_address_lat` AS DECIMAL(9,6)) ) * pi() / 180 / 2), 2 ) + COS( ".$orig_lat." * pi() / 180) * COS( CAST(`t`.`property_address_lat` AS DECIMAL(9,6)) * pi() / 180 ) * POWER( SIN( ( ".$orig_lon." - CAST(`t`.`property_address_lng` AS DECIMAL(9,6)) ) * pi() / 180 / 2 ), 2 ) ) ) AS `distance` FROM ( SELECT `$wpdb-&gt;posts`.`ID` , MAX(CASE WHEN `$wpdb-&gt;postmeta`.`meta_key` = 'chb_homes_for_sale_address_longitude' THEN `$wpdb-&gt;postmeta`.`meta_value` END ) AS `property_address_lng` , MAX(CASE WHEN `$wpdb-&gt;postmeta`.`meta_key` = 'chb_homes_for_sale_address_latitude' THEN `$wpdb-&gt;postmeta`.`meta_value` END ) AS `property_address_lat` FROM `$wpdb-&gt;posts` LEFT JOIN `$wpdb-&gt;postmeta` ON ( `$wpdb-&gt;posts`.`ID` = `$wpdb-&gt;postmeta`.`post_id` ) WHERE `$wpdb-&gt;posts`.`post_status` = 'publish' AND `$wpdb-&gt;posts`.`post_type` = 'homes-for-sale' GROUP BY `$wpdb-&gt;posts`.`ID` HAVING CAST(`property_address_lng` AS DECIMAL(9,6)) BETWEEN '".$lon1."' AND '".$lon2."' AND CAST(`property_address_lat` AS DECIMAL(9,6)) BETWEEN '".$lat1."' AND '".$lat2."' ) AS `t` HAVING `distance` &lt; ".$dist." "; // Just get the ID's $mapsearchresults = $wpdb-&gt;get_col($mapsearchquery); </code> This returns an array of all post id's that are within the users search parameters. I then past that array to WP_Query to only show posts that have the above ID's using <code> post__in </code> . Also I can do other search criteria on the WP_Query afterwards. In the above query I do a square radius check and I know this could be easily done in WP_Query using <code> meta_query </code> . But where I get stuck is running the circle radius check. Is there a way I can wrap this in WP_Query? Basically what I'm after is trying to do this all in one rather than doing two lots of queries.
I would duplicate the coordinates of the posts in a separate table <code> (post_id, lat, lon) </code> , with an index on <code> (lat, lon) </code> . With all the joins and the casts I doubt the database can use an efficient index with your query. I once wrote stackexchange-url ("an answer to a similar question") using this approach.
Is it possible to wrap Geo Location search around WP_Query?
wordpress
I need a plugin for custom post type. I need something like this: Can anyone suggest a plugin which has this feature, especially image upload and "Add another" button option.
This metabox class does exactly what you are after and so much more. wpalchemy-metaboxes
Multiple image uploader under editor?
wordpress
I'd like to make all the links in posts on one of my sites to be with rel="nofollow" on links inside posts. I wasn't able to find a plugin that did the job except for WP-NoExternalLinks. It also didn't work, unless I used it's dooms day option: "Mask ALL links in document (can slow down your blog and conflict with some cache and other plugins. Please use it on your own risk." But when I use it, it also puts nofollow on my blogroll links (which I would have preferred to keep alive.) Any suggestion what might be causing this? or how to resolve it? Thanks.
you can add a filter in your functions.php add <code> // Nofollow in content add_filter('the_content', 'my_nofollow'); function my_nofollow($content) { //return stripslashes(wp_rel_nofollow($content)); return preg_replace_callback('/&lt;a[^&gt;]+/', 'my_nofollow_callback', $content); } function my_nofollow_callback($matches) { $link = $matches[0]; $site_link = get_bloginfo('url'); if (strpos($link, 'rel') === false) { $link = preg_replace("%(href=\S(?!$site_link))%i", 'rel="nofollow" $1', $link); } elseif (preg_match("%href=\S(?!$site_link)%i", $link)) { $link = preg_replace('/rel=\S(?!nofollow)\S*/i', 'rel="nofollow"', $link); } return $link; } </code>
A plugin for having rel="nofollow" in posts?
wordpress
If you were configuring a new VPS for a WP website that hasn't launched yet, What technologies would you choose? (website specs below) Website Targeting 50-60k hits /mo. and more The website is designed to categorize embedded YouTube videos using a chained select menu (1 query for multiple boxes). Using less than 5 "static" pages. I would like to keep the homepage fairly static so the server can cache it easier. Server Starting with a Linode 512mb VPS, can scale up as needed. What I have planned so far After scouring the web, it seems that Apache with an Ngnix reverse proxy does not offer any benefits with unless you need Apache for cPanel, or are more comfortable with it (i'm not, just starting out). Latest Nginx PHP-FPM X-Cache (also using W3 Total cache in WP)
There's a post here that's very good about load optimization and performance: stackexchange-url ("Steps to Optimize WordPress in Regard to Server Load?") It might be a good idea to also utilize a CDN for a majority of your page requests. If you want performance you'll have to minimize requests to your database and setup aggressive caching. Working with Drupal i know this can be built into your drupal install. I'm not very familiar with Wordpress and if there are capabilities integrated into Wordpress to facilitate reverse proxy requests. If you're going to use mem-cache you may need more Ram to serve up the page. You may want to also setup varnish on your server. Setting up varnish alone will give you a big boost; as i've been told. Varnish http://www.varnish-cache.org/
Fastest Server Config, Whats your suggestion?
wordpress
I'm trying to synchronise my files with the Amazon S3 server for distribution using CloudFront, as the CDN. I am currently having troubles syncing the files though. I've verified that the details are correct, though, when I click on sync it says it is syncing 1 item of many, but looking at the S3 bucket, it doesn't seem to do that. There are no errors in the PHP log to help me either. I'm running WordPress 3.1.2, on Windows Server 2008 R2, IIS 7.5 - PHP 5.3.6. cURL is installed, as per PHPInfo Any ideas what's going on here? Thanks, Shamil
I switched to W3 Total Cache, and it now works.
Cannot upload to S3 using CDN Sync Tool
wordpress
Recently our site began no longer returning correct search results. When searching it returns one result that's unrelated to the inquiry. I've turned off all plugins and reverted back to a day when I thought it was working properly to no avail. What could possibly cause this to occur? You can see in the image below that the result is not related to the inquiry. Here's an example of a page with the title and terms related to the inquiry. The front end also returns inaccurate results
AFAIK, out-of-the-box WordPress does not include taxonomies, such as tags and categories, in it's search, only post titles &amp; content. I'm sure this has always been the case, so I'm a little confused as to why it 'used to work'. Perhaps the pages have been modified, and used to contain the search terms themselves, but no longer do? UPDATE : Taking a look at your <code> functions.php </code> , I see three possible troublemakers; Line 572, <code> add_filter('pre_get_posts', 'query_post_type'); </code> Line 597, <code> add_filter('pre_get_posts','SearchFilter'); </code> Line 776, <code> add_filter('posts_groupby', 'group_by_post_type' ); </code> I suggest, one at a time, commenting out the line (prepend the line with <code> // </code> ) and then testing a search. If there are no improvements, try all three commented out and work your way backwards. Either way you should be able to isolate the problem. Also, two minor improvement suggestions (off-topic); Remove the line <code> add_action('init', 'my_init_method'); </code> (it's worthless) Remove the two <code> update_option </code> calls at the top (unneccessary database writes on every request).
What would causes search to return incorrect results?
wordpress
On this page: http://codex.wordpress.org/Function_Reference/wp_add_dashboard_widget The function wp_add_dashboard_widget is described. It states: <code> wp_add_dashboard_widget($widget_id, $widget_name, $callback, $control_callback = null) </code> How do you use the $control_callback, properly? I am completeley stuck, as I have defined it but cannot use it. I need to create a form within this widget which is why I am using the control_callback. EDIT: as a side note I am using Wordpress 3 and Multisite
Solution : hover on the title bar of your widget, then click configure Don't ask me why this works like this but it does.
How do I use the control callback when creating a simple dashboard plugin
wordpress
I want two menus using the new WordPress 3.0 feature. In <code> functions.php </code> I have: <code> function register_my_menus() { register_nav_menus( array( 'header-menu' =&gt; __( 'Header Menu' ), 'top-menu' =&gt; __('Top Menu') ) ); } add_action( 'init', 'register_my_menus' ); </code> And in <code> header.php </code> I have: <code> &lt;?php wp_nav_menu( array( 'name' =&gt; 'Header Menu' ) ); ?&gt; .... &lt;?php wp_nav_menu( array( 'name' =&gt; 'Top Menu' ) ); ?&gt; </code> Now they seem to fallback or something, always showing the same menu. The menus have been defined and setup in wp-admin "theme-locations". Why won't they load appropriately?
<code> wp_nav_menu() </code> does not have a <code> name </code> argument . Instead, you should use <code> theme_location </code> . With <code> register_nav_menus() </code> , you indicate that you have two locations in your theme where you can display a menu. The user can then create multiple menus, and assign them to these locations. This is why we have the indirection via <code> theme_location </code> . If you know the ID, slug or name of the menu you want to use, you can use the <code> menu </code> argument of <code> wp_nav_menu() </code> .
Can't display custom menu using name?
wordpress
say i've got a url http://bfami.modernactivity.co.uk/category/museum/orderby/date/order/desc/ that works with; <code> add_rewrite_rule( 'category/(.+?)/orderby/([^/]+)/order/([^/]+)(/page/?([0-9]{1,}))?/?$', 'index.php?category_name=$matches[1]&amp;paged=$matches[5]&amp;orderby=$matches[2]&amp;order=$matches[3]', 'top' ); </code> how do i get the value of orderby or order on a page? Think wordpress removes the GET values which is what i'd normally use... Just want to highlight the active order filter on the page!
ended up with; <code> class="&lt;?=( strpos( $oby ,'date' ) ? 'active' : null )?&gt;" </code> though can imagine i'll need to get this working on one job or the other... thanks all!
get variable from url?
wordpress
At the begining, I thought there was an issue with my HTML or CSS files. But then I realized that other people using Wordpress 3.1 had the same problem (check out stackexchange-url ("this link")). The admin bar disappears when I click another 'Pages' or 'Posts,' but it leaves its 28px padding at the top of the page. I'm not sure if this has something to do with folder's permission issues in ubuntu (I'm using ubuntu 11.04). I did <code> chmod -R 777 </code> to my <code> www </code> folder (the default folder for my <code> locahhost </code> ), but I'm still having the same issue. Any suggestions to fix this?
Verify that <code> wp_footer() </code> is being called in all template files, and that the Admin Bar javascript and CSS are being properly hooked into the document head.
Wordpress 3.1's admin bar disappears only leaving its 28 px padding (in ubuntu)!
wordpress
I am trying to find a function, plugin, query - something that will separate the parent comment count from the reply count. Does anyone know how to achieve this? 10 comments total are broken into 3 parent comments and 7 replies. How can I display this at the top of the comment form? Please &amp; thank you!
here's a quick and dirty method... in functions php, we create a callback function for wp_list_comments() which will count our comments: <code> $GLOBALS['parent_comments_count'] = 0; $GLOBALS['child_comments_count'] = 0; function count_comments( $comment, $args, $depth ) { $GLOBALS['comment'] = $comment; if($comment-&gt;comment_parent==0): $GLOBALS['parent_comments_count']++; else: $GLOBALS['child_comments_count']++; endif; } </code> then, in our template where it calls wp_list_comments(), we add another with a callback to our count function, then immediately after we can echo our count. then we have the regular wp_list_comments(), which will actually output the comments: <code> wp_list_comments( array( 'callback' =&gt; 'count_comments' ) ); echo "parents: ". $GLOBALS['parent_comments_count']; echo "children: ". $GLOBALS['child_comments_count']; wp_list_comments(); </code> emphasis on 'dirty', I'm sure there's a cleaner way to do this. Here's another method which uses an additional query. This will get numbers regardless of pagination. We use the <code> comment_count </code> variable in <code> $post </code> to subtract number of parents from to get number of children. In functions.php: <code> function c_parent_comment_counter($id){ global $wpdb; $query = "SELECT COUNT(comment_post_id) AS count FROM $wpdb-&gt;comments WHERE `comment_approved` = 1 AND `comment_post_ID` = $id AND `comment_parent` = 0"; $parents = $wpdb-&gt;get_row($query); return $parents-&gt;count; } </code> In the template: <code> &lt;?php $number_of_parents = c_parent_comment_counter($post-&gt;ID); $number_of_children = $post-&gt;comment_count - $number_of_parents; echo "parents: ".$number_of_parents; echo "children: ".$number_of_children; ?&gt; </code>
Count parent comments & replies separately?
wordpress
I have a custom post type "mycustom_products" (hierarchical) that has custom taxonomies called 'categories' and 'tags' (as many other custom post types do). My custom category is called "myprod_category" (also hierarchical) and my tag taxonomy is called "product_tag" ( not hierarchical). I want to show a list of Product Tags that correspond ONLY to certain Product Categories. For example, with Product Categories like "soap" &amp; "lotion", there might be tags called "Blueberry" or "Lavender" (scents) but "jewelry" would have tags like "silver" or "gold". I want to be able to have a listing of the "scent" only tags (which would be the ones that correspond only with the "soap" and "lotion" categories. I don't want the tags for "jewelry" to be included. So any tags that have been used on products entered in those categories would be included, and any used for other categories wouldn't be. Obviously I could hard code everything into the theme, but if/when the client adds more tags, I would have to go in and re-code everything and I'd like to avoid doing that. I tried using <code> &lt;?php wp_tag_cloud( array( 'taxonomy' =&gt; 'product_tag', format =&gt; 'list' ) ); ?&gt; </code> to list out all my tags, but I can't seem to get the EXCLUDE argument to prevent whole "product categories" from showing. Seems like I can do it using the tag_ID but that would be tedious, and would put me back to hard coding them into the theme and having to update each time a new tag is added. Is there a filter or something I can use to exclude a category? Or is there a better way to list tags in this fashion. Thanks!
If you have a lot of products, probably a custom sql query is a better option. I'd probably recommend following that route either way. Custom queries may be 'icky', but it'll lighten resources and be a darn slight quicker in most cases* I've written a function that does most of the labour, and may well come in handy in other scenarios (I've used the word 'soft' to imply the relations are not explicit). <code> /** * Get terms that are indirectly associated with others through the posts they * are attached to. * * @see http://codex.wordpress.org/Function_Reference/WP_Query#Taxonomy_Parameters * @link stackexchange-url * * @param string|array $taxonomy The taxonomy(s) of the terms you wish to obtain. * @param array $tax_query A tax query for the posts you want to make the association with. * @return array Array of term IDs. */ function get_terms_soft_associated( $taxonomy, $tax_query ) { global $wpdb; // so you can pass a single tax query rather than wasted nested array if ( isset( $tax_query['taxonomy'] ) ) $tax_query = array( $tax_query ); $tax = new WP_Tax_Query( $tax_query ); extract( $tax-&gt;get_sql( $wpdb-&gt;posts, 'ID' ) ); if ( empty( $join ) || ( !$posts = $wpdb-&gt;get_col( "SELECT $wpdb-&gt;posts.ID FROM $wpdb-&gt;posts $join WHERE 1=1 $where" ) ) ) return array(); $taxonomy = implode( "','", array_map( 'esc_sql', ( array ) $taxonomy ) ); $posts = implode( ',', wp_parse_id_list( $posts ) ); return $wpdb-&gt;get_col( "SELECT DISTINCT t.term_id FROM $wpdb-&gt;terms AS t " . "INNER JOIN $wpdb-&gt;term_taxonomy AS tt ON tt.term_id = t.term_id " . "INNER JOIN $wpdb-&gt;term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id " . "WHERE tt.taxonomy IN('$taxonomy') AND tr.object_id IN($posts)" ); } </code> You can also check out the codex on tax queries for more help with <code> $tax_query </code> . This is the query we're using to filter posts, before we do a reverse lookup to gather all their terms for another taxonomy. Now onwards to the solution; <code> // suggestion 1 - for a single post $product_cats = get_the_terms( get_the_ID(), 'myprod_category' ); // suggestion 2 - for a product category archive $product_cats = get_queried_object_id(); // suggestion 3 - for all posts on the current page of an archive foreach( $wp_query-&gt;posts as $_post ) { $_product_cats = get_the_terms( $_post-&gt;ID, 'myprod_category' ); foreach ( $_product_cats as $_product_cat ) $product_cats[] = $_product_cat-&gt;term_id; } // now get the 'associated' tag IDs $product_assoc_tags = get_term_soft_association( 'product_tag', array( 'taxonomy' =&gt; 'myprod_category', 'field' =&gt; 'term_id', 'terms' =&gt; $product_cats ) ); wp_tag_cloud( array( 'taxonomy' =&gt; 'product_tag', 'include' =&gt; $product_assoc_tags ) ); </code> Note the suggestions are examples of how to grab all the product categories to later query against, depending on your circumstance and which post(s) you want to affect the outcome (only use one of the suggestions, or your own!). If you find it's not working as you expected , chances are we just need to tweak the tax query for the second argument of the function. * Footnote: Native post querying pulls in all post data, whilst we only need to work with IDs. Saving memory where you can always helps, and as @Daniel says, if we're talking a lot of posts, we're also talking a lot of memory. I also say quicker as, under out-of-the-box conditions, we're using far fewer database queries &amp; processing than had we used functions like <code> get_terms() </code> and <code> get_posts() </code> .
Show certain terms from custom taxonomy but exclude 'parent' terms?
wordpress
If I know a taxonomy term slug, how can I get that term's name?
The function you are looking for is <code> get_term_by </code> . You would use it as such: <code> &lt;?php $term = get_term_by('slug', 'my-term-slug', 'category'); $name = $term-&gt;name; ?&gt; </code> This results in <code> $term </code> being an object containing the following: <code> term_id name slug term_group term_taxonomy_id taxonomy description parent count </code> The codex does a great job explaining this function: http://codex.wordpress.org/Function_Reference/get_term_by
How to get a taxonomy term name by the slug?
wordpress
I hope this question is easy. I want to customize my theme so that the post titles are created on the fly with code. For example, I might have a post where a price changes on the page 4 times a week, and I want to be able to change my to say: Get Product X for $19.99 without having to manually edit a meta variable... Is it possible to do? Is there a wordpress function I can call to override the title using a plugin?
I can't answer how you'll get your dynamic data with which to update your Post Title, but you can easily hook into the Post Title, using the <code> the_title </code> filter: <code> &lt;?php function mytheme_dynamic_title( $title ) { // do something to the Post Title, which is passed // into this function as the variable $title // and then return $title return $title; } add_filter( 'the_title', 'mytheme_dynamic_title' ); ?&gt; </code> That should get you started with hooking into the Title.
Customizing Titles on the Fly with Code
wordpress
My question is basically identical to this other question stackexchange-url ("here"), however my question is still slightly different. I basically have a custom post type called "Packages" each package can have a slideshow with its own images. I understand the images are uploaded through the media uploader (as per the associated questions chosen answer), however is it possible to only get a list of images attached to the post that AREN'T the featured image? My understanding is that the answer given to the other question would get all images including the featured image, does Wordpress treat featured images differently in the background so I can exclude them?
Generally speaking, I would take the approach of querying for post attachments, but withhold the attachment that is the post thumbnail. WP provides a simple way of finding the post thumbnail ID with <code> get_post_thumbnail_id </code> (Codex Ref). To modify the code from the other post, I would add the following parameter to the <code> $args </code> array to withhold the thumbnail attachment from being queried: <code> 'post__not_in' =&gt; array( get_post_thumbnail_id($post-&gt;ID) ) </code> The <code> post__not_in </code> parameter will "Specify post NOT to retrieve." (Codex Ref) To put the whole thing together, the code would look like: <code> $args = array( 'post_type' =&gt; 'attachment', 'numberposts' =&gt; null, 'post_status' =&gt; null, 'post_parent' =&gt; $post-&gt;ID, 'post__not_in' =&gt; array( get_post_thumbnail_id($post-&gt;ID) ) ); $attachments = get_posts($args); if ($attachments) { foreach ($attachments as $attachment) { echo apply_filters('the_title', $attachment-&gt;post_title); the_attachment_link($attachment-&gt;ID, false); } } </code> In order to further fine tune your queries, I would highly recommend exploring the WP_Query class (Codex Ref). It's power is only rivaled by its ease of use.
Creating a metabox to upload multiple images, Ignoring The Featured Image
wordpress
Are there any plugins that allow one to make use of the _trackPageLoadTime(); functionality available in the new version of Google Analytics yet?
Google Analytics by Yoast has Custom Code setting to add stuff to tracking code. But says that it is added before <code> trackPageview </code> , while site speed instructions show it added after. Might or might not matter, I don't know. Update Plugin has been updated to support (and default to) site speed tracking .
Analytics plugins that allow for inclusion of _trackPageLoadTime()?
wordpress
Basically, I would like to add something like this into my WordPress site (which obviously will also give the user an option to sign up for an account using WordPress' default sign up system): Is there any plugin or tutorial that may be helpful to accomplish this?
Try Make Your Site Social plugin which does most of the job for you
Login with OpenID, similar to Stack Exchange sites?
wordpress
When I use <code> add_menu_page </code> &amp; <code> add_submenu_page </code> to add menu items, <code> add_menu_page( 'Forms', 'Forms', 'administrator', 'forms', 'forms_job_menupage_cb' ); add_submenu_page( 'forms', 'Job Applications', 'Job Applications', 'administrator', 'job-applications', 'forms_job_menupage_cb' ); add_submenu_page( 'forms', 'Quote Requests', 'Quote Requests', 'administrator', 'quote-req', 'forms_req_menupage_cb' ); add_submenu_page( 'forms', 'Contact', 'Contact', 'administrator', 'contact', 'forms_contact_menupage_cb' ); </code> I will get something like Forms Forms Job Applications Quote Requests Contacts Is it possible to create it such that it becomes Forms Job Applications Quote Requests Contacts In other words Forms will link to Job Applications and I dont want the extra Forms submenu item
Hi @JM at Work: Yes, it is unfortunately that the submenu page is added for every menu page. It would be nice if there were an option but alas, there currently is not . To remove the submenu page option in WordPress 3.1 or great use <code> remove_submenu_page() </code> with code like this in your theme's <code> functions.php </code> file, or in a <code> .php </code> file of a plugin you might be writing: <code> add_action( 'admin_menu', 'yoursite_admin_menu' ); function yoursite_admin_menu() { add_menu_page( 'Forms', 'Forms', 'administrator', 'forms', 'forms_job_menupage_cb' ); add_submenu_page( 'forms', 'Job Applications', 'Job Applications', 'administrator', 'job-applications', 'forms_job_menupage_cb' ); add_submenu_page( 'forms', 'Quote Requests', 'Quote Requests', 'administrator', 'quote-req', 'forms_req_menupage_cb' ); add_submenu_page( 'forms', 'Contact', 'Contact', 'administrator', 'contact', 'forms_contact_menupage_cb' ); remove_submenu_page('forms','forms'); } </code> If you are still using WordPress 3.0 you have to <code> unset() </code> an element of the global variable <code> $submenu </code> like this: <code> add_action( 'admin_menu', 'yoursite_admin_menu' ); function yoursite_admin_menu() { add_menu_page( 'Forms', 'Forms', 'administrator', 'forms', 'forms_job_menupage_cb' ); add_submenu_page( 'forms', 'Job Applications', 'Job Applications', 'administrator', 'job-applications', 'forms_job_menupage_cb' ); add_submenu_page( 'forms', 'Quote Requests', 'Quote Requests', 'administrator', 'quote-req', 'forms_req_menupage_cb' ); add_submenu_page( 'forms', 'Contact', 'Contact', 'administrator', 'contact', 'forms_contact_menupage_cb' ); unset($GLOBALS['submenu']['forms'][0]); } </code>
Remove duplicate main - submenu in admin?
wordpress