question
stringlengths 0
34.8k
| answer
stringlengths 0
28.3k
| title
stringlengths 7
150
| forum_tag
stringclasses 12
values |
---|---|---|---|
Just looking for some advice on something that is bugging me. Please bear in mind I am a PHP noob :-) I am passing a variable in the url to my WP index page like so: <code> <a href="<?php bloginfo('url');?>/?do=thing">Thing</a> </code> I am the catching that variable, and using it to show content like so: <code> <?php $do_that = $_GET["do"]; if($do_that == 'thing') : ?> etc </code> Naturally I am getting debug errors when the variable is not passed :-) <code> "Undefined index: do" </code> My question is what am I missing wrong? Obvious I spose? Also is this bad practice?
|
The error is occurring as the $_GET array doesn't have the item $_GET['do'] in it. Therefore it throws this notice. To check if something exisits in the array try: <code> if( isset( $_GET['do'] ) ) $do_that = $_GET['do']; else $do_that = ''; </code> or a cleaner method would be to use short hand notation <code> $do_that = ( isset( $_GET['do'] ) ) ? $_GET['do'] : ''; </code>
|
Using a _GET gives me a debug error (over my head)
|
wordpress
|
In my theme, i want to create a generic way of inserting a meta box to a post, page, portfolio or other custom item. For now, this action is like : <code> add_action('admin_init', 'add_portfolio_settings'); </code> Which works fine, but has a problem. It currently works only for creating an add_meta_box for a portfolio item. However, what if i wanted to add the same to a post or page ? So, i would like to have add_action passing an argument to my add_portfolio_settings function, ideally an array, that specifies what the types that a new meta box should register under. I've read stuff and tried different things about do_action, but i cannot get it to work. Any ideas ?
|
What you want is quite possible, but not exactly mainstream technique. Take a look at my stackexchange-url ("Implementing advanced add_* function wrappers") question. However your real issue here is not being unable to pass arguments. It is lack of context. The simplest way to track context is inside your hooked function (check what page you are at, do something accordingly). Slightly more complex is adding your own dynamic hook ( Post Status Transirions are great example). Even more complex is contextual hook .
|
add_action for admin_init hook with a parameter
|
wordpress
|
Right now by blog has the 'home' section where all my new posts go, and 'pages' sections which are static pages that i can edit. my question is, can i have another section that will behave like the 'home' link? for example, can i have a page called 'cars' and a section called 'cats', where i can add new posts to either section? if this is not possible, what are some workarounds? edit: i dont want the blog homepage to contains ALL stories, i want it to contain all stories under the cat category, and the 'car' page contain all the posts under 'car' category. in essence, it will be like i have 2 different blogs under a single blog
|
You can also create a custom feed and this to WP; use the function add_feed() for add a feed to wordpress and define the content inside the feed. A example for feed with the draftsa of WP you can see on this post http://wpengineer.com/424/feed-for-drafts-plugin/
|
can i create 2 blog 'feeds' within one blog
|
wordpress
|
Short Version I need to give in the absolute path of a Javascript file that is to be hooked into something. It works if I hardcode it into 'http://mywebsite.com/folder/script.js' However I prefer not to hardcode it in. I can do <code> dirname(___FILE___) </code> , which gives me this: '/home/public_html/folder/script.js' But that fails, the script isn't loaded. What's the best practice to find the absolute path (starting with 'http://')? - Long Version On this page in the Wordpress documentation relating to the tinyMCE plugin creation, I found this: <code> // Load the TinyMCE plugin : editor_plugin.js (wp2.5) function add_myplugin_tinymce_plugin($plugin_array) { $plugin_array['myplugin'] = URLPATH.'tinymce/editor_plugin.js'; return $plugin_array; } </code> There's a note at the bottom saying: Note: when using the mce_external_plugins filter, the url should point to the actual plugin file, as in the example above. A bit higher in the documentation they say mce_external_plugins: passes in/out an associative php array 'plugin_name' => 'plugin_url'. The url should be absolute and on the same domain as your WordPress installation. I am completely puzzled because I can't find any information about 'URLPATH' which is used in their example. I don't think it exists in PHP, WP or TinyMCE, but I could be wrong. Incidentally, were this to be an error in the WP documentation, what would I replace URLPATH with to make it work?
|
Assuming your resource is included in your Plugin: <code> plugins_url() </code> is the URL to <code> \wp-content\plugins\ </code> ( Codex ref ) So if you have a .js file in <code> \wp-content\plugins\plugin-slug\file.js </code> : <code> <?php echo plugins_url() . '\plugin-slug\file.js'; ?> </code> BUT WAIT!! If your purpose is actually to load a javascript file, you actually want to enqueue that file, using <code> wp_enqueue_script() </code> , hooked into the <code> wp_enqueue_scripts </code> hook. And <code> wp_enqueue_script() </code> uses the filepath rather than the URL , so you could use <code> dirname(___FILE___) </code> if that' what you're comfortable with.
|
How can I find the 'public absolute' path of a file?
|
wordpress
|
I am on a (non-hosted) server...what level of permissions should my plugins folder (and everything inside of it) be set to? I seem to be having issues deleting or moving files inside of this folder...
|
Typically, the plugin folder only needs to be writable by your user account, but this could potentially vary depending on what user your web server is running as. For example, most of my installs have the plugins folder set to 755, but this is because Apache is running as the same user as the owner of the folder. Check who your server is running as if you think the permissions are correct. For more info on permissions and WordPress hardening in general, check out http://codex.wordpress.org/Hardening_WordPress#File_permissions
|
What level of permissions should the plugins folder be set to?
|
wordpress
|
I am displaying the wordpress posts on the index page with: <code> <?php the_excerpt(); ?> </code> In my functions.php file I have following code: <code> add_filter('excerpt_length', 'my_excerpt_length'); function my_excerpt_length($length) { return 30; } </code> This works fine but it shows <code> [...] </code> at the end of excerpt. I want to remove these <code> [ </code> and <code> ] </code> and instead I want to show only three dots <code> ... </code> . How can i do that? Thanks.
|
Use the <code> excerpt_more </code> filter hook: <code> function mytheme_excerpt_more( $text ) { $text = '...'; return $text; } add_filter( 'excerpt_more', 'mytheme_excerpt_more' ); </code>
|
Remove [ and ] from excerpt
|
wordpress
|
I am using PowerPress for my podcast support. I am working on some things on the web site and I swear, I set the enclosure, verify via phpMyAdmin that it is there. I don't touch anything on the site and check minutes later and the enclosure is missing. Huh?!? Does anyone have any ideas where to start looking? I am running my own server on Ubuntu 11.x. I am using Apache for my web server.
|
Okay, looks like this is a "feature" .
|
Enclosures being deleted "automatically"
|
wordpress
|
This is the manual page and this is the code . But I'm still struggling to understand how to use this function. Perhaps I am using it right, but something I can't think of is wrong. But more surely, I need to know what this means: <code> callback </code> - I assumed this was the name of the Widget class. Am I right? <code> widget id </code> , what is this? <code> id base </code> , what is it? Whether to check in <code> wp_inactive_widgets </code> . What is <code> wp_inactive_widgets </code> ? I really feel like the manual isn't explaining these things. Here's something that I put together which does not work: <code> function cbs_register_widgets() { register_widget( 'cbs_map_widget' ); } add_action( 'widgets_init', 'cbs_register_widgets' ); function cbs_enqueue_resources() { if ( is_active_widget( 'cbs_map_widget' ) ) { wp_enqueue_script( 'fancybox-js', plugins_url( '/fancybox/jquery.fancybox-1.3.4.pack.js', __FILE__), array( 'jquery' ), '1.3.4' ); wp_enqueue_style( 'fancybox-css', plugins_url( '/fancybox/jquery.fancybox-1.3.4.js', __FILE__ ), '', '1.3.4' ); } wp_enqueue_script( 'cbs-widgets-js', plugins_url( '/js/cbs-widgets.js', __FILE__ ), array( 'jquery' ) ); wp_enqueue_style( 'cbs-widgets-css', plugins_url( '/css/style.css', __FILE__ ) ); } add_action( 'template_redirect', 'cbs_enqueue_resources' ); </code> The enqueueing in itself works, it is the <code> is_active_widget </code> that doesn't work. The widget itself works too, and displays correctly. Just the fancybox js that's missing. Here's my implementation of one of the answers I got below, it does not work either: <code> class cbs_map_widget extends WP_Widget { function cbs_map_widget() { $ops = array('classname' => 'cbs-map-widget', 'description' => 'Visar en karta över Chalmers område där lokaler som används av Sällskapet har markerats.'); $this->WP_Widget('cbs-map-widget', 'CBS kartwidget', $ops); } function widget($args, $instance) { extract($args); echo $before_widget; echo '<div class="overline">text</div>'; echo '<a href="#" class="cbs-map-widget"><img src="' . plugins_url( '/images/map.png', __FILE__ ) . '" title="" /></a>'; echo $after_widget; add_action('wp_enqueue_scripts', array(&$this, 'js')); } function js() { if ( is_active_widget(false, false, $this->id_base, true) ) { wp_enqueue_script( 'fancybox-js', plugins_url( '/fancybox/jquery.fancybox-1.3.4.pack.js', __FILE__), array( 'jquery' ), '1.3.4' ); wp_enqueue_style( 'fancybox-css', plugins_url( '/fancybox/jquery.fancybox-1.3.4.js', __FILE__ ), '', '1.3.4' ); } } } </code>
|
You should make the check inside the widget class, unless you don't have a choice. The example in the codex is pretty much what you're looking for: <code> class cbs_map_widget extends WP_Widget{ function cbs_map_widget(){ $this->WP_Widget('cbsmaps', __('Widget Name'), array('classname' => 'cbsmaps', 'description' => __('whatever'))); ... add_action('wp_enqueue_scripts', array(&$this, 'js')); } function js(){ if ( is_active_widget(false, false, $this->id_base, true) ) { // enqueue your scripts; } } ... } </code> The <code> $widget_id </code> parameter is useful when you need to include your scripts only for a specific widget instance. For example when you have two <code> cbs_map_widget </code> widgets and want to include custom javascript for each of them. The <code> $callback </code> argument is useful when you need to do the check outside the widget class (like you did above), but try to avoid it if you can do your check inside the class. The other arguments are pretty much self explanatory (id_base is basically a "widget class indentifier", and the <code> $skip_inactive </code> is whether to check inactive widgets as well - should be true because I don't think you want to do that)... Edit: How to find the <code> $widget_id </code> (A widget instance ID) Again, you don't need this unless you specifically want to check if a certain widget instance is active. Personally I use this method because I can access the instance options too: <code> ... function js(){ // we need to process all instances because this function gets to run only once $widget_settings = get_option($this->option_name); foreach((array)$widget_settings as $instance => $options){ // identify instance $id = "{$this->id_base}-{$instance}"; // check if it's our instance if(!is_active_widget(false, $id, $this->id_base)) continue; // not active // instance is active // access the widget instance options here, you may need them to do your checks if($options['yourwidgetoption']) { // do stuff } } } ... </code>
|
How to use is_active_widget?
|
wordpress
|
What i'm trying to do here is to modify the existing wp-postratings plugin. The function to display the ratings is: <code> <?php if(function_exists('the_ratings')) { the_ratings(); } ?> </code> However, the above code displays the ratings on every post. What would be the conditional statement to add such that if a post has a custom field with name/value as ratings/yes This way, based on the conditional statement, the ratings would be displayed only on posts where the custom field has the ratings/yes added.
|
<code> <?php // get the value of our custom field $meta_value = get_post_meta($post->ID, 'ratings', true); // if it's not empty and the_ratings function exists: if( !empty($meta_value) && function_exists('the_ratings') ){ the_ratings(); } </code>
|
How to display a feature only if custom field value is set?
|
wordpress
|
No matter what I try I can't seem to get the code snippets to work that will display the number of followers of Twitter. I tried various ones as the Plugin I'm using is not showing the Twitter number at all, so I need to look for alternatives. When I tried this snippet , for example, I got the following error message: http://pastebin.com/iif9g35a Anybody any idea what's going wrong here? I think it's strange that the "Suscribers to text" plugin doesn't display the number of followres to begin with - otherwise I wouldn't have to look for alternatives.
|
Ouch, that snippet is ancient (I am kinda its author, more precisely adapted to twitter from other snippet). I would strongly consider using some newer solution. I had later made newer and written from scratch version, try it http://www.rarst.net/script/twitter-counts-wordpress/
|
Show Twitter followers count snippets don't work
|
wordpress
|
I had a site that was hacked (had Arab words on the index.php), and all files deleted, but database still there. I used Fantastico to install a clean release of WP 3.1, and I still some something suspicious. In lower right side of Firefox it says "Read www.clickcoupon.me". With FireBug and PageSpeed, I can see it's opening: http://www.clickcoupon.me/plugin/sources/clickcoupon.js and http://clickcoupon.me/plugin/sources/jquery-1.3.2_nd.js which both look extremely suspicious. These are not part of the standard WordPress are they? The site is http://cpanelvideocenter.com . As of the time I'm posting this, it is a default install from Fantastico. Unless they hacked my hosting company as well, I don't see how these files could be involved.
|
Found it! It was happening in FireFox but not Chrome. I looked at all my FireFox Extensions, and found "Browser Enhancements 1.0" and "Browser Coupons 1.0" http://www.webenhancements.me/ . The other URL was searchdock.me, and was reported as a "threat" here: http://www.threatexpert.com/report.aspx?md5=af6cc99d717c0daef65a9dafd6c45db7 I'm not sure when I installed these or why, but I don't think they were related to the hacking incident. It was just that when i was analyzing the hack incident carefully, I discovered these "extras" that probably didn't need to be on my machine anyway.
|
Suspicious URLs being loaded after hack and restore
|
wordpress
|
I'm trying to use a jquery toggle shortcode in a theme template. The shortcode goes like this: <code> [sws_toggle3 title="Title"]You can now see the displayed text.[/sws_toggle3] </code> I want to pull posts from a specific category and use the toggle to display them in the page. This is what my theme template currently has: <code> <?php $wp_query->query('cat=11&paged=' . $paged); while ($wp_query->have_posts()) : $wp_query->the_post();?> <li id="post-<?php the_ID(); ?>"> <h2><a class="title" href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <div class="post"> <?php the_content(); ?> </div> <div class="clear"></div> </li> <?php endwhile; ?> </code> With the output being something like: <code> [sws_toggle3 title="<?php the_title(); ?>"]<?php the_content(); ?>[/sws_toggle3] </code> Is this possible? Any help would be much appreciated. Thanks
|
You should be able to use <code> do_shortcode() </code> , with a few modifications: <code> <?php echo do_shortcode( '[sws_toggle3 title="' . get_the_title() . '"]' . get_the_content() . '[/sws_toggle3]' ); ?> </code> EDIT If you need to maintain the formatting of <code> the_content() </code> , simply pass <code> get_the_content() </code> through the appropriate filter: <code> <?php $content = get_the_content(); $content = apply_filters( 'the_content', $content ); echo do_shortcode( '[sws_toggle3 title="' . get_the_title() . '"]' . $content . '[/sws_toggle3]' ); ?> </code>
|
Populating shortcode values dynamically in theme template
|
wordpress
|
I have a list of 350 or so terms that I am trying to set to a post. Here's my code: <code> add_action('init', 'add_cities_to_story'); function add_cities_to_story() { $cities_list = get_term_children('115', 'location'); // MA wp_set_object_terms('632', $cities_list, 'location'); } </code> The trouble is that it appears to timeout about 3/4 of the way through the list. Also, any ideas how to bulk remove the tags from a post? :)
|
Dealing with terms is known to be very heavy operation. The common tweak recommended is to use <code> wp_defer_term_counting() </code> to temporarily disable updating of terms count (which is stored persistently in database and so must be updated when you change terms).
|
wp_set_object_terms timing out?
|
wordpress
|
I have registered custom post type Article in my template using register_post_type function. and i also having taxonomy category for this article posts. Here i want to filter the posts under particular category. using query post How can i do this Thanks in advance !
|
If you read http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters in detail it outlines everything you need. Take a look at the following code sample taken from the codex. It should help you :) <code> $args = array( 'post_type' => 'Article', /* This is where you should put your Post Type */ 'tax_query' => array( array( 'taxonomy' => 'people', 'field' => 'slug', 'terms' => 'bob' ) ) ); $query = new WP_Query( $args ); </code> Please note that this query does NOT account for paginated data.
|
how can i get posts from custom post type particular taxonomy category
|
wordpress
|
I have a query like this; <code> <?php $temp_query = $wp_query; ?> <?php foreach(get_the_category() as $category) { $cat = $category->cat_ID; } query_posts('orderby=date&cat=' . $cat . '&order=desc&posts_per_page=-1'); ?> </code> It grabs all the posts from the current category. What i then do with this information is create a list of all the thumbnails associated with those posts. What i would like to do is highlight in some way, the current post. (through a class or something), something that is obviously done automatically normally. Thanks Alex
|
save the main current post id into a variable and compare it in the loop with the current post id; example: <code> <?php $this_post = $post->ID; ?> <?php $temp_query = $wp_query; ?> <?php foreach(get_the_category() as $category) { $cat = $category->cat_ID; } query_posts('orderby=date&cat=' . $cat . '&order=desc&posts_per_page=-1'); while( have_posts() ) : ?> <span<?php if( $this_post == $post->ID ) { echo ' class="current"'; } ?>> /*output of your posts here*/ </span> <?php endwhile; ?> </code>
|
Add class to current post in query_post
|
wordpress
|
I would like to show a plugin in a specific page's sidebar only. For Example: I have the pages like .. home about us sub page 1 sub page 2 sub page 3 sub page 4 UPdate: i want to show, plugin 1 in sub page 1 and sub page 4 only and not to all other pages.i tried <code> is_page('sub page 1','sub page 4') </code> but not working :(.please help me.
|
The way to use is_page with multiple pages is as follows: <code> is_page(array(42,'about-me','Contact')); </code> You have to use the <code> array </code> keyword
|
How to show my sidebar in specific page only?
|
wordpress
|
I am looking for a gallery plugin that will allow users to comment on each individual photo as opposed to the entire gallery. I have tried Lazyest Gallery ; however, it doesn't seem to be integrating well with another plugin I have installed called Facebook Comments for WordPress which I'm using to replace the default WordPress commenting system. Does such a plugin exist? Or perhaps there is a better solution? What do you guys think?
|
Usually your Wordpress theme will have an "attachments.php" page that would have a "single view" of the image in question. For an example: http://twentyelevenphoto.wordpress.com/2011/05/25/an-image/mcm_5276/ That gives you a "single" view of your image as well as comments. To test to see if your site has this, create a gallery and make sure to check "Attachment Page" when setting the Link Thumbnail to option. Then view the post, click on the gallery image and it should take you to that images single page.
|
Any gallery plugins that allow commenting on single images?
|
wordpress
|
I am trying to delete some plugins via the Wordpress admin panel. Sometimes it deletes the plugin quite quickly, but other times it hangs. I have access to my server, is there anything I can do to speed the performance up?
|
Is it a shared hosting? Try rising the php memory limit. That will make wordpress admin go faster and your blog!
|
Wordpress FTP via admin panel slow
|
wordpress
|
Here's my setup. I have a Multisite instance running at http://example.com, and I want to do development and staging. Moving an existing Multisite instance of WP onto localhost is a nightmare, so I'm going to do dev on a staging location instead. I set up http://staging.example.com to point to the /public_html/staging/ directory of the hosting account, and copied all of the WP files from my root into the /staging/ directory. I also copied the database files (SQL dump, imported the tables into a new database), and changed the wp-config.php file to point to the new database. After running SQL to change the database records, I also change this one line in the wp-config.php file: <code> /** Turning on WordPress MU, new in 3.0 */ define( 'MULTISITE', true ); define( 'SUBDOMAIN_INSTALL', false ); $base = '/'; define( 'DOMAIN_CURRENT_SITE', 'example.com' ); // <- I change this line define( 'PATH_CURRENT_SITE', '/' ); define( 'SITE_ID_CURRENT_SITE', 1 ); define( 'BLOG_ID_CURRENT_SITE', 1 ); </code> Changed to: <code> define( 'DOMAIN_CURRENT_SITE', 'staging.example.com' ); // <- now changed </code> When I load up http://staging.example.com, I get... <code> Error establishing database connection </code> ! I've checked and triple checked the username and password, made sure that the user has all privileges on the new staging database, and I've left the DBHOST as 'localhost' (although changing it to staging.example.com didn't help, either). Why would the database connection fail? Anyone? (Thanks for your help in advance.) NB: http://example.com is working fine running on very similar db connection settings, just with a different database, so it's not an issue with the database server being down.
|
One thought - when I go to www.example.com/staging/wp-admin it automatically redirects me to www.example.com/wp-admin Could the redirect from staging.example.com to example.com/staging be conflicting with the existing install? UPDATE: looks like it could be related to .htaccess issues and complicated domain references in the database From the WP Codex: Moving WordPress Multisite Multisite is far more complicated to move, as the database itself has multiple references to the server name as well as the folder locations. The best way to move Multisite is to move the files, edit the .htaccess and wp-config.php (if the folder name containing Multisite changed), and then manually edit the database. Search for all instances of your domain name, and change them as needed. This step cannot yet be easily automated. If you're moving Multisite from one folder to another, you will need to make sure you edit the wp_blogs entries to change the folder name correctly.
|
DB connection error after copying a WordPress Multisite instance to a second location
|
wordpress
|
I want to use built-in WP media gallery. I'm trying to simply add images in one - horizontal line. I want images with original size and without any link. I'm trying to add/edit some code into wp-admin/includes/media.php but I can't get it ;/ I know I have to use size="full" and columns="0" but how to add this with shortcode as default? And I have no idea how to get rid of links under images? Am I looking in good file? If no - point me to right direction please ;)
|
UPDATE I've just submitted a core patch to add <code> link="none" </code> support to the <code> [gallery] </code> shortcode. ORIGINAL ANSWER You don't need to hack core to do what you want to do; just use the appropriate <code> [gallery] </code> shortcode parameters , e.g.: <code> [gallery columns="0" size="full"] </code> If you want to change the defaults, then use the <code> post_gallery </code> filter: <code> function mytheme_gallery_shortcode_defaults( $output, $attr ) { global $post; $attr = array( 'columns' => '0', 'size' => 'full' ); return $output; } add_filter( 'post_gallery', 'mytheme_gallery_shortcode_defaults', 10, 2 ); </code> The only way to remove the link is to clear the image link field in the Media Library, or you can do some involved code replacement . EDIT I'm somewhat guessing here, as I'm not fully familiar with filtering the gallery output. I've made a couple of modifications, including passing both variables to the callback, correcting the <code> add_filter() </code> call to accommodate both variables, and returning <code> $output </code> rather than <code> $attr </code> . EDIT 2 Okay, so it looks like, currently, the only way to override th shortcode attributes is to rewrite the entire walker. See this Trac Ticket for details. So, basically, this: <code> function mytheme_gallery_shortcode( $output, $attr ) { global $post, $wp_locale; static $instance = 0; $instance++; // Allow plugins/themes to override the default gallery template. $output = apply_filters('post_gallery', '', $attr); if ( $output != '' ) return $output; // We're trusting author input, so let's at least make sure it looks like a valid orderby statement if ( isset( $attr['orderby'] ) ) { $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] ); if ( !$attr['orderby'] ) unset( $attr['orderby'] ); } extract(shortcode_atts(array( 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'itemtag' => 'dl', 'icontag' => 'dt', 'captiontag' => 'dd', 'columns' => 0, 'size' => 'full', 'include' => '', 'exclude' => '', 'link' => 'none' ), $attr)); $id = intval($id); if ( 'RAND' == $order ) $orderby = 'none'; if ( !empty($include) ) { $include = preg_replace( '/[^0-9,]+/', '', $include ); $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); $attachments = array(); foreach ( $_attachments as $key => $val ) { $attachments[$val->ID] = $_attachments[$key]; } } elseif ( !empty($exclude) ) { $exclude = preg_replace( '/[^0-9,]+/', '', $exclude ); $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); } else { $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); } if ( empty($attachments) ) return ''; if ( is_feed() ) { $output = "\n"; foreach ( $attachments as $att_id => $attachment ) $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; return $output; } $itemtag = tag_escape($itemtag); $captiontag = tag_escape($captiontag); $columns = intval($columns); $itemwidth = $columns > 0 ? floor(100/$columns) : 100; $float = is_rtl() ? 'right' : 'left'; $selector = "gallery-{$instance}"; $gallery_style = $gallery_div = ''; if ( apply_filters( 'use_default_gallery_style', true ) ) $gallery_style = " <style type='text/css'> #{$selector} { margin: auto; } #{$selector} .gallery-item { float: {$float}; margin-top: 10px; text-align: center; width: {$itemwidth}%; } #{$selector} img { border: 2px solid #cfcfcf; } #{$selector} .gallery-caption { margin-left: 0; } </style> <!-- see gallery_shortcode() in wp-includes/media.php -->"; $size_class = sanitize_html_class( $size ); $gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>"; $output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div ); $i = 0; foreach ( $attachments as $id => $attachment ) { $image = wp_get_attachment_image( $id, $size, false ); $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false); $image_output = ( 'none' == $attr['link'] ? $image : $link ); $output .= "<{$itemtag} class='gallery-item'>"; $output .= " <{$icontag} class='gallery-icon'> $image_output </{$icontag}>"; if ( $captiontag && trim($attachment->post_excerpt) ) { $output .= " <{$captiontag} class='wp-caption-text gallery-caption'> " . wptexturize($attachment->post_excerpt) . " </{$captiontag}>"; } $output .= "</{$itemtag}>"; if ( $columns > 0 && ++$i % $columns == 0 ) $output .= '<br style="clear: both" />'; } $output .= " <br style='clear: both;' /> </div>\n"; return $output; } add_filter( 'post_gallery', 'mytheme_gallery_shortcode', 10, 2 ); </code>
|
Media gallery - inserting full size images without link
|
wordpress
|
I've added a custom post type, on the 'init' action, like so: <code> // Setup the 'Classifieds' Post Type $labels = array( 'name' => _x('Classifieds', 'post type general name'), 'singular_name' => _x('Classifieds', 'post type singular name'), 'add_new' => _x('Add New', 'classifieds'), 'add_new_item' => __('Add Classifieds Item'), 'edit_item' => __('Edit Classifieds'), 'new_item' => __('New Classifieds Item'), 'view_item' => __('View Classifieds'), 'search_items' => __('Search Classifieds'), 'not_found' => __('No classifieds found'), 'not_found_in_trash' => __('No classifieds found in Trash'), 'parent_item_colon' => '', 'menu_name' => 'Classifieds' ); // Configure the 'Classifieds' post type $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array("slug" => "classifieds"), 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => true, 'menu_position' => 5, 'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'comments', add_theme_support( 'post-formats', array('aside', 'gallery') ) ), 'taxonomies' => array('category', 'post_tag') ); // Add the 'Classifieds' post type register_post_type('classifieds', $args); </code> My problem is when I want to insert a custom post programatically, like so: <code> $cat_ID = get_cat_ID( 'calendar' ); $data = array( 'post_content' => stripslashes($output), 'post_title' => stripslashes($title), 'post_date' => date('Y-m-d H:i:s'), 'post_category' => array($cat_ID), 'post_status' => $statusPost, 'post_author' => $post_author ); $post_id = wp_insert_post($data); </code> The custom post is displayed under the Admin's generic 'Post' type post, not under the custom post type of 'Classifieds' which I created above. Does anyone have any suggestions?
|
you need to specify the post_type in your <code> $data </code> array : <code> $data = array( 'post_type' => 'classifieds', 'post_content' => stripslashes($output), 'post_title' => stripslashes($title), 'post_date' => date('Y-m-d H:i:s'), 'post_category' => array($cat_ID), 'post_status' => $statusPost, 'post_author' => $post_author ); </code>
|
Programmmatically adding a Custom Post
|
wordpress
|
I have added several new fields to the user profile (areacode, company, affiliate, etc) and I would like to present a way to search on these fields. Please point me in the right direction.
|
I just had a project where i needed to create a search by user meta form and i ended up creating a shortcode for it, i just altered it a bit to show you how to make it work with your fields, so just paste this code inside your theme's functions.php file or a plugin file: <code> add_shortcode('user_search','My_User_search'); function My_User_search($atts = null){ $out = user_search_form(); if (isset($_GET['user_search']) && $_GET['user_search'] == "search_users" && isset($_GET['search_by'])){ global $wpdb; $metakey = $_GET['search_by']; $args = array('meta_key' => $metakey); if (isset($_GET['s_value'])){ $metavalue = $_GET['s_value']; $args['meta_value'] = $metavalue; } $search_users = get_users($args); $out .= '<div class="user_search_results">'; if (count($search_users) >0){ // here we loop over the users found and return whatever you want eg: $out .= '<ul>'; foreach ($search_users as $user) { $out .= '<li>' . $user->user_email . '</li>'; } $out .= '</ul>'; }else{ $out .= 'No users found, try searching for something else.'; } $out .= '</div>'; } return $out; } //function to display user search form function user_search_form(){ $metavalue = $metakey = ''; if (isset($_GET['search_by'])){ $metakey = $_GET['search_by']; } if (isset($_GET['s_value'])){ $metavalue = $_GET['s_value']; } $re = '<div class="user_search"><form action="" name="user_s" method="get"> <label for="search_by">Search by:</label> <select id="search_by" name="search_by">'; if ($metakey != ''){ $re.= '"'; $re.= ($metakey == "nickname") ? '<option value="nickname" selected="selected">Name</option>': '<option value="nickname">Name</option>'; $re.= ($metakey == "areacode") ? '<option value="areacode" selected="selected">area code</option>': '<option value="areacode">area code</option>'; $re.= ($metakey == "company") ? '<option value="company" selected="selected">company</option>': '<option value="company">area code</option>'; $re.= ($metakey == "affiliate") ? '<option value="affiliate" selected="selected">affiliate</option>': '<option value="affiliate">area code</option>'; }else{ $re .= ' <option value="nickname">Name</option> <option value="areacode">area code</option> <option value="company">company</option> <option value="affiliate">affiliate</option>'; } $re .= ' </select> <label for="s_value">Value:</label> <input id="s_value" name="s_value" type="text" value="'.$metavalue.'"/> <input name="user_search" id="user_search" type="hidden" value="search_users"/> <input id="submit" type="submit" value="Search" /> </form></div>'; return $re; } </code> Usage: simply create a page or a post and enter <code> [user_search] </code>
|
How to search for users based on added user metadata
|
wordpress
|
I've just started developing a WP plugin, and i've been reading some code from other plugins as a way to get started. I've seen a couple of plugins that wrap all or some of their functions in the following code: <code> if(!function_exists('my_function')) { function my_function() { // a cool function } } </code> Is it considered good practice to wrap all functions in this code to avoid naming conflicts with other plugins? Thanks
|
I would not do this to prevent naming conflicts: if another unrelated plugin uses the same name, it's unlikely that they will provide the same functionality and your plugin can continue as normal. There you want to fail early, not sneaky later on. Or prevent the conflict with a better prefix of course :-) The only reason to do this is to create a pluggable function , a separate piece of functionality that can be implemented in a different way by an additional plugin. You can see this in the WordPress core code: functions like wp_mail() are pluggable so you can use a completely custom mailing system. You also see this in themes that are likely to get child themes. The default themes, Twemty Eleven and Twenty Ten before it, are good examples of this. Child themes can define functions with the same name, and they will be used instead. Personally, I don't really like this approach to provide hooks for other code. They make it harder to figure out what code will be called (an my IDE code completion gets confused). I try to provide all extension points via "classic" actions and filters.
|
When to check if a function exists
|
wordpress
|
I have a custom post with a lot of meta boxes. I recently tried to add some dynamic metaboxes, using this question: stackexchange-url ("Create more Meta Boxes as needed") I managed to get the metaboxes to add nicely, the jquery works, everything works except the save_post action - the "Reviews" save nicely, but the "Screenings" don't. What have I done wrong in my code? I'm sure it must be something very simple that I'm overlooking, perhaps with the nonces? Edit : I know I can do all of this with one <code> save_post </code> , and that works if I only have 1 of these dynamic metaboxes, but if I add a second (or more) dynamic metabox section, that data doesn't save. Edit : If necessary, I can post my entire custom-posts.php function file to pastebin or something, but I have just included what I think is the relevant snippet here for brevity Edit : Updated code... <code> <?php add_action('save_post', 'save_postdata'); // saves post data from another function earlier on add_action('save_post', 'save_postdata_dynamic_reviews_metabox' ); add_meta_box("film-reviews", "Reviews", "print_dynamic_reviews_metabox", "film", "normal", "low"); add_action('save_post', 'save_postdata_dynamic_screenings_metabox' ); add_meta_box("film-screenings", "Screenings", "print_dynamic_screenings_metabox", "film", "normal", "low"); /* Prints the box content */ function print_dynamic_reviews_metabox() { global $post; // Use nonce for verification echo '<input type="hidden" name="reviews_noncename" id="reviews_noncename" value="' . wp_create_nonce( 'reviews-nonce' ) . '" />'; echo '<div id="meta_inner-reviews">'; echo '<ol id="reviews-meta">'; $reviews = get_post_meta($post->ID,'reviews',true); //get any previously saved meta as an array so we can display it // print_r($reviews); $c = 0; if( is_array($reviews) ) { foreach($reviews as $review ) { if (isset($review['review-name']) || isset($review['review-link']) ) { echo ' <li><span class="remove-review" title="Delete">Remove</span> <label><strong>Review Name/Title:</strong> <input type="text" class="meta-review-name saveddata" name="reviews['.$c.'][review-name]" value="'.$review['review-name'].'" /></label> <label><strong>Review URL:</strong> (don't forget the http://) <input type="text" class="meta-review-url saveddata" name="reviews['.$c.'][review-url]" value="'.$review['review-url'].'" /></label>'; echo '<span class="remove-review" title="Delete">Remove</span></li>'; $c = $c +1; } // ends if isset $award[album] } // ends foreach } // ends if (is_array) echo '</ol>'; echo '<span class="add-review">Add New Review</span>'; ?> <script> var $ =jQuery.noConflict(); $(document).ready(function() { var count = <?php echo $c; ?>; $(".add-review").click(function() { count = count + 1; $('#reviews-meta').append('<li><span class="remove-review" title="Delete">Remove</span> <label><strong>Review Name/Title:</strong> <input type="text" class="meta-review-name" name="reviews['+count+'][review-name]" value="" /></label> <label><strong>Review URL:</strong> (don't forget the http://) <input type="text" class="meta-review-url" name="reviews['+count+'][review-url]" value="" /></label></li> <span class="remove-review" title="Delete">Remove</span>'); return false; }); $(".remove-review").live('click', function() { $(this).parent().remove(); }); }); </script> <?php echo '</div>'; // ends div#meta_inner } // ends function print_dynamic_reviews_metabox() function save_postdata_dynamic_reviews_metabox( $post_id ) { // 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; } // Check permissions if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id )) { return $post_id; }} elseif ( !current_user_can( 'edit_post', $post_id )) { return $post_id;} // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (isset($_POST['reviews_noncename'])){ if ( !wp_verify_nonce( $_POST['reviews_noncename'], 'reviews-nonce' ) ) return; }else{return;} // OK, we're authenticated: we need to find and save the data $reviews = $_POST['reviews']; update_post_meta($post_id,'reviews',$reviews); } // ends function save_postdata_dynamic_reviews_metabox /* Prints the box content */ function print_dynamic_screenings_metabox() { global $post; // Use nonce for verification echo '<input type="hidden" name="screenings_noncename" id="screenings_noncename" value="' . wp_create_nonce( 'screenings-nonce' ) . '" />'; echo '<div id="meta_inner-screenings">'; echo '<ol id="screenings-meta">'; $screenings= get_post_meta($post->ID,'screenings',true); //get any previously saved meta as an array so we can display it // print_r($screenings); $c = 0; if( is_array($screenings) ) { foreach($screenings as $screening ) { if (isset($screening['screening-festival-name']) || isset($screening['screening-festival-date']) ) { echo ' <li><span class="remove-screening" title="Delete">Remove</span> <label><strong>Festival Name:</strong> <input type="text" class="meta-screening-festival-name saveddata" name="screenings['.$c.'][screening-festival-name]" value="'.$screening['screening-festival-name'].'" /></label> <label><strong>Festival Date:</strong> <input type="text" class="meta-screening-festival-date saveddata" name="screenings['.$c.'][screening-festival-date]" value="'.$screening['screening-festival-date'].'" /></label>'; echo '<span class="remove-screening" title="Delete">Remove</span></li>'; $c = $c +1; } // ends if isset $award[album] } // ends foreach } // ends if (is_array) echo '</ol>'; echo '<span class="add-screening">Add New Screening</span>'; ?> <script> var $ =jQuery.noConflict(); $(document).ready(function() { var count = <?php echo $c; ?>; $(".add-screening").click(function() { count = count + 1; $('#screenings-meta').append('<li><span class="remove-screening" title="Delete">Remove</span> <label><strong>Festival Name:</strong> <input type="text" class="meta-screening-festival-name" name="screenings['+count+'][screening-festival-name]" value="" /></label> <label><strong>Festival Date:</strong> <input type="text" class="meta-screening-festival-date" name="screenings['+count+'][screening-festival-date]" value="" /></label> <span class="remove-screening" title="Delete">Remove</span>'); return false; }); $(".remove-screening").live('click', function() { $(this).parent().remove(); }); }); </script> <?php echo '</div>'; // ends div#meta_inner } // ends function print_dynamic_screenings_metabox() function save_postdata_dynamic_screenings_metabox( $post_id ) { // 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; } // Check permissions if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id )) { return $post_id; }} elseif ( !current_user_can( 'edit_post', $post_id )) { return $post_id;} // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (isset($_POST['screenings_noncename'])){ if ( !wp_verify_nonce( $_POST['screenings_noncename'], 'screenings-nonce' ) ) return; }else{return;} // OK, we're authenticated: we need to find and save the data $screenings= $_POST['screenings']; update_post_meta($post_id,'screenings',$screenings); } // ends function save_postdata_dynamic_screenings_metabox ?> </code>
|
Following are the issues that were preventing from the meta values to be saved in both of your save functions. 1. Incorrect post_type checking. You are checking post type to be of 'page' in your save function where as your meta boxes are being displayed on your custom post type of 'film'. Your code: <code> if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id )) { return $post_id; }} </code> It should be: <code> if ( 'film' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id )) { return $post_id; }} </code> 2. Incorrect nonce field name. As @tollmanz pointed out you are checking incorrect field names when checking nonces. The field name in save functions should match the input field name in print meta box functions. Your code: <code> if (isset($_POST['reviews-nonce'])){ if ( !wp_verify_nonce( $_POST['reviews-nonce'], 'reviews-nonce' ) ) return; }else{return;} </code> It should be: <code> if (isset($_POST['reviews_noncename'])){ if ( !wp_verify_nonce( $_POST['reviews_noncename'], 'reviews-nonce' ) ) return; }else{return;} </code> For screening nonce your code: <code> if (isset($_POST['screenings-nonce'])){ if ( !wp_verify_nonce( $_POST['screenings-nonce'], 'screenings-nonce' ) ) return; }else{return;} </code> It should be: <code> if (isset($_POST['screenings_noncename'])){ if ( !wp_verify_nonce( $_POST['screenings_noncename'], 'screenings-nonce' ) ) return; }else{return;} </code> 3. Incorrectly saving the meta values. You were using update_post_meta to store the meta values. 4. Inoccrectly getting meta values. You were using third parameter in your get_post_meta calls which is to specify to only fetch single meta value, were in your case you need to fetch all meta values. Your code: <code> $reviews = get_post_meta($post->ID,'reviews',true); //get any previously saved meta as an array so we can display it </code> It should be: <code> $reviews = get_post_meta($post->ID,'reviews'); //get any previously saved meta as an array so we can display it </code> Your code for screenings: <code> $reviews = get_post_meta($post->ID,'screenings',true); //get any previously saved meta as an array so we can display it </code> It should be: <code> $reviews = get_post_meta($post->ID,'screenings',true); //get any previously saved meta as an array so we can display it </code> Below is the correct code. The code below should work for you as I have tested it and it worked fine. If it doesn't work for some reason I will need to look at your complete code. <code> add_action('save_post', 'save_postdata_dynamic_reviews_metabox' ); add_meta_box("film-reviews", "Reviews", "print_dynamic_reviews_metabox", "film", "normal", "low"); add_action('save_post', 'save_postdata_dynamic_screenings_metabox' ); add_meta_box("film-screenings", "Reviews", "print_dynamic_screenings_metabox", "film", "normal", "low"); /* Prints the box content */ function print_dynamic_reviews_metabox() { global $post; // Use nonce for verification echo '<input type="hidden" name="reviews_noncename" id="reviews_noncename" value="' . wp_create_nonce( 'reviews-nonce' ) . '" />'; echo '<div id="meta_inner-reviews">'; echo '<ol id="reviews-meta">'; $reviews = get_post_meta($post->ID,'reviews'); //get any previously saved meta as an array so we can display it // print_r($reviews); $c = 0; if( is_array($reviews) ) { foreach($reviews as $review ) { if (isset($review['review-name']) || isset($review['review-link']) ) { echo ' <li><span class="remove-review" title="Delete">Remove</span> <label><strong>Review Name/Title:</strong> <input type="text" class="meta-review-name saveddata" name="reviews['.$c.'][review-name]" value="'.$review['review-name'].'" /></label> <label><strong>Review URL:</strong> (don't forget the http://) <input type="text" class="meta-review-url saveddata" name="reviews['.$c.'][review-url]" value="'.$review['review-url'].'" /></label>'; echo '<span class="remove-review" title="Delete">Remove</span></li>'; $c = $c +1; } // ends if isset $award[album] } // ends foreach } // ends if (is_array) echo '</ol>'; echo '<span class="add-review">Add New Review</span>'; ?> <script> var $ =jQuery.noConflict(); $(document).ready(function() { var count = <?php echo $c; ?>; $(".add-review").click(function() { count = count + 1; $('#reviews-meta').append('<li><span class="remove-review" title="Delete">Remove</span> <label><strong>Review Name/Title:</strong> <input type="text" class="meta-review-name" name="reviews['+count+'][review-name]" value="" /></label> <label><strong>Review URL:</strong> (don't forget the http://) <input type="text" class="meta-review-url" name="reviews['+count+'][review-url]" value="" /></label></li> <span class="remove-review" title="Delete">Remove</span>'); return false; }); $(".remove-review").live('click', function() { $(this).parent().remove(); }); }); </script> <?php echo '</div>'; // ends div#meta_inner } // ends function print_dynamic_reviews_metabox() function save_postdata_dynamic_reviews_metabox( $post_id ) { // 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; } // Check permissions if ( 'film' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id )) { return $post_id; }} elseif ( !current_user_can( 'edit_post', $post_id )) { return $post_id;} // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (isset($_POST['reviews_noncename'])){ if ( !wp_verify_nonce( $_POST['reviews_noncename'], 'reviews-nonce' ) ) return; }else{return;} delete_post_meta( $post_id, 'reviews' ); // OK, we're authenticated: we need to find and save the data $reviews = $_POST['reviews']; foreach ( $reviews as $review ) { add_post_meta($post_id,'reviews',$review); } } // ends function save_postdata_dynamic_reviews_metabox /* Prints the box content */ function print_dynamic_screenings_metabox() { global $post; // Use nonce for verification echo '<input type="hidden" name="screenings_noncename" id="screenings_noncename" value="' . wp_create_nonce( 'screenings-nonce' ) . '" />'; echo '<div id="meta_inner-screenings">'; echo '<ol id="screenings-meta">'; $reviews = get_post_meta($post->ID,'screenings'); //get any previously saved meta as an array so we can display it // print_r($reviews); $c = 0; if( is_array($screenings) ) { foreach($screenings as $screening ) { if (isset($screening['screening-festival-name']) || isset($screening['screening-festival-date']) ) { echo ' <li><span class="remove-screening" title="Delete">Remove</span> <label><strong>Festival Name:</strong> <input type="text" class="meta-screening-festival-name saveddata" name="screenings['.$c.'][screening-festival-name]" value="'.$screening['screening-festival-name'].'" /></label> <label><strong>Festival Date:</strong> <input type="text" class="meta-screening-festival-date saveddata" name="screenings['.$c.'][screening-festival-date]" value="'.$screening['screening-festival-date'].'" /></label>'; echo '<span class="remove-screening" title="Delete">Remove</span></li>'; $c = $c +1; } // ends if isset $award[album] } // ends foreach } // ends if (is_array) echo '</ol>'; echo '<span class="add-screening">Add New Screening</span>'; ?> <script> var $ =jQuery.noConflict(); $(document).ready(function() { var count = <?php echo $c; ?>; $(".add-screening").click(function() { count = count + 1; $('#screenings-meta').append('<li><span class="remove-screening" title="Delete">Remove</span> <label><strong>Festival Name:</strong> <input type="text" class="meta-screening-festival-name" name="screenings['+count+'][screening-festival-name]" value="" /></label> <label><strong>Festival Date:</strong> <input type="text" class="meta-screening-festival-date" name="screenings['+count+'][screening-festival-date]" value="" /></label> <span class="remove-screening" title="Delete">Remove</span>'); return false; }); $(".remove-screening").live('click', function() { $(this).parent().remove(); }); }); </script> <?php echo '</div>'; // ends div#meta_inner } // ends function print_dynamic_screenings_metabox() function save_postdata_dynamic_screenings_metabox( $post_id ) { // 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; } // Check permissions if ( 'film' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id )) { return $post_id; }} elseif ( !current_user_can( 'edit_post', $post_id )) { return $post_id;} // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (isset($_POST['screenings_noncename'])){ if ( !wp_verify_nonce( $_POST['screenings_noncename'], 'screenings-nonce' ) ) return; }else{return;} delete_post_meta( $post_id, 'screenings' ); // OK, we're authenticated: we need to find and save the data $screenings = $_POST['screenings']; foreach ( $screenings as $screening ) { add_post_meta($post_id,'screenings',$screening); } } // ends function save_postdata_dynamic_reviews_metabox </code>
|
Why won't my metabox data save?
|
wordpress
|
I am working on a site that has the option of using Event Expresso Event Manager Pro The events part of the site is quite complicated, and needs to have - a calendar - a registration page - 'buy tickets' functionality with both Paypal and http://www.authorize.net/ - email confirmations I haven't worked a lot with event plugins, can anyone recommend one of the above plugins over the other? It sounds like there might be quite a lot of customization required, so I guess part of this question is, "Which is the easiest to customize?"
|
I know this does not meet your requirement of supporting Paypal and Authorize.net, but it does support Eventbrite, so it may be worth looking into: The Events Calendar
|
Event Management plugin
|
wordpress
|
So hard to find this info... I'd like to know a way to find out if there are pages. Something like: <code> if (has_pages()) { /* do something */ } </code> I can't find a reference to any similar function... how might one go about finding out if there are pages. In case yr wondering I'd like to only show a pages menu if there are pages.
|
You could also use <code> wp_list_pages() </code> ( Codex ref ): <code> <?php $has_pages = wp_list_pages( array( 'echo' => false ) ); if ( $has_pages ) { // There are pages; do something } ?> </code>
|
Check if has pages?
|
wordpress
|
I'm building a database of cities as a part of a "location" taxonomy. In order for the terms to render, as far as I've found, they need to have some type of content associated with them. My work-around is to create a "placeholder" post, assign it to the respective terms, then move it to the trash. So, first, if you have any suggestions for a better way to get the terms to display without yet having content associated with them, please let me know! Otherwise, what's the best way to bulk assign terms to a custom post?
|
With functions like get_terms, there is an argument hide_empty that will allow terms without associated posts to be shown. Set hide_empty to 0 and you will see your terms.
|
How do I assign a custom post to all terms in a custom taxonomy?
|
wordpress
|
I want to add "print" button to print simple reports in a plugin. The basic idea I have is to generate a printer friendly html page and redirect user to that page where he/she can use browser's print functionality. How good is that solution? Is there any other alternative?
|
check out WP Print Friendly plugin which extends WordPress template system to support printer-friendly templates. Works with permalink structures to support nice URLs.
|
"Print to printer" functionality in a plugin
|
wordpress
|
So I have created a custom post type with custom values and customize my custom post type admin columns. You can see here how my custom post type is looking in admin panel. And as you can see I can order by title all posts and I was wondering if I could do same for all columns, like "info" etc. Is it possible? I am using this code, to display columns like I wanna : <code> //display catalog products in nice list add_action("manage_posts_custom_column", "catalog_custom_columns"); add_filter("manage_edit-catalog_columns", "catalog_edit_columns"); function catalog_edit_columns($columns){ $columns = array( "cb" => "<input type=\"checkbox\" />", "title" => "Product Title", "description" => "Info", "skills" => "Category", "year" => "Price", ); return $columns; } function catalog_custom_columns($column){ global $post; switch ($column) { case "description": the_content(); break; case "skills": echo get_the_term_list($post->ID, 'atrakcijas', '', ', ',''); break; case "year": $custom = get_post_custom(); echo $custom["product_price"][0]; ?>Ls<?php break; } } </code>
|
Scribu as written a great detailed tutorial named " Create your own sortable columns " just what you need.
|
Custom post type - columns order
|
wordpress
|
I rent some webserver space (Linux, MySql, PHP, Apache) and host several Wordpress websites (for different clients, with different needs) What would be the best way to Host multiple wordpress sites on a single machine, what I'm looking for here, is saving on diskspace and number of databases needed as well as simplifying maintenance. Yes this should be for a single wordpress version. Each site should be able to have different plugins included and activated Each site should be able to have it's own themes (some shared some not) No crossing between sites - users and content not shared in any way. Easily Upgradable Single Super Admin is a plus but not essential (I know how to install and manage wordpress, I can't figure out if Wordpress MU is what I need, if so how to set it up so that my requirements are met, can I enable/disable features per user/blog created with MU). Thank you!
|
Based on your needs, yes: you should probably be using a Network (WordPress with MultiSite enabled). All network sites run the same version of WordPress Each network site can activate its own Plugins. You can explicitly allow each site to manage its own Plugins. Each network site can have access to different Themes (though you will have to manage access to each Theme via the Network Admin. Users can be managed such that each sites users are mutually exclusive Upgrades of WordPress core, Themes, Plugins, and network sites is all managed from a single location in the Network Admin Super Admin is part of a Network install, and allows granular control over each network site, Plugins, Themes, and users. As for how to set up a Network, everything is incredibly well-documented in the Codex .
|
Hosting multiple Wordpress sites on single server - best practices?
|
wordpress
|
I am trying to add the parent category class in post_class() of some posts from one of my subcatgories. I have an advanved theme so I need to style all the posts from the parent cateogry using it's class, not the subcategory class (too much hassle in CSS).
|
Perhaps something like: <code> function mytheme_get_post_class_parent_cats() { $parent_cat_classes = array(); // Get parent categories $post_cats = wp_get_post_categories(); // Loop through post categories foreach ( $post_cats as $post_cat ) { $cat_parents = get_category_parents( $post_cat , false, ',', true ); // if there are any parent categories if ( $cat_parents ) { // create an array $cat_array = explode( $cat_parents, ',' ); // First key of the array is the top-level category parent $parent_cat_id = $cat_array[0]; // Get the name of the top-level parent category $parent_cat = get_cat_name( $parent_cat_id ); // create the CSS class .category-parent-{categoryname} $parent_cat_classes[] = 'category-parent-' . $parent_cat; } else { // Otherwise, the category is a top-level cat, so use it $cat_name = get_cat_name( $post_cat ); $parent_cat_classes[] = 'category-parent-' . $cat_name; } } // Return CSS class, or false return $parent_cat_classes; } </code> Then, when you call <code> post_class() </code> : <code> <?php post_class( mytheme_get_post_class_parent_cats() ); ?> </code> Codex ref: wp_get_post_categories() Codex ref: get_category_parents() Codex ref: get_cat_name()
|
Get parent category class in post_class()
|
wordpress
|
I have an IF statement shown below that runs one of 2 custom queries, based on the url. The problem I'm facing is if the url contains pagination such as <code> /page/2/ </code> , my query breaks because the url isn't correctly matched. I'm very new to php and in my searching I've come across a few different php functions that may help my situation - I'm just unsure of how to use them and which is more efficient for my needs. These are <code> preg_match </code> , <code> parse_url </code> , and <code> dirname </code> . For example, <code> site.com/players </code> lists the players and <code> site.com/players/type/pro </code> lists the pro players. The latter has been rewritten and is actually <code> site.com/players/?type=pro </code> . The following if statement is what I have now and will not run the first query if the url has anything after the /pros/ segment, such as pagination in my case: <code> if ( $_SERVER['REQUEST_URI'] == '/players/type/pros/' ) { //run the query to list the pros } else { //run the default query for the players } </code> Here's what I need to do, which works, but without all the manual labour of writing an OR for every single page. This is where I'm guessing one of those php functions would come into play. <code> if ( $_SERVER['REQUEST_URI'] == '/players/type/pros/' || $_SERVER['REQUEST_URI'] == '/players/type/pros/page/2/' || $_SERVER['REQUEST_URI'] == '/players/type/pros/page/3/' || $_SERVER['REQUEST_URI'] == '/players/type/pros/page/4/' ) { //run the query to list the pros } else { //run the default query for the players } </code> Update Thanks to those who answered. I've been digging into WordPress' rewriting and with the help of some very informative posts on this site I ended up doing it this way. Made a new page template called player-types.php which would handle the incoming query or queries. I may need to further list players by other types. Setup some rewrite rules placed in functions.php <code> add_filter('init', 'add_page_rewrite_rules'); function add_page_rewrite_rules() { //would match www.site.com/players/type/pro add_rewrite_rule('^players/type/([^/]*)/?$','index.php?pagename=player-types&type=$matches[1]','top'); //would match www.site.com/players/type/pro/page/2 add_rewrite_rule('^players/type/([^/]*)/page/([0-9]+)?$','index.php?pagename=player-types&type=$matches[1]&paged=$matches[2]','top'); } </code> Added the <code> type </code> variable to <code> query_vars </code> so I could use it on the new page template (placed in functions.php) <code> add_filter( 'query_vars', 'add_query_vars' ); function add_query_vars( $query_vars ) { $query_vars[] = 'type'; //add type to query vars return $query_vars; } </code> And the page template in it's most basic form looks like this <code> <?php /* Template Name: Player Types */ ?> <?php if ( $wp_query->query_vars['type'] == 'pro' ) { //custom pro query } ?> </code> This allows me to have <code> www.site.com/players/type/pro </code> and I can expand on it to <code> www.site.com/players/type/whatever-else </code> . Normal players are still listed at <code> www.site.com/players/ </code> . And for those who are wondering, I didn't do it with a taxonomy because I'm listing the players based on their custom WordPress role ( pulling the author id's into the query) rather than having a check box that someone has to manually check.
|
look for the string <code> page/ </code> and capture just the part of the url before it with <code> strpos </code> and <code> substr </code> : <code> $url = '/players/type/pros/page/3/'; $find = 'page/'; $trimmed_url = substr( $url, 0, strpos($url, $find) ); </code> EDIT - so in the context of your question you could use: <code> $url = $_SERVER['REQUEST_URI']; $find = 'page/'; $pos = strpos($url, $find); if($pos): $url = substr($url, 0, $pos); endif; if( $url == '/players/type/pros/' ){ //run the query to list the pros } </code> But a question I have - why are you using the URL to determine what to load, can you not check $_GET['type'] or whatever query vars are being set?
|
Is there a PHP function that can match anything after the given URL, so my IF statement will work in each instance?
|
wordpress
|
I use excerpts of posts in my front page. In my excerpt, the summary of the post seems to be clumped together with no spaces that are indicated in the post (e.g., paragraph spaces are automatically removed). I understand this is the default behavior. Question: Is there a way to retain the paragraph in excerpts? To show excerpt on the fron page in my Twenty Ten theme's loop.php I changed this (around line #137: <code> <?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?> </code> with this: <code> <?php if ( is_home() || is_front_page() || is_archive() || is_search() ) : // Only display excerpts for archives and search. ?> </code> thanks.
|
Looks like my other answer wasn't working, so I looked into it and found this: http://aaronrussell.co.uk/legacy/improving-wordpress-the_excerpt/ That article should give you all you need to keep the <code> <p> </code> tags in there.
|
Excerpts automatically remove paragraph space
|
wordpress
|
Does anyone know where I can get a list of all the body classes generated by <code> body_class() </code> for every sections and every conditions , including custom post-types , etc.? For example, for a search result page with certain conditions (eg. logged-in ), the function produces this: <code> <body class="search search-results logged-in admin-bar single-author two-column right-sidebar"> </code> I need the full list for reference in creating a theme. Cheers!
|
Several classes have been added since WordPress 2.8 (when the WPEngineer post was written). I would refer directly to the <code> body_class() </code> Codex entry , which currently lists the following: rtl home blog archive date search paged attachment error404 single postid-(id) page-id-(page_id) attachmentid-(id) attachment-(mime-type) author author-(user_nicename) category category-(slug) tag tag-(slug) page-parent page-child parent-pageid-(id) page-template page-template-(template file name) search-results search-no-results logged-in paged-(page number) single-paged-(page number) page-paged-(page number) category-paged-(page number) tag-paged-(page number) date-paged-(page number) author-paged-(page number) search-paged-(page number) tax-(taxonomy name) (since 3.1) term-(term name) (since 3.1) admin-bar (since 3.1)
|
List of Body Classes Generated by body_class()
|
wordpress
|
I have a custom post type called "stock" and each post is going to have a stock_id, stock_name, stock_description and stock_available fields,...I would like to have defaults for these fields so the user doesn't have to load them on each new item. Is there a way?
|
A simple way to do that would be to use Verve Meta Boxes plugin which lets you define a metabox with a simple UI ( no code is needed ) and you have an options to set the default value for each field.
|
preselected custom fields in custom post type
|
wordpress
|
Currently my only internet access is via my phone, and I need to add a widget to a Wordpress site. This requires dragging and dropping the widget to the sidebar, which I cannot do via the web browser on the device. Is there some way to get around this?
|
Yes at the top of the page click on "Screen Options" then click "Enable accessibility mode" ,
|
How do I add a widget from an Android phone?
|
wordpress
|
I just built a theme for a client. I am wondering what is the best way to make footer content editable through Wordpress. The footer info looks like this: Company Name Address Line 1 Address Line 2 Phone and Fax Email (linked with mailto) I have some ideas on how to do this: Make a page called footer and grab the content from there. Widgetize the footer and make it a text widget Make a themes option panel with the option to customize this text I would love to know what you guys think is your best solution to this. Thank you in advance!
|
I would go with a Widgetized footer. If you want to go the extra mile, rather than create Theme Options, simply create a custom Widget, e.g. Footer Contact Details, that has editable text inputs for Company Name, Address Lines 1 and 2, Phone/Fax, and Email.
|
Editing Footer Information
|
wordpress
|
I have the following code that prints a comma separated list which I need in the form of an array, how do I get the list of id's into an array called $excluded_categories with contents as per below? <code> $categories = get_categories(array('taxonomy'=>'projects_category', 'exclude'=>7, 'orderby'=>'id')); if ( !empty( $categories ) ) : foreach($categories as $term){ echo $term->term_id.', '; // prints: 1,2,3,4,5,6,8,9, } endif; $excluded_categories would be an array containing: 1,2,3,4,5,6,8,9 </code>
|
WP has a lot of nifty functions in the corners for such stuff. Try this: <code> if ( !empty( $categories ) ) { $excluded_categories = wp_list_pluck( $categories, 'term_id'); $excluded_categories = implode(',', $excluded_categories); } </code>
|
Comma seperated list of ID's as an array?
|
wordpress
|
I have a custom post type of <code> players </code> , and archive-players.php lists them all at an address such as <code> www.site.com/players </code> . I'm then using a url like <code> www.site.com/players?type=pro </code> to list another page of just the pro players (modified wp_query based on custom user role, hence why I don't just do this with a taxonomy). I decided I should rewrite the url so it's <code> www.site.com/players/pro </code> . The page itself works fine, but my question is: how can I now fix the pagination when the url is something like <code> www.site.com/players/type/pro/page/3/ </code> ? at the moment I'm getting page not found. I'm using wp page-navi for the pagination. In fact, pagination doesn't work when I have it as just <code> ?type=pro </code> either. The code I have for the rewrite is below. Is it better to rewrite using wordpress or mod_rewrite? I have no experience with either. Am I going about this the right way? I've read some other questions and posts all over the place, but the whole thing just confuses me. <code> function add_query_vars($aVars) { $aVars[] = "type"; return $aVars; } add_filter('query_vars', 'add_query_vars'); function add_rewrite_rules($aRules) { $aNewRules = array('players/type/([^/]+)/?$' => 'index.php?post_type=players&type=$matches[1]'); $aRules = $aNewRules + $aRules; return $aRules; } add_filter('rewrite_rules_array', 'add_rewrite_rules'); </code>
|
You have to add another rule which maps the /page/# to the &paged=# variable. Really though, you're kinda doing it all backwards here by filtering the rules array. Just calling add_rewrite_rule to add your rules makes a bit more sense. <code> function plugin_name_add_rewrite_rules() { add_rewrite_rule('players/type/([^/]+)/?$', 'index.php?post_type=players&type=$matches[1]', 'top'); add_rewrite_rule('players/type/([^/]+)/page/([0-9]+)?$', 'index.php?post_type=players&type=$matches[1]&paged=$matches[2]', 'top'); } add_filter('init', 'plugin_name_add_rewrite_rules'); </code>
|
How to fix pagination after rewriting url? ie. www.site.com/players/type/pro/page/3/
|
wordpress
|
I was just reading the Codex regarding <code> get_terms(); </code> . What exactly is the parameter <code> 'term_group' </code> ? You can use it in ( example ): <code> 'order_by' </code> for <code> get_terms(); </code> . Hint: I could be all terms that share the same names, but have different slugs.
|
The idea of term groups was to have a term with multiple aliases. This feature doesn't seem to be fully backed and is therefore practically never used.
|
What is 'term_group' for 'order_by' in get_terms()?
|
wordpress
|
My question resembles one I asked before: stackexchange-url ("[Plugin: Posts 2 Posts] Changing display order of connections") But now I want to display the connection in the SAME order I created them ! That is, if I attache quote#1 THEN quote#2 to an article, I want quote#1 to appear before quote#2 regardless of the creation date of these quotes, their alphabetical order or whatever. Don't know if I make myself clear o_O
|
With the development version of the plugin (0.8-alpha), you have a 'p2p_orderby' query var, which you can use with WP_Query, like so: <code> $my_query = new WP_Query( array( 'connected_to' => get_queried_object_id(), 'p2p_orderby' => 'my_connection_field' ) ); </code> More info on connection fields: https://github.com/scribu/wp-posts-to-posts/wiki/Connection-information Note that this is alpha software and you still have some work to do on your own.
|
[Plugin: Posts 2 Posts] Controling the display order of connections
|
wordpress
|
I've created a custom post type with categories and sub categories, what I need to do is list out the post titles and images for a given sub-category or category in a page template. I've got as far as getting the all the listed items in the custom post type, but I'm unsure how to go further... any help appreciated. <code> <?php $args = array( 'post_type' => 'portfolio', 'posts_per_page' => 10 ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); the_title(); echo '<div class="entry-content">'; the_content(); echo '</div>'; endwhile; ?> </code> The function that creates the custom post type and taxonomy looks like this:- <code> <?php // CUSTOM POST TYPE 1 add_action('init', 'portfolio_register'); function portfolio_register() { $args = array( 'label' => __('Portfolio'), 'singular_label' => __('Portfolio'), 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => true, 'supports' => array('title', 'editor', 'thumbnail') ); register_taxonomy("galleries", array("portfolio"), array( "hierarchical" => true, "label" => "Galleries", "singular_label" => "Galleries", "rewrite" => true) ); register_post_type( 'portfolio' , $args ); } add_action("admin_init", "admin_init"); add_action('save_post', 'save_portfolio_options'); add_action('save_post', 'save_portfolio_single_options'); function admin_init(){ add_meta_box("gallerymeta", "Gallery Options", "portfolio_meta_options", "portfolio", "normal", "low"); add_meta_box("portfoliometa", "Portfolio Item Options", "portfolio_single_meta_options", "portfolio", "side", "low"); } function portfolio_meta_options(){ global $post; $custom = get_post_custom($post->ID); $excerpt = $custom["excerpt"][0]; $info = $custom["info"][0]; $linkto = $custom["linkto"][0]; ?> </code>
|
This is a version of a function I'm using in the framework I'm working on, with example html replacing another function that contains something like it. <code> // Custom Loop function arrr_custom_loop( $r_type = 'post', $r_post_num, $r_tax = 'category', $r_terms = 'featured' ) { $args = array( 'showposts' => $r_post_num, 'tax_query' => array( array( 'post_type' => $r_type, 'taxonomy' => $r_tax, 'field' => 'slug', 'terms' => array( $r_terms ), ) ) ); query_posts( $args ); if (have_posts()) while ( have_posts() ) : the_post(); $more = 0; ?> <article> <header class="pagetitle"> <?php if ( is_singular() ) { ?> <h1><?php the_title(); ?></h1> <?php } else { ?> <h2 class="entry"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <?php } ?> </header> <div class="content_wrapper"> <div class="content"> <?php the_content(); ?> </div> </div> <?php if ( comments_open() && ! post_password_required() ) { ?> <div class="comments_wrapper"> <div class="comments"> <?php comments_template(); ?> </div> </div> <?php } ?> </article> <?php endwhile; wp_reset_query(); } </code> So you would then just use the function with the arguments created: <code> arrr_custom_loop( 'portfolio', 10, 'galleries', 'pirates' ); </code>
|
Get custom post type by category in a page template
|
wordpress
|
I've used the Smart YouTube plugin to embed YouTube videos into my blogs. The way I did it is to replace the <code> http:// </code> of the YouTube url with <code> httpv:// </code> as the plugin describes. But now I noticed that it's much easier to just auto-embed the YouTube videos by posting the normal <code> http:// </code> url. I would like to disable the Smart YouTube plugin and convert all those <code> httpv:// </code> back to <code> http:// </code> . Is there a good automated way to do that? Here's an example blog post of mine that now has Smart YouTube disabled so there's just a <code> httpv:// </code> url lingering there.
|
I like to use the Search Regex plugin for mass post editing. http://wordpress.org/extend/plugins/search-regex/
|
Rename Smart YouTube's httpv back to http for all posts
|
wordpress
|
I'm using the code below from another answer to query posts from 1 custom role, eg "friends". I thought I could just comma separate the roles to list posts from more than one role, but this didn't work. Is there another way I can write it? I've tried <code> 'role' => 'friends', 'enemies' </code> and <code> 'role' => 'friends, enemies' </code> but I guess <code> get_users </code> only supports one role. <code> <?php $friends = get_users( array( 'role' => 'friends' ) ); $friend_ids = array(); foreach( $friends as $friend ) $friend_ids[] = $friend->ID; $news = new WP_Query( array( 'author' => implode( ',', $friend_ids ), 'post_type' => 'news', 'paged' => get_query_var('paged') ) ); ?> </code>
|
Just do the get_users() twice and merge the results: <code> <?php $friends = get_users( array( 'role' => 'friends' ) ); $enemies = get_users( array( 'role' => 'enemies' ) ); $friends_n_foe = array_merge($friends, $enemies); $IDs = array(); foreach( $friends_n_foe as $person ) { $IDs[] = $person->ID; } $news = new WP_Query( array( 'author' => implode( ',', $IDs ), 'post_type' => 'news', 'paged' => get_query_var('paged') ) ); ?> </code>
|
How can I query posts from multiple roles?
|
wordpress
|
I use this code for display custom posts : <code> $args = array( 'category__in' => $bookcat, 'meta_query' => array( 'relation' => 'OR', array('key' => 'bookname','compare' => 'LIKE','value' => $bookname), array('key' => 'authr','compare' => 'LIKE','value' => $authr), array('key' => 'translator','compare' => 'LIKE','value' => $translator), array('key' => 'publisher','compare' => 'LIKE','value' => $publisher), array('key' => 'pyear','compare' => '=','value' => $pyear,'type' => 'NUMERIC'), array('key' => 'ptime','compare' => '=','value' => $ptime,'type' => 'NUMERIC') ) ); </code> There is 6 array in meta_query , when I use that code , mysql server use upper than 80% of cpu! But when I use 4 array or less thats work well.for example : <code> 'meta_query' => array( 'relation' => 'OR', array('key' => 'bookname','compare' => 'LIKE','value' => $bookname), array('key' => 'authr','compare' => 'LIKE','value' => $authr), array('key' => 'translator','compare' => 'LIKE','value' => $translator), array('key' => 'publisher','compare' => 'LIKE','value' => $publisher) ) </code> Is there limit to use number of array in wordpress meta_query?or I have mistake in my code? Thanks for any help.
|
Looking at your code it looks perfectly fine. Although the more complex you make your query the more resources it is going to take and the longer it is going to take. You mention that your CPU usage rises to 80% which would be normal but how long is the usage holding at 80%? If its for a very short while then I wouldn't worry about it. What can you do to optimise the query... You could look at placing the data in a separate DB table where you can properly index the table to suit the queries you will be throwing at it. However doing this will require a fair bit of development work to get this done. If you want to go down this route then feel free to ask other questions on here to get your started.
|
WordPress & MySQL , problem with use many array in meta_query
|
wordpress
|
Company I work for has purchased an eCommerce solution for WordPress. The solution works as a complete WordPress Theme. My assignment is to split the store view from the original website design. To be more precise, website we are working on has a unique design, but when we install the store theme, the whole website theme changes to that of a store. Are there ways I can complete this assignment? I thought about it for a while but the solution I found is terrible. I wanted to allow access to a store only on one particular page, by checking <code> <?php if is_page('shop') { include TEMPLATEPATH.'storeurl/header.php'; } else { get_header(); } ?> </code> and so on, but it gets me nowhere because I need to have certain fields in admin panel for adding products. Any other ideas, please?
|
Core site functionality really shouldn't be so tightly coupled to the theme. This is why the plugin system exists. If it's not too late I would recommend exploring alternatives. That said, anything happening on the admin side is in the theme's <code> functions.php </code> file, or is included via that file. As long as that file and anything it loads is in the proper place it's likely the admin side will work. Then it's a matter of merging or including the other templates into your own theme to get the presentation you want on the front end.
|
Splitting an eCommerce store from the WordPress Theme
|
wordpress
|
Hey guys i'm creating a site network using WordPress. Lets say my site name is blahblah.com and lets say i have 10 subdomains like site1.blahblah.com,site2.blahblah.com Now i want something like this. There will be no articles in my main domain. But i want list all subdomain's articles in my main domain. When they click read more button users have to redirected to original article. I also want multisite access facility with single registration. That is if a user signed up in my main domain, then he should able to access all my sub domain using the same login credentials. Some says use the same database for all domains. But i dont think thats a good idea. Is there any premium or free plugin available for this feature?. Thanks.
|
There are two plugins that do exactly what you want, and I have used them both extensively. First, ThreeWP-Broadcast . This plugin lets you "broadcast" posts from your sub blogs to your main blog (or the other way around). It also allows you to link to broadcasted post to the original, as well as auto create tags, categories, custom fields, and featured images. Second, is Multi-Site User Management . This is a little plugin that you drop in your mu-plugins folder and it will keep your users synchronized across all sites, allowing them to login into all the sites with the same name.
|
Please suggest me some plugins in WordPress networking
|
wordpress
|
My nginx user is www-data. If I do <code> su www-data </code> I can create both file and directory. But when installing plugin I am asked for FTP credentials. I tried to give the public_html directory 777 permissions for a while to test if I can install plugin without providing FTP credentials but it didn't help either. WP 3.2.1 nginx ubuntu How can I install plugins without providing FTP credentials.
|
You can set this in the wp-config.php, check the Editing wp-config.php page in the docs.
|
What are the correct permissions so WP doesn't ask for FTP credentials if installing plugin?
|
wordpress
|
I'm trying to redirect certain users to a part of my site but I cannot seem to make it work... can you take a look at this and tell me what I'm doing wrong? <code> if ( ! function_exists( 'redirect_after_login' ) ) : function redirect_after_login() { global $user_ID; if ( $user_ID === 4 ) { global $redirect_to; if (!isset($_GET['redirect_to'])) { $redirect_to = get_option('siteurl') . '/stock-de-sexitive/'; } } } endif; add_action('auth_redirect', 'redirect_after_login'); </code> Also, I know globals are dangerous, so if you know of a canonical approach that would be great too
|
Try <code> wp_redirect() </code> . And don't forget to exit.
|
problem redirecting users to page on login
|
wordpress
|
If I upload a large size image inn my wordpress, the image breaks my template width. I have seen some templates which scale the large image's width to the maximum width of the post div. What CSS or code I need to change for that purpose? Thanks.
|
In your <code> functions.php </code> file, you need to define <code> $content_width </code> , which will cause WordPress to scale large -size images, and also embedded videos, accordingly. e.g. if the width of your content area is 600px: <code> if ( ! isset( $content_width ) ) { $content_width = 600; } </code> You will probably also want to add accompanying CSS, e.g.: <code> #content img { width: auto; max-width: 600px; height: auto; } </code> That way, when the image is scaled, it will maintain its proportion; rather than merely having its width reduced, the height will also be scaled proportionately.
|
Large size image breaks template layout
|
wordpress
|
Here's my custom function to list child categories by the parent slug. <code> function ribbon_list_cats($parent_cat_slug) { $parent_category = get_category_by_slug($parent_cat_slug); if ($parent_category->count != 0) { echo "<ul>"; echo wp_list_categories('title_li=&child_of='.$parent_category->term_id.'&hide_empty=0&show_option_none=&echo=0'); echo "</ul>"; } } </code> I'm having trouble getting it to return and output. It doesn't throw an error. I'm using it multiple times so I created this but when I do it like so: <code> $parent_category = get_category_by_slug('lifestyle'); if ($parent_category->count != 0) { echo "<ul>"; echo wp_list_categories('title_li=&child_of='.$parent_category->term_id.'&hide_empty=0&show_option_none=&echo=0'); echo "</ul>"; } </code> right in the template it works fine. But that's a lot of code to repeat over and over again. Hope that makes sense. Thanks!
|
<code> function ribbon_list_cats( $parent_cat_slug, $echo = true ) { $parent_category = get_category_by_slug( $parent_cat_slug ); if ( $parent_category->count > 0 ) { $output = '<ul>'; $output .= wp_list_categories('title_li=&child_of='.$parent_category->term_id.'&hide_empty=0&show_option_none=&echo=0'); $output .= '</ul>'; } // Debug: uncomment the following line // echo '<pre>'; var_dump( $output ); echo '</pre>'; if ( $echo === false ) return $output; return print $output; } // Call it like this: ribbon_list_cats( 'uncategorized' ); </code>
|
Having Trouble With get_category_by_slug In a Custom Function
|
wordpress
|
I currently have a site with two levels of navigation. I am styling the wp_list_pages() list to act as my navigation. I would like to disable the link on some pages which have children (not exclude) so that I can hover over them to display the drop down navigation but I can't click on them. Does anyone know of such a method or parameter I could add?
|
You could go to the wordpress menu and make the target of the link a #. If the user clicks on it, they are taken to the top of the page where they probably are anyway since they're using the navigation.
|
Disable the link on certain pages
|
wordpress
|
How can I remove "edit your profile" submenu under "my-account-with-avatar" admin menu bar, while still keeping the avatar and logout?
|
There is a <code> remove_menu </code> hook for the admin menu bar. The class you want to hook into <code> $wp_admin_bar </code> , you can see the remove function here and test it out since there is no documentation on it ( line 86), it should work with the submenu ID. http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/class-wp-admin-bar.php Since you did not seem to believe me here is the code......... <code> function ya_do_it_admin_bar_remove() { global $wp_admin_bar; /* **edit-profile is the ID** */ $wp_admin_bar->remove_menu('edit-profile'); } add_action('wp_before_admin_bar_render', 'ya_do_it_admin_bar_remove', 0); </code>
|
remove "edit your profile" from admin menu bar
|
wordpress
|
As I am a novice in web development field, I wanted to clarify some questions running in my head. I want to make a multilingual website with dynamic features. Dynamic features can be like anything under the sun. Is it possible that I can make a website using WordPress (which is mostly considered as blogging platform). Well I know that there are some limitations while making a customized website with wordpress. Should I learn any of the frameworks like Django or rails, if yes why (its obvious I would have to learn CSS, Ajax, Javascript, PHP)? Suppose I want to add dynamic features in my wordpress site real time features like that of twitter (should I learn ruby on rails then?), or building API's, support digg like features ,people submitting blogs and reblogging again, aggregaton features, editing features, some facebook features like notification features on the top of your profile page, colloborative blogging, submitting links, photos, videos, social platform for people to know each other and follow them, microblogging (realtime) like tumblr. Will it be fully customizable after I get my hands perfectly on learning some languages and/or frameworks like rails or django. I don't want to learn drupal as it learning curve is very high and meant for technically good programmers, while I don't have much knowledge of Joomla (and am ready for it to learn if wordpress fails). I also want to make a rich platform for advertisement which will be commercial. Is it possible that I make a model of advertisement which is in my mind which can link to any other websites, blogs, people (users). The most interesting,challenging and important question is: If I am not able to make a website with such dynamic features with Wordpress, will I have to make pluggins, widgets,themes on my own which can be fully customized for my website. Is it possible to make such pluggins and themes which can be fulfill above said points.
|
1) Yes you can 2) No, but spend a lot of time reading up on wordpress codex (thats more or less your bible) and of course refernce through this site too, full of valuable information. 3) Everything is very easily added to wordpress via plugins, no need to go on steep learning curves 4) Wordpress is probably the most simple of all to learn and very well documented. 5) of course WP is very flexible 6) There are thousand upon thousands of plugins (no need to re-invent the wheel) there is bound to be something that fits your requirements and as well as plugins there are also themes that have been designed specificaly for niche websites
|
How can I make a website with dynamic features with wordpress?
|
wordpress
|
I am following this tutorial to post from front end. I am able to post the title, content, category, tags, I would like to know is it possible to add more fields like in the image below. How to increment field-set? and how to add edit the post from the front end itself? basically this what I want to do.
|
I believe it is better if you use the ajax method instead of sending the POST to the same page. You can use javascript to increment the form / fieldset. Use an array for the name e.g <code> <input type="text" name="ingredient[]"/> </code> If you want to edit the post, just you us the saved data on the value attribute, e.g <code> <input type="text" name="ingredient[]" value="<?php echo get_post_meta($post->ID, 'ingredient[0]', true) ?>"/> </code> If the post meta using a same meta_key, just put it in the for each loop. Hope this help
|
Post & edit a post from front end along with upload, dropdown, and other inputs
|
wordpress
|
On a freshly built site running version 3.1.3 with the twentyten theme active and no plugins, when I click on "Media" to go the media manager, I'm getting this error: Warning: explode() expects parameter 2 to be string, array given in C:\xampplite\htdocs\testsite\wp-includes\query.php on line 2390 Warning: in_array() expects parameter 2 to be array, null given in C:\xampplite\htdocs\testsite\wp-includes\query.php on line 2399 Warning: in_array() expects parameter 2 to be array, null given in C:\xampplite\htdocs\testsite\wp-includes\query.php on line 2399 Warning: in_array() expects parameter 2 to be array, null given in C:\xampplite\htdocs\testsite\wp-includes\query.php on line 2399 Warning: in_array() expects parameter 2 to be array, null given in C:\xampplite\htdocs\testsite\wp-includes\query.php on line 2399 Warning: in_array() expects parameter 2 to be array, null given in C:\xampplite\htdocs\testsite\wp-includes\query.php on line 2399 Warning: in_array() expects parameter 2 to be array, null given in C:\xampplite\htdocs\testsite\wp-includes\query.php on line 2399 Warning: in_array() expects parameter 2 to be array, null given in C:\xampplite\htdocs\testsite\wp-includes\query.php on line 2399 Warning: in_array() expects parameter 2 to be array, null given in C:\xampplite\htdocs\testsite\wp-includes\query.php on line 2399 Warning: Cannot modify header information - headers already sent by (output started at C:\xampplite\htdocs\testsite\wp-includes\query.php:2390) in C:\xampplite\htdocs\testsite\wp-includes\functions.php on line 851 Warning: Cannot modify header information - headers already sent by (output started at C:\xampplite\htdocs\testsite\wp-includes\query.php:2390) in C:\xampplite\htdocs\testsite\wp-includes\functions.php on line 852
|
Quick look at source for that version shows parsing <code> post_status </code> argument. It's probably this bug that got fixed in 3.2 . Upgrade. :)
|
Warning: in_array() expects parameter 2 to be array, null given
|
wordpress
|
Relevant link: http://themeforward.com/demo2/2011/01/17/testing-comments/ I've been toying with this for about 10 minutes, trying to get the sidebar to align properly and I can't figure it out. I placed my comments in a new DIV to separate them from the posts. Usually I wouldn't do this but I want designers to have full CSS control without adding new classes when they start using this theme to build. Anyway, my sidebar ends up being aligned with my comments rather than the content on my page. Moving the div under the endif is not an option here because I want to be able to style just the post by itself if desired. Putting the comments below the sidebar makes the comments disappear! My code looks like this: <code> <?php get_header(); ?> <div id="container"> <div id="post_content"> <div class="clear"> <!-- Grab posts --> <?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?> <!-- Post title --> <h1><?php the_title(); ?></h1> <div class="sub-title-post"> <?php the_time('F j, Y'); ?> by <?php the_author_posts_link( ); ?>, under <?php the_category(', ') ?> </div> <!-- The post --> <?php the_content(); ?> <?php edit_post_link('Edit', '<p>', '</p>'); ?> <!-- Tags --> <h3 class="tags"><?php the_tags('Tags ',' / ','<br />'); ?></h3> <h3 class="tags"><?php $turl = getTinyUrl(get_permalink($post->ID)); echo 'Short URL <a href="'.$turl.'">'.$turl.'</a>' ?></h3> <!-- Next/Previous Posts --> <div class="mp_archive2"> <div id="more_posts"> <div class="oe"><?php previous_post_link('%link', '-', TRUE); ?></div> <div class="re"><?php next_post_link('%link', '+', TRUE); ?></div> </div> </div> </div> <?php endwhile; else: ?> <p>No matching entries found.</p> <?php endif; ?> </div> <?php comments_template(); ?> <?php get_sidebar(); ?> </div> </div> <?php get_footer(); ?> </code>
|
Put content and comments into a container div with float: left; and then add the same to your sidebar.
|
Unable to align my sidebar to the contents section instead of comments
|
wordpress
|
I was trying to clear up some empty tables left behind by other previously used plugins. As such i was trying to delete the GD Star rating plugin and now I cannot access my WP admin. i get the <code> 'You do not have sufficient permissions to access this page' </code> I turned on the debug to true and saw the errors caused by lots of plugins. So I disabled all of them, but nothing helps: This was the query I had run (and then just checked the output and clicked 'Drop' which messed it up. <code> SELECT * FROM `mydomain_main`.`wp_options` WHERE ( `option_id` LIKE '%ratings_%' OR `blog_id` LIKE '%ratings_%' OR `option_name` LIKE '%ratings_%' OR `option_value` LIKE '%ratings_%' OR `autoload` LIKE '%ratings_%' ) </code> Can someone please please advise
|
since i posted as a comment and most people miss the good tips that are in the comments, I'm posting again as an answer The reason is because <code> GD Star rating </code> plugin creates custom capabilities and your query deleted all references of <code> %rating% </code> it deleted the <code> wp_user_roles </code> option which holds all capabilities roles. the solution would be to re create that option in options table (usually wp_options) with the default value just like I answered here .
|
Help!! I Screwed up my WP
|
wordpress
|
I'm doing a category-based search that looks like this: <code> $feed = WP_Query("category_name=noticias&showposts=3&order=DESC"); </code> The problem is this also brings me posts from the child categories, which I would like to avoid... how do I do this? If I do something like <code> $feed = query_posts(array('category__in' => array(102))); </code> Then I am told that $feed is not an object next time I try to do something with it... that's why WP_Query was good for me in the first place.
|
you can use the <code> 'category__in' </code> in WP_Query; example: <code> $feed = WP_Query(array('category__in' => array(102), 'posts_per_page' => 3, 'order' => 'DESC')); </code>
|
how do I exclude child categories from a wp_query?
|
wordpress
|
I have 500x300 sized images in my all post and want 280x177 sized images to display in index page for all the post. I used regenerate thumbnails and AJAX thumbnail rebuild plugin which builds images using setting in media section but problem is that after building some of the images it stops reacting and just hangs. Why this is happening? Is these plugins not work with more images. I have approximately 2000 images. Please help me. How to rebuild this images. Thanks in advance....
|
Very likely, your issue is the large number of images, causing the processing to time out. Try increasing your PHP script execution time, and see if either Plugin can complete. Alternatively, I believe that one or both of those Plugins allows for manual thumbnail regeneration, via <code> Dashboard -> Media </code> .
|
How to regenerate image thumb with size that is specified in media section
|
wordpress
|
I have a blog with all the plugins I need committed to an internal svn repository. Wordpress is showing that some plugins need to be updated but when I do, Wordpress will delete the folder for that plugin so the .svn files are deleted as well. This will break the repository for that plugin. Any way around this?
|
a simple way around this is to update the plugins by SVN from the plugin repository.
|
Updating a Wordpress plugins breaks SVN
|
wordpress
|
I'm trying to modify how results are displayed in a post list that's currently controlled by the code below. However, it's not built in the WP_Query <code> while ( $the_query->have_posts() ) : $the_query->the_post(); </code> style I'm accustomed to and have built a lot of shortcodes and loop styles around. How can I change the code below into a "regular" Wordpress loop that will allow me to use template tags like the_title()? <code> $totalposts = $wpdb->get_results($querystr, OBJECT); $wp_query->request = $querystr . " LIMIT " . $ppp . " OFFSET " .$offset; $results = $wpdb->get_results($wp_query->request, OBJECT); foreach ($results as $result) { $offset++; $output .= '<a href="'.get_post_permalink($result->ID).'">' . $result->post_title . ' (' . $result->post_date . ')</a><br>'; } </code>
|
In order to be able to use template tags, you have to do two things after getting your custom select query: You have to declare the <code> global $post </code> variable. You have to call the setup_postdata($post) function to populate the variables. So, my code had to be changed like so: <code> $results = $wpdb->get_results($wp_query->request, OBJECT); global $post; foreach ($results as $post) { setup_postdata($post); ?> <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4> </code> etc. The key to this is on this codex page: Displaying posts using a custom select query
|
How to change a custom query into a standard loop?
|
wordpress
|
I was just wondering if calling get_bloginfo too many times was going to harm performance in a theme and if the data should just be put into its own var?
|
<code> get_bloginfo() </code> is not cached and calling it over and over would harm your performance just like creating many calls to the database yourself. a simple solution which doesn't evolve any caching in to minimize the database and function calls by defining a an array with all the info you need and save that as an option in the wp_options table. then in your header.php globalize a variable and assign that option to it and every were in your them you can just use that, something like this: in your functions.php <code> function set_get_my_blog_info(){ $my_blog_info = get_option('my_blog_info'); if ($my_blog_info === false){ global $wp_version $lang = get_locale(); $lang = str_replace('_', '-', $lang); $my_blog_info = array( 'url' => home_url(), 'wpurl' => site_url(), 'description' => get_option('blogdescription'), 'rdf_url' => get_feed_link('rdf'), 'rss_url' => get_feed_link('rss'), 'rss2_url' => get_feed_link('rss2'), 'atom_url' => get_feed_link('atom'), 'comments_atom_url' => get_feed_link('comments_atom'), 'comments_rss2_url' => get_feed_link('comments_rss2'), 'pingback_url' => get_option('siteurl') .'/xmlrpc.php', 'stylesheet_url' => get_stylesheet_uri(), 'stylesheet_directory' => get_stylesheet_directory_uri(), 'template_url' => get_template_directory_uri(), 'admin_email' => get_option('admin_email'), 'html_type' => get_option('html_type'), 'version' => $wp_version, 'language' => $lang ); update_option('my_blog_info',$my_blog_info); } return $my_blog_info; } </code> this will save most of the get_bloginfo options into one option in the database and will only run once. then in your header.php add <code> global $my_blog_info; $my_blog_info = set_get_my_blog_info(); </code> and after you do that you can use that array anywhere you want in your theme, for example instead of: <code> echo get_bloginfo('url'); </code> simply use your array: <code> echo $my_blog_options['url']; </code>
|
Are get_bloginfo queries cached to start, or should they be cached?
|
wordpress
|
How can I remove the next and previous links in a custom post type archive page, but only for that post type? I know I could wrap any function in <code> if ( get_post_type($post) == 'myposttype' ) {} </code> but I can't find a solid snippet to remove the pagination. I have tried a few solutions, stackexchange-url ("this being one of them"), but nothing is working. And yes, I did try removing them from my template. :)
|
Got it figured out... While I did manually remove the next page links, CloudFlare's cache was not playing nice.
|
How to disable pagination (next/previous links) on post type archive?
|
wordpress
|
I have a short code that is adding a form to a page. How do I ensure that the CSS for the form is loaded in time with the shortcode?
|
you can check with <code> the_posts </code> hook if your shortcode exists and only enqueue the style if so : <code> function check_for_shortcode($posts) { if ( empty($posts) ) return $posts; $found = false; foreach ($posts as $post) { if ( stripos($post->post_content, '[CHANGE_TO_YOUR_SHORT_CODE') ) $found = true; break; } if ($found){ $url = get_bloginfo( 'template_directory' ); wp_enqueue_style( 'my_login_Stylesheet',$url.'/my_login_Stylesheet.css' ); } return $posts; } add_action('the_posts', 'check_for_shortcode'); </code>
|
Custom CSS for plugin form
|
wordpress
|
I am using 2011 theme, any how I managed to get sidebar on single.php pages by installing child theme, But now I want sidebar on pages, How do I get it?
|
Funny you should ask, I've just posted an How to tutorial on how to add a sidebar on posts and pages in Twenty Eleven
|
Worpress twenty eleven sidebar on Pages
|
wordpress
|
Is there anyway to rename a user role name via hook, instead of using plugin?
|
<code> function change_role_name() { global $wp_roles; if ( ! isset( $wp_roles ) ) $wp_roles = new WP_Roles(); //You can list all currently available roles like this... //$roles = $wp_roles->get_names(); //print_r($roles); //You can replace "administrator" with any other role "editor", "author", "contributor" or "subscriber"... $wp_roles->roles['administrator']['name'] = 'Owner'; $wp_roles->role_names['administrator'] = 'Owner'; } add_action('init', 'change_role_name'); </code> http://www.garyc40.com/2010/04/ultimate-guide-to-roles-and-capabilities/
|
Is there way to rename user role name without plugin?
|
wordpress
|
I have a custom post type with its own date field. the date is setup for unix YYYY/mm/dd I need to create a simple month calendar that shows days that have a cpt on them. get_calendar works for posts but not a CPT.
|
You can put a custom function into your functions.php to show a calendar with CPTs. Details here .
|
how can I create a calendar for a cpt, using get_calendar or other
|
wordpress
|
I hope you were easily able to understand my situation through the question. 1.Do we have any theme or plugin for on-spot editing the post by people or by me after the blog post is posted? 2.If there isn't any theme or pluggin for such feature should I make plugin or theme independently for my website. 3.If both of the above fails,please give me a better option for some other kind of CMS as there are no many cms and I want to make my website with dynamic features. Please follow the link below and kindly suggest me one. http://en.wikipedia.org/wiki/List_of_content_management_systems
|
This is typically called edit in place . Try the Front End Editor plugin.
|
How can I make my website with wordpress having on-spot editing feature as compared to concrete5 CMS?
|
wordpress
|
I've managed create a metabox that lets me upload and then fetch the images and then also been able to add jquery ui sortable to be able to sort the images, however I've no idea how to add actual functionality so that the sort order get saved. If someone has an idea how to achieve this or some tutorial that would be helpful, please share, I'm helplessly stuck here. Thanks. Edit: Basically, what I need to know is how to tie jQuery sortable together with the functionality that handles the different attachments menu_order.
|
To save the menu order use <code> wp_update_post() </code> with each attachment ID and its new menu position: <code> $thisattachment = array(); $thisattachment['ID'] = $thisid; $thisattachment['menu_order'] = $new_menu_position; wp_update_post($thisattachment); </code> EDIT - assuming these are already attachments and you're updating them? Otherwise you have to insert the attachments first with wp_insert_attachment
|
Control attachments menu order with jQuery Sortable
|
wordpress
|
I am moving an entire site from html and dreamweaver format to wordpress. I imported the content using htlm import plugin that worked well. Now I have to correct all content links as they kept the same variable url format applied by dreamweaver and as I have changed the dite directory structure, most of them are broken now. Basically, my issue is the following: 1) OLD site internal links urls (dreamweaver): <code> <a href="page.html">page</a> </code> 2)Now, in WP, the correct url for it would be: <code> <a href="/parentpage/page/">page</a> </code> I am using BrokenLinks and Search&Replace plugins to correct them and my questions are: Should i replace the old url (1 above) to: <code> a) <a href="/parentpage/page/">page</a> (2 above), or b) <a href="/page/">page</a> ( I noticed that even though it is not the final full url (parent page and page), a link with this url works well in WP, probably due any redirect rules. </code> Even though both will finally work, I want to know if: What should be the format (a or b above) I should use to replace the old ones to avoid problem in case I decide to modify the parent page, for example, from "/parentpage/page/" to "/parentpageX/page/"? My doubt is if I use the option "b" to replace the old one, if I change the parent page some time, this link would become broken again? What is the better option take into account SEO? Do you suggest any better method to handle this old broken url issue? Thanks in advance for any help
|
I would use #2 (/parentpage/page/), since that's the 'official' URL WP assigned to it, WP will find the right page faster and it may help you with your SEO. Yes, if you change slugs it will be a broken link, you could use the Redirection plugin for that (it has the option to add a redirection from the old slug to the new slug, I believe it's activated by default).
|
Replacing broken urls (dreamweaver) to new ones in wordpress
|
wordpress
|
Im using wordpress together with qtranslate and it works on pages and post but not in menus, widgets etc. So i created jquery scripts to solve those issues. The problem is that the field "link_description" in wordpress link section is limited to 30. Using two languages or more, 30 characters is not enough. Is it possible to change or even remove this property without modifying any core files?
|
First of all, "link description" is defined in the database structure as VARCHAR(255), and I don't think there's anything in core limiting the size of the field farther. Are you sure that you can't fit more than 30 characters in your bookmark descriptions? That said, 255 characters can still be small if you are trying to fit several different language translations into the field. However, there's nothing stopping from you from simply redefining the column type in MySQL so that it can hold more data. Defining that field as "TEXT" would let you store up to 64K in it, and you wouldn't have to modify any core files to take advantage of that change.
|
Change maxlength of link_description in dashbord link section?
|
wordpress
|
I noticed that when starting to create a new post, and only attach images and then when leavning the post for some reason, it won't show up in the list post view. However when you look in the Media Library you'll see that the image is attached to "Auto Draft" and that the post really exists. Now, I find this useful, and would like to be able to list these Auto Drafts in the post view, but I don't really know what I need to do to list them.. Ideas?
|
try pasting this in your theme's functions.php file <code> add_filter( 'parse_query', 'display_autosave_and_revisions' ); function display_autosave_and_revisions( $query ) { global $pagenow,$typenow; if ( is_admin() && $pagenow == 'edit.php' && $typenow == "post") { $query->query_vars['post_type'] = array('revision','post'); $query->query_vars['post_status'] = 'any'; } } </code>
|
How to list "invisible" Auto Drafts?
|
wordpress
|
Just putting my feelers out on this one, I need to be able to accept incoming emails and add them as posts, however I want to be able to do a bit of processing first, for example I want to change the slug, prepend a string to the title etc. Is there a way I can hook into the email function, change some data and then let it continue. I also might want to reject the email if it isn't sent from an approved domain (this will be a field in a custom post type). Are my requirements achievable or am I barking up the wrong tree? Edit I have discovered the <code> save_post </code> hook, although it fires after the post has saved... not really what I'm looking for. Is there a hook that gets fired before a post is saved, giving me all the info about the post, especially where it's been created from. Edit 2 Alternatively is there a way to add a post manually... so I handle the receiving of the email with my own code + cron, then have an API to create a new post with?
|
If you dig into the code of postie (plugin) , you'll probably find your answer. In particular, see the filter sample files, and then trace backwards from there. From the FAQ: Can I add special text to the body of the post when using postie? , Yes. You can create your own function, and use the postie_post filter. Two short examples are included in the filterPostie.php.sample file Of note - per this ticket: post by email is slated to be dropped from WP core and switched over to a plugin, so you might be better-off switching to a plugin-based solution now, rather than building your functionality around the current core post by email functionality.
|
Extending post by email
|
wordpress
|
I'd like to replace my: <code> if(is_home()) { wp_enqueue_script( 'homestuff', get_theme_part( THEME_JS . '/home.js' ), array( 'jquery' ), null, true ); wp_enqueue_script( 'jquerycolor', get_theme_part( THEME_JS . '/jquery.color.js' ), array( 'jquery' ), null, true ); }; </code> Which is currently in header.php, by putting it in a functions.php file instead. Trying to tidy everything up on a sprawling client's site. I'm using wp-framework and ideally would stick this inside the enqueue_assets function in the main parent_theme class. Although this isn't really a wp-framework issue, I'd just like to know: How can I get is_home() to work from a functions file? Is there an alternative, using globals, I need to know about?
|
First, if you want to target the site Front Page , you need to use <code> is_front_page() </code> . The <code> is_home() </code> conditional returns true when the blog posts index is displayed, which may or may not be on the site Front Page . Second, you need to hook your function into an appropriate hook, which it appears in this case is <code> wp_enqueue_scripts </code> . (Also: what is <code> get_theme_part() </code> ? Is it a custom function in WP Framework?) For example, you can do this in <code> functions.php </code> : <code> function mytheme_enqueue_front_page_scripts() { if( is_front_page() ) { wp_enqueue_script( 'homestuff', get_theme_part( THEME_JS . '/home.js' ), array( 'jquery' ), null, true ); wp_enqueue_script( 'jquerycolor', get_theme_part( THEME_JS . '/jquery.color.js' ), array( 'jquery' ), null, true ); } } add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_front_page_scripts' ); </code>
|
Wordpress Enqueue for homepage only, functions.php, wp-framework
|
wordpress
|
Its that possible?Than when something is added to page in admin panel, page link to that page appears.
|
I think you would need to implode(',',$excluded_pages) for things to work, <code> $excluded_pages = array(); $all_pages = get_pages(); foreach ( $all_pages as $the_page ) { if ( '' == $the_page->post_content ) { $excluded_pages[] = $the_page->ID; } } wp_list_pages( array( 'exclude' => implode(',',$excluded_pages) ) ); </code> EDIT
|
Hide links to pages that dont have any content
|
wordpress
|
I'm trying to enqueue a JS script only when someone is adding or editing a custom post type I created called "recipes". Currently the script works ok when I do this: <code> if (is_admin()){ wp_enqueue_script( 'my-script' ); } </code> But this loads it in every admin page, I'm assuming I need to hook it to a function but I hvae no idea what it'd be. Thanks in advance!
|
You can do it like this (put in your <code> functions.php </code> ) : <code> function add_admin_scripts( $hook ) { global $post; if ( $hook == 'post-new.php' || $hook == 'post.php' ) { if ( 'recipes' === $post->post_type ) { wp_enqueue_script( 'myscript', get_stylesheet_directory_uri().'/js/myscript.js' ); } } } add_action( 'admin_enqueue_scripts', 'add_admin_scripts', 10, 1 ); </code>
|
How to enqueue scripts on custom post add/edit pages?
|
wordpress
|
Hopefully a basic question, but one that plagues me nonetheless. I have a couple of self-hosted WordPress installs on my website. An issue that I have is that I have common users registered for each site....however some of them feel its a pain to have to go through the signup process each time, and have to juggle multiple accounts in order to comment. Is it possible to commonize accounts, for instance simply using a WP.com/org account and accessing my blogs in that manner?
|
I think WordPress. com is an OpenID Provider , meaning that you can use the OpenID Plugin, and allow users to use their WPCOM account to register/login to your site. As far as I know, WordPress. org is not an OpenID Provider (though that would be a neat idea!).
|
Allowing WordPress.org/com accounts on a self-hosted install
|
wordpress
|
For some strange reason, comments aren't being displayed when a user is not logged in. I've done some extensive experimenting with comments.php without any success. Here's a reference to the example page: http://gycweb.org/by-this-will-all-men-know/ If you are logged in, you would see 3 comments. If you are not logged in, nothing but the form. Also, to add to the mystery, when "editing" the post from within the admin and clicking "show comments", it tries and is not able to load the comments. It appears that the "have_comments" conditional is failing for logged out users. I've also tried getting wp_list_comments to return the list with no success. I've checked for plugin conflicts and nothing obvious yet. Have any of you run into this? Any obvious answers?
|
Toscho was right. I wound up having a query that was getting in the way. It took a bit of troubleshooting to figure out, but I nailed it. If you run into similar issues, look carefully for any custom queries you may have on the template and make sure that you've wrapped them up properly.
|
have_comments not true for logged out visitors?
|
wordpress
|
I created two custom taxonomies (Majors and Seminar Types) related my custom post type CEMB Seminar and the labels on the menu, instead of showing the labels I put in are showing "Post Tags". See a screenshot here (I don't have enough reputation to post pics yet): https://picasaweb.google.com/112518288555484095597/WordPressIssues?authuser=0&authkey=Gv1sRgCNeKmKmS2J_ccQ&feat=directlink Here's the code I used to create the custom taxonomies: <code> // Register the Majors taxonomy register_taxonomy( 'cemb_seminar_major', array( 'cemb_seminar' ), $major_args ); // Register the Seminar Types taxonomy register_taxonomy( 'cemb_seminar_type', array( 'cemb_seminar' ), $types_args ); // Set up the Majors arguments $major_args = array( 'rewrite' => array( 'slug' => 'major', 'with_front' => 'false' ), 'labels' => array( 'name' => 'Majors', 'singular_name' => 'Major' ) ); // Set up the Types arguments $types_args = array( 'rewrite' => array( 'slug' => 'seminar-type', 'with_front' => 'false' ), 'labels' => array( 'name' => 'Seminar Types', 'singular_name' => 'Seminar Type' ) ); </code> I thought maybe since I didn't include all the labels, it wasn't creating the labels correctly, so I later added: <code> 'labels' => array( 'name' => _x( 'Majors', 'taxonomy general name' ), 'singular_name' => _x( 'Major', 'taxonomy singular name' ), 'search_items' => __( 'Search Majors' ), 'popular_items' => __( 'Popular Majors' ), 'all_items' => __( 'All Majors' ), 'edit_item' => __( 'Edit Major' ), 'update_item' => __( 'Update Major' ), 'add_new_item' => __( 'Add New Major' ), 'new_item_name' => __( 'New Major' ), 'separate_items_with_commas' => __( 'Separate majors with commas' ), 'add_or_remove_items' => __( 'Add or remove majors' ), 'choose_from_most_used' => __( 'Choose from the most popular majors' ) ) </code> and <code> 'labels' => array( 'name' => _x( 'Seminar Types', 'taxonomy general name' ), 'singular_name' => _x( 'Seminar Type', 'taxonomy singular name' ), 'search_items' => __( 'Search Seminar Types' ), 'popular_items' => __( 'Popular Seminar Types' ), 'all_items' => __( 'All Seminar Types' ), 'edit_item' => __( 'Edit Seminar Type' ), 'update_item' => __( 'Update Seminar Type' ), 'add_new_item' => __( 'Add New Seminar Type' ), 'new_item_name' => __( 'New Seminar Type' ), 'separate_items_with_commas' => __( 'Separate seminar types with commas' ), 'add_or_remove_items' => __( 'Add or remove seminar types' ), 'choose_from_most_used' => __( 'Choose from the most popular seminar types' ) ) </code> But neither changed helped. I noticed my custom post type also didn't have all the labels customized, so I added the labels to that code and the menu changed to reflect the newly added labels, but the custom taxonomies won't do that. What did I do wrong and how do I fix it?
|
Try changing <code> 'labels' </code> to an array arg, and passing that. Also, check for syntax: <code> $labels => array( 'name' => _x( 'Seminar Types', 'taxonomy general name' ), 'singular_name' => _x( 'Seminar Type', 'taxonomy singular name' ), 'search_items' => __( 'Search Seminar Types' ), 'popular_items' => __( 'Popular Seminar Types' ), 'all_items' => __( 'All Seminar Types' ), 'edit_item' => __( 'Edit Seminar Type' ), 'update_item' => __( 'Update Seminar Type' ), 'add_new_item' => __( 'Add New Seminar Type' ), 'new_item_name' => __( 'New Seminar Type' ), 'separate_items_with_commas' => __( 'Separate seminar types with commas' ), 'add_or_remove_items' => __( 'Add or remove seminar types' ), 'choose_from_most_used' => __( 'Choose from the most popular seminar types' ) ); // Set up the Types arguments $types_args = array( 'rewrite' => array( 'slug' => 'seminar-type', 'with_front' => 'false' ), 'labels' => $args ); // Register the Seminar Types taxonomy register_taxonomy( 'cemb_seminar_type', array( 'cemb_seminar' ), $types_args ); </code>
|
Custom taxonomy labels won't display
|
wordpress
|
There're lots of examples both here and on the internet, I've tried but don't seem to be able to achieve what I need although it does feel like it should be simple enough. Basically, I want to be able to use a shortcode like this: <code> [download]http://site.com/file.doc[/download] </code> and I need Wordpress to output this: <code> <a class="download" href="http://site.com/file.doc">download file</a> <a class="download" href="http://docs.google.com/viewer?embedded=true&url=http://site.com/file.doc">preview file</a> </code> Your help would be greatly appreciated. Thanks so much!
|
<code> // Declare your shortcode add_shortcode("download", "downloadFunction"); // Second Declare your shortcode function function downloadFunction($att, $content, $code){ // your function is passed 3 Arguments // $atts : this is an array of the shortcode's attributes // $content : this is the content between the code. in your case the file url. // $code : this is the code used. in this case it will be download. // here we only need the $content of the shortcode which we place for the file $return = '<a class="download" href="'.$content.'">download file</a>'; $return .= '<a class="download" href="http://docs.google.com/viewer?embedded=true&url='.$content.'">preview file</a>'; // we then return the result. return $return; } </code>
|
Create a shortcode in Wordpress, again
|
wordpress
|
Right now I'm using a code in the functions to override the default WordPress gallery CSS. But it seems for some reason that WP only wants to let me put 3 images per line in a gallery, despite my CSS. Anybody know how to fix this? My problem can be found here -> http://themeforward.com/demo2/features/gallery-2/ and my CSS is below. <code> /*//////////////////////////////////////////////////////////////////// // Gallery ////////////////////////////////////////////////////////////////////*/ .gallery { margin:30px 0 auto!important; text-align:center; width:680px; overflow:hidden; background:#1a1a1a } .gallery-item { float:left; text-align:center; background:#000 } .gallery img { display:inline } .gallery img:active { } .gallery-caption { display:none; font-size:.8em; margin-left:0 } .gal_img { margin:20px auto 0!important; text-align:center } .gal_caption p { font-size:1.3em!important; font-weight:640; text-align:center; font-family:Arial, Helvetica, sans-serif!important } .gal_description p { font-size:1.1em!important; text-align:center } </code> EDIT: <code> //////////////////////////////////////// Gallery add_filter('gallery_style', create_function( '$css', 'return preg_replace("#<style type='text/css'>(.*?)</style>#s", "", $css);' ) ); //////////////////////////////////////// Remove default gallery styling add_filter( 'use_default_gallery_style', '__return_false' ); </code>
|
You have to account for all appropriate CSS classes, based on the number of columns passed to the shortcode. Here's my CSS (borrowed heavily from Michael Fields), for handling from 1 to 10 columns: <code> .gallery { margin: 0px auto; text-align: center; width: 100%; min-width: 100%; } .gallery .gallery-item { float: left; margin: 0px auto; text-align: center; } .gallery img { border: 1px solid #cfcfcf; } .gallery .gallery-caption { display: none; } .gallery-columns-1 .gallery-item { max-width: 638px; width: 638px; } .gallery-columns-1 .gallery-item img { max-width: 600px; height: auto; max-height: 600px; } .gallery-columns-2 .gallery-item { max-width: 300px; width: 300px; } .gallery-columns-2 .gallery-item img { max-width: 300px; height: auto; max-height: 300px; } .gallery-columns-3 .gallery-item { max-width: 200px; width: 200px; } .gallery-columns-3 .gallery-item img { max-width: 200px; height: auto; max-height: 200px; } .gallery-columns-4 .gallery-item { max-width: 151px; width: 151px; } .gallery-columns-4 .gallery-item img { max-width: 150px; height: auto; max-height: 150px; } .gallery-columns-5 .gallery-item { max-width: 120px; width: 120px; } .gallery-columns-5 .gallery-item img { max-width: 120px; height: auto; max-height: 120px; } .gallery-columns-6 .gallery-item { max-width: 100px; width: 100px; } .gallery-columns-6 .gallery-item img { max-width: 100px; height: auto; max-height: 100px; } .gallery-columns-7 .gallery-item { max-width: 85px; width: 85px; } .gallery-columns-7 .gallery-item img { max-width: 85px; height: auto; max-height: 85px; } .gallery-columns-8 .gallery-item { max-width: 75px; width: 75px; } .gallery-columns-8 .gallery-item img { max-width: 75px; height: auto; max-height: 75px; } .gallery-columns-9 .gallery-item { max-width: 67px; width: 67px; } .gallery-columns-9 .gallery-item img { max-width: 67px; height: auto; max-height: 67px; } .gallery-columns-10 .gallery-item { max-width: 60px; width: 60px; } .gallery-columns-10 .gallery-item img { max-width: 60px; height: auto; max-height: 60px; } </code> EDIT Here you can see an example of the markup and styles being applied , from calling the following in the Post Content: <code> [gallery columns="1"] [gallery columns="2"] [gallery columns="3"] [gallery columns="4"] [gallery columns="5"] [gallery columns="6"] [gallery columns="7"] [gallery columns="8"] [gallery columns="9"] [gallery columns="10"] </code>
|
Gallery CSS Problem
|
wordpress
|
There are certain posts on the website I'm developing, that don't need the author(s) by-line. (such as press releases) Is there any method, that allows me to remove the author (and co-authors) for certain posts?
|
Thanks to mike23's suggestion, I solved my problem with conditional tags. Just insert the following in the author area of <code> single.php </code> , <code> archive.php </code> and any other page template that displays an author. <code> <?php if ( has_tag('press_releases') ) { echo ''; } else { echo 'by '; the_author_posts_link(); } ?> </code> Using the above code, you can remove the author name on all posts tagged <code> press_releases </code> . All posts without the tag <code> press_releases </code> will retain their author name.
|
How To Remove The Author(s) From Certain Posts
|
wordpress
|
My site has Facebook social graph meta tags in its page: <code> <meta property="og:title" content="First Look at Dwarves from The Hobbit"/> <meta property="og:description" content="Movie"/> </code> The only Facebook-related plugin I have installed Facebook Page Publish . Why is it only picking up the category of the post? There are no options to configure the og meta tags of this plugin. UPDATE I now figure I can use the post excerpt as the value for og:description, but whenever I use either of these functions: get_the_excerpt(); the_excerpt(); the page outputs the following code: <code> <!-- AddThis Button Begin --> <script type="text/javascript">var addthis_product = 'wpp-261'; var addthis_config = {"data_track_clickback":true,"ui_508_compliant":true};</script> <script type="text/javascript" src="//s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4df74bc61d613ae9"></script>"/> </code> I then configured the AddThis Wordpress plugin to remove Add This from the post excerpt, but the same code is still spat out by the excerpt functions.
|
The Facebook Page Publish plugin is adding the og:description. Looking through the code in fpp_index.php at lines 843 - 851: <code> $description = array(); if ($options['show_post_author']) { $description[] = esc_attr(fpp_get_post_author($post));/*, ENT_COMPAT, 'UTF-8')*/ } if ($options['show_post_categories']) { $categories = esc_attr(fpp_get_post_categories($post));/*, ENT_COMPAT, 'UTF-8')*/ if (!empty($categories)) $description[] = $categories; } echo '<meta property="og:description" content="'.implode(' | ', $description).'"/>'; </code> It appears that you have only checked the "post categories" option and have unchecked "post author" on the plugin admin page . See this screenshot . That's the option the plugin is using the generate the og:description.
|
What is generating my meta og:description?
|
wordpress
|
is it possible to create a loop of posts using WP_Query or query_posts using the title? ie <code> $args = array('post_title'='LIKE '.$str.'% '); $res = WP_Query($arg); // the loop... // trying this now... $mypostids = $wpdb->get_col("select ID from $wpdb->posts where post_title like 'Abb%' "); echo count($mypostids).", "; // works but can't echo out array of IDs for the next args? $args = array( 'post__in'=> $mypostids ); $res = WP_Query($args); while( $res->have_posts() ) : $res->the_post(); ... </code>
|
got this working with the help from this post in the end. Cheers guys; <code> $finalArgs = array ( 'posts_per_page'=>5, 'order' => 'ASC', 'post_type' => 'school' ); // Create a new instance $searchSchools = new WP_Query( $finalArgs ); $mypostids = $wpdb->get_col("select ID from $wpdb->posts where post_title LIKE '".$str."%' "); $args = array( 'post__in'=> $mypostids, 'post_type'=>'school', 'orderby'=>'title', 'order'=>'asc' ); $res = new WP_Query($args); while( $res->have_posts() ) : $res->the_post(); global $post; $EstablishmentNumber = get_post_meta($post->ID,'EstablishmentNumber', true); $schl = array('id'=>$EstablishmentNumber, 'label'=>$post->post_title , 'value'=>$EstablishmentNumber ); $matchedSchools[] = $schl; endwhile; </code>
|
query_post by title?
|
wordpress
|
What is the best way to modify a plugin? I frequently want to make small changes to one or two functions within a large plugin. This is easily done, but I have to use comments to mark my changes and modify the plugin again after an update. Ideally I'd like to leave the plugin alone and make my changes elsewhere, much like we do with themes and child themes. Can I make a plugin that requires the parent plugin and will override it?
|
IMHO, the best approach is either to fork the Plugin to maintain your changes, or else submit patches to the Plugin developer, to have your changes made a part of the original Plugin. Creating a "Child Plugin" really isn't easy. The "Child Theme" concept really applies to the template files that get used, moreso than the Theme functions (and in fact, the <code> functions.php </code> file from both Parent and Child get loaded, which does cause problems for improperly coded <code> functions.php </code> files in either the Child or Parent Theme).
|
Proper Way to Modify Plugin
|
wordpress
|
Function to list all post slugs for every post in wp_posts table? I assume there's an official function to generate a post slug, but maybe someone here already has the answer.
|
example - unordered list with post slugs: <code> <ul> <?php foreach( get_posts('numberposts=-1') as $post ) { echo '<li>' . $post->post_name . '</li>'; } ?> </ul> </code> http://codex.wordpress.org/Template_Tags/get_posts
|
Function to list all post slugs for every post in my WP database?
|
wordpress
|
I'd like to prevent certain user roles from accessing the dashboard http://www.openeye.net/wp-admin/ at all. I've moved and restyled user profiles to a new page that's viewable on the site. How would I go about doing this?
|
To lock subscribers and contributors out of the admin: <code> function wpse23007_redirect(){ if( is_admin() && !defined('DOING_AJAX') && ( current_user_can('subscriber') || current_user_can('contributor') ) ){ wp_redirect(home_url()); exit; } } add_action('init','wpse23007_redirect'); </code> Hope that helps. All roles give the user a capability that is the name of that role, so you can use any role name as a capability.
|
How do I remove dashboard access from specific user roles?
|
wordpress
|
I want to get the page content (so i can parse the tags/short-codes in it), but i don't want to output the result itself to the browser (i.e. echo=0). I tried get_the_content(); but its the same deal.
|
Where are you doing your code parsing? If you're doing it directly in the template file, inside the Loop, then you should be using <code> get_the_content() </code> . However, it might be more efficient to filter <code> the_content() </code> , via the <code> the_content </code> filter. e.g. in <code> functions.php </code> : <code> function mytheme_filter_the_content( $content ) { // add code here to filter the_content // which is contained in the $content variable, // then return $content return $content; } add_filter( 'the_content', 'mytheme_filter_the_content' ); </code> EDIT If, for whatever reason, you just want to parse <code> the_content() </code> , pull out the shorcodes, and execute them, use <code> do_shortcode() </code> ( Codex ref ). e.g.: <code> <?php $page_content = get_the_content(); $page_shortcodes = array() // ...some array that includes whatever shortcodes you found foreach ( $page_shortcodes as $page_shortcode ) { do_shortcode( $page_shortcode ); } ?> </code>
|
Get the Page Content,without generating HTML
|
wordpress
|
Well, i'm creating a wordpress theme, but i can't get wordpress loop to work correctly for some reason. This code works fine in index.php : <code> <?php if (have_posts()) : while (have_posts()) : the_post(); var_dump($post); endwhile; endif; ?> </code> But, it does not work in my blog.php page(it's not a template, it's actually a shortcode). The shortcode works correctly for sure. But when the above code is executed it just prints NULL. If i try to grab the_content, the page loops indefinitely. Any idea why this can be happening ?
|
Within your blog.php file you need to declare <code> <?php wp_head(); ?> </code> without this the loop will not work and only so many items within <code> $post </code> will be available to you.
|
Wordpress loop not working on blog.php page
|
wordpress
|
When creating a new network site, by default the site option <code> Uploads Use Yearmonth Folders </code> is on (set to <code> 1 </code> ). I have to set it to <code> 0 </code> each time I create a new site. This isn't horrid, but is it possible to make this the default for newly created sites? Perhaps a hook or something I am overlooking?
|
You could just change the option after the blog is created: <code> add_action('wpmu_new_blog', function($blog_id){ switch_to_blog($blog_id); update_option('uploads_use_yearmonth_folders', false); restore_current_blog(); }); </code> Drop this code into a .php file inside wp-content/mu-plugins
|
How can I have network sites not use year/month folders by default?
|
wordpress
|
I have installed XAMPP to build a site on localhost. After I finish, how do I transfer everything efficiently to, say, a client's server?
|
See Moving WordPress « WordPress Codex and Backing Up Your Database « WordPress Codex and How to Move WordPress Blog to New Domain or Location » My Digital Life and possibly Giving WordPress Its Own Directory « WordPress Codex Deleted this added link as it advocates using a texteditor to change URLs in the dump; that will break serialized data. Use the SQL statements in How to Move WordPress Blog to New Domain or Location above. See stackexchange-url ("Why is my database import losing text widget data?")
|
After finishing building a site on localhost, how do I transfer everything to a client's server?
|
wordpress
|
I have a widget <code> class Xwidget extends WP_Widget{ function cron_addB(){} } </code> I want to run a cron job that calls that function from outside the class <code> function xxx_cron_activation() { ; if ( !wp_next_scheduled( 'xxx_followers' ) ) { wp_schedule_event(time(), 'hourly', 'xxx_followers'); } } add_action('wp', 'xxx_cron_activation'); add_action('xxx_followers',array('Xwidget',"cron_addB")); </code> Cron is being triggered but the function is not being executed
|
Try this instead: <code> $gloabl $myxclass; $myxclass = new Xwidget(); add_action( 'xxx_followers', array(&$myxclass, "cron_addB" ) ); </code> or <code> add_action('xxx_followers', "init_xclass_and_cron"); function init_xclass_and_cron() { $myxclass = new Xwidget(); $myxclass->cron_addB(); } </code>
|
Calling static method in the Widget Class
|
wordpress
|
I've built a small widget for my website It has a couple of inputs, and a <code> <textarea> </code> among others. Whenever someone inputs to the textarea it adds a tab at the begining and changes every ' to ' After a couple of times I save the same input, I just get sentences that were It's nice to It\\\'s nice the code for the Textrea: <code> <textarea rows="5" cols="40" id="cat_<?php echo $i ?>_text" name="cat_<?php echo $i ?>_text"> <?php echo $text ?> </textarea> </code> Any ideas?
|
Try stripslashes to remove the backslash. <code> echo stripslashes( $text ); </code> This is going to replace one slash per slashes group only though, you should first reset all the contents that have multiple slashes. I guess the tab at the beginning is due to the fact that you jump a line before echoing the text. Try this instead : <code> <textarea rows="5" cols="40" id="cat_<?php echo $i ?>_text" name="cat_<?php echo $i ?>_text"><?php echo stripslashes( $text ); ?></textarea> </code>
|
Widget textarea input gets formatted
|
wordpress
|
is possible to get images added to a post programmatically? I am working on custom template (my first) and I need to display Images added to a post in specific way.(first image as title image and the rest of imgs only render into hidden img tags (will be visible through lightbox slideshow). So is there any function like <code> get_post_attachments('type'=>'image') </code> whose output I would be able to iterate over a loop? Thanks for your help
|
You can use <code> get_posts() </code> ( Codex ref for getting Post attachments ). <code> <?php $args = array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID ); $attached_images = get_posts( $args ); ?> </code>
|
How to get Images included in Post
|
wordpress
|
I have a custom post type, I am echoing out my custom taxonomies in my template by doing the following, <code> get_the_term_list( get_the_ID(), 'work', '<li>', "", '</li>') </code> , this currently returns "Design", what I am wanting to do, is the following, for the first value that it is found I want to do the following, <code> <li><a href="the taxonomies link"> Find out more about Taxonomy Name</a></li> </code> for the second value (if there is a 2nd) I would like the do the following <code> <li><a href="the taxonomies link">How Taxonomy Name can benefit you</a></li> </code> Basically how ever many taxonomies there I only want to show 2 and I want to be able to use them as above? Is this even possible?
|
I would use <code> wp_get_object_terms </code> which will return an array of object terms that you can manipulate. You also have a little more control with sorting the terms. <code> <?php $terms = wp_get_object_terms($post->ID, 'work', array('orderby' => 'name', 'order' => 'ASC')); if(is_array($terms)) : ?> <ul> <?php if(isset($terms[0])) : ?><li><a href="<?php echo get_term_link($terms[0]); ?>">Find out more about <?php echo $terms[0]->name; ?></a></li><?php endif; ?> <?php if(isset($terms[1])) : ?><li><a href="<?php echo get_term_link($terms[1]); ?>">How <?php echo $terms[1]->name; ?> can benefit you</a></li><?php endif; ?> </ul> <?php endif; ?> </code> Obviously, this is not a very dynamic solution and will only work for your first two terms, but these functions should help you sort out the correct solution for you.
|
get_the_term_list() wanting to loop through the returned values
|
wordpress
|
I want to get a sidebar and save it in a Variable, This is impossible with the get_sidebar function since it simply prints out the sidebar, is there another function that I can use?
|
You probably need to use output buffering , if I understand your question correctly. Try something like this: <code> ob_start(); dynamic_sidebar('sidebar-id'); $sidebar = ob_get_contents(); ob_end_clean(); </code> That will put the output of the sidebar into the variable $sidebar, which you can then process and return from your filter on the page content.
|
how do I get_sidebar into a varaible?
|
wordpress
|
I'm using this in a file named category-portfolio.php which is for the archives page of my portfolio. I don't want to use cat= to specify a specific category. But when I don't use cat= it pulls up every post regardless of category. How do I make this code pull up only the current/relevant/portfolio category? Thanks a million! <code> <?php get_header(); ?> <div id="container"> <div id="portfolio_content"> <!-- Grab posts --> <?php query_posts('posts_per_page=9&paged='.$paged); if (have_posts()) : ?> <div id="portfolio_wrap"> <?php while (have_posts()) : the_post(); ?> <!-- Get the image --> <div class="img"> <a href="<?php the_permalink() ?>"> <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-portfolio' ); } ?> <!-- Excerpt title --> <span class="title"><?php the_title(); ?></span></a> <!-- Excerpt description --> <div class="desc"><?php my_excerpt('short'); ?></div> </div> <?php endwhile; ?> <!-- Next/Previous Posts --> <?php if (function_exists("pagination")) { pagination($additional_loop->max_num_pages); } ?> </div> <!-- #portfolio_wrap --> <?php endif; ?> </div> <?php get_sidebar(); ?> </div> </div> <?php get_footer(); ?> </code>
|
The problem is that your call to query_posts is overwriting the original query for the page. You have to get the original query, then modify any params from there. <code> global $query_string; // start with the original query $myquery = wp_parse_args($query_string); // make any changes to the query here $myquery['posts_per_page'] = 9; query_posts($myquery); </code>
|
Call Current Category
|
wordpress
|
I am trying to call in all posts in the current category, showing their thumbnail or 'featured image'. The code below does not work, it throws out a syntax error... <code> <?php $temp_query = $wp_query; ?> <?php foreach(get_the_category() as $category) { $cat = $category->cat_ID; } query_posts('orderby=date&cat=' . $cat . '&order=ASC&posts_per_page=-1''); ?> <?php while (have_posts()) : the_post(); ?> <div class="page-thumb-wrap-single"> <?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } else { echo '<img src="#" alt="Something Went Wrong?" title="Sorry - Something went wrong?" />'; } ?> </div> <?php endwhile; ?> </code> ...however, this code does retrieve the thumbnail; <code> <?php $temp_query = $wp_query; ?> <?php foreach(get_the_category() as $category) { $cat = $category->cat_ID; } query_posts('orderby=date&cat=' . $cat . '&order=ASC&posts_per_page=-1''); ?> <?php while (have_posts()) : the_post(); ?> <div class="page-thumb-wrap-single"> <?php the_post_thumbnail(); ?> </div> <?php endwhile; ?> </code> Can someone explain to me what it is i am doing wrong and why this occurs? It may also help me answer another question; How can i create a condition inside this call to say 'if post has tag... do... if post has other tag... do...' Thanks guys!
|
the two single quote marks (after the number 1) in this line (of the top posted code section) seem to be causing the error - there should only be one single quote; shown below: <code> query_posts('orderby=date&cat=' . $cat . '&order=ASC&posts_per_page=-1'); </code> it is just puzzling that your other code (with the same error) alledegly does work (?) if this is not the cause: what was the exact syntax error message?
|
query_posts thumbnail condition
|
wordpress
|
Is there a reliable plugin that I could use to automatically backup the WP database? It's really important that it's just the database and not the files. I'd like it to automatically download a copy of the database and store it on my computer in a specified file. Is there one out there that could do this?
|
BackWPup has a lot of flexibility in timing, what to backup (down to the DB table level), and it can store to DropBox which would put it on your computer.
|
Plugin for automatic database backup?
|
wordpress
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.