Creating wordpress user registration form

You are sending the data from the form directly to TestForm.php file, which is a PHP script outside of WordPress logic. It is and independent script. You could set the form’s action attribute to a empty string, this way the form data is sent to same page that contains the form, which is part of … Read more

Allow authors to post only in categories they create in WordPress

This little plugin shows the user role ‘author’ only its own categories & posts. So you can edit it for your own post-type and taxonomy. /* Plugin Name: Show own categories Description: This plugin shows the user role ‘author’ only its own categories & posts Version: 0.1 Author: Soren Wrede License: GPL2 License URI: https://www.gnu.org/licenses/gpl-2.0.html … Read more

How to order posts by modified date without using ‘query_posts’?

You haven’t specified where you want this alteration to apply to so I’ve applied it to just the home page. You may alter to fit where this filter applies to: <?php function wpse10691_alter_query( $query ) { if ( $query->is_main_query() && ( $query->is_home() || $query->is_search() || $query->is_archive() ) ) { $query->set( ‘orderby’, ‘modified’ ); $query->set( ‘order’, … Read more

Load custom field value into div with AJAX

Firstly, a POST request is the wrong type of request to send. As stated here, POST: Submits data to be processed to a specified resource You should be using GET, which Requests data from a specified resource The next problem is that in your callback function you are checking for $_POST[“pid”], but you are not … Read more

Add Adsense code in index.php

Here is a slight variation of my other answer. First we register two new widget areas, sidebars in WordPress-speak. add_action( ‘widgets_init’, ‘wpse_84250_register_ad_widgets’ ); function wpse_84250_register_ad_widgets() { // used on the first page of main loop only register_sidebar( array ( ‘name’ => ‘Ad Widget 1’, ‘id’ => ‘ad_widget_1’, ‘before_widget’ => ‘<div class=”frontpage-ads”>’, ‘after_widget’ => ‘</div>’ ) … Read more

Prevent multiple counts by same user – WP PostViews plugin

Since the plugin author does not offer any actions or filters for us to hook onto, we’ll have to settle for “listening” to changes to the views meta field instead. function wpse_104324_prevent_multiple_views( $meta_id, $object_id, $meta_key, $meta_value ) { if ( $meta_key === ‘views’ ) { if ( ! empty( $_COOKIE[ USER_COOKIE . ‘_views’ ] ) … Read more

Get post meta in enqueued js file

You can send variables to your script with wp_localize_script: wp_enqueue_script( ‘some_handle’ ); global $post; $my_meta = get_post_meta( $post->ID, ‘my_meta’, true ); $array = array( ‘my_meta’ => $my_meta ); wp_localize_script( ‘some_handle’, ‘object_name’, $array ); You can then use the var in your script like: object_name.my_meta