Cogito ergo sum

How to let Avada Post Cards element fetch posts from the database based on a value of a custom field in the posts5 min read

Context

In the last couple of months, I have been working on the website of Stichting Civic. Stichting Civic is a Dutch foundation committed to improving the Dutch civic integration policy for refugees and other newcomers. The foundation aims at 1) collecting and stimulating socio-scientific and legal research into the outcomes of the current policy and 2) providing proposals for better integration policy for newcomers. That policy must be measurably effective, fit within our constitutional state and benefit both newcomers and society. I’m a member of Civic and I have been involved since the establishment of the foundation. In other words, I’m a volunteer and I’m doing all this work because I like Civic and I believe in their goals.

One of the requirements of the website is introducing a new and different content authoring system, different than the native WordPress one. Let me explain briefly what’s and how it’s realized.  An author on the website of Civic is a member of the Civic’s team. The author can be linked to a WP user or not. When a post is published on the website, the creator of the post can assign an author to the post. That author will be displayed on the page of the post. The author is a custom post type created using the amazing Pods Admin. This CPT has a relationship with the native WP Post type, and it’s a bi-directional relationship.

Each author/team member/person has her/his own page on the website, for example, this is the page of Anna Stupers https://stichtingcivic.nl/personen/anna-stupers/ . There you can see some basic information about the author/team member/person and beneath it an overview of written posts by that person. Those posts are fetched using the Post Cards element in Avada. Unfortunately, this element and almost all other elements in Avada fetch posts from the database using either categories or tags. That means it’s almost impossible to fetch posts from the database based on a certain value of a custom field in the posts. Just like in our case where we want to fetch all posts written (where the custom field ‘author’ has the ID of the CPT author) by the viewed person.

After a long and exhaustive search online, I came across “Custom Content Pack for Fusion Builder“. I thought it would help solve my problem. However, it didn’t help me and I got into a refund dispute with the make after all. Before purchasing the plugin, I clearly asked him what I want to achieve, and he answered “yes, you can”. After all, I wasn’t able to achieve what I wanted. So, I had no other choice than to dig into the code of Avada, Post Cards Element, and make my own version of the element.

Solution

I ended up with a working proof-of-concept Post Cards element where you can fetch WP posts by a custom field of your own choice whose value can be also specified. The screenshot below shows clearly what I have added to the element (some words are Dutch). You can see that in the section of Posts By the drop-down menu has the value of Custom Field. In the section of Custom Field Name, you can fill in the name of the custom field which is in my case “auteur” (Dutch for Author). Below that, you can see the section Custom Field Value, here you can specify the value of the custom field, in this case, I’m passing the ID of the currently viewed author/person/team member. So by setting those options correctly, you will end up with a page where you have basic information about the person and all posts written by her/him.

Modified version of PostCards Element from Avada by Peshmerge Morad

If the person has no posts linked to her/him, then nothing will be displayed in that section which is the case on my page on the website https://stichtingcivic.nl/personen/peshmerge-morad/ (I feel terrible about haven’t published or even helped with a single post/research on the website. I hope this changes soon ^_^). The screenshot below shows clearly what I mean!

Peshmerge_Morad_Profile_on_StichtingCivic

Because I was happy with what I have achieved and because I know how many people are looking for such a feature in Avada (saw a lot of people asking for something similar), I have decided to contact the makers of Avada and offer them my edited files. Normally, you would contact the support to offer you help, but this time, I contacted them and offered them something very brilliant :). On 25th of May, I opened a support ticket on https://theme-fusion.com/support  and explained my situation to them and what I have achieved, and offered them the edited files. Check the two screenshots below:

Avada_support_Peshmerge_Morad

Avada_support_Peshmerge_Morad_1

As you can see in the last two screenshots, the Post Cards Element was not the only element I edited. I have also edited the Blog element as well (check the screenshot below). However, the Post Cards element is what I’m the happiest about!

Modified version of Blog Element from Avada by Peshmerge Morad

If you need those files, just contact me or drop a comment below and I will be more than happy to provide you with the code!

UPDATE 20/08/2018:

I found out that Avada has implemented what I suggested to them three months earlier. The Post Cards Element in Avada has now natively an option to fetch posts from the database using a custom field. Check the screenshot of the current implementation (very similar to what I have made).

PostCardElement_Avada_with_custom_field_support

Honestly, I don’t know exactly when this feature was added, but a shout-out to me would be in place!

About the author

Peshmerge Morad

Data Science student and a software engineer whose interests span multiple fields.

Add comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Cogito ergo sum