Support » Fixing WordPress » show custom-post-types restricted to the way posts have been stored

  • This is a difficult task and I have no idea how to approach it. I hope someone can help here.

    The way my theme is built, my posts look different if they are created via backend or frontend: the result is that a post is shown either with its custom-post-types or without.
    Because I have thousands of posts, I imported them via backend (it wouldn’t have been possible to import them via frontend), so they are now all shown in their basic version. My problem is that I need them to be shown in the “full version” (i.e. with CPTs). I guess it’s not possible, but is there a way to achieve that?

Viewing 14 replies - 1 through 14 (of 14 total)
  • Moderator bcworkz

    (@bcworkz)

    It’s probably possible, but it may not be all that easy. I’m not sure what you mean by showing a post with its CPTs. (your “without” link doesn’t show any post content at all) What causes theme code to display related CPTs? How would code know there are CPTs and which ones relate to the current post? It sounds like there may be missing data that relates CPTs to posts. If so, you’d need to run several INSERT SQL queries to add the necessary data for each post with CPTs. But first we must determine the correct data to insert. We need to know how the code works in order to do so.

    Thank you very much for replying.
    The content (CPTs) are the black tabs on left sidebar. You can see that they are either present or not: if I create the post from frontend they are visible, but if I create/import the post via backend they are not. So, the theme has got some angular.js codes that recognizes when the post is created.
    Logically, a post made in WordPress should be the same, if created by a user in frontend or by Admin in backend, but in this case it’s not.
    The theme has got a weird logic but works fine. My problem now is that I need to fool the theme into believing posts are made via frontend whereas they are not.

    very hard to explain

    Moderator bcworkz

    (@bcworkz)

    Yes, a post is a post no matter where it is created, but data associated with it is apparently not the same. It’s not “normal” for post post_type to relate to other CPTs. Hierarchical post types like pages can relate to the other posts in their hierarchy, but not other CPTs. Of course, themes and plugins can do otherwise through their own means.

    It sounds like you don’t know how the theme is relating CPTs to posts. Fair enough. You might try comparing a front end post’s data with one you inserted through the back end. The best way to do so is through the phpMyAdmin app, a UI for your database. Check if the theme has any custom tables that might relate posts to CPTs. If none is seen, the data is likely in post meta. Search for all meta data related to a single front end post ID, then in another instance of phpMyAdmin, do the same for a backend post ID. Compare the data for something missing in the backend data that could relate to CPTs.

    Alternately, examine the template code that outputs related CPTs and try to determine what criteria it is using in its CPT query.

    If you cannot find what ties these together on your own, you should ask the theme developers for guidance. Because the specifics involve commercial theme features, there isn’t much more we can do here to help you with this.

    The theme is complex and not supported anymore. But I tried searching for one CPT and it was found inside wp_options and wp_postmeta tables. So I guess all my CPTs are stored in tables. That’s good news I guess.
    For the rest, I have difficulties understanding your tips because I’m not a developer.

    Moderator bcworkz

    (@bcworkz)

    Getting an idea of how things are organized is always good. You probably don’t need to be looking for actual CPTs though. What you really need is some sort of data that front end posts have that the imported posts don’t. It’s possibly in wp_postmeta, but CPTs could be related through other means, such as taxonomy terms.

    Maybe a better approach if you can manage it is to find the code that queries for CPTs related to the current post. Start with the template that outputs the CPTs on the post page. It’s likely just a theme function call. If so, locate the function declaration. It’ll be in theme source code somewhere. Doing a recursive grep search of all theme source code will help you find the right file. grep is a Linux command that does a full text search through multiple files, optionally recursing its search into subfolders. If you cannot access a Linux terminal, there are equivalent tools available in other O/S.

    It may be there is another function call within the declaration that actually queries for the CPTs. You may need to repeat the search process if it’s another theme function. Usually the query for CPTs is done through either get_posts() or new WP_Query(). What is crucial information is the criteria passed to one of these within the (). If a variable like $args is passed, we need to find the code that assigns criteria to $args. The criteria assigned will be very strong evidence of what is required of a post to get appropriate CPTs.

    arsenalemusica

    (@arsenalemusica)

    I thank you for the support but from your language I understand its going beyond my skills 🙁
    Sure the CPTs are output by functions (and I can spot them within the code) but I have no skills to tweak anything like that. I was looking for a more automatic approach (like a plugin). Maybe this cannot be achieved at all.

    Moderator bcworkz

    (@bcworkz)

    My hope was if you could identify what relates front end posts to CPTs, I would be able to give you some code that adds this to your back end posts. But without knowing how this relation is achieved, I wouldn’t know where to start creating the necessary code. Even if you could find the relation, I’d also need to know how code would know what CPTs should relate to which posts. Maybe it would be obvious or maybe it requires human decisions. Some things are just beyond the ability of this forum format to resolve.

    arsenalemusica

    (@arsenalemusica)

    …But I wouldn’t know what portion of code actually creates a post. There are many files with scripts running across one another, and also some calls to angular.js scripts to complicate things. Maybe you could spot something by viewing the page source of the post with CPTs? If not, I appreciated your help anyway.

    Moderator bcworkz

    (@bcworkz)

    Sadly, page HTML would not tell us what we need to know. The data I’m looking for would be in PHP or JS source somewhere, but where? Finding it in someone else’s code can be a challenge, even for experts. In any case, I don’t have access to that kind of code and have to rely upon you to know what I’m looking for. A tall order under the best circumstances.

    arsenalemusica

    (@arsenalemusica)

    …what can I do, here I cannot attach any file for you to investigate. And I would need to hire you as a freelance to sort it out, wouldn’t I?

    I can see that this portion of code outputs the tabs:
    <?php if( $tab->type == 'blog'): ?>

    which is taken from this:

    globoApp.controller('createListCtrl',function($scope , $sce , wpapi , $http , $timeout ){
    $scope.items = [{
            'title' : 'Ultime Notizie',
            'type'  : 'blog',
    	'icon'	: 'fa-comments-o'
            },
    Moderator bcworkz

    (@bcworkz)

    You can copy/paste code into pastebin.com and link to it here. By nature of the site, it’s impractical to create more than a small number of “pastes”. In any case, publishing a large part of any theme probably runs afoul of copyright restrictions. A small portion is fair use. I’m also unwilling to sift through a huge amount of code. If you think you can narrow down the applicable code to a few files, I’m willing to take a look.

    Please don’t offer any sort of compensation in these forums. It’s against our guidelines and attracts the sort of people that may not have good intentions. Never accept offers of assistance for pay through these forums. You must be very careful who you allow write access to your site. If I’m unable to help you from a few pastebin posts, hiring someone is a good way to get this resolved quickly. A couple resources for hiring knowledgeable coders is jobs.wordpress.net and jetpack.pro .

    arsenalemusica

    (@arsenalemusica)

    I appreciate your will to help me but I think it cannot be done due to the intertwined structure of the many codes. The functions are split between files (all driven by angular.js) therefore would be hard to spot the workflow.

    But I think the tabs (CPTs) are created like this:
    1) it detects if a CPT is created <div data-ng-if=”item.type == ‘portfolio'”>
    2) it shows the CPT <?php if( $tab->type == ‘portfolio’): ?>

    Moderator bcworkz

    (@bcworkz)

    That’s a help, but not the entire picture. I’m assuming “type” is the post_type. The crucial information we still need is how code knows which portfolios to list with any particular post.

    arsenalemusica

    (@arsenalemusica)

    I guess this is a clue

    if( array_key_exists(‘company_items’, $meta) ){
    $company_items = get_post_meta($post->ID , ‘company_items’, true );
    $company_items = globo_arrayToObject($company_items);

    but it also tells you how the CPTs (company_items) are both created as single items and as array, which makes the whole thing complicated

Viewing 14 replies - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.