Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Gunu

    (@grafcom)

    @zourbuth,

    can you show me an example? I do not quite understand what you mean.

    Thread Starter zourbuth

    (@zourbuth)

    add_filter( 'wp_head', 'my_post_views', 1 );
    function my_post_views() {
    	global $post;
    	if( is_singular() && 'post' == $post->post_type ) {
    		$views = get_post_meta( $post->ID, 'views', true );
    		$views = $views ? $views : 0;
    		$views++;
    		update_post_meta( $post->ID, 'views', $views );
    	}
    }

    The get_post_meta() does not return values from database.

    Soft79

    (@josk79)

    Sorry for hijacking this thread, but I have a simular issue that seems related.

    In WooCommerce, when an order is placed the stock is reduced e.g. from 2 to 1. A notification is saved in the order like this: ‘Stock reduced from 2 to 1’. But recently I discovered that the stock reduce was done right, but the numbers in the notification are wrong. Also the out of stock emails weren’t sent anymore.

    I discovered that WooCommerce calls wp_cache_delete( $this->id, 'post_meta' ); after reducing the stock, and then immediately continues by fetching the new ‘_stock’ metavalue. But, it seems that qTranslate-X also saves some translations in cache.

    TL;DR: I solved the problem for me like this, disabling qTranslate-X’ cache:

    qtranslate_frontend.php

    $meta_cache = null; //wp_cache_get( $object_id, $cache_key_lang );
    	if( !$meta_cache ){
    		$meta_cache = null; //wp_cache_get($object_id, $cache_key);
    		if ( !$meta_cache ) {
    			$meta_cache = update_meta_cache( $meta_type, array( $object_id ) );
    			$meta_cache = $meta_cache[$object_id];
    		}

    I disabled the call to wp_cache_get by placing null; //, and then all is fine!

    Somehow, if wp_cache_delete is called, the qtranslate-x meta should also be deleted.

    Soft79

    (@josk79)

    Plugin Author John Clause

    (@johnclause)

    q-X has internal cache per language and it was designed to be read-only, updates to meta do not update cache. This needs to be improved. Thank you for reporting the issue.

    Are you sure this is important to be able to dynamically update meta data at front-end? I thought that after it is configured on admin side, front-end is always read-only? Why exactly do you need to update the post meta at front-end? Is there another way for you to do the things?

    Soft79

    (@josk79)

    It is done like this in WooCommerce.

    When product stock is changed (when a customer places an order), wp_cache_delete is called and then $this->stock is unset (see abstract-wc-product.php function set_stock).

    immediately check_stock_status is called, which rereads the _stock meta value.

    Thread Starter zourbuth

    (@zourbuth)

    Thanks John Clause.

    Why exactly do you need to update the post meta at front-end?

    That is how post views works.

    Plugin Author John Clause

    (@johnclause)

    Hi All, @zourbuth, @josk79: I did some changes similar like you suggested and it passed may testing so far. Could you please try the latest https://github.com/qTranslate-Team/qtranslate-x/archive/master.zip and see if you can reproduce the problem again?

    Soft79

    (@josk79)

    Cool I’ll try it in a couple of days.

    Sorry John, this doesn’t solve it for the WooCommerce stock issue.

    I think this happens:
    1) postmeta cache gets flushed by WooCommerce
    2) stock is reread (and at this moment recached by qTr-X)
    3) stock is changed by WooCommerce, but since qTr-X cache has just been made, qTr-X will use the cache (thus unchanged) stock value.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Filter qtranxf_filter_postmeta issue’ is closed to new replies.