question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I want to get all featured items using query post. featured is meta_key using custom field plugin. I tried bellow,but it failed <code> $featured_item = new WP_Query('posts_per_page=-1&amp;cat=3&amp;meta_key=&gt;Featured List&amp;meta_value=&gt;Yes'); </code> my wp version is 3.1.3 EDIT: <code> $arg2 = array( 'posts_per_page'=&gt;'5', 'cat'=&gt;'3', 'orderby'=&gt;'rand', 'meta_query'=&gt; array( 'key'=&gt;'Featured List', 'value'=&gt;'Yes', 'compare'=&gt;'LIKE' ) ); $featured_random_item = new WP_Query($arg2); </code> This query also failed. How can i do this Thanks in advance !
Your <code> meta_query </code> needs to be a nested array, like so; <code> $args = array( 'posts_per_page' =&gt; '5', 'cat' =&gt; '3', 'orderby' =&gt; 'rand', 'meta_query' =&gt; array( array( 'key' =&gt; 'Featured List', 'value' =&gt; 'Yes' ) ) ); </code> And I get the feeling you don't actually need a <code> LIKE </code> match - this'll perform a loose comparison, and isn't as efficient as an exact match.
how can i use custom field in query post
wordpress
I'm using a script that is based on jQuery, so I'm not enqueue-ing jQuery directly, but via passing it in the array of dependent scripts: <code> wp_enqueue_script("jquery-plugin-name",'http://hostname.il/blogname/wp-content/themes/twentyten/js/jquery-plugin-name.js', array('jquery'), '1'); </code> This is loading jQuery v1.4.4, and it weighs 76kb, which seems very heavy, although the file looks compressed. I have 2 questions: Is there I way in which I can make it load the latest version of jQuery? How can I make sure that the loaded file if minified?
That's the size of the minified jQuery nowadays :) You can load the latest from Google: <code> wp_deregister_script('jquery'); wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"), false, '1.8.2'); </code> Please keep in mind that this can cause issues moving forward, as you are forcing WordPress to load a certain version of WordPress instead of the version bundled with it. There are plugins out there that may be better suited for your needs, like WP JQuery Plus , which make sure to load the same version number as WordPress does, but with the benefit of loading it from Google.
How to control what jQuery version to include, with wp_enqueue_script
wordpress
I'm trying to remove "Pending Review" (Status) and "Password protected" (Visibility) options from Publish metabox. Any ideas how can I do it?
i don't see any filters you could latch on it in wp-admin/includes/metaboxes.php. but, you could remove the box and replace it with your own version... for example: this tut removes the categories metabox and replaces it w/ a new version http://www.ilovecolors.com.ar/avoid-hierarchical-taxonomies-to-loose-hierarchy/
How to modify Publish metabox?
wordpress
I'm in a situation where I need to face a situation when there is a WordPress site with landing page and several internal page designs. I know for such situations there is recommended to create more template files for pages with some comments at the beginning like <code> Template Name: Some Style </code> I've done this already, but the problem is that many of the internal pages contains boxes, areas that are independent from the main template. Let me show you: So let's suppose we have the main article area and two other boxes. All the three areas have different design. First with some nice background, the bottom left article in a box with background and gradient stuff, the bottom right article is a box also with background and gradient with title and content inside. I was asked to solve the situation in a manner when the site admin (who don't know any piece of coding) wants to add another similar article with same structure, to be able to do this. Should I create one single template for this or three? What do you suggest? The idea when new article/page is added, to contain only the usual WordPress generated codes like h2, p, i, etc. So no manually added div's, classes and similar stuff. Did you faced similar situation? I searched the internet and did not found anything yet. I was thinking something about shortcodes but that will involde tu use codes like <code> [some]content...[/some] </code> or even to have children pages, but nothing is clear for me yet. What do you suggest for me? Thanks in advance! :)
Yes you'd need to add shortcodes to the functions.php file in your themes folder in order to use code like [box]Contained content blah blah[/box] in the WYSIWYG editor learn more about shortcodes and how to use them here http://codex.wordpress.org/Shortcode_API
custom page templating in WordPress
wordpress
I was wondering if anyone can help me out. I am looking to remove the_content part of the loop on my author pages only . So basically, I just want a list of the author posts with only the title and meta instead of the full post. When I went to the author.php file, I found this, which I believe is the code that is generating the posts on the Author Pages. <code> /* Run the loop for the author archive page to output the authors posts * If you want to overload this in a child theme then include a file * called loop-author.php and that will be used instead. */ get_template_part( 'loop', 'author' ); </code> I'm pretty new at this, so please bare with me. My question is, how I do I remove the content from the loop for only the Author pages. I wouldn't think that I should remove the function that generates the content from the loop.php file because that would remove it from all posts on my site. The comments above say, If I want to overload this in a child theme, the include a file called loop-author.php. Can I simply copy all the code from the loop.php file into a new loop-author file, remove the function that generates content from there? Would i have to change any of the parameters in the get_template_part() function? Again, really new at doing this, so any advice would be greatly appreciated. Thanks a lot.
If your Parent Theme, has a template file <code> loop-author.php </code> , copy it to your Child Theme; otherwise, copy your Parent Theme's <code> loop.php </code> template file to your Child Theme, and rename it as <code> loop-author.php </code> . Now, modify your Child Theme's <code> loop-author.php </code> template file, in whatever way you wish. You don't need to make any other changes , either to the Parent Theme or to your Child Theme. The Parent Theme already accounts for a Child Theme's use of <code> loop-author.php </code> , based on its call to <code> get_template_part( 'loop', 'author' ); </code> . The way such a call works is this: WordPress will look for files in the following order, until it finds one that exists: Child Theme <code> loop-author.php </code> Parent Theme <code> loop-author.php </code> Child Theme <code> loop.php </code> Parent Theme <code> loop.php </code> Thus, you see the power and flexibility of <code> get_template_part() </code> !
Editing the loop for Author pages
wordpress
could you figure out why I'm unable to get shortcode filters applied in ajax inclusion of posts? Let me explain better: I've managed to include a post from within another post, through admin-ajax.php , as recommended in the famous 5 tips . Obviously I don't want to display the shortcode tags, nor I'd like to strip them, so I'm echoing <code> do_shortcode($post-&gt;post_content) </code> At this point, the post gallery gets rendered but unfiltered , even though I'm running the "Cleaner Gallery" plugin, which starts with <code> add_filter( 'post_gallery', 'cleaner_gallery', 10, 2 ); </code> and succesfully works in normal (non-ajax) posts. I've been trying to debug this issue by replacing <code> $output = apply_filters('post_gallery', '', $attr); if ( $output != '' ) return $output; </code> with <code> $output = apply_filters('post_gallery', '', $attr); echo 'FILTERED OUTPUT = '.$output.' !'; if ( $output != '' ) return $output; </code> inside the function gallery_shortcode($attr) located in wp-includes/media.php . It seems that it runs twice, but in ajax inclusions the output is empty at first time and then it's not filtered. Well, in all effect it happens that also the "2nd round" echoed output I mentioned remains empty when setting again add_filter before do_shortcode ; otherwise it's shown (but, as I said, unfiltered). I've also tried to track it with <code> echo has_filter('post_gallery'); echo current_filter(); </code> and I've discovered that has returns always 1 , while current first returns ' post-gallery ' as expected, and then it gets overwritten by the ' *wp_ajax_nopriv_etc* ' hook, which is required to handle requests with admin-ajax.php but it's actually an action and not a filter . (?!?) I've also tried without success to hack the cleaner gallery plugin, in order to make it directly run the shortcode without filtering the default function, removed the originary shortcode and added that new one. It works like a charm for normal posts, but it seems there is no way to implement the plugin in ajax requests. I'm getting more and more confused. Please help me! (also posted on the WP.org forums )
Awww... in admin-ajax.php : <code> define('WP_ADMIN', true); </code> in cleaner-gallery.php : <code> function cleaner_gallery_setup() { if ( is_admin() ) { require_once( CLEANER_GALLERY_DIR . 'admin.php' ); } else { require_once( CLEANER_GALLERY_DIR . 'gallery.php' ); } } </code> So I have to manually include &amp; run the necessary plugin code skipped after checking the WP_ADMIN constant, but I guess the need for a frontend ajax handler is becoming increasingly urgent!
Ajax, filters and shortcodes
wordpress
I have a sql database of historical events, I would like it to post data into the sidebar area of a wordpress site. As I am very new to it I do not have any idea how to proceed. I would be thankful if anyone could help me out. Thanks in advance
You can edit the <code> sidebar.php </code> (or any <code> sidebar-xxx.php </code> file, depends on your theme) and interface with your database using the wpdb class . If your historical events are in the same DB as wordpress you can use the wpdb class straight away, if they are in another DB you can instanciate a new wpdb class with : <code> $my_db = new wpdb('user','pass','dbname','host'); </code>
How to send data to sidebar?
wordpress
Hey guys i recently created a theme. I want to show home.php when a visitor visit home page but all my blog posts are listed in index.php file. Can someone suggest me how to display index.php i tried http://www.mysiteurl.com/index.php but it redirecting me to http://www.mysiteurl.com/home.php Please advise me. Thanks
You're misunderstanding the purpose of <code> home.php </code> , which is not necessarily to output the Site Front Page , but rather to output the Blog Posts Index . In WordPress, the <code> index.php </code> is simply the default fallback template file, that is used when no other, more-specific template file is available.
wordpress help needed. How to display both home.php and index.php?
wordpress
What processing is done by wordpress when a page is accessed that loads all contextual information into $post and other variables? and is it possible to trigger this process manually (or simulate it) so function calls have this context? The reason I'm asking is because I have written a small plugin that allows users to call wordpress functions via Ajax. The plugin works great with context-less functions. It has a big limitation however: calling a function via ajax loses the context information (e.g. $post) that the called function would otherwise have, had it been placed from within a template. However, the ajax call does send across the HTTP Referrer information. I can easily extract the referrer info, so I know e.g. on which page the user is on. The problem is I'm not sure how to use it further. Any tips/ideas would be greatly appreciated.
you're requesting index.php which I guess it's the homepage; if I call for example is_category() trough your ajax from the category page I'll get false because the function is being ran on the homepage. Use <code> $_SERVER["REQUEST_URI"] </code> instead (don't forget to sanitize it) you're hooking your handler on the <code> init </code> action, which I think runs before the post data is set up. Use a different one, like <code> wp </code> or <code> template_redirect </code>
how to get context information inside my funcion
wordpress
For example, if I create a post type called "destinations" does that automatically create capabilities like "edit_destinations" or "delete_destinations"?
It does not automatically create that capability in the sense that there is no new capability registered with WordPress. Instead it defaults to use the capabilities assigned to creating/editing posts. For example, if an author logs in they will be able to create and publish a new destination entry by default. You can override this with the <code> capabilities </code> value when using <code> register_post_type </code> . See Justin Tadlock's excellent tutorial here http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress
When you create a custom post type, does that also create capabilities for editing/deleting that post type automatically?
wordpress
After adding support for a selection of post formats like this: <code> add_theme_support( 'post-formats', array( 'aside', 'video' ) ); </code> how can I then get the list of supported post formats back? I'm building a theme where the user can toggle support for postformat, and I want other admin elements to reflect what post formats the user has configured the theme to support. so I'm looking for something like <code> current_theme_supports( 'post-formats'); // outputs boolean </code> but that outputs just true or false, whereas I want to get an array of the post formats actually registered.. what would be the correct WordPress function to call (or constant/global var) to look at for this? I want something like this: <code> get_supported_post_formats(); // out: array('aside', 'video') </code>
Taken from <code> post_format_meta_box </code> ; <code> if ( current_theme_supports( 'post-formats' ) ) { $post_formats = get_theme_support( 'post-formats' ); if ( is_array( $post_formats[0] ) ) { print_r( $post_formats[0] ); // Array( supported_format_1, supported_format_2 ... ) } } </code>
how to get list of post formats supported by theme?
wordpress
I have this custom loop: <code> &lt;?php // Display the top ones $args = array( 'post_type' =&gt; 'reply', 'post_parent' =&gt; $post-&gt;ID, 'r_sortby' =&gt; 'highest_rated', 'r_orderby' =&gt; 'desc', 'order' =&gt; 'DESC' ); ?&gt; &lt;?php query_posts( $args ); ?&gt; &lt;div class="entry-list-top"&gt; &lt;?php while ( have_posts() ) : the_post(); ?&gt; &lt;h2 class="dark-title"&gt;&lt;?php _e( 'Top Replies' ); ?&gt;&lt;/h2&gt; &lt;div class="topic-entry"&gt; &lt;div class="topic-author"&gt; &lt;?php bbp_reply_author_link( array( 'type' =&gt; 'avatar' ) ); ?&gt; &lt;/div&gt; &lt;div class="topic-content"&gt; &lt;span class="topic-author-link"&gt;&lt;?php bbp_reply_author_link( array( 'type' =&gt; 'name' ) ); ?&gt;&lt;/span&gt; &lt;?php bbp_reply_admin_links(); ?&gt; &lt;span class="topic-post-date"&gt;&lt;?php printf( __( '&lt;span&gt;%1$s&lt;/span&gt; &lt;span&gt;at %2$s&lt;/span&gt;', 'bbpress' ), get_the_date(), esc_attr( get_the_time() ) ); ?&gt;&lt;/span&gt; &lt;?php bbp_reply_content(); ?&gt; &lt;div class="tt-like-button"&gt; &lt;?php if(function_exists('the_ratings')) { the_ratings(); } ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php $most_voted[] = get_the_ID(); // get the id of the most voted post ?&gt; &lt;?php endwhile; ?&gt; </code> I would like to retrieve the number of posts (only in this loop). (The is another loop below). Any suggestions?
Just count the number of returned posts of the first loop: Replace: <code> &lt;?php query_posts( $args ); ?&gt; </code> With: <code> &lt;?php $posts = query_posts( $args ); $count = count($posts); ?&gt; </code>
Displaying the number of posts in a custom loop (without including the number of posts of a loop below)?
wordpress
Is there a way to prevent WP from stripping the HTML from the author bio? I need it to keep my paragraphs. Thanks in advance! :) Edit - Although this question has been answered, I will clarify that I was referring to the Bio textarea when editing individual users.
remove the filter that formats the description. put this in your theme's functions.php: <code> remove_filter('pre_user_description', 'wp_filter_kses'); </code> EDIT - I should mention, if you allow random people to register and add their own bio for display on the site, not filtering that text could enable bad things.
How can HTML be allowed in Author Bio?
wordpress
I just noticed today that the documentation for query_posts() mentions some "disadvantages" of using query_posts for altering the main Loop, notably: 'causes additional SQL queries'. This seems to imply that there's another way / a better way. Obviously there's get_posts() and WP_Query for secondary loops, but I don't see them as addressing the "disadvantages" listed in the Codex documentation. I can see that by waiting until you're in the template to run query_posts, WordPress has already run a query once and this is now a second query that clobbers the first one (the first one being basically ignored). This definitely DOES sound inefficient (though perhaps not a big deal, who knows?) My question is: is there an alternative to query_posts that does NOT add "additional SQL queries" or is the Codex documentation simply deceiving?
When I added the drawbacks to the Codex, I was mainly thinking of using the 'request' filter as an alternative to query_posts(). That filter is only run for the main query, so that solves the problem with 'pre_get_posts', which fires for every query. The downside is that you don't have access to query flags like is_single() etc. Here's one way you could get access to them, without actually doing the SQL queries: <code> function alter_the_query( $request ) { $dummy_query = new WP_Query(); // the query isn't run if we don't pass any query vars $dummy_query-&gt;parse_query( $request ); // this is the actual manipulation; do whatever you need here if ( $dummy_query-&gt;is_home() ) $request['category_name'] = 'news'; return $request; } add_filter( 'request', 'alter_the_query' ); </code>
Alternative to query_posts for main loop?
wordpress
I have a site some having job postings running using jobber base. Now I am going to shift it in WP using jobroller theme that is of 99 USD. I am a developer who always like MVC rather than these CMS. I was thinking of doing it in Yii. But now I came to know about job roller. So I have 2 questions? Is jobroller worth 99 USD and will it work for my product? Can WP handle this if I want to do changes every week. As I told earlier, I am also a developer. So I will be doing changes in it but I doubt that I will not be able to do this in such friendly way as it can be easily done in an MVC framework. I am always in favor of OOP and MVC. But I actually don't have much time to develop my own. So guys please advise me that should I spend some more time and do it in MVC once or I should once continue with WP? Can any one tell me about big sites that are developed in WP? I will be thankful if any one can give me good advise?
About OOP Themes) There are dozens of Theme- &amp; Plugin-"Frameworks" out there. And some are OOP. About custom coding) You could also try libraries like WP Alchemy for meta boxes and custom content. "Rilwis" offers another one. Then you could use some stackexchange-url ("front end code") to insert stuff into Custom Post types. About "Jobroller") You should post/ask your Q about "Jobroller" in detail at their page. Furthermore is it hard to know if it's a) commercial and b) you didn't explain your needs in detail. About WP &amp; Performance) Take a look at stackexchange-url ("this Q") for a more in depth look.
Is wordpress big enough for my project
wordpress
I have done a lot of researching and haven't found quite what I am looking for, so I am hoping that I can be pointed in the right direction. I am developing an Events plugin that will book a ticket from the frontend. This is no different than any other Form submission, but what I am getting confused with is how to handle that from a plugin that is written via OOP with a class. Most articles that I found say to put the $_POST handling within the template page. Ideally I would like to have this handled by a function within the plugin. The other thing that I am not sure about is when you submit the form on the frontend, how that actually gets passed to the function on the backend. I am hoping to completely abstract the form processing from any template details. <code> // events.php if ( ! class_exists( 'Events' ) ) { Class Events { function __construct() { add_action( 'plugins_loaded', array( &amp;$this, 'includes' ), 1 ); } function includes() { require_once( EVENTS_INCLUDES . 'functions.php' ); } } } if ( class_exists( 'Events' ) ) { $events_load = New Events(); } // functions.php function process_form() { ...do form processing here... ...insert booking... } </code> I'm not sure what to hook into that would catch that, or where to send the form action too. Thanks for all the help! -Adam
Send the form action either to your homepage, or to a specific page URL. You can't have $_POST handling within the template because you need to redirect after your process it, and redirect needs to be fired before any HTML output. <code> // you should choose the appropriate tag here // template_redirect is fired just before any html output // see - http://codex.wordpress.org/Plugin_API/Action_Reference add_action('template_redirect', 'check_for_event_submissions'); function check_for_event_submissions(){ if(isset($_POST['event'])) // &amp;&amp; (get_query_var('pagename') === 'events) { // process your data here, you'll use wp_insert_post() I assume wp_redirect($_POST['redirect_url']); // add a hidden input with get_permalink() die(); } } </code> You could also check for a nonce to make sure the data was submitted from the right place...
Plugin Form Submission Best Practice
wordpress
I have a number of custom of post types - i.e. <code> 'windows' </code> , <code> 'doors' </code> , <code> 'garages' </code> and I want to load a custom template ( <code> special.php </code> ) whenever my wordpress site has a url that looks like this: <code> www.mysite.com/windows/ www.mysite.com/doors/ www.mysite.com/garages/ </code> I don't want to use pages, as it is not appropriate in this case (I have given a scaled down example in the above example) How can I achieve this? Currently, as no pages exist with those names, I am getting an 404 (index.php)
I assume that your custom post type windows would map onto /windows/ etc? You can customise the template for individual custom post types via single-posttype.php in your theme, e.g. single-windows.php single-doors.php and single-garages.php Wordpress will automatically pick these up You could also use custom page templates, e.g. page-windows.php or custom templates with the right template names. If the pages are intended to list the post types, then you could try creating post archive templates, e.g.: http://mark.mcwilliams.me/2010/10/wordpress-3-1-introduces-custom-post-type-archives/ Or, you could create a taxonomy for each of said names, and use taxonomy-windows.php Using all fo the above, one could share the code using something along the lines of: <code> &lt;?php // example code, may need minor modifications get_template_part('special',$post-&gt;post_type); </code> Allowing you to share the code for all the pages in one file, and giving you child theme support, and the ability to override via files such as special-windows.php OR, if none of the above suit you, there is a final solution: http://www.braindonor.net/coding-blog/custom-pages-with-wordpress-plugins/230/ This will let you put a page with whatever you want, wherever you want, without needing any posts or pages of any kind, in a theme independent way.
wordpress - load a template based on the URI
wordpress
I need to change the author element of the feed from dc:creator to author. How does this is possible?
Bearing in mind my comment about, you can use the <code> rss_item </code> hook to add a filter that will let you add the <code> &lt;author&gt; </code> element to your feed <code> function add_author_to_feed($feed) { $feed .= '&lt;author&gt;' . the_author_meta('user_email') . '&lt;/author&gt;'; return $feed } add_filter('rss_item', 'add_author_to_feed'); </code> (note - this code is not tested)
How can I rename the element to in my RSS?
wordpress
One year ago @t31os answered a post with a code I can't access: http://wordpress.org/support/topic/search-custom-field-data His answer... I was feeling adventurous, so i wrote a simple plugin to do it.. http://wordpress.pastebin.ca/1736605 The post search in the admin will now also check against the meta keys and meta values when checking for matching posts... ;) Is there a way to get that code so I can use it? Thank you very much Patricia
Don't know what's wrong with that link but you can see an answer to a similar question stackexchange-url ("how to filter post listing (in WP dashboard posts listing) using a custom field (search functionality) ?") Its just what you are looking for.
admin : search custom fields
wordpress
I've worked with WordPress for a while now and this is the first time I've had this problem, I can't get my permalinks to work without <code> index.php </code> on the URL even though <code> mod_rewrite </code> is enabled, a few things that might help figure the problem out: I'm using apache2 and mod_rewrite is enabled, I doubled checked by displaying the <code> phpinfo() </code> The <code> .htaccess </code> file gets written just fine when I update the permalink options and the contents are default WP Redirect rules but just in case here it is: <code> # BEGIN WordPress &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &lt;/IfModule&gt; # END WordPress </code> The permalink common settings on the option page don't actually show the <code> /index.php/ </code> part (sometimes when I've used IIS they show it there), if I use any of the common url structures I get a 404 page (not the <code> 404.php </code> one on my theme but the browsers 404 one) but if I add <code> /index.php/%postname%/ </code> for example it works just fine. Does anyone know what might be wrong? Thanks in advance!
Sigh had to add this to the httpd.conf file on the webserver: <code> &lt;Directory /var/www/&gt; Options FollowSymLinks AllowOverride All Order allow,deny Allow from all &lt;/Directory&gt; </code> First time I have to add it manually, oh well it works fine now :)
Can't get pretty permalinks to work without index.php
wordpress
Tearing my hair out a little bit here! I'm trying to create multiple image-selection boxes so users can upload as many images as they like to the species profile they've created. I'm using the following code in a .js file: jQuery(document).ready(function() { <code> var i = 2; jQuery('a#add_media').click(function() { input_code = '&lt;p&gt;' + '&lt;input id="upload_image-' + i + '" type="text" size="36" name="upload_image" value="" /&gt;' + '&lt;input id="upload_image_button-' + i + '" type="button" value="Upload Image" /&gt;' + '&lt;/p&gt;'; jQuery(input_code).appendTo('#upload_wrapper'); i++; }); jQuery('[id^="upload_image_button"]').click(function() { str = jQuery(this).attr('id'); substring = str.substring(str.length, str.length - 1); id_to_pass = 'upload_image-' + substring; alert(id_to_pass); tb_show('', 'media-upload.php?type=image&amp;amp;TB_iframe=true'); return false; }); window.send_to_editor = function(html) { imgurl = jQuery('img',html).attr('src'); jQuery('#' + id_to_pass).val(imgurl); tb_remove(); } }); </code> If I then view the DOM using Firebug, I can see that my input boxes appear correctly: <code> &lt;div id="upload_wrapper" style="margin:0; padding:0;"&gt; &lt;label&gt;Attach Image&lt;/label&gt; &lt;p&gt; &lt;input id="upload_image-1" type="text" value="" name="upload_image" size="36"&gt; &lt;input id="upload_image_button-1" type="button" value="Upload Image"&gt; &lt;span&gt; &lt;/p&gt; &lt;p&gt; &lt;input id="upload_image-2" type="text" value="" name="upload_image" size="36"&gt; &lt;input id="upload_image_button-2" type="button" value="Upload Image"&gt; &lt;/p&gt; &lt;p&gt; &lt;input id="upload_image-3" type="text" value="" name="upload_image" size="36"&gt; &lt;input id="upload_image_button-3" type="button" value="Upload Image"&gt; &lt;/p&gt; </code> Yet only the first button opens the upload frame? Thanks in advance.
OK, I've made the changes Otto suggested and it's working nicely - thanks. <code> var uploadClickHandler = function() { str = jQuery(this).attr('id'); substring = str.substring(str.length, str.length - 1); id_to_pass = 'upload_image-' + substring; tb_show('', 'media-upload.php?type=image&amp;amp;TB_iframe=true'); return false; }; jQuery(document).ready(function() { // Find the number of elements using our unique button name var i = jQuery('[id^="upload_image_button"]').size() + 1; jQuery('a#add_media').click(function() { // Variable to store the HTML for adding a new image input_code = '&lt;p&gt;' + '&lt;input id="upload_image-' + i + '" name="upload_image[' + i + ']" type="text" size="36" name="upload_image" value="" /&gt;' + '&lt;input id="upload_image_button-' + i + '" type="button" value="Upload Image" /&gt;' + '&lt;/p&gt;'; // Upon being clicked, append the input_code variable to our #upload_wrapper DIV jQuery(input_code).appendTo('#upload_wrapper'); // Use our uploadClickHandler function to add the iFrame functionality to our "on-the-fly" text boxes jQuery('[id="upload_image_button-' + i + '"]').click(uploadClickHandler); i++; }); // Add click functionality to the pre-JS-created HTML text boxes on our main page jQuery('[id^="upload_image_button"]').click(uploadClickHandler); // iFrame and return value functionality window.send_to_editor = function(html) { imgurl = jQuery('img',html).attr('src'); jQuery('#' + id_to_pass).val(imgurl); tb_remove(); } }); </code>
Why won't this jQuery code work?
wordpress
How I could made a sql query who retrieve all the sticky post in a wordpress database? This is because we use a new app over the old wordpress website database, and I don't know where Wordpress "store" the sticky attribute. Thanks in advance
It's not stored as attribute, but as list of all stickies. Snippet from core: <code> $sticky_posts = get_option('sticky_posts'); </code> So look for the option and then use IDs to retrieve posts.
How to retrieve sticky post in raw sql?
wordpress
I am building a new theme for my site, and I was wondering which is the simplest/lite theme with only the files needed like single.php index.php author.php and so on. I have read about wordpress themes and what files I have to include but I will have to code the default functions like wp-comments if I start from here. So I am looking for a lite theme to start over.
asked a few times, this link has some good answers stackexchange-url ("Opinions and recommendations on the best barebones base theme")
Which is the simplest theme for Wordpress to use it as your base?
wordpress
I moved my word press blog from Apache to IIS 7 shared hosting. my database connection is fine. I can access the admin module but I get an empty index.php with "Nothing Found for Index Php Error" in the title bar. Can someone please help.
Start by going to Settings> Permalinks , now click on the default radio button and click save. You probably used .htaccess to enable pretty permalinks, IIS doesn't use an .htaccess file. If the default structure fixed the problems you are having, but you want the old permalink structure, click this link to the WP-Codex page explaining how: Link to Codex Page (about half way down) .
Nothing Found for Index Php Error
wordpress
I'm using front-page.php to generate a static frontpage for a Web site I'm working on. I can't seem to get Wordpress to display the blog posts on any other page. I tried creating a custom template to display blog posts, but it doesn't display any posts. Also, when I try to set the front-page as a static frontpage manually in the reading settings, it doesn't appear as an option. Help?
To use a static Front Page, you need to do the following: Create two static Pages , one for your front page content, and one for your blog posts index; their names are entirely arbitrary, but for our purposes, let's call them "Front Page" and "Blog" Go to <code> Dashboard -&gt; Settings -&gt; Reading </code> Set "Front Page Displays" to "static page" In the dropdown lists below, set "front page" to "Front Page", and "posts page" to "Blog" Now, for some explanation: WordPress will use your <code> front-page.php </code> template file when rendering your site front page, whether the front page is set to display blog posts or a static Page. If you want to customize your blog posts index, use the <code> home.php </code> template, which will be used when a static Page is used to display blog posts, or when the front page is set to display blog posts if no <code> front-page.php </code> template file exists . If neither of these two template files exist, then WordPress will fall back to: <code> page.php </code> , for a static front page, or for blog posts if set to display on a static Page <code> index.php </code> in all other cases If you still need some clarification, see the Codex entry for Template Hierarchy .
Using front-page.php need new blog page
wordpress
How can I build a query to find posts that DO NOT contain a certain meta key or meta value? for example: <code> query_posts( array( 'meta_query' =&gt; array( array( 'key' =&gt; 'feature', 'value' =&gt; '_wp_zero_value', 'compare' =&gt; '!=' ) ) ) ); </code>
Getting posts without a certain meta key is a little tricky, namely due to the database design and the nature of SQL joins. AFAIK, the most efficient way would be to actually grab the post IDs that do have the meta key, and then exclude them from your query. <code> // get all post IDs that *have* 'meta_key' with a non-empty value $posts = $wpdb-&gt;get_col( "SELECT post_id FROM $wpdb-&gt;postmeta WHERE meta_key = 'my_key' AND meta_value != ''" ); // get all posts *excluding* the ones we just found query_posts( array( 'post__not_in' =&gt; $posts ) ); </code>
how to show posts that are missing a meta_value
wordpress
I am using wp_list_comments() function to draw the comment list.But,I want change many things in the form like class,styles, reply link and etc... so please help me, How can i customize the comment listing function Thanks
The <code> wp_list_comments() </code> call accepts a callback argument, in which you can define the specifc comment-list markup that you want. I would suggest taking a look at how TwentyTen handles the <code> wp_list_comments() </code> callback.
How can i customize the comment list
wordpress
Before I call the_excerpt(), the_permalink() displays the correct thing. Afterwards, it does not... <code> &lt;?php global $query_string; //strip out the "pagename=blog" so that the query will grab all of the posts instead of the content of the blog page $query_string = preg_replace("/pagename=[a-zA-Z0-9]*/", "", $query_string); query_posts( $query_string . "posts_per_page=3" ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt; &lt;li class="post-listing"&gt; &lt;div class="no-col"&gt; &lt;h3&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h3&gt; &lt;p class="meta"&gt;Posted on &lt;?php print get_the_date(); ?&gt; by &lt;?php the_author(); ?&gt; in &lt;?php the_category(', ') ?&gt;&lt;/p&gt; &lt;!-- &lt;?php the_permalink(); ?&gt; --&gt; &lt;?php the_excerpt(); ?&gt; &lt;!-- &lt;?php the_permalink(); ?&gt; --&gt; &lt;p class="meta"&gt;&lt;?php the_tags('') ?&gt;&lt;/p&gt; &lt;div class="navigation"&gt;&lt;a class="alignright" href="&lt;?php the_permalink(); ?&gt;"&gt;READ MORE &amp;raquo;&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;?php endwhile; else: ?&gt; &lt;li&gt;&lt;?php _e('Sorry, no posts matched your criteria.'); ?&gt;&lt;/li&gt; &lt;?php endif; ?&gt; </code> I have a page called "blog.php" that I have defined as a Template named "blog" that people can apply to a page they create (so that they can have a blog listing page, I know there is probably a better way, but this is the solution that was gone with for various reasons). It was working just fine, but now (a month after I wrote it) it suddenly stopped working. I have narrowed the problem (I think) down to the the_excerpt() call. The permalink displays fine before that, but afterwards craps out and instead displays the permalink for the blog.php page... I think that the_excerpt() is throwing everything completely out of "The Loop" and then the current post it sees just becomes the page that uses the blog.php template (it spits the contents of that page out and then stops as if that page were the last post in The Loop). This also happens if I replace "the_excerpt()" with "the_content()" or "get_the_excerpt()"
I had installed the "Facebook Comments for WordPress" plugin. This plugin attaches a filter to <code> the_content(); </code> . The filter contains the line <code> wp_reset_query(); </code> . Commenting this out fixes the problem (this is sub-optimal though, because, now the client will be unable to update the plugin).
the_excerpt(), get_the_excerpt() and the_content() all killing "the Loop"
wordpress
I have a few sites in a network. I don't want the site administrators to manage things like network plugins, but I would like them to be able to edit profiles of all network users, not use those on their site. At the top of the <code> /wp-admin/network/users.php </code> file is this: if ( ! current_user_can( 'manage_network_users' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); How can I grant site administrators priviledges to <code> manage_network_users </code> without promoting them to Super Admin? Here's what the code is looking like: /** * Retrieve a list of super admins. * * @since 3.0.0 * * @uses $super_admins Super admins global variable, if set. * * @return array List of super admin logins */ function get_super_admins() { global $super_admins; if ( isset($super_admins) ) return $super_admins; else return get_site_option( 'site_admins', array('admin') ); } /** * Determine if user is a site admin. * * @since 3.0.0 * * @param int $user_id (Optional) The ID of a user. Defaults to the current user. * @return bool True if the user is a site admin. */ function is_super_admin( $user_id = false ) { if ( $user_id ) $user = new WP_User( $user_id ); else $user = wp_get_current_user(); if ( empty( $user-> id ) ) return false; if ( is_multisite() ) { $super_admins = get_super_admins(); if ( is_array( $super_admins ) && in_array( $user-> user_login, $super_admins ) ) return true; } else { if ( $user-> has_cap('delete_users') ) return true; } return false; } /** * Whether user has capability or role name. * * This is useful for looking up whether the user has a specific role * assigned to the user. The second optional parameter can also be used to * check for capabilities against a specfic post. * * @since 2.0.0 * @access public * * @param string|int $cap Capability or role name to search. * @param int $post_id Optional. Post ID to check capability against specific post. * @return bool True, if user has capability; false, if user does not have capability. */ function has_cap( $cap ) { # fb($cap); if ( is_numeric( $cap ) ) { _deprecated_argument( __FUNCTION__, '2.0', __('Usage of user levels by plugins and themes is deprecated. Use roles and capabilities instead.') ); $cap = $this-> translate_level_to_cap( $cap ); } $args = array_slice( func_get_args(), 1 ); $args = array_merge( array( $cap, $this-> ID ), $args ); $caps = call_user_func_array( 'map_meta_cap', $args ); // Multisite super admin has all caps by definition, Unless specifically denied. if ( is_multisite() && is_super_admin( $this-> ID ) ) { if ( in_array('do_not_allow', $caps) ) return false; return true; } // Must have ALL requested caps $capabilities = apply_filters( 'user_has_cap', $this-> allcaps, $caps, $args ); $capabilities['exist'] = true; // Everyone is allowed to exist foreach ( (array) $caps as $cap ) { //echo "Checking cap $cap "; if ( empty( $capabilities[$cap] ) || !$capabilities[$cap] ) return false; } return true; } Code from users.php in wp-admin showing a second capability check for editing network users: // Only allow super admins on multisite to edit every user. if ( is_multisite() && ! current_user_can( 'manage_network_users' ) && $user_id != $current_user-> ID && ! apply_filters( 'enable_edit_any_user_configuration', true ) ) wp_die( __( 'You do not have permission to edit this user.' ) );
Here's a solution that worked for me: http://thereforei.am/2011/03/15/how-to-allow-administrators-to-edit-users-in-a-wordpress-network/ Pretty elegant and doesn't involve messing with core.
How to enable a site administrator to edit users in a WordPress network/ multisite setup?
wordpress
I'm developing a theme which supports WordPress' post formats. As a result I am using a big if statement, which can be found below. I would like to link my post titles to the posts while maintaining my theme as XHTML valid. I would like to call images (with classes) in the if statement while maintaining my theme as XHTML valid. I would appreciate if somebody could add the appropriate code to the following code to do so _ <code> if ( has_post_format( 'video' )) { echo the_title(); echo the_excerpt(); } </code> EDIT: Basically, the most important thing I'm looking for is that it calls the post name as a link which links to the actual post.
I don't know what you mean by "call images", but this will display the title as a link. <code> if ( has_post_format( 'video' )) { ?&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;?php the_excerpt(); } </code>
Calling Permalinks With PHP
wordpress
I suspect that this is not possible right now, but oh well.. I'll ask, maybe one of you has some intersting thoughts to share. So let's say we have the following taxonomy terms meta-boxes on our post edit page : Team accounting Team supergurus Countries Team developers Favorite ice cream Wouldn't it be nice to be able to groupe the three "Team" meta-boxes into one "container" box called "Teams" ? This would be just and empty meta-box with a title, containing the three taxonomy meta-boxes. The goal is to be more user friendly and keep the similar meta-boxes grouped together (it can become really confusing when you have a lot of taxonomies) Do you think this is doable ?
Thanks for the hint Bainternet, indeed this is very easy to implement with jQuery. Example (the four meta boxes are closed for clarity) : Here's what I did : <code> var $j = jQuery.noConflict(); $j(document).ready(function() { $j("#side-sortables").append('&lt;div id="container_div" class="postbox meta-box-sortables ui-sortable"&gt;&lt;div class="handlediv" title="Click to toggle."&gt;&lt;br&gt;&lt;/div&gt;&lt;h3 class="hndle"&gt;&lt;span&gt;Container Meta Box&lt;/span&gt;&lt;/h3&gt;&lt;div id="container_inside" class="inside"&gt;&lt;/div&gt;&lt;/div&gt;'); $j("#my_metabox_div").appendTo("#container_inside"); $j("#my_other_metabox_div").appendTo("#container_inside"); etc... }); </code> I added the classes <code> meta-box-sortables </code> and <code> ui-sortable </code> to the container div, that way you can also reorder the boxes within the container (though it's kind of tricky, the div jumps easily..). This script is then called on the admin page we want with : <code> function add_admin_scripts( $hook ) { // load script on new post page if ( $hook == 'post-new.php' ) { wp_enqueue_script( 'group_meta_boxes', get_bloginfo('template_directory').'/js/group_meta_boxes.js' ); } } add_action('admin_enqueue_scripts','add_admin_scripts',10,1); </code>
How to group meta boxes on the post edit page
wordpress
Inside of my current theme directory, I created a folder called "mobile" which contains a separate set of template files, all optimized for mobile. Now, say I setup a function that detects a mobile device, I would like wordpress to now load "mytheme/mobile/header.php" Instead of the themes root header.php and index files. Is there some way I can tell wordpress to look in a template subfolder for the template files? Many thanks
<code> if ( condition ) { get_template_part( 'path/to/template', 'mobile' ); } else { get_template_part( 'template', 'mobile' ); // in rootpath } </code> You can also intercept the behavior for <code> get_template_part() </code> with an action hook: <code> // Source in get_template_part do_action( "get_template_part_{$slug}", $slug, $name ); function wpse21352_template_part_cb( $slug, $name ) { switch ( $name ) { case 'mobile' : $slug = 'mobile/'.$slug; break; case 'tablet' : $slug = 'tablet/'.$slug; break; } return $slug; } // Now attach the above function to get_template_part() function wpse21352_template_actions() { $wpse21352_mobile_files = array( 'header' ,'logo' ,'content' // ,'etc...' ); foreach ( $wpse21352_mobile_files as $slug ) add_action( 'wpse21352_template_part_cb', 'get_template_part_'.$slug, 10, 2 ); } add_action( 'after_setup_theme', 'wpse21352_template_actions' ); // maybe some other hook </code> EDIT: As to @Otto comment, <code> locate_template() </code> might be a better choice for subdirectories. Please read the comments.
Load template inside a parent template
wordpress
I think <code> blogs.dir </code> is supposed to be used to separate content for the different blogs on a network install of Wordpress (MU or 3.0+ with networks enabled), however, I've not been able to find a clear guide to using it. Can someone shed some light and maybe post a few links to information on how to set it up, what to put in there, what the permissions should be set to, etc. ?
<code> blogs.dir </code> was the way to handle specific blog plugins and themes when it was WordPress-MU but since version 3 came out and the WordPress-MU was integrated into WordPress Core and introduced WordPress Multisite, that's no longer the story. WordPress Handles the creation of the new blogs/sites in the database and mainly in the background so you won't see too many things changing, but it also includes a new menu in the admin "Super Admin" which lets you handle the content for all sites in one place and they all site in one place. so basically WordPress handle this issue of `blogs.dir' for you.
Can somebody tell me how I am supposed to be using blogs.dir for network / MU sites?
wordpress
Is there any reason why Wordpress restricts the amount of posts you can administer at once to 20? Is there a way to display all posts? I want to change the category for about 1800 posts. I don't have the ability to change the post amount under screen options; see here: tinyurl.com/3npm5yz Using WP v3.1.3
It doesn't, in the top right under screen options it says, Show on screen , you can set this to a max of 999 ( I have never tried 999 just fyi) and you can select all, then bulk actions---> edit---> apply. Also I think there are plugins that do this that use direct <code> wpdb </code> functions, so you can effectively do it to more posts at once.
display all posts in wordpress admin
wordpress
Is there a plugin that makes external links open in new window, BUT only on the pages or domains or links I specify?
Simple Popup Plugin . this plugin helps to made external links open.. WordPress Popup Scheduler
Is there a plugin that makes extnernal links open in new window, BUT
wordpress
I have one stylesheet linked to my Wordpress page in header section: <code> &lt;link rel="stylesheet" type="text/css" href="&lt;?php bloginfo('template_directory'); ?&gt;/style.css" /&gt; </code> Now, I want to load different stylesheets on a few pages or sub-pages. What's the best/correct way of achieving this? I'm thinking about writing my own shortcode calling "wp_enqueue_style", is that a good idea?
Don't use a shortcode for <code> wp_enqueue_style() </code> ; it won't do any good, because by the time the shortcode is parsed, all the relevant hooks ( <code> wp_head </code> , <code> wp_print_styles </code> ) will have already fired. Write a function, in <code> functions.php </code> , to enqueue different style sheets based on <code> is_page( $id ) </code> (where <code> $id </code> can be an ID, slug, or title). Then hook that function into <code> wp_enqueue_scripts </code> . p.s. note also: you should be using <code> get_stylesheet_uri() </code> in your default stylesheet link, e.g.: <code> &lt;link rel="stylesheet" type="text/css" href="&lt;?php echo get_stylesheet_uri(); ?&gt;/style.css" /&gt; </code>
Loading different stylesheet on Wordpress pages?
wordpress
Is there a way to find the ids of the pages who contain meta tags/custom fields with a certain key-value pair? Say, for instance, that I wanted to find all of the pages who had a meta-tag/custom-field key of "weather" with a value of "raining", is there a way to do that?
Why not? Same custom field parameters in query should apply and you can use <code> post_type </code> argument to limit query to pages alone.
Find page IDs with specific meta tag key value pairs
wordpress
I have seen this in lots of wordpress themes and using it for a while but don't know what is the significance of it. It seems it does the same work as echo something out. Look for it in codex but failed to find anything about it. May be i have looked in wrong place. So, my question is what does <code> _e("Some String", 'String'); </code> means? And is it different from <code> echo "Some String"; </code> ?
it's for localisation/translation WPEngineer Has a great writeup on how it all works....
What is the significance of _e("Some String", 'String')?
wordpress
Is there a is_user_logged_in() function for Wordpress MU / Multisite (3.0+) where I can add in the network site ID like <code> is_user_logged_in(2) </code> where <code> 2 </code> would be the site_id? Update: After a little digging I came up with the code below. Unfortunately it does not work. //don't use this. does not work. function mu_logged_in($blog_id){ switch_to_blog($blog_id); $status = is_user_logged_in(); restore_current_blog(); return $status; } anu's answer and comments are good. also, make sure you have the cookie domain set correctly in the wp-config.php file :)
Yes, and no! The way users work in a multisite scenario is that there is a single pool of users, who are then associated with blogs. So, logged in status is common across all the blogs, but you can use <code> is_blog_user($blog_id) </code> to determine whether the current logged in user is a member of that blog. An example: <code> if (is_user_logged_in()) { if (is_blog_user(4)) echo "Current user is a member of blog 4"; } </code> Codex page for <code> is_blog_user() </code>
Is there a is_user_logged_in() for multisite?
wordpress
This seems to be an easy one but its giving me quite a hard time. get_the_post_thumbnail() suppose to take attribute as an array. Well, everything working right but when i pass style attr its doesn't work. <code> $attr = array( 'title' =&gt; get_the_title(), 'alt' =&gt; get_the_title(), 'style' =&gt; 'float:left' ); $thumb = get_the_post_thumbnail($post-&gt;ID, 'large-thumb', $attr); </code> The title and the alt attribute is set up nicely though but style attribute is missing in images. FYI: I am showing the thumbnail in rss feed.
<code> get_the_post_thumbnail </code> attribute array doesn't know <code> STYLE </code> , the fields that are available for you to use are: <code> src </code> <code> class </code> <code> alt </code> <code> title </code> so just use the class and define you class to it: <code> $attr = array( 'title' =&gt; get_the_title(), 'alt' =&gt; get_the_title(), 'class' =&gt; 'rss_thumb' ); $thumb = get_the_post_thumbnail($post-&gt;ID, 'large-thumb', $attr); </code> and then define the style in the class: <code> &lt;style&gt; .rss_thumb{float:left} &lt;/style&gt; </code> Update: My bad rss feed can really be styled like HTML since its not HTML. so to over come this problem you need to have your image inside the content tag and give it an align="left" which should work in most rss readers. so what you really want is to add a content_filter: <code> add_filter('the_content','add_rss_thumb'); function add_rss_thumb($content){ if (!is_feed()){ return $content; } //now that we know is a feed we add the image to the content: global $post; if(has_post_thumbnail()) { $post_thumbnail_id = get_post_thumbnail_id( $post-&gt;ID ); $thumbnail_attributes = wp_get_attachment_image_src( $post_thumbnail_id ); /* $thumbnail_attributes is an array containing: [0] =&gt; url [1] =&gt; width [2] =&gt; height */ return '&lt;img src="'.thumbnail_attributes[0].'" title="'.the_title_attribute('','',0).'" alt="'.the_title_attribute('','',0).'" align="left"&gt;'.$content; } return $content; } </code>
get_the_post_thumbnail() doesn't taking style attribute
wordpress
I am having vendor address field for each post using custom field plugin. In single post page.I want to generate bar code.When its scanned by mobile phone.It should display the address of the vendor in text format. Is there any existing plugin.Or any gold suggestions are appreciated. Thanks in advance !
No need for a plugin if you use the Google Chart tool api its very simple, i have a function that i wrote a while back: <code> /* * function to get QR code Image from google chart API * @Params: * $content - (string) the content to store inside the QR code (eg: url,address,string..) * $size - (string) the size of the QR code image , must be in heightxwidth format(eg: 150x150 , 320x320) * $ImgTag - (bool) if set to true the function will echo out the full img tag of QR code image , * if false then the function will return the image src (default = true) */ function get_QR_code($content = null,$size = null,$ImgTag = true){ if ($size == null){ $size = '150x150'; } if ($ImgTag){ echo '&lt;img src="http://chart.apis.google.com/chart?cht=qr&amp;chs='.$size.'&amp;choe=UTF-8&amp;chld=H&amp;chl='.$content .'"&gt;'; }else{ return 'http://chart.apis.google.com/chart?cht=qr&amp;chs='.$size.'&amp;choe=UTF-8&amp;chld=H&amp;chl='.$content; } } </code> Usage: <code> &lt;?php get_QR_code('Hello form Google API'); ?&gt; </code> which will give you this: So once you have this function in your theme's functions.php file you can call it in your template and pass the custom field value as the content: <code> $qr_content = get_post_meta($post-&gt;ID,'vendor_address_field_name',true); get_QR_code($qr_content); </code>
plugin suggestion for barcode
wordpress
As the title states all I'm trying to do is get the descriptions for all tags inside the loop on my INDEX.php page to show up. I know you can use code to call specific tag descriptions but I want to avoid that if possible since I'll have hundreds of tags all of which I want to show descriptions for. Is there a way to modify the <code> get_tags </code> tag in the loop to display descriptions following each tag?
Modified from the <code> get_tags() </code> Codex Example <code> $tags = get_the_tags(); // for the specific post // $tags = get_tags(); // all tags $html = '&lt;div class="post_tags"&gt;'; foreach ( $tags as $tag ) { $tag_link = get_tag_link( $tag-&gt;term_id ); $html .= "Describtion for ".ucfirst( strtolower( $tag-&gt;name ) ).": $tag-&gt;description"; $html .= "&lt;a href='{$tag_link}' title='{$tag-&gt;name} Tag' class='{$tag-&gt;slug}'&gt;{$tag-&gt;name}&lt;/a&gt;"; } $html .= '&lt;/div&gt;'; echo $html; </code>
How to enable all Tag Descriptions in loop?
wordpress
I know if I had a page that had a permalink such as <code> /stories/ </code> then I could create a page in my template called <code> page-stores.php </code> and it would load in place of the default <code> page.php </code> when that page loaded (see Template Hierarchy ) What I want to know is if I had that two page templates, maybe <code> page.php </code> and <code> page2.php </code> , if I could use the <code> functions.php </code> file to specify that if a page had a permalink of <code> /stories/ </code> it would use <code> page2.php </code> ? I know there is an option when editing a page to let the end user choose the page template, but in this case I would like to set it specifically.
This might work: <code> add_filter('page_template', 'custom_page_template'); function custom_page_template($template){ // check your permalink here if(get_query_var('pagename') === 'stories') return locate_template(array('page2.php', 'page.php')); return $template; } </code>
Adjust which tempalte a page uses with a function?
wordpress
I'm using <code> echo get_the_term_list( $post-&gt;ID, 'trpropcity', '', ' ', '' ); </code> to show a taxonomy link, I'd like to make this instance of it only have the first letter capitalized, Cleveland not CLEVELAND, I realize I could just change the taxonomy, but I actually want it all caps everywhere else on the site, so I figured it would be best to just change it once. I've been playing with ucwords and strtolower but haven't had any success yet.
Build the links yourself: <code> $terms = get_the_terms($post-&gt;ID, 'trpropcity'); if($terms) foreach($terms as $term) echo '&lt;a href="'.get_term_link($term, 'trpropcity').'"&gt;'.ucwords(strtolower($term-&gt;name)).'&lt;/a&gt;'; </code>
Make first letter of my taxonomy uppercase
wordpress
This functions at the moment but it only returns the first value from the array. I've been struggling to echo, print, explode, or whatever the multiple custom field values that share the same key (mp3). The shortcode is looking for comma-separated urls aka <code> tracks="http://url1.mp3, http:/url2.mp3" </code> I know i've created a bit of mess here. Wading into deeper waters... <code> &lt;div id="post_meta_player"&gt; &lt;? global $post; if(get_post_meta($post-&gt;ID, 'mp3', false)) { foreach(get_post_meta($post-&gt;ID, 'mp3', false) as $mp3) { $mytracks = print_r($mp3, ','); } } $shortcodes = '[mp3-jplayer tracks="'.$mytracks.'"]'; mp3j_put( $shortcodes); ?&gt; &lt;/div&gt; </code>
Kind of confusing question, but I think you want: <code> [mp3-jplayer tracks="'.implode(', ', get_post_meta($post-&gt;ID, 'mp3', false)).'"] </code> Assuming you get a array of meta key values this will join the into a comma-separated string
explode array within shortcode
wordpress
i've saved and array of 'open days' as a serialised array in a meta value. I was hoping i could then just search this field for the selected dates but i can't seem to create a match. serialised = a:2:{i:0;s:10:"2011-09-16";i:1;s:10:"2011-09-17";} ; // two open dates and was trying this and some variation without luck ; <code> $values_serialized = serialize(array('2011-09-16')); // need to serialise??? $args = array ('meta_query' =&gt; array( array( 'key'=&gt;'v-openDays', 'value'=&gt;$values_serialized,'compare'=&gt;'IN' ) ) ) // IN or LIKE? </code> will also be searching for multiple days but need to get one working first! Help appreciated, Dc
Don't serialize the search value, just use <code> 'value' =&gt; '2011-09-16' 'compare' =&gt; 'LIKE' </code> . Otherwise you're essentially looking for; <code> a:1:{i:0;s:10:"2011-09-16"} </code> Which of course doesn't actually match anywhere in; <code> a:2:{i:0;s:10:"2011-09-16";i:1;s:10:"2011-09-17";} </code>
search serialised meta_value for date value?
wordpress
I have come across a problem whilst using the next_post_link() function. It seems that this function automatically echo's, for position reasons I need this to just return the link. Is there any available function or workaround that I can use to achieve this result?
try to work with http://codex.wordpress.org/Function_Reference/get_adjacent_post; example: <code> $next_post_link_url = get_permalink( get_adjacent_post(false,'',false)-&gt;ID ); $prev_post_link_url = get_permalink( get_adjacent_post(false,'',true)-&gt;ID ); </code>
is it possible to get next_post_link
wordpress
I have about 1500 posts I want to change category for. Is there a quick way to do this in Wordpress Admin?
No quick way exists in the WordPress admin for 1500 posts, the better way would be to do it with MySQL directly either by custom queries and updated or by PhpMyAdmin and his friends.
Migrate posts into a different category
wordpress
I created this widget using a simple example on WordPress Codex: <code> &lt;?php function widget_container_latest_posts() { global $wpdb; global $post; get_template_part( '/includes/containers/container-latest-posts' ); } wp_register_sidebar_widget( 'widget_container_latest_posts_1', 'Container Latest Posts', 'widget_container_latest_posts', array( 'description' =&gt; 'Container Latest Posts - Adds recent posts.' ) ); ?&gt; </code> It works fine, but I want this widget to be used multiple times not only one time after I drag it on a sidebar widgets place, and so I can add it on all the other sidebars for example. Thank
You need to implement your Widget using the Widgets API , so that WordPress knows how to make multiple instances of the Widget. Your Widget declaration should take the following format: <code> class My_Widget extends WP_Widget { function My_Widget() { // widget actual processes } function form($instance) { // outputs the options form on admin } function update($new_instance, $old_instance) { // processes widget options to be saved } function widget($args, $instance) { // outputs the content of the widget } } register_widget('My_Widget'); </code>
WordPress Widget multiple use
wordpress
What we have for a project is: multiple sites (production, test, local development); migrated by multiple methods (PHPMyAdmin, Navicat, BackupBuddy); And the issue we are having is that while original production site seems to work fine, rest of the installations are constantly plagued by text encoding issues . Original site is configured with <code> latin </code> MySQL tables, but WP is configured and serves pages as <code> UTF-8 </code> , which I was told (in our chat) is already problematic. Rest of sites (whose databases mostly mirrors original production site) display issues such as: broken characters (correctable by tweaking WP encoding settings); broken characters (not correctable by tweaking WP encoding settings); site working fine, but feeding broken characters to external libraries. Since I had tried to untangle this for a while and there isn't much info on diagnosing encoding issues in WP, my questions are following: How to reliably diagnose if site has encoding configuration issues, even if it might not display them under normal circumstances? Which rules should be formulated, put into documentation and enforced to prevent encoding issues on migration?
So after about a year (on and off!) I had managed to hopefully get a fix on encoding issue. Why it breaks What my experience boiled down to, is that encoding issue like this are mostly caused by miscommunication when moving data around . in best case this is read mismatch, when correct data is wrongly interpreted in worst case that is write mismatch, when data is incorrectly saved, causing waterfall of issues and various degrees of corruption down the line Preemptive measures The earliest you can screw up database encoding in WP is when creating database. So even before you even went to download that WP archive to install. Do not rely on defaults and make sure that components talk in same encoding (like UTF8) internally, as well as to each other and visitors . This goes well beyond WP and involves MySQL configuration, possibly with some kicks for Apache and PHP on top. See WordPress Database Charset and Collation Configuration Fixing When the things are thoroughly broken you are up for a ton of pain figuring out what is wrong and how to get it back to normal. I found <code> mb_detect_encoding() </code> highly useful. It's not a magic wand, but (in a strict mode) false return from it is good signal that things are not normal. On WP-specific front <code> $wpdb </code> has encoding-related properties. When you have a reason/guess/idea of what is wrong - drag data to safe place and try to convert data to be meaningfully normalized, see: Converting Database Character Sets MySQL is destroying my Umlauts
How to diagnose and keep in check encoding issues?
wordpress
I've created a new custom post type and I need the post thumbnails or featured images generated by the <code> get_the_post_thumbnail() </code> function to be set in percent, rather than pixels, as I'm using a fluid grid. Ideally I would only set the width (to 100%). Is there a way to do this? Potentially using <code> add_image_size() </code> ?
have you tried, <code> if(has_post_thumbnail()) { $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'full' ); echo '&lt;img src="' . $image_src[0] . '" width="100%" /&gt;'; } </code>
set_post_thumbnail_size in percent, not pixels?
wordpress
For some posts, I see 404 page, even though posts exist, where is the place in WP where using permalink is decided what object needs to rendered? Thanks!
Jan Fabry wrote a very useful plugin that I think it would be helpful for you to analyze your rewrite rules.
Debugging WP routing
wordpress
I'm Using E-commerce featured product plugin.in this plugin we have a options to select a single product from product list but not able to select multiple options at same time. so any suggest to improve this plugin?
Check the plugin http://jigoshop.com/ , its free and has many possibilities. http://wordpress.org/extend/plugins/jigoshop/
wp E-commerce featured product plugin with muliple option?
wordpress
I'm currently using WP Super Edit. But the same problem persists with TinyMCE Advanced. This is how it is configured: http://i.imgur.com/4PyXi.png http://i.imgur.com/YniBi.png http://i.imgur.com/7MytG.png This is how I (admin) see it: http://i.imgur.com/OAdnF.png This is how my friend (2nd admin) sees it: http://i.imgur.com/mfUMq.png I'm getting desperate figuring out why the hell the 2nd button bar doesn't show.
Try click the " show/hide kitchen sink " button that looks like this:
2nd button row from WP Super Edit or TinyMCE Advanced doesn't show to 2nd admin
wordpress
Using the Google PageSpeed Online , it looks like the CSS/Images/JS files of most of my plugins (including wp-nivo-slider) do not get their expires-headers set. Is there a solution for this so that W3 Total Cache will set the expires headers on all the media on my page?
Make sure your hosting provider offer <code> mod_expires </code> . Because many shared hosting providers doesn't offer <code> mod_expires </code> . Just contact your hosting support.
Plugin Expires Headers - W3 Total Cache
wordpress
I was always a WP guy, built many small sites with it. I will create a new community with a big fanbase and I was wondering if 3.1.3 is fast enough? I didnt have the opportunity to work with it since 3.0. How does it react with heavy traffic web sites? Is it something that will make me worry enough to search for a lighter CMS or should I rely on it even with hundreds of visitors per day? I know about the tricks/tips to make it feels faster but is it by default ? Thank you for your answers.
I don't think there is any considerably advanced CMS that you can throw high traffic at and expect it to handle it without any configuration effort. Can WP be used for high-traffic site? Of course and it is being used as such by many sites. But it should be WP on decent hosting and well-configured software stack, rather than WP on cheap shared hosting with Apache defaults and no caching whatsoever.
Is Wordpress fast enough for a heavy traffic project?
wordpress
How should I completely disable the visual and html editor from pages? I know I can disable the visual editor in my profile, but I am trying to lock down the content input areas so that my client doesn't muck things up.
Why not use custom post types and don't add any support for the editor, that is afterall what they are for and the easiest way . The answer in this post covers how to do that, stackexchange-url ("Hide content box with Custom Post Type ?") http://codex.wordpress.org/Function_Reference/register_post_type To remove that functionality for pages or posts (and custom types) you can try and use <code> remove_post_type_support </code> . For pages; <code> add_action('init', 'my_remove_editor_from_post_type'); function my_remove_editor_from_post_type() { remove_post_type_support( 'page', 'editor' ); } </code> Ref: http://codex.wordpress.org/Function_Reference/remove_post_type_support A hacky solution is to use CSS <code> display:none; </code> for the <code> #editorcontainer </code> or one of the sub id or classes. You can also then enqueue that style only for particular users.
Completely disable editor
wordpress
I built something like this: Index Container Widgets Area and I created a widget for that - Categories Widget - Index Container .php with this in: <code> &lt;?php include (TEMPLATEPATH . '/includes/containers/container-grid-categories.php'); ?&gt; &lt;?php ///include (TEMPLATEPATH . '/includes/containers/container-list-categories.php'); ?&gt; </code> and for example in the /includes/containers/ container-grid-categories.php is this: <code> &lt;?php //include (TEMPLATEPATH . '/includes/containers/container-grid-categories/grid-thumbs.php'); ?&gt; &lt;?php include (TEMPLATEPATH . '/includes/containers/container-grid-categories/grid-tumbs-details.php'); ?&gt; </code> So, my questions, with this everything is working fine, the question is this a good way to make what I did (include TEMPLATEPATH)? Or use another way, and if that what way? Thanks
Long answer short: the absolute-best answer, for template-part files in a subdirectory, is to use <code> locate_template() </code> I would recommend referencing the stylesheet path for template file includes, so that those template part files can be easily over-ridden by Child Themes. So, ideally, you should use <code> get_stylesheet_directory_uri() </code> . Some differences/explanation of all the functions listed by @kaiser: <code> get_stylesheet_directory_uri() </code> / <code> get_template_directory_uri() </code> return a URL <code> get_stylesheet_directory() </code> / <code> get_template_directory() </code> return a file path All four of the <code> *get_*_directory_*() </code> functions perform SSL checking <code> TEMPLATEPATH </code> / <code> STYLESHEETHATH </code> are simple constants, return a file path , and do not perform SSL checking So, the four <code> get_*_directory_*() </code> functions are preferred to using <code> TEMPLATEPATH </code> / <code> STYLESHEET </code> ; however, they aren't really intended for locating template part files in subdirectories. In such a case, the best option is to use <code> locate_template() </code> directly. ( See here for a great writeup and comparison of all of the above options. )
WordPress "include TEMPLATEPATH" or?
wordpress
I need to be able to create posts in a custom post type with custom taxonomies from an XML file. It is from a job feed so when a job is added I need to be able to import it into wordpress. Do I just use wp_insert_post() ?
I did a job like this. Essentially it is parse and <code> wp_insert_post() </code> , but there are couple of fragile things to be aware of: you need some way to reliably track items to prevent duplicates, my approach was to save unique identifier from XML as post's GUID in WP for some obscure reason WP wants GUID to be URL-like (not valid URL, but formatted like one) so it's more reliable to go with custom field for identifiers that are not URLs; <code> wp_insert_term() </code> checks for some user capabilities here and there. And in WP cron there is no user set up. I vaguely remember this caused me troubles with assigning custom taxonomy and since you need that - check source and properly test that code does work in cron.
Importing posts from XML into custom post type
wordpress
In JavaScript, I'm using an Ajax call and I'm sending an array of shops. Except for the last element in the array all the shops already exist in the DB. The last element is a new shop. The PHP code should get the array and update all the shops that are already in the DB and insert the new one after the last row of the table. The PHP code uses $wpdb-> insert() to insert the last shop but for some reason it doesn't always insert it after the table's last row. The insert parameters include values for all the fields except for the index. This field is marked as auto_increment in the DB and indeed the inserted row get the expected index number. But it's not inserted after the last row as expected. What can be the cause? Here's the php code: <code> function updateshops($shopsArray){ global $wpdb; $sArray = $_POST["shopsArray"]; $aSize = sizeof($sArray); for ($i=0; $i&lt;$aSize; $i++) { if ($sArray[$i]['shopId']!=-1) // update existing records $wpdb-&gt;update( 'wp_shops', array( 'shopName'=&gt;$sArray[$i]['shopName'], 'shopAddress'=&gt;$sArray[$i]['shopAddress'] ), array('shopId'=&gt;$sArray[$i]['shopId'])); else // add new records $wpdb-&gt;insert( 'wp_shops', array( 'userId'=&gt;$sArray[0]['userId'], 'shopName'=&gt;$sArray[$i]['shopName'], 'shopAddress'=&gt;$sArray[$i]['shopAddress'], 'shopLat'=&gt;45, 'shopLng'=&gt;20 )); } } </code>
This really has almost nothing to do with WordPress. You probably haven't created a primary key for your shops table, which should probably be <code> shopid </code> (assuming you're using normal column naming conventions)
Wpdb-> insert() doesn't insert new row after the last one
wordpress
I'm trying to build some sort of a discussion boards by using custom post types and the built in comments. The structure is as following: An archive page to list all the pages of the Forum type, so each page is a "forum" Each "forum" has a title , a small description and then some threaded comments as threads with replies I think I'm at the right direction here, but I have a couple of question and maybe some one could assist me with them: Is it possible to have user to be associated with specific pages? Example: I'd like user A, B, C to be able to view "Forum" (page) 1; user D, E, F -> "Forum" (page) 2; etc. Is it possible to have users to be redirected on sign up to their profile page, but disable all other menus in the admin area for them? Is it possible to allow some users to be able to moderate comments only but not to see the other options on the site? Any help would be great.
Check out User Access Manager for point 1). For stripping back the menus &amp; controlling access, check out the User Role Editor . You can strip user capabilities down to the bare essentials, and a lot of the items in the menu will disappear for them. For example, removing all <code> *_themes </code> privileges will hide the Appearance item. You may find you can't quite hide all the menus you want, so you can hook into <code> admin_menu </code> and conditionally use <code> remove_menu_page </code> and <code> remove_submenu_page </code> depending on <code> current_user_can( 'role_name_or_capability' ) </code> . For the redirect, check out <code> wp-login.php </code> - there should be a decent hook or filter in there for you to use and change where the user gets redirected; either after logging in or registering.
Building Forums with Custom Post Types
wordpress
Videopress doesn't work for me when I drag multiple pages into a template e.g. pulling them in by their path name... <code> $page = get_page_by_path('Showreels/Excerpts'); </code> Does anyone know how I can paste a videopress link directly into the php since the shortcode doesn't seem to work?
I've got it... for anyone else having this problem... Go to where your media is kept on your WordPress.com account i.e. Media > Library Go to edit the video and make sure that 'Display share menu and allow viewers to embed or download this video' - this is so that you can click the 'share' menu on the embedded video on an actual page, grab the embed link and paste it into your html code Go back to your media page and disable the share menu again if you want to protect your videos.
Videopress Short Tags not working when pulling page into template
wordpress
I am using twentyten theme and I want there to be two sidebars on my page - one on the left and the second on the right. Can any one tell me how to do that?
Thirty Ten is a child theme of Twenty Ten and could be excellent for you as it comes with 3 columns as you want.
adding multiple sidebars on pages
wordpress
i am building a lists plugin .... i want to have a custom post type "lists" and then obviously also there would be a number of list items for each list .... i have read a fair bit of stuff about taxonomies vs postmeta but i'm still unsure as to which i should use or maybe something else ... it seems taxonomies are really more for categorising things ( like taxonomy colour, group etc ) and postmeta is more for attributes associated with a post eg ( url, phone number, price etc ) .... so it would seem that list items should be postmeta data, but my problem is that i want to have unlimited list items in the same way you could have unlimited taxonomy terms however is postmeta suitable for this .... it doestn look to me like something you'd create a new one of on the fly.... any comments ..... or maybe i should be doing it a different way altogether also i will need to be able to somehow group list items also and do a couple of other things with them eg sorting them via ajax (drag and drop)
Lists of items are already implemented in WP core. They're called custom menus . They are stored as a custom post type + taxonomy. UPDATE: I had assumed that your list items would be other posts, but I'm getting the impression that you just need them to be strings. In this case, menus would be overkill and you should store the list items as individual custom fields.
need advice on how to do a lists using custom post types - taxonomy vs postmeta
wordpress
What function can I use to override the multisite maximum file size upload restriction? I have already maxed out the kb upload size and ensured that the max file upload size in php.ini is over 50mb, yet still I'm getting an error uploading an 11mb file.
Make sure you've also boosted post_max_size to at least the same or greater. Check out the other precautions you should also take when doing so.
What function can I use to override the multisite maximum file size upload restriction?
wordpress
I released a new plugin to the .org repository about a month ago, and have committed several new versions since then, but the pie chart on the stats page has always stayed at 100% for an arbitrary version. For example, a week or so after 1.1 was released, it said that 100% of users had 1.0 installed, and recently it's been saying that 1.1.2 has 100%. I released 1.1.3 yesterday and it's gotten about 75 downloads so far, but the chart still says 1.1.2 has 100%. I realize there's probably some caching going on, but there's obviously a problem. It has around 1000 total downloads spread out over 5 releases, and we know that users don't update very frequently, so the chart should show the numbers spread out more. I'm guessing the next time it updates it'll say that 1.1.3 has 100%, like it's done for previous versions. Am I doing something wrong in my readme.txt or main PHP files? I've always had <code> Version: [current version number] </code> in the main PHP file and <code> Stable tag: [current version number] </code> in the readme.txt, and the readme.txt passes the validator.. You can browse through the different versions at http://plugins.svn.wordpress.org/basic-google-maps-placemarks/tags/ . Update: The File Header page in the codex has a specification, which can be helpful in debugging issues. Update 2: Now it's stopped working again. It might just take a couple releases with the fixed headers to work, though. . I finally fixed it; see my answer below.
I guess the following things could be a problem: Adding <code> : </code> after header comment "keys" Not using all possible header comments - WP reads the first 8bit (in a not really pleasent way), but I don't know how the repo does Move the <code> /* </code> into the same line as the <code> &lt;?php </code> tag If nothing of these are part of the problem, then i don't know and you should consider contacting the hackers list with this issue. Edit: One problem I have myself is that the repo is telling me that i have to upgrade one of my own plugins to some complete other. The solution was changing the folder name to something less general.
Repository reporting incorrect plugin 'active version' stat
wordpress
I know there are a lot of posts about this here, but NONE of them have answered my problem. I am working with a custom built theme that has a custom category type (named messagetypes). I have a category created named media. This theme is setup so that I can add a menu item that when clicked, displays all of the items labeled media, but the URL of the page is then mysite.com/messagetypes/media. I want to remove messateypes from the url and have it only mysite.com/media. The closest I have gotten is when I add to the custom category functions page, where <code> register_taxonomy( 'messagetypes', ... </code> is called with <code> 'rewrite' =&gt; array( 'slug' =&gt; ''), </code> When I do this, I get the desired result from this page, but all of my other page links break (using permalinks.) I have also tried adding to the rewrite array <code> 'with_front' =&gt; false </code> but that didn't work either. Any help or insight would be great. I've wasted too many hours on this and it's driving me nuts. Thanks.
When I do this, I get the desired result from this page, but all of my other page links break (using permalinks.) Because, quite simply, WordPress hasn't got a clue you're asking for a page. It's doing what you told it to do; For all URLs that look like <code> http://example.com/X </code> , look for posts with messagetype's of <code> X </code> . That's why you need the 'identifier' in there; so that it can distinguish the difference between requests for pages, archives, categories... If you really want this functionality, adding verbose rewrite rules at the top of the rewrite map would be the way to go; <code> add_rewrite_rule( 'media/?$', 'index.php?messagetypes=media', 'top' ); </code> If you've got a lot of messagetypes, you might want to hook into the creation and deletion of terms and dynamically update &amp; flush the rewrite rules. Otherwise, repeat the example for each term in your <code> functions.php </code> , then flush your permalinks (just visit the permalink options page in admin). One last thing, revert your <code> register_taxonomy </code> call 'back to normal' i.e. leave out the <code> rewrite </code> argument, and use the <code> term_link </code> filter to swap in the custom permalink ourselves; <code> function __custom_messagetypes_link( $link, $term, $taxonomy ) { if ( $taxonomy !== 'messagetypes' ) return $link; return str_replace( 'messagetypes/', '', $link ); } add_filter( 'term_link', '__custom_messagetypes_link', 10, 3 ); </code>
Remove taxonomy base or term from url
wordpress
I am developing a website where I need a webcam chat plugin. I have tried many plugins from wordpress.org but none of them worked. Can anyone please suggest me a working plugin. Plugins that did not work: TokBox OpenTok Plugin Problem : In the dashboard,it only pops up once i.e the first time the plugin is used and still the button to start webcam did not work(Also note that it did not show up my webcam.) Resolved: The problem was with the dashboard. I uploaded the files and it started to work . Thanks 2. Tinychat** Problem : Was unable to find API for it. VideoWhisper Video Presentation Problem : Keeps on loading and does not work Thanks.
Here's the link to the API for Tinychat . It was hidden in the footer. You could also take a look at this thread on WeekendHackers , where someone is searching for the same solution. Maybe you can put your heads together :)
Need webcam chat plugin for my client
wordpress
On my site I have multiple authors, who can add/edit/delete custom posts and upload (attach) images to those posts. The problem is - when they delete their posts, attachments stay on the server. So, I would like to get rid of all files attached to the post when it gets deleted. Can anyone share and example how it's done?
WP does not do this by default since there is no guarantee that attachment isn't still being used by some other post. Basic logic would be to hook into <code> delete_post </code> , query for child attachments and run <code> wp_delete_attachment() </code> on each. I did quick search in plugin repository and came up with tiny plugin that does just that (seems unmaintained so test before use) - Post Data Delete Advanced .
Delete post with all files attached to it
wordpress
Currently the Term Database has four columns. <code> term_id </code> <code> name </code> <code> slug </code> <code> term_group </code> . I would like to add another column called <code> menu_order </code> . How can i do this? The outcome i want is to be able to order my custom terms. If anyone knows of a beter way to do this please let me know. So far i already have code that sets up the input box. I just need help trying to order it using the <code> get_terms() </code> function. <code> add_action ( 'section_edit_form_fields', 'create_section_menu_order'); function create_section_menu_order( $tag ) { //check for existing featured ID $section_order = get_option( 'section_menu_order' ); $order_id = ''; if ( is_array( $section_order ) &amp;&amp; array_key_exists( $tag-&gt;term_id, $section_order ) ) { $order_id = $section_order[$tag-&gt;term_id]; } ?&gt; &lt;tr class="form-field"&gt; &lt;th scope="row" valign="top"&gt;&lt;label for="section_menu_order"&gt;&lt;?php _e('Order') ?&gt;&lt;/label&gt;&lt;/th&gt; &lt;td&gt; &lt;input type="text" name="section_menu_order" id="section_menu_order" size="10" style="width:60px;" maxlength="6" value="&lt;?php echo $order_id; ?&gt;"&gt;&lt;br /&gt; &lt;span class="description"&gt;The order your Sections will show. (Numeric digits only)&lt;/span&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php } add_action ( 'edited_section', 'save_section_menu_order'); function save_section_menu_order( $term_id ) { if ( isset( $_POST['section_menu_order'] ) &amp;&amp; is_numeric($term_id)) { $section_menu_order = get_option( 'section_menu_order' ); //load existing category featured option $section_menu_order[$term_id] = intval( $_POST['section_menu_order'] ); //set featured post ID to proper category ID in options array update_option( 'section_menu_order', $section_menu_order ); //save the option array } } </code>
I have a feeling that modifying that table is not a good idea. I hadn't done something like this, but if I needed to deal with considerable amount of meta information for terms I'd try to leverage Metadata API , which for terms would involve setting up separate storage table .
Add Column to Term Database
wordpress
I've tried and installed loads of free WP plugins that can't do what I would like them to do. I write a fictional news blog and I'd like to be able to display about a dozen or so adverts that I've made myself. They are each going to be 250x250px and need to be in the sidebar of my site. I figured it would be easier if it was in a widget. I'm not using a external service like Adsense. It's not necessary that my adverts keep record of impressions and they don't have a hyperlink.
Create a new folder in your WP directory called 'Adverts' Upload all your banner images to this folder as well as a PHP image randomising script I had found with a quick Google search. Place a text widget in your sidebar and add a html img tag linking directly to PHP file.
I'm trying to find a basic plugin for displaying images in a widget
wordpress
I am very new to wordpress and learning on my own.I have started to create a website where I need to upload images . I want to ask if you all usually use the same database to store the image(if so, how?) or use a image uploading site? Thanks
Wordpress images are stored in your wp-content/uploads folder no need for storing in the database, only the img uris get stored there. When you create an new wordpress post or page with your text editor you will notice several icons above it, use the first one to upload images and it will give you the option to add it to your post. Its realy very simple but there are other things to take note of before you do this like setting images sizes etc, i suggest you read up on the codex for image handling ..
Where do you upload images on a wordpress site?
wordpress
The Codex promotes this method of using <code> $ </code> inside a plugin/theme JavaScript file: <code> jQuery(document).ready(function($) { // $() will work as an alias for jQuery() inside of this function }); </code> But if you do that you only have access to <code> $ </code> inside ready(). I think functions should be broken into small modules which are called from ready(), not all lumped together inside ready(), so if I use the Codex's method then I have to pass $ to each function, which is annoying and crude. Writing out <code> jQuery </code> all the time instead of just using <code> $ </code> is also annoying. I can just do <code> $ = jQuery.noConflict(); </code> at the start of my JavaScript file and then <code> $ </code> is available everywhere, but I suspect that that might cause problems with other plugins/themes in some situations. My searches haven't turned up any thorough explanations or definitive answers. Does anyone have any thoughts?
You don't need <code> $ = jQuery.noConflict(); </code> Just wrap any functions outside document.ready() within: <code> (function($){ // use $ here safely })(jQuery); </code>
Making $ globally accessible with jQuery.noConflict()
wordpress
I am using the following permalinks structure: /%postname%/ and I also have some multi-page posts that look like /%postname%/2. The problem is I see a lot of 404 errors in webmaster tools for urls like /post-name/random stuff here How can I redirect all wrong URLs to the correct ones ?
Have you tried the Smart 404 plugin? http://wordpress.org/extend/plugins/smart-404/
Redirect wrong links Wordpress
wordpress
I have a Post Category called 'Podcasts' and under it are many other sub-categories. On a page I have titled "Podcast Categories", I would like to list all categories under the "Podcasts" category, as links to their category page. I'm fairly new to Wordpress, what would be the best way of accomplishing this? Thank you very much! Note: I do not want to display any kind of post content on this page, only the category name as a link. When I do google searching, I'm finding lots of info on how to post content from these categories. UPDATE 1: page-podcast-list.php <code> &lt;div id="content"&gt; &lt;?php $cat = get_category_by_slug( 'podcasts' ); $catid = $cat-&gt;ID; ?&gt; &lt;?php wp_list_categories( array( 'child_of' =&gt; $catid; ) ); ?&gt; &lt;/div&gt;&lt;!-- /content --&gt; </code> This isn't doing what I expected. It's printing out: Parse error: syntax error, unexpected ';', expecting ')' in /path/to/page-podcast-list.php on line 49 I'm not sure what line 49 is specifically at the moment, since I'm using the Built in WordPress Editor, without line numbers unfortunately.. I'm not familiar with php for the record, but am familiar with basic programming.
You need to use <code> wp_list_categories() </code> ( Codex ref ), using the <code> child_of </code> argument. Assuming you know the ID of the "Podcasts" category, e.g. <code> 123 </code> : <code> wp_list_categories( array( 'child_of' =&gt; '123' ) ); </code> If you need to find the category ID, use <code> get_category_by_slug </code> ( Codex ref ): <code> $cat = get_category_by_slug( 'podcasts' ); $catid = $cat-&gt;ID; wp_list_categories( array( 'child_of' =&gt; $catid ) ); </code> Rather than executing PHP from within the Page content, I would simply create a custom Page template : Copy <code> page.php </code> as <code> page-podcast-list.php </code> At the top of <code> page-podcast-list.php </code> put the following: . <code> &lt;?php /* Template Name: Podcast List */ ?&gt; </code> Look for the post content markup (e.g. <code> &lt;div id="post-&lt;?php the_ID(); ?&gt;" &lt;php post_class(); ?&gt;&gt; </code> ), and replace what's inside it (should include <code> &lt;?php the_content(); ?&gt; </code> , etc.) with the <code> $wp_list_categories() </code> code from above. If you have problems, copy/paste the code from <code> page-podcast-list.php </code> in your answer, and we'll help from there. EDIT 2 Your parse error is here, inside of your <code> wp_list_categories() </code> argument array: <code> 'child_of' =&gt; $catid; </code> Should instead be: <code> 'child_of' =&gt; $catid </code> (no semicolon)
How can I display a list of categories of my posts
wordpress
In regards to image attachments inserted into a post , I would like to wrap the img tag inside a div tag for specific design purpose. Is there a way to do this automatically after attaching the image file, like through hooks/filters maybe? Thanks in advanced!!
It's the image_send_to_editor filter: <code> if(is_admin()){ add_filter('image_send_to_editor', 'wrap_my_div', 10, 8); function wrap_my_div($html, $id, $caption, $title, $align, $url, $size, $alt){ return '&lt;div class="mydiv" id="mydiv-'.$id.'"&gt;'.$html.'&lt;/div&gt;'; } } </code> For existing images/posts you can try the regex in the function below
Automatically wrap post image in div
wordpress
I'm trying to do a query on wpdb to get the posts commented on most in the past week... Any ideas what I'm doing wrong? <code> $querystr = "SELECT comment_count, ID, post_title FROM $wpdb-&gt;posts wposts, $wpdb-&gt;comments wcomments WHERE wposts.ID = wcomments.comment_post_ID AND wcomments.comment_date &gt;= CURDATE() - 7 GROUP BY wposts.ID ORDER BY comment_count DESC LIMIT 0 , 10 "; $pageposts = $wpdb-&gt;get_results($querystr); </code> Thanks in advance. EDIT Query changed to something that sort of works I'm still not getting the date range right... it is returning the posts that are most commented on of all time, and not only the posts that have been commented on in the past week.
This should do it: <code> $querystr = "SELECT comment_count, ID, post_title FROM $wpdb-&gt;posts wposts, $wpdb-&gt;comments wcomments WHERE wposts.ID = wcomments.comment_post_ID AND wposts.post_status='publish' AND wcomments.comment_approved='1' AND wcomments.comment_date &gt; DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 YEAR) GROUP BY wposts.ID ORDER BY comment_count DESC LIMIT 0 , 10 "; </code>
WordPress Custom Query to get Most Commented Posts in the Past 7 Days
wordpress
How can I update/add a new title, post content, and category to a post with hard PHP code similar to add_post_meta(), update_post_meta()?
By using <code> wp_update_post() </code> , found in wp-includes/post.php: <code> // Update post 42 $post = array(); $post['ID'] = 42; $post['post_category'] = array( ... ); $post['post_content' ] = 'This is the updated content.'; $post['post_title' ] = 'This is the updated title.'; // Update the post into the database wp_update_post( $post ); </code>
Add title, post content, and category like add_post_meta and update_post_meta
wordpress
When viewing non-custom Posts, you get the likes of this submenu: I'm not using a title - I'm using custom columns with two fields concatenated: Is there any quick and easy way of adding the submenu to my custom post columns? Possibly by actually using the 'title' field on my custom post creation page - without having the title input box, as it's unnecessary for my users to see/edit.
In the end, I went for this: <code> function species_custom_columns($column){ global $post; if (!isset($title)) { $title = $this-&gt;getValue('genus',$post-&gt;ID,TRUE) . ' ' . $this-&gt;getValue('species',$post-&gt;ID,TRUE); } if (!isset($post_url)) { $post_url = get_site_url() . "/wp-admin/post.php?post=" . $post-&gt;ID . "&amp;action=edit"; } if (!isset($post_url_frontend)) { $post_url_frontend = get_site_url() . "/?p=" . $post-&gt;ID; } $genus_species = &lt;&lt;&lt;EOT &lt;strong&gt; &lt;a class="row-title" title="Edit “{$title}”" href="{$post_url}"&gt;{$title}&lt;/a&gt; &lt;/strong&gt; &lt;div class="row-actions"&gt; &lt;span class="edit"&gt; &lt;a title="Edit species" href="{$post_url}"&gt;Edit&lt;/a&gt; | &lt;/span&gt; EOT; $genus_species .= $this-&gt;delete_post_link('Trash', $title, '&lt;span class="trash"&gt;', ' |&lt;/span&gt;'); $genus_species .= &lt;&lt;&lt;EOT &lt;span class="view"&gt; &lt;a rel="permalink" title="View “{$title}”" href="{$post_url_frontend}"&gt;View&lt;/a&gt; &lt;/span&gt; &lt;/div&gt; EOT; switch ($column) { case "genus_species": echo $genus_species; break; case "common_names": echo $this-&gt;getValue('common_names',$post-&gt;ID,TRUE); break; case "family": echo $this-&gt;getValue('family',$post-&gt;ID,TRUE); break; case "group": if (get_the_terms($post-&gt;ID, 'group')) { $taxonomy_ar = get_the_terms($post-&gt;ID, 'group'); $output = '&lt;ul&gt;'; foreach ($taxonomy_ar as $taxonomy_term) { if ($taxonomy_term-&gt;parent) { $output .= '&lt;li&gt; &lt;span style="font-size:6px;"&gt;&amp;gt;&lt;/span&gt; '. $taxonomy_term-&gt;name .'&lt;/li&gt;'; } else { $output .= '&lt;li&gt;'. $taxonomy_term-&gt;name .'&lt;/li&gt;'; } } $output .= '&lt;/ul&gt;'; echo $output; } break; case "excerpt": //echo the_excerpt(); break; case "date_modified": echo the_modified_date('F j, Y @ g:i a'); break; } } </code> Seems to do the trick!
Custom Post Types: Custom columns with Title submenu?
wordpress
As of now I have a perfectly working script for a single meta-box. (I'll supply the details below.) However, I want to add more meta-boxes but am having trouble wrapping my head around how I would bend or add to this script to get those results. I had someone explain to me that I should create individual include's for each metabox and essentially recreate duplicates of what I already have, changing my functions and such for example: from <code> plib_add_box </code> to <code> plib_add_box_2 </code> and so on so they don't clash. But that's so crude and I know there has to be a way to simply add it to my existing include and essentially keep my format/save data portions the same. my functions.php: <code> include("metaboxes/preset-library.php"); //I created an array called $meta_box and set the array key to the relevant post type, in this case post $meta_box['post'] = array( 'id' =&gt; 'venue_location', 'title' =&gt; 'Venue/Location', 'context' =&gt; 'normal', 'priority' =&gt; 'high', 'fields' =&gt; array( array( 'name' =&gt; 'Venue', 'desc' =&gt; 'Venue Name', 'id' =&gt; 'venue_info', 'type' =&gt; 'text', 'default' =&gt; '' ), array( 'name' =&gt; 'Location', 'desc' =&gt; 'Location of the Venue', 'id' =&gt; 'location_info', 'type' =&gt; 'text', 'default' =&gt; '' ) ) ); add_action('admin_menu', 'plib_add_box'); </code> my include: <code> //Add meta boxes to post types function plib_add_box() { global $meta_box; foreach($meta_box as $post_type =&gt; $value) { add_meta_box($value['id'], $value['title'], 'plib_format_box', $post_type, $value['context'], $value['priority']); } } //Formatting function plib_format_box() { global $meta_box, $post; // verification echo '&lt;input type="hidden" name="plib_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" /&gt;'; echo '&lt;table class="form-table"&gt;'; foreach ($meta_box[$post-&gt;post_type]['fields'] as $field) { // get current post meta data $meta = get_post_meta($post-&gt;ID, $field['id'], true); echo '&lt;tr&gt;'. '&lt;th style="width:20%"&gt;&lt;label for="'. $field['id'] .'"&gt;'. $field['name']. '&lt;/label&gt;&lt;/th&gt;'. '&lt;td&gt;'; switch ($field['type']) { case 'text': echo '&lt;input type="text" name="'. $field['id']. '" id="'. $field['id'] .'" value="'. ($meta ? $meta : $field['default']) . '" size="30" style="width:97%" /&gt;'. '&lt;br /&gt;'. $field['desc']; break; case 'textarea': echo '&lt;textarea name="'. $field['id']. '" id="'. $field['id']. '" cols="60" rows="4" style="width:97%"&gt;'. ($meta ? $meta : $field['default']) . '&lt;/textarea&gt;'. '&lt;br /&gt;'. $field['desc']; break; case 'select': echo '&lt;select name="'. $field['id'] . '" id="'. $field['id'] . '"&gt;'; foreach ($field['options'] as $option) { echo '&lt;option '. ( $meta == $option ? ' selected="selected"' : '' ) . '&gt;'. $option . '&lt;/option&gt;'; } echo '&lt;/select&gt;'; break; case 'radio': foreach ($field['options'] as $option) { echo '&lt;input type="radio" name="' . $field['id'] . '" value="' . $option['value'] . '"' . ( $meta == $option['value'] ? ' checked="checked"' : '' ) . ' /&gt;' . $option['name']; } break; case 'checkbox': echo '&lt;input type="checkbox" name="' . $field['id'] . '" id="' . $field['id'] . '"' . ( $meta ? ' checked="checked"' : '' ) . ' /&gt;'; break; } echo '&lt;td&gt;'.'&lt;/tr&gt;'; } echo '&lt;/table&gt;'; } // Save data from meta box function plib_save_data($post_id) { global $meta_box, $post; //Verify if (!wp_verify_nonce($_POST['plib_meta_box_nonce'], basename(__FILE__))) { return $post_id; } //Check &gt; autosave if (defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE) { return $post_id; } //Check &gt; permissions if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } elseif (!current_user_can('edit_post', $post_id)) { return $post_id; } foreach ($meta_box[$post-&gt;post_type]['fields'] as $field) { $old = get_post_meta($post_id, $field['id'], true); $new = $_POST[$field['id']]; if ($new &amp;&amp; $new != $old) { update_post_meta($post_id, $field['id'], $new); } elseif ('' == $new &amp;&amp; $old) { delete_post_meta($post_id, $field['id'], $old); } } } add_action('save_post', 'plib_save_data'); </code>
You can create as many metaboxes as you want. Use a function to create them then hook into init. The first line should be <code> $meta_boxes = array(); </code> then start each new metabox with <code> $meta_boxes[] = array( </code> <code> add_action( 'init', 'prefix_create_metaboxes' ); function prefix_create_metaboxes() { $meta_boxes = array(); $meta_boxes[] = array( 'id' =&gt; 'venue_location', 'title' =&gt; 'Venue/Location', 'pages' =&gt; array('post'), // post type 'context' =&gt; 'normal', 'priority' =&gt; 'high', array( 'name' =&gt; 'Venue', 'desc' =&gt; 'Venue Name', 'id' =&gt; 'venue_info', 'type' =&gt; 'text', 'default' =&gt; '' ), array( 'name' =&gt; 'Location', 'desc' =&gt; 'Location of the Venue', 'id' =&gt; 'location_info', 'type' =&gt; 'text', 'default' =&gt; '' ), ) ); $meta_boxes[] = array( 'id' =&gt; 'another_meta_box', 'title' =&gt; 'Another Meta Box Title', 'pages' =&gt; array( 'post' ), // post type 'context' =&gt; 'side', 'priority' =&gt; 'low', 'show_names' =&gt; true, 'fields' =&gt; array( array( 'name' =&gt; 'Field Name', 'desc' =&gt; 'Field Desc.', 'id' =&gt; 'field_id', 'type' =&gt; 'text' ), ) ); } </code>
How to construct multiple meta boxes
wordpress
I'm trying to write a relatively simple plugin. I have two php files, one is included within the other like this: <code> define( 'PLUGIN_DIR', dirname(__FILE__).'/' ); include_once(PLUGIN_DIR . '/included_file.php'); </code> Things look fine. However I'm getting errors when I try to call some wordpress functions from within the included file: Fatal error: Call to undefined function xxx() ... The odd this is, only on some functions but not others. For example, if I place this code at the top of the included file: <code> if (!function_exists('add_action')) echo "&lt;h1&gt;add_action not found&lt;/h1&gt;"; if (!function_exists('check_admin_referer')) echo "&lt;h1&gt;check_admin_referer not found&lt;/h1&gt;"; if (!function_exists('wp_verify_nonce')) echo "&lt;h1&gt;wp_verify_nonce not found&lt;/h1&gt;"; if (!function_exists('wp_nonce_field')) echo "&lt;h1&gt;wp_nonce_field not found&lt;/h1&gt;"; </code> I get this output: <code> check_admin_referer not found wp_verify_nonce not found </code> so only two out of these four functions are accessible in the included file... I'm probably missing something very basic, but I'm a bit stuck. UPDATE: I tried creating a very basic plugin: <code> &lt;?php /* Plugin Name: Test this Plugin URI: http://www.gingerlime.com Description: test Author: Yoav Aner Version: 1.0 Requires at least: 3.1 Author URI: http://blog.gingerlime.com License: GPL 2.0, @see http://www.gnu.org/licenses/gpl-2.0.html */ if (!function_exists('add_action')) echo "&lt;h1&gt;add_action not found&lt;/h1&gt;"; if (!function_exists('check_admin_referer')) echo "&lt;h1&gt;check_admin_referer not found&lt;/h1&gt;"; if (!function_exists('wp_verify_nonce')) echo "&lt;h1&gt;wp_verify_nonce not found&lt;/h1&gt;"; if (!function_exists('wp_nonce_field')) echo "&lt;h1&gt;wp_nonce_field not found&lt;/h1&gt;"; if (function_exists('add_action')) echo "&lt;h1&gt;add_action found&lt;/h1&gt;"; if (function_exists('check_admin_referer')) echo "&lt;h1&gt;check_admin_referer found&lt;/h1&gt;"; if (function_exists('wp_verify_nonce')) echo "&lt;h1&gt;wp_verify_nonce found&lt;/h1&gt;"; if (function_exists('wp_nonce_field')) echo "&lt;h1&gt;wp_nonce_field found&lt;/h1&gt;"; ?&gt; </code> as soon as the plugin is activated it prints check_admin_referer not found wp_verify_nonce not found add_action found wp_nonce_field found I tried it on two wordpress installations. I might try a completely fresh wordpress and see what's going on. Strange.
First, since the <code> if (!function_exists('check_admin_referer')) echo "&lt;h1&gt;check_admin_referer not found&lt;/h1&gt;"; </code> code is working, then you've eliminated the issue being proper including of your Plugin sub-file. Second, all four of those functions are core WordPress functions , so you should never get a <code> call to undefined function </code> error for any of them. Can you post your relevant Plugin code, so we can see what's going on? EDIT My best guess is that certain functions aren't available until certain actions within the WordPress processing sequence. Try hooking your function into <code> init </code> , or <code> admin_init </code> , and see if the errors disappear.
can't access some worpress function from my plugin
wordpress
Can I change the order in which connections are displayed ? If I create say three connections and then display them at the bottom of my article, I will get them in reverse order. How can I change that ? I tried to use 'orderby' and 'order' but it has no effect whatsoever : <code> $connected_titles = new WP_Query( array( 'post_type' =&gt; 'as_title', 'nopaging' =&gt; true, 'orderby' =&gt; 'title', 'order' =&gt; 'DESC', 'suppress_filters' =&gt; false, 'connected_from' =&gt; get_queried_object_id() )); </code>
Just replace <code> 'order' =&gt; 'DESC' </code> with <code> 'order' =&gt; 'ASC' </code> .
[Plugin: Posts 2 Posts] Changing display order of connections
wordpress
I am new in WordPress, I want to write short code with parameters in function. That is in <code> add_shortcode('short code name','function name','parameter1,parameter2'); </code> In <code> add_shortcode() </code> , I want to pass parameters and this must get in function used for creating short code. Here is the function <code> function function name('parameter1','parameter2') { } </code> how is it possible?
According to the WordPress documentation , "a minimal example of the PHP code required to create shortcode with attributes" is <code> // [bartag foo="foo-value"] function bartag_func( $atts ) { extract( shortcode_atts( array( 'foo' =&gt; 'something', 'bar' =&gt; 'something else', ), $atts ) ); return "foo = {$foo}"; } add_shortcode( 'bartag', 'bartag_func' ); </code> You can find more detailed information on creating shortcodes in the above referenced documentation.
how to write short code in word press
wordpress
I'm trying to hide the overflow in CSS for specific template pages but can't seem to get it to work - I know that template pages are prefixed with a class but this doesn't seem to help targeting. I think I could use the is_page_template() function to hide the overflow with JS but this should be simpler with CSS. So this works... <code> html { overflow: hidden; } </code> but this doesn't work... <code> html .page-template-showreel-php { overflow: hidden; } </code> Any ideas why? Surely this should be possible with CSS.
This: <code> html .page-template-showreel-php { overflow: hidden; } </code> ...will target <code> body.page-template-showreel-php </code> . So, two questions: Do you have the <code> &lt;?php body_class(); ?&gt; </code> template tag inside of the <code> &lt;body&gt; </code> HTML tag? Is hiding overflow on the <code> &lt;body&gt; </code> tag really what you're after, or do you need to target a descendant element? EDIT There is no semantic or programmatic reason that you can't re-use the <code> &lt;?php body_class(); ?&gt; </code> template tag inside the <code> &lt;html&gt; </code> tag also. So, you might consider: <code> &lt;html &lt;?php body_class(); ?&gt;&gt; </code> and then: <code> html.page-template-showreel-php { overflow: hidden; } </code> Worth a shot...
Hide Overflow on a Specific WordPress Template
wordpress
I have a custom taxonomy filter that will filter all the pages in the selected taxonomy. I would like the code to select the pages in that taxonomy, and the children of thous pages. Heres the code. <code> add_action('restrict_manage_posts', 'restrict_manage_posts_section'); function restrict_manage_posts_section() { global $post_type; if ( is_object_in_taxonomy( $post_type, 'section' ) ) { $dropdown_options = array( 'show_option_all' =&gt; __( 'View all sections' ), 'hide_empty' =&gt; 0, 'hierarchical' =&gt; 1, 'name' =&gt; 'section', 'show_count' =&gt; 0, 'taxonomy' =&gt; 'section', 'orderby' =&gt; 'name', 'selected' =&gt; $cat ); add_filter('wp_dropdown_cats', 'wp_dropdown_section_filter', 10); wp_dropdown_categories( $dropdown_options ); remove_filter('wp_dropdown_cats', 'wp_dropdown_section_filter', 10); } } function wp_dropdown_section_filter($select) { $terms = get_terms('section', array('hide_empty' =&gt; false)); foreach( $terms as $term ) { $select = str_replace('value="'.$term-&gt;term_id.'"', 'value="'.$term-&gt;slug.'"', $select); if (isset($_GET['section']) &amp;&amp; $term-&gt;slug == $_GET['section']){ $select = str_replace('value="'.$term-&gt;slug.'"', 'value="'.$term-&gt;slug.'" selected', $select); } } return $select; } </code> EDIT Here is my Custom Post Type and Taxonomy Function <code> /* Register Custom Post Type and Taxonomy ---------------------------------------------------*/ add_action('init', 'register_module_type'); function register_module_type() { $labels = array( 'name' =&gt; _x('Modules', 'post type general name'), 'singular_name' =&gt; _x('Modules', 'post type singular name'), 'add_new' =&gt; _x('Add Module', 'module item'), 'add_new_item' =&gt; __('Add Module'), 'edit_item' =&gt; __('Edit Module'), 'new_item' =&gt; __('New Module'), 'view_item' =&gt; __('View Module'), 'search_items' =&gt; __('Search Module'), 'not_found' =&gt; __('Nothing found'), 'not_found_in_trash' =&gt; __('Nothing found in Trash'), 'parent_item_colon' =&gt; '' ); $args = array( 'labels' =&gt; $labels, 'public' =&gt; true, 'publicly_queryable' =&gt; true, 'show_ui' =&gt; true, 'query_var' =&gt; true, 'rewrite' =&gt; array( 'slug' =&gt; 'module', 'with_front' =&gt; false ), 'capability_type' =&gt; 'post', 'hierarchical' =&gt; true, 'has_archive' =&gt; true, 'can_export' =&gt; true, 'menu_position' =&gt; null, 'supports' =&gt; array('title','editor','thumbnail',/*'excerpt',*/'revisions','custom-fields','post-formats'/*,'page-attributes'*/) #'taxonomies' =&gt; array('category', 'post_tag') ); register_post_type( 'module' , $args ); #register_taxonomy_for_object_type('category', 'testimonial'); #register_taxonomy_for_object_type('post_tag', 'testimonial'); $labels = array( 'name' =&gt; _x( 'Sections', 'taxonomy general name' ), 'singular_name' =&gt; _x( 'Section', 'taxonomy singular name' ), 'search_items' =&gt; __( 'Search Sections' ), 'all_items' =&gt; __( 'All Sections' ), 'parent_item' =&gt; __( 'Parent Section' ), 'parent_item_colon' =&gt; __( 'Parent Section:' ), 'edit_item' =&gt; __( 'Edit Section' ), 'update_item' =&gt; __( 'Update Section' ), 'add_new_item' =&gt; __( 'Add New Section' ), 'new_item_name' =&gt; __( 'New Section Name' ), ); register_taxonomy( 'section', array( 'module' ), array( 'hierarchical' =&gt; true, 'labels' =&gt; $labels, 'show_ui' =&gt; true, 'query_var' =&gt; true, 'rewrite' =&gt; array( 'slug' =&gt; 'section' ), )); #add_theme_support( 'post-formats', array( 'chat','aside','gallery','link','image','quote','status','video' )); flush_rewrite_rules( false ); } </code>
This hooks into the update action for any post. It'll copy all terms for a given set of taxonomies from a parent to it's children. <code> /** * Update all children of a post with the same terms as itself. * * @param int $post_ID * @param object $post */ function __update_children_with_terms( $post_ID, $post ) { global $wpdb; // array of taxonomies to be copied to children, if the post type supports it $taxonomies = array( 'section' ); if ( ! is_post_type_hierarchical( $post-&gt;post_type ) ) return; // bail // all child IDs for current post $children = $wpdb-&gt;get_col( "SELECT ID FROM $wpdb-&gt;posts WHERE post_parent = " . ( int ) $post_ID ); // loop over each taxonomy for the current post type foreach ( get_object_taxonomies( $post-&gt;post_type ) as $taxonomy ) { if ( ! in_array( $taxonomy, $taxonomies ) ) continue; // bail, term copy not supported for this tax if ( ! $terms = wp_get_object_terms( $post_ID, $taxonomy, array( 'fields' =&gt; 'ids' ) ) ) continue; // bail, no terms for this tax // essential, otherwise wp_set_object_terms treats them as strings and creates new terms! $terms = wp_parse_id_list( $terms ); // loop over children and append the terms foreach ( $children as $child ) { wp_set_object_terms( $child, $terms, $taxonomy, true ); // this will rescursively iterate down the tree but at a cost!! // remove it if you only need parent =&gt; direct child copying wp_update_post( array( 'ID' =&gt; ( int ) $child ) ); } } } add_action( 'wp_insert_post', '__update_children_with_terms', 10, 2 ); </code> Note the last line of the inner <code> foreach </code> loop - if you only have <code> Top Level Parent =&gt; Children </code> , and not <code> Parent =&gt; Child =&gt; Grandchild </code> , I highly recommend removing the following line; <code> wp_update_post( array( 'ID' =&gt; ( int ) $child ) ); </code> It's a recursive situation, that will loop over children and run the same process, continuing to iterate until the whole tree has been processed.
Taxonomy filter all children
wordpress
I'm trying (but failing) to create 'Best Sellers' and 'New Releases' pages for my website. I'm using WP-Ecommerce 3.8.4 with WP 3.1.3 and I've gotten close but can't seem to get it right. Any help on this would be greatly appreciated... I've added the following code to wp-ecommerce> wpsc-includes> product-template.php (original code from here ): <code> //Popular products function function popular_products ( $atts ) { //Expose the Db to the function global $wpdb; //Get the results $pp = $wpdb -&gt; get_results ( "SELECT prodid, SUM(quantity) FROM {$wpdb-&gt;prefix}wpsc_cart_contents GROUP BY prodid ORDER BY quantity DESC LIMIT {$atts['limit']}", ARRAY_A); //Loop through the results foreach ( $pp as $item ) { //Output it ?&gt; &lt;img alt="&lt;?php echo wpsc_the_product_title ( null, null, $item['prodid'] )?&gt;" src="&lt;?php echo wpsc_the_product_thumbnail ( null, null, $item['prodid'] )?&gt;" /&gt; &lt;?php echo wpsc_the_product_title ( $item['prodid'] )?&gt; &lt;?php } } add_shortcode ( 'dm_popular', popular_products ); //END OF POPULAR PRODUCTS </code> I've then added [dm_popular limit=5] to the best sellers page (http://www.iconiccanvasart.co.uk/best-sellers) but as you can see it's not quite working properly: one product can appear multiple times if it's been ordered in different variations. it isn't retrieving the Products title properly (all are outputted as 'Best Sellers'). Ditto for the image Alt tags. I've not added a URL to the products yet as not sure how to at the moment. Once I've this working I'm hoping to alter slightly and have a 'New Releases' page based on a similar query (so any help on this may help to killing two birds with one stone). Any help would be greatly appreciated. ChainsawDR EDIT: I've since managed to get this all working bar the price and product text - final code can be viewed here: http://getshopped.org/forums/topic/bestselling-products/
<code> wpsc_the_product_title </code> is just a wrapper for <code> get_the_title </code> , and it doesn't take any arguments . Call <code> setup_postdata( $item['prodid'] ) </code> at the start of your <code> foreach </code> loop, and then the function should perform as expected.
How to show Best Selling WP E-Commerce Products
wordpress
I am very new to wordpress . I want to edit a wordpress theme and remove the blogpost area from it so it can be converted into a website. I also want to make some other changes. How I am trying to do it is, " I viewed the HTML code of my page and pasted in Dreamweaver and edited it. Now I am stuck with how to upload it." Please help me out. If there is a better way to do it please suggest. Thanks
Thats not really an ideal way to do it (and will bring all kinds of problems), what your real aim is, is to make wordpress into a CMS this way you can manage it as website from the wp-admin panel, add new pages etc, etc, the link i have added is just to give you an idea of whats involved, there are other Wordpress to CMS tutorials out there that will also help you.
How to Use WordPress as Static CMS Without Blog Posts
wordpress
The following functions.php edit (contributed by helgatheviking on the themeshaper forums) allows the use of a "Read More" link with custom excerpts. My problem is simply this: I'm inept at editing functions.php code, but I'd like to safely remove the "wrap excerpt in p tag" portion of this script. How would I do so? Thanks. Original script is found here: http://themeshaper.com/forums/topic/enclosing-excerpt-in-paragraph-tag-038-adding-a-custom-read-more-link <code> // excerpt read more links and wrap excerpt in p tag function all_excerpts_get_more_link($post_excerpt) { return '&lt;p&gt;' . $post_excerpt . '&lt;/p&gt;' . '&lt;p class="readmore"&gt;&lt;a href="'. get_permalink($post-&gt;ID) . '"&gt;' . 'Continue Reading &amp;raquo' . '&lt;/a&gt;&lt;/p&gt;'; } add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link'); </code>
This should remove the <code> &lt;p&gt; </code> tags, but leave the styling by replacing the paragraph tag with a <code> &lt;span&gt; </code> class: <code> function all_excerpts_get_more_link($post_excerpt) { return '' . $post_excerpt . '' . '&lt;span class="readmore"&gt;&lt;a href="'. get_permalink($post-&gt;ID) . '"&gt;' . 'Continue Reading &amp;raquo' . '&lt;/span&gt;'; } add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link'); </code>
Using "Read More" link with custom excerpt
wordpress
Basically I want to achieve a glossary using custom post types and have some issues setting up rewrites the way I want them to be. I want it like that: The main glossary URL: <code> http://example.com/glossary/ </code> Glossary terms starting with letter A : <code> http://example.com/glossary/a/ </code> The URL for a single glossary term: <code> http://example.com/glossary/a/atomic/ </code> I actually achieved this using the code below but I'm sure that it's a very awkward way to do it and I know it's malfunctioning somewhere as the wrong templates are called when viewing the pages. Except for http://example.com/glossary/, where archive-sumo-glossary-term.php gets called as expected, the other two just activate index.php in my theme. Here goes ( <code> functions.php </code> in the theme): <code> add_action('init', 'create_glossary'); function create_glossary() { register_post_type ( 'sumo-glossary-term', array ( 'labels' =&gt; array ( 'name' =&gt; _x('Glossary Terms', 'post type general name'), 'singular_name' =&gt; _x('Glossary Term', 'post type singular name') # And so on … ), 'supports' =&gt; array('title', 'editor', 'thumbnail'), 'public' =&gt; true, 'rewrite' =&gt; array ( 'slug' =&gt; 'glossary', 'with_front' =&gt; false ), 'query_var' =&gt; 'glossary-term', 'has_archive' =&gt; true ) ); register_taxonomy ( 'sumo-glossary-letter', 'sumo-glossary-term', array ( 'hierarchical' =&gt; true, 'labels' =&gt; array ( 'name' =&gt; _x('Letters', 'taxonomy general name'), 'singular_name' =&gt; _x('Letter', 'taxonomy singular name') # And so one ), 'show_ui' =&gt; true, 'query_var' =&gt; 'glossary-letter', 'rewrite' =&gt; false ) ); } add_filter('post_type_link', 'glossary_term_permalink', 10, 4); function glossary_term_permalink($post_link, $post, $leavename, $sample) { if ($post-&gt;post_type == 'sumo-glossary-term') { $permalink = str_replace('glossary/', 'glossary/' . $post-&gt;post_name[0] . '/', $post_link); } return $permalink; } add_rewrite_rule('^glossary/([^/]*)?$','index.php?glossary-letter=$matches[1]','top'); add_rewrite_rule('^glossary/([^/]*)/([^/]*)?$','index.php?glossary-term=$matches[2]','top'); </code>
You can always override the template that will be called with the <code> template_include </code> or a related filter, but this might hide deeper problems with custom archives. As I understand it, you want to use the following structure: <code> /glossary/ </code> should be an archive page for all <code> sumo-glossary-term </code> posts <code> /glossary/[letter]/ </code> should be an archive page for posts with the taxonomy term <code> [letter] </code> in the <code> sumo-glossary-letter </code> taxonomy <code> /glossary/[letter]/[term-name]/ </code> should be an individual <code> sumo-glossary-term </code> post This means that the first will load the template <code> archive-sumo-glossary-term.php </code> , the second will load <code> taxonomy-sumo-glossary-letter.php </code> , and the third will load <code> single-sumo-glossary-term.php </code> . I achieved this in WordPress 3.2 by explicitly setting the taxonomy rewrite slug, and both the rewrite slug and the archive slug for the post type, and no other rewrite rules. Also, I registered the taxonomy first and the post type after it, to make sure the priorities were right (otherwise a URL like <code> /glossary/f/page/2 </code> goes to glossary term <code> page </code> instead of page 2 of glossary letter <code> f </code> ). <code> add_action('init', 'create_glossary'); function create_glossary() { register_taxonomy ( 'sumo-glossary-letter', array(), array ( 'hierarchical' =&gt; true, 'labels' =&gt; array ( 'name' =&gt; _x('Letters', 'taxonomy general name'), 'singular_name' =&gt; _x('Letter', 'taxonomy singular name') # And so one ), 'show_ui' =&gt; true, 'query_var' =&gt; 'glossary-letter', 'rewrite' =&gt; array( 'slug' =&gt; 'glossary', ), ) ); register_post_type ( 'sumo-glossary-term', array ( 'labels' =&gt; array ( 'name' =&gt; _x('Glossary Terms', 'post type general name'), 'singular_name' =&gt; _x('Glossary Term', 'post type singular name') # And so on … ), 'supports' =&gt; array('title', 'editor', 'thumbnail'), 'public' =&gt; true, 'rewrite' =&gt; array ( 'slug' =&gt; 'glossary/%sumo-glossary-letter%', 'with_front' =&gt; false ), 'query_var' =&gt; 'glossary-term', 'has_archive' =&gt; 'glossary', 'taxonomies' =&gt; array( 'sumo-glossary-letter' ), ) ); } add_filter('post_type_link', 'glossary_term_permalink', 10, 4); function glossary_term_permalink($post_link, $post, $leavename, $sample) { if ( false !== strpos( $post_link, '%sumo-glossary-letter%' ) ) { $glossary_letter = get_the_terms( $post-&gt;ID, 'sumo-glossary-letter' ); $post_link = str_replace( '%sumo-glossary-letter%', array_pop( $glossary_letter )-&gt;slug, $post_link ); } return $post_link; } </code>
Mixing custom post type and taxonomy rewrite structures?
wordpress
I have a one column page for the home page where I have a mega menu and in side the site there is another page called about us where the mega menu is present but it is in small format just like it differs from the mega menu in width and height.So for home page I have used widget and now for about us page I want the small mega menu.So can any one tell me how to do that.I heared about if(front_page()), so I am using this but nothing is happening.So please guide me.Thanks in advance.
you can use this, <code> &lt;?php if( is_front_page() ):?&gt; &lt;div class="home-page-menu"&gt; wp_nav_menu( array( 'container_class' =&gt; 'menu-header', 'theme_location' =&gt; 'primary' ) ); &lt;/div&gt; &lt;?php elseif; ?&gt; &lt;div class="inside-page-menu"&gt; wp_nav_menu( array( 'container_class' =&gt; 'menu-header', 'theme_location' =&gt; 'primary' ) ); &lt;/div&gt; &lt;?php endif; ?&gt; </code> Here, you should be change your CSS style for home-page-menu and inside-page-menu . for more details about this <code> is_front_page() </code> follow this link http://codex.wordpress.org/Function_Reference/is_front_page
menu in different page in different style
wordpress
This is what I'm trying to do: if number of posts is greater than 20 -> display link to another page (which shows all posts) if number of posts is less than 20 -> don't display the link So far I've been able to return the number of posts using <code> $count_posts = wp_count_posts('inventory'); $published_posts = $count_posts-&gt;publish; </code> but I don't know where to go from here, any suggestions?
If I remember right count of posts in category is stored persistently in category object. So use <code> get_category() </code> or variation of it and fetch the number out of object. Example code (not tested): <code> $category = get_category($id); $count = $category-&gt;category_count; if( $count &gt; $something ) { // stuff } </code>
Count how many posts in category, based on result display link or not
wordpress
I've refrained from asking this question for a couple weeks, as I wasn't completely certain what I wanted cleared up... think I got it. I'm in the process of putting together a plugin to run a somewhat complex portfolio feature for my new personal site. The need was for a reasonable number of custom fields for each portfolio item, a number of categories (illustration, web design etc) and a way to build relationships. I use those categories to populate a list which delivers data via user submitted ajax requests. I weighed several options for this and landed on what I knew - and specifically didn't use custom post types; really, the only reason was ignorance. I did read a number of articles on the subject, but it just wasn't clear to me how to accomplish my goals. At any rate - I've spent the last couple weekends building a plugin that creates three new tables, deals with CRUD from the admin pages, and controls ajax requests. And it works great, in fact, for the "multi" template (which just gathers categories of thumbnails). Then I started working on the "single" page (which would just be a template for the display of a single line item), and it dawned on me that to incorporate searching, comments, permalinks etc, I was going to have to do a lot of hacking to tie my custom data into the main wp system. At any rate. I've since come understand that I can, in fact, use custom post types to hold the portfolio line items, and a custom taxonomy to develop the set of terms I will need for categorization. I'm hoping someone can fill me in on some of the details that are still sticking (because the documentation on this subject is very thin, at best...). The code to create a custom post type seems pretty straightforward, as is the code for a custom taxonomy, but I am still unclear on a couple points: 1. Custom Fields How do I manage them? I have about 20 columns that I'm populating - I've read a few things stating they are created via meta boxes? What table is that data actually stored in? wp-posts? 2: Custom Terms I understand how to create a custom taxonomy, but how do I go about linking my custom post type with that taxonomy? How do I filter a query for this taxonomy to populate the front-facing ajax drop-down selector? Are there plugins that can make this easier? I'm planning on coding everything at this point. Finally, given the scope of my project, are custom post types appropriate for what I'm trying to do ? Does it make sense to scrap what I've already put together? Honestly - this is my first attempt at a plugin, and I've learned quite a lot - but the addition of wp features like searching, comments, permalinks etc. all seem pretty attractive. I submit to the experts - Update How do I filter a query for this taxonomy to populate the front-facing ajax drop-down selector? Let me explain this more clearly. When the front-facing portfolio page is visited by a user, I run a query on all the available terms (currently this term data is from my non-wp, custom tables), and use those to populate either a drop-down selector, or just an unordered list. I hook into those elements to pass (in this case) ID values (categories like 'illustration' or 'web design') to an ajax sequence, which returns a json object containing sql results. I then build out thumbnails and other content for these items dynamically. The question then, is how do I structure a query to return custom post types based on terms from a custom taxonomy ? As long as I can return a json object from that query, I can just use my current ajax / js sequence as it stands. Thanks for the help -
How do I manage them? I have about 20 columns that I'm populating - I've read a few things stating they are created via meta boxes? The custom fields are more of a storage engine for meta data. It's up to you how to use them. And yes, meta boxes are common for that when you need nice way to input/edit them on post screen. What table is that data actually stored in? <code> *_postmeta </code> I understand how to create a custom taxonomy, but how do I go about linking my custom post type with that taxonomy? When you register taxonomy you pass object type(s) that it applies to. How do I filter a query for this taxonomy to populate the front-facing ajax drop-down selector? I am not sure what exactly you need here. Elaborate? Update how do I structure a query to return custom post types based on terms from a custom taxonomy? See: WP_Query > Taxonomy Parameters Advanced Taxonomy Queries Are there plugins that can make this easier? Yep, plenty. But if you are proficient enough to deal with that much code directly I recommend to at least try and do it natively first. There are plenty of awesome frameworks, plugins and other helper code for WordPress, but it is considerably hard to accurately research, evaluate and pick what will perfectly fit your needs in the long run. Finally, given the scope of my project, are custom post types appropriate for what I'm trying to do? Seems perfectly appropriate to me.
Custom post type's extra fields - how to handle?
wordpress
I am running Qtranslate for my website . I am very impressed by this plugin. Now my only problem is that I cannot set a custom title and description for my homepage per language. I can only setup one line for the title in the general settings for my website. I have installed Qtranslate META where I can set a custom title and description per page, but my only problem is the homepage. Any help would be realy appreciated how to fix this! Thanks
You have to use a static page in this case: Settings -> General -> Fron Page Display: A static Page
How to set a custom title per language?
wordpress
I was wondering how I could setup a taxonomy metabox on a post edit page that would be similar to the "tags" kind (with search field and automatic suggestions), but without the right to add a new term. So for example if I'm typign a word, I get suggestions of terms that I can use from the existing terms list, but if I type a word that doesn't exist, then it doesn't add the terms to the list. EDIT Actually, what I'm looking for is exactly the behavior of the "Search" functionality in the Menu Editor : As this is a core WP behavior, is there a way to use it on post edit pages too ? I'm wondering because these blocks look exactly the same, both have the "view all" and "most recent" tabs, but "search" is only present in the Menu Editor.
I came up with a solution for your first question. i.e the tax metabox that only suggests terms from existing terms list but does not allow you to add new terms. The solution is jQuery based and modifies the default behavior of the tags (i.e non heirarchical taxonomies) meta box. Limitation: Currently it only allows to add 1 term at a time, that is you can't add multiple existing terms as comma separated values. The code is also available as github's gist . I might do menu editor like metabox for taxonomy on next weekend. ;) the solution below can be used as plugin as can be used in your function.php file too. <code> &lt;?php /* Plugin Name: No new terms taxonomy meta box Plugin URI: https://gist.github.com/1074801 Description: Modifies the behavior of the taxonomy box, forbids user from selecting terms that don't belong to taxonomy. Author: Hameedullah Khan Author URI: http://hameedullah.com Version: 0.1 License: Do what ever you like, but don't publish it under your name without improving it. */ /* * For more information: stackexchange-url */ // currently works only with single taxonomy which should be defined here // default is the built-in post_tag define('CTM_TAXONOMY_NAME', 'post_tag'); function ctm_custom_tax_js() { // taxonomy name not defined or set to empty value if ( !defined('CTM_TAXONOMY_NAME') || !CTM_TAXONOMY_NAME ) { return; } ?&gt; &lt;script type="text/javascript"&gt; function ctm_custom_termadd_handler(event){ var tax = '&lt;?php echo CTM_TAXONOMY_NAME; ?&gt;'; var input = jQuery('#tagsdiv-&lt;?php echo CTM_TAXONOMY_NAME; ?&gt; input.newtag'); var q = input.val().split(','); // if there are more then two values, just add the first one // NOTE: because this solution does not support inserting multiple terms if (q.length &gt; 1) { q = jQuery.trim(q[0]); // as we don't support multiple terms // set the value of input box to the first term input.val(q); } jQuery.get( ajaxurl + '?action=ajax-tag-search&amp;tax=' + tax + '&amp;q=' + q, function(results) { var tokens = results.split('\n'); for (var i=0; i &lt; tokens.length; i++) { token = jQuery.trim(tokens[i]); if ( token &amp;&amp; token == q ) { (function($){ tagBox.flushTags( $('#tagsdiv-&lt;?php echo CTM_TAXONOMY_NAME; ?&gt;') ); })(jQuery); return true; } } } ); event.stopImmediatePropagation(); return false; } function ctm_custom_key_handler(event) { if (13 == event.which) { ctm_custom_termadd_handler(event); return false; } return true; } jQuery(document).ready(function() { // unbiind the click event from the taxonomy box jQuery('#tagsdiv-&lt;?php echo CTM_TAXONOMY_NAME; ?&gt; input.tagadd').unbind('click'); jQuery('#tagsdiv-&lt;?php echo CTM_TAXONOMY_NAME; ?&gt; input.newtag').unbind('keyup'); // hide the howto text for inserting multiple terms // NOTE: because this solution does not support inserting multiple terms jQuery('#tagsdiv-&lt;?php echo CTM_TAXONOMY_NAME; ?&gt; p.howto').hide(); // bind our custom handler jQuery('#tagsdiv-&lt;?php echo CTM_TAXONOMY_NAME; ?&gt; input.tagadd').click(ctm_custom_termadd_handler); jQuery('#tagsdiv-&lt;?php echo CTM_TAXONOMY_NAME; ?&gt; input.newtag').keyup(ctm_custom_key_handler); }); &lt;/script&gt; &lt;?php } add_action('admin_footer-post-new.php', 'ctm_custom_tax_js'); add_action('admin_footer-post.php', 'ctm_custom_tax_js'); ?&gt; </code> UPDATE: code updated to handle the return key as per @mike's comment.
How can I create a taxonomy meta-box with search suggestions but no new terms input?
wordpress
I have a series of posts, all with featured images, but I need to be able to customise the crop top right corner. In this instance, I need them to be cropped from top right, but it would be useful to also know how to position that point myself. At present, the add_image_size() function is taking its crop from the centre of the image. Not always pretty!!
Intermediate image generation is extremely rigid. <code> image_resize() </code> keeps it close to code and completely lacks hooks. Pretty much only option for this is to hook into <code> wp_generate_attachment_metadata </code> and overwrite WP-generated image with your own (which will need bit of a <code> image_resize() </code> fork). I need this for work so I might be able to share some code later. Ok, here is rough, but working example. Note that setting up crop in this way requires understanding of <code> imagecopyresampled() </code> . <code> add_filter('wp_generate_attachment_metadata', 'custom_crop'); function custom_crop($metadata) { $uploads = wp_upload_dir(); $file = path_join( $uploads['basedir'], $metadata['file'] ); // original image file list( $year, $month ) = explode( '/', $metadata['file'] ); $target = path_join( $uploads['basedir'], "{$year}/{$month}/".$metadata['sizes']['medium']['file'] ); // intermediate size file $image = imagecreatefromjpeg($file); // original image resource $image_target = wp_imagecreatetruecolor( 44, 44 ); // blank image to fill imagecopyresampled($image_target, $image, 0, 0, 25, 15, 44, 44, 170, 170); // crop original imagejpeg($image_target, $target, apply_filters( 'jpeg_quality', 90, 'image_resize' )); // write cropped to file return $metadata; } </code>
How can I make add_image_size() crop from the top?
wordpress
Asked this question on StackOverflow and they directed me over yonder... nice place ya got here =) I've been developing a pretty simple WordPress plugin, and wanted to do some live validation of certain fields on the page, which is where I am stuck. I've been looking everywhere for something that worked, and I simply can't make it function. I've been trying to get the ajax to function properly and I know I'm missing something obvious, I just can't figure it out. The main function file includes this to register my js file. <code> function on_screen_validation() { wp_enqueue_script( "field_validation", path_join(WP_PLUGIN_URL, basename( dirname( __FILE__ ) )."/field-validation.js"), array( 'jquery' ) ); } add_action( 'admin_print_scripts', 'on_screen_validation' ); </code> The js runs this code to capture the onblur command and pass the value to the php validation file. <code> jQuery(document).ready(function() { //run field validation on username on blur jQuery('.valusername').blur(function() { var usernameID = jQuery(this).attr('id'); var usernameVal = jQuery('#'+usernameID).val(); var thisFunction = 'validateUserName'; jQuery.post("mywebaddress...validation.php",{Function: thisFunction, thevars: usernameVal}, function(data) { alert(data); //would update validation message here }); }); }); </code> And the validation.php script looks like this: <code> if(isset($_POST['Function'])){ call_user_func($_POST['Function'], $_POST['thevars']); } function validateUserName($username){ if ( username_exists($username) ) { echo $username.' does exist'; } else { echo $username.' doesnt exist'; } } </code> Obviously I'm just using alerts for now to make sure the data is being checked properly. If I take out the WordPress username_exists function, and just echo back a string, it works fine. But with username_exists, it creates a 500 internal server error. I need to know how to get this external validation.php file to recongnise WordPress functions (I think), and nothing I've found so far will work. Thanks for reading... sorry for the long explanation I just wanted to make sure the context was all there so it made sense (I hope!)! Cheers, Matt
PLEASE!! PLEASE!! Don't send the php function names from your javascript. Below is the correct way of doing it. It might not be best way but at least secure way. To register your javascript (see the use of plugins_url instead of path_join), Also the validation is now part of your plugin, it does not have to go in separate validation.php: <code> function on_screen_validation() { wp_enqueue_script( "field_validation", plugins_url( "field-validation.js", __FILE__ ), array( 'jquery' ) ); wp_localize_script( "field_validation", "MySecureAjax", array( 'ajaxurl' =&gt; admin_url( 'admin-ajax.php' ) ) ); } add_action( 'admin_print_scripts', 'on_screen_validation' ); add_action( 'wp_ajax_UserNameValidation', 'validateUserName' ); function validateUserName() { $username = $_POST['thevars']; if ( username_exists($username) ) { echo $username.' does exist'; } else { echo $username.' doesnt exist'; } // Don't remove exit exit; } </code> You javascript part: <code> jQuery(document).ready(function() { //run field validation on username on blur jQuery('.valusername').blur(function() { var usernameVal = jQuery(this).val(); var action = 'UserNameValidation'; jQuery.post( MySecureAjax.ajaxurl, {action: action, thevars: usernameVal}, function(data) { alert(data); //would update validation message here }); }); }); </code> You can add nonce checking for further security and validation.
WordPress plugin admin page - using WordPress function in linked php file
wordpress
This is related to another question that I had asked earlier. I'm doing some rewrite code to create some custom permalinks for a custom post type. I think I'm getting it mostly working except I'm getting the following error: I noticed a few things: Whatever I have as the postname gets replaced in the url field as %postname% If I omit the post name, it loads up in WordPress no problem Here is the code to setup the rewrite: <code> add_action('init', 'setup_rewrites'); function setup_rewrites() { global $wp_rewrite; //Content add_rewrite_tag('%seriesname%','([^/]+)'); add_rewrite_tag('%contenttype%','([^/]+)'); $content_struct = '/content/%seriesname%/%contenttype%/%postname%'; add_permastruct('veda_content', $content_struct, false); } </code> an example url that doesn't work but should: http://watchonepiecelegally.com/content/one-piece/episode/test-1 A URL that does work: http://watchonepiecelegally.com/content/one-piece/episode/ What I get via Jan Fabry's Rewrite Analyzer plugin: This should work but I'm missing something. Can anyone give me a hand? EDIT: As requested, here are the rewrite rules Wordpress is generating. Hopefully this helps: <code> Array ( [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] [anime-series/.+?/attachment/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [anime-series/.+?/attachment/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [anime-series/.+?/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime-series/.+?/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime-series/.+?/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [anime-series/(.+?)/trackback/?$] =&gt; index.php?veda_series=$matches[1]&amp;tb=1 [anime-series/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_series=$matches[1]&amp;feed=$matches[2] [anime-series/(.+?)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_series=$matches[1]&amp;feed=$matches[2] [anime-series/(.+?)/page/?([0-9]{1,})/?$] =&gt; index.php?veda_series=$matches[1]&amp;paged=$matches[2] [anime-series/(.+?)/comment-page-([0-9]{1,})/?$] =&gt; index.php?veda_series=$matches[1]&amp;cpage=$matches[2] [anime-series/(.+?)(/[0-9]+)?/?$] =&gt; index.php?veda_series=$matches[1]&amp;page=$matches[2] [anime-release/[^/]+/attachment/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [anime-release/[^/]+/attachment/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [anime-release/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime-release/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime-release/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [anime-release/([^/]+)/trackback/?$] =&gt; index.php?veda_release=$matches[1]&amp;tb=1 [anime-release/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_release=$matches[1]&amp;feed=$matches[2] [anime-release/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_release=$matches[1]&amp;feed=$matches[2] [anime-release/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?veda_release=$matches[1]&amp;paged=$matches[2] [anime-release/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?veda_release=$matches[1]&amp;cpage=$matches[2] [anime-release/([^/]+)(/[0-9]+)?/?$] =&gt; index.php?veda_release=$matches[1]&amp;page=$matches[2] [anime-release/[^/]+/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [anime-release/[^/]+/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [anime-release/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime-release/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime-release/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [anime_video/[^/]+/attachment/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [anime_video/[^/]+/attachment/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [anime_video/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime_video/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime_video/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [anime_video/([^/]+)/trackback/?$] =&gt; index.php?veda_video=$matches[1]&amp;tb=1 [anime_video/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_video=$matches[1]&amp;feed=$matches[2] [anime_video/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_video=$matches[1]&amp;feed=$matches[2] [anime_video/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?veda_video=$matches[1]&amp;paged=$matches[2] [anime_video/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?veda_video=$matches[1]&amp;cpage=$matches[2] [anime_video/([^/]+)(/[0-9]+)?/?$] =&gt; index.php?veda_video=$matches[1]&amp;page=$matches[2] [anime_video/[^/]+/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [anime_video/[^/]+/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [anime_video/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime_video/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime_video/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [anime_purchase/[^/]+/attachment/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [anime_purchase/[^/]+/attachment/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [anime_purchase/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime_purchase/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime_purchase/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [anime_purchase/([^/]+)/trackback/?$] =&gt; index.php?veda_purchase=$matches[1]&amp;tb=1 [anime_purchase/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_purchase=$matches[1]&amp;feed=$matches[2] [anime_purchase/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_purchase=$matches[1]&amp;feed=$matches[2] [anime_purchase/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?veda_purchase=$matches[1]&amp;paged=$matches[2] [anime_purchase/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?veda_purchase=$matches[1]&amp;cpage=$matches[2] [anime_purchase/([^/]+)(/[0-9]+)?/?$] =&gt; index.php?veda_purchase=$matches[1]&amp;page=$matches[2] [anime_purchase/[^/]+/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [anime_purchase/[^/]+/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [anime_purchase/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime_purchase/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime_purchase/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [anime-review/[^/]+/attachment/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [anime-review/[^/]+/attachment/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [anime-review/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime-review/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime-review/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [anime-review/([^/]+)/trackback/?$] =&gt; index.php?veda_review=$matches[1]&amp;tb=1 [anime-review/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_review=$matches[1]&amp;feed=$matches[2] [anime-review/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_review=$matches[1]&amp;feed=$matches[2] [anime-review/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?veda_review=$matches[1]&amp;paged=$matches[2] [anime-review/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?veda_review=$matches[1]&amp;cpage=$matches[2] [anime-review/([^/]+)(/[0-9]+)?/?$] =&gt; index.php?veda_review=$matches[1]&amp;page=$matches[2] [anime-review/[^/]+/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [anime-review/[^/]+/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [anime-review/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime-review/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [anime-review/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [subtitle_language/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_subtitle_language=$matches[1]&amp;feed=$matches[2] [subtitle_language/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_subtitle_language=$matches[1]&amp;feed=$matches[2] [subtitle_language/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?veda_subtitle_language=$matches[1]&amp;paged=$matches[2] [subtitle_language/([^/]+)/?$] =&gt; index.php?veda_subtitle_language=$matches[1] [audio_language/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_audio_language=$matches[1]&amp;feed=$matches[2] [audio_language/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_audio_language=$matches[1]&amp;feed=$matches[2] [audio_language/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?veda_audio_language=$matches[1]&amp;paged=$matches[2] [audio_language/([^/]+)/?$] =&gt; index.php?veda_audio_language=$matches[1] [genre/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_genre=$matches[1]&amp;feed=$matches[2] [genre/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_genre=$matches[1]&amp;feed=$matches[2] [genre/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?veda_genre=$matches[1]&amp;paged=$matches[2] [genre/([^/]+)/?$] =&gt; index.php?veda_genre=$matches[1] [studio/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_studio=$matches[1]&amp;feed=$matches[2] [studio/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_studio=$matches[1]&amp;feed=$matches[2] [studio/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?veda_studio=$matches[1]&amp;paged=$matches[2] [studio/([^/]+)/?$] =&gt; index.php?veda_studio=$matches[1] [content_type/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_content_type=$matches[1]&amp;feed=$matches[2] [content_type/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_content_type=$matches[1]&amp;feed=$matches[2] [content_type/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?veda_content_type=$matches[1]&amp;paged=$matches[2] [content_type/([^/]+)/?$] =&gt; index.php?veda_content_type=$matches[1] [publisher/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_publisher=$matches[1]&amp;feed=$matches[2] [publisher/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_publisher=$matches[1]&amp;feed=$matches[2] [publisher/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?veda_publisher=$matches[1]&amp;paged=$matches[2] [publisher/([^/]+)/?$] =&gt; index.php?veda_publisher=$matches[1] [release_type/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_release_type=$matches[1]&amp;feed=$matches[2] [release_type/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_release_type=$matches[1]&amp;feed=$matches[2] [release_type/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?veda_release_type=$matches[1]&amp;paged=$matches[2] [release_type/([^/]+)/?$] =&gt; index.php?veda_release_type=$matches[1] [release_rating/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_rating=$matches[1]&amp;feed=$matches[2] [release_rating/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_rating=$matches[1]&amp;feed=$matches[2] [release_rating/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?veda_rating=$matches[1]&amp;paged=$matches[2] [release_rating/([^/]+)/?$] =&gt; index.php?veda_rating=$matches[1] [video_source/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_video_source=$matches[1]&amp;feed=$matches[2] [video_source/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_video_source=$matches[1]&amp;feed=$matches[2] [video_source/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?veda_video_source=$matches[1]&amp;paged=$matches[2] [video_source/([^/]+)/?$] =&gt; index.php?veda_video_source=$matches[1] [retailer/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_retailer=$matches[1]&amp;feed=$matches[2] [retailer/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?veda_retailer=$matches[1]&amp;feed=$matches[2] [retailer/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?veda_retailer=$matches[1]&amp;paged=$matches[2] [retailer/([^/]+)/?$] =&gt; index.php?veda_retailer=$matches[1] [content/[^/]+/[^/]+/[^/]+/attachment/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [content/[^/]+/[^/]+/[^/]+/attachment/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [content/[^/]+/[^/]+/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [content/[^/]+/[^/]+/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [content/[^/]+/[^/]+/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [content/([^/]+)/([^/]+)/([^/]+)/trackback/?$] =&gt; index.php?seriesname=$matches[1]&amp;contenttype=$matches[2]&amp;name=$matches[3]&amp;tb=1 [content/([^/]+)/([^/]+)/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?seriesname=$matches[1]&amp;contenttype=$matches[2]&amp;name=$matches[3]&amp;feed=$matches[4] [content/([^/]+)/([^/]+)/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?seriesname=$matches[1]&amp;contenttype=$matches[2]&amp;name=$matches[3]&amp;feed=$matches[4] [content/([^/]+)/([^/]+)/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?seriesname=$matches[1]&amp;contenttype=$matches[2]&amp;name=$matches[3]&amp;paged=$matches[4] [content/([^/]+)/([^/]+)/([^/]+)(/[0-9]+)?/?$] =&gt; index.php?seriesname=$matches[1]&amp;contenttype=$matches[2]&amp;name=$matches[3]&amp;page=$matches[4] [content/[^/]+/[^/]+/[^/]+/([^/]+)/?$] =&gt; index.php?attachment=$matches[1] [content/[^/]+/[^/]+/[^/]+/([^/]+)/trackback/?$] =&gt; index.php?attachment=$matches[1]&amp;tb=1 [content/[^/]+/[^/]+/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [content/[^/]+/[^/]+/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?attachment=$matches[1]&amp;feed=$matches[2] [content/[^/]+/[^/]+/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$] =&gt; index.php?attachment=$matches[1]&amp;cpage=$matches[2] [content/([^/]+)/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?seriesname=$matches[1]&amp;contenttype=$matches[2]&amp;feed=$matches[3] [content/([^/]+)/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?seriesname=$matches[1]&amp;contenttype=$matches[2]&amp;feed=$matches[3] [content/([^/]+)/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?seriesname=$matches[1]&amp;contenttype=$matches[2]&amp;paged=$matches[3] [content/([^/]+)/([^/]+)/?$] =&gt; index.php?seriesname=$matches[1]&amp;contenttype=$matches[2] [content/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?seriesname=$matches[1]&amp;feed=$matches[2] [content/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] =&gt; index.php?seriesname=$matches[1]&amp;feed=$matches[2] [content/([^/]+)/page/?([0-9]{1,})/?$] =&gt; index.php?seriesname=$matches[1]&amp;paged=$matches[2] [content/([^/]+)/?$] =&gt; index.php?seriesname=$matches[1] [robots\.txt$] =&gt; index.php?robots=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})/([^/]+)(/[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})/comment-page-([0-9]{1,})/?$] =&gt; index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;cpage=$matches[3] [([0-9]{4})/comment-page-([0-9]{1,})/?$] =&gt; index.php?year=$matches[1]&amp;cpage=$matches[2] [.+?/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> %seriesname% is a slug that coincides with the parent of the post. %contenttype% coincides with a custom taxonomy. The idea was that if the %postname% tag was omitted, those two other tags could be used to create an archive page. EDIT: Making progress. As noted in the discussion in the comments, using the builtin %postname% tag with a custom permastruct seems to be the cause of my 400 Bad Request Errors. Hopefully this should narrow down what the problem seems to be.
Okay, I feel stupid. I needed to translate %postname%. I thought it did so automatically since the admin page looked like it had but apparently if you do use custom permastructs, you have to translate even the default tags. My solution: add this to my post_type_link filter: <code> $post = get_post($post_id); $permalink = str_replace('%postname%', $post-&gt;post_name, $permalink); </code> Problem solved.
Using %postname% tag with a Custom Permastruct creates 400 Bad Request Errors from the server
wordpress
I have a page that displays posts (4 on each row), with a thumbnail image &amp; title for each. Is it possible to click a text/icon link and dynamically switch the page template? I'm looking to provide an alternate view of the posts, perhaps with larger images, more text/custom fields added etc. I thought it would be easy just to link to another page template but it changes the url (would like the url to stay the same) and for some reason it loads the closest matching post, rather than the new page template (I have the page template nested within the first). Something like this domain.com/page/?view=list
I think I have a workable solution on what I was trying to do. This works but is there a better way? Also are there any implications I should be aware of when using $_GET? Didn't realize it would be this easy :) perhaps I'm missing something. <code> &lt;?php $view = $_GET["view"]; ?&gt; </code> Then if the URL is domain.com/page/?view=list I use an IF statement inside the loop to modify the markup as required: <code> &lt;?php if ( $view == "list" ) : ?&gt; // code here for list view &lt;?php else : ?&gt; // code here for normal default view &lt;?php endif; ?&gt; </code>
How can I dynamically load another page template to provide an alternate layout of the posts?
wordpress
I need to get a return from a query that provides me with email, username or nicename as well as post title based on author id. The query is to run once daily via cron and look for posts that have spent a specific live time before they come up for removal (the query is intended to run five days and then three days before post deletion). so far i have this which works (almost) via running manual queries in phpmyadmin. <code> SELECT ID, user_email, display_name, user_nicename FROM wp_users WHERE ID IN (SELECT post_author FROM wp_posts WHERE post_type = 'sales' AND HOUR( TIMEDIFF( NOW( ) , post_date_gmt ) ) &gt;=1) </code> alls well and good here, it returns success however what i now need to get is also the post_titles of all the posts due for expiry so that it can be added inside the $message part of the wp_mail. Im going to be honest with you i havent a clue about joining stuff. whether it needs left joins, outside joins or any other kind of join there maybe, the only info i seem to keep getting back from codex is this page Update <code> &lt;?php $emailusers = $wpdb-&gt;get_results("SELECT ID, user_email FROM $wpdb-&gt;users WHERE ID IN (SELECT post_author FROM $wpdb-&gt;posts WHERE post_type = 'sales' AND HOUR( TIMEDIFF( NOW( ) , post_date_gmt ) ) &gt;=1)"); foreach ($emailusers as $user) { // do wp_mail stuff from here } ?&gt; </code> Full working code below for anyone who is interested: <code> &lt;?php require_once 'wp-load.php'; global $wpdb; $emailusers = $wpdb-&gt;get_results("SELECT u.user_nicename, u.user_email, p.post_title, p.post_date FROM $wpdb-&gt;posts p INNER JOIN $wpdb-&gt;users u ON p.post_author = u.ID WHERE post_type = 'sales' OR post_type = 'rentals' OR post_type = 'business' AND HOUR( TIMEDIFF( NOW( ) , post_date_gmt ) ) &gt;=721"); foreach ($emailusers as $user) { $to = $user-&gt;user_email; $subject = $user-&gt;post_title; $message = 'You have a property listing that will auto expire in 3 days, the property is &lt;strong&gt;' . $user-&gt;post_title .'&lt;/strong&gt; and was listed on &lt;strong&gt;' . $user-&gt;post_date .'&lt;/strong&gt;' . "\r\n"; $headers .= "From: -------- &lt;www.------------.com&gt;" . "\r\n"; wp_mail( $user_email, $subject, $message, $headers); } ?&gt; </code> The code up above will notify the author @ 720 hours that they have 3 days remaining before the post is auto deleted. regards
<code> $emailusers = $wpdb-&gt;get_results( "SELECT p.ID AS post_id, p.post-title, u.user_email " . "FROM $wpdb-&gt;posts AS p " . "INNER JOIN $wpdb-&gt;users AS u ON p.post_author = u.ID " . "WHERE p.post_type = 'sales' AND HOUR( TIMEDIFF( NOW( ) , p.post_date_gmt ) ) &gt;=1)" ); foreach ($emailusers as $user) { // do wp_mail stuff from here // $emailusers-&gt;post_title; // $emailusers-&gt;user_email; // used 'post_id' alias rather than 'ID' so it's clear it's not the author ID // $emailusers-&gt;post_id; } </code>
Join inside a wpdb query.. confused!
wordpress
I'm using wp_dropdown_categories() to output a dropdown. In default view (without having clicked it) it shows the name of the first category in the list. I'd like it to say "Categories" . Is this possible? Thanks in advance
You can use the show_option_all argument: <code> &lt;?php $args = array( 'show_option_all' =&gt; 'Categories' ); wp_dropdown_categories( $args ); ?&gt; </code> Function Reference/wp dropdown categories
change default option in wp_dropdown_categories
wordpress