question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I'm using the up/down voting feature of this plugin and would like to not allow people to 'down vote'. So basically, if they like the post, they vote it up, and if not, they leave it how it is. Is something like this possible?
I just gave a quick look at the plugin and in my opinion it would be easier to tweak the way you use it rather than to tweak the code itself. What you want is basically already existing in the ' Rationg options ', it's the heart option that only allow the user to do a like, or 'up vote', which is just the same. You then just have to change the picture of the heart for the arrow one and then have a look at the 'Ratings template' to achieve what you need.
Any way to change WP-PostRatings so you can only vote up?
wordpress
I'm experiencing a somewhat endless loop in the file mo.php <code> /wp-includes/pomo/mo.php </code> when loading the site's default text domain. The PHP error is: <code> Fatal error: Maximum execution time of 30 seconds exceeded in ...\wp-includes\pomo\streams.php on line 62 </code> I can work around this by disabling the websites translation, but that's not really helpful. I've updated to the latest wordpress version and the latest version of the translation (de_DE). I'm somehow puzzled as I never had this problem. The last call in my backtrace consumes nearly 30 seconds. The Function call is: <code> POMO_Reader-&gt;substr( $string = '\000\n&lt;h1&gt;Error establishing a database connection&lt;/h1&gt;\n&lt;p&gt;This either means that the username and password information in your &lt;code&gt;wp-config.php&lt;/code&gt; file is incorrect or we can't contact the database server at &lt;code&gt;%s&lt;/code&gt;. This could mean your host's database server is down.&lt;/p&gt;\n&lt;ul&gt;\n\t&lt;li&gt;Are you sure you have the correct username and password?&lt;/li&gt;\n\t&lt;li&gt;Are you sure that you have typed the correct hostname?&lt;/li&gt;\n\t&lt;li&gt;Are you sure that the database server is running?&lt;/li&gt;\n&lt;/ul&gt;\n&lt;p&gt;If y...', $start = 71131, $length = 8 ) </code> Does anybody has a thought about that? I'm running on windows and the files served are on a network share. Never had problems with that setup.
I was able to fix the problem by switching the xdebug extension. I had a vc9-nts version installed and switched to vc6-nts which solved the issue.
POMO_Reader-> substr() call endless loop?
wordpress
I want to use jQuery UI tabs in my WordPress 3.1.4 pages. I write programming tutorials for a VB .NET audience but like to provide C# source as well, and I want to use the tabs to let the readers switch between the two. I could probably make my own given time, but this was supposed to be a "learn things about jQuery" project. It's turning out to be more of a "WTF WordPress" project. I'm barely functional in JS and trying to correct that. I'm no WP guru, and don't care to learn more than I need to know yet. I've got a page that is nothing but a copy/paste of the jQuery UI Tabs demo. It doesn't work; the list and all divs are visible and there's no actual tabs. I know this is because I need some CSS, but this is where I got exhausted. I'm not confident having the CSS will make it work anymore, and I don't even know how to tell if it's the CSS, my JS, or my WP that's the problem. Until I started this project my blog "just worked" and that's how I like my not-work things. The first thing I tried was putting the Google CDN for jQuery in my theme's header.php. I could get alerts working, but no matter what I did the tabs didn't show up. (I know now this is because I apparently needed some CSS. Thanks for not mentioning that jQuery documentation!) So I started doing some reasearch and realized that WP loads jQuery, as do many plugins (though I'm running only Spam Karma and Askimet.) It made sense that maybe loading the Google jQuery caused some confusion. After some research, I found several sites that suggested putting wp_enqueue_script() in my header. The documentation listed a bunch of scripts, so I added "jquery", "jquery-ui-core", and "jquery-ui-tabs". I can see a script tag loading jQuery (version 1.4.4...) in my header, but the other tags seem to have no effect. I understand it's loaded in "no conflict" mode so you use "jQuery()" when you'd normally use "$()". I can get alerts working but not the tabs. Again, I'm suspicious because it doesn't look like my page is trying to load jQuery UI at all. It probably wouldn't matter because I'm not sure if WP comes with the right CSS. I've seen a few pages that suggest I have to load jQuery UI in the page's footer, others that claim I need to add some stuff I don't understand to functions.php, and a couple of other solutions from articles too old to trust. I don't know what to try next. If I did some work to figure out what CSS I need (thanks again, jQuery "documentation"!) I could get tabs working on a local file. In WP, I'm using the TwentyTen theme; my only modifications have been to add the SyntaxHighlighter scripts (which I'll disable if someone can tell me I'm close enough it should be working and they may be the problem.) I just upgraded to WP 3.1.4 today. Here's the contents of relevant files, you can view source to see what the HTML looks like: header.php <code> &lt;?php wp_enqueue_script("jquery"); ?&gt; &lt;?php wp_enqueue_script("jquery-ui-core"); ?&gt; &lt;?php wp_enqueue_script("jquery-ui-tabs"); ?&gt; &lt;script type="text/javascript" src="http://www.owenpellegrin.com/blog/highlight/scripts/shCore.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://www.owenpellegrin.com/blog/highlight/scripts/shBrushCSharp.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://www.owenpellegrin.com/blog/highlight/scripts/shBrushVb.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://www.owenpellegrin.com/blog/highlight/scripts/shBrushXml.js"&gt;&lt;/script&gt; &lt;link type="text/css" rel="stylesheet" href="http://www.owenpellegrin.com/blog/highlight/styles/shCore.css"/&gt; &lt;link type="text/css" rel="stylesheet" href="http://www.owenpellegrin.com/blog/highlight/styles/shThemeDefault.css"/&gt; &lt;script type="text/javascript"&gt; SyntaxHighlighter.all(); &lt;/script&gt; &lt;meta charset="&lt;?php bloginfo( 'charset' ); ?&gt;" /&gt; &lt;title&gt;&lt;?php (... the rest of the default TwentyTen header.php ...) </code> the linked page <code> &lt;script&gt; jQuery("document").ready(function() { jQuery( "#tabs" ).tabs(); }); &lt;/script&gt; &lt;div id="tabs"&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#tabs-1"&gt;Nunc tincidunt&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#tabs-2"&gt;Proin dolor&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#tabs-3"&gt;Aenean lacinia&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div id="tabs-1"&gt; &lt;p&gt;Tab 1 content.&lt;/p&gt; &lt;/div&gt; &lt;div id="tabs-2"&gt; &lt;p&gt;Tab 2 content&lt;/p&gt; &lt;/div&gt; &lt;div id="tabs-3"&gt; &lt;p&gt;Tab 3 content&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; </code> I added the ready() call because I was curious if perhaps the code from the demo wasn't running. I've also tried this variant of the code with no joy: <code> jQuery("document").ready(function() { jQuery( "#tabs" ).tabs(); }); </code> What am I missing?
The short answer is that you need to include a jQuery UI CSS "Theme" with your code. The jQuery UI framework is actually a combination of JavaScript and CSS (and it looks like you've only included the JavaScript). As a quick test, I just applied the "Base" theme to your code here . (Notice on the sidebar, under Manage Resources, there's a link to a Google hosted jqueryui.css file). jQuery UI has a lot of pre-built themes you can use. (See the "Gallery" tab). Or you can roll your own! Pretty flexible. To lengthen my answer a bit... I'll recommend using Google's CDN instead of the built-in jQuery files for two reasons. You'll get newer versions It'll be faster But your research is correct... You don't want to simply include the jQuery CDN reference in your header because then WordPress doesn't know that you already included it! (And you'll get conflicts with other plugins that require jQuery). A simple solution is to add the following snippet of code in your functions.php file: <code> // custom script queues if (!is_admin()) { wp_deregister_script('jquery'); wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"), false); wp_enqueue_script('jquery'); } </code> This code basically tells WordPress to ignore its own version of jQuery, use the reference you have in here, and then queue it up! (Now if another plugin "requests" jQuery via the WordPress API, it'll know that it's already loaded and ready to go). Personally, I don't worry about doing this with jQuery UI. I've yet to use a plugin that specifically wants to queue it up on its own. So in my header.php I've just included it myself, along with a theme that I like: <code> &lt;link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/themes/cupertino/jquery-ui.css"/&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js"&gt;&lt;/script&gt; </code> Good luck with your project!
How do I use jQuery UI tabs in a WordPress page?
wordpress
I have created a widget that have to run some code using the wp_footer hook as well. But if you extend the WP_Widget, the wp_footer runs twice! Has someone already past for the same issue? Here is an example: <code> /* Plugin Name: Test Description: Test Plugin by Romulo De Lazzari Version: 1.0 Author: Romulo De Lazzari */ new Test(); class Test extends WP_Widget{ public function __construct(){ parent::__construct('test-widget', 'Test Widget'); add_action('widgets_init', array($this, 'register_my_widget')); add_action('wp_footer', array($this, 'do_something')); } public function register_my_widget(){ return register_widget("Test"); } public function do_something(){ echo "&lt;p&gt;Hello! This is a test!&lt;/p&gt;"; } public function widget($args, $instance) { } public function form($instance){ } public function update($new_instance, $old_instance){ } } </code> The method do_something() is running twice here, if I take off the "Widget part" it runs well. Could someone help me? Thanks in advance, Romulo
That code doesn't look like it conforms to the current Widgets API. Perhaps your problem is related? First potential issue: your class <code> test </code> should be <code> plugin-slug-test </code> , in order to avoid naming conflicts. Second potential issue: the only functions inside of your WP_Widget extending class should be: function plugin-slug-test() {} function widget( $args, $instance ) {} function update( $new_instance, $old_instance ) {} function form( $instance ) {} You need to move your <code> add_action() </code> calls outside of your Widget class. Third potential issue: why do you declare all of your Widget class functions to be public ? Fourth potential issue: I don't think you need to declare <code> new Test(); </code> for a Widget class.
wp_footer hook running twice
wordpress
I've got an <code> add_action </code> in functions.php, the action is for <code> save_post </code> and the function I'm running I've named set_attachment_url. I'm simply getting the first attachment on a post and setting a custom field with the URL of that attachment. Good news is, everything works great when I'm adding content from the wp-admin. But when I add content from the iOS app, I don't get the same results. I have to add the post, tap the post, click "update" and THEN it works. I don't know enough about the hooks and when each gets fired, although I'm learning quickly. Can anyone spot what the issue may be, why it's not working from iOS on insert, but on update it will. Here's the basics ... <code> add_action( 'save_post', 'set_attachment_url', 10, 1 ); // process the attachment url function set_attachment_url($post_id){ // get the post and status $my_post = get_post($post_id); $post_status = $my_post-&gt;post_status; // if we are publishing if($post_status == 'publish'){ // check custom field -- this is what tells us if we need to process this photo or not // if it does not have a photo_url then we need to work on it $photo_url = get_post_meta($post_id, 'photo_url', true); // if no length, we need to fill it if(!strlen($photo_url)){ // get the first attachment for this post $args = array( 'post_type' =&gt; 'attachment', 'numberposts' =&gt; 1, 'post_status' =&gt; null, 'post_parent' =&gt; $post_id ); $attachments = get_posts($args); // set the attachment ID and get the photo url $attachment_id = $attachments[0]-&gt;ID; $photo_url = wp_get_attachment_url($attachment_id); // update the custom field with the image source update_post_meta( $post_id, 'photo_url', $photo_url ); // set the featured image update_post_meta( $post_id, '_thumbnail_id', $attachment_id ); } } } </code>
the update post function actually calls the insert function so it should work, now I'm not sure but try changing: <code> if(!strlen($photo_url)){ </code> to: <code> if(empty($photo_url)){ </code> since php <code> strlen() </code> returns 0 on an empty string.
Post via wp-admin and via iOS app, same hooks and triggers involved?
wordpress
Why is my table row background image not appearing in Wordpress. Is the stylesheet for the theme suppressing it in some way and if so, how can one override that to make the image show, or is there some other fault causing it not to appear? Note the other image in the table does display properly so the path to the files seems to work ok. <code> &lt;table width="250" height="200" cellpadding="0" cellspacing="0" border="1"&gt; &lt;tr&gt; &lt;td WIDTH="250" HEIGHT="82" colspan="3"&gt;&lt;img src="/wp-content/plugins/xxxxxxwidget/image1.png"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="background-image:url(/wp-content/plugins/xxxxxxwidget/image2.png) no-repeat center;" WIDTH="250" HEIGHT="45" colspan="3"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code> Any suggestions?
What does Firebug or Chrome Developer Tools report on the rendered background image URL? Does it return a 404? Try changing this: <code> style="background-image:url(/wp-content/plugins/xxxxxxwidget/image2.png) </code> to this: <code> style="background-image:url(&lt;?php echo wp_plugins_dir(); ?&gt;/xxxxxxwidget/image2.png) </code>
Why is my table background image not showing in wordpress?
wordpress
Pretty much as the title says, I want to use the "link" button from the HTML mode in the Visual Mode in the WYSIWYG editor (the link/unlink in visual is to "advanced" for my liking). Is this possible without too much of a hassle?
Sorry, but no. :) You can't simply use the html-button in the wysiwyg-editor. Both are different programms and have nothing in common except for their location. You'd have to unregister the current buttons, write code for a new one (that fits your likings) and then add this one. You'll find hundreds of tutorials for adding buttons to tinyMCE both on google, as here in WPSE.
WYSIWYG – Getting the "link" button from HTML mode in Visual mode
wordpress
Just looking for a recommendation on the best plugin to allow javascript in a post or page.
Or, you could just give users the 'unfiltered_html' capability. This can be done with a plugin such as Capability Manager . Warning: don't allow untrusted users to insert random scripts into the post content. With JavaScript, they can steal HTTP cookies from other users, including yourself, giving them administrator rights, basically.
What's the best plugin for allowing javascript in a post or page?
wordpress
Is it only me or this is what's happening? I just want to get all posts starting from a certain offset, like 10. Instead I get all posts starting from the 0.
<code> posts_per_page =&gt; -1 </code> is equivalent to <code> 'nopaging' =&gt; true </code> , which basically means no LIMIT clause is used at all. The workaround is to set posts_per_page to a large number. This is a limitation of the LIMIT syntax itself: http://dev.mysql.com/doc/refman/5.0/en/select.html
WP_Query: offset ignored when posts_per_page is -1?
wordpress
I'm trying to delete around 250 posts at once, but the next page I am taken to displays the error: Request-URI Too Large The requested URL's length exceeds the capacity limit for this server Does Wordpress need to use a HTTP Post action to delete posts?
Thanks. I ended up deleting them through PHPMyAdmin. They were all in the same category.
Internal Server Error 414 - Request-URI Too Large
wordpress
I am a little confused, the Wordpress 2.8 Widget API reffers to WordPress version 2.8 or is refferred to API version? Should I use 2.8 Widget API for writing my WordPress 3.1.4 widget?
WordPress APIs usually refer to group of functions and concepts and are not versioned. Any versions refer to WP itself (or in some cases to bundled components, developed by third parties such as jQuery). In WordPress version 2.8 creating widgets was refactored from older code (which you shouldn't care about) to newer class-based code (which you should use). So it's not like it is exactly same as it was in 2.8 (likely it isn't) but approach is same since then.
Wordpress 2.8 Widget API is suitable for Worpress 3.1.4 plugins development?
wordpress
I am making a plugin and I have a bunch of different data types that I am creating edit pages for. I'd rather not have to create a separate function to add each one to the admin menus, since they're all using the same function to display their edit page. I have tried: <code> `add_submenu_page('upload_manage', "Programs", "Programs", 'manage_options', 'manage-data&amp;type=program', "manage_data");` </code> (note the <code> &amp;type=program </code> -- that's what I want to work). It adds the correct link that I was trying for to the admin submenu, but when I click the menu item, I get kicked out to the dashboard with the <code> &amp;C=1 </code> URL. Is there any way to do this? Or am I going to have to create 7 different functions that all call the same function to display the edit page.. i.e. <code> manage_programs </code> <code> manage_schedule </code> <code> manage_otherstuff </code> etc...?
Your menu slug (5th parameter) can't be the same across multiple pages, and it obviously can't have an &amp; in it, but you can have all the pages you want call the same callback function (the last param). <code> add_submenu_page('upload_manage', "Programs", "Programs", 'manage_options', 'manage-programs', "manage_data"); add_submenu_page('upload_manage', "Schedule", "Schedule", 'manage_options', 'manage-schedule', "manage_data"); </code> Then in the manage_data function, check the value of $_GET['page'] for the slug and act accordingly.
Is it possible to add an admin page using add_submenu_page() and pass a var in the query string?
wordpress
I am trying to render content generated by a php file in [jQuery Colorbox][1] through AJAX in my WordPress site. The PHP resides on the same server in the same domain. It works perfect when I run it on localhost but it's not working on the server. Here is the link to my site - http://shabdcreatives.com/portfolio The links themselves are not invalid, for example the following link works fine on its own: http://shabdcreatives.com/wp-content/plugins/catgrid/includes/CatGridPost.php?ID=33 I just won't open inside the colorbox. Also the php file I am trying to load is just a fragment and DOES NOT CONTAIN any or tags. I tried the colorbox support group but no replies from them yet This is the code in the CatGridPost.php file that i am calling in the colorbox.. i tried calling a plain text file too... it returned no error.. but the colorbox did not show its contents either <code> require_once("../../../../wp-blog-header.php"); $thepost = get_post($_GET["ID"]); $thecontent = $thepost-&gt;post_content; $thetitle = $thepost-&gt;post_title; $thelink = get_permalink($_GET["ID"]); ?&gt; &lt;div id="cg-post-container"&gt; &lt;div id="cg-post-title"&gt; &lt;a href="&lt;?php echo $thelink; ?&gt;"&gt;&lt;?php echo $thetitle; ?&gt;&lt;/a&gt; &lt;/div&gt; &lt;div id="cg-post-content"&gt; &lt;?php echo $thecontent; ?&gt; &lt;/div&gt; &lt;/div&gt; </code>
You should not load wp-blog-header.php yourself. Use <code> wp-admin/admin-ajax.php </code> instead, as described here: http://codex.wordpress.org/AJAX_in_Plugins
Colorbox ajax loading of outside HTML content works perfect on localhost but not on server
wordpress
When I echo get_permalink() in a function that's called from archive.php, it reflects the permalink of the last post that's assigned to the category. How can I echo the permalink of the category page instead?
Like so: <code> echo get_category_link( get_queried_object() ); </code>
What is the_permalink() on a category page?
wordpress
Is it possible to check if a custom field exists for a given post within the loop? For example, I'm using functions like <code> get_post_meta($post-&gt;ID, 'Company', true); </code> preceded by a <code> &lt;h4&gt; </code> tag, but I'd like to check to make sure that there is a value for the custom field "Company" before writing the <code> &lt;h4&gt; </code> . Is this possible?
The WP <code> get_ </code> methods are here to retrieve data, not to display them. You can easily check the var - containing the data - before adding your head tags: <code> $my_post_meta = get_post_meta($post-&gt;ID, 'Company', true); if ( ! empty ( $my_post_meta ) ) echo '&lt;h4&gt;'.$my_post_meta.'&lt;/h4&gt;'; </code>
Check if a specific custom field exists?
wordpress
I've been looking for a way to import videos from YouTube as posts in regular intervals. Preferably daily, weekly is fine too. For the past hour I've been playing with this plug-in: http://www.ternstyle.us/products/plugins/wordpress/wordpress-automatic-youtube-video-posts It offers the ability to post videos to Wordpress as posts, but only from channels, not playlists. I'd like the playlist functionality to dynamically import videos from multiple users. Is there any way I can alter this plug-in, or create a hacked method of accomplishing this?
It is possible, but you'll have to do a little work on your own (the Plugin is not needed). First, load the Zend GData Class . Second, you'll have to read trough here .
Importing YouTube Videos As Posts - From Playlists
wordpress
For some reason I can'g get pagination using previous_posts_link and next_posts_link working. Here is the code I have... <code> &lt;?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?&gt; &lt;?php // The Query $the_query = new WP_Query( array( 'post_type'=&gt;'article', 'posts_per_page'=&gt;2, 'orderby'=&gt;'date', 'paged'=&gt;$paged ) ); // The Loop while ( $the_query-&gt;have_posts() ) : $the_query-&gt;the_post(); if($the_query-&gt;current_post == 0 &amp;&amp; $paged == 1) : ?&gt; &lt;article class="latest"&gt; &lt;div class="summary"&gt; &lt;h4&gt;LATEST ARTICLE:&lt;/h4&gt; &lt;h2&gt;&lt;?=the_title(); ?&gt;&lt;/h2&gt; &lt;div class="entry-meta"&gt; &lt;?php proagent_posted_on(); ?&gt; &lt;/div&gt;&lt;!-- .entry-meta --&gt; &lt;div class="entry-content"&gt; &lt;?=get_the_content_limit(300, 'More'); ?&gt; &lt;/div&gt;&lt;!-- .entry-content --&gt; &lt;div class="entry-topics"&gt;&lt;?=get_the_term_list($post-&gt;ID , 'topics', 'Topics: ',', '); ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;?=the_post_thumbnail('feature-post-thumbnail'); ?&gt; &lt;/article&gt; &lt;?php else: ?&gt; &lt;article class="previous"&gt; &lt;?=the_post_thumbnail(); ?&gt; &lt;div class="summary"&gt; &lt;h2&gt;&lt;?=the_title(); ?&gt;&lt;/h2&gt; &lt;div class="entry-meta"&gt; &lt;?php proagent_posted_on(); ?&gt; &lt;/div&gt;&lt;!-- .entry-meta --&gt; &lt;div class="entry-content"&gt; &lt;?=get_the_content_limit(300, 'More'); ?&gt; &lt;/div&gt;&lt;!-- .entry-content --&gt; &lt;div class="entry-topics"&gt;&lt;?=get_the_term_list($post-&gt;ID , 'topics', 'Topics: ',', '); ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;/article&gt; &lt;?php endif; ?&gt; &lt;?php endwhile; ?&gt; &lt;nav id="nav-below" class="navigation"&gt; &lt;div class="alignleft"&gt;&lt;?php previous_posts_link('« Newer Articles') ?&gt;&lt;/div&gt; &lt;div class="alignright"&gt;&lt;?php next_posts_link('Older Articles »') ?&gt;&lt;/div&gt; &lt;/nav&gt;&lt;!-- #nav-below --&gt; </code> Also.. just noticed it works when I go to /articles/page/2 there is a link to /articles/ like there should be but from the /articles/ page there is no link to page 2.. WHY? PLEASE help if you can... this is driving me crazy. Thanks! mark.
The pagination works only, if the <code> paged </code> attribute in the the global <code> $wp_query </code> variable is set. You could store your query manually in this global or just use <code> query_posts() </code> instead of <code> new WP_Query() </code> . <code> &lt;?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $the_query = query_posts( array( 'post_type'=&gt;'article', 'posts_per_page'=&gt;2, 'orderby'=&gt;'date', 'paged'=&gt;$paged ) ); // ... ?&gt; </code> The function <code> query_posts() </code> will unset an existing <code> $wp_query </code> global, runs a new <code> WP_Query() </code> and stores the result again in the global <code> $wp_query </code> variable.
Pagination with custom post type not working
wordpress
I've set up a custom post type called 'properties'. These posts can be tagged with the custom taxonomies of 'area' and 'university'. I would like to be able to have a form with a drop-down for each tag. When the form is submitted I would like to go to the URL that displays the archive of those tags. Two questions really: What is the URL that will return the correct posts? How do you construct that URL with a form? For some reason I thought that this would be really easy but I just can't find a way to do it. Any help is much appreciated.
To understand how to do it you first need to know how the url query works or more specifically what query vars you need, so: <code> 'post_type' </code> - to filter by post types. <code> 'area' </code> - to filter by area taxonomy. <code> 'university' </code> - to filter by university taxonomy. so your url would look like: <code> // http://www.domain.com/?post_type=properties&amp;area=area_term&amp;university=university_term </code> Now that we know we create the form with the needed fields: <code> function display_area_university_filter_form(){ ?&gt; &lt;form method="post" action=""&gt; &lt;p&gt;&lt;label for="area_t"&gt;Area: &lt;/label&gt; &lt;select name="area_t"&gt;&lt;option value=""&gt;Select Area:&lt;/option&gt; &lt;?php $area_terms = get_categories('taxonomy=area'); if (isset($_POST['area_t'])){ foreach ($area_terms as $term) { $option = '&lt;option value="'.$term-&gt;slug.'"'; if ($_POST['area_t'] == $term-&gt;slug){ $option.= ' selected="selected"'; } $option .= '&gt;'.$term-&gt;name; $option .= '&lt;/option&gt;'; echo $option; } }else{ foreach ($area_terms as $term) { $option = '&lt;option value="'.$term-&gt;slug.'"'; $option .= '&gt;'.$term-&gt;name; $option .= '&lt;/option&gt;'; echo $option; } } ?&gt; &lt;/select&gt; &lt;/p&gt; &lt;p&gt;&lt;label for="area_t"&gt;University: &lt;/label&gt; &lt;select name="area_t"&gt;&lt;option value=""&gt;Select University:&lt;/option&gt; &lt;?php $uni_terms = get_categories('taxonomy=university'); if (isset($_POST['univer'])){ foreach ($uni_terms as $term) { $option = '&lt;option value="'.$term-&gt;slug.'"'; if ($_POST['univer'] == $term-&gt;slug){ $option.= ' selected="selected"'; } $option .= '&gt;'.$term-&gt;name; $option .= '&lt;/option&gt;'; echo $option; } }else{ foreach ($uni_terms as $term) { $option = '&lt;option value="'.$term-&gt;slug.'"'; $option .= '&gt;'.$term-&gt;name; $option .= '&lt;/option&gt;'; echo $option; } } ?&gt; &lt;/select&gt; &lt;/p&gt; &lt;input type="hidden" name="custom_filter" value="area_uni"&gt; &lt;p&gt;&lt;input type="submit" name="submit" value="submit"&gt;&lt;/p&gt; &lt;/form&gt; &lt;?php } </code> then all that is left is just processing it: <code> if (isset($_POST['submit']) &amp;&amp; isset($_POST['custom_filter']) &amp;&amp; $_POST['custom_filter'] == "area_uni"){ $url = get_bloginfo('url'); $area = $uni = ''; if (isset($_POST['area_t'])){ $area = '&amp;area='.$_POST['area_t']; } if (isset($_POST['univer'])){ $uni = '&amp;university='.$_POST['univer']; } $url .= '/?post_type=properties'.$area.$uni; wp_redirect( $url ); exit(); } </code>
How to go to tag archives using a form
wordpress
I think proxy based comments mostly spam. So what is the best way of determining proxy using comments ?
It's possible, but it's unlikely that you succeed for comment spammers (and how do you separate them from legitimate proxy users?): <code> $proxy = $_SERVER['HTTP_X_FORWARDED_FOR']; </code>
Is it possible to determine proxy based comments?
wordpress
Here's what I have in my sidebar.php: <code> &lt;aside id="sidebar"&gt; &lt;?php if ( is_user_logged_in() ) { echo '&lt;a href="/community"&gt;&lt;img id="visit-the-forums" src="'. bloginfo('template_url') . '/images/visit-the-forums.png" alt="Check out the Forums!" /&gt;&lt;/a&gt;' } else { echo '&lt;a href="/community"&gt;&lt;img id="join-the-forums" src="'. bloginfo('template_url') . '/images/join-the-forums.png" alt="Join the Forums!" /&gt;&lt;/a&gt;' } ?&gt; &lt;a id="side-ad"&gt; &lt;img src="&lt;?php bloginfo('template_url') ?&gt;/images/ipad-ad.png" alt="iPad 2 Giveaway!" /&gt; &lt;/a&gt; &lt;/aside&gt; </code> For some reason, it doesn't show (not even in the markup) for any of the pages. I've double-checked all of the other templates to make sure <code> &lt;?php get_sidebar(); ?&gt; </code> is included. Is there something wrong w/ the code above? Edit: I should note that the below works, that is, without the if/else statement. <code> &lt;aside id="sidebar"&gt; &lt;a href="/community"&gt;&lt;img id="join-the-forums" src="&lt;?php bloginfo('template_url') ?&gt;/images/join-the-forums.png" alt="Join the Forums!" /&gt;&lt;/a&gt; &lt;a id="side-ad"&gt; &lt;img src="&lt;?php bloginfo('template_url') ?&gt;/images/ipad-ad.png" alt="iPad 2 Giveaway!" /&gt; &lt;/a&gt; &lt;/aside&gt; </code>
Does the markup after <code> &lt;?php get_sidebar(); ?&gt; </code> show up? I would guess that this is a silent PHP error, as your lines within the if/else block do not end with semi-colons. :)
sidebar isn't showing, what's wrong w/ this code?
wordpress
I'd like to add a button the the WordPress editor's toolbar. When clicked, I want to open a modal dialog (exactly like what you get when you click the "Paste from Word" icon). This might be more than one question, so the first question I have is what code to I need to add to my theme's functions.php to place the button with a click event that opens a modal window similar to the Word dialog?
Here is a nice tutorial I've read http://www.garyc40.com/2010/03/how-to-make-shortcodes-user-friendly/ He as a great example and you cal also download the source files and get a better understanding That's how I added a custom button to the tinymce editor in my plugin simple TOC which you can also download , look at the code and get an even better understanding.
How can I add a custom button to the post editor toolbar?
wordpress
I'm developing a theme for a customer in which i need several versions of the same image. In my functions.php file i've added all the image sizes i need. For instance: <code> if ( function_exists( 'add_theme_support' ) ) { add_theme_support( 'post-thumbnails' ); } if ( function_exists( 'add_image_size' ) ) { add_image_size('frontpage-post-thumbnail', 192, 192,true ); add_image_size('listing-post-thumbnail', 670, 290,true ); add_image_size('preview-post-thumbnail', 640, 640,true ); add_image_size('preview-onepost-thumbnail', 480, 480,true ); add_image_size('preview-twopost-thumbnail', 240, 240,true ); add_image_size('page-single-thumbnail', 160,9999, false); } </code> Now, in my archive.php template, i need the "listing-post-thumbnail" version, but wordpress uses the original image instead. I've checked and the 670x290 version of the image exists in the same folder as the original. Here is the code in archive.php <code> &lt;figure&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" title="Access node: &lt;?php the_title(); ?&gt;"&gt; &lt;?php echo get_the_post_thumbnail($id, array(670,290)); ?&gt; &lt;/a&gt; &lt;/figure&gt; </code>
It turns out WP got confused because i used the settings> medias screen to also set the "medium" dimensions to 670x290. This redundance seems to disable entirely both the "medium" and the "listing-post-thumbnail" dimensions. Replacing the medium dimension values to 0 and then regenerating the thumbnails solved the issue. Thanks to those who tried to help!
custom image size not being fetched
wordpress
I'm working on a WordPress plugin and want to make sure that all text that is displayed is prepared for localization. I'm having trouble localizing the text that resides inside an array. For instance, I have the following code inside a class <code> var $control_type_default = array( array( 'key' =&gt; 'automatic', 'value' =&gt; 'Automatic' ) ); var $control_types = array( array( 'key' =&gt; 'manual', 'value' =&gt; 'Manual' ) ); function process_class_vars() { // Add default control type value to beginning of control types array $this-&gt;control_types = array_merge($this-&gt;control_type_default, $this-&gt;control_types); // Prepare values for localization $temp_array = array(); foreach ($this-&gt;control_types as $control_type_array =&gt; $values) { $temp_array[] = array( 'key' =&gt; $values['key'], 'value' =&gt; __($values['value'], 'my_plugin') ); } $this-&gt;control_type = $temp_array; } </code> Note that the "process_class_vars" function is called by the constructor. As you can see, I am attempting to pass the value in the array through the <code> __() </code> function (As a side note, I'm doing this with the function "process_class_vars" function instead of when I initially create the arrays because passing that function when I created the arrays initially threw an error). The problem is that when I run this through a .po generator, the "Automatic" and "Manual" string are completely missed. How can these values be processed correctly?
You can't do that, at least not from a GUI translation helper app, because these are set to pick up strings from standard functions like <code> __() </code> , <code> _e </code> etc, they can't read variables (including string variables) Instead try: <code> var $control_types = array( array( 'key' =&gt; 'manual', 'value' =&gt; __('Manual', 'yourtextdomain') ) ); </code> But if <code> $control_types </code> is a static variable from a class then you won't be able to assign the return value of a function as it's value. Why not make it a normal variable inside the process_class_vars() method? Or just make it a function: <code> public static function control_types(){ return array( 'manual' =&gt; __('Manual', 'yourtextdomain'), ... ) ); ... foreach ($this-&gt;control_types() as $control_type =&gt; $label) { // I'm pretty sure you don't need 'key' / and 'value' as key name here either... $temp_array[] = array( 'key' =&gt; $control_type, 'value' =&gt; $label, ); } </code>
Preparing a string in an array for localization
wordpress
I am trying to set cookies to re-route returning users to my a specific page within my Wordpress site. I'd like some advice with these 2 things: Where in the Wordpress php files should cookies be checked before loading any content to handle a redirect? Is there a good file this should exist in over others? How do I properly set a cookie within Wordpress? <code> setcookie('cookie_name', 'cookie_value', time()+4000); </code> doesn't seem to be saving any cookies to my system.
Ah, realized I needed to hook this into the <code> init() </code> . SOLUTION: I created a function in functions.php that would set and check the cookie. for this to work properly, after defining the function, outside the function call this: <code> add_action('init', 'function-name'); </code>
Setting custom cookies in Wordpress
wordpress
When I want to redirect the user after successful registration, I just use "registration_redirect" filter hook. How about when registration fails, which filter hook should I use? I looked into wp-login.php but I didn't see any filter/action hook that I could use. How do I go about this?
You could add an htaccess redirect or try out the theme my login plugin: http://wordpress.org/extend/plugins/theme-my-login/ . It has options for custom redirection.
Redirect to custom url when registration fails?
wordpress
I'm currently using some JS to pop open the WordPress Media Library in a thickbox container and return the URL of a selected image, then display it. <code> window.send_to_editor = function(html) { imgurl = jQuery('img',html).attr('src'); jQuery('#upload_image-' + id_to_pass).val(imgurl); output_code = '&lt;img class="media_display" src="' + imgurl + '" /&gt;'; jQuery(output_code).appendTo('#media_display-' + id_to_pass); tb_remove(); } </code> I was wondering if it's possible to return the attachment ID instead? I would like to use the image's description and caption fields, which I won't be able to do (easily) if I can only access the image URL from the Media Library.
Take a look at this http://sltaylor.co.uk/blog/hijacking-the-wordpress-media-library-overlay/
Using the WordPress Media Library and returning the Attachment ID rather than URL?
wordpress
I'm trying to setup a function in functions.php that removes an image from the post_content on save. Everything works up until the time I'm trying to save the content, the page just hangs and I get a '500 Internal Server' error. <code> function remove_post_image( $post_ID ){ // get the post $the_post = get_post($post_ID); // get the content of the post $post_content = $the_post-&gt;post_content; // replace any images $content = preg_replace("/&lt;img[^&gt;]+\&gt;/i", "", $post_content); // save the post $my_post = array(); $my_post['ID'] = $post_ID; $my_post['post_content'] = $content; // Update the post into the database wp_update_post( $my_post ); return $post_ID; } add_action('save_post', 'remove_post_image'); </code> I fear I'm missing something very basic. Can anyone spot something I'm doing wrong? edit Already I see how silly this was setup. I'm having success with the following, but still would like to know if this is the best way? I'm using content_save_pre action... <code> function remove_post_image( $content ){ // replace any images $content = preg_replace("/&lt;img[^&gt;]+\&gt;/i", "", $content); return $content; } add_action('content_save_pre', 'remove_post_image'); </code>
<code> content_save_pre </code> would be a much better hook for striping the images and as for setting post thumbnail as post Meta you can use <code> save_post </code> since the first hook gets fired before post Id is set and you need that for <code> update_post_meta </code> .
Remove image from post_content on save_post
wordpress
In Drupal you have the GUI to create whatever type you want. How about in WP, do I still have to code to create one?
Even though there are plugins to register Custom Post Types in WordPress, this is not the way it should be done. According to core developer Andrew Nacin, Custom Post Types should be implemented (in code) not registered (by clicks). This makes them more managable and easier to improve and further develop or hack. Also, code versioning is the way it goes.
How does WP custom post types fare compared to Drupal's?
wordpress
I have read a lot of turorials an even the codex widget API, but can't solve my doubts: What are the really difference writing WorPress 3.x widget plugins? if there exists. this doubt came when trying to create plugin containing an widget I have actived <code> WP_DEBUG </code> and saw the notice that <code> register_sidebar_widget() </code> is deprecated and I should use <code> wp_register_sidebar_widget() </code> instead. So I have changed and now I get: Notice: Uninitialized string offset: 0 in /.../wp-content/plugins/raz/index.php on line 54 Notice: Uninitialized string offset: 0 in /.../wp-content/plugins/raz/index.php on line 55 Notice: Uninitialized string offset: 0 in /.../wp-content/plugins/raz/index.php on line 55 Here is the code: <code> &lt;?php // widget to show an iframe containing Brazilian CPTEC weather forecast function previsao_tempo_cptec_widget_display($args) { // print some HTML for the widget to display here print $args['before_widget']; print $args['before_title'] . "Previsão IN TITLE do Tempo - CPTEC" . $args['after_title']; // print "content of the widget"; print '&lt;center&gt;&lt;!-- Widget Previs&amp;atilde;o de Tempo CPTEC/INPE --&gt;&lt;iframe allowtransparency="true" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" src="http://www.cptec.inpe.br/widget/widget.php?p=4599&amp;w=h&amp;c=909090&amp;f=ffffff" height="200px" width="215px"&gt;&lt;/iframe&gt;&lt;noscript&gt;Previs&amp;atilde;o de &lt;a href="http://www.cptec.inpe.br/cidades/tempo/4599"&gt;Santa Maria/RS&lt;/a&gt; oferecido por &lt;a href="http://www.cptec.inpe.br"&gt;CPTEC/INPE&lt;/a&gt;&lt;/noscript&gt;&lt;!-- Widget Previs&amp;atilde;o de Tempo CPTEC/INPE --&gt;&lt;/center&gt;'; print $args['after_widget']; } // Activate the sidebar wp_register_sidebar_widget( 'TempoCPTEC_1', 'Previsão de Tempo - CPTEC', 'previsao_tempo_cptec_widget_display', array( 'description' =&gt; "Este widget mostra a previsão de Tempo pelo CPTEC - INPE/BR" ), array( 'before_widget' =&gt; '&lt;li&gt;', 'after_widget' =&gt; '&lt;/li&gt;', 'before_title' =&gt; '&lt;h2 class="widgettitle"&gt;', 'after_title' =&gt; '&lt;/h2&gt;' ) ); // Loads the widget add_action('widgets_init','previsao_tempo_cptec_widget_display'); ?&gt; </code> Other doubt, why this widget is always displayed in the top of my website and in the sidebar widgets also? Thanks for any incoming handy answer.
As per stackexchange-url ("your other question") rather than trying to use older API to implement widgets it is better to use newer and current approach as per Widgets API in Codex. The difference is that newer code is more reliable and more functional (allows to easily have more complex features, such as multiple instances of the widget). So issues with your code example are probably not worth fixing, better to just move to using currently suggested way.
What are the really difference writing WordPress 3.x widget plugins?
wordpress
how are you? I want to using a string query to list tags in array and using it. I write this query but dosen't work <code> $tags= $wpdb-&gt;query("SELECT * FROM $wpdb-&gt;term_taxonomy , $wpdb-&gt;term_taxonomy WHERE $wpdb-&gt;term_taxonomy.taxonomy = post_tag"); foreach($tags as $tag){ echo $tag; } </code> please help me ..
Use get_terms() .
I want a query to list tags
wordpress
I have my single-property.php showing custom post type 'property', within this page I want to also show the custom post type 'agent' that belongs to the author of property, each author only has one post of custom post type 'agent'. I imagine it needs to go something like this, single-property.php with the query to show custom post type 'property', get author from first query and run second query showing all posts of custom post type 'author' by the same author. Thanks
You can use the <code> $post-&gt;post_author </code> , so before your loop add <code> $agent = ''; </code> then inside the loop add <code> $agent = $post-&gt;post_author; </code> and then create a second query after you loop ends: <code> $agent_query = NEW WP_Query(array('post_type' =&gt; 'agent', 'author' =&gt; $agent)); while ($agent_query-&gt;have_posts()){ $agent_query-&gt;the_post(); //do your agent loop here } wp_reset_postdata(); </code>
Run second query on page based on author of the first query
wordpress
This question was discussed on stackexchange-url ("here") and I believe stackexchange-url ("here") as well, but I was wondering if anyone knew of any updates to this since then? To clarify, I currently have a custom taxonomy called 'Days of Week' so I only use seven terms (Monday, Tuesday, Wednesday etc.) but under <code> hiearchical=&gt;true </code> , WordPress lists them in an alphabetical order instead. Friday Monday Saturday Sunday Thursday Tuesday Wednesday Normally this wouldn't be an issue, but given that some users of the site might find it confusing, I thought I'd ask to see if anyone had any ideas? Thanks in advance!
I have a new answer for this, use my brand new plugin: http://wordpress.org/extend/plugins/custom-taxonomy-sort/ . I hope this helps with this issue.
Sort Custom Taxonomy Terms in admin by custom order
wordpress
For example i've <code> domain.com/about?project=1 </code> but i've permalinks enabled and i'm using thins to generate the pagination paginate_links . The proble is that the links generated are like this <code> domain.com/about?project=1/page/1 </code> and it breaks everything because the project is taken as <code> 1/page/1 </code> There is a way to get <code> domain.com/about/project/1/page/1 </code> in the paginations links? I'm submitting that from a form using get to display the project.
To add arguments to the links in paginate posts, use the <code> 'add_args' </code> argument in the function. You have to pass the arguments as an associative array. So, to add <code> project=1 </code> to the end of all your links, you would do this: <code> global $wp_query; paginate_links(array( 'total' =&gt; $wp_query-&gt;max_num_pages, 'current' =&gt; (get_query_var('paged') ? get_query_var('paged') : 1), 'base' =&gt; 'http://domain.com/about/%_%', 'format' =&gt; 'page/%#%', 'add_args' =&gt; array( 'project' =&gt; 1 /* or whatever the project number is*/ ), )); </code> Hope that helped! EDIT To get <code> domain.com/about/projects/1/page/1 </code> , you can add a custom permastruct. I'm going to assume <code> about </code> is a page. <code> function wpse21802_init(){ add_rewrite_rule( '([^/]+)/projects/([^/])/?$', 'index.php?pagename=$matches[1]&amp;project=$matches[2]', 'top' ); add_rewrite_rule( '([^/]+)/projects/([^/])/page/(/d+)/?$', 'index.php?pagename=$matches[1]&amp;project=$matches[2]&amp;paged=$matches[3]', 'top' ); } add_action( 'init', 'wpse21802_init' ); </code> After adding that code, flush the rewrite rules by going to Settings -> Permalinks.
Passing custom args in paginate_links
wordpress
The text returned by the_excerpt() does not respect my widget format. I couldn't explain it better so I will just show you my code: <code> function widget($args, $options) { extract($args); $post_type = $options['post_type']; $num_of_posts = $options['limit']; // Create a new instance $second_query = new WP_Query( array( 'post_type' =&gt; "$post_type", 'posts_per_page' =&gt; "$num_of_posts", 'post_status' =&gt; 'publish', ) ); // The Loop if ($second_query-&gt;have_posts()) : while( $second_query-&gt;have_posts() ) : $second_query-&gt;the_post(); $byh_content .= "&lt;p&gt;" . the_excerpt() . "&lt;/p&gt;"; endwhile; else : $byh_content = "&lt;p&gt;No " . $options['post_type'] . "s found.&lt;/p&gt;"; endif; wp_reset_postdata(); $title = "&lt;h3&gt;" . $options['title'] . "&lt;/h3&gt;"; $content = $byh_content; echo $before_widget.$title.$content.$after_widget; } </code> The result isn't what I expected. Here's what it looks like when rendered: The title should be at the top. The reason is that, the excerpt isn't where it is supposed to be:
as you are working with strings, you need to use a function which returns the value, instead of echoing it; in this line: <code> $byh_content .= "&lt;p&gt;" . the_excerpt() . "&lt;/p&gt;"; </code> use <code> get_the_excerpt() </code> http://codex.wordpress.org/Function_Reference/get_the_excerpt
Broken markup when using the_excerpt() in a widget?
wordpress
Is it possible to let a non-admin user (e.g an editor / author or another role) manage the users? I am working on a Wordpress website where multiple people manage the website, and there will be someone who must be able to manage the users, but does not need access to all the admin features. Thanks.
First off, there is no generic "manage users" ability. There are several individual abilities under that rubric. See http://codex.wordpress.org/Roles_and_Capabilities Anyway, you have a couple options. You can add certain capabilities to existing users or you can create a new custom role with the capabilities you need. If a brand new role is needed, one can be created using add_role() and add_cap(): <code> $role = add_role('foo_doer', 'Foo Doer'); $role-&gt;add_cap('do_foo'); $role-&gt;add_cap('do_bar'); </code> If you want to manipulate a user specifically: <code> // get user by user ID $user = new WP_User( $id ); // or get user by username $user = new WP_User( null, $name ) </code> then <code> // add $cap capability to this role object $role_object-&gt;add_cap( $capability_name ); </code> That's the basics. A full and elegant rundown is here: http://www.garyc40.com/2010/04/ultimate-guide-to-roles-and-capabilities/
Wordpress manage users as non admin
wordpress
I need to <code> get_the_tag_list </code> but want to remove whitespace within individual tags. Thus, <code> firefox, internet explorer, opera </code> becomes <code> firefox, internetexplorer, opera </code> All the filters I found removed whitespace from the HTML, not the content itself.
<code> $tags = get_the_tags(); $tag_links = array(); foreach((array)$tags as $tag) $tag_links[] = '&lt;a href="'.get_tag_link($tag-&gt;term_id).'" rel="tag"&gt;'.str_replace(' ', '', $tag-&gt;name)).'&lt;/a&gt;'; echo implode(', ', $tag_links); </code>
return get_the_tag_list with whitespace removed
wordpress
The majority of new user signups I receive on my Wordpress blog look dodgy, with @someblog.com, @somearticle.com, or @gmail.com addresses. What do they gain by signing up as a new user?
Some are attempting to leave their links behind, they believe the quantity not quality approach will actual help increase SEO rankings. The other reason would be affiliate marketing garbage links trying to make a penny.
What do spammers gain by signing up as a user?
wordpress
I am running wordpress 3.2rc2 multisite. I inserted a few .mp4 videos into the root of my domain so that I can run a few basic tests with the jw player. When I try to access the url to the .mp4 video, I somehow end up with a wordpress 404 page. This is also causing errors within the jw player saying that either the file is not found, or access is denied. Permissions are 644 on the mp4 files, and the owner/group is correct. Why is this happening and how do I fix it so that wordpress stops messing with my mp4 files? Also: can someone please add the mp4 tag, I don't have enough rep to do this yet. Here is my htaccess file: <code> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] # uploaded files RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L] # add a trailing slash to /wp-admin RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] RewriteRule . index.php [L] AddType video/ogg .ogv AddType video/mp4 .mp4 AddType video/webm .webm </code> Edit If I use the wordpress media uploader, then I can access the mp4 videos just fine. I just can't place them anywhere else on the server which is a problem. Anyone have any further ideas as to why wordpress is screwing with my mp4s when in other directories or even when they are in the root?
A missing mime type should not cause a 404 page but the AddType needs to be wrapped in <code> &lt;IfModule mod_mime.c&gt; </code> tags. <code> &lt;IfModule mod_mime.c&gt; AddType video/mp4 .mp4 .m4v AddType video/mpeg .mpeg .mpg .mpe AddType video/asf .asf .asx .wax .wmv .wmx AddType video/avi .avi AddType video/quicktime .mov .qt AddType audio/ogg .ogg &lt;/IfModule&gt; </code> I'm running jw player on a multisite and I had to use absolute urls to access the player and the file. I created a folder in my site root that contained the player and files then wrote a function to display the video and enqueued the swfobject using wp_enqueue_script. <code> add_action( 'template_redirect', 'load_swf_object' ); function load_swf_object() { wp_enqueue_script('swf_object', '/jw/swfobject.js'); } function c3m_play_the_video() { echo "&lt;div id='front-vid'&gt; &lt;div id='videospace'&gt;This text will be replaced&lt;/div&gt; &lt;script type='text/javascript'&gt; var so = new SWFObject('http://example.com/jw/player.swf','mpl','520','350','9'); so.addParam('allowfullscreen','true'); so.addParam('allowscriptaccess','always'); so.addParam('wmode','opaque'); so.addVariable('file','http://example.com/jw/video/video_name.mp4'); so.addVariable('image','http://example.com/jw/video/video-face.jpg'); so.addVariable('skin','http://example.com/jw/skins/glow.zip'); so.addVariable('bufferlength','3'); so.write('videospace'); &lt;/script&gt; &lt;/div&gt;"; } </code>
wordpress htaccess is hijacking my .mp4 files
wordpress
I use hack of stackexchange-url ("Chris_O") for highlighting the search terms. When a user enters the search keywords without any blank space in the beginning or at end of the search string it retrieves and highlights the search terms in the corresponding records nicely. But if the user enters the search string with blank_space in the beginning or at the end, it retrieves and highlights the the search terms but all non-english portions of the post content appears weird (like ���� or ????). Although the english content appears fine but with tags (e..g, <code> &lt;p style="text-align: center;"&gt;test site&lt;/p&gt; </code> etc.) Is it possible in the hack to strip/remove all blank spaces at the beginning/end of a search string? thanks a lot. I use version 3.1.4 with the default twentyten theme. Here is the Hack: Step 1: Add these 2 functions to your functions.php <code> function search_content_highlight() { $content = get_the_content(); $keys = implode('|', explode(' ', get_search_query())); $content = preg_replace('/(' . $keys .')/iu', '&lt;strong class="search-highlight"&gt;'placeholder4'&lt;/strong&gt;', $content); echo '&lt;p&gt;' . $content . '&lt;/p&gt;'; } function search_title_highlight() { $title = get_the_title(); $keys = implode('|', explode(' ', get_search_query())); $title = preg_replace('/(' . $keys .')/iu', '&lt;strong class="search-highlight"&gt;'placeholder4'&lt;/strong&gt;', $title); echo $title; } </code> Step 2: In my theme's loop.php file I call <code> &lt;?php search_title_highlight(); ?&gt; </code> instead of <code> &lt;?php the_title(); ?&gt; </code> and use <code> &lt;?php search_content_highlight(); ?&gt; </code> instead of <code> &lt;?php the_content(); ?&gt; </code> Step 3: In my css add the search-highlight class
i agree w/ chip, you need trim() i'd try replacing: <code> $keys = implode('|', explode(' ', get_search_query())); </code> with <code> $keys = implode('|', explode(' ', trim(get_search_query()))); </code>
How to strip/remove all blank spaces at the beginning/end of a search string
wordpress
I'm trying to figure out a way to include a div(which will contain a background image) for a specific tag. This block of code works but fails when a post has more than 1 tag. I'm using a page called tag.php which is the default template for all tags. I'll have quite a few tags so I don't want to create template files for them all, ie: tag-name.php <code> &lt;?php if( has_tag('books') ) { include 'tags/books.php';} elseif ( has_tag('tables') ) { include 'tags/tables.php';} ?&gt; </code> It's always possible there is an easier way to do this. I essentially need a script that detects which tag is being viewed, as a page, then displays the correct image for it. So when the page for the tag "table" is loaded that tag will always use an image named "table.jpg" Does anyone have any suggestions or know of a way I can modify the script above to do what I described?
Here are 2 solutions: Using Tag titles <code> &lt;?php switch( single_tag_title( '', false ) ) { case 'Books' : include 'tags/books.php'; break; case 'Tables' : include 'tags/tables.php'; break; default : break; } ?&gt; </code> Using tag slugs: <code> &lt;?php if ( is_tag( 'books' ) ) { include 'tags/books.php'; } else if ( is_tag( 'tables' ) ) { include 'tags/tables.php'; } ?&gt; </code>
Detect tag page and include an Image for that specific tag
wordpress
When I'm reading a custom type post in the single view, I see that the URL is www.my_site.com/my_custom_post_type/title_of_my_post. How to get rid of this ugly /my_custom_post_type/ ?
<code> register_post_type( 'my_custom_post_type', array( 'rewrite' =&gt; array( 'with_front' =&gt; false ), // other args )); </code> Make sure you flush your permalinks after changing your code - simply going to Settings > Permalinks is sufficient.
Getting rid of /my_custom_post_type/ in the single view URL
wordpress
I'd like to allow my users to send their WordPress login credentials along with their comment, as opposed to having to log in first, and then post their comment. I'm not really sure where to hook into here, and any help would be much appreciated. My basic plan is to get the user's login and pass (and comment), log the user in (maybe during preprocess_comment), then supply the user id etc to the comment object, then let everything run as usual. But I'm wondering if I'm opening myself up to some kind of exploit by doing so. I understand that WordPress has a login form for a reason, and I'm hesitant to log the user in without going through the official form.
You can log a user in securely by simply calling wp_signon with the proper credentials. This has to be done before any output is produced, so that WP can set the users cookie properly. Example: <code> $user = wp_signon(array('user_login'=&gt;'example', 'user_password' = &gt; 'swordfish')); </code> That will do a proper login from the front end of the site, set cookies, and return the user object. Then you can set the $commentdata['user_id'] = $user-> ID and return, and the comment will be dealt with accordingly. An auth failure will make that return a WP_Error object instead, so use is_wp_error on the result to see if it's a WP_Error or a WP_User object that you get back.
Send along login credentials with comment content
wordpress
I know how to get the value of a custom field, using code like <code> get_post_meta($post-&gt;ID, 'company', true); </code> . Is there a way to get the name of the custom field?
to get a post custom fields name you can use get_post_custom eg: <code> $post_meta = get_post_custom($post-&gt;ID); foreach ( $post_meta as $key =&gt; $value ) echo $key . " =&gt; " . $value . "&lt;br /&gt;"; </code> this will print a list of custom_field_name => custom_field_value
How to Get the title of a custom field?
wordpress
How can I define the maximum number of revisions on a per-post type basis? For example posts have 3 max revisions where as pages have a max of 10.
I might be wrong, but my first guess would be that this is not easily possible, because number of revisions gets saved into constant and does not seem hook-able. From quick search relevant checks are in <code> wp_save_post_revision() </code> and it's very rigid.
Define maximum number of revisions per post type?
wordpress
Does anyone know of a wordpress theme or plugin that offers custom user registration + 'My account' panel? I'm trying to build a cashback site.. would appreciate if you could share themes or plugins that could do the job.
Just echoing what Chip already said: Themes are for presentation , plugins are for functionality. Custom user registration and a 'My Account' panel would be in the realm of custom functionality. To quote another WordPress developer: If you're building a bathroom and you change the wallpaper, the toilet shouldn't disappear, too. Themes are the look and feel of your site and should be capable of being interchanged and swapped out easily. Changing the theme, though, shouldn't remove your custom features (i.e. user management tools). This is why they should be housed in a plugin rather than the theme. That said, Chip also recommended an outstanding system: Members Plugin . If that's not quite what you're looking for, check out these as well: Custom User Registration Lite WP User Registration Simplr User Registration Form Finally, since the custom work you need done might fall outside the realm of any existing plugin, you might consider listing the project on jobs.wordpress.net and hiring a developer to build the system for you.
Can anyone suggest a wordpress them with built in user management
wordpress
I've been writing some Wordpress plugins, and I've been having some problem with Wordpress putting magic quotes on POST and GET data. Specifically, the "wp_magic_quotes" function in \wp-includes\load.php, which is called (presumably on every response) in wp-settings.php. This function adds magic quotes to the data even if I turn off magic quotes in PHP settings. <code> /** * Add magic quotes to $_GET, $_POST, $_COOKIE, and $_SERVER. * * Also forces $_REQUEST to be $_GET + $_POST. If $_SERVER, $_COOKIE, * or $_ENV are needed, use those superglobals directly. * * @access private * @since 3.0.0 */ function wp_magic_quotes() { // If already slashed, strip. if ( get_magic_quotes_gpc() ) { $_GET = stripslashes_deep( $_GET ); $_POST = stripslashes_deep( $_POST ); $_COOKIE = stripslashes_deep( $_COOKIE ); } // Escape with wpdb. $_GET = add_magic_quotes( $_GET ); $_POST = add_magic_quotes( $_POST ); $_COOKIE = add_magic_quotes( $_COOKIE ); $_SERVER = add_magic_quotes( $_SERVER ); // Force REQUEST to be GET + POST. $_REQUEST = array_merge( $_GET, $_POST ); } </code> Is it safe for me to just comment out the wp_magic_quotes() call in wp-settings.php? That is, will it negatively affect the normal Wordpress code and/or open up some exploitation vector? If so, is there some other way to do it besides modifying WP code (so I don't have to deal with this every time there's an update)?
Simply put WP turns indeterminate situation (magic quotes might or might not be enabled in server configuration) into determinate (magic quotes are always present and server configuration does not matter). Rather than messing with this for all WP core it makes much more sense to simply strip slashes in your code on your own variables, when you need that.
Wordpress and magic quotes
wordpress
Hi I have built a settings page which from the menu leads to: http://www.mysite.com/wp-admin/admin.php?page=theme_options The problem is that when I go to save the options and I am an EDITOR user I get this error: You do not have sufficient permissions to access this page. I am using User Role Editor plugin and edit_theme_options capability is enabled for the Editor user type. What can I do to fix this? thanks
I am not sure this is the issue here, but if I remember right the current limitation of Settings API is that <code> manage_options </code> capability is required for everything to be saved properly. Quick search shows it might get fixed in 3.2, see this trac ticket .
Insufficient permissions to save options
wordpress
Hi iam developing a plugin to activated a couple of plugins. i.e: the plugin jetpack has six plugins and all gets activated on a single install,like wise i need to activate a group of plugins from acivating this plugin. for example consider a plugin called 'site plugin' which has sub folders of other plugins. when i activate 'site plugin' it should show options to activate other plugins in it. I hope some one could help me.
You're main pluggin can use register_activation_hook and use the function you register thru the hook to activate you're necesary pluggins. Smth along these lines : <code> // get already activated plugins $plugins = get_option('active_plugins'); $puginsToActiv = array('Plugin1', 'Plugin2', 'Plugin3'); if($plugins) { $changed = false; foreach ($puginsTostActiv as $plugin) { if (!in_array($plugin, $plugins)) { $changed = true; array_push($plugins,$plugin); } } if ( $changed ) update_option('active_plugins',$plugins); } // code not tested </code>
Wordpress plugin for activating other plugins
wordpress
Been looking around for an alternative to this method: http://allcreatives.net/2011/02/02/using-the-native-wordpress-tinymce-wysiwyg-editor-with-your-custom-post-meta-textareas/ To add the WYSIWYG capability to custom metaboxes. You get so little control with this method, is there any other way?
Use this class: http://www.deluxeblogtips.com/p/meta-box-script-for-wordpress.html and then call the metabox like this (don't forget to read the manual and view some examples): <code> $meta_boxes[] = array( 'id' =&gt; 'textmetabox', 'title' =&gt; 'Your Meta Box Title', 'pages' =&gt; array('post', 'slider', 'whatever-your-cpt-is'), 'fields' =&gt; array( array( 'name' =&gt; 'Your thoughts about Deluxe Blog Tips', 'id' =&gt; $prefix . 'thoughts', 'type' =&gt; 'wysiwyg', 'std' =&gt; '&lt;b&gt;It's great!&lt;/b&gt;', 'desc' =&gt; 'Do you think so?', 'style' =&gt; 'width: 300px; height: 400px' ) ) ); </code>
Add TinyMCE to CPT metaboxes in 3.1?
wordpress
What are the best practices for using post_id? Can I use this safely in my templates to call specific posts, or will these post_id's ever change? The reason I ask is that randomly today the post_id's changed on my site, and I'm wondering what could have caused it. It didn't mess up any of the permalinks (thankfully!) but I did have to go switch some custom queries which were calling content specifically by the post_id (specifically in some custom_post_types I've created) So... should I use a different query to get a specific post? The query I'm using looks like this. <code> &lt;?php query_posts('post_type=home_feature&amp;p=36')?&gt; </code> Just earlier today, post_id for this post was 139 and my query was: <code> &lt;?php query_posts('post_type=home_feature&amp;p=139')?&gt; </code> Obviously, when the post_id changed, my query (and subsequently the custom home feature) broke. I'm just not sure what could have caused this change.. and if that means I shouldn't be using the post_id in custom queries.. Thoughts?
Post ID's do not change. The reason behind this is the ID column in MYSQL is the primary key for the table. It is auto incremented when a new row is added. It is improbable that a post ID would change programatically unless someone is doing something rogue in the database.
will post_id ever change? Can I safely use post_id for custom queries?
wordpress
Is there a well-coded plugin or function that will enable me to create a global feed for only one post type in a multisite setup?
Perhaps you might be able to achieve your goal by combining the feeds of the posts you are interested and create a new feed this way? That's what I did for a multisite setup. In this setup I created a page template which would load the rss feed which I created using Simple Pie (to combine all rss feeds into one cached feed).
Global site feed plugin/function for custom post type?
wordpress
This might be a stupid question, and maybe I've missed some best practices thing, but I've been having this problem with clients using sites on WordPress. Let's say we have a fairly complex page that requires some good amount of HTML code inside the page itself. We put it up and it looks great. Now, month later client wants to edit couple words there, goes in and edits them in Visual Mode, and of course all markup that we did is now screwed up, so stuff is all over the place. What are the approaches we can use to handle cases like that?
One thing you could do is create page templates for complex pages and simply add the content through the editor, leave as little mark-up as possible in the editor. Another thing that might help is using the editor style (activated with <code> add_editor_style() </code> in <code> functions.php </code> ) and defined in <code> editor-style.css </code> so the client has a better sense of what's going to be displayed (if you mimic your theme pretty closely) right in the editor. Add custom fields with descriptive names for information which needs to be displayed in a certain way, in a certain place, rather than lumping it in the main content. The simple fields plugin simplifies this a lot, permits repeatable fields and file uploads. It gives flexibility while avoiding letting your client shoot himself in the foot so easily. Or you could make your own metaboxes,etc.
Editing Complex Pages in Visual Mode
wordpress
On one of my page templates I need to include the contents of several other pages. For example, if my page template is called Fruit, I need to pull in page content from pages named Apple, Pear, Orange, Lime, etc. This gives my user the ability to edit Apple and Lime individually from admin area. I'm trying to use get_page_by_title() to pull in these sub pages, but that function only seems to want to work once per page. The first time I call <code> get_page_by_title('Apple') </code> works perfectly. When I later call <code> get_page_by_title('Lime') </code> it displays Apple again. Is this function limited to once per page, or am I doing something else wrong? Edit: It seems that no matter what title I pass to get_page_by_title() it will always get the content of the current page. So if I'm on example.com/fruit and call <code> get_page_by_title('Apples') </code> with in the page, it will always display the content from Fruit. Not Apples.
get_page_by_title returns an id not content. here is an example of what I use to get content from a certain page id. call the function <code> $page_id = get_page_by_title('title'); $excerpt = get_excerpt_by_id($page_id); </code> in functions.php <code> function get_excerpt_by_id($post_id) { global $wpdb; $query = "SELECT post_content FROM $wpdb-&gt;posts WHERE ID = $post_id LIMIT 1"; $result = $wpdb-&gt;get_results($query, ARRAY_A); return $result[0]['post_content']; } </code>
Unable to use get_page_by_title() more than once per page?
wordpress
i've been having a world of difficulty w/ the WP-minify plugin. usually i get 400/bad request errors when i try to access the combined/minified script or style files. this tends to break the entire look of my site. but on my last site i came across a new error... when i try to view the combined script i see the following warning/errors followed by a bunch of gibberish. anybody know what the heck this is about? ` Warning : is_file() [function.is-file]: open_basedir restriction in effect. File(/home/kathyi/public_html/wp-content/plugins/wp-minify/cache//minify_2fac368eb244a71e24b5c8bb929e8107.gz) is not within the allowed path(s): (/var/www/vhosts/soulmatesummit.net/httpdocs:/tmp) in /var/www/vhosts/soulmatesummit.net/httpdocs/online-course/wp-content/plugins/wp-minify/min/lib/Minify/Cache/File.php on line 71 Warning : is_file() [function.is-file]: open_basedir restriction in effect. File(/home/kathyi/public_html/wp-content/plugins/wp-minify/cache//minify_2fac368eb244a71e24b5c8bb929e8107) is not within the allowed path(s): (/var/www/vhosts/soulmatesummit.net/httpdocs:/tmp) in /var/www/vhosts/soulmatesummit.net/httpdocs/online-course/wp-content/plugins/wp-minify/min/lib/Minify/Cache/File.php on line 33 Warning : is_file() [function.is-file]: open_basedir restriction in effect. File(/home/kathyi/public_html/wp-content/plugins/wp-minify/cache//minify_2fac368eb244a71e24b5c8bb929e8107.gz) is not within the allowed path(s): (/var/www/vhosts/mysite.net/httpdocs:/tmp) in /var/www/vhosts/mysite.net/httpdocs/online-course/wp-content/plugins/wp-minify/min/lib/Minify/Cache/File.php on line 33 Warning : Cannot modify header information - headers already sent by (output started at /var/www/vhosts/mysite.net/httpdocs/online-course/wp-content/plugins/wp-minify/min/lib/Minify/Cache/File.php:71) in /var/www/vhosts/soulmatesummit.net/httpdocs/online-course/wp-content/plugins/wp-minify/min/lib/Minify.php on line 312 `
"open_basedir restriction in effect" errors mean the host is very restrictive in terms of php configs. The open_basedir setting prevents scripts from reading files (via requires, includes, any of the file handing functions, etc.) from directories that are not marked as "safe." It was designed to prevent users from accessing sensitive files and/or other user's files shared servers while PHP was running as "nobody." If you have Cpanel or Plesk, etc., try switching to the CGI version of PHP using suPHP. But if you can't, find a new host.
WP-Minify 400 errors and open_basedir restriction in effect
wordpress
When it comes to excerpts, do you believe TimThumb or WordPress thumbnails is the way to go? And why? Answers will not be graded (but may be criticized).
In my opinion the built in <code> &lt;?php add_image_size( $name, $width, $height, $crop ); ?&gt; </code> function is much more flexible, easy and with less overhead. It does resize-crop, so I don't see a reason to go back to TimThumb (which I used extensively in the past).
What is your take: TimThumb vs. WordPress Thumbnails? The great debate
wordpress
I've got 3 languages on my site. Picking the same featured image 3 times for the 3 versions of each article is boring. Is there any way to do it only once ? (same for picking a tag)
You'll find the answer here : http://wpml.org/2011/05/new-plugin-wpml-media-translation/
WPML : how to pick a featured image only once for different languages?
wordpress
I'm working with a team of developers on a new site and we've experienced an issue. All of have a local install (under SVN) of WP 3.1.3 running on our machines, but we're all connected to the same remote database. The issue comes in when one of us creates a new plugin and installs it. Until the plugin files are checked-in to the SVN repository, and the other devs check-out the new plugin files, WP will deactivate the plugin (since we're all on the same db, but different local installs) if it can't find the plugin file on another dev's machine who happens to be in the WP Dashboard. So for example: Dev A creates a plugin, and installs it. The files are local on his machine. He checks then into SVN. Dev B is in the dashboard, and hasn't gotten latest from the SVN repository so WP deactivates the plugin that Dev A just created since it can't find the files on Dev B's machine. Is there any way around this other than each dev having a local db installed? Any help would be much appreciated!
I recently had a similar issue, sadly, the only way around it was either local database for each Dev team or all dev teams working on a shared remote environment. Save your self the time and brain melt downs looking for another solution and pick whichever works better for you and go with it.
Multiple Instances sharing the same database in a development environment
wordpress
I'm trying to fix a friend's feed to show full content in the category feed instead of only a summary. He's already done the setting bit, but it still doesn't seem to work. Thoughts? EDIT: The feed in question is http://blogs.gnome.org/happyaron/category/debian/feed/
Full Text Feed plugin shows full content....follow the installation steps there,and then goto settings-> Reading-> For each article in a feed, show=> select Full text and save.it'll work.if you want to implement via the code means, <code> &lt;?php if (get_option('rss_use_excerpt')) : ?&gt; &lt;description&gt;&lt;![CDATA[&lt;?php the_excerpt_rss() ?&gt;]]&gt;&lt;/description&gt; &lt;?php else : ?&gt; &lt;description&gt;&lt;![CDATA[&lt;?php the_excerpt_rss() ?&gt;]]&gt;&lt;/description&gt; &lt;?php if ( strlen( $post-&gt;post_content ) &gt; 0 ) : ?&gt; &lt;content:encoded&gt;&lt;![CDATA[&lt;?php the_content() ?&gt;]]&gt;&lt;/content:encoded&gt; &lt;?php else : ?&gt; &lt;content:encoded&gt;&lt;![CDATA[&lt;?php the_excerpt_rss() ?&gt;]]&gt;&lt;/content:encoded&gt; &lt;?php endif; ?&gt; &lt;?php endif; ?&gt; </code>
How to make category RSS feeds show full content
wordpress
I can't seem to get <code> post__in </code> to work with custom post types. Is this true? What's the alternative? <code> $args = array('post_type' =&gt; array( 'post', 'page', 'tf_events', 'duka' ), 'orderby' =&gt; 'menu_order', 'showposts' =&gt; -1, 'post__in' =&gt; explode(',',$mtheme_featured) ); query_posts($args); </code> <code> $mtheme_featured </code> has two ids separated by commas, one post and one tf_event; only the post is shown.
You said the post type is called 'tf_event', but in the 'post_type' array it's 'tf_events'.
Query custom type posts by array of IDs
wordpress
I have a problem with the wordpress editor. It keeps removing my enters and scrambling the content. How can I solve this problem?
I'd suggest using editor style for your wysiwyg. Add <code> add_editor_style(); </code> to your functions.php and then add a new file called <code> editor-style.css </code> to your main theme directory. Your editor style should reflect the basic css settings like your actual frontend content width, H1, H2, p etc tags styles, margins, image padding adn margins etc. Don't copy your default style.css, only the basic styling. Here is an example of an editor-style.css file I used on my latest project (note html .mceContentBody): <code> html .mceContentBody { width:690px; font-family:Arial, Helvetica, sans-serif; } h1 { color: #AC2327; display: block; font-size: 16px; font-weight: bold; line-height: 50px; } h2 { color: #494949; font-size: 14px; font-weight: bold; margin: 10px 0 15px; } ul li { color: #494949; font-size: 12px; font-weight: normal; line-height: 1.7em; list-style: disc inside url(includes/images/dot.gif); padding: 2px 0; } p { color: #494949; font-size: 12px; font-weight: normal; line-height: 1.6em; margin: 15px 0 5px; } p a { color: #CA1016; text-decoration: none; } strong { font-weight: bold; } img { border: 1px solid #E4E2E2; clear: both; margin: 0 25px 25px; } hr { background-color: #D7D7D7; border: 0 none; color: #D7D7D7; float: left; height: 1px; margin: 0 0 18px; width: 100%; } </code>
wysiwyg is scrambled
wordpress
As I mentioned stackexchange-url ("here"), I'm planning to moving my blog to a new hosting provider from WordPress.com. I think I've settled on Page.ly as the new home for it, and I was hoping to get the benefit of experience from any of you who have transitioned an existing blog specifically from WordPress.com to page.ly . Some examples of the potential issues I'm trying to ferret out: Am I going to lose any WordPress.com specific features in the transition? Any new maintenance issues/headaches that weren't there on Wordpress.com? Any surprise "Upgrade" fees for things I'm used to getting for free? What information can I expect to lose in an export/import process (Site stats, dates on comments/posts/subscribed users/something else?) General tips, advice, whatever that you wish you knew before you did the move.
You can expect to lose your site stats. You can expect your site to be harder to find. You can expect to have greater freedom in terms of customization and possible features. You can expect to have to upgrade your WordPress version periodically. You can expect less users commenting, as WordPress.com uses a social networking style bar that won't be on your normal WordPress blog. You can expect to pay money for a really good theme, if you so choose.
What can I expect when moving from a hosted (WordPress.com) blog to one hosted by Page.ly
wordpress
I am trying to outline a new project where I want to give my users the ability to customize their 'profile' pages in my website theme. Concepts like adding in their own background images, choosing templates etc. It seemed logical to me to store this information in the author meta, as that seems to be the only table that stores unique information for each user. Once I have input boxes setup then I can easily make the calls in my theme. Users don't appear to be post-types, or taxonomies, but I can't figure out what they 'really' are. Could someone take a moment to describe what 'users' really are in the eyes of WordPress? What I was ultimately hoping for is to find a class where I can easily add metaboxes to the edit author profile pages. I do know how to extend profile fields via forms, but I am looking for something much more flexible. *I use the farinspace metabox class for my post-types and absolutely love how it works, really hoping I can use something similar for the author pages.. Is any of this possible, or is there a better route I should take?
Authors are rather simple content objects in WordPress. They have roles and capabilities , some basic meta data and their own edit screens. That’s it pretty much. If you want to add a custom taxonomy to authors you have to mirror each user with a (hidden) custom post type because the author object doesn’t support taxonomies … Anyway … for meta boxes I have written a simple class. I hope it helps to understand how things work and where to hook in. class T5_User_Profile_Addon <code> &lt;?php /** * Adds a form field to the edit profile page. * * @author Thomas Scholz http://toscho.de * @version 1.2 * @license GPL * */ class T5_User_Profile_Addon { public $settings = array ( /* The name attribute. */ 'name' =&gt; '' , 'label' =&gt; '' , 'description' =&gt; '' /* You may use the following placeholder: * %name% - name attribute * %label% - label text * %description% - additional text * To use more placeholders, extend markup_filter(). */ , 'markup' =&gt; '' /* If both are not FALSE, they will replace the 'markup', and a * table will be created. Uses the same placeholders as 'markup'. */ , 'th' =&gt; FALSE , 'td' =&gt; FALSE /* Capabilities to show and edit the field. * Useful, if want to add a field that only administrators or editors * may edit or view. */ , 'cap_show' =&gt; 'read' , 'cap_save' =&gt; 'edit_user' ); /** * Constructor * * @param array $args See settings. 'name' and 'markup' required. */ public function __construct( $args ) { $this-&gt;settings = array_merge( $this-&gt;settings, $args ); // The id attribute should be different to name, otherwise it doesn’t // work in Opera. empty ( $this-&gt;settings['id'] ) and $this-&gt;settings['id'] = $this-&gt;settings['name'] . '_id'; FALSE !== $this-&gt;settings['th'] and FALSE !== $this-&gt;settings['td'] and $this-&gt;settings['markup'] = '&lt;table class="form-table"&gt;&lt;tr&gt;&lt;th&gt;' . $this-&gt;settings['th'] . '&lt;/th&gt;&lt;td&gt;' . $this-&gt;settings['td'] . '&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;'; add_action( 'show_user_profile', array ( $this, 'show' ) ); add_action( 'edit_user_profile', array ( $this, 'show' ) ); add_action( 'personal_options_update', array ( $this, 'save' ) ); add_action( 'edit_user_profile_update', array ( $this, 'save' ) ); } /** * Prints the form. * * @param object $user * @return void */ public function show( $user ) { if ( ! current_user_can( $this-&gt;settings['cap_show'], $user-&gt;ID ) ) { return; } $label = "&lt;label for='{$this-&gt;settings['id']}'&gt;{$this-&gt;settings['label']}&lt;/label&gt;"; $markup = strtr( $this-&gt;settings['markup'], array ( '%name%' =&gt; $this-&gt;settings['name'] , '%id%' =&gt; $this-&gt;settings['id'] , '%label%' =&gt; $label , '%description%' =&gt; $this-&gt;settings['description'] ) ); $old_val = trim( get_the_author_meta( $this-&gt;settings['name'], $user-&gt;ID ) ); $markup = $this-&gt;markup_filter( $markup, $old_val ); print $markup; } /** * Saves the data. * * @param int $user_id * @return void */ public function save( $user_id ) { if ( ! current_user_can( $this-&gt;settings['cap_save'], $user_id ) ) { return; } $input = empty ( $_POST[ $this-&gt;settings['name'] ] ) ? '' : $_POST[ $this-&gt;settings['name'] ]; $input = $this-&gt;prepare_input( $input ); update_user_meta( $user_id, $this-&gt;settings['name'], $input ); } /** * Prepares the user input. For extensions. * * @param string $input * @return string */ public function prepare_input( $input ) { return $input; } /** * Prepares the form markup. * * @param string $markup * @param string $old_val * @return string */ public function markup_filter( $markup, $old_val ) { $old_val = htmlspecialchars( $old_val, ENT_QUOTES, 'utf-8', FALSE ); return str_replace( '%content%', $old_val, $markup ); } } </code> Usage <code> &lt;?php add_action( 'init', 'init_profile_addons' ); function init_profile_addons() { $GLOBALS['extended_author_text'] = new T5_User_Profile_Addon( array ( 'name' =&gt; 'extended_author_text' , 'label' =&gt; 'Second text field' , 'description' =&gt; '&lt;p&gt;This text will be shown at the top of your author archive. You may use HTML.&lt;/p&gt;' , 'markup' =&gt; '&lt;table class="form-table"&gt;&lt;tr&gt;&lt;th&gt;%label%&lt;br /&gt;&lt;br /&gt;%description%&lt;/th&gt; &lt;td&gt;&lt;textarea name="%name%" id="%id%" rows="10" cols="30"&gt;%content%&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;' ) ); } </code> Example: a checkbox In some cases you may want to extend the class to change some behavior. Here I built a checkbox: <code> /** * Template for a simple checkbox. */ class T5_User_Profile_Checkbox extends T5_User_Profile_Addon { public function prepare_input( $input ) { // Convert the checkbox value to integer return '' == trim( $input ) ? 0 : 1; } public function markup_filter( $markup, $old_value ) { // Preselect the checkbox if necessary. $checked = 1 == $old_value ? ' checked="checked"' : ''; return str_replace( '%checked%', $checked, $markup ); } } </code> My primitive template system may not be the best approach. There is no user friendly error handling. I just needed something that works and is easy to understand. :)
What are 'authors' in Wordpress, and is there an author 'metabox class' available anywhere?
wordpress
I need WP to show an embedded representation of a url such as http://domain.com/1121 using oembed. I have setup http://domain.com/1121 with a discovery link: <code> &lt;link href="http://www.domain.com/generator/oembed/?url=http%3A//domain.com/1121" rel="alternate" type="text/xml+oembed" /&gt; </code> I'm aware that WP no longer automatically discovers embeddable URLs, so I installed enable-oembed-discovery plugin to re-enable this feature. I have monitored my apache logs and confirmed that WP does hits the link to discover - so I guess the enable-oembed-discovery plugin works, but the URL is NEVER converted. I even wrote a plugin to whitelist my custom URL (really should not be needed since enable-oembed-discovery plugin should enable auto-discovery, but what the heck): <code> add_action( 'init', 'my_oembed_provider' ); function my_oembed_provider() { wp_oembed_add_provider( 'http://domain.com/*', 'http://www.domain.com/generator/oembed/', false); } </code> and still nothing. The API endpoint (http://www.domain.com/generator/oembed/) is hard coded to generate the following XML: <code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;OEmbed&gt; &lt;type&gt;rich&lt;/type&gt; &lt;width&gt;400&lt;/width&gt; &lt;height&gt;342&lt;/height&gt; &lt;html&gt;&lt;![CDATA[&amp;lt;b&amp;gt;HELLO WORLD FROM OEMBED &amp;lt;/b&amp;gt;]]&gt;&lt;/html&gt; &lt;/OEmbed&gt; </code> The API endpoint sends the right content-type header ( <code> header("Content-type: text/xml"); </code> ) as required by the oembed spec The user adding the post has admin privileges and therefore is allowed <code> unfiltered_html </code> I'm out of ideas and at wit's end. What am I missing?
Your XML root element was 'OEmbed', not 'oembed', as given in the spec. XML element names are case-sensitive, per the XML spec.
Wordpress refuses to show oembed URL
wordpress
I've seen a few plugins that add rich text editing to the default "Text" Widget. However, all of the ones I've tested are either too complicated (or try to do too much) or don't work properly with the latest WP versions. I'm just looking for a simple rich text toolbar with a minimal feature set (basic formatting and lists), image upload and hyperlink tool. Ideally, I'd like to find one that does not require a separate window to handle rich text. Just a simple tab to switch between html and wysiwyg. Any suggestions or recommendations?
I've never found one that was reliable and/or not a huge resource/memory drain. :( I ended up using the very handy " Page in Widget " plugin instead - it has the advantage of all the functionality of a regular editable page and your widget content won't accidentally get wiped, which has happened to me far too often. Sorry not to have the perfect solution. Will check back to see if others do! :) Michelle
Simple rich text editor in Text widget?
wordpress
I have my WordPress post format codes: <code> &lt;?php if ( has_post_format( 'image' )) { echo 'This is a image post'; } ?&gt; </code> And my code to grab the first image from a post... <code> &lt;a href="&lt;?php the_permalink() ?&gt;"&gt; &lt;?php $image = catch_that_image(); if( $image ) { ?&gt; &lt;img src="&lt;?php echo get_template_directory_uri(); ?&gt;/scripts/timthumb.php?src=&lt;?php echo $image; ?&gt;&amp;amp;h=240&amp;amp;w=280" class="index" alt="&lt;?php the_title(); ?&gt;" title="&lt;?php the_title(); ?&gt;" /&gt; &lt;?php } ?&gt; &lt;/a&gt; </code> So how do I put the image which is grabbed into the first code? Thanks for all the help guys and gals, I really do appreciate it.
here: <code> &lt;?php if ( has_post_format( 'image' )) { ?&gt; &lt;a href="&lt;?php the_permalink() ?&gt;"&gt; &lt;?php $image = catch_that_image(); if( $image ) { ?&gt; &lt;img src="&lt;?php echo get_template_directory_uri(); ?&gt;/scripts/timthumb.php?src=&lt;?php echo $image; ?&gt;&amp;amp;h=240&amp;amp;w=280" class="index" alt="&lt;?php the_title(); ?&gt;" title="&lt;?php the_title(); ?&gt;" /&gt; &lt;?php } ?&gt; &lt;/a&gt; &lt;?php } ?&gt; </code>
Help Combine These Two PHP Codes
wordpress
When a user creates a new post there is a meta field on the back end where they can enter the id of the nextgen gallery to display. I want to then display in their post the gallery which corresponds to the id they entered. When I run the code below $meta echoes as #3 and the gallery shows, so I know that for this post rw_propGallery is set to 3, and that three is the id of an existing gallery. <code> $meta = get_post_meta(get_the_ID(), 'rw_propGallery', true); echo $meta; echo do_shortcode('[nggallery id=3]') </code> But if I switch it to <code> echo do_shortcode('[nggallery id=$meta]') </code> I get the number 3, and "Gallery not found". Any suggestions?
Perhaps try: <code> echo do_shortcode('[nggallery id=' . $meta . ']'); </code>
Displaying NextGen Gallery using value from meta not working
wordpress
I am using WooTheme's Canvas theme and would like to "hardcode" in the [post_comments] shortcode into my theme. [post_comments] displays a comment link with comment count (ie Comments 10) in my post. Right now I am inserting the [post_comments] shortcode into my theme's meta "Meta Manager"; however, this is not ideal for me as I have limited control over the placement of where the this shows up in my post. What type of function or such should I be looking for to do this within my .php files? Thank you
Check out do_shortcode(): http://codex.wordpress.org/Function_Reference/do_shortcode <code> do_shortcode('[shortcode option1="value1" option2="value2"]'); </code> So your example would be: <code> do_shortcode('[post_comments]'); </code> What might be easier is to tap into the underlying comment functions: http://codex.wordpress.org/Function_Reference/comments_number <code> &lt;p&gt; This post currently has &lt;?php comments_number( 'no responses', 'one response', '% responses' ); ?&gt;. &lt;/p&gt; </code> You can also use <code> get_comments_number </code> which returns the value rather than printing it to the screen. This function however needs to be in the Loop for it to work, however I have a feeling it is.
How do I hardcode a WordPress shortcode into my theme?
wordpress
Is there anyway to customize the default WordPress widgets or do i need to create my own? For example, I want my recent post widgets to display date aswell. Thanks in advance! /Richard
You'll have to create your own but you can copy the code and customize from /wp-includes/default-widgets.php If you edit the defaults they'll screw up when you update WP.
Customizing wordpress default widgets?
wordpress
I have my own SQL string to select Custom Post Type posts with specific WHERE clause. I've used the offset and limit to return appropriate posts depending on a page being displayed. That's working fine. Now, I would like to make <code> previous_posts_link() </code> and <code> next_posts_link() </code> functions work. They both are called from <code> get_posts_nav_link </code> which uses <code> global $wp_query </code> . Is there a way I can re-assign <code> global $wp_query </code> with my SQL string or <code> $wpdb-&gt;get_results </code> results or anything else? So the native <code> previous_posts_link() </code> and <code> next_posts_link() </code> WP functions would work. If not, how can I reproduce the prev and next post link functions? I would really appreciate any help and advice! I'm totally stuck with this. Thanks :) NOTE: I have just noticed that <code> previous_posts_link() </code> is working correctly on all the pages, but <code> no idea why </code> and in this case, why <code> next_posts_link </code> doesn't work :S Here is the code: <code> $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $post_per_page = intval(get_query_var('posts_per_page')); $offset = ($paged - 1)*$post_per_page; $sql = " SELECT SQL_CALC_FOUND_ROWS wp_posts.*, wp_postmeta.* FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) INNER JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id) WHERE 1=1 AND wp_posts.post_type = 'movie' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') AND ((wp_postmeta.meta_key = '_expiry_date' AND CAST(wp_postmeta.meta_value AS DATE) &gt;= '".$current_date."') OR (mt1.meta_key = '_expiry_date' AND CAST(mt1.meta_value AS CHAR) = '')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT ".$offset.", ".$post_per_page; $movies_all_current = $wpdb-&gt;get_results( $sql, OBJECT); if($movies_all_current) { global $post; //loop foreach( $movies_all_current as $key=&gt;$post ) { setup_postdata($post); //display each post //... } //end foreach ?&gt; //navigation &lt;div class="navigation"&gt; &lt;div class="previous panel"&gt;&lt;?php previous_posts_link('&amp;laquo; newer') ?&gt;&lt;/div&gt; &lt;div class="next panel"&gt;&lt;?php next_posts_link('older &amp;raquo;') ?&gt;&lt;/div&gt; &lt;/div&gt; } </code>
Ok, I got there at the end. I couldn't use <code> WP_Query </code> class as I really needed to have my own pretty big and complex SQL. Here is what I ended up having: In <code> functions.php </code> I have my custom SQL and logic for counting the values needed for the WP pagination logic: <code> function vacancies_current( ){ global $wpdb, $paged, $max_num_pages, $current_date; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $post_per_page = intval(get_query_var('posts_per_page')); $offset = ($paged - 1)*$post_per_page; /* Custom sql here. I left out the important bits and deleted the body as it will be specific when you have your own. */ $sql = " SELECT SQL_CALC_FOUND_ROWS {$wpdb-&gt;posts}.* FROM {$wpdb-&gt;posts} .... GROUP BY {$wpdb-&gt;posts}.ID ORDER BY {$wpdb-&gt;posts}.post_date DESC LIMIT ".$offset.", ".$post_per_page."; "; $sql_result = $wpdb-&gt;get_results( $sql, OBJECT); /* Determine the total of results found to calculate the max_num_pages for next_posts_link navigation */ $sql_posts_total = $wpdb-&gt;get_var( "SELECT FOUND_ROWS();" ); $max_num_pages = ceil($sql_posts_total / $post_per_page); return $sql_result; } </code> Then in my template file I'd have: <code> &lt;?php $vacancies_current = vacancies_current(); /*followed by a standart loop to display your results */ ?&gt; &lt;div class="navigation"&gt; &lt;div class="previous panel"&gt;&lt;?php previous_posts_link('&amp;laquo; previous vacancies',$max_num_pages) ?&gt;&lt;/div&gt; &lt;div class="next panel"&gt;&lt;?php next_posts_link('more vacancies &amp;raquo;',$max_num_pages) ?&gt;&lt;/div&gt; &lt;/div&gt; </code> The trick was in supplying <code> previous_posts_link() </code> and <code> next_posts_link </code> the <code> $max_num_pages </code> value and obviously in calculating it correctly. This works very well. Hope it will help someone :) Dasha
Pagination with custom SQL query
wordpress
I'm working with post formats, most of my code looks similar to this: <code> if ( has_post_format( 'standard' )) { echo '&lt;?php get_sidebar(); ?&gt;'; } if ( has_post_format( 'aside' )) { echo 'this is an aside'; } if ( has_post_format( 'chat' )) { echo 'this is the video format'; } </code> But I also want one of the if statements to include how to call it if the user did not select a post format. Anybody know?
use <code> get_post_format </code> : <code> $format = get_post_format(); if ( false === $format ) echo "no post format"; </code> EDIT - an example using a switch statement: <code> $format = get_post_format(); switch( $format ){ case "aside": echo "aside"; break; case "chat": echo "chat"; break; default: echo "standard"; } </code>
If Statement Post Formats: No post format selected
wordpress
I am using Register Plus Redux. I don't know what happened exactly but after I upgraded to 3.1.4, the password provided on registration isn't recognized. I have to go in using admin account and set the password again. This does not happen with the default registration form though. I don't where to contact the author, if this isn't appropriate feel free to delete it.
This is a bug in the Register Plus Redux and has nothing to do with other plugins. Normally when you register with normal wordpress, it sends you a temporary password that you can modify after.. what happens with RPR is it sends you by email the temporary password generated by wordpress but puts in the database the password you have registred with! causing this bug. I advise you to disable this plugin now while waiting for an update from author. some users advised to edit the file register-plus-redux.php but this is risky since when plugin is updated it will overwrite your edits.
Cannot login due to incorrect password right after registration?
wordpress
Somewhere in my code I need to know what is the current language and display a certain custom field or another one based on this knowledge. How can I know this information ?
WPML defines constants that you can use go get the current language: <code> ICL_LANGUAGE_CODE </code> - current language code (eg: en,fr,sp). <code> ICL_LANGUAGE_NAME_EN </code> - Name of the current language in English (eg: English, French. Spanish). <code> ICL_LANGUAGE_NAME </code> - Name of current language, in the current language (eg: English, Français, Español).
WPML : how to determine manually the language in which a given page is displayed
wordpress
I am using WordPress 3.1.4 by now. I am confused with where (which hook) do I use: to register and/or enqueue scripts and styles on front- and back-ends? Questions: Which are right hooks to use? All front end register/enqueue scripts/styles in <code> init </code> ? Why is there no <code> admin_print_styles-{xxx} </code> ?
Why registering and queuing properly matters it should be in time - earlier than script/style is up for being output to page, otherwise it is too late; it should be conditional - otherwise you are loading stuff where you don't need it and cause performance and functionality issues, for this you need WP environment loaded to late stage. The three stages of the process register - this explains WP details about script/style and makes it store that info; enqueue - (often lumped together with register in one <code> wp_enqueue_*() </code> call) - this tells WP to add scripts/style to the queue, according to its settings (dependencies, header/footer loading). print - this happens when WP processes queue, tries to load something specific for itself or when you explicitly do it with <code> wp_print_*() </code> function. Front-end structure of functions and hooks <code> wp_head() </code> <code> wp_head </code> (1) <code> wp_enqueue_scripts() </code> <code> wp_enqueue_scripts </code> « this is what you need (8) <code> wp_print_styles() </code> (9) <code> wp_print_head_scripts() </code> <code> wp_footer() </code> <code> wp_footer </code> (10) <code> wp_print_footer_scripts() </code> It goes much deeper, but this is simple and good enough for important points: <code> wp_enqueue_scripts </code> is most appropriate hook for registering and queuing scripts and styles on front end and it is there specifically for that; <code> init </code> has nothing to do with this, it will work, but - past Codex recommendation to use only it was incorrect ; you can get away with queuing scripts (not styles) for footer at any point before <code> wp_print_footer_scripts() </code> call; <code> wp_print_* </code> hooks are NOT appropriate for register/queue , they are points in code when output is already happening. They are appropriate for manual/custom script/style output. What about admin? Well, the functionality there is even more complex, elaborate and nested. for starters just use <code> admin_enqueue_scripts </code> hook (it gets passed <code> $hook_suffix </code> global for conditional stuff ) for everything, it will do nicely for most cases; when you need something complex - look through <code> admin-header.php </code> and dig from there for appropriate hooks. What about login? There's a specific hook named <code> login_enqueue_scripts </code> .
Where is the right place to register/enqueue scripts & styles
wordpress
we're using the Atlas HTML sitemap plugin, which caches the sitemap using the transients API with a call like: <code> set_transient( 'dmac_html_sitemap', $output, 60*60*24*7 ); </code> Now, we also have a multi-site setup and I was wondering where the transients are stored and if WP multisite is keeping them separate. It keeps options separate as each site(blog) has its own DB table prefix (wp_29_options for example). I read somewhere that transients could be stored with memcached - so I'm guessing the back-end storage is pluggable. The reason for the question is that we have custom code that duplicates sites. If the transient is in the DB somewhere, it'll get copied and so I'll want to delete the cache for the newly duplicated site (part of the copy process also generates site-specific pages). If I just call: <code> delete_transient( 'dmac_html_sitemap' ); </code> from our plugin's network page admin, which site's transient will that delete? all? none? only the main site? Edit: As Rarst points out below, when an external persistent cache plugin isn't being used, the transients are just stored as options (prefixed with transient ). So, in that case they will be site-specific (as there is an options table for each site/blog). Hence, the question now becomes - does the wp_cache_set() and friends keep cache items separated by site by using the blog_id or something in the cache key or not? (e.g. if stored in memcached or APC for example)
Default Transient API behavior is to use Options API for storage and so behavior identical to options. However if there is external object cache (declared by plugin or whatever) then they get stored using object cache functions instead. So basically it will work in scope of current site, unless there are plugins that make it work otherwise.
Transients API and multisite
wordpress
I'm currently displaying custom taxonomies in a drop down menu. Each taxonomy has its own little wrapper in the sidebar. Is it possible to move the taxonomy to inside of my custom write box for ease-of-use purposes?
The following is taken from a "move author to publish box" task, but it should give you a starting point. Next you should take a look at "/wp-admin/edit-form-advanced.php" where you'll find something about <code> get_object_taxonomies() </code> to see how your stuff get's named, so you can remove and add stuff. <code> function wpse_remove_author_box() { if ( ! is_admin() ) return; remove_meta_box( 'authordiv', 'post', 'normal' ); } add_action( 'admin_menu', 'wpse_remove_author_box' ); function wpse_author_to_publish_box() { if ( ! is_admin() ) return; global $post_ID; $post = get_post( $post_ID ); ?&gt; &lt;div id="author" class="misc-pub-section" style="border-top-style:solid; border-top-width:1px; border-top-color:#EEEEEE; border-bottom-width:0px;"&gt; Author: &lt;?php post_author_meta_box( $post ); ?&gt; &lt;/div&gt; &lt;?php } add_action( 'post_submitbox_misc_actions', 'wpse_author_to_publish_box' ); </code>
Can custom taxonomies be displayed inside of a custom meta box?
wordpress
I have a taxonomy eg. authors. I want to create a custom UI for. I think integrating with a Meta Box together with other post meta will make things easier for the user. Also I think a jQuery UI AutoComplete (Multiple comma separated values) is more appropriate So I will need to know how I can "update_post_taxonomy". I suppose I will need to if taxonomy does not exists create it if post does not have the taxonomy term add it remove terms that are not specified by user I am sure there are functions for this?
The function you are looking for is <code> wp_set_post_terms() </code> which can create the terms if they don't exists and you can specify if to appended or replace existing terms. so you can remove all none user terms. as for if post does not have the taxonomy term , add it you can use <code> wp_get_post_terms() </code> to check if the post has any terms of that taxonomy and if not then you can create and add using <code> wp_set_post_terms() </code> once again
How to update post taxonomies (Creating a custom UI for Custom Taxonomy)
wordpress
I am manipulating an img element in functions.php using jQuery by changing the src attr on hover. How do I make so the absolute path works? Currently, when I view the image directly in the browser it brings me to 404 page. Relative path doesn't work either.
i always start every theme w/ some constants ` define('THEME', get_bloginfo('stylesheet_directory')); //or you could use this one: //define('THEME', get_stylesheet_directory_uri()); define('IMAGES', THEME . '/images'); ` and some others, but the point is that at any place in my code i can point to my theme's image folder <code> img src = "&lt;?php echo IMAGES . '/image.png';?&gt;" </code>
Absolute path to stylesheet_dir/images/my_img.jpg does not work?
wordpress
I installed the Wordpress System Health Plugin and it says that the revisions table in my database is at 70% capacity with 994 rows. I don't fully understand what this means. I anticipate that my site will get much larger than it is today. Questions Am I going to run into trouble or is there some way I can increase that table's capacity? Is it a hosting issue? One proactive thing I have done is set a max number of post revisions to 4. Any solution or an explanation to help me understand what's going on would be really appreciated. Thanks for your help.
SQL query to run via phpmyadmin <code> DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision' </code> That query will remove all post revisions from your wp database,, But remember always back up your database before running any direct SQL query.. you can also add a line into wp_config.php that will disable revisions (optional, i use it as i find revisions a bit of a pain) <code> define('WP_POST_REVISIONS', false); </code>
The revisions table in my database is at 70% capacity and growing. What should I do?
wordpress
Is there a way to wrap a wordpress shortcode around a div in a template file? Here is my code: <code> &lt;div id="subscription"&gt; &lt;?php do_shortcode('[subscribe]');?&gt; &lt;p&gt;This is subscription text&lt;/p&gt; &lt;/div&gt; </code> I've also tried <code> &lt;div id="subscription"&gt; &lt;?php do_shortcode('[subscribe]');?&gt; &lt;p&gt;This is subscription text&lt;/p&gt; &lt;?php do_shortcode('[/subscribe]');?&gt; &lt;/div&gt; </code>
If by template file you mean a php file in the themes folder, you can call do_shortcode to have the shortcode processor do its magic on your div. EDIT: not entirely sure I understand what you want, but you could try this: <code> &lt;div id="subscription"&gt; &lt;?php do_shortcode('[subscribe]'.call_php_function().'[/subscribe]');?&gt; &lt;/div&gt; </code>
Wordpress Shortcode wrap around div
wordpress
I prefer not to use asterisk markers on required fields in the comment form. So I'd like to remove or alter the 'required fields are marked (*)' message. Being a good wordpress user, I'd like to do it with my functions.php. I can work out how to filter most areas of the form, but not this. I'm guessing it will involve modifying the 'comment-notes-before' field of the 'defaults' array, but I can't quite see how to do that.
What you need to use is <code> comment_form_defaults </code> filter that has large and nested <code> $defaults </code> array passed. That array will have (among other things) something like this in it: <code> fields author &lt;&lt; this will have something like &lt;span class="required"&gt;*&lt;/span&gt; in it email &lt;&lt; this will have something like &lt;span class="required"&gt;*&lt;/span&gt; in it url comment_notes_before &lt;&lt; this will have something like Required fields are marked&lt;span class="required"&gt;*&lt;/span&gt; in it </code> So in your filter you need to change these fields in array you got passed and return whole array.
Alter required message using comment form api
wordpress
I'd like to have a query that returns posts grouped five by five. Right now I have a simple query loop like this one : <code> &lt;?php if( $query-&gt;have_posts() ) : ?&gt; &lt;ul class="posts"&gt; &lt;?php while ( $query-&gt;have_posts() ) : $query-&gt;the_post(); ?&gt; &lt;li&gt; &lt;?php the_title(); ?&gt; &lt;/li&gt; &lt;?php endwhile; ?&gt; &lt;/ul&gt; &lt;?php endif; ?&gt; </code> It outputs : <code> &lt;ul class="posts"&gt; &lt;li&gt;post 1&lt;/li&gt; &lt;li&gt;post 2&lt;/li&gt; &lt;li&gt;post 3&lt;/li&gt; &lt;li&gt;post 4&lt;/li&gt; &lt;li&gt;post 5&lt;/li&gt; &lt;li&gt;post 6&lt;/li&gt; &lt;li&gt;post 7&lt;/li&gt; &lt;li&gt;post 8&lt;/li&gt; &lt;li&gt;post 9&lt;/li&gt; &lt;li&gt;post 10&lt;/li&gt; &lt;/ul&gt; </code> Instead, what I'd like to have is : <code> &lt;ul class="posts"&gt; &lt;li&gt;post 1&lt;/li&gt; &lt;li&gt;post 2&lt;/li&gt; &lt;li&gt;post 3&lt;/li&gt; &lt;li&gt;post 4&lt;/li&gt; &lt;li&gt;post 5&lt;/li&gt; &lt;/ul&gt; &lt;ul class="posts"&gt; &lt;li&gt;post 6&lt;/li&gt; &lt;li&gt;post 7&lt;/li&gt; &lt;li&gt;post 8&lt;/li&gt; &lt;li&gt;post 9&lt;/li&gt; &lt;li&gt;post 10&lt;/li&gt; &lt;/ul&gt; </code> How can this be done ?
you can create a simple counter and condition: <code> &lt;?php $count = 0; ?&gt; &lt;?php if( $query-&gt;have_posts() ) : ?&gt; &lt;ul class="posts"&gt; &lt;?php while ( $query-&gt;have_posts() ) : $query-&gt;the_post(); if ($count &lt; 5){ ?&gt; &lt;li&gt; &lt;?php the_title(); ?&gt; &lt;/li&gt; &lt;?php }else{ echo '&lt;/ul&gt;&lt;ul class="posts"&gt;'; ?&gt; &lt;li&gt; &lt;?php the_title(); ?&gt; &lt;/li&gt; &lt;?php $count = 0; } $count = $count + 1; &lt;?php endwhile; ?&gt; &lt;/ul&gt; &lt;?php endif; ?&gt; </code>
How to setup a query to output posts by groups of five?
wordpress
I need to find only posts with a tag <code> forest gump </code> . I've tried: <code> new WP_Query('tag=forest+gump'); </code> , <code> new WP_Query('tag=forest gump'); </code> . However they both return ALL the posts and not only the posts with <code> forest gump </code> tag. Single tags (without spaces) work fine, though. Alternatives (like plain SQL) will work as well. The entry tag line is <code> forest gump, forrest gump, questend </code> .
<code> new WP_Query(array('tag_slug__in' =&gt; array('forrest-gump', 'forest-gump', 'questend'))); </code> <code> new WP_Query('tag=forrest+gump,forest+gump,questend'); </code> should work too...
tag search using WP_Query
wordpress
I just created a web page that uses a lot of JavaScript to build a fancy form that helps build an build the object/html behind an mp3 player for a user. I got it working and tested in a plain-html page outside of WordPress. I then copied into a WordPress "page", took out the &lt;head&gt; tag, changed &lt;body&gt; to a &lt;div&gt;, but no luck. Can it even be done? I also want to use a small javascript to open up a video-player in a new small browser-window. Working on raw html page: http://learnhowtoputaudioonyoursite.com/TestMP3Player.html Not working in WP page: http://learnhowtoputaudioonyoursite.com/build-player
You'd be much better off creating a custom page template , pasting your HTML into the file, then simply attaching the template to a page in the admin. WordPress applies a lot of filtering on post/page content , and it's probably wreaking havoc with your code (not to mention you've got things there that belong in the <code> &lt;head /&gt; </code> ). UPDATE: Create a PHP file in your theme folder (name it template-something.php); <code> &lt;?php /* Template Name: My Template Something */ ?&gt; &lt;!-- any PHP &amp; HTML goes here!! --&gt; &lt;!-- Note: Should be a complete HTML document if not calling get_header() --&gt; </code>
Use of Javascript with Dojo/Dijit on a WordPress page
wordpress
I have installed wordpress in directory above the root called "wp". I'm having issues with the google xml sitemap generator. I cannot rebuild the xml code and write it the sitemap.xml file. I have been on the phone with my hosting company and they assure me the file does have full control for its file permissions. Does anyone have any advice for this?
Hate to self promote BUT ;) My WordPress SEO plugin actually fixes this by not generating a static file at all. It works in all circumstances.
google xml sitemap won't work on directory install
wordpress
Okay, let's assume that I want to create a dynamic "printable" page using a system that doesn't play well with wordpress's theming engine, is there a way for me to define a "permalink" in my plugin that will call a predefined function, also in my plugin? If you're familiar with Drupal it's similar to how their hook_menu works, but I only need it on a very limited basis, so it doesn't have to be that robust.
Something along the lines of this would probably do it: <code> function wpse21372_init(){ add_rewrite_rule( 'your-page-regex/?$', 'index.php?wpse21372=1', 'top' ); add_rewrite_tag( '%wpse21372%', '([^&amp;]+)' ); } add_action( 'wp', 'wpse21372_wp' ); function wpse21372_wp( $wp ){ if( isset( $wp-&gt;query_vars['wpse21372'] ) &amp;&amp; !empty( $wp-&gt;query_vars['wpse21372'] ) ){ //You're on your custom page. //you may want to exit page //execution when you're done //so the rest of WordPress' //normal execution doesn't take //over from here. } } </code> After you're done adding that code, make sure you flush the rewrite rules by going to Settings -> Permalinks.
Creating a path in a plugin to call a function
wordpress
I am creating a largely static site for the collections/archives office of a library. Since I am expecting most content to be created once and slowly appended or modified over time, instead of regular posts, my first inclination is to make everything a page. On the other hand, I have pages/posts that exist in two or 3 categories that I would really love to be able to generate listings of and I cannot think of a good way to do this except by using categories and posts. I know that there is a plugin allowing you tag pages with categories, but get_posts does not always work when I do this. Is the fact that I have content that needs multiple categories and have overlaps with each other more important than the fact that this content should largely be static? I have an collection that is made up of sites dedicated to specific topics. If I made each of those mini sites a post type, I could then make the main page loop through those posts to create entries on the collections main page and now that as long as they were tagged properly, items would show up there. So, is static content the only determiner of whether something is a page or a post?
the way WordPress stores pages in the database is the same as it stores posts, so it makes no difference if the content is created as pages or posts (static or not). And if most of the content is static you can always use a caching plugin to serve that content as static.
Posts vs Pages and categories
wordpress
I have page called "Apple", the page's ID id 2533. In page.php file I have line: <code> echo $bannerimg </code> And this function in functions.php: <code> if ( is_page( '2533' ) ) { // also tested with 'Apple' $bannerimg = 'apple.jpg'; } elseif ( is_page( 'test' ) ) { $bannerimg = 'test.jpg'; } elseif ( is_page( 'admissions' ) ) { $bannerimg = 'admissions.jpg'; } else { $bannerimg = 'home.jpg'; } </code> The point is the $bannerimg echoes "home.jpg" on every page, including Apple, test and admissions. I've even checked all the IDs using the_ID &amp; $page-> ID. Nothing. So I guess there's something wrong with the code above?
<code> functions.php </code> is processed way before you can know which page is being loaded. Instead of assigning value to variable put your code into function and use that function in <code> page.php </code> template.
Why isn't is_page working when I put it in the functions.php file?
wordpress
I'm having an interesting problem that I can't seem to solve. While creating a widget, I have created a select field with options that can be chosen on the widget screen. It all works perfectly fine, except when I save the widget, all of the options in the select field vanish. They all come back, with my chosen option saved, as soon as I refresh. The code for each of the select options looks like this: <code> foreach ($posttypes as $option) { echo '&lt;option id="' . $option-&gt;name . '"', $posttype == $option-&gt;name ? ' selected="selected"' : '', '&gt;', $option-&gt;name, '&lt;/option&gt;'; } </code> In this case, $posttypes is an array of post types. When the select fields are rendered, they look like this: <code> &lt;select name="option-name" id="option-name"&gt; &lt;option value="option-value"&gt;Option Value&lt;/option&gt; &lt;option value="option-value"&gt;Option Value&lt;/option&gt; &lt;option value="option-value"&gt;Option Value&lt;/option&gt; &lt;/select&gt; </code> Any ideas why they would vanish like this?
Found it. There was an extra closing slash on the opening select field.
SELECT field options disappear when saving widget
wordpress
Is there an straight-forward example anywhere of using wp_update_post() to edit post_meta on the front end? I have not been able to find any good learning resources. What I want to do is display post meta in an input field and when a user clicks submit trigger <code> wp_update_post(); </code> . Thanks!
<code> wp_update_post </code> isn't used for updating custom fields (ie postmeta content) - you should use <code> update_post_meta </code>
What action hook updates post meta?
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
I don't think you fully understand the meaning of templates in WordPress. You do not choose template by including it in URL, WordPress deals with choosing template by making sense of URL request. See Template Hierarchy in Codex.
How to display both home.php and index.php
wordpress
I have a custom post type, called App. This has details like the name, description, thumbnail image, and some custom fields. Then I have posts about this app, that I'd like to associate with it. In the end, I'd like to be able to view the custom post type and all the posts that are associated with it. But I don't see any way to associate a post with anything besides a category or tag. But categories and tags don't allow for custom fields, images, etc. Is the only way to create a category with the same name as the custom post type, and then do something like have a custom field in that custom post type that has the ID of that category? Thanks!
No you don't really have to create a category to associate your different post types. You can use this great Post 2 Post plugin by scribu. It does exactly what you are trying to do.
Associate custom post types with normal posts
wordpress
I have written a small class that will handle enqueues in my theme : <code> &lt;?php class Header { public function init_hooks() { add_action('wp_print_scripts', array(__CLASS__,'include_all_files')); } public function include_css_files() { wp_register_script('style.css', get_bloginfo('stylesheet_url')); wp_enqueue_script('style.css'); } public function include_js_files() { wp_register_script('jquery-min', "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"); wp_enqueue_script('jquery-min'); } public function include_all_files() { $this-&gt;include_css_files(); $this-&gt;include_js_files(); } } ?&gt; </code> I call it right before closing the head tag, like : <code> $header = new Header(); $header-&gt;init_hooks(); </code> But it does not work. There is no error, but no script is added. Any ideas ?
You mean you call your class right before closing HTML tag? It is too late to enqueue scripts then. Don't hook into <code> wp_print_scripts </code> to enqueue your scripts and styles. I just stackexchange-url ("learned") this today from Rarst. So change your init_hooks function to something like following: <code> public function init_hooks() { add_action('wp_enqueue_scripts', array(__CLASS__,'include_all_files')); } </code> Also you are using <code> wp_register_script </code> and <code> wp_enqueue_script </code> functions to enqueue your styles, Wordpress has separate functions to enqueue your styles <code> wp_register_style </code> and <code> wp_enqueue_style </code> . Your <code> include_css_files </code> should look like: <code> public function include_css_files() { // NOTE: you don't really have to use the filename as style slug. wp_register_style('my_style', get_bloginfo('stylesheet_url')); wp_enqueue_style('my_style'); } </code> Now about instantiating your class and calling init_hooks. You can either place it directly inside your functions.php, or you can use the init action to instantiate your class.
Enqueue scripts inside a class
wordpress
Is it possible to add a checkbox to all widgets loaded into sidebars? For example, I'd like to allow the site owner to choose whether any widget should appear on the home page, inside pages, both or neither. I'm thinking a checkbox interface appended to the widget control interface. Has anyone done something like this and what level of complexity are we talking?
There are plugins that can do this like Widget Context or Widget Logic . If you want your own solution then it's pretty easy: hook your function with the checkbox on <code> in_widget_form </code> hook your widget update function <code> widget_update_callback </code> (update the widget option) check if the option was checked using the <code> widget_display_callback </code> hook (return false if it is) Post what you have so far if you need sample code. I've implemented a feature like this in one of my themes...
Option to show/hide widget depending on is_home?
wordpress
I need to switch WordPress's post context, sort of like <code> switch_to_blog() </code> but for posts. What's the safest way to alter WordPress's global state and switch it back?
Use <code> setup_postdata() </code> to change and <code> wp_reset_postdata() </code> to roll back to original.
What's the safest way to switch and restore a post global?
wordpress
In the multi-site wordpress install, you get a very nice "upload settings" in the network admin settings. (see attached image). I am trying to change these settings without using php.ini for a single-site wordpress install and I can't find them anywhere... help? Tim Attached: Network Admin Settings Example:
create an file <code> php.ini </code> and copy via ftp or ssh to wp-admin; inside this file the follow values; play with values for test and see the result. <code> memory_limit = 32M upload_max_filesize = 32M post_max_size = 32M file_uploads = On </code>
How do I change the upload file size limit in single-site wordpress install?
wordpress
Normally when using a rich text editor, when you hit return (i.e. do a full paragraph return) Your text is wrapped i.e. <code> &lt;p&gt; my text &lt;/p&gt; </code> however this does not happen in wordpress. Is there any way to trigger this functionality?
This happens at the time the content is output the browser. At that point, the content is passed through several filters, one of which is called <code> wpautop </code> . This filter function is defined in <code> wp-includes/formatting.php </code> . In combination with the other default WordPress filters, this generally means that you can compose content in the HTML (non-wysiwyg) editor as if you were writing plain text, and it will format the final HTML output in a logical, intuitive manner. On the other hand, you can also feel free to manually compose HTML tags in your output, and WP will preserve your tags. There are some edge-cases that can get you sometimes (using non-standard tags or attributes), but for the most part, the editor and the filters are pretty smart.
Why does the HTML editor not wrap my code in paragraph tags when I press enter
wordpress
When I add an image to a post I want it to be in a div e.g. , and I want that to be done automatically, so I don't have to do that in HTML editor. I don't want to use js to accomplish this and by the way I want to know how to automatically add custom classes to a image in a post. Cheers!
By default images already have unique class's but this depends on your theme. Use firebug and hover over the images and you should see stuff like <code> class="aligncenter size-full wp-image-1525" </code> . If you want to change the class or id or alter any attributes of the image you can use the <code> get_image_tag </code> filter. For example, <code> add_filter('get_image_tag_class','my_custom_class'); function my_custom_class($class){ $class='my_custom_name'; return $class; } </code>
How to wrap every image in a post with a div?
wordpress
I'm one of the contributors for the Meta Box Class here on Github ( link ) and before I get too deep, I wanted to ask if anyone knew of a straight forward way to allow users to add additional fields "on the fly", having an "add" button with a text field to add additional fields (i.e. list items). I've seen this done a few ways in the past, but I'm all for not reinventing the wheel.
Agreed, I've seen it too, but I don't think there's any readily available API or method. For me, I use a lick of jQuery; <code> &lt;input type="text" class="list-item" name="list_items[]" /&gt; &lt;input type="button" class="button-secondary" id="add-list" /&gt; &lt;script type="text/javascript"&gt; ( function( $ ) { $( '#add-list' ).click( function() { var $item = $( '.list-item:last' ), $new = $item.clone(); $item.after( $new.val( '' ) ); } })( jQuery ); &lt;/script&gt; </code> Note that you might wanna tweak those selectors if you plan on having multiple 'instances' of these.
Add custom fields within meta box class "on the fly"
wordpress
I'm trying to figure out how to do, Second Level Menu as a template function, that persistent when visiting any level, whether its a top level page, or a grand children Page. Any Ideas?
example: <code> &lt;?php //get top level page ID; $top = ( $post-&gt;post_parent ) ? array_pop(get_post_ancestors($post-&gt;ID)) : $post-&gt;ID; echo '&lt;ul&gt;'; wp_list_pages('title_li=&amp;child_of='.$top.'&amp;depth=1'); echo '&lt;/ul&gt;'; ?&gt; </code>
Second Level Menu
wordpress
Thanks to @Anu's stackexchange-url ("correction") I now have a function to update_post_meta from the front end. Something is wrong in my script however, because with the function below nothing is being displayed on the page. It only displays is a white screen. if I take out the <code> if ( empty($_POST) || </code> section the page template will display, but any changes I make to the form are not saving. What am I missing? <code> // top of page if ( empty($_POST) || !wp_verify_nonce($_POST['name_of_nonce_field'],'name_of_my_action') ) { //if fail nonce check, exit script exit; } else : { global $post; $postid = $post-&gt;ID; $data = $_POST['priceone']; update_post_meta($postid,'metakey',$data); } endif; // in single.php $priceone = get_post_meta($post-&gt;ID, 'priceone', true); &lt;form method="post" action=""&gt; &lt;?php wp_nonce_field('update_drw_postmeta','drw_inventory'); ?&gt; &lt;label&gt;This is label&lt;/label&gt; &lt;input type='text' name='priceone' value='&lt;?php echo $priceone ?&gt;' /&gt; &lt;input type='submit' value='save' /&gt; &lt;/form&gt; </code>
Change your nonce verify to actually verify and update post meta, else do nothing. But don't use exit at the top of your template. <code> // top of page if ( isset( $_POST['drw_inventory'] ) &amp;&amp; wp_verify_nonce($_POST['drw_inventory'],'update_drw_postmeta') ) { //if nonce check succeeds. global $post; $postid = $post-&gt;ID; $data = $_POST['priceone']; update_post_meta($postid,'metakey',$data); } // in single.php $priceone = get_post_meta($post-&gt;ID, 'priceone', true); &lt;form method="post" action=""&gt; &lt;?php wp_nonce_field('update_drw_postmeta','drw_inventory'); ?&gt; &lt;label&gt;This is label&lt;/label&gt; &lt;input type='text' name='priceone' value='&lt;?php echo $priceone ?&gt;' /&gt; &lt;input type='submit' value='save' /&gt; &lt;/form&gt; </code>
Front-end update_post_meta snippet displays white screen?
wordpress