Recent

Counts_Command class Pro only

Counts_Command

View and manage post view counts.

EXAMPLES

# View top 10 posts by count
$ wp top10 counts view

# Get the count for a specific post
$ wp top10 counts get 42

Namespace: WebberZone\Top_Ten\Pro\CLI
Since: 4.3.0
Source: includes/cli/class-counts-command.php line 32 Extends: Base_Command

Methods

view()

List popular posts with their view counts.

OPTIONS

[—table=

] : Which table to query: overall, daily. Default: overall.

[—limit=] : Number of posts to return. Default: 10.

[—from-date=] : Start date filter (Y-m-d) for daily table.

[—to-date=] : End date filter (Y-m-d) for daily table.

[—post-type=] : Post type to filter by. Default: post.

[—format=] : Output format (table, json, csv). Default: table.

[—network] : List popular posts for all sites in the network.

[—blog-id=] : Specific blog ID to query (multisite only).

EXAMPLES

wp top10 counts view
wp top10 counts view --table=daily --limit=20 --format=json
wp top10 counts view --from-date=2025-01-01 --to-date=2025-12-31
wp top10 counts view --network

Line: 73

public function view( array $args, array $assoc_args ): void;
TypeNameDescription
array$argsCommand arguments.
array$assoc_argsCommand associative arguments.

Returns: void

get()

Get the view count for a specific post.

OPTIONS

: The ID of the post.

[—table=

] : Which table to query: overall, daily. Default: overall.

EXAMPLES

wp top10 counts get 42
wp top10 counts get 42 --table=daily

Line: 144

public function get( array $args, array $assoc_args ): void;
TypeNameDescription
array$argsCommand arguments.
array$assoc_argsCommand associative arguments.

Returns: void

set()

Set the overall view count for a specific post.

OPTIONS

: The ID of the post. : The count value to set.

[—dry-run] : Show what would be changed without updating.

EXAMPLES

wp top10 counts set 42 1000
wp top10 counts set 42 1000 --dry-run

Line: 182

public function set( array $args, array $assoc_args ): void;
TypeNameDescription
array$argsCommand arguments.
array$assoc_argsCommand associative arguments.

Returns: void

reset()

Reset (delete) view counts for one or more posts.

OPTIONS

[—post-id=] : Comma-separated post ID(s) to reset. Omit to reset all.

[—table=

] : Which table to reset: overall, daily, all. Default: all.

[—force] : Skip interactive confirmation.

[—dry-run] : Show what would be deleted without deleting.

[—network] : Reset counts for all sites in the network.

[—blog-id=] : Specific blog ID to reset counts for (multisite only).

EXAMPLES

wp top10 counts reset --post-id=42,43 --table=overall
wp top10 counts reset --force
wp top10 counts reset --dry-run
wp top10 counts reset --network --force

Line: 240

public function reset( array $args, array $assoc_args ): void;
TypeNameDescription
array$argsCommand arguments.
array$assoc_argsCommand associative arguments.

Returns: void

export()

Export view counts to a CSV file.

The output format matches the admin Import/Export page so files are interchangeable: Post ID, Visits, [Date,] Blog ID[, URL].

OPTIONS

[—file=] : Output file path. Default: tptn-counts-{timestamp}.csv

[—table=

] : Which table to export: overall, daily. Default: overall.

[—limit=] : Maximum rows to export. Default: 0 (all).

[—include-urls] : Add a URL column (same as the admin “Include URLs in export” option).

[—dry-run] : Show how many rows would be exported without writing the file.

[—network] : Export rows for all sites in the network.

[—blog-id=] : Specific blog ID to export (multisite only).

EXAMPLES

wp top10 counts export
wp top10 counts export --file=counts.csv --table=daily --limit=1000
wp top10 counts export --include-urls --network
wp top10 counts export --dry-run

Line: 329

public function export( array $args, array $assoc_args ): void;
TypeNameDescription
array$argsCommand arguments.
array$assoc_argsCommand associative arguments.

Returns: void

import()

Import view counts from a CSV file.

Accepts the same positional format produced by wp top10 counts export and the admin Import/Export page: Post ID, Visits, [Date,] Blog ID[, URL]. The first row must be a header; its content is used to auto-detect whether the file is for the overall or daily table (presence of a “Date” column).

OPTIONS

: Path to the CSV file to import.

[—table=

] : Which table to import into: overall, daily. Default: auto-detected from header.

[—use-urls] : Resolve the URL column to a post ID instead of using the Post ID column (matches the admin “Use URLs” option).

[—mode=] : How to handle existing rows: add (increment via bulk_upsert), set (overwrite per row). Default: add.

[—batch-size=] : Rows to process per batch. Default: 1000.

[—dry-run] : Parse the file and show a row count without writing anything.

[—force] : Skip interactive confirmation.

[—blog-id=] : Specific blog ID to import into (multisite only).

EXAMPLES

wp top10 counts import counts.csv
wp top10 counts import counts.csv --table=daily --dry-run
wp top10 counts import counts.csv --mode=set --force
wp top10 counts import counts-with-urls.csv --use-urls
wp top10 counts import counts.csv --blog-id=3

Line: 417

public function import( array $args, array $assoc_args ): void;
TypeNameDescription
array$argsCommand arguments.
array$assoc_argsCommand associative arguments.

Returns: void