php – WordPress – display relationship between blog posts and custom posts

I created through ACF a relationship between blog posts and the custom post type, which contains employee profiles. Through the relationship, I am able to display links to the employee’s profile, who is the author of a post.

I want to display now the list of posts created by employees at their profiles. I was able to find a code which does that. Unfortunately, whenever I assign more than 5 blog posts to an employee, the next ones are not visible. Would you be able to help me and tweak the code to display more than 5 posts in new rows?

<div class="author-content">

        <?php 
        /*
         *  Query posts for a relationship value.
         *  This method uses the meta_query LIKE to match the string "123" to the database value a:1:{i:0;s:3:"123";} (serialized array)
         */

         $documents = get_posts(array(
                     'post_type' => 'post',
                     'meta_query' => array(
                      array(
                            'key' => 'our_people_author', // name of custom field
                            'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
                            'compare' => 'LIKE'
                                )
                            )
                        ));

                        ?>
        <?php if( $documents ): ?>

          <ul class="table-author">
             <?php foreach( $documents as $document ): ?>
<li class="singleauth-list">
<a href="<?php echo get_permalink( $document->ID ); ?>"><img src="<?php echo get_the_post_thumbnail_url($document->ID, 'thumbnail');?>" class="people-post-image"></a>
                   <a href="<?php echo get_permalink( $document->ID ); ?>" class="author-links">
                     <?php echo get_the_title( $document->ID ); ?>
                   </a>
</li>
             <?php endforeach; ?>
         </ul>
      <?php endif; ?>
</div>

Display category filters for custom post type when category is shared by multiple post types

I already have a solution to this problem but I’m wondering if there’s a more efficient way to do it. I have a custom post type called “galleries” that uses the same taxonomy as blog posts. So if a user creates a category named “Animals” when making a blog post, that category will show up as an option when creating a new gallery.

On the gallery display page, I want to output a list of categories in a select element which are used to filter the galleries. However, if no galleries are using the category “Animals”, that category shouldn’t be displayed, since selecting it will return no results.

Here’s how I solved this so far:

<?php
  // 1. Get all the categories
  $categories = get_categories( array(
     'orderby'   => 'name',
     'order'     => 'ASC'
  ) );
?>

<select>

<?php
// 2. Loop through the categories
foreach($categories as $cat) {

  // 3. Get the ID of the current category
  $category_id= get_cat_id($cat->name);

  // 4. Query the galleries post type for posts using the current category
  $args = array(
    'post_type' => 'galleries',
    'category' => $category_id
   );
  $posts = get_posts($args);

   // 5. Count the number of posts using the current category
   $count = count($posts);

   // 6. Display the option if that number is greater than 0
   if($count > 0) { ?>

     <option value="<?php echo $cat->slug; ?>"><?php echo $cat->name; ?></option>

   <?php } ?>

</select>

It seems like that’s a lot of steps and maybe I’m doing this in a roundabout kind of way. Is there a more efficient way to do this? Thanks in advance.

hdmi – External display switches to lower resolution and I need to restart my MacBook to fix it

My setup is the following:

  • macOS Catalina, version 10.15.7 (but this has been happening since before Catalina)
  • MacBook Pro (15-inch 2019)
  • AOC Q27P1 External display, connected via this USB C to HDMI cable

Display will work fine for some time, then it suddenly goes black for a couple of seconds and when it comes back on, it switches to a lower resolution for a seemingly random reason.

Here’s the Displays settings when the bug happens:

enter image description here

And here’s what I see after I restart the MacBook:

enter image description here

As you can see, the highest two resolutions disappear until I restart the MacBook. Where do you think could be the problem?

Add Filter in REST Export display in view in D8

is there any way to add the same filter for the REST Export display ?

On your regular View page, apply filter for something, and you’ll see a URL query gets appended to your URL. For example, when I’m filtering by content type, for mine, I see:

mysite.com/page-view?title=&type=article&status=All&langcode=All (This is based on the view filters I have).

Then all you have to do is append this query to your REST export URL.

mysite.com/rest-export?title=&type=article&status=All&langcode=All (Assuming you have the same filters as your page view, they should’ve been added by default when you added the REST view).

You’ll need to create documentation for this. So people that are using your API know what parameter names & values are accepted.

8 – How to display default drupal search block in twig template

In twig_tweak module before version 2 (for Drupal 8) I could place the following code in my page twig template and it would work:

{{ drupal_block('exposedformsearch_contentpage_1') }}

This would display put the default site search box.

After upgrading to version 2, this doesn’t work anymore and see the following message on the page:

This block is broken or missing. You may be missing content or you might need to enable the original module. 

I tried using the command:

{{ drupal_block('search_form_block') }}

That displays the same error message.

Does anyone know what the the correct call is? I can’t seem to find any documentation anywhere as to what the replacement call should be.

Thanks.

Search Result displays Item_default as display template for my custom result type

My Search Results displays Item_default as display template for my custom result type . I have my display template major version published and have mapped in Search Result Types. My search result type is also under site collection. In content search web part I have set result type to decide option.

I don’t know where else to look to debug the issue. Any pointers ?

how to know when the user is in specific part of the website and when he leaves that part and display the data in the admin dashboard

I want to display for the admin when a user visits a page and when he leaves that page

the page is for example test.test/my-dashboard. and it’s only available for the logged in users.
the admin knows to know the time when the user is in that page and the time the user leaves that page.

thanks in advance and excuse my language.

display images on my cpanel email

is there any way to display uploaded image in our mail content in cpanel emails ? I created a online application form with picture file upload field but i cant view the picture on my emails from cpanel.

Why doesn’t a simple Http request to display a remote web page violate the Same Origin Policy?

On a w3schools page, I found that HTTP requests work like this:

  • A client (a browser) sends an HTTP request to the web
  • A web server receives the request, and runs an application to process it
  • The server returns an HTTP response (output) to the browser
  • The client (the browser) receives the response.

On the same page I found that an XMLHttpRequest works like this:

  • A browser creates an XMLHttpRequest object and sends it to the server
  • The server processes the request, creates a response and sends data back to the browser
  • The browser processes the returned data using JavaScript and updates the page content.

The above two processes appear pretty much the same to me. However, the latter one violates the Same Origin Policy (SOP) if the server runs on a remote domain. This question on stackoverflow about the url in the open() method says that

As we can only send requests to our own web server, I assume that we don’t have to rewrite the website’s name in the URL.

Applying the same logic to the first case (Http requests) would mean that I couldn’t open a web page if it is not on my own computer. Luckily, this is not the case.

So, why doesn’t an Http request to display a remote web page violate the SOP? What is the key point/difference here?

I assume it’s about the fact that the second process (XMLHttpRequest) is initiated from a script, while the first one is triggered by the user. However, isn’t the Http request sent from a script when I click a hyperlink on a web page? And how can a web server distinguish between requests coming from a script and coming from a user?

Display 10 popular tags of custom posts of curent custom taxonomy term

I want to display 10 popular tags in current taxonomy. ok i can display popular tags of total tags but i need to display tags of custom posts of current custom taxonomy term. please need help. i spend all may day to fix this problem.