learnthat
Forum Replies Created
-
I’m not sure, I used this on a client project and haven’t looked at this in a long time. Have you tried using it in a widget? I think the changes I made would only allow you to filter by custom post type when used in a widget.
Forum: Fixing WordPress
In reply to: OEmbed and Custom FIeldHi joehuffman2,
I wanted the same thing and achieve it using this code in my single.php file:
<?php echo wp_oembed_get( get_post_meta($post->ID, "videourlcustom", true) ); ?>
In the example, videourlcustom is the name of the custom field which contains the URL for what you want to embed.
If you want to put it somewhere else, just change $post->ID to the ID of the post you want to query – for example, if you were going to place it in a sidebar widget. In this example, it should be inside the loop.
I hope this helps!
Forum: Fixing WordPress
In reply to: oEmbed auto embed function for custom fields/themes?Hi lilqhgal,
I wanted the same thing and achieve it using this code in my single.php file:
<?php echo wp_oembed_get( get_post_meta($post->ID, "videourlcustom", true) ); ?>
In the example, videourlcustom is the name of the custom field which contains the URL for what you want to embed.
I hope this helps!
One caveat that I didn’t think of: the exclude categories portion of the widget likely won’t work with custom post types in their current form. Custom post types have the ability to create custom taxonomies, but I’m sure querying based on those taxonomies use slightly different code. This may be something I need in the future and I’ll address it at some point.
I believe, you would have to provide an additional option and change this line:
WHERE x.taxonomy = 'category'
to dynamic based on the taxonomy selected.
I posted a link the full version of this file here: https://jerm.com/wordpress-popular-posts.php.txt
Please let me know if you decide to use this – otherwise I will need to fork it so the end users do not accidentally upgrade some day and lose these changes. I appreciate all your hard work,
Thanks!
JeremyHi Ikki,
It actually wasn’t too difficult to update the plug-in to support custom post types. Here’s what I did – if you’d like, I can send you the file.
General steps:
- Remove the current post/page options.
- Query the public custom post types and generate a select list.
- Add in support for the option.
- Change $nopages to the new SQL query variable based on the value of the post type select field.
Actual code:
Comment out this line:
//$instance['pages'] = $new_instance['pages'];
Add this line around line 172:
$instance['posttype'] = $new_instance['posttype'];
Comment out this line in the form function:
//'pages' => true,
Add in this line in the form function around line 219:
'posttype' => 'all',
Delete the checkbox section for ‘pages’ on the form.
Add this code to the form for the widget above the thumbnail section:
<fieldset class="widefat"> <legend><?php _e('Select Post Types', 'wordpress-popular-posts'); ?></legend> <select id="<?php echo $this->get_field_id( 'posttype' ); ?>" name="<?php echo $this->get_field_name( 'posttype' ); ?>"> <option value="all"<?php if ( $instance['posttype'] == "all" ) : ?> selected="selected"<?php endif; ?>><?php _e('All', 'wordpress-popular-posts'); ?></option> <option value="pagesposts"<?php if ( $instance['posttype'] == "pagesposts" ) : ?> selected="selected"<?php endif; ?>><?php _e('Posts and Pages', 'wordpress-popular-posts'); ?></option> <?php // Thank you to John James Jacoby for this code from post-type-switcher $safe_filter = array( 'public' => true, 'show_ui' => true ); $post_types = get_post_types( (array)$safe_filter ); foreach ( $post_types as $post_type ) { $pt = get_post_type_object( $post_type ); ?> <option value="<?php echo $pt->name; ?>"<?php if ( $instance['posttype'] == $pt->name ) : ?> selected="selected"<?php endif; ?>><?php echo $pt->label; ?></option> <?php } ?> </select> </fieldset> <br />
Near the top of the get_popular_posts function, add this code and comment out the old code:
// Support custom post types if ( $instance['posttype'] == 'all' ) { $nopages = ''; } else { if ( $instance['posttype'] == 'pagesposts' ) { $nopages = "AND ($wpdb->posts.post_type = 'post' OR $wpdb->posts.post_type = 'pages')"; } else { $nopages = "AND $wpdb->posts.post_type = '" .$instance['posttype'] . "'"; } } // Deprecated with post-type support above //if ( $instance['pages'] ) { // $nopages = ''; //} else { // $nopages = "AND $wpdb->posts.post_type = 'post'"; //}
If you see anything I did wrong, please let me know, but it seems to work fine. Thanks for creating such a great, easy to use plug in.
Jeremy
Forum: Alpha/Beta/RC
In reply to: Installing 3.0 on iis.I was receiving a similar error – I changed the parent directory (above the directory WordPress is installed in) by adding the local IUSR account and giving it read access. For example, if your site is in:
c:\websites\mysite\wwwroot
Add the IUSR account to c:\websites\mysite and give it read access.
I was experiencing a “white screen” on IIS prior to this fix. Hope this helps.
Forum: Alpha/Beta/RC
In reply to: WordPress 3.0: Changing to new post typesThere is a plugin to handle this:
https://www.ads-software.com/extend/plugins/post-type-switcher/
It provides a little select menu on each post to change to a different post type, seems to work like a charm.
Forum: Alpha/Beta/RC
In reply to: WP 3.0 Permalinks are BrokenI am having the same issue. With pretty permalinks, I cannot get to any custom posts. When I turn off pretty permalinks, the custom post is there with the non-pretty url. Any resolution?