PHPackages                             calderawp/caldera-forms-query - 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. calderawp/caldera-forms-query

ActiveLibrary

calderawp/caldera-forms-query
=============================

Caldera Forms Query Library

0.3.2(7y ago)26.4k↓100%3[6 issues](https://github.com/CalderaWP/caldera-forms-query/issues)GPL-2.0PHPPHP &gt;=5.6

Since May 14Pushed 7y ago2 watchersCompare

[ Source](https://github.com/CalderaWP/caldera-forms-query)[ Packagist](https://packagist.org/packages/calderawp/caldera-forms-query)[ RSS](/packages/calderawp-caldera-forms-query/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (9)Used By (0)

[![Build Status](https://camo.githubusercontent.com/709609fecf21093377b6b5e9c0d1690fe0cba9e395a29de0399b57aa72f0efe3/68747470733a2f2f7472617669732d63692e6f72672f63616c6465726177702f63616c646572612d666f726d732d71756572792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/calderawp/caldera-forms-query)

This library provides for developer-friendly ways to query for or delete Caldera Forms entry data.

Why?
----

[](#why)

- [To provide the types of queries we need for reporting and deleting data in order to add GDPR compliance to Caldera Forms](https://github.com/CalderaWP/Caldera-Forms/issues/2108)
- To provide the types of queries we need for improving Caldera Forms features such as entry viewer, entry export, entry editing and Connected Forms.

Install
-------

[](#install)

`composer require calderawp/caldera-forms-query`

Requires
--------

[](#requires)

- WordPress - tested with 4.8, latest and trunk
- PHP 5.6+ - tested with PHP 7.1 and 7.2
- Caldera Forms 1.6.0+ - tested with Caldera Forms 1.6.1 beta 1

Status
------

[](#status)

- Works
- Does not yet select/delete by date range
- **Prepared SQL needs to be sanitized better.**

Usage
-----

[](#usage)

### Basic Queries

[](#basic-queries)

```
/**
 * Examples of simple queries
 *
 * Using the class: \calderawp\CalderaFormsQuery\Features\FeatureContainer
 * Via the static accessor function: calderawp\CalderaFormsQueries\CalderaFormsQueries()
 */

/** First make the function usable without a full namespace */
use function calderawp\CalderaFormsQueries\CalderaFormsQueries;

/** Do Some Queries */
//Select all data by user ID
$entries = CalderaFormsQueries()->selectByUserId(42);

//Select all entries that have a field whose slug is "email" and the value of that field's value is "delete@please.eu"
$entries = CalderaFormsQueries()->selectByFieldValue( 'email', 'delete@please.eu' );

//Select all entries that do not have field whose slug is "size" and the value of that field's value is "big"
$entries = CalderaFormsQueries()->selectByFieldValue( 'size', 'big', false );

//Delete all data by Entry ID
CalderaFormsQueries()->deleteByEntryIds([1,1,2,3,5,8,42]);

//Delete all data by User ID
CalderaFormsQueries()->deleteByUserId(42);
```

### Paginated Queries

[](#paginated-queries)

The selectByFieldValue feature method defaults to limiting queries to 25. You can set the page and limit with the 4th &amp; 5th arguments.

```
/**
 * Examples of simple queries
 *
 * Using the class: \calderawp\CalderaFormsQuery\Features\FeatureContainer
 * Via the static accessor function: calderawp\CalderaFormsQueries\CalderaFormsQueries()
 */

/** First make the function usable without a full namespace */
use function calderawp\CalderaFormsQueries\CalderaFormsQueries;

/** Do Some Queries */
//Select all entries that have a field whose slug is "email" and the value of that field's value is "delete@please.eu"
//The first 25 entries
$entries = CalderaFormsQueries()->selectByFieldValue( 'email', 'delete@please.eu' );
//The second 25 entries
$entries = CalderaFormsQueries()->selectByFieldValue( 'email', 'delete@please.eu', true, 2 );
//Get 5th page, with 50 results per page
$entries = CalderaFormsQueries()->selectByFieldValue( 'email', 'delete@please.eu', true, 5, 50 );
```

Constructing Other Queries
--------------------------

[](#constructing-other-queries)

The feature container provides helper methods that allow for simple queries like those listed above. It also exposes the underlying query generators.

You can access any of the generators using the `getQueries()` method. For example:

```
 $featureContainer = \calderawp\CalderaFormsQueries\CalderaFormsQueries();
    $fieldValue = 'X@x.com';
    $formId = 'CF5afb00e97d698';
    $count = Caldera_Forms_Entry_Bulk::count($formId );

    $entrySelector = $featureContainer
        ->getQueries()
        ->entrySelect();
```

#### `is()` Helper Method

[](#is-helper-method)

This is a more complete example showing a selection of entry values where the field with the slug `primary_email` is `roy@hiroy.club` and the field with the slug of `first_name` is `Mike`. It is also using the `is()` method to add WHERE statements, as well as the `addPagination()` method to query for the second page of results with 50 results per page.

```
    $featureContainer = \calderawp\CalderaFormsQueries\CalderaFormsQueries();
    $entrySelector = $featureContainer
        ->getQueries()
        ->entrySelect()
        ->is( 'primary_email', 'roy@hiroy.club' )
        ->is( 'first_name', 'Mike' )
        ->addPagination(2,50 );
```

#### `in()` Helper Method

[](#in-helper-method)

This example shows selection of all entry values where the entry ID is in an array of entry IDs.

```
    $featureContainer = \calderawp\CalderaFormsQueries\CalderaFormsQueries();
    $entrySelector = $featureContainer
        ->getQueries()
        ->entrySelect()
        ->in( 'entry_id', [ 42, 3 ] );
```

### Query Generators

[](#query-generators)

All query generators extend the `\calderawp\CalderaFormsQuery\QueryBuilder` class and impairment `\calderawp\CalderaFormsQuery\CreatesSqlQueries`.

Query generators are responsible for creating SQL queries. They do not perform sequel queries.

#### Select Query Generators

[](#select-query-generators)

Select query generators extend `\calderawp\CalderaFormsQuery\Select\SelectQueryBuilder` and impliment `\calderawp\CalderaFormsQuery\Select\DoesSelectQuery` and `\calderawp\CalderaFormsQuery\Select\DoesSelectQueryByEntryId`.

#### Useful Methods of `SelectQueryBuilder`s

[](#useful-methods-of-selectquerybuilders)

- `in()`

### Using Query Generators To Perform SQL Queries

[](#using-query-generators-to-perform-sql-queries)

#### SELECT

[](#select)

The `getQueries()` method of the `FeatureContainer` returns a `calderawp\CalderaFormsQuery\Features\Queries` instance. This provides us with a `select` method when passed a `SelectQueryBuilder` returns an array of `stdClass` object of results.

```
        $featureContainer = \calderawp\CalderaFormsQueries\CalderaFormsQueries();
        $entryValueSelect = $featureContainer
            ->getQueries()
            ->entryValuesSelect()
            ->is( 'size', 'large' );

       $featureContainer->getQueries()->select( $entryValueSelect );
```

You can also access the generated SQL as a string.

```
  $featureContainer = \calderawp\CalderaFormsQueries\CalderaFormsQueries();
        $sql = $featureContainer
            ->getQueries()
            ->entryValuesSelect()
            ->is( 'size', 'large' )
            ->getPreparedSql();
```

#### DELETE

[](#delete)

The `Queries` class also has a `delete` method we can pass a `DeleteQueryBuilder` to perform a DELETE query against the database.

Development
-----------

[](#development)

### Install

[](#install-1)

Requires git and Composer

- `git clone git@github.com:calderawp/caldera-forms-query.git`
- `cd caldera-forms-query`
- `composer install`

### Local Development Environment

[](#local-development-environment)

A local development environment is included, and provided. It is used for integration tests. Requires Composer, Docker and Docker Compose.

- Install Local Environment And WordPress "Unit" Test Suite

- `composer wp-install`

You should know have WordPress at

- (re)Start Server: Once server is installed, you can start it again

- `composer wp-start`

### Testing

[](#testing)

#### Install

[](#install-2)

Follow the steps above to create local development environment, then you can use the commands listed in the next section.

#### Use

[](#use)

Run these commands from the plugin's root directory.

- Run All Tests and Code Sniffs and Fixes
    - `composer tests`
- Run Unit Tests
    - `composer unit-tests`
- Run WordPress Integration Tests
    - `composer wp-tests`
- Fix All Code Formatting
    - `composer formatting`

WordPress and Caldera Forms Dependency
--------------------------------------

[](#wordpress-and-caldera-forms-dependency)

For now, this library is dependent on Caldera Forms and WordPress (for `\WPDB`.) This will change, possibly with breaking changes, when [caldera-interop](https://github.com/CalderaWP/caldera-interop) is integrated with this tool.

Stuff.
------

[](#stuff)

Copyright 2018 CalderaWP LLC. License: GPL v2 or later.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~24 days

Recently: every ~35 days

Total

7

Last Release

2771d ago

### Community

Maintainers

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

---

Top Contributors

[![Shelob9](https://avatars.githubusercontent.com/u/1994311?v=4)](https://github.com/Shelob9 "Shelob9 (4 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/calderawp-caldera-forms-query/health.svg)

```
[![Health](https://phpackages.com/badges/calderawp-caldera-forms-query/health.svg)](https://phpackages.com/packages/calderawp-caldera-forms-query)
```

PHPackages © 2026

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