PHPackages                             benjaminmedia/wp-cxense - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. benjaminmedia/wp-cxense

ActiveWordpress-plugin[API Development](/categories/api)

benjaminmedia/wp-cxense
=======================

This plugin integrates your site with cXense by adding meta tags and calling the cXense api

3.3.3(3y ago)211.2k1[1 PRs](https://github.com/BenjaminMedia/wp-cxense/pulls)1MITPHPPHP &gt;=7.4

Since Sep 27Pushed 2y ago13 watchersCompare

[ Source](https://github.com/BenjaminMedia/wp-cxense)[ Packagist](https://packagist.org/packages/benjaminmedia/wp-cxense)[ Docs](https://github.com/BenjaminMedia/wp-cxense)[ RSS](/packages/benjaminmedia-wp-cxense/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (13)Versions (101)Used By (1)

Bonnier Publications - WordPress cXense plugin
==============================================

[](#bonnier-publications---wordpress-cxense-plugin)

This plugin enables your WordPress site to integrate with cXense. It adds the meta tags and scripts needed by cXense in order to scan your site. It also calls cXense whenever you make changes to your content. Finally it adds the possibility to save a cXense recommendation widget per content type and provides hooks to call them in your view/theme.

### Requirements

[](#requirements)

- WordPress 4.3 or higher
- Language support (Optional) Polylang plugin must installed and activated version 1.8.4 or higher
- PHP 7.1 or higher

### Installation/Configuration

[](#installationconfiguration)

Install through composer:

```
composer require benjaminmedia/wp-cxense
```

Download lastest release from: And unzip and place in your /wp-content/plugins directory.

#### Settings

[](#settings)

Once you have installed and activated the plugin then make sure that you have a set of api credentials for the cXense API. Once you have your credentials you may go to the settings page labeled cXense. Here you must enter your `cXense Site ID`, `cXense API user`, `cXense API key` and finally your `cXense Organisation prefix`.

##### Remember the plugin will not work until you check the `Enable` switch in the settings page

[](#remember-the-plugin-will-not-work-until-you-check-the-enable-switch-in-the-settings-page)

---

### Widgets

[](#widgets)

The plugin will generate a `CX Widget ID` settings field for each post type you have available on your WordPress Installation. Here you must enter the cXense recommendation widget ID that you would like represented on your content type.

For debug purpose you can enable or disable the query cache. It is recommended to be enabled in production.

SortBy Widget ID will be only used for widgets sortby options in wp-base.

#### Rendering widgets

[](#rendering-widgets)

In order to render the widgets available for your post you should make sure that you have filled out the `CX widget ID` field in the plugin settings page.

When rendering the widgets the plugin provides you with two options:

1. Let cXense render the HTML of the widgets
2. Get the data and for the widget and build the HMTL yourself

Once you have picked the method you want to use you should go to the theme file that represents the single view of your post\_type from this file you may call the following methods to get the widget data:

###### Let cXense render the HTML of the widgets

[](#let-cxense-render-the-html-of-the-widgets)

```
WpCxense::instance()->render_widget();
```

The sample output of this function could look like:

```

            document.write(data.response.template + '\n');

                Hindbærsmoothie med æble og lakrids

                Herkules Pavillonens bedste frokost-opskrifter

	...

```

---

###### Get the data and for the widget and build the HMTL yourself

[](#get-the-data-and-for-the-widget-and-build-the-hmtl-yourself)

```
WpCxense::instance()->get_widget_data();
```

The sample output of this function could look like:

```
array (size=12)
  0 =>
    object(stdClass)[2636]
      public 'recs-articleid' => string '795' (length=3)
      public 'bod-pagetype' => string 'recipe' (length=6)
      public 'dominantthumbnail' => string 'http://content-thumbnail.cxpublic.com/content/dominantthumbnail/f95381682e3604de99d30788b24fb3a1538616ee.jpg?57e79849' (length=117)
      public 'dominantthumbnaildimensions' => string '300x236' (length=7)
      public 'title' => string 'Hindbærsmoothie med æble og lakrids' (length=37)
      public 'click_url' => string 'http://api.cxense.com/public/widget/click/HV4bL7qxuVIVUmrMEsh4zQ6S2A5_BkkxEuByIzyDKMZAYCrJlJOTpy7QFvYxf7dkW0ljBE_55ig9vYxG3FNaXmKGsr03HH5w1wa7-E6mbJI-gdqHJNx6pgIjvKyM8TUGnhfwe0NsyjAkgzirNM66WfPhG9_Z9lsiWIJauO3C82KWYdRhA99EBXg6Ynsh9xwIq62wNJAaj_OPTVFhUuGiLxW7uVQ4DNT0BjRcn8ne0Uq6y8Ew0DYUDCfCFp6DwOy_D9MK7j5wpKSfRykLOGNNo35udNcfALBcZJfoMZ7Uqgs19IZeGrAv11RDIz1cNBmWq3yEn-QKqeKFgK7cqwjKeCr91PERbwGbDu4kN9xkv1NPjTK1M_attpQjlCLy3E9_JstO-aCxP6XtmtnIExUnl1Qq7iVPXAbP3fxlT3wmIOetk4IvoGKsXhdFkRIMCD1owQwY27bVvzwuPCgTXJ-7UO'... (length=599)
      public 'url' => string 'http://maaltid.nu/opskrifter/hindbaersmoothie-med-aeble-og-lakrids' (length=66)
  1 =>
    object(stdClass)[2672]
      public 'recs-articleid' => string '1369' (length=4)
      public 'bod-pagetype' => string 'recipe' (length=6)
      public 'dominantthumbnail' => string 'http://content-thumbnail.cxpublic.com/content/dominantthumbnail/6b0ddce458039f3905b5b3515356002536ab614c.jpg?57ea261a' (length=117)
      public 'dominantthumbnaildimensions' => string '300x236' (length=7)
      public 'title' => string 'Italiensk til middag: Risotto med 2 slags græskar og salvie' (length=60)
      public 'click_url' => string 'http://api.cxense.com/public/widget/click/mLsD8MoXunkEcOtky6wQJXpRjzYcvvrFoXsONQdOI5FDqsmnlun6sVcaK-PIsvyT9KoXSvOKxiS4wzBrjGb0PaCtk_1bFn88sHSzq7LJF4CL7-Q4-50nJl3JC3oyrnAM1W_Cub7qXcAHSFmBjVkBjAGRaiA_F-Du9Y1q2by9YikilWco43hRZeUHVyQ2RLOZ7as8C1SeEXdKHeDi8HT5SGqMox-hAdBhwHNLtXLdJ_t1u9G90QOmQw-xitTc4PUknHSdtPyiDgYrBNNxHhOehs0_wHKGxka4k-g6VOAo7ovFGF2aRB-32QAqSPu_ohd-nNO_J0tEMll1uofTI9XCePnkI2O1W0Cq6MkEcyWVZQ-72hWiTrfn2z8x-BRd9ZE8cFvdWV8OU-Ojf02KEKesGfVgUltFY-HLImdE2NCkGV-jk7RoHYXesghIvfTufvKnMORmayI5lkLDZQ5Dp7u9wh'... (length=613)
      public 'url' => string 'http://maaltid.nu/opskrifter/kom-i-godt-humor-med-graeskarrisotto-med-salvie' (length=76)
  2 => ...
```

### Documents

[](#documents)

#### Searching documents

[](#searching-documents)

If the key 'query' is missing from the search array then a [DocumentSearchMissingSearch](https://github.com/BenjaminMedia/wp-cxense/blob/search_documents/src/Bonnier/WP/Cxense/Exceptions/DocumentSearchMissingSearch.php) exception is thrown.

##### Search

[](#search)

```
WpCxense::instance()->search_documents([
    'query' => 'search_term', // mandatory
    'page' => 1, // optional, defaults to 1
    'count' => 10, // optional, defaults to 10
    'filter_operator => 'AND', // optional, defaults to OR
    'filter' => [ // optional
        'field' => [
            'value',
        ],
    ],
    'filter_exclude' => [ // optional
        'field' => [
             'value',
        ],
    ],
    'facets' => [ // optional
        0 => [
            'type' => 'string',
            'field' => 'field'
        ],
        1 => [
            'type' => 'string',
            'field' => 'field'
        ]
    ],
    'spellcheck' => true, // optional
    'highlights' => [ // optional
        0 => [
            'field' => 'body',
            'start' => '',
            'stop' => '',
            'length' => 50
        ]
    ]
]);
```

Searching documents will return an object of the following format:

```
object(stdClass)[543]
  public 'facets' =>
    array (size=2)
      0 =>
        object(stdClass)[538]
          public 'buckets' =>
            array (size=6)
              ...
      1 =>
        object(stdClass)[542]
          public 'buckets' =>
            array (size=3)
              ...
  public 'totalCount' => int 79
  public 'matches' =>
    array (size=10)
      0 =>
        object(Bonnier\WP\Cxense\Parsers\Document)[521]
          public 'id' => string '551790ba522b4b9427ca947e1b3353e137d78a85' (length=40)
          public 'siteId' => string '1129402680464567580' (length=19)
          public 'score' => float 2.0455377
          public 'fields' =>
            array (size=10)
              ...
          public 'highlights' =>
            array (size=1)
              ...
  public 'spellcheck' =>
      array (size=1)
        0 =>
          object(stdClass)[663]
            public 'term' => string 'mor' (length=3)
            public 'suggestions' =>
              array (size=0)
                ...
```

The 'matches' key contains an array of objects that have the 'fields' value accessible directly through the magic method \_\_get(). This means that you can call any field from the 'fields' with the direct pointer:

```
$objResults->matches[0]->author;
```

A complete document result looks like:

```
object(Bonnier\WP\Cxense\Parsers\Document)[710]
  public 'id' => string '551790ba522b4b9427ca947e1b3353e137d78a85' (length=40)
  public 'siteId' => string '1129402680464567580' (length=19)
  public 'score' => float 0.40566906
  public 'fields' =>
    array (size=9)
      0 =>
        object(stdClass)[715]
          public 'field' => string 'author' (length=6)
          public 'value' => string 'i form' (length=6)
      1 =>
        object(stdClass)[718]
          public 'field' => string 'bod-cat' (length=7)
          public 'value' => string 'Sund graviditet' (length=15)
      2 =>
        object(stdClass)[719]
          public 'field' => string 'bod-cat-top' (length=11)
          public 'value' => string 'Sundhed' (length=7)
      3 =>
        object(stdClass)[720]
          public 'field' => string 'bod-cat-url' (length=11)
          public 'value' => string 'http://iform.dk/sundhed/sund-graviditet' (length=39)
      4 =>
        object(stdClass)[721]
          public 'field' => string 'bod-pagetype' (length=12)
          public 'value' => string 'article' (length=7)
      5 =>
        object(stdClass)[722]
          public 'field' => string 'description' (length=11)
          public 'value' => string 'Går du med babytanker, har du en fordel, hvis du bor tæt på din mor.' (length=71)
      6 =>
        object(stdClass)[723]
          public 'field' => string 'recs-publishtime' (length=16)
          public 'value' => string '2015-04-19T22:00:00.000Z' (length=24)
      7 =>
        object(stdClass)[724]
          public 'field' => string 'title' (length=5)
          public 'value' => string 'Din mor øger dine baby-chancer' (length=31)
      8 =>
        object(stdClass)[725]
          public 'field' => string 'url' (length=3)
          public 'value' => string 'http://iform.dk/sundhed/sund-graviditet/din-mor-kan-hjaelpe-til-familieforoegelsen' (length=82)
```

#### Widget documents

[](#widget-documents)

If the key 'widget\_id' is missing from the input array then a [WidgetMissingId](https://github.com/BenjaminMedia/wp-cxense/blob/search_documents/src/Bonnier/WP/Cxense/Exceptions/WidgetMissingId.php) exception is thrown.

Example how to fetch cxense data

```
WidgetDocumentQuery::make()
                    ->addContext('url', get_permalink())
                    ->setMatchingMode($this->getCxenseTaxonomy())
                    ->addParameter('pageType', 'article gallery story')
                    ->setCategories(array($this->getCategory()))
                    ->setTags(array($this->getTag()))
                    ->get();
```

#### Recently viewed by user 'TAX\_RECENT'

[](#recently-viewed-by-user-tax_recent)

This type of taxonomy requires user browser cookie. In order to fetch it from the browser console you can use

```
cX.getUserId()

```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community25

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Recently: every ~45 days

Total

97

Last Release

1344d ago

Major Versions

v1.2.19 → 2.0.02018-07-25

v1.3.2 → 2.2.02018-08-14

1.4.4 → 2.5.22020-05-05

2.5.2 → v3.0.0.x-dev2020-06-30

PHP version history (4 changes)v1.0.0PHP &gt;=5.6

2.0.0PHP &gt;=7.1

3.1.0PHP ~7.1

3.3.3PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/737efb54dd51c1c52e71bb30c0292f48675e60282aa0f73272697113542cdbe6?d=identicon)[alfhen](/maintainers/alfhen)

![](https://www.gravatar.com/avatar/a652ae71c3dbb5561c66c620c07b46301f1a06ac938200727a00a9bf21797731?d=identicon)[Interactives](/maintainers/Interactives)

---

Top Contributors

[![sulfo](https://avatars.githubusercontent.com/u/830016?v=4)](https://github.com/sulfo "sulfo (72 commits)")[![alfhen](https://avatars.githubusercontent.com/u/5700924?v=4)](https://github.com/alfhen "alfhen (53 commits)")[![lms-it](https://avatars.githubusercontent.com/u/12814322?v=4)](https://github.com/lms-it "lms-it (51 commits)")[![madspaaskesen](https://avatars.githubusercontent.com/u/404800?v=4)](https://github.com/madspaaskesen "madspaaskesen (35 commits)")[![MFlor](https://avatars.githubusercontent.com/u/3704257?v=4)](https://github.com/MFlor "MFlor (29 commits)")[![jonastanz](https://avatars.githubusercontent.com/u/12626047?v=4)](https://github.com/jonastanz "jonastanz (24 commits)")[![ovidiu-ostafi](https://avatars.githubusercontent.com/u/18714163?v=4)](https://github.com/ovidiu-ostafi "ovidiu-ostafi (17 commits)")[![Xayer](https://avatars.githubusercontent.com/u/1837767?v=4)](https://github.com/Xayer "Xayer (16 commits)")[![SorenThorup](https://avatars.githubusercontent.com/u/5878056?v=4)](https://github.com/SorenThorup "SorenThorup (14 commits)")[![186dk](https://avatars.githubusercontent.com/u/21238139?v=4)](https://github.com/186dk "186dk (7 commits)")[![Frozire](https://avatars.githubusercontent.com/u/6813614?v=4)](https://github.com/Frozire "Frozire (5 commits)")[![mrhn](https://avatars.githubusercontent.com/u/5760050?v=4)](https://github.com/mrhn "mrhn (4 commits)")[![interactive-bonnier](https://avatars.githubusercontent.com/u/16895282?v=4)](https://github.com/interactive-bonnier "interactive-bonnier (3 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")

---

Tags

cxensewordpresswordpress-pluginwp-cxensepluginwordpress

### Embed Badge

![Health badge](/badges/benjaminmedia-wp-cxense/health.svg)

```
[![Health](https://phpackages.com/badges/benjaminmedia-wp-cxense/health.svg)](https://phpackages.com/packages/benjaminmedia-wp-cxense)
```

###  Alternatives

[sybrew/the-seo-framework

An automated, advanced, accessible, unbranded and extremely fast SEO solution for any WordPress website.

47078.8k](/packages/sybrew-the-seo-framework)[imranhsayed/headless-cms

A WordPress plugin that adds features to use WordPress as a headless CMS with any front-end environment using REST API

2125.1k](/packages/imranhsayed-headless-cms)[madeitbelgium/wordpress-php-sdk

WordPress Laravel PHP SDK

4422.9k1](/packages/madeitbelgium-wordpress-php-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
