question
stringlengths 0
34.8k
| answer
stringlengths 0
28.3k
| title
stringlengths 7
150
| forum_tag
stringclasses 12
values |
---|---|---|---|
Shortcode: <code> [permalink][title][/permalink] </code> Output: <code> <a href="foobar">[title]</a> </code> Wordpress shortcode API sais, it's correct: http://codex.wordpress.org/Shortcode_API#Nested_Shortcodes Any Ideas?
|
From the page you linked: The shortcode parser correctly deals with nested shortcode macros, provided their handler functions support it by recursively calling do_shortcode(): You need to recursively call <code> do_shortcode() </code> on any shortcode handler that could contain nested shortcodes. So for example: <code> function wpse18659_permalink( $atts, $content ){ return '<a href="' . get_permalink() . '" title="Permalink to ' . get_the_title() . '" alt="">' . do_shortcode( $content ) . '</a>'; } add_shortcode( 'permalink', 'wpse18659_permalink' ); </code> That should handle nested shortcodes just fine.
|
nested Shortcode doesn't work
|
wordpress
|
Is there a way to add a hook for a plugin when a new author is added by the administrator? I would like to be able to add that user to my plugin database table. Thank you.
|
There's user_register .
|
Plugin Hook When New Author Added
|
wordpress
|
I have installed the audio plugin, to create Xbrowser playlists, but I am getting the following error <code> jPlayer 2.0.0 : id='jquery_jplayer_1' : Error! </code> All I have done so far is create a new post, upload audio to the post using the wordpress audio uploader, added the playlist to the post using the following shortcode, and published. <code> [audio layout="list"] </code> and also tried <code> [audio] </code> but produced the same error The files are .mp3 format, they play in other players fine. The site is stored locally, in case that is relevant.
|
Answered my own question. Kept here for others who may have in the same problem. Turns out, being locally hosted WAS relevant. the problem is line 192 in <code> /wp-content/plugins/audio/js/audio.js </code> <code> swfPath: 'http://' + window.location.host + '/wp-content/plugins/audio/js/', </code> This expects the site to be based at the root <code> / </code> , as mine was in a folder I just changed it to: <code> swfPath: 'http://' + window.location.host + 'MY_SITE/wp-content/plugins/audio/js/', </code> and we're away. Remember: revert to original line when moving to production.
|
Error Using Audio plugin
|
wordpress
|
I am getting <code> function deactivate_plugins does not exist </code> error when calling this function <code> function deactivateSelf(){ deactivate_plugins(RSD_PLUGIN, true); //gives error: function deactivate_plugins does not exist header("Location: plugins.php?deactivate=true"); //redirect to plugin management with message die(); } </code> the function <code> deactivate_plugins </code> is on the server in <code> /wp-admin/wp-includes/plugin.php </code> the function deactivateSelf works on my developer's computer but not on my linode server I downloaded http://www.turnkeylinux.org/wordpress , which should have pretty standard configuration and I got the same error. I tried to upgrade wp to the latest version and still got the same error. Any idea how to make it work?
|
The file <code> wp-admin/includes/plugin.php </code> is not always included. You may have to do this in your plugin. And your <code> Location </code> header is invalid: You have to send a complete URL. You should use: <code> require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); </code> When do you call this function? Maybe too early.
|
function deactivate_plugins does not exist
|
wordpress
|
I'm thinking maybe limit the number of posts a user can make in a given period of time. (Say a user can only publish 1 post per 5 minutes?) Is there such a plugin?
|
Limit Post Creation Per Day plugin seems to provide this functionality.
|
Restrict the Number of Posts an Author can Publish (over time)?
|
wordpress
|
I built a post interface to accept specific data in the form of custom meta boxes [rant]but now the end user says it's too much work to cut and paste 4 times[/rant]. So now (completely out of original scope) I need to parse the data entered into a new text area meta box and assign each line as a value to 2 existing keys, the_tile and a substr 'd excerpt. (see image) Actually it really doesn't need to use the existing keys. It can use new ones or just be assigned to a new $variable (I would rather parse on save than on query). The meta boxes are built using a class that handles the saving and updating, I just need to know how to split of the new field. I also have to conditionally determine if they used the individual boxes or the new text area box. One of the meta boxes is for an external url. I have to check if it exists. If it's null the the template uses the permalink. The use case is very specific as all the data is output in specific places on various sized boxes. See below: The order I need to parse the data: title <code> <---- I'm saying this one is optional (They still have to enter a post title) </code> source `<---- meta_key is $prefix.'article-source' excerpt <code> <--- the_excerpt but can be a new key </code> It can only output 115 characters to avoid breaking the layout. We also have to check if anything was entered into the real WordPress excerpt box before we decide to do any of this. click-through-url <code> <--- meta_key is $prefix.'external_link </code> All this code works fine. Just adding it to show how the data is used. <code> while ($box_query->have_posts()) : $box_query->the_post(); global $post; global $prefix; $box_size = c3m_get_field( $prefix.'box_size', FALSE ); $box_image = c3m_get_field( $prefix.'post_box_image', FALSE ); $overlay_class = c3m_get_field( $prefix.'overlay_class', FALSE ); $ad_code = c3m_get_field( $prefix.'ad_code', FALSE ); $source = c3m_get_field( $prefix.'article-source', FALSE ); if ( c3m_get_field($prefix.'external_link', FALSE) ) { $post_link = c3m_get_field($prefix.'external_link', FALSE) ; } else { $post_link = post_permalink(); } ?> <li class="ui-state-default <?php echo $box_size;?>"> <article <?php post_class() ?>> <?php if ( $ad_code ) { ?> <div class="ad-box <?php echo $overlay_class;?>"> <?php echo $ad_code; } else { echo '<a href="'.$post_link.'" ><img src="'.esc_url($box_image).'" alt="Image via xxxxxxxxxx.com" /></a>'; ?> <div class="post-box <?php echo $overlay_class;?>"> <?php if ( c3m_get_field( $prefix.'text_display', FALSE) ) { ?> <h2><a href="<?php echo $post_link?>"><?php the_title();?></a></h2> <p><?php if ( $source ) { echo '(' .$source. ') '; } if ( $box_size == 'double-single' ) { echo substr( $post->post_excerpt, 0, 300) .'...'; ?></p> <?php } else { echo substr( $post->post_excerpt, 0, 115) .'...' ; ?></p> <?php } ?> <?php } ?> <?php } ?> </code> So the question is How do take 4 cr break lines pasted into 1 meta box and assign a variable to each line. Thanks and I'll hang up and listen. Edit: The information pasted will be 4 lines First Line: Title Second Line: Source Third Line: Short excerpt Fourth Line: Link Url Example: After 4 Years, Egypt Reopens Its Border With Gaza Strip New York Times Hundreds of Palestinian residents of the Gaza Strip arrived here by the busload Saturday to pass through the reopened border into Egypt. http://www.nytimes.com/2011/05/29/world/middleeast/29egypt.html?_r=1&hp That input will look like this on the front end. The title links to the link url:
|
This is a very simple script that will split up the text of the box in different lines and fill them in in the title, excerpt and two custom fields. <code> jQuery( function( $ ) { $( '#wpse18528_paste_box' ).keyup( function() { var text = $( '#wpse18528_paste_box' ).val(); var lines = text.split( /[\n\r]+/ ); $( '#title' ).val( lines[0] ); $( '#title' ).siblings( '#title-prompt-text' ).css( 'visibility', 'hidden' ); $( '#excerpt' ).val( lines[2] ); $( '#wpse18528_source' ).val( lines[1] ); $( '#wpse18528_link' ).val( lines[3] ); } ); } ); </code> The current regex is one or more linebreaks - I don't know if you want this? Also, instead of triggering this on each <code> keyup </code> (which works nicely with pasting and editing small errors in the "lazy box"), you can also add a "Split" button and use the <code> click </code> event of it.
|
Parse a text area custom meta box and assign as value to existing meta keys
|
wordpress
|
I'd like to include Pages in my RSS feed. Whenever I add or edit a page, I'd like it to show up in the feed. I can't seem to find any setting in the default WordPress installation or in the default (TwentyTen) theme. Is there a theme or plugin which can do this? I'm using the latest version of WordPress (3.1.3).
|
Adding the following code to your theme function file (functions.php) will solve your problem: <code> // Add Pages to RSS Feeds function myfeed_request($qv) { if (isset($qv['feed']) && !isset($qv['post_type'])) $qv['post_type'] = array('post', 'page'); return $qv; } </code> Credit: http://www.wpbeginner.com/wp-tutorials/how-to-add-custom-post-types-to-your-main-wordpress-rss-feed/
|
How to add pages to feed?
|
wordpress
|
Working on a new site, I'm trying to plant recent post excerpts on a static front-page. I had been doing all my static content outside of wordpress (as static files), but was convinced to pull everything into the WP fold, so to speak. On my external static file that was serving as my home page, I had figured out how to include the blog header <code> <?php require('../wordpress/wp-blog-header.php'); ?> </code> and then call up posts on that page, and it worked like a charm: <code> <?php $count = 0; ?> <?php if ( have_posts() ) while ( have_posts() && $count <= 6 ) : the_post(); ?> <section class="post"> <header class="post"> <h2><a class="light" href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2> <?php twentyten_posted_on(); ?> <div class="hr"></div> </header> <article class="post"> <?php the_excerpt(); ?> </article> <footer class="post"> <?php twentyten_posted_in(); ?> </footer> </section> <?php $count++; ?> <?php endwhile; // end of the loop. ?> </code> So, now, I have set up a wordpress front-page template , and it is being delivered dynamically, using the my theme header and this same chunk of the loop, I am getting not posts , but pages back. Instead of seeing a set of current posts, I get back some title info for the 3 wp pages currently on my site. I get that this is due to url query variables, but I'm not exactly clear how to get arround it. I tried manually calling up a <code> new WP-Query(); </code> but that returned nothing at all. Tho I suspect that it may work, given the proper arguments... Any thoughts on how to pull in recent posts, instead of a list of pages, to a static front-page with this modified loop? Much appreciated -
|
Ah - got it - was almost there with the new WP_Query, but was failing to call the query method on it... This works perfectly: <code> <?php $excerptQuery = new WP_Query(); $excerptQuery->query('showposts=6'); ?> <?php if ( $excerptQuery->have_posts() ) while ( $excerptQuery->have_posts()) : $excerptQuery->the_post(); ?> <section class="post"> <header class="post"> <h2><a class="light" href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2> <?php twentyten_posted_on(); ?> <div class="hr"></div> </header> <article class="post"> <?php the_excerpt(); ?> </article> <footer class="post"> <?php twentyten_posted_in(); ?> </footer> </section> <?php endwhile; // end of the loop. ?> </code>
|
Static Front-Page Excerpts
|
wordpress
|
For example, we have some image on the external site: http://site.com/image.png How do I upload this image to my wordpress as an image attachment by php? Image should be copied to my uploads folder, post added, meta generated.
|
You can <code> media_sideload_image() </code> function to upload your files ex: <code> $upload = media_sideload_image( $url, $post_id ); </code> or you can use a plugin like Cache Images which uploads all external images to your server as attachments.
|
Upload attachment from external site
|
wordpress
|
some of my posts have the post meta of "project_id". How can I retrive all the posts which have the meta key of "project_id" ? I tried: <code> $meta_key = 'project_id'; return $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->postmeta WHERE meta_key = %s", $meta_key)); </code> It returns nothing. Please help! Thanks!
|
As simple as this: <code> $the_posts_you_want = get_posts( array( 'meta_key' => 'project_id' ) ); </code> <code> foreach ( $the_posts_you_want as $post ) { // Do whatever you need in here... // Read further how to inspect the post object: stackexchange-url // echo each meta key echo $post->whatever; // or save it into a new array for further processing $project_ids = array(); $project_ids[] = $post->whatever; } // If you saved them into an array, you can continue here... foreach ( $project_ids as $id ) { // do stuff } </code>
|
how to get all post with the same post meta?
|
wordpress
|
So I did something like below, but I get just (I am expecting a Facebook textbox?) I hope its not too messy. I am new to Settings API ... <code> add_action('admin_init', function() { register_setting('elem_opts', 'elem_opts', 'elem_validate_opts'); add_settings_section('elem_opts_form', 'Elements Theme Options', 'elem_opts_form_cb', 'elems_opts'); add_settings_field('elem_opts_form', 'Facebook', 'elem_opts_social_fb_cb', 'elems_opts', 'elem_opts_form'); }); function elem_opts_social_fb_cb() { $opts = get_option('elem_opts'); if (empty($opts) || !is_array($opts)) { $opts = array(); } ?> <input type="text" name="elem_opts[fb]" value="<?php echo $opts['fb'] ? $opts['fb'] : ''; ?>" /> <?php } add_action('admin_menu', function() { add_theme_page('Elements Options', 'Elements Options', 'manage_options', 'elem_opts', 'elem_opts_cb'); }); function elem_validate_opts($input) { return $input; } function elem_opts_form() { ?> <p>Enable social network links, by entering your username for the respective social networks</p> <?php } function elem_opts_cb() { ?> <div class="wrap"> <h2>Elements Theme Options</h2> <form action="options.php" method="post"> <?php settings_fields('elem_opts'); do_settings_sections('elem_opts'); ?> <input type="submit" name="Submit" value="Save changes" /> </form> </div> <?php } </code>
|
You have some of the callback functions and the ID's mixed up, try this: <code> add_action('admin_init', function() { register_setting('elem_opts', 'elem_opts', 'elem_validate_opts'); add_settings_section('elem_opts_form1', 'Elements Theme Options', 'elem_opts_form', 'elem_opts'); add_settings_field('elem_opts_form', 'Facebook', 'elem_opts_social_fb_cb', 'elem_opts', 'elem_opts_form1'); }); function elem_opts_social_fb_cb() { $opts = get_option('elem_opts'); if (empty($opts) || !is_array($opts)) { $opts = array(); } ?> <input type="text" name="elem_opts[fb]" value="<?php echo $opts['fb'] ? $opts['fb'] : ''; ?>" /> <?php } add_action('admin_menu', function() { add_theme_page('Elements Options', 'Elements Options', 'manage_options', 'elem_opts', 'elem_opts_cb'); }); function elem_validate_opts($input) { return $input; } function elem_opts_form() { ?> <p>Enable social network links, by entering your username for the respective social networks</p> <?php } function elem_opts_cb() { ?> <div class="wrap"> <h2>Elements Theme Options</h2> <form action="options.php" method="post"> <?php settings_fields('elem_opts'); do_settings_sections('elem_opts'); ?> <input type="submit" name="Submit" value="Save changes" /> </form> </div> <?php } </code> which give me this: and for next time try to use different names and ids for each function, callback, section and page slug.
|
Need help understanding/coding with Settings API
|
wordpress
|
I'm building a template for twentyten child theme. I need to add a class in in the template page, but not in other pages.My template inherits the header and footer, so, I can't change any markup there. How can I add a class in there without adding that class to other pages? Thanks a lot for the help.
|
You're probably looking for something like this: <code> <?php function add_classes_to_body_class($classes) { // make sure 'page-template.php' matches your template name if ( is_page_template('page-template.php') ) { $classes[] = 'main'; } return $classes; } add_filter( 'body_class', 'add_classes_to_body_class' ); ?> </code> make sure you add <code> body_class() </code> into your markup. Traditionally it would be in your body tag like so. <code> <body id="foobar" <?php body_class(); ?>> </code>
|
I want to add a class to main div on a template. how can I do that?
|
wordpress
|
I have a multisite installation, and I was changing the settings of one of my sites from the mu administration panel when I came across a setting called <code> Use BalanceTags </code> . Out of curiosity, what does that setting do?
|
balanceTags fixes incorrectly nested html markup, for instance if you had an opening tag but no closing tag, or if they're closed in the wrong order.
|
What does "Use BalanceTags" Do?
|
wordpress
|
I've created custom taxonomy called <code> Brands </code> and made it hierarchical so I can add Car brands and models there and keep their relations, like this: Ford Mustang Mondeo Focus Problem is, this list might get pretty long and only one brand and one model is needed per post, so checkboxes are misleading. I'm thinking to split that metabox in to two (one for brand and one for model) and make them dropdowns. So when brand is selected in the first dropdown, second dropdown would show only models related to that brand. But i have no idea how to code it. Maybe anyone could show me an example?
|
Here is an example. I have also created a Gist with more generic code. <code> add_action('add_meta_boxes', 'my_custom_metabox'); function my_custom_metabox() { add_meta_box('custom-taxonomy-dropdown','Brands','taxonomy_dropdowns_box','post','side','high'); } function taxonomy_dropdowns_box( $post ) { wp_nonce_field('custom-dropdown', 'dropdown-nonce'); $terms = get_terms( 'brands', 'hide_empty=0'); $object_terms = wp_get_object_terms( $post->ID, 'brands', array('fields'=>'ids')); // you can move the below java script to admin_head ?> <script type="text/javascript"> jQuery(document).ready(function() { jQuery('#custombrandoptions').change(function() { var custombrand = jQuery('#custombrandoptions').val(); if ( custombrand == '0') { jQuery('#custommodeloptions').html(''); jQuery('#modelcontainer').css('display', 'none'); } else { var data = { 'action':'get_brand_models', 'custombrand':custombrand, 'dropdown-nonce': jQuery('#dropdown-nonce').val() }; jQuery.post(ajaxurl, data, function(response){ jQuery('#custommodeloptions').html(response); jQuery('#modelcontainer').css('display', 'inline'); }); } }); }); </script> <?php echo "Brand:"; echo "<select id='custombrandoptions' name='custombrands[]'>"; echo "<option value='0'>None</option>"; foreach ( $terms as $term ) { if ( $term->parent == 0) { if ( in_array($term->term_id, $object_terms) ) { $parent_id = $term->term_id; echo "<option value='{$term->term_id}' selected='selected'>{$term->name}</option>"; } else { echo "<option value='{$term->term_id}'>{$term->name}</option>"; } } } echo "</select><br />"; echo "<div id='modelcontainer'"; if ( !isset( $parent_id)) echo " style='display: none;'"; echo ">"; echo "Models:"; echo "<select id='custommodeloptions' name='custombrands[]'>"; if ( isset( $parent_id)) { $models = get_terms( 'brands', 'hide_empty=0&child_of='.$parent_id); foreach ( $models as $model ) { if ( in_array($model->term_id, $object_terms) ) { echo "<option value='{$model->term_id}' selected='selected'>{$model->name}</option>"; } else { echo "<option value='{$model->term_id}'>{$model->name}</option>"; } } } echo "</select>"; echo "</div>"; } add_action('save_post','save_my_custom_taxonomy'); function save_my_custom_taxonomy( $post_id ) { if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return; if ( !wp_verify_nonce($_POST['dropdown-nonce'], 'custom-dropdown')) return; $brands = array_map('intval', $_POST['custombrands']); wp_set_object_terms($post_id, $brands, 'brands'); } add_action('wp_ajax_get_brand_models', 'get_brand_models'); function get_brand_models() { check_ajax_referer('custom-dropdown', 'dropdown-nonce'); if (isset($_POST['custombrand'])) { $models = get_terms( 'brands', 'hide_empty=0&child_of='. $_POST['custombrand']); echo "<option value='0'>Select one</option>"; foreach ($models as $model) { echo "<option value='{$model->term_id}'>{$model->name}</option>"; } } die(); } </code>
|
Taxonomy dropdown metabox in the back-end
|
wordpress
|
I use the default TwentyTen theme and I have made a child theme with some CSS adjustments, and that's pretty much it. Now I'd like to do two things Make the theme load the latest jQuery, and to load it using the Google CDN. Add a javascript file which would be loaded on every page. What's the best way to do that? I'm a total WordPress newb, so don't really know my way around.
|
Here you go. <code> add_action('init', 'register_custom_jquery'); function register_custom_jquery() { wp_deregister_script('jquery'); wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js', array(), '1.6.1' ); wp_register_script( 'my-custom-script', 'http://example.com/js/script.js', array(), '1.0' ); } add_action('wp_enqueue_scripts', 'add_js_to_page'); function add_js_to_page() { wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'my-custom-script' ); } </code>
|
Best way to add some custom javascript using jquery to a child theme
|
wordpress
|
At the moment I have the following code for changing the author_base slug. <code> /** ADD REWRITE RULES **/ function change_author_permalinks() { global $wp_rewrite; $wp_rewrite->author_base = 'profile'; $wp_rewrite->flush_rules(); } add_action('init','change_author_permalinks'); </code> How can I add, for example, a extra "edit" page on to this, i.e., /profile/my-user-name/edit ???
|
The author rewrite rules are filtered through <code> author_rewrite_rules </code> . You can add a rule there for the pattern <code> author/([^/]+)/edit/?$ </code> , but the substitution will depend on how you want to create the <code> edit </code> page. A simple example that will set a custom query variable and load a specific template if this variable is set: <code> add_action( 'author_rewrite_rules', 'wpse18547_author_rewrite_rules' ); function wpse18547_author_rewrite_rules( $author_rules ) { $author_rules['author/([^/]+)/edit/?$'] = 'index.php?author_name=$matches[1]&wpse18547_author_edit=1'; return $author_rules; } add_filter( 'query_vars', 'wpse18547_query_vars' ); function wpse18547_query_vars( $query_vars ) { $query_vars[] = 'wpse18547_author_edit'; return $query_vars; } add_filter( 'author_template', 'wpse18547_author_template' ); function wpse18547_author_template( $author_template ) { if ( get_query_var( 'wpse18547_author_edit' ) ) { return locate_template( array( 'edit-author.php', $author_template ) ); } return $author_template; } </code> Small tip: Don't call <code> flush_rules() </code> on every <code> init </code> , it's an expensive operation. You only need to do it when the rewrite rules change. You can manually flush the rules by just visiting the Permalinks settings page. And if you are going to play with the rewrite rules, I recommend you install stackexchange-url ("my Rewrite analyzer plugin").
|
Adding more pages to author pages
|
wordpress
|
I remember seeing a search plugin that creates a database log of your pages it use for search. Does anyone know of the plugin? And would this be a good way to make the Widget Text searchable? If not is there a plugin to add widget text to the search?
|
I think Search Engine works by indexing front-end pages.
|
Replacement search plugin that reads widgets or catalogs entire page?
|
wordpress
|
I learned that you can add new cron schedules by using the cron_schedules filter. If I change a interval of a schedule that I added earlier, will a job that uses this schedule be scheduled using this new interval the next time, or will it still use the previous interval?
|
After some testing I figured out that yes, it will use the new schedule, updated using the 'cron_schedules' filter.
|
Will Wordpress use the newer schedule if it is updated using the filter 'cron_schedules'?
|
wordpress
|
it is not the first i see that we "delete" a post meta even if it does not exist : example : <code> $count = get_post_meta($postID, $count_key, true); if($count==''){ $count = 0; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); </code> So if $count is empty, so if it does not exist in the database, we first delete the post meta? Why ? Thanks for your answer
|
The reason why in the code, you show there, that <code> delete_post_meta() </code> is run first, is because <code> add_post_meta() </code> is run after it. If the delete wasn't done first then you would end up with multiple entries stored in the meta table. To be honest it would be better to use <code> update_post_meta() </code> rather than both <code> delete_post_meta() </code> and <code> add_post_meta() </code> . The reason for this is that <code> update_post_meta() </code> will try to update the existing value and if it doesn't exist; will add the value.
|
delete post meta from db, even if does not exist?
|
wordpress
|
My "links" come in from Windows Live Writer, from a perl based delicious sync directly to the database and who knows where from. They all have in common that the category is 'Daily-Links'. So I think I will schedule a cron that every day checks for all posts in the category 'Daily Links' and then adds the post format type 'format-link' to it. (since e.g. WLW does not support 'post formats') Or is there a better approach? I wanted to kick this off by running a SQL query since it are probably hunderds of posts (for each object_id,term_taxonomy_id pair which has not already term_taxonomy_id=(id of format-link) AND which has the term_taxonomy_id of (the specific category) DO add the term_taxonomy_id of the format-link) But... maybe there is already a WP function call for this? Is there?
|
Hook save_post and add the post format if the post is for that category. (save_post) Runs whenever a post or page is created or updated, which could be from an import, post/page edit form, xmlrpc, or post by email.
|
How can I convert everything from category X to have post format Link
|
wordpress
|
I'm running this code to tell me what plugins need updating: <code> $update_plugins = get_site_transient('update_plugins'); </code> Here is an example return: <code> Array ( [login-lockdown/loginlockdown.php] => stdClass Object ( [id] => 3760 [slug] => login-lockdown [new_version] => v1.5 [url] => http://wordpress.org/extend/plugins/login-lockdown/ [package] => http://downloads.wordpress.org/plugin/login-lockdown.1.5.zip ) ) </code> From that it doesn't tell me the name of the plugin that needs updating. Is there a WordPress function that you can feed the plugin file name like: <code> ogin-lockdown/loginlockdown.php </code> and return the plugin name? In this case I'd want <code> Login LockDown </code> to be returned.
|
I think you'll have to work via <code> get_plugins() </code> . It will return a list of all plugins in your plugin folder, indexed by plugin location - which is the same as your array index. This is also what the plugin administration table uses . If you only need the data from one file you could also call <code> get_plugin_data() </code> directly. <code> get_plugins() </code> basically just calls that function in a loop, and caches the result.
|
How to get plugin name from plugin file location
|
wordpress
|
I'm using the code below to first grab the post's attachments (if they're either a Word doc or pdf file), then echoing the url of said attachment. This works great on the first post on a page. However, on each subsequent post the same attachment url is echoed, even if that post doesn't have an attachment. How can I keep that from happening? <code> $args = array( 'post_type' => 'attachment', 'post_mime_type' => array('application/doc','application/pdf'), 'numberposts' => 1, 'post_status' => null, 'post_parent' => $post->ID ); $attachments = get_posts( $args ); foreach ($attachments as $attachment) { echo '<a href="' . wp_get_attachment_url( $attachment->ID ) . '">Download Spec Sheet</a>'; echo '</div>'; } </code>
|
Try this: <code> <?php if ( $attachments = get_children( array( 'post_type' => 'attachment', 'post_mime_type' => array('application/doc','application/pdf'), 'numberposts' => 1, 'post_status' => null, 'post_parent' => $post->ID ))); foreach ($attachments as $attachment) { echo '<a href="' . wp_get_attachment_url( $attachment->ID ) . '">Download Spec Sheet</a>'; echo '</div>'; } ?> </code>
|
How can I display a link to a post's (Word doc or pdf) attachment?
|
wordpress
|
At the moment, Wordpress checks the wordpress core for it's updates. But, I'd like to add an additional check to repeat the process for themes and plugins using a seperate address, for updating themes that are not on the core wordpress repositories, such as commercial themes and such. Is this possible? If so how would it be done?
|
There is no native mechanism for WP to check for updates from non-official resources. Some plugins/theme have such functionality of their own for themselves. If you want to implement such checks for arbitrary plugins/themes (coded without such in mind) it is not impossible, but will take loads of custom code and handling different possible sources and downloads.
|
Custom theme/plugin update checks
|
wordpress
|
I removed some widgets from the dashboard in the wrong way (using <code> unset() </code> on <code> $wp_meta_boxes </code> ) and as a side effect my dashboard widget area is now split into 4 columns, but with just the first 2 having the normal default widgets in, thus the page is squashed. Is there a way to change the amount of widget columns in the dashboard? They are all active as I can drag and drop the widgets around, but now 4 is too many. I am using Wordpress 3.1.3 so don't have the new admin interface yet.
|
Under "Screen Options", you can change the number of columns. Does that fix your problem?
|
Change number of widget columns in dashboard?
|
wordpress
|
There is something missing because this is driving me crazy at the moment. I'm using the wp_query with the following args. <code> $args = array( 'post_type' => 'project', 'post_status' => 'publish', 'meta_query' => array( array( 'key' => '_sf_project_budget', 'value' => '6', //'compare' => '=', //'type' => 'NUMERIC' ) ) ); $search_query = new WP_Query($args); </code> When print_r the $search_query I can see the following: <code> WP_Query Object ( [query_vars] => Array ( [post_type] => project [post_status] => publish [meta_query] => Array ( [0] => Array ( [key] => _sf_project_budget [value] => 6 ) ) </code> But the "SQL" doesn't seem to change: <code> [request] => SELECT SQL_CALC_FOUND_ROWS wps_posts.* FROM wps_posts WHERE 1=1 AND wps_posts.post_type = 'project' AND (wps_posts.post_status = 'publish') ORDER BY wps_posts.post_date DESC LIMIT 0, 10 </code> Shouldn't this change to incorporate the meta query vars? Can't see what I'm doing wrong or what's missing, tried different things and it brings all the posts all the time. I checked in postmeta table and I can see that the values are there. Any pointers in the right direction? Thank you.
|
The meta query is converted by <code> _get_meta_sql() </code> . You can check the output by hooking into <code> get_meta_sql </code> . Dump that value and see what it gives.
|
What's missing in this wp_query and meta_query
|
wordpress
|
When my results show in Google for the respective keywords, in the meta description I see the date as well. Is there a way to remove the date? Example meta description shows up as: 15 Jun 2009 ... My meta description I use FV Simplr SEO and very pleased with it.. Would like to know if there's a hack for this.
|
I havent tried these yet but I was actually looking at the exact same thing the other day. http://magstags.com/wordpress-seo/remove-date-meta-descriptions-wordpress-seo/ and http://seo-ho.blogspot.com/2011/02/how-to-remove-date-from-meta.html
|
How to remove date from showing in meta description
|
wordpress
|
I have a massive WXR file im trying to import into wordpress. I run out of memory when i try to import as one file, so I'm thinking of how i can split the big file into smaller files programatically and if anyone had a script to do this
|
Googling for "split wxr file" returned several results, including python script for splitting .wxr file GUI for splitting WXR files (OSX and Windows) .Net splitter for WXR files Haven't tried any of these, but the comments look positive.
|
WXR slicing script
|
wordpress
|
I need to display a list of results which will include a name, time, etc. They will be in this format: results . I have looked at using tables, but short of writing a script to parse the text file, it wouldn't work. I think the best option is to make them appear in a monospaced font but I cannot find a way to do this that would not require code written on each post. Cheers, Will.
|
So you want to import textual content and preserve its formatting, as opposed to parsing it into HTML? I suppose the <code> <pre></pre> </code> tags are meant for exactly this. However I would consider spending osme effort to parse input after all, otherwise there is little merit in having it in WordPress.
|
How to display list of results
|
wordpress
|
I want to let my customer choose any image (in my backend) and then it will be displayed in my header.php. i've found Image Widget, but it just show images in the sidebar. I want something like: <code> <?php wp_plugin_that_shows_a_simple_image(); ?> </code> In my header. Which plugin could I use? I've searched a lot. WP 3. Thank you.
|
WordPress contains built-in support to select header images for a theme . You only have to indicate that your theme supports this, by calling <code> add_custom_image_header() </code> . See the Twenty Ten initialization for details. In your theme's <code> header.php </code> you then call <code> header_image() </code> to get the current header image.
|
Show an image in my header.php
|
wordpress
|
Any ideas on this? I earlier got an error on some update directory, and manually deleted it (unfortunately I didn't write it down). I think I've done auto-upgrades on the same domain before. <code> Downloading update from http://wordpress.org/wordpress-3.1.3.zip… Unpacking the update… Warning: copy(/home/nwalters/public_html/wp-admin/includes/update-core.php) [function.copy]: failed to open stream: Permission denied in /home/myname/public_html/wp-admin/includes/class-wp-filesystem-direct.php on line 200 Could not copy files. Installation Failed </code>
|
sounds like you need to think about a new host... do I dare ask where you're hosted now? But yes that's a permission issue.
|
3.1.3 auto-upgrade
|
wordpress
|
I am having posts with images.In single post page all contents displaying well with image. But in blog page , the content only displaying not an image. How can i make it to display For example, http://www.beezid.com/blog this blog displaying images with read more link but not in my case http://optisolbusiness.com/gonzobidz/blog/ Thanks in advance !
|
If you did not set an explicit excerpt for your post in the post editor, WordPress by default calls <code> wp_trim_excerpt() </code> to auto-generate an excerpt. This function throws out all HTML tags to make life simple. <code> the_content() </code> does not do this when it splits your post on a <code> <!--more--> </code> tag. If you don't want this default behavior you can unhook the <code> wp_trim_excerpt() </code> function and duplicate it with one of your own that does not remove HTML tags. Watch out when you split your text somewhere: call <code> force_balance_tags() </code> to make sure your excerpt does not end with <code> Some <strong>great news... [Read more] </code> , because everything after it will be bold too. You will also have to see how this works with embedded content: if you remove some of the tags for a Flash video you also won't get what you expect.
|
the_excerpt function not showing image
|
wordpress
|
I found an XML to WP decoder script that stores the data as an array in a custom meta field. What is the best way to extract the information? For example how could I display the "Manufactured in" field as "CANADA"? <code> [_ttn_i_details] => Array ( [0] => a:5:{s:9:"engine_id";a:1:{i:0;s:9:"300000225";}s:15:"transmission_id";a:1:{i:0;s:6:"257691";}s:5:"plant";a:1:{i:0;s:23:"Oshawa, Ontario, Canada";}s:15:"Manufactured in";a:1:{i:0;s:6:"CANADA";}s:22:"Production Seq. Number";a:1:{i:0;s:6:"151411";}} ) </code> The example code above was produced via <code> print_r(get_post_custom($post->ID)); </code> . I really appreciate any insight, no matter how small. :)
|
Use unserialize() to convert it into an array. <code> $mydata = 'a:5:{s:9:"engine_id";a:1:{i:0;s:9:"300000225";}s:15:"transmission_id";a:1:{i:0;s:6:"257691";}s:5:"plant";a:1:{i:0;s:23:"Oshawa, Ontario, Canada";}s:15:"Manufactured in";a:1:{i:0;s:6:"CANADA";}s:22:"Production Seq. Number";a:1:{i:0;s:6:"151411";}}'; $mydata = unserialize($mydata); echo $mydata['Manufactured in'][0]; </code> Edit - Related thought- something to keep in mind when storing meta data serialized like this is that you limit your ability to use that data in queries, if that's a concern for you. for instance, it's not so easy to write queries like "show me all parts manufactured in Canada", or order results by engine id, since that data is tucked away with a bunch of other data in one field.
|
How to extract data from a post meta serialized array?
|
wordpress
|
I need to override the setting in the WP Admin for the number of recent posts in the Syndication settings under General -> Admin. I'm using the following code, which gets all posts, but I don't need that many. Can someone tell me how to retrieve 50 posts? <code> function no_limits_for_feed( $limits ) { return ''; } add_filter( 'post_limits', 'no_limits_for_feed' ); </code>
|
This is no normal filter. It's a <code> filter_ref_array </code> . <code> // Use this to alter your limit: add_filter( 'post_limits', create_function( '$a', "return 'LIMIT $start, 10';" ) ); </code> EDIT After I saw that this got marked as solution, I want to show you a more "best practice"-approach: <code> function alter_feed_post_limits( $limits ) { return " LIMIT 0,50"; } add_action( 'post_limits', 'alter_feed_post_limits' ); </code>
|
How to get override the WP Admin Syndication feed limit for a custom feed?
|
wordpress
|
I've got a button in theme options that calls a file called color.php, (the contents of which are below). On certain installations of the theme, the script is generating a 404 error and failing unless I take out everything above the //do something line. Any suggestions on what might be causing it? <code> <?php require('../../../wp-blog-header.php'); if (!is_user_logged_in()){ die("You Must Be Logged In to Access This"); } if( ! current_user_can('edit_files')) { die("Oops sorry you are not authorized to do this"); } //do something ?> </code>
|
It is not a 404 error, it’s a server error. You are calling <code> is_user_logged_in </code> and <code> current_user_can </code> probably before the definition is loaded. Hook your check to an action where these functions are known, <code> admin_init </code> for example.
|
Call to require('../../../wp-blog-header.php') results in 404 error?
|
wordpress
|
I think this is a fairly simple issue but I haven't got my head around it. Question: how do I get my custom posts to show only on the category archives, but not in the blog post listing page? Background: I have a custom post type "video", with has_archive true and 'taxonomies' => array('category', 'post_tag') - I want to use standard categories with this custom post type. I have successfully got my category pages to display by setting post_type and using the hook pre_get_posts as follows: <code> function my_query_post_type($query) { if ( is_home() && false == $query->query_vars['suppress_filters'] ) $query->set( 'post_type', array( 'post', 'video', 'attachment' ) ); return $query; } add_filter('pre_get_posts', 'my_query_post_type'); </code> If I don't use pre_get_posts, then my videos don't show - as expected. However, now my blog post listing page shows the custom posts - as expected because I've changed the post_type in query. Question: how do I get my custom posts to show only on the category archives, but not in the blog post listing page?
|
This may be overly simplistic, but have you tried changing <code> is_home() </code> to <code> is_category() </code> , in this line: <code> if ( is_home() && false == $query->query_vars['suppress_filters'] ) </code> i.e. change it to this: <code> if ( is_category() && false == $query->query_vars['suppress_filters'] ) </code> Worth a shot, anyway...
|
Displaying custom post type on category pages but not on blog listings
|
wordpress
|
I'm using WordPress 3.1.3 and trying to make a "product" menu with post count in each category. Like this: New Cars (4) BMW (2) Ford (1) Nissan (1) Used Cars (10) BMW (3) Ford (1) Nissan (6) For this, I've created custom post type <code> Cars </code> and taxonomies <code> Type </code> and <code> Brand </code> . Not sure if it the best way to do this, but here's my code: <code> <?php $auto_types = get_terms('type', 'hide_empty=1'); ?> <ul> <?php foreach( $auto_types as $auto_type ) : ?> <li> <a href="<?php echo get_term_link( $auto_type->slug, 'type' ); ?>"> <?php echo $auto_type->name; ?> (<?php echo $auto_type->count; ?>) </a> <?php $terms = get_terms('brand'); $count = count($terms); if($count > 0) : ?> <ul> <?php foreach ($terms as $term) : ?> <li> <a href="/?type=<?php echo $auto_type->slug ?>&brand=<?php echo $term->slug ?>"> - - <?php echo $term->name; ?> (<?php echo $term->count; ?>) </a> </li> <?php endforeach ?> </ul> <?php endif ?> </li> <?php endforeach ?> </ul> </code> So my questions are: is this is a good way to do it? how do I filter post counts? Edit - I've managed to solve my second problem, but i'm still not sure if it's a good way to do it. Here's new code: <code> <?php $auto_types = get_terms('type', 'hide_empty=1'); ?> <ul> <?php foreach( $auto_types as $auto_type ) : ?> <li> <a href="<?php echo get_term_link( $auto_type->slug, 'type' ); ?>"> <?php echo $auto_type->name; ?> </a> <?php $auto_brands = get_terms('brand', 'parent=0' ); ?> <ul> <?php foreach ($auto_brands as $auto_brand) : ?> <?php $brand_filter['tax_query'] = array( 'relation' => 'AND', array( 'taxonomy' => 'type', 'terms' => array($auto_type->slug), 'field' => 'slug', ), array( 'taxonomy' => 'brand', 'terms' => array($auto_brand->slug), 'field' => 'slug', ), ); $tax_query = new WP_Query($brand_filter); $count = 0; if ( $tax_query->have_posts() ) : while ( $tax_query->have_posts() ) : $tax_query->the_post(); $count++; endwhile; endif; wp_reset_postdata(); if ( $count > 0 ) : ?> <li> <a href="/?type=<?php echo $auto_type->slug ?>&brand=<?php echo $auto_brand->slug ?>"> - - <?php echo $auto_brand->name; ?> (<?php echo $count; ?>) </a> </li> <?php endif; endforeach ?> </ul> </li> <?php endforeach ?> </ul> </code> Edit 2 - Changed <code> query_posts() </code> method to <code> wp_query() </code> (thanks to VicePrez), but is it efficient to use query to only get correct post count or there's a better way to make this menu?
|
I adjusted your code a little bit to integrate the <code> wp_query() </code> class instead of <code> query posts() </code> , which is stackexchange-url ("only meant for altering the main loop"). You should always opt to use <code> wp_query() </code> when trying to create secondary loops. Since we're using <code> wp_query() </code> , we're also going to have to use <code> wp_reset_postdata() </code> instead of <code> wp_reset_query </code> . Im not sure if this is going to fix your problem, but adjust your code to this, and we'll tackle the rest of your problems step by step. <code> <?php $auto_types = get_terms('type', 'hide_empty=1'); ?> <ul> <?php foreach( $auto_types as $auto_type ) : ?> <li> <a href="<?php echo get_term_link( $auto_type->slug, 'type' ); ?>"> <?php echo $auto_type->name; ?> </a> <?php $auto_brands = get_terms('brand', 'parent=0' ); ?> <ul> <?php foreach ($auto_brands as $auto_brand) : ?> <?php $brand_filter['tax_query'] = array( 'relation' => 'AND', array( 'taxonomy' => 'type', 'terms' => array($auto_type->slug), 'field' => 'slug', ), array( 'taxonomy' => 'brand', 'terms' => array($auto_brand->slug), 'field' => 'slug', ), ); $tax_query = new WP_Query($brand_filter); if ( $tax_query->have_posts() ) : $count = 1; while ( $tax_query->have_posts() ) : $tax_query->the_post(); if ( $count >= 1 ) { ?> <li> <a href="/?type=<?php echo $auto_type->slug ?>&brand=<?php echo $auto_brand->slug ?>"> - - <?php echo $auto_brand->name; ?> (<?php echo $count; ?>) </a> </li> <? } $count++; endwhile; wp_reset_postdata(); endif; endforeach ?> </ul> </li> <?php endforeach ?> </ul> </code> UPDATE: I added the <code> posts_per_page </code> parameter and set it to <code> -1 </code> to show all posts. I tested it on my side. It should give you the results you were looking for. <code> <?php $auto_types = get_terms('type', 'hide_empty=1'); ?> <ul> <?php foreach( $auto_types as $auto_type ) : ?> <li> <a href="<?php echo get_term_link( $auto_type->slug, 'type' ); ?>"> <?php echo $auto_type->name; ?> </a> <?php $auto_brands = get_terms('brand', 'parent=0' ); ?> <ul> <?php foreach ($auto_brands as $auto_brand) : ?> <?php $brand_filter = array( 'posts_per_page' => '-1', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'type', 'field' => 'slug', 'terms' => array($auto_type->slug), ), array( 'taxonomy' => 'brand', 'field' => 'slug', 'terms' => array($auto_brand->slug), ) ) ); $tax_query = new WP_Query($brand_filter); $count = 0; if ( $tax_query->have_posts() ) : while ( $tax_query->have_posts() ) : $tax_query->the_post(); $count++; endwhile; endif; wp_reset_postdata(); if ( $count > 0 ) : ?> <li> <a href="/?type=<?php echo $auto_type->slug ?>&brand=<?php echo $auto_brand->slug ?>"> - - <?php echo $auto_brand->name; ?> (<?php echo $count; ?>) </a> </li> <?php endif; endforeach ?> </ul> </li> <?php endforeach ?> </ul> </code>
|
Taxonomy menu with post count and multiple parents
|
wordpress
|
I'm trying to hide a navigation menu item under certain circumstances. Specifically, if a user is logged in AND has already registered their product bar code, I want to hide the 'Register Kit' link (which has a class of 'ac-regkit'). Below is the PHP I've added to the head section of header.php, just before wp_head();. <code> /* If User is loggied in, hide LOG IN and SIGN UP links */ <?php if ( is_user_logged_in() ) { ?> <style> .ac-login { display: none; } .ac-signup { display: none; } </style> /*If user has not yet registered their DNA Test Kit, show link */ <?php $current_user = wp_get_current_user(); $user_id = $current_user; $key = 'redeem_code'; $single = true; $ac-barcode = wp_get_user_meta( $user_id, $key, $single); if ( $ac-barcode = '' ) { ?> <style> .ac-regkit { display: inline; font-weight: bold; } .ac-regkit a { color: red; } </style> <?php }; ?> <?php } ?> </code> And this is the error I'm getting: Server Error The website encountered an error while retrieving http://athleticode.com/ . It may be down for maintenance or configured incorrectly. I'm not an expert in PHP, so I'm sure it's a syntax error or something like that -- and there is probably a better way to achieve this result -- so any help would be greatly appreciated.
|
I'd have 2 menus, and show the 2nd only if the user meet criteria. Then, use CSS to show both menus like its only one. I think it's the easiest way. And you have the benefit that the items aren't really there, not just hidden.
|
Hide a nav menu item based on get_user_meta results
|
wordpress
|
I'm using url like «wp-login.php?action=register&role=patient» and «register_form» hook for add extra inputs form which depends on urls like this: <code> add_action('register_form','add_extra_role_fields'); function add_extra_role_fields() { if (isset($_GET['role'])) { $user_type = $_GET['role']; } if (isset($user_type) && $user_type == "patient") [...] if (isset($user_type) && $user_type == "doctor") [...] </code> Problem : Wordpress redirects user after form validation with error to http://example.com/wp-login.php?action=register instead of http://example.com/wp-login.php?action=register&role=patient and all logic is broken. Question : Can wordpress redirect user to previos url «?action=register&role=doctor» (not default «?action=register») ? Solution : Thank you Jan Fabry :). <code> if ( isset($_REQUEST['role']) && ( ($_REQUEST['role'] == 'patient') OR ($_REQUEST['role'] == 'doctor') ) ) { add_filter( 'site_url', 'doctor_site_url', 10, 4 ); function doctor_site_url( $url, $path, $scheme, $blog_id ) { if ( 'login_post' == $scheme ) { $url .= '&role='.$_REQUEST['role']; } return $url; } } </code>
|
If you want to keep this information in the <code> $_GET </code> , you will have to modify the form's <code> action </code> parameter URL . You can do this by hooking into <code> site_url </code> : <code> add_filter( 'site_url', 'wpse18418_site_url', 10, 4 ); function wpse18418_site_url( $url, $path, $scheme, $blog_id ) { if ( 'login_post' == $scheme ) { $url .= '&role=doctor'; // Or do this dynamically } return $url; } </code> But instead of always looking in the <code> $_GET </code> , it might be a solution to save the <code> role </code> field in a hidden field and check <code> $_REQUEST </code> instead - it will contain both <code> $_GET </code> and <code> $_POST </code> .
|
Can I change default registration link (without htaccess)?
|
wordpress
|
How can I update the URLs that Drag-To-Share eXtended generates? At least in version 1.13, sharing items for Twitter and Facebook does not produce the proper url string for actually sharing the content on either network. Facebook, Twitter, and possibly other networks have since changed the url query string methods for sharing... This would require a quick update to the plugin so it writes up-to-date urls, but I don't know where to look.
|
The URLs are constructed in the <code> wp-dragtoshare-extended.js </code> Javascript file . For most services you can see how the <code> customUrl </code> is constructed and change it right there. For Twitter you should look a bit lower, in the <code> isGD </code> function, because it does an Ajax request to shorten the link - but maybe this is not needed anymore with the current Twitter sharing service? If you modify this script you should be aware that the plugin has two versions of the script: <code> wp-dragtoshare-extended.js </code> is the normal version, <code> wp-dragtoshare-extended-packed.js </code> a minified version to speed up loading. The plugin loads the packed version , so either remember to edit that version too (by minifying your edited version) or edit the PHP code so it loads the non-minified version.
|
Updating the Drag-To-Share eXtended share URLs?
|
wordpress
|
I want to exclude posts from aside post-format in the feed. I have already checked up stackexchange-url ("here") about how to exclude posts from a certain post format from the loop but how to exclude posts from a post format in the feed? Couldn't modify it because I am not very good with the code.
|
If you want to modify the feed, you should hook into the main query that WordPress will do on every page request. The best hook here is <code> pre_get_posts </code> . This code example will hook into <code> pre_get_posts </code> , check whether it is a feed, and add the post format taxonomy query: <code> add_action( 'pre_get_posts', 'wpse18412_pre_get_posts' ); function wpse18412_pre_get_posts( &$wp_query ) { if ( $wp_query->is_feed() ) { $post_format_tax_query = array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => 'post-format-image', // Change this to the format you want to exclude 'operator' => 'NOT IN' ); $tax_query = $wp_query->get( 'tax_query' ); if ( is_array( $tax_query ) ) { $tax_query = $tax_query + $post_format_tax_query; } else { $tax_query = array( $post_format_tax_query ); } $wp_query->set( 'tax_query', $tax_query ); } } </code>
|
How to exclude posts of a certain format from the feed
|
wordpress
|
I saved a group of data in post meta, now I need to get the meta and use them as other items. My code not working, please help me correct it, thanks! <code> $boxes = Array( 'height', 'width' ); foreach ( $boxes as $data ){ $project = get_post_meta($post->ID, $data, true); } $item_a = $project->height; $item_b = $project->width; </code>
|
<code> foreach ($boxes as $data) { $project[$data] = get_post_meta($post->ID, $data, true); } $item_a = $project['height']; $item_b = $project['width']; </code>
|
How to obtain a group of post meta and assign each meta to other variables?
|
wordpress
|
I created an options page for my theme, where I can manually edit the CSS. Lets say I change the CSS in the options page for the <code> <H1> </code> tag, so it will now change it on the front-end. What I want to also do is have it change in the visual editor. I have added the function <code> add_editor_style(style.php); </code> and in the <code> style.php </code> I have it saying in the top <code> <?php header('Content-type: text/css'); ?> </code> so it recognizes the file. But now I can't get the options dynamically... How should I achieve this? EDIT this is in the functions. <code> add_filter( 'mce_css', 'cnote_visual_css' ); function cnote_visual_css() { return get_bloginfo('template_directory') . '/cnotethegr8/global-style.php'; } </code> this is the global stylesheet <code> <?php header('Content-type: text/css'); global $shortname; ?> h1 { <?php echo(get_option($shortname.'_style_h1')); ?> } </code> when i echo $shortname nothing shows...
|
The reason why this isn't working is because the WordPress core isn't loaded when this dynamic style sheet is loaded. <code> get_option() </code> hasn't been defined yet. What you need to do is load WordPress at the top of your dynamic stylesheet: <code> <?php include("../../../wp-load.php"); ?> </code>
|
Dynamically add CSS to the visual editor
|
wordpress
|
The function below is called from my index.php just below the main content block. Its purpose is to write out a link list of the latest posts. However, I need to reset the post object once this function has completed (or the sidebar query that follows thinks that the current post is the last post that gets executed by this function.) How should I reset the post back to the current post of the page? I've tried adding wp_reset_query() at the end of the function, but its not producing the results I want (produces multiple posts in the content area). Any help much appreciated. <code> function myFunction(){ $catHidden=get_cat_ID('hidden'); $myquery = new WP_Query(); $myquery->query(array('cat' => "-$catHidden",'post__not_in' => get_option('sticky_posts'))); $myrecentpostscount = $myquery->found_posts; if ($myrecentpostscount > 0){ ?> <div> <h4>Menu Title</h4> <ul> <?php global $post; $myrecentposts = get_posts(array('post__not_in' => get_option('sticky_posts'), 'cat' => "-$catHidden",'numberposts' => get_option('latest_count'))); foreach($myrecentposts as $idxrecent=>$post) { ?> <li class="page_item"> <a href="<?php the_permalink(); ?>"><?php if(has_post_thumbnail() && get_option('show_thumbs')) the_post_thumbnail('thumbnail', array('class' => 'alignleft', 'style' => 'margin:0 10px 0 0;')); ?><?php the_title(); ?></a> <?php if(has_post_thumbnail() && get_option('show_thumbs')) echo '<div style="clear:both">&nbsp;</div>';?> </li> <?php } echo "</ul></div>";}} </code>
|
<code> wp_reset_query() </code> will reset the query to the original query WordPress did on this page. So if you somewhere called <code> query_posts() </code> , it will not reset back to that query, but to the "main" query. You probably want to use <code> wp_reset_postdata() </code> , which resets the <code> $post </code> variable to the current post in <code> $wp_query </code> . The best thing is to not overwrite the global <code> $post </code> variable in your function. All WordPress functions have variants that accept a post object, so there should be no need to use the global variable there.
|
How to effectively reset the post object after calling get_posts()
|
wordpress
|
I'm wondering if it's possible in the single.php template to use the width of the post's featured image elsewhere in the page. What I'm trying to do is add a div element on the page with the same width as the post's featured image (which will always be a different width). If anyone has any ideas, let me know. Thanks
|
Try the following. First, add this piece of code to the template: <code> <?php $image_data = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "thumbnail" ); ?> </code> $image_data will now return an array containing the url, width, and height (function reference). To get the width, you might do this: <code> <?php $image_width = $image_data[1]; ?> </code> In your specific example, after adding the two pieces of code above to your template, you might do this: <code> <div style="width:<?php echo $image_width; ?>"> </code> Is that helpful?
|
How to get featured image's width and use elsewhere in template?
|
wordpress
|
How do I create a new usermeta field with a drop down selection values? Im want to create a conditional statement for all users with a certain value of the new custom field I want. For example, The new field would be: Approved The drop down values are: Yes and No The conditional statement will recognize all users with the Approved field value of Yes. Then it will post a code. Im working with the wp_get_current_user function(), which does exactly what I need, but I just need a new custom usermeta field. In the example the new usermeta field would be "artwork_approved." Example: <code> wp_get_current_user(); if ($current_user->artwork_approved == 'Yes'){ echo 'Thank you for approving your artwork!'; } </code> There seems to be no plugin for this and I really need this feature. I would really appreciate some advice on creating a new usermeta with drop down options. Thanks a lot!
|
You need to hook edit_user_profile to add your custom inputs. Then, you need to hook the profile_update action and use the function add_user_meta to add the metadata
|
Create a new usermeta field for users
|
wordpress
|
ok so i have a nav menu with the top level of menu items being static pages. When you highlight or visit one of them there is a sub-menu that pops up. Each one of them has there own sub-menu and each sub-menu is full of custom taxonomy terms. Since WordPress will only give the current-menu-item class on an archive page i need to either add my own class or just add some custom css to show and highlight the term parent when viewing a single item. My problem is I had the code working but then it quit working. See the code below <code> <? $has_news = has_term('news'); if ($has_news) echo '<style type=text/css>#navbar{display:block}'; else echo ''; ?> </code> This is related to one of my other questions but I figured it would best be suite under its own with different tags. Related Question: stackexchange-url ("Highlight nav menu terms") wpversion: 3.1.2
|
Problem is that you'd need to pass a <code> $post->ID </code> in order to not <code> return false. </code> Better use <code> is_object_in_taxonomy($object_type, $taxonomy) </code> and fill both the term and the tax in the function. It returns <code> (boolean) </code> , so simply add your class based on the result: <code> echo $class = is_object_in_taxonomy( 'news', 'your_taxonomy' ) ? 'current-whatever' : ''; // or: (simplified for readabilities sake: // set empty and override only in case. // So you avoid dropping errors if the condition was not met and $current not set. $class = ''; if ( is_object_in_taxonomy( 'news', 'your_taxonomy' ) ) echo $class = 'current-whatever'; </code>
|
has_term if/echo else/echo function
|
wordpress
|
If I use the URL "/tag/tag1,tag2/feed", it will retrieve posts that have both tags. Is there anyway to do this and just get posts that have BOTH tag1 and tag2?
|
You could make a custom rss feed..... Here's a link for that http://yoast.com/custom-rss-feeds-wordpress/ Simply use that info to make a page template Make a new page through the WP interface and assign that template The url for that page is your new feed. You just need to adjust the query line to call to both tags For instance, I have a hockey feed, my custom post type is col_avs, I've adjusted my query like: <code> $posts = query_posts('post_type=col_avs&showposts='.$numposts); </code> You can see it in action at http://www.rvoodoo.com/hockey-feed It goes to a feedburner feed, but that feed is generated using this method
|
Anyway to retrieve a feed of posts that have BOTH tags?
|
wordpress
|
I've just purchased a plan with MaxCDN to deliver my content through CDN, but i've got a small issue before i create a pull-zone. I moved my WordPress core files out of my root and into a sub-directory. These are my current settings: WordPress address URL: <code> http://example.com/wordpress </code> Site address URL: <code> http://example.com </code> The question is whether i should have my Origin Server URL and custom CDN domain name according to my WordPress address or site address. Here is the tutorial I'm currently following, in case you need to view the MaxCDN dashboard. Thanks in advance.
|
Just use the site address URL, <code> http://example.com </code> From the literature: `When the custom CDN URL works, you can access all files in your site via that URL and it will be delivered through the MaxCDN content delivery network. For example, if you normally open an image from example.com/images/example.jpg, that same image now opens with cdn.example.com/images/example.jpg as well, and it's loaded from content delivery network.` This would be exactly the same for <code> cdn.example.com/wordpress/wp-content/uploads </code> and <code> cdn.example.com/wordpress/wp-content/themes/twentyten </code> or whatever else. So going this route, everything below your root will be available via CDN, including all your wordpress files. Why complicate things?
|
CDN: Origin server URL, WordPress Core files installed in sub-directory
|
wordpress
|
Working on an SEO plugin and stuck on something I thought would be simple. Looking for code to generate just the URLs for categories, tags, search, and date archives when on that archive set. So if on category ABC there's the URL to www.domain.com/category/abc/ Was hoping it was something simple like this for the categories part: <code> echo get_category_link($cat->term_id); or echo get_category_link($category->term_id); </code> but apparently not. The general code works if I add a specific category <code> echo get_category_link(123); </code> The plugin adds code to the head via wp_head() The plugin (if I ever finish it) will be a replacement for so called SEO plugins that use noindex and nofollow to 'sculpt' PR/protect link benefit. Noindex wastes link benefit, nofollow deletes link benefit so they shouldn't be used. David
|
in a category archive, the code could be: <code> echo get_category_link(get_query_var('cat')); </code> in a tag archive, this could be: <code> if(is_tag()) echo get_term_link(get_query_var('tag'), 'post_tag'); </code> the conditional was added to avoid an error messages if not in a tag archive.
|
Code for Category, Tags, Archive URLs
|
wordpress
|
I'm working on a plugin that will be installed in a multisite instance. How do I create a single settings page that is visible at the "Network admin" level only - most of the guides i've seen relate to a standard blog level plugin. Any links to information would be useful, otherwise I'll just end up going through sitewide tags to see how it's being done there. [Update] Looks like sitewide_tags uses <code> add_site_option </code> , <code> get_site_option </code> and <code> update_site_option </code> , and these functions use wp_sitemeta. However, from what I can see, there's no support for register_setting, add_setting, etc, so you have to get and set your options manually.
|
As a reference To create network or global settings, you need to do the following Add a settings page <code> add_submenu_page( 'settings.php'... # cf options.php for blog level` </code> Add a global option <code> add_site_option($key,$value) </code> Update a global option <code> update_site_option($key,$value) </code> Get a site option <code> get_site_option($key) </code> Global settings are saved to the <code> sitemeta </code> table (individual blog settings are saved to <code> <blog_id>_options </code> table I think the Settings API functions at the blog level - so uses the options table, not sitemeta. So, you can't use option groups and the like at the network level ( please comment if I've got this wrong )
|
'Global' settings page for multisite plugin
|
wordpress
|
What is the best way to display/dump all custom fields associated with a post? It doesn't have to be pretty, I just need to verify what is being saved in what field array for debugging. Thanks!
|
you can use get_post_custom() which returns a multidimensional array with all custom fields of a particular post or page: <code> echo '<pre>'; print_r(get_post_custom($post_id)); echo '</pre>'; </code>
|
How to display all custom fields associated with a post type?
|
wordpress
|
This might be kind of simple, but I couldn't find a way to do so in the WP docs. My plugin currently uses custom fields for things I could just have radio buttons/check boxes for each post. How do I add a little section where I can have such options rather than custom fields?
|
Below is the example of a couple of checkboxes to set custom field values: <code> // register the meta box add_action( 'add_meta_boxes', 'my_custom_field_checkboxes' ); function my_custom_field_checkboxes() { add_meta_box( 'my_meta_box_id', // this is HTML id of the box on edit screen 'My Plugin Checkboxes', // title of the box 'my_customfield_box_content', // function to be called to display the checkboxes, see the function below 'post', // on which edit screen the box should appear 'normal', // part of page where the box should appear 'default' // priority of the box ); } // display the metabox function my_customfield_box_content( $post_id ) { // nonce field for security check, you can have the same // nonce field for all your meta boxes of same plugin wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_nonce' ); echo '<input type="checkbox" name="my_plugin_paid_content" value="1" /> Paid Content <br />'; echo '<input type="checkbox" name="my_plugin_network_wide" value="1" /> Network wide'; } // save data from checkboxes add_action( 'save_post', 'my_custom_field_data' ); function my_custom_field_data() { // check if this isn't an auto save if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; // security check if ( !wp_verify_nonce( $_POST['mypluing_nonce'], plugin_basename( __FILE__ ) ) ) return; // further checks if you like, // for example particular user, role or maybe post type in case of custom post types // now store data in custom fields based on checkboxes selected if ( isset( $_POST['my_plugin_paid_content'] ) ) update_post_meta( $post_id, 'my_plugin_paid_content', 1 ); else update_post_meta( $post_id, 'my_plugin_paid_content', 0 ); if ( isset( $_POST['my_plugin_network_wide'] ) ) update_post_meta( $post_id, 'my_plugin_network_wide', 1 ); else update_post_meta( $post_id, 'my_plugin_network_wide', 0 ); } </code> Following following hooks and functions are required for adding a meta box, see below references for more information about them: Hooks admin_init (action) save_post (action) add_meta_boxes (action) (you don't need admin_init in WordPress 3.0+) Functions add_meta_box wp_verify_nonce
|
How to add option box in "Edit Post" plugin API?
|
wordpress
|
I have a function which is used to display a video, I want this video to be shown after the post, It should display the video when the post ends. I have added filter to it, but then too, the video is shown before the post. Here is the filter which I am using: <code> function append_the_video($content) { global $post; $content .= youtube_video(); return $content; } add_filter('the_content', 'append_the_video'); </code> edited entire function <code> <?php function youtube_video() { ?> <div class="post"> <?php $newvar = urlencode(get_the_title()); include_once(ABSPATH . WPINC . '/rss.php'); $rss = fetch_rss('http://gdata.youtube.com/feeds/base/videos?q='.$newvar.'&client=ytapi-youtube-search&v=2'); $maxitems = get_option('novideos'); $items =is_array($rss->items) ? array_slice($rss->items, 0, $maxitems) : '' ; ?> <ul> <?php if (empty($items)) {echo "No current video uploads by ".get_the_title();} else foreach ( $items as $item ) : ?> <?php $youtubeid = strchr($item['link'],'='); $youtubeid = substr($youtubeid,1); ?> <p>Latest Videos of <b><?php the_title(); ?>:</b></p> <br> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="320" height="265"> <param name="movie" value="http://www.youtube.com/v/<?php echo $youtubeid ?>&hl=en&fs=1" /> <!--[if !IE]>--> <object type="application/x-shockwave-flash" data="http://www.youtube.com/v/<?php echo $youtubeid ?>&hl=en&fs=1" width="320" height="265"> <!--<![endif]--> <p><a href="http://www.youtube.com/v/<?php echo $youtubeid ?>">View movie&raquo;</a></p> <!--[if !IE]>--> </object> <!--<![endif]--> </object> </li> <?php endforeach; ?> </ul> </div> <?php } function append_the_video($content) { global $post; $content .= youtube_video(); return $content; } add_filter('the_content', 'append_the_video'); ?> </code>
|
2 options: 1) Edit your youtube_video() function so it return a string instead of printing the code 2) The easiest way... if you can edit your theme, place the youtube_video() call after showing your post content Edit: <code> <?php function youtube_video() { $ret = ""; $ret .= "<div class='post'>"; $newvar = urlencode(get_the_title()); include_once(ABSPATH . WPINC . '/rss.php'); $rss = fetch_rss('http://gdata.youtube.com/feeds/base/videos?q='.$newvar.'&client=ytapi-youtube-search&v=2'); $maxitems = get_option('novideos'); $items =is_array($rss->items) ? array_slice($rss->items, 0, $maxitems) : '' ; $ret .= "<ul>"; if (empty($items)) {$ret .= " 'No current video uploads by '.get_the_title()";} else foreach ( $items as $item ) : $youtubeid = strchr($item['link'],'='); $youtubeid = substr($youtubeid,1); $ret .= "<p>Latest Videos of <b>" . get_the_title() . ":</b></p>"; $ret .= "<br>"; $ret .= "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='320' height='265'>"; $ret .= "<param name='movie' value='http://www.youtube.com/v/" . $youtubeid ."&hl=en&fs=1' />"; $ret .= "<!--[if !IE]>-->"; $ret .= "<object type='application/x-shockwave-flash' data='http://www.youtube.com/v/" . $youtubeid ."&hl=en&fs=1' width='320' height='265'>"; $ret .= "<!--<![endif]-->"; $ret .= "<p><a href='http://www.youtube.com/v/" . $youtubeid ."'>View movie&raquo;</a></p>"; $ret .= "<!--[if !IE]>-->"; $ret .= "</object>"; $ret .= "<!--<![endif]-->"; $ret .= "</object>"; $ret .= "</li>"; endforeach; $ret .= "</ul>"; $ret .= "</div>"; return $ret; } ?> </code>
|
Add filter to the end of the post
|
wordpress
|
Is there any free (or cheap) software that can be used for testing WordPress functionality? I would like to create some test scripts and then them against my self-hosted WordPress installation.
|
This isn't really a WordPress question - more a generic web development issue. These are some open source tools that can be used for scripting and testing a web browser session. Selenium Cucumber Watir
|
Is there any free (or cheap) software that can be used for testing WordPress functionality?
|
wordpress
|
i've just find out about the custom field, which makes it possible to add something near a post, but what is the difference between "add_meta_box" and "custom field"? Custom field is inside the "supports" line, when we register a post type, so : isn't it easier to create a custom field than a add meta box? or are there many differences between both?
|
A meta box is an element in the graphical user interface, a custom field is an extra key and value stored with a post. Most of the time the interface to change the value of a custom field is put in an extra meta box - or in the default meta box for custom fields, which you can enable per post type. Maybe a picture can help explain this. I have a post with two custom fields: <code> my_custom_field </code> and <code> _thumbnail_id </code> . In the database they are stored in the <code> wp_postmeta </code> table: But in the post interface they can be edited in different places. The <code> _thumbnail_id </code> is displayed in the Featured Image meta box and can be edited with the image browser because it is hard to know the attachment ID. The other value can just be edited via the "generic" Custom Fields meta box: It will depend on the values you need to enter in your plugin and the experience of your users whether the Custom Fields meta box is enough, otherwise it will be more user-friendly to add a separate meta box.
|
add meta box - custom field : which to choose?
|
wordpress
|
How I can handle this shortcode: [my_gallery] img01.jpg img02.jpg img03.jpg img04.jpg [/my_gallery] I can't understand how to write a function, to handle image files name.
|
Are you going to put newlines in there between each image? or just spaces? I'll put in both for this example, checking if there's a newline. You would want something like this in your functions.php: <code> add_shortcode('my_gallery', 'gallery_function'); function gallery_function($atts, $code=''){ $files=preg_split( '/\s+/', $code ); // Added in from Jan's comment. foreach($files as $img){ if($img=="") continue; // ensures that no empty items from the split have entered in, since that is possible with the preg_split //handle each filename in here. } } </code> It's not perfect.. if you use both spaces and newlines in your shortcode, it'll mess things up - though that could be dealt with in more detail inside the function. Hope this helps.
|
Create own Wordpress shortcode gallery
|
wordpress
|
My custom widget's form will have two pull-down menus: the content of the second menu is dependent on the user's selection in the first menu (think of the way Country and State/Province works). I think the easiest implementation (though perhaps not the most user-friendly) would simply be to have the form automatically submit itself when the first pulldown is changed (ie: <code> <select onchange="submit_the_page_via_ajax()"> </code> ). I tried <code> onchange="this.form.submit();" </code> but that didn't leverage the Ajax call to my surprise (I would have thought that the sophisticated WordPress developers would have hiJaxed the form's submit event). They must be hijaxing the submit button however, since all my view source shows me is a standard html input type for the button. Anyway, I would appreciate a little insight into a best practice for submitting a widget's form leveraging ajax. This is a great post but only addresses the widget's display, not the back-end form.
|
The Save buttons have a class <code> widget-control-save </code> , and this is hooked up to <code> wpWidgets.save() </code> . So you either have to call <code> wpWidgets.save() </code> , or (probably easier) trigger a click event on the Save button.
|
How can I use AJAX to save/update a widget form?
|
wordpress
|
I just installed a WPML, but my custom post types is showing just in default language, if I am switching to other languages, it will show the same posts as default language, but in wordpress panel they are translated. Part of my code in function.php <code> $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => false, 'show_ui' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'hierarchical' => true, 'menu_position' => 5, 'supports' => array('title','thumbnail','taxonomy') </code> And to get those post types I am using : <code> query_posts('post_type=objekts'); ... </code>
|
Which versions of WPML and WordPress are you using? I'm sure that you noticed that the old versions of WPML from wp.org only run on old WordPress versions (up to 3.0.5).
|
WPML custom post type - not translated
|
wordpress
|
I have a custom front end page where users can post from. All works fine but the i want if more than one field is empty then the errors for all empty fields should show all together. Right now the code only show error for the first empty field it detects. The code is : <code> $errors = new WP_Error(); if (isEmptyString($title_stripped)) $errors->add('empty_title', __('Please enter a title')); if (isEmptyString($description_stripped)) $errors->add('empty_desc', __('Enter a breif description')); if (isEmptyString($content_stripped)) $errors->add('empty_content', __('Please enter your article here')); return $errors; </code> Edit : Solved Sorry to bother . It was one of my other functions which was limiting the error to echo only once. Here is the previous code : <code> function display_message( $message = false ) { if( is_wp_error( $message ) ) { echo '<div class="error"><p>' . $message->get_error_message() . '</p></div>'; } </code> It worked fine when i changed it too : <code> function display_message( $message = false ) { if( is_wp_error( $message ) ) { echo '<div class="error"><p>'; foreach ( $message->get_error_messages($code) as $error ) { echo $error . "<br />\n"; } echo '</p></div>'; } </code>
|
Sorry to bother . It was one of my other functions which was limiting the error to echo only once. Here is the previous code : <code> function display_message( $message = false ) { if( is_wp_error( $message ) ) { echo '<div class="error"><p>' . $message->get_error_message() . '</p></div>'; } </code> It worked fine when i changed it too : <code> function display_message( $message = false ) { if( is_wp_error( $message ) ) { echo '<div class="error"><p>'; foreach ( $message->get_error_messages($code) as $error ) { echo $error . "<br />\n"; } echo '</p></div>'; } </code>
|
Display all WP Errors together during form validation
|
wordpress
|
In Buddypress, after Registration first step, users are redirected to Change Avatar step. Im trying to find a way to redirect to an alternate page, for example: http://www.mysite.com/yeah Im using the following code, but Im continuously redirected to Change Avatar page. <code> function custom_filter_bp_signup() { global $current_site; return 'http://' . $current_site->domain . $current_site->path . 'yeah'; } add_filter('wp_signup_location', 'custom_filter_bp_signup'); </code> Any help is welcome, Thanks in advance.
|
Yeah I ge it: <code> function bp_redirect($user) { $redirect_url = 'http://www.mysite.com/yeah'; bp_core_redirect($redirect_url); } add_action('bp_core_signup_user', 'bp_redirect', 100, 1); </code>
|
Redirect after registration in BuddyPress
|
wordpress
|
I have my CPT edit screen almost looking how I want it but want to remove the filter and view options from this screen as they are not needed for this interface. How do I remove them? Are there any filters that disable them? My edit screen has got to this stage by this code so far: <code> // Manage columns in edit screen add_filter('manage_edit-staff_columns', 'sc_staff_modify_columns'); function sc_staff_modify_columns($staff_columns) { $staff_columns['title'] = __('Staff Name', 'sc_wilsons_custom'); $staff_columns['job_role'] = __('Job Role', 'sc_wilsons_custom'); $staff_columns['is_store_manager'] = __('Store Manager', 'sc_wilsons_custom'); $staff_columns['located'] = __('Located At', 'sc_wilsons_custom'); unset($staff_columns['date']); return $staff_columns; } add_action('manage_staff_posts_custom_column', 'sc_staff_manage_columns', 10, 2); function sc_staff_manage_columns($column_name, $id) { global $wpdb; $custom = get_post_custom($id); switch ($column_name) { case 'job_role': echo $custom["sc_staff_job_role"][0]; break; case 'is_store_manager': echo ($custom["sc_staff_store_manager"][0] == 1) ? __('Yes', 'sc_wilsons_custom') : __('No', 'sc_wilsons_custom'); break; case 'located': if(is_int($custom["sc_staff_located"][0])){ $post = get_post($custom["sc_staff_located"][0]); echo $post->post_title; } else { _e('Unknown', 'sc_wilsons_custom'); } break; } } </code> EDIT: if it helps I have found where the code for these bits are generated. Functions <code> months_dropdown() </code> and <code> view_switcher </code> in file /wp-admin/includes/class-wp-list-table.php I don't see any filters or hooks here so might be out of luck. Anyway of doing this by extending the WP_List_Table class?
|
Css: <code> .tablenav.top .alignleft.actions select[name="m"], .tablenav.top .alignleft.actions select#cat, .tablenav.top .alignleft.actions input#post-query-submit, .tablenav.top .view-switch { display: none; } </code> Note: You'll have to take a look at the input elements ID. I guess this will be named different on custom post types.
|
Remove filter and view options from custom post type edit screen
|
wordpress
|
Nightly Builds or Beta Releases? I like using the <code> /wp-admin/update-core.php </code> utility to update wordpress. But I'd like to be able to use it to download beta releases or nightly builds. Does anybody know of a way to enable this? Perhaps a constant or option in <code> wp-config.php </code> ?
|
There's not a constant or anything there, but you can install the WP Beta Tester plugin to switch your update stream to the latest nightlies. Once you install this plugin, you can automatically update to the latest "bleeding edge" release from the standard update panel. Just remember, it's not advised to update production sites to the latest nightly build. Something might be broken, so always back up before you update.
|
Is there a wp-config.php option or constant that I can set to allow me to download nightly / beta builds?
|
wordpress
|
I need to assign some tags to my posts (for external use), but I don't want them showing anywhere that tags are listed. Can someone tell me how to do this?
|
The best way is not to do this. Use a custom taxonomy instead.
|
How to hide certain tags from the_tags()?
|
wordpress
|
I have a custom post I am looking to categorize via a custom taxonomy. The taxonomy itself I want to be dependent on the items of another custom post type. Is it possible to populate a taxonomy via the items of a custom post type, or is it something I have to do manually? Plugins, snippets, guidance on alternat methods of approach would be greatly appreciated. EDIT WITH EXAMPLE: I have a custom post type that basically acts like a page. When I create one, I want it to populate a custom taxonomy with its title. Daniel Dvorkin's answer is the sort of solution I was thinking about.
|
I always use something like: <code> add_action('save_post', 'mdz_correlate_casos_taxonomy'); function mdz_correlate_casos_taxonomy( $post_id ){ if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; if ( 'YOUR CUSTOM POST TYPE' == $_POST['post_type'] ){ if (!wp_is_post_revision($post_id)){ if (!term_exists( $_POST["post_title"], 'YOUR CUSTOM TAXONOMY' )){ $termid = wp_insert_term( $_POST["post_title"], 'YOUR CUSTOM TAXONOMY' ); } } } } </code> But this is prone to get inconsistent (ie: if you delete a post, the term won't get deleted)
|
Populate Taxonomy from Custom Posts
|
wordpress
|
How can I limit the get_pages to only show 5 items? I thought adding <code> 'number' => 5 </code> to the array would limit it to 5 but it doesn't show anything. Here's my code: <code> <?php $pages = get_pages(array('post_type' => 'page','sort_column' => 'menu_order','sort_order' => 'ASC','child_of' => 765)); foreach($pages as $post) { setup_postdata($post); $fields = get_fields(); ?> <p><?php echo $fields->start_date; ?> <a href="<?php echo get_page_link($post->ID) ?>"><?php echo substr($fields->event_title,0,24) . "..."; ?></a></p> <?php } wp_reset_query(); ?> </code>
|
I have had similar problems with the <code> number </code> attribute in <code> get_pages() </code> I got around it by using get_children : <code> $pages = get_children(array( 'numberposts' =>1, 'post_parent' => $heading_page->post_id )); </code> and using <code> post_parent </code> instead of <code> child_of </code> .
|
Limit get_pages to only show 5 items
|
wordpress
|
Is there a way to disable atom feed and have only rss feed? When I click on the RSS button on my Firefox, I am show 'subscribe to domaintitle using RSS feeds' and 'subscribe to domaintitle using atom feeds' I do not use a plugin but rather a function.
|
The feed links that are included in the HTML code depend on your theme. For example, Twenty Ten only includes one feed type (with two feeds: posts and comments). Check your <code> header.php </code> to see which feeds are referenced there. If it is a modern theme (like Twenty Ten), you might see no feed links there. This is because WordPress calls <code> feed_links() </code> in <code> wp_head </code> , which will (if the theme supports <code> automatic-feed-links </code> ) output links for posts and entries in the default feed format, which is <code> rss2 </code> if you don't change it via the <code> default_feed </code> filter. Additionally, on some pages like category archives, <code> feed_links_extra() </code> will also output links for a feed for only that category, again in the default feed format. If you really want to disable a feed (so requests for <code> example.com/atom </code> will no longer work), you can do something like two7s_clash suggested, or play with the rewrite rules so <code> atom </code> is no longer part of the allowed feeds.
|
How to disable atom feed and only use RSS feed
|
wordpress
|
I have created a custom post types and added some custom metaboxes and now I am wondering witch translation plugin I use for my site? I don't have experience with none of them, so I don't know who will support my custom metaboxes and who will not.
|
take a look at Internationalizing Your Plugin codex entry to get a better understanding of WordPress Translations. and read I18n for WordPress Developers after that you will know that if you coded your custom post types and metaboxes the right way with Translatable strings , all plugins work in the same way of looking for these strings. and i would suggest using Codestyling Localization plugin which create a UI for translating plugins and themes inside WordPress admin.
|
Custom metabox translation
|
wordpress
|
I'm trying to pull rss from sites similar to this: http://andreabadendyck.blogg.no/ I have several posts with the URL in the title, so I can pull the URLS from here and hardcode the rss reader in the theme. I want to display the recent posts like this (under "Siste innlegg"): http://blogglisten.no/blogg/andreabadendyck.blogg.no Is it any available plugins for this? I have tried RSS Feed Reader for WordPress with no luck.
|
I followed this guide to insert the feed in the post: http://digwp.com/2009/11/import-and-display-feeds-in-wordpress/ My only problem is that I need to strip away the HTML from the feed.
|
Pulling RSS from site and display it in posts
|
wordpress
|
I have combination of valid input with native WP function throwing PHP notice. In this specific case it is image without extension with <code> image_resize() </code> . This is usually suppressed by WP, but it still has me worried because it runs in feed and such things can explode XML to pieces. If I can neither change core or input then what should I do? I suppose I could try to explicitly suppress error output around there. Or should I just ignore the possibility as edge case?
|
Simply use the <code> @ </code> operator in front of a function to suppress an error message/notice/whatever. Fun as it is: Even the <code> image_resize() </code> function uses it for <code> chmod </code> . :)
|
How to handle core code throwing notice on valid input?
|
wordpress
|
How would I make my WordPress Comments Editable? I tried using an Ajax plugin that take them to another screen, but it's not as nice as I would like. For example, I just want it to re-open the initial comment box and allow them to edit their comment for at least 30 minutes after a post.
|
Best plugin I've found is Editable Comments .
|
Making Comments Editable?
|
wordpress
|
On my new site i am displaying most of the images instead of text. I show images for recently written, recently viewed, mostly viewed posts etc. I found that in 40% of cases posts are same. so i need not to hit the DB to extract the image. It can save number of hits to Db & processing time. I intially thought to cache post IDs. So before querying to DB or processing contents to extract image, i can search for post id into cache. If post id found in cache then i can directly show image from disk. I found that there are many of the plugins who cache DB queries and their result. I am using wp-total cache. Please tell me whether it can fulfill my requirement or i should write my own logic
|
As long as you use WP API ( <code> $wpdb </code> ) to perform queries, they will be cached by caching plugins (well, by those that have such functionality). If you need to cache data that is more compelx to generate rather than just retrieve look into Transients API .
|
Cache DB queries result
|
wordpress
|
I am implementing (trying) a front end posting system which shows taxonomy data in several dropdown select fields, each of the dropdowns is named by using the "name" $arg in wp_dropdown_categories. <code> <?php wp_dropdown_categories('taxonomy=location&hide_empty=0&orderby=name&order=asc&name=location') ?> </code> as you can see taxonomy is "location" and select name is "location". I then add the variables for each of the taxonomy select dropdowns like so along with post_title, post_content etc: <code> $title = trim($_POST['wpuf_post_title']); $content = trim($_POST['wpuf_post_content']); $tags = wpuf_clean_tags($_POST['wpuf_post_tags']); $customcategory = trim($_POST['customcategory']); $cat = trim($_POST['cat']); $location = trim($_POST['location']); $sale_rental = trim($_POST['sale_rental']); $price = trim($_POST['price']); </code> and finally i add the extra info into an array ready to be sent by wp_insert_post, im quite stuck on whether i am doing the right thing by adding tax_input into the array like below as this is what i seem to be understanding from codex that i need to do. <code> 'tax-input' => array( $location, $sale_rental, $price ), </code> so that it all ends up looking like this: <code> $my_post = array( 'post_title' => $title, 'post_content' => $content, 'post_status' => $post_status, 'post_author' => $userdata->ID, 'post_category' => array($_POST['cat']), 'post_type' => $customcategory, 'tags_input' => $tags, 'tax_input' => array( $location, $sale_rental, $price ), ); $post_id = wp_insert_post($my_post); </code> however when i submitted the new post, all the standard post data (and also my custom post type) goes in ok, but the taxonomies do not, im obviously doing something wrong, but what?
|
Use <code> wp_set_object_terms </code> after you have the post id for each taxonomy: <code> ... $post_id = wp_insert_post($my_post); wp_set_object_terms($post_id,$location,'location'); wp_set_object_terms($post_id,$sale_rental,'sale_rental'); wp_set_object_terms($post_id,$price,'price'); </code>
|
Attaching taxonomy data to post with wp_insert_post
|
wordpress
|
I released the first version of stackexchange-url ("my Rewrite analyzer plugin") with a commit on 2010-05-12. The WordPress.org plugin directory however still displays 2010-11-27 as the "Last Updated" date - this is the date when the plugin directory was created in the repository. The Developer FAQ states: Last updated time Time of last check in to the appropriate directory (trunk/ or the stable tag directory) after a version number change . Most developers commit their first version right after their plugin directory gets created, so you won't notice the difference. But I have seen the same discrepancy in other plugins that were committed more than one day after the directory was created. I committed both the <code> trunk/ </code> and <code> tags/1.0/ </code> directories in one go (with a local copy and then a commit), but the other plugin with this problem did it like most people do: a commit of <code> trunk/ </code> and then a remote copy to <code> tags/1.0/ </code> . Otto recently said: The only time the readme gets parsed and the entry gets rebuilt is when the version of the plugin changes. However, for people using tags, this generally happens after they make the new tag and update the Stable Tag. The readme file got parsed, so I don't know what else I could have done to make it update correctly?
|
I've been trying to work out the issue for months now, and have made several adjustments to try to solve the problem. In short: Yes, we know there's a problem. No, I don't know how to fix it yet. You can stop reporting it already. Current workaround: ANY commit of any kind should trigger it to update. So simply adding a space to the readme.txt and waiting 30 minutes should do the trick. If it doesn't, then contact me: [email protected]
|
Plugin directory "Last Updated" not changed after initial commit?
|
wordpress
|
I've developed a few plugin for Wordpress. Currently I've not been able to replicate the way wp save settings. I've a setting page which I learned from a tutorial. It POST to <code> option.php </code> , and wp take care of saving the data. But I have some custom option page which require more complex handling. Basically I wanted to POST some data to my own php, then redirect back to the original page/url after handling. I can't find a "proper" way to redirect correctly, i.e. without load the whole page then redirect using javascript. Currently I use GET with <code> add_query_arg() </code> , the url will display the data that I passed. Using POST will trigger a redirect prompt when refreshed. Is there a built in wp function that does it automatically? OR If I were to POST to <code> option.php </code> , how should I access the data without it handling automatically? EDIT: Example of one of the complex page would be like this: I assign a usermeta to some users which we would call SU (SpecialUser). To ease the job of admin, I have a page to display the list of users with a column showing whether they are SU. The text in that column of each row is a link which if clicked, will toggle the state of SU for that user. Currently I use GET, to pass the id of the user and also action to be carried out. Then page itself will detect, if both action and id is valid, the state of the user is toggled. At the same time, the updated result is displayed. The GET query remain at the URL What I would really like to do is to use POST, pass the id and action to the same page, then toggle the state but not displaying anything, then "redirect" back to the page displaying the updated user list. What I've tried earlier while implementing this is to use javascript to redirect the page, but this means it will have to load the whole page before the javascript can be executed. It's not resource friendly. I would like it to work much like how the Settings API would. Sorry for the long explaination. I'm sure there's a term to what I wanted to do, but I'm not sure what it is. Thanks EDIT: It's more or less like the Plugin page, when you activate/deactivate the plugin. The plugin page is using GET. The problem I have is actually redirecting, so GET or POST shouldn't matter.
|
I've found a way to overcome what I needed by using wp_redirect() . I'm calling <code> wp_redirect() </code> after I've done processing. Also following advise from WordPress and wp_redirect() function problem , I added <code> noheader=true </code> to the form's action or link to prevent the error "header already sent" from php.
|
Wordpress Plugin Setting's POST
|
wordpress
|
How do I override the search template i.e. used inside a theme with a custom search page inside a plugin? Please point our any relevant action/filter hooks which can be used to do this. Any help is highly appreciated.
|
You can use <code> template_include </code> filter hook <code> add_filter('template_include','my_custom_search_template'); function my_custom_search_template($template){ global $wp_query; if (!$wp_query->is_search) return $template return dirname( __FILE__ ) . '/my_search_template.php'; } </code>
|
How do I override the search template in a plugin?
|
wordpress
|
Using Wordpress 3.1 is it possible to completely disable the drafts functionality or at least remove the "Save Draft" button from the post screen?
|
If by draft, you mean "autosave", you can consider using this plugin: http://wordpress.org/extend/plugins/wp-feature-disable/ If you want to disable revisions, instead...try this: <code> define('WP_POST_REVISIONS', 'false'); </code> You can put that in your /wp-config.php file and it should immediately take effect. Any previously saved revisions in your database will need to be purged. You can do it by running the following MySQL query in phpMyAdmin: <code> DELETE FROM wp_posts WHERE post_type = "revision"; </code>
|
How to disable drafts?
|
wordpress
|
Is it possible to completely disable Bulk Edit functionality? I'm using Wordpress 3.1.
|
A more reliable approach than messing with CSS would be to add some Javascript in the admin_head action, and basically override the built-in "inlineEditPost" function (located in wp-admin/js/inline-edit-post.js and easier to read in inline-edit-post.dev.js). I haven't looked into it much specifically, but the brute force method would be to copy (and rename) that entire function and basically reverse the show/hide methods. I've confirmed that disabling Javascript disables the Bulk Edit functionality entirely, so there wouldn't really be a workaround to your override.
|
How to remove bulk edit options
|
wordpress
|
I want to set up a basic 'post rating' system for my site - I don't want to use a plugin - so I want to add the custom field 'rating' to each new custom post and populate this field with the number 1. Is this possible? Or am I going about this the wrong way? Did a lot of searching a found not much, <code> add_post_meta() </code> ? I'm not sure where that would go.
|
you can do that with hooking a simple function to <code> save_post </code> hook <code> add_action('save_post','my_rating_field'); function my_rating_field($post_id){ global $post; // verify if this is an auto save routine. // If it is our form has not been submitted, so we dont want to do anything if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) ) return; // Check post type if ($post->post_type != "YOUR_POST_TYPE_NAME") return; // OK, we're authenticated: we need to find and save the data $rating = get_post_meta($post_id,'rating',true); //if field not exists create it and give it the value of one if (empty($rating) || !isset($rating)){ update_post_meta($post_id,'rating',1); } } </code>
|
Populate Custom Fields in a Custom Post Type?
|
wordpress
|
I'm familiar with this method... <code> update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’); </code> The problem is, I'm trying to do this to all tables (or select tables), but need the replace to hit all columns for the table in question. Currently, the only way I've found for a table with 20 columns is to repeat this query 20 times. Once for each column. Is there any way to simply apply the search replace on the table rather than column?
|
Have you tried the search and replace plugin? it will allow you to select particular tables: http://wordpress.org/extend/plugins/search-and-replace/ Of course use it with caution. etc.
|
Global MySQL replacing of text patterns/matches
|
wordpress
|
Was asked to simplify the question. Here we go: As you know, the "content" part of a WordPress posts all appears together. What I'm trying to recreate is how on several news sites, they'll have the title (and the rest of the "meta" stuff), followed by a photo or video, but then the body text is slightly indented either from the get-go (or shortly thereafter) to make room for a thin, left column that might display related stories, advertisements, additional meta data about the post itself, or even contain videos for the post itself. Examples: http://www.cnn.com/2011/US/05/24/nasa.new.spacecraft/index.html?hpt=T1 - story highlights, related topics. Image and caption take up full width, but the highlights column indents body text. http://www.chicagotribune.com/news/local/breaking/chibrknews-blagojevich-to-take-the-stand-20110524,0,6202649.story - related articles, related topics, ads. Unlike the CNN example, the column actually starts partway through the body text. My dilemma is that since the photo or video that starts each post is part of the "content," I can't indent the text and put in the column unless I were to do that manually for each post. I've contemplated making a custom field for the image or video input to essentially "separate" it from the body text, but that might prove difficult, since I don't know how it would differentiate between an image URL and a YouTube URL or embed code. Anyone have any better ideas?
|
a few ideas- use shortcodes to insert inline markup with your content. use custom fields to insert inline markup with your content. if you don't want to deal with parsing out the URL to figure out if it's an image, youtube, etc., just define different custom field names and handle them individually if they exist. read up on "floating" and positioning elements with html and css. you may be able to achieve the layout you want with just front-end markup changes.
|
How to insert a column (part of theme) in the middle of the content body?
|
wordpress
|
Hi: I have been using the comments.php, comments-popup.php, single.php and loop from the Kubrick theme to create my blog functionality in themes I build from scratch. But with WP 3.0 there's a new approach and I can't quite get it to work. From what I've gathered I have the loop in the index.php, loop with some additional code in the single.php, a category.php, and in the comments.php all there should be is one line of code: <code> <?php comment_form(); ?> </code> On the server there's a wp-comments.php page with what appears to be the various parameters that can be adjusted - though how to do that is another question. But my first question is: what exact templates and code are needed to get basic fully functioning comments? Do I have to add anything to the functions.php? I almost got there but I couldn't get comments to actually appear on a page. I had the ability to enter comments working, and the comments would come into the admin, and the live page itself would have a link: 1 comment. But clicking the link took me nowhere. I'm using the loops etc. from this article: http://www.onextrapixel.com/2011/03/08/how-to-code-a-wordpress-3-0-theme-from-scratch/ Can someone enumerate the specific steps to make the new approach work? I'm an HTML/CSS person who understands a little php but not a lot. I'm trying to grasp the relationship between all the pieces/parts needed to make the comments work with the new approach. Thank you for any help!
|
Just download twentyten and see how it works, it's relatively simple to use it as an example. Nothing needs to go into functions.php for comments to work. You can use custom callbacks in there if you wish, but just a few template tags get the comments going <code> <?php comments_template( '', true ); ?> </code> Is what goes into your single.php, page.php etc to disply the form. http://codex.wordpress.org/Function_Reference/comments_template Something like <code> <p><?php comments_popup_link('No comments yet', '1 comment so far', '% comments so far (is that a lot?)', 'comments-link', 'Comments are off for this post'); ?></p> </code> Is great for index.php http://codex.wordpress.org/Function_Reference/comments_popup_link And then within comments.php, wp_list_comments displays the comments, and yes, <code> <?php comment_form(); ?> </code> Is what displays the actual form I like this article for usage of the comment form
|
What templates/funtions needed in custom theme to allow comments the new 3.0 way
|
wordpress
|
I'm using Wordpress as CMS and have a checkout page where info is inserted into the db using $wpdb-> insert. I have 2 questions: Is 'sql injection' already a part of that function or do I need to add my own code? Are there wordpress form input validation functions that I can use on my custom form?
|
Is 'sql injection' already a part of that function or do I need to add my own code? When inserting input to the database you should use <code> prepare </code> method of WPDB class which supports both a <code> sprintf() </code> - like and <code> vsprintf() </code> -like syntax. read more at the codex Are there wordpress form input validation functions that I can use on my custom form? Yes there are many and they are covered in Data Validation codex entry like toscho pointed out.
|
Data Validation
|
wordpress
|
I want to create a custom archive page. It will look like this: 2011 January February March April May June... (Months) May (Current Month) Post 1 Post 2 Post 3 ... And clicked one of months ( <code> is_month() </code> page) it will be look like this : 2011 (Selected Year) January February March April May June... (Months) April (Selected Month) Post 1 Post 2 Post 3 ... I tried to solve this by using <code> wp_get_archives(); </code> but it's insufficient for this situation. Anyone got some ideas? Thanks! Wordpress version is 3.1
|
I highly recommend checking out the Smart Archives Reloaded plugin . It has several formats and one of them, called "fancy", displays things very similar to what you described.
|
Custom Archive Page
|
wordpress
|
I want to write a plugin so I can hook up the <code> wp_install_defaults </code> function. I actually need to do the following: when a new site is created, I want to import a default XML file with some categories and default posts. <code> wp_install_defaults </code> is the function that does that, but it doesn't seem to work. Isn't <code> wp_install_defaults </code> hook-able?
|
You can use <code> wpmu_new_blog </code> action hook which accepts 6 arguments: $blog_id $user_id $domain $path $site_id $meta
|
Hook up MU site creation
|
wordpress
|
When you create a post in WP, if you don't specify a title rapidly, WP generates a default slug on autosave, based on the post ID. Then, when you add the title later, unless you modify the slug by editing it, it remains the same (based on post ID) What I'm trying to do is add an action on post publish, that generates and saves the post slug, based on the post title.
|
As long as haven’t touched the slug WordPress will generate a new one after you entered a title. Update To change other peoples slugs use a filter (not tested!): <code> add_filter( 'wp_insert_post_data', 'prevent_numeric_slugs', 10, 1 ); function prevent_numeric_slugs( $post_data ) { if ( ! isset ( $post_data['post_title'] ) or ! is_numeric( $post_data['post_name'] ) ) { // exit early return $post_data; } // post_name is the slug $post_data['post_name'] = sanitize_title( $post_data['post_title'] ); return $post_data; } </code>
|
How can I automatically set a post slug based on the post title during post publish?
|
wordpress
|
Ive created a custom post type and I want to hide the main textarea content in the publish/edit page. Is it possible ? Thanks!
|
Yes, remove the editor support from your custom post type. You can do it in two ways. While registering your custom post type: Example: <code> $args = array( 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'capability_type' => 'post', 'has_archive' => true, 'supports' => array('title','author','thumbnail','excerpt','comments') ); register_post_type('book',$args); </code> 2.Using the remove_post_type support if the custom post type is not defined by your code (i.e some other plugin/theme has defined custom post type). Example: <code> add_action('init', 'my_rem_editor_from_post_type'); function my_rem_editor_from_post_type() { remove_post_type_support( <POST TYPE>, 'editor' ); } </code>
|
Hide content box with Custom Post Type?
|
wordpress
|
I have three custom post types, each with around 5 taxonomies and 2 of the custom post types share two taxonomies. I've just about got everything set up for posting from the front end other than the part of a dropdown to show the post_types. As it is now front end posting works but, the urls are broken because they dont have the custom post type in them, i've searched all over and can find zero on listing custom post types... can it be done? Regards Martin edit: Just stumbled upon this over at codex ,,
|
Sorry about that feels a bit weird answering ones own question, but here you go.... Firstly declare the variable: (customcategory) <code> global $userdata; $errors = array(); $title = trim($_POST['wpuf_post_title']); $customcategory = trim($_POST['customcategory']); $content = trim($_POST['wpuf_post_content']); $tags = wpuf_clean_tags($_POST['wpuf_post_tags']); $cat = trim($_POST['cat']); </code> Secondly the array for adding the post: <code> if (!$errors) { $frontend_post = array( 'post_title' => $title, 'post_content' => $content, 'post_status' => $post_status, 'post_author' => $userdata->ID, 'post_category' => array($_POST['cat']), 'post_type' => $customcategory, 'tags_input' => $tags ); $post_id = wp_insert_post($frontend_post); </code> and finally create the dropdrown from the get_post_types function: <code> <?php $args=array( 'public' => true, '_builtin' => false ); $output = 'names'; $operator = 'and'; $post_types=get_post_types($args,$output,$operator); echo '<select name="customcategory">'; foreach ($post_types as $post_type ) { echo '<option value="'. $post_type.'">'. $post_type. '</option>'; }echo '</select>'; ?> </code>
|
List custom post types in dropdown
|
wordpress
|
I'm new to Wordpress and I'm trying to edit the Twenty Ten theme so that my template for basic pages (basic-template.php) does not show the comments box. I do want the comments box to show up on other pages, such as blog posts. I'm pretty sure that changes need to be made in loop.php, but my doesn't seem to be having the right effect. For the comments box, I edited: <code> <?php comments_template( '', true ); ?> </code> to be as follows. <code> <?php wp_reset_query(); if ( is_page_template(‘basic-template.php’) ) { comments_template(); } else { comments_template( '', true ); } ?> </code> When I get rid of the else statement, the comments disappear, so I think the problem is my code for that part. Any advice would be much appreciated!
|
You can turn off the discussion per post/page when you're creating new posts/pages. this option is usually below the text editor and is often hidden. In order to bring it up, you might have to click on "Screen Options" at the top of the page and check the box next to "Discussion"
|
How can I edit the Twenty Ten Theme to remove the comments box when a page uses a specific template?
|
wordpress
|
I'd like to have a custom field interface show up only when a certain template is assigned to a particular WordPress page. Any ideas?
|
The best way to approach this situation is via JavaScript. That way, whenever the selected value changes, you can instantly hide/show the related metabox. Use <code> wp_enqueue_script() </code> in <code> functions.php </code> to load a custom JavaScript file in the admin area: <code> add_action('admin_enqueue_scripts', 'my_admin_script'); function my_admin_script() { wp_enqueue_script('my-admin', get_bloginfo('template_url').'/my-admin.js', array('jquery')); } </code> The script itself, which requires jQuery, simply hides or shows a metabox based on the selected value in the page template dropdown list. In this example, I'm only showing the metabox for post thumbnails in case the default page template is selected: <code> (function($){ $(document).ready(function() { var $page_template = $('#page_template') ,$metabox = $('#postimagediv'); // For example $page_template.change(function() { if ($(this).val() == 'default') { $metabox.show(); } else { $metabox.hide(); } }).change(); }); })(jQuery); </code> And, just for fun, here's a shorter, less verbose, version of the same script: <code> (function($){ $(function() { $('#page_template').change(function() { $('#postimagediv').toggle($(this).val() == 'default'); }).change(); }); })(jQuery); </code>
|
Toggle admin metabox based upon chosen page template
|
wordpress
|
I am currently looking for a way to replicate the image I have below. I have come across many tabbed content plugin's and snippets of code, but I cannot figure out how to add different background images to each tab.
|
Prepare You will have to use some jQuery and jQuery UI on your tabs. Load it with <code> wp_enqueue_script </code> - Codex , How-To . The search In any case: Google for "jQuery Tabs". Mark up The mark-up will look close to this one. <code> <!-- These are the tabs --> <ul class="wpse-tabs"> <li> <a href="#your-target-div-A" title="Your target description A"> <span class="wpse-tabs-icon smilie-icon"></span> A: Some descriptive text </a> </li> <li> <a href="#your-target-div-B" title="Your target description B"> <span class="wpse-tabs-icon stats-icon"></span> B: Some descriptive text </a> </li> </ul> <!-- This is your content with wrapper --> <div class="tab-target-wrapper"> <div id="your-target-div-A">Your content A</div> <div id="your-target-div-B">Your content B</div> </div> </code> The Style <code> <style> /* Assumin you're using an image sprite as background. In case you don't know what that is, ask google */ .wpse-tabs-icon { display: block; width: 16px; height: 16px; background: url('iconsprite.png') no-repeat; } .smilie-icon { background-position: 0px 0px; } .stats-icon { background-position: 20px 0px; } </style> </code>
|
tabbed content box with different tabbed background images
|
wordpress
|
I have been using WordPress for several years, but have yet to see a reason to employ tags over categories or tags with categories. What is the thinking behind the two, and when are each appropriate?
|
Aside from the technical aspects, Categories are for broad topics while Tags are for adding more detail to your posts' subject. Lorelle has written the definitive guide on the difference between categories and tags . You might also want to check out the WordPress.com guide on Categories vs. Tags .
|
What is the difference between a "tag" and a "category"?
|
wordpress
|
Ok = I've looked around a lot for a clear answer to this, but find very few real answers. I would really appreciate some info from experienced individuals. A tiny bit of background. I've worked content generation (among other thing) on a largeish website for many years, and it follows the pretty basic file system and discreet html (.aspx) pages for content. You want a new page, you make a new file and build your content. Done. I've built a dozen or so brochure sites like this as well. This is the system that makes sense to me, and I find myself a little hesitant to veer away. CMS systems, like WP, obviously do not work like this. I am not inexperienced with wordpress. I've built and implemented a couple custom themes, but have "tried" to make the above file structure work "along side" of a wordpress install - mostly leading to headaches. That is where I currently sit, having spent a couple of months of weekends building my new personal site (which is almost finished). The format of the site is pretty straightforward - its a developer blog (I do a lot of AS3), a portfolio for artwork, and a main intro page that contains a bit of both. My file structure looks a bit like so: <code> mysite.com- /css/ /home/ /images/ /javascript/ /portfolio/ /php/ (holds a lot of php snippets that is included elsewhere) /swf/ /wordpress/../theme/ (draws upon img/css/php in external folders) index.php </code> While I do very much like the familiarity of this structure, the cross sharing of assets between static files and dynamic wordpress content is a pain. My option is to turn all static files into templates, and make use of WP's database driven page system. What do I stand to gain from "buying into" the WP system completely? Or, conversely, is a static file structure external to wordpress "workable" - and are there preferred methods of doing so? I realize this question is somewhat subjective, however, the proper handling of static content is, I think, a quite valid point of inquiry (tho... you might not think it, considering how little info there is to be found on the subject). Thanks
|
Put everything into WordPress. This way, you can search your entire content from the built-in search engine, and you can edit each piece. If you need pages with special markup create templates for your theme. Naked Template <code> <?php /* * Template Name: Naked * * That’s the complete template! */ </code> Basic HTML5 <code> <?php /* * Template Name: Basic HTML5 */ ?> <!doctype html> <meta charset="<?php bloginfo( 'charset' ); ?>"> <title><?php wp_title( '' ); ?></title> <?php while ( have_posts() ) { the_post(); ?> <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1> <?php the_content(); } </code> Import To import your old HTML pages use the plugin Import HTML Pages .
|
Static files or dynamic WP pages for "static content"?
|
wordpress
|
I would like to modify a WP Gallery to use the jquery cycle plugin by malsup . I know this is possible but would like to know best practice for this, if anything just pulling out the url for each image should give me enough to work with. Please advise on best practice for this. Note I do not want to use a plugin and would like to build this site on WP Core.
|
What your asking for has the basic functionality of a plugin, so saying you don't want to use a plugin doesn't make much sense. If you do for some reason want to write your own , using any jquery or JavaScript is relatively straightforward, you enqueue the script where you want it, then wrap whatever data your using in the javascript tags ( usually a div class or id ). This is a very basic example. http://codex.wordpress.org/Function_Reference/wp_enqueue_script <code> wp_register_script( 'jquery_cycle_name','http://path-to-your-cycle.js'); wp_enqueue_script( 'jquery_cycle_name' ); </code> The javascript: <code> jQuery(document).ready(function($) { $('#featured-works').cycle('fade'); }); </code> Your template or whatever you wrap your info in, typically you want this in a loop to go through several images/posts or content. <code> <div class="featured-work"> images, etc, go here</div> </code>
|
using jQuery Cycle by Malsup with WordPress Page and Gallery
|
wordpress
|
Does anyone know of a way to create a sitemap by using wp_list_pages and have the order by the same orders a custom nav menu?
|
Using wp_list_pages you can sort order only by: 'post_title' 'menu_order' 'post_date' 'post_modified' 'ID' 'post_author' 'post_name' anything else (like order by custom menu order) you would have to write your own function. But a better way to get it done would be to create a custom walker for it so you could control the output.
|
wp_list_pages sort order by custom nav menu order
|
wordpress
|
i found a code searching through stackexchange --> to create a "list" inside a meta box of a custom type, BUT, i don't see anything appearing in this meta box, except the input field (which comes from the example page from the CODEX : http://codex.wordpress.org/Function_Reference/add_meta_box ), is it a problem with WP_QUERY inside a function? Can you please tell me what is the magic trick to fix this? in my callback function, i added this code : <code> function myplugin_inner_custom_box() { // Use nonce for verification wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' ); // The actual fields for data entry echo '<label for="myplugin_new_field">'; _e("Description for this field", 'myplugin_textdomain' ); echo '</label> '; echo '<input type="text" id="myplugin_new_field" name="myplugin_new_field"/>'; $s_query = new WP_Query( array( 'suppress_filters' => false, 'post_type' => 'movies')); while($s_query->have_posts()):$s_query->the_post(); $sname = $post->post_title; $s_output2 =''; $s_output2 .= '<option value="'.$post->ID.'" >'; $s_output2 .= $post->post_title; $s_output2 .= '</option>'; echo $s_output2; endwhile ; wp_reset_query(); } </code> But as i said, the "list" doesn't appear. Could you please help me?
|
You are missing the declaration of the HTML select tag which options are his children so just add something like this: <code> function myplugin_inner_custom_box() { // Use nonce for verification wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' ); // The actual fields for data entry echo '<label for="myplugin_new_field">'; _e("Description for this field", 'myplugin_textdomain' ); echo '</label> '; echo '<input type="text" id="myplugin_new_field" name="myplugin_new_field"/>'; //the actual select tag echo '<label for="my_list_field">'; _e("Description for this field", 'myplugin_textdomain' ); echo '</label> '; echo '<select name="my_list_field" id="my_list_field">'; $s_query = new WP_Query( array( 'suppress_filters' => false, 'post_type' => 'movies')); while($s_query->have_posts()):$s_query->the_post(); $sname = $post->post_title; $s_output2 =''; $s_output2 .= '<option value="'.$post->ID.'" >'; $s_output2 .= $post->post_title; $s_output2 .= '</option>'; echo $s_output2; endwhile ; echo '</select>'; wp_reset_query(); } </code>
|
add a "list" into add meta box : problem
|
wordpress
|
I am using the code below to display posts defined as a custom-post-type and filtered by a custom-taxonomy of 'england'. I've tried using 'posts_per_page=5' in the query_posts function but this brings up a completely different set of posts from one of my post categories of type 'news'. When I remove the posts-per-page from the query, it returns the listings I want but it defaults to the default 10 set within the Wordpress Settings. How do I override it in the code below? <code> <?php query_posts( array( 'country' => 'event-england') ); ?> <?php if( is_tax() ) { global $wp_query; $term = $wp_query->get_queried_object(); $title = $term->name; } ?> <ul> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endwhile; else: ?> <?php endif; ?> </ul> </code>
|
Something like this is what you need. The Codex page for WP_Query is very helpful <code> $args = array('post_type' => '<your custom post type name>', 'posts_per_page' => 5, 'tax_query' => array( array( 'taxonomy' => '<your custom taxonomy name>', 'field' => 'slug', 'terms' => 'event-england' ) ) ) $query = new WP_Query($args) </code>
|
Limit the number of posts in query_posts function with custom post types
|
wordpress
|
Is there a way in WordPress 3.1 to restrict allowed file uploads by extension (images only) and file size? Bonus question: Can I limit users to only be able view files they have uploaded themselves?
|
I believe you can add a filter to <code> upload_mimes </code> to restrict to certain types. The hook: http://adambrown.info/p/wp_hooks/hook/upload_mimes The filter: <code> add_filter('upload_mimes','restict_mime'); function restict_mime($mimes) { $mimes = array( 'jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', ); </code> From what I understand this will not work for admins or any user with the <code> unfiltered_upload </code> capability. Also have a look at this post stackexchange-url ("Limit image upload to one and disable audio, video and other document file types to upload.") An alternative to control size limit would be to use .htaccess or php.ini: For upload limit you can set in .htaccess one of the following; <code> LimitRequestBody 1073741824 //( 1MB) php_value upload_max_filesize 1M php_value post_max_size 1M </code> For php.ini you can set <code> upload_max_filesize = 1M </code>
|
Restrict file uploads by extension?
|
wordpress
|
How can I limit html elements allowed in the tinymce editor in Wordpress 3.1 and ensure harmful scripts have been removed (script/embed tags, etc)
|
Adjust HTML-Filter: <code> <?php function fb_change_mce_options($initArray) { // Comma separated string od extendes tags // Command separated string of extended elements $ext = 'pre[id|name|class|style],iframe[align|longdesc|name|width|height|frameborder|scrolling|marginheight|marginwidth|src]'; if ( isset( $initArray['extended_valid_elements'] ) ) { $initArray['extended_valid_elements'] .= ',' . $ext; } else { $initArray['extended_valid_elements'] = $ext; } // maybe; set tiny paramter verify_html //$initArray['verify_html'] = false; return $initArray; } add_filter('tiny_mce_before_init', 'fb_change_mce_options'); ?> </code> Customizing the function of the buttons in your Editor: <code> <?php function fb_change_mce_buttons( $initArray ) { //@see http://wiki.moxiecode.com/index.php/TinyMCE:Control_reference $initArray['theme_advanced_blockformats'] = 'p,address,pre,code,h3,h4,h5,h6'; $initArray['theme_advanced_disable'] = 'forecolor'; return $initArray; } add_filter('tiny_mce_before_init', 'fb_change_mce_buttons'); ?> </code> Change language of spelling: <code> <?php function fb_mce_external_languages($initArray){ $initArray['spellchecker_languages'] = '+German=de, English=en'; return $initArray; } add_filter('tiny_mce_before_init', 'fb_mce_external_languages'); ?> </code> The default values of WordPress: <code> 'mode' => 'specific_textareas' 'editor_selector' => 'theEditor' 'width' => '100%' 'theme' => 'advanced' 'skin' => 'wp_theme' 'theme_advanced_buttons1' => 'bold,italic,strikethrough,|,bullist,numlist,blockquote,|,justifyleft,justifycenter,justifyright,|,link,unlink,wp_more,|,spellchecker,fullscreen,wp_adv' 'theme_advanced_buttons2' => 'formatselect,underline,justifyfull,forecolor,|,pastetext,pasteword,removeformat,|,media,charmap,|,outdent,indent,|,undo,redo,wp_help' 'theme_advanced_buttons3' => '' 'theme_advanced_buttons4' => '' 'language' => 'de' 'spellchecker_languages' => 'English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,+German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv' 'theme_advanced_toolbar_location' => 'top' 'theme_advanced_toolbar_align' => 'left' 'theme_advanced_statusbar_location' => 'bottom' 'theme_advanced_resizing' => true 'theme_advanced_resize_horizontal' => false 'dialog_type' => 'modal' 'relative_urls' => false 'remove_script_host' => false 'convert_urls' => false 'apply_source_formatting' => false 'remove_linebreaks' => true 'gecko_spellcheck' => true 'entities' => '38,amp,60,lt,62,gt' 'accessibility_focus' => true 'tabfocus_elements' => 'major-publishing-actions' 'media_strict' => false 'paste_remove_styles' => true 'paste_remove_spans' => true 'paste_strip_class_attributes' => 'all' 'wpeditimage_disable_captions' => false 'plugins' => 'safari,inlinepopups,spellchecker,paste,wordpress,media,fullscreen,wpeditimage,wpgallery,tabfocus' </code> I hope this helps you. You should be able to change just about anything you like.
|
Limiting allowed html elements/strip harmful scripts from editor
|
wordpress
|
In my taxonomy.php, my query is ` <code> $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $wpq = array ('posts_per_page' => -1, $term->taxonomy => $term->slug, 'order' => 'ASC', 'orderby' => 'slug'); $loop = new WP_Query($wpq);` </code> It correctly retrieves the droids posts I am looking for, but does not <code> orderby </code> <code> slug </code> . I can't find <code> slug </code> as an option in the documentation any more, but I swear I have successfully used it before. How do I make it so? Edit: <code> 'orderby' => 'name' </code> appears to work in 1 category but not in my other category (so far, there are only 2). I'm wondering if the category where it does work is just coincidence...
|
Not possible in WP 3.2.1. See here http://codex.wordpress.org/Function_Reference/get_pages under "Parameters" and "page_name". I'm working on exactly the same thing, but it seems I'll need to resort to to a custom query: http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query
|
Can you orderby slug in a taxonomy archive page using WP_Query?
|
wordpress
|
I need to conditionally not show the comment form. I've added a filter to <code> comment_form_defaults </code> as follows: <code> function dont_show_comments($defaults) { $defaults = array( 'fields' => array(), 'comment_field' => '', 'must_log_in' => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>', 'logged_in_as' => '', 'comment_notes_before' => '', 'comment_notes_after' => '', 'id_form' => 'commentform', 'id_submit' => 'hide', 'title_reply' => __( 'You need to have accepted the terms to leave a reply' ), 'title_reply_to' => __( 'Leave a Reply %s' ), 'cancel_reply_link' => __( 'Cancel reply' ), 'label_submit' => '', ); return $defaults; } </code> This mostly works, but I'm left with an unlabelled button (the submit button). What's the best way of not showing the form at all - preferably via a hook, and preferably not using CSS.
|
I can think of only following ways to achieve this. There is a filter " comments_open " that check if the post whose $post_id is provided has comments open. You can use that to return false. There is another filter " comments_template " that return the template file to be used to display comment form. You can return an empty file and hence no comment form will be displayed. The other is to set the comment_status on $post object to close before comment form is displayed, it will stop theme from displaying the comment form even if they use the hardcoded comment form.
|
Hide comment form completely (preferably without using CSS)
|
wordpress
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.