• Resolved karpo518

    (@karpo518)


    Hello! I’m using the posts unique view counter plugin to count and display the number of views of posts on my site. This plugin stores data in its own table. I would like all responses to graphql queries to posts to include the number of views field. How can I get it? I’m also looking for an efficient way to update the view count when a user navigates to a single post page.

Viewing 1 replies (of 1 total)
  • I am trying something similar without success:

    <?php
    class special_notifications
    {
        public function __construct()
        {
            $this->data = get_option('special_notifications', array());
            add_action('init', function () {
                register_setting('special_notifications', 'special_notifications', array('type' => 'array', 'default' => array(), 'show_in_graphql' => TRUE));
            });
            return TRUE;
        }
    
        public function update()
        {
            // This is stored elsewhere in the class
            update_option('special_notifications', 'special_notifications', TRUE);
            return TRUE;
        }
    }

    I’ve read this article and at WPGraphQL | Docs | Settings, but following the steps hasn’t resolved it.

    Are you able to assist?

Viewing 1 replies (of 1 total)
  • The topic ‘How to add custom fields (not ACF) to posts and post query data?’ is closed to new replies.