• Resolved drafttreesoon

    (@drafttreesoon)


    I have a popular posts loop in my homepage.php that uses post_html to build out the markup. I am trying to get an ACF text field text field in there and all attempts leave me with the same text showing on each post.

    Hoping there is some documentation I missed or I am just missing something super obvious.

    This is my code

    page functions.php

    /**
    * Parses custom content tags in WordPress Popular Posts.
    *
    * @param string $html The HTML markup from the plugin.
    * @param integer $post_id The post/page ID.
    * @return string
    */
    function wpp_parse_tags_in_popular_posts( $html, $post_id ){
    if ( false !== strpos($html, ‘{battery_price}’) ) {
    $acf_price = get_field( ‘battery_price’, $post_id );
    if ( $acf_price ) {
    $html = str_replace( ‘{battery_price}’, $acf_price, $html );
    }
    else {
    $html = str_replace( ‘{battery_price}’, ”, $html );
    }
    }
    return $html;

    }

    page homepage.php

    <?php

    $args = array(
    ‘order_by’ => ‘views’,
    ‘post_type’ => ‘post’,
    ‘cat’ => ‘178,-3,-162,-26’,
    ‘limit’ => 3,
    ‘range’ => ‘all’,
    ‘thumbnail_width’ => 100,
    ‘thumbnail_height’ => 75,
    ‘post_html’ => ‘

    <div class=”flex-wheel-other”>
    <div class=”wheel-small-box -wheel”>
    <figure class=”thumb”>
    {thumb}
    </figure>
    </div>
    <div class=”wheel-small-box”>
    <p>{text_title}</p>
    <p class=”price”>{battery_price} บาท</p>
    <p>({views} views)</p>
    </div>
    <div class=”wheel-small-box -num”>
    <div class=”number-other”>
    1
    </div>
    </div>
    </div>

    );

    wpp_get_mostpopular($args );
    ?>

    battery_price not show acf field post 🙁

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter drafttreesoon

    (@drafttreesoon)

    Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @drafttreesoon,

    It seems you forgot to add the add_filter call to your functions.php file:

    /**
     * Parses custom content tags in WordPress Popular Posts.
     *
     * @param string $html The HTML markup from the plugin.
     * @param integer $post_id The post/page ID.
     * @return string
     */
    function wpp_parse_tags_in_popular_posts( $html, $post_id ){
    	if ( false !== strpos($html, '{battery_price}') ) {
    		$acf_price = get_field( 'battery_price', $post_id );
    
    		if ( $acf_price ) {
    			$html = str_replace( '{battery_price}', $acf_price, $html );
    		}
    		else {
    			$html = str_replace( '{battery_price}', '', $html );
    		}
    	}
    
    	return $html;
    }
    add_filter("wpp_parse_custom_content_tags", "wpp_parse_tags_in_popular_posts", 10, 2);

    That’s the reason why your custom {battery_price} tag isn’t working as expected.

    Thread Starter drafttreesoon

    (@drafttreesoon)

    Oh I forgot it thank you very much

    Thread Starter drafttreesoon

    (@drafttreesoon)

    how to translate {date} to thai language ?

    Plugin Author Hector Cabrera

    (@hcabrera)

    Alright, since your original question was answered I’m marking this topic as resolved.

    As for your second question, you’ll need to create a Thai translation for the date:

    1. Create a copy of this file and name it as th.php.

    2. Open the file with a code editor and translate the days, weeks, etc into Thai.

    3. When you’re done, place your th.php file in /wp-content/plugins/wordpress-popular-posts/src/Moment/Locales. If everything is correct the date now should appear in Thai language.

    Thread Starter drafttreesoon

    (@drafttreesoon)

    thank you verymuch

    Thread Starter drafttreesoon

    (@drafttreesoon)

    Sorry I have a one problem. Umm I want use field acf multiple fields. How to use function.

    image acf field

    https://www.img.in.th/image/U6dtEY

    • This reply was modified 5 years, 11 months ago by drafttreesoon.
    • This reply was modified 5 years, 11 months ago by drafttreesoon.
    Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @drafttreesoon,

    You could just create new if blocks per custom field.

    For example:

    function wpp_parse_tags_in_popular_posts( $html, $post_id ){
    	// Battery Price
    	if ( false !== strpos($html, '{battery_price}') ) {
    		$acf_price = get_field( 'battery_price', $post_id );
    
    		if ( $acf_price ) {
    			$html = str_replace( '{battery_price}', $acf_price, $html );
    		}
    		else {
    			$html = str_replace( '{battery_price}', '', $html );
    		}
    	}
    
    	// Logo Tire Wrap
    	if ( false !== strpos($html, '{logo_tire_wrap_option}') ) {
    		$acf_price = get_field( 'logo_tire_wrap_option', $post_id );
    
    		if ( $acf_price ) {
    			// Do something
    		}
    		else {
    			$html = str_replace( '{logo_tire_wrap_option}', '', $html );
    		}
    	}
    
    	// Etc.
    
    	// Add as many custom tags as needed here, then ...
    
    	return $html;
    }
    add_filter("wpp_parse_custom_content_tags", "wpp_parse_tags_in_popular_posts", 10, 2);
Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘ACF field integration?’ is closed to new replies.