Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [craft2]

Questions specific to the Craft 2 version of Craft CMS; avoid using for questions applicable to all or multiple versions.

0
votes
0answers
22 views

Open Tab on Page Load

The code below works when you click on the tab, but I am trying to get it to open the first tab on page load using Craft CMS. Any suggestions. <div class="available-options-tabs"> <h2&...
1
vote
1answer
29 views

Changing some letters in entry's uri before save it

I need to replace some characters in my entry's URI because we have some letters which do not exist in English like "ş" or "ç". It is a problem for SEO and we have to change each time manually. I ...
0
votes
0answers
21 views

ColdCache(?) error - count(): Parameter must be an array or an object that implements Countable

I'm getting a semi-persistent error that seems to be related to coldcache. Originally on PHP 7.2.6, though also present on PHP 7.3.5. I'm experimenting with different caching approaches and my ...
1
vote
1answer
27 views

Get a specific product with Element API, Commerce and Craft 2

How do I get a specific product via Element API? Here's what i have so far 'api/product' => function() { $productId = craft()->request->getRequiredQuery( 'productId' ); return [ ...
1
vote
1answer
34 views

Craft 2.X Local setup error – Craft not connecting to MySQL (via Sequel Pro)

Novice dev here, really struggling to get my local setup functioning. After a couple of days of wrestling with Apache config settings, I finally have Craft connecting via a VHOST setup. The problem –  ...
0
votes
0answers
12 views

Group entries alphebetically

After copying the "group" docs almost verbatim, I'm trying to sort a list of entries by province and then by city, this what I have: {# See Group docs for info: https://docs.craftcms.com/v2/...
0
votes
0answers
27 views

Is it possible to use craft()->runController with variables in Craft 2

I'm trying to run a plugin 1 controller from plugin 2. I can get it to run and re-direct to plugin 1's controller but as it is not being run with posted variables I need to be able to tell plugin 1's ...
0
votes
1answer
49 views

An unknown error occurred - no log entry

After copying files from a web server to my local devbox I am unable to open any 'Entries'. I keep getting two of the following error: "An unknown error occured." The assets section does open and I ...
2
votes
1answer
20 views

Maintaining order when getting by entries by ID

I'd like to get a certain set of entries in a specific order, but the element query comes back ordered by the default 'postDate desc' {% set ids = ['4213','3200','4204','4212'] %} {% set ...
0
votes
0answers
19 views

Why does $entry['slug'] and $entry->slug return different values?

I'm writing a simple plugin for 'Craft 2' and It seems that a slug of an entry is returned if you reffer it like: $entry['slug'] but calling $entry->slug returns same value as entry title. Is ...
1
vote
0answers
21 views

Exclude entries [duplicate]

I want to use search but exclude some types but when I use paginate craft.entries({ search: query }).type('not faq').limit(4).order('postDate desc') as pageInfo, results %} results are ...
1
vote
1answer
28 views

Clear template cache after update sale on Craft Commerce

How can I clear products template cache after update sale ? Because product price don't change ... Thank you.
1
vote
1answer
22 views

Preview PDF doesn't work in Safari but works in other browser

I'm trying to figure out why I am able to preview a PDF in all other browser apart from Safari. The PDF is generated using DOMPDF (printmaker plugin) and output to the browser though PHP using Craft ...
2
votes
1answer
27 views

How can I return only 1 random block in a Matrix in Craft using Twig?

I have a matrix with a couple of text fields for a caption, location and URL and an image Every time this page loads I want a random slide to show - so the background image is random, as well as the ...
1
vote
1answer
67 views

CSRF token is null or empty in craft 2

I'm having an issue with Craft 2.6 and the CSRF token. I enabled Csrf Protection in my general.php file by adding this line $config['*'] array so it looks like: $config['*'] = [ ... '...
1
vote
1answer
72 views

Ajax Post to Plugin Controller

I have been stuck on trying to make an ajax call to a custom plugin controller in Craft 2 for a few days after trying everything from following the documentation for Craft 2 as well as looking up ...
2
votes
1answer
37 views

