0

We are running Wordpress 6.3.1 and Civicrm 5.65.1

We would like to dynamically display the Total Member count on our Wordpress home page. We have different member categories and would like to display this as a total only.

Is there an easy way to do this? Any help would be greatly appreciated.

Thanks

1 Answer 1

2

You can create a Search kit to display number for Memberships and use shortcode to display on pages or widget

Search kit import:

[
  [
    "SavedSearch",
    "save",
    {
      "records": [
        {
          "name": "Member_count",
          "label": "Member count",
          "form_values": null,
          "mapping_id": null,
          "search_custom_id": null,
          "api_entity": "Membership",
          "api_params": {
            "version": 4,
            "select": [
              "COUNT(id) AS COUNT_id"
            ],
            "orderBy": [],
            "where": [
              [
                "status_id:name",
                "IN",
                [
                  "New",
                  "Current"
                ]
              ]
            ],
            "groupBy": [
              "Membership_MembershipType_membership_type_id_01.member_of_contact_id"
            ],
            "join": [
              [
                "MembershipType AS Membership_MembershipType_membership_type_id_01",
                "LEFT",
                [
                  "membership_type_id",
                  "=",
                  "Membership_MembershipType_membership_type_id_01.id"
                ]
              ]
            ],
            "having": []
          },
          "expires_date": null,
          "description": null
        }
      ],
      "match": [
        "name"
      ]
    }
  ],
  [
    "SearchDisplay",
    "save",
    {
      "records": [
        {
          "name": "Member_count_Grid_1",
          "label": "Member count Grid 1",
          "saved_search_id.name": "Member_count",
          "type": "grid",
          "settings": {
            "colno": "3",
            "limit": 0,
            "sort": [],
            "pager": false,
            "columns": [
              {
                "type": "field",
                "key": "COUNT_id",
                "dataType": "Integer",
                "rewrite": "[COUNT_id] Members"
              }
            ],
            "placeholder": 0
          },
          "acl_bypass": false
        }
      ],
      "match": [
        "name",
        "saved_search_id"
      ]
    }
  ],
  [
    "Afform",
    "save",
    {
      "records": [
        {
          "name": "afsearchMembers",
          "requires": [],
          "title": "Members",
          "description": "",
          "is_dashlet": false,
          "is_public": false,
          "is_token": false,
          "permission": [
            "access AJAX API"
          ],
          "type": "search",
          "entity_type": null,
          "join_entity": null,
          "contact_summary": null,
          "summary_contact_type": null,
          "icon": "fa-list-alt",
          "server_route": "",
          "redirect": null,
          "create_submission": false,
          "navigation": null,
          "layout": "<div af-fieldset=\"\">\n  <crm-search-display-grid search-name=\"Member_count\" display-name=\"Member_count_Grid_1\"></crm-search-display-grid>\n</div>\n"
        }
      ]
    }
  ]
]

Shortcode:

[civicrm component="afform" name="afsearchMembers"]
5
  • Thanks @Pradeep...The code works in Search Kit and when executed within Search Kit it brings back the correct results.....It looks like when I execute the shortcode I do not get anything. I am suspecting it is to do with Afform. My version of Afform in extensions is 0.5......how do I get this updated with the latest version 5.65.1 ?
    – markd
    Sep 28, 2023 at 23:08
  • Are you on Civi 5.65.1 ? If yes you will need to delete the extension from the extension folder and then clear CiviCRM cache. The afform extension now comes with Civi so there shouldn't be any code under your extension folder Sep 28, 2023 at 23:16
  • Yes I am on 5.65.1.....researching further I do not have afform directory in ~/wp-content/uploads/civicrm/ext.....the only directory I have afform in is ~/wp-content/plugins/civicrm/civicrm/ext....do you need me to delete afform and its subdirectories in ~/wp-content/plugins/civicrm/civicrm/ext ??....thanks for you assistance..
    – markd
    Sep 28, 2023 at 23:48
  • I believe that there may be a problem with my last upgrade from 5.58 to 5.65.1....I will upgrade to 5.66.X next week when it is released. I will revert with my findings after that upgrade.
    – markd
    Sep 29, 2023 at 7:47
  • It should be under the extension directory where you place contrib extensions Sep 29, 2023 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.