keep wp_insert_post from adding duplicates

The problem ended up being the hook after_setup_theme. I was effectively invoking the function by refreshing the browser which launches the hook in both Javascript and PHP so the hook was being triggered more than once when the browser was refreshed. Once I disabled Javascript everything worked fine. Another solution would have been to use … Read more

wp_insert_post if page doesn’t exist under current page

$args = array( ‘post_type’ => ‘page’, ‘posts_per_page’ => -1, ‘post_parent’ => $post->ID, ); $children= new WP_Query( $args ); $seasonepisode = array( ‘post_title’ => $episodetitle, ‘post_content’ => ‘Some Content’, ‘post_status’ => ‘publish’, ‘post_parent’ => $post->ID, ‘post_type’ => ‘page’, ‘page_template’ => ‘template-songlist.php’ ); if ( $children->have_posts() ){ while ( $children->have_posts() ) { $children->the_post(); if(get_the_title() != $episodetitle){ wp_insert_post($seasonepisode); … Read more

WPML – Set language of inserted post

The wpml_set_element_language_details action element_type need to be with the correct prefix that WPML use: From the WPML Docs element_type(string) The type of an element. Can be a post type: post_post, post_page, post_attachment, post_nav_menu_item, post_{custom post key} or taxonomy: tax_category, tax_post_tag, tax_nav_menu, tax_{custom taxonomy key}. Defaults to post_post if not set. In your case it should … Read more

add_menu_page Callback Function: Skip page content?

add_action( ‘admin_menu’, ‘av_subscribe_create_menu’ ); function av_subscribe_create_menu() { $hook = add_menu_page( ‘Add Comment Feed’, ‘Add Comment Feed’, ‘manage_options’, ‘av-create-feed’, // Don’t use __FILE__ as the slug, keep it short ‘n sweet! ‘__return_true’ // We need a callback otherwise WP won’t properly handle the page, though it’s never seen ); if ( $hook ) // Current user … Read more

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