question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I'm creating a child theme off of wp-framework and in it's header it uses <code> &lt;?php echo IMAGES . '/favicon.ico'; ?&gt; </code> to recall the folder where images are kept. How do I define or create the location in order to recall it using echo IMAGES? and if I can save the image folder location as IMAGES (If I recall it's a string?) can I do the same with other information?
Many WordPress frameworks include helper functions and pre-defined folder locations. WP Framework is very well coded but requires some learning and inspecting the code to find the documentation. In the file core.php many constants are defined but I did not see IMAGES but THEME_IMAGE is defined so it is likely that IMAMGE refers to the images folder in the child theme directory. Here is the list of constants available for you to use: WP Framework V 3.6 core.php: <code> function wpf_initial_constants() { // Sets the File path to the current parent theme's directory. define( 'PARENT_THEME_DIR', TEMPLATEPATH ); // Sets the URI path to the current parent theme's directory. define( 'PARENT_THEME_URI', get_template_directory_uri() ); // Sets the File path to the current parent theme's directory. define( 'CHILD_THEME_DIR', STYLESHEETPATH ); // Sets the URI path to the current child theme's directory. define( 'CHILD_THEME_URI', get_stylesheet_directory_uri() ); // Sets the file path to WP Framework define( 'WPF_DIR', PARENT_THEME_DIR . '/framework' ); // Sets the URI path to WP Framework define( 'WPF_URI', PARENT_THEME_URI . '/framework' ); // Sets the file path to extensions define( 'WPF_EXT_DIR', WPF_DIR . '/extensions' ); // Sets the URI path to extensions define( 'WPF_EXT_URI', WPF_URI . '/extensions' ); } /** * Templating constants that you can override before WP Framework is loaded. * * @since 0.3.0 * * @return void */ function wpf_templating_constants() { // Sets a unique ID for the theme. if ( !defined( 'THEME_ID' ) ) define( 'THEME_ID', 'wpf_' . get_template() ); // Sets the default theme options db name if ( !defined( 'THEME_OPTIONS' ) ) define( 'THEME_OPTIONS', 'theme_options' ); // Sets relative paths for the default directories/paths if ( !defined( 'THEME_LIBRARY' ) ) define( 'THEME_LIBRARY', '/library' ); if ( !defined( 'THEME_I18N' ) ) define( 'THEME_I18N', THEME_LIBRARY . '/languages' ); if ( !defined( 'THEME_FUNC' ) ) define( 'THEME_FUNC', THEME_LIBRARY . '/functions' ); if ( !defined( 'THEME_IMG' ) ) define( 'THEME_IMG', THEME_LIBRARY . '/images' ); if ( !defined( 'THEME_CSS' ) ) define( 'THEME_CSS', THEME_LIBRARY . '/css' ); if ( !defined( 'THEME_JS' ) ) define( 'THEME_JS', THEME_LIBRARY . '/js' ); // Sets the default custom header image if ( !defined( 'DEFAULT_HEADER_IMAGE' ) ) define( 'DEFAULT_HEADER_IMAGE', get_theme_part( THEME_IMG . '/custom-header.gif' ) ); } </code>
defining a folder location in order to recall it
wordpress
I don't need this whole mess of classes like this... <code> &lt;body class="page page-id-829 page-template page-template-page-template-portfolio-php portfolio"&gt; </code> I'd like something like this... <code> &lt;body class="portfolio"&gt; </code> Is there a filter snippet somewhere that has a list of all the classes and I can then just uncomment the stuff I don't want to see in the body class. Thanks.
You can configure the <code> $whitelist </code> array in this function to filter out all other unwanted classes. <code> add_filter( 'body_class', 'wpse15850_body_class', 10, 2 ); function wpse15850_body_class( $wp_classes, $extra_classes ) { // List of the only WP generated classes allowed $whitelist = array( 'portfolio', 'home', 'error404' ); // Filter the body classes $wp_classes = array_intersect( $wp_classes, $whitelist ); // Add the extra classes back untouched return array_merge( $wp_classes, (array) $extra_classes ); } </code>
Remove classes from body_class
wordpress
I would like to achive the following link structure on my site: /properties/ -> a <code> properties </code> page with <code> properties </code> CPT, page 1. /properties/page/2 -> a <code> properties </code> page with <code> properties </code> CPT, page 2. /properties/property-name -> a single <code> properties </code> page with a property details. I have a Custom Post Type (CPT) called <code> property </code> . It's registered as following with the <code> rewrite </code> rule specified as <code> 'rewrite' =&gt; array('slug' =&gt; 'properties', 'with_front' =&gt; false) </code> : <code> function property_post_type_init() { $labels = array( 'name' =&gt; _x('Properties', 'post type general name'), 'singular_name' =&gt; _x('Property', 'post type singular name'), 'add_new' =&gt; _x('Add New', 'property') ); $args = array( 'labels' =&gt; $labels, 'public' =&gt; true, 'publicly_queryable' =&gt; true, 'show_ui' =&gt; true, 'rewrite' =&gt; array('slug' =&gt; 'properties', 'with_front' =&gt; false), 'query_var' =&gt; true, 'capability_type' =&gt; 'post', 'hierarchical' =&gt; false, 'show_in_nav_menus' =&gt; false, 'menu_position' =&gt; 5, 'supports' =&gt; array( 'title', 'editor', 'revisions' ) ); register_post_type('property',$args); </code> I also have a page with the slug <code> properties </code> and the permalink structure is set as <code> /%category%/%postname%/ </code> On the <code> Properties </code> page I construct a new <code> WP_Query </code> object with the following arguments: <code> $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' =&gt; 'property', 'orderby' =&gt; 'date', 'order' =&gt; 'DESC', 'paged' =&gt; $paged ); return $args; </code> I use a custom pagination code (in functions.php) which generates pagination correctly with the correct urls: <code> &lt;my-site&gt;/properties/ &lt;my-site&gt;/properties/page/2/ &lt;my-site&gt;/properties/page/3/ </code> However, when I click on any page in the pagination I get redirected to 404 page. I've expected the query params and they are the following: <code> [page] =&gt; 2 [property] =&gt; page [post_type] =&gt; property [name] =&gt; page </code> Which is not correct! I don't understand where these parameters are coming from: <code> [page] =&gt; 2 [property] =&gt; page [name] =&gt; page </code> I'm sure it's something to do with the <code> rewrite </code> rule when registering a CPT. How can I achive the following set up to work correctly: A <code> properties </code> page that displays all <code> properties </code> custom post types posts with pagination. A <code> properties </code> custom post type with <code> 'rewrite' =&gt; array('slug' =&gt; 'properties', 'with_front' =&gt; false) </code> rule. Permalink of <code> /%category%/%postname%/ </code> structure So that I have the following link structure: /properties/ -> a <code> properties </code> page with <code> properties </code> CPT, page 1. /properties/page/2 -> a <code> properties </code> page with <code> properties </code> CPT, page 2. /properties/property-name -> a single <code> properties </code> page with a property details. Hope that makes sense. Thanks, Dasha
Try changing the page's slug to something else and changing your post type registration to this: <code> $args = array( 'labels' =&gt; $labels, 'public' =&gt; true, 'publicly_queryable' =&gt; true, 'has_archive' =&gt; true, 'show_ui' =&gt; true, 'rewrite' =&gt; array('slug' =&gt; 'properties', 'with_front' =&gt; false), 'query_var' =&gt; true, 'capability_type' =&gt; 'post', 'hierarchical' =&gt; false, 'show_in_nav_menus' =&gt; false, 'menu_position' =&gt; 5, 'supports' =&gt; array( 'title', 'editor', 'revisions' ) ); </code> The operative new argument is <code> 'has_archive' </code> . This is new in 3.1, and gives you a <code> /properties/ </code> , <code> /properties/page/2 </code> , etc. structure by default. Then flush your rewrite rules and see if that fixes it. You may also need to comment out any code you've written playing with the query or rewrite rules
Custom Post Type pagination when CPT 'rewrite' rule and a page have the same slug
wordpress
What is the definite hook which identifies links.php page (add, edit, delete, etc. Blogroll Links), and only this page? Any help would be appreciated. Thanks, cadeyrn EDIT Sorry, I forgot to mention, I need this hook in the admin area. I have a plugin, that brakes an other one, because both are triggered by the admin_menu add_action. Therefore I need an add_action point that is only valid for the admin menu's link edit/add/delete part.
OK, I made an awful, but working solution: the hook is <code> admin_menu </code> , than, in the called function, I added <code> if( strstr($_SERVER['PHP_SELF'],'link.php') </code> in the begining. If there's a better solution, please someone send it.
add_action hook for links.php page
wordpress
hey guys, is it possible to format text in a custom field input box automatically with paragraphs? e.g. like the normal text-widget that has the option to say "auto-add paragraphs" when there is a linebreak. I just want my blogauthors to spare typing at the end of every line in a custom field! is there a way to do so? update: <code> &lt;?php if (have_posts()) : ?&gt; &lt;?php while (have_posts()) : the_post(); $sidebar_title = get_post_meta($post-&gt;ID, 'sidebar-title', $single = true); $sidebar_text = get_post_meta($post-&gt;ID, 'sidebar-text', $single = true); ?&gt; &lt;?php if ( $sidebar_title !== '' &amp;&amp; $sidebar_text !== '' ) { ?&gt; &lt;li class="widget-container widget-light-blue custom"&gt; &lt;h3 class="widget-title"&gt;&lt;?php echo wpautop($sidebar_title, $br); ?&gt;&lt;/h3&gt; &lt;?php echo wpautop($sidebar_text, $br); ?&gt; &lt;/li&gt; &lt;?php } ?&gt; &lt;?php endwhile; ?&gt; &lt;?php endif; ?&gt; </code>
Why don't you use <code> apply_filters( 'the_content', $var ); </code> when outputting your custom field? You don't really want to save the extra paragraphs, otherwise you'll end up seeing them when editing the custom field. This is not what happens with WordPress. If you're not happy with what <code> the_content </code> does (it does a lot of things including <code> wpautop </code> ) then create a custom filter like this: <code> // Assuming $var is your custom field value add_filter( 'my_custom_filter', 'wpautop' ); echo apply_filters( 'my_custom_filter', $var ); </code> Cheers!
Auto-add paragraphs to custom field?
wordpress
I have this code and all the vars pull in but the latest news is not showing up and the subscribe link is not dropping anything. any ideas? Everything else works like a charm. <code> &lt;div class="content"&gt; &lt;?php get_sidebar('field'); ?&gt; &lt;?php global $current_user; get_currentuserinfo(); $user_info = get_userdata($current_user-&gt;ID); if ( have_posts() &amp;&amp; $user_info-&gt;user_level != 0) : while ( have_posts() ) : the_post(); ?&gt; &lt;?php // get custom fields $wt_email = get_post_meta($post-&gt;ID, 'wt_email', true); $wt_feed = get_post_meta($post-&gt;ID, 'wt_website', true); $wt_facebook = get_post_meta($post-&gt;ID, 'wt_facebook', true); $wt_twitter = get_post_meta($post-&gt;ID, 'wt_twitter', true); $wt_linkedin = get_post_meta($post-&gt;ID, 'wt_linkedin', true); ?&gt; &lt;div class="entry"&gt; &lt;h1&gt;&lt;?php the_title(); ?&gt;&lt;/h1&gt; &lt;div class="body"&gt; &lt;?php the_content(); ?&gt; &lt;/div&gt; &lt;div class="share"&gt; &lt;div class="links"&gt; &lt;h3&gt;Links&lt;/h3&gt; &lt;ul&gt; &lt;?php if($wt_twitter) { ?&gt;&lt;li&gt;&lt;a href="http://&lt;?php print $wt_twitter; ?&gt;"&gt;Twitter&lt;/a&gt;&lt;/li&gt;&lt;?php } ?&gt; &lt;?php if($wt_facebook) { ?&gt;&lt;li&gt;&lt;a href="http://&lt;?php print $wt_facebook; ?&gt;"&gt;Facebook&lt;/a&gt;&lt;/li&gt;&lt;?php } ?&gt; &lt;?php if($wt_email) { ?&gt;&lt;li&gt;&lt;a href="mailto:&lt;?php print $wt_email; ?&gt;"&gt;Email&lt;/a&gt;&lt;/li&gt;&lt;?php } ?&gt; &lt;?php if($wt_linkedin) { ?&gt;&lt;li&gt;&lt;a href="http://&lt;?php print $wt_linkedin; ?&gt;"&gt;Website&lt;/a&gt;&lt;/li&gt;&lt;?php } ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;?php endwhile; // End the loop. Whew. ?&gt; &lt;div class="news"&gt; &lt;h3&gt;Latest News&lt;/h3&gt; &lt;ul&gt; &lt;?php // The Query $loop = new WP_Query( array( 'category_name' =&gt; $wt_feed, 'order' =&gt; 'ASC', 'posts_per_page'=&gt; 5 ) ); // The Loop if( $loop-&gt;have_posts() ) : while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); echo '&lt;li&gt;&lt;a href="' . the_permalink() . '"&gt;'; the_title(); echo '&lt;/a&gt;&lt;/li&gt;'; endwhile; endif; // Reset Query wp_reset_query(); ?&gt; &lt;/ul&gt; &lt;?php $args=array( 'category_name' =&gt; $wt_feed, 'type' =&gt; 'post' ); $categories=get_categories($args); if($wt_feed) { ?&gt;&lt;a href="/&lt;?php print $categories-&gt;slug; ?&gt;/feed" class="subscribe"&gt;Subscribe&lt;/a&gt;&lt;?php } ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php else : ?&gt; &lt;div class="entry"&gt; &lt;h1&gt;Listing Private&lt;/h1&gt; &lt;div class="body"&gt; &lt;p&gt;You need to have a Member account view the details of this list. Request an account membership.&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php endif; ?&gt; &lt;div class="clearfix"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php get_footer(); ?&gt; </code> output in compiled html for news section. <code> &lt;div class="news"&gt; &lt;h3&gt;Latest News&lt;/h3&gt; &lt;ul&gt;&lt;/ul&gt; &lt;a class="subscribe"href="//feed"&gt;Subscribe&lt;/a&gt; &lt;/div&gt; </code>
this could be a dumb answer - but is it because you end the loop and have two loops in one page? If so I'd work around it by putting the news loop into a second file and then call it into the main file.... but again I could be giving u a very basic answer to a quite complex problem
Loops for cat links not looping for wordpress site
wordpress
I've enabled my theme with the ability to display the "Featured Image" for the post. However, I'm trying now to determine (1) How to assign a hyperlink to the image and (2) How to call the_post_thumbnail() so that it wraps the hyperlink around the image. I can't find where this is supported in the current release of WP, but I'm thinking that I must just be missing something. <code> &lt;div class="entry"&gt; &lt;?php if(has_post_thumbnail() &amp;&amp; get_option('theme_show_featured_image')) the_post_thumbnail('large', array( 'class' =&gt; 'alignleft', 'style' =&gt; 'margin:0 10px 10px 0;')); ?&gt; &lt;?php the_content('&lt;p class="serif"&gt;Read the rest of this page &amp;raquo;&lt;/p&gt;'); ?&gt; </code>
I assume you want this to be output inside of <code> the_content() </code> ? You would probably have to define a shortcode that will output <code> the_post_thumbnail() </code> . You could either define the shortcode to accept a URL as an argument, or else wrap the shortcode with HTML anchor tags. EDIT: Assuming you're already outputting <code> the_post_thumbnail() </code> inside of <code> the_content() </code> , you could add a custom field into which the user enters a URL, and then, if the URL is present, output anchor tags around the call to <code> the_post_thumbnail() </code> .
How to add a user defined hyperlink to the "Featured Image" and the_post_thumbnail()
wordpress
Pretty simple, I've written a widget and I can't find out for the life of me where to save it?! Using the most recent version of wordpress. Thanks, John.
you can make it a plugin and put it in the plugins folder, or you can make it part of a theme and put it in the theme's functions.php file.
Where do I save widget code for wordpress?
wordpress
I have a frontend form with a bunch of input. My requirements force me to use a custom shortcode to create the form. I have already tested a page with that shortcode. Here's my : <code> &lt;form name="myform" method="post" action="&lt;?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?&gt;" enctype="multipart/form-data"&gt; </code> Based on this, it should open up the same page (and it did). However, when I hit submit, I got 404 on that very same URL. Is there any solution? UPDATE #1 I try different route, using add_action('init'): <code> add_action('init', 'mbro1_intercept_form_input'); function mbro1_intercept_form_input() { if( !(isset($_POST['action_code']) &amp;&amp; $_POST['action_code'] == 'mbro_intercept_form_input') ) return ""; if( isset( $_POST['submit'] ) ) { //do my code here wp_redirect( get_permalink(35) );//page that has [shortcode] } } </code> This successfully run my intended action on submit. But! upon redirection, it still got 404. I don't know what is wrong.
I take <code> die() </code> as solution. Though, I don't prefer this. <code> $redirect_link = get_permalink(35) ; //page that has form $script_redirect = "&lt;div&gt;Your form is submitted. Please wait a moment. If your browser didn't redirect, click &lt;a href='$redirect_link'&gt;here&lt;/a&gt;.&lt;/div&gt; &lt;script type='text/javasript' language='javascript'&gt; window.location = '$redirect_link'; &lt;/script&gt; "; die( $script_redirect ); </code>
Custom form, shortcode, and submit handler
wordpress
<code> plugins_url() </code> function accepts plugin slug or file path to build URL for. I have following directory structure: <code> /wp-content/mu-plugins/someplugin/css/file.css /wp-content/mu-plugins/someplugin/includes/file.php </code> I need to build URL to <code> file.css </code> in <code> file.php </code> . I can't pass <code> __FILE__ </code> because that will be one level too deep. <code> plugins_url('css/file.css', __FILE__ ) </code> I can pass <code> __DIR__ </code> to get correct level and it seems to work, but it's not documented as allowed and I am not sure there isn't something to bite me later with this. <code> plugins_url('css/file.css', __DIR__ ) </code> So, is this adequate? Any better way to build URL for these conditions?
<code> __DIR__ </code> is rather new and not always supported. Use <code> dirname( __FILE__ ) </code> . <code> plugins_url() </code> is using … <code> $folder = dirname(plugin_basename($plugin)); </code> … so yes, it is safe. Just use <code> plugins_url( 'subfolder/file.css', dirname( __FILE__ ) ) </code>
Is it safe to pass directory path to plugins_url()?
wordpress
How significant is the guid field in wp_posts? I'm doing a migration and adding a lot of images to the table (via <code> wp_insert_attachment, wp_generate_attachment_metadata and wp_update_attachment_metadata </code> ), but the guid field isn't filled by default. Should i correct this?
If you want to offer an ATOM feed for your attachments you should pass a GUID to <code> wp_insert_attachment() </code> or add a filter for <code> 'get_the_guid' </code> that handles empty values. In most (all?) other cases I wouldn’t care about it.
GUID field in wp_posts - relevance for attachments?
wordpress
On http://wordpress.barrycarter.info/index.php/page/7/ I disabled comments for "USDCAD options vs CADUSD options arbitrage?", but it still has a "Leave a Comment" link. Clicking the link takes you to http://wordpress.barrycarter.info/index.php/2011/02/25/usdcad-options-vs-cadusd-options-arbitrage-2/#respond where it, of course, shows that you can't leave a comment. The timeline page correctly does not show the 'comment' link: http://wordpress.barrycarter.info/index.php/2011/02/ How to fix?
In the <code> loop.php </code> template file, you will find this line: <code> &lt;span class="comments-link"&gt;&lt;?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?&gt;&lt;/span&gt; </code> If you don't want "leave a comment" to display if comments are closed, you can wrap the call to <code> comments_popup_link() </code> in a <code> if ( comments_open() ) </code> conditional, like such: <code> &lt;span class="comments-link"&gt;&lt;?php if ( comments_open() ) comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?&gt;&lt;/span&gt; </code> Note: you may also want to check the other <code> loop-foobar.php </code> template files.
"Leave a comment" link even when you can't
wordpress
Is there documentation somewhere on how to change the default data that is entered into the WordPress database when setting up a new database? I want to change the default category and add a couple others. Change the default post. Set a different theme, activate a couple plugins all by default. All of this to make it easy for setting up multiple sites that are all similar.
See stackexchange-url ("Initialization Script for “Standard” Aspects of a WordPress Website?") and my plugin WordPress Basic Settings for details. You may also use a custom <code> install.php </code> but that’s somewhat tricky for multi-site setups.
Change the default data installed when setting up WordPress
wordpress
I am using developing a child theme for Woothemes' Canvas. I am trying to use functions.php in the child theme to only use actions on my custom post type. This code doesn't seem to be working: <code> add_action( 'woo_post_inside_after', 'my_geo_mashup' ); function my_geo_mashup() { echo GeoMashup::map(); if ($post-&gt;post_type == 'listings') { //My function } } add_action( 'woo_post_inside_before', 'listings_nivo' ); function listings_nivo() { echo do_shortcode('[nivo source="current-post" ]'); if ($post-&gt;post_type == 'listings') { //My function } } </code> So, I'm unsure how to get the above to work properly and only show these items on the custom post type, or only for the custom post type template single-listings.php (as I only want the map and slider to show on the actual post, not on the blog page (archive.php)
you need a <code> global $post; </code> within that function before trying to access the contents of $post.
Custom post type functions.php if statement on action
wordpress
I'm wondering if it's possible to get status and position of metaboxes added to a dashboard-like page. The main page of my plugin has several metaboxes laying in a two-columns page and a "table of content" box on top (with internal links, like a wikipedia page). However, since you can order/hide/reveal a metabox, the TOC box should be updated accordingly via an ajax method. Is it possible to trigger a method like that, passing all parameters i need to accomplish the ordering (position and status of all metaboxes)? tnx in advance, Gabriele
You can hook into the <code> sortstop </code> event of the <code> sortable </code> metaboxes, and read the current state: <code> jQuery( function( $ ) { $( '.meta-box-sortables' ).bind( 'sortstop', function( event, ui ) { var sortData = {}; $('.meta-box-sortables').each( function() { sortData[this.id.split('-')[0]] = $(this).sortable( 'toArray' ); } ); console.log( sortData ); } ); } ); </code> You can also hook into the events that hide or reveal metaboxes, but this requires some more work on your side, since WordPress does not provide nice events for this. See the <code> postbox.js </code> script for more details. There are stackexchange-url ("other answers on this site that deal with the Ajax part").
Dashboard - get status and position of metaboxes and pass them to ajax method
wordpress
I am turning a restaurants website into a wordpress website to allow for the customer to take over content changes. The restaurant has a menu that has categories like Baskets with different types. For instance under the Basket type there is Fish which has a Title, Description, and Price. So what I want to do is to be able to have the customer create or delete Menu categories and have the ability to create,delete, update menu types. Then the entire menu is shown on one page. You can view the page at www.tailfinstogo.com/menu.html .
You can really do it either way. I would personally make a custom post type of "Menu Item" then use a custom taxonomy for type of food (e.g., 'Baskets', 'Poboys', 'Soups', etc.). I would then have a custom fields for sizes and price so you could enter something like '4pc' and '10pc' and '7.99'. One of things I've learned with doing WP sites for clients is that training for the client is often overlooked. Just because you do a great job designing and developing the site does not mean the client will know how to use it. I would recommend taking the time to train your client how to use the site after you implement whatever solution you decide on. Good luck!
Custom post type or just use custom fields
wordpress
I have a WordPress project that I'm using as a CMS. I also have a database with some products in it that I'd like to display on the site (gallery or portfolio maybe?) I have a custom post type for Products that I want to be editable in the wordpress admin (along with the rest of the content). I know I have to do a custom post type (which I'm reading up on, probably will use Simple Fields plugin) but I'm not seeing a way to pull these values from a database. Products will have ProductName, URL, Category, and Type. I would want to list and add/edit/delete these in the word press admin side of course. Any advice will be greatly appreciated. Thank you all! EDIT: I've created the Custom Post Type for <code> Products </code> . Now each <code> Product </code> can have a <code> Category </code> , <code> Subcategory </code> , and <code> Type </code> , which I'm assuming will also need their own Custom Post Type if they are to be manageable right? The layout for the products will be roughly: <code> ProductName </code> , <code> Type </code> , <code> Category </code> , <code> SubCategory </code> , <code> Document Name </code> , <code> Document URL </code> . Remember the <code> Category </code> , <code> SubCategory </code> , <code> Type </code> will need to be manageable and editable so I guess they will need to be custom post types as well. Thinking about this some more, could I use the built-in categories for MY custom post type categories and have the subcategories as children of the main categories? That might be the easier way out on that end. But how would I map a custom post type of <code> ProductType </code> to my custom post type of <code> Product </code> ? Here is my product custom post type: <code> /* CUSTOM POST TYPE AREA FOR PRODUCTS */ add_action( 'init', 'create_product_post_type' ); function create_product_post_type() { $labels = array( 'name' =&gt; _x('Products', 'post type general name'), 'singular_name' =&gt; _x('Product', 'post type singular name'), 'add_new' =&gt; _x('Add New', 'products'), 'add_new_item' =&gt; __('Add New Product'), 'edit_item' =&gt; __('Edit Product'), 'new_item' =&gt; __('New Product'), 'view_item' =&gt; __('View Product'), 'search_item' =&gt; __('Search Products'), 'not_found' =&gt; __('No products found'), 'not_found_in_trash' =&gt; __('No products found in Trash'), 'parent_item_colon' =&gt; '', 'menu_name' =&gt; 'Products' ); $args = array( 'label' =&gt; __('Products'), 'labels' =&gt; $labels, 'public' =&gt; true, 'can_export' =&gt; true, 'show_ui' =&gt; true, '_builtin' =&gt; false, 'capability_type' =&gt; 'post', 'menu_icon' =&gt; get_bloginfo('template_url').'/functions/images/product.png', 'hierarchial' =&gt; false, //'rewrite' =&gt; array( "slug" =&gt; "events" ), 'supports' =&gt; array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ), 'show_in_nav_menus' =&gt; true ); register_post_type( 'tf_events', $args); } </code>
What you really need to do is create Custom Taxonomies for your products instead of second custom post type. You can create taxonomies that are hierarchical like categories, or non-hierachical like tags. Give them names, slugs, etc. This way you won't interfere with the blog categories and tags, and get a more customized result.
Custom Post Type for displaying products in a database table
wordpress
I've been trying to wade my way through learning the ins and outs of taxonomies and how to integrate them into themes and I've run into a pretty basic issue that I can't seem to figure out. I started working on this in a BuddyPress install using More Taxonomies. After not being able to get the custom template to load (taxonomy-platform.php) using the rewrite slug of platform... www.mydomain.com/wpinstall/platform .... I deleted the taxonomies from More Taxonomies (but not the entries in the database for terms), uninstalled More Taxonomies and entered the Taxonomies into my buddypress functions.php. First I used <code> //hook into the init action and call create_platform_taxonomies when it fires add_action( 'init', 'create_platform_taxonomies', 0); //create the non-heirarchical Platforms taxonomy function create_platform_taxonomies() { // Adding a taxonomy for Platforms, non heirarchical $labels = array( 'name' =&gt; _x( 'Platforms', 'taxonomy general name' ), 'singular_name' =&gt; _x( 'Platform', 'taxonomy singular name' ), 'search_items' =&gt; __( 'Search Platforms' ), 'popular_items' =&gt; __( 'Popular Platforms' ), 'all_items' =&gt; __( 'All Platforms' ), 'parent_item' =&gt; null, 'parent_item_colon' =&gt; null, 'edit_item' =&gt; __( 'Edit Platform' ), 'update_item' =&gt; __( 'Update Platform' ), 'add_new_item' =&gt; __( 'Add New Platform' ), 'new_item_name' =&gt; __( 'New Platform Name' ), 'separate_items_with_commas' =&gt; __( 'Separate platforms with commas' ), 'add_or_remove_items' =&gt; __( 'Add or remove platforms' ), 'choose_from_most_used' =&gt; __( 'Choose from the most used platforms' ), 'menu_name' =&gt; __( 'Platforms' ), ); register_taxonomy('platform', array( 'post', 'page', 'mediapage', 'attachment', 'revision', 'nav_menu_item', 'cheats', 'reviews', 'tutorials' ), array( 'hierarchical' =&gt; false, 'labels' =&gt; $labels, 'show_ui' =&gt; true, 'query_var' =&gt; true, 'rewrite' =&gt; array( 'slug' =&gt; 'platform' ), )); } </code> but that still didn't allow it to work properly. *Let me note here that I have been over-zealous about flushing my rewrites using the Permalinks page save method during this entire process. I then rolled back to 2010, and entered that same code into functions.php, and tried again, same result. The taxonomy showed up under all the post types, it pulled the old term data from the database, entered into posts correctly, but I could not bring up the taxonomy-platform.php page, always getting a "that page could not be found" error. so now I wrote what I felt was a much more dumbed down taxonomy and tried that; <code> add_action( 'init', 'create_testtax_taxonomies', 0); function create_testtax_taxonomies() { register_taxonomy ( 'testtax', array( 'post', ), array( 'hierarchical' =&gt; false, 'labels' =&gt; array( 'Testtax', ), 'show_ui' =&gt; true, 'query_var' =&gt; true, 'rewrite' =&gt; array( 'slug' =&gt; 'testtax' ), )); } </code> this showed up (although its titled as a second 'Post Tags' in my Posts post type but I figured that's cause I cut down on labeling so heavily), but displayed the same behavior when trying to navigate to www.mydomain.com/wpinstall/testtax this is my code for the taxonomy-testtax.php page <code> &lt;?php /* This is the custom template for * the platforms taxonomy. */ get_header(); ?&gt; &lt;div id="container"&gt; &lt;div id="content" role="main"&gt; hello &lt;/div&gt;&lt;!-- #content --&gt; &lt;/div&gt;&lt;!-- #container --&gt; &lt;?php get_sidebar(); ?&gt; &lt;?php get_footer(); ?&gt; </code> Again, for the moment as simple as possible, but I've also used copies of the index and other various loop-enabled pages. Any help would be appreciated, thanks in advance! Not sure if I'm missing something simple, or skipping a process in properly enabling taxonomies... just not sure. Adding some more info to expand on some the answers/comments below (can't find a more efficient way to do this) I had seen a couple posts regarding this kind of issue I noticed some folks were able to flush an entire array of their soft re-write rules from WordPress. I figured I'd see if I could get the same sort of my print out myself. First I added; <code> add_action('wp_footer', 'show_rewrite_rules'); function show_rewrite_rules(){ global $wp_rewrite; echo "&lt;pre&gt;"; print_r($wp_rewrite-&gt;rules); echo "&lt;/pre&gt;"; } </code> So, added that to my Functions.php in 2010 (I'm pretty much keeping my 2010 theme and my BuddyPress install/theme uptodate with all these possible fixes and changes and testing in both - also have disabled plugins again a couple times and done a save as I've tried some of the suggests below). I got this output; <code> Array ( [categories/(.+)/search_type/(.+)/order/(.+)/page/(.+)] =&gt; index.php?cat=$matches[1]&amp;search_type=$matches[2]&amp;order=$matches[3]&amp;paged=$matches[4] [categories/(.+)/search_type/(.+)/order/(.+)] =&gt; index.php?cat=$matches[1]&amp;search_type=$matches[2]&amp;order=$matches[3] [categories/(.+)/page/(.+)] =&gt; index.php?cat=$matches[1]&amp;paged=$matches[2] [categories/(.+)] =&gt; index.php?cat=$matches[1] [promotion/?$] =&gt; index.php?post_type=ps_promotion [promotion/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?post_type=ps_promotion&amp;feed=$matches[1] [promotion/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?post_type=ps_promotion&amp;feed=$matches[1] [promotion/page/([0-9]{1,})/?$] =&gt; index.php?post_type=ps_promotion&amp;paged=$matches[1] [category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?category_name=$matches[1]&amp;feed=$matches[2] [category/(.+?)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?category_name=$matches[1]&amp;feed=$matches[2] [category/(.+?)/page/?([0-9]{1,})/?$] =&gt; index.php?category_name=$matches[1]&amp;paged=$matches[2] [category/(.+?)/?$] =&gt; index.php?category_name=$matches[1] [tag/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?tag=$matches[1]&amp;feed=$matches[2] [tag/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?tag=$matches[1]&amp;feed=$matches[2] [tag/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?tag=$matches[1]&amp;paged=$matches[2] [tag/([^/]+)/?$] =&gt; index.php?tag=$matches[1] [type/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?post_format=$matches[1]&amp;feed=$matches[2] [type/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?post_format=$matches[1]&amp;feed=$matches[2] [type/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?post_format=$matches[1]&amp;paged=$matches[2] [type/([^/]+)/?$] =&gt; index.php?post_format=$matches[1] [cheats/[^/]+/attachment/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [cheats/[^/]+/attachment/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [cheats/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [cheats/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [cheats/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [cheats/([^/]+)/trackback/?$] =&gt; index.php?cheats=$matches[1]&amp;tb=1 [cheats/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?cheats=$matches[1]&amp;feed=$matches[2] [cheats/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?cheats=$matches[1]&amp;feed=$matches[2] [cheats/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?cheats=$matches[1]&amp;paged=$matches[2] [cheats/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?cheats=$matches[1]&amp;cpage=$matches[2] [cheats/([^/]+)/entry(/(.*))?/?$] =&gt; index.php?cheats=$matches[1]&amp;entry=$matches[3] [cheats/([^/]+)(/[0-9]+)?/?$] =&gt; index.php?cheats=$matches[1]&amp;page=$matches[2] [cheats/[^/]+/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [cheats/[^/]+/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [cheats/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [cheats/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [cheats/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [reviews/[^/]+/attachment/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [reviews/[^/]+/attachment/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [reviews/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [reviews/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [reviews/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [reviews/([^/]+)/trackback/?$] =&gt; index.php?reviews=$matches[1]&amp;tb=1 [reviews/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?reviews=$matches[1]&amp;feed=$matches[2] [reviews/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?reviews=$matches[1]&amp;feed=$matches[2] [reviews/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?reviews=$matches[1]&amp;paged=$matches[2] [reviews/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?reviews=$matches[1]&amp;cpage=$matches[2] [reviews/([^/]+)/entry(/(.*))?/?$] =&gt; index.php?reviews=$matches[1]&amp;entry=$matches[3] [reviews/([^/]+)(/[0-9]+)?/?$] =&gt; index.php?reviews=$matches[1]&amp;page=$matches[2] [reviews/[^/]+/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [reviews/[^/]+/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [reviews/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [reviews/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [reviews/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [tutorials/[^/]+/attachment/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [tutorials/[^/]+/attachment/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [tutorials/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [tutorials/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [tutorials/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [tutorials/([^/]+)/trackback/?$] =&gt; index.php?tutorials=$matches[1]&amp;tb=1 [tutorials/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?tutorials=$matches[1]&amp;feed=$matches[2] [tutorials/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?tutorials=$matches[1]&amp;feed=$matches[2] [tutorials/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?tutorials=$matches[1]&amp;paged=$matches[2] [tutorials/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?tutorials=$matches[1]&amp;cpage=$matches[2] [tutorials/([^/]+)/entry(/(.*))?/?$] =&gt; index.php?tutorials=$matches[1]&amp;entry=$matches[3] [tutorials/([^/]+)(/[0-9]+)?/?$] =&gt; index.php?tutorials=$matches[1]&amp;page=$matches[2] [tutorials/[^/]+/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [tutorials/[^/]+/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [tutorials/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [tutorials/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [tutorials/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [platform/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?platform=$matches[1]&amp;feed=$matches[2] [platform/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?platform=$matches[1]&amp;feed=$matches[2] [platform/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?platform=$matches[1]&amp;paged=$matches[2] [platform/([^/]+)/?$] =&gt; index.php?platform=$matches[1] [testtax/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?testtax=$matches[1]&amp;feed=$matches[2] [testtax/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?testtax=$matches[1]&amp;feed=$matches[2] [testtax/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?testtax=$matches[1]&amp;paged=$matches[2] [testtax/([^/]+)/?$] =&gt; index.php?testtax=$matches[1] [promotion/[^/]+/attachment/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [promotion/[^/]+/attachment/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [promotion/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [promotion/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [promotion/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [promotion/([^/]+)/trackback/?$] =&gt; index.php?ps_promotion=$matches[1]&amp;tb=1 [promotion/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?ps_promotion=$matches[1]&amp;feed=$matches[2] [promotion/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?ps_promotion=$matches[1]&amp;feed=$matches[2] [promotion/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?ps_promotion=$matches[1]&amp;paged=$matches[2] [promotion/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?ps_promotion=$matches[1]&amp;cpage=$matches[2] [promotion/([^/]+)/entry(/(.*))?/?$] =&gt; index.php?ps_promotion=$matches[1]&amp;entry=$matches[3] [promotion/([^/]+)(/[0-9]+)?/?$] =&gt; index.php?ps_promotion=$matches[1]&amp;page=$matches[2] [promotion/[^/]+/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [promotion/[^/]+/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [promotion/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [promotion/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [promotion/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [promotions/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?promotion-categories=$matches[1]&amp;feed=$matches[2] [promotions/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?promotion-categories=$matches[1]&amp;feed=$matches[2] [promotions/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?promotion-categories=$matches[1]&amp;paged=$matches[2] [promotions/([^/]+)/?$] =&gt; index.php?promotion-categories=$matches[1] [(.+)/entry/%entry%/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?%entry%$matches[1]&amp;feed=$matches[2] [(.+)/entry/%entry%/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?%entry%$matches[1]&amp;feed=$matches[2] [(.+)/entry/%entry%/page/?([0-9]{1,})/?$] =&gt; index.php?%entry%$matches[1]&amp;paged=$matches[2] [(.+)/entry/%entry%/?$] =&gt; index.php?%entry%$matches[1] [.*wp-atom.php$] =&gt; index.php?feed=atom [.*wp-rdf.php$] =&gt; index.php?feed=rdf [.*wp-rss.php$] =&gt; index.php?feed=rss [.*wp-rss2.php$] =&gt; index.php?feed=rss2 [.*wp-feed.php$] =&gt; index.php?feed=feed [.*wp-commentsrss2.php$] =&gt; index.php?feed=rss2&amp;withcomments=1 [feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?&amp;feed=$matches[1] [(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?&amp;feed=$matches[1] [page/?([0-9]{1,})/?$] =&gt; index.php?&amp;paged=$matches[1] [comments/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?&amp;feed=$matches[1]&amp;withcomments=1 [comments/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?&amp;feed=$matches[1]&amp;withcomments=1 [comments/page/?([0-9]{1,})/?$] =&gt; index.php?&amp;paged=$matches[1] [search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?s=$matches[1]&amp;feed=$matches[2] [search/(.+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?s=$matches[1]&amp;feed=$matches[2] [search/(.+)/page/?([0-9]{1,})/?$] =&gt; index.php?s=$matches[1]&amp;paged=$matches[2] [search/(.+)/?$] =&gt; index.php?s=$matches[1] [author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?author_name=$matches[1]&amp;feed=$matches[2] [author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?author_name=$matches[1]&amp;feed=$matches[2] [author/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?author_name=$matches[1]&amp;paged=$matches[2] [author/([^/]+)/?$] =&gt; index.php?author_name=$matches[1] [([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;day=$matches[3]&amp;feed=$matches[4] [([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;day=$matches[3]&amp;feed=$matches[4] [([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;day=$matches[3]&amp;paged=$matches[4] [([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;day=$matches[3] [([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;feed=$matches[3] [([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;feed=$matches[3] [([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;paged=$matches[3] [([0-9]{4})/([0-9]{1,2})/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2] [([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?year=$matches[1]&amp;feed=$matches[2] [([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?year=$matches[1]&amp;feed=$matches[2] [([0-9]{4})/page/?([0-9]{1,})/?$] =&gt; index.php?year=$matches[1]&amp;paged=$matches[2] [([0-9]{4})/?$] =&gt; index.php?year=$matches[1] [[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/trackback/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;day=$matches[3]&amp;name=$matches[4]&amp;tb=1 [([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;day=$matches[3]&amp;name=$matches[4]&amp;feed=$matches[5] [([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;day=$matches[3]&amp;name=$matches[4]&amp;feed=$matches[5] [([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;day=$matches[3]&amp;name=$matches[4]&amp;paged=$matches[5] [([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;day=$matches[3]&amp;name=$matches[4]&amp;cpage=$matches[5] [([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/entry(/(.*))?/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;day=$matches[3]&amp;name=$matches[4]&amp;entry=$matches[6] [([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)(/[0-9]+)?/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;day=$matches[3]&amp;name=$matches[4]&amp;page=$matches[5] [[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/comment-page-([0-9]{1,})/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;day=$matches[3]&amp;cpage=$matches[4] [([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/entry(/(.*))?/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;day=$matches[3]&amp;entry=$matches[5] [([0-9]{4})/([0-9]{1,2})/comment-page-([0-9]{1,})/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;cpage=$matches[3] [([0-9]{4})/([0-9]{1,2})/entry(/(.*))?/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;entry=$matches[4] [([0-9]{4})/comment-page-([0-9]{1,})/?$] =&gt; index.php?year=$matches[1]&amp;cpage=$matches[2] [([0-9]{4})/entry(/(.*))?/?$] =&gt; index.php?year=$matches[1]&amp;entry=$matches[3] [.+?/attachment/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [.+?/attachment/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [.+?/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [.+?/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [.+?/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [(.+?)/trackback/?$] =&gt; index.php?pagename=$matches[1]&amp;tb=1 [(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?pagename=$matches[1]&amp;feed=$matches[2] [(.+?)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?pagename=$matches[1]&amp;feed=$matches[2] [(.+?)/page/?([0-9]{1,})/?$] =&gt; index.php?pagename=$matches[1]&amp;paged=$matches[2] [(.+?)/comment-page-([0-9]{1,})/?$] =&gt; index.php?pagename=$matches[1]&amp;cpage=$matches[2] [(.+?)(/[0-9]+)?/?$] =&gt; index.php?pagename=$matches[1]&amp;page=$matches[2] ) </code> So I see Platform and Testtax in there, they don't have as many lines as the rewrites for my custom post types, however from what I can tell it looks like they do have rules that should make this work.
I found this code; <code> function ftc_flush_rewrites() { global $wp_rewrite; $wp_rewrite-&gt;flush_rules(); } function ftc_add_rewrites() { global $wp_rewrite; $ftc_new_non_wp_rules = array( 'find/(this)' =&gt; '/addit.php?here=$1', ); $wp_rewrite-&gt;non_wp_rules = $ftc_new_non_wp_rules + $wp_rewrite-&gt;non_wp_rules; } add_action('generate_rewrite_rules', 'ftc_add_rewrites'); add_action('admin_init', 'ftc_flush_rewrites'); </code> in this thread http://wordpress.org/support/topic/writing-wp_rewrite-gtnon_wp_rules-to-htaccess ...not sure if that addresses the problem but good luck!
Can't get a custom template taxonomy page to display
wordpress
I have recently found myself with some time on my hands and with no problem of my own, I would like to solve someone's problem. I'd like to contribute to the WP community how best would I be able to do this? I would like to contribute in way of code. I can take a suggestion of a modules/features I could pick one, maybe the one with the most up votes.
The Codex has a page on how to contribute to WordPress . Some other ways to help: Help others with questions. On the WP.org support forums, here, or on other sites, it does not matter. Pick stackexchange-url ("a question that has been open for a while") and try to solve it. I have stackexchange-url ("a tool to quickly start experimenting with code"), and most of what I know about WordPress comes from answering questions here. It even made me write stackexchange-url ("my first plugin for other developers"). Improve the Codex. The same reason as answering questions: to explain something you must first understand it yourself. And the Codex is in need of some serious rewriting. Look at code written by others. You can volunteer to review themes : this will teach you about the coding standards and you'll learn interesting ways to use WordPress. Write code yourself. If you are not confident enough to write complete patches, you can also test new features or confirm new bug reports. By trying to isolate the bug you will also learn how the inner code works, and gain respect among your peers.
Contributing to the community
wordpress
I am being forced to use a SOAP service on a site, and for some of the UI elements it is calling images that I have to put in place. I can't point them to a theme folder, as I have no control over the HTML, and I am reluctant to use javascript. the code points to <code> &lt;img src="images/image.jpg" &gt; </code> , I have tried adding an images folder to the root of my WP installation, to no avail. So my question is where should I put the image so that the HTML can find it?
The plugin is search for an 'images' folder inside the current working directory. For example if you are in <code> /blogs/ </code> , a file looking for <code> images/image.jpg </code> is actually looking for <code> /blogs/images/image.jpg </code> . This can obviously get very messy when re-writing URLs with stuff like <code> /2010/03/blog-title </code> so actually put an image in the specific location is impossible, you will need to edit HTML or at least .htaccass to resolve it. Look up: <code> &lt;base&gt; </code> tag, mod-rewrites, javascript or editing whatever plugin is creating that HTML (str_replace on the output?). Personally I think you need to look into filtering the HTML you're receiving from the SOAP service to clear that up.
where is images/image.jpg?
wordpress
My permalink settings is simply <code> /%postname%/ </code> (yes I read from the codex that this is bad performance practice). The result is: a page url might look like <code> site.com/pagename </code> a blog post looks like <code> site.com/post-title </code> a portfolio (custom post type) post will look like <code> site.com/portfolio/item-1 </code> I would like my blog post page ( <code> single.php </code> ) to have a URL like <code> site.com/blog/post-title </code> . How might I do that?
Change your permalink structure to <code> /blog/%postname%/ </code> . EDIT To get your custom post type to leave out the <code> /blog </code> part, in its registration arguments array, set the rewrite argument like this: <code> 'rewrite' =&gt; array( 'slug' =&gt; 'portfolio', 'with_front' =&gt; false ) </code>
How to prepend route with /blog for blog listing page only
wordpress
I'm working on building some custom taxonomies for a custom post type I created. The custom post type is <code> Products </code> . For the custom post type <code> Products </code> I've created a taxonomy of <code> Category </code> . Now Under <code> Category </code> , I'd like to have a taxonomy of <code> Sub_Category </code> . I've created all the taxonomies and set them to hierarchical, but the <code> Sub_Category </code> tax seems to be relative to the <code> Product </code> Custom Post Type, NOT the <code> Category </code> custom taxonomy. Is there a way to do this? I saw a screenshot where someone was filling out a taxonomy form for a taxonomy they created and it had an option for PARENT but I could never get that to show up. How can I choose a PARENT <code> Category </code> taxonomy on my <code> SubCategory </code> taxonomy? Here is my <code> Category </code> and <code> SubCategory </code> taxonomy code: <code> function create_productcategory_taxonomy() { $labels = array( 'name' =&gt; _x( 'Categories', 'taxonomy general name' ), 'singular_name' =&gt;_x( 'Category', 'taxonomy singular name' ), 'search_items' =&gt; __( 'Search Categories' ), 'popular_items' =&gt; __( 'Popular Categories' ), 'all_items' =&gt; __( 'All Categories' ), 'parent_item' =&gt; null, 'parent_item_colon' =&gt; null, 'edit_item' =&gt; __( 'Edit Product Category' ), 'update_item' =&gt; __( 'Update Product Category' ), 'add_new_item' =&gt; __( 'Add New Product Category' ), 'new_item_name' =&gt; __( 'New Product Category' ), 'separate_items_with_commas' =&gt; __( 'Separate categories with commas' ), 'add_or_remove_items' =&gt; __( 'Add or remove product categories' ), 'choose_from_most_used' =&gt; __( 'Choose from the most used categories' ) ); register_taxonomy('tf_productcategory', 'tf_products', array ( 'label' =&gt; __('Product Category'), 'labels' =&gt; $labels, 'hierarchial' =&gt; true, 'show_ui' =&gt; true, 'query_var' =&gt; true, 'rewrite' =&gt; array( 'slug' =&gt; 'product-category'), )); } function create_product_subcategory_taxonomy() { $labels = array( 'name' =&gt; _x( 'SubCategories', 'taxonomy general name' ), 'singular_name' =&gt;_x( 'SubCategory', 'taxonomy singular name' ), 'search_items' =&gt; __( 'Search SubCategories' ), 'popular_items' =&gt; __( 'Popular SubCategories' ), 'all_items' =&gt; __( 'All SubCategories' ), 'parent_item' =&gt; __( 'Main Category' ), 'parent_item_colon' =&gt; ( 'Main Category:' ), 'edit_item' =&gt; __( 'Edit Product SubCategory' ), 'update_item' =&gt; __( 'Update Product SubCategory' ), 'add_new_item' =&gt; __( 'Add New Product SubCategory' ), 'new_item_name' =&gt; __( 'New Product SubCategory' ), 'menu_name' =&gt; __( 'SubCategories' ) ); register_taxonomy('tf_productsubcategory', 'tf_products', array ( 'label' =&gt; __('Product SubCategory'), 'labels' =&gt; $labels, 'hierarchial' =&gt; true, 'show_ui' =&gt; true, 'query_var' =&gt; true, 'rewrite' =&gt; array( 'slug' =&gt; 'product-subcategory'), )); } add_action( 'init', 'create_productcategory_taxonomy', 0 ); add_action( 'init', 'create_product_subcategory_taxonomy', 0 ); </code>
Hierarchical refers to the terms relation to each other not the taxonomies relation to another taxonomy. Non hierarchical taxonomies are like tags they don't have parents or children. Hierarchical taxonomies means that the terms can have parents and children. taxonomy = category category terms: blue products ( parent term ) light blue products (child term) dark blue products (child term) red products ( parent term ) dark red products (child term) light red products (child term) Also in your code above change: <code> 'hierarchial' =&gt; true, </code> To: <code> 'hierarchical' =&gt; true, </code>
Custom Taxonomy Hierarchy for Custom Post Types (eg Categories and Subcategories)
wordpress
I'm trying to hide some fields on public BuddyPress profiles, it is possible? Thanks in advance.
I dont know, but you can hide via css or javascript the areas; via css: <code> #id_or_.class_of_elemet { display:none; } </code>
BuddyPress - A hook available to hide custom born date on public profile view?
wordpress
Is WP a good HTML editor? A friend of mine wants to create HTML pages, but doesn't know HTML. Can WP become a WYSIWIG HTML editor via the appropriate plugin? He'll be formatting images, wanting to place text in specific locations, etc. Nothing too fancy, but not just text either.
WordPress is a CMS (Content Management System) and not an editor. That being said WordPress does have a simple WYSIWIG style editor built into it for formatting the content that you want to post.
WP as an HTML editor
wordpress
I'm looking for a way to allow post editors to see two different previews of the posts they are writing. On the front, the same post can appear it two different sections of the website (each shows a different amount of custom fields). How can I create two preview links (for ex : "Preview with template 1" and "Preview with template 2") ?
The easiest way to solve this is to create a special template file for previews, that will show the post twice in the different layouts. The following code will use the <code> single-preview.php </code> template file if it exists: <code> add_filter( 'single_template', 'wpse15770_single_template' ); function wpse15770_single_template( $templates ) { if ( is_preview() ) { $templates = locate_template( array( 'single-preview.php', $templates ) ); } return $templates; } </code> If you want to show the same post twice you must remember to add <code> rewind_posts() </code> in your <code> single-preview.php </code> template file, otherwise you can't loop over the posts again.
Is it possible to have two different previews of a post (ie. two templates for one post)?
wordpress
Can you add the visual editor to the description field for custom taxonomies? It would be nice to have this option available when you edit an entry for a taxonomy be it core or custom.
Just wrote the function. It'll display the tinymce editor in every custom taxonomy description right now. Surely you can edit to show it for only some specific taxonomy. <code> /** * Display advanced TinyMCE editor in taxonomy page */ function wpse_7156_enqueue_category() { global $pagenow, $current_screen; if( $pagenow == 'edit-tags.php' ) { require_once(ABSPATH . 'wp-admin/includes/post.php'); require_once(ABSPATH . 'wp-admin/includes/template.php'); wp_tiny_mce( false, array( 'editor_selector' =&gt; 'description', 'elements' =&gt; 'description', 'mode' =&gt; 'exact' )); } } add_action( 'init', 'wpse_7156_enqueue_category' ); </code> You can provide the first argument in <code> wp_tiny_mce </code> as <code> true </code> if you want a stripped version of tinyMCE
Can you add the visual editor to the description field for custom taxonomies?
wordpress
I consistently get spam attempts on various and sundry media attachments on my primary WP blog. By default, media has open comments (for instance, http://literalbarrage.org/blog/archives/2009/03/18/daddywill-date-march-2009/dsc08760/ ), yet there is no native way to disable comments on media files. (e.g. https://skitch.com/zamoose/rhktp/attachmentedit ) So, two questions: How do I disable all comments for future uploads by default? How do I retroactively disable comments on all previous uploads? This will help a ton in reducing my incoming spam...
This ought to do it: <code> function wpse15750_comment_check( $id ){ if( get_post_type( $id ) == 'attachment' ) exit; } add_action( 'pre_comment_on_post', 'wpse15750_comment_check' ); </code> EDIT Ignore the above. That will stop new comments, but to do what you want, this is much better: <code> function wpse15750_comments_closed( $open, $id ){ if( get_post_type( $id ) == 'attachment' ) return false; return $open; } add_action( 'pre_comment_on_post', 'wpse15750_comments_closed', 10, 2 ); </code> That will tell WordPress that attachments always have closed comments, but their database values will still say 'open'. If you want to change that, run the following code: <code> global $wpdb; $wpdb-&gt;update( $wpdb-&gt;posts, array( 'comment_status' =&gt; 'closed' ), array( 'post_type' =&gt; 'attachments', 'comment_status' =&gt; 'open' ) ); </code> To prevent any future attachments from having open comments, use the following filter: <code> function wpse15750_no_attachment_comments( $data ){ if( $data['post_type'] == 'attachment' ) $data['comment_status'] = 'closed'; return $data; } add_filter( 'wp_insert_post_data', 'wpse15750_no_attachment_comments' ); </code>
What's the easiest way to close comments on media/attachments?
wordpress
I've been hosting my blog on WordPress.com for a few years now, but am starting to feel a bit constrained by some of the limitations. The most troublesome in priority order are inability to include JavaScript in my posts, the requirement to pay an ongoing fee for customized CSS, and inability to install my own WP plugins. I've thought about self-hosting, but the last thing I need is another side project of managing the blogging software. It's tough enough finding time to keep posting new content on the blog. I'm not interested in installing upgrades, doing backups, etc. Long story short, I am wondering if there is another Wordpress hosting provider out there that offers the benefits of the virtually maintenance free hosting of WordPress.com, but without the restriction on CSS and Javasscript. Any suggestions?
Have a look at page.ly WP Engine I'm sure there are plenty of others. I'm specifically discounting hosts that provide 1-click installs because even they require some administration.
Hosting alternatives to WordPress.com
wordpress
The following blog of okcupid had this interesting feature that shows a "share this" window only when you reach the end of the post: http://blog.okcupid.com/index.php/what-if-there-were-not-so-many-white-people/ How is it possible to do this? Thanks
They've attached a function to the scroll event of the page, it looks at the scroll position of the document relative to its height to detect when you've reached the bottom, in which case they animate the flyout div. jQuery has some easy methods for this: <code> $(document).height(); </code> , <code> $(document).scrollTop(); </code> edit: these may help stackexchange-url ("one") stackexchange-url ("two")
How to make a share-this window drop when reaching end of post?
wordpress
I run small wordpress blog with 3-5 users. People add/edit/remove and read content all the time... What I want is to be able to see some sort of statistics.... which posts/pages are most popular, most updated, commented... which external links are the ones clicked most times... etc.... is there a plugin (not external service) to achieve that?
Piwik is similar to Google Analytics, but you install on your own server. Also- I've seen a private internal intranet site that was tracked on Google Analytics. It was certainly not publicly or search engine accessible, so it is possible to at least use GA on a private site if you're curious to investigate further.
Blog statistics
wordpress
If I sign up for a Wordpress blog that is hosted for free by Wordpress here , who will own the content I post, and how much storage will I have? I know I could ask their customer support, but I don't trust companies (their lawyers specifically).
From the TOS : By submitting Content to Automattic for inclusion on your Website, you grant Automattic a world-wide, royalty-free, and non-exclusive license to reproduce, modify, adapt and publish the Content solely for the purpose of displaying, distributing and promoting your blog. If you delete Content, Automattic will use reasonable efforts to remove it from the Website, but you acknowledge that caching or references to the Content may not be made immediately unavailable. It means that you own it but they have full rights.
Who owns the content posted on .wordpress.com blogs?
wordpress
The basic of what I need; A public page where the visitor have to fill out a form in order to be able to download a large file (the one and the same file for all downloads/users). The file should only be available trough something like a temporary url for a specific amount of time from when the form was submitted. In other words, time limited access to the file for a specific user. To create and setup the form is no problem, but making the file accessible for a limited amount of time to the user whom submitted the form is a completely different story. I have no good ideas on how to create time limited access. Don't know where to start. Any ideas on how to create this with WordPress? Plugin suggestions are welcome too.
a simple way would be to set a cookie with a timestamp when they submit the form, then check for the cookie and valid timestamp when they hit the url to download the file. a more complicated process would be to generate a unique url key for each user, put that in a db table with a timestamp, then look up the url, check the time and then delete when they hit it for download.
Time limited file download upon form submit
wordpress
Hi to all I'm running a wordpress based website and I need to let the users choose how to show the posts inside categories pages. I would like to have a button inside a category page that can be clicked so the reader can choose if he wants to see posts ordered by date or from A to Z or from Z to A. Is there anyone who can tell me how to achieve this? Please explain it like if you are speaking to your 12 years son :-) I google a lot about this and I've never found nothing that I can copy/paste into my code or that I can modify. I can't understand how to do this... any solution?
First in your category.php (depending on your theme files) add a simple form to let the user sort A-Z or Z-A: <code> &lt;form action="" name="custom_order" method="POST"&gt; &lt;p&gt; sort order: &lt;select name="CU_Order" id="CU_Order"&gt; &lt;option value="ASC"&gt;A-Z&lt;/option&gt; &lt;option value="DESC"&gt;Z-A&lt;/option&gt; &lt;/select&gt; &lt;/p&gt; &lt;p&gt; &lt;input type="hidden" name="cs_action" value="custom_sort_order"&gt; &lt;input type="submit" name="submit" value="sort"&gt; &lt;/p&gt; &lt;/form&gt; </code> then using <code> pre_get_posts </code> hook you alter the query to order like the user has selected: <code> add_action( 'pre_get_posts', 'change_sort_order' ); function change_sort_order(&amp;$query){ if (isset($_POST['cs_action']) &amp;&amp; $_POST['cs_action'] == 'custom_sort_order'){ global $wp; if (isset($wp-&gt;query_vars["CU_Order"])){ $query-&gt;set( 'order', $wp-&gt;query_vars["CU_Order"] ); } } } </code> and all that is left is to add <code> CU_Order </code> order to the list of query vars WordPress knows using <code> query_vars </code> hook: <code> add_filter('query_vars', 'add_custom_order_query_vars'); function add_custom_order_query_vars($vars) { // add CU_Order to the valid list of variables $new_vars = array('CU_Order'); $vars = $new_vars + $vars; return $vars; } </code> simpler explanation: copy the first code in your category.php copy the rest in to your theme's functions.php Done.
How to let users choose posts order in categories?
wordpress
I currently have a taxonomy called wpsc_product_category. Under that taxonomy I have several terms used as sub-categories, and finally each sub-category has a number of products. I'm trying to use wp_list_categories to show an ul starting from the parent category of the current product your are viewing. ¿Is this possible? <code> &lt;?php $taxonomy = 'wpsc_product_category'; $orderby = 'name'; $show_count = 0; // 1 for yes, 0 for no $pad_counts = 0; // 1 for yes, 0 for no $hierarchical = 1; // 1 for yes, 0 for no $title = ''; $child_of = $actualcategoryparentid $args = array( 'taxonomy' =&gt; $taxonomy, 'orderby' =&gt; $orderby, 'show_count' =&gt; $show_count, 'pad_counts' =&gt; $pad_counts, 'hierarchical' =&gt; $hierarchical, 'title_li' =&gt; $title 'child_of' =&gt; $child_of ); ?&gt; &lt;ul&gt; &lt;?php wp_list_categories( $args ); ?&gt; &lt;/ul&gt; </code> I thought of something like this, but I don't know how to retrieve $actualcategoryparentid. Any ideas? Thanks!
this will work: <code> $terms = wp_get_object_terms( $post-&gt;ID, 'wpsc_product_category' ); foreach($terms as $term){ if($term-&gt;parent != 0){ // this category has a parent and its id is $term-&gt;parent } } </code>
Use wp_list_categories to list parent categories from actual term
wordpress
I have been having problems with a custom taxonomy not working with a url. For example mysite.com/testcat/test1 will 404 but mysite.com/make/ford will work. More troubling is that mysite.com/?make=ford&amp;testcat=test1 will bring up my test page (both taxonomies where included). Here is a clipping of the functions.php <code> register_taxonomy( 'testcat', 'videos', array( 'hierarchical' =&gt; True, 'label' =&gt; 'testcat', 'query_var' =&gt; true, 'rewrite' =&gt; true ) ); </code> Any ideas of what i'm doing wrong?
Did you flush your rewrite rules after you created the taxonomy? I tested your code (only changing <code> 'videos' </code> to <code> 'post' </code> ) by adding to my functions PHP (TwentyEleven Theme WordPress 3.2 Trunk) then flushed my rewrite rules and created a post and gave it the testcat of test1 and the URL worked. <code> add_action( 'init', 'c3m_wp_stackx'); function c3m_wp_stackx() { register_taxonomy( 'testcat', 'post', array( 'hierarchical' =&gt; True, 'label' =&gt; 'testcat', 'query_var' =&gt; true, 'rewrite' =&gt; true ) ); } </code> Screenshot:
Random category URLs not working
wordpress
I am looking for a plugin that will embed my amazon affiliate id in outbound amazon links on my blog. I've tried a couple of top plugins (e.g. sorted by popularity) and most are a huge overkill (e.g. providing image popups, search lists, products lists, price integration, etc...) Can someone recommend a plugin that does what I am looking for?
I've been using the plugin called WordPress-Amazon-Associate . It was easy to setup and has been working fine. For more information: link to the author's home page link to the official WP plugin page
Simple Amazon Affiliate Plugin
wordpress
I have a taxonomy wp_query and i would like to order the list by title and by meta value (numeric value) Have a meta value Interesting = 1 or 0 in the posts Not so interesting posts would be at the bottom of the query GOAL - OUTPUT LIKE THIS: (is this possible with WP_QUERY and WP3.1) A ( META KEY interesting = 1 ) B ( META KEY interesting = 1 ) C ( META KEY interesting = 1 ) A ( META KEY interesting = 0 ) B ( META KEY interesting = 0 )
You can filter the <code> orderby </code> part of the query to get what you want (trying to pass it via the <code> orderby </code> parameter will not work, it will be filtered out). This simple example adds the <code> meta_value </code> sort order before the standard title sort order. <code> add_filter( 'posts_orderby', 'wpse15168_posts_orderby' ); $query = new WP_Query( array( 'meta_key' =&gt; 'interesting', 'orderby' =&gt; 'title', 'order' =&gt; 'ASC', ) ); remove_filter( 'posts_orderby', 'wpse15168_posts_orderby' ); function wpse15168_posts_orderby( $orderby ) { global $wpdb; $orderby = $wpdb-&gt;postmeta . '.meta_value DESC, ' . $orderby; return $orderby; } </code>
wp_query orderby title and meta key value (WP3.1)
wordpress
I have a client that needs to give access to her clients certain documents. She wants the ability to give them user name and password, so once they log in, they go directly to their page or post which will list the documents available for download. Plugins don't seem to help here and some are way too complicated. I have read many articles and tried several concepts but can't get it right. It's almost a membership to access info, but it's free and members can only be allowed to see what was written for them. This is a tough one for me. Any suggestions?
Well, in short, I had our in-house programmer build me a 3rd party system which we integrated into Wordpress. WP is awesome, but not quite there yet with these kinds of features built in. To the future!
Suggestions for allowing basic users to view their own posts?
wordpress
I've been suggested by my hosting to move from w3-total-cache to wp-super-cache since the later is supposed to be using less memory then the first. Is there any knowledge about this comparison? Is there a way to test it on my own site? (I am on a managed VPS) Thanks.
If you're using a memory cache like APC or memcached, their respective admin pages will have the total memory you're using (my Wordpress installs are using 80MB with W3 Total Cache). You could then install wp-super-cache and see what it does to your memory usage.
Memory consumption in w3-total-cache vs wp-super-cache?
wordpress
I'm trying to set-up pretty permalinks for my site. WordPress has a warning that my htaccess files is not writable. It provided some code to copy and put in the htaccess file. I'm on a Mac, my local machine running WordPress 3.1.1. I coped the code WP provided and pasted it into a new new TextEdit file that I named 1.htaccess . I put the file in the root directory Sites/mysite/. Then I tried to re-name the file and remove the "1", but my Mac gave a warning that files starting with "." are system files and wouldn't let me re-name it. How can I make an htaccess file on a Mac? Thank you. -Laxmidi
Open up terminal. Found in Utilities. Type: <code> cd /path/to/htaccess/file/ mv 1.htaccess .htaccess </code> For future edits of the htaccess file I'd recommend learning to use vi in the terminal. <code> cd /path/to/htaccess/file/ vi .htaccess </code>
How can I make an htaccess file on a Mac?
wordpress
I'm using <code> [wp_login_form()][1] </code> to display login form in a jQuery dialog window. If user enters wrong password, the user is taken to the backend. I don't want that. Is there a way to notify user that he entered wrong password and still remain on the same page? Before <code> wp_login_form() </code> came I was using a plugin. I'm kind of hoping I can avoid using a plugin for this. My code: <code> wp_login_form(array( 'label_remember' =&gt; __( 'Remember me' ), 'label_log_in' =&gt; __( 'Login' ) )); </code>
<code> wp_login_form() </code> creates a form with an action attribute of <code> site_url/wp-login.php </code> and that means that when you click the submit button the the form is posted to <code> site_url/wp-login.php </code> which ignores redirect_to on errors (like wrong password) so in your case either go back to using a plugin or recreate the whole login process and that way you have control on errors, take a look at stackexchange-url ("Check for correct username on custom login form") which is very similar question.
How can I redirect user after entering wrong password?
wordpress
Here is my comments block: <code> &lt;div id="comments"&gt; &lt;?php if (have_comments()) : ?&gt; &lt;h3&gt;&lt;?php printf(_n('1 comment', '%1$s comments', get_comments_number()), number_format_i18n( get_comments_number() ), '' ); ?&gt;&lt;/h3&gt; &lt;div class="comment_list"&gt; &lt;?php $comments_by_type = &amp;separate_comments($comments); ?&gt; &lt;?php if ( !empty($comments_by_type['comment']) ) : ?&gt; &lt;ol&gt; &lt;?php wp_list_comments(array('callback' =&gt; 'commentslist', 'type' =&gt; 'comment')); ?&gt; &lt;/ol&gt; &lt;?php endif; ?&gt; &lt;?php if ( ! empty($comments_by_type['pings']) ) : ?&gt; &lt;h3 id="pings"&gt;Pingbacks/Trackbacks&lt;/h3&gt; &lt;ol class="pinglist"&gt; &lt;?php wp_list_comments(array('callback' =&gt; 'commentslist', 'type' =&gt; 'pings')); ?&gt; &lt;/ol&gt; &lt;?php endif; ?&gt; &lt;/div&gt; &lt;?php endif; // end have_comments() ?&gt; &lt;/div&gt; </code> Here is my <code> wp_list_comments </code> callback: <code> function commentslist($comment, $args, $depth) { $GLOBALS['comment'] = $comment; require_once(ABSPATH . WPINC . '/registration.php'); if ($comment-&gt;user_id || email_exists($comment-&gt;comment_author_email)){ //comment by registered user $avatar = '/images/bird_comments_big.png'; }else{ //comment by none registered user $avatar = '/images/bird_comments_pink.png'; } ?&gt; &lt;li&gt; &lt;div id="comment-&lt;?php comment_ID(); ?&gt;" &lt;?php comment_class(); ?&gt;&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;?php echo get_avatar($comment, 70, get_bloginfo('template_url').$avatar); ?&gt; &lt;/td&gt; &lt;td&gt; &lt;div class="comment-meta"&gt; &lt;?php printf(__('&lt;p class="comment-author"&gt;&lt;span&gt;%s&lt;/span&gt; says:&lt;/p&gt;'), get_comment_author_link()) ?&gt; &lt;?php printf(__('&lt;p class="comment-date"&gt;%s&lt;/p&gt;'), get_comment_date('M j, Y')) ?&gt; &lt;?php comment_reply_link(array_merge($args, array('depth' =&gt; $depth, 'max_depth' =&gt; $args['max_depth']))) ?&gt; &lt;/div&gt; &lt;/td&gt; &lt;td&gt; &lt;div class="comment-text"&gt; &lt;?php if ($comment-&gt;comment_approved == '0') : ?&gt; &lt;p&gt;&lt;?php _e('Your comment is awaiting moderation.') ?&gt;&lt;/p&gt; &lt;br/&gt; &lt;?php endif; ?&gt; &lt;?php comment_text() ?&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;?php } </code> It seems to that wp_gravatar should call up the non-registered user image due to a lack of an e-mail address for pings, but instead its returning nothing.
By default WordPress does not display an avatar for a pingback or a trackback - do they even contain an e-mail address? You can add these to the <code> get_avatar_comment_types </code> filter if you want to change this.
Default Gravatar not showing for pings
wordpress
what is the action hook, if a user activates his profile? For the profile update, it is: <code> profile_update </code> for example. My goal is, to execute a function, if a user activates his profile. Something like this: <code> add_action( 'user_activate','my_function'); </code>
Well there you go Register Plus Redux is the plugin which is adding your new user verification, and by looking at its code there are no filters or hooks which is said because if you make changes to it they will be lost the next time you update, so i would suggest to contact the plugin developer and ask him to add it. But a quick fix for you would be to add <code> do_action('3cees_user_activate',$user_id); </code> after line 2938 at register-plus-redux.php and you can then call it like this: <code> add_action( '3cees_user_activate','your_function'); </code> and your function will run when a user is activated and $user_id will be passed to it.
Wordpress Hook for user account activation in normal Wp (not MU)
wordpress
I need some help with a custom menu. I'm using WP 3.1.1. I need to create an unclickable placeholder in the nav menu. So, the children will be clickable, but the "title" in the nav bar is not. For example, let's say I have a Shovel Page, Trowel Page, and a Spade Page and I want them all to be accessible under the Tools section in the Custom Menu. In the menu, "Tools" isn't clickable, only the children are. I tried the solution outlined here: stackexchange-url ("non-clickable placeholder in the menul") . But, if I click the placeholder I get an Alert. Also, his opened Custom Link box looks different than mine. I only have options for URL, Navigation Label, and Title Attribute. I don't know if that has anything to do with why it doesn't work. Any suggestions? Thank you. -Laxmidi
HERE´S YOUR ANSWER http://wordpress.org/support/topic/unclickable-menu-button CHEERS
Unclickable Menu Item Label in Custom Menu with Clickable Children
wordpress
I am a new user with WordPress, and I would like to use mathematical formulas. I have been reading the mathjax pages for hours, such as this one and quite a few others. This may be a bad question, but can someone please help me? All I want to do is enable Latex, and I am hopelessly lost. My most recent attempts have been trying to find the "header file" so that I can copy and paste in <code> &lt;script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"&gt; &lt;/script&gt; </code> I have tried looking for it, and looked over a whole bunch of forum posts about where to find this header file, but I just do not understand. A step by step explanation of how to make mathjax work in the simplest way possible would be extremely appreciated!! (Also, don't worry about leaving in too many steps!)
If you have a blog that is hosted on WordPress.com, you can't install extra plugins or modify the theme files yourself - this is only possible with a self-hosted version. However, WordPress.com has enabled LaTeX support for everyone. Just write <code> $latex your-latex-code$ </code> and it will be rendered as images.
Math notation on WordPress.com?
wordpress
I've tried a bunch of AdSense plugins but I can't seem to make any work. Can someone recommend something that is known to work? My requirements are simple: display an ad under the header.
If your requirements end at "display an ad under the header" then just open up your theme's header.php file and paste your adsense code there directly and avoid using a plugin all together.
A reliable AdSense plugin. Does it exist?
wordpress
I would like to add a custom field that is set by a jquery datepicker ui in the post edit panel. Im new to wordpress, so Im not sure how to go about adding something like this. I haven't had much luck with plugins, so I would like to know how one would go about adding something like this manually. I am familiar with PHP.
Since you are new to WordPress I would suggest using Meta Box Script for WordPress which provides an easy way of adding your custom fields to the post edit panel and its main features are: Support various field types, including: text, textarea, checkbox, checkbox list, radio box, select, wysiwyg, file, image, date, time, color. Developers can easily add more types by extending the script. Allow to create multiple meta boxes. Written in OOP, allow developers easily extend the script. Work with custom post types. Each meta box can be defined for many custom post types.
Add a Jquery Datepicker to custom field in post edit
wordpress
I am currently in version 3.1 of WordPress and I have a problem with planning my post. In fact, whenever I plan a post, it is written: "Scheduled missed. Could you help me please. Thank you in advance Francis NIKOU
Due to your server configuration, you may need to use the alternate cron method, which uses redirect rather than http loopback. Try adding the following to your <code> wp-config.php </code> file: <code> // Alternate cron method define( 'ALTERNATE_WP_CRON', true ); </code>
Missed scheduled WordPress
wordpress
I'm trying to add BuddyPress nav menu support to my theme and, unfortunately, BP's template tags still aren't fully up to snuff. (Basically, if you're not making an explicit child theme for the BP Default theme, you've got to reinvent several wheels.) So what I'd like to do is Detect when BP is active (I know how to do this) Register a menu position when BP is active (also a known quantity) Create a default menu containing links to the BP sections ( this is where the hole in my knowledge exists ) Assign said default menu to the newly-registered position So, essentially, with my theme active, if a user activates BuddyPress, they'll automatically get a menu with Members, Forums, Activity, etc. and it will be displayed to a position, but if users wanted to override the menu, they would be free to do so. Thoughts? EDIT 1 Bainternet wins the prize. Here's what I did, slightly modified from his solution: I conditionally registered a menu location <code> if( function_exists( 'bp_get_loggedin_user_nav' ) ){ register_nav_menu( 'lblgbpmenu', 'Default BuddyPress Menu' ); } </code> I then conditionally hooked in a call to the menu setup <code> if( function_exists( 'bp_get_loggedin_user_nav' ) ){ add_action( 'widgets_init', 'lblg_add_default_buddypress_menu' ); } </code> Then, last of all, I actually registered the menu <code> function lblg_add_default_buddypress_menu(){ global $lblg_themename; $menuname = $lblg_themename . ' BuddyPress Menu'; $bpmenulocation = 'lblgbpmenu'; // Does the menu exist already? $menu_exists = wp_get_nav_menu_object( $menuname ); // If it doesn't exist, let's create it. if( !$menu_exists){ $menu_id = wp_create_nav_menu($menuname); // Set up default BuddyPress links and add them to the menu. wp_update_nav_menu_item($menu_id, 0, array( 'menu-item-title' =&gt; __('Home'), 'menu-item-classes' =&gt; 'home', 'menu-item-url' =&gt; home_url( '/' ), 'menu-item-status' =&gt; 'publish')); wp_update_nav_menu_item($menu_id, 0, array( 'menu-item-title' =&gt; __('Activity'), 'menu-item-classes' =&gt; 'activity', 'menu-item-url' =&gt; home_url( '/activity/' ), 'menu-item-status' =&gt; 'publish')); wp_update_nav_menu_item($menu_id, 0, array( 'menu-item-title' =&gt; __('Members'), 'menu-item-classes' =&gt; 'members', 'menu-item-url' =&gt; home_url( '/members/' ), 'menu-item-status' =&gt; 'publish')); wp_update_nav_menu_item($menu_id, 0, array( 'menu-item-title' =&gt; __('Groups'), 'menu-item-classes' =&gt; 'groups', 'menu-item-url' =&gt; home_url( '/groups/' ), 'menu-item-status' =&gt; 'publish')); wp_update_nav_menu_item($menu_id, 0, array( 'menu-item-title' =&gt; __('Forums'), 'menu-item-classes' =&gt; 'forums', 'menu-item-url' =&gt; home_url( '/forums/' ), 'menu-item-status' =&gt; 'publish')); // Grab the theme locations and assign our newly-created menu // to the BuddyPress menu location. if( !has_nav_menu( $bpmenulocation ) ){ $locations = get_theme_mod('nav_menu_locations'); $locations[$bpmenulocation] = $menu_id; set_theme_mod( 'nav_menu_locations', $locations ); } } } </code>
So basically you are asking how to create a custom menu by code and assign it to a menu location: <code> //give your menu a name $name = 'theme default menu'; //create the menu $menu_id = wp_create_nav_menu($name); //then get the menu object by its name $menu = get_term_by( 'name', $name, 'nav_menu' ); //then add the actuall link/ menu item and you do this for each item you want to add wp_update_nav_menu_item($menu-&gt;term_id, 0, array( 'menu-item-title' =&gt; __('Home'), 'menu-item-classes' =&gt; 'home', 'menu-item-url' =&gt; home_url( '/' ), 'menu-item-status' =&gt; 'publish')); // you add as many items ass you need with wp_update_nav_menu_item() //then you set the wanted theme location $locations = get_theme_mod('nav_menu_locations'); $locations['LOCATION_NAME'] = $menu-&gt;term_id; set_theme_mod( 'nav_menu_locations', $locations ); </code> So all you have to do is add as many links as you want, change <code> LOCATION_NAME </code> to the actual location name and make sure this code is only run once.
How can I create an auto-populated menu that is automatically assigned to a location?
wordpress
I'm using Mac OS X's built in Apache + PHP with MySQL. Everything works perfectly, except for my pretty %postname% permalinks — they just won't work. I have obviously enabled mod_rewrite and set the AllowOverride setting to All on my httpd.conf file. In case there's anything I can do (I really don't want to run MAMP), is there any programmatic way to use default permalinks on localhost using the very same template files?
Your /etc/users/{username}.conf should look like this: <code> &lt;Directory "/Users/username/Sites/"&gt; Options Indexes MultiViews FollowSymLinks AllowOverride All AuthConfig Order allow,deny Allow from all &lt;/Directory&gt; </code> You also have to change the name Apache runs under to be able to save the .htaccess rules and use the media uploader etc... <code> &lt;IfModule !mpm_netware_module&gt; &lt;IfModule !mpm_winnt_module&gt; User chris Group admin #or you can use staff &lt;/IfModule&gt; &lt;/IfModule&gt; </code> The AllowOverride is listed a couple of times in httpd.conf make sure you changed the right one or both. One is the default setting and the other is for Library/WebServer/Documents which you should change to whatever server document root your using. Apache has to be restarted for any changes to take affect. <code> sudo apachectl restart </code> Also see How to Install Apache and PHP on Mac OSX for more details.
How to enable %postname% permalinks on Mac?
wordpress
Looking for a plugin that I can hardcode into my custom post type template that pulls the images from gallery images added into the standard WP gallery. Thoughts?
See the code in my stackexchange-url ("answer to a similar question"). It strips out and reworks the gallery shortcode to use with jQuery Gallerific.
Slideshow/Gallery plugin based on WP Core Gallery
wordpress
I have a client (same for my stackexchange-url ("previous post about the slider")) who believes that the url structure needs to include a "google page id" to be compliant with google news. Therefore, they want the url structure set up like: http://www.sitename.com/blog/article-name-goes-here?p=85532 . I think they want just a unique 3+ number id associated with every post. Does anyone know how to go about this? I am quite good with design and front-end dev, but when it comes to WordPress loops or settings sometimes I am just clueless.
Go to the Permalink page (in Settings), and choose custom structure, and use something like this: <code> /%year%/%monthnum%/%day%/%postname%/00%post_id% </code>
WordPress Page Id
wordpress
Hey, I'm stuck trying to add a box with settings for all pages (the ones users create/edit). What I'm attempting to do is add 6, 7 check boxes and an input field for all pages that alters the rendering of it; for example: "Display a contact form at the bottom yes/no?" . How do you do this without, of course, editing any Wordpress core files?
In WordPress these boxes are called "meta box" and to add one to your new/edit page screen you can use add_meta_box() function (look at the example at the bottom for the examples), you can also use this class which is nicely documented and does most of the job for you. Or you can use a plugin like Verve Meta Boxes which does all of the job for you and you just add the options you want form its UI.
Add box with custom per-page properties
wordpress
I'm using a custom field query (or trying to) : <code> $args = array( 'post_type' =&gt; 'pf_cookbook', 'meta_query' =&gt; array( 'key' =&gt; 'pf_cookbook_recipes', 'value' =&gt; '5', 'compare' =&gt; 'NOT IN', 'type' =&gt; 'NUMERIC' ) ); </code> However, the meta value to be compared is an array. The idea here is I am querying the DB to get the cookbooks which don't contain a certain recipe. The Recipes &amp; Cookbooks are Custom Post Types. The Cookbooks have a meta key 'pf_cookbook_recipes' which I am storing an array of recipe IDs. Maybe I am missing something?
<code> meta_query </code> needs to be an array of arrays - have a look at the code sample in the Codex again. So, for your example: <code> $args = array( 'post_type' =&gt; 'pf_cookbook', 'meta_query' =&gt; array( array( 'key' =&gt; 'pf_cookbook_recipes', 'value' =&gt; '5', 'compare' =&gt; 'NOT IN', 'type' =&gt; 'NUMERIC' ) ) ); </code> );
Custom Field Query - Meta Value is Array
wordpress
I am building a site on WordPress. I can't publish posts: when I attempt to do so, the site just hangs and then I get a time out page. However, I can add new pages without a problem. I have tried: Upgrading the WP build. Switching my theme to Twenty Ten. I still cannot publish posts. Deleting all plugins and the plugin folder. None of this has resolved the issue. Should I contact my host or is this a WP issue? Thank you for any help, Jeff
Considering all the content generated by WordPress websites, it seems rather far-fetched that this would be a WordPress problem. I'd contact your host.
Cannot publish posts, but can create new pages
wordpress
I'm working on a site that has 150,000 comments with an obvious hit in performance; is there an SQL query that can delete all comments older than say 90 days? They're not spam comments, and they are all approved; they're just too numerous. And: what about bulk changing all posts older than 90 days to untick "Allow comments" and "Allow trackbacks and pingbacks"? So they don't get re-commented?
Regarding comments- what about the case where a comment older than 90 days has child replies younger than 90 days? for comment and pingback status, this should do it: <code> UPDATE wp_posts SET comment_status = 'closed', ping_status = 'closed' WHERE post_date &lt; DATE_SUB(NOW(), INTERVAL 3 MONTH) AND post_status = 'publish'; </code>
SQL query to delete comments older than 90 days?
wordpress
I can't seem to find such an option listed here: http://codex.wordpress.org/XML-RPC_wp#wp.setOptions Does it exist? Thanks.
No, that option does not currently exist through XML-RPC. However, you can always create your own method in a plugin and hook it up to XML-RPC. Update There's an upcoming Google Summer of Code project that will be extending the XML-RPC interface to allow direct manipulation of themes, so I won't give away code to implement that here. But keep your ears and eyes open for when new code (core changes and/or plugins) start releasing this summer. In the meantime, I will provide an alternative. The set of options that you can view and set through XML-RPC is filterable. Basically, you can tell the system to give you more information than it normally would. What you can already get (bold options are read only ... you can't change them with <code> wp.setOptions </code> but you can retrieve them with <code> wp.getOptions </code> ): software_name software_version blog_url content_width time_zone blog_title blog_tagline date_format time_format users_can_register thumbnail_size_w thumbnail_size_h thumbnail_crop medium_size_w medium_size_h large_size_w large_size_h This list (actually, an array with other settings), is passed through the <code> xmlrpc_blog_options </code> filter, which means you can add and remove to this list all you want. To enable the fetching of the current theme by <code> wp.getOptions </code> and the changing of the theme by <code> wp.setOptions </code> you'd use the following: <code> function allow_xmlrpc_theme_changes( $xmlrpcoptions ) { $xmlrpcoptions['active-theme'] = array( 'desc' =&gt; __( 'Active site theme' ), 'readonly' =&gt; false, 'option' =&gt; 'template' ); $xmlrpcoptions['active-stylesheet'] = array( 'desc' =&gt; __( 'Active site stylesheet' ), 'readonly' =&gt; false, 'option' =&gt; 'stylesheet' ); return $xmlrpcoptions } add_filter( 'xmlrpc_blog_options', 'allow_xmlrpc_theme_changes' ); </code> This adds two fields that you can set: "active-theme" and "active-stylesheet". Remember, you'll be setting these options the same way as you would using <code> update_option() </code> , so double check the codex before doing anything.
Is it possible to change a blog's theme through XML-RPC command? (and if so how?)
wordpress
Using 3.1.1 with debug on, I am getting following notice. <code> Notice: Undefined variable: _POST in &lt;filepath&gt; on line 1000 </code> Code at line 1000 is <code> $data = $_POST </code> Why am I getting this notice? How can I remove this particular notice?
First check if it is a non-empty POST request: <code> if ( 'POST' == $_SERVER['REQUEST_METHOD'] and ! empty ( $_POST ) { // don't forget to sanitize these data! $data = $_POST; } else { return FALSE; } </code>
Undefined variable _POST
wordpress
I've added a separate menu page (an object page) with minimum access level required as 'Subscriber'. I'm doing this because I'm registering new users and they'll be 'Subscribers' with an extra capability to edit a section that my plugin creates. So I want them to be able to see this menu as well. I created my menu page as follows: <code> add_object_page('Personal Section', 'Personal Section', 'subscriber', 'personal-section', 'personal_section_fn'); </code> Now when I log in with the subscriber credentials, I'm able to see this menu, but I'm not able to see it when logged in as Admin. Am I doing something wrong here? Thanks in advance!
<code> subscriber </code> is a role, not a capability . Use a capability to manage access, e.g. <code> read </code> . To understand the difference better install Justin Tadlock’s plugin Members . For the subscriber role you get a list of capabilities like this: The administrator role in contrast:
Menu page with minimum capability as 'Subscriber' doesn't allow 'Admin' to access it?
wordpress
There are cases in which a plugin or theme needs to create a php file somewhere that can later include it. For example a captcha plugin, or some kind of a templating system like twig/smarty (In my situation it's simple template engine for a collection of widgets). Where should be this file created? The only place I can think of is <code> wp-content/uploads/ </code> , but that just doesn't sound right :) So is there a safe place where you can create files, and not worry about them being deleted on WordPress/plugin/theme update ? One solution could be to create a child theme / directory in the themes / plugins directory...
The appropriate place IMHO would be a custom folder that you create inside the wp-content directory Read this before creating files: http://ottopress.com/2011/tutorial-using-the-wp_filesystem/
Where to store PHP files created by plugin / themes
wordpress
Is it possible to automatically email the daily archive.php page as an html email newsletter? For example, at 4am every weekday WordPress would send an email of the 2011/04/25/ page. Any input is greatly appreciated!
I do not think this is built into WordPress currently. This would probably need to be custom-built. It would be some php code that is attached to a cron job. Set the cron job to run every day, and have your php script email out the page. These resources may help: http://ss64.com/osx/crontab.html (via stackexchange-url ("stackexchange-url
Automatically email daily archive
wordpress
Is there a plugin or a "hack" that can help me do this? I have spent hours try to figure this out so I would greatly appreciate nay help. I have WP 3.1 running php5 Thanks! eg.: postitle_image-ID.jpg
Hook into the filter <code> 'sanitize_file_name' </code> . See my plugin Germanix URL for a working example. A plugin doing this is Rename Media .
Automatic image renaming based on title
wordpress
I have re-worded this to make more sense. Ok, I have a plugin that uses a remote service that check for updates, much like default WordPress plugins, in this case it just checks an XML file. I want to show a menu bubble like this when an update is available. It can show just a "1" or text like "alert", it doesn't matter. Since my plugin uses an options page (using <code> add_options_page </code> ) the plugin settings show up under the default "Settings" submenu. I think I need to add the following CSS to get the bubble to show up, <code> &lt;span class='update-plugins count-1' title='title'&gt;&lt;span class='update-count'&gt;1&lt;/span&gt;&lt;/span&gt; </code> and tie into the global <code> $submenu </code> . The problem is I cannot use a hard-coded array value for the menu since each site will have different values. So I cannot use <code> $submenu[80][10] .= &lt;span class='update-plugins count-1' title='title'&gt;&lt;span class='update-count'&gt;1&lt;/span&gt;&lt;/span&gt; </code> How can I find my plugins submenu value, do I have to loop through the array and match the string values? Also even when I hard-coded the values I could not get the bubble to show up. <code> //adding plugin to menu add_action('admin_menu', 'sec_plugin_checker'); function sec_plugin_checker() { add_options_page(' Plugin Checker', 'Plugin Check', 'activate_plugins', 'sec_plugin_check', 'sec_checker'); // the conditional where I want the bubble to appear if (!empty($matches)){ echo "Match found !&lt;br /&gt;"; global $submenu; foreach( $submenu as $item ) { $item[41][20] = sprintf( __( 'Updates %s', 'sec_plugin_checker' ), "&lt;span class='update-plugins count-1' title='title'&gt; &lt;span class='update-count'&gt;1&lt;/span&gt;&lt;/span&gt;"); } } </code> and here is what a <code> var_dump($submenu); </code> looks like, <code> ["options-general.php"]=&gt; array(9){ ... [41]=&gt; array(4) { [0]=&gt; string(20) "Plugin Check" [1]=&gt; string(16) "activate_plugins" [2]=&gt; string(21) "sec_plugin_check" [3]=&gt; string(23) " Plugin Checker" ... } </code>
I would do this when you call <code> add_options_page() </code> , not later. It's always better to do this with the supported API instead of playing with the internal structures. The plugin updater periodically checks the plugin status and then saves the result in a transient . This means that it only reads this cached status when the menu is created, it doesn't do the full check on every page load. You can do something similar: <code> add_action( 'admin_menu', 'wpse15567_admin_menu' ); function wpse15567_admin_menu() { $warnings = get_transient( 'wpse15567_warnings' ); $warning_count = count( $warnings ); $warning_title = esc_attr( sprintf( '%d plugin warnings', $warning_count ) ); $menu_label = sprintf( __( 'Plugin Checker %s' ), "&lt;span class='update-plugins count-$warning_count' title='$warning_title'&gt;&lt;span class='update-count'&gt;" . number_format_i18n($warning_count) . "&lt;/span&gt;&lt;/span&gt;" ); add_options_page( 'Plugin Check', $menu_label, 'activate_plugins', 'sec_plugin_check', 'sec_checker' ); } </code> When you do the actual warning check, you save the results in the transient so it can be read later: <code> if ( ! empty( $matches ) ) { set_transient( 'wpse15567_warnings', $matches ); } </code> Notice that I don't do anything special when there are no warnings. The bubble doesn't get displayed because it gets the class <code> count-0 </code> , which has <code> display: none </code> in the css .
Add update notification bubble to admin menu item?
wordpress
I just imported my entries from my blog into a freshly installed Wordpress. I created a new user..e.g. "bob" (bob has an ID=2 in the wp_users table). I want the author of the new posts that I've imported to be "bob". So I thought that I change the post_author of a post to 2! However, when I went to view the post in the blog, the author was still the old author. I found the work around for this...you can actually change the author by using the bulk post editing function. After I did this, the posts in the blog had their author as "bob". But, when I went to the wp_posts table, the post_author field did not change. I looked at all the wp_ tables and can't see where a post's author is indicated. The only place that I found was the wp_posts table...but changing the post_author doesn't see to take any effect when you look at the blog. So, the mystery is...where is the real author id of a post kept? UPDATE OK...I found out that there were some posts that were duplicated except for their 'post_status'. There are some weird statuses such as 'auto-save' and 'inherit'. I unfortunately didn't see the post_status column and changed the 'post_author' of a post with the 'inherit' status. So mystery solved... The new mystery, i.e. what the different 'post_status' values are is answered here .
the real author id is stored in... post_author in the posts table. not sure what's going on in your case. I've just created a new user now and changed some post_author ids to this new user directly in the database and it's showing immediately when I refresh the admin interface. maybe some sort of cache situation you've got happening.
Changing user of post by changing 'post_author' field in 'wp_posts' table not taking effect. Where is the real post author info kept?
wordpress
When you visit wordpress.com, they have a list of the most popular posts right on the front page. I was wondering if there was a way to do the same thing on my multisite installation. Is it possible, and if it is, how would I go about doing it (plugin? theme?)?
Possibly related: stackexchange-url ("Aggregate Summaries of Posts of Different Blogs in Multisite Instance").
How to display the most popular posts of all the blogs in a mu setup?
wordpress
Okay guys, here's the scenario. I'm am trying to setup a function that will automatically duplicate a post (when published) over to another post type. So, a regular blog post is published, and when it is published, all of its information is copied over to a custom post type (for WP ECommerce), automatically creating a store entry for that blog post. I've written a function that takes care of picking up all of the information and inserting it into a new post with wp_insert_post(). It all works great, except for one thing. I'm using wp_set_object_terms() to set the store category ids of the new product based on the tags of the blog post. However, for some reason, wp_set_object_terms() never works. Now, here's the catch. I'm running all of this on a multi site install and am using threeWP_Broadcast to allow me to cross publish posts. The blog posts (which have to be copied to the store) are published from a sub site and broadcasted to the main site. The store is on the main site. So I've hooked my custom function into the broadcast plugin so that it gets fired when a post is broadcasted from a sub site to the main site. Everything with my function works great, except for the wp_set_object_terms() Here's function: <code> function copy_post_to_store_product() { global $blog_id; global $wpdb; // only copy the post over if on main site, not subsites if ($blog_id == 1) { $args = array('numberposts' =&gt; 1); $latest = get_posts($args); foreach($latest as $post) : setup_postdata($post); // if NOT Tip and NOT source avail, create product // if source, price is ALWAYS $4 // auto create for source files only -- regular post type $custom_meta = get_post_custom($post-&gt;ID); // what kind of post is this? $post_type = $custom_meta['cgc_post_type'][0]; // does this post have a source file product associated with it? $source_avail = $custom_meta['cgc_source_avail'][0]; // source file price $price = '4'; $product_info = array( 'post_title' =&gt; $post-&gt;post_title, 'post_type' =&gt; 'wpsc-product', 'post_content' =&gt; $post-&gt;post_content, 'post_author' =&gt; $post-&gt;post_author, 'post_status' =&gt; 'draft', ); if($post_type == 'Regular' &amp;&amp; $source_avail == true) { // only auto create product for Regular posts that have source files for sale $product_id = wp_insert_post($product_info); update_post_meta($product_id, '_wpsc_price', $price); if (has_tag('blender', $post-&gt;ID)) { $product_cats = array(23,32); } elseif (has_tag('max', $post-&gt;ID)) { $product_cats = array(23,34); } elseif (has_tag('modo', $post-&gt;ID)) { $product_cats = array(23,19); } // set the product categories wp_set_object_terms($product_id, $product_cats, 'wpsc_product_category' ); } endforeach; } </code> } The function works by retrieving the latest post from the main site ($blog_id == 1) and copying all of its information into variables for wp_insert_post(). Now, the really interesting thing is that works perfectly if I attach the function to a publish_post hook, but, unfortunately, I can't do that because that hook doesn't fire when a post is broadcasted. Any ideas would be hugely appreciated.
I don't have a solution, but here's the root of your problem: http://core.trac.wordpress.org/ticket/20541 Apparently a call to switch_to_blog() would not repopulate $wp_taxomies, which these taxonomies rely on.
wp_set_object_terms() Fails to Set Terms
wordpress
I'm using WordPress as a Facebook platform and have a page that shows posts from 2 different categories. Each category has it's own pagination using wp-pagenavi. In order to stay in Facebook I need the pagination links to load using ajax. I've seen this article which gives a nice clue about it, but would love to know if anyone had already solved this and has any leads. My main issue here (and this is stupid), I get that I need to call an ajax function with jQuery and pass it the specific category and the desired page number. I have no idea how to get the page number. But once again, if you have an already made solution - it will be much appreciated Currently I tried using this tutorial, the tab code can be seen here . as you can see pagination affects both categories :-(
Take a look at this tutorial: http://www.wpmods.com/easily-ajax-wordpress-pagination
How To create ajaxed wp-pagenavi?
wordpress
Guys, I need to know how to do the following: When I receive a comment ... This comment must be approved by three moderators. To appear on the site. Anyone know how to do it or some plugin?
you can use <code> comment_unapproved_to_approved </code> action hook to call your function which will use a commentmeta field to count how many times that comment has been approved or by how many users and if it's less then 3 then we updated the comment to not approved : update I'm posting an updated code in the form of a plugin which fixes a few typos: <code> &lt;?php /* Plugin Name: 3-comment-mod Plugin URI: http://en.bainternet.info Description: Answer to stackexchange-url 1.0 Author: Bainternet Author URI: http://en.bainternet.info */ if(!function_exists('check_add_approved_count')) { function check_add_approved_count($comment){ global $current_user; get_currentuserinfo(); //respect the admin comments approved by one approval if (current_user_can('manage_options')){ return ''; } $mods = get_comment_meta($comment-&gt;comment_ID,'approved_by',true); if(!empty($mods) &amp;&amp; is_array($mods)){ //only allow each mod to approve once if (in_array($current_user-&gt;ID,$mods)){ return ''; }else{ //here we check the count if (count($mods) &lt; 3){ //if less then 3 then //we add the current mod to the approving list $mods[] = $current_user-&gt;ID; update_comment_meta($comment-&gt;comment_ID,'approved_by',$mods); //and revert back the comment to not approved $commentarr = get_comment($comment-&gt;comment_ID, ARRAY_A); $commentarr['comment_approved'] = 0; wp_update_comment($commentarr); } } } //if we got here it means that this is the first approval //so we just add the user to the list and revert back the comment to not approved $mods[] = $current_user-&gt;ID; update_comment_meta($comment-&gt;comment_ID,'approved_by',$mods); //and revert back the comment to not approved $commentarr = get_comment($comment-&gt;comment_ID, ARRAY_A); $commentarr['comment_approved'] = 0; wp_update_comment($commentarr); } } add_action('comment_unapproved_to_approved','check_add_approved_count'); ?&gt; </code>
3 moderators to approve comment
wordpress
Is there any plugin that allows you to use a custom field as the thumbnail to display the most popular post within the last day (24 hours)? I have found several plugins but none seem to have the capabilities that would allow me to add a custom field as the image or even a thumbnail at all.
If you know the $Post-> ID of the "most popular post", why not just use <code> get_the_post_thumbnail() </code> ( Codex ref ): <code> &lt;?php echo get_the_post_thumbnail( $id, $size ); ?&gt; </code>
Popular Post With Thumbnail?
wordpress
Just bump into the issue that I can't execute multiple sql queries using the <code> $wpdb-&gt;query() </code> . Generated queries work fine directly in phpmyadmin so its something will the ezSQL class only. By design perhaps? I found this http://wordpress.org/support/topic/wpdb-gtquery-fails-when-multiple-update-statements-are-used which also says its by design. Can anyone confirm? ezSQL docs dont say anything about multiple queries support. If you have to do a bunch of queries mainly (INSERT/UPDATE/DELETE), any better way of doing them other than doing them one by one using <code> $wpdb-&gt;insert() </code> and like functions?
Using PHP 5.3.5, I was unable to make this syntax work even after setting the 5th parameter of <code> mysql_connect() </code> to 65536 ( <code> CLIENT_MULTI_STATEMENTS </code> ). Looks like it's not possible to concatenate multiple queries into one statement as long as the old-school MySQL API is running the show. I assume you're familiar with the MySQL multiple row INSERT syntax, but I mention it just in case.
$wpdb-> query() multiple query support
wordpress
I have a custom post type (CPT) called <code> event </code> . I have a meta box for the type with several fields. I would like to validate some fields before publishing an event. For example, if an event's date is not specified I would like to display an informative error message, save the event for future editing, but prevent that event from being published. Is 'pending' status for an CPT post without all necessary info the right way to treat it? What's the best practice to do CPT fields validation and prevent a post from being published, but save it for future editing. Many thanks, Dasha
You can stop the post from saving all together with minor JQuery hacks and validate the fields before saving on the client side or server side with ajax: first we add our JavaScript to capture the submit/publish event and use it to submit our own ajax function before the actual submit: <code> add_action('wp_print_scripts','my_publish_admin_hook'); function my_publish_admin_hook(){ if (is_admin()){ ?&gt; &lt;script language="javascript" type="text/javascript"&gt; jQuery(document).ready(function() { jQuery('#post').submit(function() { var form_data = jQuery('#post').serializeArray(); form_data = jQuery.param(form_data); var data = { action: 'my_pre_submit_validation', security: '&lt;?php echo wp_create_nonce( 'pre_publish_validation' ); ?&gt;', form_data: form_data }; jQuery.post(ajaxurl, data, function(response) { if (response.indexOf('True') &gt; -1 || response.indexOf('true') &gt; -1 || response = true || response) { jQuery('#ajax-loading').hide(); jQuery('#publish').removeClass('button-primary-disabled'); return true; }else{ alert("please correct the following errors: " + response); jQuery('#ajax-loading').hide(); jQuery('#publish').removeClass('button-primary-disabled'); return false; } }); return false; }); }); &lt;/script&gt; &lt;?php } } </code> then we create the function to do the actual validation: <code> add_action('wp_ajax_my_pre_submit_validation', 'pre_submit_validation'); function pre_submit_validation(){ //simple Security check check_ajax_referer( 'pre_publish_validation', 'security' ); //do your validation here //all of the form fields are in $_POST['form_data'] array //and return true to submit: echo 'true'; die(); //or your error message: echo 'bal bla bla'; die(); } </code> you can always change it up a bit to do the validation only for your post type by adding a conditional check to <code> my_publish_admin_hook </code> function for your post type and to validate on the client side but i prefer on the server side.
don't publish custom post type post if a meta data field isn't valid
wordpress
i am new to multisite. It is a simple question. I know WordPress multisite can be setup for subdomains. Is it possible to use domains along with subdomains? I have searched google but have not had really good results. Perhaps I have used the wrong keywords. so i can use a single wordpress installation for: domain.com sub1.domain.com sub2.domain.com example.com example2.com sub1.example2com Hope you get it. Thanks in advance!
"example2.com sub1.example2com" Actually for subsites off of mapped sites, you want a multi network plugin. Free - http://wordpress.org/extend/plugins/wp-multi-network/ Paid - http://wpebooks.com/networks/
WordPress Multisite. Can domain be used instead of subdomain?
wordpress
This code: <code> &lt;?php comments_template( '', true ); ?&gt; </code> Outputs: <code> &lt;h3 id="comments-title"&gt; &lt;h2&gt; 12 Responses to My Post. &lt;/h2&gt; &lt;/h3&gt; (comments template) </code> I don't know where this h2 tag comes from. I want to get rid of that. And customize my comments-title (so there will be h4 instead of h3 and "comments" instead of "Responses". How to achieve that?
Comment markup - both the comments list and the comment reply form, will be in the <code> comments.php </code> template file. The contents of this file are entirely Theme-dependent, so any more-specific help will require the content of <code> comments.php </code> .
Wordpress comments title
wordpress
I am doing a WordPress site for a school. One of the pages would have a list of 20 or so students, which would include their name, photo and small blurb. How is this type of thing handled in Wordpress? I would like the user of the CMS to be able to manage this page effectively - adding/removing students etc. I know Wordpress is being used in e-commerce sites, so people who run these site must be in the same situation on their pages of products. Should I be using plugins? Custom fields? thanks in advance
You could create a custom post type 'student', with post thumbnails for the images. The post title would be their name, post content would be the blurb. If the code scares you, there are plugins to assist. Taxonomies are also available to you, which operate like categories and tags, but can be any set of attributes or means of grouping.
How is a student directory best handled in WordPress?
wordpress
I'm using mac os x 10.6 with xampp. <code> http://wp3.1/ </code> is the url to where I have WordPress installed. The physical path is <code> /Users/myUserName/Sites/wp3.1/ </code> I do not install plugins or themes in the "natural" way. I have created a directory named "git" which is located in <code> /Users/myUserName/git/ </code> . This is where all my git repositories live. When I want to install a plugin, I just create a symbolic link in <code> /Users/myUserName/Sites/wp3.1/wp-content/plugins/ </code> . This works great for simple plugins, but if the plugin enqueue's a style sheet or script, the url displays as: <code> http://wp3.1/wp-content/plugins/Users/myUserName/git/options-framework-plugin/css/colorpicker.css?ver=3.1.1 </code> How do I fix this?
Symbolic links are … stackexchange-url ("risky") in WordPress. It is easier to use a separate domain for plugins per wp-config.php: <code> define( 'WP_PLUGIN_DIR', '/local/path/to/plugin/directory' ); define( 'WP_PLUGIN_URL', 'http://plugins.dev'); </code> See stackexchange-url ("Strategy On Building Plugin Using Eclipse") as an example for IDE configuration with such a setup.
Symbolic Links on dev box with plugins and stylesheets
wordpress
The site is Videos-de-musica.com it is a simple wordpress blog with music videos. Somehow the subdomain stats.videos-de-musica.com filled up with spam, I remember setting the domain for pwiki stats, but then uninstalled it and I don't remember what happened to it. This is an example spam page stats.videos-de-musica.com/aal-0exe.htm When you search PRINTABLE SUPERMAN EMBLEM BATMAN on Google that is the first result, and when you access it you are redirected to a "Google has found malicious software may be installed onto your computer if you proceed" scam site. I have tried disabling all the plugins with no change. Does anybody know what happened and how to remove this? I am downloading all the site directory to search for any clues. Thanks.
Hi @JavierRey: You probably downloaded a theme or plugin that added a "backdoor." stackexchange-url ("Otto") has a good post on the subject: How to find a backdoor in a hacked WordPress
Something is generating spam pages on my site
wordpress
I'm looking for a plugin that is compatible up to the current version of WordPress (3.1.1 as of writing of this question) and that supports some kind of inline highlighting of programming language syntax. Basically, I want to be able to write a <code> function name </code> or a <code> variable name </code> or a quick <code> if statement </code> as part of a paragraph and have it look like <code> code </code> , much like what you get in the StackExchange editor with the <code> backticks </code> . There are several good plugins for highlighting programming language syntax in WordPress, but they don't seem to support inline syntax highlighting. jQuery.Syntax claims to have the inline capability, but I can't get it to work on Wordpress 3.1.1.
If you still want to use SO-type backtick markup for styling your inline code examples, I've created some code that will accomplish it. To make it into your own plug-in, just add the code below to your functions.php. It calls the wordpress filter "the_content" to apply the transformation to the content when it is displayed, thereby keeping any transformations from becoming stored in the database. <code> function style_my_inline($content){ //what you use to denote your code $inline_marker = "`"; //regex for code $pattern = "/".$inline_marker."[\w\D\d]+?".$inline_marker."/"; preg_match_all($pattern,$content,$matches); //what you want your surrounding markup to be $prepend_tag = "&lt;span class = \"code\"&gt;"; $append_tag = "&lt;/span&gt;"; //for each occurance in preg match results... foreach($matches as $match){ for($i=0;$i&lt;count($match);$i++){ //remove inline marker from match text $match_without_inline_marker = str_replace($inline_marker,'',$match[$i]); //add surrounding markup to match $match_with_tags = $prepend_tag.$match_without_inline_marker.$append_tag; //replace match in original content with marked-up match $content = str_replace($match[$i],$match_with_tags,$content); } } return $content; } apply_filters("the_content","style_my_inline"); </code> Now, I tested the code above with some dummy text and used backticks to define code blocks like so: <code> Lorem ipsum dolor sit amet, `consectetur adipiscing elit`. Donec nec magna erat. `Aenean nisi ante`, semper vel imperdiet sed, laoreet. </code> Then applied the following css: <code> &lt;style type = "text/css"&gt; span.code{color:#56aaff;font-family:courier;background:#e5e5e5;padding:1px;} &lt;/style&gt; </code> And what I get looks like this: Hope this works for you.
Highlight Syntax Inline
wordpress
I am building a custom app in WordPress, so I need some means of logging my events. I searched and found this plugin - http://wordpress.org/extend/plugins/wp-logs/ which looks very convenient to use. It uses database to store logs and can display them in the backend itself. Another option for me is to learn WP filesystem (something which I haven't tried yet) and use it to write logs to file on disk. What do you think would be best considering the tradeoff between performance &amp; convenience? Database write is equal to <code> I/O write </code> + some extra work. Thoughts?
I would prefer to use WP-Logs plugin because its code looks pretty well and you will not waste so much time writing something completely from the scratch. I also store data in the database more likely because I think database could be scaled more efficiently when needed. The another reason why I would prefer database is that the data could be accessed more easily by other plugins/APIs. From my point of view it's more secure too (for me it's easier to secure the database then the files on the FTP or in case when you need to access it from the external source...).
Options for logging events in WordPress
wordpress
Why is that? It's a new installation. EDIT: I don't have plugins installed and I tried to restore default theme to Twenty Ten, but it didn't change anything.
Upper right corner in posts editing page > "Screen Options"...there you have to check "Excerpt" ;)
Excerpt textarea missing on post editing page in admin panel
wordpress
I want to add a onsite social bookmarking system to a WordPress installation. is there any thing like this available?
I think SexyBookmarks is the best http://wordpress.org/extend/plugins/sexybookmarks/ . There are some others Bookmark Me Simple Social Bookmarks
Is there a good plugin for social bookmarking on site for WordPress
wordpress
I'm looking for an easy to use step by step guide on how to create a MultiColoumn menu for categories on wordpress. Actually in my blog I have 10/12 "main" categories and a couple of them have something like 50 Sub-categories and I will add more so I need something Automatic to show them in my menu. Actually I have one but it is full of bugs. So I need something new please. This is my CSS (you can also write it from scratch, maybe it's better :P) <code> .videoCssMenucontainer {margin: 2px 0 0;} UL.ws_css_cb_menu {background-color : #7F9DB9;width : 96%;margin:0 1.75% 10px 1.75%;font : bold 13px Arial, Helvetica, sans-serif;display : block;float : left;height : 33px;border-top-right-radius : 0;border-bottom-right-radius : 10px;border-bottom-left-radius : 10px;border-top-left-radius : 0;position:relative;z-index:10000;} UL.ws_css_cb_menu LI {display : block;margin : 2px 0 0 2px;float : left;} UL.ws_css_cb_menu A:hover UL, UL.ws_css_cb_menu A:hover A:hover UL, UL.ws_css_cb_menu A:hover A:hover A:hover UL {display : block;} UL.ws_css_cb_menu A {display : block;vertical-align : middle;border-width : 0;border-color : #6655ff;border-style : solid;padding : 2px;color : #444444;text-decoration : none;text-align : left;} UL.ws_css_cb_menu SPAN {overflow : hidden;} UL.ws_css_cb_menu LI A:hover, UL.ws_css_cb_menu LI A {padding : 9px;color : #763319;} UL.ws_css_cb_menum LI A:hover, UL.ws_css_cb_menum LI A {padding : 4px;font-weight : normal;color : #000;} UL.ws_css_cb_menu UL {position : absolute;left : -1px;top : 98%;width : 160.65px;background-color : #ffffff;} UL.ws_css_cb_menu UL UL {position : absolute;left : 98%;top : -2px;} UL.ws_css_cb_menu, UL.ws_css_cb_menu UL {margin : 0;list-style : none;padding : 0 2px 2px 0;} UL.ws_css_cb_menu A:active, UL.ws_css_cb_menu A:focus {outline-style : none;} UL.ws_css_cb_menu UL LI {float : left;width : 150px;} UL.ws_css_cb_menu UL A {white-space : nowrap;text-align : left;} UL.ws_css_cb_menu LI:hover {position : relative;} UL.ws_css_cb_menu LI:hover &gt; A {background-color : #fff;color : #000;border-color : #665500;border-style : solid;text-decoration : none;} UL.ws_css_cb_menu LI A:hover {position : relative;background-color : #fff;color : #000;text-decoration : none;border-color : #665500;border-style : solid;} UL.ws_css_cb_menum LI A:hover {background-color : #ffc000;} UL.ws_css_cb_menu IMG {border : none;float : left;margin-right : 4px;width : 16px;height : 16px;} UL.ws_css_cb_menu UL IMG {width : 16px;height : 16px;} UL.ws_css_cb_menu UL, UL.ws_css_cb_menu A:hover UL UL {display : none;z-index : 99999;} UL.ws_css_cb_menu LI:hover &gt; UL {display : block;} UL.ws_css_cb_menu SPAN {display : block;padding-right : 11px;background-position : right center;background-repeat : no-repeat;} UL.ws_css_cb_menu LI A TABLE, UL.ws_css_cb_menu LI A:hover TABLE {border-collapse : collapse;margin : -4px 0 0 -9px;border : 0 solid #000000;padding : 0;} UL.ws_css_cb_menu LI A TABLE TR TD, UL.ws_css_cb_menu LI A:hover TABLE TR TD {padding : 0;border : 0 solid #000000;} UL.ws_css_cb_menu LI A TABLE UL, UL.ws_css_cb_menu LI A:hover TABLE UL {border-collapse : collapse;padding : 0;margin : -4px 0 0 -9px;} UL.videoCssMenu {font-size : 13px;width : 96%;margin:0 1.75% 10px 1.75%;background : #7F9DB9;color:#FFF;text-shadow: rgba(0, 0, 0, 0.398438) 1px 1px 1px;border : 0 solid #000000;} UL.videoCssMenu .videoMenuTitleImage {margin : -2px 0 0 -2px;width : 79px;height : 30px;} UL.videoCssMenu UL {left : 0;background-color : #857DA2;width : 430px;} UL.videoCssMenu LI A {color:#FFF;text-shadow: rgba(0, 0, 0, 0.398438) 1px 1px 1px;padding: 5px !important;text-transform:uppercase;} UL.videoCssMenu UL LI A {overflow: hidden; float:left;} UL.videoCssMenu UL LI {width : auto;float : left;height : 27px;} UL.videoCssMenu LI:hover &gt; A, UL.videoCssMenu LI A:hover {background-color : #ffffff;border-radius : 5px;border-color : #fff;padding : 5px !important ;color : #000;} UL.videoCssMenu LI UL LI:hover &gt; A, UL.videoCssMenu LI UL LI A:hover {background-color : #ecb899;border-color : #fff;padding : 5px;color : #000;} ul.ws_css_cb_menu ul ul ul{background:#ccc;color:#142E51;text-shadow:1px 1px 1px #000;} ul.ws_css_cb_menu ul ul ul a{color:#142E51;text-shadow:1px 1px 1px #000;} .ws_css_cb_menum LI {width:auto;height:20px;} </code> And this is my HTML/PHP: <code> &lt;ul class="ws_css_cb_menu videoCssMenu"&gt; &lt;li&gt;&lt;a href="http://downloadtaky.info" title="Downloadtaky.info | Download FREE Film IPA Serie TV"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt; &lt;a href="#"&gt;Categorie&lt;/a&gt; &lt;!--[if lte IE 6]&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;![endif]--&gt; &lt;ul class='ws_css_cb_menum'&gt; &lt;?php wp_list_categories('sort_column=name&amp;sort_order=name&amp;style=list&amp;children=true&amp;hierarchical=true&amp;title_li=0&amp;dept=5&amp;show_count=1&amp;feed_image=/images/RSS.png'); ?&gt; &lt;/ul&gt; &lt;!--[if lte IE 6]&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/a&gt;&lt;![endif]--&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#"&gt;Pagine&lt;/a&gt; &lt;!--[if lte IE 6]&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;![endif]--&gt; &lt;ul class='ws_css_cb_menum'&gt; &lt;?php wp_list_pages('title_li='); ?&gt; &lt;/ul&gt; &lt;!--[if lte IE 6]&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/a&gt;&lt;![endif]--&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#"&gt;Hack&lt;/a&gt; &lt;!--[if lte IE 6]&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;![endif]--&gt; &lt;ul class='ws_css_cb_menum'&gt; &lt;li&gt;&lt;a href="http://proxy.downloadtaky.info"&gt;Proxy&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://hide.downloadtaky.info/"&gt;Url Hider&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://html2bbcode.downloadtaky.info"&gt;HTML 2 bbCode Converter&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;!--[if lte IE 6]&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/a&gt;&lt;![endif]--&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#"&gt;Seo&lt;/a&gt; &lt;!--[if lte IE 6]&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;![endif]--&gt; &lt;ul class='ws_css_cb_menum'&gt; &lt;li&gt;&lt;a href="http://pagerank.downloadtaky.info/"&gt;Pagerank&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://seo.downloadtaky.info/"&gt;FREE Seo Services&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://submit.downloadtaky.info/"&gt;Url Submitter&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;!--[if lte IE 6]&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/a&gt;&lt;![endif]--&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#"&gt;Servizi CSS&lt;/a&gt; &lt;!--[if lte IE 6]&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;![endif]--&gt; &lt;ul class='ws_css_cb_menum'&gt; &lt;li&gt;&lt;a href="http://buttongenerator.downloadtaky.info/"&gt;CSS Button Generator&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://favicon.downloadtaky.info/"&gt;Favicon Generator&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;!--[if lte IE 6]&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/a&gt;&lt;![endif]--&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#"&gt;Generatori Link Premium FREE&lt;/a&gt; &lt;!--[if lte IE 6]&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;![endif]--&gt; &lt;ul class='ws_css_cb_menum'&gt; &lt;li&gt;&lt;a title="Megavideo Unlocker, supera il limite di Megavideo" href="http://www.premiummu.com/megavideounlocker.php"&gt;Supera il limite di Megavideo&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a title="Fileserve, Megaupload,Uploading FREE Premium Link Generator" href="http://www.premiummu.com/premiumlinkgenerator.php"&gt;Premium link generator&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;!--[if lte IE 6]&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/a&gt;&lt;![endif]--&gt; &lt;/li&gt; &lt;?php include('supsearch.php');?&gt; &lt;/ul&gt; </code> I don't care about IE6 anymore, IE7 support will be enough, thank you to all for your help!
You are overloading the taxonomy category . Learn to use stackexchange-url ("custom taxonomies"). Some of your categories are in fact series , others belong into their own taxonomy too. Replace the hard coded navigation <code> ul </code> with a stackexchange-url ("nav menu") and look into the TwentyTen theme: it has a working solution for your problem. You can use your stackexchange-url ("own walker") to adjust it even more. But the first step to get a more professional look for your website is: drop Comic Sans. ;)
How to create an automatic MultiColoumn MegaMenu with Categories WordPress
wordpress
I want to put my flair in as a widget in the top of my sidebar in my blog. There was a similar question asked stackexchange-url ("here") but the only answer links to the flair page and suggests copying and pasting the html into the theme. I don't want to edit my theme, I want to be able to add is as a widget. Is this possible?
You can add the flair code to a text widget. Then go to your WordPress dashboard Appearance - > Widgets Your flair in the sidebar
How to put Stack Exchange Flair as widget?
wordpress
hey guys, weird problem. My blog theme works fine in ie8, ie9 and all other major browsers... however ie7 doesn't even render it? in ie7 it seems like my blog even has serverside problems? any idea what could cause that? In my programming history i've encountered ie7 styling issues and stuff but never something like this that the webpage doesn't even get rendered? Sometimes the page is kind of loaded in ie7, however the browser does crash anyway. any idea what could cause that? If sometimes the page gets loaded in ie7 the bar at the bottom says: "loaded but with errors" ... I do not have a single error if I validate the page!
You have a javascript error on line 451: ReferenceError: Can't find variable: jQuery. and then Failed to load resource: the server responded with a status of 403 (Forbidden): axx1cxj-b.css. The second one looks like s stylesheet that typekit is trying to load.
my blog crashes ie7?
wordpress
Alright, I have almost finished up a clients project in WordPress, but I have hit a wall. I am not really great with jQuery (and I have yet to find a plugin to achieve what they are looking for). The client wants an automatic slider on the homepage that pulls in featured posts out of their five categories. I have scoured the net for plugins to achieve the "look" they want, but to no avail. The look in question can be seen here . Does anyone know how to go about this?
This is one of those things you probably have to do yourself, even though there are some slider plugins, they are difficult to customize. Using a jquery slider is pretty straightforward, they are usually just controlled with ID's and CLASS's, so you can wrap any WordPress code, for instance a wp_query (for featured posts). toscho's answer pretty much covers it, I tend to use Jquery Tools a lot since it has great docs and tons of functionality, http://flowplayer.org/tools/index.html
WordPress Featured Post Slider
wordpress
I am working on a Thematic child theme and using the WPAlchemy Meta Box Class to create an 'Artwork Info' meta box that I want to conditionally echo like this at the end of each post: Title Medium Dimensions Additional Info My instance of the class is defined like this in <code> functions.php </code> : <code> $prefix = 'wpf_'; $artinfo_mb = new WPAlchemy_MetaBox(array ( 'id' =&gt; '_custom_meta', // underscore prefix hides fields from the custom fields area 'title' =&gt; 'Artwork Info', 'template' =&gt; STYLESHEETPATH . '/custom/artwork-meta.php', 'context' =&gt; 'normal', )); </code> And here's an example of the HTML for each field, located in <code> artwork_meta.php </code> : <code> &lt;label&gt;Title&lt;/label&gt; &lt;p&gt; &lt;?php $mb-&gt;the_field('title'); ?&gt; &lt;input type="text" style="width:99%" name="&lt;?php $mb-&gt;the_name(); ?&gt;" value="&lt;?php $mb-&gt;the_value(); ?&gt;"/&gt; &lt;/p&gt; </code> I am using this function in <code> functions.php </code> to print the data in each post via an array of the fields: <code> function display_artwork_info() { global $artinfo_mb; $artinfo_mb-&gt;the_meta(); $values = array('title','medium','dimen','additional'); echo the_content(); // loop through and conditionally echo the value with a line break foreach ($values as $val) { if ($val != ''){ $mb-&gt;the_value($val); echo '&lt;br /&gt;'; } } } add_action('thematic_post', 'display_artwork_info'); </code> All works fine except the <code> foreach ($values as $val) </code> always echoes the line breaks, even if the field's value contains no data. For example, if the 'medium' and 'additional info' fields are empty, the HTML echoes like this: <code> Title &lt;br /&gt; &lt;br /&gt; Dimensions &lt;br /&gt; </code> Is there something wrong with my loop? Am I using the wrong WPAlchemy function to echo the meta data? Thanks in advance :)
$val will never == '' here, because $val is holding your field name, not the data. also, use get_the_value to have it returned, the_value will just echo the data out. <code> foreach ($values as $val) { if ($artinfo_mb-&gt;get_the_value($val) != ''){ $artinfo_mb-&gt;the_value($val); echo '&lt;br /&gt;'; } } </code>
conditionally echo in meta box data loop
wordpress
Aa you know, as of WP3.0 there are options for custom advanced queries, which is great. As of this, some query parameters of custom fields like meta_key, meta_value were deprecated for the new meta_query parameter ( see here ) I try to have a pretty simple query with the new syntax, query posts by a certain post_type (services) that contains a specified meta_key (order_in_archive)- this is going well as expected. But - I want to orderby the query by the meta_value, and with no success. This is my query - <code> query_posts( array( 'post_type' =&gt; 'services', 'order' =&gt; 'ASC', 'orderby' =&gt; 'meta_value', 'meta_query' =&gt; array( array('key' =&gt; 'order_in_archive')) ) ); </code> I tried orderby also by meta_value_numeric and meta_value, but in any case the results are being ordered by the publication date (as regular posts do). Anyone know how can this be done? Thanks
You can define the meta key for orderby parameter using the old method (I tested on WP 3.1.1)... <code> query_posts( array( 'post_type' =&gt; 'services', 'order' =&gt; 'ASC', 'meta_key' =&gt; 'some_key', 'orderby' =&gt; 'meta_value', //or 'meta_value_num' 'meta_query' =&gt; array( array('key' =&gt; 'order_in_archive', 'value' =&gt; 'some_value' ) ) ) ); </code>
Custom query with orderby meta_value of custom field
wordpress
Im trying to find a way to set the members search by name and also by username. Now it seems to search only by name. Thanks in advance.
Somebody on a different site had this to say: I don’t recommend to change the core files of buddypress. The best way to do it is to write a custom code (I don’t know how to guide you). So if you don’t mind changing the core files, here is a quick way. Open /buddypress/bp-core/bp-core-classes.php and change the $sql['where_searchterms'] = “AND pd.value LIKE ‘%%$search_terms%%’”; to $sql['where_searchterms'] = “AND (pd.value LIKE ‘%%$search_terms%%’ OR u.user_login LIKE’%%$search_terms%%’)” ; If someone can guide us how to do it in bp-custom.php, it would be great.
BuddyPress - Search members by name and also by username
wordpress
How to clear floats in WYSIWYG editor? Not everyone know how to add <code> &lt;div style="clear:both&gt;" </code> in HTML mode. Is there any way to add extra button to WYSIWYG or plugin. TineMCE doesn't have that option.
Write a simple shortcode to add a <code> &lt;div style="clear: both;"&gt;&amp;nbsp;&lt;/div&gt; </code> Detailed Explanation: http://brettterpstra.com/adding-a-tinymce-button/
WYSIWYG clear:both
wordpress
Is there any way that i can hard code the custom menu items when first theme installed? I am creating a theme which will automatically make some common pages when installed. So I need to know if I can also add them to Wordpress custom menu so client don't need to add them manually? In other words: how to insert/create custom menu item programmatically? Let me know if anything unclear. Guide to the appropriate codex page is welcome. Thanks! update: tried code from here stackexchange-url ("Targeting specific menu with wp_nav_menu_items") Menu registration: <code> function register_my_menus() { register_nav_menus( array('main-menu' =&gt; __( 'Main Menu' ) ) ); } add_action( 'init', 'register_my_menus' ); </code> Template use: <code> &lt;?php wp_nav_menu( array( 'theme_location' =&gt; 'main-menu' ) ); ?&gt; </code> Code for adding new items: <code> function new_nav_menu_items($items) { if( $args-&gt;theme_location == 'main-menu' ){ $homelink = '&lt;li class="home"&gt;&lt;a href="' . home_url( '/' ) . '"&gt;' . __('Home') . '&lt;/a&gt;&lt;/li&gt;'; $items = $homelink . $items; return $items; } } add_filter( 'wp_nav_menu_items', 'new_nav_menu_items', 10, 2 ); </code> when adding the code for adding new items in nav menu in <code> functions.php </code> file nothings happens in menu page in admin panel but the current menu items are gone in site!
The Problem with your code is that its not actually adding the links to the menu and only to the menu's output, hence the use of a filter (add_filter) so you are just filtering the output of the menu in fact even if you don't have a menu your link will be shown with the code you are using. But to create a link and add it to a menu you can use this code: <code> $run_once = get_option('menu_check'); if (!$run_once){ //give your menu a name $name = 'theme default menu'; //create the menu $menu_id = wp_create_nav_menu($name); //then get the menu object by its name $menu = get_term_by( 'name', $name, 'nav_menu' ); //then add the actuall link/ menu item and you do this for each item you want to add wp_update_nav_menu_item($menu-&gt;term_id, 0, array( 'menu-item-title' =&gt; __('Home'), 'menu-item-classes' =&gt; 'home', 'menu-item-url' =&gt; home_url( '/' ), 'menu-item-status' =&gt; 'publish')); //then you set the wanted theme location $locations = get_theme_mod('nav_menu_locations'); $locations['main-menu'] = $menu-&gt;term_id; set_theme_mod( 'nav_menu_locations', $locations ); // then update the menu_check option to make sure this code only runs once update_option('menu_check', true); } </code> I commented all over to make it simpler. To create a child page/sub page/second level menu (how ever you may call it), you just need to set the <code> menu-item-parent-id </code> in the new item for example: <code> //create the top level menu item (home) $top_menu = wp_update_nav_menu_item($menu-&gt;term_id, 0, array( 'menu-item-title' =&gt; __('Home'), 'menu-item-classes' =&gt; 'home', 'menu-item-url' =&gt; home_url( '/' ), 'menu-item-status' =&gt; 'publish' 'menu-item-parent-id' =&gt; 0, )); //Sub menu item (first child) $first_child = wp_update_nav_menu_item($menu-&gt;term_id, 0, array( 'menu-item-title' =&gt; __('First_Child'), 'menu-item-classes' =&gt; 'home', 'menu-item-url' =&gt; home_url( '/' ), 'menu-item-status' =&gt; 'publish' 'menu-item-parent-id' =&gt; $top_menu, )); //Sub Sub menu item (first child) $Second_child = wp_update_nav_menu_item($menu-&gt;term_id, 0, array( 'menu-item-title' =&gt; __('Second_Child'), 'menu-item-classes' =&gt; 'home', 'menu-item-url' =&gt; home_url( '/' ), 'menu-item-status' =&gt; 'publish' 'menu-item-parent-id' =&gt; $first_child, )); </code> also you can set the position by code with <code> menu-item-position </code> and i think its done like this: First item - 'menu-item-position' => 1 First item first child - 'menu-item-position' => 1 First item second child - 'menu-item-position' => 1 First item second child first child - 'menu-item-position' => 1 Second item - 'menu-item-position' => 2 3rd item - 'menu-item-position' => 3 4th item - 'menu-item-position' => 4
How to Hard Code Custom menu items
wordpress
I always want new posts to have a category, but sometimes I forget. How can I make Wordpress warn me when I'm about something 'uncategorized'?
Category Reminder plugin
Warn me about 'uncategorized' posts
wordpress
I recently discovered Scribu's Posts 2 Posts plugin, which seems to be exactly what I was looking for in order to connect pages and posts for a big editorial website. But I cannot get it to work, which is frustrating because the principle seems really easy. I followed the wiki basic usage example , in my functions.php I have : <code> function my_connection_types() { if ( !function_exists( 'p2p_register_connection_type' ) ) return; p2p_register_connection_type( array( 'from' =&gt; 'post', 'to' =&gt; 'page' ) ); } add_action( 'init', 'my_connection_types', 100 ); </code> And in page.php : <code> $connected = new WP_Query( array( 'post_type' =&gt; 'post', 'connected_from' =&gt; get_queried_object_id() ) ); echo '&lt;p&gt;Related posts:&lt;/p&gt;'; echo '&lt;ul&gt;'; while( $connected-&gt;have_posts() ) : $connected-&gt;the_post(); echo '&lt;li&gt;'; the_title(); echo '&lt;/li&gt;'; endwhile; echo '&lt;/ul&gt;'; wp_reset_postdata(); </code> I have a post called "Tacos", which I connected to the page called "About". When I go to the "About" page, I see "Related posts:", but nothing else after that (ie. where is my Taco ?) a <code> print_r( $connected ) </code> gives the following : <code> WP_Query Object ( [query_vars] =&gt; Array ( [post_type] =&gt; post [connected_from] =&gt; 2 [error] =&gt; [m] =&gt; 0 [p] =&gt; 0 [post_parent] =&gt; [subpost] =&gt; [subpost_id] =&gt; [attachment] =&gt; [attachment_id] =&gt; 0 [name] =&gt; [static] =&gt; [pagename] =&gt; [page_id] =&gt; 0 [second] =&gt; [minute] =&gt; [hour] =&gt; [day] =&gt; 0 [monthnum] =&gt; 0 [year] =&gt; 0 [w] =&gt; 0 [category_name] =&gt; [tag] =&gt; [cat] =&gt; [tag_id] =&gt; [author_name] =&gt; [feed] =&gt; [tb] =&gt; [paged] =&gt; 0 [comments_popup] =&gt; [meta_key] =&gt; [meta_value] =&gt; [preview] =&gt; [s] =&gt; [sentence] =&gt; [fields] =&gt; [category__in] =&gt; Array ( ) [category__not_in] =&gt; Array ( ) [category__and] =&gt; Array ( ) [post__in] =&gt; Array ( ) [post__not_in] =&gt; Array ( ) [tag__in] =&gt; Array ( ) [tag__not_in] =&gt; Array ( ) [tag__and] =&gt; Array ( ) [tag_slug__in] =&gt; Array ( ) [tag_slug__and] =&gt; Array ( ) [meta_query] =&gt; Array ( ) [ignore_sticky_posts] =&gt; [suppress_filters] =&gt; [cache_results] =&gt; 1 [update_post_term_cache] =&gt; 1 [update_post_meta_cache] =&gt; 1 [posts_per_page] =&gt; 10 [nopaging] =&gt; [comments_per_page] =&gt; 50 [no_found_rows] =&gt; [order] =&gt; DESC [orderby] =&gt; il_posts.post_date DESC ) [tax_query] =&gt; WP_Tax_Query Object ( [queries] =&gt; Array ( ) [relation] =&gt; AND ) [post_count] =&gt; 0 [current_post] =&gt; -1 [in_the_loop] =&gt; [comment_count] =&gt; 0 [current_comment] =&gt; -1 [found_posts] =&gt; 0 [max_num_pages] =&gt; 0 [max_num_comment_pages] =&gt; 0 [is_single] =&gt; [is_preview] =&gt; [is_page] =&gt; [is_archive] =&gt; [is_date] =&gt; [is_year] =&gt; [is_month] =&gt; [is_day] =&gt; [is_time] =&gt; [is_author] =&gt; [is_category] =&gt; [is_tag] =&gt; [is_tax] =&gt; [is_search] =&gt; [is_feed] =&gt; [is_comment_feed] =&gt; [is_trackback] =&gt; [is_home] =&gt; 1 [is_404] =&gt; [is_comments_popup] =&gt; [is_paged] =&gt; [is_admin] =&gt; [is_attachment] =&gt; [is_singular] =&gt; [is_robots] =&gt; [is_posts_page] =&gt; [is_post_type_archive] =&gt; [query_vars_hash] =&gt; 90a220b2f180d3ea6ccbd9473e26ec4c [query_vars_changed] =&gt; [query] =&gt; Array ( [post_type] =&gt; post [connected_from] =&gt; 2 ) [request] =&gt; SELECT SQL_CALC_FOUND_ROWS il_posts.*, il_p2p.* FROM il_posts INNER JOIN il_p2p WHERE 1=1 AND il_posts.post_type = 'post' AND (il_posts.post_status = 'publish' OR il_posts.post_status = 'private') AND il_posts.ID = il_p2p.p2p_to AND il_p2p.p2p_from IN (2) ORDER BY il_posts.post_date DESC LIMIT 0, 10 [posts] =&gt; Array ( ) ) </code> What am I missing? ps. Wordpress 3.1.1, Posts 2 Posts 0.7 and PHP 5.3.3
try <code> 'connected' =&gt; get_queried_object_id() </code> instead of <code> 'connected_from' =&gt; get_queried_object_id() </code>
[Plugin: Posts 2 Posts] How does it work?
wordpress
I have a site with many users and many of them have the same last name. I want to get the emails of all the users with the same last name (IE: Smith) that has a post related to a particular taxonomy term (IE: Baseball). So far I have this code that works great in getting all the users with the same last name ( thanks to stackexchange-url ("Mike Schinkel") ). I suck at using the JOIN function but I am learning and I really need this sooner than later, so I need help. <code> $sql =&lt;&lt;&lt;SQL SELECT {$wpdb-&gt;users}.user_email, {$wpdb-&gt;usermeta}.meta_value FROM {$wpdb-&gt;users} LEFT JOIN {$wpdb-&gt;usermeta} ON {$wpdb-&gt;users}.ID = {$wpdb-&gt;usermeta}.user_id WHERE 1=1 AND {$wpdb-&gt;users}.user_status = '0' AND {$wpdb-&gt;usermeta}.meta_key = 'last_name' AND {$wpdb-&gt;usermeta}.meta_value = 'Smith' SQL; $usersemails = $wpdb-&gt;get_results($sql); header('Content-type:text/plain'); print_r($usersemails); </code> Your time is greatly appreciated and I will pay it forward. Thanks.
Hi @Holidaymaine: Here's the query you are looking for: <code> &lt;?php include( '../wp-load.php' ); $sql =&lt;&lt;&lt;SQL SELECT DISTINCT u.user_email AS user_email, um.meta_value AS user_lastname FROM {$wpdb-&gt;users} AS u LEFT JOIN {$wpdb-&gt;usermeta} AS um ON u.ID = um.user_id LEFT JOIN {$wpdb-&gt;posts} AS p ON u.ID = p.post_author LEFT JOIN {$wpdb-&gt;term_relationships} AS tr ON p.ID = tr.object_id LEFT JOIN {$wpdb-&gt;term_taxonomy} AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id LEFT JOIN {$wpdb-&gt;terms} AS t ON tt.term_id = t.term_id WHERE 1=1 AND u.user_status = '0' AND um.meta_key = 'last_name' AND um.meta_value = '%s' AND t.slug = '%s' SQL; $sql = $wpdb-&gt;prepare( $sql, 'Smith', 'baseball' ); $usersemails = $wpdb-&gt;get_results( $sql ); header( 'Content-type:text/plain' ); print_r( $usersemails ); </code>
Querying Email Addresses for a List of Users with Same Last Name?
wordpress
I'm trying to show the archive list like that <code> &lt;ul&gt; &lt;li&gt;Year&lt;/li&gt; &lt;li&gt;Month&lt;/li&gt; &lt;li&gt;Month&lt;/li&gt; &lt;li&gt;Month&lt;/li&gt; &lt;li&gt;Year&lt;/li&gt; &lt;li&gt;Month&lt;/li&gt; &lt;/ul&gt; </code> and so on, with the relative link only on the month. I tried different solutions as the CG Archive plugin ( http://wordpress.pastebin.ca/209160 ) and that's the only kind of plugin I can use since I need to place the php output wherever I want and the other plugins/widgets I found doesn't let me do that. The problem is that it doesn't show anything at all! Do you know any alternative solutions to accomplis that? Really thanks in advance and sorry for my poor english.
Place this in your functions.php file or create a simple plugin... <code> /** * Display archive links based on year/month and format. * * The date archives will logically display dates with links to the archive post * page. * * The 'limit' argument will only display a limited amount of links, specified * by the 'limit' integer value. By default, there is no limit. The * 'show_post_count' argument will show how many posts are within the archive. * By default, the 'show_post_count' argument is set to false. * * For the 'format', 'before', and 'after' arguments, see {@link * get_archives_link()}. The values of these arguments have to do with that * function. * * @param string|array $args Optional. Override defaults. */ function wp_custom_archive($args = '') { global $wpdb, $wp_locale; $defaults = array( 'limit' =&gt; '', 'format' =&gt; 'html', 'before' =&gt; '', 'after' =&gt; '', 'show_post_count' =&gt; false, 'echo' =&gt; 1 ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); if ( '' != $limit ) { $limit = absint($limit); $limit = ' LIMIT '.$limit; } // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride $archive_date_format_over_ride = 0; // options for daily archive (only if you over-ride the general date format) $archive_day_date_format = 'Y/m/d'; // options for weekly archive (only if you over-ride the general date format) $archive_week_start_date_format = 'Y/m/d'; $archive_week_end_date_format = 'Y/m/d'; if ( !$archive_date_format_over_ride ) { $archive_day_date_format = get_option('date_format'); $archive_week_start_date_format = get_option('date_format'); $archive_week_end_date_format = get_option('date_format'); } //filters $where = apply_filters('customarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r ); $join = apply_filters('customarchives_join', "", $r); $output = '&lt;ul&gt;'; $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb-&gt;posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit"; $key = md5($query); $cache = wp_cache_get( 'wp_custom_archive' , 'general'); if ( !isset( $cache[ $key ] ) ) { $arcresults = $wpdb-&gt;get_results($query); $cache[ $key ] = $arcresults; wp_cache_set( 'wp_custom_archive', $cache, 'general' ); } else { $arcresults = $cache[ $key ]; } if ( $arcresults ) { $afterafter = $after; foreach ( (array) $arcresults as $arcresult ) { $url = get_month_link( $arcresult-&gt;year, $arcresult-&gt;month ); $year_url = get_year_link($arcresult-&gt;year); /* translators: 1: month name, 2: 4-digit year */ $text = sprintf(__('%s'), $wp_locale-&gt;get_month($arcresult-&gt;month)); $year_text = sprintf('%d', $arcresult-&gt;year); if ( $show_post_count ) $after = '&amp;nbsp;('.$arcresult-&gt;posts.')' . $afterafter; $year_output = get_archives_link($year_url, $year_text, $format, $before, $after); $output .= ( $arcresult-&gt;year != $temp_year ) ? $year_output : ''; $output .= get_archives_link($url, $text, $format, $before, $after); $temp_year = $arcresult-&gt;year; } } $output .= '&lt;/ul&gt;'; if ( $echo ) echo $output; else return $output; } </code> "just the year's text" version: <code> /** * Display archive links based on year/month and format. * * The date archives will logically display dates with links to the archive post * page. * * The 'limit' argument will only display a limited amount of links, specified * by the 'limit' integer value. By default, there is no limit. The * 'show_post_count' argument will show how many posts are within the archive. * By default, the 'show_post_count' argument is set to false. * * For the 'format', 'before', and 'after' arguments, see {@link * get_archives_link()}. The values of these arguments have to do with that * function. * * @param string|array $args Optional. Override defaults. */ function wp_custom_archive($args = '') { global $wpdb, $wp_locale; $defaults = array( 'limit' =&gt; '', 'format' =&gt; 'html', 'before' =&gt; '', 'after' =&gt; '', 'show_post_count' =&gt; false, 'echo' =&gt; 1 ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); if ( '' != $limit ) { $limit = absint($limit); $limit = ' LIMIT '.$limit; } // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride $archive_date_format_over_ride = 0; // options for daily archive (only if you over-ride the general date format) $archive_day_date_format = 'Y/m/d'; // options for weekly archive (only if you over-ride the general date format) $archive_week_start_date_format = 'Y/m/d'; $archive_week_end_date_format = 'Y/m/d'; if ( !$archive_date_format_over_ride ) { $archive_day_date_format = get_option('date_format'); $archive_week_start_date_format = get_option('date_format'); $archive_week_end_date_format = get_option('date_format'); } //filters $where = apply_filters('customarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r ); $join = apply_filters('customarchives_join', "", $r); $output = '&lt;ul&gt;'; $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb-&gt;posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit"; $key = md5($query); $cache = wp_cache_get( 'wp_custom_archive' , 'general'); if ( !isset( $cache[ $key ] ) ) { $arcresults = $wpdb-&gt;get_results($query); $cache[ $key ] = $arcresults; wp_cache_set( 'wp_custom_archive', $cache, 'general' ); } else { $arcresults = $cache[ $key ]; } if ( $arcresults ) { $afterafter = $after; foreach ( (array) $arcresults as $arcresult ) { $url = get_month_link( $arcresult-&gt;year, $arcresult-&gt;month ); /* translators: 1: month name, 2: 4-digit year */ $text = sprintf(__('%s'), $wp_locale-&gt;get_month($arcresult-&gt;month)); $year_text = sprintf('&lt;li&gt;%d&lt;/li&gt;', $arcresult-&gt;year); if ( $show_post_count ) $after = '&amp;nbsp;('.$arcresult-&gt;posts.')' . $afterafter; $output .= ( $arcresult-&gt;year != $temp_year ) ? $year_text : ''; $output .= get_archives_link($url, $text, $format, $before, $after); $temp_year = $arcresult-&gt;year; } } $output .= '&lt;/ul&gt;'; if ( $echo ) echo $output; else return $output; } </code> Now you can use <code> wp_custom_archive </code> function wherever in your theme: <code> &lt;?php wp_custom_archive(); ?&gt; </code>
Archive list with only years and months
wordpress
Best way to programatically remove attachments that are missing images? I ask because after using a caching plugin, I have images that have been input in the database as attachments that don't actually exist. These usually take the form of xxxx.1jpg, where xxxx.jpg is a valid. Sometimes this number is a 2 or a 21. I guess it would be better to just remove "duplicate" bad images. I think it might be good to have other types of missing images remain, so they could be corrected. Ideas?
Try this: <code> $imgs = get_posts("post_type=attachment&amp;numberposts=-1"); foreach($imgs as $img){ $file = get_attached_file($img-&gt;ID); if(!file_exists($file)){ wp_delete_post( $img-&gt;ID, false ); } } </code>
remove missing image attachments
wordpress
I enabled the compression option on WP Super Cache (off by default!) on my blog . After that, Website Optimization started identifying my pages as being compressed (before, it didn't). All seemed well with the world, but then I double checked with Page Speed Firefox plugin , and and sniffed the traffic with Wireshark, and according to both these measures my page is not compressed. Are my pages being compressed or not? Could it be some proxy my ISP is running, that does not support compression? (that would explain some of the horrible internet experience I'm getting). Here are the HTTP headers I'm seeing with wireshark.
I'm getting a <code> Content-Encoding:gzip </code> header when I visit your site... <code> Cache-Control:max-age=300, must-revalidate Connection:Keep-Alive Content-Encoding:gzip Content-Type:text/html; charset=UTF-8 Date:Sat, 23 Apr 2011 15:27:48 GMT Keep-Alive:timeout=15, max=100 Server:Apache Transfer-Encoding:Identity Vary:Accept-Encoding,Cookie </code> Also, you have a jQuery reference error in the wp-minify plugin :)
Does WP Super Cache really compress my pages?
wordpress
I want to be able to take a url and see if the domain is one of the ones Wordpress supports to add embeds via oEmbed. Is there a built in function that does this in WordPress or would I need to create my own? Example: if I have a url from a video site I want to be able to examine the url and be able to tell if the domain is supported by WordPress for use to embed as a video.
<code> wp-includes/class-oembed.php </code> has a public variable <code> $providers </code> . So you can build a small function to get all of them: <code> function list_oembed_providers( $print = TRUE ) { require_once( ABSPATH . WPINC . '/class-oembed.php' ); $oembed = _wp_oembed_get_object(); $print and print '&lt;pre&gt;' . htmlspecialchars( var_export( $oembed-&gt;providers, TRUE ) ) . '&lt;/pre&gt;'; return $oembed-&gt;providers; } </code> If you call this function … <code> list_oembed_providers(); </code> … you get in WordPress 3.1.1: <code> array ( '#http://(www\\.)?youtube.com/watch.*#i' =&gt; array ( 0 =&gt; 'http://www.youtube.com/oembed', 1 =&gt; true, ), 'http://youtu.be/*' =&gt; array ( 0 =&gt; 'http://www.youtube.com/oembed', 1 =&gt; false, ), 'http://blip.tv/file/*' =&gt; array ( 0 =&gt; 'http://blip.tv/oembed/', 1 =&gt; false, ), '#http://(www\\.)?vimeo\\.com/.*#i' =&gt; array ( 0 =&gt; 'http://www.vimeo.com/api/oembed.{format}', 1 =&gt; true, ), '#http://(www\\.)?dailymotion\\.com/.*#i' =&gt; array ( 0 =&gt; 'http://www.dailymotion.com/api/oembed', 1 =&gt; true, ), '#http://(www\\.)?flickr\\.com/.*#i' =&gt; array ( 0 =&gt; 'http://www.flickr.com/services/oembed/', 1 =&gt; true, ), '#http://(.+)?smugmug\\.com/.*#i' =&gt; array ( 0 =&gt; 'http://api.smugmug.com/services/oembed/', 1 =&gt; true, ), '#http://(www\\.)?hulu\\.com/watch/.*#i' =&gt; array ( 0 =&gt; 'http://www.hulu.com/api/oembed.{format}', 1 =&gt; true, ), '#http://(www\\.)?viddler\\.com/.*#i' =&gt; array ( 0 =&gt; 'http://lab.viddler.com/services/oembed/', 1 =&gt; true, ), 'http://qik.com/*' =&gt; array ( 0 =&gt; 'http://qik.com/api/oembed.{format}', 1 =&gt; false, ), 'http://revision3.com/*' =&gt; array ( 0 =&gt; 'http://revision3.com/api/oembed/', 1 =&gt; false, ), 'http://i*.photobucket.com/albums/*' =&gt; array ( 0 =&gt; 'http://photobucket.com/oembed', 1 =&gt; false, ), 'http://gi*.photobucket.com/groups/*' =&gt; array ( 0 =&gt; 'http://photobucket.com/oembed', 1 =&gt; false, ), '#http://(www\\.)?scribd\\.com/.*#i' =&gt; array ( 0 =&gt; 'http://www.scribd.com/services/oembed', 1 =&gt; true, ), 'http://wordpress.tv/*' =&gt; array ( 0 =&gt; 'http://wordpress.tv/oembed/', 1 =&gt; false, ), '#http://(answers|surveys)\\.polldaddy.com/.*#i' =&gt; array ( 0 =&gt; 'http://polldaddy.com/oembed/', 1 =&gt; true, ), '#http://(www\\.)?funnyordie\\.com/videos/.*#i' =&gt; array ( 0 =&gt; 'http://www.funnyordie.com/oembed', 1 =&gt; true, ), ) </code>
Is there a built in function to see if a URLis oEmbed Compatible?
wordpress
I want to remove the admin bar from the top of the page and actually place it into a custom location within my theme. Question: How would I call wp_admin_bar() inside a custom div. I would also need to remove the built in css, so that I can apply my own. *I already have a filter to do this part. Reasons: My theme is being built to be ipad/iphone friendly. I want the admin bar to be 'fixed' to the top of the screen. The problem is that mobile safari does not accept position:fixed, which requires a js workaround, which I have already solved. My theme already has a fixed header which is ipad ready. If I can call the wp_admin_bar() and place that within this 'special' div, then the problem is solved. *thanks to other people helping me on this forum, I have managed to place the built in wp_menu() into the admin bar, which is really cool. With that functionality added to the admin bar, I now have a really awesome nav bar by combining its built in functionality with custom menus.
You can try to output the admin bar at a different location, but the included Javascript always moves the bar to the <code> body </code> element - probably to make it work when a theme has not closed all HTML elements at the end of the page. So if you want to move it somewhere else, you must do this after the standard script moved it to the body. I did this by loading the script in the footer, after the admin bar: <code> function wpse15444_wp_print_scripts() { if ( ! is_admin() ) { wp_enqueue_script( 'wpse-15444', plugins_url( 'wpse-15444.js', __FILE__ ), array( 'jquery' ), false, true ); } } // wpse-15444.js jQuery( window ).load( function() { jQuery( '#wpadminbar' ).appendTo( jQuery( '#wpse15444-admin-bar-container' ) ); } ); </code> Because the bar normally has <code> position: fixed </code> you won't see it move, so make it <code> position: absolute </code> in your own stylesheet. By adding the <code> wpse1544-admin-bar-container </code> in the <code> #header </code> of the Twenty Ten theme, I got the following result:
Is there an easy way to move the wp_admin_bar to my own location?
wordpress
I'd like to show the post type of a post, you can do that with get_post_type() , but in my case the names are not pretty (for ex : p_project_plans). So instead I thought I'd show the asociated "menu_name" (as declared with register_post_type), which looks much nicer (for ex : Project plans). Is there a way to do that ?
Hi @mike23: This code shows you how to get both singular and plural names (assuming you specified them as such in your <code> register_post_type() </code> ) . Note that the code example is presented as a standalone file you can save as <code> test.php </code> file in the root of your website and load in your browser with <code> http://yoursite.com/test.php </code> (assuming you replace <code> yoursite.com </code> with your site's domain!): <code> &lt;?php /* Filename: test.php */ include( '../wp-load.php' ); header( 'Content-type:text/plain' ); $post_type_object = get_post_type_object('p_project_plans'); echo "Singular: {$post_type_object-&gt;labels-&gt;singular_name}\n"; echo "Plural: {$post_type_object-&gt;labels-&gt;name}\n"; </code>
How to get custom post type menu_name?
wordpress
Is it possible to create the following: A new page dynamically daily, containing the last three posts Archive this page, so that tomorrow's page is a new page, with the three newest posts Basically I'd like to use WordPress for our news releases, we publish three each day. The day's page should contain all three stories, and then be archived so the next day's page can be created. If you have any ideas how to setup something like this I'd appreciate it.
You can create date.php (you can copy the content for this from archive.php or index.php ) in your theme folder which will handle all the "day" pages... <code> &lt;?php get_header(); ?&gt; &lt;div id="container"&gt; &lt;div id="content" role="main"&gt; &lt;?php $day = get_query_var('day'); $monthnum = get_query_var('monthnum'); $year = get_query_var('year'); if ( is_day() ) : ?&gt; &lt;a href="&lt;?php echo get_day_link($year, $monthnum, $day-1); ?&gt;"&gt;Previous day's posts&lt;/a&gt; | &lt;a href="&lt;?php echo get_day_link(); ?&gt;"&gt;This day's posts&lt;/a&gt; &lt;?php if ( mktime(0, 0, 0, $monthnum, $day, $year) &lt; mktime(0, 0, 0) ) : ?&gt; | &lt;a href="&lt;?php echo get_day_link($year, $monthnum, $day+1); ?&gt;"&gt;Next day's posts&lt;/a&gt; &lt;?php endif; ?&gt; &lt;?php elseif ( is_month() ) : ?&gt; &lt;a href="&lt;?php echo get_month_link($year, $monthnum-1); ?&gt;"&gt;Previous month's posts&lt;/a&gt; | &lt;a href="&lt;?php echo get_month_link(); ?&gt;"&gt;This month's posts&lt;/a&gt; &lt;?php if ( mktime(0, 0, 0, $monthnum) &lt; mktime(0, 0, 0) ) : ?&gt; | &lt;a href="&lt;?php echo get_month_link($year, $monthnum+1); ?&gt;"&gt;Next month's posts&lt;/a&gt; &lt;?php endif; ?&gt; &lt;?php elseif ( is_year() ) : ?&gt; &lt;a href="&lt;?php echo get_year_link($year-1); ?&gt;"&gt;Previous year's posts&lt;/a&gt; | &lt;a href="&lt;?php echo get_year_link(); ?&gt;"&gt;This year's posts&lt;/a&gt; &lt;?php if ( mktime(0, 0, 0, 0, 0, $year) &lt; mktime(0, 0, 0, 0, 0) ) : ?&gt; | &lt;a href="&lt;?php echo get_year_link($year+1); ?&gt;"&gt;Next year's posts&lt;/a&gt; &lt;?php endif; ?&gt; &lt;?php endif; ?&gt; &lt;?php /* Queue the first post, that way we know * what date we're dealing with (if that is the case). * * We reset this later so we can run the loop * properly with a call to rewind_posts(). */ if ( have_posts() ) : the_post(); ?&gt; &lt;h1 class="page-title"&gt; &lt;?php if ( is_day() ) : ?&gt; &lt;?php printf( __( 'Daily Archives: &lt;span&gt;%s&lt;/span&gt;' ), get_the_date() ); ?&gt; &lt;?php elseif ( is_month() ) : ?&gt; &lt;?php printf( __( 'Monthly Archives: &lt;span&gt;%s&lt;/span&gt;' ), get_the_date( 'F Y' ) ); ?&gt; &lt;?php elseif ( is_year() ) : ?&gt; &lt;?php printf( __( 'Yearly Archives: &lt;span&gt;%s&lt;/span&gt;' ), get_the_date( 'Y' ) ); ?&gt; &lt;?php else : ?&gt; &lt;?php _e( 'Blog Archives', 'twentyten' ); ?&gt; &lt;?php endif; ?&gt; &lt;/h1&gt; &lt;?php endif; ?&gt; &lt;?php /* Since we called the_post() above, we need to * rewind the loop back to the beginning that way * we can run the loop properly, in full. */ rewind_posts(); /* Run the loop for the archives page to output the posts. * If you want to overload this in a child theme then include a file * called loop-archive.php and that will be used instead. */ if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt; &lt;div id="post-&lt;?php the_ID(); ?&gt;" &lt;?php post_class(); ?&gt;&gt; &lt;h2 class="entry-title"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php printf( esc_attr__( 'Permalink to %s' ), the_title_attribute( 'echo=0' ) ); ?&gt;" rel="bookmark"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt; &lt;div class="entry-summary"&gt; &lt;?php the_excerpt(); ?&gt; &lt;/div&gt;&lt;!-- .entry-summary --&gt; &lt;div class="entry-utility"&gt; &lt;?php if ( count( get_the_category() ) ) : ?&gt; &lt;span class="cat-links"&gt; &lt;?php printf( __( '&lt;span class="%1$s"&gt;Posted in&lt;/span&gt; %2$s' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?&gt; &lt;/span&gt; &lt;span class="meta-sep"&gt;|&lt;/span&gt; &lt;?php endif; ?&gt; &lt;?php $tags_list = get_the_tag_list( '', ', ' ); if ( $tags_list ): ?&gt; &lt;span class="tag-links"&gt; &lt;?php printf( __( '&lt;span class="%1$s"&gt;Tagged&lt;/span&gt; %2$s' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?&gt; &lt;/span&gt; &lt;span class="meta-sep"&gt;|&lt;/span&gt; &lt;?php endif; ?&gt; &lt;span class="comments-link"&gt;&lt;?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment' ), __( '% Comments' ) ); ?&gt;&lt;/span&gt; &lt;?php edit_post_link( __( 'Edit' ), '&lt;span class="meta-sep"&gt;|&lt;/span&gt; &lt;span class="edit-link"&gt;', '&lt;/span&gt;' ); ?&gt; &lt;/div&gt;&lt;!-- .entry-utility --&gt; &lt;/div&gt;&lt;!-- #post-## --&gt; &lt;?php endwhile; ?&gt; &lt;?php else : ?&gt; &lt;h1 class="page-title"&gt;There are no posts for this date.&lt;/h1&gt; &lt;?php endif; ?&gt; &lt;/div&gt;&lt;!-- #content --&gt; &lt;/div&gt;&lt;!-- #container --&gt; &lt;?php get_sidebar(); ?&gt; </code> This example can also handle the "month" and the "year" pages. <code> http://wptest.dev/2011/04/23/ </code>
Automatically create a new page daily with last three posts
wordpress
Post save functions are conflicting with each other when adding them to the save_post action hook. 2 different custom post types with 2 different (one for each post type) custom meta boxes. I'm only including the code for 1 of the meta boxes. The other one is very similar and each one works fine separately but not together. The 'register_metabox_cb' call back function: <code> function c3m_video_meta() { add_meta_box('_c3m_video_embed', __('Enter Video Embed Code In the Box Below') , 'c3m_video_embed', 'video', 'normal', 'low'); } </code> Adding the meta box to the post edit screen: <code> function c3m_video_embed($post) { global $post; wp_nonce_field(__FILE__,'video_nonce'); $embed-code = get_post_meta($post-&gt;ID, '_embed-code', true); echo '&lt;input type="text" name="_embed-code" value=""' . $embed-code . '" class="widefat" /&gt;' ; } </code> The save function: <code> function c3m_save_video_meta( $post_id , $post ) { if ( !wp_verify_nonce( $_POST [ 'video_nonce' ], __FILE__ ) ) { return $post -&gt;ID; } if ( !current_user_can( 'edit_post' , $post -&gt;ID )) return $post -&gt;ID; $c3m_video_embed-code [ '_embed-code' ] = $_POST [ '_embed-code' ]; foreach ( $c3m_video_embed-code as $key =&gt; $value ) { if ( $post -&gt;post_type == 'revision' ) return ; $value = implode( ',' , ( array ) $value ); if (get_post_meta( $post -&gt;ID, $key , FALSE)) { update_post_meta( $post -&gt;ID, $key , $value ); } else { add_post_meta( $post -&gt;ID, $key , $value ); } if (! $value ) delete_post_meta( $post -&gt;ID, $key ); } } </code> The action hooks: <code> add_action( 'admin_menu' , 'c3m_video_meta' ); </code> <code> add_action( 'save_post' , 'c3m_save_video_meta' , 1, 2); </code> This is fine and dandy and works but when I add another meta box to a different post type and use a similar function (different function name, nonce name and key ) when the post is saved I get this error: Notice: Undefined index: _embed-code in /Applications/MAMP/htdocs/wordpress/wp-content/plugins/ieew-custom-functions/ieew-custom-functions.php on line 181 Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/wordpress/wp-content/plugins/ieew-custom-functions/ieew-custom-functions.php:181) in /Applications/MAMP/htdocs/wordpress/wp-includes/pluggable.php on line 897 The undefined _embed-code is when saving the post that does not contain the _embed-code variable. Since the error messages are reversed depending on wich post type I try to save it leads me to believe that both (2 different) save functions are being added to the save_post action. They are also being added when saving a normal post. If I'm only using 1 of the save functions there are no errors when saving a normal post. Rather than this question being a "Fix My Code" question I would rather the answer contain the how and why of adding custom meta boxes and using the various nonce methods. Sure I could use the More Fields plugin but I would rather learn the best way to accomplish customizing the post edit screen with custom content types. I have used this same code and method to add multiple meta boxes to a single custom post type and it has always worked fine.
After doing some more research I found that: Instead of hooking the <code> add_meta_box </code> function into <code> admin_menu </code> it should be hooked into <code> add_meta_boxes </code> Instead of the foreach loop use the <code> update_post_meta </code> function on the save function Instead of using the <code> wp_nonce_field </code> the data can be sanitized using <code> esc_attr </code> and <code> strip_tags </code> To pass the post id to the save meta box function you don't need to include the additional $post variable You have to add a conditional state for the post type on the save function You have to call <code> global $post </code> on the save function The new and much simpler code for adding both meta boxes: <code> add_action( 'add_meta_boxes', 'c3m_sponsor_meta' ); function c3m_sponsor_meta() { add_meta_box( 'c3m_sponsor_url', 'Sponsor URL Metabox', 'c3m_sponsor_url', 'sponsor', 'side', 'high' ); } function c3m_sponsor_url( $post ) { $sponsor_url = get_post_meta( $post-&gt;ID, '_sponsor_url', true); echo 'Please enter the sponsors website link below'; ?&gt; &lt;input type="text" name="sponsor_url" value="&lt;?php echo esc_attr( $sponsor_url ); ?&gt;" /&gt; &lt;?php } add_action( 'save_post', 'c3m_save_sponsor_meta' ); function c3m_save_sponsor_meta( $post_id ) { global $post; if( $post-&gt;post_type == "sponsor" ) { if (isset( $_POST ) ) { update_post_meta( $post_ID, '_sponsor_url', strip_tags( $_POST['sponsor_url'] ) ); } } } add_action( 'add_meta_boxes', 'c3m_video_meta' ); function c3m_video_meta() { add_meta_box( 'c3m_video_embed_code', 'Video Embed Code Meta Box', 'c3m_video_embed_code', 'video', 'normal', 'high' ); } function c3m_video_embed_code( $post ) { $embed_code = get_post_meta( $post-&gt;ID, '_embed_code', true); echo 'Please enter the video embed code below'; ?&gt; &lt;input type="text" name="embed_code" value="&lt;?php echo esc_attr( $embed_code ); ?&gt;" /&gt; &lt;?php } add_action( 'save_post', 'c3m_save_video_meta' ); function c3m_save_video_meta( $post_id ) { global $post; if( $post-&gt;post_type == "video" ) { if (isset( $_POST ) ) { update_post_meta( $post_ID, '_embed_code', strip_tags( $_POST['embed_code'] ) ); } } } </code>
Conflicting save_post functions when passing the post id and saving custom meta boxes for different post types
wordpress