Check if row exists before inserting

There are several problems with your function. For example, $tablename points to a table that does not exist. And you don’t need it anyway. If you are trying to create a new user if that email does not exist then try this: function register_user() { global $wpdb; $name = $_POST[‘name’]; $email = $_POST[’email’]; $password = … Read more

Change the slug of a particular page every x hours

You’ll need a two step process for that. Create a function that actually changes the slug (not rewrite it) Schedule an event in WordPress to run that function in every X hours. Here are something to start with function wpse402903_schedule_event() { add_action( ‘wpse402903_cron’, ‘wpse402903_cron_callback’ ); if ( !wp_next_scheduled(‘wpse402903_cron’) ) { //Change 12 to your interval … Read more

modify a function filter

The filter exists to avoid the need for replacements in the plugin code. What you probably need is: add_filter( ‘wpsc_purchase_logs_cap’, ‘wpse_72095_admin_to_editor’ ); function wpse_72095_admin_to_editor() { return ‘edit_others_posts’; } This will change the capability/role to editor.

adding custom classes for tables

In your case you need to add custom hook for the_content filter: add_filter( ‘the_content’, ‘wpse8170_add_custom_table_class’ ); function wpse8170_add_custom_table_class( $content ) { return str_replace( ‘<table>’, ‘<table class=”mycustom-class”>’, $content ); } Add this snippet to your functions.php file.

options.php problem – data not saved

Add <?php settings_fields( ‘settings-group’ ); ?> <?php do_settings_sections( ‘settings-group’ ); ?> immediately after the <form> tag Your code is registering the settings group, setting up the DB to store the information, but it is/was missing the callback to allow WordPress to actually act on that information or store it. The code I provided tells WordPress … Read more

Remove function or filter

Your problem isn’t that you did the wrong thing, it’s that you did it at the wrong time. When it happens is important, not where. In a child theme, the functions.php is loaded, then the parents, so you’re doing this: Remove the first_paragraph function from the_content filter Add the first_paragraph function to the_content filter Clearly … Read more

Custom Shortcode, functions PHP WP_Query loop

You are returning inside your loop – so it returns on the first iteration, giving you one result only. You should build a string inside your loop instead, and only return when the loop is over. Something like $featured_properties=””; if( $featured_query->have_posts() ): while( $featured_query->have_posts() ) : $featured_query->the_post(); $featured_properties .= get_the_title() . ‘<br />’; endwhile; endif; … Read more

If is multiple page templates

I you want the script be enqueued on page-index.php and page-contact-us.php, then you must check that that page templates are used but you are checking if they are not used. Chagne this: if ( !is_page_template(‘page-templates/page-index.php’) && !is_page_template(‘page-templates/page-contact-us.php’) ) { with: if ( is_page_template(‘page-templates/page-index.php’) || is_page_template(‘page-templates/page-contact-us.php’) ) { The first code reads like: if is NOT … Read more