Stumped – Ajax Response Returns 0

Debug it logically. This code works. I just tested it. This in a theme (I put it in header.php for testing): jQuery(document).ready(function() { var lanid = ‘demo’; var ajaxurl=”<?php echo admin_url(“admin-ajax.php”, null); ?>”; data = { action: “get_ldapattr”, lanid: lanid}; jQuery.ajax({ url: ajaxurl, data: data, dataType: ‘json’, type: ‘post’, success: function(response) { console.log(response); } }); … Read more

Why is this Ajax not working?

When you load a php file directly via an ajax request (UncheckPackageThemeHelper.php) it’s loaded outside the context of WordPress, so no WordPress core functions are available. All WordPress ajax requests should be routed through admin-ajax.php. You can print the URL with the function admin_url: admin_url( ‘admin-ajax.php’ ) When admin-ajax.php is loaded, WordPress is bootstrapped, so … Read more

Display all categories including sub categories

Solved with the following: $args = array( ‘orderby’ => ‘name’, ‘parent’ => 0 ); $categories = get_categories( $args ); $first = true; foreach ($categories as $category) { if ( $first ) { echo ‘<li class=”title” style=”border-top: 0px;”><a href=”https://wordpress.stackexchange.com/questions/116483/acatalog/abovegroundpools.html”>’.$category->cat_name.'</a>’; $first = false; } else { echo ‘<li class=”title”><a href=”https://wordpress.stackexchange.com/questions/116483/acatalog/abovegroundpools.html”>’.$category->cat_name.'</a>’; } $theid = $category->term_id; $children = $wpdb->get_results( … Read more

How do I add text in a shortcode?

hello you can try this // Add Shortcode function text_shortcode( $atts , $content = null ) { // Code return ‘<div>’ . $content . ‘</div>’; } add_shortcode( ‘b’, ‘text_shortcode’ ); The shortcode will be something like this [b] content [/b]

Strange wordpress slowness

You can use the plugin Debug Objects and his query function to identify the slowest queries from core and plugins. I see very often the problem on a plugin or theme functionality. Identify and solve.

Create Logout Link WordPress Admin Menu

You can use the awesome WP_Admin_Bar & hook in with admin_bar_menu: /** * Add a “Log out” link directly to the admin bar. * * @link http://wordpress.stackexchange.com/q/141446/1685 * * @param WP_Admin_Bar $wp_admin_bar */ function wpse_141446_admin_bar_logout( $wp_admin_bar ) { if ( is_user_logged_in() ) { $wp_admin_bar->add_menu( array( ‘id’ => ‘my-log-out’, ‘parent’ => ‘top-secondary’, ‘title’ => __( ‘Log … Read more

Can I use HTTP POSTs? Is there a better alternative?

WordPress is an HTTP/PHP web application. The ordinary rules of HTTP and PHP apply, and work. WordPress itself uses $_POST and $_GET more times than I can count. If you want to pass information from one page to another– say from a form to a search handler– you have to use one or the other. … Read more