Customization – Meta query for custom post type that is ignored in the main query

I looked through the Interwebz but couldn't find a solution.

I am creating a website with custom post types where posts also contain custom post meta (via ACF).

I am creating an archive file and want to implement some filters (filter post by category and two different custom fields.

To even display the custom posts (called "mowcy") in the category template, I added this snippet to my function file:


function custom_post_type_cat_filter($query) {
   if ( !is_admin() && $query->is_main_query() ) {
      if ($query->is_category()) {
      $query->set( 'post_type', array( 'post', 'mowcy' ) );

Now I have uploaded a simple archive template to see how it works:


This is where the problem begins:

If I specify the arguments in the code and use a custom query to display custom posts with a certain custom field value "EN" (an ACF "Languages" field with multiple check boxes for different languages), it works fine:

// Specify query parameters
$args = array(
    'post_type' => 'mowcy',
    'meta_query' => array(
            'key'     => 'languages',
            'value'   => '"EN"',
            'compare' => 'LIKE'
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) // ... Beginning of the loop

However, when I print the same arguments to use in the URL (using http_build_query with $ args) it looks like this:


After archive.php has been reset to use the main query and URL parameters again and the above parameters have been used, meta_query is completely removed from the query and only shows all posts of the user-defined type "mowcy". I can add a category parameter to the url and it works fine, but meta_query is still completely ignored.

What am i missing Does the query feature ignore meta_queries for custom post types by default? How can I fix it?

As I said at the beginning, I also plan to filter the posts by an additional second custom value (i.e. a second additional meta_query). Will this be an additional problem (when looking for a solution I saw a few mentions that in such a case you would have to manually merge two meta queries)?

Thanks in advance for any kind of support.

Make sure that a query argument with array formulas works in Google Sheets

Can you help me please?
I've figured out how to get the result I want, but how can I get it to work with array formulas? Here is my google sheet

This works for me in Y2:

= COUNT (QUERY (& # 39; Feed from Register & # 39 ;! $ B $ 2: Select $ E, "B, where B> Date & # 39;" & TEXT (TODAY () – ValidDatesOnRegister! $ B $ 1 , "YYYY-MM-DD") & "& # 39; and E contains & # 39;" & $ W2 & "& # 39;"))

But however much I've tried, I can't use it as an array formula in the column. Which approach do I have to choose if the & # 39; and & # 39; caused the problem? IF or filter?

Help much appreciated …
Enter the image description here

Query – Prevents versioning of .woff files (fonts)

If you load your fonts using the standard stylesheet queue, you can add them to your functions.php file:

function remove_querystrings( $src ) {
    $parts = explode( '.woff?ver', $src );
    return $parts(0);
add_filter( 'style_loader_src',  'remove_querystrings', 15, 1 );

I haven't tested this, but I'm pretty sure it will only work if you add the fonts as well wp_enqueue_style();,

I use the above in production environments to remove the query string from all scripts and styles, not just fonts, but only on finalized websites where only content is updated. (With that in mind, I've never tested it .woff before the ?ver.)

Query addition and subtraction of the same SQL field

I have the following inconvenience because I can add and subtract the same field in the same "Entries" table in a single query. It would be to add a SUM field (entry.ent_quantity) if the field entry.id_user = 0 and subtract this sum if the fieldentries.id_user <> 0. That means I get two sums from the same field, if the field id_user = 0 and if id_user <> 0 and these then add up the rest. Thanks in advance. I add the query code that I want to change

 $sql = "SELECT productos.id_producto as id_producto,, productos.marca, productos.proveedor, productos.stock_inicial, productos.fecha_ingreso, productos.nro_expediente,  productos.stock_actual,, SUM(entradas.cantidad_ent)  FROM productos
   INNER JOIN categorias on  categorias.id_categoria = productos.id_categoria
   LEFT JOIN entradas on entradas.id_producto= productos.id_producto
   where productos.id_area='$id_area2'  and productos.precio_unidad != 0  group by id_producto ";

$query = mysqli_query($conn, $sql);

sql – Age PROCEDURE must be the first statement in a query batch

Every time I want to run this script:

str2 = "USE (" + database + ");" + vbCrLf +
                "ALTER PROC (dbo).(GenerateTreeViewDataXML)

                @string NVARCHAR(max) out
                Declare @xmldata xml
                SET @xmldata = (select 

                from " + database + "
                left join AreaSet Area ON Area.TerminalId = Terminal.Id

                for XML AUTO 
                ,Root ('Terminals'))
                SET @string = CONVERT(NVARCHAR(max), @xmldata)

An error message is displayed:
Age PROCEDURE must be the first statement in a query batch.

query – SQL Server string concat with order by and subquery

While working on dynamic SQL production code, we came across code that concatenates a series of strings and a subquery, and then concatenates more strings. The goal of the code is to populate an SQL variable to finally call EXEC (@sql). One thing we noticed was that despite our string concat and COALESCE reviews, only the last record filled the variable.

The following code is a simplified version to reproduce the results.

IF OBJECT_ID('tempdb..#test') IS NOT NULL
  DROP TABLE #test

    tmp_id INT IDENTITY(1,1),
    error VARCHAR(MAX),
    error2 VARCHAR(MAX),
    object_id INT


INSERT INTO #test(error, error2, object_id)
FROM sys.columns

SELECT @sql += 
     CONVERT(VARCHAR(MAX), error) + (SELECT + CONVERT(VARCHAR(MAX), xC.object_id) 
                                               FROM sys.columns xC
                                               WHERE = T.error
                                                AND xC.object_id = T.object_id) + ',' + CONVERT(VARCHAR(MAX), error) + ',' + CONVERT(VARCHAR(MAX), error) + ',' + CONVERT(VARCHAR(MAX), error) + ',' + CONVERT(VARCHAR(MAX), error2) + CONVERT(VARCHAR(MAX), error) + ',' + CONVERT(VARCHAR(MAX), error) + ','
FROM #test T
ORDER BY tmp_id


The strange thing is that a combination of factors seems to be involved here. If you remove the sys.columns suborder or the order or the error2 column, it works as expected. You can also change the order by mistakenly ordering instead of tmp_id and it will continue to work.

I'm not looking for a solution since I've already rewritten the production code, but I'm very interested in the "why" that happens. I tested on SQL Server 2008, 2016, 2017 and 2019 servers.

Does anyone have any ideas about the cause?

Database – Update the custom post type taxonomy using SQL Query

In the following I will explain some of my tasks and how I would like to process this request.

  1. I imported all & # 39;posts& # 39; from my other website in & # 39;posts& # 39; on my current website.

  2. On the new website, I have a custom post type called "Recipe". With the following query I can transfer all "Posts" with the category "Recipes" / "Slug" into the user-defined post type "Recipe".

Here is the code:

UPDATE  `wp_posts` p 
    LEFT OUTER JOIN wp_term_relationships r ON r.object_id = p.ID
    LEFT OUTER JOIN wp_term_taxonomy x ON x.term_taxonomy_id = r.term_taxonomy_id
    LEFT OUTER JOIN wp_terms t ON t.term_id = x.term_id
    SET  p.post_type =  'recipe'
    WHERE p.post_status = 'publish'
    AND p.post_type = 'post'
    AND t.slug = 'recipes';

This moved all of my posts to my custom post type that has a & # 39; recipe & # 39; slug associated with (Which is what i want) – The - Hyphens are the categories that have not been transferred.
Enter the image description here

I'm stuck here, I have the following question:

UPDATE `wp_term_taxonomy` SET `taxonomy` = 'recipe-categories' WHERE `taxonomy` = 'category';

This query transmits and fills in all taxonomies, but then all posts in my "Posts" are removed from their categories.


Here's the ultimate goal: Select custom recipe post type where taxonomy is 'category' and change it to 'recipe-categories' – Is that possible? I want to change the taxonomy in "Recipe Categories" of ONLY posts that are associated with a custom "Recipe" post type.

Fill the last cell with the query function in Google Sheet

Look for a way to fill an extra column in a QUERY Function. My data is an example of this

A | B
ID | Active
001 | FALSE
002 | FALSE

and with something like =(query(A:A, "Select A, B(=TRUE)")) I want to be the edition

A | B
ID | Active
001 | TRUE
002 | TRUE

I am aware that converting and padding FALSE to TRUE only takes 15 seconds, but I want to avoid the manual touch.

thank you in advance

php – Laravel Eloquent query / subquery without values ​​triggers an error

All my departments have to submit different reports every quarter: budget, staff, etc. I want to display a table listing all the required reports for the department of the logged in user (all departments have to submit the same reports), a Boolean value if they have submitted it , and a boolean if this file is considered valid. I mainly have problems with the Boolean values.

I have three tables: reports saves the id. name, and due_date;; file_uploads saves the id. report_id. filename, and department_id;; file_upload_errors Shops id. file_upload_id, and error,

In order to create the table that should be displayed to the user, I queried the report table:

$data = Reports::with((
    'file_uploads' => function ($query) {
        $query->where('department_id', '=', user()->department_id);

Next I need to map the data to my view model:

$vm = array();
//map the data to the view model
foreach ($data as $value) {
    $mapping = new DataRequestsViewModel();
    $mapping->ReportName = $value->name;
    $mapping->DueDate = $value->due_date;
    $mapping->IsUploaded = ($value->file_uploads->count() > 0) ? true : false;
    $mapping->IsValid = ($value->file_uploads->file_upload_errors->count() < 1) ? true : false;
    $vm() = $mapping;

However, I get an exception: Property (file_upload_errors) does not exist on this collection instance.

I understand that this is because the user cannot query the relationship of if he has not yet uploaded the file null to see if there are any file_upload_errors but i don't know how to deal with it ... can anyone show me a good approach?

Query multiple SQL Server instances using Powershell by referencing the list of instances in a text file

Instead of issuing one query per instance through SQL Server Management Studio, we're trying to create a powershell script to query multiple instances by looping through it that points to a text file that contains, for example, 100 SQL Server instances. Search each instance of SQL Server, issue a query, and export it to CSV.

The following is the powershell script we currently have:

$ ServerInstance = "C: Users \ Documents InstanceList.txt"

foreach ($ i in $ ServerInstance)

$ sql = "SELECT
DB_NAME (dbid) as DBName,
COUNT (dbid) as NumberOfConnections,
RTRIM (login name) as login name,
RTRIM (host name) As host name, login_time, program name
WHERE –DB_NAME (dbid) = & # 39; Genesys_wfm & # 39; and
dbid> 5
–and hostname = & # 39; xxxx & # 39;
and login name not in (& # 39; NT AUTHORITY SYSTEM & # 39 ;, & # 39; ACE & # 39 ;, & # 39; domain xxxx & # 39;)
dbid, loginame, hostname, login_time, program name
Order after Login_Time desc; "

Invoke-Sqlcmd ServerInstance $ i -Query $ sql-ConnectionTimeout 60 -QueryTimeout 99999

The following is the InstanceList.txt:
Server name instance name 1
Servername2 instance name2
and so on.

Thanks, I hope my explanation helps.