Update a lightswitch field in Craft CMS 2

How can I edit a lightswitch field in an entries field layout via PHP? This is my current approach public function actionSponsoredEntriesPriority() { $this->requireAdmin(); $this->...
1
vote
1answer
38 views

Get entries based on custom field lightswitch in custom plugin in Craft 2

I am trying to get the entries in my custom plugin template ( CP ) Each entry has a lightswitch I want to fetch only those where lightswitch is enabled. In controller file: $criteria = craft()->...
1
vote
1answer
24 views

Open pop on click of custom action and get filled data

I created a new custom action. A new button is added in getAvailableActions() as we can se in below screenshot in red marked rectangle, now when i click on that button (Cusotm Action) i want to ...
1
vote
1answer
124 views

What is CDbException Error: SQLSTATE[42000]: Syntax error or access violation while moving a site to remote?

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #28 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'site....
1
vote
0answers
14 views

Templating not displaying after Craft server migration

A small team and I have inherited a Craft 2 site. We are brand new to craft with no previous experience with it. In wanting to work on offline copies of the sight the team is attempting to migrate the ...
1
vote
1answer
27 views

Craft error on NFS filesystem

I have a Craft 2 install that's been working fine until recently when the admin page is giving an error: file_put_contents(): Exclusive locks are not supported for this stream The front end is fine....
1
vote
1answer
50 views

Multiple and or relatedTo in plugin element criteria

I am trying to return entries that relate to a series of categories. For example, I am trying to return clothing, in this example, I want to return all entries related to (flannel or denim) and (blue ...
1
vote
1answer
31 views

ID of matrix printed instead of value

I have strange issue and cannot find out the solution for that. I have this field (matrix with some text values): https://imgur.com/a/KaFXubJ Also I have this entry: https://imgur.com/a/cPMrGul And ...
1
vote
1answer
24 views

Craft 2 - Returning Value in Variable from Plugin to Template

I am working with a plugin and wish to return a value from it to the template that calls it. In my plugin, there is an XML feed call, and I would like to pass a value(variable) from the plugin to the ...
1
vote
1answer
137 views

Variable “entry” does not exist in template at Structure Section

So, the subject. I am currently working with customer of craftcms v2. I am setting up Structure Section where I want to add Entry Type for index listing of items and add some items in list. So, here ...
1
vote
1answer
36 views

Craft 2, MySQL database, Twig, JavaScript files

I have created in Craft 2 CMS, under the profile of users (ex. parents), new tab for (children), where parents can fill in there children information. The data is saved in a database under the ...
1
vote
1answer
40 views

Log Errors from twig template

I need to log flash messages from craft.session.getFlashes to a error log file from a particular twig template in Craft 2. Is there a way to do it ?
1
vote
2answers
83 views

Unable to access site after importing DB

I am installing a repo locally, and everything runs smoothly and I am able to see the site and login to my admin. But when I import my DB then visit my site: I get the error message "Site unavailable"....
1
vote
0answers
25 views

Shipping and billing addresses dissapear when close and open the page

I have the following problem. When I set shipping and billing address on my cart and exit the page, the addresses are cleared once I open the page again. Is it possible to disable this behavior? ...
1
vote
1answer
115 views

Using Recaptcha v2 and Guest Entries plugin

How can I prevent bots from sending tons of messages from a frontend form, it uses the Craft Guest Entries plugin. I'm using Recaptcha 2 but it only hides the submit button and it doesn't work using ...
1
vote
1answer
32 views

Craft 2.6 Session Issues

We are having issues staying logged in to Craft (2.6). There was a plugin error which is what we thought was causing the issues, so we removed the sprout SEO plugin. However the error still persists. ...
0
votes
0answers
31 views

CP doesn't recognize update from 2.7.3 to 2.7.4

I have a site running Craft 2.7.3. My update flow is to make sure that my development branch is up to date (with no outstanding commits) and that my local db is up to date with production. I then ...
1
vote
1answer
50 views

Adding entry type using setContentFromPost

I'm creating a new user using $user->setContentFromPost(). It all works fine except I can't attach an entry to an Entries field. $user = new UserModel(); $user->username = $email; $user-...
1
vote
1answer
23 views

How to determine if a user's email has changed

I'm trying to determine if a user has changed their email address via a front-end form. From what I've gleaned, the best way to do this would be by checking the existing record during users....
1
vote
1answer
17 views

ElementCriteriaModel combine with 'and' and 'or' filters

Saying I want to convert the following SQL query into ElementCriteriaModel: SELECT * FROM users WHERE fieldA = 1 AND (fieldB = 1 or fieldC = 1) I can't find a way in ElementCriteriaModel to do so. {...
1
vote
1answer
30 views

Custom plugin log not logging

I'm having this weird issue that both of my custom plugin logs are not working but all other third party ones including craft.log work fine. By 'not working' I mean the log file is generated, but ...
1
vote
0answers
73 views

Order entries by custom date field

I want to modify this query so that the dated entries are sorted in descending order on a custom field called 'startDate'. Have tried adding .order('startDate') to the end of the craft.entries(query)....
2
votes
1answer
95 views

Is it possible to pass a variable to an event in a plugin?

I need to find out if any changes have been made to the entry on successful save. Using events entries.onBeforeSaveEntry and entries.onSaveEntry seems to be a way to do it. Maybe. Can I pass some ...
2
votes
1answer
42 views

Set a route for all requests within a plugin

I’m trying to use a plugin to set up a site route that will direct every page request to a special template. This is what I’ve set up in my plugin file. public function registerSiteRoutes() { ...
1
vote
0answers
60 views

Avoiding includeJsFile, includeJS from caching

In my template, I have an includeJSFile that loads properly on the first load, but disappears on subsequent loads. The includeJSFile is outside the caching tags, so I'm not sure why this is still ...
2
votes
1answer
104 views

Impossible to invoke a method (“limit”) on an array

I recently upgraded a site from Craft 2 to Craft 3, so I'm trying to figure out what was deprecated and caused this error. At the top of the page I have this {% set solutions = craft.entries....
1
vote
1answer
21 views

Accessing global set's field gives object that couldn't be converted to string

I've been using globals many times but this is my first time encounter with such problem. Let's go from the bottom. I have two global sets with handles tax and company. The Tax set have only one plain ...
1
vote
1answer
47 views

Failed Stale Template Cache Delete Error…Analyzed…But No Answer

For some of the extremely static content on my site, I use caching to prevent multiple db queries during every single load. I also have multiple locale on my site with custom cache key names. The ...
2
votes
1answer
26 views

How to directly get value of text field in a given section of type structure?

I am trying to get a value of a text field that is in a Section which is a structure and has multiple entry types. I don't want to use a loop. I tried this and some other variations but does not give ...
1
vote
1answer
19 views

Craft localisation caching error

long time listener, first time caller. I'm having some issues getting localisation setup on my homestead/vagrant craft 2 site. I'm running into issues, I believe, with the craft cache when I try to ...
1
vote
1answer
69 views

where command sql query not working

My problem is that I can't update the specific $userId. have the values I've selected. I also get an error: Call to a member function where() on integer I just started to learn Craft. It can be ...
1
vote
1answer
25 views

Tasks runs only after admin is logged in

I have a plugin which runs a task on order complete. The tasks runs successfully without any errors. But the problem is the task is only completed when admin is logged in. So if someone has completed ...
1
vote
1answer
73 views

Matrix field validation on guest entry submission

First I illustrate the way I set up guest entry form. Let's say I have channels blog product and comment cart. Guest entry submits to the comment cart channel. Form lives in template which I use to ...
1
vote
1answer
14 views

Forward users to the right template according to the current active site's language

I am using Craft 2 and trying to forward users to the right template according to the current active site's language when they reset their password. The problem is that the reset URL that Craft ...