How can I create a custom shortcode that will return a custom post type by ID?

Ok, I found a simple answer to my problem. This is the shortcode function I ended up using to get my desired result: function cpt_case_study_func($atts){ extract( shortcode_atts( array( ‘id’ => null, ), $atts ) ); $post = get_post($id); $content=”<div class=”case-study”><h3>” . $post->post_title . ‘</h3> <p>’ . $post->post_content . ‘</p></div>’; return $content; } add_shortcode(‘case_study’,’cpt_case_study_func’); Thanks to … Read more

Remove ALL css for a specific plugin page

You can try this function. function remove_all_theme_styles() { global $wp_styles; $wp_styles->queue = array(); } add_action(‘wp_print_styles’, ‘remove_all_theme_styles’, 100); This should work on any theme, but its not really a good approach to disable theme css just to make your plugin look good.

How to create custom tables in WordPress using my own plugin?

Creating Tables with plugin This page shows how to work with tables in plugins. Example on that page includes table creation during installation of plugin. But it can be dynamically used also to create table. See below. if(isset($_POST[‘create’]) { $table_name=$_POST[‘table_name’]; Note : don’t use – in variable names. global $wpdb; $sql = “CREATE TABLE $table_name … Read more

Prevent WordPress installing plugins and themes via Admin

You can simply delete the lines from your wp-config.php. define(‘FTP_HOST’, ‘yourhost.com’); define(‘FTP_USER’, ‘youruser’); define(‘FTP_PASS’, ‘yourpass’); However, this does not automatically mean that you are secure. There are a lot of backdoors where malware could be injected, starting from the server, security-issues in your plugins, outdated software etc. Please be sure to check for all the … Read more

Access WordPress database outside of WordPress

In a nutshell there is no generic reliable way to load WordPress core from arbitrary file. Since core and extensions directories are independent from each other (they are co-located by default, not by necessity) only core configuration “knows” where extensions are, but not other way around. In private code things like this just get hardcoded. … Read more

Problem converting tags to categories while having large number of tags

Yes, there is a SQL-based method to do this. Just run this SQL (it will convert all tags to categories, if you want to convert only some of them, you have to add your conditions to WHERE clause): UPDATE wp_term_taxonomy SET taxonomy=’category’ WHERE taxonomy=’post_tag’ You can do this using $wpdb: $wpdb->query( “UPDATE $wpdb->term_taxonomy SET taxonomy=’category’ … Read more

Exclude post by custom meta with pre_get_posts

Your can use the “meta_query” argument of the query, I think is better than filter the post_where: add_action( ‘pre_get_posts’, ‘bbwp_calendar_visible_events’ ); function bbwp_calendar_visible_events( $query ) { $postType=”bbwp_calendar”; if ( !is_admin() && $query->is_main_query() ){ if ( is_post_type_archive( $postType ) ) { $meta_query = array( ‘relation’ => ‘OR’, //current time <= event_end_date array( ‘key’ => ‘event_end_date’, //Check … Read more