Forum Replies Created

Viewing 15 replies - 16 through 30 (of 138 total)
  • First of all the default wp post don’t have post parent assign to them, unless you are working with a custom post type that has the hierarchical argument set. Now assuming your post can have parent post, this should work:

    add_action('template_redirect', 'your_function');
    function your_function() {
    	if ( is_single() ) {
    		global $post;
    		$date1 = date_create( $post->post_date );
    		$now = ( date("Y-m-d", time() ) );
    		$date2 = date_create( $now );
    		$diff = date_diff( $date2, $date1 );
    		$days = $diff->format( '%a' ) ;
    		// change to the appropriate word count and days
    		if( ( str_word_count( $post->post_content ) >=  1253 ) && ( intval($days) >= 291 ) ) {
    			$category = get_the_category( $post->post_parent );
    			// first category
    			if( $category[0] ){
    				//wp_delete_post( $post->ID );
    				$link = get_category_link( $category[0]->term_id );
    				wp_redirect( $link, '301' ); exit;
    			}
    
    		}
    	}
    }

    The issue is kind of strange because the codes that handles upload to s3 and the code that insert the ‘amazonS3_info’ post meta value are all located in the same function. In fact right after the main file is uploaded to s3 the next line of code is to insert the post meta value,then uploading the remaining thumbs to s3.
    I need you to do one more check, for all the files that you uploaded while the malfunction occurred. Check your s3 bucket to see whether the main file and all its thumbs where actually uploaded to s3.
    If the check above check is true, then we need to do a db upgrade so that these files are also served with their corresponding s3 url. Insert the below function in your functions.php file.

    $s3_settings = get_option( 'tantan_wordpress_s3' );
            $bucket = $s3_settings['bucket'] ;
            $region = $s3_settings['region'];
    
    	$args = array(
    		'post_type' => 'attachment',
    		'numberposts' => -1,
    		'suppress_filters' => false
    	);
    
    	function filter_where( $where = '' ) {
    		// change to the right start and end date
    		$start_date = '2015-04-03'; $end_date = '2015-04-07';
    		$where .= "AND post_date >= '{$start_date}' AND post_date <= '{$end_date}'";
    		return $where;
    	}
    	add_filter( 'posts_where', 'filter_where' );
    	$attachments = get_posts( $args );
    	remove_filter( 'posts_where', 'filter_where' );
    
    	$att_ids = array();
    	foreach( $attachments as $attachment ) {
    		$att_ids []= $attachment->ID;
    	}
    
    	$atts_info = array();
    	foreach( $att_ids as $id ) {
    		$prefix = $s3_settings['object-prefix'];
    		$att_file = get_post_meta( $id , '_wp_attached_file', true );
    		$att_basename = basename($att_file);
    		if ( !empty( $prefix) ){
    			$key = $prefix.$att_basename;
    		} else {
    			$key = $att_basename;
    		}
    		$args = array(
    			'id' => $id,
    			'key' => $key
    		);
    		$atts_info []= $args;
    	}
    
    	foreach( $atts_info as $att_info ) {
    		$args = array (
    			'bucket' => $bucket,
    			'key' => $att_info['key'],
    			'region' => $region,
    		);
    		update_post_meta( $att_info['id'], 'amazonS3_info', $args );
    	}

    Make sure the plugin settings is actually the same when you had the issue please, because the code will be using the bucket, prefix and region settings of the plugin.

    $start_date and $end_date should be the dates in between the malfunction, so we should be working only with the needed attachments and should be in the format `$tart_date = ‘yyyy-mm-dd’ for example.
    After running the above db upgrade you should be good. Please don’t forget to remove the codes after you are done.

    On second thought, this is what you will do. While saving your manual excerpt in the post edit screen, type for example ‘[..]’ at the end of the excerpts, Do not use the string ‘[…]` as it will be interpreted as a symbol or any other string that will also be interpreted as a symbol. Then update the last codes I posted replacing the two occurrence of string'[…]’ with ‘[..]’. It ‘s working on my end.

    Ok now I get what you are trying to do. How are you then loading your script on the page/pages that has the menu link?..

    I hope you did not replace the entire code in the function with the line of code I suggested above. Your finally code should like this:

    function custom_excerpt($text) {  // custom 'read more' link
       if (strpos($text, '[...]')) {
          $excerpt = strip_tags(str_replace('[...]', '<div class="readmore"><a class="readmore" href="'. get_permalink( get_the_ID() ) . '"><small>CONTINUE READING</small></a></div>', $text), "<a>");
       } else {
          $excerpt = '<div class="readmore"><a class="readmore" href="'. get_permalink( get_the_ID() ) . '"><small>CONTINUE READING</small></a></div>';
       }
       return $excerpt;
    }
    add_filter('the_excerpt', 'custom_excerpt');

    First of all, your js should look more like this:

    jQuery(document).ready(function($) {
    	$(".hide_nav").click(function(){
    		$(".webform").hide(500);
    	});
    	$(".show_nav").click(function(){
    		$(".webform").show(500);
    	});
    });

    Try using more specific classname,so as not to cause conflict issues with other css classes. Also if you are trying to hide the entire list. I suggest using the wp_nav_menu() to add your class to the ul element of the menu list once.

    https://codex.ww.wp.xz.cn/Function_Reference/wp_nav_menu

    Change this line:

    $excerpt = '' . strip_tags($text) . '<div class="readmore"><a class="readmore" href="'. get_permalink( get_the_ID() ) . '"><small>CONTINUE READING</small></a></div>';

    to this:

    $excerpt = '<div class="readmore"><a class="readmore" href="'. get_permalink( get_the_ID() ) . '"><small>CONTINUE READING</small></a></div>';

    Ok… What you are asking for,is a little bit tricky. We will need to create a javascript file plus add more codes to the functions.php file. Just to make it easy for you, I have inserted the whole stuff inside a simple plugin.Please download the plugin here, remove the previous code you inserted in your functions.php,activate the plugin and report your results.
    A couple of things you need to know, if the post title is empty while inserting the mp3 file, let’s say writing a new post, the plugin would default to the mp3 title as the anchor text. Also Anytime the post title is edited, the plugin records the changes and therefore insert the edited post title as the anchor text…

    One more suggestion, just try to make your codes as DRY as possible. I see repetitions in your codes.

    Thanks..

    Insert the codes in your theme’s functions.php file…

    Something like this would work:

    add_filter( 'media_send_to_editor', 'mp3_media_insert', 20, 3 );
    function mp3_media_insert( $html, $id, $attachment ){
    	$output = '';
    	$post = get_post( $id );
    	if ( 'audio/mpeg' == $post->post_mime_type ) {
    		$output .= '<strong>MP3:</strong>';
    		$output .= '<a href="'.$attachment[url].'">'.$post->post_title.'</a>';
    		$output .= $html;
    		return $output;
    	} else {
    		return $html;
    	}
    }

    Assuming you want to use the first value for key ‘original_guid’ in your custom field, use this instead:

    $htmlURL = $custom_fields['original_guid'][0];

    Also this check:

    if ( get_post_meta($post_id, '_apt_skip_post_thumb', true) ) {
    
    }

    as the name of the key implies, are you not suppose to be doing the opposite:

    $meta_value = get_post_meta($post_id, '_apt_skip_post_thumb', true);
    if ( empty( $meta_value ) ) {
    
    }

    So so sorry..I double checked the EWWW file and the code I reference above was actually hooked to wp_generate_attachment_metadata instead of wp_update_attachment_metadata. My mistake,sorry for the headache, and yes your code should work by switching to wp_generate_attachment_metadata because it is called before wp_update_attachment_metadata. Sorry…

    Something like this works:

    add_action('publish_post', 'auto_featured_image_publish_post',10,2);
    function auto_featured_image_publish_post($post_id, $post) {
    
    	$cat_detail=get_the_category($post_id);
    	$cat_name = array();
    	foreach($cat_detail as $cd){
    		$cat_name[] = $cd->cat_name;
    	}
    
           $htmlURL = get_permalink( $post_id );
    
           // try to load the webpage
           $doc = new DOMDocument();
           @$doc->loadHTMLFile($htmlURL);
    
    	// get all image tags
            $images = $doc->getElementsByTagName('img');
    	if ( has_post_thumbnail($post_id) == false ) {
    		if ( in_array( 'Mongolia.GoGo.mn', $cat_name ) ) {
    			$imageURL = $images->item(62)->getAttribute('src');
    
    			// download image from url
    			$tmp = download_url($imageURL);
    
    			$file = array(
    				'name' => basename($imageURL),
    				'tmp_name' => $tmp
    			);
    
    			// create attachment from the uploaded image
    			$attachment_id = media_handle_sideload( $file, $post_id );
    
    			// set the featured image
    			update_post_meta($post_id, '_thumbnail_id', $attachment_id);
    		}
    	}
    }

    or this:

    add_action('publish_post', 'auto_featured_image_publish_post',10,2);
    function auto_featured_image_publish_post($post_id, $post) {
    
    	$cat_detail=get_the_category($post_id);
    	$cat_name = array();
    	foreach($cat_detail as $cd){
    		$cat_name[] = $cd->cat_name;
    	}
    
           $post_content = $post->post_content;
           $doc = new DOMDocument();
           $doc->loadHTML($post_content);
    
    	// get all image tags
           $images = $doc->getElementsByTagName('img');
           if ( has_post_thumbnail($post_id) == false ) {
    		if ( in_array( 'Mongolia.GoGo.mn', $cat_name ) ) {
    			$imageURL = $images->item(62)->getAttribute('src');
    
    			// download image from url
    			$tmp = download_url($imageURL);
    
    			$file = array(
    				'name' => basename($imageURL),
    				'tmp_name' => $tmp
    			);
    
    			// create attachment from the uploaded image
    			$attachment_id = media_handle_sideload( $file, $post_id );
    
    			// set the featured image
    			update_post_meta($post_id, '_thumbnail_id', $attachment_id);
    		}
    	}
    }

Viewing 15 replies - 16 through 30 (of 138 total)