Displaying a WooCommerce product via PHP

Use do_shortcode(). For example, in a template, if you were wanting to display products specifically by ID: <?php echo do_shortcode(‘[products ids=”1, 2, 3, 4, 5″]’); ?> WooCommerce comes with several shortcodes which can be used to insert content inside posts and pages: http://docs.woothemes.com/document/woocommerce-shortcodes/ You can add shortcodes to a post or page easily via the … Read more

Get php var inside javascript file (making plugin)

You can use wp_localize_script() to pass php variables to javascript. You create an array in php and then pass it to the function as the third parameter. It will come through as an object you name with the second parameter. First, register the script. wp_register_script( ‘custom-name-js’, plugins_url( ‘assets/custom-js.php’, __FILE__ ) ); Second, build your array … Read more

How to disable Gutenberg editor?

Yes, you can disable it. You can do this with code If you want to disable it globally, you can use this code: if ( version_compare($GLOBALS[‘wp_version’], ‘5.0-beta’, ‘>’) ) { // WP > 5 beta add_filter( ‘use_block_editor_for_post_type’, ‘__return_false’, 100 ); } else { // WP < 5 beta add_filter( ‘gutenberg_can_edit_post_type’, ‘__return_false’ ); } And if … Read more

Importing Tweets with certain hashtags into WordPress

I wrote a shortcode function based on “Twitter Hash Tag Widget” plugin just copy this function to your themes functions.php file function tweets_by_hashtag_9867($atts, $content = null){ extract(shortcode_atts(array( “hashtag” => ‘default_tag’, “number” => 5, ), $atts)); $api_url=”http://search.twitter.com/search.json”; $raw_response = wp_remote_get(“$api_url?q=%23$hashtag&rpp=$number”); if ( is_wp_error($raw_response) ) { $output = “<p>Failed to update from Twitter!</p>\n”; $output .= “<!–{$raw_response->errors[‘http_request_failed’][0]}–>\n”; $output … Read more

Using require_once in a Plugin?

The first one is like saying… Include the file found in the inc directory, above the directory where this file is located. The second statement is saying… in the server root (/) look in the inc folder for canagan_admin_functions.php and include it. The first one will work, the second won’t. In the second you’re looking … Read more

How to empty wordpress custom post Database table

I used a custom page template to delete all the post from the wordpress database. Everytime I would go to this page it would delete 300 posts.The code for the page template is: <?php // Get 300 custom post types pages, set the number higher if is not slow. $mycustomposts = get_posts( array( ‘post_type’ => … Read more

How to upload image with simple form?

There are several parts. You need to add an enctype to the profile form. function edit_form_type_wpse_98375() { echo ‘ enctype=”multipart/form-data”‘; } add_action(‘user_edit_form_tag’,’edit_form_type_wpse_98375′); Then add a field to the form. function user_fields_wpse_98375($profileuser) { $_profile_photo = get_user_meta($profileuser->data->ID,’_profile_photo’,true); echo ‘<h3>’.__(‘Additional User Data’,THEME_TEXTDOMAIN).'</h3>’; echo ‘<tr class=”show-admin-bar”>’; echo ‘<th scope=”row”>’.__(‘Profile Photo’, THEME_TEXTDOMAIN).'</th>’; echo ‘<td’.$tspan.’>’; echo ‘<fieldset>’; echo ‘<legend class=”screen-reader-text”><span>’.__(‘Profile Photo’, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)